aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/hpsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/hpsa.c')
-rw-r--r--drivers/scsi/hpsa.c344
1 files changed, 182 insertions, 162 deletions
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index b96962c39449..500e20dd56ec 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -56,6 +56,7 @@
56/* HPSA_DRIVER_VERSION must be 3 byte values (0-255) separated by '.' */ 56/* HPSA_DRIVER_VERSION must be 3 byte values (0-255) separated by '.' */
57#define HPSA_DRIVER_VERSION "2.0.2-1" 57#define HPSA_DRIVER_VERSION "2.0.2-1"
58#define DRIVER_NAME "HP HPSA Driver (v " HPSA_DRIVER_VERSION ")" 58#define DRIVER_NAME "HP HPSA Driver (v " HPSA_DRIVER_VERSION ")"
59#define HPSA "hpsa"
59 60
60/* How long to wait (in milliseconds) for board to go into simple mode */ 61/* How long to wait (in milliseconds) for board to go into simple mode */
61#define MAX_CONFIG_WAIT 30000 62#define MAX_CONFIG_WAIT 30000
@@ -202,30 +203,31 @@ static int check_for_unit_attention(struct ctlr_info *h,
202 203
203 switch (c->err_info->SenseInfo[12]) { 204 switch (c->err_info->SenseInfo[12]) {
204 case STATE_CHANGED: 205 case STATE_CHANGED:
205 dev_warn(&h->pdev->dev, "hpsa%d: a state change " 206 dev_warn(&h->pdev->dev, HPSA "%d: a state change "
206 "detected, command retried\n", h->ctlr); 207 "detected, command retried\n", h->ctlr);
207 break; 208 break;
208 case LUN_FAILED: 209 case LUN_FAILED:
209 dev_warn(&h->pdev->dev, "hpsa%d: LUN failure " 210 dev_warn(&h->pdev->dev, HPSA "%d: LUN failure "
210 "detected, action required\n", h->ctlr); 211 "detected, action required\n", h->ctlr);
211 break; 212 break;
212 case REPORT_LUNS_CHANGED: 213 case REPORT_LUNS_CHANGED:
213 dev_warn(&h->pdev->dev, "hpsa%d: report LUN data " 214 dev_warn(&h->pdev->dev, HPSA "%d: report LUN data "
214 "changed, action required\n", h->ctlr); 215 "changed, action required\n", h->ctlr);
215 /* 216 /*
216 * Note: this REPORT_LUNS_CHANGED condition only occurs on the MSA2012. 217 * Note: this REPORT_LUNS_CHANGED condition only occurs on the external
218 * target (array) devices.
217 */ 219 */
218 break; 220 break;
219 case POWER_OR_RESET: 221 case POWER_OR_RESET:
220 dev_warn(&h->pdev->dev, "hpsa%d: a power on " 222 dev_warn(&h->pdev->dev, HPSA "%d: a power on "
221 "or device reset detected\n", h->ctlr); 223 "or device reset detected\n", h->ctlr);
222 break; 224 break;
223 case UNIT_ATTENTION_CLEARED: 225 case UNIT_ATTENTION_CLEARED:
224 dev_warn(&h->pdev->dev, "hpsa%d: unit attention " 226 dev_warn(&h->pdev->dev, HPSA "%d: unit attention "
225 "cleared by another initiator\n", h->ctlr); 227 "cleared by another initiator\n", h->ctlr);
226 break; 228 break;
227 default: 229 default:
228 dev_warn(&h->pdev->dev, "hpsa%d: unknown " 230 dev_warn(&h->pdev->dev, HPSA "%d: unknown "
229 "unit attention detected\n", h->ctlr); 231 "unit attention detected\n", h->ctlr);
230 break; 232 break;
231 } 233 }
@@ -296,11 +298,23 @@ static u32 unresettable_controller[] = {
296 0x40800E11, /* Smart Array 5i */ 298 0x40800E11, /* Smart Array 5i */
297 0x409C0E11, /* Smart Array 6400 */ 299 0x409C0E11, /* Smart Array 6400 */
298 0x409D0E11, /* Smart Array 6400 EM */ 300 0x409D0E11, /* Smart Array 6400 EM */
301 0x40700E11, /* Smart Array 5300 */
302 0x40820E11, /* Smart Array 532 */
303 0x40830E11, /* Smart Array 5312 */
304 0x409A0E11, /* Smart Array 641 */
305 0x409B0E11, /* Smart Array 642 */
306 0x40910E11, /* Smart Array 6i */
299}; 307};
300 308
301/* List of controllers which cannot even be soft reset */ 309/* List of controllers which cannot even be soft reset */
302static u32 soft_unresettable_controller[] = { 310static u32 soft_unresettable_controller[] = {
303 0x40800E11, /* Smart Array 5i */ 311 0x40800E11, /* Smart Array 5i */
312 0x40700E11, /* Smart Array 5300 */
313 0x40820E11, /* Smart Array 532 */
314 0x40830E11, /* Smart Array 5312 */
315 0x409A0E11, /* Smart Array 641 */
316 0x409B0E11, /* Smart Array 642 */
317 0x40910E11, /* Smart Array 6i */
304 /* Exclude 640x boards. These are two pci devices in one slot 318 /* Exclude 640x boards. These are two pci devices in one slot
305 * which share a battery backed cache module. One controls the 319 * which share a battery backed cache module. One controls the
306 * cache, the other accesses the cache through the one that controls 320 * cache, the other accesses the cache through the one that controls
@@ -475,8 +489,8 @@ static struct device_attribute *hpsa_shost_attrs[] = {
475 489
476static struct scsi_host_template hpsa_driver_template = { 490static struct scsi_host_template hpsa_driver_template = {
477 .module = THIS_MODULE, 491 .module = THIS_MODULE,
478 .name = "hpsa", 492 .name = HPSA,
479 .proc_name = "hpsa", 493 .proc_name = HPSA,
480 .queuecommand = hpsa_scsi_queue_command, 494 .queuecommand = hpsa_scsi_queue_command,
481 .scan_start = hpsa_scan_start, 495 .scan_start = hpsa_scan_start,
482 .scan_finished = hpsa_scan_finished, 496 .scan_finished = hpsa_scan_finished,
@@ -577,21 +591,19 @@ static int hpsa_find_target_lun(struct ctlr_info *h,
577 int i, found = 0; 591 int i, found = 0;
578 DECLARE_BITMAP(lun_taken, HPSA_MAX_DEVICES); 592 DECLARE_BITMAP(lun_taken, HPSA_MAX_DEVICES);
579 593
580 memset(&lun_taken[0], 0, HPSA_MAX_DEVICES >> 3); 594 bitmap_zero(lun_taken, HPSA_MAX_DEVICES);
581 595
582 for (i = 0; i < h->ndevices; i++) { 596 for (i = 0; i < h->ndevices; i++) {
583 if (h->dev[i]->bus == bus && h->dev[i]->target != -1) 597 if (h->dev[i]->bus == bus && h->dev[i]->target != -1)
584 set_bit(h->dev[i]->target, lun_taken); 598 __set_bit(h->dev[i]->target, lun_taken);
585 } 599 }
586 600
587 for (i = 0; i < HPSA_MAX_DEVICES; i++) { 601 i = find_first_zero_bit(lun_taken, HPSA_MAX_DEVICES);
588 if (!test_bit(i, lun_taken)) { 602 if (i < HPSA_MAX_DEVICES) {
589 /* *bus = 1; */ 603 /* *bus = 1; */
590 *target = i; 604 *target = i;
591 *lun = 0; 605 *lun = 0;
592 found = 1; 606 found = 1;
593 break;
594 }
595 } 607 }
596 return !found; 608 return !found;
597} 609}
@@ -675,6 +687,20 @@ lun_assigned:
675 return 0; 687 return 0;
676} 688}
677 689
690/* Update an entry in h->dev[] array. */
691static void hpsa_scsi_update_entry(struct ctlr_info *h, int hostno,
692 int entry, struct hpsa_scsi_dev_t *new_entry)
693{
694 /* assumes h->devlock is held */
695 BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES);
696
697 /* Raid level changed. */
698 h->dev[entry]->raid_level = new_entry->raid_level;
699 dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d updated.\n",
700 scsi_device_type(new_entry->devtype), hostno, new_entry->bus,
701 new_entry->target, new_entry->lun);
702}
703
678/* Replace an entry from h->dev[] array. */ 704/* Replace an entry from h->dev[] array. */
679static void hpsa_scsi_replace_entry(struct ctlr_info *h, int hostno, 705static void hpsa_scsi_replace_entry(struct ctlr_info *h, int hostno,
680 int entry, struct hpsa_scsi_dev_t *new_entry, 706 int entry, struct hpsa_scsi_dev_t *new_entry,
@@ -781,10 +807,25 @@ static inline int device_is_the_same(struct hpsa_scsi_dev_t *dev1,
781 return 1; 807 return 1;
782} 808}
783 809
810static inline int device_updated(struct hpsa_scsi_dev_t *dev1,
811 struct hpsa_scsi_dev_t *dev2)
812{
813 /* Device attributes that can change, but don't mean
814 * that the device is a different device, nor that the OS
815 * needs to be told anything about the change.
816 */
817 if (dev1->raid_level != dev2->raid_level)
818 return 1;
819 return 0;
820}
821
784/* Find needle in haystack. If exact match found, return DEVICE_SAME, 822/* Find needle in haystack. If exact match found, return DEVICE_SAME,
785 * and return needle location in *index. If scsi3addr matches, but not 823 * and return needle location in *index. If scsi3addr matches, but not
786 * vendor, model, serial num, etc. return DEVICE_CHANGED, and return needle 824 * vendor, model, serial num, etc. return DEVICE_CHANGED, and return needle
787 * location in *index. If needle not found, return DEVICE_NOT_FOUND. 825 * location in *index.
826 * In the case of a minor device attribute change, such as RAID level, just
827 * return DEVICE_UPDATED, along with the updated device's location in index.
828 * If needle not found, return DEVICE_NOT_FOUND.
788 */ 829 */
789static int hpsa_scsi_find_entry(struct hpsa_scsi_dev_t *needle, 830static int hpsa_scsi_find_entry(struct hpsa_scsi_dev_t *needle,
790 struct hpsa_scsi_dev_t *haystack[], int haystack_size, 831 struct hpsa_scsi_dev_t *haystack[], int haystack_size,
@@ -794,15 +835,19 @@ static int hpsa_scsi_find_entry(struct hpsa_scsi_dev_t *needle,
794#define DEVICE_NOT_FOUND 0 835#define DEVICE_NOT_FOUND 0
795#define DEVICE_CHANGED 1 836#define DEVICE_CHANGED 1
796#define DEVICE_SAME 2 837#define DEVICE_SAME 2
838#define DEVICE_UPDATED 3
797 for (i = 0; i < haystack_size; i++) { 839 for (i = 0; i < haystack_size; i++) {
798 if (haystack[i] == NULL) /* previously removed. */ 840 if (haystack[i] == NULL) /* previously removed. */
799 continue; 841 continue;
800 if (SCSI3ADDR_EQ(needle->scsi3addr, haystack[i]->scsi3addr)) { 842 if (SCSI3ADDR_EQ(needle->scsi3addr, haystack[i]->scsi3addr)) {
801 *index = i; 843 *index = i;
802 if (device_is_the_same(needle, haystack[i])) 844 if (device_is_the_same(needle, haystack[i])) {
845 if (device_updated(needle, haystack[i]))
846 return DEVICE_UPDATED;
803 return DEVICE_SAME; 847 return DEVICE_SAME;
804 else 848 } else {
805 return DEVICE_CHANGED; 849 return DEVICE_CHANGED;
850 }
806 } 851 }
807 } 852 }
808 *index = -1; 853 *index = -1;
@@ -838,6 +883,8 @@ static void adjust_hpsa_scsi_table(struct ctlr_info *h, int hostno,
838 * sd[] and remove them from h->dev[], and for any 883 * sd[] and remove them from h->dev[], and for any
839 * devices which have changed, remove the old device 884 * devices which have changed, remove the old device
840 * info and add the new device info. 885 * info and add the new device info.
886 * If minor device attributes change, just update
887 * the existing device structure.
841 */ 888 */
842 i = 0; 889 i = 0;
843 nremoved = 0; 890 nremoved = 0;
@@ -858,6 +905,8 @@ static void adjust_hpsa_scsi_table(struct ctlr_info *h, int hostno,
858 * at the bottom of hpsa_update_scsi_devices() 905 * at the bottom of hpsa_update_scsi_devices()
859 */ 906 */
860 sd[entry] = NULL; 907 sd[entry] = NULL;
908 } else if (device_change == DEVICE_UPDATED) {
909 hpsa_scsi_update_entry(h, hostno, i, sd[entry]);
861 } 910 }
862 i++; 911 i++;
863 } 912 }
@@ -1257,46 +1306,6 @@ static void complete_scsi_command(struct CommandList *cp)
1257 cmd_free(h, cp); 1306 cmd_free(h, cp);
1258} 1307}
1259 1308
1260static int hpsa_scsi_detect(struct ctlr_info *h)
1261{
1262 struct Scsi_Host *sh;
1263 int error;
1264
1265 sh = scsi_host_alloc(&hpsa_driver_template, sizeof(h));
1266 if (sh == NULL)
1267 goto fail;
1268
1269 sh->io_port = 0;
1270 sh->n_io_port = 0;
1271 sh->this_id = -1;
1272 sh->max_channel = 3;
1273 sh->max_cmd_len = MAX_COMMAND_SIZE;
1274 sh->max_lun = HPSA_MAX_LUN;
1275 sh->max_id = HPSA_MAX_LUN;
1276 sh->can_queue = h->nr_cmds;
1277 sh->cmd_per_lun = h->nr_cmds;
1278 sh->sg_tablesize = h->maxsgentries;
1279 h->scsi_host = sh;
1280 sh->hostdata[0] = (unsigned long) h;
1281 sh->irq = h->intr[h->intr_mode];
1282 sh->unique_id = sh->irq;
1283 error = scsi_add_host(sh, &h->pdev->dev);
1284 if (error)
1285 goto fail_host_put;
1286 scsi_scan_host(sh);
1287 return 0;
1288
1289 fail_host_put:
1290 dev_err(&h->pdev->dev, "hpsa_scsi_detect: scsi_add_host"
1291 " failed for controller %d\n", h->ctlr);
1292 scsi_host_put(sh);
1293 return error;
1294 fail:
1295 dev_err(&h->pdev->dev, "hpsa_scsi_detect: scsi_host_alloc"
1296 " failed for controller %d\n", h->ctlr);
1297 return -ENOMEM;
1298}
1299
1300static void hpsa_pci_unmap(struct pci_dev *pdev, 1309static void hpsa_pci_unmap(struct pci_dev *pdev,
1301 struct CommandList *c, int sg_used, int data_direction) 1310 struct CommandList *c, int sg_used, int data_direction)
1302{ 1311{
@@ -1641,7 +1650,7 @@ bail_out:
1641 return 1; 1650 return 1;
1642} 1651}
1643 1652
1644static unsigned char *msa2xxx_model[] = { 1653static unsigned char *ext_target_model[] = {
1645 "MSA2012", 1654 "MSA2012",
1646 "MSA2024", 1655 "MSA2024",
1647 "MSA2312", 1656 "MSA2312",
@@ -1650,78 +1659,54 @@ static unsigned char *msa2xxx_model[] = {
1650 NULL, 1659 NULL,
1651}; 1660};
1652 1661
1653static int is_msa2xxx(struct ctlr_info *h, struct hpsa_scsi_dev_t *device) 1662static int is_ext_target(struct ctlr_info *h, struct hpsa_scsi_dev_t *device)
1654{ 1663{
1655 int i; 1664 int i;
1656 1665
1657 for (i = 0; msa2xxx_model[i]; i++) 1666 for (i = 0; ext_target_model[i]; i++)
1658 if (strncmp(device->model, msa2xxx_model[i], 1667 if (strncmp(device->model, ext_target_model[i],
1659 strlen(msa2xxx_model[i])) == 0) 1668 strlen(ext_target_model[i])) == 0)
1660 return 1; 1669 return 1;
1661 return 0; 1670 return 0;
1662} 1671}
1663 1672
1664/* Helper function to assign bus, target, lun mapping of devices. 1673/* Helper function to assign bus, target, lun mapping of devices.
1665 * Puts non-msa2xxx logical volumes on bus 0, msa2xxx logical 1674 * Puts non-external target logical volumes on bus 0, external target logical
1666 * volumes on bus 1, physical devices on bus 2. and the hba on bus 3. 1675 * volumes on bus 1, physical devices on bus 2. and the hba on bus 3.
1667 * Logical drive target and lun are assigned at this time, but 1676 * Logical drive target and lun are assigned at this time, but
1668 * physical device lun and target assignment are deferred (assigned 1677 * physical device lun and target assignment are deferred (assigned
1669 * in hpsa_find_target_lun, called by hpsa_scsi_add_entry.) 1678 * in hpsa_find_target_lun, called by hpsa_scsi_add_entry.)
1670 */ 1679 */
1671static void figure_bus_target_lun(struct ctlr_info *h, 1680static void figure_bus_target_lun(struct ctlr_info *h,
1672 u8 *lunaddrbytes, int *bus, int *target, int *lun, 1681 u8 *lunaddrbytes, struct hpsa_scsi_dev_t *device)
1673 struct hpsa_scsi_dev_t *device)
1674{ 1682{
1675 u32 lunid; 1683 u32 lunid = le32_to_cpu(*((__le32 *) lunaddrbytes));
1676 1684
1677 if (is_logical_dev_addr_mode(lunaddrbytes)) { 1685 if (!is_logical_dev_addr_mode(lunaddrbytes)) {
1678 /* logical device */ 1686 /* physical device, target and lun filled in later */
1679 if (unlikely(is_scsi_rev_5(h))) {
1680 /* p1210m, logical drives lun assignments
1681 * match SCSI REPORT LUNS data.
1682 */
1683 lunid = le32_to_cpu(*((__le32 *) lunaddrbytes));
1684 *bus = 0;
1685 *target = 0;
1686 *lun = (lunid & 0x3fff) + 1;
1687 } else {
1688 /* not p1210m... */
1689 lunid = le32_to_cpu(*((__le32 *) lunaddrbytes));
1690 if (is_msa2xxx(h, device)) {
1691 /* msa2xxx way, put logicals on bus 1
1692 * and match target/lun numbers box
1693 * reports.
1694 */
1695 *bus = 1;
1696 *target = (lunid >> 16) & 0x3fff;
1697 *lun = lunid & 0x00ff;
1698 } else {
1699 /* Traditional smart array way. */
1700 *bus = 0;
1701 *lun = 0;
1702 *target = lunid & 0x3fff;
1703 }
1704 }
1705 } else {
1706 /* physical device */
1707 if (is_hba_lunid(lunaddrbytes)) 1687 if (is_hba_lunid(lunaddrbytes))
1708 if (unlikely(is_scsi_rev_5(h))) { 1688 hpsa_set_bus_target_lun(device, 3, 0, lunid & 0x3fff);
1709 *bus = 0; /* put p1210m ctlr at 0,0,0 */
1710 *target = 0;
1711 *lun = 0;
1712 return;
1713 } else
1714 *bus = 3; /* traditional smartarray */
1715 else 1689 else
1716 *bus = 2; /* physical disk */ 1690 /* defer target, lun assignment for physical devices */
1717 *target = -1; 1691 hpsa_set_bus_target_lun(device, 2, -1, -1);
1718 *lun = -1; /* we will fill these in later. */ 1692 return;
1693 }
1694 /* It's a logical device */
1695 if (is_ext_target(h, device)) {
1696 /* external target way, put logicals on bus 1
1697 * and match target/lun numbers box
1698 * reports, other smart array, bus 0, target 0, match lunid
1699 */
1700 hpsa_set_bus_target_lun(device,
1701 1, (lunid >> 16) & 0x3fff, lunid & 0x00ff);
1702 return;
1719 } 1703 }
1704 hpsa_set_bus_target_lun(device, 0, 0, lunid & 0x3fff);
1720} 1705}
1721 1706
1722/* 1707/*
1723 * If there is no lun 0 on a target, linux won't find any devices. 1708 * If there is no lun 0 on a target, linux won't find any devices.
1724 * For the MSA2xxx boxes, we have to manually detect the enclosure 1709 * For the external targets (arrays), we have to manually detect the enclosure
1725 * which is at lun zero, as CCISS_REPORT_PHYSICAL_LUNS doesn't report 1710 * which is at lun zero, as CCISS_REPORT_PHYSICAL_LUNS doesn't report
1726 * it for some reason. *tmpdevice is the target we're adding, 1711 * it for some reason. *tmpdevice is the target we're adding,
1727 * this_device is a pointer into the current element of currentsd[] 1712 * this_device is a pointer into the current element of currentsd[]
@@ -1730,46 +1715,46 @@ static void figure_bus_target_lun(struct ctlr_info *h,
1730 * lun 0 assigned. 1715 * lun 0 assigned.
1731 * Returns 1 if an enclosure was added, 0 if not. 1716 * Returns 1 if an enclosure was added, 0 if not.
1732 */ 1717 */
1733static int add_msa2xxx_enclosure_device(struct ctlr_info *h, 1718static int add_ext_target_dev(struct ctlr_info *h,
1734 struct hpsa_scsi_dev_t *tmpdevice, 1719 struct hpsa_scsi_dev_t *tmpdevice,
1735 struct hpsa_scsi_dev_t *this_device, u8 *lunaddrbytes, 1720 struct hpsa_scsi_dev_t *this_device, u8 *lunaddrbytes,
1736 int bus, int target, int lun, unsigned long lunzerobits[], 1721 unsigned long lunzerobits[], int *n_ext_target_devs)
1737 int *nmsa2xxx_enclosures)
1738{ 1722{
1739 unsigned char scsi3addr[8]; 1723 unsigned char scsi3addr[8];
1740 1724
1741 if (test_bit(target, lunzerobits)) 1725 if (test_bit(tmpdevice->target, lunzerobits))
1742 return 0; /* There is already a lun 0 on this target. */ 1726 return 0; /* There is already a lun 0 on this target. */
1743 1727
1744 if (!is_logical_dev_addr_mode(lunaddrbytes)) 1728 if (!is_logical_dev_addr_mode(lunaddrbytes))
1745 return 0; /* It's the logical targets that may lack lun 0. */ 1729 return 0; /* It's the logical targets that may lack lun 0. */
1746 1730
1747 if (!is_msa2xxx(h, tmpdevice)) 1731 if (!is_ext_target(h, tmpdevice))
1748 return 0; /* It's only the MSA2xxx that have this problem. */ 1732 return 0; /* Only external target devices have this problem. */
1749 1733
1750 if (lun == 0) /* if lun is 0, then obviously we have a lun 0. */ 1734 if (tmpdevice->lun == 0) /* if lun is 0, then we have a lun 0. */
1751 return 0; 1735 return 0;
1752 1736
1753 memset(scsi3addr, 0, 8); 1737 memset(scsi3addr, 0, 8);
1754 scsi3addr[3] = target; 1738 scsi3addr[3] = tmpdevice->target;
1755 if (is_hba_lunid(scsi3addr)) 1739 if (is_hba_lunid(scsi3addr))
1756 return 0; /* Don't add the RAID controller here. */ 1740 return 0; /* Don't add the RAID controller here. */
1757 1741
1758 if (is_scsi_rev_5(h)) 1742 if (is_scsi_rev_5(h))
1759 return 0; /* p1210m doesn't need to do this. */ 1743 return 0; /* p1210m doesn't need to do this. */
1760 1744
1761 if (*nmsa2xxx_enclosures >= MAX_MSA2XXX_ENCLOSURES) { 1745 if (*n_ext_target_devs >= MAX_EXT_TARGETS) {
1762 dev_warn(&h->pdev->dev, "Maximum number of MSA2XXX " 1746 dev_warn(&h->pdev->dev, "Maximum number of external "
1763 "enclosures exceeded. Check your hardware " 1747 "target devices exceeded. Check your hardware "
1764 "configuration."); 1748 "configuration.");
1765 return 0; 1749 return 0;
1766 } 1750 }
1767 1751
1768 if (hpsa_update_device_info(h, scsi3addr, this_device, NULL)) 1752 if (hpsa_update_device_info(h, scsi3addr, this_device, NULL))
1769 return 0; 1753 return 0;
1770 (*nmsa2xxx_enclosures)++; 1754 (*n_ext_target_devs)++;
1771 hpsa_set_bus_target_lun(this_device, bus, target, 0); 1755 hpsa_set_bus_target_lun(this_device,
1772 set_bit(target, lunzerobits); 1756 tmpdevice->bus, tmpdevice->target, 0);
1757 set_bit(tmpdevice->target, lunzerobits);
1773 return 1; 1758 return 1;
1774} 1759}
1775 1760
@@ -1863,10 +1848,9 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
1863 struct hpsa_scsi_dev_t **currentsd, *this_device, *tmpdevice; 1848 struct hpsa_scsi_dev_t **currentsd, *this_device, *tmpdevice;
1864 int ncurrent = 0; 1849 int ncurrent = 0;
1865 int reportlunsize = sizeof(*physdev_list) + HPSA_MAX_PHYS_LUN * 8; 1850 int reportlunsize = sizeof(*physdev_list) + HPSA_MAX_PHYS_LUN * 8;
1866 int i, nmsa2xxx_enclosures, ndevs_to_allocate; 1851 int i, n_ext_target_devs, ndevs_to_allocate;
1867 int bus, target, lun;
1868 int raid_ctlr_position; 1852 int raid_ctlr_position;
1869 DECLARE_BITMAP(lunzerobits, HPSA_MAX_TARGETS_PER_CTLR); 1853 DECLARE_BITMAP(lunzerobits, MAX_EXT_TARGETS);
1870 1854
1871 currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_DEVICES, GFP_KERNEL); 1855 currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_DEVICES, GFP_KERNEL);
1872 physdev_list = kzalloc(reportlunsize, GFP_KERNEL); 1856 physdev_list = kzalloc(reportlunsize, GFP_KERNEL);
@@ -1883,11 +1867,11 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
1883 logdev_list, &nlogicals)) 1867 logdev_list, &nlogicals))
1884 goto out; 1868 goto out;
1885 1869
1886 /* We might see up to 32 MSA2xxx enclosures, actually 8 of them 1870 /* We might see up to the maximum number of logical and physical disks
1887 * but each of them 4 times through different paths. The plus 1 1871 * plus external target devices, and a device for the local RAID
1888 * is for the RAID controller. 1872 * controller.
1889 */ 1873 */
1890 ndevs_to_allocate = nphysicals + nlogicals + MAX_MSA2XXX_ENCLOSURES + 1; 1874 ndevs_to_allocate = nphysicals + nlogicals + MAX_EXT_TARGETS + 1;
1891 1875
1892 /* Allocate the per device structures */ 1876 /* Allocate the per device structures */
1893 for (i = 0; i < ndevs_to_allocate; i++) { 1877 for (i = 0; i < ndevs_to_allocate; i++) {
@@ -1913,7 +1897,7 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
1913 raid_ctlr_position = nphysicals + nlogicals; 1897 raid_ctlr_position = nphysicals + nlogicals;
1914 1898
1915 /* adjust our table of devices */ 1899 /* adjust our table of devices */
1916 nmsa2xxx_enclosures = 0; 1900 n_ext_target_devs = 0;
1917 for (i = 0; i < nphysicals + nlogicals + 1; i++) { 1901 for (i = 0; i < nphysicals + nlogicals + 1; i++) {
1918 u8 *lunaddrbytes, is_OBDR = 0; 1902 u8 *lunaddrbytes, is_OBDR = 0;
1919 1903
@@ -1929,26 +1913,24 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
1929 if (hpsa_update_device_info(h, lunaddrbytes, tmpdevice, 1913 if (hpsa_update_device_info(h, lunaddrbytes, tmpdevice,
1930 &is_OBDR)) 1914 &is_OBDR))
1931 continue; /* skip it if we can't talk to it. */ 1915 continue; /* skip it if we can't talk to it. */
1932 figure_bus_target_lun(h, lunaddrbytes, &bus, &target, &lun, 1916 figure_bus_target_lun(h, lunaddrbytes, tmpdevice);
1933 tmpdevice);
1934 this_device = currentsd[ncurrent]; 1917 this_device = currentsd[ncurrent];
1935 1918
1936 /* 1919 /*
1937 * For the msa2xxx boxes, we have to insert a LUN 0 which 1920 * For external target devices, we have to insert a LUN 0 which
1938 * doesn't show up in CCISS_REPORT_PHYSICAL data, but there 1921 * doesn't show up in CCISS_REPORT_PHYSICAL data, but there
1939 * is nonetheless an enclosure device there. We have to 1922 * is nonetheless an enclosure device there. We have to
1940 * present that otherwise linux won't find anything if 1923 * present that otherwise linux won't find anything if
1941 * there is no lun 0. 1924 * there is no lun 0.
1942 */ 1925 */
1943 if (add_msa2xxx_enclosure_device(h, tmpdevice, this_device, 1926 if (add_ext_target_dev(h, tmpdevice, this_device,
1944 lunaddrbytes, bus, target, lun, lunzerobits, 1927 lunaddrbytes, lunzerobits,
1945 &nmsa2xxx_enclosures)) { 1928 &n_ext_target_devs)) {
1946 ncurrent++; 1929 ncurrent++;
1947 this_device = currentsd[ncurrent]; 1930 this_device = currentsd[ncurrent];
1948 } 1931 }
1949 1932
1950 *this_device = *tmpdevice; 1933 *this_device = *tmpdevice;
1951 hpsa_set_bus_target_lun(this_device, bus, target, lun);
1952 1934
1953 switch (this_device->devtype) { 1935 switch (this_device->devtype) {
1954 case TYPE_ROM: 1936 case TYPE_ROM:
@@ -2228,13 +2210,42 @@ static void hpsa_unregister_scsi(struct ctlr_info *h)
2228 2210
2229static int hpsa_register_scsi(struct ctlr_info *h) 2211static int hpsa_register_scsi(struct ctlr_info *h)
2230{ 2212{
2231 int rc; 2213 struct Scsi_Host *sh;
2214 int error;
2232 2215
2233 rc = hpsa_scsi_detect(h); 2216 sh = scsi_host_alloc(&hpsa_driver_template, sizeof(h));
2234 if (rc != 0) 2217 if (sh == NULL)
2235 dev_err(&h->pdev->dev, "hpsa_register_scsi: failed" 2218 goto fail;
2236 " hpsa_scsi_detect(), rc is %d\n", rc); 2219
2237 return rc; 2220 sh->io_port = 0;
2221 sh->n_io_port = 0;
2222 sh->this_id = -1;
2223 sh->max_channel = 3;
2224 sh->max_cmd_len = MAX_COMMAND_SIZE;
2225 sh->max_lun = HPSA_MAX_LUN;
2226 sh->max_id = HPSA_MAX_LUN;
2227 sh->can_queue = h->nr_cmds;
2228 sh->cmd_per_lun = h->nr_cmds;
2229 sh->sg_tablesize = h->maxsgentries;
2230 h->scsi_host = sh;
2231 sh->hostdata[0] = (unsigned long) h;
2232 sh->irq = h->intr[h->intr_mode];
2233 sh->unique_id = sh->irq;
2234 error = scsi_add_host(sh, &h->pdev->dev);
2235 if (error)
2236 goto fail_host_put;
2237 scsi_scan_host(sh);
2238 return 0;
2239
2240 fail_host_put:
2241 dev_err(&h->pdev->dev, "%s: scsi_add_host"
2242 " failed for controller %d\n", __func__, h->ctlr);
2243 scsi_host_put(sh);
2244 return error;
2245 fail:
2246 dev_err(&h->pdev->dev, "%s: scsi_host_alloc"
2247 " failed for controller %d\n", __func__, h->ctlr);
2248 return -ENOMEM;
2238} 2249}
2239 2250
2240static int wait_for_device_to_become_ready(struct ctlr_info *h, 2251static int wait_for_device_to_become_ready(struct ctlr_info *h,
@@ -2700,16 +2711,16 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
2700 status = -EINVAL; 2711 status = -EINVAL;
2701 goto cleanup1; 2712 goto cleanup1;
2702 } 2713 }
2703 if (ioc->buf_size > ioc->malloc_size * MAXSGENTRIES) { 2714 if (ioc->buf_size > ioc->malloc_size * SG_ENTRIES_IN_CMD) {
2704 status = -EINVAL; 2715 status = -EINVAL;
2705 goto cleanup1; 2716 goto cleanup1;
2706 } 2717 }
2707 buff = kzalloc(MAXSGENTRIES * sizeof(char *), GFP_KERNEL); 2718 buff = kzalloc(SG_ENTRIES_IN_CMD * sizeof(char *), GFP_KERNEL);
2708 if (!buff) { 2719 if (!buff) {
2709 status = -ENOMEM; 2720 status = -ENOMEM;
2710 goto cleanup1; 2721 goto cleanup1;
2711 } 2722 }
2712 buff_size = kmalloc(MAXSGENTRIES * sizeof(int), GFP_KERNEL); 2723 buff_size = kmalloc(SG_ENTRIES_IN_CMD * sizeof(int), GFP_KERNEL);
2713 if (!buff_size) { 2724 if (!buff_size) {
2714 status = -ENOMEM; 2725 status = -ENOMEM;
2715 goto cleanup1; 2726 goto cleanup1;
@@ -3354,7 +3365,7 @@ static int hpsa_controller_hard_reset(struct pci_dev *pdev,
3354static __devinit void init_driver_version(char *driver_version, int len) 3365static __devinit void init_driver_version(char *driver_version, int len)
3355{ 3366{
3356 memset(driver_version, 0, len); 3367 memset(driver_version, 0, len);
3357 strncpy(driver_version, "hpsa " HPSA_DRIVER_VERSION, len - 1); 3368 strncpy(driver_version, HPSA " " HPSA_DRIVER_VERSION, len - 1);
3358} 3369}
3359 3370
3360static __devinit int write_driver_ver_to_cfgtable( 3371static __devinit int write_driver_ver_to_cfgtable(
@@ -3935,7 +3946,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
3935 return err; 3946 return err;
3936 } 3947 }
3937 3948
3938 err = pci_request_regions(h->pdev, "hpsa"); 3949 err = pci_request_regions(h->pdev, HPSA);
3939 if (err) { 3950 if (err) {
3940 dev_err(&h->pdev->dev, 3951 dev_err(&h->pdev->dev,
3941 "cannot obtain PCI resources, aborting\n"); 3952 "cannot obtain PCI resources, aborting\n");
@@ -4253,7 +4264,7 @@ static void start_controller_lockup_detector(struct ctlr_info *h)
4253 spin_lock_init(&lockup_detector_lock); 4264 spin_lock_init(&lockup_detector_lock);
4254 hpsa_lockup_detector = 4265 hpsa_lockup_detector =
4255 kthread_run(detect_controller_lockup_thread, 4266 kthread_run(detect_controller_lockup_thread,
4256 NULL, "hpsa"); 4267 NULL, HPSA);
4257 } 4268 }
4258 if (!hpsa_lockup_detector) { 4269 if (!hpsa_lockup_detector) {
4259 dev_warn(&h->pdev->dev, 4270 dev_warn(&h->pdev->dev,
@@ -4325,7 +4336,7 @@ reinit_after_soft_reset:
4325 if (rc != 0) 4336 if (rc != 0)
4326 goto clean1; 4337 goto clean1;
4327 4338
4328 sprintf(h->devname, "hpsa%d", number_of_controllers); 4339 sprintf(h->devname, HPSA "%d", number_of_controllers);
4329 h->ctlr = number_of_controllers; 4340 h->ctlr = number_of_controllers;
4330 number_of_controllers++; 4341 number_of_controllers++;
4331 4342
@@ -4482,6 +4493,14 @@ static void hpsa_shutdown(struct pci_dev *pdev)
4482#endif /* CONFIG_PCI_MSI */ 4493#endif /* CONFIG_PCI_MSI */
4483} 4494}
4484 4495
4496static void __devexit hpsa_free_device_info(struct ctlr_info *h)
4497{
4498 int i;
4499
4500 for (i = 0; i < h->ndevices; i++)
4501 kfree(h->dev[i]);
4502}
4503
4485static void __devexit hpsa_remove_one(struct pci_dev *pdev) 4504static void __devexit hpsa_remove_one(struct pci_dev *pdev)
4486{ 4505{
4487 struct ctlr_info *h; 4506 struct ctlr_info *h;
@@ -4497,6 +4516,7 @@ static void __devexit hpsa_remove_one(struct pci_dev *pdev)
4497 iounmap(h->vaddr); 4516 iounmap(h->vaddr);
4498 iounmap(h->transtable); 4517 iounmap(h->transtable);
4499 iounmap(h->cfgtable); 4518 iounmap(h->cfgtable);
4519 hpsa_free_device_info(h);
4500 hpsa_free_sg_chain_blocks(h); 4520 hpsa_free_sg_chain_blocks(h);
4501 pci_free_consistent(h->pdev, 4521 pci_free_consistent(h->pdev,
4502 h->nr_cmds * sizeof(struct CommandList), 4522 h->nr_cmds * sizeof(struct CommandList),
@@ -4530,7 +4550,7 @@ static int hpsa_resume(__attribute__((unused)) struct pci_dev *pdev)
4530} 4550}
4531 4551
4532static struct pci_driver hpsa_pci_driver = { 4552static struct pci_driver hpsa_pci_driver = {
4533 .name = "hpsa", 4553 .name = HPSA,
4534 .probe = hpsa_init_one, 4554 .probe = hpsa_init_one,
4535 .remove = __devexit_p(hpsa_remove_one), 4555 .remove = __devexit_p(hpsa_remove_one),
4536 .id_table = hpsa_pci_device_id, /* id_table */ 4556 .id_table = hpsa_pci_device_id, /* id_table */
@@ -4592,15 +4612,15 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
4592 * Each SG entry requires 16 bytes. The eight registers are programmed 4612 * Each SG entry requires 16 bytes. The eight registers are programmed
4593 * with the number of 16-byte blocks a command of that size requires. 4613 * with the number of 16-byte blocks a command of that size requires.
4594 * The smallest command possible requires 5 such 16 byte blocks. 4614 * The smallest command possible requires 5 such 16 byte blocks.
4595 * the largest command possible requires MAXSGENTRIES + 4 16-byte 4615 * the largest command possible requires SG_ENTRIES_IN_CMD + 4 16-byte
4596 * blocks. Note, this only extends to the SG entries contained 4616 * blocks. Note, this only extends to the SG entries contained
4597 * within the command block, and does not extend to chained blocks 4617 * within the command block, and does not extend to chained blocks
4598 * of SG elements. bft[] contains the eight values we write to 4618 * of SG elements. bft[] contains the eight values we write to
4599 * the registers. They are not evenly distributed, but have more 4619 * the registers. They are not evenly distributed, but have more
4600 * sizes for small commands, and fewer sizes for larger commands. 4620 * sizes for small commands, and fewer sizes for larger commands.
4601 */ 4621 */
4602 int bft[8] = {5, 6, 8, 10, 12, 20, 28, MAXSGENTRIES + 4}; 4622 int bft[8] = {5, 6, 8, 10, 12, 20, 28, SG_ENTRIES_IN_CMD + 4};
4603 BUILD_BUG_ON(28 > MAXSGENTRIES + 4); 4623 BUILD_BUG_ON(28 > SG_ENTRIES_IN_CMD + 4);
4604 /* 5 = 1 s/g entry or 4k 4624 /* 5 = 1 s/g entry or 4k
4605 * 6 = 2 s/g entry or 8k 4625 * 6 = 2 s/g entry or 8k
4606 * 8 = 4 s/g entry or 16k 4626 * 8 = 4 s/g entry or 16k
@@ -4613,8 +4633,9 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
4613 memset(h->reply_pool, 0, h->reply_pool_size); 4633 memset(h->reply_pool, 0, h->reply_pool_size);
4614 h->reply_pool_head = h->reply_pool; 4634 h->reply_pool_head = h->reply_pool;
4615 4635
4616 bft[7] = h->max_sg_entries + 4; 4636 bft[7] = SG_ENTRIES_IN_CMD + 4;
4617 calc_bucket_map(bft, ARRAY_SIZE(bft), 32, h->blockFetchTable); 4637 calc_bucket_map(bft, ARRAY_SIZE(bft),
4638 SG_ENTRIES_IN_CMD, h->blockFetchTable);
4618 for (i = 0; i < 8; i++) 4639 for (i = 0; i < 8; i++)
4619 writel(bft[i], &h->transtable->BlockFetch[i]); 4640 writel(bft[i], &h->transtable->BlockFetch[i]);
4620 4641
@@ -4652,14 +4673,13 @@ static __devinit void hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h)
4652 return; 4673 return;
4653 4674
4654 hpsa_get_max_perf_mode_cmds(h); 4675 hpsa_get_max_perf_mode_cmds(h);
4655 h->max_sg_entries = 32;
4656 /* Performant mode ring buffer and supporting data structures */ 4676 /* Performant mode ring buffer and supporting data structures */
4657 h->reply_pool_size = h->max_commands * sizeof(u64); 4677 h->reply_pool_size = h->max_commands * sizeof(u64);
4658 h->reply_pool = pci_alloc_consistent(h->pdev, h->reply_pool_size, 4678 h->reply_pool = pci_alloc_consistent(h->pdev, h->reply_pool_size,
4659 &(h->reply_pool_dhandle)); 4679 &(h->reply_pool_dhandle));
4660 4680
4661 /* Need a block fetch table for performant mode */ 4681 /* Need a block fetch table for performant mode */
4662 h->blockFetchTable = kmalloc(((h->max_sg_entries+1) * 4682 h->blockFetchTable = kmalloc(((SG_ENTRIES_IN_CMD + 1) *
4663 sizeof(u32)), GFP_KERNEL); 4683 sizeof(u32)), GFP_KERNEL);
4664 4684
4665 if ((h->reply_pool == NULL) 4685 if ((h->reply_pool == NULL)