Merge master.kernel.org:/pub/scm/linux/kernel/git/steve/gfs2-2.6-nmw
[pandora-kernel.git] / drivers / block / cciss.c
index c834305..892e092 100644 (file)
@@ -141,7 +141,6 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
                       unsigned int cmd, unsigned long arg);
 static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo);
 
-static int revalidate_allvol(ctlr_info_t *host);
 static int cciss_revalidate(struct gendisk *disk);
 static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk);
 static int deregister_disk(struct gendisk *disk, drive_info_struct *drv,
@@ -857,9 +856,7 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
                }
 
        case CCISS_REVALIDVOLS:
-               if (bdev != bdev->bd_contains || drv != host->drv)
-                       return -ENXIO;
-               return revalidate_allvol(host);
+               return rebuild_lun_table(host, NULL);
 
        case CCISS_GETLUNINFO:{
                        LogvolInfo_struct luninfo;
@@ -1159,75 +1156,6 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
        }
 }
 
-/*
- * revalidate_allvol is for online array config utilities.  After a
- * utility reconfigures the drives in the array, it can use this function
- * (through an ioctl) to make the driver zap any previous disk structs for
- * that controller and get new ones.
- *
- * Right now I'm using the getgeometry() function to do this, but this
- * function should probably be finer grained and allow you to revalidate one
- * particular logical volume (instead of all of them on a particular
- * controller).
- */
-static int revalidate_allvol(ctlr_info_t *host)
-{
-       int ctlr = host->ctlr, i;
-       unsigned long flags;
-
-       spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
-       if (host->usage_count > 1) {
-               spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
-               printk(KERN_WARNING "cciss: Device busy for volume"
-                      " revalidation (usage=%d)\n", host->usage_count);
-               return -EBUSY;
-       }
-       host->usage_count++;
-       spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
-
-       for (i = 0; i < NWD; i++) {
-               struct gendisk *disk = host->gendisk[i];
-               if (disk) {
-                       request_queue_t *q = disk->queue;
-
-                       if (disk->flags & GENHD_FL_UP)
-                               del_gendisk(disk);
-                       if (q)
-                               blk_cleanup_queue(q);
-               }
-       }
-
-       /*
-        * Set the partition and block size structures for all volumes
-        * on this controller to zero.  We will reread all of this data
-        */
-       memset(host->drv, 0, sizeof(drive_info_struct)
-              * CISS_MAX_LUN);
-       /*
-        * Tell the array controller not to give us any interrupts while
-        * we check the new geometry.  Then turn interrupts back on when
-        * we're done.
-        */
-       host->access.set_intr_mask(host, CCISS_INTR_OFF);
-       cciss_getgeometry(ctlr);
-       host->access.set_intr_mask(host, CCISS_INTR_ON);
-
-       /* Loop through each real device */
-       for (i = 0; i < NWD; i++) {
-               struct gendisk *disk = host->gendisk[i];
-               drive_info_struct *drv = &(host->drv[i]);
-               /* we must register the controller even if no disks exist */
-               /* this is for the online array utilities */
-               if (!drv->heads && i)
-                       continue;
-               blk_queue_hardsect_size(drv->queue, drv->block_size);
-               set_capacity(disk, drv->nr_blocks);
-               add_disk(disk);
-       }
-       host->usage_count--;
-       return 0;
-}
-
 static inline void complete_buffers(struct bio *bio, int status)
 {
        while (bio) {
@@ -1387,6 +1315,11 @@ static void cciss_update_drive_info(int ctlr, int drv_index)
        /* if it's the controller it's already added */
        if (drv_index) {
                disk->queue = blk_init_queue(do_cciss_request, &h->lock);
+               sprintf(disk->disk_name, "cciss/c%dd%d", ctlr, drv_index);
+               disk->major = h->major;
+               disk->first_minor = drv_index << NWD_SHIFT;
+               disk->fops = &cciss_fops;
+               disk->private_data = &h->drv[drv_index];
 
                /* Set up queue information */
                disk->queue->backing_dev_info.ra_pages = READ_AHEAD;
@@ -1465,11 +1398,6 @@ static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk)
 
        /* Set busy_configuring flag for this operation */
        spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
-       if (h->num_luns >= CISS_MAX_LUN) {
-               spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
-               return -EINVAL;
-       }
-
        if (h->busy_configuring) {
                spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
                return -EBUSY;
@@ -1502,17 +1430,8 @@ static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk)
                                              0, 0, TYPE_CMD);
 
                if (return_code == IO_OK) {
-                       listlength |=
-                           (0xff & (unsigned int)(ld_buff->LUNListLength[0]))
-                           << 24;
-                       listlength |=
-                           (0xff & (unsigned int)(ld_buff->LUNListLength[1]))
-                           << 16;
-                       listlength |=
-                           (0xff & (unsigned int)(ld_buff->LUNListLength[2]))
-                           << 8;
-                       listlength |=
-                           0xff & (unsigned int)(ld_buff->LUNListLength[3]);
+                       listlength =
+                               be32_to_cpu(*(__u32 *) ld_buff->LUNListLength);
                } else {        /* reading number of logical volumes failed */
                        printk(KERN_WARNING "cciss: report logical volume"
                               " command failed\n");
@@ -1563,6 +1482,14 @@ static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk)
                                if (drv_index == -1)
                                        goto freeret;
 
+                               /*Check if the gendisk needs to be allocated */
+                               if (!h->gendisk[drv_index]){
+                                       h->gendisk[drv_index] = alloc_disk(1 << NWD_SHIFT);
+                                       if (!h->gendisk[drv_index]){
+                                               printk(KERN_ERR "cciss: could not allocate new disk %d\n", drv_index);
+                                               goto mem_msg;
+                                       }
+                               }
                        }
                        h->drv[drv_index].LunID = lunid;
                        cciss_update_drive_info(ctlr, drv_index);
