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 #define OSM_NAME "config-osm"
52 #define OSM_VERSION "$Rev$"
53 #define OSM_DESCRIPTION "I2O Configuration OSM"
55 extern int i2o_parm_issue(struct i2o_device
*, int, void *, int, void *, int);
57 static spinlock_t i2o_config_lock
;
59 #define MODINC(x,y) ((x) = ((x) + 1) % (y))
61 struct sg_simple_element
{
68 struct fasync_struct
*fasync
;
69 struct i2o_evt_info event_q
[I2O_EVT_Q_LEN
];
70 u16 q_in
; // Queue head index
71 u16 q_out
; // Queue tail index
72 u16 q_len
; // Queue length
73 u16 q_lost
; // Number of lost events
74 ulong q_id
; // Event queue ID...used as tx_context
75 struct i2o_cfg_info
*next
;
77 static struct i2o_cfg_info
*open_files
= NULL
;
78 static ulong i2o_cfg_info_id
= 0;
81 * Each of these describes an i2o message handler. They are
82 * multiplexed by the i2o_core code
85 static struct i2o_driver i2o_config_driver
= {
89 static int i2o_cfg_getiops(unsigned long arg
)
91 struct i2o_controller
*c
;
92 u8 __user
*user_iop_table
= (void __user
*)arg
;
93 u8 tmp
[MAX_I2O_CONTROLLERS
];
96 memset(tmp
, 0, MAX_I2O_CONTROLLERS
);
98 list_for_each_entry(c
, &i2o_controllers
, list
)
101 if (copy_to_user(user_iop_table
, tmp
, MAX_I2O_CONTROLLERS
))
107 static int i2o_cfg_gethrt(unsigned long arg
)
109 struct i2o_controller
*c
;
110 struct i2o_cmd_hrtlct __user
*cmd
= (struct i2o_cmd_hrtlct __user
*)arg
;
111 struct i2o_cmd_hrtlct kcmd
;
117 if (copy_from_user(&kcmd
, cmd
, sizeof(struct i2o_cmd_hrtlct
)))
120 if (get_user(reslen
, kcmd
.reslen
) < 0)
123 if (kcmd
.resbuf
== NULL
)
126 c
= i2o_find_iop(kcmd
.iop
);
130 hrt
= (i2o_hrt
*) c
->hrt
.virt
;
132 len
= 8 + ((hrt
->entry_len
* hrt
->num_entries
) << 2);
134 /* We did a get user...so assuming mem is ok...is this bad? */
135 put_user(len
, kcmd
.reslen
);
138 if (copy_to_user(kcmd
.resbuf
, (void *)hrt
, len
))
144 static int i2o_cfg_getlct(unsigned long arg
)
146 struct i2o_controller
*c
;
147 struct i2o_cmd_hrtlct __user
*cmd
= (struct i2o_cmd_hrtlct __user
*)arg
;
148 struct i2o_cmd_hrtlct kcmd
;
154 if (copy_from_user(&kcmd
, cmd
, sizeof(struct i2o_cmd_hrtlct
)))
157 if (get_user(reslen
, kcmd
.reslen
) < 0)
160 if (kcmd
.resbuf
== NULL
)
163 c
= i2o_find_iop(kcmd
.iop
);
167 lct
= (i2o_lct
*) c
->lct
;
169 len
= (unsigned int)lct
->table_size
<< 2;
170 put_user(len
, kcmd
.reslen
);
173 else if (copy_to_user(kcmd
.resbuf
, lct
, len
))
179 static int i2o_cfg_parms(unsigned long arg
, unsigned int type
)
182 struct i2o_controller
*c
;
183 struct i2o_device
*dev
;
184 struct i2o_cmd_psetget __user
*cmd
=
185 (struct i2o_cmd_psetget __user
*)arg
;
186 struct i2o_cmd_psetget kcmd
;
192 u32 i2o_cmd
= (type
== I2OPARMGET
?
193 I2O_CMD_UTIL_PARAMS_GET
: I2O_CMD_UTIL_PARAMS_SET
);
195 if (copy_from_user(&kcmd
, cmd
, sizeof(struct i2o_cmd_psetget
)))
198 if (get_user(reslen
, kcmd
.reslen
))
201 c
= i2o_find_iop(kcmd
.iop
);
205 dev
= i2o_iop_find_device(c
, kcmd
.tid
);
209 ops
= (u8
*) kmalloc(kcmd
.oplen
, GFP_KERNEL
);
213 if (copy_from_user(ops
, kcmd
.opbuf
, kcmd
.oplen
)) {
219 * It's possible to have a _very_ large table
220 * and that the user asks for all of it at once...
222 res
= (u8
*) kmalloc(65536, GFP_KERNEL
);
228 len
= i2o_parm_issue(dev
, i2o_cmd
, ops
, kcmd
.oplen
, res
, 65536);
236 put_user(len
, kcmd
.reslen
);
239 else if (copy_to_user(kcmd
.resbuf
, res
, len
))
247 static int i2o_cfg_swdl(unsigned long arg
)
249 struct i2o_sw_xfer kxfer
;
250 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
251 unsigned char maxfrag
= 0, curfrag
= 1;
252 struct i2o_dma buffer
;
253 struct i2o_message __iomem
*msg
;
255 unsigned int status
= 0, swlen
= 0, fragsize
= 8192;
256 struct i2o_controller
*c
;
258 if (copy_from_user(&kxfer
, pxfer
, sizeof(struct i2o_sw_xfer
)))
261 if (get_user(swlen
, kxfer
.swlen
) < 0)
264 if (get_user(maxfrag
, kxfer
.maxfrag
) < 0)
267 if (get_user(curfrag
, kxfer
.curfrag
) < 0)
270 if (curfrag
== maxfrag
)
271 fragsize
= swlen
- (maxfrag
- 1) * 8192;
273 if (!kxfer
.buf
|| !access_ok(VERIFY_READ
, kxfer
.buf
, fragsize
))
276 c
= i2o_find_iop(kxfer
.iop
);
280 m
= i2o_msg_get_wait(c
, &msg
, I2O_TIMEOUT_MESSAGE_GET
);
281 if (m
== I2O_QUEUE_EMPTY
)
284 if (i2o_dma_alloc(&c
->pdev
->dev
, &buffer
, fragsize
, GFP_KERNEL
)) {
289 __copy_from_user(buffer
.virt
, kxfer
.buf
, fragsize
);
291 writel(NINE_WORD_MSG_SIZE
| SGL_OFFSET_7
, &msg
->u
.head
[0]);
292 writel(I2O_CMD_SW_DOWNLOAD
<< 24 | HOST_TID
<< 12 | ADAPTER_TID
,
294 writel(i2o_config_driver
.context
, &msg
->u
.head
[2]);
295 writel(0, &msg
->u
.head
[3]);
296 writel((((u32
) kxfer
.flags
) << 24) | (((u32
) kxfer
.sw_type
) << 16) |
297 (((u32
) maxfrag
) << 8) | (((u32
) curfrag
)), &msg
->body
[0]);
298 writel(swlen
, &msg
->body
[1]);
299 writel(kxfer
.sw_id
, &msg
->body
[2]);
300 writel(0xD0000000 | fragsize
, &msg
->body
[3]);
301 writel(buffer
.phys
, &msg
->body
[4]);
303 osm_debug("swdl frag %d/%d (size %d)\n", curfrag
, maxfrag
, fragsize
);
304 status
= i2o_msg_post_wait_mem(c
, m
, 60, &buffer
);
306 if (status
!= -ETIMEDOUT
)
307 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
309 if (status
!= I2O_POST_WAIT_OK
) {
310 // it fails if you try and send frags out of order
311 // and for some yet unknown reasons too
312 osm_info("swdl failed, DetailedStatus = %d\n", status
);
319 static int i2o_cfg_swul(unsigned long arg
)
321 struct i2o_sw_xfer kxfer
;
322 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
323 unsigned char maxfrag
= 0, curfrag
= 1;
324 struct i2o_dma buffer
;
325 struct i2o_message __iomem
*msg
;
327 unsigned int status
= 0, swlen
= 0, fragsize
= 8192;
328 struct i2o_controller
*c
;
331 if (copy_from_user(&kxfer
, pxfer
, sizeof(struct i2o_sw_xfer
)))
334 if (get_user(swlen
, kxfer
.swlen
) < 0)
337 if (get_user(maxfrag
, kxfer
.maxfrag
) < 0)
340 if (get_user(curfrag
, kxfer
.curfrag
) < 0)
343 if (curfrag
== maxfrag
)
344 fragsize
= swlen
- (maxfrag
- 1) * 8192;
349 c
= i2o_find_iop(kxfer
.iop
);
353 m
= i2o_msg_get_wait(c
, &msg
, I2O_TIMEOUT_MESSAGE_GET
);
354 if (m
== I2O_QUEUE_EMPTY
)
357 if (i2o_dma_alloc(&c
->pdev
->dev
, &buffer
, fragsize
, GFP_KERNEL
)) {
362 writel(NINE_WORD_MSG_SIZE
| SGL_OFFSET_7
, &msg
->u
.head
[0]);
363 writel(I2O_CMD_SW_UPLOAD
<< 24 | HOST_TID
<< 12 | ADAPTER_TID
,
365 writel(i2o_config_driver
.context
, &msg
->u
.head
[2]);
366 writel(0, &msg
->u
.head
[3]);
367 writel((u32
) kxfer
.flags
<< 24 | (u32
) kxfer
.
368 sw_type
<< 16 | (u32
) maxfrag
<< 8 | (u32
) curfrag
,
370 writel(swlen
, &msg
->body
[1]);
371 writel(kxfer
.sw_id
, &msg
->body
[2]);
372 writel(0xD0000000 | fragsize
, &msg
->body
[3]);
373 writel(buffer
.phys
, &msg
->body
[4]);
375 osm_debug("swul frag %d/%d (size %d)\n", curfrag
, maxfrag
, fragsize
);
376 status
= i2o_msg_post_wait_mem(c
, m
, 60, &buffer
);
378 if (status
!= I2O_POST_WAIT_OK
) {
379 if (status
!= -ETIMEDOUT
)
380 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
382 osm_info("swul failed, DetailedStatus = %d\n", status
);
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
) {
435 osm_info("swdel failed, DetailedStatus = %d\n", token
);
442 static int i2o_cfg_validate(unsigned long arg
)
446 struct i2o_message __iomem
*msg
;
448 struct i2o_controller
*c
;
450 c
= i2o_find_iop(iop
);
454 m
= i2o_msg_get_wait(c
, &msg
, I2O_TIMEOUT_MESSAGE_GET
);
455 if (m
== I2O_QUEUE_EMPTY
)
458 writel(FOUR_WORD_MSG_SIZE
| SGL_OFFSET_0
, &msg
->u
.head
[0]);
459 writel(I2O_CMD_CONFIG_VALIDATE
<< 24 | HOST_TID
<< 12 | iop
,
461 writel(i2o_config_driver
.context
, &msg
->u
.head
[2]);
462 writel(0, &msg
->u
.head
[3]);
464 token
= i2o_msg_post_wait(c
, m
, 10);
466 if (token
!= I2O_POST_WAIT_OK
) {
467 osm_info("Can't validate configuration, ErrorStatus = %d\n",
475 static int i2o_cfg_evt_reg(unsigned long arg
, struct file
*fp
)
477 struct i2o_message __iomem
*msg
;
479 struct i2o_evt_id __user
*pdesc
= (struct i2o_evt_id __user
*)arg
;
480 struct i2o_evt_id kdesc
;
481 struct i2o_controller
*c
;
482 struct i2o_device
*d
;
484 if (copy_from_user(&kdesc
, pdesc
, sizeof(struct i2o_evt_id
)))
488 c
= i2o_find_iop(kdesc
.iop
);
493 d
= i2o_iop_find_device(c
, kdesc
.tid
);
497 m
= i2o_msg_get_wait(c
, &msg
, I2O_TIMEOUT_MESSAGE_GET
);
498 if (m
== I2O_QUEUE_EMPTY
)
501 writel(FOUR_WORD_MSG_SIZE
| SGL_OFFSET_0
, &msg
->u
.head
[0]);
502 writel(I2O_CMD_UTIL_EVT_REGISTER
<< 24 | HOST_TID
<< 12 | kdesc
.tid
,
504 writel(i2o_config_driver
.context
, &msg
->u
.head
[2]);
505 writel(i2o_cntxt_list_add(c
, fp
->private_data
), &msg
->u
.head
[3]);
506 writel(kdesc
.evt_mask
, &msg
->body
[0]);
513 static int i2o_cfg_evt_get(unsigned long arg
, struct file
*fp
)
515 struct i2o_cfg_info
*p
= NULL
;
516 struct i2o_evt_get __user
*uget
= (struct i2o_evt_get __user
*)arg
;
517 struct i2o_evt_get kget
;
520 for (p
= open_files
; p
; p
= p
->next
)
521 if (p
->q_id
== (ulong
) fp
->private_data
)
527 memcpy(&kget
.info
, &p
->event_q
[p
->q_out
], sizeof(struct i2o_evt_info
));
528 MODINC(p
->q_out
, I2O_EVT_Q_LEN
);
529 spin_lock_irqsave(&i2o_config_lock
, flags
);
531 kget
.pending
= p
->q_len
;
532 kget
.lost
= p
->q_lost
;
533 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
535 if (copy_to_user(uget
, &kget
, sizeof(struct i2o_evt_get
)))
541 static int i2o_cfg_passthru32(unsigned fd
, unsigned cmnd
, unsigned long arg
,
544 struct i2o_cmd_passthru32 __user
*cmd
;
545 struct i2o_controller
*c
;
546 u32 __user
*user_msg
;
548 u32 __user
*user_reply
= NULL
;
552 struct i2o_dma sg_list
[SG_TABLESIZE
];
556 i2o_status_block
*sb
;
557 struct i2o_message
*msg
;
561 cmd
= (struct i2o_cmd_passthru32 __user
*)arg
;
563 if (get_user(iop
, &cmd
->iop
) || get_user(i
, &cmd
->msg
))
566 user_msg
= compat_ptr(i
);
568 c
= i2o_find_iop(iop
);
570 osm_debug("controller %d not found\n", iop
);
574 m
= i2o_msg_get_wait(c
, &msg
, I2O_TIMEOUT_MESSAGE_GET
);
576 sb
= c
->status_block
.virt
;
578 if (get_user(size
, &user_msg
[0])) {
579 osm_warn("unable to get size!\n");
584 if (size
> sb
->inbound_frame_size
) {
585 osm_warn("size of message > inbound_frame_size");
589 user_reply
= &user_msg
[size
];
591 size
<<= 2; // Convert to bytes
593 /* Copy in the user's I2O command */
594 if (copy_from_user(msg
, user_msg
, size
)) {
595 osm_warn("unable to copy user message\n");
598 i2o_dump_message(msg
);
600 if (get_user(reply_size
, &user_reply
[0]) < 0)
606 reply
= kmalloc(reply_size
, GFP_KERNEL
);
608 printk(KERN_WARNING
"%s: Could not allocate reply buffer\n",
612 memset(reply
, 0, reply_size
);
614 sg_offset
= (msg
->u
.head
[0] >> 4) & 0x0f;
616 writel(i2o_config_driver
.context
, &msg
->u
.s
.icntxt
);
617 writel(i2o_cntxt_list_add(c
, reply
), &msg
->u
.s
.tcntxt
);
619 memset(sg_list
, 0, sizeof(sg_list
[0]) * SG_TABLESIZE
);
621 struct sg_simple_element
*sg
;
623 if (sg_offset
* 4 >= size
) {
628 sg
= (struct sg_simple_element
*)((&msg
->u
.head
[0]) +
631 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
632 if (sg_count
> SG_TABLESIZE
) {
633 printk(KERN_DEBUG
"%s:IOCTL SG List too large (%u)\n",
639 for (i
= 0; i
< sg_count
; i
++) {
643 if (!(sg
[i
].flag_count
& 0x10000000
644 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
646 "%s:Bad SG element %d - not simple (%x)\n",
647 c
->name
, i
, sg
[i
].flag_count
);
651 sg_size
= sg
[i
].flag_count
& 0xffffff;
653 /* Allocate memory for the transfer */
655 (&c
->pdev
->dev
, p
, sg_size
,
656 PCI_DMA_BIDIRECTIONAL
)) {
658 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
659 c
->name
, sg_size
, i
, sg_count
);
663 /* Copy in the user's SG buffer if necessary */
665 flag_count
& 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
668 (p
->virt
, (void __user
*)(unsigned long)sg
[i
].addr_bus
,
671 "%s: Could not copy SG buf %d FROM user\n",
678 sg
[i
].addr_bus
= (u32
) p
->phys
;
682 rcode
= i2o_msg_post_wait(c
, m
, 60);
688 /* Copy back the Scatter Gather buffers back to user space */
691 struct sg_simple_element
*sg
;
694 // re-acquire the original message to handle correctly the sg copy operation
695 memset(&msg
, 0, MSG_FRAME_SIZE
* 4);
696 // get user msg size in u32s
697 if (get_user(size
, &user_msg
[0])) {
703 /* Copy in the user's I2O command */
704 if (copy_from_user(msg
, user_msg
, size
)) {
709 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
712 sg
= (struct sg_simple_element
*)(msg
+ sg_offset
);
713 for (j
= 0; j
< sg_count
; j
++) {
714 /* Copy out the SG list to user's buffer if necessary */
717 flag_count
& 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
718 sg_size
= sg
[j
].flag_count
& 0xffffff;
721 ((void __user
*)(u64
) sg
[j
].addr_bus
,
722 sg_list
[j
].virt
, sg_size
)) {
724 "%s: Could not copy %p TO user %x\n",
725 c
->name
, sg_list
[j
].virt
,
734 /* Copy back the reply to user space */
736 // we wrote our own values for context - now restore the user supplied ones
737 if (copy_from_user(reply
+ 2, user_msg
+ 2, sizeof(u32
) * 2)) {
739 "%s: Could not copy message context FROM user\n",
743 if (copy_to_user(user_reply
, reply
, reply_size
)) {
745 "%s: Could not copy reply TO user\n", c
->name
);
757 static int i2o_cfg_passthru(unsigned long arg
)
759 struct i2o_cmd_passthru __user
*cmd
=
760 (struct i2o_cmd_passthru __user
*)arg
;
761 struct i2o_controller
*c
;
762 u32 __user
*user_msg
;
764 u32 __user
*user_reply
= NULL
;
768 void *sg_list
[SG_TABLESIZE
];
774 i2o_status_block
*sb
;
775 struct i2o_message __iomem
*msg
;
779 if (get_user(iop
, &cmd
->iop
) || get_user(user_msg
, &cmd
->msg
))
782 c
= i2o_find_iop(iop
);
784 osm_warn("controller %d not found\n", iop
);
788 m
= i2o_msg_get_wait(c
, &msg
, I2O_TIMEOUT_MESSAGE_GET
);
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 /* Copy in the user's I2O command */
806 if (copy_from_user(msg
, user_msg
, size
))
809 if (get_user(reply_size
, &user_reply
[0]) < 0)
815 reply
= kmalloc(reply_size
, GFP_KERNEL
);
817 printk(KERN_WARNING
"%s: Could not allocate reply buffer\n",
821 memset(reply
, 0, reply_size
);
823 sg_offset
= (msg
->u
.head
[0] >> 4) & 0x0f;
825 writel(i2o_config_driver
.context
, &msg
->u
.s
.icntxt
);
826 writel(i2o_cntxt_list_add(c
, reply
), &msg
->u
.s
.tcntxt
);
828 memset(sg_list
, 0, sizeof(sg_list
[0]) * SG_TABLESIZE
);
830 struct sg_simple_element
*sg
;
832 if (sg_offset
* 4 >= size
) {
837 sg
= (struct sg_simple_element
*)((&msg
->u
.head
[0]) +
840 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
841 if (sg_count
> SG_TABLESIZE
) {
842 printk(KERN_DEBUG
"%s:IOCTL SG List too large (%u)\n",
848 for (i
= 0; i
< sg_count
; i
++) {
851 if (!(sg
[i
].flag_count
& 0x10000000
852 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
854 "%s:Bad SG element %d - not simple (%x)\n",
855 c
->name
, i
, sg
[i
].flag_count
);
859 sg_size
= sg
[i
].flag_count
& 0xffffff;
860 /* Allocate memory for the transfer */
861 p
= kmalloc(sg_size
, GFP_KERNEL
);
864 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
865 c
->name
, sg_size
, i
, sg_count
);
869 sg_list
[sg_index
++] = p
; // sglist indexed with input frame, not our internal frame.
870 /* Copy in the user's SG buffer if necessary */
872 flag_count
& 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
875 (p
, (void __user
*)sg
[i
].addr_bus
,
878 "%s: Could not copy SG buf %d FROM user\n",
885 sg
[i
].addr_bus
= virt_to_bus(p
);
889 rcode
= i2o_msg_post_wait(c
, m
, 60);
895 /* Copy back the Scatter Gather buffers back to user space */
898 struct sg_simple_element
*sg
;
901 // re-acquire the original message to handle correctly the sg copy operation
902 memset(&msg
, 0, MSG_FRAME_SIZE
* 4);
903 // get user msg size in u32s
904 if (get_user(size
, &user_msg
[0])) {
910 /* Copy in the user's I2O command */
911 if (copy_from_user(msg
, user_msg
, size
)) {
916 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
919 sg
= (struct sg_simple_element
*)(msg
+ sg_offset
);
920 for (j
= 0; j
< sg_count
; j
++) {
921 /* Copy out the SG list to user's buffer if necessary */
924 flag_count
& 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
925 sg_size
= sg
[j
].flag_count
& 0xffffff;
928 ((void __user
*)sg
[j
].addr_bus
, sg_list
[j
],
931 "%s: Could not copy %p TO user %x\n",
941 /* Copy back the reply to user space */
943 // we wrote our own values for context - now restore the user supplied ones
944 if (copy_from_user(reply
+ 2, user_msg
+ 2, sizeof(u32
) * 2)) {
946 "%s: Could not copy message context FROM user\n",
950 if (copy_to_user(user_reply
, reply
, reply_size
)) {
952 "%s: Could not copy reply TO user\n", c
->name
);
966 static int i2o_cfg_ioctl(struct inode
*inode
, struct file
*fp
, unsigned int cmd
,
973 ret
= i2o_cfg_getiops(arg
);
977 ret
= i2o_cfg_gethrt(arg
);
981 ret
= i2o_cfg_getlct(arg
);
985 ret
= i2o_cfg_parms(arg
, I2OPARMSET
);
989 ret
= i2o_cfg_parms(arg
, I2OPARMGET
);
993 ret
= i2o_cfg_swdl(arg
);
997 ret
= i2o_cfg_swul(arg
);
1001 ret
= i2o_cfg_swdel(arg
);
1005 ret
= i2o_cfg_validate(arg
);
1009 ret
= i2o_cfg_evt_reg(arg
, fp
);
1013 ret
= i2o_cfg_evt_get(arg
, fp
);
1016 #ifndef CONFIG_COMPAT
1018 ret
= i2o_cfg_passthru(arg
);
1023 osm_debug("unknown ioctl called!\n");
1030 static int cfg_open(struct inode
*inode
, struct file
*file
)
1032 struct i2o_cfg_info
*tmp
=
1033 (struct i2o_cfg_info
*)kmalloc(sizeof(struct i2o_cfg_info
),
1035 unsigned long flags
;
1040 file
->private_data
= (void *)(i2o_cfg_info_id
++);
1043 tmp
->q_id
= (ulong
) file
->private_data
;
1048 tmp
->next
= open_files
;
1050 spin_lock_irqsave(&i2o_config_lock
, flags
);
1052 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
1057 static int cfg_fasync(int fd
, struct file
*fp
, int on
)
1059 ulong id
= (ulong
) fp
->private_data
;
1060 struct i2o_cfg_info
*p
;
1062 for (p
= open_files
; p
; p
= p
->next
)
1069 return fasync_helper(fd
, fp
, on
, &p
->fasync
);
1072 static int cfg_release(struct inode
*inode
, struct file
*file
)
1074 ulong id
= (ulong
) file
->private_data
;
1075 struct i2o_cfg_info
*p1
, *p2
;
1076 unsigned long flags
;
1081 spin_lock_irqsave(&i2o_config_lock
, flags
);
1082 for (p1
= open_files
; p1
;) {
1083 if (p1
->q_id
== id
) {
1086 cfg_fasync(-1, file
, 0);
1088 p2
->next
= p1
->next
;
1090 open_files
= p1
->next
;
1098 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
1104 static struct file_operations config_fops
= {
1105 .owner
= THIS_MODULE
,
1106 .llseek
= no_llseek
,
1107 .ioctl
= i2o_cfg_ioctl
,
1109 .release
= cfg_release
,
1110 .fasync
= cfg_fasync
,
1113 static struct miscdevice i2o_miscdev
= {
1119 static int __init
i2o_config_init(void)
1121 printk(KERN_INFO OSM_DESCRIPTION
" v" OSM_VERSION
"\n");
1123 spin_lock_init(&i2o_config_lock
);
1125 if (misc_register(&i2o_miscdev
) < 0) {
1126 osm_err("can't register device.\n");
1130 * Install our handler
1132 if (i2o_driver_register(&i2o_config_driver
)) {
1133 osm_err("handler register failed.\n");
1134 misc_deregister(&i2o_miscdev
);
1137 #ifdef CONFIG_COMPAT
1138 register_ioctl32_conversion(I2OPASSTHRU32
, i2o_cfg_passthru32
);
1139 register_ioctl32_conversion(I2OGETIOPS
, (void *)sys_ioctl
);
1144 static void i2o_config_exit(void)
1146 #ifdef CONFIG_COMPAT
1147 unregister_ioctl32_conversion(I2OPASSTHRU32
);
1148 unregister_ioctl32_conversion(I2OGETIOPS
);
1150 misc_deregister(&i2o_miscdev
);
1151 i2o_driver_unregister(&i2o_config_driver
);
1154 MODULE_AUTHOR("Red Hat Software");
1155 MODULE_LICENSE("GPL");
1156 MODULE_DESCRIPTION(OSM_DESCRIPTION
);
1157 MODULE_VERSION(OSM_VERSION
);
1159 module_init(i2o_config_init
);
1160 module_exit(i2o_config_exit
);