headers: smp_lock.h redux
[safe/jmp/linux-2.6] / drivers / block / cpqarray.c
index 570d2f0..44fa201 100644 (file)
@@ -37,6 +37,7 @@
 #include <linux/spinlock.h>
 #include <linux/blkdev.h>
 #include <linux/genhd.h>
+#include <linux/scatterlist.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
@@ -155,18 +156,17 @@ static int sendcmd(
        unsigned int blkcnt,
        unsigned int log_unit );
 
-static int ida_open(struct inode *inode, struct file *filep);
-static int ida_release(struct inode *inode, struct file *filep);
-static int ida_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg);
+static int ida_open(struct block_device *bdev, fmode_t mode);
+static int ida_release(struct gendisk *disk, fmode_t mode);
+static int ida_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg);
 static int ida_getgeo(struct block_device *bdev, struct hd_geometry *geo);
 static int ida_ctlr_ioctl(ctlr_info_t *h, int dsk, ida_ioctl_t *io);
 
-static void do_ida_request(request_queue_t *q);
+static void do_ida_request(struct request_queue *q);
 static void start_io(ctlr_info_t *h);
 
 static inline void addQ(cmdlist_t **Qptr, cmdlist_t *c);
 static inline cmdlist_t *removeQ(cmdlist_t **Qptr, cmdlist_t *c);
-static inline void complete_buffers(struct bio *bio, int ok);
 static inline void complete_command(cmdlist_t *cmd, int timeout);
 
 static irqreturn_t do_ida_intr(int irq, void *dev_id);
@@ -197,7 +197,7 @@ static struct block_device_operations ida_fops  = {
        .owner          = THIS_MODULE,
        .open           = ida_open,
        .release        = ida_release,
-       .ioctl          = ida_ioctl,
+       .locked_ioctl   = ida_ioctl,
        .getgeo         = ida_getgeo,
        .revalidate_disk= ida_revalidate,
 };