@@ -1600,6 +1527,7 @@ static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk)
 static int deregister_disk(struct gendisk *disk, drive_info_struct *drv,
                           int clear_all)
 {
+       int i;
        ctlr_info_t *h = get_host(disk);
 
        if (!capable(CAP_SYS_RAWIO))
@@ -1623,9 +1551,35 @@ static int deregister_disk(struct gendisk *disk, drive_info_struct *drv,
                                del_gendisk(disk);
                        if (q) {
                                blk_cleanup_queue(q);
+                               /* Set drv->queue to NULL so that we do not try
+                                * to call blk_start_queue on this queue in the
+                                * interrupt handler
+                                */
                                drv->queue = NULL;
                        }
+                       /* If clear_all is set then we are deleting the logical
+                        * drive, not just refreshing its info.  For drives
+                        * other than disk 0 we will call put_disk.  We do not
+                        * do this for disk 0 as we need it to be able to
+                        * configure the controller.
+                       */
+                       if (clear_all){
+                               /* This isn't pretty, but we need to find the
+                                * disk in our array and NULL our the pointer.
+                                * This is so that we will call alloc_disk if
+                                * this index is used again later.
+                               */
+                               for (i=0; i < CISS_MAX_LUN; i++){
+                                       if(h->gendisk[i] == disk){
+                                               h->gendisk[i] = NULL;
+                                               break;
+                                       }
+                               }
+                               put_disk(disk);
+                       }
                }
+       } else {
+               set_capacity(disk, 0);
        }
 
        --h->num_luns;
@@ -2834,23 +2788,21 @@ static void __devinit cciss_interrupt_mode(ctlr_info_t *c,
                if (err > 0) {
                        printk(KERN_WARNING "cciss: only %d MSI-X vectors "
                               "available\n", err);
+                       goto default_int_mode;
                } else {
                        printk(KERN_WARNING "cciss: MSI-X init failed %d\n",
                               err);
+                       goto default_int_mode;
                }
        }
        if (pci_find_capability(pdev, PCI_CAP_ID_MSI)) {
                if (!pci_enable_msi(pdev)) {
-                       c->intr[SIMPLE_MODE_INT] = pdev->irq;
                        c->msi_vector = 1;
-                       return;
                } else {
                        printk(KERN_WARNING "cciss: MSI init failed\n");
-                       c->intr[SIMPLE_MODE_INT] = pdev->irq;
-                       return;
                }
        }
-      default_int_mode:
+default_int_mode:
 #endif                         /* CONFIG_PCI_MSI */
        /* if we get here we're going to use the default interrupt mode */
        c->intr[SIMPLE_MODE_INT] = pdev->irq;
