]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/block/cciss.c
[PATCH] cciss: support for >2TB logical volumes
[linux-2.6-omap-h63xx.git] / drivers / block / cciss.c
index 1c4df22dfd2a960a2309570e093828e570096d94..e707f39e990c991c79b9f169842f72539985fa21 100644 (file)
 #include <linux/completion.h>
 
 #define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
-#define DRIVER_NAME "HP CISS Driver (v 2.6.10)"
-#define DRIVER_VERSION CCISS_DRIVER_VERSION(2,6,10)
+#define DRIVER_NAME "HP CISS Driver (v 3.6.10)"
+#define DRIVER_VERSION CCISS_DRIVER_VERSION(3,6,10)
 
 /* Embedded module documentation macros - see modules.h */
 MODULE_AUTHOR("Hewlett-Packard Company");
-MODULE_DESCRIPTION("Driver for HP Controller SA5xxx SA6xxx version 2.6.10");
+MODULE_DESCRIPTION("Driver for HP Controller SA5xxx SA6xxx version 3.6.10");
 MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400"
-                       " SA6i P600 P800 P400 P400i E200 E200i");
+                       " SA6i P600 P800 P400 P400i E200 E200i E500");
 MODULE_LICENSE("GPL");
 
 #include "cciss_cmd.h"
@@ -82,6 +82,7 @@ static const struct pci_device_id cciss_pci_device_id[] = {
        {PCI_VENDOR_ID_HP,     PCI_DEVICE_ID_HP_CISSD,     0x103C, 0x3213},
        {PCI_VENDOR_ID_HP,     PCI_DEVICE_ID_HP_CISSD,     0x103C, 0x3214},
        {PCI_VENDOR_ID_HP,     PCI_DEVICE_ID_HP_CISSD,     0x103C, 0x3215},
+       {PCI_VENDOR_ID_HP,     PCI_DEVICE_ID_HP_CISSC,     0x103C, 0x3233},
        {0,}
 };
 
@@ -110,6 +111,7 @@ static struct board_type products[] = {
        {0x3213103C, "Smart Array E200i", &SA5_access},
        {0x3214103C, "Smart Array E200i", &SA5_access},
        {0x3215103C, "Smart Array E200i", &SA5_access},
+       {0x3233103C, "Smart Array E500", &SA5_access},
 };
 
 /* How long to wait (in milliseconds) for board to go into simple mode */
@@ -142,13 +144,13 @@ 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);
 
-static void cciss_read_capacity(int ctlr, int logvol, ReadCapdata_struct *buf,
-                               int withirq, unsigned int *total_size,
-                               unsigned int *block_size);
-static void cciss_geometry_inquiry(int ctlr, int logvol, int withirq,
-                                  unsigned int total_size,
-                                  unsigned int block_size,
-                                  InquiryData_struct *inq_buff,
+static void cciss_read_capacity(int ctlr, int logvol, int withirq,
+                       sector_t *total_size, unsigned int *block_size);
+static void cciss_read_capacity_16(int ctlr, int logvol, int withirq,
+                       sector_t *total_size, unsigned int *block_size);
+static void cciss_geometry_inquiry(int ctlr, int logvol,
+                       int withirq, sector_t total_size,
+                       unsigned int block_size, InquiryData_struct *inq_buff,
                                   drive_info_struct *drv);
 static void cciss_getgeometry(int cntl_num);
 static void __devinit cciss_interrupt_mode(ctlr_info_t *, struct pci_dev *,
@@ -1227,12 +1229,55 @@ static inline void complete_buffers(struct bio *bio, int status)
                int nr_sectors = bio_sectors(bio);
 
                bio->bi_next = NULL;
-               blk_finished_io(len);
                bio_endio(bio, nr_sectors << 9, status ? 0 : -EIO);
                bio = xbh;
        }
 }
 