@@ -214,7 +214,7 @@ static struct proc_dir_entry *proc_array;
 static void __init ida_procinit(int i)
 {
        if (proc_array == NULL) {
-               proc_array = proc_mkdir("cpqarray", proc_root_driver);
+               proc_array = proc_mkdir("driver/cpqarray", NULL);
                if (!proc_array) return;
        }
 
@@ -391,7 +391,7 @@ static void __devexit cpqarray_remove_one_eisa (int i)
 /* pdev is NULL for eisa */
 static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
 {
-       request_queue_t *q;
+       struct request_queue *q;
        int j;
 
        /* 
@@ -420,18 +420,17 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
                        goto Enomem2;
        }
 
-       hba[i]->cmd_pool = (cmdlist_t *)pci_alloc_consistent(
+       hba[i]->cmd_pool = pci_alloc_consistent(
                hba[i]->pci_dev, NR_CMDS * sizeof(cmdlist_t),
                &(hba[i]->cmd_pool_dhandle));
-       hba[i]->cmd_pool_bits = kmalloc(
-               ((NR_CMDS+BITS_PER_LONG-1)/BITS_PER_LONG)*sizeof(unsigned long),
+       hba[i]->cmd_pool_bits = kcalloc(
+               DIV_ROUND_UP(NR_CMDS, BITS_PER_LONG), sizeof(unsigned long),
                GFP_KERNEL);
 
        if (!hba[i]->cmd_pool_bits || !hba[i]->cmd_pool)
                        goto Enomem1;
 
        memset(hba[i]->cmd_pool, 0, NR_CMDS * sizeof(cmdlist_t));
-       memset(hba[i]->cmd_pool_bits, 0, ((NR_CMDS+BITS_PER_LONG-1)/BITS_PER_LONG)*sizeof(unsigned long));
        printk(KERN_INFO "cpqarray: Finding drives on %s",
                hba[i]->devname);
 
@@ -475,7 +474,7 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
                disk->fops = &ida_fops;
                if (j && !drv->nr_blks)
                        continue;
-               blk_queue_hardsect_size(hba[i]->queue, drv->blk_size);
+               blk_queue_logical_block_size(hba[i]->queue, drv->blk_size);
                set_capacity(disk, drv->nr_blks);
                disk->queue = hba[i]->queue;
                disk->private_data = drv;
@@ -568,7 +567,12 @@ static int __init cpqarray_init(void)
                        num_cntlrs_reg++;
        }
 
-       return(num_cntlrs_reg);
+       if (num_cntlrs_reg)
+               return 0;
+       else {
+               pci_unregister_driver(&cpqarray_pci_driver);
+               return -ENODEV;
+       }
 }
 
 /* Function to find the first free pointer into our hba[] array */
@@ -613,6 +617,7 @@ static int cpqarray_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
        int i;
 
        c->pci_dev = pdev;
+       pci_set_master(pdev);
        if (pci_enable_device(pdev)) {
                printk(KERN_ERR "cpqarray: Unable to Enable PCI device\n");
                return -1;
@@ -819,12 +824,12 @@ DBGINFO(
 /*
  * Open.  Make sure the device is really there.
  */
-static int ida_open(struct inode *inode, struct file *filep)
+static int ida_open(struct block_device *bdev, fmode_t mode)
 {
-       drv_info_t *drv = get_drv(inode->i_bdev->bd_disk);
-       ctlr_info_t *host = get_host(inode->i_bdev->bd_disk);
+       drv_info_t *drv = get_drv(bdev->bd_disk);
+       ctlr_info_t *host = get_host(bdev->bd_disk);
 
-       DBGINFO(printk("ida_open %s\n", inode->i_bdev->bd_disk->disk_name));
+       DBGINFO(printk("ida_open %s\n", bdev->bd_disk->disk_name));
        /*
         * Root is allowed to open raw volume zero even if it's not configured
         * so array config can still work.  I don't think I really like this,
@@ -844,9 +849,9 @@ static int ida_open(struct inode *inode, struct file *filep)
 /*
  * Close.  Sync first.
  */
-static int ida_release(struct inode *inode, struct file *filep)
+static int ida_release(struct gendisk *disk, fmode_t mode)
 {
-       ctlr_info_t *host = get_host(inode->i_bdev->bd_disk);
+       ctlr_info_t *host = get_host(disk);
        host->usage_count--;
        return 0;
 }
@@ -886,7 +891,7 @@ static inline cmdlist_t *removeQ(cmdlist_t **Qptr, cmdlist_t *c)
  * are in here (either via the dummy do_ida_request functions or by being
  * called from the interrupt handler
  */
-static void do_ida_request(request_queue_t *q)
+static void do_ida_request(struct request_queue *q)
 {
        ctlr_info_t *h = q->queuedata;
        cmdlist_t *c;
@@ -898,7 +903,7 @@ static void do_ida_request(request_queue_t *q)
                goto startio;
 
 queue_next:
-       creq = elv_next_request(q);
+       creq = blk_peek_request(q);
        if (!creq)
                goto startio;
 
@@ -907,18 +912,20 @@ queue_next:
        if ((c = cmd_alloc(h,1)) == NULL)
                goto startio;
 
-       blkdev_dequeue_request(creq);
+       blk_start_request(creq);
 
        c->ctlr = h->ctlr;
        c->hdr.unit = (drv_info_t *)(creq->rq_disk->private_data) - h->drv;
        c->hdr.size = sizeof(rblk_t) >> 2;
        c->size += sizeof(rblk_t);
 
-       c->req.hdr.blk = creq->sector;
+       c->req.hdr.blk = blk_rq_pos(creq);
        c->rq = creq;
 DBGPX(
-       printk("sector=%d, nr_sectors=%d\n", creq->sector, creq->nr_sectors);
+       printk("sector=%d, nr_sectors=%u\n",
+              blk_rq_pos(creq), blk_rq_sectors(creq));
 );
+       sg_init_table(tmp_sg, SG_MAX);
        seg = blk_rq_map_sg(q, creq, tmp_sg);
 
        /* Now do all the DMA Mappings */
@@ -930,13 +937,13 @@ DBGPX(
        {
                c->req.sg[i].size = tmp_sg[i].length;
                c->req.sg[i].addr = (__u32) pci_map_page(h->pci_dev,
-                                                tmp_sg[i].page,
+                                                sg_page(&tmp_sg[i]),
                                                 tmp_sg[i].offset,
                                                 tmp_sg[i].length, dir);
        }
-DBGPX( printk("Submitting %d sectors in %d segments\n", creq->nr_sectors, seg); );
+DBGPX( printk("Submitting %u sectors in %d segments\n", blk_rq_sectors(creq), seg); );
        c->req.hdr.sg_cnt = seg;
-       c->req.hdr.blk_cnt = creq->nr_sectors;
+       c->req.hdr.blk_cnt = blk_rq_sectors(creq);
        c->req.hdr.cmd = (rq_data_dir(creq) == READ) ? IDA_READ : IDA_WRITE;
        c->type = CMD_RWREQ;
 
@@ -979,26 +986,13 @@ static void start_io(ctlr_info_t *h)
        }
 }
 
-static inline void complete_buffers(struct bio *bio, int ok)
-{
-       struct bio *xbh;
-       while(bio) {
-               int nr_sectors = bio_sectors(bio);
-
-               xbh = bio->bi_next;
-               bio->bi_next = NULL;
-               
-               bio_endio(bio, nr_sectors << 9, ok ? 0 : -EIO);
-
-               bio = xbh;
-       }
-}
 /*
  * Mark all buffers that cmd was responsible for
  */
 static inline void complete_command(cmdlist_t *cmd, int timeout)
 {
-       int ok=1;
+       struct request *rq = cmd->rq;
+       int error = 0;
        int i, ddir;
 
        if (cmd->req.hdr.rcode & RCODE_NONFATAL &&
@@ -1010,16 +1004,17 @@ static inline void complete_command(cmdlist_t *cmd, int timeout)
        if (cmd->req.hdr.rcode & RCODE_FATAL) {
                printk(KERN_WARNING "Fatal error on ida/c%dd%d\n",
                                cmd->ctlr, cmd->hdr.unit);
-               ok = 0;
+               error = -EIO;
        }
        if (cmd->req.hdr.rcode & RCODE_INVREQ) {
                                printk(KERN_WARNING "Invalid request on ida/c%dd%d = (cmd=%x sect=%d cnt=%d sg=%d ret=%x)\n",
                                cmd->ctlr, cmd->hdr.unit, cmd->req.hdr.cmd,
                                cmd->req.hdr.blk, cmd->req.hdr.blk_cnt,
                                cmd->req.hdr.sg_cnt, cmd->req.hdr.rcode);
-               ok = 0; 
+               error = -EIO;
        }
-       if (timeout) ok = 0;
+       if (timeout)
+               error = -EIO;
        /* unmap the DMA mapping for all the scatter gather elements */
        if (cmd->req.hdr.cmd == IDA_READ)
                ddir = PCI_DMA_FROMDEVICE;
@@ -1029,12 +1024,8 @@ static inline void complete_command(cmdlist_t *cmd, int timeout)
                 pci_unmap_page(hba[cmd->ctlr]->pci_dev, cmd->req.sg[i].addr,
                                cmd->req.sg[i].size, ddir);
 
-       complete_buffers(cmd->rq->bio, ok);
-
-       add_disk_randomness(cmd->rq->rq_disk);
-
-        DBGPX(printk("Done with %p\n", cmd->rq););
-       end_that_request_last(cmd->rq, ok ? 1 : -EIO);
+       DBGPX(printk("Done with %p\n", rq););
+       __blk_end_request_all(rq, error);
 }
 
 /*
@@ -1143,10 +1134,10 @@ static int ida_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  *  ida_ioctl does some miscellaneous stuff like reporting drive geometry,
  *  setting readahead and submitting commands from userspace to the controller.
  */
-static int ida_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg)
+static int ida_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg)
 {
-       drv_info_t *drv = get_drv(inode->i_bdev->bd_disk);
-       ctlr_info_t *host = get_host(inode->i_bdev->bd_disk);
+       drv_info_t *drv = get_drv(bdev->bd_disk);
+       ctlr_info_t *host = get_host(bdev->bd_disk);
        int error;
        ida_ioctl_t __user *io = (ida_ioctl_t __user *)arg;
        ida_ioctl_t *my_io;
@@ -1180,7 +1171,7 @@ out_passthru:
                put_user(host->ctlr_sig, (int __user *)arg);
                return 0;
        case IDAREVALIDATEVOLS:
-               if (iminor(inode) != 0)
+               if (MINOR(bdev->bd_dev) != 0)
                        return -ENXIO;
                return revalidate_allvol(host);
        case IDADRIVERVERSION:
@@ -1555,7 +1546,7 @@ static int revalidate_allvol(ctlr_info_t *host)
                drv_info_t *drv = &host->drv[i];
                if (i && !drv->nr_blks)
                        continue;
-               blk_queue_hardsect_size(host->queue, drv->blk_size);
+               blk_queue_logical_block_size(host->queue, drv->blk_size);
                set_capacity(disk, drv->nr_blks);
                disk->queue = host->queue;
                disk->private_data = drv;
@@ -1618,7 +1609,7 @@ static void start_fwbk(int ctlr)
                " processing\n");
        /* Command does not return anything, but idasend command needs a 
                buffer */
-       id_ctlr_buf = (id_ctlr_t *)kmalloc(sizeof(id_ctlr_t), GFP_KERNEL);
+       id_ctlr_buf = kmalloc(sizeof(id_ctlr_t), GFP_KERNEL);
        if(id_ctlr_buf==NULL)
        {
                printk(KERN_WARNING "cpqarray: Out of memory. "
@@ -1653,45 +1644,30 @@ static void getgeometry(int ctlr)
 
        info_p->log_drv_map = 0;        
        
-       id_ldrive = (id_log_drv_t *)kmalloc(sizeof(id_log_drv_t), GFP_KERNEL);
-       if(id_ldrive == NULL)
-       {
+       id_ldrive = kzalloc(sizeof(id_log_drv_t), GFP_KERNEL);
+       if (!id_ldrive) {
                printk( KERN_ERR "cpqarray:  out of memory.\n");
-               return;
+               goto err_0;
        }
 
-       id_ctlr_buf = (id_ctlr_t *)kmalloc(sizeof(id_ctlr_t), GFP_KERNEL);
-       if(id_ctlr_buf == NULL)
-       {
-               kfree(id_ldrive);
+       id_ctlr_buf = kzalloc(sizeof(id_ctlr_t), GFP_KERNEL);
+       if (!id_ctlr_buf) {
                printk( KERN_ERR "cpqarray:  out of memory.\n");
-               return;
+               goto err_1;
        }
 
-       id_lstatus_buf = (sense_log_drv_stat_t *)kmalloc(sizeof(sense_log_drv_stat_t), GFP_KERNEL);
-       if(id_lstatus_buf == NULL)
-       {
-               kfree(id_ctlr_buf);
-               kfree(id_ldrive);
+       id_lstatus_buf = kzalloc(sizeof(sense_log_drv_stat_t), GFP_KERNEL);
+       if (!id_lstatus_buf) {
                printk( KERN_ERR "cpqarray:  out of memory.\n");
-               return;
+               goto err_2;
        }
 
-       sense_config_buf = (config_t *)kmalloc(sizeof(config_t), GFP_KERNEL);
-       if(sense_config_buf == NULL)
-       {
-               kfree(id_lstatus_buf);
-               kfree(id_ctlr_buf);
-               kfree(id_ldrive);
+       sense_config_buf = kzalloc(sizeof(config_t), GFP_KERNEL);
+       if (!sense_config_buf) {
                printk( KERN_ERR "cpqarray:  out of memory.\n");
-               return;
+               goto err_3;
        }
 
-       memset(id_ldrive, 0, sizeof(id_log_drv_t));
-       memset(id_ctlr_buf, 0, sizeof(id_ctlr_t));
-       memset(id_lstatus_buf, 0, sizeof(sense_log_drv_stat_t));
-       memset(sense_config_buf, 0, sizeof(config_t));
-
        info_p->phys_drives = 0;
        info_p->log_drv_map = 0;
        info_p->drv_assign_map = 0;
@@ -1705,13 +1681,8 @@ static void getgeometry(int ctlr)
                 * so the idastubopen will fail on all logical drives
                 * on the controller.
                 */
-                /* Free all the buffers and return */ 
                printk(KERN_ERR "cpqarray: error sending ID controller\n");
-               kfree(sense_config_buf);
-                kfree(id_lstatus_buf);
-                kfree(id_ctlr_buf);
-                kfree(id_ldrive);
-                return;
+                goto err_4;
         }
 
        info_p->log_drives = id_ctlr_buf->nr_drvs;
@@ -1757,12 +1728,7 @@ static void getgeometry(int ctlr)
                                " failed to report status of logical drive %d\n"
                         "Access to this controller has been disabled\n",
                                ctlr, log_unit);
-                       /* Free all the buffers and return */
-                       kfree(sense_config_buf);
-                       kfree(id_lstatus_buf);
-                       kfree(id_ctlr_buf);
-                       kfree(id_ldrive);
-                       return;
+                       goto err_4;
                }
                /*
                   Make sure the logical drive is configured
@@ -1791,14 +1757,8 @@ static void getgeometry(int ctlr)
                                 sizeof(config_t), 0, 0, log_unit);
                                if (ret_code == IO_ERROR) {
                                        info_p->log_drv_map = 0;
-                                       /* Free all the buffers and return */
                                        printk(KERN_ERR "cpqarray: error sending sense config\n");
-                                       kfree(sense_config_buf);
-                                       kfree(id_lstatus_buf);
-                                       kfree(id_ctlr_buf);
-                                       kfree(id_ldrive);
-                                       return;
-
+                                       goto err_4;
                                }
 
                                info_p->phys_drives =
@@ -1813,12 +1773,18 @@ static void getgeometry(int ctlr)
                        log_index = log_index + 1;
                }               /* end of if logical drive configured */
        }                       /* end of for log_unit */
+
+       /* Free all the buffers and return */
+err_4:
        kfree(sense_config_buf);
-       kfree(id_ldrive);
+err_3:
        kfree(id_lstatus_buf);
+err_2:
        kfree(id_ctlr_buf);
+err_1:
+       kfree(id_ldrive);
+err_0:
        return;
-
 }
 
 static void __exit cpqarray_exit(void)
@@ -1836,7 +1802,7 @@ static void __exit cpqarray_exit(void)
                }
        }
 
-       remove_proc_entry("cpqarray", proc_root_driver);
+       remove_proc_entry("driver/cpqarray", NULL);
 }
 
 module_init(cpqarray_init)