aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.osdl.org>2006-11-16 14:48:01 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-11-16 14:48:01 -0500
commitd0cac32fa551b0e7dc1f014607eabb93b0ebbbe8 (patch)
treed6abb3575e8e7026d132aa1f17a48b557bc0b9de /drivers
parent626db29f31ce253726411182ff6c15e31efe2e9a (diff)
parent05052f7f130b1232faeee1674a5bc41f67746cff (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6: [SCSI] psi240i.c: fix an array overrun [SCSI] gdth: Fix && typos [SCSI] iscsi class: update version [SCSI] iscsi_tcp: fix xmittask oops [SCSI] iscsi: add newlines to debug messages [SCSI] iscsi: always release crypto [SCSI] sg: fix incorrect last scatg length [SCSI] 3ware 9000 add support for 9650SE [SCSI] aic94xx SCSI timeout fix: SMP retry fix. [SCSI] aic94xx SCSI timeout fix
Diffstat (limited to 'drivers')
-rw-r--r--drivers/scsi/3w-9xxx.c141
-rw-r--r--drivers/scsi/3w-9xxx.h14
-rw-r--r--drivers/scsi/aic94xx/aic94xx_hwi.c18
-rw-r--r--drivers/scsi/aic94xx/aic94xx_hwi.h12
-rw-r--r--drivers/scsi/aic94xx/aic94xx_init.c2
-rw-r--r--drivers/scsi/aic94xx/aic94xx_sas.h1
-rw-r--r--drivers/scsi/aic94xx/aic94xx_scb.c72
-rw-r--r--drivers/scsi/aic94xx/aic94xx_seq.c5
-rw-r--r--drivers/scsi/aic94xx/aic94xx_seq.h2
-rw-r--r--drivers/scsi/gdth.c4
-rw-r--r--drivers/scsi/iscsi_tcp.c22
-rw-r--r--drivers/scsi/libiscsi.c9
-rw-r--r--drivers/scsi/libsas/sas_expander.c84
-rw-r--r--drivers/scsi/psi240i.c2
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c2
-rw-r--r--drivers/scsi/sg.c25
16 files changed, 278 insertions, 137 deletions
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 5f8c26cd66ca..b091a0fc4eb0 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -66,6 +66,9 @@
66 2.26.02.006 - Fix 9550SX pchip reset timeout. 66 2.26.02.006 - Fix 9550SX pchip reset timeout.
67 Add big endian support. 67 Add big endian support.
68 2.26.02.007 - Disable local interrupts during kmap/unmap_atomic(). 68 2.26.02.007 - Disable local interrupts during kmap/unmap_atomic().
69 2.26.02.008 - Free irq handler in __twa_shutdown().
70 Serialize reset code.
71 Add support for 9650SE controllers.
69*/ 72*/
70 73
71#include <linux/module.h> 74#include <linux/module.h>
@@ -89,7 +92,7 @@
89#include "3w-9xxx.h" 92#include "3w-9xxx.h"
90 93
91/* Globals */ 94/* Globals */
92#define TW_DRIVER_VERSION "2.26.02.007" 95#define TW_DRIVER_VERSION "2.26.02.008"
93static TW_Device_Extension *twa_device_extension_list[TW_MAX_SLOT]; 96static TW_Device_Extension *twa_device_extension_list[TW_MAX_SLOT];
94static unsigned int twa_device_extension_count; 97static unsigned int twa_device_extension_count;
95static int twa_major = -1; 98static int twa_major = -1;
@@ -566,9 +569,9 @@ static int twa_check_srl(TW_Device_Extension *tw_dev, int *flashed)
566 goto out; 569 goto out;
567 } 570 }
568 571
569 tw_dev->working_srl = fw_on_ctlr_srl; 572 tw_dev->tw_compat_info.working_srl = fw_on_ctlr_srl;
570 tw_dev->working_branch = fw_on_ctlr_branch; 573 tw_dev->tw_compat_info.working_branch = fw_on_ctlr_branch;
571 tw_dev->working_build = fw_on_ctlr_build; 574 tw_dev->tw_compat_info.working_build = fw_on_ctlr_build;
572 575
573 /* Try base mode compatibility */ 576 /* Try base mode compatibility */
574 if (!(init_connect_result & TW_CTLR_FW_COMPATIBLE)) { 577 if (!(init_connect_result & TW_CTLR_FW_COMPATIBLE)) {
@@ -590,10 +593,23 @@ static int twa_check_srl(TW_Device_Extension *tw_dev, int *flashed)
590 } 593 }
591 goto out; 594 goto out;
592 } 595 }
593 tw_dev->working_srl = TW_BASE_FW_SRL; 596 tw_dev->tw_compat_info.working_srl = TW_BASE_FW_SRL;
594 tw_dev->working_branch = TW_BASE_FW_BRANCH; 597 tw_dev->tw_compat_info.working_branch = TW_BASE_FW_BRANCH;
595 tw_dev->working_build = TW_BASE_FW_BUILD; 598 tw_dev->tw_compat_info.working_build = TW_BASE_FW_BUILD;
596 } 599 }
600
601 /* Load rest of compatibility struct */
602 strncpy(tw_dev->tw_compat_info.driver_version, TW_DRIVER_VERSION, strlen(TW_DRIVER_VERSION));
603 tw_dev->tw_compat_info.driver_srl_high = TW_CURRENT_DRIVER_SRL;
604 tw_dev->tw_compat_info.driver_branch_high = TW_CURRENT_DRIVER_BRANCH;
605 tw_dev->tw_compat_info.driver_build_high = TW_CURRENT_DRIVER_BUILD;
606 tw_dev->tw_compat_info.driver_srl_low = TW_BASE_FW_SRL;
607 tw_dev->tw_compat_info.driver_branch_low = TW_BASE_FW_BRANCH;
608 tw_dev->tw_compat_info.driver_build_low = TW_BASE_FW_BUILD;
609 tw_dev->tw_compat_info.fw_on_ctlr_srl = fw_on_ctlr_srl;
610 tw_dev->tw_compat_info.fw_on_ctlr_branch = fw_on_ctlr_branch;
611 tw_dev->tw_compat_info.fw_on_ctlr_build = fw_on_ctlr_build;
612
597 retval = 0; 613 retval = 0;
598out: 614out:
599 return retval; 615 return retval;
@@ -631,7 +647,7 @@ static int twa_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int
631 goto out2; 647 goto out2;
632 648
633 /* Check data buffer size */ 649 /* Check data buffer size */
634 if (driver_command.buffer_length > TW_MAX_SECTORS * 512) { 650 if (driver_command.buffer_length > TW_MAX_SECTORS * 2048) {
635 retval = TW_IOCTL_ERROR_OS_EINVAL; 651 retval = TW_IOCTL_ERROR_OS_EINVAL;
636 goto out2; 652 goto out2;
637 } 653 }
@@ -680,13 +696,6 @@ static int twa_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int
680 /* Now wait for command to complete */ 696 /* Now wait for command to complete */
681 timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout); 697 timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout);
682 698
683 /* See if we reset while waiting for the ioctl to complete */
684 if (test_bit(TW_IN_RESET, &tw_dev->flags)) {
685 clear_bit(TW_IN_RESET, &tw_dev->flags);
686 retval = TW_IOCTL_ERROR_OS_ERESTARTSYS;
687 goto out3;
688 }
689
690 /* We timed out, and didn't get an interrupt */ 699 /* We timed out, and didn't get an interrupt */
691 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) { 700 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) {
692 /* Now we need to reset the board */ 701 /* Now we need to reset the board */
@@ -694,11 +703,6 @@ static int twa_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int
694 tw_dev->host->host_no, TW_DRIVER, 0xc, 703 tw_dev->host->host_no, TW_DRIVER, 0xc,
695 cmd); 704 cmd);
696 retval = TW_IOCTL_ERROR_OS_EIO; 705 retval = TW_IOCTL_ERROR_OS_EIO;
697 spin_lock_irqsave(tw_dev->host->host_lock, flags);
698 tw_dev->state[request_id] = TW_S_COMPLETED;
699 twa_free_request_id(tw_dev, request_id);
700 tw_dev->posted_request_count--;
701 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
702 twa_reset_device_extension(tw_dev, 1); 706 twa_reset_device_extension(tw_dev, 1);
703 goto out3; 707 goto out3;
704 } 708 }
@@ -717,16 +721,7 @@ static int twa_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int
717 tw_ioctl->driver_command.status = 0; 721 tw_ioctl->driver_command.status = 0;
718 /* Copy compatiblity struct into ioctl data buffer */ 722 /* Copy compatiblity struct into ioctl data buffer */
719 tw_compat_info = (TW_Compatibility_Info *)tw_ioctl->data_buffer; 723 tw_compat_info = (TW_Compatibility_Info *)tw_ioctl->data_buffer;
720 strncpy(tw_compat_info->driver_version, TW_DRIVER_VERSION, strlen(TW_DRIVER_VERSION)); 724 memcpy(tw_compat_info, &tw_dev->tw_compat_info, sizeof(TW_Compatibility_Info));
721 tw_compat_info->working_srl = tw_dev->working_srl;
722 tw_compat_info->working_branch = tw_dev->working_branch;
723 tw_compat_info->working_build = tw_dev->working_build;
724 tw_compat_info->driver_srl_high = TW_CURRENT_DRIVER_SRL;
725 tw_compat_info->driver_branch_high = TW_CURRENT_DRIVER_BRANCH;
726 tw_compat_info->driver_build_high = TW_CURRENT_DRIVER_BUILD;
727 tw_compat_info->driver_srl_low = TW_BASE_FW_SRL;
728 tw_compat_info->driver_branch_low = TW_BASE_FW_BRANCH;
729 tw_compat_info->driver_build_low = TW_BASE_FW_BUILD;
730 break; 725 break;
731 case TW_IOCTL_GET_LAST_EVENT: 726 case TW_IOCTL_GET_LAST_EVENT:
732 if (tw_dev->event_queue_wrapped) { 727 if (tw_dev->event_queue_wrapped) {
@@ -895,7 +890,8 @@ static int twa_decode_bits(TW_Device_Extension *tw_dev, u32 status_reg_value)
895 } 890 }
896 891
897 if (status_reg_value & TW_STATUS_QUEUE_ERROR) { 892 if (status_reg_value & TW_STATUS_QUEUE_ERROR) {
898 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xe, "Controller Queue Error: clearing"); 893 if ((tw_dev->tw_pci_dev->device != PCI_DEVICE_ID_3WARE_9650SE) || (!test_bit(TW_IN_RESET, &tw_dev->flags)))
894 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xe, "Controller Queue Error: clearing");
899 writel(TW_CONTROL_CLEAR_QUEUE_ERROR, TW_CONTROL_REG_ADDR(tw_dev)); 895 writel(TW_CONTROL_CLEAR_QUEUE_ERROR, TW_CONTROL_REG_ADDR(tw_dev));
900 } 896 }
901 897
@@ -939,10 +935,12 @@ static int twa_empty_response_queue_large(TW_Device_Extension *tw_dev)
939 unsigned long before; 935 unsigned long before;
940 int retval = 1; 936 int retval = 1;
941 937
942 if (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9550SX) { 938 if ((tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9550SX) ||
939 (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9650SE)) {
943 before = jiffies; 940 before = jiffies;
944 while ((response_que_value & TW_9550SX_DRAIN_COMPLETED) != TW_9550SX_DRAIN_COMPLETED) { 941 while ((response_que_value & TW_9550SX_DRAIN_COMPLETED) != TW_9550SX_DRAIN_COMPLETED) {
945 response_que_value = readl(TW_RESPONSE_QUEUE_REG_ADDR_LARGE(tw_dev)); 942 response_que_value = readl(TW_RESPONSE_QUEUE_REG_ADDR_LARGE(tw_dev));
943 msleep(1);
946 if (time_after(jiffies, before + HZ * 30)) 944 if (time_after(jiffies, before + HZ * 30))
947 goto out; 945 goto out;
948 } 946 }
@@ -1214,6 +1212,10 @@ static irqreturn_t twa_interrupt(int irq, void *dev_instance)
1214 1212
1215 handled = 1; 1213 handled = 1;
1216 1214
1215 /* If we are resetting, bail */
1216 if (test_bit(TW_IN_RESET, &tw_dev->flags))
1217 goto twa_interrupt_bail;
1218
1217 /* Check controller for errors */ 1219 /* Check controller for errors */
1218 if (twa_check_bits(status_reg_value)) { 1220 if (twa_check_bits(status_reg_value)) {
1219 if (twa_decode_bits(tw_dev, status_reg_value)) { 1221 if (twa_decode_bits(tw_dev, status_reg_value)) {
@@ -1355,8 +1357,8 @@ static void twa_load_sgl(TW_Command_Full *full_command_packet, int request_id, d
1355 1357
1356 if (TW_OP_OUT(full_command_packet->command.newcommand.opcode__reserved) == TW_OP_EXECUTE_SCSI) { 1358 if (TW_OP_OUT(full_command_packet->command.newcommand.opcode__reserved) == TW_OP_EXECUTE_SCSI) {
1357 newcommand = &full_command_packet->command.newcommand; 1359 newcommand = &full_command_packet->command.newcommand;
1358 newcommand->request_id__lunl = 1360 newcommand->request_id__lunl =
1359 TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->request_id__lunl), request_id); 1361 cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->request_id__lunl), request_id));
1360 newcommand->sg_list[0].address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache) - 1); 1362 newcommand->sg_list[0].address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache) - 1);
1361 newcommand->sg_list[0].length = cpu_to_le32(length); 1363 newcommand->sg_list[0].length = cpu_to_le32(length);
1362 newcommand->sgl_entries__lunh = 1364 newcommand->sgl_entries__lunh =
@@ -1531,6 +1533,13 @@ static int twa_post_command_packet(TW_Device_Extension *tw_dev, int request_id,
1531 int retval = 1; 1533 int retval = 1;
1532 1534
1533 command_que_value = tw_dev->command_packet_phys[request_id]; 1535 command_que_value = tw_dev->command_packet_phys[request_id];
1536
1537 /* For 9650SE write low 4 bytes first */
1538 if (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9650SE) {
1539 command_que_value += TW_COMMAND_OFFSET;
1540 writel((u32)command_que_value, TW_COMMAND_QUEUE_REG_ADDR_LARGE(tw_dev));
1541 }
1542
1534 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev)); 1543 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1535 1544
1536 if (twa_check_bits(status_reg_value)) 1545 if (twa_check_bits(status_reg_value))
@@ -1557,13 +1566,17 @@ static int twa_post_command_packet(TW_Device_Extension *tw_dev, int request_id,
1557 TW_UNMASK_COMMAND_INTERRUPT(tw_dev); 1566 TW_UNMASK_COMMAND_INTERRUPT(tw_dev);
1558 goto out; 1567 goto out;
1559 } else { 1568 } else {
1560 /* We successfully posted the command packet */ 1569 if (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9650SE) {
1561 if (sizeof(dma_addr_t) > 4) { 1570 /* Now write upper 4 bytes */
1562 command_que_value += TW_COMMAND_OFFSET; 1571 writel((u32)((u64)command_que_value >> 32), TW_COMMAND_QUEUE_REG_ADDR_LARGE(tw_dev) + 0x4);
1563 writel((u32)command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
1564 writel((u32)((u64)command_que_value >> 32), TW_COMMAND_QUEUE_REG_ADDR(tw_dev) + 0x4);
1565 } else { 1572 } else {
1566 writel(TW_COMMAND_OFFSET + command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev)); 1573 if (sizeof(dma_addr_t) > 4) {
1574 command_que_value += TW_COMMAND_OFFSET;
1575 writel((u32)command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
1576 writel((u32)((u64)command_que_value >> 32), TW_COMMAND_QUEUE_REG_ADDR(tw_dev) + 0x4);
1577 } else {
1578 writel(TW_COMMAND_OFFSET + command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
1579 }
1567 } 1580 }
1568 tw_dev->state[request_id] = TW_S_POSTED; 1581 tw_dev->state[request_id] = TW_S_POSTED;
1569 tw_dev->posted_request_count++; 1582 tw_dev->posted_request_count++;
@@ -1620,14 +1633,9 @@ static int twa_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_res
1620 goto out; 1633 goto out;
1621 1634
1622 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev); 1635 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
1636 clear_bit(TW_IN_RESET, &tw_dev->flags);
1637 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1623 1638
1624 /* Wake up any ioctl that was pending before the reset */
1625 if ((tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE) || (ioctl_reset)) {
1626 clear_bit(TW_IN_RESET, &tw_dev->flags);
1627 } else {
1628 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1629 wake_up(&tw_dev->ioctl_wqueue);
1630 }
1631 retval = 0; 1639 retval = 0;
1632out: 1640out:
1633 return retval; 1641 return retval;
@@ -1736,6 +1744,9 @@ static int twa_scsi_eh_reset(struct scsi_cmnd *SCpnt)
1736 "WARNING: (0x%02X:0x%04X): Command (0x%x) timed out, resetting card.\n", 1744 "WARNING: (0x%02X:0x%04X): Command (0x%x) timed out, resetting card.\n",
1737 TW_DRIVER, 0x2c, SCpnt->cmnd[0]); 1745 TW_DRIVER, 0x2c, SCpnt->cmnd[0]);
1738 1746
1747 /* Make sure we are not issuing an ioctl or resetting from ioctl */
1748 mutex_lock(&tw_dev->ioctl_lock);
1749
1739 /* Now reset the card and some of the device extension data */ 1750 /* Now reset the card and some of the device extension data */
1740 if (twa_reset_device_extension(tw_dev, 0)) { 1751 if (twa_reset_device_extension(tw_dev, 0)) {
1741 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2b, "Controller reset failed during scsi host reset"); 1752 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2b, "Controller reset failed during scsi host reset");
@@ -1744,6 +1755,7 @@ static int twa_scsi_eh_reset(struct scsi_cmnd *SCpnt)
1744 1755
1745 retval = SUCCESS; 1756 retval = SUCCESS;
1746out: 1757out:
1758 mutex_unlock(&tw_dev->ioctl_lock);
1747 return retval; 1759 return retval;
1748} /* End twa_scsi_eh_reset() */ 1760} /* End twa_scsi_eh_reset() */
1749 1761
@@ -1753,8 +1765,14 @@ static int twa_scsi_queue(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd
1753 int request_id, retval; 1765 int request_id, retval;
1754 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; 1766 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
1755 1767
1768 /* If we are resetting due to timed out ioctl, report as busy */
1769 if (test_bit(TW_IN_RESET, &tw_dev->flags)) {
1770 retval = SCSI_MLQUEUE_HOST_BUSY;
1771 goto out;
1772 }
1773
1756 /* Check if this FW supports luns */ 1774 /* Check if this FW supports luns */
1757 if ((SCpnt->device->lun != 0) && (tw_dev->working_srl < TW_FW_SRL_LUNS_SUPPORTED)) { 1775 if ((SCpnt->device->lun != 0) && (tw_dev->tw_compat_info.working_srl < TW_FW_SRL_LUNS_SUPPORTED)) {
1758 SCpnt->result = (DID_BAD_TARGET << 16); 1776 SCpnt->result = (DID_BAD_TARGET << 16);
1759 done(SCpnt); 1777 done(SCpnt);
1760 retval = 0; 1778 retval = 0;
@@ -1960,6 +1978,9 @@ static void __twa_shutdown(TW_Device_Extension *tw_dev)
1960 /* Disable interrupts */ 1978 /* Disable interrupts */
1961 TW_DISABLE_INTERRUPTS(tw_dev); 1979 TW_DISABLE_INTERRUPTS(tw_dev);
1962 1980
1981 /* Free up the IRQ */
1982 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
1983
1963 printk(KERN_WARNING "3w-9xxx: Shutting down host %d.\n", tw_dev->host->host_no); 1984 printk(KERN_WARNING "3w-9xxx: Shutting down host %d.\n", tw_dev->host->host_no);
1964 1985
1965 /* Tell the card we are shutting down */ 1986 /* Tell the card we are shutting down */
@@ -2091,21 +2112,25 @@ static int __devinit twa_probe(struct pci_dev *pdev, const struct pci_device_id
2091 2112
2092 /* Initialize the card */ 2113 /* Initialize the card */
2093 if (twa_reset_sequence(tw_dev, 0)) 2114 if (twa_reset_sequence(tw_dev, 0))
2094 goto out_release_mem_region; 2115 goto out_iounmap;
2095 2116
2096 /* Set host specific parameters */ 2117 /* Set host specific parameters */
2097 host->max_id = TW_MAX_UNITS; 2118 if (pdev->device == PCI_DEVICE_ID_3WARE_9650SE)
2119 host->max_id = TW_MAX_UNITS_9650SE;
2120 else
2121 host->max_id = TW_MAX_UNITS;
2122
2098 host->max_cmd_len = TW_MAX_CDB_LEN; 2123 host->max_cmd_len = TW_MAX_CDB_LEN;
2099 2124
2100 /* Channels aren't supported by adapter */ 2125 /* Channels aren't supported by adapter */
2101 host->max_lun = TW_MAX_LUNS(tw_dev->working_srl); 2126 host->max_lun = TW_MAX_LUNS(tw_dev->tw_compat_info.working_srl);
2102 host->max_channel = 0; 2127 host->max_channel = 0;
2103 2128
2104 /* Register the card with the kernel SCSI layer */ 2129 /* Register the card with the kernel SCSI layer */
2105 retval = scsi_add_host(host, &pdev->dev); 2130 retval = scsi_add_host(host, &pdev->dev);
2106 if (retval) { 2131 if (retval) {
2107 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x27, "scsi add host failed"); 2132 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x27, "scsi add host failed");
2108 goto out_release_mem_region; 2133 goto out_iounmap;
2109 } 2134 }
2110 2135
2111 pci_set_drvdata(pdev, host); 2136 pci_set_drvdata(pdev, host);
@@ -2145,6 +2170,8 @@ static int __devinit twa_probe(struct pci_dev *pdev, const struct pci_device_id
2145 2170
2146out_remove_host: 2171out_remove_host:
2147 scsi_remove_host(host); 2172 scsi_remove_host(host);
2173out_iounmap:
2174 iounmap(tw_dev->base_addr);
2148out_release_mem_region: 2175out_release_mem_region:
2149 pci_release_regions(pdev); 2176 pci_release_regions(pdev);
2150out_free_device_extension: 2177out_free_device_extension:
@@ -2170,12 +2197,12 @@ static void twa_remove(struct pci_dev *pdev)
2170 twa_major = -1; 2197 twa_major = -1;
2171 } 2198 }
2172 2199
2173 /* Free up the IRQ */
2174 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
2175
2176 /* Shutdown the card */ 2200 /* Shutdown the card */
2177 __twa_shutdown(tw_dev); 2201 __twa_shutdown(tw_dev);
2178 2202
2203 /* Free IO remapping */
2204 iounmap(tw_dev->base_addr);
2205
2179 /* Free up the mem region */ 2206 /* Free up the mem region */
2180 pci_release_regions(pdev); 2207 pci_release_regions(pdev);
2181 2208
@@ -2193,6 +2220,8 @@ static struct pci_device_id twa_pci_tbl[] __devinitdata = {
2193 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2220 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2194 { PCI_VENDOR_ID_3WARE, PCI_DEVICE_ID_3WARE_9550SX, 2221 { PCI_VENDOR_ID_3WARE, PCI_DEVICE_ID_3WARE_9550SX,
2195 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2222 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2223 { PCI_VENDOR_ID_3WARE, PCI_DEVICE_ID_3WARE_9650SE,
2224 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2196 { } 2225 { }
2197}; 2226};
2198MODULE_DEVICE_TABLE(pci, twa_pci_tbl); 2227MODULE_DEVICE_TABLE(pci, twa_pci_tbl);
diff --git a/drivers/scsi/3w-9xxx.h b/drivers/scsi/3w-9xxx.h
index e5685be96f45..7901517d4513 100644
--- a/drivers/scsi/3w-9xxx.h
+++ b/drivers/scsi/3w-9xxx.h
@@ -289,7 +289,6 @@ static twa_message_type twa_error_table[] = {
289#define TW_STATUS_VALID_INTERRUPT 0x00DF0000 289#define TW_STATUS_VALID_INTERRUPT 0x00DF0000
290 290
291/* PCI related defines */ 291/* PCI related defines */
292#define TW_NUMDEVICES 1
293#define TW_PCI_CLEAR_PARITY_ERRORS 0xc100 292#define TW_PCI_CLEAR_PARITY_ERRORS 0xc100
294#define TW_PCI_CLEAR_PCI_ABORT 0x2000 293#define TW_PCI_CLEAR_PCI_ABORT 0x2000
295 294
@@ -335,6 +334,7 @@ static twa_message_type twa_error_table[] = {
335#define TW_ALIGNMENT_9000 4 /* 4 bytes */ 334#define TW_ALIGNMENT_9000 4 /* 4 bytes */
336#define TW_ALIGNMENT_9000_SGL 0x3 335#define TW_ALIGNMENT_9000_SGL 0x3
337#define TW_MAX_UNITS 16 336#define TW_MAX_UNITS 16
337#define TW_MAX_UNITS_9650SE 32
338#define TW_INIT_MESSAGE_CREDITS 0x100 338#define TW_INIT_MESSAGE_CREDITS 0x100
339#define TW_INIT_COMMAND_PACKET_SIZE 0x3 339#define TW_INIT_COMMAND_PACKET_SIZE 0x3
340#define TW_INIT_COMMAND_PACKET_SIZE_EXTENDED 0x6 340#define TW_INIT_COMMAND_PACKET_SIZE_EXTENDED 0x6
@@ -354,7 +354,6 @@ static twa_message_type twa_error_table[] = {
354#define TW_MAX_RESPONSE_DRAIN 256 354#define TW_MAX_RESPONSE_DRAIN 256
355#define TW_MAX_AEN_DRAIN 40 355#define TW_MAX_AEN_DRAIN 40
356#define TW_IN_RESET 2 356#define TW_IN_RESET 2
357#define TW_IN_CHRDEV_IOCTL 3
358#define TW_IN_ATTENTION_LOOP 4 357#define TW_IN_ATTENTION_LOOP 4
359#define TW_MAX_SECTORS 256 358#define TW_MAX_SECTORS 256
360#define TW_AEN_WAIT_TIME 1000 359#define TW_AEN_WAIT_TIME 1000
@@ -417,6 +416,9 @@ static twa_message_type twa_error_table[] = {
417#ifndef PCI_DEVICE_ID_3WARE_9550SX 416#ifndef PCI_DEVICE_ID_3WARE_9550SX
418#define PCI_DEVICE_ID_3WARE_9550SX 0x1003 417#define PCI_DEVICE_ID_3WARE_9550SX 0x1003
419#endif 418#endif
419#ifndef PCI_DEVICE_ID_3WARE_9650SE
420#define PCI_DEVICE_ID_3WARE_9650SE 0x1004
421#endif
420 422
421/* Bitmask macros to eliminate bitfields */ 423/* Bitmask macros to eliminate bitfields */
422 424
@@ -442,6 +444,7 @@ static twa_message_type twa_error_table[] = {
442#define TW_CONTROL_REG_ADDR(x) (x->base_addr) 444#define TW_CONTROL_REG_ADDR(x) (x->base_addr)
443#define TW_STATUS_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + 0x4) 445#define TW_STATUS_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + 0x4)
444#define TW_COMMAND_QUEUE_REG_ADDR(x) (sizeof(dma_addr_t) > 4 ? ((unsigned char __iomem *)x->base_addr + 0x20) : ((unsigned char __iomem *)x->base_addr + 0x8)) 446#define TW_COMMAND_QUEUE_REG_ADDR(x) (sizeof(dma_addr_t) > 4 ? ((unsigned char __iomem *)x->base_addr + 0x20) : ((unsigned char __iomem *)x->base_addr + 0x8))
447#define TW_COMMAND_QUEUE_REG_ADDR_LARGE(x) ((unsigned char __iomem *)x->base_addr + 0x20)
445#define TW_RESPONSE_QUEUE_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + 0xC) 448#define TW_RESPONSE_QUEUE_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + 0xC)
446#define TW_RESPONSE_QUEUE_REG_ADDR_LARGE(x) ((unsigned char __iomem *)x->base_addr + 0x30) 449#define TW_RESPONSE_QUEUE_REG_ADDR_LARGE(x) ((unsigned char __iomem *)x->base_addr + 0x30)
447#define TW_CLEAR_ALL_INTERRUPTS(x) (writel(TW_STATUS_VALID_INTERRUPT, TW_CONTROL_REG_ADDR(x))) 450#define TW_CLEAR_ALL_INTERRUPTS(x) (writel(TW_STATUS_VALID_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
@@ -626,6 +629,9 @@ typedef struct TAG_TW_Compatibility_Info
626 unsigned short driver_srl_low; 629 unsigned short driver_srl_low;
627 unsigned short driver_branch_low; 630 unsigned short driver_branch_low;
628 unsigned short driver_build_low; 631 unsigned short driver_build_low;
632 unsigned short fw_on_ctlr_srl;
633 unsigned short fw_on_ctlr_branch;
634 unsigned short fw_on_ctlr_build;
629} TW_Compatibility_Info; 635} TW_Compatibility_Info;
630 636
631#pragma pack() 637#pragma pack()
@@ -668,9 +674,7 @@ typedef struct TAG_TW_Device_Extension {
668 wait_queue_head_t ioctl_wqueue; 674 wait_queue_head_t ioctl_wqueue;
669 struct mutex ioctl_lock; 675 struct mutex ioctl_lock;
670 char aen_clobber; 676 char aen_clobber;
671 unsigned short working_srl; 677 TW_Compatibility_Info tw_compat_info;
672 unsigned short working_branch;
673 unsigned short working_build;
674} TW_Device_Extension; 678} TW_Device_Extension;
675 679
676#endif /* _3W_9XXX_H */ 680#endif /* _3W_9XXX_H */
diff --git a/drivers/scsi/aic94xx/aic94xx_hwi.c b/drivers/scsi/aic94xx/aic94xx_hwi.c
index 3c2d7a379931..af7e01134364 100644
--- a/drivers/scsi/aic94xx/aic94xx_hwi.c
+++ b/drivers/scsi/aic94xx/aic94xx_hwi.c
@@ -112,6 +112,21 @@ static int asd_init_phy(struct asd_phy *phy)
112 return 0; 112 return 0;
113} 113}
114 114
115static void asd_init_ports(struct asd_ha_struct *asd_ha)
116{
117 int i;
118
119 spin_lock_init(&asd_ha->asd_ports_lock);
120 for (i = 0; i < ASD_MAX_PHYS; i++) {
121 struct asd_port *asd_port = &asd_ha->asd_ports[i];
122
123 memset(asd_port->sas_addr, 0, SAS_ADDR_SIZE);
124 memset(asd_port->attached_sas_addr, 0, SAS_ADDR_SIZE);
125 asd_port->phy_mask = 0;
126 asd_port->num_phys = 0;
127 }
128}
129
115static int asd_init_phys(struct asd_ha_struct *asd_ha) 130static int asd_init_phys(struct asd_ha_struct *asd_ha)
116{ 131{
117 u8 i; 132 u8 i;
@@ -121,6 +136,7 @@ static int asd_init_phys(struct asd_ha_struct *asd_ha)
121 struct asd_phy *phy = &asd_ha->phys[i]; 136 struct asd_phy *phy = &asd_ha->phys[i];
122 137
123 phy->phy_desc = &asd_ha->hw_prof.phy_desc[i]; 138 phy->phy_desc = &asd_ha->hw_prof.phy_desc[i];
139 phy->asd_port = NULL;
124 140
125 phy->sas_phy.enabled = 0; 141 phy->sas_phy.enabled = 0;
126 phy->sas_phy.id = i; 142 phy->sas_phy.id = i;
@@ -658,6 +674,8 @@ int asd_init_hw(struct asd_ha_struct *asd_ha)
658 goto Out; 674 goto Out;
659 } 675 }
660 676
677 asd_init_ports(asd_ha);
678
661 err = asd_init_scbs(asd_ha); 679 err = asd_init_scbs(asd_ha);
662 if (err) { 680 if (err) {
663 asd_printk("couldn't initialize scbs for %s\n", 681 asd_printk("couldn't initialize scbs for %s\n",
diff --git a/drivers/scsi/aic94xx/aic94xx_hwi.h b/drivers/scsi/aic94xx/aic94xx_hwi.h
index 7b6aca02cf70..c6c3d18222fa 100644
--- a/drivers/scsi/aic94xx/aic94xx_hwi.h
+++ b/drivers/scsi/aic94xx/aic94xx_hwi.h
@@ -193,6 +193,16 @@ struct asd_seq_data {
193 struct asd_ascb **escb_arr; /* array of pointers to escbs */ 193 struct asd_ascb **escb_arr; /* array of pointers to escbs */
194}; 194};
195 195
196/* This is an internal port structure. These are used to get accurate
197 * phy_mask for updating DDB 0.
198 */
199struct asd_port {
200 u8 sas_addr[SAS_ADDR_SIZE];
201 u8 attached_sas_addr[SAS_ADDR_SIZE];
202 u32 phy_mask;
203 int num_phys;
204};
205
196/* This is the Host Adapter structure. It describes the hardware 206/* This is the Host Adapter structure. It describes the hardware
197 * SAS adapter. 207 * SAS adapter.
198 */ 208 */
@@ -211,6 +221,8 @@ struct asd_ha_struct {
211 struct hw_profile hw_prof; 221 struct hw_profile hw_prof;
212 222
213 struct asd_phy phys[ASD_MAX_PHYS]; 223 struct asd_phy phys[ASD_MAX_PHYS];
224 spinlock_t asd_ports_lock;
225 struct asd_port asd_ports[ASD_MAX_PHYS];
214 struct asd_sas_port ports[ASD_MAX_PHYS]; 226 struct asd_sas_port ports[ASD_MAX_PHYS];
215 227
216 struct dma_pool *scb_pool; 228 struct dma_pool *scb_pool;
diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
index a4cc432bbdab..57c5ba4043f2 100644
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -786,8 +786,6 @@ static void asd_remove_driver_attrs(struct device_driver *driver)
786} 786}
787 787
788static struct sas_domain_function_template aic94xx_transport_functions = { 788static struct sas_domain_function_template aic94xx_transport_functions = {
789 .lldd_port_formed = asd_update_port_links,
790
791 .lldd_dev_found = asd_dev_found, 789 .lldd_dev_found = asd_dev_found,
792 .lldd_dev_gone = asd_dev_gone, 790 .lldd_dev_gone = asd_dev_gone,
793 791
diff --git a/drivers/scsi/aic94xx/aic94xx_sas.h b/drivers/scsi/aic94xx/aic94xx_sas.h
index 64d231712345..9050e93bfd5e 100644
--- a/drivers/scsi/aic94xx/aic94xx_sas.h
+++ b/drivers/scsi/aic94xx/aic94xx_sas.h
@@ -733,6 +733,7 @@ struct asd_phy {
733 733
734 struct sas_identify_frame *identify_frame; 734 struct sas_identify_frame *identify_frame;
735 struct asd_dma_tok *id_frm_tok; 735 struct asd_dma_tok *id_frm_tok;
736 struct asd_port *asd_port;
736 737
737 u8 frame_rcvd[ASD_EDB_SIZE]; 738 u8 frame_rcvd[ASD_EDB_SIZE];
738}; 739};
diff --git a/drivers/scsi/aic94xx/aic94xx_scb.c b/drivers/scsi/aic94xx/aic94xx_scb.c
index 7ee49b51b724..b15caf1c8fa2 100644
--- a/drivers/scsi/aic94xx/aic94xx_scb.c
+++ b/drivers/scsi/aic94xx/aic94xx_scb.c
@@ -168,6 +168,70 @@ static inline void asd_get_attached_sas_addr(struct asd_phy *phy, u8 *sas_addr)
168 } 168 }
169} 169}
170 170
171static void asd_form_port(struct asd_ha_struct *asd_ha, struct asd_phy *phy)
172{
173 int i;
174 struct asd_port *free_port = NULL;
175 struct asd_port *port;
176 struct asd_sas_phy *sas_phy = &phy->sas_phy;
177 unsigned long flags;
178
179 spin_lock_irqsave(&asd_ha->asd_ports_lock, flags);
180 if (!phy->asd_port) {
181 for (i = 0; i < ASD_MAX_PHYS; i++) {
182 port = &asd_ha->asd_ports[i];
183
184 /* Check for wide port */
185 if (port->num_phys > 0 &&
186 memcmp(port->sas_addr, sas_phy->sas_addr,
187 SAS_ADDR_SIZE) == 0 &&
188 memcmp(port->attached_sas_addr,
189 sas_phy->attached_sas_addr,
190 SAS_ADDR_SIZE) == 0) {
191 break;
192 }
193
194 /* Find a free port */
195 if (port->num_phys == 0 && free_port == NULL) {
196 free_port = port;
197 }
198 }
199
200 /* Use a free port if this doesn't form a wide port */
201 if (i >= ASD_MAX_PHYS) {
202 port = free_port;
203 BUG_ON(!port);
204 memcpy(port->sas_addr, sas_phy->sas_addr,
205 SAS_ADDR_SIZE);
206 memcpy(port->attached_sas_addr,
207 sas_phy->attached_sas_addr,
208 SAS_ADDR_SIZE);
209 }
210 port->num_phys++;
211 port->phy_mask |= (1U << sas_phy->id);
212 phy->asd_port = port;
213 }
214 ASD_DPRINTK("%s: updating phy_mask 0x%x for phy%d\n",
215 __FUNCTION__, phy->asd_port->phy_mask, sas_phy->id);
216 asd_update_port_links(asd_ha, phy);
217 spin_unlock_irqrestore(&asd_ha->asd_ports_lock, flags);
218}
219
220static void asd_deform_port(struct asd_ha_struct *asd_ha, struct asd_phy *phy)
221{
222 struct asd_port *port = phy->asd_port;
223 struct asd_sas_phy *sas_phy = &phy->sas_phy;
224 unsigned long flags;
225
226 spin_lock_irqsave(&asd_ha->asd_ports_lock, flags);
227 if (port) {
228 port->num_phys--;
229 port->phy_mask &= ~(1U << sas_phy->id);
230 phy->asd_port = NULL;
231 }
232 spin_unlock_irqrestore(&asd_ha->asd_ports_lock, flags);
233}
234
171static inline void asd_bytes_dmaed_tasklet(struct asd_ascb *ascb, 235static inline void asd_bytes_dmaed_tasklet(struct asd_ascb *ascb,
172 struct done_list_struct *dl, 236 struct done_list_struct *dl,
173 int edb_id, int phy_id) 237 int edb_id, int phy_id)
@@ -187,6 +251,7 @@ static inline void asd_bytes_dmaed_tasklet(struct asd_ascb *ascb,
187 asd_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr); 251 asd_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
188 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags); 252 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
189 asd_dump_frame_rcvd(phy, dl); 253 asd_dump_frame_rcvd(phy, dl);
254 asd_form_port(ascb->ha, phy);
190 sas_ha->notify_port_event(&phy->sas_phy, PORTE_BYTES_DMAED); 255 sas_ha->notify_port_event(&phy->sas_phy, PORTE_BYTES_DMAED);
191} 256}
192 257
@@ -197,6 +262,7 @@ static inline void asd_link_reset_err_tasklet(struct asd_ascb *ascb,
197 struct asd_ha_struct *asd_ha = ascb->ha; 262 struct asd_ha_struct *asd_ha = ascb->ha;
198 struct sas_ha_struct *sas_ha = &asd_ha->sas_ha; 263 struct sas_ha_struct *sas_ha = &asd_ha->sas_ha;
199 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id]; 264 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
265 struct asd_phy *phy = &asd_ha->phys[phy_id];
200 u8 lr_error = dl->status_block[1]; 266 u8 lr_error = dl->status_block[1];
201 u8 retries_left = dl->status_block[2]; 267 u8 retries_left = dl->status_block[2];
202 268
@@ -221,6 +287,7 @@ static inline void asd_link_reset_err_tasklet(struct asd_ascb *ascb,
221 287
222 asd_turn_led(asd_ha, phy_id, 0); 288 asd_turn_led(asd_ha, phy_id, 0);
223 sas_phy_disconnected(sas_phy); 289 sas_phy_disconnected(sas_phy);
290 asd_deform_port(asd_ha, phy);
224 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); 291 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
225 292
226 if (retries_left == 0) { 293 if (retries_left == 0) {
@@ -248,6 +315,8 @@ static inline void asd_primitive_rcvd_tasklet(struct asd_ascb *ascb,
248 unsigned long flags; 315 unsigned long flags;
249 struct sas_ha_struct *sas_ha = &ascb->ha->sas_ha; 316 struct sas_ha_struct *sas_ha = &ascb->ha->sas_ha;
250 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id]; 317 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
318 struct asd_ha_struct *asd_ha = ascb->ha;
319 struct asd_phy *phy = &asd_ha->phys[phy_id];
251 u8 reg = dl->status_block[1]; 320 u8 reg = dl->status_block[1];
252 u32 cont = dl->status_block[2] << ((reg & 3)*8); 321 u32 cont = dl->status_block[2] << ((reg & 3)*8);
253 322
@@ -284,6 +353,7 @@ static inline void asd_primitive_rcvd_tasklet(struct asd_ascb *ascb,
284 phy_id); 353 phy_id);
285 /* The sequencer disables all phys on that port. 354 /* The sequencer disables all phys on that port.
286 * We have to re-enable the phys ourselves. */ 355 * We have to re-enable the phys ourselves. */
356 asd_deform_port(asd_ha, phy);
287 sas_ha->notify_port_event(sas_phy, PORTE_HARD_RESET); 357 sas_ha->notify_port_event(sas_phy, PORTE_HARD_RESET);
288 break; 358 break;
289 359
@@ -351,6 +421,7 @@ static void escb_tasklet_complete(struct asd_ascb *ascb,
351 u8 sb_opcode = dl->status_block[0]; 421 u8 sb_opcode = dl->status_block[0];
352 int phy_id = sb_opcode & DL_PHY_MASK; 422 int phy_id = sb_opcode & DL_PHY_MASK;
353 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id]; 423 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
424 struct asd_phy *phy = &asd_ha->phys[phy_id];
354 425
355 if (edb > 6 || edb < 0) { 426 if (edb > 6 || edb < 0) {
356 ASD_DPRINTK("edb is 0x%x! dl->opcode is 0x%x\n", 427 ASD_DPRINTK("edb is 0x%x! dl->opcode is 0x%x\n",
@@ -395,6 +466,7 @@ static void escb_tasklet_complete(struct asd_ascb *ascb,
395 asd_turn_led(asd_ha, phy_id, 0); 466 asd_turn_led(asd_ha, phy_id, 0);
396 /* the device is gone */ 467 /* the device is gone */
397 sas_phy_disconnected(sas_phy); 468 sas_phy_disconnected(sas_phy);
469 asd_deform_port(asd_ha, phy);
398 sas_ha->notify_port_event(sas_phy, PORTE_TIMER_EVENT); 470 sas_ha->notify_port_event(sas_phy, PORTE_TIMER_EVENT);
399 break; 471 break;
400 case REQ_TASK_ABORT: 472 case REQ_TASK_ABORT:
diff --git a/drivers/scsi/aic94xx/aic94xx_seq.c b/drivers/scsi/aic94xx/aic94xx_seq.c
index 56e4b3ba6a08..845112539d05 100644
--- a/drivers/scsi/aic94xx/aic94xx_seq.c
+++ b/drivers/scsi/aic94xx/aic94xx_seq.c
@@ -1369,10 +1369,9 @@ int asd_start_seqs(struct asd_ha_struct *asd_ha)
1369 * port_map_by_links is also used as the conn_mask byte in the 1369 * port_map_by_links is also used as the conn_mask byte in the
1370 * initiator/target port DDB. 1370 * initiator/target port DDB.
1371 */ 1371 */
1372void asd_update_port_links(struct asd_sas_phy *sas_phy) 1372void asd_update_port_links(struct asd_ha_struct *asd_ha, struct asd_phy *phy)
1373{ 1373{
1374 struct asd_ha_struct *asd_ha = sas_phy->ha->lldd_ha; 1374 const u8 phy_mask = (u8) phy->asd_port->phy_mask;
1375 const u8 phy_mask = (u8) sas_phy->port->phy_mask;
1376 u8 phy_is_up; 1375 u8 phy_is_up;
1377 u8 mask; 1376 u8 mask;
1378 int i, err; 1377 int i, err;
diff --git a/drivers/scsi/aic94xx/aic94xx_seq.h b/drivers/scsi/aic94xx/aic94xx_seq.h
index 42281c36153b..9e715e5496af 100644
--- a/drivers/scsi/aic94xx/aic94xx_seq.h
+++ b/drivers/scsi/aic94xx/aic94xx_seq.h
@@ -64,7 +64,7 @@ int asd_unpause_lseq(struct asd_ha_struct *asd_ha, u8 lseq_mask);
64int asd_init_seqs(struct asd_ha_struct *asd_ha); 64int asd_init_seqs(struct asd_ha_struct *asd_ha);
65int asd_start_seqs(struct asd_ha_struct *asd_ha); 65int asd_start_seqs(struct asd_ha_struct *asd_ha);
66 66
67void asd_update_port_links(struct asd_sas_phy *phy); 67void asd_update_port_links(struct asd_ha_struct *asd_ha, struct asd_phy *phy);
68#endif 68#endif
69 69
70#endif 70#endif
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 4bc14ad92e22..4c698a71f66f 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -3531,7 +3531,7 @@ static irqreturn_t gdth_interrupt(int irq,void *dev_id)
3531 IStatus &= ~0x80; 3531 IStatus &= ~0x80;
3532#ifdef INT_COAL 3532#ifdef INT_COAL
3533 if (coalesced) 3533 if (coalesced)
3534 ha->status = pcs->ext_status && 0xffff; 3534 ha->status = pcs->ext_status & 0xffff;
3535 else 3535 else
3536#endif 3536#endif
3537 ha->status = gdth_readw(&dp6m_ptr->i960r.status); 3537 ha->status = gdth_readw(&dp6m_ptr->i960r.status);
@@ -3543,7 +3543,7 @@ static irqreturn_t gdth_interrupt(int irq,void *dev_id)
3543 if (coalesced) { 3543 if (coalesced) {
3544 ha->info = pcs->info0; 3544 ha->info = pcs->info0;
3545 ha->info2 = pcs->info1; 3545 ha->info2 = pcs->info1;
3546 ha->service = (pcs->ext_status >> 16) && 0xffff; 3546 ha->service = (pcs->ext_status >> 16) & 0xffff;
3547 } else 3547 } else
3548#endif 3548#endif
3549 { 3549 {
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 0a9dbc59663f..d0b139cccbbc 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -415,8 +415,8 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
415 iscsi_solicit_data_init(conn, ctask, r2t); 415 iscsi_solicit_data_init(conn, ctask, r2t);
416 416
417 tcp_ctask->exp_r2tsn = r2tsn + 1; 417 tcp_ctask->exp_r2tsn = r2tsn + 1;
418 tcp_ctask->xmstate |= XMSTATE_SOL_HDR;
419 __kfifo_put(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*)); 418 __kfifo_put(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*));
419 tcp_ctask->xmstate |= XMSTATE_SOL_HDR;
420 list_move_tail(&ctask->running, &conn->xmitqueue); 420 list_move_tail(&ctask->running, &conn->xmitqueue);
421 421
422 scsi_queue_work(session->host, &conn->xmitwork); 422 scsi_queue_work(session->host, &conn->xmitwork);
@@ -1627,9 +1627,12 @@ static int iscsi_send_sol_pdu(struct iscsi_conn *conn,
1627 if (tcp_ctask->xmstate & XMSTATE_SOL_HDR) { 1627 if (tcp_ctask->xmstate & XMSTATE_SOL_HDR) {
1628 tcp_ctask->xmstate &= ~XMSTATE_SOL_HDR; 1628 tcp_ctask->xmstate &= ~XMSTATE_SOL_HDR;
1629 tcp_ctask->xmstate |= XMSTATE_SOL_DATA; 1629 tcp_ctask->xmstate |= XMSTATE_SOL_DATA;
1630 if (!tcp_ctask->r2t) 1630 if (!tcp_ctask->r2t) {
1631 spin_lock_bh(&session->lock);
1631 __kfifo_get(tcp_ctask->r2tqueue, (void*)&tcp_ctask->r2t, 1632 __kfifo_get(tcp_ctask->r2tqueue, (void*)&tcp_ctask->r2t,
1632 sizeof(void*)); 1633 sizeof(void*));
1634 spin_unlock_bh(&session->lock);
1635 }
1633send_hdr: 1636send_hdr:
1634 r2t = tcp_ctask->r2t; 1637 r2t = tcp_ctask->r2t;
1635 dtask = &r2t->dtask; 1638 dtask = &r2t->dtask;
@@ -1816,21 +1819,14 @@ iscsi_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn)
1816{ 1819{
1817 struct iscsi_conn *conn = cls_conn->dd_data; 1820 struct iscsi_conn *conn = cls_conn->dd_data;
1818 struct iscsi_tcp_conn *tcp_conn = conn->dd_data; 1821 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1819 int digest = 0;
1820
1821 if (conn->hdrdgst_en || conn->datadgst_en)
1822 digest = 1;
1823 1822
1824 iscsi_tcp_release_conn(conn); 1823 iscsi_tcp_release_conn(conn);
1825 iscsi_conn_teardown(cls_conn); 1824 iscsi_conn_teardown(cls_conn);
1826 1825
1827 /* now free tcp_conn */ 1826 if (tcp_conn->tx_hash.tfm)
1828 if (digest) { 1827 crypto_free_hash(tcp_conn->tx_hash.tfm);
1829 if (tcp_conn->tx_hash.tfm) 1828 if (tcp_conn->rx_hash.tfm)
1830 crypto_free_hash(tcp_conn->tx_hash.tfm); 1829 crypto_free_hash(tcp_conn->rx_hash.tfm);
1831 if (tcp_conn->rx_hash.tfm)
1832 crypto_free_hash(tcp_conn->rx_hash.tfm);
1833 }
1834 1830
1835 kfree(tcp_conn); 1831 kfree(tcp_conn);
1836} 1832}
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 2865ebd557ef..5d8862189485 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -975,13 +975,13 @@ int iscsi_eh_host_reset(struct scsi_cmnd *sc)
975 if (session->state == ISCSI_STATE_TERMINATE) { 975 if (session->state == ISCSI_STATE_TERMINATE) {
976failed: 976failed:
977 debug_scsi("failing host reset: session terminated " 977 debug_scsi("failing host reset: session terminated "
978 "[CID %d age %d]", conn->id, session->age); 978 "[CID %d age %d]\n", conn->id, session->age);
979 spin_unlock_bh(&session->lock); 979 spin_unlock_bh(&session->lock);
980 return FAILED; 980 return FAILED;
981 } 981 }
982 982
983 if (sc->SCp.phase == session->age) { 983 if (sc->SCp.phase == session->age) {
984 debug_scsi("failing connection CID %d due to SCSI host reset", 984 debug_scsi("failing connection CID %d due to SCSI host reset\n",
985 conn->id); 985 conn->id);
986 fail_session = 1; 986 fail_session = 1;
987 } 987 }
@@ -1054,7 +1054,8 @@ static int iscsi_exec_abort_task(struct scsi_cmnd *sc,
1054 NULL, 0); 1054 NULL, 0);
1055 if (rc) { 1055 if (rc) {
1056 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); 1056 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1057 debug_scsi("abort sent failure [itt 0x%x] %d", ctask->itt, rc); 1057 debug_scsi("abort sent failure [itt 0x%x] %d\n", ctask->itt,
1058 rc);
1058 return rc; 1059 return rc;
1059 } 1060 }
1060 1061
@@ -1071,7 +1072,7 @@ static int iscsi_exec_abort_task(struct scsi_cmnd *sc,
1071 conn->tmabort_timer.function = iscsi_tmabort_timedout; 1072 conn->tmabort_timer.function = iscsi_tmabort_timedout;
1072 conn->tmabort_timer.data = (unsigned long)ctask; 1073 conn->tmabort_timer.data = (unsigned long)ctask;
1073 add_timer(&conn->tmabort_timer); 1074 add_timer(&conn->tmabort_timer);
1074 debug_scsi("abort set timeout [itt 0x%x]", ctask->itt); 1075 debug_scsi("abort set timeout [itt 0x%x]\n", ctask->itt);
1075 } 1076 }
1076 spin_unlock_bh(&session->lock); 1077 spin_unlock_bh(&session->lock);
1077 mutex_unlock(&conn->xmitmutex); 1078 mutex_unlock(&conn->xmitmutex);
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index 30b8014bcc7a..e34a93435497 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -71,55 +71,65 @@ static void smp_task_done(struct sas_task *task)
71static int smp_execute_task(struct domain_device *dev, void *req, int req_size, 71static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
72 void *resp, int resp_size) 72 void *resp, int resp_size)
73{ 73{
74 int res; 74 int res, retry;
75 struct sas_task *task = sas_alloc_task(GFP_KERNEL); 75 struct sas_task *task = NULL;
76 struct sas_internal *i = 76 struct sas_internal *i =
77 to_sas_internal(dev->port->ha->core.shost->transportt); 77 to_sas_internal(dev->port->ha->core.shost->transportt);
78 78
79 if (!task) 79 for (retry = 0; retry < 3; retry++) {
80 return -ENOMEM; 80 task = sas_alloc_task(GFP_KERNEL);
81 81 if (!task)
82 task->dev = dev; 82 return -ENOMEM;
83 task->task_proto = dev->tproto;
84 sg_init_one(&task->smp_task.smp_req, req, req_size);
85 sg_init_one(&task->smp_task.smp_resp, resp, resp_size);
86 83
87 task->task_done = smp_task_done; 84 task->dev = dev;
85 task->task_proto = dev->tproto;
86 sg_init_one(&task->smp_task.smp_req, req, req_size);
87 sg_init_one(&task->smp_task.smp_resp, resp, resp_size);
88 88
89 task->timer.data = (unsigned long) task; 89 task->task_done = smp_task_done;
90 task->timer.function = smp_task_timedout;
91 task->timer.expires = jiffies + SMP_TIMEOUT*HZ;
92 add_timer(&task->timer);
93 90
94 res = i->dft->lldd_execute_task(task, 1, GFP_KERNEL); 91 task->timer.data = (unsigned long) task;
92 task->timer.function = smp_task_timedout;
93 task->timer.expires = jiffies + SMP_TIMEOUT*HZ;
94 add_timer(&task->timer);
95 95
96 if (res) { 96 res = i->dft->lldd_execute_task(task, 1, GFP_KERNEL);
97 del_timer(&task->timer);
98 SAS_DPRINTK("executing SMP task failed:%d\n", res);
99 goto ex_err;
100 }
101 97
102 wait_for_completion(&task->completion); 98 if (res) {
103 res = -ETASK; 99 del_timer(&task->timer);
104 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) { 100 SAS_DPRINTK("executing SMP task failed:%d\n", res);
105 SAS_DPRINTK("smp task timed out or aborted\n");
106 i->dft->lldd_abort_task(task);
107 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
108 SAS_DPRINTK("SMP task aborted and not done\n");
109 goto ex_err; 101 goto ex_err;
110 } 102 }
103
104 wait_for_completion(&task->completion);
105 res = -ETASK;
106 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
107 SAS_DPRINTK("smp task timed out or aborted\n");
108 i->dft->lldd_abort_task(task);
109 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
110 SAS_DPRINTK("SMP task aborted and not done\n");
111 goto ex_err;
112 }
113 }
114 if (task->task_status.resp == SAS_TASK_COMPLETE &&
115 task->task_status.stat == SAM_GOOD) {
116 res = 0;
117 break;
118 } else {
119 SAS_DPRINTK("%s: task to dev %016llx response: 0x%x "
120 "status 0x%x\n", __FUNCTION__,
121 SAS_ADDR(dev->sas_addr),
122 task->task_status.resp,
123 task->task_status.stat);
124 sas_free_task(task);
125 task = NULL;
126 }
111 } 127 }
112 if (task->task_status.resp == SAS_TASK_COMPLETE &&
113 task->task_status.stat == SAM_GOOD)
114 res = 0;
115 else
116 SAS_DPRINTK("%s: task to dev %016llx response: 0x%x "
117 "status 0x%x\n", __FUNCTION__,
118 SAS_ADDR(dev->sas_addr),
119 task->task_status.resp,
120 task->task_status.stat);
121ex_err: 128ex_err:
122 sas_free_task(task); 129 BUG_ON(retry == 3 && task != NULL);
130 if (task != NULL) {
131 sas_free_task(task);
132 }
123 return res; 133 return res;
124} 134}
125 135
diff --git a/drivers/scsi/psi240i.c b/drivers/scsi/psi240i.c
index ac0419e2714a..899e89d6fe67 100644
--- a/drivers/scsi/psi240i.c
+++ b/drivers/scsi/psi240i.c
@@ -328,7 +328,7 @@ static void Irq_Handler (int irq, void *dev_id)
328 pinquiryData->AdditionalLength = 35 - 4; 328 pinquiryData->AdditionalLength = 35 - 4;
329 329
330 // Fill in vendor identification fields. 330 // Fill in vendor identification fields.
331 for ( z = 0; z < 20; z += 2 ) 331 for ( z = 0; z < 8; z += 2 )
332 { 332 {
333 pinquiryData->VendorId[z] = ((UCHAR *)identifyData.ModelNumber)[z + 1]; 333 pinquiryData->VendorId[z] = ((UCHAR *)identifyData.ModelNumber)[z + 1];
334 pinquiryData->VendorId[z + 1] = ((UCHAR *)identifyData.ModelNumber)[z]; 334 pinquiryData->VendorId[z + 1] = ((UCHAR *)identifyData.ModelNumber)[z];
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 2d3baa99ca25..9b25124a989e 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -33,7 +33,7 @@
33#define ISCSI_SESSION_ATTRS 11 33#define ISCSI_SESSION_ATTRS 11
34#define ISCSI_CONN_ATTRS 11 34#define ISCSI_CONN_ATTRS 11
35#define ISCSI_HOST_ATTRS 0 35#define ISCSI_HOST_ATTRS 0
36#define ISCSI_TRANSPORT_VERSION "2.0-685" 36#define ISCSI_TRANSPORT_VERSION "2.0-724"
37 37
38struct iscsi_internal { 38struct iscsi_internal {
39 int daemon_pid; 39 int daemon_pid;
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 3f8b93188567..81e3bc7b02a1 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -60,7 +60,7 @@ static int sg_version_num = 30534; /* 2 digits for each component */
60 60
61#ifdef CONFIG_SCSI_PROC_FS 61#ifdef CONFIG_SCSI_PROC_FS
62#include <linux/proc_fs.h> 62#include <linux/proc_fs.h>
63static char *sg_version_date = "20060920"; 63static char *sg_version_date = "20061027";
64 64
65static int sg_proc_init(void); 65static int sg_proc_init(void);
66static void sg_proc_cleanup(void); 66static void sg_proc_cleanup(void);
@@ -710,12 +710,12 @@ sg_common_write(Sg_fd * sfp, Sg_request * srp,
710 (int) cmnd[0], (int) hp->cmd_len)); 710 (int) cmnd[0], (int) hp->cmd_len));
711 711
712 if ((k = sg_start_req(srp))) { 712 if ((k = sg_start_req(srp))) {
713 SCSI_LOG_TIMEOUT(1, printk("sg_write: start_req err=%d\n", k)); 713 SCSI_LOG_TIMEOUT(1, printk("sg_common_write: start_req err=%d\n", k));
714 sg_finish_rem_req(srp); 714 sg_finish_rem_req(srp);
715 return k; /* probably out of space --> ENOMEM */ 715 return k; /* probably out of space --> ENOMEM */
716 } 716 }
717 if ((k = sg_write_xfer(srp))) { 717 if ((k = sg_write_xfer(srp))) {
718 SCSI_LOG_TIMEOUT(1, printk("sg_write: write_xfer, bad address\n")); 718 SCSI_LOG_TIMEOUT(1, printk("sg_common_write: write_xfer, bad address\n"));
719 sg_finish_rem_req(srp); 719 sg_finish_rem_req(srp);
720 return k; 720 return k;
721 } 721 }
@@ -746,7 +746,7 @@ sg_common_write(Sg_fd * sfp, Sg_request * srp,
746 hp->dxfer_len, srp->data.k_use_sg, timeout, 746 hp->dxfer_len, srp->data.k_use_sg, timeout,
747 SG_DEFAULT_RETRIES, srp, sg_cmd_done, 747 SG_DEFAULT_RETRIES, srp, sg_cmd_done,
748 GFP_ATOMIC)) { 748 GFP_ATOMIC)) {
749 SCSI_LOG_TIMEOUT(1, printk("sg_write: scsi_execute_async failed\n")); 749 SCSI_LOG_TIMEOUT(1, printk("sg_common_write: scsi_execute_async failed\n"));
750 /* 750 /*
751 * most likely out of mem, but could also be a bad map 751 * most likely out of mem, but could also be a bad map
752 */ 752 */
@@ -1283,7 +1283,7 @@ sg_cmd_done(void *data, char *sense, int result, int resid)
1283 sg_finish_rem_req(srp); 1283 sg_finish_rem_req(srp);
1284 srp = NULL; 1284 srp = NULL;
1285 if (NULL == sfp->headrp) { 1285 if (NULL == sfp->headrp) {
1286 SCSI_LOG_TIMEOUT(1, printk("sg...bh: already closed, final cleanup\n")); 1286 SCSI_LOG_TIMEOUT(1, printk("sg_cmd_done: already closed, final cleanup\n"));
1287 if (0 == sg_remove_sfp(sdp, sfp)) { /* device still present */ 1287 if (0 == sg_remove_sfp(sdp, sfp)) { /* device still present */
1288 scsi_device_put(sdp->device); 1288 scsi_device_put(sdp->device);
1289 } 1289 }
@@ -1512,12 +1512,12 @@ sg_remove(struct class_device *cl_dev, struct class_interface *cl_intf)
1512 POLL_HUP); 1512 POLL_HUP);
1513 } 1513 }
1514 } 1514 }
1515 SCSI_LOG_TIMEOUT(3, printk("sg_detach: dev=%d, dirty\n", k)); 1515 SCSI_LOG_TIMEOUT(3, printk("sg_remove: dev=%d, dirty\n", k));
1516 if (NULL == sdp->headfp) { 1516 if (NULL == sdp->headfp) {
1517 sg_dev_arr[k] = NULL; 1517 sg_dev_arr[k] = NULL;
1518 } 1518 }
1519 } else { /* nothing active, simple case */ 1519 } else { /* nothing active, simple case */
1520 SCSI_LOG_TIMEOUT(3, printk("sg_detach: dev=%d\n", k)); 1520 SCSI_LOG_TIMEOUT(3, printk("sg_remove: dev=%d\n", k));
1521 sg_dev_arr[k] = NULL; 1521 sg_dev_arr[k] = NULL;
1522 } 1522 }
1523 sg_nr_dev--; 1523 sg_nr_dev--;
@@ -1876,14 +1876,15 @@ sg_build_indirect(Sg_scatter_hold * schp, Sg_fd * sfp, int buff_size)
1876 } 1876 }
1877 } 1877 }
1878 sg->page = p; 1878 sg->page = p;
1879 sg->length = ret_sz; 1879 sg->length = (ret_sz > num) ? num : ret_sz;
1880 1880
1881 SCSI_LOG_TIMEOUT(5, printk("sg_build_build: k=%d, a=0x%p, len=%d\n", 1881 SCSI_LOG_TIMEOUT(5, printk("sg_build_indirect: k=%d, num=%d, "
1882 k, p, ret_sz)); 1882 "ret_sz=%d\n", k, num, ret_sz));
1883 } /* end of for loop */ 1883 } /* end of for loop */
1884 1884
1885 schp->k_use_sg = k; 1885 schp->k_use_sg = k;
1886 SCSI_LOG_TIMEOUT(5, printk("sg_build_indirect: k_use_sg=%d, rem_sz=%d\n", k, rem_sz)); 1886 SCSI_LOG_TIMEOUT(5, printk("sg_build_indirect: k_use_sg=%d, "
1887 "rem_sz=%d\n", k, rem_sz));
1887 1888
1888 schp->bufflen = blk_size; 1889 schp->bufflen = blk_size;
1889 if (rem_sz > 0) /* must have failed */ 1890 if (rem_sz > 0) /* must have failed */
@@ -2014,7 +2015,7 @@ sg_remove_scat(Sg_scatter_hold * schp)
2014 for (k = 0; (k < schp->k_use_sg) && sg->page; 2015 for (k = 0; (k < schp->k_use_sg) && sg->page;
2015 ++k, ++sg) { 2016 ++k, ++sg) {
2016 SCSI_LOG_TIMEOUT(5, printk( 2017 SCSI_LOG_TIMEOUT(5, printk(
2017 "sg_remove_scat: k=%d, a=0x%p, len=%d\n", 2018 "sg_remove_scat: k=%d, pg=0x%p, len=%d\n",
2018 k, sg->page, sg->length)); 2019 k, sg->page, sg->length));
2019 sg_page_free(sg->page, sg->length); 2020 sg_page_free(sg->page, sg->length);
2020 } 2021 }