+static void cciss_check_queues(ctlr_info_t *h)
+{
+       int start_queue = h->next_to_run;
+       int i;
+
+       /* check to see if we have maxed out the number of commands that can
+        * be placed on the queue.  If so then exit.  We do this check here
+        * in case the interrupt we serviced was from an ioctl and did not
+        * free any new commands.
+        */
+       if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS)
+               return;
+
+       /* We have room on the queue for more commands.  Now we need to queue
+        * them up.  We will also keep track of the next queue to run so
+        * that every queue gets a chance to be started first.
+        */
+       for (i = 0; i < h->highest_lun + 1; i++) {
+               int curr_queue = (start_queue + i) % (h->highest_lun + 1);
+               /* make sure the disk has been added and the drive is real
+                * because this can be called from the middle of init_one.
+                */
+               if (!(h->drv[curr_queue].queue) || !(h->drv[curr_queue].heads))
+                       continue;
+               blk_start_queue(h->gendisk[curr_queue]->queue);
+
+               /* check to see if we have maxed out the number of commands
+                * that can be placed on the queue.
+                */
+               if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS) {
+                       if (curr_queue == start_queue) {
+                               h->next_to_run =
+                                   (start_queue + 1) % (h->highest_lun + 1);
+                               break;
+                       } else {
+                               h->next_to_run = curr_queue;
+                               break;
+                       }
+               } else {
+                       curr_queue = (curr_queue + 1) % (h->highest_lun + 1);
+               }
+       }
+}
+
 static void cciss_softirq_done(struct request *rq)
 {
        CommandList_struct *cmd = rq->completion_data;
@@ -1264,6 +1309,7 @@ static void cciss_softirq_done(struct request *rq)
        spin_lock_irqsave(&h->lock, flags);
        end_that_request_last(rq, rq->errors);
        cmd_free(h, cmd, 1);
+       cciss_check_queues(h);
        spin_unlock_irqrestore(&h->lock, flags);
 }
 
@@ -1279,10 +1325,9 @@ static void cciss_update_drive_info(int ctlr, int drv_index)
 {
        ctlr_info_t *h = hba[ctlr];
        struct gendisk *disk;
-       ReadCapdata_struct *size_buff = NULL;
        InquiryData_struct *inq_buff = NULL;
        unsigned int block_size;
-       unsigned int total_size;
+       sector_t total_size;
        unsigned long flags = 0;
        int ret = 0;
 
@@ -1301,15 +1346,25 @@ static void cciss_update_drive_info(int ctlr, int drv_index)
                return;
 
        /* Get information about the disk and modify the driver structure */
-       size_buff = kmalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
-       if (size_buff == NULL)
-               goto mem_msg;
        inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL);
        if (inq_buff == NULL)
                goto mem_msg;
 
-       cciss_read_capacity(ctlr, drv_index, size_buff, 1,
+       cciss_read_capacity(ctlr, drv_index, 1,
                            &total_size, &block_size);
+
+       /* total size = last LBA + 1 */
+       /* FFFFFFFF + 1 = 0, cannot have a logical volume of size 0 */
+       /* so we assume this volume this must be >2TB in size */
+       if (total_size == (__u32) 0) {
+               cciss_read_capacity_16(ctlr, drv_index, 1,
+               &total_size, &block_size);
+               h->cciss_read = CCISS_READ_16;
+               h->cciss_write = CCISS_WRITE_16;
+       } else {
+               h->cciss_read = CCISS_READ_10;
+               h->cciss_write = CCISS_WRITE_10;
+       }
        cciss_geometry_inquiry(ctlr, drv_index, 1, total_size, block_size,
                               inq_buff, &h->drv[drv_index]);
 
@@ -1345,7 +1400,6 @@ static void cciss_update_drive_info(int ctlr, int drv_index)
        }
 
       freeret:
-       kfree(size_buff);
        kfree(inq_buff);
        return;
       mem_msg:
@@ -1670,6 +1724,22 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
                        c->Request.Timeout = 0;
                        c->Request.CDB[0] = cmd;
                        break;
+               case CCISS_READ_CAPACITY_16:
+                       c->Header.LUN.LogDev.VolId = h->drv[log_unit].LunID;
+                       c->Header.LUN.LogDev.Mode = 1;
+                       c->Request.CDBLen = 16;
+                       c->Request.Type.Attribute = ATTR_SIMPLE;
+                       c->Request.Type.Direction = XFER_READ;
+                       c->Request.Timeout = 0;
+                       c->Request.CDB[0] = cmd;
+                       c->Request.CDB[1] = 0x10;
+                       c->Request.CDB[10] = (size >> 24) & 0xFF;
+                       c->Request.CDB[11] = (size >> 16) & 0xFF;
+                       c->Request.CDB[12] = (size >> 8) & 0xFF;
+                       c->Request.CDB[13] = size & 0xFF;
+                       c->Request.Timeout = 0;
+                       c->Request.CDB[0] = cmd;
+                       break;
                case CCISS_CACHE_FLUSH:
                        c->Request.CDBLen = 12;
                        c->Request.Type.Attribute = ATTR_SIMPLE;
