diff options
author | Ralf Baechle <ralf@linux-mips.org> | 2000-02-16 01:07:24 +0000 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2000-02-16 01:07:24 +0000 |
commit | 95db6b748fc86297827fbd9c9ef174d491c9ad89 (patch) | |
tree | 27a92a942821cde1edda9a1b088718d436b3efe4 /drivers/i2o/i2o_config.c | |
parent | 45b27b0a0652331d104c953a5b192d843fff88f8 (diff) |
Merge with Linux 2.3.40.
Diffstat (limited to 'drivers/i2o/i2o_config.c')
-rw-r--r-- | drivers/i2o/i2o_config.c | 316 |
1 files changed, 271 insertions, 45 deletions
diff --git a/drivers/i2o/i2o_config.c b/drivers/i2o/i2o_config.c index 96d9c17e1..4133db0cb 100644 --- a/drivers/i2o/i2o_config.c +++ b/drivers/i2o/i2o_config.c @@ -1,26 +1,28 @@ /* - * I2O Configuration Interface Driver + * I2O Configuration Interface Driver * - * (C) Copyright 1999 Red Hat Software + * (C) Copyright 1999 Red Hat Software * - * Written by Alan Cox, Building Number Three Ltd + * Written by Alan Cox, Building Number Three Ltd * - * Modified 04/20/1999 by Deepak Saxena - * - Added basic ioctl() support - * Modified 06/07/1999 by Deepak Saxena - * - Added software download ioctl (still testing) - * Modified 09/10/1999 by Auvo Häkkinen - * - Changes to i2o_cfg_reply(), ioctl_parms() - * - Added ioct_validate() - * Modified 09/30/1999 by Taneli Vähäkangas - * - Fixed ioctl_swdl() - * Modified 10/04/1999 by Taneli Vähäkangas - * - Changed ioctl_swdl(), implemented ioctl_swul() and ioctl_swdel() + * Modified 04/20/1999 by Deepak Saxena + * - Added basic ioctl() support + * Modified 06/07/1999 by Deepak Saxena + * - Added software download ioctl (still testing) + * Modified 09/10/1999 by Auvo Häkkinen + * - Changes to i2o_cfg_reply(), ioctl_parms() + * - Added ioct_validate() + * Modified 09/30/1999 by Taneli Vähäkangas + * - Fixed ioctl_swdl() + * Modified 10/04/1999 by Taneli Vähäkangas + * - Changed ioctl_swdl(), implemented ioctl_swul() and ioctl_swdel() + * Modified 11/18/199 by Deepak Saxena + * - Added event managmenet support * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version - * 2 of the License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. */ #include <linux/module.h> @@ -37,13 +39,29 @@ #include <asm/uaccess.h> #include <asm/io.h> -static int i2o_cfg_token = 0; static int i2o_cfg_context = -1; static void *page_buf; static void *i2o_buffer; static spinlock_t i2o_config_lock = SPIN_LOCK_UNLOCKED; struct wait_queue *i2o_wait_queue; +#define MODINC(x,y) (x = x++ % y) + +struct i2o_cfg_info +{ + struct file* fp; + struct fasync_struct *fasync; + struct i2o_evt_info event_q[I2O_EVT_Q_LEN]; + u16 q_in; // Queue head index + u16 q_out; // Queue tail index + u16 q_len; // Queue length + u16 q_lost; // Number of lost events + u32 q_id; // Event queue ID...used as tx_context + struct i2o_cfg_info *next; +}; +static struct i2o_cfg_info *open_files = NULL; +static int i2o_cfg_info_id = 0; + static int ioctl_getiops(unsigned long); static int ioctl_gethrt(unsigned long); static int ioctl_getlct(unsigned long); @@ -53,6 +71,9 @@ static int ioctl_swdl(unsigned long); static int ioctl_swul(unsigned long); static int ioctl_swdel(unsigned long); static int ioctl_validate(unsigned long); +static int ioctl_evt_reg(unsigned long, struct file *); +static int ioctl_evt_get(unsigned long, struct file *); +static int cfg_fasync(int, struct file*, int); /* * This is the callback for any message we have posted. The message itself @@ -62,13 +83,78 @@ static int ioctl_validate(unsigned long); */ static void i2o_cfg_reply(struct i2o_handler *h, struct i2o_controller *c, struct i2o_message *m) { - u32 *msg = (u32 *)m; + u32 *msg = (u32 *)m; + + if (msg[0] & (1<<13)) + printk(KERN_ERR "i2o_config: IOP failed to process the msg.\n"); - if (msg[4] >> 24) // RegStatus != SUCCESS - i2o_cfg_token = -(msg[4] & 0xFFFF); // DetailedStatus - else - i2o_cfg_token = I2O_POST_WAIT_OK; - + if (msg[4] >> 24) // RegStatus != SUCCESS + i2o_report_status(KERN_INFO,"i2o_config",msg); + + if(m->function == I2O_CMD_UTIL_EVT_REGISTER) + { + struct i2o_cfg_info *inf; + + for(inf = open_files; inf; inf = inf->next) + if(inf->q_id == msg[3]) + break; + + // + // If this is the case, it means that we're getting + // events for a file descriptor that's been close()'d + // w/o the user unregistering for events first. + // The code currently assumes that the user will + // take care of unregistering for events before closing + // a file. + // + // TODO: + // Should we track event registartion and deregister + // for events when a file is close()'d so this doesn't + // happen? That would get rid of the search through + // the linked list since file->private_data could point + // directly to the i2o_config_info data structure...but + // it would mean having all sorts of tables to track + // what each file is registered for...I think the + // current method is simpler. - DS + // + if(!inf) + return; + + inf->event_q[inf->q_in].id.iop = c->unit; + inf->event_q[inf->q_in].id.tid = m->target_tid; + inf->event_q[inf->q_in].id.evt_mask = msg[4]; + + // + // Data size = msg size - reply header + // + inf->event_q[inf->q_in].data_size = (m->size - 5) * 4; + if(inf->event_q[inf->q_in].data_size) + memcpy(inf->event_q[inf->q_in].evt_data, + (unsigned char *)(msg + 5), + inf->event_q[inf->q_in].data_size); + + spin_lock(&i2o_config_lock); + MODINC(inf->q_in, I2O_EVT_Q_LEN); + if(inf->q_len == I2O_EVT_Q_LEN) + { + MODINC(inf->q_out, I2O_EVT_Q_LEN); + inf->q_lost++; + } + else + { + // Keep I2OEVTGET on another CPU from touching this + inf->q_len++; + } + spin_unlock(&i2o_config_lock); + + +// printk(KERN_INFO "File %p w/id %d has %d events\n", +// inf->fp, inf->q_id, inf->q_len); + + if(inf->fasync) + kill_fasync(inf->fasync, SIGIO, POLL_IN); + } + return; } @@ -107,14 +193,11 @@ static ssize_t cfg_read(struct file *file, char *buf, size_t count, loff_t *ptr) /* * IOCTL Handler */ -static int cfg_ioctl(struct inode *inode, struct file *file, unsigned int cmd, +static int cfg_ioctl(struct inode *inode, struct file *fp, unsigned int cmd, unsigned long arg) { int ret; - /* Only 1 token, so lock... */ - spin_lock(&i2o_config_lock); - switch(cmd) { case I2OGETIOPS: @@ -157,11 +240,18 @@ static int cfg_ioctl(struct inode *inode, struct file *file, unsigned int cmd, ret = ioctl_html(arg); break; + case I2OEVTREG: + ret = ioctl_evt_reg(arg, fp); + break; + + case I2OEVTGET: + ret = ioctl_evt_get(arg, fp); + break; + default: ret = -EINVAL; } - spin_unlock(&i2o_config_lock); return ret; } @@ -320,7 +410,7 @@ static int ioctl_parms(unsigned long arg, unsigned int type) } len = i2o_issue_params(i2o_cmd, c, kcmd.tid, - ops, kcmd.oplen, res, sizeof(res)); + ops, kcmd.oplen, res, 65536); i2o_unlock_controller(c); kfree(ops); @@ -392,7 +482,7 @@ int ioctl_html(unsigned long arg) } } - res = kmalloc(4096, GFP_KERNEL); + res = kmalloc(65536, GFP_KERNEL); if(!res) { i2o_unlock_controller(c); @@ -403,21 +493,22 @@ int ioctl_html(unsigned long arg) msg[2] = i2o_cfg_context; msg[3] = 0; msg[4] = kcmd.page; - msg[5] = 0xD0000000|4096; + msg[5] = 0xD0000000|65536; msg[6] = virt_to_bus(res); if(!kcmd.qlen) /* Check for post data */ msg[0] = SEVEN_WORD_MSG_SIZE|SGL_OFFSET_5; else { msg[0] = NINE_WORD_MSG_SIZE|SGL_OFFSET_5; - msg[5] = 0x50000000|4096; + msg[5] = 0x50000000|65536; msg[7] = 0xD4000000|(kcmd.qlen); msg[8] = virt_to_phys(query); } token = i2o_post_wait(c, msg, 9*4, 10); - if(token != I2O_POST_WAIT_OK) + if(token) { + printk(KERN_DEBUG "token = %#10x\n", token); i2o_unlock_controller(c); kfree(res); if(kcmd.qlen) kfree(query); @@ -426,7 +517,7 @@ int ioctl_html(unsigned long arg) } i2o_unlock_controller(c); - len = strnlen(res, 8192); + len = strnlen(res, 65536); put_user(len, kcmd.reslen); if(len > reslen) ret = -ENOMEM; @@ -500,7 +591,7 @@ int ioctl_swdl(unsigned long arg) { // it fails if you try and send frags out of order // and for some yet unknown reasons too - printk("i2o_config: swdl failed, DetailedStatus = %d\n", status); + printk(KERN_INFO "i2o_config: swdl failed, DetailedStatus = %d\n", status); return -ETIMEDOUT; } @@ -562,7 +653,7 @@ int ioctl_swul(unsigned long arg) if (status != I2O_POST_WAIT_OK) { kfree(buffer); - printk("i2o_config: swul failed, DetailedStatus = %d\n", status); + printk(KERN_INFO "i2o_config: swul failed, DetailedStatus = %d\n", status); return -ETIMEDOUT; } @@ -603,7 +694,7 @@ int ioctl_swdel(unsigned long arg) if (token != I2O_POST_WAIT_OK) { - printk("i2o_config: swdel failed, DetailedStatus = %d\n", token); + printk(KERN_INFO "i2o_config: swdel failed, DetailedStatus = %d\n", token); return -ETIMEDOUT; } @@ -631,7 +722,7 @@ int ioctl_validate(unsigned long arg) if (token != I2O_POST_WAIT_OK) { - printk("Can't validate configuration, ErrorStatus = %d\n", + printk(KERN_INFO "Can't validate configuration, ErrorStatus = %d\n", token); return -ETIMEDOUT; } @@ -639,22 +730,154 @@ int ioctl_validate(unsigned long arg) return 0; } +static int ioctl_evt_reg(unsigned long arg, struct file *fp) +{ + u32 msg[5]; + struct i2o_evt_id *pdesc = (struct i2o_evt_id *)arg; + struct i2o_evt_id kdesc; + struct i2o_controller *iop; + struct i2o_device *d; + + if (copy_from_user(&kdesc, pdesc, sizeof(struct i2o_evt_id))) + return -EFAULT; + + /* IOP exists? */ + iop = i2o_find_controller(kdesc.iop); + if(!iop) + return -ENXIO; + i2o_unlock_controller(iop); + + /* Device exists? */ + for(d = iop->devices; d; d = d->next) + if(d->lct_data->tid == kdesc.tid) + break; + + if(!d) + return -ENODEV; + + msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0; + msg[1] = I2O_CMD_UTIL_EVT_REGISTER<<24 | HOST_TID<<12 | kdesc.tid; + msg[2] = (u32)i2o_cfg_context; + msg[3] = (u32)fp->private_data; + msg[4] = kdesc.evt_mask; + + i2o_post_this(iop, msg, 20); + + return 0; +} + +static int ioctl_evt_get(unsigned long arg, struct file *fp) +{ + u32 id = (u32)fp->private_data; + struct i2o_cfg_info *p = NULL; + struct i2o_evt_get *uget = (struct i2o_evt_get*)arg; + struct i2o_evt_get kget; + unsigned int flags; + + // access_ok doesn't check for NULL?!?! + if(!arg) + return -EFAULT; + + if(!access_ok(VERIFY_WRITE, uget, sizeof(struct i2o_evt_get))) + return -EFAULT; + + for(p = open_files; p; p = p->next) + if(p->q_id == id) + break; + + if(!p->q_len) + { + return -ENOENT; + return 0; + } + + memcpy(&kget.info, &p->event_q[p->q_out], sizeof(struct i2o_evt_info)); + MODINC(p->q_out, I2O_EVT_Q_LEN); + spin_lock_irqsave(&i2o_config_lock, flags); + p->q_len--; + kget.pending = p->q_len; + kget.lost = p->q_lost; + spin_unlock_irqrestore(&i2o_config_lock, flags); + + __copy_to_user(uget, &kget, sizeof(struct i2o_evt_get)); + + return 0; +} static int cfg_open(struct inode *inode, struct file *file) { - /* - * Should support multiple management users - */ + struct i2o_cfg_info *tmp = + (struct i2o_cfg_info *)kmalloc(sizeof(struct i2o_cfg_info), GFP_KERNEL); + unsigned int flags; + + if(!tmp) + return -ENOMEM; + + file->private_data = (void*)(i2o_cfg_info_id++); + tmp->fp = file; + tmp->fasync = NULL; + tmp->q_id = (u32)file->private_data; + tmp->q_len = 0; + tmp->q_in = 0; + tmp->q_out = 0; + tmp->q_lost = 0; + tmp->next = open_files; + + spin_lock_irqsave(&i2o_config_lock, flags); + open_files = tmp; + spin_unlock_irqrestore(&i2o_config_lock, flags); + MOD_INC_USE_COUNT; return 0; } static int cfg_release(struct inode *inode, struct file *file) { + u32 id = (u32)file->private_data; + struct i2o_cfg_info *p1, *p2; + unsigned int flags; + + p1 = p2 = NULL; + + spin_lock_irqsave(&i2o_config_lock, flags); + for(p1 = open_files; p1; ) + { + if(p1->q_id == id) + { + + if(p1->fasync) + cfg_fasync(-1, file, 0); + if(p2) + p2->next = p1->next; + else + open_files = p1->next; + + kfree(p1); + break; + } + p2 = p1; + p1 = p1->next; + } + spin_unlock_irqrestore(&i2o_config_lock, flags); + MOD_DEC_USE_COUNT; return 0; } +static int cfg_fasync(int fd, struct file *fp, int on) +{ + u32 id = (u32)fp->private_data; + struct i2o_cfg_info *p; + + for(p = open_files; p; p = p->next) + if(p->q_id == id) + break; + + if(!p) + return -EBADF; + + return fasync_helper(fd, fp, on, &p->fasync); +} static struct file_operations config_fops = { @@ -667,7 +890,9 @@ static struct file_operations config_fops = NULL, /* No mmap */ cfg_open, NULL, /* No flush */ - cfg_release + cfg_release, + NULL, + cfg_fasync }; static struct miscdevice i2o_miscdev = { @@ -682,7 +907,8 @@ int init_module(void) int __init i2o_config_init(void) #endif { - printk(KERN_INFO "i2o configuration manager v 0.03\n"); + printk(KERN_INFO "I2O configuration manager v 0.04.\n"); + printk(KERN_INFO " (C) Copyright 1999 Red Hat Software"); if((page_buf = kmalloc(4096, GFP_KERNEL))==NULL) { |