aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/cciss.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/block/cciss.c')
-rw-r--r--drivers/block/cciss.c928
1 files changed, 560 insertions, 368 deletions
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 4d4d5e0d3fa6..c7a527c08a09 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -38,7 +38,6 @@
38#include <linux/hdreg.h> 38#include <linux/hdreg.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <linux/compat.h> 40#include <linux/compat.h>
41#include <linux/blktrace_api.h>
42#include <asm/uaccess.h> 41#include <asm/uaccess.h>
43#include <asm/io.h> 42#include <asm/io.h>
44 43
@@ -180,11 +179,13 @@ static void __devinit cciss_interrupt_mode(ctlr_info_t *, struct pci_dev *,
180 __u32); 179 __u32);
181static void start_io(ctlr_info_t *h); 180static void start_io(ctlr_info_t *h);
182static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, 181static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size,
183 unsigned int use_unit_num, unsigned int log_unit,
184 __u8 page_code, unsigned char *scsi3addr, int cmd_type); 182 __u8 page_code, unsigned char *scsi3addr, int cmd_type);
185static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size, 183static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size,
186 unsigned int use_unit_num, unsigned int log_unit, 184 __u8 page_code, unsigned char scsi3addr[],
187 __u8 page_code, int cmd_type); 185 int cmd_type);
186static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
187 int attempt_retry);
188static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c);
188 189
189static void fail_all_cmds(unsigned long ctlr); 190static void fail_all_cmds(unsigned long ctlr);
190static int scan_thread(void *data); 191static int scan_thread(void *data);
@@ -437,6 +438,194 @@ static void __devinit cciss_procinit(int i)
437} 438}
438#endif /* CONFIG_PROC_FS */ 439#endif /* CONFIG_PROC_FS */
439 440
441#define MAX_PRODUCT_NAME_LEN 19
442
443#define to_hba(n) container_of(n, struct ctlr_info, dev)
444#define to_drv(n) container_of(n, drive_info_struct, dev)
445
446static struct device_type cciss_host_type = {
447 .name = "cciss_host",
448};
449
450static ssize_t dev_show_unique_id(struct device *dev,
451 struct device_attribute *attr,
452 char *buf)
453{
454 drive_info_struct *drv = to_drv(dev);
455 struct ctlr_info *h = to_hba(drv->dev.parent);
456 __u8 sn[16];
457 unsigned long flags;
458 int ret = 0;
459
460 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
461 if (h->busy_configuring)
462 ret = -EBUSY;
463 else
464 memcpy(sn, drv->serial_no, sizeof(sn));
465 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
466
467 if (ret)
468 return ret;
469 else
470 return snprintf(buf, 16 * 2 + 2,
471 "%02X%02X%02X%02X%02X%02X%02X%02X"
472 "%02X%02X%02X%02X%02X%02X%02X%02X\n",
473 sn[0], sn[1], sn[2], sn[3],
474 sn[4], sn[5], sn[6], sn[7],
475 sn[8], sn[9], sn[10], sn[11],
476 sn[12], sn[13], sn[14], sn[15]);
477}
478DEVICE_ATTR(unique_id, S_IRUGO, dev_show_unique_id, NULL);
479
480static ssize_t dev_show_vendor(struct device *dev,
481 struct device_attribute *attr,
482 char *buf)
483{
484 drive_info_struct *drv = to_drv(dev);
485 struct ctlr_info *h = to_hba(drv->dev.parent);
486 char vendor[VENDOR_LEN + 1];
487 unsigned long flags;
488 int ret = 0;
489
490 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
491 if (h->busy_configuring)
492 ret = -EBUSY;
493 else
494 memcpy(vendor, drv->vendor, VENDOR_LEN + 1);
495 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
496
497 if (ret)
498 return ret;
499 else
500 return snprintf(buf, sizeof(vendor) + 1, "%s\n", drv->vendor);
501}
502DEVICE_ATTR(vendor, S_IRUGO, dev_show_vendor, NULL);
503
504static ssize_t dev_show_model(struct device *dev,
505 struct device_attribute *attr,
506 char *buf)
507{
508 drive_info_struct *drv = to_drv(dev);
509 struct ctlr_info *h = to_hba(drv->dev.parent);
510 char model[MODEL_LEN + 1];
511 unsigned long flags;
512 int ret = 0;
513
514 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
515 if (h->busy_configuring)
516 ret = -EBUSY;
517 else
518 memcpy(model, drv->model, MODEL_LEN + 1);
519 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
520
521 if (ret)
522 return ret;
523 else
524 return snprintf(buf, sizeof(model) + 1, "%s\n", drv->model);
525}
526DEVICE_ATTR(model, S_IRUGO, dev_show_model, NULL);
527
528static ssize_t dev_show_rev(struct device *dev,
529 struct device_attribute *attr,
530 char *buf)
531{
532 drive_info_struct *drv = to_drv(dev);
533 struct ctlr_info *h = to_hba(drv->dev.parent);
534 char rev[REV_LEN + 1];
535 unsigned long flags;
536 int ret = 0;
537
538 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
539 if (h->busy_configuring)
540 ret = -EBUSY;
541 else
542 memcpy(rev, drv->rev, REV_LEN + 1);
543 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
544
545 if (ret)
546 return ret;
547 else
548 return snprintf(buf, sizeof(rev) + 1, "%s\n", drv->rev);
549}
550DEVICE_ATTR(rev, S_IRUGO, dev_show_rev, NULL);
551
552static struct attribute *cciss_dev_attrs[] = {
553 &dev_attr_unique_id.attr,
554 &dev_attr_model.attr,
555 &dev_attr_vendor.attr,
556 &dev_attr_rev.attr,
557 NULL
558};
559
560static struct attribute_group cciss_dev_attr_group = {
561 .attrs = cciss_dev_attrs,
562};
563
564static struct attribute_group *cciss_dev_attr_groups[] = {
565 &cciss_dev_attr_group,
566 NULL
567};
568
569static struct device_type cciss_dev_type = {
570 .name = "cciss_device",
571 .groups = cciss_dev_attr_groups,
572};
573
574static struct bus_type cciss_bus_type = {
575 .name = "cciss",
576};
577
578
579/*
580 * Initialize sysfs entry for each controller. This sets up and registers
581 * the 'cciss#' directory for each individual controller under
582 * /sys/bus/pci/devices/<dev>/.
583 */
584static int cciss_create_hba_sysfs_entry(struct ctlr_info *h)
585{
586 device_initialize(&h->dev);
587 h->dev.type = &cciss_host_type;
588 h->dev.bus = &cciss_bus_type;
589 dev_set_name(&h->dev, "%s", h->devname);
590 h->dev.parent = &h->pdev->dev;
591
592 return device_add(&h->dev);
593}
594
595/*
596 * Remove sysfs entries for an hba.
597 */
598static void cciss_destroy_hba_sysfs_entry(struct ctlr_info *h)
599{
600 device_del(&h->dev);
601}
602
603/*
604 * Initialize sysfs for each logical drive. This sets up and registers
605 * the 'c#d#' directory for each individual logical drive under
606 * /sys/bus/pci/devices/<dev/ccis#/. We also create a link from
607 * /sys/block/cciss!c#d# to this entry.
608 */
609static int cciss_create_ld_sysfs_entry(struct ctlr_info *h,
610 drive_info_struct *drv,
611 int drv_index)
612{
613 device_initialize(&drv->dev);
614 drv->dev.type = &cciss_dev_type;
615 drv->dev.bus = &cciss_bus_type;
616 dev_set_name(&drv->dev, "c%dd%d", h->ctlr, drv_index);
617 drv->dev.parent = &h->dev;
618 return device_add(&drv->dev);
619}
620
621/*
622 * Remove sysfs entries for a logical drive.
623 */
624static void cciss_destroy_ld_sysfs_entry(drive_info_struct *drv)
625{
626 device_del(&drv->dev);
627}
628
440/* 629/*
441 * For operations that cannot sleep, a command block is allocated at init, 630 * For operations that cannot sleep, a command block is allocated at init,
442 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track 631 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track
@@ -1299,7 +1488,6 @@ static void cciss_softirq_done(struct request *rq)
1299{ 1488{
1300 CommandList_struct *cmd = rq->completion_data; 1489 CommandList_struct *cmd = rq->completion_data;
1301 ctlr_info_t *h = hba[cmd->ctlr]; 1490 ctlr_info_t *h = hba[cmd->ctlr];
1302 unsigned int nr_bytes;
1303 unsigned long flags; 1491 unsigned long flags;
1304 u64bit temp64; 1492 u64bit temp64;
1305 int i, ddir; 1493 int i, ddir;
@@ -1321,15 +1509,11 @@ static void cciss_softirq_done(struct request *rq)
1321 printk("Done with %p\n", rq); 1509 printk("Done with %p\n", rq);
1322#endif /* CCISS_DEBUG */ 1510#endif /* CCISS_DEBUG */
1323 1511
1324 /* 1512 /* set the residual count for pc requests */
1325 * Store the full size and set the residual count for pc requests
1326 */
1327 nr_bytes = blk_rq_bytes(rq);
1328 if (blk_pc_request(rq)) 1513 if (blk_pc_request(rq))
1329 rq->data_len = cmd->err_info->ResidualCnt; 1514 rq->resid_len = cmd->err_info->ResidualCnt;
1330 1515
1331 if (blk_end_request(rq, (rq->errors == 0) ? 0 : -EIO, nr_bytes)) 1516 blk_end_request_all(rq, (rq->errors == 0) ? 0 : -EIO);
1332 BUG();
1333 1517
1334 spin_lock_irqsave(&h->lock, flags); 1518 spin_lock_irqsave(&h->lock, flags);
1335 cmd_free(h, cmd, 1); 1519 cmd_free(h, cmd, 1);
@@ -1337,6 +1521,56 @@ static void cciss_softirq_done(struct request *rq)
1337 spin_unlock_irqrestore(&h->lock, flags); 1521 spin_unlock_irqrestore(&h->lock, flags);
1338} 1522}
1339 1523
1524static void log_unit_to_scsi3addr(ctlr_info_t *h, unsigned char scsi3addr[],
1525 uint32_t log_unit)
1526{
1527 log_unit = h->drv[log_unit].LunID & 0x03fff;
1528 memset(&scsi3addr[4], 0, 4);
1529 memcpy(&scsi3addr[0], &log_unit, 4);
1530 scsi3addr[3] |= 0x40;
1531}
1532
1533/* This function gets the SCSI vendor, model, and revision of a logical drive
1534 * via the inquiry page 0. Model, vendor, and rev are set to empty strings if
1535 * they cannot be read.
1536 */
1537static void cciss_get_device_descr(int ctlr, int logvol, int withirq,
1538 char *vendor, char *model, char *rev)
1539{
1540 int rc;
1541 InquiryData_struct *inq_buf;
1542 unsigned char scsi3addr[8];
1543
1544 *vendor = '\0';
1545 *model = '\0';
1546 *rev = '\0';
1547
1548 inq_buf = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
1549 if (!inq_buf)
1550 return;
1551
1552 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
1553 if (withirq)
1554 rc = sendcmd_withirq(CISS_INQUIRY, ctlr, inq_buf,
1555 sizeof(InquiryData_struct), 0,
1556 scsi3addr, TYPE_CMD);
1557 else
1558 rc = sendcmd(CISS_INQUIRY, ctlr, inq_buf,
1559 sizeof(InquiryData_struct), 0,
1560 scsi3addr, TYPE_CMD);
1561 if (rc == IO_OK) {
1562 memcpy(vendor, &inq_buf->data_byte[8], VENDOR_LEN);
1563 vendor[VENDOR_LEN] = '\0';
1564 memcpy(model, &inq_buf->data_byte[16], MODEL_LEN);
1565 model[MODEL_LEN] = '\0';
1566 memcpy(rev, &inq_buf->data_byte[32], REV_LEN);
1567 rev[REV_LEN] = '\0';
1568 }
1569
1570 kfree(inq_buf);
1571 return;
1572}
1573
1340/* This function gets the serial number of a logical drive via 1574/* This function gets the serial number of a logical drive via
1341 * inquiry page 0x83. Serial no. is 16 bytes. If the serial 1575 * inquiry page 0x83. Serial no. is 16 bytes. If the serial
1342 * number cannot be had, for whatever reason, 16 bytes of 0xff 1576 * number cannot be had, for whatever reason, 16 bytes of 0xff
@@ -1348,6 +1582,7 @@ static void cciss_get_serial_no(int ctlr, int logvol, int withirq,
1348#define PAGE_83_INQ_BYTES 64 1582#define PAGE_83_INQ_BYTES 64
1349 int rc; 1583 int rc;
1350 unsigned char *buf; 1584 unsigned char *buf;
1585 unsigned char scsi3addr[8];
1351 1586
1352 if (buflen > 16) 1587 if (buflen > 16)
1353 buflen = 16; 1588 buflen = 16;
@@ -1356,12 +1591,13 @@ static void cciss_get_serial_no(int ctlr, int logvol, int withirq,
1356 if (!buf) 1591 if (!buf)
1357 return; 1592 return;
1358 memset(serial_no, 0, buflen); 1593 memset(serial_no, 0, buflen);
1594 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
1359 if (withirq) 1595 if (withirq)
1360 rc = sendcmd_withirq(CISS_INQUIRY, ctlr, buf, 1596 rc = sendcmd_withirq(CISS_INQUIRY, ctlr, buf,
1361 PAGE_83_INQ_BYTES, 1, logvol, 0x83, TYPE_CMD); 1597 PAGE_83_INQ_BYTES, 0x83, scsi3addr, TYPE_CMD);
1362 else 1598 else
1363 rc = sendcmd(CISS_INQUIRY, ctlr, buf, 1599 rc = sendcmd(CISS_INQUIRY, ctlr, buf,
1364 PAGE_83_INQ_BYTES, 1, logvol, 0x83, NULL, TYPE_CMD); 1600 PAGE_83_INQ_BYTES, 0x83, scsi3addr, TYPE_CMD);
1365 if (rc == IO_OK) 1601 if (rc == IO_OK)
1366 memcpy(serial_no, &buf[8], buflen); 1602 memcpy(serial_no, &buf[8], buflen);
1367 kfree(buf); 1603 kfree(buf);
@@ -1377,7 +1613,7 @@ static void cciss_add_disk(ctlr_info_t *h, struct gendisk *disk,
1377 disk->first_minor = drv_index << NWD_SHIFT; 1613 disk->first_minor = drv_index << NWD_SHIFT;
1378 disk->fops = &cciss_fops; 1614 disk->fops = &cciss_fops;
1379 disk->private_data = &h->drv[drv_index]; 1615 disk->private_data = &h->drv[drv_index];
1380 disk->driverfs_dev = &h->pdev->dev; 1616 disk->driverfs_dev = &h->drv[drv_index].dev;
1381 1617
1382 /* Set up queue information */ 1618 /* Set up queue information */
1383 blk_queue_bounce_limit(disk->queue, h->pdev->dma_mask); 1619 blk_queue_bounce_limit(disk->queue, h->pdev->dma_mask);
@@ -1394,8 +1630,8 @@ static void cciss_add_disk(ctlr_info_t *h, struct gendisk *disk,
1394 1630
1395 disk->queue->queuedata = h; 1631 disk->queue->queuedata = h;
1396 1632
1397 blk_queue_hardsect_size(disk->queue, 1633 blk_queue_logical_block_size(disk->queue,
1398 h->drv[drv_index].block_size); 1634 h->drv[drv_index].block_size);
1399 1635
1400 /* Make sure all queue data is written out before */ 1636 /* Make sure all queue data is written out before */
1401 /* setting h->drv[drv_index].queue, as setting this */ 1637 /* setting h->drv[drv_index].queue, as setting this */
@@ -1468,6 +1704,8 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time)
1468 drvinfo->block_size = block_size; 1704 drvinfo->block_size = block_size;
1469 drvinfo->nr_blocks = total_size + 1; 1705 drvinfo->nr_blocks = total_size + 1;
1470 1706
1707 cciss_get_device_descr(ctlr, drv_index, 1, drvinfo->vendor,
1708 drvinfo->model, drvinfo->rev);
1471 cciss_get_serial_no(ctlr, drv_index, 1, drvinfo->serial_no, 1709 cciss_get_serial_no(ctlr, drv_index, 1, drvinfo->serial_no,
1472 sizeof(drvinfo->serial_no)); 1710 sizeof(drvinfo->serial_no));
1473 1711
@@ -1517,6 +1755,9 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time)
1517 h->drv[drv_index].cylinders = drvinfo->cylinders; 1755 h->drv[drv_index].cylinders = drvinfo->cylinders;
1518 h->drv[drv_index].raid_level = drvinfo->raid_level; 1756 h->drv[drv_index].raid_level = drvinfo->raid_level;
1519 memcpy(h->drv[drv_index].serial_no, drvinfo->serial_no, 16); 1757 memcpy(h->drv[drv_index].serial_no, drvinfo->serial_no, 16);
1758 memcpy(h->drv[drv_index].vendor, drvinfo->vendor, VENDOR_LEN + 1);
1759 memcpy(h->drv[drv_index].model, drvinfo->model, MODEL_LEN + 1);
1760 memcpy(h->drv[drv_index].rev, drvinfo->rev, REV_LEN + 1);
1520 1761
1521 ++h->num_luns; 1762 ++h->num_luns;
1522 disk = h->gendisk[drv_index]; 1763 disk = h->gendisk[drv_index];
@@ -1591,6 +1832,8 @@ static int cciss_add_gendisk(ctlr_info_t *h, __u32 lunid, int controller_node)
1591 } 1832 }
1592 } 1833 }
1593 h->drv[drv_index].LunID = lunid; 1834 h->drv[drv_index].LunID = lunid;
1835 if (cciss_create_ld_sysfs_entry(h, &h->drv[drv_index], drv_index))
1836 goto err_free_disk;
1594 1837
1595 /* Don't need to mark this busy because nobody */ 1838 /* Don't need to mark this busy because nobody */
1596 /* else knows about this disk yet to contend */ 1839 /* else knows about this disk yet to contend */
@@ -1598,6 +1841,11 @@ static int cciss_add_gendisk(ctlr_info_t *h, __u32 lunid, int controller_node)
1598 h->drv[drv_index].busy_configuring = 0; 1841 h->drv[drv_index].busy_configuring = 0;
1599 wmb(); 1842 wmb();
1600 return drv_index; 1843 return drv_index;
1844
1845err_free_disk:
1846 put_disk(h->gendisk[drv_index]);
1847 h->gendisk[drv_index] = NULL;
1848 return -1;
1601} 1849}
1602 1850
1603/* This is for the special case of a controller which 1851/* This is for the special case of a controller which
@@ -1668,8 +1916,8 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time)
1668 goto mem_msg; 1916 goto mem_msg;
1669 1917
1670 return_code = sendcmd_withirq(CISS_REPORT_LOG, ctlr, ld_buff, 1918 return_code = sendcmd_withirq(CISS_REPORT_LOG, ctlr, ld_buff,
1671 sizeof(ReportLunData_struct), 0, 1919 sizeof(ReportLunData_struct),
1672 0, 0, TYPE_CMD); 1920 0, CTLR_LUNID, TYPE_CMD);
1673 1921
1674 if (return_code == IO_OK) 1922 if (return_code == IO_OK)
1675 listlength = be32_to_cpu(*(__be32 *) ld_buff->LUNListLength); 1923 listlength = be32_to_cpu(*(__be32 *) ld_buff->LUNListLength);
@@ -1718,6 +1966,7 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time)
1718 h->drv[i].busy_configuring = 1; 1966 h->drv[i].busy_configuring = 1;
1719 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 1967 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
1720 return_code = deregister_disk(h, i, 1); 1968 return_code = deregister_disk(h, i, 1);
1969 cciss_destroy_ld_sysfs_entry(&h->drv[i]);
1721 h->drv[i].busy_configuring = 0; 1970 h->drv[i].busy_configuring = 0;
1722 } 1971 }
1723 } 1972 }
@@ -1877,11 +2126,9 @@ static int deregister_disk(ctlr_info_t *h, int drv_index,
1877 return 0; 2126 return 0;
1878} 2127}
1879 2128
1880static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_t size, unsigned int use_unit_num, /* 0: address the controller, 2129static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff,
1881 1: address logical volume log_unit, 2130 size_t size, __u8 page_code, unsigned char *scsi3addr,
1882 2: periph device address is scsi3addr */ 2131 int cmd_type)
1883 unsigned int log_unit, __u8 page_code,
1884 unsigned char *scsi3addr, int cmd_type)
1885{ 2132{
1886 ctlr_info_t *h = hba[ctlr]; 2133 ctlr_info_t *h = hba[ctlr];
1887 u64bit buff_dma_handle; 2134 u64bit buff_dma_handle;
@@ -1897,27 +2144,12 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1897 c->Header.SGTotal = 0; 2144 c->Header.SGTotal = 0;
1898 } 2145 }
1899 c->Header.Tag.lower = c->busaddr; 2146 c->Header.Tag.lower = c->busaddr;
2147 memcpy(c->Header.LUN.LunAddrBytes, scsi3addr, 8);
1900 2148
1901 c->Request.Type.Type = cmd_type; 2149 c->Request.Type.Type = cmd_type;
1902 if (cmd_type == TYPE_CMD) { 2150 if (cmd_type == TYPE_CMD) {
1903 switch (cmd) { 2151 switch (cmd) {
1904 case CISS_INQUIRY: 2152 case CISS_INQUIRY:
1905 /* If the logical unit number is 0 then, this is going
1906 to controller so It's a physical command
1907 mode = 0 target = 0. So we have nothing to write.
1908 otherwise, if use_unit_num == 1,
1909 mode = 1(volume set addressing) target = LUNID
1910 otherwise, if use_unit_num == 2,
1911 mode = 0(periph dev addr) target = scsi3addr */
1912 if (use_unit_num == 1) {
1913 c->Header.LUN.LogDev.VolId =
1914 h->drv[log_unit].LunID;
1915 c->Header.LUN.LogDev.Mode = 1;
1916 } else if (use_unit_num == 2) {
1917 memcpy(c->Header.LUN.LunAddrBytes, scsi3addr,
1918 8);
1919 c->Header.LUN.LogDev.Mode = 0;
1920 }
1921 /* are we trying to read a vital product page */ 2153 /* are we trying to read a vital product page */
1922 if (page_code != 0) { 2154 if (page_code != 0) {
1923 c->Request.CDB[1] = 0x01; 2155 c->Request.CDB[1] = 0x01;
@@ -1947,8 +2179,6 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1947 break; 2179 break;
1948 2180
1949 case CCISS_READ_CAPACITY: 2181 case CCISS_READ_CAPACITY:
1950 c->Header.LUN.LogDev.VolId = h->drv[log_unit].LunID;
1951 c->Header.LUN.LogDev.Mode = 1;
1952 c->Request.CDBLen = 10; 2182 c->Request.CDBLen = 10;
1953 c->Request.Type.Attribute = ATTR_SIMPLE; 2183 c->Request.Type.Attribute = ATTR_SIMPLE;
1954 c->Request.Type.Direction = XFER_READ; 2184 c->Request.Type.Direction = XFER_READ;
@@ -1956,8 +2186,6 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1956 c->Request.CDB[0] = cmd; 2186 c->Request.CDB[0] = cmd;
1957 break; 2187 break;
1958 case CCISS_READ_CAPACITY_16: 2188 case CCISS_READ_CAPACITY_16:
1959 c->Header.LUN.LogDev.VolId = h->drv[log_unit].LunID;
1960 c->Header.LUN.LogDev.Mode = 1;
1961 c->Request.CDBLen = 16; 2189 c->Request.CDBLen = 16;
1962 c->Request.Type.Attribute = ATTR_SIMPLE; 2190 c->Request.Type.Attribute = ATTR_SIMPLE;
1963 c->Request.Type.Direction = XFER_READ; 2191 c->Request.Type.Direction = XFER_READ;
@@ -1979,6 +2207,12 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1979 c->Request.CDB[0] = BMIC_WRITE; 2207 c->Request.CDB[0] = BMIC_WRITE;
1980 c->Request.CDB[6] = BMIC_CACHE_FLUSH; 2208 c->Request.CDB[6] = BMIC_CACHE_FLUSH;
1981 break; 2209 break;
2210 case TEST_UNIT_READY:
2211 c->Request.CDBLen = 6;
2212 c->Request.Type.Attribute = ATTR_SIMPLE;
2213 c->Request.Type.Direction = XFER_NONE;
2214 c->Request.Timeout = 0;
2215 break;
1982 default: 2216 default:
1983 printk(KERN_WARNING 2217 printk(KERN_WARNING
1984 "cciss%d: Unknown Command 0x%c\n", ctlr, cmd); 2218 "cciss%d: Unknown Command 0x%c\n", ctlr, cmd);
@@ -1997,13 +2231,13 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1997 memcpy(&c->Request.CDB[4], buff, 8); 2231 memcpy(&c->Request.CDB[4], buff, 8);
1998 break; 2232 break;
1999 case 1: /* RESET message */ 2233 case 1: /* RESET message */
2000 c->Request.CDBLen = 12; 2234 c->Request.CDBLen = 16;
2001 c->Request.Type.Attribute = ATTR_SIMPLE; 2235 c->Request.Type.Attribute = ATTR_SIMPLE;
2002 c->Request.Type.Direction = XFER_WRITE; 2236 c->Request.Type.Direction = XFER_NONE;
2003 c->Request.Timeout = 0; 2237 c->Request.Timeout = 0;
2004 memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); 2238 memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB));
2005 c->Request.CDB[0] = cmd; /* reset */ 2239 c->Request.CDB[0] = cmd; /* reset */
2006 c->Request.CDB[1] = 0x04; /* reset a LUN */ 2240 c->Request.CDB[1] = 0x03; /* reset a target */
2007 break; 2241 break;
2008 case 3: /* No-Op message */ 2242 case 3: /* No-Op message */
2009 c->Request.CDBLen = 1; 2243 c->Request.CDBLen = 1;
@@ -2035,114 +2269,152 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
2035 return status; 2269 return status;
2036} 2270}
2037 2271
2038static int sendcmd_withirq(__u8 cmd, 2272static int check_target_status(ctlr_info_t *h, CommandList_struct *c)
2039 int ctlr,
2040 void *buff,
2041 size_t size,
2042 unsigned int use_unit_num,
2043 unsigned int log_unit, __u8 page_code, int cmd_type)
2044{ 2273{
2045 ctlr_info_t *h = hba[ctlr]; 2274 switch (c->err_info->ScsiStatus) {
2046 CommandList_struct *c; 2275 case SAM_STAT_GOOD:
2276 return IO_OK;
2277 case SAM_STAT_CHECK_CONDITION:
2278 switch (0xf & c->err_info->SenseInfo[2]) {
2279 case 0: return IO_OK; /* no sense */
2280 case 1: return IO_OK; /* recovered error */
2281 default:
2282 printk(KERN_WARNING "cciss%d: cmd 0x%02x "
2283 "check condition, sense key = 0x%02x\n",
2284 h->ctlr, c->Request.CDB[0],
2285 c->err_info->SenseInfo[2]);
2286 }
2287 break;
2288 default:
2289 printk(KERN_WARNING "cciss%d: cmd 0x%02x"
2290 "scsi status = 0x%02x\n", h->ctlr,
2291 c->Request.CDB[0], c->err_info->ScsiStatus);
2292 break;
2293 }
2294 return IO_ERROR;
2295}
2296
2297static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c)
2298{
2299 int return_status = IO_OK;
2300
2301 if (c->err_info->CommandStatus == CMD_SUCCESS)
2302 return IO_OK;
2303
2304 switch (c->err_info->CommandStatus) {
2305 case CMD_TARGET_STATUS:
2306 return_status = check_target_status(h, c);
2307 break;
2308 case CMD_DATA_UNDERRUN:
2309 case CMD_DATA_OVERRUN:
2310 /* expected for inquiry and report lun commands */
2311 break;
2312 case CMD_INVALID:
2313 printk(KERN_WARNING "cciss: cmd 0x%02x is "
2314 "reported invalid\n", c->Request.CDB[0]);
2315 return_status = IO_ERROR;
2316 break;
2317 case CMD_PROTOCOL_ERR:
2318 printk(KERN_WARNING "cciss: cmd 0x%02x has "
2319 "protocol error \n", c->Request.CDB[0]);
2320 return_status = IO_ERROR;
2321 break;
2322 case CMD_HARDWARE_ERR:
2323 printk(KERN_WARNING "cciss: cmd 0x%02x had "
2324 " hardware error\n", c->Request.CDB[0]);
2325 return_status = IO_ERROR;
2326 break;
2327 case CMD_CONNECTION_LOST:
2328 printk(KERN_WARNING "cciss: cmd 0x%02x had "
2329 "connection lost\n", c->Request.CDB[0]);
2330 return_status = IO_ERROR;
2331 break;
2332 case CMD_ABORTED:
2333 printk(KERN_WARNING "cciss: cmd 0x%02x was "
2334 "aborted\n", c->Request.CDB[0]);
2335 return_status = IO_ERROR;
2336 break;
2337 case CMD_ABORT_FAILED:
2338 printk(KERN_WARNING "cciss: cmd 0x%02x reports "
2339 "abort failed\n", c->Request.CDB[0]);
2340 return_status = IO_ERROR;
2341 break;
2342 case CMD_UNSOLICITED_ABORT:
2343 printk(KERN_WARNING
2344 "cciss%d: unsolicited abort 0x%02x\n", h->ctlr,
2345 c->Request.CDB[0]);
2346 return_status = IO_NEEDS_RETRY;
2347 break;
2348 default:
2349 printk(KERN_WARNING "cciss: cmd 0x%02x returned "
2350 "unknown status %x\n", c->Request.CDB[0],
2351 c->err_info->CommandStatus);
2352 return_status = IO_ERROR;
2353 }
2354 return return_status;
2355}
2356
2357static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
2358 int attempt_retry)
2359{
2360 DECLARE_COMPLETION_ONSTACK(wait);
2047 u64bit buff_dma_handle; 2361 u64bit buff_dma_handle;
2048 unsigned long flags; 2362 unsigned long flags;
2049 int return_status; 2363 int return_status = IO_OK;
2050 DECLARE_COMPLETION_ONSTACK(wait);
2051 2364
2052 if ((c = cmd_alloc(h, 0)) == NULL) 2365resend_cmd2:
2053 return -ENOMEM;
2054 return_status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num,
2055 log_unit, page_code, NULL, cmd_type);
2056 if (return_status != IO_OK) {
2057 cmd_free(h, c, 0);
2058 return return_status;
2059 }
2060 resend_cmd2:
2061 c->waiting = &wait; 2366 c->waiting = &wait;
2062
2063 /* Put the request on the tail of the queue and send it */ 2367 /* Put the request on the tail of the queue and send it */
2064 spin_lock_irqsave(CCISS_LOCK(ctlr), flags); 2368 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
2065 addQ(&h->reqQ, c); 2369 addQ(&h->reqQ, c);
2066 h->Qdepth++; 2370 h->Qdepth++;
2067 start_io(h); 2371 start_io(h);
2068 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 2372 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
2069 2373
2070 wait_for_completion(&wait); 2374 wait_for_completion(&wait);
2071 2375
2072 if (c->err_info->CommandStatus != 0) { /* an error has occurred */ 2376 if (c->err_info->CommandStatus == 0 || !attempt_retry)
2073 switch (c->err_info->CommandStatus) { 2377 goto command_done;
2074 case CMD_TARGET_STATUS:
2075 printk(KERN_WARNING "cciss: cmd %p has "
2076 " completed with errors\n", c);
2077 if (c->err_info->ScsiStatus) {
2078 printk(KERN_WARNING "cciss: cmd %p "
2079 "has SCSI Status = %x\n",
2080 c, c->err_info->ScsiStatus);
2081 }
2082 2378
2083 break; 2379 return_status = process_sendcmd_error(h, c);
2084 case CMD_DATA_UNDERRUN: 2380
2085 case CMD_DATA_OVERRUN: 2381 if (return_status == IO_NEEDS_RETRY &&
2086 /* expected for inquire and report lun commands */ 2382 c->retry_count < MAX_CMD_RETRIES) {
2087 break; 2383 printk(KERN_WARNING "cciss%d: retrying 0x%02x\n", h->ctlr,
2088 case CMD_INVALID: 2384 c->Request.CDB[0]);
2089 printk(KERN_WARNING "cciss: Cmd %p is " 2385 c->retry_count++;
2090 "reported invalid\n", c); 2386 /* erase the old error information */
2091 return_status = IO_ERROR; 2387 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
2092 break; 2388 return_status = IO_OK;
2093 case CMD_PROTOCOL_ERR: 2389 INIT_COMPLETION(wait);
2094 printk(KERN_WARNING "cciss: cmd %p has " 2390 goto resend_cmd2;
2095 "protocol error \n", c);
2096 return_status = IO_ERROR;
2097 break;
2098 case CMD_HARDWARE_ERR:
2099 printk(KERN_WARNING "cciss: cmd %p had "
2100 " hardware error\n", c);
2101 return_status = IO_ERROR;
2102 break;
2103 case CMD_CONNECTION_LOST:
2104 printk(KERN_WARNING "cciss: cmd %p had "
2105 "connection lost\n", c);
2106 return_status = IO_ERROR;
2107 break;
2108 case CMD_ABORTED:
2109 printk(KERN_WARNING "cciss: cmd %p was "
2110 "aborted\n", c);
2111 return_status = IO_ERROR;
2112 break;
2113 case CMD_ABORT_FAILED:
2114 printk(KERN_WARNING "cciss: cmd %p reports "
2115 "abort failed\n", c);
2116 return_status = IO_ERROR;
2117 break;
2118 case CMD_UNSOLICITED_ABORT:
2119 printk(KERN_WARNING
2120 "cciss%d: unsolicited abort %p\n", ctlr, c);
2121 if (c->retry_count < MAX_CMD_RETRIES) {
2122 printk(KERN_WARNING
2123 "cciss%d: retrying %p\n", ctlr, c);
2124 c->retry_count++;
2125 /* erase the old error information */
2126 memset(c->err_info, 0,
2127 sizeof(ErrorInfo_struct));
2128 return_status = IO_OK;
2129 INIT_COMPLETION(wait);
2130 goto resend_cmd2;
2131 }
2132 return_status = IO_ERROR;
2133 break;
2134 default:
2135 printk(KERN_WARNING "cciss: cmd %p returned "
2136 "unknown status %x\n", c,
2137 c->err_info->CommandStatus);
2138 return_status = IO_ERROR;
2139 }
2140 } 2391 }
2392
2393command_done:
2141 /* unlock the buffers from DMA */ 2394 /* unlock the buffers from DMA */
2142 buff_dma_handle.val32.lower = c->SG[0].Addr.lower; 2395 buff_dma_handle.val32.lower = c->SG[0].Addr.lower;
2143 buff_dma_handle.val32.upper = c->SG[0].Addr.upper; 2396 buff_dma_handle.val32.upper = c->SG[0].Addr.upper;
2144 pci_unmap_single(h->pdev, (dma_addr_t) buff_dma_handle.val, 2397 pci_unmap_single(h->pdev, (dma_addr_t) buff_dma_handle.val,
2145 c->SG[0].Len, PCI_DMA_BIDIRECTIONAL); 2398 c->SG[0].Len, PCI_DMA_BIDIRECTIONAL);
2399 return return_status;
2400}
2401
2402static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size,
2403 __u8 page_code, unsigned char scsi3addr[],
2404 int cmd_type)
2405{
2406 ctlr_info_t *h = hba[ctlr];
2407 CommandList_struct *c;
2408 int return_status;
2409
2410 c = cmd_alloc(h, 0);
2411 if (!c)
2412 return -ENOMEM;
2413 return_status = fill_cmd(c, cmd, ctlr, buff, size, page_code,
2414 scsi3addr, cmd_type);
2415 if (return_status == IO_OK)
2416 return_status = sendcmd_withirq_core(h, c, 1);
2417
2146 cmd_free(h, c, 0); 2418 cmd_free(h, c, 0);
2147 return return_status; 2419 return return_status;
2148} 2420}
@@ -2155,15 +2427,17 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
2155{ 2427{
2156 int return_code; 2428 int return_code;
2157 unsigned long t; 2429 unsigned long t;
2430 unsigned char scsi3addr[8];
2158 2431
2159 memset(inq_buff, 0, sizeof(InquiryData_struct)); 2432 memset(inq_buff, 0, sizeof(InquiryData_struct));
2433 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
2160 if (withirq) 2434 if (withirq)
2161 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr, 2435 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr,
2162 inq_buff, sizeof(*inq_buff), 1, 2436 inq_buff, sizeof(*inq_buff),
2163 logvol, 0xC1, TYPE_CMD); 2437 0xC1, scsi3addr, TYPE_CMD);
2164 else 2438 else
2165 return_code = sendcmd(CISS_INQUIRY, ctlr, inq_buff, 2439 return_code = sendcmd(CISS_INQUIRY, ctlr, inq_buff,
2166 sizeof(*inq_buff), 1, logvol, 0xC1, NULL, 2440 sizeof(*inq_buff), 0xC1, scsi3addr,
2167 TYPE_CMD); 2441 TYPE_CMD);
2168 if (return_code == IO_OK) { 2442 if (return_code == IO_OK) {
2169 if (inq_buff->data_byte[8] == 0xFF) { 2443 if (inq_buff->data_byte[8] == 0xFF) {
@@ -2204,6 +2478,7 @@ cciss_read_capacity(int ctlr, int logvol, int withirq, sector_t *total_size,
2204{ 2478{
2205 ReadCapdata_struct *buf; 2479 ReadCapdata_struct *buf;
2206 int return_code; 2480 int return_code;
2481 unsigned char scsi3addr[8];
2207 2482
2208 buf = kzalloc(sizeof(ReadCapdata_struct), GFP_KERNEL); 2483 buf = kzalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
2209 if (!buf) { 2484 if (!buf) {
@@ -2211,14 +2486,15 @@ cciss_read_capacity(int ctlr, int logvol, int withirq, sector_t *total_size,
2211 return; 2486 return;
2212 } 2487 }
2213 2488
2489 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
2214 if (withirq) 2490 if (withirq)
2215 return_code = sendcmd_withirq(CCISS_READ_CAPACITY, 2491 return_code = sendcmd_withirq(CCISS_READ_CAPACITY,
2216 ctlr, buf, sizeof(ReadCapdata_struct), 2492 ctlr, buf, sizeof(ReadCapdata_struct),
2217 1, logvol, 0, TYPE_CMD); 2493 0, scsi3addr, TYPE_CMD);
2218 else 2494 else
2219 return_code = sendcmd(CCISS_READ_CAPACITY, 2495 return_code = sendcmd(CCISS_READ_CAPACITY,
2220 ctlr, buf, sizeof(ReadCapdata_struct), 2496 ctlr, buf, sizeof(ReadCapdata_struct),
2221 1, logvol, 0, NULL, TYPE_CMD); 2497 0, scsi3addr, TYPE_CMD);
2222 if (return_code == IO_OK) { 2498 if (return_code == IO_OK) {
2223 *total_size = be32_to_cpu(*(__be32 *) buf->total_size); 2499 *total_size = be32_to_cpu(*(__be32 *) buf->total_size);
2224 *block_size = be32_to_cpu(*(__be32 *) buf->block_size); 2500 *block_size = be32_to_cpu(*(__be32 *) buf->block_size);
@@ -2238,6 +2514,7 @@ cciss_read_capacity_16(int ctlr, int logvol, int withirq, sector_t *total_size,
2238{ 2514{
2239 ReadCapdata_struct_16 *buf; 2515 ReadCapdata_struct_16 *buf;
2240 int return_code; 2516 int return_code;
2517 unsigned char scsi3addr[8];
2241 2518
2242 buf = kzalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL); 2519 buf = kzalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL);
2243 if (!buf) { 2520 if (!buf) {
@@ -2245,15 +2522,16 @@ cciss_read_capacity_16(int ctlr, int logvol, int withirq, sector_t *total_size,
2245 return; 2522 return;
2246 } 2523 }
2247 2524
2525 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
2248 if (withirq) { 2526 if (withirq) {
2249 return_code = sendcmd_withirq(CCISS_READ_CAPACITY_16, 2527 return_code = sendcmd_withirq(CCISS_READ_CAPACITY_16,
2250 ctlr, buf, sizeof(ReadCapdata_struct_16), 2528 ctlr, buf, sizeof(ReadCapdata_struct_16),
2251 1, logvol, 0, TYPE_CMD); 2529 0, scsi3addr, TYPE_CMD);
2252 } 2530 }
2253 else { 2531 else {
2254 return_code = sendcmd(CCISS_READ_CAPACITY_16, 2532 return_code = sendcmd(CCISS_READ_CAPACITY_16,
2255 ctlr, buf, sizeof(ReadCapdata_struct_16), 2533 ctlr, buf, sizeof(ReadCapdata_struct_16),
2256 1, logvol, 0, NULL, TYPE_CMD); 2534 0, scsi3addr, TYPE_CMD);
2257 } 2535 }
2258 if (return_code == IO_OK) { 2536 if (return_code == IO_OK) {
2259 *total_size = be64_to_cpu(*(__be64 *) buf->total_size); 2537 *total_size = be64_to_cpu(*(__be64 *) buf->total_size);
@@ -2303,7 +2581,7 @@ static int cciss_revalidate(struct gendisk *disk)
2303 cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size, 2581 cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size,
2304 inq_buff, drv); 2582 inq_buff, drv);
2305 2583
2306 blk_queue_hardsect_size(drv->queue, drv->block_size); 2584 blk_queue_logical_block_size(drv->queue, drv->block_size);
2307 set_capacity(disk, drv->nr_blocks); 2585 set_capacity(disk, drv->nr_blocks);
2308 2586
2309 kfree(inq_buff); 2587 kfree(inq_buff);
@@ -2333,86 +2611,21 @@ static unsigned long pollcomplete(int ctlr)
2333 return 1; 2611 return 1;
2334} 2612}
2335 2613
2336static int add_sendcmd_reject(__u8 cmd, int ctlr, unsigned long complete) 2614/* Send command c to controller h and poll for it to complete.
2337{ 2615 * Turns interrupts off on the board. Used at driver init time
2338 /* We get in here if sendcmd() is polling for completions 2616 * and during SCSI error recovery.
2339 and gets some command back that it wasn't expecting --
2340 something other than that which it just sent down.
2341 Ordinarily, that shouldn't happen, but it can happen when
2342 the scsi tape stuff gets into error handling mode, and
2343 starts using sendcmd() to try to abort commands and
2344 reset tape drives. In that case, sendcmd may pick up
2345 completions of commands that were sent to logical drives
2346 through the block i/o system, or cciss ioctls completing, etc.
2347 In that case, we need to save those completions for later
2348 processing by the interrupt handler.
2349 */
2350
2351#ifdef CONFIG_CISS_SCSI_TAPE
2352 struct sendcmd_reject_list *srl = &hba[ctlr]->scsi_rejects;
2353
2354 /* If it's not the scsi tape stuff doing error handling, (abort */
2355 /* or reset) then we don't expect anything weird. */
2356 if (cmd != CCISS_RESET_MSG && cmd != CCISS_ABORT_MSG) {
2357#endif
2358 printk(KERN_WARNING "cciss cciss%d: SendCmd "
2359 "Invalid command list address returned! (%lx)\n",
2360 ctlr, complete);
2361 /* not much we can do. */
2362#ifdef CONFIG_CISS_SCSI_TAPE
2363 return 1;
2364 }
2365
2366 /* We've sent down an abort or reset, but something else
2367 has completed */
2368 if (srl->ncompletions >= (hba[ctlr]->nr_cmds + 2)) {
2369 /* Uh oh. No room to save it for later... */
2370 printk(KERN_WARNING "cciss%d: Sendcmd: Invalid command addr, "
2371 "reject list overflow, command lost!\n", ctlr);
2372 return 1;
2373 }
2374 /* Save it for later */
2375 srl->complete[srl->ncompletions] = complete;
2376 srl->ncompletions++;
2377#endif
2378 return 0;
2379}
2380
2381/*
2382 * Send a command to the controller, and wait for it to complete.
2383 * Only used at init time.
2384 */ 2617 */
2385static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, unsigned int use_unit_num, /* 0: address the controller, 2618static int sendcmd_core(ctlr_info_t *h, CommandList_struct *c)
2386 1: address logical volume log_unit,
2387 2: periph device address is scsi3addr */
2388 unsigned int log_unit,
2389 __u8 page_code, unsigned char *scsi3addr, int cmd_type)
2390{ 2619{
2391 CommandList_struct *c;
2392 int i; 2620 int i;
2393 unsigned long complete; 2621 unsigned long complete;
2394 ctlr_info_t *info_p = hba[ctlr]; 2622 int status = IO_ERROR;
2395 u64bit buff_dma_handle; 2623 u64bit buff_dma_handle;
2396 int status, done = 0;
2397 2624
2398 if ((c = cmd_alloc(info_p, 1)) == NULL) { 2625resend_cmd1:
2399 printk(KERN_WARNING "cciss: unable to get memory"); 2626
2400 return IO_ERROR; 2627 /* Disable interrupt on the board. */
2401 } 2628 h->access.set_intr_mask(h, CCISS_INTR_OFF);
2402 status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num,
2403 log_unit, page_code, scsi3addr, cmd_type);
2404 if (status != IO_OK) {
2405 cmd_free(info_p, c, 1);
2406 return status;
2407 }
2408 resend_cmd1:
2409 /*
2410 * Disable interrupt
2411 */
2412#ifdef CCISS_DEBUG
2413 printk(KERN_DEBUG "cciss: turning intr off\n");
2414#endif /* CCISS_DEBUG */
2415 info_p->access.set_intr_mask(info_p, CCISS_INTR_OFF);
2416 2629
2417 /* Make sure there is room in the command FIFO */ 2630 /* Make sure there is room in the command FIFO */
2418 /* Actually it should be completely empty at this time */ 2631 /* Actually it should be completely empty at this time */
@@ -2420,21 +2633,15 @@ static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, unsigned int use
2420 /* tape side of the driver. */ 2633 /* tape side of the driver. */
2421 for (i = 200000; i > 0; i--) { 2634 for (i = 200000; i > 0; i--) {
2422 /* if fifo isn't full go */ 2635 /* if fifo isn't full go */
2423 if (!(info_p->access.fifo_full(info_p))) { 2636 if (!(h->access.fifo_full(h)))
2424
2425 break; 2637 break;
2426 }
2427 udelay(10); 2638 udelay(10);
2428 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full," 2639 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
2429 " waiting!\n", ctlr); 2640 " waiting!\n", h->ctlr);
2430 } 2641 }
2431 /* 2642 h->access.submit_command(h, c); /* Send the cmd */
2432 * Send the cmd
2433 */
2434 info_p->access.submit_command(info_p, c);
2435 done = 0;
2436 do { 2643 do {
2437 complete = pollcomplete(ctlr); 2644 complete = pollcomplete(h->ctlr);
2438 2645
2439#ifdef CCISS_DEBUG 2646#ifdef CCISS_DEBUG
2440 printk(KERN_DEBUG "cciss: command completed\n"); 2647 printk(KERN_DEBUG "cciss: command completed\n");
@@ -2443,97 +2650,102 @@ static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, unsigned int use
2443 if (complete == 1) { 2650 if (complete == 1) {
2444 printk(KERN_WARNING 2651 printk(KERN_WARNING
2445 "cciss cciss%d: SendCmd Timeout out, " 2652 "cciss cciss%d: SendCmd Timeout out, "
2446 "No command list address returned!\n", ctlr); 2653 "No command list address returned!\n", h->ctlr);
2447 status = IO_ERROR; 2654 status = IO_ERROR;
2448 done = 1;
2449 break; 2655 break;
2450 } 2656 }
2451 2657
2452 /* This will need to change for direct lookup completions */ 2658 /* Make sure it's the command we're expecting. */
2453 if ((complete & CISS_ERROR_BIT) 2659 if ((complete & ~CISS_ERROR_BIT) != c->busaddr) {
2454 && (complete & ~CISS_ERROR_BIT) == c->busaddr) { 2660 printk(KERN_WARNING "cciss%d: Unexpected command "
2455 /* if data overrun or underun on Report command 2661 "completion.\n", h->ctlr);
2456 ignore it 2662 continue;
2457 */ 2663 }
2458 if (((c->Request.CDB[0] == CISS_REPORT_LOG) || 2664
2459 (c->Request.CDB[0] == CISS_REPORT_PHYS) || 2665 /* It is our command. If no error, we're done. */
2460 (c->Request.CDB[0] == CISS_INQUIRY)) && 2666 if (!(complete & CISS_ERROR_BIT)) {
2461 ((c->err_info->CommandStatus == 2667 status = IO_OK;
2462 CMD_DATA_OVERRUN) || 2668 break;
2463 (c->err_info->CommandStatus == CMD_DATA_UNDERRUN)
2464 )) {
2465 complete = c->busaddr;
2466 } else {
2467 if (c->err_info->CommandStatus ==
2468 CMD_UNSOLICITED_ABORT) {
2469 printk(KERN_WARNING "cciss%d: "
2470 "unsolicited abort %p\n",
2471 ctlr, c);
2472 if (c->retry_count < MAX_CMD_RETRIES) {
2473 printk(KERN_WARNING
2474 "cciss%d: retrying %p\n",
2475 ctlr, c);
2476 c->retry_count++;
2477 /* erase the old error */
2478 /* information */
2479 memset(c->err_info, 0,
2480 sizeof
2481 (ErrorInfo_struct));
2482 goto resend_cmd1;
2483 } else {
2484 printk(KERN_WARNING
2485 "cciss%d: retried %p too "
2486 "many times\n", ctlr, c);
2487 status = IO_ERROR;
2488 goto cleanup1;
2489 }
2490 } else if (c->err_info->CommandStatus ==
2491 CMD_UNABORTABLE) {
2492 printk(KERN_WARNING
2493 "cciss%d: command could not be aborted.\n",
2494 ctlr);
2495 status = IO_ERROR;
2496 goto cleanup1;
2497 }
2498 printk(KERN_WARNING "ciss ciss%d: sendcmd"
2499 " Error %x \n", ctlr,
2500 c->err_info->CommandStatus);
2501 printk(KERN_WARNING "ciss ciss%d: sendcmd"
2502 " offensive info\n"
2503 " size %x\n num %x value %x\n",
2504 ctlr,
2505 c->err_info->MoreErrInfo.Invalid_Cmd.
2506 offense_size,
2507 c->err_info->MoreErrInfo.Invalid_Cmd.
2508 offense_num,
2509 c->err_info->MoreErrInfo.Invalid_Cmd.
2510 offense_value);
2511 status = IO_ERROR;
2512 goto cleanup1;
2513 }
2514 } 2669 }
2515 /* This will need changing for direct lookup completions */ 2670
2516 if (complete != c->busaddr) { 2671 /* There is an error... */
2517 if (add_sendcmd_reject(cmd, ctlr, complete) != 0) { 2672
2518 BUG(); /* we are pretty much hosed if we get here. */ 2673 /* if data overrun or underun on Report command ignore it */
2674 if (((c->Request.CDB[0] == CISS_REPORT_LOG) ||
2675 (c->Request.CDB[0] == CISS_REPORT_PHYS) ||
2676 (c->Request.CDB[0] == CISS_INQUIRY)) &&
2677 ((c->err_info->CommandStatus == CMD_DATA_OVERRUN) ||
2678 (c->err_info->CommandStatus == CMD_DATA_UNDERRUN))) {
2679 complete = c->busaddr;
2680 status = IO_OK;
2681 break;
2682 }
2683
2684 if (c->err_info->CommandStatus == CMD_UNSOLICITED_ABORT) {
2685 printk(KERN_WARNING "cciss%d: unsolicited abort %p\n",
2686 h->ctlr, c);
2687 if (c->retry_count < MAX_CMD_RETRIES) {
2688 printk(KERN_WARNING "cciss%d: retrying %p\n",
2689 h->ctlr, c);
2690 c->retry_count++;
2691 /* erase the old error information */
2692 memset(c->err_info, 0, sizeof(c->err_info));
2693 goto resend_cmd1;
2519 } 2694 }
2520 continue; 2695 printk(KERN_WARNING "cciss%d: retried %p too many "
2521 } else 2696 "times\n", h->ctlr, c);
2522 done = 1; 2697 status = IO_ERROR;
2523 } while (!done); 2698 break;
2699 }
2700
2701 if (c->err_info->CommandStatus == CMD_UNABORTABLE) {
2702 printk(KERN_WARNING "cciss%d: command could not be "
2703 "aborted.\n", h->ctlr);
2704 status = IO_ERROR;
2705 break;
2706 }
2707
2708 if (c->err_info->CommandStatus == CMD_TARGET_STATUS) {
2709 status = check_target_status(h, c);
2710 break;
2711 }
2712
2713 printk(KERN_WARNING "cciss%d: sendcmd error\n", h->ctlr);
2714 printk(KERN_WARNING "cmd = 0x%02x, CommandStatus = 0x%02x\n",
2715 c->Request.CDB[0], c->err_info->CommandStatus);
2716 status = IO_ERROR;
2717 break;
2718
2719 } while (1);
2524 2720
2525 cleanup1:
2526 /* unlock the data buffer from DMA */ 2721 /* unlock the data buffer from DMA */
2527 buff_dma_handle.val32.lower = c->SG[0].Addr.lower; 2722 buff_dma_handle.val32.lower = c->SG[0].Addr.lower;
2528 buff_dma_handle.val32.upper = c->SG[0].Addr.upper; 2723 buff_dma_handle.val32.upper = c->SG[0].Addr.upper;
2529 pci_unmap_single(info_p->pdev, (dma_addr_t) buff_dma_handle.val, 2724 pci_unmap_single(h->pdev, (dma_addr_t) buff_dma_handle.val,
2530 c->SG[0].Len, PCI_DMA_BIDIRECTIONAL); 2725 c->SG[0].Len, PCI_DMA_BIDIRECTIONAL);
2531#ifdef CONFIG_CISS_SCSI_TAPE 2726 return status;
2532 /* if we saved some commands for later, process them now. */ 2727}
2533 if (info_p->scsi_rejects.ncompletions > 0) 2728
2534 do_cciss_intr(0, info_p); 2729/*
2535#endif 2730 * Send a command to the controller, and wait for it to complete.
2536 cmd_free(info_p, c, 1); 2731 * Used at init time, and during SCSI error recovery.
2732 */
2733static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size,
2734 __u8 page_code, unsigned char *scsi3addr, int cmd_type)
2735{
2736 CommandList_struct *c;
2737 int status;
2738
2739 c = cmd_alloc(hba[ctlr], 1);
2740 if (!c) {
2741 printk(KERN_WARNING "cciss: unable to get memory");
2742 return IO_ERROR;
2743 }
2744 status = fill_cmd(c, cmd, ctlr, buff, size, page_code,
2745 scsi3addr, cmd_type);
2746 if (status == IO_OK)
2747 status = sendcmd_core(hba[ctlr], c);
2748 cmd_free(hba[ctlr], c, 1);
2537 return status; 2749 return status;
2538} 2750}
2539 2751
@@ -2691,7 +2903,7 @@ static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd,
2691 printk(KERN_WARNING "cciss: cmd %p has" 2903 printk(KERN_WARNING "cciss: cmd %p has"
2692 " completed with data underrun " 2904 " completed with data underrun "
2693 "reported\n", cmd); 2905 "reported\n", cmd);
2694 cmd->rq->data_len = cmd->err_info->ResidualCnt; 2906 cmd->rq->resid_len = cmd->err_info->ResidualCnt;
2695 } 2907 }
2696 break; 2908 break;
2697 case CMD_DATA_OVERRUN: 2909 case CMD_DATA_OVERRUN:
@@ -2806,7 +3018,7 @@ static void do_cciss_request(struct request_queue *q)
2806 goto startio; 3018 goto startio;
2807 3019
2808 queue: 3020 queue:
2809 creq = elv_next_request(q); 3021 creq = blk_peek_request(q);
2810 if (!creq) 3022 if (!creq)
2811 goto startio; 3023 goto startio;
2812 3024
@@ -2815,7 +3027,7 @@ static void do_cciss_request(struct request_queue *q)
2815 if ((c = cmd_alloc(h, 1)) == NULL) 3027 if ((c = cmd_alloc(h, 1)) == NULL)
2816 goto full; 3028 goto full;
2817 3029
2818 blkdev_dequeue_request(creq); 3030 blk_start_request(creq);
2819 3031
2820 spin_unlock_irq(q->queue_lock); 3032 spin_unlock_irq(q->queue_lock);
2821 3033
@@ -2840,10 +3052,10 @@ static void do_cciss_request(struct request_queue *q)
2840 c->Request.Timeout = 0; // Don't time out 3052 c->Request.Timeout = 0; // Don't time out
2841 c->Request.CDB[0] = 3053 c->Request.CDB[0] =
2842 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write; 3054 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write;
2843 start_blk = creq->sector; 3055 start_blk = blk_rq_pos(creq);
2844#ifdef CCISS_DEBUG 3056#ifdef CCISS_DEBUG
2845 printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n", (int)creq->sector, 3057 printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n",
2846 (int)creq->nr_sectors); 3058 (int)blk_rq_pos(creq), (int)blk_rq_sectors(creq));
2847#endif /* CCISS_DEBUG */ 3059#endif /* CCISS_DEBUG */
2848 3060
2849 sg_init_table(tmp_sg, MAXSGENTRIES); 3061 sg_init_table(tmp_sg, MAXSGENTRIES);
@@ -2869,8 +3081,8 @@ static void do_cciss_request(struct request_queue *q)
2869 h->maxSG = seg; 3081 h->maxSG = seg;
2870 3082
2871#ifdef CCISS_DEBUG 3083#ifdef CCISS_DEBUG
2872 printk(KERN_DEBUG "cciss: Submitting %lu sectors in %d segments\n", 3084 printk(KERN_DEBUG "cciss: Submitting %u sectors in %d segments\n",
2873 creq->nr_sectors, seg); 3085 blk_rq_sectors(creq), seg);
2874#endif /* CCISS_DEBUG */ 3086#endif /* CCISS_DEBUG */
2875 3087
2876 c->Header.SGList = c->Header.SGTotal = seg; 3088 c->Header.SGList = c->Header.SGTotal = seg;
@@ -2882,8 +3094,8 @@ static void do_cciss_request(struct request_queue *q)
2882 c->Request.CDB[4] = (start_blk >> 8) & 0xff; 3094 c->Request.CDB[4] = (start_blk >> 8) & 0xff;
2883 c->Request.CDB[5] = start_blk & 0xff; 3095 c->Request.CDB[5] = start_blk & 0xff;
2884 c->Request.CDB[6] = 0; // (sect >> 24) & 0xff; MSB 3096 c->Request.CDB[6] = 0; // (sect >> 24) & 0xff; MSB
2885 c->Request.CDB[7] = (creq->nr_sectors >> 8) & 0xff; 3097 c->Request.CDB[7] = (blk_rq_sectors(creq) >> 8) & 0xff;
2886 c->Request.CDB[8] = creq->nr_sectors & 0xff; 3098 c->Request.CDB[8] = blk_rq_sectors(creq) & 0xff;
2887 c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0; 3099 c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
2888 } else { 3100 } else {
2889 u32 upper32 = upper_32_bits(start_blk); 3101 u32 upper32 = upper_32_bits(start_blk);
@@ -2898,10 +3110,10 @@ static void do_cciss_request(struct request_queue *q)
2898 c->Request.CDB[7]= (start_blk >> 16) & 0xff; 3110 c->Request.CDB[7]= (start_blk >> 16) & 0xff;
2899 c->Request.CDB[8]= (start_blk >> 8) & 0xff; 3111 c->Request.CDB[8]= (start_blk >> 8) & 0xff;
2900 c->Request.CDB[9]= start_blk & 0xff; 3112 c->Request.CDB[9]= start_blk & 0xff;
2901 c->Request.CDB[10]= (creq->nr_sectors >> 24) & 0xff; 3113 c->Request.CDB[10]= (blk_rq_sectors(creq) >> 24) & 0xff;
2902 c->Request.CDB[11]= (creq->nr_sectors >> 16) & 0xff; 3114 c->Request.CDB[11]= (blk_rq_sectors(creq) >> 16) & 0xff;
2903 c->Request.CDB[12]= (creq->nr_sectors >> 8) & 0xff; 3115 c->Request.CDB[12]= (blk_rq_sectors(creq) >> 8) & 0xff;
2904 c->Request.CDB[13]= creq->nr_sectors & 0xff; 3116 c->Request.CDB[13]= blk_rq_sectors(creq) & 0xff;
2905 c->Request.CDB[14] = c->Request.CDB[15] = 0; 3117 c->Request.CDB[14] = c->Request.CDB[15] = 0;
2906 } 3118 }
2907 } else if (blk_pc_request(creq)) { 3119 } else if (blk_pc_request(creq)) {
@@ -2931,44 +3143,18 @@ startio:
2931 3143
2932static inline unsigned long get_next_completion(ctlr_info_t *h) 3144static inline unsigned long get_next_completion(ctlr_info_t *h)
2933{ 3145{
2934#ifdef CONFIG_CISS_SCSI_TAPE
2935 /* Any rejects from sendcmd() lying around? Process them first */
2936 if (h->scsi_rejects.ncompletions == 0)
2937 return h->access.command_completed(h);
2938 else {
2939 struct sendcmd_reject_list *srl;
2940 int n;
2941 srl = &h->scsi_rejects;
2942 n = --srl->ncompletions;
2943 /* printk("cciss%d: processing saved reject\n", h->ctlr); */
2944 printk("p");
2945 return srl->complete[n];
2946 }
2947#else
2948 return h->access.command_completed(h); 3146 return h->access.command_completed(h);
2949#endif
2950} 3147}
2951 3148
2952static inline int interrupt_pending(ctlr_info_t *h) 3149static inline int interrupt_pending(ctlr_info_t *h)
2953{ 3150{
2954#ifdef CONFIG_CISS_SCSI_TAPE
2955 return (h->access.intr_pending(h)
2956 || (h->scsi_rejects.ncompletions > 0));
2957#else
2958 return h->access.intr_pending(h); 3151 return h->access.intr_pending(h);
2959#endif
2960} 3152}
2961 3153
2962static inline long interrupt_not_for_us(ctlr_info_t *h) 3154static inline long interrupt_not_for_us(ctlr_info_t *h)
2963{ 3155{
2964#ifdef CONFIG_CISS_SCSI_TAPE
2965 return (((h->access.intr_pending(h) == 0) ||
2966 (h->interrupts_enabled == 0))
2967 && (h->scsi_rejects.ncompletions == 0));
2968#else
2969 return (((h->access.intr_pending(h) == 0) || 3156 return (((h->access.intr_pending(h) == 0) ||
2970 (h->interrupts_enabled == 0))); 3157 (h->interrupts_enabled == 0)));
2971#endif
2972} 3158}
2973 3159
2974static irqreturn_t do_cciss_intr(int irq, void *dev_id) 3160static irqreturn_t do_cciss_intr(int irq, void *dev_id)
@@ -3723,12 +3909,15 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3723 INIT_HLIST_HEAD(&hba[i]->reqQ); 3909 INIT_HLIST_HEAD(&hba[i]->reqQ);
3724 3910
3725 if (cciss_pci_init(hba[i], pdev) != 0) 3911 if (cciss_pci_init(hba[i], pdev) != 0)
3726 goto clean1; 3912 goto clean0;
3727 3913
3728 sprintf(hba[i]->devname, "cciss%d", i); 3914 sprintf(hba[i]->devname, "cciss%d", i);
3729 hba[i]->ctlr = i; 3915 hba[i]->ctlr = i;
3730 hba[i]->pdev = pdev; 3916 hba[i]->pdev = pdev;
3731 3917
3918 if (cciss_create_hba_sysfs_entry(hba[i]))
3919 goto clean0;
3920
3732 /* configure PCI DMA stuff */ 3921 /* configure PCI DMA stuff */
3733 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) 3922 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)))
3734 dac = 1; 3923 dac = 1;
@@ -3787,15 +3976,6 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3787 printk(KERN_ERR "cciss: out of memory"); 3976 printk(KERN_ERR "cciss: out of memory");
3788 goto clean4; 3977 goto clean4;
3789 } 3978 }
3790#ifdef CONFIG_CISS_SCSI_TAPE
3791 hba[i]->scsi_rejects.complete =
3792 kmalloc(sizeof(hba[i]->scsi_rejects.complete[0]) *
3793 (hba[i]->nr_cmds + 5), GFP_KERNEL);
3794 if (hba[i]->scsi_rejects.complete == NULL) {
3795 printk(KERN_ERR "cciss: out of memory");
3796 goto clean4;
3797 }
3798#endif
3799 spin_lock_init(&hba[i]->lock); 3979 spin_lock_init(&hba[i]->lock);
3800 3980
3801 /* Initialize the pdev driver private data. 3981 /* Initialize the pdev driver private data.
@@ -3828,7 +4008,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3828 } 4008 }
3829 4009
3830 return_code = sendcmd_withirq(CISS_INQUIRY, i, inq_buff, 4010 return_code = sendcmd_withirq(CISS_INQUIRY, i, inq_buff,
3831 sizeof(InquiryData_struct), 0, 0 , 0, TYPE_CMD); 4011 sizeof(InquiryData_struct), 0, CTLR_LUNID, TYPE_CMD);
3832 if (return_code == IO_OK) { 4012 if (return_code == IO_OK) {
3833 hba[i]->firm_ver[0] = inq_buff->data_byte[32]; 4013 hba[i]->firm_ver[0] = inq_buff->data_byte[32];
3834 hba[i]->firm_ver[1] = inq_buff->data_byte[33]; 4014 hba[i]->firm_ver[1] = inq_buff->data_byte[33];
@@ -3855,9 +4035,6 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3855 4035
3856clean4: 4036clean4:
3857 kfree(inq_buff); 4037 kfree(inq_buff);
3858#ifdef CONFIG_CISS_SCSI_TAPE
3859 kfree(hba[i]->scsi_rejects.complete);
3860#endif
3861 kfree(hba[i]->cmd_pool_bits); 4038 kfree(hba[i]->cmd_pool_bits);
3862 if (hba[i]->cmd_pool) 4039 if (hba[i]->cmd_pool)
3863 pci_free_consistent(hba[i]->pdev, 4040 pci_free_consistent(hba[i]->pdev,
@@ -3872,6 +4049,8 @@ clean4:
3872clean2: 4049clean2:
3873 unregister_blkdev(hba[i]->major, hba[i]->devname); 4050 unregister_blkdev(hba[i]->major, hba[i]->devname);
3874clean1: 4051clean1:
4052 cciss_destroy_hba_sysfs_entry(hba[i]);
4053clean0:
3875 hba[i]->busy_initializing = 0; 4054 hba[i]->busy_initializing = 0;
3876 /* cleanup any queues that may have been initialized */ 4055 /* cleanup any queues that may have been initialized */
3877 for (j=0; j <= hba[i]->highest_lun; j++){ 4056 for (j=0; j <= hba[i]->highest_lun; j++){
@@ -3907,8 +4086,8 @@ static void cciss_shutdown(struct pci_dev *pdev)
3907 /* sendcmd will turn off interrupt, and send the flush... 4086 /* sendcmd will turn off interrupt, and send the flush...
3908 * To write all data in the battery backed cache to disks */ 4087 * To write all data in the battery backed cache to disks */
3909 memset(flush_buf, 0, 4); 4088 memset(flush_buf, 0, 4);
3910 return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0, 0, 0, NULL, 4089 return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0,
3911 TYPE_CMD); 4090 CTLR_LUNID, TYPE_CMD);
3912 if (return_code == IO_OK) { 4091 if (return_code == IO_OK) {
3913 printk(KERN_INFO "Completed flushing cache on controller %d\n", i); 4092 printk(KERN_INFO "Completed flushing cache on controller %d\n", i);
3914 } else { 4093 } else {
@@ -3973,15 +4152,13 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
3973 pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(ErrorInfo_struct), 4152 pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(ErrorInfo_struct),
3974 hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle); 4153 hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle);
3975 kfree(hba[i]->cmd_pool_bits); 4154 kfree(hba[i]->cmd_pool_bits);
3976#ifdef CONFIG_CISS_SCSI_TAPE
3977 kfree(hba[i]->scsi_rejects.complete);
3978#endif
3979 /* 4155 /*
3980 * Deliberately omit pci_disable_device(): it does something nasty to 4156 * Deliberately omit pci_disable_device(): it does something nasty to
3981 * Smart Array controllers that pci_enable_device does not undo 4157 * Smart Array controllers that pci_enable_device does not undo
3982 */ 4158 */
3983 pci_release_regions(pdev); 4159 pci_release_regions(pdev);
3984 pci_set_drvdata(pdev, NULL); 4160 pci_set_drvdata(pdev, NULL);
4161 cciss_destroy_hba_sysfs_entry(hba[i]);
3985 free_hba(i); 4162 free_hba(i);
3986} 4163}
3987 4164
@@ -3999,6 +4176,8 @@ static struct pci_driver cciss_pci_driver = {
3999 */ 4176 */
4000static int __init cciss_init(void) 4177static int __init cciss_init(void)
4001{ 4178{
4179 int err;
4180
4002 /* 4181 /*
4003 * The hardware requires that commands are aligned on a 64-bit 4182 * The hardware requires that commands are aligned on a 64-bit
4004 * boundary. Given that we use pci_alloc_consistent() to allocate an 4183 * boundary. Given that we use pci_alloc_consistent() to allocate an
@@ -4008,8 +4187,20 @@ static int __init cciss_init(void)
4008 4187
4009 printk(KERN_INFO DRIVER_NAME "\n"); 4188 printk(KERN_INFO DRIVER_NAME "\n");
4010 4189
4190 err = bus_register(&cciss_bus_type);
4191 if (err)
4192 return err;
4193
4011 /* Register for our PCI devices */ 4194 /* Register for our PCI devices */
4012 return pci_register_driver(&cciss_pci_driver); 4195 err = pci_register_driver(&cciss_pci_driver);
4196 if (err)
4197 goto err_bus_register;
4198
4199 return 0;
4200
4201err_bus_register:
4202 bus_unregister(&cciss_bus_type);
4203 return err;
4013} 4204}
4014 4205
4015static void __exit cciss_cleanup(void) 4206static void __exit cciss_cleanup(void)
@@ -4026,6 +4217,7 @@ static void __exit cciss_cleanup(void)
4026 } 4217 }
4027 } 4218 }
4028 remove_proc_entry("driver/cciss", NULL); 4219 remove_proc_entry("driver/cciss", NULL);
4220 bus_unregister(&cciss_bus_type);
4029} 4221}
4030 4222
4031static void fail_all_cmds(unsigned long ctlr) 4223static void fail_all_cmds(unsigned long ctlr)