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 extern int i2o_parm_issue(struct i2o_device *, int, void *, int, void *, int);
53 static spinlock_t i2o_config_lock = SPIN_LOCK_UNLOCKED;
54 struct wait_queue *i2o_wait_queue;
56 #define MODINC(x,y) ((x) = ((x) + 1) % (y))
58 struct sg_simple_element {
65 struct fasync_struct *fasync;
66 struct i2o_evt_info event_q[I2O_EVT_Q_LEN];
67 u16 q_in; // Queue head index
68 u16 q_out; // Queue tail index
69 u16 q_len; // Queue length
70 u16 q_lost; // Number of lost events
71 ulong q_id; // Event queue ID...used as tx_context
72 struct i2o_cfg_info *next;
74 static struct i2o_cfg_info *open_files = NULL;
75 static ulong i2o_cfg_info_id = 0;
79 * This is the callback for any message we have posted. The message itself
80 * will be returned to the message pool when we return from the IRQ
82 * This runs in irq context so be short and sweet.
84 static void i2o_cfg_reply(struct i2o_handler *h, struct i2o_controller *c,
85 struct i2o_message *m)
89 if (msg[0] & MSG_FAIL) {
90 u32 *preserved_msg = (u32 *) (c->msg_virt + msg[7]);
92 printk(KERN_ERR "i2o_config: IOP failed to process the msg.\n");
94 /* Release the preserved msg frame by resubmitting it as a NOP */
96 preserved_msg[0] = THREE_WORD_MSG_SIZE | SGL_OFFSET_0;
97 preserved_msg[1] = I2O_CMD_UTIL_NOP << 24 | HOST_TID << 12 | 0;
99 i2o_post_message(c, msg[7]);
102 if (msg[4] >> 24) // ReqStatus != SUCCESS
103 i2o_report_status(KERN_INFO, "i2o_config", msg);
105 if (m->function == I2O_CMD_UTIL_EVT_REGISTER) {
106 struct i2o_cfg_info *inf;
108 for (inf = open_files; inf; inf = inf->next)
109 if (inf->q_id == i2o_cntxt_list_get(c, msg[3]))
113 // If this is the case, it means that we're getting
114 // events for a file descriptor that's been close()'d
115 // w/o the user unregistering for events first.
116 // The code currently assumes that the user will
117 // take care of unregistering for events before closing
121 // Should we track event registartion and deregister
122 // for events when a file is close()'d so this doesn't
123 // happen? That would get rid of the search through
124 // the linked list since file->private_data could point
125 // directly to the i2o_config_info data structure...but
126 // it would mean having all sorts of tables to track
127 // what each file is registered for...I think the
128 // current method is simpler. - DS
133 inf->event_q[inf->q_in].id.iop = c->unit;
134 inf->event_q[inf->q_in].id.tid = m->target_tid;
135 inf->event_q[inf->q_in].id.evt_mask = msg[4];
138 // Data size = msg size - reply header
140 inf->event_q[inf->q_in].data_size = (m->size - 5) * 4;
141 if (inf->event_q[inf->q_in].data_size)
142 memcpy(inf->event_q[inf->q_in].evt_data,
143 (unsigned char *)(msg + 5),
144 inf->event_q[inf->q_in].data_size);
146 spin_lock(&i2o_config_lock);
147 MODINC(inf->q_in, I2O_EVT_Q_LEN);
148 if (inf->q_len == I2O_EVT_Q_LEN) {
149 MODINC(inf->q_out, I2O_EVT_Q_LEN);
152 // Keep I2OEVTGET on another CPU from touching this
155 spin_unlock(&i2o_config_lock);
157 // printk(KERN_INFO "File %p w/id %d has %d events\n",
158 // inf->fp, inf->q_id, inf->q_len);
160 kill_fasync(&inf->fasync, SIGIO, POLL_IN);
168 * Each of these describes an i2o message handler. They are
169 * multiplexed by the i2o_core code
172 struct i2o_driver i2o_config_driver = {
176 static int i2o_cfg_getiops(unsigned long arg)
178 struct i2o_controller *c;
179 u8 __user *user_iop_table = (void __user *)arg;
180 u8 tmp[MAX_I2O_CONTROLLERS];
182 memset(tmp, 0, MAX_I2O_CONTROLLERS);
184 if (!access_ok(VERIFY_WRITE, user_iop_table, MAX_I2O_CONTROLLERS))
187 list_for_each_entry(c, &i2o_controllers, list)
190 __copy_to_user(user_iop_table, tmp, MAX_I2O_CONTROLLERS);
195 static int i2o_cfg_gethrt(unsigned long arg)
197 struct i2o_controller *c;
198 struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg;
199 struct i2o_cmd_hrtlct kcmd;
205 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
208 if (get_user(reslen, kcmd.reslen) < 0)
211 if (kcmd.resbuf == NULL)
214 c = i2o_find_iop(kcmd.iop);
218 hrt = (i2o_hrt *) c->hrt.virt;
220 len = 8 + ((hrt->entry_len * hrt->num_entries) << 2);
222 /* We did a get user...so assuming mem is ok...is this bad? */
223 put_user(len, kcmd.reslen);
226 if (copy_to_user(kcmd.resbuf, (void *)hrt, len))
232 static int i2o_cfg_getlct(unsigned long arg)
234 struct i2o_controller *c;
235 struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg;
236 struct i2o_cmd_hrtlct kcmd;
242 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
245 if (get_user(reslen, kcmd.reslen) < 0)
248 if (kcmd.resbuf == NULL)
251 c = i2o_find_iop(kcmd.iop);
255 lct = (i2o_lct *) c->lct;
257 len = (unsigned int)lct->table_size << 2;
258 put_user(len, kcmd.reslen);
261 else if (copy_to_user(kcmd.resbuf, lct, len))
267 static int i2o_cfg_parms(unsigned long arg, unsigned int type)
270 struct i2o_controller *c;
271 struct i2o_device *dev;
272 struct i2o_cmd_psetget __user *cmd =
273 (struct i2o_cmd_psetget __user *)arg;
274 struct i2o_cmd_psetget kcmd;
280 u32 i2o_cmd = (type == I2OPARMGET ?
281 I2O_CMD_UTIL_PARAMS_GET : I2O_CMD_UTIL_PARAMS_SET);
283 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_psetget)))
286 if (get_user(reslen, kcmd.reslen))
289 c = i2o_find_iop(kcmd.iop);
293 dev = i2o_iop_find_device(c, kcmd.tid);
297 ops = (u8 *) kmalloc(kcmd.oplen, GFP_KERNEL);
301 if (copy_from_user(ops, kcmd.opbuf, kcmd.oplen)) {
307 * It's possible to have a _very_ large table
308 * and that the user asks for all of it at once...
310 res = (u8 *) kmalloc(65536, GFP_KERNEL);
316 len = i2o_parm_issue(dev, i2o_cmd, ops, kcmd.oplen, res, 65536);
324 put_user(len, kcmd.reslen);
327 else if (copy_to_user(kcmd.resbuf, res, len))
335 static int i2o_cfg_swdl(unsigned long arg)
337 struct i2o_sw_xfer kxfer;
338 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
339 unsigned char maxfrag = 0, curfrag = 1;
340 struct i2o_dma buffer;
341 struct i2o_message *msg;
343 unsigned int status = 0, swlen = 0, fragsize = 8192;
344 struct i2o_controller *c;
346 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
349 if (get_user(swlen, kxfer.swlen) < 0)
352 if (get_user(maxfrag, kxfer.maxfrag) < 0)
355 if (get_user(curfrag, kxfer.curfrag) < 0)
358 if (curfrag == maxfrag)
359 fragsize = swlen - (maxfrag - 1) * 8192;
361 if (!kxfer.buf || !access_ok(VERIFY_READ, kxfer.buf, fragsize))
364 c = i2o_find_iop(kxfer.iop);
368 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
369 if (m == I2O_QUEUE_EMPTY)
372 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) {
377 __copy_from_user(buffer.virt, kxfer.buf, fragsize);
379 writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_7, &msg->u.head[0]);
380 writel(I2O_CMD_SW_DOWNLOAD << 24 | HOST_TID << 12 | ADAPTER_TID,
382 writel(i2o_config_driver.context, &msg->u.head[2]);
383 writel(0, &msg->u.head[3]);
384 writel((((u32) kxfer.flags) << 24) | (((u32) kxfer.sw_type) << 16) |
385 (((u32) maxfrag) << 8) | (((u32) curfrag)), &msg->body[0]);
386 writel(swlen, &msg->body[1]);
387 writel(kxfer.sw_id, &msg->body[2]);
388 writel(0xD0000000 | fragsize, &msg->body[3]);
389 writel(buffer.phys, &msg->body[4]);
391 // printk("i2o_config: swdl frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
392 status = i2o_msg_post_wait_mem(c, m, 60, &buffer);
394 if (status != -ETIMEDOUT)
395 i2o_dma_free(&c->pdev->dev, &buffer);
397 if (status != I2O_POST_WAIT_OK) {
398 // it fails if you try and send frags out of order
399 // and for some yet unknown reasons too
401 "i2o_config: swdl failed, DetailedStatus = %d\n",
409 static int i2o_cfg_swul(unsigned long arg)
411 struct i2o_sw_xfer kxfer;
412 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
413 unsigned char maxfrag = 0, curfrag = 1;
414 struct i2o_dma buffer;
415 struct i2o_message *msg;
417 unsigned int status = 0, swlen = 0, fragsize = 8192;
418 struct i2o_controller *c;
420 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
423 if (get_user(swlen, kxfer.swlen) < 0)
426 if (get_user(maxfrag, kxfer.maxfrag) < 0)
429 if (get_user(curfrag, kxfer.curfrag) < 0)
432 if (curfrag == maxfrag)
433 fragsize = swlen - (maxfrag - 1) * 8192;
435 if (!kxfer.buf || !access_ok(VERIFY_WRITE, kxfer.buf, fragsize))
438 c = i2o_find_iop(kxfer.iop);
442 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
443 if (m == I2O_QUEUE_EMPTY)
446 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) {
451 writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_7, &msg->u.head[0]);
452 writel(I2O_CMD_SW_UPLOAD << 24 | HOST_TID << 12 | ADAPTER_TID,
454 writel(i2o_config_driver.context, &msg->u.head[2]);
455 writel(0, &msg->u.head[3]);
456 writel((u32) kxfer.flags << 24 | (u32) kxfer.
457 sw_type << 16 | (u32) maxfrag << 8 | (u32) curfrag,
459 writel(swlen, &msg->body[1]);
460 writel(kxfer.sw_id, &msg->body[2]);
461 writel(0xD0000000 | fragsize, &msg->body[3]);
462 writel(buffer.phys, &msg->body[4]);
464 // printk("i2o_config: swul frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
465 status = i2o_msg_post_wait_mem(c, m, 60, &buffer);
467 if (status != I2O_POST_WAIT_OK) {
468 if (status != -ETIMEDOUT)
469 i2o_dma_free(&c->pdev->dev, &buffer);
472 "i2o_config: swul failed, DetailedStatus = %d\n",
477 __copy_to_user(kxfer.buf, buffer.virt, fragsize);
478 i2o_dma_free(&c->pdev->dev, &buffer);
483 static int i2o_cfg_swdel(unsigned long arg)
485 struct i2o_controller *c;
486 struct i2o_sw_xfer kxfer;
487 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
488 struct i2o_message *msg;
493 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
496 if (get_user(swlen, kxfer.swlen) < 0)
499 c = i2o_find_iop(kxfer.iop);
503 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
504 if (m == I2O_QUEUE_EMPTY)
507 writel(SEVEN_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
508 writel(I2O_CMD_SW_REMOVE << 24 | HOST_TID << 12 | ADAPTER_TID,
510 writel(i2o_config_driver.context, &msg->u.head[2]);
511 writel(0, &msg->u.head[3]);
512 writel((u32) kxfer.flags << 24 | (u32) kxfer.sw_type << 16,
514 writel(swlen, &msg->body[1]);
515 writel(kxfer.sw_id, &msg->body[2]);
517 token = i2o_msg_post_wait(c, m, 10);
519 if (token != I2O_POST_WAIT_OK) {
521 "i2o_config: swdel failed, DetailedStatus = %d\n",
529 static int i2o_cfg_validate(unsigned long arg)
533 struct i2o_message *msg;
535 struct i2o_controller *c;
537 c = i2o_find_iop(iop);
541 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
542 if (m == I2O_QUEUE_EMPTY)
545 writel(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
546 writel(I2O_CMD_CONFIG_VALIDATE << 24 | HOST_TID << 12 | iop,
548 writel(i2o_config_driver.context, &msg->u.head[2]);
549 writel(0, &msg->u.head[3]);
551 token = i2o_msg_post_wait(c, m, 10);
553 if (token != I2O_POST_WAIT_OK) {
554 printk(KERN_INFO "Can't validate configuration, ErrorStatus = "
562 static int i2o_cfg_evt_reg(unsigned long arg, struct file *fp)
564 struct i2o_message *msg;
566 struct i2o_evt_id __user *pdesc = (struct i2o_evt_id __user *)arg;
567 struct i2o_evt_id kdesc;
568 struct i2o_controller *c;
569 struct i2o_device *d;
571 if (copy_from_user(&kdesc, pdesc, sizeof(struct i2o_evt_id)))
575 c = i2o_find_iop(kdesc.iop);
580 d = i2o_iop_find_device(c, kdesc.tid);
584 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
585 if (m == I2O_QUEUE_EMPTY)
588 writel(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
589 writel(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 | kdesc.tid,
591 writel(i2o_config_driver.context, &msg->u.head[2]);
592 writel(i2o_cntxt_list_add(c, fp->private_data), &msg->u.head[3]);
593 writel(kdesc.evt_mask, &msg->body[0]);
600 static int i2o_cfg_evt_get(unsigned long arg, struct file *fp)
602 struct i2o_cfg_info *p = NULL;
603 struct i2o_evt_get __user *uget = (struct i2o_evt_get __user *)arg;
604 struct i2o_evt_get kget;
607 for (p = open_files; p; p = p->next)
608 if (p->q_id == (ulong) fp->private_data)
614 memcpy(&kget.info, &p->event_q[p->q_out], sizeof(struct i2o_evt_info));
615 MODINC(p->q_out, I2O_EVT_Q_LEN);
616 spin_lock_irqsave(&i2o_config_lock, flags);
618 kget.pending = p->q_len;
619 kget.lost = p->q_lost;
620 spin_unlock_irqrestore(&i2o_config_lock, flags);
622 if (copy_to_user(uget, &kget, sizeof(struct i2o_evt_get)))
628 static int i2o_cfg_passthru32(unsigned fd, unsigned cmnd, unsigned long arg,
631 struct i2o_cmd_passthru32 __user *cmd;
632 struct i2o_controller *c;
633 u32 __user *user_msg;
635 u32 __user *user_reply = NULL;
639 struct i2o_dma sg_list[SG_TABLESIZE];
643 i2o_status_block *sb;
644 struct i2o_message *msg;
648 cmd = (struct i2o_cmd_passthru32 __user *)arg;
650 if (get_user(iop, &cmd->iop) || get_user(i, &cmd->msg))
653 user_msg = compat_ptr(i);
655 c = i2o_find_iop(iop);
657 pr_debug("controller %d not found\n", iop);
661 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
663 sb = c->status_block.virt;
665 if (get_user(size, &user_msg[0])) {
666 printk(KERN_WARNING "unable to get size!\n");
671 if (size > sb->inbound_frame_size) {
672 pr_debug("size of message > inbound_frame_size");
676 user_reply = &user_msg[size];
678 size <<= 2; // Convert to bytes
680 /* Copy in the user's I2O command */
681 if (copy_from_user(msg, user_msg, size)) {
682 printk(KERN_WARNING "unable to copy user message\n");
685 i2o_dump_message(msg);
687 if (get_user(reply_size, &user_reply[0]) < 0)
693 reply = kmalloc(reply_size, GFP_KERNEL);
695 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
699 memset(reply, 0, reply_size);
701 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
703 writel(i2o_config_driver.context, &msg->u.s.icntxt);
704 writel(i2o_cntxt_list_add(c, reply), &msg->u.s.tcntxt);
706 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
708 struct sg_simple_element *sg;
710 if (sg_offset * 4 >= size) {
715 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
718 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
719 if (sg_count > SG_TABLESIZE) {
720 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
726 for (i = 0; i < sg_count; i++) {
730 if (!(sg[i].flag_count & 0x10000000
731 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
733 "%s:Bad SG element %d - not simple (%x)\n",
734 c->name, i, sg[i].flag_count);
738 sg_size = sg[i].flag_count & 0xffffff;
740 /* Allocate memory for the transfer */
742 (&c->pdev->dev, p, sg_size,
743 PCI_DMA_BIDIRECTIONAL)) {
745 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
746 c->name, sg_size, i, sg_count);
750 /* Copy in the user's SG buffer if necessary */
752 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
755 (p->virt, (void __user *)(unsigned long)sg[i].addr_bus,
758 "%s: Could not copy SG buf %d FROM user\n",
765 sg[i].addr_bus = (u32) p->phys;
769 rcode = i2o_msg_post_wait(c, m, 60);
775 /* Copy back the Scatter Gather buffers back to user space */
778 struct sg_simple_element *sg;
780 printk(KERN_INFO "sg_offset\n");
782 // re-acquire the original message to handle correctly the sg copy operation
783 memset(&msg, 0, MSG_FRAME_SIZE * 4);
784 // get user msg size in u32s
785 if (get_user(size, &user_msg[0])) {
791 /* Copy in the user's I2O command */
792 if (copy_from_user(msg, user_msg, size)) {
797 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
800 sg = (struct sg_simple_element *)(msg + sg_offset);
801 for (j = 0; j < sg_count; j++) {
802 /* Copy out the SG list to user's buffer if necessary */
805 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
806 sg_size = sg[j].flag_count & 0xffffff;
809 ((void __user *)(u64) sg[j].addr_bus,
810 sg_list[j].virt, sg_size)) {
812 "%s: Could not copy %p TO user %x\n",
813 c->name, sg_list[j].virt,
822 /* Copy back the reply to user space */
824 // we wrote our own values for context - now restore the user supplied ones
825 printk(KERN_INFO "reply_size\n");
826 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
828 "%s: Could not copy message context FROM user\n",
832 if (copy_to_user(user_reply, reply, reply_size)) {
834 "%s: Could not copy reply TO user\n", c->name);
841 printk(KERN_INFO "rcode: %d\n", rcode);
847 static int i2o_cfg_passthru(unsigned long arg)
849 struct i2o_cmd_passthru __user *cmd =
850 (struct i2o_cmd_passthru __user *)arg;
851 struct i2o_controller *c;
852 u32 __user *user_msg;
854 u32 __user *user_reply = NULL;
858 void *sg_list[SG_TABLESIZE];
864 i2o_status_block *sb;
865 struct i2o_message *msg;
869 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
872 c = i2o_find_iop(iop);
874 pr_debug("controller %d not found\n", iop);
878 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
880 sb = c->status_block.virt;
882 if (get_user(size, &user_msg[0]))
886 if (size > sb->inbound_frame_size) {
887 pr_debug("size of message > inbound_frame_size");
891 user_reply = &user_msg[size];
893 size <<= 2; // Convert to bytes
895 /* Copy in the user's I2O command */
896 if (copy_from_user(msg, user_msg, size))
899 if (get_user(reply_size, &user_reply[0]) < 0)
905 reply = kmalloc(reply_size, GFP_KERNEL);
907 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
911 memset(reply, 0, reply_size);
913 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
915 writel(i2o_config_driver.context, &msg->u.s.icntxt);
916 writel(i2o_cntxt_list_add(c, reply), &msg->u.s.tcntxt);
918 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
920 struct sg_simple_element *sg;
922 if (sg_offset * 4 >= size) {
927 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
930 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
931 if (sg_count > SG_TABLESIZE) {
932 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
938 for (i = 0; i < sg_count; i++) {
941 if (!(sg[i].flag_count & 0x10000000
942 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
944 "%s:Bad SG element %d - not simple (%x)\n",
945 c->name, i, sg[i].flag_count);
949 sg_size = sg[i].flag_count & 0xffffff;
950 /* Allocate memory for the transfer */
951 p = kmalloc(sg_size, GFP_KERNEL);
954 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
955 c->name, sg_size, i, sg_count);
959 sg_list[sg_index++] = p; // sglist indexed with input frame, not our internal frame.
960 /* Copy in the user's SG buffer if necessary */
962 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
965 (p, (void __user *)sg[i].addr_bus,
968 "%s: Could not copy SG buf %d FROM user\n",
975 sg[i].addr_bus = virt_to_bus(p);
979 rcode = i2o_msg_post_wait(c, m, 60);
985 /* Copy back the Scatter Gather buffers back to user space */
988 struct sg_simple_element *sg;
990 printk(KERN_INFO "sg_offset\n");
992 // re-acquire the original message to handle correctly the sg copy operation
993 memset(&msg, 0, MSG_FRAME_SIZE * 4);
994 // get user msg size in u32s
995 if (get_user(size, &user_msg[0])) {
1001 /* Copy in the user's I2O command */
1002 if (copy_from_user(msg, user_msg, size)) {
1007 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
1010 sg = (struct sg_simple_element *)(msg + sg_offset);
1011 for (j = 0; j < sg_count; j++) {
1012 /* Copy out the SG list to user's buffer if necessary */
1015 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
1016 sg_size = sg[j].flag_count & 0xffffff;
1019 ((void __user *)sg[j].addr_bus, sg_list[j],
1022 "%s: Could not copy %p TO user %x\n",
1023 c->name, sg_list[j],
1032 /* Copy back the reply to user space */
1034 // we wrote our own values for context - now restore the user supplied ones
1035 printk(KERN_INFO "reply_size\n");
1036 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
1038 "%s: Could not copy message context FROM user\n",
1042 if (copy_to_user(user_reply, reply, reply_size)) {
1044 "%s: Could not copy reply TO user\n", c->name);
1058 static int i2o_cfg_ioctl(struct inode *inode, struct file *fp, unsigned int cmd,
1065 ret = i2o_cfg_getiops(arg);
1069 ret = i2o_cfg_gethrt(arg);
1073 ret = i2o_cfg_getlct(arg);
1077 ret = i2o_cfg_parms(arg, I2OPARMSET);
1081 ret = i2o_cfg_parms(arg, I2OPARMGET);
1085 ret = i2o_cfg_swdl(arg);
1089 ret = i2o_cfg_swul(arg);
1093 ret = i2o_cfg_swdel(arg);
1097 ret = i2o_cfg_validate(arg);
1101 ret = i2o_cfg_evt_reg(arg, fp);
1105 ret = i2o_cfg_evt_get(arg, fp);
1108 #ifndef CONFIG_COMPAT
1110 ret = i2o_cfg_passthru(arg);
1115 pr_debug("i2o_config: unknown ioctl called!\n");
1122 static int cfg_open(struct inode *inode, struct file *file)
1124 struct i2o_cfg_info *tmp =
1125 (struct i2o_cfg_info *)kmalloc(sizeof(struct i2o_cfg_info),
1127 unsigned long flags;
1132 file->private_data = (void *)(i2o_cfg_info_id++);
1135 tmp->q_id = (ulong) file->private_data;
1140 tmp->next = open_files;
1142 spin_lock_irqsave(&i2o_config_lock, flags);
1144 spin_unlock_irqrestore(&i2o_config_lock, flags);
1149 static int cfg_fasync(int fd, struct file *fp, int on)
1151 ulong id = (ulong) fp->private_data;
1152 struct i2o_cfg_info *p;
1154 for (p = open_files; p; p = p->next)
1161 return fasync_helper(fd, fp, on, &p->fasync);
1164 static int cfg_release(struct inode *inode, struct file *file)
1166 ulong id = (ulong) file->private_data;
1167 struct i2o_cfg_info *p1, *p2;
1168 unsigned long flags;
1173 spin_lock_irqsave(&i2o_config_lock, flags);
1174 for (p1 = open_files; p1;) {
1175 if (p1->q_id == id) {
1178 cfg_fasync(-1, file, 0);
1180 p2->next = p1->next;
1182 open_files = p1->next;
1190 spin_unlock_irqrestore(&i2o_config_lock, flags);
1196 static struct file_operations config_fops = {
1197 .owner = THIS_MODULE,
1198 .llseek = no_llseek,
1199 .ioctl = i2o_cfg_ioctl,
1201 .release = cfg_release,
1202 .fasync = cfg_fasync,
1205 static struct miscdevice i2o_miscdev = {
1211 static int __init i2o_config_init(void)
1213 printk(KERN_INFO "I2O configuration manager v 0.04.\n");
1214 printk(KERN_INFO " (C) Copyright 1999 Red Hat Software\n");
1216 if (misc_register(&i2o_miscdev) < 0) {
1217 printk(KERN_ERR "i2o_config: can't register device.\n");
1221 * Install our handler
1223 if (i2o_driver_register(&i2o_config_driver)) {
1224 printk(KERN_ERR "i2o_config: handler register failed.\n");
1225 misc_deregister(&i2o_miscdev);
1228 #ifdef CONFIG_COMPAT
1229 register_ioctl32_conversion(I2OPASSTHRU32, i2o_cfg_passthru32);
1230 register_ioctl32_conversion(I2OGETIOPS, (void *)sys_ioctl);
1235 static void i2o_config_exit(void)
1237 #ifdef CONFIG_COMPAT
1238 unregister_ioctl32_conversion(I2OPASSTHRU32);
1239 unregister_ioctl32_conversion(I2OGETIOPS);
1241 misc_deregister(&i2o_miscdev);
1242 i2o_driver_unregister(&i2o_config_driver);
1245 MODULE_AUTHOR("Red Hat Software");
1246 MODULE_DESCRIPTION("I2O Configuration");
1247 MODULE_LICENSE("GPL");
1249 module_init(i2o_config_init);
1250 module_exit(i2o_config_exit);