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/mutex.h>
35 #include <linux/compat.h>
36 #include <linux/slab.h>
37 #include <linux/uaccess.h>
41 #define SG_TABLESIZE 30
43 static DEFINE_MUTEX(i2o_cfg_mutex);
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;
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 if (put_user(len, kcmd.reslen))
116 else if (len > reslen)
118 else 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 if (put_user(len, kcmd.reslen))
152 else if (len > reslen)
154 else if (copy_to_user(kcmd.resbuf, lct, len))
160 static int i2o_cfg_parms(unsigned long arg, unsigned int type)
163 struct i2o_controller *c;
164 struct i2o_device *dev;
165 struct i2o_cmd_psetget __user *cmd =
166 (struct i2o_cmd_psetget __user *)arg;
167 struct i2o_cmd_psetget kcmd;
173 u32 i2o_cmd = (type == I2OPARMGET ?
174 I2O_CMD_UTIL_PARAMS_GET : I2O_CMD_UTIL_PARAMS_SET);
176 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_psetget)))
179 if (get_user(reslen, kcmd.reslen))
182 c = i2o_find_iop(kcmd.iop);
186 dev = i2o_iop_find_device(c, kcmd.tid);
191 * Stop users being able to try and allocate arbitrary amounts
192 * of DMA space. 64K is way more than sufficient for this.
194 if (kcmd.oplen > 65536)
197 ops = memdup_user(kcmd.opbuf, kcmd.oplen);
202 * It's possible to have a _very_ large table
203 * and that the user asks for all of it at once...
205 res = kmalloc(65536, GFP_KERNEL);
211 len = i2o_parm_issue(dev, i2o_cmd, ops, kcmd.oplen, res, 65536);
219 if (put_user(len, kcmd.reslen))
221 else if (len > reslen)
223 else if (copy_to_user(kcmd.resbuf, res, len))
231 static int i2o_cfg_swdl(unsigned long arg)
233 struct i2o_sw_xfer kxfer;
234 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
235 unsigned char maxfrag = 0, curfrag = 1;
236 struct i2o_dma buffer;
237 struct i2o_message *msg;
238 unsigned int status = 0, swlen = 0, fragsize = 8192;
239 struct i2o_controller *c;
241 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
244 if (get_user(swlen, kxfer.swlen) < 0)
247 if (get_user(maxfrag, kxfer.maxfrag) < 0)
250 if (get_user(curfrag, kxfer.curfrag) < 0)
253 if (curfrag == maxfrag)
254 fragsize = swlen - (maxfrag - 1) * 8192;
256 if (!kxfer.buf || !access_ok(VERIFY_READ, kxfer.buf, fragsize))
259 c = i2o_find_iop(kxfer.iop);
263 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
267 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
272 if (__copy_from_user(buffer.virt, kxfer.buf, fragsize)) {
274 i2o_dma_free(&c->pdev->dev, &buffer);
278 msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_7);
280 cpu_to_le32(I2O_CMD_SW_DOWNLOAD << 24 | HOST_TID << 12 |
282 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
283 msg->u.head[3] = cpu_to_le32(0);
285 cpu_to_le32((((u32) kxfer.flags) << 24) | (((u32) kxfer.
287 (((u32) maxfrag) << 8) | (((u32) curfrag)));
288 msg->body[1] = cpu_to_le32(swlen);
289 msg->body[2] = cpu_to_le32(kxfer.sw_id);
290 msg->body[3] = cpu_to_le32(0xD0000000 | fragsize);
291 msg->body[4] = cpu_to_le32(buffer.phys);
293 osm_debug("swdl frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
294 status = i2o_msg_post_wait_mem(c, msg, 60, &buffer);
296 if (status != -ETIMEDOUT)
297 i2o_dma_free(&c->pdev->dev, &buffer);
299 if (status != I2O_POST_WAIT_OK) {
300 // it fails if you try and send frags out of order
301 // and for some yet unknown reasons too
302 osm_info("swdl failed, DetailedStatus = %d\n", status);
309 static int i2o_cfg_swul(unsigned long arg)
311 struct i2o_sw_xfer kxfer;
312 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
313 unsigned char maxfrag = 0, curfrag = 1;
314 struct i2o_dma buffer;
315 struct i2o_message *msg;
316 unsigned int status = 0, swlen = 0, fragsize = 8192;
317 struct i2o_controller *c;
320 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
323 if (get_user(swlen, kxfer.swlen) < 0)
326 if (get_user(maxfrag, kxfer.maxfrag) < 0)
329 if (get_user(curfrag, kxfer.curfrag) < 0)
332 if (curfrag == maxfrag)
333 fragsize = swlen - (maxfrag - 1) * 8192;
338 c = i2o_find_iop(kxfer.iop);
342 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
346 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
351 msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_7);
353 cpu_to_le32(I2O_CMD_SW_UPLOAD << 24 | HOST_TID << 12 | ADAPTER_TID);
354 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
355 msg->u.head[3] = cpu_to_le32(0);
357 cpu_to_le32((u32) kxfer.flags << 24 | (u32) kxfer.
358 sw_type << 16 | (u32) maxfrag << 8 | (u32) curfrag);
359 msg->body[1] = cpu_to_le32(swlen);
360 msg->body[2] = cpu_to_le32(kxfer.sw_id);
361 msg->body[3] = cpu_to_le32(0xD0000000 | fragsize);
362 msg->body[4] = cpu_to_le32(buffer.phys);
364 osm_debug("swul frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
365 status = i2o_msg_post_wait_mem(c, msg, 60, &buffer);
367 if (status != I2O_POST_WAIT_OK) {
368 if (status != -ETIMEDOUT)
369 i2o_dma_free(&c->pdev->dev, &buffer);
371 osm_info("swul failed, DetailedStatus = %d\n", status);
375 if (copy_to_user(kxfer.buf, buffer.virt, fragsize))
378 i2o_dma_free(&c->pdev->dev, &buffer);
383 static int i2o_cfg_swdel(unsigned long arg)
385 struct i2o_controller *c;
386 struct i2o_sw_xfer kxfer;
387 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
388 struct i2o_message *msg;
392 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
395 if (get_user(swlen, kxfer.swlen) < 0)
398 c = i2o_find_iop(kxfer.iop);
402 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
406 msg->u.head[0] = cpu_to_le32(SEVEN_WORD_MSG_SIZE | SGL_OFFSET_0);
408 cpu_to_le32(I2O_CMD_SW_REMOVE << 24 | HOST_TID << 12 | ADAPTER_TID);
409 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
410 msg->u.head[3] = cpu_to_le32(0);
412 cpu_to_le32((u32) kxfer.flags << 24 | (u32) kxfer.sw_type << 16);
413 msg->body[1] = cpu_to_le32(swlen);
414 msg->body[2] = cpu_to_le32(kxfer.sw_id);
416 token = i2o_msg_post_wait(c, msg, 10);
418 if (token != I2O_POST_WAIT_OK) {
419 osm_info("swdel failed, DetailedStatus = %d\n", token);
426 static int i2o_cfg_validate(unsigned long arg)
430 struct i2o_message *msg;
431 struct i2o_controller *c;
433 c = i2o_find_iop(iop);
437 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
441 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
443 cpu_to_le32(I2O_CMD_CONFIG_VALIDATE << 24 | HOST_TID << 12 | iop);
444 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
445 msg->u.head[3] = cpu_to_le32(0);
447 token = i2o_msg_post_wait(c, msg, 10);
449 if (token != I2O_POST_WAIT_OK) {
450 osm_info("Can't validate configuration, ErrorStatus = %d\n",
458 static int i2o_cfg_evt_reg(unsigned long arg, struct file *fp)
460 struct i2o_message *msg;
461 struct i2o_evt_id __user *pdesc = (struct i2o_evt_id __user *)arg;
462 struct i2o_evt_id kdesc;
463 struct i2o_controller *c;
464 struct i2o_device *d;
466 if (copy_from_user(&kdesc, pdesc, sizeof(struct i2o_evt_id)))
470 c = i2o_find_iop(kdesc.iop);
475 d = i2o_iop_find_device(c, kdesc.tid);
479 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
483 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
485 cpu_to_le32(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 |
487 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
488 msg->u.head[3] = cpu_to_le32(i2o_cntxt_list_add(c, fp->private_data));
489 msg->body[0] = cpu_to_le32(kdesc.evt_mask);
491 i2o_msg_post(c, msg);
496 static int i2o_cfg_evt_get(unsigned long arg, struct file *fp)
498 struct i2o_cfg_info *p = NULL;
499 struct i2o_evt_get __user *uget = (struct i2o_evt_get __user *)arg;
500 struct i2o_evt_get kget;
503 for (p = open_files; p; p = p->next)
504 if (p->q_id == (ulong) fp->private_data)
510 memcpy(&kget.info, &p->event_q[p->q_out], sizeof(struct i2o_evt_info));
511 MODINC(p->q_out, I2O_EVT_Q_LEN);
512 spin_lock_irqsave(&i2o_config_lock, flags);
514 kget.pending = p->q_len;
515 kget.lost = p->q_lost;
516 spin_unlock_irqrestore(&i2o_config_lock, flags);
518 if (copy_to_user(uget, &kget, sizeof(struct i2o_evt_get)))
524 static int i2o_cfg_passthru32(struct file *file, unsigned cmnd,
527 struct i2o_cmd_passthru32 __user *cmd;
528 struct i2o_controller *c;
529 u32 __user *user_msg;
531 u32 __user *user_reply = NULL;
535 struct i2o_dma sg_list[SG_TABLESIZE];
540 i2o_status_block *sb;
541 struct i2o_message *msg;
544 cmd = (struct i2o_cmd_passthru32 __user *)arg;
546 if (get_user(iop, &cmd->iop) || get_user(i, &cmd->msg))
549 user_msg = compat_ptr(i);
551 c = i2o_find_iop(iop);
553 osm_debug("controller %d not found\n", iop);
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 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
579 /* Copy in the user's I2O command */
580 if (copy_from_user(msg, user_msg, size)) {
581 osm_warn("unable to copy user message\n");
584 i2o_dump_message(msg);
586 if (get_user(reply_size, &user_reply[0]) < 0)
593 reply = kzalloc(reply_size, GFP_KERNEL);
595 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
600 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
602 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
604 struct sg_simple_element *sg;
606 if (sg_offset * 4 >= size) {
611 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
614 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
615 if (sg_count > SG_TABLESIZE) {
616 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
622 for (i = 0; i < sg_count; i++) {
626 if (!(sg[i].flag_count & 0x10000000
627 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
629 "%s:Bad SG element %d - not simple (%x)\n",
630 c->name, i, sg[i].flag_count);
634 sg_size = sg[i].flag_count & 0xffffff;
635 p = &(sg_list[sg_index]);
636 /* Allocate memory for the transfer */
637 if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
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;
645 /* Copy in the user's SG buffer if necessary */
647 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
651 (void __user *)(unsigned long)sg[i].
652 addr_bus, sg_size)) {
654 "%s: Could not copy SG buf %d FROM user\n",
657 goto sg_list_cleanup;
661 sg[i].addr_bus = (u32) p->phys;
665 rcode = i2o_msg_post_wait(c, msg, 60);
668 reply[4] = ((u32) rcode) << 24;
669 goto sg_list_cleanup;
673 u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
674 /* Copy back the Scatter Gather buffers back to user space */
677 struct sg_simple_element *sg;
680 // re-acquire the original message to handle correctly the sg copy operation
681 memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
682 // get user msg size in u32s
683 if (get_user(size, &user_msg[0])) {
685 goto sg_list_cleanup;
689 if (size > sizeof(rmsg)) {
691 goto sg_list_cleanup;
694 /* Copy in the user's I2O command */
695 if (copy_from_user(rmsg, user_msg, size)) {
697 goto sg_list_cleanup;
700 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
703 sg = (struct sg_simple_element *)(rmsg + sg_offset);
704 for (j = 0; j < sg_count; j++) {
705 /* Copy out the SG list to user's buffer if necessary */
708 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
709 sg_size = sg[j].flag_count & 0xffffff;
712 ((void __user *)(u64) sg[j].addr_bus,
713 sg_list[j].virt, sg_size)) {
715 "%s: Could not copy %p TO user %x\n",
716 c->name, sg_list[j].virt,
719 goto sg_list_cleanup;
726 /* Copy back the reply to user space */
728 // we wrote our own values for context - now restore the user supplied ones
729 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
731 "%s: Could not copy message context FROM user\n",
735 if (copy_to_user(user_reply, reply, reply_size)) {
737 "%s: Could not copy reply TO user\n", c->name);
741 for (i = 0; i < sg_index; i++)
742 i2o_dma_free(&c->pdev->dev, &sg_list[i]);
752 static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
758 ret = i2o_cfg_ioctl(file, cmd, arg);
761 mutex_lock(&i2o_cfg_mutex);
762 ret = i2o_cfg_passthru32(file, cmd, arg);
763 mutex_unlock(&i2o_cfg_mutex);
774 #ifdef CONFIG_I2O_EXT_ADAPTEC
775 static int i2o_cfg_passthru(unsigned long arg)
777 struct i2o_cmd_passthru __user *cmd =
778 (struct i2o_cmd_passthru __user *)arg;
779 struct i2o_controller *c;
780 u32 __user *user_msg;
782 u32 __user *user_reply = NULL;
786 struct i2o_dma sg_list[SG_TABLESIZE];
791 i2o_status_block *sb;
792 struct i2o_message *msg;
795 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
798 c = i2o_find_iop(iop);
800 osm_warn("controller %d not found\n", iop);
804 sb = c->status_block.virt;
806 if (get_user(size, &user_msg[0]))
810 if (size > sb->inbound_frame_size) {
811 osm_warn("size of message > inbound_frame_size");
815 user_reply = &user_msg[size];
817 size <<= 2; // Convert to bytes
819 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
824 /* Copy in the user's I2O command */
825 if (copy_from_user(msg, user_msg, size))
828 if (get_user(reply_size, &user_reply[0]) < 0)
834 reply = kzalloc(reply_size, GFP_KERNEL);
836 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
842 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
844 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
846 struct sg_simple_element *sg;
849 if (sg_offset * 4 >= size) {
854 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
857 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
858 if (sg_count > SG_TABLESIZE) {
859 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
865 for (i = 0; i < sg_count; i++) {
868 if (!(sg[i].flag_count & 0x10000000
869 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
871 "%s:Bad SG element %d - not simple (%x)\n",
872 c->name, i, sg[i].flag_count);
874 goto sg_list_cleanup;
876 sg_size = sg[i].flag_count & 0xffffff;
877 p = &(sg_list[sg_index]);
878 if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
879 /* Allocate memory for the transfer */
881 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
882 c->name, sg_size, i, sg_count);
884 goto sg_list_cleanup;
887 /* Copy in the user's SG buffer if necessary */
889 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
892 (p->virt, (void __user *)sg[i].addr_bus,
895 "%s: Could not copy SG buf %d FROM user\n",
898 goto sg_list_cleanup;
901 sg[i].addr_bus = p->phys;
905 rcode = i2o_msg_post_wait(c, msg, 60);
908 reply[4] = ((u32) rcode) << 24;
909 goto sg_list_cleanup;
913 u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
914 /* Copy back the Scatter Gather buffers back to user space */
917 struct sg_simple_element *sg;
920 // re-acquire the original message to handle correctly the sg copy operation
921 memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
922 // get user msg size in u32s
923 if (get_user(size, &user_msg[0])) {
925 goto sg_list_cleanup;
929 if (size > sizeof(rmsg)) {
931 goto sg_list_cleanup;
934 /* Copy in the user's I2O command */
935 if (copy_from_user(rmsg, user_msg, size)) {
937 goto sg_list_cleanup;
940 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
943 sg = (struct sg_simple_element *)(rmsg + sg_offset);
944 for (j = 0; j < sg_count; j++) {
945 /* Copy out the SG list to user's buffer if necessary */
948 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
949 sg_size = sg[j].flag_count & 0xffffff;
952 ((void __user *)sg[j].addr_bus, sg_list[j].virt,
955 "%s: Could not copy %p TO user %x\n",
956 c->name, sg_list[j].virt,
959 goto sg_list_cleanup;
966 /* Copy back the reply to user space */
968 // we wrote our own values for context - now restore the user supplied ones
969 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
971 "%s: Could not copy message context FROM user\n",
975 if (copy_to_user(user_reply, reply, reply_size)) {
977 "%s: Could not copy reply TO user\n", c->name);
982 for (i = 0; i < sg_index; i++)
983 i2o_dma_free(&c->pdev->dev, &sg_list[i]);
997 static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
1001 mutex_lock(&i2o_cfg_mutex);
1004 ret = i2o_cfg_getiops(arg);
1008 ret = i2o_cfg_gethrt(arg);
1012 ret = i2o_cfg_getlct(arg);
1016 ret = i2o_cfg_parms(arg, I2OPARMSET);
1020 ret = i2o_cfg_parms(arg, I2OPARMGET);
1024 ret = i2o_cfg_swdl(arg);
1028 ret = i2o_cfg_swul(arg);
1032 ret = i2o_cfg_swdel(arg);
1036 ret = i2o_cfg_validate(arg);
1040 ret = i2o_cfg_evt_reg(arg, fp);
1044 ret = i2o_cfg_evt_get(arg, fp);
1047 #ifdef CONFIG_I2O_EXT_ADAPTEC
1049 ret = i2o_cfg_passthru(arg);
1054 osm_debug("unknown ioctl called!\n");
1057 mutex_unlock(&i2o_cfg_mutex);
1061 static int cfg_open(struct inode *inode, struct file *file)
1063 struct i2o_cfg_info *tmp = kmalloc(sizeof(struct i2o_cfg_info),
1065 unsigned long flags;
1070 mutex_lock(&i2o_cfg_mutex);
1071 file->private_data = (void *)(i2o_cfg_info_id++);
1074 tmp->q_id = (ulong) file->private_data;
1079 tmp->next = open_files;
1081 spin_lock_irqsave(&i2o_config_lock, flags);
1083 spin_unlock_irqrestore(&i2o_config_lock, flags);
1084 mutex_unlock(&i2o_cfg_mutex);
1089 static int cfg_fasync(int fd, struct file *fp, int on)
1091 ulong id = (ulong) fp->private_data;
1092 struct i2o_cfg_info *p;
1095 mutex_lock(&i2o_cfg_mutex);
1096 for (p = open_files; p; p = p->next)
1101 ret = fasync_helper(fd, fp, on, &p->fasync);
1102 mutex_unlock(&i2o_cfg_mutex);
1106 static int cfg_release(struct inode *inode, struct file *file)
1108 ulong id = (ulong) file->private_data;
1109 struct i2o_cfg_info *p, **q;
1110 unsigned long flags;
1112 mutex_lock(&i2o_cfg_mutex);
1113 spin_lock_irqsave(&i2o_config_lock, flags);
1114 for (q = &open_files; (p = *q) != NULL; q = &p->next) {
1115 if (p->q_id == id) {
1121 spin_unlock_irqrestore(&i2o_config_lock, flags);
1122 mutex_unlock(&i2o_cfg_mutex);
1127 static const struct file_operations config_fops = {
1128 .owner = THIS_MODULE,
1129 .llseek = no_llseek,
1130 .unlocked_ioctl = i2o_cfg_ioctl,
1131 #ifdef CONFIG_COMPAT
1132 .compat_ioctl = i2o_cfg_compat_ioctl,
1135 .release = cfg_release,
1136 .fasync = cfg_fasync,
1139 static struct miscdevice i2o_miscdev = {
1145 static int __init i2o_config_old_init(void)
1147 spin_lock_init(&i2o_config_lock);
1149 if (misc_register(&i2o_miscdev) < 0) {
1150 osm_err("can't register device.\n");
1157 static void i2o_config_old_exit(void)
1159 misc_deregister(&i2o_miscdev);
1162 MODULE_AUTHOR("Red Hat Software");