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
= memdup_user(kcmd
.opbuf
, kcmd
.oplen
);
194 * It's possible to have a _very_ large table
195 * and that the user asks for all of it at once...
197 res
= kmalloc(65536, GFP_KERNEL
);
203 len
= i2o_parm_issue(dev
, i2o_cmd
, ops
, kcmd
.oplen
, res
, 65536);
211 put_user(len
, kcmd
.reslen
);
214 else if (copy_to_user(kcmd
.resbuf
, res
, len
))
222 static int i2o_cfg_swdl(unsigned long arg
)
224 struct i2o_sw_xfer kxfer
;
225 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
226 unsigned char maxfrag
= 0, curfrag
= 1;
227 struct i2o_dma buffer
;
228 struct i2o_message
*msg
;
229 unsigned int status
= 0, swlen
= 0, fragsize
= 8192;
230 struct i2o_controller
*c
;
232 if (copy_from_user(&kxfer
, pxfer
, sizeof(struct i2o_sw_xfer
)))
235 if (get_user(swlen
, kxfer
.swlen
) < 0)
238 if (get_user(maxfrag
, kxfer
.maxfrag
) < 0)
241 if (get_user(curfrag
, kxfer
.curfrag
) < 0)
244 if (curfrag
== maxfrag
)
245 fragsize
= swlen
- (maxfrag
- 1) * 8192;
247 if (!kxfer
.buf
|| !access_ok(VERIFY_READ
, kxfer
.buf
, fragsize
))
250 c
= i2o_find_iop(kxfer
.iop
);
254 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
258 if (i2o_dma_alloc(&c
->pdev
->dev
, &buffer
, fragsize
)) {
263 if (__copy_from_user(buffer
.virt
, kxfer
.buf
, fragsize
)) {
265 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
269 msg
->u
.head
[0] = cpu_to_le32(NINE_WORD_MSG_SIZE
| SGL_OFFSET_7
);
271 cpu_to_le32(I2O_CMD_SW_DOWNLOAD
<< 24 | HOST_TID
<< 12 |
273 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
274 msg
->u
.head
[3] = cpu_to_le32(0);
276 cpu_to_le32((((u32
) kxfer
.flags
) << 24) | (((u32
) kxfer
.
278 (((u32
) maxfrag
) << 8) | (((u32
) curfrag
)));
279 msg
->body
[1] = cpu_to_le32(swlen
);
280 msg
->body
[2] = cpu_to_le32(kxfer
.sw_id
);
281 msg
->body
[3] = cpu_to_le32(0xD0000000 | fragsize
);
282 msg
->body
[4] = cpu_to_le32(buffer
.phys
);
284 osm_debug("swdl frag %d/%d (size %d)\n", curfrag
, maxfrag
, fragsize
);
285 status
= i2o_msg_post_wait_mem(c
, msg
, 60, &buffer
);
287 if (status
!= -ETIMEDOUT
)
288 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
290 if (status
!= I2O_POST_WAIT_OK
) {
291 // it fails if you try and send frags out of order
292 // and for some yet unknown reasons too
293 osm_info("swdl failed, DetailedStatus = %d\n", status
);
300 static int i2o_cfg_swul(unsigned long arg
)
302 struct i2o_sw_xfer kxfer
;
303 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
304 unsigned char maxfrag
= 0, curfrag
= 1;
305 struct i2o_dma buffer
;
306 struct i2o_message
*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 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
337 if (i2o_dma_alloc(&c
->pdev
->dev
, &buffer
, fragsize
)) {
342 msg
->u
.head
[0] = cpu_to_le32(NINE_WORD_MSG_SIZE
| SGL_OFFSET_7
);
344 cpu_to_le32(I2O_CMD_SW_UPLOAD
<< 24 | HOST_TID
<< 12 | ADAPTER_TID
);
345 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
346 msg
->u
.head
[3] = cpu_to_le32(0);
348 cpu_to_le32((u32
) kxfer
.flags
<< 24 | (u32
) kxfer
.
349 sw_type
<< 16 | (u32
) maxfrag
<< 8 | (u32
) curfrag
);
350 msg
->body
[1] = cpu_to_le32(swlen
);
351 msg
->body
[2] = cpu_to_le32(kxfer
.sw_id
);
352 msg
->body
[3] = cpu_to_le32(0xD0000000 | fragsize
);
353 msg
->body
[4] = cpu_to_le32(buffer
.phys
);
355 osm_debug("swul frag %d/%d (size %d)\n", curfrag
, maxfrag
, fragsize
);
356 status
= i2o_msg_post_wait_mem(c
, msg
, 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
);
374 static int i2o_cfg_swdel(unsigned long arg
)
376 struct i2o_controller
*c
;
377 struct i2o_sw_xfer kxfer
;
378 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
379 struct i2o_message
*msg
;
383 if (copy_from_user(&kxfer
, pxfer
, sizeof(struct i2o_sw_xfer
)))
386 if (get_user(swlen
, kxfer
.swlen
) < 0)
389 c
= i2o_find_iop(kxfer
.iop
);
393 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
397 msg
->u
.head
[0] = cpu_to_le32(SEVEN_WORD_MSG_SIZE
| SGL_OFFSET_0
);
399 cpu_to_le32(I2O_CMD_SW_REMOVE
<< 24 | HOST_TID
<< 12 | ADAPTER_TID
);
400 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
401 msg
->u
.head
[3] = cpu_to_le32(0);
403 cpu_to_le32((u32
) kxfer
.flags
<< 24 | (u32
) kxfer
.sw_type
<< 16);
404 msg
->body
[1] = cpu_to_le32(swlen
);
405 msg
->body
[2] = cpu_to_le32(kxfer
.sw_id
);
407 token
= i2o_msg_post_wait(c
, msg
, 10);
409 if (token
!= I2O_POST_WAIT_OK
) {
410 osm_info("swdel failed, DetailedStatus = %d\n", token
);
417 static int i2o_cfg_validate(unsigned long arg
)
421 struct i2o_message
*msg
;
422 struct i2o_controller
*c
;
424 c
= i2o_find_iop(iop
);
428 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
432 msg
->u
.head
[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE
| SGL_OFFSET_0
);
434 cpu_to_le32(I2O_CMD_CONFIG_VALIDATE
<< 24 | HOST_TID
<< 12 | iop
);
435 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
436 msg
->u
.head
[3] = cpu_to_le32(0);
438 token
= i2o_msg_post_wait(c
, msg
, 10);
440 if (token
!= I2O_POST_WAIT_OK
) {
441 osm_info("Can't validate configuration, ErrorStatus = %d\n",
449 static int i2o_cfg_evt_reg(unsigned long arg
, struct file
*fp
)
451 struct i2o_message
*msg
;
452 struct i2o_evt_id __user
*pdesc
= (struct i2o_evt_id __user
*)arg
;
453 struct i2o_evt_id kdesc
;
454 struct i2o_controller
*c
;
455 struct i2o_device
*d
;
457 if (copy_from_user(&kdesc
, pdesc
, sizeof(struct i2o_evt_id
)))
461 c
= i2o_find_iop(kdesc
.iop
);
466 d
= i2o_iop_find_device(c
, kdesc
.tid
);
470 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
474 msg
->u
.head
[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE
| SGL_OFFSET_0
);
476 cpu_to_le32(I2O_CMD_UTIL_EVT_REGISTER
<< 24 | HOST_TID
<< 12 |
478 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
479 msg
->u
.head
[3] = cpu_to_le32(i2o_cntxt_list_add(c
, fp
->private_data
));
480 msg
->body
[0] = cpu_to_le32(kdesc
.evt_mask
);
482 i2o_msg_post(c
, msg
);
487 static int i2o_cfg_evt_get(unsigned long arg
, struct file
*fp
)
489 struct i2o_cfg_info
*p
= NULL
;
490 struct i2o_evt_get __user
*uget
= (struct i2o_evt_get __user
*)arg
;
491 struct i2o_evt_get kget
;
494 for (p
= open_files
; p
; p
= p
->next
)
495 if (p
->q_id
== (ulong
) fp
->private_data
)
501 memcpy(&kget
.info
, &p
->event_q
[p
->q_out
], sizeof(struct i2o_evt_info
));
502 MODINC(p
->q_out
, I2O_EVT_Q_LEN
);
503 spin_lock_irqsave(&i2o_config_lock
, flags
);
505 kget
.pending
= p
->q_len
;
506 kget
.lost
= p
->q_lost
;
507 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
509 if (copy_to_user(uget
, &kget
, sizeof(struct i2o_evt_get
)))
515 static int i2o_cfg_passthru32(struct file
*file
, unsigned cmnd
,
518 struct i2o_cmd_passthru32 __user
*cmd
;
519 struct i2o_controller
*c
;
520 u32 __user
*user_msg
;
522 u32 __user
*user_reply
= NULL
;
526 struct i2o_dma sg_list
[SG_TABLESIZE
];
531 i2o_status_block
*sb
;
532 struct i2o_message
*msg
;
535 cmd
= (struct i2o_cmd_passthru32 __user
*)arg
;
537 if (get_user(iop
, &cmd
->iop
) || get_user(i
, &cmd
->msg
))
540 user_msg
= compat_ptr(i
);
542 c
= i2o_find_iop(iop
);
544 osm_debug("controller %d not found\n", iop
);
548 sb
= c
->status_block
.virt
;
550 if (get_user(size
, &user_msg
[0])) {
551 osm_warn("unable to get size!\n");
556 if (size
> sb
->inbound_frame_size
) {
557 osm_warn("size of message > inbound_frame_size");
561 user_reply
= &user_msg
[size
];
563 size
<<= 2; // Convert to bytes
565 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
570 /* Copy in the user's I2O command */
571 if (copy_from_user(msg
, user_msg
, size
)) {
572 osm_warn("unable to copy user message\n");
575 i2o_dump_message(msg
);
577 if (get_user(reply_size
, &user_reply
[0]) < 0)
584 reply
= kzalloc(reply_size
, GFP_KERNEL
);
586 printk(KERN_WARNING
"%s: Could not allocate reply buffer\n",
591 sg_offset
= (msg
->u
.head
[0] >> 4) & 0x0f;
593 memset(sg_list
, 0, sizeof(sg_list
[0]) * SG_TABLESIZE
);
595 struct sg_simple_element
*sg
;
597 if (sg_offset
* 4 >= size
) {
602 sg
= (struct sg_simple_element
*)((&msg
->u
.head
[0]) +
605 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
606 if (sg_count
> SG_TABLESIZE
) {
607 printk(KERN_DEBUG
"%s:IOCTL SG List too large (%u)\n",
613 for (i
= 0; i
< sg_count
; i
++) {
617 if (!(sg
[i
].flag_count
& 0x10000000
618 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
620 "%s:Bad SG element %d - not simple (%x)\n",
621 c
->name
, i
, sg
[i
].flag_count
);
625 sg_size
= sg
[i
].flag_count
& 0xffffff;
626 p
= &(sg_list
[sg_index
]);
627 /* Allocate memory for the transfer */
628 if (i2o_dma_alloc(&c
->pdev
->dev
, p
, sg_size
)) {
630 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
631 c
->name
, sg_size
, i
, sg_count
);
633 goto sg_list_cleanup
;
636 /* Copy in the user's SG buffer if necessary */
638 flag_count
& 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
642 (void __user
*)(unsigned long)sg
[i
].
643 addr_bus
, sg_size
)) {
645 "%s: Could not copy SG buf %d FROM user\n",
648 goto sg_list_cleanup
;
652 sg
[i
].addr_bus
= (u32
) p
->phys
;
656 rcode
= i2o_msg_post_wait(c
, msg
, 60);
659 reply
[4] = ((u32
) rcode
) << 24;
660 goto sg_list_cleanup
;
664 u32 rmsg
[I2O_OUTBOUND_MSG_FRAME_SIZE
];
665 /* Copy back the Scatter Gather buffers back to user space */
668 struct sg_simple_element
*sg
;
671 // re-acquire the original message to handle correctly the sg copy operation
672 memset(&rmsg
, 0, I2O_OUTBOUND_MSG_FRAME_SIZE
* 4);
673 // get user msg size in u32s
674 if (get_user(size
, &user_msg
[0])) {
676 goto sg_list_cleanup
;
680 /* Copy in the user's I2O command */
681 if (copy_from_user(rmsg
, user_msg
, size
)) {
683 goto sg_list_cleanup
;
686 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
689 sg
= (struct sg_simple_element
*)(rmsg
+ sg_offset
);
690 for (j
= 0; j
< sg_count
; j
++) {
691 /* Copy out the SG list to user's buffer if necessary */
694 flag_count
& 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
695 sg_size
= sg
[j
].flag_count
& 0xffffff;
698 ((void __user
*)(u64
) sg
[j
].addr_bus
,
699 sg_list
[j
].virt
, sg_size
)) {
701 "%s: Could not copy %p TO user %x\n",
702 c
->name
, sg_list
[j
].virt
,
705 goto sg_list_cleanup
;
712 /* Copy back the reply to user space */
714 // we wrote our own values for context - now restore the user supplied ones
715 if (copy_from_user(reply
+ 2, user_msg
+ 2, sizeof(u32
) * 2)) {
717 "%s: Could not copy message context FROM user\n",
721 if (copy_to_user(user_reply
, reply
, reply_size
)) {
723 "%s: Could not copy reply TO user\n", c
->name
);
727 for (i
= 0; i
< sg_index
; i
++)
728 i2o_dma_free(&c
->pdev
->dev
, &sg_list
[i
]);
738 static long i2o_cfg_compat_ioctl(struct file
*file
, unsigned cmd
,
745 ret
= i2o_cfg_ioctl(file
, cmd
, arg
);
748 ret
= i2o_cfg_passthru32(file
, cmd
, arg
);
760 #ifdef CONFIG_I2O_EXT_ADAPTEC
761 static int i2o_cfg_passthru(unsigned long arg
)
763 struct i2o_cmd_passthru __user
*cmd
=
764 (struct i2o_cmd_passthru __user
*)arg
;
765 struct i2o_controller
*c
;
766 u32 __user
*user_msg
;
768 u32 __user
*user_reply
= NULL
;
772 struct i2o_dma sg_list
[SG_TABLESIZE
];
777 i2o_status_block
*sb
;
778 struct i2o_message
*msg
;
781 if (get_user(iop
, &cmd
->iop
) || get_user(user_msg
, &cmd
->msg
))
784 c
= i2o_find_iop(iop
);
786 osm_warn("controller %d not found\n", iop
);
790 sb
= c
->status_block
.virt
;
792 if (get_user(size
, &user_msg
[0]))
796 if (size
> sb
->inbound_frame_size
) {
797 osm_warn("size of message > inbound_frame_size");
801 user_reply
= &user_msg
[size
];
803 size
<<= 2; // Convert to bytes
805 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
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
= kzalloc(reply_size
, GFP_KERNEL
);
822 printk(KERN_WARNING
"%s: Could not allocate reply buffer\n",
828 sg_offset
= (msg
->u
.head
[0] >> 4) & 0x0f;
830 memset(sg_list
, 0, sizeof(sg_list
[0]) * SG_TABLESIZE
);
832 struct sg_simple_element
*sg
;
835 if (sg_offset
* 4 >= size
) {
840 sg
= (struct sg_simple_element
*)((&msg
->u
.head
[0]) +
843 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
844 if (sg_count
> SG_TABLESIZE
) {
845 printk(KERN_DEBUG
"%s:IOCTL SG List too large (%u)\n",
851 for (i
= 0; i
< sg_count
; i
++) {
854 if (!(sg
[i
].flag_count
& 0x10000000
855 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
857 "%s:Bad SG element %d - not simple (%x)\n",
858 c
->name
, i
, sg
[i
].flag_count
);
860 goto sg_list_cleanup
;
862 sg_size
= sg
[i
].flag_count
& 0xffffff;
863 p
= &(sg_list
[sg_index
]);
864 if (i2o_dma_alloc(&c
->pdev
->dev
, p
, sg_size
)) {
865 /* Allocate memory for the transfer */
867 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
868 c
->name
, sg_size
, i
, sg_count
);
870 goto sg_list_cleanup
;
873 /* Copy in the user's SG buffer if necessary */
875 flag_count
& 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
878 (p
->virt
, (void __user
*)sg
[i
].addr_bus
,
881 "%s: Could not copy SG buf %d FROM user\n",
884 goto sg_list_cleanup
;
887 sg
[i
].addr_bus
= p
->phys
;
891 rcode
= i2o_msg_post_wait(c
, msg
, 60);
894 reply
[4] = ((u32
) rcode
) << 24;
895 goto sg_list_cleanup
;
899 u32 rmsg
[I2O_OUTBOUND_MSG_FRAME_SIZE
];
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(&rmsg
, 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(rmsg
, user_msg
, size
)) {
918 goto sg_list_cleanup
;
921 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
924 sg
= (struct sg_simple_element
*)(rmsg
+ 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
].virt
,
936 "%s: Could not copy %p TO user %x\n",
937 c
->name
, sg_list
[j
].virt
,
940 goto sg_list_cleanup
;
947 /* Copy back the reply to user space */
949 // we wrote our own values for context - now restore the user supplied ones
950 if (copy_from_user(reply
+ 2, user_msg
+ 2, sizeof(u32
) * 2)) {
952 "%s: Could not copy message context FROM user\n",
956 if (copy_to_user(user_reply
, reply
, reply_size
)) {
958 "%s: Could not copy reply TO user\n", c
->name
);
963 for (i
= 0; i
< sg_index
; i
++)
964 i2o_dma_free(&c
->pdev
->dev
, &sg_list
[i
]);
978 static long i2o_cfg_ioctl(struct file
*fp
, unsigned int cmd
, unsigned long arg
)
985 ret
= i2o_cfg_getiops(arg
);
989 ret
= i2o_cfg_gethrt(arg
);
993 ret
= i2o_cfg_getlct(arg
);
997 ret
= i2o_cfg_parms(arg
, I2OPARMSET
);
1001 ret
= i2o_cfg_parms(arg
, I2OPARMGET
);
1005 ret
= i2o_cfg_swdl(arg
);
1009 ret
= i2o_cfg_swul(arg
);
1013 ret
= i2o_cfg_swdel(arg
);
1017 ret
= i2o_cfg_validate(arg
);
1021 ret
= i2o_cfg_evt_reg(arg
, fp
);
1025 ret
= i2o_cfg_evt_get(arg
, fp
);
1028 #ifdef CONFIG_I2O_EXT_ADAPTEC
1030 ret
= i2o_cfg_passthru(arg
);
1035 osm_debug("unknown ioctl called!\n");
1042 static int cfg_open(struct inode
*inode
, struct file
*file
)
1044 struct i2o_cfg_info
*tmp
=
1045 (struct i2o_cfg_info
*)kmalloc(sizeof(struct i2o_cfg_info
),
1047 unsigned long flags
;
1053 file
->private_data
= (void *)(i2o_cfg_info_id
++);
1056 tmp
->q_id
= (ulong
) file
->private_data
;
1061 tmp
->next
= open_files
;
1063 spin_lock_irqsave(&i2o_config_lock
, flags
);
1065 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
1071 static int cfg_fasync(int fd
, struct file
*fp
, int on
)
1073 ulong id
= (ulong
) fp
->private_data
;
1074 struct i2o_cfg_info
*p
;
1078 for (p
= open_files
; p
; p
= p
->next
)
1083 ret
= fasync_helper(fd
, fp
, on
, &p
->fasync
);
1088 static int cfg_release(struct inode
*inode
, struct file
*file
)
1090 ulong id
= (ulong
) file
->private_data
;
1091 struct i2o_cfg_info
*p
, **q
;
1092 unsigned long flags
;
1095 spin_lock_irqsave(&i2o_config_lock
, flags
);
1096 for (q
= &open_files
; (p
= *q
) != NULL
; q
= &p
->next
) {
1097 if (p
->q_id
== id
) {
1103 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
1109 static const struct file_operations config_fops
= {
1110 .owner
= THIS_MODULE
,
1111 .llseek
= no_llseek
,
1112 .unlocked_ioctl
= i2o_cfg_ioctl
,
1113 #ifdef CONFIG_COMPAT
1114 .compat_ioctl
= i2o_cfg_compat_ioctl
,
1117 .release
= cfg_release
,
1118 .fasync
= cfg_fasync
,
1121 static struct miscdevice i2o_miscdev
= {
1127 static int __init
i2o_config_old_init(void)
1129 spin_lock_init(&i2o_config_lock
);
1131 if (misc_register(&i2o_miscdev
) < 0) {
1132 osm_err("can't register device.\n");
1139 static void i2o_config_old_exit(void)
1141 misc_deregister(&i2o_miscdev
);
1144 MODULE_AUTHOR("Red Hat Software");