@@ -1703,6 +1773,7 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
                        memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB));
                        c->Request.CDB[0] = cmd;        /* reset */
                        c->Request.CDB[1] = 0x04;       /* reset a LUN */
+                       break;
                case 3: /* No-Op message */
                        c->Request.CDBLen = 1;
                        c->Request.Type.Attribute = ATTR_SIMPLE;
@@ -1846,12 +1917,15 @@ static int sendcmd_withirq(__u8 cmd,
 }
 
 static void cciss_geometry_inquiry(int ctlr, int logvol,
-                                  int withirq, unsigned int total_size,
+                                  int withirq, sector_t total_size,
                                   unsigned int block_size,
                                   InquiryData_struct *inq_buff,
                                   drive_info_struct *drv)
 {
        int return_code;
+       unsigned long t;
+       unsigned long rem;
+
        memset(inq_buff, 0, sizeof(InquiryData_struct));
        if (withirq)
                return_code = sendcmd_withirq(CISS_INQUIRY, ctlr,
@@ -1870,10 +1944,10 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
                        drv->nr_blocks = total_size;
                        drv->heads = 255;
                        drv->sectors = 32;      // Sectors per track
-                       drv->cylinders = total_size / 255 / 32;
+                       t = drv->heads * drv->sectors;
+                       drv->cylinders = total_size;
+                       rem = do_div(drv->cylinders, t);
                } else {
-                       unsigned int t;
-
                        drv->block_size = block_size;
                        drv->nr_blocks = total_size;
                        drv->heads = inq_buff->data_byte[6];
@@ -1883,7 +1957,8 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
                        drv->raid_level = inq_buff->data_byte[8];
                        t = drv->heads * drv->sectors;
                        if (t > 1) {
-                               drv->cylinders = total_size / t;
+                               drv->cylinders = total_size;
+                               rem = do_div(drv->cylinders, t);
                        }
                }
        } else {                /* Get geometry failed */
@@ -1894,31 +1969,72 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
 }
 
 static void
-cciss_read_capacity(int ctlr, int logvol, ReadCapdata_struct *buf,
-                   int withirq, unsigned int *total_size,
+cciss_read_capacity(int ctlr, int logvol, int withirq, sector_t *total_size,
                    unsigned int *block_size)
 {
+       ReadCapdata_struct *buf;
        int return_code;
-       memset(buf, 0, sizeof(*buf));
+       buf = kmalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
+       if (buf == NULL) {
+               printk(KERN_WARNING "cciss: out of memory\n");
+               return;
+       }
+       memset(buf, 0, sizeof(ReadCapdata_struct));
        if (withirq)
                return_code = sendcmd_withirq(CCISS_READ_CAPACITY,
-                                             ctlr, buf, sizeof(*buf), 1,
-                                             logvol, 0, TYPE_CMD);
+                               ctlr, buf, sizeof(ReadCapdata_struct),
+                                       1, logvol, 0, TYPE_CMD);
        else
                return_code = sendcmd(CCISS_READ_CAPACITY,
-                                     ctlr, buf, sizeof(*buf), 1, logvol, 0,
-                                     NULL, TYPE_CMD);
+                               ctlr, buf, sizeof(ReadCapdata_struct),
+                                       1, logvol, 0, NULL, TYPE_CMD);
        if (return_code == IO_OK) {
-               *total_size =
-                   be32_to_cpu(*((__be32 *) & buf->total_size[0])) + 1;
-               *block_size = be32_to_cpu(*((__be32 *) & buf->block_size[0]));
+               *total_size = be32_to_cpu(*(__u32 *) buf->total_size)+1;
+               *block_size = be32_to_cpu(*(__u32 *) buf->block_size);
        } else {                /* read capacity command failed */
                printk(KERN_WARNING "cciss: read capacity failed\n");
                *total_size = 0;
                *block_size = BLOCK_SIZE;
        }
