Lines Matching refs:h
21 #include <linux/module.h>
22 #include <linux/interrupt.h>
23 #include <linux/types.h>
24 #include <linux/pci.h>
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/delay.h>
28 #include <linux/fs.h>
29 #include <linux/timer.h>
30 #include <linux/init.h>
31 #include <linux/spinlock.h>
32 #include <linux/compat.h>
33 #include <linux/blktrace_api.h>
34 #include <linux/uaccess.h>
35 #include <linux/io.h>
36 #include <linux/dma-mapping.h>
37 #include <linux/completion.h>
38 #include <linux/moduleparam.h>
39 #include <scsi/scsi.h>
40 #include <scsi/scsi_cmnd.h>
41 #include <scsi/scsi_device.h>
42 #include <scsi/scsi_host.h>
43 #include <scsi/scsi_tcq.h>
44 #include <scsi/scsi_eh.h>
45 #include <scsi/scsi_transport_sas.h>
46 #include <scsi/scsi_dbg.h>
47 #include <linux/cciss_ioctl.h>
48 #include <linux/string.h>
49 #include <linux/bitmap.h>
50 #include <linux/atomic.h>
51 #include <linux/jiffies.h>
52 #include <linux/percpu-defs.h>
53 #include <linux/percpu.h>
54 #include <linux/unaligned.h>
55 #include <asm/div64.h>
56 #include "hpsa_cmd.h"
57 #include "hpsa.h"
79 /* Embedded module documentation macros - see modules.h */
238 static int hpsa_add_sas_host(struct ctlr_info *h);
239 static void hpsa_delete_sas_host(struct ctlr_info *h);
244 *hpsa_find_device_by_sas_rphy(struct ctlr_info *h,
257 static int hpsa_passthru_ioctl(struct ctlr_info *h,
259 static int hpsa_big_passthru_ioctl(struct ctlr_info *h,
267 static void cmd_free(struct ctlr_info *h, struct CommandList *c);
268 static struct CommandList *cmd_alloc(struct ctlr_info *h);
269 static void cmd_tagged_free(struct ctlr_info *h, struct CommandList *c);
270 static struct CommandList *cmd_tagged_alloc(struct ctlr_info *h,
272 static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
275 static void hpsa_free_cmd_pool(struct ctlr_info *h);
279 static int hpsa_scsi_queue_command(struct Scsi_Host *h, struct scsi_cmnd *cmd);
291 static void hpsa_update_scsi_devices(struct ctlr_info *h);
292 static int check_for_unit_attention(struct ctlr_info *h,
294 static void check_ioctl_unit_attention(struct ctlr_info *h,
299 static void hpsa_free_performant_mode(struct ctlr_info *h);
300 static int hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h);
301 static inline u32 next_command(struct ctlr_info *h, u8 q);
309 static int wait_for_device_to_become_ready(struct ctlr_info *h,
315 static int hpsa_wait_for_mode_change_ack(struct ctlr_info *h);
318 static void hpsa_drain_accel_commands(struct ctlr_info *h);
319 static void hpsa_flush_cache(struct ctlr_info *h);
320 static int hpsa_scsi_ioaccel_queue_command(struct ctlr_info *h,
324 static u32 lockup_detected(struct ctlr_info *h);
325 static int detect_controller_lockup(struct ctlr_info *h);
326 static void hpsa_disable_rld_caching(struct ctlr_info *h);
327 static inline int hpsa_scsi_do_report_phys_luns(struct ctlr_info *h,
329 static bool hpsa_vpd_page_supported(struct ctlr_info *h,
331 static int hpsa_luns_changed(struct ctlr_info *h);
332 static bool hpsa_cmd_dev_match(struct ctlr_info *h, struct CommandList *c,
375 static int check_for_unit_attention(struct ctlr_info *h,
393 dev_warn(&h->pdev->dev,
395 h->devname);
398 dev_warn(&h->pdev->dev,
399 "%s: LUN failure detected\n", h->devname);
402 dev_warn(&h->pdev->dev,
403 "%s: report LUN data changed\n", h->devname);
410 dev_warn(&h->pdev->dev,
412 h->devname);
415 dev_warn(&h->pdev->dev,
417 h->devname);
420 dev_warn(&h->pdev->dev,
422 h->devname);
428 static int check_for_busy(struct ctlr_info *h, struct CommandList *c)
434 dev_warn(&h->pdev->dev, HPSA "device busy");
438 static u32 lockup_detected(struct ctlr_info *h);
443 struct ctlr_info *h;
446 h = shost_to_hba(shost);
447 ld = lockup_detected(h);
457 struct ctlr_info *h;
464 h = shost_to_hba(shost);
465 h->acciopath_status = !!status;
466 dev_warn(&h->pdev->dev,
468 h->acciopath_status ? "enabled" : "disabled");
477 struct ctlr_info *h;
486 h = shost_to_hba(shost);
487 h->raid_offload_debug = debug_level;
488 dev_warn(&h->pdev->dev, "hpsa: Set raid_offload_debug level = %d\n",
489 h->raid_offload_debug);
497 struct ctlr_info *h;
499 h = shost_to_hba(shost);
500 hpsa_scan_start(h->scsi_host);
513 struct ctlr_info *h;
517 h = shost_to_hba(shost);
518 if (!h->hba_inquiry_data)
520 fwrev = &h->hba_inquiry_data[32];
529 struct ctlr_info *h = shost_to_hba(shost);
532 atomic_read(&h->commands_outstanding));
538 struct ctlr_info *h;
541 h = shost_to_hba(shost);
543 h->transMethod & CFGTBL_Trans_Performant ?
550 struct ctlr_info *h;
553 h = shost_to_hba(shost);
555 (h->acciopath_status == 1) ? "enabled" : "disabled");
634 struct ctlr_info *h;
637 h = shost_to_hba(shost);
638 return snprintf(buf, 20, "%d\n", ctlr_is_resettable(h->board_id));
669 struct ctlr_info *h;
675 h = sdev_to_hba(sdev);
676 spin_lock_irqsave(&h->lock, flags);
679 spin_unlock_irqrestore(&h->lock, flags);
685 spin_unlock_irqrestore(&h->lock, flags);
691 spin_unlock_irqrestore(&h->lock, flags);
701 struct ctlr_info *h;
708 h = sdev_to_hba(sdev);
709 spin_lock_irqsave(&h->lock, flags);
712 spin_unlock_irqrestore(&h->lock, flags);
716 spin_unlock_irqrestore(&h->lock, flags);
723 struct ctlr_info *h;
730 h = sdev_to_hba(sdev);
731 spin_lock_irqsave(&h->lock, flags);
734 spin_unlock_irqrestore(&h->lock, flags);
738 spin_unlock_irqrestore(&h->lock, flags);
751 struct ctlr_info *h;
758 h = sdev_to_hba(sdev);
759 spin_lock_irqsave(&h->lock, flags);
762 spin_unlock_irqrestore(&h->lock, flags);
766 spin_unlock_irqrestore(&h->lock, flags);
774 struct ctlr_info *h;
781 h = sdev_to_hba(sdev);
782 spin_lock_irqsave(&h->lock, flags);
785 spin_unlock_irqrestore(&h->lock, flags);
789 spin_unlock_irqrestore(&h->lock, flags);
802 struct ctlr_info *h;
815 h = sdev_to_hba(sdev);
816 spin_lock_irqsave(&h->devlock, flags);
819 spin_unlock_irqrestore(&h->devlock, flags);
836 h->scsi_host->host_no,
880 spin_unlock_irqrestore(&h->devlock, flags);
887 struct ctlr_info *h;
890 h = shost_to_hba(shost);
891 return snprintf(buf, 20, "%d\n", h->ctlr);
897 struct ctlr_info *h;
900 h = shost_to_hba(shost);
901 return snprintf(buf, 20, "%d\n", h->legacy_board ? 1 : 0);
986 static inline u32 next_command(struct ctlr_info *h, u8 q)
989 struct reply_queue_buffer *rq = &h->reply_queue[q];
991 if (h->transMethod & CFGTBL_Trans_io_accel1)
992 return h->access.command_completed(h, q);
994 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
995 return h->access.command_completed(h, q);
1000 atomic_dec(&h->commands_outstanding);
1005 if (rq->current_entry == h->max_commands) {
1044 static void set_performant_mode(struct ctlr_info *h, struct CommandList *c,
1047 if (likely(h->transMethod & CFGTBL_Trans_Performant)) {
1048 c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1);
1049 if (unlikely(!h->msix_vectors))
1055 static void set_ioaccel1_performant_mode(struct ctlr_info *h,
1059 struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[c->cmdindex];
1072 c->busaddr |= 1 | (h->ioaccel1_blockFetchTable[c->Header.SGList] << 1) |
1076 static void set_ioaccel2_tmf_performant_mode(struct ctlr_info *h,
1081 &h->ioaccel2_cmd_pool[c->cmdindex];
1092 c->busaddr |= h->ioaccel2_blockFetchTable[0];
1095 static void set_ioaccel2_performant_mode(struct ctlr_info *h,
1099 struct io_accel2_cmd *cp = &h->ioaccel2_cmd_pool[c->cmdindex];
1112 c->busaddr |= (h->ioaccel2_blockFetchTable[cp->sg_count]);
1128 static void dial_down_lockup_detection_during_fw_flash(struct ctlr_info *h,
1133 atomic_inc(&h->firmware_flash_in_progress);
1134 h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL_DURING_FLASH;
1137 static void dial_up_lockup_detection_on_fw_flash_complete(struct ctlr_info *h,
1141 atomic_dec_and_test(&h->firmware_flash_in_progress))
1142 h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL;
1145 static void __enqueue_cmd_and_start_io(struct ctlr_info *h,
1148 dial_down_lockup_detection_during_fw_flash(h, c);
1149 atomic_inc(&h->commands_outstanding);
1156 reply_queue = h->reply_map[raw_smp_processor_id()];
1159 set_ioaccel1_performant_mode(h, c, reply_queue);
1160 writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
1163 set_ioaccel2_performant_mode(h, c, reply_queue);
1164 writel(c->busaddr, h->vaddr + IOACCEL2_INBOUND_POSTQ_32);
1167 set_ioaccel2_tmf_performant_mode(h, c, reply_queue);
1168 writel(c->busaddr, h->vaddr + IOACCEL2_INBOUND_POSTQ_32);
1171 set_performant_mode(h, c, reply_queue);
1172 h->access.submit_command(h, c);
1176 static void enqueue_cmd_and_start_io(struct ctlr_info *h, struct CommandList *c)
1178 __enqueue_cmd_and_start_io(h, c, DEFAULT_REPLY_QUEUE);
1186 static inline int is_scsi_rev_5(struct ctlr_info *h)
1188 if (!h->hba_inquiry_data)
1190 if ((h->hba_inquiry_data[2] & 0x07) == 5)
1195 static int hpsa_find_target_lun(struct ctlr_info *h,
1199 * assumes h->devlock is held
1206 for (i = 0; i < h->ndevices; i++) {
1207 if (h->dev[i]->bus == bus && h->dev[i]->target != -1)
1208 __set_bit(h->dev[i]->target, lun_taken);
1221 static void hpsa_show_dev_msg(const char *level, struct ctlr_info *h,
1227 if (h == NULL || h->pdev == NULL || h->scsi_host == NULL)
1263 dev_printk(level, &h->pdev->dev,
1265 h->scsi_host->host_no, dev->bus, dev->target, dev->lun,
1276 /* Add an entry into h->dev[] array. */
1277 static int hpsa_scsi_add_entry(struct ctlr_info *h,
1281 /* assumes h->devlock is held */
1282 int n = h->ndevices;
1288 dev_err(&h->pdev->dev, "too many devices, some will be "
1304 if (hpsa_find_target_lun(h, device->scsi3addr,
1320 sd = h->dev[i];
1333 dev_warn(&h->pdev->dev, "physical device with no LUN=0,"
1341 h->dev[n] = device;
1342 h->ndevices++;
1345 hpsa_show_dev_msg(KERN_INFO, h, device,
1353 * Update an entry in h->dev[] array.
1355 static void hpsa_scsi_update_entry(struct ctlr_info *h,
1358 /* assumes h->devlock is held */
1362 h->dev[entry]->raid_level = new_entry->raid_level;
1367 h->dev[entry]->ioaccel_handle = new_entry->ioaccel_handle;
1377 * h->dev[entry]->offload_enabled is currently 0.
1379 h->dev[entry]->raid_map = new_entry->raid_map;
1380 h->dev[entry]->ioaccel_handle = new_entry->ioaccel_handle;
1383 h->dev[entry]->ioaccel_handle = new_entry->ioaccel_handle;
1386 h->dev[entry]->hba_ioaccel_enabled = new_entry->hba_ioaccel_enabled;
1387 h->dev[entry]->offload_config = new_entry->offload_config;
1388 h->dev[entry]->offload_to_mirror = new_entry->offload_to_mirror;
1389 h->dev[entry]->queue_depth = new_entry->queue_depth;
1393 * ioaccel on until we can update h->dev[entry]->phys_disk[], but we
1396 h->dev[entry]->offload_to_be_enabled = new_entry->offload_to_be_enabled;
1402 h->dev[entry]->offload_enabled = 0;
1404 hpsa_show_dev_msg(KERN_INFO, h, h->dev[entry], "updated");
1407 /* Replace an entry from h->dev[] array. */
1408 static void hpsa_scsi_replace_entry(struct ctlr_info *h,
1413 /* assumes h->devlock is held */
1415 removed[*nremoved] = h->dev[entry];
1423 new_entry->target = h->dev[entry]->target;
1424 new_entry->lun = h->dev[entry]->lun;
1427 h->dev[entry] = new_entry;
1431 hpsa_show_dev_msg(KERN_INFO, h, new_entry, "replaced");
1434 /* Remove an entry from h->dev[] array. */
1435 static void hpsa_scsi_remove_entry(struct ctlr_info *h, int entry,
1438 /* assumes h->devlock is held */
1444 sd = h->dev[entry];
1445 removed[*nremoved] = h->dev[entry];
1448 for (i = entry; i < h->ndevices-1; i++)
1449 h->dev[i] = h->dev[i+1];
1450 h->ndevices--;
1451 hpsa_show_dev_msg(KERN_INFO, h, sd, "removed");
1464 static void fixup_botched_add(struct ctlr_info *h,
1468 * h->dev[] to match the mid layer's view.
1473 spin_lock_irqsave(&h->lock, flags);
1474 for (i = 0; i < h->ndevices; i++) {
1475 if (h->dev[i] == added) {
1476 for (j = i; j < h->ndevices-1; j++)
1477 h->dev[j] = h->dev[j+1];
1478 h->ndevices--;
1482 spin_unlock_irqrestore(&h->lock, flags);
1581 static void hpsa_monitor_offline_device(struct ctlr_info *h,
1588 spin_lock_irqsave(&h->offline_device_lock, flags);
1589 list_for_each_entry(device, &h->offline_device_list, offline_list) {
1592 spin_unlock_irqrestore(&h->offline_device_lock, flags);
1596 spin_unlock_irqrestore(&h->offline_device_lock, flags);
1604 spin_lock_irqsave(&h->offline_device_lock, flags);
1605 list_add_tail(&device->offline_list, &h->offline_device_list);
1606 spin_unlock_irqrestore(&h->offline_device_lock, flags);
1610 static void hpsa_show_volume_status(struct ctlr_info *h,
1614 dev_info(&h->pdev->dev,
1616 h->scsi_host->host_no,
1622 dev_info(&h->pdev->dev,
1624 h->scsi_host->host_no,
1628 dev_info(&h->pdev->dev,
1630 h->scsi_host->host_no,
1634 dev_info(&h->pdev->dev,
1636 h->scsi_host->host_no,
1640 dev_info(&h->pdev->dev,
1642 h->scsi_host->host_no,
1646 dev_info(&h->pdev->dev,
1648 h->scsi_host->host_no,
1652 dev_info(&h->pdev->dev,
1654 h->scsi_host->host_no,
1658 dev_info(&h->pdev->dev,
1660 h->scsi_host->host_no,
1664 dev_info(&h->pdev->dev,
1666 h->scsi_host->host_no,
1670 dev_info(&h->pdev->dev,
1672 h->scsi_host->host_no,
1676 dev_info(&h->pdev->dev,
1678 h->scsi_host->host_no,
1682 dev_info(&h->pdev->dev,
1684 h->scsi_host->host_no,
1694 static void hpsa_figure_phys_disk_ptrs(struct ctlr_info *h,
1733 qdepth = min(h->nr_cmds, qdepth +
1746 dev_warn(&h->pdev->dev,
1749 h->scsi_host->host_no, logical_drive->bus,
1765 logical_drive->queue_depth = h->nr_cmds;
1769 static void hpsa_update_log_drive_phys_drive_ptrs(struct ctlr_info *h,
1803 hpsa_figure_phys_disk_ptrs(h, dev, ndevices, dev[i]);
1807 static int hpsa_add_device(struct ctlr_info *h, struct hpsa_scsi_dev_t *device)
1811 if (!h->scsi_host)
1815 rc = scsi_add_device(h->scsi_host, device->bus,
1818 rc = hpsa_add_sas_device(h->sas_host, device);
1823 static int hpsa_find_outstanding_commands_for_dev(struct ctlr_info *h,
1829 for (i = 0; i < h->nr_cmds; i++) {
1830 struct CommandList *c = h->cmd_pool + i;
1833 if (refcount > 1 && hpsa_cmd_dev_match(h, c, dev,
1837 spin_lock_irqsave(&h->lock, flags); /* Implied MB */
1840 spin_unlock_irqrestore(&h->lock, flags);
1843 cmd_free(h, c);
1850 static void hpsa_wait_for_outstanding_commands_for_dev(struct ctlr_info *h,
1861 cmds = hpsa_find_outstanding_commands_for_dev(h, device);
1870 dev_warn(&h->pdev->dev,
1873 h->scsi_host->host_no,
1878 static void hpsa_remove_device(struct ctlr_info *h,
1883 if (!h->scsi_host)
1890 hpsa_wait_for_outstanding_commands_for_dev(h, device);
1893 sdev = scsi_device_lookup(h->scsi_host, device->bus,
1904 hpsa_show_dev_msg(KERN_WARNING, h, device,
1913 static void adjust_hpsa_scsi_table(struct ctlr_info *h,
1918 * reality and updates h->dev[] to reflect that reality.
1930 spin_lock_irqsave(&h->reset_lock, flags);
1931 if (h->reset_in_progress) {
1932 h->drv_req_rescan = 1;
1933 spin_unlock_irqrestore(&h->reset_lock, flags);
1936 spin_unlock_irqrestore(&h->reset_lock, flags);
1942 dev_warn(&h->pdev->dev, "out of memory in "
1947 spin_lock_irqsave(&h->devlock, flags);
1949 /* find any devices in h->dev[] that are not in
1950 * sd[] and remove them from h->dev[], and for any
1959 while (i < h->ndevices) {
1960 csd = h->dev[i];
1964 hpsa_scsi_remove_entry(h, i, removed, &nremoved);
1968 hpsa_scsi_replace_entry(h, i, sd[entry],
1975 hpsa_scsi_update_entry(h, i, sd[entry]);
1981 * listed in h->dev[], adding them if they aren't found
1994 hpsa_show_volume_status(h, sd[i]);
1995 hpsa_show_dev_msg(KERN_INFO, h, sd[i], "offline");
1999 device_change = hpsa_scsi_find_entry(sd[i], h->dev,
2000 h->ndevices, &entry);
2003 if (hpsa_scsi_add_entry(h, sd[i], added, &nadded) != 0)
2009 dev_warn(&h->pdev->dev,
2014 hpsa_update_log_drive_phys_drive_ptrs(h, h->dev, h->ndevices);
2017 * Now that h->dev[]->phys_disk[] is coherent, we can enable
2024 for (i = 0; i < h->ndevices; i++) {
2025 if (h->dev[i] == NULL)
2027 h->dev[i]->offload_enabled = h->dev[i]->offload_to_be_enabled;
2030 spin_unlock_irqrestore(&h->devlock, flags);
2033 * brought online later. This must be done without holding h->devlock,
2034 * so don't touch h->dev[]
2040 hpsa_monitor_offline_device(h, sd[i]->scsi3addr);
2055 hpsa_remove_device(h, removed[i]);
2068 rc = hpsa_add_device(h, added[i]);
2071 dev_warn(&h->pdev->dev,
2073 /* now we have to remove it from h->dev,
2076 fixup_botched_add(h, added[i]);
2077 h->drv_req_rescan = 1;
2087 * Assume's h->devlock is held.
2089 static struct hpsa_scsi_dev_t *lookup_hpsa_scsi_dev(struct ctlr_info *h,
2095 for (i = 0; i < h->ndevices; i++) {
2096 sd = h->dev[i];
2107 struct ctlr_info *h;
2109 h = sdev_to_hba(sdev);
2110 spin_lock_irqsave(&h->devlock, flags);
2117 sd = hpsa_find_device_by_sas_rphy(h, rphy);
2124 sd = lookup_hpsa_scsi_dev(h, sdev_channel(sdev),
2132 spin_unlock_irqrestore(&h->devlock, flags);
2180 static void hpsa_free_ioaccel2_sg_chain_blocks(struct ctlr_info *h)
2184 if (!h->ioaccel2_cmd_sg_list)
2186 for (i = 0; i < h->nr_cmds; i++) {
2187 kfree(h->ioaccel2_cmd_sg_list[i]);
2188 h->ioaccel2_cmd_sg_list[i] = NULL;
2190 kfree(h->ioaccel2_cmd_sg_list);
2191 h->ioaccel2_cmd_sg_list = NULL;
2194 static int hpsa_allocate_ioaccel2_sg_chain_blocks(struct ctlr_info *h)
2198 if (h->chainsize <= 0)
2201 h->ioaccel2_cmd_sg_list =
2202 kcalloc(h->nr_cmds, sizeof(*h->ioaccel2_cmd_sg_list),
2204 if (!h->ioaccel2_cmd_sg_list)
2206 for (i = 0; i < h->nr_cmds; i++) {
2207 h->ioaccel2_cmd_sg_list[i] =
2208 kmalloc_array(h->maxsgentries,
2209 sizeof(*h->ioaccel2_cmd_sg_list[i]),
2211 if (!h->ioaccel2_cmd_sg_list[i])
2217 hpsa_free_ioaccel2_sg_chain_blocks(h);
2221 static void hpsa_free_sg_chain_blocks(struct ctlr_info *h)
2225 if (!h->cmd_sg_list)
2227 for (i = 0; i < h->nr_cmds; i++) {
2228 kfree(h->cmd_sg_list[i]);
2229 h->cmd_sg_list[i] = NULL;
2231 kfree(h->cmd_sg_list);
2232 h->cmd_sg_list = NULL;
2235 static int hpsa_alloc_sg_chain_blocks(struct ctlr_info *h)
2239 if (h->chainsize <= 0)
2242 h->cmd_sg_list = kcalloc(h->nr_cmds, sizeof(*h->cmd_sg_list),
2244 if (!h->cmd_sg_list)
2247 for (i = 0; i < h->nr_cmds; i++) {
2248 h->cmd_sg_list[i] = kmalloc_array(h->chainsize,
2249 sizeof(*h->cmd_sg_list[i]),
2251 if (!h->cmd_sg_list[i])
2258 hpsa_free_sg_chain_blocks(h);
2262 static int hpsa_map_ioaccel2_sg_chain_block(struct ctlr_info *h,
2269 chain_block = h->ioaccel2_cmd_sg_list[c->cmdindex];
2271 temp64 = dma_map_single(&h->pdev->dev, chain_block, chain_size,
2273 if (dma_mapping_error(&h->pdev->dev, temp64)) {
2282 static void hpsa_unmap_ioaccel2_sg_chain_block(struct ctlr_info *h,
2292 dma_unmap_single(&h->pdev->dev, temp64, chain_size, DMA_TO_DEVICE);
2295 static int hpsa_map_sg_chain_block(struct ctlr_info *h,
2302 chain_sg = &c->SG[h->max_cmd_sg_entries - 1];
2303 chain_block = h->cmd_sg_list[c->cmdindex];
2306 (le16_to_cpu(c->Header.SGTotal) - h->max_cmd_sg_entries);
2308 temp64 = dma_map_single(&h->pdev->dev, chain_block, chain_len,
2310 if (dma_mapping_error(&h->pdev->dev, temp64)) {
2319 static void hpsa_unmap_sg_chain_block(struct ctlr_info *h,
2324 if (le16_to_cpu(c->Header.SGTotal) <= h->max_cmd_sg_entries)
2327 chain_sg = &c->SG[h->max_cmd_sg_entries - 1];
2328 dma_unmap_single(&h->pdev->dev, le64_to_cpu(chain_sg->Addr),
2337 static int handle_ioaccel_mode2_error(struct ctlr_info *h,
2417 h->drv_req_rescan = 1;
2418 dev_warn(&h->pdev->dev,
2452 static void hpsa_cmd_resolve_events(struct ctlr_info *h,
2468 wake_up_all(&h->event_sync_wait_queue);
2472 static void hpsa_cmd_resolve_and_free(struct ctlr_info *h,
2475 hpsa_cmd_resolve_events(h, c);
2476 cmd_tagged_free(h, c);
2479 static void hpsa_cmd_free_and_done(struct ctlr_info *h,
2482 hpsa_cmd_resolve_and_free(h, c);
2487 static void hpsa_retry_cmd(struct ctlr_info *h, struct CommandList *c)
2490 queue_work_on(raw_smp_processor_id(), h->resubmit_wq, &c->work);
2493 static void process_ioaccel2_completion(struct ctlr_info *h,
2497 struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex];
2503 return hpsa_cmd_free_and_done(h, c, cmd);
2521 return hpsa_cmd_free_and_done(h, c, cmd);
2524 return hpsa_retry_cmd(h, c);
2527 if (handle_ioaccel_mode2_error(h, c, cmd, c2, dev))
2528 return hpsa_retry_cmd(h, c);
2530 return hpsa_cmd_free_and_done(h, c, cmd);
2534 static int hpsa_evaluate_tmf_status(struct ctlr_info *h,
2554 dev_warn(&h->pdev->dev, "Unknown TMF status: 0x%02x\n",
2564 struct ctlr_info *h;
2576 h = cp->h;
2580 return hpsa_cmd_free_and_done(h, cp, cmd);
2586 return hpsa_cmd_free_and_done(h, cp, cmd);
2588 c2 = &h->ioaccel2_cmd_pool[cp->cmdindex];
2592 (le16_to_cpu(cp->Header.SGTotal) > h->max_cmd_sg_entries))
2593 hpsa_unmap_sg_chain_block(h, cp);
2597 hpsa_unmap_ioaccel2_sg_chain_block(h, c2);
2603 hpsa_cmd_resolve_and_free(h, cp);
2611 return hpsa_cmd_free_and_done(h, cp, cmd);
2625 return hpsa_cmd_free_and_done(h, cp, cmd);
2629 return process_ioaccel2_completion(h, cp, cmd, dev);
2633 return hpsa_cmd_free_and_done(h, cp, cmd);
2639 struct io_accel1_cmd *c = &h->ioaccel_cmd_pool[cp->cmdindex];
2655 return hpsa_retry_cmd(h, cp);
2682 h->drv_req_rescan = 1;
2697 dev_warn(&h->pdev->dev, "cp %p has status 0x%x "
2704 dev_warn(&h->pdev->dev, "cp %p SCSI status was 0. "
2726 dev_warn(&h->pdev->dev,
2743 dev_warn(&h->pdev->dev, "CDB %16phN : protocol error\n",
2748 dev_warn(&h->pdev->dev, "CDB %16phN : hardware error\n",
2753 dev_warn(&h->pdev->dev, "CDB %16phN : connection lost\n",
2761 dev_warn(&h->pdev->dev, "CDB %16phN : abort failed\n",
2766 dev_warn(&h->pdev->dev, "CDB %16phN : unsolicited abort\n",
2771 dev_warn(&h->pdev->dev, "CDB %16phN timed out\n",
2776 dev_warn(&h->pdev->dev, "Command unabortable\n");
2779 if (hpsa_evaluate_tmf_status(h, cp)) /* TMF failed? */
2787 dev_warn(&h->pdev->dev,
2792 dev_warn(&h->pdev->dev, "cp %p returned unknown status %x\n",
2796 return hpsa_cmd_free_and_done(h, cp, cmd);
2841 static int hpsa_scsi_do_simple_cmd_core(struct ctlr_info *h,
2847 __enqueue_cmd_and_start_io(h, c, reply_queue);
2855 dev_warn(&h->pdev->dev, "Command timed out.\n");
2861 static int hpsa_scsi_do_simple_cmd(struct ctlr_info *h, struct CommandList *c,
2864 if (unlikely(lockup_detected(h))) {
2868 return hpsa_scsi_do_simple_cmd_core(h, c, reply_queue, timeout_msecs);
2871 static u32 lockup_detected(struct ctlr_info *h)
2877 lockup_detected = per_cpu_ptr(h->lockup_detected, cpu);
2884 static int hpsa_scsi_do_simple_cmd_with_retry(struct ctlr_info *h,
2893 rc = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE,
2903 } while ((check_for_unit_attention(h, c) ||
2904 check_for_busy(h, c)) &&
2906 hpsa_pci_unmap(h->pdev, c, 1, data_direction);
2912 static void hpsa_print_cmd(struct ctlr_info *h, char *txt,
2918 dev_warn(&h->pdev->dev, "%s: LUN:%8phN CDB:%16phN\n",
2922 static void hpsa_scsi_interpret_error(struct ctlr_info *h,
2926 struct device *d = &cp->h->pdev->dev;
2938 hpsa_print_cmd(h, "SCSI status", cp);
2953 hpsa_print_cmd(h, "overrun condition", cp);
2959 hpsa_print_cmd(h, "invalid command", cp);
2964 hpsa_print_cmd(h, "protocol error", cp);
2967 hpsa_print_cmd(h, "hardware error", cp);
2970 hpsa_print_cmd(h, "connection lost", cp);
2973 hpsa_print_cmd(h, "aborted", cp);
2976 hpsa_print_cmd(h, "abort failed", cp);
2979 hpsa_print_cmd(h, "unsolicited abort", cp);
2982 hpsa_print_cmd(h, "timed out", cp);
2985 hpsa_print_cmd(h, "unabortable", cp);
2988 hpsa_print_cmd(h, "controller lockup detected", cp);
2991 hpsa_print_cmd(h, "unknown status", cp);
2997 static int hpsa_do_receive_diagnostic(struct ctlr_info *h, u8 *scsi3addr,
3004 c = cmd_alloc(h);
3005 if (fill_cmd(c, RECEIVE_DIAGNOSTIC, h, buf, bufsize,
3010 rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3016 hpsa_scsi_interpret_error(h, c);
3020 cmd_free(h, c);
3024 static u64 hpsa_get_enclosure_logical_identifier(struct ctlr_info *h,
3035 rc = hpsa_do_receive_diagnostic(h, scsi3addr, RECEIVE_DIAGNOSTIC,
3048 static int hpsa_scsi_do_inquiry(struct ctlr_info *h, unsigned char *scsi3addr,
3056 c = cmd_alloc(h);
3058 if (fill_cmd(c, HPSA_INQUIRY, h, buf, bufsize,
3063 rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3069 hpsa_scsi_interpret_error(h, c);
3073 cmd_free(h, c);
3077 static int hpsa_send_reset(struct ctlr_info *h, struct hpsa_scsi_dev_t *dev,
3084 c = cmd_alloc(h);
3088 (void) fill_cmd(c, reset_type, h, NULL, 0, 0, dev->scsi3addr, TYPE_MSG);
3089 rc = hpsa_scsi_do_simple_cmd(h, c, reply_queue, NO_TIMEOUT);
3091 dev_warn(&h->pdev->dev, "Failed to send reset command\n");
3098 hpsa_scsi_interpret_error(h, c);
3102 cmd_free(h, c);
3106 static bool hpsa_cmd_dev_match(struct ctlr_info *h, struct CommandList *c,
3112 struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex];
3157 dev_err(&h->pdev->dev, "unexpected cmd_type: %d\n",
3165 static int hpsa_do_reset(struct ctlr_info *h, struct hpsa_scsi_dev_t *dev,
3171 if (mutex_lock_interruptible(&h->reset_mutex) == -EINTR) {
3172 dev_warn(&h->pdev->dev, "concurrent reset wait interrupted.\n");
3176 rc = hpsa_send_reset(h, dev, reset_type, reply_queue);
3180 wait_event(h->event_sync_wait_queue,
3182 lockup_detected(h));
3185 if (unlikely(lockup_detected(h))) {
3186 dev_warn(&h->pdev->dev,
3192 rc = wait_for_device_to_become_ready(h, dev->scsi3addr, 0);
3194 mutex_unlock(&h->reset_mutex);
3198 static void hpsa_get_raid_level(struct ctlr_info *h,
3209 if (!hpsa_vpd_page_supported(h, scsi3addr,
3213 rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE |
3227 static void hpsa_debug_map_buff(struct ctlr_info *h, int rc,
3238 if (h->raid_offload_debug < 2)
3241 dev_info(&h->pdev->dev, "structure_size = %u\n",
3243 dev_info(&h->pdev->dev, "volume_blk_size = %u\n",
3245 dev_info(&h->pdev->dev, "volume_blk_cnt = 0x%llx\n",
3247 dev_info(&h->pdev->dev, "physicalBlockShift = %u\n",
3249 dev_info(&h->pdev->dev, "parity_rotation_shift = %u\n",
3251 dev_info(&h->pdev->dev, "strip_size = %u\n",
3253 dev_info(&h->pdev->dev, "disk_starting_blk = 0x%llx\n",
3255 dev_info(&h->pdev->dev, "disk_blk_cnt = 0x%llx\n",
3257 dev_info(&h->pdev->dev, "data_disks_per_row = %u\n",
3259 dev_info(&h->pdev->dev, "metadata_disks_per_row = %u\n",
3261 dev_info(&h->pdev->dev, "row_cnt = %u\n",
3263 dev_info(&h->pdev->dev, "layout_map_count = %u\n",
3265 dev_info(&h->pdev->dev, "flags = 0x%x\n",
3267 dev_info(&h->pdev->dev, "encryption = %s\n",
3270 dev_info(&h->pdev->dev, "dekindex = %u\n",
3274 dev_info(&h->pdev->dev, "Map%u:\n", map);
3277 dev_info(&h->pdev->dev, " Row%u:\n", row);
3281 dev_info(&h->pdev->dev,
3282 " D%02u: h=0x%04x xor=%u,%u\n",
3288 dev_info(&h->pdev->dev,
3289 " M%02u: h=0x%04x xor=%u,%u\n",
3296 static void hpsa_debug_map_buff(__attribute__((unused)) struct ctlr_info *h,
3303 static int hpsa_get_raid_map(struct ctlr_info *h,
3310 c = cmd_alloc(h);
3312 if (fill_cmd(c, HPSA_GET_RAID_MAP, h, &this_device->raid_map,
3315 dev_warn(&h->pdev->dev, "hpsa_get_raid_map fill_cmd failed\n");
3316 cmd_free(h, c);
3319 rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3325 hpsa_scsi_interpret_error(h, c);
3329 cmd_free(h, c);
3334 dev_warn(&h->pdev->dev, "RAID map size is too large!\n");
3337 hpsa_debug_map_buff(h, rc, &this_device->raid_map);
3340 cmd_free(h, c);
3344 static int hpsa_bmic_sense_subsystem_information(struct ctlr_info *h,
3352 c = cmd_alloc(h);
3354 rc = fill_cmd(c, BMIC_SENSE_SUBSYSTEM_INFORMATION, h, buf, bufsize,
3362 rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3368 hpsa_scsi_interpret_error(h, c);
3372 cmd_free(h, c);
3376 static int hpsa_bmic_id_controller(struct ctlr_info *h,
3383 c = cmd_alloc(h);
3385 rc = fill_cmd(c, BMIC_IDENTIFY_CONTROLLER, h, buf, bufsize,
3390 rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3396 hpsa_scsi_interpret_error(h, c);
3400 cmd_free(h, c);
3404 static int hpsa_bmic_id_physical_device(struct ctlr_info *h,
3412 c = cmd_alloc(h);
3413 rc = fill_cmd(c, BMIC_IDENTIFY_PHYSICAL_DEVICE, h, buf, bufsize,
3421 hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3425 hpsa_scsi_interpret_error(h, c);
3429 cmd_free(h, c);
3440 static void hpsa_get_enclosure_info(struct ctlr_info *h,
3459 hpsa_get_enclosure_logical_identifier(h, scsi3addr);
3481 rc = hpsa_bmic_id_physical_device(h, scsi3addr, bmic_device_index,
3484 dev_warn(&h->pdev->dev, "%s: id_phys failed %d bdi[0x%x]\n",
3489 c = cmd_alloc(h);
3491 rc = fill_cmd(c, BMIC_SENSE_STORAGE_BOX_PARAMS, h, bssbp,
3502 rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3523 cmd_free(h, c);
3526 hpsa_show_dev_msg(KERN_INFO, h, encl_dev,
3530 static u64 hpsa_get_sas_address_from_report_physical(struct ctlr_info *h,
3542 if (hpsa_scsi_do_report_phys_luns(h, physdev, sizeof(*physdev))) {
3543 dev_err(&h->pdev->dev, "report physical LUNs failed.\n");
3560 static void hpsa_get_sas_address(struct ctlr_info *h, unsigned char *scsi3addr,
3573 rc = hpsa_bmic_sense_subsystem_information(h,
3577 h->sas_address = sa;
3582 sa = hpsa_get_sas_address_from_report_physical(h, scsi3addr);
3587 static void hpsa_ext_ctrl_present(struct ctlr_info *h,
3593 if (h->discovery_polling)
3602 dev_info(&h->pdev->dev,
3604 hpsa_disable_rld_caching(h);
3605 h->discovery_polling = 1;
3612 static bool hpsa_vpd_page_supported(struct ctlr_info *h,
3625 rc = hpsa_scsi_do_inquiry(h, scsi3addr,
3637 rc = hpsa_scsi_do_inquiry(h, scsi3addr,
3662 static void hpsa_get_ioaccel_status(struct ctlr_info *h,
3676 if (!hpsa_vpd_page_supported(h, scsi3addr, HPSA_VPD_LV_IOACCEL_STATUS))
3678 rc = hpsa_scsi_do_inquiry(h, scsi3addr,
3696 rc = hpsa_get_raid_map(h, scsi3addr, this_device);
3709 static int hpsa_get_device_id(struct ctlr_info *h, unsigned char *scsi3addr,
3716 if (!hpsa_vpd_page_supported(h, scsi3addr, HPSA_VPD_LV_DEVICE_ID))
3723 rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE |
3736 static int hpsa_scsi_do_report_luns(struct ctlr_info *h, int logical,
3745 c = cmd_alloc(h);
3749 if (fill_cmd(c, logical ? HPSA_REPORT_LOG : HPSA_REPORT_PHYS, h,
3756 rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
3763 hpsa_scsi_interpret_error(h, c);
3769 if (!h->legacy_board) {
3770 dev_err(&h->pdev->dev,
3780 cmd_free(h, c);
3784 static inline int hpsa_scsi_do_report_phys_luns(struct ctlr_info *h,
3790 rc = hpsa_scsi_do_report_luns(h, 0, buf, bufsize,
3800 rc = hpsa_scsi_do_report_luns(h, 0, lbuf, sizeof(*lbuf), 0);
3815 static inline int hpsa_scsi_do_report_log_luns(struct ctlr_info *h,
3818 return hpsa_scsi_do_report_luns(h, 1, buf, bufsize, 0);
3830 static int hpsa_get_volume_status(struct ctlr_info *h,
3843 if (!hpsa_vpd_page_supported(h, scsi3addr, HPSA_VPD_LV_STATUS))
3847 rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE | HPSA_VPD_LV_STATUS,
3854 rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE | HPSA_VPD_LV_STATUS,
3874 static unsigned char hpsa_volume_offline(struct ctlr_info *h,
3886 c = cmd_alloc(h);
3888 (void) fill_cmd(c, TEST_UNIT_READY, h, NULL, 0, 0, scsi3addr, TYPE_CMD);
3889 rc = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE,
3892 cmd_free(h, c);
3901 cmd_free(h, c);
3904 ldstat = hpsa_get_volume_status(h, scsi3addr);
3933 static int hpsa_update_device_info(struct ctlr_info *h,
3954 if (hpsa_scsi_do_inquiry(h, scsi3addr, 0, inq_buff,
3956 dev_err(&h->pdev->dev,
3975 if (hpsa_get_device_id(h, scsi3addr, this_device->device_id, 8,
3977 dev_err(&h->pdev->dev,
3979 h->ctlr, __func__,
3980 h->scsi_host->host_no,
3994 hpsa_get_raid_level(h, scsi3addr, &this_device->raid_level);
3995 if (h->fw_support & MISC_FW_RAID_OFFLOAD_BASIC)
3996 hpsa_get_ioaccel_status(h, scsi3addr, this_device);
3997 volume_offline = hpsa_volume_offline(h, scsi3addr);
3999 h->legacy_board) {
4003 dev_info(&h->pdev->dev,
4011 dev_err(&h->pdev->dev,
4022 this_device->queue_depth = h->nr_cmds;
4051 static void figure_bus_target_lun(struct ctlr_info *h,
4082 static int figure_external_status(struct ctlr_info *h, int raid_ctlr_position,
4109 static int hpsa_gather_lun_info(struct ctlr_info *h,
4113 if (hpsa_scsi_do_report_phys_luns(h, physdev, sizeof(*physdev))) {
4114 dev_err(&h->pdev->dev, "report physical LUNs failed.\n");
4119 dev_warn(&h->pdev->dev, "maximum physical LUNs (%d) exceeded. %d LUNs ignored.\n",
4123 if (hpsa_scsi_do_report_log_luns(h, logdev, sizeof(*logdev))) {
4124 dev_err(&h->pdev->dev, "report logical LUNs failed.\n");
4130 dev_warn(&h->pdev->dev,
4137 dev_warn(&h->pdev->dev,
4146 static u8 *figure_lunaddrbytes(struct ctlr_info *h, int raid_ctlr_position,
4174 static void hpsa_get_ioaccel_drive_info(struct ctlr_info *h,
4191 rc = hpsa_bmic_id_physical_device(h, &rle->lunid[0],
4237 static int hpsa_set_local_logical_count(struct ctlr_info *h,
4244 dev_warn(&h->pdev->dev, "%s: id_ctlr buffer is NULL.\n",
4249 rc = hpsa_bmic_id_controller(h, id_ctlr, sizeof(*id_ctlr));
4261 static bool hpsa_is_disk_spare(struct ctlr_info *h, u8 *lunaddrbytes)
4271 rc = hpsa_bmic_id_physical_device(h,
4288 static bool hpsa_skip_device(struct ctlr_info *h, u8 *lunaddrbytes,
4320 if (hpsa_is_disk_spare(h, lunaddrbytes))
4326 static void hpsa_update_scsi_devices(struct ctlr_info *h)
4361 dev_err(&h->pdev->dev, "out of memory\n");
4365 h->drv_req_rescan = 0; /* cancel scheduled rescan - we're doing it. */
4367 if (hpsa_gather_lun_info(h, physdev_list, &nphysicals,
4369 h->drv_req_rescan = 1;
4374 if (hpsa_set_local_logical_count(h, id_ctlr, &nlocal_logicals)) {
4375 dev_warn(&h->pdev->dev,
4386 hpsa_ext_ctrl_present(h, physdev_list);
4391 dev_warn(&h->pdev->dev, "maximum devices (%d) exceeded."
4399 h->drv_req_rescan = 1;
4405 if (is_scsi_rev_5(h))
4422 lunaddrbytes = figure_lunaddrbytes(h, raid_ctlr_position,
4427 figure_external_status(h, raid_ctlr_position, i,
4435 skip_device = hpsa_skip_device(h, lunaddrbytes,
4442 rc = hpsa_update_device_info(h, lunaddrbytes, tmpdevice,
4445 dev_warn(&h->pdev->dev,
4447 h->drv_req_rescan = 1;
4451 h->drv_req_rescan = 1;
4455 figure_bus_target_lun(h, lunaddrbytes, tmpdevice);
4475 hpsa_get_sas_address(h, lunaddrbytes, this_device);
4495 hpsa_get_ioaccel_drive_info(h, this_device,
4508 hpsa_get_enclosure_info(h, lunaddrbytes,
4530 if (h->sas_host == NULL) {
4533 rc = hpsa_add_sas_host(h);
4535 dev_warn(&h->pdev->dev,
4541 adjust_hpsa_scsi_table(h, currentsd, ncurrent);
4569 static int hpsa_scatter_gather(struct ctlr_info *h,
4577 BUG_ON(scsi_sg_count(cmd) > h->maxsgentries);
4594 chained = use_sg > h->max_cmd_sg_entries;
4595 sg_limit = chained ? h->max_cmd_sg_entries - 1 : use_sg;
4608 curr_sg = h->cmd_sg_list[cp->cmdindex];
4619 if (use_sg + chained > h->maxSG)
4620 h->maxSG = use_sg + chained;
4623 cp->Header.SGList = h->max_cmd_sg_entries;
4625 if (hpsa_map_sg_chain_block(h, cp)) {
4639 static inline void warn_zero_length_transfer(struct ctlr_info *h,
4643 dev_warn(&h->pdev->dev,
4725 static int hpsa_scsi_ioaccel1_queue_command(struct ctlr_info *h,
4730 struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[c->cmdindex];
4740 if (scsi_sg_count(cmd) > h->ioaccel_maxsg) {
4748 warn_zero_length_transfer(h, cdb, cdb_len, __func__);
4761 c->busaddr = (u32) h->ioaccel_cmd_pool_dhandle +
4795 dev_err(&h->pdev->dev, "unknown data direction: %d\n",
4814 enqueue_cmd_and_start_io(h, c);
4822 static int hpsa_scsi_ioaccel_direct_map(struct ctlr_info *h,
4836 return hpsa_scsi_ioaccel_queue_command(h, c, dev->ioaccel_handle,
4843 static void set_encrypt_ioaccel2(struct ctlr_info *h,
4884 dev_err(&h->pdev->dev,
4899 static int hpsa_scsi_ioaccel2_queue_command(struct ctlr_info *h,
4904 struct io_accel2_cmd *cp = &h->ioaccel2_cmd_pool[c->cmdindex];
4918 BUG_ON(scsi_sg_count(cmd) > h->maxsgentries);
4921 warn_zero_length_transfer(h, cdb, cdb_len, __func__);
4933 c->busaddr = (u32) h->ioaccel2_cmd_pool_dhandle +
4948 if (use_sg > h->ioaccel_maxsg) {
4950 h->ioaccel2_cmd_sg_list[c->cmdindex]->address);
4958 curr_sg = h->ioaccel2_cmd_sg_list[c->cmdindex];
4992 dev_err(&h->pdev->dev, "unknown data direction: %d\n",
5003 set_encrypt_ioaccel2(h, c, cp);
5015 if (use_sg > h->ioaccel_maxsg) {
5018 if (hpsa_map_ioaccel2_sg_chain_block(h, cp, c)) {
5031 enqueue_cmd_and_start_io(h, c);
5038 static int hpsa_scsi_ioaccel_queue_command(struct ctlr_info *h,
5057 if (h->transMethod & CFGTBL_Trans_io_accel1)
5058 return hpsa_scsi_ioaccel1_queue_command(h, c, ioaccel_handle,
5062 return hpsa_scsi_ioaccel2_queue_command(h, c, ioaccel_handle,
5096 static int hpsa_scsi_ioaccel_raid_map(struct ctlr_info *h,
5440 return hpsa_scsi_ioaccel_queue_command(h, c, disk_handle, cdb, cdb_len,
5450 static int hpsa_ciss_submit(struct ctlr_info *h,
5499 dev_err(&h->pdev->dev, "unknown data direction: %d\n",
5505 if (hpsa_scatter_gather(h, c, cmd) < 0) { /* Fill SG list */
5506 hpsa_cmd_resolve_and_free(h, c);
5511 hpsa_cmd_resolve_and_free(h, c);
5517 enqueue_cmd_and_start_io(h, c);
5522 static void hpsa_cmd_init(struct ctlr_info *h, int index,
5530 cmd_dma_handle = h->cmd_pool_dhandle + index * sizeof(*c);
5531 c->err_info = h->errinfo_pool + index;
5533 err_dma_handle = h->errinfo_pool_dhandle
5539 c->h = h;
5543 static void hpsa_preinitialize_commands(struct ctlr_info *h)
5547 for (i = 0; i < h->nr_cmds; i++) {
5548 struct CommandList *c = h->cmd_pool + i;
5550 hpsa_cmd_init(h, i, c);
5555 static inline void hpsa_cmd_partial_init(struct ctlr_info *h, int index,
5558 dma_addr_t cmd_dma_handle = h->cmd_pool_dhandle + index * sizeof(*c);
5567 static int hpsa_ioaccel_submit(struct ctlr_info *h,
5586 hpsa_cmd_init(h, c->cmdindex, c); /* Zeroes out all fields */
5592 rc = hpsa_scsi_ioaccel_raid_map(h, c);
5596 hpsa_cmd_init(h, c->cmdindex, c); /* Zeroes out all fields */
5602 rc = hpsa_scsi_ioaccel_direct_map(h, c);
5619 return hpsa_cmd_free_and_done(c->h, c, cmd);
5624 return hpsa_cmd_free_and_done(c->h, c, cmd);
5628 struct ctlr_info *h = c->h;
5629 struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex];
5635 rc = hpsa_ioaccel_submit(h, c, cmd, true);
5645 return hpsa_cmd_free_and_done(h, c, cmd);
5650 hpsa_cmd_partial_init(c->h, c->cmdindex, c);
5660 if (hpsa_ciss_submit(c->h, c, cmd, dev)) {
5677 struct ctlr_info *h;
5683 h = sdev_to_hba(cmd->device);
5700 if (unlikely(lockup_detected(h))) {
5709 c = cmd_tagged_alloc(h, cmd);
5729 h->acciopath_status)) {
5731 rc = hpsa_ioaccel_submit(h, c, cmd, false);
5735 hpsa_cmd_resolve_and_free(h, c);
5739 return hpsa_ciss_submit(h, c, cmd, dev);
5742 static void hpsa_scan_complete(struct ctlr_info *h)
5746 spin_lock_irqsave(&h->scan_lock, flags);
5747 h->scan_finished = 1;
5748 wake_up(&h->scan_wait_queue);
5749 spin_unlock_irqrestore(&h->scan_lock, flags);
5754 struct ctlr_info *h = shost_to_hba(sh);
5763 if (unlikely(lockup_detected(h)))
5764 return hpsa_scan_complete(h);
5769 spin_lock_irqsave(&h->scan_lock, flags);
5770 if (h->scan_waiting) {
5771 spin_unlock_irqrestore(&h->scan_lock, flags);
5775 spin_unlock_irqrestore(&h->scan_lock, flags);
5779 spin_lock_irqsave(&h->scan_lock, flags);
5780 if (h->scan_finished)
5782 h->scan_waiting = 1;
5783 spin_unlock_irqrestore(&h->scan_lock, flags);
5784 wait_event(h->scan_wait_queue, h->scan_finished);
5791 h->scan_finished = 0; /* mark scan as in progress */
5792 h->scan_waiting = 0;
5793 spin_unlock_irqrestore(&h->scan_lock, flags);
5795 if (unlikely(lockup_detected(h)))
5796 return hpsa_scan_complete(h);
5801 spin_lock_irqsave(&h->reset_lock, flags);
5802 if (h->reset_in_progress) {
5803 h->drv_req_rescan = 1;
5804 spin_unlock_irqrestore(&h->reset_lock, flags);
5805 hpsa_scan_complete(h);
5808 spin_unlock_irqrestore(&h->reset_lock, flags);
5810 hpsa_update_scsi_devices(h);
5812 hpsa_scan_complete(h);
5833 struct ctlr_info *h = shost_to_hba(sh);
5837 spin_lock_irqsave(&h->scan_lock, flags);
5838 finished = h->scan_finished;
5839 spin_unlock_irqrestore(&h->scan_lock, flags);
5843 static int hpsa_scsi_host_alloc(struct ctlr_info *h)
5849 dev_err(&h->pdev->dev, "scsi_host_alloc failed\n");
5860 sh->can_queue = h->nr_cmds - HPSA_NRESERVED_CMDS;
5862 sh->sg_tablesize = h->maxsgentries;
5864 sh->hostdata[0] = (unsigned long) h;
5865 sh->irq = pci_irq_vector(h->pdev, 0);
5868 h->scsi_host = sh;
5872 static int hpsa_scsi_add_host(struct ctlr_info *h)
5876 rv = scsi_add_host(h->scsi_host, &h->pdev->dev);
5878 dev_err(&h->pdev->dev, "scsi_add_host failed\n");
5881 scsi_scan_host(h->scsi_host);
5906 static int hpsa_send_test_unit_ready(struct ctlr_info *h,
5913 (void) fill_cmd(c, TEST_UNIT_READY, h,
5915 rc = hpsa_scsi_do_simple_cmd(h, c, reply_queue, NO_TIMEOUT);
5942 static int hpsa_wait_for_test_unit_ready(struct ctlr_info *h,
5959 rc = hpsa_send_test_unit_ready(h, c, lunaddr, reply_queue);
5967 dev_warn(&h->pdev->dev,
5975 static int wait_for_device_to_become_ready(struct ctlr_info *h,
5985 c = cmd_alloc(h);
5994 last_queue = h->nreply_queues - 1;
6001 rc = hpsa_wait_for_test_unit_ready(h, c, lunaddr, rq);
6007 dev_warn(&h->pdev->dev, "giving up on device.\n");
6009 dev_warn(&h->pdev->dev, "device is ready.\n");
6011 cmd_free(h, c);
6022 struct ctlr_info *h;
6029 h = sdev_to_hba(scsicmd->device);
6030 if (h == NULL) /* paranoia */
6033 spin_lock_irqsave(&h->reset_lock, flags);
6034 h->reset_in_progress = 1;
6035 spin_unlock_irqrestore(&h->reset_lock, flags);
6037 if (lockup_detected(h)) {
6044 dev_err(&h->pdev->dev, "%s: device lookup failed\n", __func__);
6055 if (lockup_detected(h)) {
6059 hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
6065 if (detect_controller_lockup(h)) {
6069 hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
6087 hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
6101 rc = hpsa_do_reset(h, dev, reset_type, DEFAULT_REPLY_QUEUE);
6110 hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
6113 spin_lock_irqsave(&h->reset_lock, flags);
6114 h->reset_in_progress = 0;
6117 spin_unlock_irqrestore(&h->reset_lock, flags);
6128 static struct CommandList *cmd_tagged_alloc(struct ctlr_info *h,
6132 struct CommandList *c = h->cmd_pool + idx;
6134 if (idx < HPSA_NRESERVED_CMDS || idx >= h->nr_cmds) {
6135 dev_err(&h->pdev->dev, "Bad block tag: %d not in [%d..%d]\n",
6136 idx, HPSA_NRESERVED_CMDS, h->nr_cmds - 1);
6150 if (idx != h->last_collision_tag) { /* Print once per tag */
6151 dev_warn(&h->pdev->dev,
6155 h->last_collision_tag = idx;
6161 hpsa_cmd_partial_init(h, idx, c);
6172 static void cmd_tagged_free(struct ctlr_info *h, struct CommandList *c)
6190 static struct CommandList *cmd_alloc(struct ctlr_info *h)
6216 i = find_next_zero_bit(h->cmd_pool_bits,
6223 c = h->cmd_pool + i;
6226 cmd_free(h, c); /* already in use */
6230 set_bit(i, h->cmd_pool_bits);
6233 hpsa_cmd_partial_init(h, i, c);
6251 static void cmd_free(struct ctlr_info *h, struct CommandList *c)
6256 i = c - h->cmd_pool;
6257 clear_bit(i, h->cmd_pool_bits);
6266 struct ctlr_info *h = sdev_to_hba(dev);
6282 if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0)
6284 err = hpsa_passthru_ioctl(h, &arg64);
6285 atomic_inc(&h->passthru_cmds_avail);
6297 struct ctlr_info *h = sdev_to_hba(dev);
6313 if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0)
6315 err = hpsa_big_passthru_ioctl(h, &arg64);
6316 atomic_inc(&h->passthru_cmds_avail);
6357 static int hpsa_getpciinfo_ioctl(struct ctlr_info *h, void __user *argp)
6363 pciinfo.domain = pci_domain_nr(h->pdev->bus);
6364 pciinfo.bus = h->pdev->bus->number;
6365 pciinfo.dev_fn = h->pdev->devfn;
6366 pciinfo.board_id = h->board_id;
6372 static int hpsa_getdrivver_ioctl(struct ctlr_info *h, void __user *argp)
6381 dev_info(&h->pdev->dev, "driver version string '%s' "
6395 static int hpsa_passthru_ioctl(struct ctlr_info *h,
6424 c = cmd_alloc(h);
6446 temp64 = dma_map_single(&h->pdev->dev, buff,
6448 if (dma_mapping_error(&h->pdev->dev, (dma_addr_t) temp64)) {
6458 rc = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE,
6461 hpsa_pci_unmap(h->pdev, c, 1, DMA_BIDIRECTIONAL);
6462 check_ioctl_unit_attention(h, c);
6480 cmd_free(h, c);
6486 static int hpsa_big_passthru_ioctl(struct ctlr_info *h,
6541 c = cmd_alloc(h);
6553 temp64 = dma_map_single(&h->pdev->dev, buff[i],
6555 if (dma_mapping_error(&h->pdev->dev,
6559 hpsa_pci_unmap(h->pdev, c, i,
6570 status = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE,
6573 hpsa_pci_unmap(h->pdev, c, sg_used, DMA_BIDIRECTIONAL);
6574 check_ioctl_unit_attention(h, c);
6597 cmd_free(h, c);
6610 static void check_ioctl_unit_attention(struct ctlr_info *h,
6615 (void) check_for_unit_attention(h, c);
6624 struct ctlr_info *h = sdev_to_hba(dev);
6631 hpsa_scan_start(h->scsi_host);
6634 return hpsa_getpciinfo_ioctl(h, argp);
6636 return hpsa_getdrivver_ioctl(h, argp);
6644 if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0)
6646 rc = hpsa_passthru_ioctl(h, &iocommand);
6647 atomic_inc(&h->passthru_cmds_avail);
6658 if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0)
6660 rc = hpsa_big_passthru_ioctl(h, &ioc);
6661 atomic_inc(&h->passthru_cmds_avail);
6671 static void hpsa_send_host_reset(struct ctlr_info *h, u8 reset_type)
6675 c = cmd_alloc(h);
6678 (void) fill_cmd(c, HPSA_DEVICE_RESET_MSG, h, NULL, 0, 0,
6682 enqueue_cmd_and_start_io(h, c);
6690 static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
6853 dev_warn(&h->pdev->dev, "unknown command 0x%c\n", cmd);
6889 dev_warn(&h->pdev->dev, "unknown message type %d\n",
6894 dev_warn(&h->pdev->dev, "unknown command type %d\n", cmd_type);
6911 if (hpsa_map_one(h->pdev, c, buff, size, dir))
6929 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
6931 return h->access.command_completed(h, q);
6934 static inline bool interrupt_pending(struct ctlr_info *h)
6936 return h->access.intr_pending(h);
6939 static inline long interrupt_not_for_us(struct ctlr_info *h)
6941 return (h->access.intr_pending(h) == 0) ||
6942 (h->interrupts_enabled == 0);
6945 static inline int bad_tag(struct ctlr_info *h, u32 tag_index,
6948 if (unlikely(tag_index >= h->nr_cmds)) {
6949 dev_warn(&h->pdev->dev, "bad tag 0x%08x ignored.\n", raw_tag);
6957 dial_up_lockup_detection_on_fw_flash_complete(c->h, c);
6966 static inline void process_indexed_cmd(struct ctlr_info *h,
6973 if (!bad_tag(h, tag_index, raw_tag)) {
6974 c = h->cmd_pool + tag_index;
6984 static int ignore_bogus_interrupt(struct ctlr_info *h)
6989 if (likely(h->interrupts_enabled))
6992 dev_info(&h->pdev->dev, "Received interrupt while interrupts disabled "
6999 * Convert &h->q[x] (passed to interrupt handlers) back to h.
7000 * Relies on (h-q[x] == x) being true for x such that
7010 struct ctlr_info *h = queue_to_hba(queue);
7014 if (ignore_bogus_interrupt(h))
7017 if (interrupt_not_for_us(h))
7019 h->last_intr_timestamp = get_jiffies_64();
7020 while (interrupt_pending(h)) {
7021 raw_tag = get_next_completion(h, q);
7023 raw_tag = next_command(h, q);
7030 struct ctlr_info *h = queue_to_hba(queue);
7034 if (ignore_bogus_interrupt(h))
7037 h->last_intr_timestamp = get_jiffies_64();
7038 raw_tag = get_next_completion(h, q);
7040 raw_tag = next_command(h, q);
7046 struct ctlr_info *h = queue_to_hba((u8 *) queue);
7050 if (interrupt_not_for_us(h))
7052 h->last_intr_timestamp = get_jiffies_64();
7053 while (interrupt_pending(h)) {
7054 raw_tag = get_next_completion(h, q);
7056 process_indexed_cmd(h, raw_tag);
7057 raw_tag = next_command(h, q);
7065 struct ctlr_info *h = queue_to_hba(queue);
7069 h->last_intr_timestamp = get_jiffies_64();
7070 raw_tag = get_next_completion(h, q);
7072 process_indexed_cmd(h, raw_tag);
7073 raw_tag = next_command(h, q);
7200 * CSR=00h. The software off state is D3, CSR=03h. To reset
7474 static void hpsa_disable_interrupt_mode(struct ctlr_info *h)
7476 pci_free_irq_vectors(h->pdev);
7477 h->msix_vectors = 0;
7480 static void hpsa_setup_reply_map(struct ctlr_info *h)
7485 for (queue = 0; queue < h->msix_vectors; queue++) {
7486 mask = pci_irq_get_affinity(h->pdev, queue);
7491 h->reply_map[cpu] = queue;
7497 h->reply_map[cpu] = 0;
7503 static int hpsa_interrupt_mode(struct ctlr_info *h)
7509 switch (h->board_id) {
7516 ret = pci_alloc_irq_vectors(h->pdev, 1, MAX_REPLY_QUEUES,
7519 h->msix_vectors = ret;
7527 ret = pci_alloc_irq_vectors(h->pdev, 1, 1, flags);
7622 static void hpsa_free_cfgtables(struct ctlr_info *h)
7624 if (h->transtable) {
7625 iounmap(h->transtable);
7626 h->transtable = NULL;
7628 if (h->cfgtable) {
7629 iounmap(h->cfgtable);
7630 h->cfgtable = NULL;
7637 static int hpsa_find_cfgtables(struct ctlr_info *h)
7645 rc = hpsa_find_cfg_addrs(h->pdev, h->vaddr, &cfg_base_addr,
7649 h->cfgtable = remap_pci_mem(pci_resource_start(h->pdev,
7650 cfg_base_addr_index) + cfg_offset, sizeof(*h->cfgtable));
7651 if (!h->cfgtable) {
7652 dev_err(&h->pdev->dev, "Failed mapping cfgtable\n");
7655 rc = write_driver_ver_to_cfgtable(h->cfgtable);
7659 trans_offset = readl(&h->cfgtable->TransMethodOffset);
7660 h->transtable = remap_pci_mem(pci_resource_start(h->pdev,
7662 sizeof(*h->transtable));
7663 if (!h->transtable) {
7664 dev_err(&h->pdev->dev, "Failed mapping transfer table\n");
7665 hpsa_free_cfgtables(h);
7671 static void hpsa_get_max_perf_mode_cmds(struct ctlr_info *h)
7676 h->max_commands = readl(&h->cfgtable->MaxPerformantModeCommands);
7679 if (reset_devices && h->max_commands > 32)
7680 h->max_commands = 32;
7682 if (h->max_commands < MIN_MAX_COMMANDS) {
7683 dev_warn(&h->pdev->dev,
7685 h->max_commands,
7687 h->max_commands = MIN_MAX_COMMANDS;
7695 static int hpsa_supports_chained_sg_blocks(struct ctlr_info *h)
7697 return h->maxsgentries > 512;
7704 static void hpsa_find_board_params(struct ctlr_info *h)
7706 hpsa_get_max_perf_mode_cmds(h);
7707 h->nr_cmds = h->max_commands;
7708 h->maxsgentries = readl(&(h->cfgtable->MaxScatterGatherElements));
7709 h->fw_support = readl(&(h->cfgtable->misc_fw_support));
7710 if (hpsa_supports_chained_sg_blocks(h)) {
7712 h->max_cmd_sg_entries = 32;
7713 h->chainsize = h->maxsgentries - h->max_cmd_sg_entries;
7714 h->maxsgentries--; /* save one for chain pointer */
7721 h->max_cmd_sg_entries = 31;
7722 h->maxsgentries = 31; /* default to traditional values */
7723 h->chainsize = 0;
7727 h->TMFSupportFlags = readl(&(h->cfgtable->TMFSupportFlags));
7728 if (!(HPSATMF_PHYS_TASK_ABORT & h->TMFSupportFlags))
7729 dev_warn(&h->pdev->dev, "Physical aborts not supported\n");
7730 if (!(HPSATMF_LOG_TASK_ABORT & h->TMFSupportFlags))
7731 dev_warn(&h->pdev->dev, "Logical aborts not supported\n");
7732 if (!(HPSATMF_IOACCEL_ENABLED & h->TMFSupportFlags))
7733 dev_warn(&h->pdev->dev, "HP SSD Smart Path aborts not supported\n");
7736 static inline bool hpsa_CISS_signature_present(struct ctlr_info *h)
7738 if (!check_signature(h->cfgtable->Signature, "CISS", 4)) {
7739 dev_err(&h->pdev->dev, "not a valid CISS config table\n");
7745 static inline void hpsa_set_driver_support_bits(struct ctlr_info *h)
7749 driver_support = readl(&(h->cfgtable->driver_support));
7755 writel(driver_support, &(h->cfgtable->driver_support));
7761 static inline void hpsa_p600_dma_prefetch_quirk(struct ctlr_info *h)
7765 if (h->board_id != 0x3225103C)
7767 dma_prefetch = readl(h->vaddr + I2O_DMA1_CFG);
7769 writel(dma_prefetch, h->vaddr + I2O_DMA1_CFG);
7772 static int hpsa_wait_for_clear_event_notify_ack(struct ctlr_info *h)
7779 spin_lock_irqsave(&h->lock, flags);
7780 doorbell_value = readl(h->vaddr + SA5_DOORBELL);
7781 spin_unlock_irqrestore(&h->lock, flags);
7792 static int hpsa_wait_for_mode_change_ack(struct ctlr_info *h)
7803 if (h->remove_in_progress)
7805 spin_lock_irqsave(&h->lock, flags);
7806 doorbell_value = readl(h->vaddr + SA5_DOORBELL);
7807 spin_unlock_irqrestore(&h->lock, flags);
7819 static int hpsa_enter_simple_mode(struct ctlr_info *h)
7823 trans_support = readl(&(h->cfgtable->TransportSupport));
7827 h->max_commands = readl(&(h->cfgtable->CmdsOutMax));
7830 writel(CFGTBL_Trans_Simple, &(h->cfgtable->HostWrite.TransportRequest));
7831 writel(0, &h->cfgtable->HostWrite.command_pool_addr_hi);
7832 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
7833 if (hpsa_wait_for_mode_change_ack(h))
7835 print_cfg_table(&h->pdev->dev, h->cfgtable);
7836 if (!(readl(&(h->cfgtable->TransportActive)) & CFGTBL_Trans_Simple))
7838 h->transMethod = CFGTBL_Trans_Simple;
7841 dev_err(&h->pdev->dev, "failed to enter simple mode\n");
7846 static void hpsa_free_pci_init(struct ctlr_info *h)
7848 hpsa_free_cfgtables(h); /* pci_init 4 */
7849 iounmap(h->vaddr); /* pci_init 3 */
7850 h->vaddr = NULL;
7851 hpsa_disable_interrupt_mode(h); /* pci_init 2 */
7856 pci_disable_device(h->pdev); /* pci_init 1 */
7857 pci_release_regions(h->pdev); /* pci_init 2 */
7861 static int hpsa_pci_init(struct ctlr_info *h)
7866 prod_index = hpsa_lookup_board_id(h->pdev, &h->board_id, &legacy_board);
7869 h->product_name = products[prod_index].product_name;
7870 h->access = *(products[prod_index].access);
7871 h->legacy_board = legacy_board;
7872 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
7875 err = pci_enable_device(h->pdev);
7877 dev_err(&h->pdev->dev, "failed to enable PCI device\n");
7878 pci_disable_device(h->pdev);
7882 err = pci_request_regions(h->pdev, HPSA);
7884 dev_err(&h->pdev->dev,
7886 pci_disable_device(h->pdev);
7890 pci_set_master(h->pdev);
7892 err = hpsa_interrupt_mode(h);
7897 hpsa_setup_reply_map(h);
7899 err = hpsa_pci_find_memory_BAR(h->pdev, &h->paddr);
7902 h->vaddr = remap_pci_mem(h->paddr, 0x250);
7903 if (!h->vaddr) {
7904 dev_err(&h->pdev->dev, "failed to remap PCI mem\n");
7908 err = hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_READY);
7911 err = hpsa_find_cfgtables(h);
7914 hpsa_find_board_params(h);
7916 if (!hpsa_CISS_signature_present(h)) {
7920 hpsa_set_driver_support_bits(h);
7921 hpsa_p600_dma_prefetch_quirk(h);
7922 err = hpsa_enter_simple_mode(h);
7928 hpsa_free_cfgtables(h);
7930 iounmap(h->vaddr);
7931 h->vaddr = NULL;
7933 hpsa_disable_interrupt_mode(h);
7939 pci_disable_device(h->pdev);
7940 pci_release_regions(h->pdev);
7944 static void hpsa_hba_inquiry(struct ctlr_info *h)
7949 h->hba_inquiry_data = kmalloc(HBA_INQUIRY_BYTE_COUNT, GFP_KERNEL);
7950 if (!h->hba_inquiry_data)
7952 rc = hpsa_scsi_do_inquiry(h, RAID_CTLR_LUNID, 0,
7953 h->hba_inquiry_data, HBA_INQUIRY_BYTE_COUNT);
7955 kfree(h->hba_inquiry_data);
7956 h->hba_inquiry_data = NULL;
8022 static void hpsa_free_cmd_pool(struct ctlr_info *h)
8024 bitmap_free(h->cmd_pool_bits);
8025 h->cmd_pool_bits = NULL;
8026 if (h->cmd_pool) {
8027 dma_free_coherent(&h->pdev->dev,
8028 h->nr_cmds * sizeof(struct CommandList),
8029 h->cmd_pool,
8030 h->cmd_pool_dhandle);
8031 h->cmd_pool = NULL;
8032 h->cmd_pool_dhandle = 0;
8034 if (h->errinfo_pool) {
8035 dma_free_coherent(&h->pdev->dev,
8036 h->nr_cmds * sizeof(struct ErrorInfo),
8037 h->errinfo_pool,
8038 h->errinfo_pool_dhandle);
8039 h->errinfo_pool = NULL;
8040 h->errinfo_pool_dhandle = 0;
8044 static int hpsa_alloc_cmd_pool(struct ctlr_info *h)
8046 h->cmd_pool_bits = bitmap_zalloc(h->nr_cmds, GFP_KERNEL);
8047 h->cmd_pool = dma_alloc_coherent(&h->pdev->dev,
8048 h->nr_cmds * sizeof(*h->cmd_pool),
8049 &h->cmd_pool_dhandle, GFP_KERNEL);
8050 h->errinfo_pool = dma_alloc_coherent(&h->pdev->dev,
8051 h->nr_cmds * sizeof(*h->errinfo_pool),
8052 &h->errinfo_pool_dhandle, GFP_KERNEL);
8053 if ((h->cmd_pool_bits == NULL)
8054 || (h->cmd_pool == NULL)
8055 || (h->errinfo_pool == NULL)) {
8056 dev_err(&h->pdev->dev, "out of memory in %s", __func__);
8059 hpsa_preinitialize_commands(h);
8062 hpsa_free_cmd_pool(h);
8067 static void hpsa_free_irqs(struct ctlr_info *h)
8073 irq_vector = h->intr_mode;
8075 if (!h->msix_vectors || h->intr_mode != PERF_MODE_INT) {
8077 free_irq(pci_irq_vector(h->pdev, irq_vector),
8078 &h->q[h->intr_mode]);
8079 h->q[h->intr_mode] = 0;
8083 for (i = 0; i < h->msix_vectors; i++) {
8084 free_irq(pci_irq_vector(h->pdev, i), &h->q[i]);
8085 h->q[i] = 0;
8088 h->q[i] = 0;
8092 static int hpsa_request_irqs(struct ctlr_info *h,
8100 irq_vector = h->intr_mode;
8103 * initialize h->q[x] = x so that interrupt handlers know which
8107 h->q[i] = (u8) i;
8109 if (h->intr_mode == PERF_MODE_INT && h->msix_vectors > 0) {
8111 for (i = 0; i < h->msix_vectors; i++) {
8112 sprintf(h->intrname[i], "%s-msix%d", h->devname, i);
8113 rc = request_irq(pci_irq_vector(h->pdev, i), msixhandler,
8114 0, h->intrname[i],
8115 &h->q[i]);
8119 dev_err(&h->pdev->dev,
8121 pci_irq_vector(h->pdev, i), h->devname);
8123 free_irq(pci_irq_vector(h->pdev, j), &h->q[j]);
8124 h->q[j] = 0;
8127 h->q[j] = 0;
8133 if (h->msix_vectors > 0 || h->pdev->msi_enabled) {
8134 sprintf(h->intrname[0], "%s-msi%s", h->devname,
8135 h->msix_vectors ? "x" : "");
8136 rc = request_irq(pci_irq_vector(h->pdev, irq_vector),
8138 h->intrname[0],
8139 &h->q[h->intr_mode]);
8141 sprintf(h->intrname[h->intr_mode],
8142 "%s-intx", h->devname);
8143 rc = request_irq(pci_irq_vector(h->pdev, irq_vector),
8145 h->intrname[0],
8146 &h->q[h->intr_mode]);
8150 dev_err(&h->pdev->dev, "failed to get irq %d for %s\n",
8151 pci_irq_vector(h->pdev, irq_vector), h->devname);
8152 hpsa_free_irqs(h);
8158 static int hpsa_kdump_soft_reset(struct ctlr_info *h)
8161 hpsa_send_host_reset(h, HPSA_RESET_TYPE_CONTROLLER);
8163 dev_info(&h->pdev->dev, "Waiting for board to soft reset.\n");
8164 rc = hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_NOT_READY);
8166 dev_warn(&h->pdev->dev, "Soft reset had no effect.\n");
8170 dev_info(&h->pdev->dev, "Board reset, awaiting READY status.\n");
8171 rc = hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_READY);
8173 dev_warn(&h->pdev->dev, "Board failed to become ready "
8181 static void hpsa_free_reply_queues(struct ctlr_info *h)
8185 for (i = 0; i < h->nreply_queues; i++) {
8186 if (!h->reply_queue[i].head)
8188 dma_free_coherent(&h->pdev->dev,
8189 h->reply_queue_size,
8190 h->reply_queue[i].head,
8191 h->reply_queue[i].busaddr);
8192 h->reply_queue[i].head = NULL;
8193 h->reply_queue[i].busaddr = 0;
8195 h->reply_queue_size = 0;
8198 static void hpsa_undo_allocations_after_kdump_soft_reset(struct ctlr_info *h)
8200 hpsa_free_performant_mode(h); /* init_one 7 */
8201 hpsa_free_sg_chain_blocks(h); /* init_one 6 */
8202 hpsa_free_cmd_pool(h); /* init_one 5 */
8203 hpsa_free_irqs(h); /* init_one 4 */
8204 scsi_host_put(h->scsi_host); /* init_one 3 */
8205 h->scsi_host = NULL; /* init_one 3 */
8206 hpsa_free_pci_init(h); /* init_one 2_5 */
8207 free_percpu(h->lockup_detected); /* init_one 2 */
8208 h->lockup_detected = NULL; /* init_one 2 */
8209 if (h->resubmit_wq) {
8210 destroy_workqueue(h->resubmit_wq); /* init_one 1 */
8211 h->resubmit_wq = NULL;
8213 if (h->rescan_ctlr_wq) {
8214 destroy_workqueue(h->rescan_ctlr_wq);
8215 h->rescan_ctlr_wq = NULL;
8217 if (h->monitor_ctlr_wq) {
8218 destroy_workqueue(h->monitor_ctlr_wq);
8219 h->monitor_ctlr_wq = NULL;
8222 kfree(h); /* init_one 1 */
8226 static void fail_all_outstanding_cmds(struct ctlr_info *h)
8232 flush_workqueue(h->resubmit_wq); /* ensure all cmds are fully built */
8233 for (i = 0; i < h->nr_cmds; i++) {
8234 c = h->cmd_pool + i;
8239 atomic_dec(&h->commands_outstanding);
8242 cmd_free(h, c);
8244 dev_warn(&h->pdev->dev,
8248 static void set_lockup_detected_for_all_cpus(struct ctlr_info *h, u32 value)
8254 lockup_detected = per_cpu_ptr(h->lockup_detected, cpu);
8260 static void controller_lockup_detected(struct ctlr_info *h)
8265 h->access.set_intr_mask(h, HPSA_INTR_OFF);
8266 spin_lock_irqsave(&h->lock, flags);
8267 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
8270 dev_warn(&h->pdev->dev,
8272 h->heartbeat_sample_interval / HZ);
8275 set_lockup_detected_for_all_cpus(h, lockup_detected);
8276 spin_unlock_irqrestore(&h->lock, flags);
8277 dev_warn(&h->pdev->dev, "Controller lockup detected: 0x%08x after %d\n",
8278 lockup_detected, h->heartbeat_sample_interval / HZ);
8280 dev_warn(&h->pdev->dev, "Telling controller to do a CHKPT\n");
8281 writel(DOORBELL_GENERATE_CHKPT, h->vaddr + SA5_DOORBELL);
8283 pci_disable_device(h->pdev);
8284 fail_all_outstanding_cmds(h);
8287 static int detect_controller_lockup(struct ctlr_info *h)
8295 if (time_after64(h->last_intr_timestamp +
8296 (h->heartbeat_sample_interval), now))
8304 if (time_after64(h->last_heartbeat_timestamp +
8305 (h->heartbeat_sample_interval), now))
8309 spin_lock_irqsave(&h->lock, flags);
8310 heartbeat = readl(&h->cfgtable->HeartBeat);
8311 spin_unlock_irqrestore(&h->lock, flags);
8312 if (h->last_heartbeat == heartbeat) {
8313 controller_lockup_detected(h);
8318 h->last_heartbeat = heartbeat;
8319 h->last_heartbeat_timestamp = now;
8332 static void hpsa_set_ioaccel_status(struct ctlr_info *h)
8340 if (!h)
8350 for (i = 0; i < h->ndevices; i++) {
8354 device = h->dev[i];
8358 if (!hpsa_vpd_page_supported(h, device->scsi3addr,
8364 rc = hpsa_scsi_do_inquiry(h, device->scsi3addr,
8405 static void hpsa_ack_ctlr_events(struct ctlr_info *h)
8409 if (!(h->fw_support & MISC_FW_EVENT_NOTIFY))
8413 if ((h->transMethod & (CFGTBL_Trans_io_accel1
8415 (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_STATE_CHANGE ||
8416 h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_CONFIG_CHANGE)) {
8418 if (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_STATE_CHANGE)
8420 if (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_CONFIG_CHANGE)
8423 scsi_block_requests(h->scsi_host);
8424 hpsa_set_ioaccel_status(h);
8425 hpsa_drain_accel_commands(h);
8427 dev_warn(&h->pdev->dev,
8429 h->events, event_type);
8430 writel(h->events, &(h->cfgtable->clear_event_notify));
8432 writel(DOORBELL_CLEAR_EVENTS, h->vaddr + SA5_DOORBELL);
8434 hpsa_wait_for_clear_event_notify_ack(h);
8435 scsi_unblock_requests(h->scsi_host);
8438 writel(h->events, &(h->cfgtable->clear_event_notify));
8439 writel(DOORBELL_CLEAR_EVENTS, h->vaddr + SA5_DOORBELL);
8440 hpsa_wait_for_clear_event_notify_ack(h);
8450 static int hpsa_ctlr_needs_rescan(struct ctlr_info *h)
8452 if (h->drv_req_rescan) {
8453 h->drv_req_rescan = 0;
8457 if (!(h->fw_support & MISC_FW_EVENT_NOTIFY))
8460 h->events = readl(&(h->cfgtable->event_notify));
8461 return h->events & RESCAN_REQUIRED_EVENT_BITS;
8467 static int hpsa_offline_devices_ready(struct ctlr_info *h)
8473 spin_lock_irqsave(&h->offline_device_lock, flags);
8474 list_for_each_safe(this, tmp, &h->offline_device_list) {
8477 spin_unlock_irqrestore(&h->offline_device_lock, flags);
8478 if (!hpsa_volume_offline(h, d->scsi3addr)) {
8479 spin_lock_irqsave(&h->offline_device_lock, flags);
8481 spin_unlock_irqrestore(&h->offline_device_lock, flags);
8484 spin_lock_irqsave(&h->offline_device_lock, flags);
8486 spin_unlock_irqrestore(&h->offline_device_lock, flags);
8490 static int hpsa_luns_changed(struct ctlr_info *h)
8499 if (!h->lastlogicals)
8506 if (hpsa_scsi_do_report_luns(h, 1, logdev, sizeof(*logdev), 0)) {
8507 dev_warn(&h->pdev->dev,
8511 if (memcmp(logdev, h->lastlogicals, sizeof(*logdev))) {
8512 dev_info(&h->pdev->dev,
8514 memcpy(h->lastlogicals, logdev, sizeof(*logdev));
8523 static void hpsa_perform_rescan(struct ctlr_info *h)
8531 spin_lock_irqsave(&h->reset_lock, flags);
8532 if (h->reset_in_progress) {
8533 h->drv_req_rescan = 1;
8534 spin_unlock_irqrestore(&h->reset_lock, flags);
8537 spin_unlock_irqrestore(&h->reset_lock, flags);
8539 sh = scsi_host_get(h->scsi_host);
8543 h->drv_req_rescan = 0;
8552 struct ctlr_info *h = container_of(to_delayed_work(work),
8556 spin_lock_irqsave(&h->lock, flags);
8557 if (h->remove_in_progress) {
8558 spin_unlock_irqrestore(&h->lock, flags);
8561 spin_unlock_irqrestore(&h->lock, flags);
8563 if (hpsa_ctlr_needs_rescan(h)) {
8564 hpsa_ack_ctlr_events(h);
8565 hpsa_perform_rescan(h);
8568 spin_lock_irqsave(&h->lock, flags);
8569 if (!h->remove_in_progress)
8570 queue_delayed_work(h->monitor_ctlr_wq, &h->event_monitor_work,
8572 spin_unlock_irqrestore(&h->lock, flags);
8578 struct ctlr_info *h = container_of(to_delayed_work(work),
8581 spin_lock_irqsave(&h->lock, flags);
8582 if (h->remove_in_progress) {
8583 spin_unlock_irqrestore(&h->lock, flags);
8586 spin_unlock_irqrestore(&h->lock, flags);
8588 if (h->drv_req_rescan || hpsa_offline_devices_ready(h)) {
8589 hpsa_perform_rescan(h);
8590 } else if (h->discovery_polling) {
8591 if (hpsa_luns_changed(h)) {
8592 dev_info(&h->pdev->dev,
8594 hpsa_perform_rescan(h);
8597 spin_lock_irqsave(&h->lock, flags);
8598 if (!h->remove_in_progress)
8599 queue_delayed_work(h->rescan_ctlr_wq, &h->rescan_ctlr_work,
8600 h->heartbeat_sample_interval);
8601 spin_unlock_irqrestore(&h->lock, flags);
8607 struct ctlr_info *h = container_of(to_delayed_work(work),
8610 detect_controller_lockup(h);
8611 if (lockup_detected(h))
8614 spin_lock_irqsave(&h->lock, flags);
8615 if (!h->remove_in_progress)
8616 queue_delayed_work(h->monitor_ctlr_wq, &h->monitor_ctlr_work,
8617 h->heartbeat_sample_interval);
8618 spin_unlock_irqrestore(&h->lock, flags);
8621 static struct workqueue_struct *hpsa_create_controller_wq(struct ctlr_info *h,
8626 wq = alloc_ordered_workqueue("%s_%d_hpsa", 0, name, h->ctlr);
8628 dev_err(&h->pdev->dev, "failed to create %s workqueue\n", name);
8633 static void hpda_free_ctlr_info(struct ctlr_info *h)
8635 kfree(h->reply_map);
8636 kfree(h);
8641 struct ctlr_info *h;
8643 h = kzalloc(sizeof(*h), GFP_KERNEL);
8644 if (!h)
8647 h->reply_map = kcalloc(nr_cpu_ids, sizeof(*h->reply_map), GFP_KERNEL);
8648 if (!h->reply_map) {
8649 kfree(h);
8652 return h;
8658 struct ctlr_info *h;
8689 * the driver. See comments in hpsa.h for more info.
8692 h = hpda_alloc_ctlr_info();
8693 if (!h) {
8698 h->pdev = pdev;
8700 h->intr_mode = hpsa_simple_mode ? SIMPLE_MODE_INT : PERF_MODE_INT;
8701 INIT_LIST_HEAD(&h->offline_device_list);
8702 spin_lock_init(&h->lock);
8703 spin_lock_init(&h->offline_device_lock);
8704 spin_lock_init(&h->scan_lock);
8705 spin_lock_init(&h->reset_lock);
8706 atomic_set(&h->passthru_cmds_avail, HPSA_MAX_CONCURRENT_PASSTHRUS);
8709 h->lockup_detected = alloc_percpu(u32);
8710 if (!h->lockup_detected) {
8711 dev_err(&h->pdev->dev, "Failed to allocate lockup detector\n");
8713 goto clean1; /* aer/h */
8715 set_lockup_detected_for_all_cpus(h, 0);
8717 rc = hpsa_pci_init(h);
8719 goto clean2; /* lu, aer/h */
8721 /* relies on h-> settings made by hpsa_pci_init, including
8722 * interrupt_mode h->intr */
8723 rc = hpsa_scsi_host_alloc(h);
8725 goto clean2_5; /* pci, lu, aer/h */
8727 sprintf(h->devname, HPSA "%d", h->scsi_host->host_no);
8728 h->ctlr = number_of_controllers;
8737 goto clean3; /* shost, pci, lu, aer/h */
8742 h->access.set_intr_mask(h, HPSA_INTR_OFF);
8744 rc = hpsa_request_irqs(h, do_hpsa_intr_msi, do_hpsa_intr_intx);
8746 goto clean3; /* shost, pci, lu, aer/h */
8747 rc = hpsa_alloc_cmd_pool(h);
8749 goto clean4; /* irq, shost, pci, lu, aer/h */
8750 rc = hpsa_alloc_sg_chain_blocks(h);
8752 goto clean5; /* cmd, irq, shost, pci, lu, aer/h */
8753 init_waitqueue_head(&h->scan_wait_queue);
8754 init_waitqueue_head(&h->event_sync_wait_queue);
8755 mutex_init(&h->reset_mutex);
8756 h->scan_finished = 1; /* no scan currently in progress */
8757 h->scan_waiting = 0;
8759 pci_set_drvdata(pdev, h);
8760 h->ndevices = 0;
8762 spin_lock_init(&h->devlock);
8763 rc = hpsa_put_ctlr_into_performant_mode(h);
8765 goto clean6; /* sg, cmd, irq, shost, pci, lu, aer/h */
8768 h->rescan_ctlr_wq = hpsa_create_controller_wq(h, "rescan");
8769 if (!h->rescan_ctlr_wq) {
8774 h->resubmit_wq = hpsa_create_controller_wq(h, "resubmit");
8775 if (!h->resubmit_wq) {
8777 goto clean7; /* aer/h */
8780 h->monitor_ctlr_wq = hpsa_create_controller_wq(h, "monitor");
8781 if (!h->monitor_ctlr_wq) {
8800 spin_lock_irqsave(&h->lock, flags);
8801 h->access.set_intr_mask(h, HPSA_INTR_OFF);
8802 spin_unlock_irqrestore(&h->lock, flags);
8803 hpsa_free_irqs(h);
8804 rc = hpsa_request_irqs(h, hpsa_msix_discard_completions,
8807 dev_warn(&h->pdev->dev,
8813 hpsa_free_performant_mode(h); /* clean7 */
8814 hpsa_free_sg_chain_blocks(h); /* clean6 */
8815 hpsa_free_cmd_pool(h); /* clean5 */
8817 * skip hpsa_free_irqs(h) clean4 since that
8823 rc = hpsa_kdump_soft_reset(h);
8828 dev_info(&h->pdev->dev, "Board READY.\n");
8829 dev_info(&h->pdev->dev,
8831 h->access.set_intr_mask(h, HPSA_INTR_ON);
8833 h->access.set_intr_mask(h, HPSA_INTR_OFF);
8835 rc = controller_reset_failed(h->cfgtable);
8837 dev_info(&h->pdev->dev,
8844 hpsa_undo_allocations_after_kdump_soft_reset(h);
8854 h->acciopath_status = 1;
8856 h->discovery_polling = 0;
8860 h->access.set_intr_mask(h, HPSA_INTR_ON);
8862 hpsa_hba_inquiry(h);
8864 h->lastlogicals = kzalloc(sizeof(*(h->lastlogicals)), GFP_KERNEL);
8865 if (!h->lastlogicals)
8866 dev_info(&h->pdev->dev,
8870 rc = hpsa_scsi_add_host(h);
8872 goto clean8; /* lastlogicals, perf, sg, cmd, irq, shost, pci, lu, aer/h */
8875 h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL;
8876 INIT_DELAYED_WORK(&h->monitor_ctlr_work, hpsa_monitor_ctlr_worker);
8877 schedule_delayed_work(&h->monitor_ctlr_work,
8878 h->heartbeat_sample_interval);
8879 INIT_DELAYED_WORK(&h->rescan_ctlr_work, hpsa_rescan_ctlr_worker);
8880 queue_delayed_work(h->rescan_ctlr_wq, &h->rescan_ctlr_work,
8881 h->heartbeat_sample_interval);
8882 INIT_DELAYED_WORK(&h->event_monitor_work, hpsa_event_monitor_worker);
8883 schedule_delayed_work(&h->event_monitor_work,
8887 clean8: /* lastlogicals, perf, sg, cmd, irq, shost, pci, lu, aer/h */
8888 kfree(h->lastlogicals);
8889 clean7: /* perf, sg, cmd, irq, shost, pci, lu, aer/h */
8890 hpsa_free_performant_mode(h);
8891 h->access.set_intr_mask(h, HPSA_INTR_OFF);
8892 clean6: /* sg, cmd, irq, pci, lockup, wq/aer/h */
8893 hpsa_free_sg_chain_blocks(h);
8894 clean5: /* cmd, irq, shost, pci, lu, aer/h */
8895 hpsa_free_cmd_pool(h);
8896 clean4: /* irq, shost, pci, lu, aer/h */
8897 hpsa_free_irqs(h);
8898 clean3: /* shost, pci, lu, aer/h */
8899 scsi_host_put(h->scsi_host);
8900 h->scsi_host = NULL;
8901 clean2_5: /* pci, lu, aer/h */
8902 hpsa_free_pci_init(h);
8903 clean2: /* lu, aer/h */
8904 if (h->lockup_detected) {
8905 free_percpu(h->lockup_detected);
8906 h->lockup_detected = NULL;
8908 clean1: /* wq/aer/h */
8909 if (h->resubmit_wq) {
8910 destroy_workqueue(h->resubmit_wq);
8911 h->resubmit_wq = NULL;
8913 if (h->rescan_ctlr_wq) {
8914 destroy_workqueue(h->rescan_ctlr_wq);
8915 h->rescan_ctlr_wq = NULL;
8917 if (h->monitor_ctlr_wq) {
8918 destroy_workqueue(h->monitor_ctlr_wq);
8919 h->monitor_ctlr_wq = NULL;
8921 hpda_free_ctlr_info(h);
8925 static void hpsa_flush_cache(struct ctlr_info *h)
8931 if (unlikely(lockup_detected(h)))
8937 c = cmd_alloc(h);
8939 if (fill_cmd(c, HPSA_CACHE_FLUSH, h, flush_buf, 4, 0,
8943 rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_TO_DEVICE,
8949 dev_warn(&h->pdev->dev,
8951 cmd_free(h, c);
8958 static void hpsa_disable_rld_caching(struct ctlr_info *h)
8965 if (unlikely(h->lockup_detected))
8972 c = cmd_alloc(h);
8975 if (fill_cmd(c, BMIC_SENSE_DIAG_OPTIONS, h, options, 4, 0,
8979 rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
8987 if (fill_cmd(c, BMIC_SET_DIAG_OPTIONS, h, options, 4, 0,
8991 rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_TO_DEVICE,
8997 if (fill_cmd(c, BMIC_SENSE_DIAG_OPTIONS, h, options, 4, 0,
9001 rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
9010 dev_err(&h->pdev->dev,
9013 cmd_free(h, c);
9019 struct ctlr_info *h;
9021 h = pci_get_drvdata(pdev);
9026 hpsa_flush_cache(h);
9027 h->access.set_intr_mask(h, HPSA_INTR_OFF);
9028 hpsa_free_irqs(h); /* init_one 4 */
9029 hpsa_disable_interrupt_mode(h); /* pci_init 2 */
9038 static void hpsa_free_device_info(struct ctlr_info *h)
9042 for (i = 0; i < h->ndevices; i++) {
9043 kfree(h->dev[i]);
9044 h->dev[i] = NULL;
9050 struct ctlr_info *h;
9057 h = pci_get_drvdata(pdev);
9060 spin_lock_irqsave(&h->lock, flags);
9061 h->remove_in_progress = 1;
9062 spin_unlock_irqrestore(&h->lock, flags);
9063 cancel_delayed_work_sync(&h->monitor_ctlr_work);
9064 cancel_delayed_work_sync(&h->rescan_ctlr_work);
9065 cancel_delayed_work_sync(&h->event_monitor_work);
9066 destroy_workqueue(h->rescan_ctlr_wq);
9067 destroy_workqueue(h->resubmit_wq);
9068 destroy_workqueue(h->monitor_ctlr_wq);
9070 hpsa_delete_sas_host(h);
9078 if (h->scsi_host)
9079 scsi_remove_host(h->scsi_host); /* init_one 8 */
9084 hpsa_free_device_info(h); /* scan */
9086 kfree(h->hba_inquiry_data); /* init_one 10 */
9087 h->hba_inquiry_data = NULL; /* init_one 10 */
9088 hpsa_free_ioaccel2_sg_chain_blocks(h);
9089 hpsa_free_performant_mode(h); /* init_one 7 */
9090 hpsa_free_sg_chain_blocks(h); /* init_one 6 */
9091 hpsa_free_cmd_pool(h); /* init_one 5 */
9092 kfree(h->lastlogicals);
9096 scsi_host_put(h->scsi_host); /* init_one 3 */
9097 h->scsi_host = NULL; /* init_one 3 */
9100 hpsa_free_pci_init(h); /* init_one 2.5 */
9102 free_percpu(h->lockup_detected); /* init_one 2 */
9103 h->lockup_detected = NULL; /* init_one 2 */
9105 hpda_free_ctlr_info(h); /* init_one 1 */
9169 static int hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
9223 for (i = 0; i < h->nreply_queues; i++)
9224 memset(h->reply_queue[i].head, 0, h->reply_queue_size);
9228 SG_ENTRIES_IN_CMD, 4, h->blockFetchTable);
9230 writel(bft[i], &h->transtable->BlockFetch[i]);
9233 writel(h->max_commands, &h->transtable->RepQSize);
9234 writel(h->nreply_queues, &h->transtable->RepQCount);
9235 writel(0, &h->transtable->RepQCtrAddrLow32);
9236 writel(0, &h->transtable->RepQCtrAddrHigh32);
9238 for (i = 0; i < h->nreply_queues; i++) {
9239 writel(0, &h->transtable->RepQAddr[i].upper);
9240 writel(h->reply_queue[i].busaddr,
9241 &h->transtable->RepQAddr[i].lower);
9244 writel(0, &h->cfgtable->HostWrite.command_pool_addr_hi);
9245 writel(transMethod, &(h->cfgtable->HostWrite.TransportRequest));
9251 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
9252 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
9256 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
9257 if (hpsa_wait_for_mode_change_ack(h)) {
9258 dev_err(&h->pdev->dev,
9262 register_value = readl(&(h->cfgtable->TransportActive));
9264 dev_err(&h->pdev->dev,
9269 h->access = access;
9270 h->transMethod = transMethod;
9278 for (i = 0; i < h->nreply_queues; i++) {
9279 writel(i, h->vaddr + IOACCEL_MODE1_REPLY_QUEUE_INDEX);
9280 h->reply_queue[i].current_entry =
9281 readl(h->vaddr + IOACCEL_MODE1_PRODUCER_INDEX);
9283 bft[7] = h->ioaccel_maxsg + 8;
9284 calc_bucket_map(bft, ARRAY_SIZE(bft), h->ioaccel_maxsg, 8,
9285 h->ioaccel1_blockFetchTable);
9288 for (i = 0; i < h->nreply_queues; i++)
9289 memset(h->reply_queue[i].head,
9291 h->reply_queue_size);
9296 for (i = 0; i < h->nr_cmds; i++) {
9297 struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[i];
9300 cp->err_info = (u32) (h->errinfo_pool_dhandle +
9311 cpu_to_le64(h->ioaccel_cmd_pool_dhandle +
9318 hpsa_find_cfg_addrs(h->pdev, h->vaddr, &cfg_base_addr,
9321 bft2[15] = h->ioaccel_maxsg + HPSA_IOACCEL2_HEADER_SZ;
9322 calc_bucket_map(bft2, ARRAY_SIZE(bft2), h->ioaccel_maxsg,
9323 4, h->ioaccel2_blockFetchTable);
9324 bft2_offset = readl(&h->cfgtable->io_accel_request_size_offset);
9327 h->ioaccel2_bft2_regs =
9328 remap_pci_mem(pci_resource_start(h->pdev,
9332 sizeof(*h->ioaccel2_bft2_regs));
9334 writel(bft2[i], &h->ioaccel2_bft2_regs[i]);
9336 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
9337 if (hpsa_wait_for_mode_change_ack(h)) {
9338 dev_err(&h->pdev->dev,
9346 static void hpsa_free_ioaccel1_cmd_and_bft(struct ctlr_info *h)
9348 if (h->ioaccel_cmd_pool) {
9349 dma_free_coherent(&h->pdev->dev,
9350 h->nr_cmds * sizeof(*h->ioaccel_cmd_pool),
9351 h->ioaccel_cmd_pool,
9352 h->ioaccel_cmd_pool_dhandle);
9353 h->ioaccel_cmd_pool = NULL;
9354 h->ioaccel_cmd_pool_dhandle = 0;
9356 kfree(h->ioaccel1_blockFetchTable);
9357 h->ioaccel1_blockFetchTable = NULL;
9361 static int hpsa_alloc_ioaccel1_cmd_and_bft(struct ctlr_info *h)
9363 h->ioaccel_maxsg =
9364 readl(&(h->cfgtable->io_accel_max_embedded_sg_count));
9365 if (h->ioaccel_maxsg > IOACCEL1_MAXSGENTRIES)
9366 h->ioaccel_maxsg = IOACCEL1_MAXSGENTRIES;
9374 h->ioaccel_cmd_pool =
9375 dma_alloc_coherent(&h->pdev->dev,
9376 h->nr_cmds * sizeof(*h->ioaccel_cmd_pool),
9377 &h->ioaccel_cmd_pool_dhandle, GFP_KERNEL);
9379 h->ioaccel1_blockFetchTable =
9380 kmalloc(((h->ioaccel_maxsg + 1) *
9383 if ((h->ioaccel_cmd_pool == NULL) ||
9384 (h->ioaccel1_blockFetchTable == NULL))
9387 memset(h->ioaccel_cmd_pool, 0,
9388 h->nr_cmds * sizeof(*h->ioaccel_cmd_pool));
9392 hpsa_free_ioaccel1_cmd_and_bft(h);
9397 static void hpsa_free_ioaccel2_cmd_and_bft(struct ctlr_info *h)
9399 hpsa_free_ioaccel2_sg_chain_blocks(h);
9401 if (h->ioaccel2_cmd_pool) {
9402 dma_free_coherent(&h->pdev->dev,
9403 h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool),
9404 h->ioaccel2_cmd_pool,
9405 h->ioaccel2_cmd_pool_dhandle);
9406 h->ioaccel2_cmd_pool = NULL;
9407 h->ioaccel2_cmd_pool_dhandle = 0;
9409 kfree(h->ioaccel2_blockFetchTable);
9410 h->ioaccel2_blockFetchTable = NULL;
9414 static int hpsa_alloc_ioaccel2_cmd_and_bft(struct ctlr_info *h)
9420 h->ioaccel_maxsg =
9421 readl(&(h->cfgtable->io_accel_max_embedded_sg_count));
9422 if (h->ioaccel_maxsg > IOACCEL2_MAXSGENTRIES)
9423 h->ioaccel_maxsg = IOACCEL2_MAXSGENTRIES;
9427 h->ioaccel2_cmd_pool =
9428 dma_alloc_coherent(&h->pdev->dev,
9429 h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool),
9430 &h->ioaccel2_cmd_pool_dhandle, GFP_KERNEL);
9432 h->ioaccel2_blockFetchTable =
9433 kmalloc(((h->ioaccel_maxsg + 1) *
9436 if ((h->ioaccel2_cmd_pool == NULL) ||
9437 (h->ioaccel2_blockFetchTable == NULL)) {
9442 rc = hpsa_allocate_ioaccel2_sg_chain_blocks(h);
9446 memset(h->ioaccel2_cmd_pool, 0,
9447 h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool));
9451 hpsa_free_ioaccel2_cmd_and_bft(h);
9456 static void hpsa_free_performant_mode(struct ctlr_info *h)
9458 kfree(h->blockFetchTable);
9459 h->blockFetchTable = NULL;
9460 hpsa_free_reply_queues(h);
9461 hpsa_free_ioaccel1_cmd_and_bft(h);
9462 hpsa_free_ioaccel2_cmd_and_bft(h);
9468 static int hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h)
9476 trans_support = readl(&(h->cfgtable->TransportSupport));
9482 rc = hpsa_alloc_ioaccel1_cmd_and_bft(h);
9486 rc = hpsa_alloc_ioaccel2_cmd_and_bft(h);
9491 h->nreply_queues = h->msix_vectors > 0 ? h->msix_vectors : 1;
9492 hpsa_get_max_perf_mode_cmds(h);
9494 h->reply_queue_size = h->max_commands * sizeof(u64);
9496 for (i = 0; i < h->nreply_queues; i++) {
9497 h->reply_queue[i].head = dma_alloc_coherent(&h->pdev->dev,
9498 h->reply_queue_size,
9499 &h->reply_queue[i].busaddr,
9501 if (!h->reply_queue[i].head) {
9505 h->reply_queue[i].size = h->max_commands;
9506 h->reply_queue[i].wraparound = 1; /* spec: init to 1 */
9507 h->reply_queue[i].current_entry = 0;
9511 h->blockFetchTable = kmalloc(((SG_ENTRIES_IN_CMD + 1) *
9513 if (!h->blockFetchTable) {
9518 rc = hpsa_enter_performant_mode(h, trans_support);
9524 kfree(h->blockFetchTable);
9525 h->blockFetchTable = NULL;
9527 hpsa_free_reply_queues(h);
9528 hpsa_free_ioaccel1_cmd_and_bft(h);
9529 hpsa_free_ioaccel2_cmd_and_bft(h);
9538 static void hpsa_drain_accel_commands(struct ctlr_info *h)
9546 for (i = 0; i < h->nr_cmds; i++) {
9547 c = h->cmd_pool + i;
9551 cmd_free(h, c);
9723 *hpsa_find_device_by_sas_rphy(struct ctlr_info *h,
9729 for (i = 0; i < h->ndevices; i++) {
9730 device = h->dev[i];
9740 static int hpsa_add_sas_host(struct ctlr_info *h)
9748 parent_dev = &h->scsi_host->shost_dev;
9754 hpsa_sas_port = hpsa_alloc_sas_port(hpsa_sas_node, h->sas_address);
9770 h->sas_host = hpsa_sas_node;
9785 static void hpsa_delete_sas_host(struct ctlr_info *h)
9787 hpsa_free_sas_node(h->sas_host);
9843 struct ctlr_info *h;
9849 h = shost_to_hba(shost);
9851 if (!h)
9854 sd = hpsa_find_device_by_sas_rphy(h, rphy);