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/module.h>
34 #include <linux/kernel.h>
35 #include <linux/pci.h>
36 #include <linux/i2o.h>
37 #include <linux/errno.h>
38 #include <linux/init.h>
39 #include <linux/slab.h>
40 #include <linux/miscdevice.h>
42 #include <linux/spinlock.h>
43 #include <linux/smp_lock.h>
44 #include <linux/ioctl32.h>
45 #include <linux/compat.h>
46 #include <linux/syscalls.h>
48 #include <asm/uaccess.h>
51 extern int i2o_parm_issue(struct i2o_device *, int, void *, int, void *, int);
53 static spinlock_t i2o_config_lock;
55 #define MODINC(x,y) ((x) = ((x) + 1) % (y))
57 struct sg_simple_element {
64 struct fasync_struct *fasync;
65 struct i2o_evt_info event_q[I2O_EVT_Q_LEN];
66 u16 q_in; // Queue head index
67 u16 q_out; // Queue tail index
68 u16 q_len; // Queue length
69 u16 q_lost; // Number of lost events
70 ulong q_id; // Event queue ID...used as tx_context
71 struct i2o_cfg_info *next;
73 static struct i2o_cfg_info *open_files = NULL;
74 static ulong i2o_cfg_info_id = 0;
77 * Each of these describes an i2o message handler. They are
78 * multiplexed by the i2o_core code
81 static struct i2o_driver i2o_config_driver = {
85 static int i2o_cfg_getiops(unsigned long arg)
87 struct i2o_controller *c;
88 u8 __user *user_iop_table = (void __user *)arg;
89 u8 tmp[MAX_I2O_CONTROLLERS];
92 memset(tmp, 0, MAX_I2O_CONTROLLERS);
94 list_for_each_entry(c, &i2o_controllers, list)
97 if (copy_to_user(user_iop_table, tmp, MAX_I2O_CONTROLLERS))
103 static int i2o_cfg_gethrt(unsigned long arg)
105 struct i2o_controller *c;
106 struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg;
107 struct i2o_cmd_hrtlct kcmd;
113 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
116 if (get_user(reslen, kcmd.reslen) < 0)
119 if (kcmd.resbuf == NULL)
122 c = i2o_find_iop(kcmd.iop);
126 hrt = (i2o_hrt *) c->hrt.virt;
128 len = 8 + ((hrt->entry_len * hrt->num_entries) << 2);
130 /* We did a get user...so assuming mem is ok...is this bad? */
131 put_user(len, kcmd.reslen);
134 if (copy_to_user(kcmd.resbuf, (void *)hrt, len))
140 static int i2o_cfg_getlct(unsigned long arg)
142 struct i2o_controller *c;
143 struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg;
144 struct i2o_cmd_hrtlct kcmd;
150 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
153 if (get_user(reslen, kcmd.reslen) < 0)
156 if (kcmd.resbuf == NULL)
159 c = i2o_find_iop(kcmd.iop);
163 lct = (i2o_lct *) c->lct;
165 len = (unsigned int)lct->table_size << 2;
166 put_user(len, kcmd.reslen);
169 else if (copy_to_user(kcmd.resbuf, lct, len))
175 static int i2o_cfg_parms(unsigned long arg, unsigned int type)
178 struct i2o_controller *c;
179 struct i2o_device *dev;
180 struct i2o_cmd_psetget __user *cmd =
181 (struct i2o_cmd_psetget __user *)arg;
182 struct i2o_cmd_psetget kcmd;
188 u32 i2o_cmd = (type == I2OPARMGET ?
189 I2O_CMD_UTIL_PARAMS_GET : I2O_CMD_UTIL_PARAMS_SET);
191 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_psetget)))
194 if (get_user(reslen, kcmd.reslen))
197 c = i2o_find_iop(kcmd.iop);
201 dev = i2o_iop_find_device(c, kcmd.tid);
205 ops = (u8 *) kmalloc(kcmd.oplen, GFP_KERNEL);
209 if (copy_from_user(ops, kcmd.opbuf, kcmd.oplen)) {
215 * It's possible to have a _very_ large table
216 * and that the user asks for all of it at once...
218 res = (u8 *) kmalloc(65536, GFP_KERNEL);
224 len = i2o_parm_issue(dev, i2o_cmd, ops, kcmd.oplen, res, 65536);
232 put_user(len, kcmd.reslen);
235 else if (copy_to_user(kcmd.resbuf, res, len))
243 static int i2o_cfg_swdl(unsigned long arg)
245 struct i2o_sw_xfer kxfer;
246 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
247 unsigned char maxfrag = 0, curfrag = 1;
248 struct i2o_dma buffer;
249 struct i2o_message __iomem *msg;
251 unsigned int status = 0, swlen = 0, fragsize = 8192;
252 struct i2o_controller *c;
254 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
257 if (get_user(swlen, kxfer.swlen) < 0)
260 if (get_user(maxfrag, kxfer.maxfrag) < 0)
263 if (get_user(curfrag, kxfer.curfrag) < 0)
266 if (curfrag == maxfrag)
267 fragsize = swlen - (maxfrag - 1) * 8192;
269 if (!kxfer.buf || !access_ok(VERIFY_READ, kxfer.buf, fragsize))
272 c = i2o_find_iop(kxfer.iop);
276 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
277 if (m == I2O_QUEUE_EMPTY)
280 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) {
285 __copy_from_user(buffer.virt, kxfer.buf, fragsize);
287 writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_7, &msg->u.head[0]);
288 writel(I2O_CMD_SW_DOWNLOAD << 24 | HOST_TID << 12 | ADAPTER_TID,
290 writel(i2o_config_driver.context, &msg->u.head[2]);
291 writel(0, &msg->u.head[3]);
292 writel((((u32) kxfer.flags) << 24) | (((u32) kxfer.sw_type) << 16) |
293 (((u32) maxfrag) << 8) | (((u32) curfrag)), &msg->body[0]);
294 writel(swlen, &msg->body[1]);
295 writel(kxfer.sw_id, &msg->body[2]);
296 writel(0xD0000000 | fragsize, &msg->body[3]);
297 writel(buffer.phys, &msg->body[4]);
299 // printk(KERN_INFO "i2o_config: swdl frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
300 status = i2o_msg_post_wait_mem(c, m, 60, &buffer);
302 if (status != -ETIMEDOUT)
303 i2o_dma_free(&c->pdev->dev, &buffer);
305 if (status != I2O_POST_WAIT_OK) {
306 // it fails if you try and send frags out of order
307 // and for some yet unknown reasons too
309 "i2o_config: swdl failed, DetailedStatus = %d\n",
317 static int i2o_cfg_swul(unsigned long arg)
319 struct i2o_sw_xfer kxfer;
320 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
321 unsigned char maxfrag = 0, curfrag = 1;
322 struct i2o_dma buffer;
323 struct i2o_message __iomem *msg;
325 unsigned int status = 0, swlen = 0, fragsize = 8192;
326 struct i2o_controller *c;
329 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
332 if (get_user(swlen, kxfer.swlen) < 0)
335 if (get_user(maxfrag, kxfer.maxfrag) < 0)
338 if (get_user(curfrag, kxfer.curfrag) < 0)
341 if (curfrag == maxfrag)
342 fragsize = swlen - (maxfrag - 1) * 8192;
347 c = i2o_find_iop(kxfer.iop);
351 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
352 if (m == I2O_QUEUE_EMPTY)
355 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) {
360 writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_7, &msg->u.head[0]);
361 writel(I2O_CMD_SW_UPLOAD << 24 | HOST_TID << 12 | ADAPTER_TID,
363 writel(i2o_config_driver.context, &msg->u.head[2]);
364 writel(0, &msg->u.head[3]);
365 writel((u32) kxfer.flags << 24 | (u32) kxfer.
366 sw_type << 16 | (u32) maxfrag << 8 | (u32) curfrag,
368 writel(swlen, &msg->body[1]);
369 writel(kxfer.sw_id, &msg->body[2]);
370 writel(0xD0000000 | fragsize, &msg->body[3]);
371 writel(buffer.phys, &msg->body[4]);
373 // printk(KERN_INFO "i2o_config: swul frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
374 status = i2o_msg_post_wait_mem(c, m, 60, &buffer);
376 if (status != I2O_POST_WAIT_OK) {
377 if (status != -ETIMEDOUT)
378 i2o_dma_free(&c->pdev->dev, &buffer);
381 "i2o_config: swul failed, DetailedStatus = %d\n",
386 if (copy_to_user(kxfer.buf, buffer.virt, fragsize))
389 i2o_dma_free(&c->pdev->dev, &buffer);
398 static int i2o_cfg_swdel(unsigned long arg)
400 struct i2o_controller *c;
401 struct i2o_sw_xfer kxfer;
402 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
403 struct i2o_message __iomem *msg;
408 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
411 if (get_user(swlen, kxfer.swlen) < 0)
414 c = i2o_find_iop(kxfer.iop);
418 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
419 if (m == I2O_QUEUE_EMPTY)
422 writel(SEVEN_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
423 writel(I2O_CMD_SW_REMOVE << 24 | HOST_TID << 12 | ADAPTER_TID,
425 writel(i2o_config_driver.context, &msg->u.head[2]);
426 writel(0, &msg->u.head[3]);
427 writel((u32) kxfer.flags << 24 | (u32) kxfer.sw_type << 16,
429 writel(swlen, &msg->body[1]);
430 writel(kxfer.sw_id, &msg->body[2]);
432 token = i2o_msg_post_wait(c, m, 10);
434 if (token != I2O_POST_WAIT_OK) {
436 "i2o_config: swdel failed, DetailedStatus = %d\n",
444 static int i2o_cfg_validate(unsigned long arg)
448 struct i2o_message __iomem *msg;
450 struct i2o_controller *c;
452 c = i2o_find_iop(iop);
456 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
457 if (m == I2O_QUEUE_EMPTY)
460 writel(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
461 writel(I2O_CMD_CONFIG_VALIDATE << 24 | HOST_TID << 12 | iop,
463 writel(i2o_config_driver.context, &msg->u.head[2]);
464 writel(0, &msg->u.head[3]);
466 token = i2o_msg_post_wait(c, m, 10);
468 if (token != I2O_POST_WAIT_OK) {
469 printk(KERN_INFO "Can't validate configuration, ErrorStatus = "
477 static int i2o_cfg_evt_reg(unsigned long arg, struct file *fp)
479 struct i2o_message __iomem *msg;
481 struct i2o_evt_id __user *pdesc = (struct i2o_evt_id __user *)arg;
482 struct i2o_evt_id kdesc;
483 struct i2o_controller *c;
484 struct i2o_device *d;
486 if (copy_from_user(&kdesc, pdesc, sizeof(struct i2o_evt_id)))
490 c = i2o_find_iop(kdesc.iop);
495 d = i2o_iop_find_device(c, kdesc.tid);
499 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
500 if (m == I2O_QUEUE_EMPTY)
503 writel(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
504 writel(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 | kdesc.tid,
506 writel(i2o_config_driver.context, &msg->u.head[2]);
507 writel(i2o_cntxt_list_add(c, fp->private_data), &msg->u.head[3]);
508 writel(kdesc.evt_mask, &msg->body[0]);
515 static int i2o_cfg_evt_get(unsigned long arg, struct file *fp)
517 struct i2o_cfg_info *p = NULL;
518 struct i2o_evt_get __user *uget = (struct i2o_evt_get __user *)arg;
519 struct i2o_evt_get kget;
522 for (p = open_files; p; p = p->next)
523 if (p->q_id == (ulong) fp->private_data)
529 memcpy(&kget.info, &p->event_q[p->q_out], sizeof(struct i2o_evt_info));
530 MODINC(p->q_out, I2O_EVT_Q_LEN);
531 spin_lock_irqsave(&i2o_config_lock, flags);
533 kget.pending = p->q_len;
534 kget.lost = p->q_lost;
535 spin_unlock_irqrestore(&i2o_config_lock, flags);
537 if (copy_to_user(uget, &kget, sizeof(struct i2o_evt_get)))
543 static int i2o_cfg_passthru32(unsigned fd, unsigned cmnd, unsigned long arg,
546 struct i2o_cmd_passthru32 __user *cmd;
547 struct i2o_controller *c;
548 u32 __user *user_msg;
550 u32 __user *user_reply = NULL;
554 struct i2o_dma sg_list[SG_TABLESIZE];
558 i2o_status_block *sb;
559 struct i2o_message *msg;
563 cmd = (struct i2o_cmd_passthru32 __user *)arg;
565 if (get_user(iop, &cmd->iop) || get_user(i, &cmd->msg))
568 user_msg = compat_ptr(i);
570 c = i2o_find_iop(iop);
572 pr_debug("controller %d not found\n", iop);
576 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
578 sb = c->status_block.virt;
580 if (get_user(size, &user_msg[0])) {
581 printk(KERN_WARNING "unable to get size!\n");
586 if (size > sb->inbound_frame_size) {
587 pr_debug("size of message > inbound_frame_size");
591 user_reply = &user_msg[size];
593 size <<= 2; // Convert to bytes
595 /* Copy in the user's I2O command */
596 if (copy_from_user(msg, user_msg, size)) {
597 printk(KERN_WARNING "unable to copy user message\n");
600 i2o_dump_message(msg);
602 if (get_user(reply_size, &user_reply[0]) < 0)
608 reply = kmalloc(reply_size, GFP_KERNEL);
610 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
614 memset(reply, 0, reply_size);
616 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
618 writel(i2o_config_driver.context, &msg->u.s.icntxt);
619 writel(i2o_cntxt_list_add(c, reply), &msg->u.s.tcntxt);
621 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
623 struct sg_simple_element *sg;
625 if (sg_offset * 4 >= size) {
630 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
633 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
634 if (sg_count > SG_TABLESIZE) {
635 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
641 for (i = 0; i < sg_count; i++) {
645 if (!(sg[i].flag_count & 0x10000000
646 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
648 "%s:Bad SG element %d - not simple (%x)\n",
649 c->name, i, sg[i].flag_count);
653 sg_size = sg[i].flag_count & 0xffffff;
655 /* Allocate memory for the transfer */
657 (&c->pdev->dev, p, sg_size,
658 PCI_DMA_BIDIRECTIONAL)) {
660 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
661 c->name, sg_size, i, sg_count);
665 /* Copy in the user's SG buffer if necessary */
667 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
670 (p->virt, (void __user *)(unsigned long)sg[i].addr_bus,
673 "%s: Could not copy SG buf %d FROM user\n",
680 sg[i].addr_bus = (u32) p->phys;
684 rcode = i2o_msg_post_wait(c, m, 60);
690 /* Copy back the Scatter Gather buffers back to user space */
693 struct sg_simple_element *sg;
695 printk(KERN_INFO "sg_offset\n");
697 // re-acquire the original message to handle correctly the sg copy operation
698 memset(&msg, 0, MSG_FRAME_SIZE * 4);
699 // get user msg size in u32s
700 if (get_user(size, &user_msg[0])) {
706 /* Copy in the user's I2O command */
707 if (copy_from_user(msg, user_msg, size)) {
712 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
715 sg = (struct sg_simple_element *)(msg + sg_offset);
716 for (j = 0; j < sg_count; j++) {
717 /* Copy out the SG list to user's buffer if necessary */
720 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
721 sg_size = sg[j].flag_count & 0xffffff;
724 ((void __user *)(u64) sg[j].addr_bus,
725 sg_list[j].virt, sg_size)) {
727 "%s: Could not copy %p TO user %x\n",
728 c->name, sg_list[j].virt,
737 /* Copy back the reply to user space */
739 // we wrote our own values for context - now restore the user supplied ones
740 printk(KERN_INFO "reply_size\n");
741 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
743 "%s: Could not copy message context FROM user\n",
747 if (copy_to_user(user_reply, reply, reply_size)) {
749 "%s: Could not copy reply TO user\n", c->name);
756 printk(KERN_INFO "rcode: %d\n", rcode);
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 pr_debug("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 pr_debug("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);
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);
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",
890 sg[i].addr_bus = virt_to_bus(p);
894 rcode = i2o_msg_post_wait(c, m, 60);
900 /* Copy back the Scatter Gather buffers back to user space */
903 struct sg_simple_element *sg;
905 printk(KERN_INFO "sg_offset\n");
907 // re-acquire the original message to handle correctly the sg copy operation
908 memset(&msg, 0, MSG_FRAME_SIZE * 4);
909 // get user msg size in u32s
910 if (get_user(size, &user_msg[0])) {
916 /* Copy in the user's I2O command */
917 if (copy_from_user(msg, user_msg, size)) {
922 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
925 sg = (struct sg_simple_element *)(msg + sg_offset);
926 for (j = 0; j < sg_count; j++) {
927 /* Copy out the SG list to user's buffer if necessary */
930 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
931 sg_size = sg[j].flag_count & 0xffffff;
934 ((void __user *)sg[j].addr_bus, sg_list[j],
937 "%s: Could not copy %p TO user %x\n",
947 /* Copy back the reply to user space */
949 // we wrote our own values for context - now restore the user supplied ones
950 printk(KERN_INFO "reply_size\n");
951 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
953 "%s: Could not copy message context FROM user\n",
957 if (copy_to_user(user_reply, reply, reply_size)) {
959 "%s: Could not copy reply TO user\n", c->name);
973 static int i2o_cfg_ioctl(struct inode *inode, struct file *fp, unsigned int cmd,
980 ret = i2o_cfg_getiops(arg);
984 ret = i2o_cfg_gethrt(arg);
988 ret = i2o_cfg_getlct(arg);
992 ret = i2o_cfg_parms(arg, I2OPARMSET);
996 ret = i2o_cfg_parms(arg, I2OPARMGET);
1000 ret = i2o_cfg_swdl(arg);
1004 ret = i2o_cfg_swul(arg);
1008 ret = i2o_cfg_swdel(arg);
1012 ret = i2o_cfg_validate(arg);
1016 ret = i2o_cfg_evt_reg(arg, fp);
1020 ret = i2o_cfg_evt_get(arg, fp);
1023 #ifndef CONFIG_COMPAT
1025 ret = i2o_cfg_passthru(arg);
1030 pr_debug("i2o_config: unknown ioctl called!\n");
1037 static int cfg_open(struct inode *inode, struct file *file)
1039 struct i2o_cfg_info *tmp =
1040 (struct i2o_cfg_info *)kmalloc(sizeof(struct i2o_cfg_info),
1042 unsigned long flags;
1047 file->private_data = (void *)(i2o_cfg_info_id++);
1050 tmp->q_id = (ulong) file->private_data;
1055 tmp->next = open_files;
1057 spin_lock_irqsave(&i2o_config_lock, flags);
1059 spin_unlock_irqrestore(&i2o_config_lock, flags);
1064 static int cfg_fasync(int fd, struct file *fp, int on)
1066 ulong id = (ulong) fp->private_data;
1067 struct i2o_cfg_info *p;
1069 for (p = open_files; p; p = p->next)
1076 return fasync_helper(fd, fp, on, &p->fasync);
1079 static int cfg_release(struct inode *inode, struct file *file)
1081 ulong id = (ulong) file->private_data;
1082 struct i2o_cfg_info *p1, *p2;
1083 unsigned long flags;
1088 spin_lock_irqsave(&i2o_config_lock, flags);
1089 for (p1 = open_files; p1;) {
1090 if (p1->q_id == id) {
1093 cfg_fasync(-1, file, 0);
1095 p2->next = p1->next;
1097 open_files = p1->next;
1105 spin_unlock_irqrestore(&i2o_config_lock, flags);
1111 static struct file_operations config_fops = {
1112 .owner = THIS_MODULE,
1113 .llseek = no_llseek,
1114 .ioctl = i2o_cfg_ioctl,
1116 .release = cfg_release,
1117 .fasync = cfg_fasync,
1120 static struct miscdevice i2o_miscdev = {
1126 static int __init i2o_config_init(void)
1128 printk(KERN_INFO "I2O configuration manager v 0.04.\n");
1129 printk(KERN_INFO " (C) Copyright 1999 Red Hat Software\n");
1131 spin_lock_init(&i2o_config_lock);
1133 if (misc_register(&i2o_miscdev) < 0) {
1134 printk(KERN_ERR "i2o_config: can't register device.\n");
1138 * Install our handler
1140 if (i2o_driver_register(&i2o_config_driver)) {
1141 printk(KERN_ERR "i2o_config: handler register failed.\n");
1142 misc_deregister(&i2o_miscdev);
1145 #ifdef CONFIG_COMPAT
1146 register_ioctl32_conversion(I2OPASSTHRU32, i2o_cfg_passthru32);
1147 register_ioctl32_conversion(I2OGETIOPS, (void *)sys_ioctl);
1152 static void i2o_config_exit(void)
1154 #ifdef CONFIG_COMPAT
1155 unregister_ioctl32_conversion(I2OPASSTHRU32);
1156 unregister_ioctl32_conversion(I2OGETIOPS);
1158 misc_deregister(&i2o_miscdev);
1159 i2o_driver_unregister(&i2o_config_driver);
1162 MODULE_AUTHOR("Red Hat Software");
1163 MODULE_DESCRIPTION("I2O Configuration");
1164 MODULE_LICENSE("GPL");
1166 module_init(i2o_config_init);
1167 module_exit(i2o_config_exit);