-       printk(KERN_INFO "      blocks= %u block_size= %d\n",
+       if (*total_size != (__u32) 0)
+               printk(KERN_INFO "      blocks= %lld block_size= %d\n",
+               *total_size, *block_size);
+       kfree(buf);
+       return;
+}
+
+static void
+cciss_read_capacity_16(int ctlr, int logvol, int withirq, sector_t *total_size,                                unsigned int *block_size)
+{
+       ReadCapdata_struct_16 *buf;
+       int return_code;
+       buf = kmalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL);
+       if (buf == NULL) {
+               printk(KERN_WARNING "cciss: out of memory\n");
+               return;
+       }
+       memset(buf, 0, sizeof(ReadCapdata_struct_16));
+       if (withirq) {
+               return_code = sendcmd_withirq(CCISS_READ_CAPACITY_16,
+                       ctlr, buf, sizeof(ReadCapdata_struct_16),
+                               1, logvol, 0, TYPE_CMD);
+       }
+       else {
+               return_code = sendcmd(CCISS_READ_CAPACITY_16,
+                       ctlr, buf, sizeof(ReadCapdata_struct_16),
+                               1, logvol, 0, NULL, TYPE_CMD);
+       }
+       if (return_code == IO_OK) {
+               *total_size = be64_to_cpu(*(__u64 *) buf->total_size)+1;
+               *block_size = be32_to_cpu(*(__u32 *) buf->block_size);
+       } else {                /* read capacity command failed */
+               printk(KERN_WARNING "cciss: read capacity failed\n");
+               *total_size = 0;
+               *block_size = BLOCK_SIZE;
+       }
+       printk(KERN_INFO "      blocks= %lld block_size= %d\n",
               *total_size, *block_size);
+       kfree(buf);
        return;
 }
 
@@ -1929,8 +2045,7 @@ static int cciss_revalidate(struct gendisk *disk)
        int logvol;
        int FOUND = 0;
        unsigned int block_size;
-       unsigned int total_size;
-       ReadCapdata_struct *size_buff = NULL;
+       sector_t total_size;
        InquiryData_struct *inq_buff = NULL;
 
        for (logvol = 0; logvol < CISS_MAX_LUN; logvol++) {
@@ -1943,27 +2058,24 @@ static int cciss_revalidate(struct gendisk *disk)
        if (!FOUND)
                return 1;
 
-       size_buff = kmalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
-       if (size_buff == NULL) {
-               printk(KERN_WARNING "cciss: out of memory\n");
-               return 1;
-       }
        inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL);
        if (inq_buff == NULL) {
                printk(KERN_WARNING "cciss: out of memory\n");
-               kfree(size_buff);
                return 1;
        }
-
-       cciss_read_capacity(h->ctlr, logvol, size_buff, 1, &total_size,
-                           &block_size);
+       if (h->cciss_read == CCISS_READ_10) {
+               cciss_read_capacity(h->ctlr, logvol, 1,
+                                       &total_size, &block_size);
+       } else {
+               cciss_read_capacity_16(h->ctlr, logvol, 1,
+                                       &total_size, &block_size);
+       }
        cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size,
                               inq_buff, drv);
 
        blk_queue_hardsect_size(drv->queue, drv->block_size);
        set_capacity(disk, drv->nr_blocks);
 
-       kfree(size_buff);
        kfree(inq_buff);
        return 0;
 }
