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>
37 #include <asm/uaccess.h>
41 #define SG_TABLESIZE 30
43 static long i2o_cfg_ioctl(struct file
*, unsigned int, unsigned long);
45 static spinlock_t i2o_config_lock
;
47 #define MODINC(x,y) ((x) = ((x) + 1) % (y))
49 struct sg_simple_element
{
56 struct fasync_struct
*fasync
;
57 struct i2o_evt_info event_q
[I2O_EVT_Q_LEN
];
58 u16 q_in
; // Queue head index
59 u16 q_out
; // Queue tail index
60 u16 q_len
; // Queue length
61 u16 q_lost
; // Number of lost events
62 ulong q_id
; // Event queue ID...used as tx_context
63 struct i2o_cfg_info
*next
;
65 static struct i2o_cfg_info
*open_files
= NULL
;
66 static ulong i2o_cfg_info_id
= 0;
68 static int i2o_cfg_getiops(unsigned long arg
)
70 struct i2o_controller
*c
;
71 u8 __user
*user_iop_table
= (void __user
*)arg
;
72 u8 tmp
[MAX_I2O_CONTROLLERS
];
75 memset(tmp
, 0, MAX_I2O_CONTROLLERS
);
77 list_for_each_entry(c
, &i2o_controllers
, list
)
80 if (copy_to_user(user_iop_table
, tmp
, MAX_I2O_CONTROLLERS
))
86 static int i2o_cfg_gethrt(unsigned long arg
)
88 struct i2o_controller
*c
;
89 struct i2o_cmd_hrtlct __user
*cmd
= (struct i2o_cmd_hrtlct __user
*)arg
;
90 struct i2o_cmd_hrtlct kcmd
;
96 if (copy_from_user(&kcmd
, cmd
, sizeof(struct i2o_cmd_hrtlct
)))
99 if (get_user(reslen
, kcmd
.reslen
) < 0)
102 if (kcmd
.resbuf
== NULL
)
105 c
= i2o_find_iop(kcmd
.iop
);
109 hrt
= (i2o_hrt
*) c
->hrt
.virt
;
111 len
= 8 + ((hrt
->entry_len
* hrt
->num_entries
) << 2);
113 /* We did a get user...so assuming mem is ok...is this bad? */
114 put_user(len
, kcmd
.reslen
);
117 if (copy_to_user(kcmd
.resbuf
, (void *)hrt
, len
))
123 static int i2o_cfg_getlct(unsigned long arg
)
125 struct i2o_controller
*c
;
126 struct i2o_cmd_hrtlct __user
*cmd
= (struct i2o_cmd_hrtlct __user
*)arg
;
127 struct i2o_cmd_hrtlct kcmd
;
133 if (copy_from_user(&kcmd
, cmd
, sizeof(struct i2o_cmd_hrtlct
)))
136 if (get_user(reslen
, kcmd
.reslen
) < 0)
139 if (kcmd
.resbuf
== NULL
)
142 c
= i2o_find_iop(kcmd
.iop
);
146 lct
= (i2o_lct
*) c
->lct
;
148 len
= (unsigned int)lct
->table_size
<< 2;
149 put_user(len
, kcmd
.reslen
);
152 else if (copy_to_user(kcmd
.resbuf
, lct
, len
))
158 static int i2o_cfg_parms(unsigned long arg
, unsigned int type
)
161 struct i2o_controller
*c
;
162 struct i2o_device
*dev
;
163 struct i2o_cmd_psetget __user
*cmd
=
164 (struct i2o_cmd_psetget __user
*)arg
;
165 struct i2o_cmd_psetget kcmd
;
171 u32 i2o_cmd
= (type
== I2OPARMGET
?
172 I2O_CMD_UTIL_PARAMS_GET
: I2O_CMD_UTIL_PARAMS_SET
);
174 if (copy_from_user(&kcmd
, cmd
, sizeof(struct i2o_cmd_psetget
)))
177 if (get_user(reslen
, kcmd
.reslen
))
180 c
= i2o_find_iop(kcmd
.iop
);
184 dev
= i2o_iop_find_device(c
, kcmd
.tid
);
188 ops
= kmalloc(kcmd
.oplen
, GFP_KERNEL
);
192 if (copy_from_user(ops
, kcmd
.opbuf
, kcmd
.oplen
)) {
198 * It's possible to have a _very_ large table
199 * and that the user asks for all of it at once...
201 res
= kmalloc(65536, GFP_KERNEL
);
207 len
= i2o_parm_issue(dev
, i2o_cmd
, ops
, kcmd
.oplen
, res
, 65536);
215 put_user(len
, kcmd
.reslen
);
218 else if (copy_to_user(kcmd
.resbuf
, res
, len
))
226 static int i2o_cfg_swdl(unsigned long arg
)
228 struct i2o_sw_xfer kxfer
;
229 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
230 unsigned char maxfrag
= 0, curfrag
= 1;
231 struct i2o_dma buffer
;
232 struct i2o_message
*msg
;
233 unsigned int status
= 0, swlen
= 0, fragsize
= 8192;
234 struct i2o_controller
*c
;
236 if (copy_from_user(&kxfer
, pxfer
, sizeof(struct i2o_sw_xfer
)))
239 if (get_user(swlen
, kxfer
.swlen
) < 0)
242 if (get_user(maxfrag
, kxfer
.maxfrag
) < 0)
245 if (get_user(curfrag
, kxfer
.curfrag
) < 0)
248 if (curfrag
== maxfrag
)
249 fragsize
= swlen
- (maxfrag
- 1) * 8192;
251 if (!kxfer
.buf
|| !access_ok(VERIFY_READ
, kxfer
.buf
, fragsize
))
254 c
= i2o_find_iop(kxfer
.iop
);
258 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
262 if (i2o_dma_alloc(&c
->pdev
->dev
, &buffer
, fragsize
)) {
267 if (__copy_from_user(buffer
.virt
, kxfer
.buf
, fragsize
)) {
269 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
273 msg
->u
.head
[0] = cpu_to_le32(NINE_WORD_MSG_SIZE
| SGL_OFFSET_7
);
275 cpu_to_le32(I2O_CMD_SW_DOWNLOAD
<< 24 | HOST_TID
<< 12 |
277 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
278 msg
->u
.head
[3] = cpu_to_le32(0);
280 cpu_to_le32((((u32
) kxfer
.flags
) << 24) | (((u32
) kxfer
.
282 (((u32
) maxfrag
) << 8) | (((u32
) curfrag
)));
283 msg
->body
[1] = cpu_to_le32(swlen
);
284 msg
->body
[2] = cpu_to_le32(kxfer
.sw_id
);
285 msg
->body
[3] = cpu_to_le32(0xD0000000 | fragsize
);
286 msg
->body
[4] = cpu_to_le32(buffer
.phys
);
288 osm_debug("swdl frag %d/%d (size %d)\n", curfrag
, maxfrag
, fragsize
);
289 status
= i2o_msg_post_wait_mem(c
, msg
, 60, &buffer
);
291 if (status
!= -ETIMEDOUT
)
292 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
294 if (status
!= I2O_POST_WAIT_OK
) {
295 // it fails if you try and send frags out of order
296 // and for some yet unknown reasons too
297 osm_info("swdl failed, DetailedStatus = %d\n", status
);
304 static int i2o_cfg_swul(unsigned long arg
)
306 struct i2o_sw_xfer kxfer
;
307 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
308 unsigned char maxfrag
= 0, curfrag
= 1;
309 struct i2o_dma buffer
;
310 struct i2o_message
*msg
;
311 unsigned int status
= 0, swlen
= 0, fragsize
= 8192;
312 struct i2o_controller
*c
;
315 if (copy_from_user(&kxfer
, pxfer
, sizeof(struct i2o_sw_xfer
)))
318 if (get_user(swlen
, kxfer
.swlen
) < 0)
321 if (get_user(maxfrag
, kxfer
.maxfrag
) < 0)
324 if (get_user(curfrag
, kxfer
.curfrag
) < 0)
327 if (curfrag
== maxfrag
)
328 fragsize
= swlen
- (maxfrag
- 1) * 8192;
333 c
= i2o_find_iop(kxfer
.iop
);
337 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
341 if (i2o_dma_alloc(&c
->pdev
->dev
, &buffer
, fragsize
)) {
346 msg
->u
.head
[0] = cpu_to_le32(NINE_WORD_MSG_SIZE
| SGL_OFFSET_7
);
348 cpu_to_le32(I2O_CMD_SW_UPLOAD
<< 24 | HOST_TID
<< 12 | ADAPTER_TID
);
349 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
350 msg
->u
.head
[3] = cpu_to_le32(0);
352 cpu_to_le32((u32
) kxfer
.flags
<< 24 | (u32
) kxfer
.
353 sw_type
<< 16 | (u32
) maxfrag
<< 8 | (u32
) curfrag
);
354 msg
->body
[1] = cpu_to_le32(swlen
);
355 msg
->body
[2] = cpu_to_le32(kxfer
.sw_id
);
356 msg
->body
[3] = cpu_to_le32(0xD0000000 | fragsize
);
357 msg
->body
[4] = cpu_to_le32(buffer
.phys
);
359 osm_debug("swul frag %d/%d (size %d)\n", curfrag
, maxfrag
, fragsize
);
360 status
= i2o_msg_post_wait_mem(c
, msg
, 60, &buffer
);
362 if (status
!= I2O_POST_WAIT_OK
) {
363 if (status
!= -ETIMEDOUT
)
364 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
366 osm_info("swul failed, DetailedStatus = %d\n", status
);
370 if (copy_to_user(kxfer
.buf
, buffer
.virt
, fragsize
))
373 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
382 static int i2o_cfg_swdel(unsigned long arg
)
384 struct i2o_controller
*c
;
385 struct i2o_sw_xfer kxfer
;
386 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
387 struct i2o_message
*msg
;
391 if (copy_from_user(&kxfer
, pxfer
, sizeof(struct i2o_sw_xfer
)))
394 if (get_user(swlen
, kxfer
.swlen
) < 0)
397 c
= i2o_find_iop(kxfer
.iop
);
401 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
405 msg
->u
.head
[0] = cpu_to_le32(SEVEN_WORD_MSG_SIZE
| SGL_OFFSET_0
);
407 cpu_to_le32(I2O_CMD_SW_REMOVE
<< 24 | HOST_TID
<< 12 | ADAPTER_TID
);
408 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
409 msg
->u
.head
[3] = cpu_to_le32(0);
411 cpu_to_le32((u32
) kxfer
.flags
<< 24 | (u32
) kxfer
.sw_type
<< 16);
412 msg
->body
[1] = cpu_to_le32(swlen
);
413 msg
->body
[2] = cpu_to_le32(kxfer
.sw_id
);
415 token
= i2o_msg_post_wait(c
, msg
, 10);
417 if (token
!= I2O_POST_WAIT_OK
) {
418 osm_info("swdel failed, DetailedStatus = %d\n", token
);
425 static int i2o_cfg_validate(unsigned long arg
)
429 struct i2o_message
*msg
;
430 struct i2o_controller
*c
;
432 c
= i2o_find_iop(iop
);
436 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
440 msg
->u
.head
[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE
| SGL_OFFSET_0
);
442 cpu_to_le32(I2O_CMD_CONFIG_VALIDATE
<< 24 | HOST_TID
<< 12 | iop
);
443 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
444 msg
->u
.head
[3] = cpu_to_le32(0);
446 token
= i2o_msg_post_wait(c
, msg
, 10);
448 if (token
!= I2O_POST_WAIT_OK
) {
449 osm_info("Can't validate configuration, ErrorStatus = %d\n",
457 static int i2o_cfg_evt_reg(unsigned long arg
, struct file
*fp
)
459 struct i2o_message
*msg
;
460 struct i2o_evt_id __user
*pdesc
= (struct i2o_evt_id __user
*)arg
;
461 struct i2o_evt_id kdesc
;
462 struct i2o_controller
*c
;
463 struct i2o_device
*d
;
465 if (copy_from_user(&kdesc
, pdesc
, sizeof(struct i2o_evt_id
)))
469 c
= i2o_find_iop(kdesc
.iop
);
474 d
= i2o_iop_find_device(c
, kdesc
.tid
);
478 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
482 msg
->u
.head
[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE
| SGL_OFFSET_0
);
484 cpu_to_le32(I2O_CMD_UTIL_EVT_REGISTER
<< 24 | HOST_TID
<< 12 |
486 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
487 msg
->u
.head
[3] = cpu_to_le32(i2o_cntxt_list_add(c
, fp
->private_data
));
488 msg
->body
[0] = cpu_to_le32(kdesc
.evt_mask
);
490 i2o_msg_post(c
, msg
);
495 static int i2o_cfg_evt_get(unsigned long arg
, struct file
*fp
)
497 struct i2o_cfg_info
*p
= NULL
;
498 struct i2o_evt_get __user
*uget
= (struct i2o_evt_get __user
*)arg
;
499 struct i2o_evt_get kget
;
502 for (p
= open_files
; p
; p
= p
->next
)
503 if (p
->q_id
== (ulong
) fp
->private_data
)
509 memcpy(&kget
.info
, &p
->event_q
[p
->q_out
], sizeof(struct i2o_evt_info
));
510 MODINC(p
->q_out
, I2O_EVT_Q_LEN
);
511 spin_lock_irqsave(&i2o_config_lock
, flags
);
513 kget
.pending
= p
->q_len
;
514 kget
.lost
= p
->q_lost
;
515 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
517 if (copy_to_user(uget
, &kget
, sizeof(struct i2o_evt_get
)))
523 static int i2o_cfg_passthru32(struct file
*file
, unsigned cmnd
,
526 struct i2o_cmd_passthru32 __user
*cmd
;
527 struct i2o_controller
*c
;
528 u32 __user
*user_msg
;
530 u32 __user
*user_reply
= NULL
;
534 struct i2o_dma sg_list
[SG_TABLESIZE
];
539 i2o_status_block
*sb
;
540 struct i2o_message
*msg
;
543 cmd
= (struct i2o_cmd_passthru32 __user
*)arg
;
545 if (get_user(iop
, &cmd
->iop
) || get_user(i
, &cmd
->msg
))
548 user_msg
= compat_ptr(i
);
550 c
= i2o_find_iop(iop
);
552 osm_debug("controller %d not found\n", iop
);
556 sb
= c
->status_block
.virt
;
558 if (get_user(size
, &user_msg
[0])) {
559 osm_warn("unable to get size!\n");
564 if (size
> sb
->inbound_frame_size
) {
565 osm_warn("size of message > inbound_frame_size");
569 user_reply
= &user_msg
[size
];
571 size
<<= 2; // Convert to bytes
573 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
578 /* Copy in the user's I2O command */
579 if (copy_from_user(msg
, user_msg
, size
)) {
580 osm_warn("unable to copy user message\n");
583 i2o_dump_message(msg
);
585 if (get_user(reply_size
, &user_reply
[0]) < 0)
592 reply
= kzalloc(reply_size
, GFP_KERNEL
);
594 printk(KERN_WARNING
"%s: Could not allocate reply buffer\n",
599 sg_offset
= (msg
->u
.head
[0] >> 4) & 0x0f;
601 memset(sg_list
, 0, sizeof(sg_list
[0]) * SG_TABLESIZE
);
603 struct sg_simple_element
*sg
;
605 if (sg_offset
* 4 >= size
) {
610 sg
= (struct sg_simple_element
*)((&msg
->u
.head
[0]) +
613 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
614 if (sg_count
> SG_TABLESIZE
) {
615 printk(KERN_DEBUG
"%s:IOCTL SG List too large (%u)\n",
621 for (i
= 0; i
< sg_count
; i
++) {
625 if (!(sg
[i
].flag_count
& 0x10000000
626 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
628 "%s:Bad SG element %d - not simple (%x)\n",
629 c
->name
, i
, sg
[i
].flag_count
);
633 sg_size
= sg
[i
].flag_count
& 0xffffff;
634 p
= &(sg_list
[sg_index
]);
635 /* Allocate memory for the transfer */
636 if (i2o_dma_alloc(&c
->pdev
->dev
, p
, sg_size
)) {
638 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
639 c
->name
, sg_size
, i
, sg_count
);
641 goto sg_list_cleanup
;
644 /* Copy in the user's SG buffer if necessary */
646 flag_count
& 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
650 (void __user
*)(unsigned long)sg
[i
].
651 addr_bus
, sg_size
)) {
653 "%s: Could not copy SG buf %d FROM user\n",
656 goto sg_list_cleanup
;
660 sg
[i
].addr_bus
= (u32
) p
->phys
;
664 rcode
= i2o_msg_post_wait(c
, msg
, 60);
667 reply
[4] = ((u32
) rcode
) << 24;
668 goto sg_list_cleanup
;
672 u32 rmsg
[I2O_OUTBOUND_MSG_FRAME_SIZE
];
673 /* Copy back the Scatter Gather buffers back to user space */
676 struct sg_simple_element
*sg
;
679 // re-acquire the original message to handle correctly the sg copy operation
680 memset(&rmsg
, 0, I2O_OUTBOUND_MSG_FRAME_SIZE
* 4);
681 // get user msg size in u32s
682 if (get_user(size
, &user_msg
[0])) {
684 goto sg_list_cleanup
;
688 /* Copy in the user's I2O command */
689 if (copy_from_user(rmsg
, user_msg
, size
)) {
691 goto sg_list_cleanup
;
694 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
697 sg
= (struct sg_simple_element
*)(rmsg
+ sg_offset
);
698 for (j
= 0; j
< sg_count
; j
++) {
699 /* Copy out the SG list to user's buffer if necessary */
702 flag_count
& 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
703 sg_size
= sg
[j
].flag_count
& 0xffffff;
706 ((void __user
*)(u64
) sg
[j
].addr_bus
,
707 sg_list
[j
].virt
, sg_size
)) {
709 "%s: Could not copy %p TO user %x\n",
710 c
->name
, sg_list
[j
].virt
,
713 goto sg_list_cleanup
;
720 /* Copy back the reply to user space */
722 // we wrote our own values for context - now restore the user supplied ones
723 if (copy_from_user(reply
+ 2, user_msg
+ 2, sizeof(u32
) * 2)) {
725 "%s: Could not copy message context FROM user\n",
729 if (copy_to_user(user_reply
, reply
, reply_size
)) {
731 "%s: Could not copy reply TO user\n", c
->name
);
735 for (i
= 0; i
< sg_index
; i
++)
736 i2o_dma_free(&c
->pdev
->dev
, &sg_list
[i
]);
746 static long i2o_cfg_compat_ioctl(struct file
*file
, unsigned cmd
,
753 ret
= i2o_cfg_ioctl(file
, cmd
, arg
);
756 ret
= i2o_cfg_passthru32(file
, cmd
, arg
);
768 #ifdef CONFIG_I2O_EXT_ADAPTEC
769 static int i2o_cfg_passthru(unsigned long arg
)
771 struct i2o_cmd_passthru __user
*cmd
=
772 (struct i2o_cmd_passthru __user
*)arg
;
773 struct i2o_controller
*c
;
774 u32 __user
*user_msg
;
776 u32 __user
*user_reply
= NULL
;
780 struct i2o_dma sg_list
[SG_TABLESIZE
];
785 i2o_status_block
*sb
;
786 struct i2o_message
*msg
;
789 if (get_user(iop
, &cmd
->iop
) || get_user(user_msg
, &cmd
->msg
))
792 c
= i2o_find_iop(iop
);
794 osm_warn("controller %d not found\n", iop
);
798 sb
= c
->status_block
.virt
;
800 if (get_user(size
, &user_msg
[0]))
804 if (size
> sb
->inbound_frame_size
) {
805 osm_warn("size of message > inbound_frame_size");
809 user_reply
= &user_msg
[size
];
811 size
<<= 2; // Convert to bytes
813 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
818 /* Copy in the user's I2O command */
819 if (copy_from_user(msg
, user_msg
, size
))
822 if (get_user(reply_size
, &user_reply
[0]) < 0)
828 reply
= kzalloc(reply_size
, GFP_KERNEL
);
830 printk(KERN_WARNING
"%s: Could not allocate reply buffer\n",
836 sg_offset
= (msg
->u
.head
[0] >> 4) & 0x0f;
838 memset(sg_list
, 0, sizeof(sg_list
[0]) * SG_TABLESIZE
);
840 struct sg_simple_element
*sg
;
843 if (sg_offset
* 4 >= size
) {
848 sg
= (struct sg_simple_element
*)((&msg
->u
.head
[0]) +
851 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
852 if (sg_count
> SG_TABLESIZE
) {
853 printk(KERN_DEBUG
"%s:IOCTL SG List too large (%u)\n",
859 for (i
= 0; i
< sg_count
; i
++) {
862 if (!(sg
[i
].flag_count
& 0x10000000
863 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
865 "%s:Bad SG element %d - not simple (%x)\n",
866 c
->name
, i
, sg
[i
].flag_count
);
868 goto sg_list_cleanup
;
870 sg_size
= sg
[i
].flag_count
& 0xffffff;
871 p
= &(sg_list
[sg_index
]);
872 if (i2o_dma_alloc(&c
->pdev
->dev
, p
, sg_size
)) {
873 /* Allocate memory for the transfer */
875 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
876 c
->name
, sg_size
, i
, sg_count
);
878 goto sg_list_cleanup
;
881 /* Copy in the user's SG buffer if necessary */
883 flag_count
& 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
886 (p
->virt
, (void __user
*)sg
[i
].addr_bus
,
889 "%s: Could not copy SG buf %d FROM user\n",
892 goto sg_list_cleanup
;
895 sg
[i
].addr_bus
= p
->phys
;
899 rcode
= i2o_msg_post_wait(c
, msg
, 60);
902 reply
[4] = ((u32
) rcode
) << 24;
903 goto sg_list_cleanup
;
907 u32 rmsg
[I2O_OUTBOUND_MSG_FRAME_SIZE
];
908 /* Copy back the Scatter Gather buffers back to user space */
911 struct sg_simple_element
*sg
;
914 // re-acquire the original message to handle correctly the sg copy operation
915 memset(&rmsg
, 0, I2O_OUTBOUND_MSG_FRAME_SIZE
* 4);
916 // get user msg size in u32s
917 if (get_user(size
, &user_msg
[0])) {
919 goto sg_list_cleanup
;
923 /* Copy in the user's I2O command */
924 if (copy_from_user(rmsg
, user_msg
, size
)) {
926 goto sg_list_cleanup
;
929 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
932 sg
= (struct sg_simple_element
*)(rmsg
+ sg_offset
);
933 for (j
= 0; j
< sg_count
; j
++) {
934 /* Copy out the SG list to user's buffer if necessary */
937 flag_count
& 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
938 sg_size
= sg
[j
].flag_count
& 0xffffff;
941 ((void __user
*)sg
[j
].addr_bus
, sg_list
[j
].virt
,
944 "%s: Could not copy %p TO user %x\n",
945 c
->name
, sg_list
[j
].virt
,
948 goto sg_list_cleanup
;
955 /* Copy back the reply to user space */
957 // we wrote our own values for context - now restore the user supplied ones
958 if (copy_from_user(reply
+ 2, user_msg
+ 2, sizeof(u32
) * 2)) {
960 "%s: Could not copy message context FROM user\n",
964 if (copy_to_user(user_reply
, reply
, reply_size
)) {
966 "%s: Could not copy reply TO user\n", c
->name
);
971 for (i
= 0; i
< sg_index
; i
++)
972 i2o_dma_free(&c
->pdev
->dev
, &sg_list
[i
]);
986 static long i2o_cfg_ioctl(struct file
*fp
, unsigned int cmd
, unsigned long arg
)
993 ret
= i2o_cfg_getiops(arg
);
997 ret
= i2o_cfg_gethrt(arg
);
1001 ret
= i2o_cfg_getlct(arg
);
1005 ret
= i2o_cfg_parms(arg
, I2OPARMSET
);
1009 ret
= i2o_cfg_parms(arg
, I2OPARMGET
);
1013 ret
= i2o_cfg_swdl(arg
);
1017 ret
= i2o_cfg_swul(arg
);
1021 ret
= i2o_cfg_swdel(arg
);
1025 ret
= i2o_cfg_validate(arg
);
1029 ret
= i2o_cfg_evt_reg(arg
, fp
);
1033 ret
= i2o_cfg_evt_get(arg
, fp
);
1036 #ifdef CONFIG_I2O_EXT_ADAPTEC
1038 ret
= i2o_cfg_passthru(arg
);
1043 osm_debug("unknown ioctl called!\n");
1050 static int cfg_open(struct inode
*inode
, struct file
*file
)
1052 struct i2o_cfg_info
*tmp
=
1053 (struct i2o_cfg_info
*)kmalloc(sizeof(struct i2o_cfg_info
),
1055 unsigned long flags
;
1061 file
->private_data
= (void *)(i2o_cfg_info_id
++);
1064 tmp
->q_id
= (ulong
) file
->private_data
;
1069 tmp
->next
= open_files
;
1071 spin_lock_irqsave(&i2o_config_lock
, flags
);
1073 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
1079 static int cfg_fasync(int fd
, struct file
*fp
, int on
)
1081 ulong id
= (ulong
) fp
->private_data
;
1082 struct i2o_cfg_info
*p
;
1086 for (p
= open_files
; p
; p
= p
->next
)
1091 ret
= fasync_helper(fd
, fp
, on
, &p
->fasync
);
1096 static int cfg_release(struct inode
*inode
, struct file
*file
)
1098 ulong id
= (ulong
) file
->private_data
;
1099 struct i2o_cfg_info
*p
, **q
;
1100 unsigned long flags
;
1103 spin_lock_irqsave(&i2o_config_lock
, flags
);
1104 for (q
= &open_files
; (p
= *q
) != NULL
; q
= &p
->next
) {
1105 if (p
->q_id
== id
) {
1111 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
1117 static const struct file_operations config_fops
= {
1118 .owner
= THIS_MODULE
,
1119 .llseek
= no_llseek
,
1120 .unlocked_ioctl
= i2o_cfg_ioctl
,
1121 #ifdef CONFIG_COMPAT
1122 .compat_ioctl
= i2o_cfg_compat_ioctl
,
1125 .release
= cfg_release
,
1126 .fasync
= cfg_fasync
,
1129 static struct miscdevice i2o_miscdev
= {
1135 static int __init
i2o_config_old_init(void)
1137 spin_lock_init(&i2o_config_lock
);
1139 if (misc_register(&i2o_miscdev
) < 0) {
1140 osm_err("can't register device.\n");
1147 static void i2o_config_old_exit(void)
1149 misc_deregister(&i2o_miscdev
);
1152 MODULE_AUTHOR("Red Hat Software");