574
580
0x409D0E11, /* Smart Array 6400 EM */
577
static int ctlr_is_resettable(struct ctlr_info *h)
583
/* List of controllers which cannot even be soft reset */
584
static u32 soft_unresettable_controller[] = {
585
0x409C0E11, /* Smart Array 6400 */
586
0x409D0E11, /* Smart Array 6400 EM */
589
static int ctlr_is_hard_resettable(u32 board_id)
581
593
for (i = 0; i < ARRAY_SIZE(unresettable_controller); i++)
582
if (unresettable_controller[i] == h->board_id)
594
if (unresettable_controller[i] == board_id)
599
static int ctlr_is_soft_resettable(u32 board_id)
603
for (i = 0; i < ARRAY_SIZE(soft_unresettable_controller); i++)
604
if (soft_unresettable_controller[i] == board_id)
609
static int ctlr_is_resettable(u32 board_id)
611
return ctlr_is_hard_resettable(board_id) ||
612
ctlr_is_soft_resettable(board_id);
587
615
static ssize_t host_show_resettable(struct device *dev,
2646
static int __devinit cciss_send_reset(ctlr_info_t *h, unsigned char *scsi3addr,
2649
CommandList_struct *c;
2655
return_status = fill_cmd(h, c, CCISS_RESET_MSG, NULL, 0, 0,
2656
CTLR_LUNID, TYPE_MSG);
2657
c->Request.CDB[1] = reset_type; /* fill_cmd defaults to target reset */
2658
if (return_status != IO_OK) {
2659
cmd_special_free(h, c);
2660
return return_status;
2663
enqueue_cmd_and_start_io(h, c);
2664
/* Don't wait for completion, the reset won't complete. Don't free
2665
* the command either. This is the last command we will send before
2666
* re-initializing everything, so it doesn't matter and won't leak.
2618
2671
static int check_target_status(ctlr_info_t *h, CommandList_struct *c)
2620
2673
switch (c->err_info->ScsiStatus) {
3461
3514
return next_command(h);
3517
/* Some controllers, like p400, will give us one interrupt
3518
* after a soft reset, even if we turned interrupts off.
3519
* Only need to check for this in the cciss_xxx_discard_completions
3522
static int ignore_bogus_interrupt(ctlr_info_t *h)
3524
if (likely(!reset_devices))
3527
if (likely(h->interrupts_enabled))
3530
dev_info(&h->pdev->dev, "Received interrupt while interrupts disabled "
3531
"(known firmware bug.) Ignoring.\n");
3536
static irqreturn_t cciss_intx_discard_completions(int irq, void *dev_id)
3538
ctlr_info_t *h = dev_id;
3539
unsigned long flags;
3542
if (ignore_bogus_interrupt(h))
3545
if (interrupt_not_for_us(h))
3547
spin_lock_irqsave(&h->lock, flags);
3548
while (interrupt_pending(h)) {
3549
raw_tag = get_next_completion(h);
3550
while (raw_tag != FIFO_EMPTY)
3551
raw_tag = next_command(h);
3553
spin_unlock_irqrestore(&h->lock, flags);
3557
static irqreturn_t cciss_msix_discard_completions(int irq, void *dev_id)
3559
ctlr_info_t *h = dev_id;
3560
unsigned long flags;
3563
if (ignore_bogus_interrupt(h))
3566
spin_lock_irqsave(&h->lock, flags);
3567
raw_tag = get_next_completion(h);
3568
while (raw_tag != FIFO_EMPTY)
3569
raw_tag = next_command(h);
3570
spin_unlock_irqrestore(&h->lock, flags);
3464
3574
static irqreturn_t do_cciss_intx(int irq, void *dev_id)
3466
3576
ctlr_info_t *h = dev_id;
4422
4533
pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
4423
4534
pmcsr |= PCI_D0;
4424
4535
pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
4540
static __devinit void init_driver_version(char *driver_version, int len)
4542
memset(driver_version, 0, len);
4543
strncpy(driver_version, "cciss " DRIVER_NAME, len - 1);
4546
static __devinit int write_driver_ver_to_cfgtable(
4547
CfgTable_struct __iomem *cfgtable)
4549
char *driver_version;
4550
int i, size = sizeof(cfgtable->driver_version);
4552
driver_version = kmalloc(size, GFP_KERNEL);
4553
if (!driver_version)
4556
init_driver_version(driver_version, size);
4557
for (i = 0; i < size; i++)
4558
writeb(driver_version[i], &cfgtable->driver_version[i]);
4559
kfree(driver_version);
4563
static __devinit void read_driver_ver_from_cfgtable(
4564
CfgTable_struct __iomem *cfgtable, unsigned char *driver_ver)
4568
for (i = 0; i < sizeof(cfgtable->driver_version); i++)
4569
driver_ver[i] = readb(&cfgtable->driver_version[i]);
4572
static __devinit int controller_reset_failed(
4573
CfgTable_struct __iomem *cfgtable)
4576
char *driver_ver, *old_driver_ver;
4577
int rc, size = sizeof(cfgtable->driver_version);
4579
old_driver_ver = kmalloc(2 * size, GFP_KERNEL);
4580
if (!old_driver_ver)
4582
driver_ver = old_driver_ver + size;
4584
/* After a reset, the 32 bytes of "driver version" in the cfgtable
4585
* should have been changed, otherwise we know the reset failed.
4587
init_driver_version(old_driver_ver, size);
4588
read_driver_ver_from_cfgtable(cfgtable, driver_ver);
4589
rc = !memcmp(driver_ver, old_driver_ver, size);
4590
kfree(old_driver_ver);
4431
4594
/* This does a hard reset of the controller using PCI power management
4432
4595
* states or using the doorbell register. */
4433
4596
static __devinit int cciss_kdump_hard_reset_controller(struct pci_dev *pdev)
4498
4665
goto unmap_vaddr;
4667
rc = write_driver_ver_to_cfgtable(cfgtable);
4501
/* If reset via doorbell register is supported, use that. */
4671
/* If reset via doorbell register is supported, use that.
4672
* There are two such methods. Favor the newest method.
4502
4674
misc_fw_support = readl(&cfgtable->misc_fw_support);
4503
use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET;
4505
/* The doorbell reset seems to cause lockups on some Smart
4506
* Arrays (e.g. P410, P410i, maybe others). Until this is
4507
* fixed or at least isolated, avoid the doorbell reset.
4675
use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET2;
4677
use_doorbell = DOORBELL_CTLR_RESET2;
4679
use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET;
4681
dev_warn(&pdev->dev, "Controller claims that "
4682
"'Bit 2 doorbell reset' is "
4683
"supported, but not 'bit 5 doorbell reset'. "
4684
"Firmware update is recommended.\n");
4685
rc = -ENOTSUPP; /* use the soft reset */
4686
goto unmap_cfgtable;
4511
4690
rc = cciss_controller_hard_reset(pdev, vaddr, use_doorbell);
4524
4703
msleep(CCISS_POST_RESET_PAUSE_MSECS);
4526
4705
/* Wait for board to become not ready, then ready. */
4527
dev_info(&pdev->dev, "Waiting for board to become ready.\n");
4706
dev_info(&pdev->dev, "Waiting for board to reset.\n");
4528
4707
rc = cciss_wait_for_board_state(pdev, vaddr, BOARD_NOT_READY);
4529
if (rc) /* Don't bail, might be E500, etc. which can't be reset */
4530
dev_warn(&pdev->dev,
4531
"failed waiting for board to become not ready\n");
4709
dev_warn(&pdev->dev, "Failed waiting for board to hard reset."
4710
" Will try soft reset.\n");
4711
rc = -ENOTSUPP; /* Not expected, but try soft reset later */
4712
goto unmap_cfgtable;
4532
4714
rc = cciss_wait_for_board_state(pdev, vaddr, BOARD_READY);
4534
4716
dev_warn(&pdev->dev,
4535
"failed waiting for board to become ready\n");
4717
"failed waiting for board to become ready "
4718
"after hard reset\n");
4536
4719
goto unmap_cfgtable;
4538
dev_info(&pdev->dev, "board ready.\n");
4540
/* Controller should be in simple mode at this point. If it's not,
4541
* It means we're on one of those controllers which doesn't support
4542
* the doorbell reset method and on which the PCI power management reset
4543
* method doesn't work (P800, for example.)
4544
* In those cases, don't try to proceed, as it generally doesn't work.
4546
active_transport = readl(&cfgtable->TransportActive);
4547
if (active_transport & PERFORMANT_MODE) {
4548
dev_warn(&pdev->dev, "Unable to successfully reset controller,"
4549
" Ignoring controller.\n");
4722
rc = controller_reset_failed(vaddr);
4724
goto unmap_cfgtable;
4726
dev_warn(&pdev->dev, "Unable to successfully hard reset "
4727
"controller. Will try soft reset.\n");
4728
rc = -ENOTSUPP; /* Not expected, but try soft reset later */
4730
dev_info(&pdev->dev, "Board ready after hard reset.\n");
4553
4733
unmap_cfgtable:
4775
static __devinit int cciss_allocate_cmd_pool(ctlr_info_t *h)
4777
h->cmd_pool_bits = kmalloc(
4778
DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG) *
4779
sizeof(unsigned long), GFP_KERNEL);
4780
h->cmd_pool = pci_alloc_consistent(h->pdev,
4781
h->nr_cmds * sizeof(CommandList_struct),
4782
&(h->cmd_pool_dhandle));
4783
h->errinfo_pool = pci_alloc_consistent(h->pdev,
4784
h->nr_cmds * sizeof(ErrorInfo_struct),
4785
&(h->errinfo_pool_dhandle));
4786
if ((h->cmd_pool_bits == NULL)
4787
|| (h->cmd_pool == NULL)
4788
|| (h->errinfo_pool == NULL)) {
4789
dev_err(&h->pdev->dev, "out of memory");
4795
static __devinit int cciss_allocate_scatterlists(ctlr_info_t *h)
4799
/* zero it, so that on free we need not know how many were alloc'ed */
4800
h->scatter_list = kzalloc(h->max_commands *
4801
sizeof(struct scatterlist *), GFP_KERNEL);
4802
if (!h->scatter_list)
4805
for (i = 0; i < h->nr_cmds; i++) {
4806
h->scatter_list[i] = kmalloc(sizeof(struct scatterlist) *
4807
h->maxsgentries, GFP_KERNEL);
4808
if (h->scatter_list[i] == NULL) {
4809
dev_err(&h->pdev->dev, "could not allocate "
4817
static void cciss_free_scatterlists(ctlr_info_t *h)
4821
if (h->scatter_list) {
4822
for (i = 0; i < h->nr_cmds; i++)
4823
kfree(h->scatter_list[i]);
4824
kfree(h->scatter_list);
4828
static void cciss_free_cmd_pool(ctlr_info_t *h)
4830
kfree(h->cmd_pool_bits);
4832
pci_free_consistent(h->pdev,
4833
h->nr_cmds * sizeof(CommandList_struct),
4834
h->cmd_pool, h->cmd_pool_dhandle);
4835
if (h->errinfo_pool)
4836
pci_free_consistent(h->pdev,
4837
h->nr_cmds * sizeof(ErrorInfo_struct),
4838
h->errinfo_pool, h->errinfo_pool_dhandle);
4841
static int cciss_request_irq(ctlr_info_t *h,
4842
irqreturn_t (*msixhandler)(int, void *),
4843
irqreturn_t (*intxhandler)(int, void *))
4845
if (h->msix_vector || h->msi_vector) {
4846
if (!request_irq(h->intr[PERF_MODE_INT], msixhandler,
4847
IRQF_DISABLED, h->devname, h))
4849
dev_err(&h->pdev->dev, "Unable to get msi irq %d"
4850
" for %s\n", h->intr[PERF_MODE_INT],
4855
if (!request_irq(h->intr[PERF_MODE_INT], intxhandler,
4856
IRQF_DISABLED, h->devname, h))
4858
dev_err(&h->pdev->dev, "Unable to get irq %d for %s\n",
4859
h->intr[PERF_MODE_INT], h->devname);
4863
static int __devinit cciss_kdump_soft_reset(ctlr_info_t *h)
4865
if (cciss_send_reset(h, CTLR_LUNID, CCISS_RESET_TYPE_CONTROLLER)) {
4866
dev_warn(&h->pdev->dev, "Resetting array controller failed.\n");
4870
dev_info(&h->pdev->dev, "Waiting for board to soft reset.\n");
4871
if (cciss_wait_for_board_state(h->pdev, h->vaddr, BOARD_NOT_READY)) {
4872
dev_warn(&h->pdev->dev, "Soft reset had no effect.\n");
4876
dev_info(&h->pdev->dev, "Board reset, awaiting READY status.\n");
4877
if (cciss_wait_for_board_state(h->pdev, h->vaddr, BOARD_READY)) {
4878
dev_warn(&h->pdev->dev, "Board failed to become ready "
4879
"after soft reset.\n");
4886
static void cciss_undo_allocations_after_kdump_soft_reset(ctlr_info_t *h)
4890
free_irq(h->intr[PERF_MODE_INT], h);
4891
#ifdef CONFIG_PCI_MSI
4893
pci_disable_msix(h->pdev);
4894
else if (h->msi_vector)
4895
pci_disable_msi(h->pdev);
4896
#endif /* CONFIG_PCI_MSI */
4897
cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
4898
cciss_free_scatterlists(h);
4899
cciss_free_cmd_pool(h);
4900
kfree(h->blockFetchTable);
4902
pci_free_consistent(h->pdev, h->max_commands * sizeof(__u64),
4903
h->reply_pool, h->reply_pool_dhandle);
4905
iounmap(h->transtable);
4907
iounmap(h->cfgtable);
4910
unregister_blkdev(h->major, h->devname);
4911
cciss_destroy_hba_sysfs_entry(h);
4912
pci_release_regions(h->pdev);
4595
4918
* This is it. Find all the controllers and register them. I really hate
4596
4919
* stealing all these major device numbers.
4663
5004
/* make sure the board interrupts are off */
4664
5005
h->access.set_intr_mask(h, CCISS_INTR_OFF);
4665
if (h->msi_vector || h->msix_vector) {
4666
if (request_irq(h->intr[PERF_MODE_INT],
4668
IRQF_DISABLED, h->devname, h)) {
4669
dev_err(&h->pdev->dev, "Unable to get irq %d for %s\n",
4670
h->intr[PERF_MODE_INT], h->devname);
4674
if (request_irq(h->intr[PERF_MODE_INT], do_cciss_intx,
4675
IRQF_DISABLED, h->devname, h)) {
4676
dev_err(&h->pdev->dev, "Unable to get irq %d for %s\n",
4677
h->intr[PERF_MODE_INT], h->devname);
5006
rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
4682
5010
dev_info(&h->pdev->dev, "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n",
4683
5011
h->devname, pdev->device, pci_name(pdev),
4684
5012
h->intr[PERF_MODE_INT], dac ? "" : " not");
4687
kmalloc(DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG)
4688
* sizeof(unsigned long), GFP_KERNEL);
4689
h->cmd_pool = (CommandList_struct *)
4690
pci_alloc_consistent(h->pdev,
4691
h->nr_cmds * sizeof(CommandList_struct),
4692
&(h->cmd_pool_dhandle));
4693
h->errinfo_pool = (ErrorInfo_struct *)
4694
pci_alloc_consistent(h->pdev,
4695
h->nr_cmds * sizeof(ErrorInfo_struct),
4696
&(h->errinfo_pool_dhandle));
4697
if ((h->cmd_pool_bits == NULL)
4698
|| (h->cmd_pool == NULL)
4699
|| (h->errinfo_pool == NULL)) {
4700
dev_err(&h->pdev->dev, "out of memory");
4704
/* Need space for temp scatter list */
4705
h->scatter_list = kmalloc(h->max_commands *
4706
sizeof(struct scatterlist *),
4708
if (!h->scatter_list)
4711
for (k = 0; k < h->nr_cmds; k++) {
4712
h->scatter_list[k] = kmalloc(sizeof(struct scatterlist) *
4715
if (h->scatter_list[k] == NULL) {
4716
dev_err(&h->pdev->dev,
4717
"could not allocate s/g lists\n");
5014
if (cciss_allocate_cmd_pool(h))
5017
if (cciss_allocate_scatterlists(h))
4721
5020
h->cmd_sg_list = cciss_allocate_sg_chain_blocks(h,
4722
5021
h->chainsize, h->nr_cmds);
4723
5022
if (!h->cmd_sg_list && h->chainsize > 0)
4741
5040
h->gendisk[j] = NULL;
5043
/* At this point, the controller is ready to take commands.
5044
* Now, if reset_devices and the hard reset didn't work, try
5045
* the soft reset and see if that works.
5047
if (try_soft_reset) {
5049
/* This is kind of gross. We may or may not get a completion
5050
* from the soft reset command, and if we do, then the value
5051
* from the fifo may or may not be valid. So, we wait 10 secs
5052
* after the reset throwing away any completions we get during
5053
* that time. Unregister the interrupt handler and register
5054
* fake ones to scoop up any residual completions.
5056
spin_lock_irqsave(&h->lock, flags);
5057
h->access.set_intr_mask(h, CCISS_INTR_OFF);
5058
spin_unlock_irqrestore(&h->lock, flags);
5059
free_irq(h->intr[PERF_MODE_INT], h);
5060
rc = cciss_request_irq(h, cciss_msix_discard_completions,
5061
cciss_intx_discard_completions);
5063
dev_warn(&h->pdev->dev, "Failed to request_irq after "
5068
rc = cciss_kdump_soft_reset(h);
5070
dev_warn(&h->pdev->dev, "Soft reset failed.\n");
5074
dev_info(&h->pdev->dev, "Board READY.\n");
5075
dev_info(&h->pdev->dev,
5076
"Waiting for stale completions to drain.\n");
5077
h->access.set_intr_mask(h, CCISS_INTR_ON);
5079
h->access.set_intr_mask(h, CCISS_INTR_OFF);
5081
rc = controller_reset_failed(h->cfgtable);
5083
dev_info(&h->pdev->dev,
5084
"Soft reset appears to have failed.\n");
5086
/* since the controller's reset, we have to go back and re-init
5087
* everything. Easiest to just forget what we've done and do it
5090
cciss_undo_allocations_after_kdump_soft_reset(h);
5093
/* don't go to clean4, we already unallocated */
5096
goto reinit_after_soft_reset;
4744
5099
cciss_scsi_setup(h);
4746
5101
/* Turn the interrupts on so we can service requests */
4778
kfree(h->cmd_pool_bits);
4779
/* Free up sg elements */
4780
for (k-- ; k >= 0; k--)
4781
kfree(h->scatter_list[k]);
4782
kfree(h->scatter_list);
5133
cciss_free_cmd_pool(h);
5134
cciss_free_scatterlists(h);
4783
5135
cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
4785
pci_free_consistent(h->pdev,
4786
h->nr_cmds * sizeof(CommandList_struct),
4787
h->cmd_pool, h->cmd_pool_dhandle);
4788
if (h->errinfo_pool)
4789
pci_free_consistent(h->pdev,
4790
h->nr_cmds * sizeof(ErrorInfo_struct),
4792
h->errinfo_pool_dhandle);
4793
5136
free_irq(h->intr[PERF_MODE_INT], h);
4795
5138
unregister_blkdev(h->major, h->devname);
4887
5230
iounmap(h->cfgtable);
4888
5231
iounmap(h->vaddr);
4890
pci_free_consistent(h->pdev, h->nr_cmds * sizeof(CommandList_struct),
4891
h->cmd_pool, h->cmd_pool_dhandle);
4892
pci_free_consistent(h->pdev, h->nr_cmds * sizeof(ErrorInfo_struct),
4893
h->errinfo_pool, h->errinfo_pool_dhandle);
4894
kfree(h->cmd_pool_bits);
5233
cciss_free_cmd_pool(h);
4895
5234
/* Free up sg elements */
4896
5235
for (j = 0; j < h->nr_cmds; j++)
4897
5236
kfree(h->scatter_list[j]);
4898
5237
kfree(h->scatter_list);
4899
5238
cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
5239
kfree(h->blockFetchTable);
5241
pci_free_consistent(h->pdev, h->max_commands * sizeof(__u64),
5242
h->reply_pool, h->reply_pool_dhandle);
4901
5244
* Deliberately omit pci_disable_device(): it does something nasty to
4902
5245
* Smart Array controllers that pci_enable_device does not undo