@@ -2372,7 +2484,8 @@ static void do_cciss_request(request_queue_t *q)
 {
        ctlr_info_t *h = q->queuedata;
        CommandList_struct *c;
-       int start_blk, seg;
+       sector_t start_blk;
+       int seg;
        struct request *creq;
        u64bit temp64;
        struct scatterlist tmp_sg[MAXSGENTRIES];
@@ -2416,10 +2529,10 @@ static void do_cciss_request(request_queue_t *q)
        c->Request.Type.Type = TYPE_CMD;        // It is a command.
        c->Request.Type.Attribute = ATTR_SIMPLE;
        c->Request.Type.Direction =
-           (rq_data_dir(creq) == READ) ? XFER_READ : XFER_WRITE;
+           (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write;
        c->Request.Timeout = 0; // Don't time out
        c->Request.CDB[0] =
-           (rq_data_dir(creq) == READ) ? CCISS_READ : CCISS_WRITE;
+           (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write;
        start_blk = creq->sector;
 #ifdef CCISS_DEBUG
        printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n", (int)creq->sector,
@@ -2453,15 +2566,33 @@ static void do_cciss_request(request_queue_t *q)
 #endif                         /* CCISS_DEBUG */
 
        c->Header.SGList = c->Header.SGTotal = seg;
-       c->Request.CDB[1] = 0;
-       c->Request.CDB[2] = (start_blk >> 24) & 0xff;   //MSB
-       c->Request.CDB[3] = (start_blk >> 16) & 0xff;
-       c->Request.CDB[4] = (start_blk >> 8) & 0xff;
-       c->Request.CDB[5] = start_blk & 0xff;
-       c->Request.CDB[6] = 0;  // (sect >> 24) & 0xff; MSB
-       c->Request.CDB[7] = (creq->nr_sectors >> 8) & 0xff;
-       c->Request.CDB[8] = creq->nr_sectors & 0xff;
-       c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
+       if(h->cciss_read == CCISS_READ_10) {
+               c->Request.CDB[1] = 0;
+               c->Request.CDB[2] = (start_blk >> 24) & 0xff;   //MSB
+               c->Request.CDB[3] = (start_blk >> 16) & 0xff;
+               c->Request.CDB[4] = (start_blk >> 8) & 0xff;
+               c->Request.CDB[5] = start_blk & 0xff;
+               c->Request.CDB[6] = 0;  // (sect >> 24) & 0xff; MSB
+               c->Request.CDB[7] = (creq->nr_sectors >> 8) & 0xff;
+               c->Request.CDB[8] = creq->nr_sectors & 0xff;
+               c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
+       } else {
+               c->Request.CDBLen = 16;
+               c->Request.CDB[1]= 0;
+               c->Request.CDB[2]= (start_blk >> 56) & 0xff;    //MSB
+               c->Request.CDB[3]= (start_blk >> 48) & 0xff;
+               c->Request.CDB[4]= (start_blk >> 40) & 0xff;
+               c->Request.CDB[5]= (start_blk >> 32) & 0xff;
+               c->Request.CDB[6]= (start_blk >> 24) & 0xff;
+               c->Request.CDB[7]= (start_blk >> 16) & 0xff;
+               c->Request.CDB[8]= (start_blk >>  8) & 0xff;
+               c->Request.CDB[9]= start_blk & 0xff;
+               c->Request.CDB[10]= (creq->nr_sectors >>  24) & 0xff;
+               c->Request.CDB[11]= (creq->nr_sectors >>  16) & 0xff;
+               c->Request.CDB[12]= (creq->nr_sectors >>  8) & 0xff;
+               c->Request.CDB[13]= creq->nr_sectors & 0xff;
+               c->Request.CDB[14] = c->Request.CDB[15] = 0;
+       }
 
        spin_lock_irq(q->queue_lock);
 
@@ -2471,9 +2602,9 @@ static void do_cciss_request(request_queue_t *q)
                h->maxQsinceinit = h->Qdepth;
 
        goto queue;
-      full:
+full:
        blk_stop_queue(q);
-      startio:
+startio:
        /* We will already have the driver lock here so not need
         * to lock it.
         */
@@ -2528,8 +2659,6 @@ static irqreturn_t do_cciss_intr(int irq, void *dev_id, struct pt_regs *regs)
        CommandList_struct *c;
        unsigned long flags;
        __u32 a, a1, a2;
-       int j;
-       int start_queue = h->next_to_run;
 
        if (interrupt_not_for_us(h))
                return IRQ_NONE;
@@ -2588,45 +2717,6 @@ static irqreturn_t do_cciss_intr(int irq, void *dev_id, struct pt_regs *regs)
                }
        }
 
-       /* check to see if we have maxed out the number of commands that can
-        * be placed on the queue.  If so then exit.  We do this check here
-        * in case the interrupt we serviced was from an ioctl and did not
-        * free any new commands.
-        */
-       if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS)
-               goto cleanup;
-
-       /* We have room on the queue for more commands.  Now we need to queue
-        * them up.  We will also keep track of the next queue to run so
-        * that every queue gets a chance to be started first.
-        */
-       for (j = 0; j < h->highest_lun + 1; j++) {
-               int curr_queue = (start_queue + j) % (h->highest_lun + 1);
-               /* make sure the disk has been added and the drive is real
-                * because this can be called from the middle of init_one.
-                */
-               if (!(h->drv[curr_queue].queue) || !(h->drv[curr_queue].heads))
-                       continue;
-               blk_start_queue(h->gendisk[curr_queue]->queue);
-
-               /* check to see if we have maxed out the number of commands
-                * that can be placed on the queue.
-                */
-               if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS) {
-                       if (curr_queue == start_queue) {
-                               h->next_to_run =
-                                   (start_queue + 1) % (h->highest_lun + 1);
-                               goto cleanup;
-                       } else {
-                               h->next_to_run = curr_queue;
-                               goto cleanup;
-                       }
-               } else {
-                       curr_queue = (curr_queue + 1) % (h->highest_lun + 1);
-               }
-       }
-
-      cleanup:
        spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
        return IRQ_HANDLED;
 }
