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>
38 #include <asm/uaccess.h>
42 #define SG_TABLESIZE 30
44 static DEFINE_MUTEX(i2o_cfg_mutex
);
45 static long i2o_cfg_ioctl(struct file
*, unsigned int, unsigned long);
47 static spinlock_t i2o_config_lock
;
49 #define MODINC(x,y) ((x) = ((x) + 1) % (y))
51 struct sg_simple_element
{
58 struct fasync_struct
*fasync
;
59 struct i2o_evt_info event_q
[I2O_EVT_Q_LEN
];
60 u16 q_in
; // Queue head index
61 u16 q_out
; // Queue tail index
62 u16 q_len
; // Queue length
63 u16 q_lost
; // Number of lost events
64 ulong q_id
; // Event queue ID...used as tx_context
65 struct i2o_cfg_info
*next
;
67 static struct i2o_cfg_info
*open_files
= NULL
;
68 static ulong i2o_cfg_info_id
= 0;
70 static int i2o_cfg_getiops(unsigned long arg
)
72 struct i2o_controller
*c
;
73 u8 __user
*user_iop_table
= (void __user
*)arg
;
74 u8 tmp
[MAX_I2O_CONTROLLERS
];
77 memset(tmp
, 0, MAX_I2O_CONTROLLERS
);
79 list_for_each_entry(c
, &i2o_controllers
, list
)
82 if (copy_to_user(user_iop_table
, tmp
, MAX_I2O_CONTROLLERS
))
88 static int i2o_cfg_gethrt(unsigned long arg
)
90 struct i2o_controller
*c
;
91 struct i2o_cmd_hrtlct __user
*cmd
= (struct i2o_cmd_hrtlct __user
*)arg
;
92 struct i2o_cmd_hrtlct kcmd
;
98 if (copy_from_user(&kcmd
, cmd
, sizeof(struct i2o_cmd_hrtlct
)))
101 if (get_user(reslen
, kcmd
.reslen
) < 0)
104 if (kcmd
.resbuf
== NULL
)
107 c
= i2o_find_iop(kcmd
.iop
);
111 hrt
= (i2o_hrt
*) c
->hrt
.virt
;
113 len
= 8 + ((hrt
->entry_len
* hrt
->num_entries
) << 2);
115 if (put_user(len
, kcmd
.reslen
))
117 else if (len
> reslen
)
119 else if (copy_to_user(kcmd
.resbuf
, (void *)hrt
, len
))
125 static int i2o_cfg_getlct(unsigned long arg
)
127 struct i2o_controller
*c
;
128 struct i2o_cmd_hrtlct __user
*cmd
= (struct i2o_cmd_hrtlct __user
*)arg
;
129 struct i2o_cmd_hrtlct kcmd
;
135 if (copy_from_user(&kcmd
, cmd
, sizeof(struct i2o_cmd_hrtlct
)))
138 if (get_user(reslen
, kcmd
.reslen
) < 0)
141 if (kcmd
.resbuf
== NULL
)
144 c
= i2o_find_iop(kcmd
.iop
);
148 lct
= (i2o_lct
*) c
->lct
;
150 len
= (unsigned int)lct
->table_size
<< 2;
151 if (put_user(len
, kcmd
.reslen
))
153 else if (len
> reslen
)
155 else if (copy_to_user(kcmd
.resbuf
, lct
, len
))
161 static int i2o_cfg_parms(unsigned long arg
, unsigned int type
)
164 struct i2o_controller
*c
;
165 struct i2o_device
*dev
;
166 struct i2o_cmd_psetget __user
*cmd
=
167 (struct i2o_cmd_psetget __user
*)arg
;
168 struct i2o_cmd_psetget kcmd
;
174 u32 i2o_cmd
= (type
== I2OPARMGET
?
175 I2O_CMD_UTIL_PARAMS_GET
: I2O_CMD_UTIL_PARAMS_SET
);
177 if (copy_from_user(&kcmd
, cmd
, sizeof(struct i2o_cmd_psetget
)))
180 if (get_user(reslen
, kcmd
.reslen
))
183 c
= i2o_find_iop(kcmd
.iop
);
187 dev
= i2o_iop_find_device(c
, kcmd
.tid
);
192 * Stop users being able to try and allocate arbitary amounts
193 * of DMA space. 64K is way more than sufficient for this.
195 if (kcmd
.oplen
> 65536)
198 ops
= memdup_user(kcmd
.opbuf
, kcmd
.oplen
);
203 * It's possible to have a _very_ large table
204 * and that the user asks for all of it at once...
206 res
= kmalloc(65536, GFP_KERNEL
);
212 len
= i2o_parm_issue(dev
, i2o_cmd
, ops
, kcmd
.oplen
, res
, 65536);
220 if (put_user(len
, kcmd
.reslen
))
222 else if (len
> reslen
)
224 else if (copy_to_user(kcmd
.resbuf
, res
, len
))
232 static int i2o_cfg_swdl(unsigned long arg
)
234 struct i2o_sw_xfer kxfer
;
235 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
236 unsigned char maxfrag
= 0, curfrag
= 1;
237 struct i2o_dma buffer
;
238 struct i2o_message
*msg
;
239 unsigned int status
= 0, swlen
= 0, fragsize
= 8192;
240 struct i2o_controller
*c
;
242 if (copy_from_user(&kxfer
, pxfer
, sizeof(struct i2o_sw_xfer
)))
245 if (get_user(swlen
, kxfer
.swlen
) < 0)
248 if (get_user(maxfrag
, kxfer
.maxfrag
) < 0)
251 if (get_user(curfrag
, kxfer
.curfrag
) < 0)
254 if (curfrag
== maxfrag
)
255 fragsize
= swlen
- (maxfrag
- 1) * 8192;
257 if (!kxfer
.buf
|| !access_ok(VERIFY_READ
, kxfer
.buf
, fragsize
))
260 c
= i2o_find_iop(kxfer
.iop
);
264 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
268 if (i2o_dma_alloc(&c
->pdev
->dev
, &buffer
, fragsize
)) {
273 if (__copy_from_user(buffer
.virt
, kxfer
.buf
, fragsize
)) {
275 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
279 msg
->u
.head
[0] = cpu_to_le32(NINE_WORD_MSG_SIZE
| SGL_OFFSET_7
);
281 cpu_to_le32(I2O_CMD_SW_DOWNLOAD
<< 24 | HOST_TID
<< 12 |
283 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
284 msg
->u
.head
[3] = cpu_to_le32(0);
286 cpu_to_le32((((u32
) kxfer
.flags
) << 24) | (((u32
) kxfer
.
288 (((u32
) maxfrag
) << 8) | (((u32
) curfrag
)));
289 msg
->body
[1] = cpu_to_le32(swlen
);
290 msg
->body
[2] = cpu_to_le32(kxfer
.sw_id
);
291 msg
->body
[3] = cpu_to_le32(0xD0000000 | fragsize
);
292 msg
->body
[4] = cpu_to_le32(buffer
.phys
);
294 osm_debug("swdl frag %d/%d (size %d)\n", curfrag
, maxfrag
, fragsize
);
295 status
= i2o_msg_post_wait_mem(c
, msg
, 60, &buffer
);
297 if (status
!= -ETIMEDOUT
)
298 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
300 if (status
!= I2O_POST_WAIT_OK
) {
301 // it fails if you try and send frags out of order
302 // and for some yet unknown reasons too
303 osm_info("swdl failed, DetailedStatus = %d\n", status
);
310 static int i2o_cfg_swul(unsigned long arg
)
312 struct i2o_sw_xfer kxfer
;
313 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
314 unsigned char maxfrag
= 0, curfrag
= 1;
315 struct i2o_dma buffer
;
316 struct i2o_message
*msg
;
317 unsigned int status
= 0, swlen
= 0, fragsize
= 8192;
318 struct i2o_controller
*c
;
321 if (copy_from_user(&kxfer
, pxfer
, sizeof(struct i2o_sw_xfer
)))
324 if (get_user(swlen
, kxfer
.swlen
) < 0)
327 if (get_user(maxfrag
, kxfer
.maxfrag
) < 0)
330 if (get_user(curfrag
, kxfer
.curfrag
) < 0)
333 if (curfrag
== maxfrag
)
334 fragsize
= swlen
- (maxfrag
- 1) * 8192;
339 c
= i2o_find_iop(kxfer
.iop
);
343 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
347 if (i2o_dma_alloc(&c
->pdev
->dev
, &buffer
, fragsize
)) {
352 msg
->u
.head
[0] = cpu_to_le32(NINE_WORD_MSG_SIZE
| SGL_OFFSET_7
);
354 cpu_to_le32(I2O_CMD_SW_UPLOAD
<< 24 | HOST_TID
<< 12 | ADAPTER_TID
);
355 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
356 msg
->u
.head
[3] = cpu_to_le32(0);
358 cpu_to_le32((u32
) kxfer
.flags
<< 24 | (u32
) kxfer
.
359 sw_type
<< 16 | (u32
) maxfrag
<< 8 | (u32
) curfrag
);
360 msg
->body
[1] = cpu_to_le32(swlen
);
361 msg
->body
[2] = cpu_to_le32(kxfer
.sw_id
);
362 msg
->body
[3] = cpu_to_le32(0xD0000000 | fragsize
);
363 msg
->body
[4] = cpu_to_le32(buffer
.phys
);
365 osm_debug("swul frag %d/%d (size %d)\n", curfrag
, maxfrag
, fragsize
);
366 status
= i2o_msg_post_wait_mem(c
, msg
, 60, &buffer
);
368 if (status
!= I2O_POST_WAIT_OK
) {
369 if (status
!= -ETIMEDOUT
)
370 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
372 osm_info("swul failed, DetailedStatus = %d\n", status
);
376 if (copy_to_user(kxfer
.buf
, buffer
.virt
, fragsize
))
379 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
384 static int i2o_cfg_swdel(unsigned long arg
)
386 struct i2o_controller
*c
;
387 struct i2o_sw_xfer kxfer
;
388 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
389 struct i2o_message
*msg
;
393 if (copy_from_user(&kxfer
, pxfer
, sizeof(struct i2o_sw_xfer
)))
396 if (get_user(swlen
, kxfer
.swlen
) < 0)
399 c
= i2o_find_iop(kxfer
.iop
);
403 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
407 msg
->u
.head
[0] = cpu_to_le32(SEVEN_WORD_MSG_SIZE
| SGL_OFFSET_0
);
409 cpu_to_le32(I2O_CMD_SW_REMOVE
<< 24 | HOST_TID
<< 12 | ADAPTER_TID
);
410 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
411 msg
->u
.head
[3] = cpu_to_le32(0);
413 cpu_to_le32((u32
) kxfer
.flags
<< 24 | (u32
) kxfer
.sw_type
<< 16);
414 msg
->body
[1] = cpu_to_le32(swlen
);
415 msg
->body
[2] = cpu_to_le32(kxfer
.sw_id
);
417 token
= i2o_msg_post_wait(c
, msg
, 10);
419 if (token
!= I2O_POST_WAIT_OK
) {
420 osm_info("swdel failed, DetailedStatus = %d\n", token
);
427 static int i2o_cfg_validate(unsigned long arg
)
431 struct i2o_message
*msg
;
432 struct i2o_controller
*c
;
434 c
= i2o_find_iop(iop
);
438 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
442 msg
->u
.head
[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE
| SGL_OFFSET_0
);
444 cpu_to_le32(I2O_CMD_CONFIG_VALIDATE
<< 24 | HOST_TID
<< 12 | iop
);
445 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
446 msg
->u
.head
[3] = cpu_to_le32(0);
448 token
= i2o_msg_post_wait(c
, msg
, 10);
450 if (token
!= I2O_POST_WAIT_OK
) {
451 osm_info("Can't validate configuration, ErrorStatus = %d\n",
459 static int i2o_cfg_evt_reg(unsigned long arg
, struct file
*fp
)
461 struct i2o_message
*msg
;
462 struct i2o_evt_id __user
*pdesc
= (struct i2o_evt_id __user
*)arg
;
463 struct i2o_evt_id kdesc
;
464 struct i2o_controller
*c
;
465 struct i2o_device
*d
;
467 if (copy_from_user(&kdesc
, pdesc
, sizeof(struct i2o_evt_id
)))
471 c
= i2o_find_iop(kdesc
.iop
);
476 d
= i2o_iop_find_device(c
, kdesc
.tid
);
480 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
484 msg
->u
.head
[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE
| SGL_OFFSET_0
);
486 cpu_to_le32(I2O_CMD_UTIL_EVT_REGISTER
<< 24 | HOST_TID
<< 12 |
488 msg
->u
.head
[2] = cpu_to_le32(i2o_config_driver
.context
);
489 msg
->u
.head
[3] = cpu_to_le32(i2o_cntxt_list_add(c
, fp
->private_data
));
490 msg
->body
[0] = cpu_to_le32(kdesc
.evt_mask
);
492 i2o_msg_post(c
, msg
);
497 static int i2o_cfg_evt_get(unsigned long arg
, struct file
*fp
)
499 struct i2o_cfg_info
*p
= NULL
;
500 struct i2o_evt_get __user
*uget
= (struct i2o_evt_get __user
*)arg
;
501 struct i2o_evt_get kget
;
504 for (p
= open_files
; p
; p
= p
->next
)
505 if (p
->q_id
== (ulong
) fp
->private_data
)
511 memcpy(&kget
.info
, &p
->event_q
[p
->q_out
], sizeof(struct i2o_evt_info
));
512 MODINC(p
->q_out
, I2O_EVT_Q_LEN
);
513 spin_lock_irqsave(&i2o_config_lock
, flags
);
515 kget
.pending
= p
->q_len
;
516 kget
.lost
= p
->q_lost
;
517 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
519 if (copy_to_user(uget
, &kget
, sizeof(struct i2o_evt_get
)))
525 static int i2o_cfg_passthru32(struct file
*file
, unsigned cmnd
,
528 struct i2o_cmd_passthru32 __user
*cmd
;
529 struct i2o_controller
*c
;
530 u32 __user
*user_msg
;
532 u32 __user
*user_reply
= NULL
;
536 struct i2o_dma sg_list
[SG_TABLESIZE
];
541 i2o_status_block
*sb
;
542 struct i2o_message
*msg
;
545 cmd
= (struct i2o_cmd_passthru32 __user
*)arg
;
547 if (get_user(iop
, &cmd
->iop
) || get_user(i
, &cmd
->msg
))
550 user_msg
= compat_ptr(i
);
552 c
= i2o_find_iop(iop
);
554 osm_debug("controller %d not found\n", iop
);
558 sb
= c
->status_block
.virt
;
560 if (get_user(size
, &user_msg
[0])) {
561 osm_warn("unable to get size!\n");
566 if (size
> sb
->inbound_frame_size
) {
567 osm_warn("size of message > inbound_frame_size");
571 user_reply
= &user_msg
[size
];
573 size
<<= 2; // Convert to bytes
575 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
580 /* Copy in the user's I2O command */
581 if (copy_from_user(msg
, user_msg
, size
)) {
582 osm_warn("unable to copy user message\n");
585 i2o_dump_message(msg
);
587 if (get_user(reply_size
, &user_reply
[0]) < 0)
594 reply
= kzalloc(reply_size
, GFP_KERNEL
);
596 printk(KERN_WARNING
"%s: Could not allocate reply buffer\n",
601 sg_offset
= (msg
->u
.head
[0] >> 4) & 0x0f;
603 memset(sg_list
, 0, sizeof(sg_list
[0]) * SG_TABLESIZE
);
605 struct sg_simple_element
*sg
;
607 if (sg_offset
* 4 >= size
) {
612 sg
= (struct sg_simple_element
*)((&msg
->u
.head
[0]) +
615 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
616 if (sg_count
> SG_TABLESIZE
) {
617 printk(KERN_DEBUG
"%s:IOCTL SG List too large (%u)\n",
623 for (i
= 0; i
< sg_count
; i
++) {
627 if (!(sg
[i
].flag_count
& 0x10000000
628 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
630 "%s:Bad SG element %d - not simple (%x)\n",
631 c
->name
, i
, sg
[i
].flag_count
);
635 sg_size
= sg
[i
].flag_count
& 0xffffff;
636 p
= &(sg_list
[sg_index
]);
637 /* Allocate memory for the transfer */
638 if (i2o_dma_alloc(&c
->pdev
->dev
, p
, sg_size
)) {
640 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
641 c
->name
, sg_size
, i
, sg_count
);
643 goto sg_list_cleanup
;
646 /* Copy in the user's SG buffer if necessary */
648 flag_count
& 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
652 (void __user
*)(unsigned long)sg
[i
].
653 addr_bus
, sg_size
)) {
655 "%s: Could not copy SG buf %d FROM user\n",
658 goto sg_list_cleanup
;
662 sg
[i
].addr_bus
= (u32
) p
->phys
;
666 rcode
= i2o_msg_post_wait(c
, msg
, 60);
669 reply
[4] = ((u32
) rcode
) << 24;
670 goto sg_list_cleanup
;
674 u32 rmsg
[I2O_OUTBOUND_MSG_FRAME_SIZE
];
675 /* Copy back the Scatter Gather buffers back to user space */
678 struct sg_simple_element
*sg
;
681 // re-acquire the original message to handle correctly the sg copy operation
682 memset(&rmsg
, 0, I2O_OUTBOUND_MSG_FRAME_SIZE
* 4);
683 // get user msg size in u32s
684 if (get_user(size
, &user_msg
[0])) {
686 goto sg_list_cleanup
;
690 /* Copy in the user's I2O command */
691 if (copy_from_user(rmsg
, user_msg
, size
)) {
693 goto sg_list_cleanup
;
696 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
699 sg
= (struct sg_simple_element
*)(rmsg
+ sg_offset
);
700 for (j
= 0; j
< sg_count
; j
++) {
701 /* Copy out the SG list to user's buffer if necessary */
704 flag_count
& 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
705 sg_size
= sg
[j
].flag_count
& 0xffffff;
708 ((void __user
*)(u64
) sg
[j
].addr_bus
,
709 sg_list
[j
].virt
, sg_size
)) {
711 "%s: Could not copy %p TO user %x\n",
712 c
->name
, sg_list
[j
].virt
,
715 goto sg_list_cleanup
;
722 /* Copy back the reply to user space */
724 // we wrote our own values for context - now restore the user supplied ones
725 if (copy_from_user(reply
+ 2, user_msg
+ 2, sizeof(u32
) * 2)) {
727 "%s: Could not copy message context FROM user\n",
731 if (copy_to_user(user_reply
, reply
, reply_size
)) {
733 "%s: Could not copy reply TO user\n", c
->name
);
737 for (i
= 0; i
< sg_index
; i
++)
738 i2o_dma_free(&c
->pdev
->dev
, &sg_list
[i
]);
748 static long i2o_cfg_compat_ioctl(struct file
*file
, unsigned cmd
,
752 mutex_lock(&i2o_cfg_mutex
);
755 ret
= i2o_cfg_ioctl(file
, cmd
, arg
);
758 ret
= i2o_cfg_passthru32(file
, cmd
, arg
);
764 mutex_unlock(&i2o_cfg_mutex
);
770 #ifdef CONFIG_I2O_EXT_ADAPTEC
771 static int i2o_cfg_passthru(unsigned long arg
)
773 struct i2o_cmd_passthru __user
*cmd
=
774 (struct i2o_cmd_passthru __user
*)arg
;
775 struct i2o_controller
*c
;
776 u32 __user
*user_msg
;
778 u32 __user
*user_reply
= NULL
;
782 struct i2o_dma sg_list
[SG_TABLESIZE
];
787 i2o_status_block
*sb
;
788 struct i2o_message
*msg
;
791 if (get_user(iop
, &cmd
->iop
) || get_user(user_msg
, &cmd
->msg
))
794 c
= i2o_find_iop(iop
);
796 osm_warn("controller %d not found\n", iop
);
800 sb
= c
->status_block
.virt
;
802 if (get_user(size
, &user_msg
[0]))
806 if (size
> sb
->inbound_frame_size
) {
807 osm_warn("size of message > inbound_frame_size");
811 user_reply
= &user_msg
[size
];
813 size
<<= 2; // Convert to bytes
815 msg
= i2o_msg_get_wait(c
, I2O_TIMEOUT_MESSAGE_GET
);
820 /* Copy in the user's I2O command */
821 if (copy_from_user(msg
, user_msg
, size
))
824 if (get_user(reply_size
, &user_reply
[0]) < 0)
830 reply
= kzalloc(reply_size
, GFP_KERNEL
);
832 printk(KERN_WARNING
"%s: Could not allocate reply buffer\n",
838 sg_offset
= (msg
->u
.head
[0] >> 4) & 0x0f;
840 memset(sg_list
, 0, sizeof(sg_list
[0]) * SG_TABLESIZE
);
842 struct sg_simple_element
*sg
;
845 if (sg_offset
* 4 >= size
) {
850 sg
= (struct sg_simple_element
*)((&msg
->u
.head
[0]) +
853 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
854 if (sg_count
> SG_TABLESIZE
) {
855 printk(KERN_DEBUG
"%s:IOCTL SG List too large (%u)\n",
861 for (i
= 0; i
< sg_count
; i
++) {
864 if (!(sg
[i
].flag_count
& 0x10000000
865 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
867 "%s:Bad SG element %d - not simple (%x)\n",
868 c
->name
, i
, sg
[i
].flag_count
);
870 goto sg_list_cleanup
;
872 sg_size
= sg
[i
].flag_count
& 0xffffff;
873 p
= &(sg_list
[sg_index
]);
874 if (i2o_dma_alloc(&c
->pdev
->dev
, p
, sg_size
)) {
875 /* Allocate memory for the transfer */
877 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
878 c
->name
, sg_size
, i
, sg_count
);
880 goto sg_list_cleanup
;
883 /* Copy in the user's SG buffer if necessary */
885 flag_count
& 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
888 (p
->virt
, (void __user
*)sg
[i
].addr_bus
,
891 "%s: Could not copy SG buf %d FROM user\n",
894 goto sg_list_cleanup
;
897 sg
[i
].addr_bus
= p
->phys
;
901 rcode
= i2o_msg_post_wait(c
, msg
, 60);
904 reply
[4] = ((u32
) rcode
) << 24;
905 goto sg_list_cleanup
;
909 u32 rmsg
[I2O_OUTBOUND_MSG_FRAME_SIZE
];
910 /* Copy back the Scatter Gather buffers back to user space */
913 struct sg_simple_element
*sg
;
916 // re-acquire the original message to handle correctly the sg copy operation
917 memset(&rmsg
, 0, I2O_OUTBOUND_MSG_FRAME_SIZE
* 4);
918 // get user msg size in u32s
919 if (get_user(size
, &user_msg
[0])) {
921 goto sg_list_cleanup
;
925 /* Copy in the user's I2O command */
926 if (copy_from_user(rmsg
, user_msg
, size
)) {
928 goto sg_list_cleanup
;
931 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
934 sg
= (struct sg_simple_element
*)(rmsg
+ sg_offset
);
935 for (j
= 0; j
< sg_count
; j
++) {
936 /* Copy out the SG list to user's buffer if necessary */
939 flag_count
& 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
940 sg_size
= sg
[j
].flag_count
& 0xffffff;
943 ((void __user
*)sg
[j
].addr_bus
, sg_list
[j
].virt
,
946 "%s: Could not copy %p TO user %x\n",
947 c
->name
, sg_list
[j
].virt
,
950 goto sg_list_cleanup
;
957 /* Copy back the reply to user space */
959 // we wrote our own values for context - now restore the user supplied ones
960 if (copy_from_user(reply
+ 2, user_msg
+ 2, sizeof(u32
) * 2)) {
962 "%s: Could not copy message context FROM user\n",
966 if (copy_to_user(user_reply
, reply
, reply_size
)) {
968 "%s: Could not copy reply TO user\n", c
->name
);
973 for (i
= 0; i
< sg_index
; i
++)
974 i2o_dma_free(&c
->pdev
->dev
, &sg_list
[i
]);
988 static long i2o_cfg_ioctl(struct file
*fp
, unsigned int cmd
, unsigned long arg
)
992 mutex_lock(&i2o_cfg_mutex
);
995 ret
= i2o_cfg_getiops(arg
);
999 ret
= i2o_cfg_gethrt(arg
);
1003 ret
= i2o_cfg_getlct(arg
);
1007 ret
= i2o_cfg_parms(arg
, I2OPARMSET
);
1011 ret
= i2o_cfg_parms(arg
, I2OPARMGET
);
1015 ret
= i2o_cfg_swdl(arg
);
1019 ret
= i2o_cfg_swul(arg
);
1023 ret
= i2o_cfg_swdel(arg
);
1027 ret
= i2o_cfg_validate(arg
);
1031 ret
= i2o_cfg_evt_reg(arg
, fp
);
1035 ret
= i2o_cfg_evt_get(arg
, fp
);
1038 #ifdef CONFIG_I2O_EXT_ADAPTEC
1040 ret
= i2o_cfg_passthru(arg
);
1045 osm_debug("unknown ioctl called!\n");
1048 mutex_unlock(&i2o_cfg_mutex
);
1052 static int cfg_open(struct inode
*inode
, struct file
*file
)
1054 struct i2o_cfg_info
*tmp
= kmalloc(sizeof(struct i2o_cfg_info
),
1056 unsigned long flags
;
1061 mutex_lock(&i2o_cfg_mutex
);
1062 file
->private_data
= (void *)(i2o_cfg_info_id
++);
1065 tmp
->q_id
= (ulong
) file
->private_data
;
1070 tmp
->next
= open_files
;
1072 spin_lock_irqsave(&i2o_config_lock
, flags
);
1074 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
1075 mutex_unlock(&i2o_cfg_mutex
);
1080 static int cfg_fasync(int fd
, struct file
*fp
, int on
)
1082 ulong id
= (ulong
) fp
->private_data
;
1083 struct i2o_cfg_info
*p
;
1086 mutex_lock(&i2o_cfg_mutex
);
1087 for (p
= open_files
; p
; p
= p
->next
)
1092 ret
= fasync_helper(fd
, fp
, on
, &p
->fasync
);
1093 mutex_unlock(&i2o_cfg_mutex
);
1097 static int cfg_release(struct inode
*inode
, struct file
*file
)
1099 ulong id
= (ulong
) file
->private_data
;
1100 struct i2o_cfg_info
*p
, **q
;
1101 unsigned long flags
;
1103 mutex_lock(&i2o_cfg_mutex
);
1104 spin_lock_irqsave(&i2o_config_lock
, flags
);
1105 for (q
= &open_files
; (p
= *q
) != NULL
; q
= &p
->next
) {
1106 if (p
->q_id
== id
) {
1112 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
1113 mutex_unlock(&i2o_cfg_mutex
);
1118 static const struct file_operations config_fops
= {
1119 .owner
= THIS_MODULE
,
1120 .llseek
= no_llseek
,
1121 .unlocked_ioctl
= i2o_cfg_ioctl
,
1122 #ifdef CONFIG_COMPAT
1123 .compat_ioctl
= i2o_cfg_compat_ioctl
,
1126 .release
= cfg_release
,
1127 .fasync
= cfg_fasync
,
1130 static struct miscdevice i2o_miscdev
= {
1136 static int __init
i2o_config_old_init(void)
1138 spin_lock_init(&i2o_config_lock
);
1140 if (misc_register(&i2o_miscdev
) < 0) {
1141 osm_err("can't register device.\n");
1148 static void i2o_config_old_exit(void)
1150 misc_deregister(&i2o_miscdev
);
1153 MODULE_AUTHOR("Red Hat Software");