@@ -3191,13 +3143,7 @@ geo_inq:
 /* Returns -1 if no free entries are left.  */
 static int alloc_cciss_hba(void)
 {
-       struct gendisk *disk[NWD];
-       int i, n;
-       for (n = 0; n < NWD; n++) {
-               disk[n] = alloc_disk(1 << NWD_SHIFT);
-               if (!disk[n])
-                       goto out;
-       }
+       int i;
 
        for (i = 0; i < MAX_CTLR; i++) {
                if (!hba[i]) {
@@ -3205,20 +3151,18 @@ static int alloc_cciss_hba(void)
                        p = kzalloc(sizeof(ctlr_info_t), GFP_KERNEL);
                        if (!p)
                                goto Enomem;
-                       for (n = 0; n < NWD; n++)
-                               p->gendisk[n] = disk[n];
+                       p->gendisk[0] = alloc_disk(1 << NWD_SHIFT);
+                       if (!p->gendisk[0])
+                               goto Enomem;
                        hba[i] = p;
                        return i;
                }
        }
        printk(KERN_WARNING "cciss: This driver supports a maximum"
               " of %d controllers.\n", MAX_CTLR);
-       goto out;
-      Enomem:
+       return -1;
+Enomem:
        printk(KERN_ERR "cciss: out of memory.\n");
-      out:
-       while (n--)
-               put_disk(disk[n]);
        return -1;
 }
 
@@ -3228,7 +3172,7 @@ static void free_hba(int i)
        int n;
 
        hba[i] = NULL;
-       for (n = 0; n < NWD; n++)
+       for (n = 0; n < CISS_MAX_LUN; n++)
                put_disk(p->gendisk[n]);
        kfree(p);
 }
@@ -3241,9 +3185,8 @@ static void free_hba(int i)
 static int __devinit cciss_init_one(struct pci_dev *pdev,
                                    const struct pci_device_id *ent)
 {
-       request_queue_t *q;
        int i;
-       int j;
+       int j = 0;
        int rc;
        int dac;
 
@@ -3355,16 +3298,29 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
 
        hba[i]->busy_initializing = 0;
 
-       for (j = 0; j < NWD; j++) {     /* mfm */
+       do {
                drive_info_struct *drv = &(hba[i]->drv[j]);
                struct gendisk *disk = hba[i]->gendisk[j];
+               request_queue_t *q;
+
+               /* Check if the disk was allocated already */
+               if (!disk){
+                       hba[i]->gendisk[j] = alloc_disk(1 << NWD_SHIFT);
+                       disk = hba[i]->gendisk[j];
+               }
+
+               /* Check that the disk was able to be allocated */
+               if (!disk) {
+                       printk(KERN_ERR "cciss: unable to allocate memory for disk %d\n", j);
+                       goto clean4;
+               }
 
                q = blk_init_queue(do_cciss_request, &hba[i]->lock);
                if (!q) {
                        printk(KERN_ERR
                               "cciss:  unable to allocate queue for disk %d\n",
                               j);
-                       break;
+                       goto clean4;
                }
                drv->queue = q;
 
@@ -3396,7 +3352,8 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
                blk_queue_hardsect_size(q, drv->block_size);
                set_capacity(disk, drv->nr_blocks);
                add_disk(disk);
-       }
+               j++;
+       } while (j <= hba[i]->highest_lun);
 
        return 1;
 
@@ -3419,6 +3376,15 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
        unregister_blkdev(hba[i]->major, hba[i]->devname);
       clean1:
        hba[i]->busy_initializing = 0;
+       /* cleanup any queues that may have been initialized */
+       for (j=0; j <= hba[i]->highest_lun; j++){
+               drive_info_struct *drv = &(hba[i]->drv[j]);
+               if (drv->queue)
+                       blk_cleanup_queue(drv->queue);
+       }
+       pci_release_regions(pdev);
+       pci_disable_device(pdev);
+       pci_set_drvdata(pdev, NULL);
        free_hba(i);
        return -1;
 }
@@ -3466,7 +3432,7 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
        remove_proc_entry(hba[i]->devname, proc_cciss);
 
        /* remove it from the disk list */
-       for (j = 0; j < NWD; j++) {
+       for (j = 0; j < CISS_MAX_LUN; j++) {
                struct gendisk *disk = hba[i]->gendisk[j];
                if (disk) {
                        request_queue_t *q = disk->queue;