@@ -2942,31 +3032,23 @@ static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
 static void cciss_getgeometry(int cntl_num)
 {
        ReportLunData_struct *ld_buff;
-       ReadCapdata_struct *size_buff;
        InquiryData_struct *inq_buff;
        int return_code;
        int i;
        int listlength = 0;
        __u32 lunid = 0;
        int block_size;
-       int total_size;
+       sector_t total_size;
 
        ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
        if (ld_buff == NULL) {
                printk(KERN_ERR "cciss: out of memory\n");
                return;
        }
-       size_buff = kmalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
-       if (size_buff == NULL) {
-               printk(KERN_ERR "cciss: out of memory\n");
-               kfree(ld_buff);
-               return;
-       }
        inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL);
        if (inq_buff == NULL) {
                printk(KERN_ERR "cciss: out of memory\n");
                kfree(ld_buff);
-               kfree(size_buff);
                return;
        }
        /* Get the firmware version */
@@ -3021,7 +3103,6 @@ static void cciss_getgeometry(int cntl_num)
 #endif                         /* CCISS_DEBUG */
 
        hba[cntl_num]->highest_lun = hba[cntl_num]->num_luns - 1;
-//      for(i=0; i<  hba[cntl_num]->num_luns; i++)
        for (i = 0; i < CISS_MAX_LUN; i++) {
                if (i < hba[cntl_num]->num_luns) {
                        lunid = (0xff & (unsigned int)(ld_buff->LUN[i][3]))
@@ -3040,8 +3121,26 @@ static void cciss_getgeometry(int cntl_num)
                               ld_buff->LUN[i][2], ld_buff->LUN[i][3],
                               hba[cntl_num]->drv[i].LunID);
 #endif                         /* CCISS_DEBUG */
-                       cciss_read_capacity(cntl_num, i, size_buff, 0,
+
+               /* testing to see if 16-byte CDBs are already being used */
+               if(hba[cntl_num]->cciss_read == CCISS_READ_16) {
+                       cciss_read_capacity_16(cntl_num, i, 0,
                                            &total_size, &block_size);
+                       goto geo_inq;
+               }
+               cciss_read_capacity(cntl_num, i, 0, &total_size, &block_size);
+
+               /* total_size = last LBA + 1 */
+               if(total_size == (__u32) 0) {
+                       cciss_read_capacity_16(cntl_num, i, 0,
+                       &total_size, &block_size);
+                       hba[cntl_num]->cciss_read = CCISS_READ_16;
+                       hba[cntl_num]->cciss_write = CCISS_WRITE_16;
+               } else {
+                       hba[cntl_num]->cciss_read = CCISS_READ_10;
+                       hba[cntl_num]->cciss_write = CCISS_WRITE_10;
+               }
+geo_inq:
                        cciss_geometry_inquiry(cntl_num, i, 0, total_size,
                                               block_size, inq_buff,
                                               &hba[cntl_num]->drv[i]);
@@ -3051,7 +3150,6 @@ static void cciss_getgeometry(int cntl_num)
                }
        }
        kfree(ld_buff);
-       kfree(size_buff);
        kfree(inq_buff);
 }