hpsa.c (03383736348bb73a45f8460afca3c5f5bd1be172) | hpsa.c (281a7fd03ea37c979bbba4d8376595c0288e3252) |
---|---|
1/* 2 * Disk Array driver for HP Smart Array SAS controllers 3 * Copyright 2000, 2014 Hewlett-Packard Development Company, L.P. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 2 of the License. 8 * --- 4538 unchanged lines hidden (view full) --- 4547 int i, rc; 4548 struct ctlr_info *h; 4549 struct hpsa_scsi_dev_t *dev; 4550 struct CommandList *abort; /* pointer to command to be aborted */ 4551 struct scsi_cmnd *as; /* ptr to scsi cmd inside aborted command. */ 4552 char msg[256]; /* For debug messaging. */ 4553 int ml = 0; 4554 __le32 tagupper, taglower; | 1/* 2 * Disk Array driver for HP Smart Array SAS controllers 3 * Copyright 2000, 2014 Hewlett-Packard Development Company, L.P. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 2 of the License. 8 * --- 4538 unchanged lines hidden (view full) --- 4547 int i, rc; 4548 struct ctlr_info *h; 4549 struct hpsa_scsi_dev_t *dev; 4550 struct CommandList *abort; /* pointer to command to be aborted */ 4551 struct scsi_cmnd *as; /* ptr to scsi cmd inside aborted command. */ 4552 char msg[256]; /* For debug messaging. */ 4553 int ml = 0; 4554 __le32 tagupper, taglower; |
4555 int refcount; |
|
4555 4556 /* Find the controller of the command to be aborted */ 4557 h = sdev_to_hba(sc->device); 4558 if (WARN(h == NULL, 4559 "ABORT REQUEST FAILED, Controller lookup failed.\n")) 4560 return FAILED; 4561 4562 /* Check that controller supports some kind of task abort */ --- 12 unchanged lines hidden (view full) --- 4575 dev_err(&h->pdev->dev, "%s FAILED, Device lookup failed.\n", 4576 msg); 4577 return FAILED; 4578 } 4579 4580 /* Get SCSI command to be aborted */ 4581 abort = (struct CommandList *) sc->host_scribble; 4582 if (abort == NULL) { | 4556 4557 /* Find the controller of the command to be aborted */ 4558 h = sdev_to_hba(sc->device); 4559 if (WARN(h == NULL, 4560 "ABORT REQUEST FAILED, Controller lookup failed.\n")) 4561 return FAILED; 4562 4563 /* Check that controller supports some kind of task abort */ --- 12 unchanged lines hidden (view full) --- 4576 dev_err(&h->pdev->dev, "%s FAILED, Device lookup failed.\n", 4577 msg); 4578 return FAILED; 4579 } 4580 4581 /* Get SCSI command to be aborted */ 4582 abort = (struct CommandList *) sc->host_scribble; 4583 if (abort == NULL) { |
4583 dev_err(&h->pdev->dev, "%s FAILED, Command to abort is NULL.\n", 4584 msg); 4585 return FAILED; | 4584 /* This can happen if the command already completed. */ 4585 return SUCCESS; |
4586 } | 4586 } |
4587 refcount = atomic_inc_return(&abort->refcount); 4588 if (refcount == 1) { /* Command is done already. */ 4589 cmd_free(h, abort); 4590 return SUCCESS; 4591 } |
|
4587 hpsa_get_tag(h, abort, &taglower, &tagupper); 4588 ml += sprintf(msg+ml, "Tag:0x%08x:%08x ", tagupper, taglower); 4589 as = (struct scsi_cmnd *) abort->scsi_cmd; 4590 if (as != NULL) 4591 ml += sprintf(msg+ml, "Command:0x%x SN:0x%lx ", 4592 as->cmnd[0], as->serial_number); 4593 dev_dbg(&h->pdev->dev, "%s\n", msg); 4594 dev_warn(&h->pdev->dev, "Abort request on C%d:B%d:T%d:L%d\n", --- 4 unchanged lines hidden (view full) --- 4599 * distinguish which. Send the abort down. 4600 */ 4601 rc = hpsa_send_abort_both_ways(h, dev->scsi3addr, abort); 4602 if (rc != 0) { 4603 dev_dbg(&h->pdev->dev, "%s Request FAILED.\n", msg); 4604 dev_warn(&h->pdev->dev, "FAILED abort on device C%d:B%d:T%d:L%d\n", 4605 h->scsi_host->host_no, 4606 dev->bus, dev->target, dev->lun); | 4592 hpsa_get_tag(h, abort, &taglower, &tagupper); 4593 ml += sprintf(msg+ml, "Tag:0x%08x:%08x ", tagupper, taglower); 4594 as = (struct scsi_cmnd *) abort->scsi_cmd; 4595 if (as != NULL) 4596 ml += sprintf(msg+ml, "Command:0x%x SN:0x%lx ", 4597 as->cmnd[0], as->serial_number); 4598 dev_dbg(&h->pdev->dev, "%s\n", msg); 4599 dev_warn(&h->pdev->dev, "Abort request on C%d:B%d:T%d:L%d\n", --- 4 unchanged lines hidden (view full) --- 4604 * distinguish which. Send the abort down. 4605 */ 4606 rc = hpsa_send_abort_both_ways(h, dev->scsi3addr, abort); 4607 if (rc != 0) { 4608 dev_dbg(&h->pdev->dev, "%s Request FAILED.\n", msg); 4609 dev_warn(&h->pdev->dev, "FAILED abort on device C%d:B%d:T%d:L%d\n", 4610 h->scsi_host->host_no, 4611 dev->bus, dev->target, dev->lun); |
4612 cmd_free(h, abort); |
|
4607 return FAILED; 4608 } 4609 dev_info(&h->pdev->dev, "%s REQUEST SUCCEEDED.\n", msg); 4610 4611 /* If the abort(s) above completed and actually aborted the 4612 * command, then the command to be aborted should already be 4613 * completed. If not, wait around a bit more to see if they 4614 * manage to complete normally. 4615 */ 4616#define ABORT_COMPLETE_WAIT_SECS 30 4617 for (i = 0; i < ABORT_COMPLETE_WAIT_SECS * 10; i++) { | 4613 return FAILED; 4614 } 4615 dev_info(&h->pdev->dev, "%s REQUEST SUCCEEDED.\n", msg); 4616 4617 /* If the abort(s) above completed and actually aborted the 4618 * command, then the command to be aborted should already be 4619 * completed. If not, wait around a bit more to see if they 4620 * manage to complete normally. 4621 */ 4622#define ABORT_COMPLETE_WAIT_SECS 30 4623 for (i = 0; i < ABORT_COMPLETE_WAIT_SECS * 10; i++) { |
4618 if (test_bit(abort->cmdindex & (BITS_PER_LONG - 1), 4619 h->cmd_pool_bits + 4620 (abort->cmdindex / BITS_PER_LONG))) 4621 msleep(100); 4622 else | 4624 refcount = atomic_read(&abort->refcount); 4625 if (refcount < 2) { 4626 cmd_free(h, abort); |
4623 return SUCCESS; | 4627 return SUCCESS; |
4628 } else { 4629 msleep(100); 4630 } |
|
4624 } 4625 dev_warn(&h->pdev->dev, "%s FAILED. Aborted command has not completed after %d seconds.\n", 4626 msg, ABORT_COMPLETE_WAIT_SECS); | 4631 } 4632 dev_warn(&h->pdev->dev, "%s FAILED. Aborted command has not completed after %d seconds.\n", 4633 msg, ABORT_COMPLETE_WAIT_SECS); |
4634 cmd_free(h, abort); |
|
4627 return FAILED; 4628} 4629 | 4635 return FAILED; 4636} 4637 |
4630 | |
4631/* 4632 * For operations that cannot sleep, a command block is allocated at init, 4633 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track 4634 * which ones are free or in use. Lock must be held when calling this. 4635 * cmd_free() is the complement. 4636 */ | 4638/* 4639 * For operations that cannot sleep, a command block is allocated at init, 4640 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track 4641 * which ones are free or in use. Lock must be held when calling this. 4642 * cmd_free() is the complement. 4643 */ |
4644 |
|
4637static struct CommandList *cmd_alloc(struct ctlr_info *h) 4638{ 4639 struct CommandList *c; 4640 int i; 4641 union u64bit temp64; 4642 dma_addr_t cmd_dma_handle, err_dma_handle; | 4645static struct CommandList *cmd_alloc(struct ctlr_info *h) 4646{ 4647 struct CommandList *c; 4648 int i; 4649 union u64bit temp64; 4650 dma_addr_t cmd_dma_handle, err_dma_handle; |
4643 int loopcount; | 4651 int refcount; 4652 unsigned long offset = 0; |
4644 4645 /* There is some *extremely* small but non-zero chance that that 4646 * multiple threads could get in here, and one thread could 4647 * be scanning through the list of bits looking for a free 4648 * one, but the free ones are always behind him, and other 4649 * threads sneak in behind him and eat them before he can 4650 * get to them, so that while there is always a free one, a 4651 * very unlucky thread might be starved anyway, never able to 4652 * beat the other threads. In reality, this happens so 4653 * infrequently as to be indistinguishable from never. 4654 */ 4655 | 4653 4654 /* There is some *extremely* small but non-zero chance that that 4655 * multiple threads could get in here, and one thread could 4656 * be scanning through the list of bits looking for a free 4657 * one, but the free ones are always behind him, and other 4658 * threads sneak in behind him and eat them before he can 4659 * get to them, so that while there is always a free one, a 4660 * very unlucky thread might be starved anyway, never able to 4661 * beat the other threads. In reality, this happens so 4662 * infrequently as to be indistinguishable from never. 4663 */ 4664 |
4656 loopcount = 0; 4657 do { 4658 i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds); 4659 if (i == h->nr_cmds) 4660 i = 0; 4661 loopcount++; 4662 } while (test_and_set_bit(i & (BITS_PER_LONG - 1), 4663 h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0 && 4664 loopcount < 10); | 4665 for (;;) { 4666 i = find_next_zero_bit(h->cmd_pool_bits, h->nr_cmds, offset); 4667 if (unlikely(i == h->nr_cmds)) { 4668 offset = 0; 4669 continue; 4670 } 4671 c = h->cmd_pool + i; 4672 refcount = atomic_inc_return(&c->refcount); 4673 if (unlikely(refcount > 1)) { 4674 cmd_free(h, c); /* already in use */ 4675 offset = (i + 1) % h->nr_cmds; 4676 continue; 4677 } 4678 set_bit(i & (BITS_PER_LONG - 1), 4679 h->cmd_pool_bits + (i / BITS_PER_LONG)); 4680 break; /* it's ours now. */ 4681 } |
4665 | 4682 |
4666 /* Thread got starved? We do not expect this to ever happen. */ 4667 if (loopcount >= 10) 4668 return NULL; 4669 4670 c = h->cmd_pool + i; 4671 memset(c, 0, sizeof(*c)); 4672 c->Header.tag = cpu_to_le64((u64) i << DIRECT_LOOKUP_SHIFT); | 4683 /* Zero out all of commandlist except the last field, refcount */ 4684 memset(c, 0, offsetof(struct CommandList, refcount)); 4685 c->Header.tag = cpu_to_le64((u64) (i << DIRECT_LOOKUP_SHIFT)); |
4673 cmd_dma_handle = h->cmd_pool_dhandle + i * sizeof(*c); 4674 c->err_info = h->errinfo_pool + i; 4675 memset(c->err_info, 0, sizeof(*c->err_info)); 4676 err_dma_handle = h->errinfo_pool_dhandle 4677 + i * sizeof(*c->err_info); 4678 4679 c->cmdindex = i; 4680 4681 c->busaddr = (u32) cmd_dma_handle; 4682 temp64.val = (u64) err_dma_handle; | 4686 cmd_dma_handle = h->cmd_pool_dhandle + i * sizeof(*c); 4687 c->err_info = h->errinfo_pool + i; 4688 memset(c->err_info, 0, sizeof(*c->err_info)); 4689 err_dma_handle = h->errinfo_pool_dhandle 4690 + i * sizeof(*c->err_info); 4691 4692 c->cmdindex = i; 4693 4694 c->busaddr = (u32) cmd_dma_handle; 4695 temp64.val = (u64) err_dma_handle; |
4683 c->ErrDesc.Addr = cpu_to_le64(err_dma_handle); 4684 c->ErrDesc.Len = cpu_to_le32(sizeof(*c->err_info)); | 4696 c->ErrDesc.Addr = cpu_to_le64((u64) err_dma_handle); 4697 c->ErrDesc.Len = cpu_to_le32((u32) sizeof(*c->err_info)); |
4685 4686 c->h = h; 4687 return c; 4688} 4689 4690static void cmd_free(struct ctlr_info *h, struct CommandList *c) 4691{ | 4698 4699 c->h = h; 4700 return c; 4701} 4702 4703static void cmd_free(struct ctlr_info *h, struct CommandList *c) 4704{ |
4692 int i; | 4705 if (atomic_dec_and_test(&c->refcount)) { 4706 int i; |
4693 | 4707 |
4694 i = c - h->cmd_pool; 4695 clear_bit(i & (BITS_PER_LONG - 1), 4696 h->cmd_pool_bits + (i / BITS_PER_LONG)); | 4708 i = c - h->cmd_pool; 4709 clear_bit(i & (BITS_PER_LONG - 1), 4710 h->cmd_pool_bits + (i / BITS_PER_LONG)); 4711 } |
4697} 4698 4699#ifdef CONFIG_COMPAT 4700 4701static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, 4702 void __user *arg) 4703{ 4704 IOCTL32_Command_struct __user *arg32 = --- 1888 unchanged lines hidden (view full) --- 6593 pci_disable_device(h->pdev); 6594 pci_release_regions(h->pdev); 6595 kfree(h); 6596} 6597 6598/* Called when controller lockup detected. */ 6599static void fail_all_outstanding_cmds(struct ctlr_info *h) 6600{ | 4712} 4713 4714#ifdef CONFIG_COMPAT 4715 4716static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, 4717 void __user *arg) 4718{ 4719 IOCTL32_Command_struct __user *arg32 = --- 1888 unchanged lines hidden (view full) --- 6608 pci_disable_device(h->pdev); 6609 pci_release_regions(h->pdev); 6610 kfree(h); 6611} 6612 6613/* Called when controller lockup detected. */ 6614static void fail_all_outstanding_cmds(struct ctlr_info *h) 6615{ |
6601 int i; 6602 struct CommandList *c = NULL; | 6616 int i, refcount; 6617 struct CommandList *c; |
6603 6604 flush_workqueue(h->resubmit_wq); /* ensure all cmds are fully built */ 6605 for (i = 0; i < h->nr_cmds; i++) { | 6618 6619 flush_workqueue(h->resubmit_wq); /* ensure all cmds are fully built */ 6620 for (i = 0; i < h->nr_cmds; i++) { |
6606 if (!test_bit(i & (BITS_PER_LONG - 1), 6607 h->cmd_pool_bits + (i / BITS_PER_LONG))) 6608 continue; | |
6609 c = h->cmd_pool + i; | 6621 c = h->cmd_pool + i; |
6610 c->err_info->CommandStatus = CMD_HARDWARE_ERR; 6611 finish_cmd(c); | 6622 refcount = atomic_inc_return(&c->refcount); 6623 if (refcount > 1) { 6624 c->err_info->CommandStatus = CMD_HARDWARE_ERR; 6625 finish_cmd(c); 6626 } 6627 cmd_free(h, c); |
6612 } 6613} 6614 6615static void set_lockup_detected_for_all_cpus(struct ctlr_info *h, u32 value) 6616{ 6617 int i, cpu; 6618 6619 cpu = cpumask_first(cpu_online_mask); --- 20 unchanged lines hidden (view full) --- 6640 "lockup detected but scratchpad register is zero\n"); 6641 lockup_detected = 0xffffffff; 6642 } 6643 set_lockup_detected_for_all_cpus(h, lockup_detected); 6644 spin_unlock_irqrestore(&h->lock, flags); 6645 dev_warn(&h->pdev->dev, "Controller lockup detected: 0x%08x\n", 6646 lockup_detected); 6647 pci_disable_device(h->pdev); | 6628 } 6629} 6630 6631static void set_lockup_detected_for_all_cpus(struct ctlr_info *h, u32 value) 6632{ 6633 int i, cpu; 6634 6635 cpu = cpumask_first(cpu_online_mask); --- 20 unchanged lines hidden (view full) --- 6656 "lockup detected but scratchpad register is zero\n"); 6657 lockup_detected = 0xffffffff; 6658 } 6659 set_lockup_detected_for_all_cpus(h, lockup_detected); 6660 spin_unlock_irqrestore(&h->lock, flags); 6661 dev_warn(&h->pdev->dev, "Controller lockup detected: 0x%08x\n", 6662 lockup_detected); 6663 pci_disable_device(h->pdev); |
6648 spin_lock_irqsave(&h->lock, flags); | |
6649 fail_all_outstanding_cmds(h); | 6664 fail_all_outstanding_cmds(h); |
6650 spin_unlock_irqrestore(&h->lock, flags); | |
6651} 6652 6653static void detect_controller_lockup(struct ctlr_info *h) 6654{ 6655 u64 now; 6656 u32 heartbeat; 6657 unsigned long flags; 6658 --- 785 unchanged lines hidden (view full) --- 7444{ 7445 return c->cmd_type == CMD_IOACCEL1 || c->cmd_type == CMD_IOACCEL2; 7446} 7447 7448static void hpsa_drain_accel_commands(struct ctlr_info *h) 7449{ 7450 struct CommandList *c = NULL; 7451 int i, accel_cmds_out; | 6665} 6666 6667static void detect_controller_lockup(struct ctlr_info *h) 6668{ 6669 u64 now; 6670 u32 heartbeat; 6671 unsigned long flags; 6672 --- 785 unchanged lines hidden (view full) --- 7458{ 7459 return c->cmd_type == CMD_IOACCEL1 || c->cmd_type == CMD_IOACCEL2; 7460} 7461 7462static void hpsa_drain_accel_commands(struct ctlr_info *h) 7463{ 7464 struct CommandList *c = NULL; 7465 int i, accel_cmds_out; |
7466 int refcount; |
|
7452 7453 do { /* wait for all outstanding ioaccel commands to drain out */ 7454 accel_cmds_out = 0; 7455 for (i = 0; i < h->nr_cmds; i++) { | 7467 7468 do { /* wait for all outstanding ioaccel commands to drain out */ 7469 accel_cmds_out = 0; 7470 for (i = 0; i < h->nr_cmds; i++) { |
7456 if (!test_bit(i & (BITS_PER_LONG - 1), 7457 h->cmd_pool_bits + (i / BITS_PER_LONG))) 7458 continue; | |
7459 c = h->cmd_pool + i; | 7471 c = h->cmd_pool + i; |
7460 accel_cmds_out += is_accelerated_cmd(c); | 7472 refcount = atomic_inc_return(&c->refcount); 7473 if (refcount > 1) /* Command is allocated */ 7474 accel_cmds_out += is_accelerated_cmd(c); 7475 cmd_free(h, c); |
7461 } 7462 if (accel_cmds_out <= 0) | 7476 } 7477 if (accel_cmds_out <= 0) |
7463 break; | 7478 break; |
7464 msleep(100); 7465 } while (1); 7466} 7467 7468/* 7469 * This is it. Register the PCI driver information for the cards we control 7470 * the OS will call our registered routines when it finds one of our cards. 7471 */ --- 90 unchanged lines hidden --- | 7479 msleep(100); 7480 } while (1); 7481} 7482 7483/* 7484 * This is it. Register the PCI driver information for the cards we control 7485 * the OS will call our registered routines when it finds one of our cards. 7486 */ --- 90 unchanged lines hidden --- |