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 int i2o_cfg_ioctl(struct inode
*inode
, struct file
*fp
, unsigned int cmd
,
60 static spinlock_t i2o_config_lock
;
62 #define MODINC(x,y) ((x) = ((x) + 1) % (y))
64 struct sg_simple_element
{
71 struct fasync_struct
*fasync
;
72 struct i2o_evt_info event_q
[I2O_EVT_Q_LEN
];
73 u16 q_in
; // Queue head index
74 u16 q_out
; // Queue tail index
75 u16 q_len
; // Queue length
76 u16 q_lost
; // Number of lost events
77 ulong q_id
; // Event queue ID...used as tx_context
78 struct i2o_cfg_info
*next
;
80 static struct i2o_cfg_info
*open_files
= NULL
;
81 static ulong i2o_cfg_info_id
= 0;
84 * Each of these describes an i2o message handler. They are
85 * multiplexed by the i2o_core code
88 static struct i2o_driver i2o_config_driver
= {
92 static int i2o_cfg_getiops(unsigned long arg
)
94 struct i2o_controller
*c
;
95 u8 __user
*user_iop_table
= (void __user
*)arg
;
96 u8 tmp
[MAX_I2O_CONTROLLERS
];
99 memset(tmp
, 0, MAX_I2O_CONTROLLERS
);
101 list_for_each_entry(c
, &i2o_controllers
, list
)
104 if (copy_to_user(user_iop_table
, tmp
, MAX_I2O_CONTROLLERS
))
110 static int i2o_cfg_gethrt(unsigned long arg
)
112 struct i2o_controller
*c
;
113 struct i2o_cmd_hrtlct __user
*cmd
= (struct i2o_cmd_hrtlct __user
*)arg
;
114 struct i2o_cmd_hrtlct kcmd
;
120 if (copy_from_user(&kcmd
, cmd
, sizeof(struct i2o_cmd_hrtlct
)))
123 if (get_user(reslen
, kcmd
.reslen
) < 0)
126 if (kcmd
.resbuf
== NULL
)
129 c
= i2o_find_iop(kcmd
.iop
);
133 hrt
= (i2o_hrt
*) c
->hrt
.virt
;
135 len
= 8 + ((hrt
->entry_len
* hrt
->num_entries
) << 2);
137 /* We did a get user...so assuming mem is ok...is this bad? */
138 put_user(len
, kcmd
.reslen
);
141 if (copy_to_user(kcmd
.resbuf
, (void *)hrt
, len
))
147 static int i2o_cfg_getlct(unsigned long arg
)
149 struct i2o_controller
*c
;
150 struct i2o_cmd_hrtlct __user
*cmd
= (struct i2o_cmd_hrtlct __user
*)arg
;
151 struct i2o_cmd_hrtlct kcmd
;
157 if (copy_from_user(&kcmd
, cmd
, sizeof(struct i2o_cmd_hrtlct
)))
160 if (get_user(reslen
, kcmd
.reslen
) < 0)
163 if (kcmd
.resbuf
== NULL
)
166 c
= i2o_find_iop(kcmd
.iop
);
170 lct
= (i2o_lct
*) c
->lct
;
172 len
= (unsigned int)lct
->table_size
<< 2;
173 put_user(len
, kcmd
.reslen
);
176 else if (copy_to_user(kcmd
.resbuf
, lct
, len
))
182 static int i2o_cfg_parms(unsigned long arg
, unsigned int type
)
185 struct i2o_controller
*c
;
186 struct i2o_device
*dev
;
187 struct i2o_cmd_psetget __user
*cmd
=
188 (struct i2o_cmd_psetget __user
*)arg
;
189 struct i2o_cmd_psetget kcmd
;
195 u32 i2o_cmd
= (type
== I2OPARMGET
?
196 I2O_CMD_UTIL_PARAMS_GET
: I2O_CMD_UTIL_PARAMS_SET
);
198 if (copy_from_user(&kcmd
, cmd
, sizeof(struct i2o_cmd_psetget
)))
201 if (get_user(reslen
, kcmd
.reslen
))
204 c
= i2o_find_iop(kcmd
.iop
);
208 dev
= i2o_iop_find_device(c
, kcmd
.tid
);
212 ops
= (u8
*) kmalloc(kcmd
.oplen
, GFP_KERNEL
);
216 if (copy_from_user(ops
, kcmd
.opbuf
, kcmd
.oplen
)) {
222 * It's possible to have a _very_ large table
223 * and that the user asks for all of it at once...
225 res
= (u8
*) kmalloc(65536, GFP_KERNEL
);
231 len
= i2o_parm_issue(dev
, i2o_cmd
, ops
, kcmd
.oplen
, res
, 65536);
239 put_user(len
, kcmd
.reslen
);
242 else if (copy_to_user(kcmd
.resbuf
, res
, len
))
250 static int i2o_cfg_swdl(unsigned long arg
)
252 struct i2o_sw_xfer kxfer
;
253 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
254 unsigned char maxfrag
= 0, curfrag
= 1;
255 struct i2o_dma buffer
;
256 struct i2o_message __iomem
*msg
;
258 unsigned int status
= 0, swlen
= 0, fragsize
= 8192;
259 struct i2o_controller
*c
;
261 if (copy_from_user(&kxfer
, pxfer
, sizeof(struct i2o_sw_xfer
)))
264 if (get_user(swlen
, kxfer
.swlen
) < 0)
267 if (get_user(maxfrag
, kxfer
.maxfrag
) < 0)
270 if (get_user(curfrag
, kxfer
.curfrag
) < 0)
273 if (curfrag
== maxfrag
)
274 fragsize
= swlen
- (maxfrag
- 1) * 8192;
276 if (!kxfer
.buf
|| !access_ok(VERIFY_READ
, kxfer
.buf
, fragsize
))
279 c
= i2o_find_iop(kxfer
.iop
);
283 m
= i2o_msg_get_wait(c
, &msg
, I2O_TIMEOUT_MESSAGE_GET
);
284 if (m
== I2O_QUEUE_EMPTY
)
287 if (i2o_dma_alloc(&c
->pdev
->dev
, &buffer
, fragsize
, GFP_KERNEL
)) {
292 __copy_from_user(buffer
.virt
, kxfer
.buf
, fragsize
);
294 writel(NINE_WORD_MSG_SIZE
| SGL_OFFSET_7
, &msg
->u
.head
[0]);
295 writel(I2O_CMD_SW_DOWNLOAD
<< 24 | HOST_TID
<< 12 | ADAPTER_TID
,
297 writel(i2o_config_driver
.context
, &msg
->u
.head
[2]);
298 writel(0, &msg
->u
.head
[3]);
299 writel((((u32
) kxfer
.flags
) << 24) | (((u32
) kxfer
.sw_type
) << 16) |
300 (((u32
) maxfrag
) << 8) | (((u32
) curfrag
)), &msg
->body
[0]);
301 writel(swlen
, &msg
->body
[1]);
302 writel(kxfer
.sw_id
, &msg
->body
[2]);
303 writel(0xD0000000 | fragsize
, &msg
->body
[3]);
304 writel(buffer
.phys
, &msg
->body
[4]);
306 osm_debug("swdl frag %d/%d (size %d)\n", curfrag
, maxfrag
, fragsize
);
307 status
= i2o_msg_post_wait_mem(c
, m
, 60, &buffer
);
309 if (status
!= -ETIMEDOUT
)
310 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
312 if (status
!= I2O_POST_WAIT_OK
) {
313 // it fails if you try and send frags out of order
314 // and for some yet unknown reasons too
315 osm_info("swdl failed, DetailedStatus = %d\n", status
);
322 static int i2o_cfg_swul(unsigned long arg
)
324 struct i2o_sw_xfer kxfer
;
325 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
326 unsigned char maxfrag
= 0, curfrag
= 1;
327 struct i2o_dma buffer
;
328 struct i2o_message __iomem
*msg
;
330 unsigned int status
= 0, swlen
= 0, fragsize
= 8192;
331 struct i2o_controller
*c
;
334 if (copy_from_user(&kxfer
, pxfer
, sizeof(struct i2o_sw_xfer
)))
337 if (get_user(swlen
, kxfer
.swlen
) < 0)
340 if (get_user(maxfrag
, kxfer
.maxfrag
) < 0)
343 if (get_user(curfrag
, kxfer
.curfrag
) < 0)
346 if (curfrag
== maxfrag
)
347 fragsize
= swlen
- (maxfrag
- 1) * 8192;
352 c
= i2o_find_iop(kxfer
.iop
);
356 m
= i2o_msg_get_wait(c
, &msg
, I2O_TIMEOUT_MESSAGE_GET
);
357 if (m
== I2O_QUEUE_EMPTY
)
360 if (i2o_dma_alloc(&c
->pdev
->dev
, &buffer
, fragsize
, GFP_KERNEL
)) {
365 writel(NINE_WORD_MSG_SIZE
| SGL_OFFSET_7
, &msg
->u
.head
[0]);
366 writel(I2O_CMD_SW_UPLOAD
<< 24 | HOST_TID
<< 12 | ADAPTER_TID
,
368 writel(i2o_config_driver
.context
, &msg
->u
.head
[2]);
369 writel(0, &msg
->u
.head
[3]);
370 writel((u32
) kxfer
.flags
<< 24 | (u32
) kxfer
.
371 sw_type
<< 16 | (u32
) maxfrag
<< 8 | (u32
) curfrag
,
373 writel(swlen
, &msg
->body
[1]);
374 writel(kxfer
.sw_id
, &msg
->body
[2]);
375 writel(0xD0000000 | fragsize
, &msg
->body
[3]);
376 writel(buffer
.phys
, &msg
->body
[4]);
378 osm_debug("swul frag %d/%d (size %d)\n", curfrag
, maxfrag
, fragsize
);
379 status
= i2o_msg_post_wait_mem(c
, m
, 60, &buffer
);
381 if (status
!= I2O_POST_WAIT_OK
) {
382 if (status
!= -ETIMEDOUT
)
383 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
385 osm_info("swul failed, DetailedStatus = %d\n", status
);
389 if (copy_to_user(kxfer
.buf
, buffer
.virt
, fragsize
))
392 i2o_dma_free(&c
->pdev
->dev
, &buffer
);
401 static int i2o_cfg_swdel(unsigned long arg
)
403 struct i2o_controller
*c
;
404 struct i2o_sw_xfer kxfer
;
405 struct i2o_sw_xfer __user
*pxfer
= (struct i2o_sw_xfer __user
*)arg
;
406 struct i2o_message __iomem
*msg
;
411 if (copy_from_user(&kxfer
, pxfer
, sizeof(struct i2o_sw_xfer
)))
414 if (get_user(swlen
, kxfer
.swlen
) < 0)
417 c
= i2o_find_iop(kxfer
.iop
);
421 m
= i2o_msg_get_wait(c
, &msg
, I2O_TIMEOUT_MESSAGE_GET
);
422 if (m
== I2O_QUEUE_EMPTY
)
425 writel(SEVEN_WORD_MSG_SIZE
| SGL_OFFSET_0
, &msg
->u
.head
[0]);
426 writel(I2O_CMD_SW_REMOVE
<< 24 | HOST_TID
<< 12 | ADAPTER_TID
,
428 writel(i2o_config_driver
.context
, &msg
->u
.head
[2]);
429 writel(0, &msg
->u
.head
[3]);
430 writel((u32
) kxfer
.flags
<< 24 | (u32
) kxfer
.sw_type
<< 16,
432 writel(swlen
, &msg
->body
[1]);
433 writel(kxfer
.sw_id
, &msg
->body
[2]);
435 token
= i2o_msg_post_wait(c
, m
, 10);
437 if (token
!= I2O_POST_WAIT_OK
) {
438 osm_info("swdel failed, DetailedStatus = %d\n", token
);
445 static int i2o_cfg_validate(unsigned long arg
)
449 struct i2o_message __iomem
*msg
;
451 struct i2o_controller
*c
;
453 c
= i2o_find_iop(iop
);
457 m
= i2o_msg_get_wait(c
, &msg
, I2O_TIMEOUT_MESSAGE_GET
);
458 if (m
== I2O_QUEUE_EMPTY
)
461 writel(FOUR_WORD_MSG_SIZE
| SGL_OFFSET_0
, &msg
->u
.head
[0]);
462 writel(I2O_CMD_CONFIG_VALIDATE
<< 24 | HOST_TID
<< 12 | iop
,
464 writel(i2o_config_driver
.context
, &msg
->u
.head
[2]);
465 writel(0, &msg
->u
.head
[3]);
467 token
= i2o_msg_post_wait(c
, m
, 10);
469 if (token
!= I2O_POST_WAIT_OK
) {
470 osm_info("Can't validate configuration, ErrorStatus = %d\n",
478 static int i2o_cfg_evt_reg(unsigned long arg
, struct file
*fp
)
480 struct i2o_message __iomem
*msg
;
482 struct i2o_evt_id __user
*pdesc
= (struct i2o_evt_id __user
*)arg
;
483 struct i2o_evt_id kdesc
;
484 struct i2o_controller
*c
;
485 struct i2o_device
*d
;
487 if (copy_from_user(&kdesc
, pdesc
, sizeof(struct i2o_evt_id
)))
491 c
= i2o_find_iop(kdesc
.iop
);
496 d
= i2o_iop_find_device(c
, kdesc
.tid
);
500 m
= i2o_msg_get_wait(c
, &msg
, I2O_TIMEOUT_MESSAGE_GET
);
501 if (m
== I2O_QUEUE_EMPTY
)
504 writel(FOUR_WORD_MSG_SIZE
| SGL_OFFSET_0
, &msg
->u
.head
[0]);
505 writel(I2O_CMD_UTIL_EVT_REGISTER
<< 24 | HOST_TID
<< 12 | kdesc
.tid
,
507 writel(i2o_config_driver
.context
, &msg
->u
.head
[2]);
508 writel(i2o_cntxt_list_add(c
, fp
->private_data
), &msg
->u
.head
[3]);
509 writel(kdesc
.evt_mask
, &msg
->body
[0]);
516 static int i2o_cfg_evt_get(unsigned long arg
, struct file
*fp
)
518 struct i2o_cfg_info
*p
= NULL
;
519 struct i2o_evt_get __user
*uget
= (struct i2o_evt_get __user
*)arg
;
520 struct i2o_evt_get kget
;
523 for (p
= open_files
; p
; p
= p
->next
)
524 if (p
->q_id
== (ulong
) fp
->private_data
)
530 memcpy(&kget
.info
, &p
->event_q
[p
->q_out
], sizeof(struct i2o_evt_info
));
531 MODINC(p
->q_out
, I2O_EVT_Q_LEN
);
532 spin_lock_irqsave(&i2o_config_lock
, flags
);
534 kget
.pending
= p
->q_len
;
535 kget
.lost
= p
->q_lost
;
536 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
538 if (copy_to_user(uget
, &kget
, sizeof(struct i2o_evt_get
)))
544 static int i2o_cfg_passthru32(struct file
*file
, unsigned cmnd
, unsigned long arg
)
546 struct i2o_cmd_passthru32 __user
*cmd
;
547 struct i2o_controller
*c
;
548 u32 __user
*user_msg
;
550 u32 __user
*user_reply
= NULL
;
554 struct i2o_dma sg_list
[SG_TABLESIZE
];
558 i2o_status_block
*sb
;
559 struct i2o_message
*msg
;
563 cmd
= (struct i2o_cmd_passthru32 __user
*)arg
;
565 if (get_user(iop
, &cmd
->iop
) || get_user(i
, &cmd
->msg
))
568 user_msg
= compat_ptr(i
);
570 c
= i2o_find_iop(iop
);
572 osm_debug("controller %d not found\n", iop
);
576 m
= i2o_msg_get_wait(c
, &msg
, I2O_TIMEOUT_MESSAGE_GET
);
578 sb
= c
->status_block
.virt
;
580 if (get_user(size
, &user_msg
[0])) {
581 osm_warn("unable to get size!\n");
586 if (size
> sb
->inbound_frame_size
) {
587 osm_warn("size of message > inbound_frame_size");
591 user_reply
= &user_msg
[size
];
593 size
<<= 2; // Convert to bytes
595 /* Copy in the user's I2O command */
596 if (copy_from_user(msg
, user_msg
, size
)) {
597 osm_warn("unable to copy user message\n");
600 i2o_dump_message(msg
);
602 if (get_user(reply_size
, &user_reply
[0]) < 0)
608 reply
= kmalloc(reply_size
, GFP_KERNEL
);
610 printk(KERN_WARNING
"%s: Could not allocate reply buffer\n",
614 memset(reply
, 0, reply_size
);
616 sg_offset
= (msg
->u
.head
[0] >> 4) & 0x0f;
618 writel(i2o_config_driver
.context
, &msg
->u
.s
.icntxt
);
619 writel(i2o_cntxt_list_add(c
, reply
), &msg
->u
.s
.tcntxt
);
621 memset(sg_list
, 0, sizeof(sg_list
[0]) * SG_TABLESIZE
);
623 struct sg_simple_element
*sg
;
625 if (sg_offset
* 4 >= size
) {
630 sg
= (struct sg_simple_element
*)((&msg
->u
.head
[0]) +
633 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
634 if (sg_count
> SG_TABLESIZE
) {
635 printk(KERN_DEBUG
"%s:IOCTL SG List too large (%u)\n",
641 for (i
= 0; i
< sg_count
; i
++) {
645 if (!(sg
[i
].flag_count
& 0x10000000
646 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
648 "%s:Bad SG element %d - not simple (%x)\n",
649 c
->name
, i
, sg
[i
].flag_count
);
653 sg_size
= sg
[i
].flag_count
& 0xffffff;
655 /* Allocate memory for the transfer */
657 (&c
->pdev
->dev
, p
, sg_size
,
658 PCI_DMA_BIDIRECTIONAL
)) {
660 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
661 c
->name
, sg_size
, i
, sg_count
);
665 /* Copy in the user's SG buffer if necessary */
667 flag_count
& 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
670 (p
->virt
, (void __user
*)(unsigned long)sg
[i
].addr_bus
,
673 "%s: Could not copy SG buf %d FROM user\n",
680 sg
[i
].addr_bus
= (u32
) p
->phys
;
684 rcode
= i2o_msg_post_wait(c
, m
, 60);
690 /* Copy back the Scatter Gather buffers back to user space */
693 struct sg_simple_element
*sg
;
696 // re-acquire the original message to handle correctly the sg copy operation
697 memset(&msg
, 0, MSG_FRAME_SIZE
* 4);
698 // get user msg size in u32s
699 if (get_user(size
, &user_msg
[0])) {
705 /* Copy in the user's I2O command */
706 if (copy_from_user(msg
, user_msg
, size
)) {
711 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
714 sg
= (struct sg_simple_element
*)(msg
+ sg_offset
);
715 for (j
= 0; j
< sg_count
; j
++) {
716 /* Copy out the SG list to user's buffer if necessary */
719 flag_count
& 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
720 sg_size
= sg
[j
].flag_count
& 0xffffff;
723 ((void __user
*)(u64
) sg
[j
].addr_bus
,
724 sg_list
[j
].virt
, sg_size
)) {
726 "%s: Could not copy %p TO user %x\n",
727 c
->name
, sg_list
[j
].virt
,
736 /* Copy back the reply to user space */
738 // we wrote our own values for context - now restore the user supplied ones
739 if (copy_from_user(reply
+ 2, user_msg
+ 2, sizeof(u32
) * 2)) {
741 "%s: Could not copy message context FROM user\n",
745 if (copy_to_user(user_reply
, reply
, reply_size
)) {
747 "%s: Could not copy reply TO user\n", c
->name
);
757 static long i2o_cfg_compat_ioctl(struct file
*file
, unsigned cmd
, unsigned long arg
)
763 ret
= i2o_cfg_ioctl(NULL
, file
, cmd
, arg
);
766 ret
= i2o_cfg_passthru32(file
, cmd
, arg
);
778 static int i2o_cfg_passthru(unsigned long arg
)
780 struct i2o_cmd_passthru __user
*cmd
=
781 (struct i2o_cmd_passthru __user
*)arg
;
782 struct i2o_controller
*c
;
783 u32 __user
*user_msg
;
785 u32 __user
*user_reply
= NULL
;
789 void *sg_list
[SG_TABLESIZE
];
795 i2o_status_block
*sb
;
796 struct i2o_message __iomem
*msg
;
800 if (get_user(iop
, &cmd
->iop
) || get_user(user_msg
, &cmd
->msg
))
803 c
= i2o_find_iop(iop
);
805 osm_warn("controller %d not found\n", iop
);
809 m
= i2o_msg_get_wait(c
, &msg
, I2O_TIMEOUT_MESSAGE_GET
);
811 sb
= c
->status_block
.virt
;
813 if (get_user(size
, &user_msg
[0]))
817 if (size
> sb
->inbound_frame_size
) {
818 osm_warn("size of message > inbound_frame_size");
822 user_reply
= &user_msg
[size
];
824 size
<<= 2; // Convert to bytes
826 /* Copy in the user's I2O command */
827 if (copy_from_user(msg
, user_msg
, size
))
830 if (get_user(reply_size
, &user_reply
[0]) < 0)
836 reply
= kmalloc(reply_size
, GFP_KERNEL
);
838 printk(KERN_WARNING
"%s: Could not allocate reply buffer\n",
842 memset(reply
, 0, reply_size
);
844 sg_offset
= (msg
->u
.head
[0] >> 4) & 0x0f;
846 writel(i2o_config_driver
.context
, &msg
->u
.s
.icntxt
);
847 writel(i2o_cntxt_list_add(c
, reply
), &msg
->u
.s
.tcntxt
);
849 memset(sg_list
, 0, sizeof(sg_list
[0]) * SG_TABLESIZE
);
851 struct sg_simple_element
*sg
;
853 if (sg_offset
* 4 >= size
) {
858 sg
= (struct sg_simple_element
*)((&msg
->u
.head
[0]) +
861 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
862 if (sg_count
> SG_TABLESIZE
) {
863 printk(KERN_DEBUG
"%s:IOCTL SG List too large (%u)\n",
869 for (i
= 0; i
< sg_count
; i
++) {
872 if (!(sg
[i
].flag_count
& 0x10000000
873 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
875 "%s:Bad SG element %d - not simple (%x)\n",
876 c
->name
, i
, sg
[i
].flag_count
);
880 sg_size
= sg
[i
].flag_count
& 0xffffff;
881 /* Allocate memory for the transfer */
882 p
= kmalloc(sg_size
, GFP_KERNEL
);
885 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
886 c
->name
, sg_size
, i
, sg_count
);
890 sg_list
[sg_index
++] = p
; // sglist indexed with input frame, not our internal frame.
891 /* Copy in the user's SG buffer if necessary */
893 flag_count
& 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
896 (p
, (void __user
*)sg
[i
].addr_bus
,
899 "%s: Could not copy SG buf %d FROM user\n",
906 sg
[i
].addr_bus
= virt_to_bus(p
);
910 rcode
= i2o_msg_post_wait(c
, m
, 60);
916 /* Copy back the Scatter Gather buffers back to user space */
919 struct sg_simple_element
*sg
;
922 // re-acquire the original message to handle correctly the sg copy operation
923 memset(&msg
, 0, MSG_FRAME_SIZE
* 4);
924 // get user msg size in u32s
925 if (get_user(size
, &user_msg
[0])) {
931 /* Copy in the user's I2O command */
932 if (copy_from_user(msg
, user_msg
, size
)) {
937 (size
- sg_offset
* 4) / sizeof(struct sg_simple_element
);
940 sg
= (struct sg_simple_element
*)(msg
+ sg_offset
);
941 for (j
= 0; j
< sg_count
; j
++) {
942 /* Copy out the SG list to user's buffer if necessary */
945 flag_count
& 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
946 sg_size
= sg
[j
].flag_count
& 0xffffff;
949 ((void __user
*)sg
[j
].addr_bus
, sg_list
[j
],
952 "%s: Could not copy %p TO user %x\n",
962 /* Copy back the reply to user space */
964 // we wrote our own values for context - now restore the user supplied ones
965 if (copy_from_user(reply
+ 2, user_msg
+ 2, sizeof(u32
) * 2)) {
967 "%s: Could not copy message context FROM user\n",
971 if (copy_to_user(user_reply
, reply
, reply_size
)) {
973 "%s: Could not copy reply TO user\n", c
->name
);
986 static int i2o_cfg_ioctl(struct inode
*inode
, struct file
*fp
, unsigned int cmd
,
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
);
1037 ret
= i2o_cfg_passthru(arg
);
1041 osm_debug("unknown ioctl called!\n");
1048 static int cfg_open(struct inode
*inode
, struct file
*file
)
1050 struct i2o_cfg_info
*tmp
=
1051 (struct i2o_cfg_info
*)kmalloc(sizeof(struct i2o_cfg_info
),
1053 unsigned long flags
;
1058 file
->private_data
= (void *)(i2o_cfg_info_id
++);
1061 tmp
->q_id
= (ulong
) file
->private_data
;
1066 tmp
->next
= open_files
;
1068 spin_lock_irqsave(&i2o_config_lock
, flags
);
1070 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
1075 static int cfg_fasync(int fd
, struct file
*fp
, int on
)
1077 ulong id
= (ulong
) fp
->private_data
;
1078 struct i2o_cfg_info
*p
;
1080 for (p
= open_files
; p
; p
= p
->next
)
1087 return fasync_helper(fd
, fp
, on
, &p
->fasync
);
1090 static int cfg_release(struct inode
*inode
, struct file
*file
)
1092 ulong id
= (ulong
) file
->private_data
;
1093 struct i2o_cfg_info
*p1
, *p2
;
1094 unsigned long flags
;
1099 spin_lock_irqsave(&i2o_config_lock
, flags
);
1100 for (p1
= open_files
; p1
;) {
1101 if (p1
->q_id
== id
) {
1104 cfg_fasync(-1, file
, 0);
1106 p2
->next
= p1
->next
;
1108 open_files
= p1
->next
;
1116 spin_unlock_irqrestore(&i2o_config_lock
, flags
);
1122 static struct file_operations config_fops
= {
1123 .owner
= THIS_MODULE
,
1124 .llseek
= no_llseek
,
1125 .ioctl
= i2o_cfg_ioctl
,
1126 #ifdef CONFIG_COMPAT
1127 .compat_ioctl
= i2o_cfg_compat_ioctl
,
1130 .release
= cfg_release
,
1131 .fasync
= cfg_fasync
,
1134 static struct miscdevice i2o_miscdev
= {
1140 static int __init
i2o_config_init(void)
1142 printk(KERN_INFO OSM_DESCRIPTION
" v" OSM_VERSION
"\n");
1144 spin_lock_init(&i2o_config_lock
);
1146 if (misc_register(&i2o_miscdev
) < 0) {
1147 osm_err("can't register device.\n");
1151 * Install our handler
1153 if (i2o_driver_register(&i2o_config_driver
)) {
1154 osm_err("handler register failed.\n");
1155 misc_deregister(&i2o_miscdev
);
1161 static void i2o_config_exit(void)
1163 misc_deregister(&i2o_miscdev
);
1164 i2o_driver_unregister(&i2o_config_driver
);
1167 MODULE_AUTHOR("Red Hat Software");
1168 MODULE_LICENSE("GPL");
1169 MODULE_DESCRIPTION(OSM_DESCRIPTION
);
1170 MODULE_VERSION(OSM_VERSION
);
1172 module_init(i2o_config_init
);
1173 module_exit(i2o_config_exit
);