Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | ******************************************************************************* |
| 3 | ** O.S : Linux |
| 4 | ** FILE NAME : arcmsr_hba.c |
| 5 | ** BY : Erich Chen |
| 6 | ** Description: SCSI RAID Device Driver for |
| 7 | ** ARECA RAID Host adapter |
| 8 | ******************************************************************************* |
| 9 | ** Copyright (C) 2002 - 2005, Areca Technology Corporation All rights reserved |
| 10 | ** |
| 11 | ** Web site: www.areca.com.tw |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 12 | ** E-mail: support@areca.com.tw |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 13 | ** |
| 14 | ** This program is free software; you can redistribute it and/or modify |
| 15 | ** it under the terms of the GNU General Public License version 2 as |
| 16 | ** published by the Free Software Foundation. |
| 17 | ** This program is distributed in the hope that it will be useful, |
| 18 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | ** GNU General Public License for more details. |
| 21 | ******************************************************************************* |
| 22 | ** Redistribution and use in source and binary forms, with or without |
| 23 | ** modification, are permitted provided that the following conditions |
| 24 | ** are met: |
| 25 | ** 1. Redistributions of source code must retain the above copyright |
| 26 | ** notice, this list of conditions and the following disclaimer. |
| 27 | ** 2. Redistributions in binary form must reproduce the above copyright |
| 28 | ** notice, this list of conditions and the following disclaimer in the |
| 29 | ** documentation and/or other materials provided with the distribution. |
| 30 | ** 3. The name of the author may not be used to endorse or promote products |
| 31 | ** derived from this software without specific prior written permission. |
| 32 | ** |
| 33 | ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 34 | ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 35 | ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 36 | ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 37 | ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING,BUT |
| 38 | ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 39 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION)HOWEVER CAUSED AND ON ANY |
| 40 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 41 | ** (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF |
| 42 | ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 43 | ******************************************************************************* |
| 44 | ** For history of changes, see Documentation/scsi/ChangeLog.arcmsr |
| 45 | ** Firmware Specification, see Documentation/scsi/arcmsr_spec.txt |
| 46 | ******************************************************************************* |
| 47 | */ |
| 48 | #include <linux/module.h> |
| 49 | #include <linux/reboot.h> |
| 50 | #include <linux/spinlock.h> |
| 51 | #include <linux/pci_ids.h> |
| 52 | #include <linux/interrupt.h> |
| 53 | #include <linux/moduleparam.h> |
| 54 | #include <linux/errno.h> |
| 55 | #include <linux/types.h> |
| 56 | #include <linux/delay.h> |
| 57 | #include <linux/dma-mapping.h> |
| 58 | #include <linux/timer.h> |
| 59 | #include <linux/pci.h> |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 60 | #include <linux/aer.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 61 | #include <linux/slab.h> |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 62 | #include <asm/dma.h> |
| 63 | #include <asm/io.h> |
| 64 | #include <asm/system.h> |
| 65 | #include <asm/uaccess.h> |
| 66 | #include <scsi/scsi_host.h> |
| 67 | #include <scsi/scsi.h> |
| 68 | #include <scsi/scsi_cmnd.h> |
| 69 | #include <scsi/scsi_tcq.h> |
| 70 | #include <scsi/scsi_device.h> |
| 71 | #include <scsi/scsi_transport.h> |
| 72 | #include <scsi/scsicam.h> |
| 73 | #include "arcmsr.h" |
| 74 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 75 | #ifdef CONFIG_SCSI_ARCMSR_RESET |
| 76 | static int sleeptime = 20; |
| 77 | static int retrycount = 12; |
| 78 | module_param(sleeptime, int, S_IRUGO|S_IWUSR); |
| 79 | MODULE_PARM_DESC(sleeptime, "The waiting period for FW ready while bus reset"); |
| 80 | module_param(retrycount, int, S_IRUGO|S_IWUSR); |
| 81 | MODULE_PARM_DESC(retrycount, "The retry count for FW ready while bus reset"); |
| 82 | #endif |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 83 | MODULE_AUTHOR("Erich Chen <support@areca.com.tw>"); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 84 | MODULE_DESCRIPTION("ARECA (ARC11xx/12xx/13xx/16xx) SATA/SAS RAID Host Bus Adapter"); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 85 | MODULE_LICENSE("Dual BSD/GPL"); |
| 86 | MODULE_VERSION(ARCMSR_DRIVER_VERSION); |
| 87 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 88 | static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, |
| 89 | struct scsi_cmnd *cmd); |
| 90 | static int arcmsr_iop_confirm(struct AdapterControlBlock *acb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 91 | static int arcmsr_abort(struct scsi_cmnd *); |
| 92 | static int arcmsr_bus_reset(struct scsi_cmnd *); |
| 93 | static int arcmsr_bios_param(struct scsi_device *sdev, |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 94 | struct block_device *bdev, sector_t capacity, int *info); |
| 95 | static int arcmsr_queue_command(struct scsi_cmnd *cmd, |
| 96 | void (*done) (struct scsi_cmnd *)); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 97 | static int arcmsr_probe(struct pci_dev *pdev, |
| 98 | const struct pci_device_id *id); |
| 99 | static void arcmsr_remove(struct pci_dev *pdev); |
| 100 | static void arcmsr_shutdown(struct pci_dev *pdev); |
| 101 | static void arcmsr_iop_init(struct AdapterControlBlock *acb); |
| 102 | static void arcmsr_free_ccb_pool(struct AdapterControlBlock *acb); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 103 | static u32 arcmsr_disable_outbound_ints(struct AdapterControlBlock *acb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 104 | static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock *acb); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 105 | static void arcmsr_flush_hba_cache(struct AdapterControlBlock *acb); |
| 106 | static void arcmsr_flush_hbb_cache(struct AdapterControlBlock *acb); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 107 | static void arcmsr_request_device_map(unsigned long pacb); |
| 108 | static void arcmsr_request_hba_device_map(struct AdapterControlBlock *acb); |
| 109 | static void arcmsr_request_hbb_device_map(struct AdapterControlBlock *acb); |
| 110 | static void arcmsr_message_isr_bh_fn(struct work_struct *work); |
| 111 | static void *arcmsr_get_firmware_spec(struct AdapterControlBlock *acb, int mode); |
| 112 | static void arcmsr_start_adapter_bgrb(struct AdapterControlBlock *acb); |
| 113 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 114 | static const char *arcmsr_info(struct Scsi_Host *); |
| 115 | static irqreturn_t arcmsr_interrupt(struct AdapterControlBlock *acb); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 116 | static int arcmsr_adjust_disk_queue_depth(struct scsi_device *sdev, |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 117 | int queue_depth, int reason) |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 118 | { |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 119 | if (reason != SCSI_QDEPTH_DEFAULT) |
| 120 | return -EOPNOTSUPP; |
| 121 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 122 | if (queue_depth > ARCMSR_MAX_CMD_PERLUN) |
| 123 | queue_depth = ARCMSR_MAX_CMD_PERLUN; |
| 124 | scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth); |
| 125 | return queue_depth; |
| 126 | } |
| 127 | |
| 128 | static struct scsi_host_template arcmsr_scsi_host_template = { |
| 129 | .module = THIS_MODULE, |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 130 | .name = "ARCMSR ARECA SATA/SAS RAID Host Bus Adapter" |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 131 | ARCMSR_DRIVER_VERSION, |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 132 | .info = arcmsr_info, |
| 133 | .queuecommand = arcmsr_queue_command, |
| 134 | .eh_abort_handler = arcmsr_abort, |
| 135 | .eh_bus_reset_handler = arcmsr_bus_reset, |
| 136 | .bios_param = arcmsr_bios_param, |
| 137 | .change_queue_depth = arcmsr_adjust_disk_queue_depth, |
| 138 | .can_queue = ARCMSR_MAX_OUTSTANDING_CMD, |
| 139 | .this_id = ARCMSR_SCSI_INITIATOR_ID, |
| 140 | .sg_tablesize = ARCMSR_MAX_SG_ENTRIES, |
| 141 | .max_sectors = ARCMSR_MAX_XFER_SECTORS, |
| 142 | .cmd_per_lun = ARCMSR_MAX_CMD_PERLUN, |
| 143 | .use_clustering = ENABLE_CLUSTERING, |
| 144 | .shost_attrs = arcmsr_host_attrs, |
| 145 | }; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 146 | static struct pci_device_id arcmsr_device_id_table[] = { |
| 147 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1110)}, |
| 148 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1120)}, |
| 149 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1130)}, |
| 150 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1160)}, |
| 151 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1170)}, |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 152 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1200)}, |
| 153 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1201)}, |
| 154 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1202)}, |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 155 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1210)}, |
| 156 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1220)}, |
| 157 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1230)}, |
| 158 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1260)}, |
| 159 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1270)}, |
| 160 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1280)}, |
| 161 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1380)}, |
| 162 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1381)}, |
| 163 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1680)}, |
| 164 | {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1681)}, |
| 165 | {0, 0}, /* Terminating entry */ |
| 166 | }; |
| 167 | MODULE_DEVICE_TABLE(pci, arcmsr_device_id_table); |
| 168 | static struct pci_driver arcmsr_pci_driver = { |
| 169 | .name = "arcmsr", |
| 170 | .id_table = arcmsr_device_id_table, |
| 171 | .probe = arcmsr_probe, |
| 172 | .remove = arcmsr_remove, |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 173 | .shutdown = arcmsr_shutdown, |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 176 | static irqreturn_t arcmsr_do_interrupt(int irq, void *dev_id) |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 177 | { |
| 178 | irqreturn_t handle_state; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 179 | struct AdapterControlBlock *acb = dev_id; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 180 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 181 | spin_lock(acb->host->host_lock); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 182 | handle_state = arcmsr_interrupt(acb); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 183 | spin_unlock(acb->host->host_lock); |
| 184 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 185 | return handle_state; |
| 186 | } |
| 187 | |
| 188 | static int arcmsr_bios_param(struct scsi_device *sdev, |
| 189 | struct block_device *bdev, sector_t capacity, int *geom) |
| 190 | { |
| 191 | int ret, heads, sectors, cylinders, total_capacity; |
| 192 | unsigned char *buffer;/* return copy of block device's partition table */ |
| 193 | |
| 194 | buffer = scsi_bios_ptable(bdev); |
| 195 | if (buffer) { |
| 196 | ret = scsi_partsize(buffer, capacity, &geom[2], &geom[0], &geom[1]); |
| 197 | kfree(buffer); |
| 198 | if (ret != -1) |
| 199 | return ret; |
| 200 | } |
| 201 | total_capacity = capacity; |
| 202 | heads = 64; |
| 203 | sectors = 32; |
| 204 | cylinders = total_capacity / (heads * sectors); |
| 205 | if (cylinders > 1024) { |
| 206 | heads = 255; |
| 207 | sectors = 63; |
| 208 | cylinders = total_capacity / (heads * sectors); |
| 209 | } |
| 210 | geom[0] = heads; |
| 211 | geom[1] = sectors; |
| 212 | geom[2] = cylinders; |
| 213 | return 0; |
| 214 | } |
| 215 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 216 | static void arcmsr_define_adapter_type(struct AdapterControlBlock *acb) |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 217 | { |
| 218 | struct pci_dev *pdev = acb->pdev; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 219 | u16 dev_id; |
| 220 | pci_read_config_word(pdev, PCI_DEVICE_ID, &dev_id); |
| 221 | switch (dev_id) { |
| 222 | case 0x1201 : { |
| 223 | acb->adapter_type = ACB_ADAPTER_TYPE_B; |
| 224 | } |
| 225 | break; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 226 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 227 | default : acb->adapter_type = ACB_ADAPTER_TYPE_A; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | static int arcmsr_alloc_ccb_pool(struct AdapterControlBlock *acb) |
| 232 | { |
| 233 | |
| 234 | switch (acb->adapter_type) { |
| 235 | |
| 236 | case ACB_ADAPTER_TYPE_A: { |
| 237 | struct pci_dev *pdev = acb->pdev; |
| 238 | void *dma_coherent; |
| 239 | dma_addr_t dma_coherent_handle, dma_addr; |
| 240 | struct CommandControlBlock *ccb_tmp; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 241 | int i, j; |
| 242 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 243 | acb->pmuA = ioremap(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0)); |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 244 | if (!acb->pmuA) { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 245 | printk(KERN_NOTICE "arcmsr%d: memory mapping region fail \n", |
| 246 | acb->host->host_no); |
Al Viro | db3a91f | 2007-10-29 05:08:38 +0000 | [diff] [blame] | 247 | return -ENOMEM; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | dma_coherent = dma_alloc_coherent(&pdev->dev, |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 251 | ARCMSR_MAX_FREECCB_NUM * |
| 252 | sizeof (struct CommandControlBlock) + 0x20, |
| 253 | &dma_coherent_handle, GFP_KERNEL); |
Al Viro | db3a91f | 2007-10-29 05:08:38 +0000 | [diff] [blame] | 254 | |
| 255 | if (!dma_coherent) { |
| 256 | iounmap(acb->pmuA); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 257 | return -ENOMEM; |
Al Viro | db3a91f | 2007-10-29 05:08:38 +0000 | [diff] [blame] | 258 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 259 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 260 | acb->dma_coherent = dma_coherent; |
| 261 | acb->dma_coherent_handle = dma_coherent_handle; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 262 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 263 | if (((unsigned long)dma_coherent & 0x1F)) { |
| 264 | dma_coherent = dma_coherent + |
| 265 | (0x20 - ((unsigned long)dma_coherent & 0x1F)); |
| 266 | dma_coherent_handle = dma_coherent_handle + |
| 267 | (0x20 - ((unsigned long)dma_coherent_handle & 0x1F)); |
| 268 | } |
| 269 | |
| 270 | dma_addr = dma_coherent_handle; |
| 271 | ccb_tmp = (struct CommandControlBlock *)dma_coherent; |
| 272 | for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) { |
| 273 | ccb_tmp->cdb_shifted_phyaddr = dma_addr >> 5; |
| 274 | ccb_tmp->acb = acb; |
| 275 | acb->pccb_pool[i] = ccb_tmp; |
| 276 | list_add_tail(&ccb_tmp->list, &acb->ccb_free_list); |
| 277 | dma_addr = dma_addr + sizeof(struct CommandControlBlock); |
| 278 | ccb_tmp++; |
| 279 | } |
| 280 | |
| 281 | acb->vir2phy_offset = (unsigned long)ccb_tmp -(unsigned long)dma_addr; |
| 282 | for (i = 0; i < ARCMSR_MAX_TARGETID; i++) |
| 283 | for (j = 0; j < ARCMSR_MAX_TARGETLUN; j++) |
| 284 | acb->devstate[i][j] = ARECA_RAID_GONE; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 285 | } |
| 286 | break; |
| 287 | |
| 288 | case ACB_ADAPTER_TYPE_B: { |
| 289 | |
| 290 | struct pci_dev *pdev = acb->pdev; |
| 291 | struct MessageUnit_B *reg; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 292 | void __iomem *mem_base0, *mem_base1; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 293 | void *dma_coherent; |
| 294 | dma_addr_t dma_coherent_handle, dma_addr; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 295 | struct CommandControlBlock *ccb_tmp; |
| 296 | int i, j; |
| 297 | |
| 298 | dma_coherent = dma_alloc_coherent(&pdev->dev, |
| 299 | ((ARCMSR_MAX_FREECCB_NUM * |
| 300 | sizeof(struct CommandControlBlock) + 0x20) + |
| 301 | sizeof(struct MessageUnit_B)), |
| 302 | &dma_coherent_handle, GFP_KERNEL); |
| 303 | if (!dma_coherent) |
| 304 | return -ENOMEM; |
| 305 | |
| 306 | acb->dma_coherent = dma_coherent; |
| 307 | acb->dma_coherent_handle = dma_coherent_handle; |
| 308 | |
| 309 | if (((unsigned long)dma_coherent & 0x1F)) { |
| 310 | dma_coherent = dma_coherent + |
| 311 | (0x20 - ((unsigned long)dma_coherent & 0x1F)); |
| 312 | dma_coherent_handle = dma_coherent_handle + |
| 313 | (0x20 - ((unsigned long)dma_coherent_handle & 0x1F)); |
| 314 | } |
| 315 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 316 | dma_addr = dma_coherent_handle; |
| 317 | ccb_tmp = (struct CommandControlBlock *)dma_coherent; |
| 318 | for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) { |
| 319 | ccb_tmp->cdb_shifted_phyaddr = dma_addr >> 5; |
| 320 | ccb_tmp->acb = acb; |
| 321 | acb->pccb_pool[i] = ccb_tmp; |
| 322 | list_add_tail(&ccb_tmp->list, &acb->ccb_free_list); |
| 323 | dma_addr = dma_addr + sizeof(struct CommandControlBlock); |
| 324 | ccb_tmp++; |
| 325 | } |
| 326 | |
| 327 | reg = (struct MessageUnit_B *)(dma_coherent + |
| 328 | ARCMSR_MAX_FREECCB_NUM * sizeof(struct CommandControlBlock)); |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 329 | acb->pmuB = reg; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 330 | mem_base0 = ioremap(pci_resource_start(pdev, 0), |
| 331 | pci_resource_len(pdev, 0)); |
Al Viro | db3a91f | 2007-10-29 05:08:38 +0000 | [diff] [blame] | 332 | if (!mem_base0) |
| 333 | goto out; |
| 334 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 335 | mem_base1 = ioremap(pci_resource_start(pdev, 2), |
| 336 | pci_resource_len(pdev, 2)); |
Al Viro | db3a91f | 2007-10-29 05:08:38 +0000 | [diff] [blame] | 337 | if (!mem_base1) { |
| 338 | iounmap(mem_base0); |
| 339 | goto out; |
| 340 | } |
| 341 | |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 342 | reg->drv2iop_doorbell_reg = mem_base0 + ARCMSR_DRV2IOP_DOORBELL; |
| 343 | reg->drv2iop_doorbell_mask_reg = mem_base0 + |
| 344 | ARCMSR_DRV2IOP_DOORBELL_MASK; |
| 345 | reg->iop2drv_doorbell_reg = mem_base0 + ARCMSR_IOP2DRV_DOORBELL; |
| 346 | reg->iop2drv_doorbell_mask_reg = mem_base0 + |
| 347 | ARCMSR_IOP2DRV_DOORBELL_MASK; |
| 348 | reg->ioctl_wbuffer_reg = mem_base1 + ARCMSR_IOCTL_WBUFFER; |
| 349 | reg->ioctl_rbuffer_reg = mem_base1 + ARCMSR_IOCTL_RBUFFER; |
| 350 | reg->msgcode_rwbuffer_reg = mem_base1 + ARCMSR_MSGCODE_RWBUFFER; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 351 | |
| 352 | acb->vir2phy_offset = (unsigned long)ccb_tmp -(unsigned long)dma_addr; |
| 353 | for (i = 0; i < ARCMSR_MAX_TARGETID; i++) |
| 354 | for (j = 0; j < ARCMSR_MAX_TARGETLUN; j++) |
| 355 | acb->devstate[i][j] = ARECA_RAID_GOOD; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 356 | } |
| 357 | break; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 358 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 359 | return 0; |
Al Viro | db3a91f | 2007-10-29 05:08:38 +0000 | [diff] [blame] | 360 | |
| 361 | out: |
| 362 | dma_free_coherent(&acb->pdev->dev, |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 363 | (ARCMSR_MAX_FREECCB_NUM * sizeof(struct CommandControlBlock) + 0x20 + |
| 364 | sizeof(struct MessageUnit_B)), acb->dma_coherent, acb->dma_coherent_handle); |
Al Viro | db3a91f | 2007-10-29 05:08:38 +0000 | [diff] [blame] | 365 | return -ENOMEM; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 366 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 367 | static void arcmsr_message_isr_bh_fn(struct work_struct *work) |
| 368 | { |
| 369 | struct AdapterControlBlock *acb = container_of(work, struct AdapterControlBlock, arcmsr_do_message_isr_bh); |
| 370 | |
| 371 | switch (acb->adapter_type) { |
| 372 | case ACB_ADAPTER_TYPE_A: { |
| 373 | |
| 374 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
| 375 | char *acb_dev_map = (char *)acb->device_map; |
| 376 | uint32_t __iomem *signature = (uint32_t __iomem *) (®->message_rwbuffer[0]); |
| 377 | char __iomem *devicemap = (char __iomem *) (®->message_rwbuffer[21]); |
| 378 | int target, lun; |
| 379 | struct scsi_device *psdev; |
| 380 | char diff; |
| 381 | |
| 382 | atomic_inc(&acb->rq_map_token); |
| 383 | if (readl(signature) == ARCMSR_SIGNATURE_GET_CONFIG) { |
| 384 | for (target = 0; target < ARCMSR_MAX_TARGETID - 1; target++) { |
| 385 | diff = (*acb_dev_map)^readb(devicemap); |
| 386 | if (diff != 0) { |
| 387 | char temp; |
| 388 | *acb_dev_map = readb(devicemap); |
| 389 | temp = *acb_dev_map; |
| 390 | for (lun = 0; lun < ARCMSR_MAX_TARGETLUN; lun++) { |
| 391 | if ((temp & 0x01) == 1 && (diff & 0x01) == 1) { |
| 392 | scsi_add_device(acb->host, 0, target, lun); |
| 393 | } else if ((temp & 0x01) == 0 && (diff & 0x01) == 1) { |
| 394 | psdev = scsi_device_lookup(acb->host, 0, target, lun); |
| 395 | if (psdev != NULL) { |
| 396 | scsi_remove_device(psdev); |
| 397 | scsi_device_put(psdev); |
| 398 | } |
| 399 | } |
| 400 | temp >>= 1; |
| 401 | diff >>= 1; |
| 402 | } |
| 403 | } |
| 404 | devicemap++; |
| 405 | acb_dev_map++; |
| 406 | } |
| 407 | } |
| 408 | break; |
| 409 | } |
| 410 | |
| 411 | case ACB_ADAPTER_TYPE_B: { |
| 412 | struct MessageUnit_B *reg = acb->pmuB; |
| 413 | char *acb_dev_map = (char *)acb->device_map; |
| 414 | uint32_t __iomem *signature = (uint32_t __iomem *)(®->msgcode_rwbuffer_reg[0]); |
| 415 | char __iomem *devicemap = (char __iomem *)(®->msgcode_rwbuffer_reg[21]); |
| 416 | int target, lun; |
| 417 | struct scsi_device *psdev; |
| 418 | char diff; |
| 419 | |
| 420 | atomic_inc(&acb->rq_map_token); |
| 421 | if (readl(signature) == ARCMSR_SIGNATURE_GET_CONFIG) { |
| 422 | for (target = 0; target < ARCMSR_MAX_TARGETID - 1; target++) { |
| 423 | diff = (*acb_dev_map)^readb(devicemap); |
| 424 | if (diff != 0) { |
| 425 | char temp; |
| 426 | *acb_dev_map = readb(devicemap); |
| 427 | temp = *acb_dev_map; |
| 428 | for (lun = 0; lun < ARCMSR_MAX_TARGETLUN; lun++) { |
| 429 | if ((temp & 0x01) == 1 && (diff & 0x01) == 1) { |
| 430 | scsi_add_device(acb->host, 0, target, lun); |
| 431 | } else if ((temp & 0x01) == 0 && (diff & 0x01) == 1) { |
| 432 | psdev = scsi_device_lookup(acb->host, 0, target, lun); |
| 433 | if (psdev != NULL) { |
| 434 | scsi_remove_device(psdev); |
| 435 | scsi_device_put(psdev); |
| 436 | } |
| 437 | } |
| 438 | temp >>= 1; |
| 439 | diff >>= 1; |
| 440 | } |
| 441 | } |
| 442 | devicemap++; |
| 443 | acb_dev_map++; |
| 444 | } |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 449 | |
| 450 | static int arcmsr_probe(struct pci_dev *pdev, |
| 451 | const struct pci_device_id *id) |
| 452 | { |
| 453 | struct Scsi_Host *host; |
| 454 | struct AdapterControlBlock *acb; |
| 455 | uint8_t bus, dev_fun; |
| 456 | int error; |
| 457 | |
| 458 | error = pci_enable_device(pdev); |
| 459 | if (error) |
| 460 | goto out; |
| 461 | pci_set_master(pdev); |
| 462 | |
| 463 | host = scsi_host_alloc(&arcmsr_scsi_host_template, |
| 464 | sizeof(struct AdapterControlBlock)); |
| 465 | if (!host) { |
| 466 | error = -ENOMEM; |
| 467 | goto out_disable_device; |
| 468 | } |
| 469 | acb = (struct AdapterControlBlock *)host->hostdata; |
| 470 | memset(acb, 0, sizeof (struct AdapterControlBlock)); |
| 471 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 472 | error = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 473 | if (error) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 474 | error = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 475 | if (error) { |
| 476 | printk(KERN_WARNING |
| 477 | "scsi%d: No suitable DMA mask available\n", |
| 478 | host->host_no); |
| 479 | goto out_host_put; |
| 480 | } |
| 481 | } |
| 482 | bus = pdev->bus->number; |
| 483 | dev_fun = pdev->devfn; |
| 484 | acb->host = host; |
| 485 | acb->pdev = pdev; |
| 486 | host->max_sectors = ARCMSR_MAX_XFER_SECTORS; |
| 487 | host->max_lun = ARCMSR_MAX_TARGETLUN; |
| 488 | host->max_id = ARCMSR_MAX_TARGETID;/*16:8*/ |
| 489 | host->max_cmd_len = 16; /*this is issue of 64bit LBA, over 2T byte*/ |
| 490 | host->sg_tablesize = ARCMSR_MAX_SG_ENTRIES; |
| 491 | host->can_queue = ARCMSR_MAX_FREECCB_NUM; /* max simultaneous cmds */ |
| 492 | host->cmd_per_lun = ARCMSR_MAX_CMD_PERLUN; |
| 493 | host->this_id = ARCMSR_SCSI_INITIATOR_ID; |
| 494 | host->unique_id = (bus << 8) | dev_fun; |
| 495 | host->irq = pdev->irq; |
| 496 | error = pci_request_regions(pdev, "arcmsr"); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 497 | if (error) { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 498 | goto out_host_put; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 499 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 500 | arcmsr_define_adapter_type(acb); |
| 501 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 502 | acb->acb_flags |= (ACB_F_MESSAGE_WQBUFFER_CLEARED | |
| 503 | ACB_F_MESSAGE_RQBUFFER_CLEARED | |
| 504 | ACB_F_MESSAGE_WQBUFFER_READED); |
| 505 | acb->acb_flags &= ~ACB_F_SCSISTOPADAPTER; |
| 506 | INIT_LIST_HEAD(&acb->ccb_free_list); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 507 | INIT_WORK(&acb->arcmsr_do_message_isr_bh, arcmsr_message_isr_bh_fn); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 508 | error = arcmsr_alloc_ccb_pool(acb); |
| 509 | if (error) |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 510 | goto out_release_regions; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 511 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 512 | arcmsr_iop_init(acb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 513 | error = request_irq(pdev->irq, arcmsr_do_interrupt, |
Jeff Garzik | 488a5c8 | 2007-07-27 13:01:15 -0400 | [diff] [blame] | 514 | IRQF_SHARED, "arcmsr", acb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 515 | if (error) |
| 516 | goto out_free_ccb_pool; |
| 517 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 518 | pci_set_drvdata(pdev, host); |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 519 | if (strncmp(acb->firm_version, "V1.42", 5) >= 0) |
| 520 | host->max_sectors= ARCMSR_MAX_XFER_SECTORS_B; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 521 | |
| 522 | error = scsi_add_host(host, &pdev->dev); |
| 523 | if (error) |
| 524 | goto out_free_irq; |
| 525 | |
| 526 | error = arcmsr_alloc_sysfs_attr(acb); |
| 527 | if (error) |
| 528 | goto out_free_sysfs; |
| 529 | |
| 530 | scsi_scan_host(host); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 531 | #ifdef CONFIG_SCSI_ARCMSR_AER |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 532 | pci_enable_pcie_error_reporting(pdev); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 533 | #endif |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 534 | atomic_set(&acb->rq_map_token, 16); |
| 535 | acb->fw_state = true; |
| 536 | init_timer(&acb->eternal_timer); |
| 537 | acb->eternal_timer.expires = jiffies + msecs_to_jiffies(10*HZ); |
| 538 | acb->eternal_timer.data = (unsigned long) acb; |
| 539 | acb->eternal_timer.function = &arcmsr_request_device_map; |
| 540 | add_timer(&acb->eternal_timer); |
| 541 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 542 | return 0; |
| 543 | out_free_sysfs: |
| 544 | out_free_irq: |
| 545 | free_irq(pdev->irq, acb); |
| 546 | out_free_ccb_pool: |
| 547 | arcmsr_free_ccb_pool(acb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 548 | out_release_regions: |
| 549 | pci_release_regions(pdev); |
| 550 | out_host_put: |
| 551 | scsi_host_put(host); |
| 552 | out_disable_device: |
| 553 | pci_disable_device(pdev); |
| 554 | out: |
| 555 | return error; |
| 556 | } |
| 557 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 558 | static uint8_t arcmsr_hba_wait_msgint_ready(struct AdapterControlBlock *acb) |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 559 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 560 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 561 | uint32_t Index; |
| 562 | uint8_t Retries = 0x00; |
| 563 | |
| 564 | do { |
| 565 | for (Index = 0; Index < 100; Index++) { |
| 566 | if (readl(®->outbound_intstatus) & |
| 567 | ARCMSR_MU_OUTBOUND_MESSAGE0_INT) { |
| 568 | writel(ARCMSR_MU_OUTBOUND_MESSAGE0_INT, |
| 569 | ®->outbound_intstatus); |
| 570 | return 0x00; |
| 571 | } |
| 572 | msleep(10); |
| 573 | }/*max 1 seconds*/ |
| 574 | |
| 575 | } while (Retries++ < 20);/*max 20 sec*/ |
| 576 | return 0xff; |
| 577 | } |
| 578 | |
| 579 | static uint8_t arcmsr_hbb_wait_msgint_ready(struct AdapterControlBlock *acb) |
| 580 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 581 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 582 | uint32_t Index; |
| 583 | uint8_t Retries = 0x00; |
| 584 | |
| 585 | do { |
| 586 | for (Index = 0; Index < 100; Index++) { |
| 587 | if (readl(reg->iop2drv_doorbell_reg) |
| 588 | & ARCMSR_IOP2DRV_MESSAGE_CMD_DONE) { |
| 589 | writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN |
| 590 | , reg->iop2drv_doorbell_reg); |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 591 | writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT, reg->drv2iop_doorbell_reg); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 592 | return 0x00; |
| 593 | } |
| 594 | msleep(10); |
| 595 | }/*max 1 seconds*/ |
| 596 | |
| 597 | } while (Retries++ < 20);/*max 20 sec*/ |
| 598 | return 0xff; |
| 599 | } |
| 600 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 601 | static uint8_t arcmsr_abort_hba_allcmd(struct AdapterControlBlock *acb) |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 602 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 603 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 604 | |
| 605 | writel(ARCMSR_INBOUND_MESG0_ABORT_CMD, ®->inbound_msgaddr0); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 606 | if (arcmsr_hba_wait_msgint_ready(acb)) { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 607 | printk(KERN_NOTICE |
| 608 | "arcmsr%d: wait 'abort all outstanding command' timeout \n" |
| 609 | , acb->host->host_no); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 610 | return 0xff; |
| 611 | } |
| 612 | return 0x00; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 615 | static uint8_t arcmsr_abort_hbb_allcmd(struct AdapterControlBlock *acb) |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 616 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 617 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 618 | |
| 619 | writel(ARCMSR_MESSAGE_ABORT_CMD, reg->drv2iop_doorbell_reg); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 620 | if (arcmsr_hbb_wait_msgint_ready(acb)) { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 621 | printk(KERN_NOTICE |
| 622 | "arcmsr%d: wait 'abort all outstanding command' timeout \n" |
| 623 | , acb->host->host_no); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 624 | return 0xff; |
| 625 | } |
| 626 | return 0x00; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 627 | } |
| 628 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 629 | static uint8_t arcmsr_abort_allcmd(struct AdapterControlBlock *acb) |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 630 | { |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 631 | uint8_t rtnval = 0; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 632 | switch (acb->adapter_type) { |
| 633 | case ACB_ADAPTER_TYPE_A: { |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 634 | rtnval = arcmsr_abort_hba_allcmd(acb); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 635 | } |
| 636 | break; |
| 637 | |
| 638 | case ACB_ADAPTER_TYPE_B: { |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 639 | rtnval = arcmsr_abort_hbb_allcmd(acb); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 640 | } |
| 641 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 642 | return rtnval; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 643 | } |
| 644 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 645 | static void arcmsr_pci_unmap_dma(struct CommandControlBlock *ccb) |
| 646 | { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 647 | struct scsi_cmnd *pcmd = ccb->pcmd; |
| 648 | |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 649 | scsi_dma_unmap(pcmd); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | static void arcmsr_ccb_complete(struct CommandControlBlock *ccb, int stand_flag) |
| 653 | { |
| 654 | struct AdapterControlBlock *acb = ccb->acb; |
| 655 | struct scsi_cmnd *pcmd = ccb->pcmd; |
| 656 | |
| 657 | arcmsr_pci_unmap_dma(ccb); |
| 658 | if (stand_flag == 1) |
| 659 | atomic_dec(&acb->ccboutstandingcount); |
| 660 | ccb->startdone = ARCMSR_CCB_DONE; |
| 661 | ccb->ccb_flags = 0; |
| 662 | list_add_tail(&ccb->list, &acb->ccb_free_list); |
| 663 | pcmd->scsi_done(pcmd); |
| 664 | } |
| 665 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 666 | static void arcmsr_flush_hba_cache(struct AdapterControlBlock *acb) |
| 667 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 668 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 669 | int retry_count = 30; |
| 670 | |
| 671 | writel(ARCMSR_INBOUND_MESG0_FLUSH_CACHE, ®->inbound_msgaddr0); |
| 672 | do { |
| 673 | if (!arcmsr_hba_wait_msgint_ready(acb)) |
| 674 | break; |
| 675 | else { |
| 676 | retry_count--; |
| 677 | printk(KERN_NOTICE "arcmsr%d: wait 'flush adapter cache' \ |
| 678 | timeout, retry count down = %d \n", acb->host->host_no, retry_count); |
| 679 | } |
| 680 | } while (retry_count != 0); |
| 681 | } |
| 682 | |
| 683 | static void arcmsr_flush_hbb_cache(struct AdapterControlBlock *acb) |
| 684 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 685 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 686 | int retry_count = 30; |
| 687 | |
| 688 | writel(ARCMSR_MESSAGE_FLUSH_CACHE, reg->drv2iop_doorbell_reg); |
| 689 | do { |
| 690 | if (!arcmsr_hbb_wait_msgint_ready(acb)) |
| 691 | break; |
| 692 | else { |
| 693 | retry_count--; |
| 694 | printk(KERN_NOTICE "arcmsr%d: wait 'flush adapter cache' \ |
| 695 | timeout,retry count down = %d \n", acb->host->host_no, retry_count); |
| 696 | } |
| 697 | } while (retry_count != 0); |
| 698 | } |
| 699 | |
| 700 | static void arcmsr_flush_adapter_cache(struct AdapterControlBlock *acb) |
| 701 | { |
| 702 | switch (acb->adapter_type) { |
| 703 | |
| 704 | case ACB_ADAPTER_TYPE_A: { |
| 705 | arcmsr_flush_hba_cache(acb); |
| 706 | } |
| 707 | break; |
| 708 | |
| 709 | case ACB_ADAPTER_TYPE_B: { |
| 710 | arcmsr_flush_hbb_cache(acb); |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | static void arcmsr_report_sense_info(struct CommandControlBlock *ccb) |
| 716 | { |
| 717 | |
| 718 | struct scsi_cmnd *pcmd = ccb->pcmd; |
| 719 | struct SENSE_DATA *sensebuffer = (struct SENSE_DATA *)pcmd->sense_buffer; |
| 720 | |
| 721 | pcmd->result = DID_OK << 16; |
| 722 | if (sensebuffer) { |
| 723 | int sense_data_length = |
FUJITA Tomonori | b80ca4f | 2008-01-13 15:46:13 +0900 | [diff] [blame] | 724 | sizeof(struct SENSE_DATA) < SCSI_SENSE_BUFFERSIZE |
| 725 | ? sizeof(struct SENSE_DATA) : SCSI_SENSE_BUFFERSIZE; |
| 726 | memset(sensebuffer, 0, SCSI_SENSE_BUFFERSIZE); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 727 | memcpy(sensebuffer, ccb->arcmsr_cdb.SenseData, sense_data_length); |
| 728 | sensebuffer->ErrorCode = SCSI_SENSE_CURRENT_ERRORS; |
| 729 | sensebuffer->Valid = 1; |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | static u32 arcmsr_disable_outbound_ints(struct AdapterControlBlock *acb) |
| 734 | { |
| 735 | u32 orig_mask = 0; |
| 736 | switch (acb->adapter_type) { |
| 737 | |
| 738 | case ACB_ADAPTER_TYPE_A : { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 739 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 740 | orig_mask = readl(®->outbound_intmask); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 741 | writel(orig_mask|ARCMSR_MU_OUTBOUND_ALL_INTMASKENABLE, \ |
| 742 | ®->outbound_intmask); |
| 743 | } |
| 744 | break; |
| 745 | |
| 746 | case ACB_ADAPTER_TYPE_B : { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 747 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 748 | orig_mask = readl(reg->iop2drv_doorbell_mask_reg); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 749 | writel(0, reg->iop2drv_doorbell_mask_reg); |
| 750 | } |
| 751 | break; |
| 752 | } |
| 753 | return orig_mask; |
| 754 | } |
| 755 | |
| 756 | static void arcmsr_report_ccb_state(struct AdapterControlBlock *acb, \ |
| 757 | struct CommandControlBlock *ccb, uint32_t flag_ccb) |
| 758 | { |
| 759 | |
| 760 | uint8_t id, lun; |
| 761 | id = ccb->pcmd->device->id; |
| 762 | lun = ccb->pcmd->device->lun; |
| 763 | if (!(flag_ccb & ARCMSR_CCBREPLY_FLAG_ERROR)) { |
| 764 | if (acb->devstate[id][lun] == ARECA_RAID_GONE) |
| 765 | acb->devstate[id][lun] = ARECA_RAID_GOOD; |
| 766 | ccb->pcmd->result = DID_OK << 16; |
| 767 | arcmsr_ccb_complete(ccb, 1); |
| 768 | } else { |
| 769 | switch (ccb->arcmsr_cdb.DeviceStatus) { |
| 770 | case ARCMSR_DEV_SELECT_TIMEOUT: { |
| 771 | acb->devstate[id][lun] = ARECA_RAID_GONE; |
| 772 | ccb->pcmd->result = DID_NO_CONNECT << 16; |
| 773 | arcmsr_ccb_complete(ccb, 1); |
| 774 | } |
| 775 | break; |
| 776 | |
| 777 | case ARCMSR_DEV_ABORTED: |
| 778 | |
| 779 | case ARCMSR_DEV_INIT_FAIL: { |
| 780 | acb->devstate[id][lun] = ARECA_RAID_GONE; |
| 781 | ccb->pcmd->result = DID_BAD_TARGET << 16; |
| 782 | arcmsr_ccb_complete(ccb, 1); |
| 783 | } |
| 784 | break; |
| 785 | |
| 786 | case ARCMSR_DEV_CHECK_CONDITION: { |
| 787 | acb->devstate[id][lun] = ARECA_RAID_GOOD; |
| 788 | arcmsr_report_sense_info(ccb); |
| 789 | arcmsr_ccb_complete(ccb, 1); |
| 790 | } |
| 791 | break; |
| 792 | |
| 793 | default: |
| 794 | printk(KERN_NOTICE |
| 795 | "arcmsr%d: scsi id = %d lun = %d" |
| 796 | " isr get command error done, " |
| 797 | "but got unknown DeviceStatus = 0x%x \n" |
| 798 | , acb->host->host_no |
| 799 | , id |
| 800 | , lun |
| 801 | , ccb->arcmsr_cdb.DeviceStatus); |
| 802 | acb->devstate[id][lun] = ARECA_RAID_GONE; |
| 803 | ccb->pcmd->result = DID_NO_CONNECT << 16; |
| 804 | arcmsr_ccb_complete(ccb, 1); |
| 805 | break; |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | static void arcmsr_drain_donequeue(struct AdapterControlBlock *acb, uint32_t flag_ccb) |
| 811 | |
| 812 | { |
| 813 | struct CommandControlBlock *ccb; |
| 814 | |
| 815 | ccb = (struct CommandControlBlock *)(acb->vir2phy_offset + (flag_ccb << 5)); |
| 816 | if ((ccb->acb != acb) || (ccb->startdone != ARCMSR_CCB_START)) { |
| 817 | if (ccb->startdone == ARCMSR_CCB_ABORTED) { |
| 818 | struct scsi_cmnd *abortcmd = ccb->pcmd; |
| 819 | if (abortcmd) { |
| 820 | abortcmd->result |= DID_ABORT << 16; |
| 821 | arcmsr_ccb_complete(ccb, 1); |
| 822 | printk(KERN_NOTICE "arcmsr%d: ccb ='0x%p' \ |
| 823 | isr got aborted command \n", acb->host->host_no, ccb); |
| 824 | } |
| 825 | } |
| 826 | printk(KERN_NOTICE "arcmsr%d: isr get an illegal ccb command \ |
| 827 | done acb = '0x%p'" |
| 828 | "ccb = '0x%p' ccbacb = '0x%p' startdone = 0x%x" |
| 829 | " ccboutstandingcount = %d \n" |
| 830 | , acb->host->host_no |
| 831 | , acb |
| 832 | , ccb |
| 833 | , ccb->acb |
| 834 | , ccb->startdone |
| 835 | , atomic_read(&acb->ccboutstandingcount)); |
| 836 | } |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 837 | else |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 838 | arcmsr_report_ccb_state(acb, ccb, flag_ccb); |
| 839 | } |
| 840 | |
| 841 | static void arcmsr_done4abort_postqueue(struct AdapterControlBlock *acb) |
| 842 | { |
| 843 | int i = 0; |
| 844 | uint32_t flag_ccb; |
| 845 | |
| 846 | switch (acb->adapter_type) { |
| 847 | |
| 848 | case ACB_ADAPTER_TYPE_A: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 849 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 850 | uint32_t outbound_intstatus; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 851 | outbound_intstatus = readl(®->outbound_intstatus) & |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 852 | acb->outbound_int_enable; |
| 853 | /*clear and abort all outbound posted Q*/ |
| 854 | writel(outbound_intstatus, ®->outbound_intstatus);/*clear interrupt*/ |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 855 | while (((flag_ccb = readl(®->outbound_queueport)) != 0xFFFFFFFF) |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 856 | && (i++ < ARCMSR_MAX_OUTSTANDING_CMD)) { |
| 857 | arcmsr_drain_donequeue(acb, flag_ccb); |
| 858 | } |
| 859 | } |
| 860 | break; |
| 861 | |
| 862 | case ACB_ADAPTER_TYPE_B: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 863 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 864 | /*clear all outbound posted Q*/ |
| 865 | for (i = 0; i < ARCMSR_MAX_HBB_POSTQUEUE; i++) { |
| 866 | if ((flag_ccb = readl(®->done_qbuffer[i])) != 0) { |
| 867 | writel(0, ®->done_qbuffer[i]); |
| 868 | arcmsr_drain_donequeue(acb, flag_ccb); |
| 869 | } |
| 870 | writel(0, ®->post_qbuffer[i]); |
| 871 | } |
| 872 | reg->doneq_index = 0; |
| 873 | reg->postq_index = 0; |
| 874 | } |
| 875 | break; |
| 876 | } |
| 877 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 878 | static void arcmsr_remove(struct pci_dev *pdev) |
| 879 | { |
| 880 | struct Scsi_Host *host = pci_get_drvdata(pdev); |
| 881 | struct AdapterControlBlock *acb = |
| 882 | (struct AdapterControlBlock *) host->hostdata; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 883 | int poll_count = 0; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 884 | arcmsr_free_sysfs_attr(acb); |
| 885 | scsi_remove_host(host); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 886 | flush_scheduled_work(); |
| 887 | del_timer_sync(&acb->eternal_timer); |
| 888 | arcmsr_disable_outbound_ints(acb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 889 | arcmsr_stop_adapter_bgrb(acb); |
| 890 | arcmsr_flush_adapter_cache(acb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 891 | acb->acb_flags |= ACB_F_SCSISTOPADAPTER; |
| 892 | acb->acb_flags &= ~ACB_F_IOP_INITED; |
| 893 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 894 | for (poll_count = 0; poll_count < ARCMSR_MAX_OUTSTANDING_CMD; poll_count++) { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 895 | if (!atomic_read(&acb->ccboutstandingcount)) |
| 896 | break; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 897 | arcmsr_interrupt(acb);/* FIXME: need spinlock */ |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 898 | msleep(25); |
| 899 | } |
| 900 | |
| 901 | if (atomic_read(&acb->ccboutstandingcount)) { |
| 902 | int i; |
| 903 | |
| 904 | arcmsr_abort_allcmd(acb); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 905 | arcmsr_done4abort_postqueue(acb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 906 | for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) { |
| 907 | struct CommandControlBlock *ccb = acb->pccb_pool[i]; |
| 908 | if (ccb->startdone == ARCMSR_CCB_START) { |
| 909 | ccb->startdone = ARCMSR_CCB_ABORTED; |
| 910 | ccb->pcmd->result = DID_ABORT << 16; |
| 911 | arcmsr_ccb_complete(ccb, 1); |
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | free_irq(pdev->irq, acb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 917 | arcmsr_free_ccb_pool(acb); |
| 918 | pci_release_regions(pdev); |
| 919 | |
| 920 | scsi_host_put(host); |
| 921 | |
| 922 | pci_disable_device(pdev); |
| 923 | pci_set_drvdata(pdev, NULL); |
| 924 | } |
| 925 | |
| 926 | static void arcmsr_shutdown(struct pci_dev *pdev) |
| 927 | { |
| 928 | struct Scsi_Host *host = pci_get_drvdata(pdev); |
| 929 | struct AdapterControlBlock *acb = |
| 930 | (struct AdapterControlBlock *)host->hostdata; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 931 | del_timer_sync(&acb->eternal_timer); |
| 932 | arcmsr_disable_outbound_ints(acb); |
| 933 | flush_scheduled_work(); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 934 | arcmsr_stop_adapter_bgrb(acb); |
| 935 | arcmsr_flush_adapter_cache(acb); |
| 936 | } |
| 937 | |
| 938 | static int arcmsr_module_init(void) |
| 939 | { |
| 940 | int error = 0; |
| 941 | |
| 942 | error = pci_register_driver(&arcmsr_pci_driver); |
| 943 | return error; |
| 944 | } |
| 945 | |
| 946 | static void arcmsr_module_exit(void) |
| 947 | { |
| 948 | pci_unregister_driver(&arcmsr_pci_driver); |
| 949 | } |
| 950 | module_init(arcmsr_module_init); |
| 951 | module_exit(arcmsr_module_exit); |
| 952 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 953 | static void arcmsr_enable_outbound_ints(struct AdapterControlBlock *acb, |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 954 | u32 intmask_org) |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 955 | { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 956 | u32 mask; |
| 957 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 958 | switch (acb->adapter_type) { |
| 959 | |
| 960 | case ACB_ADAPTER_TYPE_A : { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 961 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 962 | mask = intmask_org & ~(ARCMSR_MU_OUTBOUND_POSTQUEUE_INTMASKENABLE | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 963 | ARCMSR_MU_OUTBOUND_DOORBELL_INTMASKENABLE| |
| 964 | ARCMSR_MU_OUTBOUND_MESSAGE0_INTMASKENABLE); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 965 | writel(mask, ®->outbound_intmask); |
| 966 | acb->outbound_int_enable = ~(intmask_org & mask) & 0x000000ff; |
| 967 | } |
| 968 | break; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 969 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 970 | case ACB_ADAPTER_TYPE_B : { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 971 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 972 | mask = intmask_org | (ARCMSR_IOP2DRV_DATA_WRITE_OK | |
| 973 | ARCMSR_IOP2DRV_DATA_READ_OK | |
| 974 | ARCMSR_IOP2DRV_CDB_DONE | |
| 975 | ARCMSR_IOP2DRV_MESSAGE_CMD_DONE); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 976 | writel(mask, reg->iop2drv_doorbell_mask_reg); |
| 977 | acb->outbound_int_enable = (intmask_org | mask) & 0x0000000f; |
| 978 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 982 | static int arcmsr_build_ccb(struct AdapterControlBlock *acb, |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 983 | struct CommandControlBlock *ccb, struct scsi_cmnd *pcmd) |
| 984 | { |
| 985 | struct ARCMSR_CDB *arcmsr_cdb = (struct ARCMSR_CDB *)&ccb->arcmsr_cdb; |
| 986 | int8_t *psge = (int8_t *)&arcmsr_cdb->u; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 987 | __le32 address_lo, address_hi; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 988 | int arccdbsize = 0x30; |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 989 | int nseg; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 990 | |
| 991 | ccb->pcmd = pcmd; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 992 | memset(arcmsr_cdb, 0, sizeof(struct ARCMSR_CDB)); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 993 | arcmsr_cdb->Bus = 0; |
| 994 | arcmsr_cdb->TargetID = pcmd->device->id; |
| 995 | arcmsr_cdb->LUN = pcmd->device->lun; |
| 996 | arcmsr_cdb->Function = 1; |
| 997 | arcmsr_cdb->CdbLength = (uint8_t)pcmd->cmd_len; |
| 998 | arcmsr_cdb->Context = (unsigned long)arcmsr_cdb; |
| 999 | memcpy(arcmsr_cdb->Cdb, pcmd->cmnd, pcmd->cmd_len); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1000 | |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1001 | nseg = scsi_dma_map(pcmd); |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 1002 | if (nseg > ARCMSR_MAX_SG_ENTRIES) |
| 1003 | return FAILED; |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1004 | BUG_ON(nseg < 0); |
| 1005 | |
| 1006 | if (nseg) { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1007 | __le32 length; |
| 1008 | int i, cdb_sgcount = 0; |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1009 | struct scatterlist *sg; |
| 1010 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1011 | /* map stor port SG list to our iop SG List. */ |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1012 | scsi_for_each_sg(pcmd, sg, nseg, i) { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1013 | /* Get the physical address of the current data pointer */ |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1014 | length = cpu_to_le32(sg_dma_len(sg)); |
| 1015 | address_lo = cpu_to_le32(dma_addr_lo32(sg_dma_address(sg))); |
| 1016 | address_hi = cpu_to_le32(dma_addr_hi32(sg_dma_address(sg))); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1017 | if (address_hi == 0) { |
| 1018 | struct SG32ENTRY *pdma_sg = (struct SG32ENTRY *)psge; |
| 1019 | |
| 1020 | pdma_sg->address = address_lo; |
| 1021 | pdma_sg->length = length; |
| 1022 | psge += sizeof (struct SG32ENTRY); |
| 1023 | arccdbsize += sizeof (struct SG32ENTRY); |
| 1024 | } else { |
| 1025 | struct SG64ENTRY *pdma_sg = (struct SG64ENTRY *)psge; |
| 1026 | |
| 1027 | pdma_sg->addresshigh = address_hi; |
| 1028 | pdma_sg->address = address_lo; |
Al Viro | 6a7d26d | 2007-10-29 05:08:48 +0000 | [diff] [blame] | 1029 | pdma_sg->length = length|cpu_to_le32(IS_SG64_ADDR); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1030 | psge += sizeof (struct SG64ENTRY); |
| 1031 | arccdbsize += sizeof (struct SG64ENTRY); |
| 1032 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1033 | cdb_sgcount++; |
| 1034 | } |
| 1035 | arcmsr_cdb->sgcount = (uint8_t)cdb_sgcount; |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1036 | arcmsr_cdb->DataLength = scsi_bufflen(pcmd); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1037 | if ( arccdbsize > 256) |
| 1038 | arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_SGL_BSIZE; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1039 | } |
| 1040 | if (pcmd->sc_data_direction == DMA_TO_DEVICE ) { |
| 1041 | arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_WRITE; |
| 1042 | ccb->ccb_flags |= CCB_FLAG_WRITE; |
| 1043 | } |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 1044 | return SUCCESS; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | static void arcmsr_post_ccb(struct AdapterControlBlock *acb, struct CommandControlBlock *ccb) |
| 1048 | { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1049 | uint32_t cdb_shifted_phyaddr = ccb->cdb_shifted_phyaddr; |
| 1050 | struct ARCMSR_CDB *arcmsr_cdb = (struct ARCMSR_CDB *)&ccb->arcmsr_cdb; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1051 | atomic_inc(&acb->ccboutstandingcount); |
| 1052 | ccb->startdone = ARCMSR_CCB_START; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1053 | |
| 1054 | switch (acb->adapter_type) { |
| 1055 | case ACB_ADAPTER_TYPE_A: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1056 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1057 | |
| 1058 | if (arcmsr_cdb->Flags & ARCMSR_CDB_FLAG_SGL_BSIZE) |
| 1059 | writel(cdb_shifted_phyaddr | ARCMSR_CCBPOST_FLAG_SGL_BSIZE, |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1060 | ®->inbound_queueport); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1061 | else { |
| 1062 | writel(cdb_shifted_phyaddr, ®->inbound_queueport); |
| 1063 | } |
| 1064 | } |
| 1065 | break; |
| 1066 | |
| 1067 | case ACB_ADAPTER_TYPE_B: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1068 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1069 | uint32_t ending_index, index = reg->postq_index; |
| 1070 | |
| 1071 | ending_index = ((index + 1) % ARCMSR_MAX_HBB_POSTQUEUE); |
| 1072 | writel(0, ®->post_qbuffer[ending_index]); |
| 1073 | if (arcmsr_cdb->Flags & ARCMSR_CDB_FLAG_SGL_BSIZE) { |
| 1074 | writel(cdb_shifted_phyaddr | ARCMSR_CCBPOST_FLAG_SGL_BSIZE,\ |
| 1075 | ®->post_qbuffer[index]); |
| 1076 | } |
| 1077 | else { |
| 1078 | writel(cdb_shifted_phyaddr, ®->post_qbuffer[index]); |
| 1079 | } |
| 1080 | index++; |
| 1081 | index %= ARCMSR_MAX_HBB_POSTQUEUE;/*if last index number set it to 0 */ |
| 1082 | reg->postq_index = index; |
| 1083 | writel(ARCMSR_DRV2IOP_CDB_POSTED, reg->drv2iop_doorbell_reg); |
| 1084 | } |
| 1085 | break; |
| 1086 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1089 | static void arcmsr_stop_hba_bgrb(struct AdapterControlBlock *acb) |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1090 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1091 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1092 | acb->acb_flags &= ~ACB_F_MSG_START_BGRB; |
| 1093 | writel(ARCMSR_INBOUND_MESG0_STOP_BGRB, ®->inbound_msgaddr0); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1094 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1095 | if (arcmsr_hba_wait_msgint_ready(acb)) { |
| 1096 | printk(KERN_NOTICE |
| 1097 | "arcmsr%d: wait 'stop adapter background rebulid' timeout \n" |
| 1098 | , acb->host->host_no); |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | static void arcmsr_stop_hbb_bgrb(struct AdapterControlBlock *acb) |
| 1103 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1104 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1105 | acb->acb_flags &= ~ACB_F_MSG_START_BGRB; |
| 1106 | writel(ARCMSR_MESSAGE_STOP_BGRB, reg->drv2iop_doorbell_reg); |
| 1107 | |
| 1108 | if (arcmsr_hbb_wait_msgint_ready(acb)) { |
| 1109 | printk(KERN_NOTICE |
| 1110 | "arcmsr%d: wait 'stop adapter background rebulid' timeout \n" |
| 1111 | , acb->host->host_no); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock *acb) |
| 1116 | { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1117 | switch (acb->adapter_type) { |
| 1118 | case ACB_ADAPTER_TYPE_A: { |
| 1119 | arcmsr_stop_hba_bgrb(acb); |
| 1120 | } |
| 1121 | break; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1122 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1123 | case ACB_ADAPTER_TYPE_B: { |
| 1124 | arcmsr_stop_hbb_bgrb(acb); |
| 1125 | } |
| 1126 | break; |
| 1127 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | static void arcmsr_free_ccb_pool(struct AdapterControlBlock *acb) |
| 1131 | { |
Al Viro | db3a91f | 2007-10-29 05:08:38 +0000 | [diff] [blame] | 1132 | switch (acb->adapter_type) { |
| 1133 | case ACB_ADAPTER_TYPE_A: { |
| 1134 | iounmap(acb->pmuA); |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 1135 | dma_free_coherent(&acb->pdev->dev, |
| 1136 | ARCMSR_MAX_FREECCB_NUM * sizeof (struct CommandControlBlock) + 0x20, |
| 1137 | acb->dma_coherent, |
| 1138 | acb->dma_coherent_handle); |
Al Viro | db3a91f | 2007-10-29 05:08:38 +0000 | [diff] [blame] | 1139 | break; |
| 1140 | } |
| 1141 | case ACB_ADAPTER_TYPE_B: { |
| 1142 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1143 | iounmap((u8 *)reg->drv2iop_doorbell_reg - ARCMSR_DRV2IOP_DOORBELL); |
| 1144 | iounmap((u8 *)reg->ioctl_wbuffer_reg - ARCMSR_IOCTL_WBUFFER); |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 1145 | dma_free_coherent(&acb->pdev->dev, |
| 1146 | (ARCMSR_MAX_FREECCB_NUM * sizeof(struct CommandControlBlock) + 0x20 + |
| 1147 | sizeof(struct MessageUnit_B)), acb->dma_coherent, acb->dma_coherent_handle); |
Al Viro | db3a91f | 2007-10-29 05:08:38 +0000 | [diff] [blame] | 1148 | } |
| 1149 | } |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 1150 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1153 | void arcmsr_iop_message_read(struct AdapterControlBlock *acb) |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1154 | { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1155 | switch (acb->adapter_type) { |
| 1156 | case ACB_ADAPTER_TYPE_A: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1157 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1158 | writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK, ®->inbound_doorbell); |
| 1159 | } |
| 1160 | break; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1161 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1162 | case ACB_ADAPTER_TYPE_B: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1163 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1164 | writel(ARCMSR_DRV2IOP_DATA_READ_OK, reg->drv2iop_doorbell_reg); |
| 1165 | } |
| 1166 | break; |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | static void arcmsr_iop_message_wrote(struct AdapterControlBlock *acb) |
| 1171 | { |
| 1172 | switch (acb->adapter_type) { |
| 1173 | case ACB_ADAPTER_TYPE_A: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1174 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1175 | /* |
| 1176 | ** push inbound doorbell tell iop, driver data write ok |
| 1177 | ** and wait reply on next hwinterrupt for next Qbuffer post |
| 1178 | */ |
| 1179 | writel(ARCMSR_INBOUND_DRIVER_DATA_WRITE_OK, ®->inbound_doorbell); |
| 1180 | } |
| 1181 | break; |
| 1182 | |
| 1183 | case ACB_ADAPTER_TYPE_B: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1184 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1185 | /* |
| 1186 | ** push inbound doorbell tell iop, driver data write ok |
| 1187 | ** and wait reply on next hwinterrupt for next Qbuffer post |
| 1188 | */ |
| 1189 | writel(ARCMSR_DRV2IOP_DATA_WRITE_OK, reg->drv2iop_doorbell_reg); |
| 1190 | } |
| 1191 | break; |
| 1192 | } |
| 1193 | } |
| 1194 | |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1195 | struct QBUFFER __iomem *arcmsr_get_iop_rqbuffer(struct AdapterControlBlock *acb) |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1196 | { |
Al Viro | 0c7eb2e | 2007-10-29 05:08:58 +0000 | [diff] [blame] | 1197 | struct QBUFFER __iomem *qbuffer = NULL; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1198 | |
| 1199 | switch (acb->adapter_type) { |
| 1200 | |
| 1201 | case ACB_ADAPTER_TYPE_A: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1202 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
| 1203 | qbuffer = (struct QBUFFER __iomem *)®->message_rbuffer; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1204 | } |
| 1205 | break; |
| 1206 | |
| 1207 | case ACB_ADAPTER_TYPE_B: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1208 | struct MessageUnit_B *reg = acb->pmuB; |
| 1209 | qbuffer = (struct QBUFFER __iomem *)reg->ioctl_rbuffer_reg; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1210 | } |
| 1211 | break; |
| 1212 | } |
| 1213 | return qbuffer; |
| 1214 | } |
| 1215 | |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1216 | static struct QBUFFER __iomem *arcmsr_get_iop_wqbuffer(struct AdapterControlBlock *acb) |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1217 | { |
Al Viro | 0c7eb2e | 2007-10-29 05:08:58 +0000 | [diff] [blame] | 1218 | struct QBUFFER __iomem *pqbuffer = NULL; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1219 | |
| 1220 | switch (acb->adapter_type) { |
| 1221 | |
| 1222 | case ACB_ADAPTER_TYPE_A: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1223 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
| 1224 | pqbuffer = (struct QBUFFER __iomem *) ®->message_wbuffer; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1225 | } |
| 1226 | break; |
| 1227 | |
| 1228 | case ACB_ADAPTER_TYPE_B: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1229 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1230 | pqbuffer = (struct QBUFFER __iomem *)reg->ioctl_wbuffer_reg; |
| 1231 | } |
| 1232 | break; |
| 1233 | } |
| 1234 | return pqbuffer; |
| 1235 | } |
| 1236 | |
| 1237 | static void arcmsr_iop2drv_data_wrote_handle(struct AdapterControlBlock *acb) |
| 1238 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1239 | struct QBUFFER __iomem *prbuffer; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1240 | struct QBUFFER *pQbuffer; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1241 | uint8_t __iomem *iop_data; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1242 | int32_t my_empty_len, iop_len, rqbuf_firstindex, rqbuf_lastindex; |
| 1243 | |
| 1244 | rqbuf_lastindex = acb->rqbuf_lastindex; |
| 1245 | rqbuf_firstindex = acb->rqbuf_firstindex; |
| 1246 | prbuffer = arcmsr_get_iop_rqbuffer(acb); |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1247 | iop_data = (uint8_t __iomem *)prbuffer->data; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1248 | iop_len = prbuffer->data_len; |
| 1249 | my_empty_len = (rqbuf_firstindex - rqbuf_lastindex -1)&(ARCMSR_MAX_QBUFFER -1); |
| 1250 | |
| 1251 | if (my_empty_len >= iop_len) |
| 1252 | { |
| 1253 | while (iop_len > 0) { |
| 1254 | pQbuffer = (struct QBUFFER *)&acb->rqbuffer[rqbuf_lastindex]; |
| 1255 | memcpy(pQbuffer, iop_data,1); |
| 1256 | rqbuf_lastindex++; |
| 1257 | rqbuf_lastindex %= ARCMSR_MAX_QBUFFER; |
| 1258 | iop_data++; |
| 1259 | iop_len--; |
| 1260 | } |
| 1261 | acb->rqbuf_lastindex = rqbuf_lastindex; |
| 1262 | arcmsr_iop_message_read(acb); |
| 1263 | } |
| 1264 | |
| 1265 | else { |
| 1266 | acb->acb_flags |= ACB_F_IOPDATA_OVERFLOW; |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | static void arcmsr_iop2drv_data_read_handle(struct AdapterControlBlock *acb) |
| 1271 | { |
| 1272 | acb->acb_flags |= ACB_F_MESSAGE_WQBUFFER_READED; |
| 1273 | if (acb->wqbuf_firstindex != acb->wqbuf_lastindex) { |
| 1274 | uint8_t *pQbuffer; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1275 | struct QBUFFER __iomem *pwbuffer; |
| 1276 | uint8_t __iomem *iop_data; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1277 | int32_t allxfer_len = 0; |
| 1278 | |
| 1279 | acb->acb_flags &= (~ACB_F_MESSAGE_WQBUFFER_READED); |
| 1280 | pwbuffer = arcmsr_get_iop_wqbuffer(acb); |
| 1281 | iop_data = (uint8_t __iomem *)pwbuffer->data; |
| 1282 | |
| 1283 | while ((acb->wqbuf_firstindex != acb->wqbuf_lastindex) && \ |
| 1284 | (allxfer_len < 124)) { |
| 1285 | pQbuffer = &acb->wqbuffer[acb->wqbuf_firstindex]; |
| 1286 | memcpy(iop_data, pQbuffer, 1); |
| 1287 | acb->wqbuf_firstindex++; |
| 1288 | acb->wqbuf_firstindex %= ARCMSR_MAX_QBUFFER; |
| 1289 | iop_data++; |
| 1290 | allxfer_len++; |
| 1291 | } |
| 1292 | pwbuffer->data_len = allxfer_len; |
| 1293 | |
| 1294 | arcmsr_iop_message_wrote(acb); |
| 1295 | } |
| 1296 | |
| 1297 | if (acb->wqbuf_firstindex == acb->wqbuf_lastindex) { |
| 1298 | acb->acb_flags |= ACB_F_MESSAGE_WQBUFFER_CLEARED; |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | static void arcmsr_hba_doorbell_isr(struct AdapterControlBlock *acb) |
| 1303 | { |
| 1304 | uint32_t outbound_doorbell; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1305 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1306 | |
| 1307 | outbound_doorbell = readl(®->outbound_doorbell); |
| 1308 | writel(outbound_doorbell, ®->outbound_doorbell); |
| 1309 | if (outbound_doorbell & ARCMSR_OUTBOUND_IOP331_DATA_WRITE_OK) { |
| 1310 | arcmsr_iop2drv_data_wrote_handle(acb); |
| 1311 | } |
| 1312 | |
| 1313 | if (outbound_doorbell & ARCMSR_OUTBOUND_IOP331_DATA_READ_OK) { |
| 1314 | arcmsr_iop2drv_data_read_handle(acb); |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | static void arcmsr_hba_postqueue_isr(struct AdapterControlBlock *acb) |
| 1319 | { |
| 1320 | uint32_t flag_ccb; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1321 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1322 | |
| 1323 | while ((flag_ccb = readl(®->outbound_queueport)) != 0xFFFFFFFF) { |
| 1324 | arcmsr_drain_donequeue(acb, flag_ccb); |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | static void arcmsr_hbb_postqueue_isr(struct AdapterControlBlock *acb) |
| 1329 | { |
| 1330 | uint32_t index; |
| 1331 | uint32_t flag_ccb; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1332 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1333 | |
| 1334 | index = reg->doneq_index; |
| 1335 | |
| 1336 | while ((flag_ccb = readl(®->done_qbuffer[index])) != 0) { |
| 1337 | writel(0, ®->done_qbuffer[index]); |
| 1338 | arcmsr_drain_donequeue(acb, flag_ccb); |
| 1339 | index++; |
| 1340 | index %= ARCMSR_MAX_HBB_POSTQUEUE; |
| 1341 | reg->doneq_index = index; |
| 1342 | } |
| 1343 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1344 | /* |
| 1345 | ********************************************************************************** |
| 1346 | ** Handle a message interrupt |
| 1347 | ** |
| 1348 | ** The only message interrupt we expect is in response to a query for the current adapter config. |
| 1349 | ** We want this in order to compare the drivemap so that we can detect newly-attached drives. |
| 1350 | ********************************************************************************** |
| 1351 | */ |
| 1352 | static void arcmsr_hba_message_isr(struct AdapterControlBlock *acb) |
| 1353 | { |
| 1354 | struct MessageUnit_A *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1355 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1356 | /*clear interrupt and message state*/ |
| 1357 | writel(ARCMSR_MU_OUTBOUND_MESSAGE0_INT, ®->outbound_intstatus); |
| 1358 | schedule_work(&acb->arcmsr_do_message_isr_bh); |
| 1359 | } |
| 1360 | static void arcmsr_hbb_message_isr(struct AdapterControlBlock *acb) |
| 1361 | { |
| 1362 | struct MessageUnit_B *reg = acb->pmuB; |
| 1363 | |
| 1364 | /*clear interrupt and message state*/ |
| 1365 | writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN, reg->iop2drv_doorbell_reg); |
| 1366 | schedule_work(&acb->arcmsr_do_message_isr_bh); |
| 1367 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1368 | static int arcmsr_handle_hba_isr(struct AdapterControlBlock *acb) |
| 1369 | { |
| 1370 | uint32_t outbound_intstatus; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1371 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1372 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1373 | outbound_intstatus = readl(®->outbound_intstatus) & |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1374 | acb->outbound_int_enable; |
| 1375 | if (!(outbound_intstatus & ARCMSR_MU_OUTBOUND_HANDLE_INT)) { |
| 1376 | return 1; |
| 1377 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1378 | writel(outbound_intstatus, ®->outbound_intstatus); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1379 | if (outbound_intstatus & ARCMSR_MU_OUTBOUND_DOORBELL_INT) { |
| 1380 | arcmsr_hba_doorbell_isr(acb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1381 | } |
| 1382 | if (outbound_intstatus & ARCMSR_MU_OUTBOUND_POSTQUEUE_INT) { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1383 | arcmsr_hba_postqueue_isr(acb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1384 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1385 | if (outbound_intstatus & ARCMSR_MU_OUTBOUND_MESSAGE0_INT) { |
| 1386 | /* messenger of "driver to iop commands" */ |
| 1387 | arcmsr_hba_message_isr(acb); |
| 1388 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1389 | return 0; |
| 1390 | } |
| 1391 | |
| 1392 | static int arcmsr_handle_hbb_isr(struct AdapterControlBlock *acb) |
| 1393 | { |
| 1394 | uint32_t outbound_doorbell; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1395 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1396 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1397 | outbound_doorbell = readl(reg->iop2drv_doorbell_reg) & |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1398 | acb->outbound_int_enable; |
| 1399 | if (!outbound_doorbell) |
| 1400 | return 1; |
| 1401 | |
| 1402 | writel(~outbound_doorbell, reg->iop2drv_doorbell_reg); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1403 | /*in case the last action of doorbell interrupt clearance is cached, |
| 1404 | this action can push HW to write down the clear bit*/ |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 1405 | readl(reg->iop2drv_doorbell_reg); |
| 1406 | writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT, reg->drv2iop_doorbell_reg); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1407 | if (outbound_doorbell & ARCMSR_IOP2DRV_DATA_WRITE_OK) { |
| 1408 | arcmsr_iop2drv_data_wrote_handle(acb); |
| 1409 | } |
| 1410 | if (outbound_doorbell & ARCMSR_IOP2DRV_DATA_READ_OK) { |
| 1411 | arcmsr_iop2drv_data_read_handle(acb); |
| 1412 | } |
| 1413 | if (outbound_doorbell & ARCMSR_IOP2DRV_CDB_DONE) { |
| 1414 | arcmsr_hbb_postqueue_isr(acb); |
| 1415 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1416 | if (outbound_doorbell & ARCMSR_IOP2DRV_MESSAGE_CMD_DONE) { |
| 1417 | /* messenger of "driver to iop commands" */ |
| 1418 | arcmsr_hbb_message_isr(acb); |
| 1419 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1420 | |
| 1421 | return 0; |
| 1422 | } |
| 1423 | |
| 1424 | static irqreturn_t arcmsr_interrupt(struct AdapterControlBlock *acb) |
| 1425 | { |
| 1426 | switch (acb->adapter_type) { |
| 1427 | case ACB_ADAPTER_TYPE_A: { |
| 1428 | if (arcmsr_handle_hba_isr(acb)) { |
| 1429 | return IRQ_NONE; |
| 1430 | } |
| 1431 | } |
| 1432 | break; |
| 1433 | |
| 1434 | case ACB_ADAPTER_TYPE_B: { |
| 1435 | if (arcmsr_handle_hbb_isr(acb)) { |
| 1436 | return IRQ_NONE; |
| 1437 | } |
| 1438 | } |
| 1439 | break; |
| 1440 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1441 | return IRQ_HANDLED; |
| 1442 | } |
| 1443 | |
| 1444 | static void arcmsr_iop_parking(struct AdapterControlBlock *acb) |
| 1445 | { |
| 1446 | if (acb) { |
| 1447 | /* stop adapter background rebuild */ |
| 1448 | if (acb->acb_flags & ACB_F_MSG_START_BGRB) { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1449 | uint32_t intmask_org; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1450 | acb->acb_flags &= ~ACB_F_MSG_START_BGRB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1451 | intmask_org = arcmsr_disable_outbound_ints(acb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1452 | arcmsr_stop_adapter_bgrb(acb); |
| 1453 | arcmsr_flush_adapter_cache(acb); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1454 | arcmsr_enable_outbound_ints(acb, intmask_org); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1455 | } |
| 1456 | } |
| 1457 | } |
| 1458 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1459 | void arcmsr_post_ioctldata2iop(struct AdapterControlBlock *acb) |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1460 | { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1461 | int32_t wqbuf_firstindex, wqbuf_lastindex; |
| 1462 | uint8_t *pQbuffer; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1463 | struct QBUFFER __iomem *pwbuffer; |
| 1464 | uint8_t __iomem *iop_data; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1465 | int32_t allxfer_len = 0; |
| 1466 | |
| 1467 | pwbuffer = arcmsr_get_iop_wqbuffer(acb); |
| 1468 | iop_data = (uint8_t __iomem *)pwbuffer->data; |
| 1469 | if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_READED) { |
| 1470 | acb->acb_flags &= (~ACB_F_MESSAGE_WQBUFFER_READED); |
| 1471 | wqbuf_firstindex = acb->wqbuf_firstindex; |
| 1472 | wqbuf_lastindex = acb->wqbuf_lastindex; |
| 1473 | while ((wqbuf_firstindex != wqbuf_lastindex) && (allxfer_len < 124)) { |
| 1474 | pQbuffer = &acb->wqbuffer[wqbuf_firstindex]; |
| 1475 | memcpy(iop_data, pQbuffer, 1); |
| 1476 | wqbuf_firstindex++; |
| 1477 | wqbuf_firstindex %= ARCMSR_MAX_QBUFFER; |
| 1478 | iop_data++; |
| 1479 | allxfer_len++; |
| 1480 | } |
| 1481 | acb->wqbuf_firstindex = wqbuf_firstindex; |
| 1482 | pwbuffer->data_len = allxfer_len; |
| 1483 | arcmsr_iop_message_wrote(acb); |
| 1484 | } |
| 1485 | } |
| 1486 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1487 | static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1488 | struct scsi_cmnd *cmd) |
| 1489 | { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1490 | struct CMD_MESSAGE_FIELD *pcmdmessagefld; |
| 1491 | int retvalue = 0, transfer_len = 0; |
| 1492 | char *buffer; |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1493 | struct scatterlist *sg; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1494 | uint32_t controlcode = (uint32_t ) cmd->cmnd[5] << 24 | |
| 1495 | (uint32_t ) cmd->cmnd[6] << 16 | |
| 1496 | (uint32_t ) cmd->cmnd[7] << 8 | |
| 1497 | (uint32_t ) cmd->cmnd[8]; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1498 | /* 4 bytes: Areca io control code */ |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1499 | |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1500 | sg = scsi_sglist(cmd); |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 1501 | buffer = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset; |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1502 | if (scsi_sg_count(cmd) > 1) { |
| 1503 | retvalue = ARCMSR_MESSAGE_FAIL; |
| 1504 | goto message_out; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1505 | } |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1506 | transfer_len += sg->length; |
| 1507 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1508 | if (transfer_len > sizeof(struct CMD_MESSAGE_FIELD)) { |
| 1509 | retvalue = ARCMSR_MESSAGE_FAIL; |
| 1510 | goto message_out; |
| 1511 | } |
| 1512 | pcmdmessagefld = (struct CMD_MESSAGE_FIELD *) buffer; |
| 1513 | switch(controlcode) { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1514 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1515 | case ARCMSR_MESSAGE_READ_RQBUFFER: { |
Daniel Drake | 69e562c | 2008-02-20 13:29:05 +0000 | [diff] [blame] | 1516 | unsigned char *ver_addr; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1517 | uint8_t *pQbuffer, *ptmpQbuffer; |
| 1518 | int32_t allxfer_len = 0; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1519 | |
Daniel Drake | 69e562c | 2008-02-20 13:29:05 +0000 | [diff] [blame] | 1520 | ver_addr = kmalloc(1032, GFP_ATOMIC); |
| 1521 | if (!ver_addr) { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1522 | retvalue = ARCMSR_MESSAGE_FAIL; |
| 1523 | goto message_out; |
| 1524 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1525 | |
| 1526 | if (!acb->fw_state) { |
| 1527 | pcmdmessagefld->cmdmessage.ReturnCode = |
| 1528 | ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON; |
| 1529 | goto message_out; |
| 1530 | } |
| 1531 | |
Daniel Drake | 69e562c | 2008-02-20 13:29:05 +0000 | [diff] [blame] | 1532 | ptmpQbuffer = ver_addr; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1533 | while ((acb->rqbuf_firstindex != acb->rqbuf_lastindex) |
| 1534 | && (allxfer_len < 1031)) { |
| 1535 | pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; |
| 1536 | memcpy(ptmpQbuffer, pQbuffer, 1); |
| 1537 | acb->rqbuf_firstindex++; |
| 1538 | acb->rqbuf_firstindex %= ARCMSR_MAX_QBUFFER; |
| 1539 | ptmpQbuffer++; |
| 1540 | allxfer_len++; |
| 1541 | } |
| 1542 | if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1543 | |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1544 | struct QBUFFER __iomem *prbuffer; |
| 1545 | uint8_t __iomem *iop_data; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1546 | int32_t iop_len; |
| 1547 | |
| 1548 | acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; |
| 1549 | prbuffer = arcmsr_get_iop_rqbuffer(acb); |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1550 | iop_data = prbuffer->data; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1551 | iop_len = readl(&prbuffer->data_len); |
| 1552 | while (iop_len > 0) { |
| 1553 | acb->rqbuffer[acb->rqbuf_lastindex] = readb(iop_data); |
| 1554 | acb->rqbuf_lastindex++; |
| 1555 | acb->rqbuf_lastindex %= ARCMSR_MAX_QBUFFER; |
| 1556 | iop_data++; |
| 1557 | iop_len--; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1558 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1559 | arcmsr_iop_message_read(acb); |
| 1560 | } |
Daniel Drake | 69e562c | 2008-02-20 13:29:05 +0000 | [diff] [blame] | 1561 | memcpy(pcmdmessagefld->messagedatabuffer, ver_addr, allxfer_len); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1562 | pcmdmessagefld->cmdmessage.Length = allxfer_len; |
| 1563 | pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK; |
Daniel Drake | 69e562c | 2008-02-20 13:29:05 +0000 | [diff] [blame] | 1564 | kfree(ver_addr); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1565 | } |
| 1566 | break; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1567 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1568 | case ARCMSR_MESSAGE_WRITE_WQBUFFER: { |
Daniel Drake | 69e562c | 2008-02-20 13:29:05 +0000 | [diff] [blame] | 1569 | unsigned char *ver_addr; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1570 | int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; |
| 1571 | uint8_t *pQbuffer, *ptmpuserbuffer; |
| 1572 | |
Daniel Drake | 69e562c | 2008-02-20 13:29:05 +0000 | [diff] [blame] | 1573 | ver_addr = kmalloc(1032, GFP_ATOMIC); |
| 1574 | if (!ver_addr) { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1575 | retvalue = ARCMSR_MESSAGE_FAIL; |
| 1576 | goto message_out; |
| 1577 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1578 | if (!acb->fw_state) { |
| 1579 | pcmdmessagefld->cmdmessage.ReturnCode = |
| 1580 | ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON; |
| 1581 | goto message_out; |
| 1582 | } |
| 1583 | |
Daniel Drake | 69e562c | 2008-02-20 13:29:05 +0000 | [diff] [blame] | 1584 | ptmpuserbuffer = ver_addr; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1585 | user_len = pcmdmessagefld->cmdmessage.Length; |
| 1586 | memcpy(ptmpuserbuffer, pcmdmessagefld->messagedatabuffer, user_len); |
| 1587 | wqbuf_lastindex = acb->wqbuf_lastindex; |
| 1588 | wqbuf_firstindex = acb->wqbuf_firstindex; |
| 1589 | if (wqbuf_lastindex != wqbuf_firstindex) { |
| 1590 | struct SENSE_DATA *sensebuffer = |
| 1591 | (struct SENSE_DATA *)cmd->sense_buffer; |
| 1592 | arcmsr_post_ioctldata2iop(acb); |
| 1593 | /* has error report sensedata */ |
| 1594 | sensebuffer->ErrorCode = 0x70; |
| 1595 | sensebuffer->SenseKey = ILLEGAL_REQUEST; |
| 1596 | sensebuffer->AdditionalSenseLength = 0x0A; |
| 1597 | sensebuffer->AdditionalSenseCode = 0x20; |
| 1598 | sensebuffer->Valid = 1; |
| 1599 | retvalue = ARCMSR_MESSAGE_FAIL; |
| 1600 | } else { |
| 1601 | my_empty_len = (wqbuf_firstindex-wqbuf_lastindex - 1) |
| 1602 | &(ARCMSR_MAX_QBUFFER - 1); |
| 1603 | if (my_empty_len >= user_len) { |
| 1604 | while (user_len > 0) { |
| 1605 | pQbuffer = |
| 1606 | &acb->wqbuffer[acb->wqbuf_lastindex]; |
| 1607 | memcpy(pQbuffer, ptmpuserbuffer, 1); |
| 1608 | acb->wqbuf_lastindex++; |
| 1609 | acb->wqbuf_lastindex %= ARCMSR_MAX_QBUFFER; |
| 1610 | ptmpuserbuffer++; |
| 1611 | user_len--; |
| 1612 | } |
| 1613 | if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_CLEARED) { |
| 1614 | acb->acb_flags &= |
| 1615 | ~ACB_F_MESSAGE_WQBUFFER_CLEARED; |
| 1616 | arcmsr_post_ioctldata2iop(acb); |
| 1617 | } |
| 1618 | } else { |
| 1619 | /* has error report sensedata */ |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1620 | struct SENSE_DATA *sensebuffer = |
| 1621 | (struct SENSE_DATA *)cmd->sense_buffer; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1622 | sensebuffer->ErrorCode = 0x70; |
| 1623 | sensebuffer->SenseKey = ILLEGAL_REQUEST; |
| 1624 | sensebuffer->AdditionalSenseLength = 0x0A; |
| 1625 | sensebuffer->AdditionalSenseCode = 0x20; |
| 1626 | sensebuffer->Valid = 1; |
| 1627 | retvalue = ARCMSR_MESSAGE_FAIL; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1628 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1629 | } |
Daniel Drake | 69e562c | 2008-02-20 13:29:05 +0000 | [diff] [blame] | 1630 | kfree(ver_addr); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1631 | } |
| 1632 | break; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1633 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1634 | case ARCMSR_MESSAGE_CLEAR_RQBUFFER: { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1635 | uint8_t *pQbuffer = acb->rqbuffer; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1636 | if (!acb->fw_state) { |
| 1637 | pcmdmessagefld->cmdmessage.ReturnCode = |
| 1638 | ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON; |
| 1639 | goto message_out; |
| 1640 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1641 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1642 | if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { |
| 1643 | acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; |
| 1644 | arcmsr_iop_message_read(acb); |
| 1645 | } |
| 1646 | acb->acb_flags |= ACB_F_MESSAGE_RQBUFFER_CLEARED; |
| 1647 | acb->rqbuf_firstindex = 0; |
| 1648 | acb->rqbuf_lastindex = 0; |
| 1649 | memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER); |
| 1650 | pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1651 | } |
| 1652 | break; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1653 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1654 | case ARCMSR_MESSAGE_CLEAR_WQBUFFER: { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1655 | uint8_t *pQbuffer = acb->wqbuffer; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1656 | if (!acb->fw_state) { |
| 1657 | pcmdmessagefld->cmdmessage.ReturnCode = |
| 1658 | ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON; |
| 1659 | goto message_out; |
| 1660 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1661 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1662 | if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { |
| 1663 | acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; |
| 1664 | arcmsr_iop_message_read(acb); |
| 1665 | } |
| 1666 | acb->acb_flags |= |
| 1667 | (ACB_F_MESSAGE_WQBUFFER_CLEARED | |
| 1668 | ACB_F_MESSAGE_WQBUFFER_READED); |
| 1669 | acb->wqbuf_firstindex = 0; |
| 1670 | acb->wqbuf_lastindex = 0; |
| 1671 | memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER); |
| 1672 | pcmdmessagefld->cmdmessage.ReturnCode = |
| 1673 | ARCMSR_MESSAGE_RETURNCODE_OK; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1674 | } |
| 1675 | break; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1676 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1677 | case ARCMSR_MESSAGE_CLEAR_ALLQBUFFER: { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1678 | uint8_t *pQbuffer; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1679 | if (!acb->fw_state) { |
| 1680 | pcmdmessagefld->cmdmessage.ReturnCode = |
| 1681 | ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON; |
| 1682 | goto message_out; |
| 1683 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1684 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1685 | if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { |
| 1686 | acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; |
| 1687 | arcmsr_iop_message_read(acb); |
| 1688 | } |
| 1689 | acb->acb_flags |= |
| 1690 | (ACB_F_MESSAGE_WQBUFFER_CLEARED |
| 1691 | | ACB_F_MESSAGE_RQBUFFER_CLEARED |
| 1692 | | ACB_F_MESSAGE_WQBUFFER_READED); |
| 1693 | acb->rqbuf_firstindex = 0; |
| 1694 | acb->rqbuf_lastindex = 0; |
| 1695 | acb->wqbuf_firstindex = 0; |
| 1696 | acb->wqbuf_lastindex = 0; |
| 1697 | pQbuffer = acb->rqbuffer; |
| 1698 | memset(pQbuffer, 0, sizeof(struct QBUFFER)); |
| 1699 | pQbuffer = acb->wqbuffer; |
| 1700 | memset(pQbuffer, 0, sizeof(struct QBUFFER)); |
| 1701 | pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1702 | } |
| 1703 | break; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1704 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1705 | case ARCMSR_MESSAGE_RETURN_CODE_3F: { |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1706 | if (!acb->fw_state) { |
| 1707 | pcmdmessagefld->cmdmessage.ReturnCode = |
| 1708 | ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON; |
| 1709 | goto message_out; |
| 1710 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1711 | pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_3F; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1712 | } |
| 1713 | break; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1714 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1715 | case ARCMSR_MESSAGE_SAY_HELLO: { |
| 1716 | int8_t *hello_string = "Hello! I am ARCMSR"; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1717 | if (!acb->fw_state) { |
| 1718 | pcmdmessagefld->cmdmessage.ReturnCode = |
| 1719 | ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON; |
| 1720 | goto message_out; |
| 1721 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1722 | memcpy(pcmdmessagefld->messagedatabuffer, hello_string |
| 1723 | , (int16_t)strlen(hello_string)); |
| 1724 | pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1725 | } |
| 1726 | break; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1727 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1728 | case ARCMSR_MESSAGE_SAY_GOODBYE: |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1729 | if (!acb->fw_state) { |
| 1730 | pcmdmessagefld->cmdmessage.ReturnCode = |
| 1731 | ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON; |
| 1732 | goto message_out; |
| 1733 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1734 | arcmsr_iop_parking(acb); |
| 1735 | break; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1736 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1737 | case ARCMSR_MESSAGE_FLUSH_ADAPTER_CACHE: |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1738 | if (!acb->fw_state) { |
| 1739 | pcmdmessagefld->cmdmessage.ReturnCode = |
| 1740 | ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON; |
| 1741 | goto message_out; |
| 1742 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1743 | arcmsr_flush_adapter_cache(acb); |
| 1744 | break; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1745 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1746 | default: |
| 1747 | retvalue = ARCMSR_MESSAGE_FAIL; |
| 1748 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1749 | message_out: |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1750 | sg = scsi_sglist(cmd); |
| 1751 | kunmap_atomic(buffer - sg->offset, KM_IRQ0); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1752 | return retvalue; |
| 1753 | } |
| 1754 | |
| 1755 | static struct CommandControlBlock *arcmsr_get_freeccb(struct AdapterControlBlock *acb) |
| 1756 | { |
| 1757 | struct list_head *head = &acb->ccb_free_list; |
| 1758 | struct CommandControlBlock *ccb = NULL; |
| 1759 | |
| 1760 | if (!list_empty(head)) { |
| 1761 | ccb = list_entry(head->next, struct CommandControlBlock, list); |
| 1762 | list_del(head->next); |
| 1763 | } |
| 1764 | return ccb; |
| 1765 | } |
| 1766 | |
| 1767 | static void arcmsr_handle_virtual_command(struct AdapterControlBlock *acb, |
| 1768 | struct scsi_cmnd *cmd) |
| 1769 | { |
| 1770 | switch (cmd->cmnd[0]) { |
| 1771 | case INQUIRY: { |
| 1772 | unsigned char inqdata[36]; |
| 1773 | char *buffer; |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1774 | struct scatterlist *sg; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1775 | |
| 1776 | if (cmd->device->lun) { |
| 1777 | cmd->result = (DID_TIME_OUT << 16); |
| 1778 | cmd->scsi_done(cmd); |
| 1779 | return; |
| 1780 | } |
| 1781 | inqdata[0] = TYPE_PROCESSOR; |
| 1782 | /* Periph Qualifier & Periph Dev Type */ |
| 1783 | inqdata[1] = 0; |
| 1784 | /* rem media bit & Dev Type Modifier */ |
| 1785 | inqdata[2] = 0; |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 1786 | /* ISO, ECMA, & ANSI versions */ |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1787 | inqdata[4] = 31; |
| 1788 | /* length of additional data */ |
| 1789 | strncpy(&inqdata[8], "Areca ", 8); |
| 1790 | /* Vendor Identification */ |
| 1791 | strncpy(&inqdata[16], "RAID controller ", 16); |
| 1792 | /* Product Identification */ |
| 1793 | strncpy(&inqdata[32], "R001", 4); /* Product Revision */ |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1794 | |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1795 | sg = scsi_sglist(cmd); |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 1796 | buffer = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset; |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1797 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1798 | memcpy(buffer, inqdata, sizeof(inqdata)); |
FUJITA Tomonori | deff262 | 2007-05-14 19:25:56 +0900 | [diff] [blame] | 1799 | sg = scsi_sglist(cmd); |
| 1800 | kunmap_atomic(buffer - sg->offset, KM_IRQ0); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1801 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1802 | cmd->scsi_done(cmd); |
| 1803 | } |
| 1804 | break; |
| 1805 | case WRITE_BUFFER: |
| 1806 | case READ_BUFFER: { |
| 1807 | if (arcmsr_iop_message_xfer(acb, cmd)) |
| 1808 | cmd->result = (DID_ERROR << 16); |
| 1809 | cmd->scsi_done(cmd); |
| 1810 | } |
| 1811 | break; |
| 1812 | default: |
| 1813 | cmd->scsi_done(cmd); |
| 1814 | } |
| 1815 | } |
| 1816 | |
| 1817 | static int arcmsr_queue_command(struct scsi_cmnd *cmd, |
| 1818 | void (* done)(struct scsi_cmnd *)) |
| 1819 | { |
| 1820 | struct Scsi_Host *host = cmd->device->host; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1821 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1822 | struct CommandControlBlock *ccb; |
| 1823 | int target = cmd->device->id; |
| 1824 | int lun = cmd->device->lun; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1825 | uint8_t scsicmd = cmd->cmnd[0]; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1826 | cmd->scsi_done = done; |
| 1827 | cmd->host_scribble = NULL; |
| 1828 | cmd->result = 0; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1829 | |
| 1830 | if ((scsicmd == SYNCHRONIZE_CACHE) || (scsicmd == SEND_DIAGNOSTIC)) { |
| 1831 | if (acb->devstate[target][lun] == ARECA_RAID_GONE) { |
| 1832 | cmd->result = (DID_NO_CONNECT << 16); |
| 1833 | } |
| 1834 | cmd->scsi_done(cmd); |
| 1835 | return 0; |
| 1836 | } |
| 1837 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1838 | if (acb->acb_flags & ACB_F_BUS_RESET) { |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1839 | switch (acb->adapter_type) { |
| 1840 | case ACB_ADAPTER_TYPE_A: { |
| 1841 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
| 1842 | uint32_t intmask_org, outbound_doorbell; |
| 1843 | |
| 1844 | if ((readl(®->outbound_msgaddr1) & |
| 1845 | ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK) == 0) { |
| 1846 | printk(KERN_NOTICE "arcmsr%d: bus reset and return busy\n", |
| 1847 | acb->host->host_no); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1848 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1849 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1850 | |
| 1851 | acb->acb_flags &= ~ACB_F_FIRMWARE_TRAP; |
| 1852 | printk(KERN_NOTICE "arcmsr%d: hardware bus reset and reset ok\n", |
| 1853 | acb->host->host_no); |
| 1854 | /* disable all outbound interrupt */ |
| 1855 | intmask_org = arcmsr_disable_outbound_ints(acb); |
| 1856 | arcmsr_get_firmware_spec(acb, 1); |
| 1857 | /*start background rebuild*/ |
| 1858 | arcmsr_start_adapter_bgrb(acb); |
| 1859 | /* clear Qbuffer if door bell ringed */ |
| 1860 | outbound_doorbell = readl(®->outbound_doorbell); |
| 1861 | /*clear interrupt */ |
| 1862 | writel(outbound_doorbell, ®->outbound_doorbell); |
| 1863 | writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK, |
| 1864 | ®->inbound_doorbell); |
| 1865 | /* enable outbound Post Queue,outbound doorbell Interrupt */ |
| 1866 | arcmsr_enable_outbound_ints(acb, intmask_org); |
| 1867 | acb->acb_flags |= ACB_F_IOP_INITED; |
| 1868 | acb->acb_flags &= ~ACB_F_BUS_RESET; |
| 1869 | } |
| 1870 | break; |
| 1871 | case ACB_ADAPTER_TYPE_B: { |
| 1872 | } |
| 1873 | } |
| 1874 | } |
| 1875 | |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 1876 | if (target == 16) { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1877 | /* virtual device for iop message transfer */ |
| 1878 | arcmsr_handle_virtual_command(acb, cmd); |
| 1879 | return 0; |
| 1880 | } |
| 1881 | if (acb->devstate[target][lun] == ARECA_RAID_GONE) { |
| 1882 | uint8_t block_cmd; |
| 1883 | |
| 1884 | block_cmd = cmd->cmnd[0] & 0x0f; |
| 1885 | if (block_cmd == 0x08 || block_cmd == 0x0a) { |
| 1886 | printk(KERN_NOTICE |
| 1887 | "arcmsr%d: block 'read/write'" |
| 1888 | "command with gone raid volume" |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 1889 | " Cmd = %2x, TargetId = %d, Lun = %d \n" |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1890 | , acb->host->host_no |
| 1891 | , cmd->cmnd[0] |
| 1892 | , target, lun); |
| 1893 | cmd->result = (DID_NO_CONNECT << 16); |
| 1894 | cmd->scsi_done(cmd); |
| 1895 | return 0; |
| 1896 | } |
| 1897 | } |
| 1898 | if (atomic_read(&acb->ccboutstandingcount) >= |
| 1899 | ARCMSR_MAX_OUTSTANDING_CMD) |
| 1900 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1901 | |
| 1902 | ccb = arcmsr_get_freeccb(acb); |
| 1903 | if (!ccb) |
| 1904 | return SCSI_MLQUEUE_HOST_BUSY; |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 1905 | if ( arcmsr_build_ccb( acb, ccb, cmd ) == FAILED ) { |
| 1906 | cmd->result = (DID_ERROR << 16) | (RESERVATION_CONFLICT << 1); |
| 1907 | cmd->scsi_done(cmd); |
| 1908 | return 0; |
| 1909 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1910 | arcmsr_post_ccb(acb, ccb); |
| 1911 | return 0; |
| 1912 | } |
| 1913 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1914 | static void *arcmsr_get_hba_config(struct AdapterControlBlock *acb, int mode) |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1915 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1916 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1917 | char *acb_firm_model = acb->firm_model; |
| 1918 | char *acb_firm_version = acb->firm_version; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1919 | char *acb_device_map = acb->device_map; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1920 | char __iomem *iop_firm_model = (char __iomem *)(®->message_rwbuffer[15]); |
| 1921 | char __iomem *iop_firm_version = (char __iomem *)(®->message_rwbuffer[17]); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1922 | char __iomem *iop_device_map = (char __iomem *) (®->message_rwbuffer[21]); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1923 | int count; |
| 1924 | |
| 1925 | writel(ARCMSR_INBOUND_MESG0_GET_CONFIG, ®->inbound_msgaddr0); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1926 | if (arcmsr_hba_wait_msgint_ready(acb)) { |
| 1927 | printk(KERN_NOTICE "arcmsr%d: wait 'get adapter firmware \ |
| 1928 | miscellaneous data' timeout \n", acb->host->host_no); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1929 | return NULL; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1930 | } |
| 1931 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1932 | if (mode == 1) { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1933 | count = 8; |
| 1934 | while (count) { |
| 1935 | *acb_firm_model = readb(iop_firm_model); |
| 1936 | acb_firm_model++; |
| 1937 | iop_firm_model++; |
| 1938 | count--; |
| 1939 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1940 | |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1941 | count = 16; |
| 1942 | while (count) { |
| 1943 | *acb_firm_version = readb(iop_firm_version); |
| 1944 | acb_firm_version++; |
| 1945 | iop_firm_version++; |
| 1946 | count--; |
| 1947 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1948 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1949 | count = 16; |
| 1950 | while (count) { |
| 1951 | *acb_device_map = readb(iop_device_map); |
| 1952 | acb_device_map++; |
| 1953 | iop_device_map++; |
| 1954 | count--; |
| 1955 | } |
| 1956 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1957 | printk(KERN_INFO "ARECA RAID ADAPTER%d: FIRMWARE VERSION %s \n" |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1958 | , acb->host->host_no |
| 1959 | , acb->firm_version); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1960 | acb->signature = readl(®->message_rwbuffer[0]); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 1961 | acb->firm_request_len = readl(®->message_rwbuffer[1]); |
| 1962 | acb->firm_numbers_queue = readl(®->message_rwbuffer[2]); |
| 1963 | acb->firm_sdram_size = readl(®->message_rwbuffer[3]); |
| 1964 | acb->firm_hd_channels = readl(®->message_rwbuffer[4]); |
| 1965 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1966 | return reg->message_rwbuffer; |
| 1967 | } |
| 1968 | static void __iomem *arcmsr_get_hbb_config(struct AdapterControlBlock *acb, int mode) |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1969 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1970 | struct MessageUnit_B *reg = acb->pmuB; |
| 1971 | uint32_t __iomem *lrwbuffer = reg->msgcode_rwbuffer_reg; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1972 | char *acb_firm_model = acb->firm_model; |
| 1973 | char *acb_firm_version = acb->firm_version; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1974 | char *acb_device_map = acb->device_map; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1975 | char __iomem *iop_firm_model = (char __iomem *)(&lrwbuffer[15]); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1976 | /*firm_model,15,60-67*/ |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 1977 | char __iomem *iop_firm_version = (char __iomem *)(&lrwbuffer[17]); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1978 | /*firm_version,17,68-83*/ |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1979 | char __iomem *iop_device_map = (char __iomem *) (&lrwbuffer[21]); |
| 1980 | /*firm_version,21,84-99*/ |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1981 | int count; |
| 1982 | |
| 1983 | writel(ARCMSR_MESSAGE_GET_CONFIG, reg->drv2iop_doorbell_reg); |
| 1984 | if (arcmsr_hbb_wait_msgint_ready(acb)) { |
| 1985 | printk(KERN_NOTICE "arcmsr%d: wait 'get adapter firmware \ |
| 1986 | miscellaneous data' timeout \n", acb->host->host_no); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1987 | return NULL; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1988 | } |
| 1989 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 1990 | if (mode == 1) { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 1991 | count = 8; |
| 1992 | while (count) |
| 1993 | { |
| 1994 | *acb_firm_model = readb(iop_firm_model); |
| 1995 | acb_firm_model++; |
| 1996 | iop_firm_model++; |
| 1997 | count--; |
| 1998 | } |
| 1999 | |
| 2000 | count = 16; |
| 2001 | while (count) |
| 2002 | { |
| 2003 | *acb_firm_version = readb(iop_firm_version); |
| 2004 | acb_firm_version++; |
| 2005 | iop_firm_version++; |
| 2006 | count--; |
| 2007 | } |
| 2008 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2009 | count = 16; |
| 2010 | while (count) { |
| 2011 | *acb_device_map = readb(iop_device_map); |
| 2012 | acb_device_map++; |
| 2013 | iop_device_map++; |
| 2014 | count--; |
| 2015 | } |
| 2016 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2017 | printk(KERN_INFO "ARECA RAID ADAPTER%d: FIRMWARE VERSION %s \n", |
| 2018 | acb->host->host_no, |
| 2019 | acb->firm_version); |
| 2020 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2021 | acb->signature = readl(lrwbuffer++); |
| 2022 | /*firm_signature,1,00-03*/ |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2023 | acb->firm_request_len = readl(lrwbuffer++); |
| 2024 | /*firm_request_len,1,04-07*/ |
| 2025 | acb->firm_numbers_queue = readl(lrwbuffer++); |
| 2026 | /*firm_numbers_queue,2,08-11*/ |
| 2027 | acb->firm_sdram_size = readl(lrwbuffer++); |
| 2028 | /*firm_sdram_size,3,12-15*/ |
| 2029 | acb->firm_hd_channels = readl(lrwbuffer); |
| 2030 | /*firm_ide_channels,4,16-19*/ |
| 2031 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2032 | return reg->msgcode_rwbuffer_reg; |
| 2033 | } |
| 2034 | static void *arcmsr_get_firmware_spec(struct AdapterControlBlock *acb, int mode) |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2035 | { |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2036 | void *rtnval = 0; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2037 | switch (acb->adapter_type) { |
| 2038 | case ACB_ADAPTER_TYPE_A: { |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2039 | rtnval = arcmsr_get_hba_config(acb, mode); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2040 | } |
| 2041 | break; |
| 2042 | |
| 2043 | case ACB_ADAPTER_TYPE_B: { |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2044 | rtnval = arcmsr_get_hbb_config(acb, mode); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2045 | } |
| 2046 | break; |
| 2047 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2048 | return rtnval; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | static void arcmsr_polling_hba_ccbdone(struct AdapterControlBlock *acb, |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2052 | struct CommandControlBlock *poll_ccb) |
| 2053 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 2054 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2055 | struct CommandControlBlock *ccb; |
| 2056 | uint32_t flag_ccb, outbound_intstatus, poll_ccb_done = 0, poll_count = 0; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2057 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2058 | polling_hba_ccb_retry: |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2059 | poll_count++; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2060 | outbound_intstatus = readl(®->outbound_intstatus) & acb->outbound_int_enable; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2061 | writel(outbound_intstatus, ®->outbound_intstatus);/*clear interrupt*/ |
| 2062 | while (1) { |
| 2063 | if ((flag_ccb = readl(®->outbound_queueport)) == 0xFFFFFFFF) { |
| 2064 | if (poll_ccb_done) |
| 2065 | break; |
| 2066 | else { |
| 2067 | msleep(25); |
| 2068 | if (poll_count > 100) |
| 2069 | break; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2070 | goto polling_hba_ccb_retry; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2071 | } |
| 2072 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2073 | ccb = (struct CommandControlBlock *)(acb->vir2phy_offset + (flag_ccb << 5)); |
| 2074 | poll_ccb_done = (ccb == poll_ccb) ? 1:0; |
| 2075 | if ((ccb->acb != acb) || (ccb->startdone != ARCMSR_CCB_START)) { |
| 2076 | if ((ccb->startdone == ARCMSR_CCB_ABORTED) || (ccb == poll_ccb)) { |
| 2077 | printk(KERN_NOTICE "arcmsr%d: scsi id = %d lun = %d ccb = '0x%p'" |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2078 | " poll command abort successfully \n" |
| 2079 | , acb->host->host_no |
| 2080 | , ccb->pcmd->device->id |
| 2081 | , ccb->pcmd->device->lun |
| 2082 | , ccb); |
| 2083 | ccb->pcmd->result = DID_ABORT << 16; |
| 2084 | arcmsr_ccb_complete(ccb, 1); |
| 2085 | poll_ccb_done = 1; |
| 2086 | continue; |
| 2087 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2088 | printk(KERN_NOTICE "arcmsr%d: polling get an illegal ccb" |
| 2089 | " command done ccb = '0x%p'" |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 2090 | "ccboutstandingcount = %d \n" |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2091 | , acb->host->host_no |
| 2092 | , ccb |
| 2093 | , atomic_read(&acb->ccboutstandingcount)); |
| 2094 | continue; |
| 2095 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2096 | arcmsr_report_ccb_state(acb, ccb, flag_ccb); |
| 2097 | } |
| 2098 | } |
| 2099 | |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 2100 | static void arcmsr_polling_hbb_ccbdone(struct AdapterControlBlock *acb, |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2101 | struct CommandControlBlock *poll_ccb) |
| 2102 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 2103 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2104 | struct CommandControlBlock *ccb; |
| 2105 | uint32_t flag_ccb, poll_ccb_done = 0, poll_count = 0; |
| 2106 | int index; |
| 2107 | |
| 2108 | polling_hbb_ccb_retry: |
| 2109 | poll_count++; |
| 2110 | /* clear doorbell interrupt */ |
| 2111 | writel(ARCMSR_DOORBELL_INT_CLEAR_PATTERN, reg->iop2drv_doorbell_reg); |
| 2112 | while (1) { |
| 2113 | index = reg->doneq_index; |
| 2114 | if ((flag_ccb = readl(®->done_qbuffer[index])) == 0) { |
| 2115 | if (poll_ccb_done) |
| 2116 | break; |
| 2117 | else { |
| 2118 | msleep(25); |
| 2119 | if (poll_count > 100) |
| 2120 | break; |
| 2121 | goto polling_hbb_ccb_retry; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2122 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2123 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2124 | writel(0, ®->done_qbuffer[index]); |
| 2125 | index++; |
| 2126 | /*if last index number set it to 0 */ |
| 2127 | index %= ARCMSR_MAX_HBB_POSTQUEUE; |
| 2128 | reg->doneq_index = index; |
| 2129 | /* check ifcommand done with no error*/ |
| 2130 | ccb = (struct CommandControlBlock *)\ |
| 2131 | (acb->vir2phy_offset + (flag_ccb << 5));/*frame must be 32 bytes aligned*/ |
| 2132 | poll_ccb_done = (ccb == poll_ccb) ? 1:0; |
| 2133 | if ((ccb->acb != acb) || (ccb->startdone != ARCMSR_CCB_START)) { |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 2134 | if ((ccb->startdone == ARCMSR_CCB_ABORTED) || (ccb == poll_ccb)) { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2135 | printk(KERN_NOTICE "arcmsr%d: \ |
| 2136 | scsi id = %d lun = %d ccb = '0x%p' poll command abort successfully \n" |
| 2137 | ,acb->host->host_no |
| 2138 | ,ccb->pcmd->device->id |
| 2139 | ,ccb->pcmd->device->lun |
| 2140 | ,ccb); |
| 2141 | ccb->pcmd->result = DID_ABORT << 16; |
| 2142 | arcmsr_ccb_complete(ccb, 1); |
| 2143 | continue; |
| 2144 | } |
| 2145 | printk(KERN_NOTICE "arcmsr%d: polling get an illegal ccb" |
| 2146 | " command done ccb = '0x%p'" |
| 2147 | "ccboutstandingcount = %d \n" |
| 2148 | , acb->host->host_no |
| 2149 | , ccb |
| 2150 | , atomic_read(&acb->ccboutstandingcount)); |
| 2151 | continue; |
| 2152 | } |
| 2153 | arcmsr_report_ccb_state(acb, ccb, flag_ccb); |
| 2154 | } /*drain reply FIFO*/ |
| 2155 | } |
| 2156 | |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 2157 | static void arcmsr_polling_ccbdone(struct AdapterControlBlock *acb, |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2158 | struct CommandControlBlock *poll_ccb) |
| 2159 | { |
| 2160 | switch (acb->adapter_type) { |
| 2161 | |
| 2162 | case ACB_ADAPTER_TYPE_A: { |
| 2163 | arcmsr_polling_hba_ccbdone(acb,poll_ccb); |
| 2164 | } |
| 2165 | break; |
| 2166 | |
| 2167 | case ACB_ADAPTER_TYPE_B: { |
| 2168 | arcmsr_polling_hbb_ccbdone(acb,poll_ccb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2169 | } |
| 2170 | } |
| 2171 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2172 | |
| 2173 | static int arcmsr_iop_confirm(struct AdapterControlBlock *acb) |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 2174 | { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2175 | uint32_t cdb_phyaddr, ccb_phyaddr_hi32; |
| 2176 | dma_addr_t dma_coherent_handle; |
| 2177 | /* |
| 2178 | ******************************************************************** |
| 2179 | ** here we need to tell iop 331 our freeccb.HighPart |
| 2180 | ** if freeccb.HighPart is not zero |
| 2181 | ******************************************************************** |
| 2182 | */ |
| 2183 | dma_coherent_handle = acb->dma_coherent_handle; |
| 2184 | cdb_phyaddr = (uint32_t)(dma_coherent_handle); |
| 2185 | ccb_phyaddr_hi32 = (uint32_t)((cdb_phyaddr >> 16) >> 16); |
| 2186 | /* |
| 2187 | *********************************************************************** |
| 2188 | ** if adapter type B, set window of "post command Q" |
| 2189 | *********************************************************************** |
| 2190 | */ |
| 2191 | switch (acb->adapter_type) { |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 2192 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2193 | case ACB_ADAPTER_TYPE_A: { |
| 2194 | if (ccb_phyaddr_hi32 != 0) { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 2195 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2196 | uint32_t intmask_org; |
| 2197 | intmask_org = arcmsr_disable_outbound_ints(acb); |
| 2198 | writel(ARCMSR_SIGNATURE_SET_CONFIG, \ |
| 2199 | ®->message_rwbuffer[0]); |
| 2200 | writel(ccb_phyaddr_hi32, ®->message_rwbuffer[1]); |
| 2201 | writel(ARCMSR_INBOUND_MESG0_SET_CONFIG, \ |
| 2202 | ®->inbound_msgaddr0); |
| 2203 | if (arcmsr_hba_wait_msgint_ready(acb)) { |
| 2204 | printk(KERN_NOTICE "arcmsr%d: ""set ccb high \ |
| 2205 | part physical address timeout\n", |
| 2206 | acb->host->host_no); |
| 2207 | return 1; |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 2208 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2209 | arcmsr_enable_outbound_ints(acb, intmask_org); |
| 2210 | } |
| 2211 | } |
| 2212 | break; |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 2213 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2214 | case ACB_ADAPTER_TYPE_B: { |
| 2215 | unsigned long post_queue_phyaddr; |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 2216 | uint32_t __iomem *rwbuffer; |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 2217 | |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 2218 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2219 | uint32_t intmask_org; |
| 2220 | intmask_org = arcmsr_disable_outbound_ints(acb); |
| 2221 | reg->postq_index = 0; |
| 2222 | reg->doneq_index = 0; |
| 2223 | writel(ARCMSR_MESSAGE_SET_POST_WINDOW, reg->drv2iop_doorbell_reg); |
| 2224 | if (arcmsr_hbb_wait_msgint_ready(acb)) { |
| 2225 | printk(KERN_NOTICE "arcmsr%d:can not set diver mode\n", \ |
| 2226 | acb->host->host_no); |
| 2227 | return 1; |
| 2228 | } |
| 2229 | post_queue_phyaddr = cdb_phyaddr + ARCMSR_MAX_FREECCB_NUM * \ |
| 2230 | sizeof(struct CommandControlBlock) + offsetof(struct MessageUnit_B, post_qbuffer) ; |
| 2231 | rwbuffer = reg->msgcode_rwbuffer_reg; |
| 2232 | /* driver "set config" signature */ |
| 2233 | writel(ARCMSR_SIGNATURE_SET_CONFIG, rwbuffer++); |
| 2234 | /* normal should be zero */ |
| 2235 | writel(ccb_phyaddr_hi32, rwbuffer++); |
| 2236 | /* postQ size (256 + 8)*4 */ |
| 2237 | writel(post_queue_phyaddr, rwbuffer++); |
| 2238 | /* doneQ size (256 + 8)*4 */ |
| 2239 | writel(post_queue_phyaddr + 1056, rwbuffer++); |
| 2240 | /* ccb maxQ size must be --> [(256 + 8)*4]*/ |
| 2241 | writel(1056, rwbuffer); |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 2242 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2243 | writel(ARCMSR_MESSAGE_SET_CONFIG, reg->drv2iop_doorbell_reg); |
| 2244 | if (arcmsr_hbb_wait_msgint_ready(acb)) { |
| 2245 | printk(KERN_NOTICE "arcmsr%d: 'set command Q window' \ |
| 2246 | timeout \n",acb->host->host_no); |
| 2247 | return 1; |
| 2248 | } |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 2249 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2250 | writel(ARCMSR_MESSAGE_START_DRIVER_MODE, reg->drv2iop_doorbell_reg); |
| 2251 | if (arcmsr_hbb_wait_msgint_ready(acb)) { |
| 2252 | printk(KERN_NOTICE "arcmsr%d: 'can not set diver mode \n"\ |
| 2253 | ,acb->host->host_no); |
| 2254 | return 1; |
| 2255 | } |
| 2256 | arcmsr_enable_outbound_ints(acb, intmask_org); |
| 2257 | } |
| 2258 | break; |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 2259 | } |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2260 | return 0; |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 2261 | } |
| 2262 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2263 | static void arcmsr_wait_firmware_ready(struct AdapterControlBlock *acb) |
| 2264 | { |
| 2265 | uint32_t firmware_state = 0; |
| 2266 | |
| 2267 | switch (acb->adapter_type) { |
| 2268 | |
| 2269 | case ACB_ADAPTER_TYPE_A: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 2270 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2271 | do { |
| 2272 | firmware_state = readl(®->outbound_msgaddr1); |
| 2273 | } while ((firmware_state & ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK) == 0); |
| 2274 | } |
| 2275 | break; |
| 2276 | |
| 2277 | case ACB_ADAPTER_TYPE_B: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 2278 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2279 | do { |
| 2280 | firmware_state = readl(reg->iop2drv_doorbell_reg); |
| 2281 | } while ((firmware_state & ARCMSR_MESSAGE_FIRMWARE_OK) == 0); |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 2282 | writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT, reg->drv2iop_doorbell_reg); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2283 | } |
| 2284 | break; |
| 2285 | } |
| 2286 | } |
| 2287 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2288 | static void arcmsr_request_hba_device_map(struct AdapterControlBlock *acb) |
| 2289 | { |
| 2290 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
| 2291 | |
| 2292 | if (unlikely(atomic_read(&acb->rq_map_token) == 0)) { |
| 2293 | acb->fw_state = false; |
| 2294 | } else { |
| 2295 | /*to prevent rq_map_token from changing by other interrupt, then |
| 2296 | avoid the dead-lock*/ |
| 2297 | acb->fw_state = true; |
| 2298 | atomic_dec(&acb->rq_map_token); |
| 2299 | if (!(acb->fw_state) || |
| 2300 | (acb->ante_token_value == atomic_read(&acb->rq_map_token))) { |
| 2301 | atomic_set(&acb->rq_map_token, 16); |
| 2302 | } |
| 2303 | acb->ante_token_value = atomic_read(&acb->rq_map_token); |
| 2304 | writel(ARCMSR_INBOUND_MESG0_GET_CONFIG, ®->inbound_msgaddr0); |
| 2305 | } |
| 2306 | mod_timer(&acb->eternal_timer, jiffies + msecs_to_jiffies(6000)); |
| 2307 | return; |
| 2308 | } |
| 2309 | |
| 2310 | static void arcmsr_request_hbb_device_map(struct AdapterControlBlock *acb) |
| 2311 | { |
| 2312 | struct MessageUnit_B __iomem *reg = acb->pmuB; |
| 2313 | |
| 2314 | if (unlikely(atomic_read(&acb->rq_map_token) == 0)) { |
| 2315 | acb->fw_state = false; |
| 2316 | } else { |
| 2317 | /*to prevent rq_map_token from changing by other interrupt, then |
| 2318 | avoid the dead-lock*/ |
| 2319 | acb->fw_state = true; |
| 2320 | atomic_dec(&acb->rq_map_token); |
| 2321 | if (!(acb->fw_state) || |
| 2322 | (acb->ante_token_value == atomic_read(&acb->rq_map_token))) { |
| 2323 | atomic_set(&acb->rq_map_token, 16); |
| 2324 | } |
| 2325 | acb->ante_token_value = atomic_read(&acb->rq_map_token); |
| 2326 | writel(ARCMSR_MESSAGE_GET_CONFIG, reg->drv2iop_doorbell_reg); |
| 2327 | } |
| 2328 | mod_timer(&acb->eternal_timer, jiffies + msecs_to_jiffies(6000)); |
| 2329 | return; |
| 2330 | } |
| 2331 | |
| 2332 | static void arcmsr_request_device_map(unsigned long pacb) |
| 2333 | { |
| 2334 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *)pacb; |
| 2335 | |
| 2336 | switch (acb->adapter_type) { |
| 2337 | case ACB_ADAPTER_TYPE_A: { |
| 2338 | arcmsr_request_hba_device_map(acb); |
| 2339 | } |
| 2340 | break; |
| 2341 | case ACB_ADAPTER_TYPE_B: { |
| 2342 | arcmsr_request_hbb_device_map(acb); |
| 2343 | } |
| 2344 | break; |
| 2345 | } |
| 2346 | } |
| 2347 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2348 | static void arcmsr_start_hba_bgrb(struct AdapterControlBlock *acb) |
| 2349 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 2350 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2351 | acb->acb_flags |= ACB_F_MSG_START_BGRB; |
| 2352 | writel(ARCMSR_INBOUND_MESG0_START_BGRB, ®->inbound_msgaddr0); |
| 2353 | if (arcmsr_hba_wait_msgint_ready(acb)) { |
| 2354 | printk(KERN_NOTICE "arcmsr%d: wait 'start adapter background \ |
| 2355 | rebulid' timeout \n", acb->host->host_no); |
| 2356 | } |
| 2357 | } |
| 2358 | |
| 2359 | static void arcmsr_start_hbb_bgrb(struct AdapterControlBlock *acb) |
| 2360 | { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 2361 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2362 | acb->acb_flags |= ACB_F_MSG_START_BGRB; |
| 2363 | writel(ARCMSR_MESSAGE_START_BGRB, reg->drv2iop_doorbell_reg); |
| 2364 | if (arcmsr_hbb_wait_msgint_ready(acb)) { |
| 2365 | printk(KERN_NOTICE "arcmsr%d: wait 'start adapter background \ |
| 2366 | rebulid' timeout \n",acb->host->host_no); |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | static void arcmsr_start_adapter_bgrb(struct AdapterControlBlock *acb) |
| 2371 | { |
| 2372 | switch (acb->adapter_type) { |
| 2373 | case ACB_ADAPTER_TYPE_A: |
| 2374 | arcmsr_start_hba_bgrb(acb); |
| 2375 | break; |
| 2376 | case ACB_ADAPTER_TYPE_B: |
| 2377 | arcmsr_start_hbb_bgrb(acb); |
| 2378 | break; |
| 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | static void arcmsr_clear_doorbell_queue_buffer(struct AdapterControlBlock *acb) |
| 2383 | { |
| 2384 | switch (acb->adapter_type) { |
| 2385 | case ACB_ADAPTER_TYPE_A: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 2386 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2387 | uint32_t outbound_doorbell; |
| 2388 | /* empty doorbell Qbuffer if door bell ringed */ |
| 2389 | outbound_doorbell = readl(®->outbound_doorbell); |
| 2390 | /*clear doorbell interrupt */ |
| 2391 | writel(outbound_doorbell, ®->outbound_doorbell); |
| 2392 | writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK, ®->inbound_doorbell); |
| 2393 | } |
| 2394 | break; |
| 2395 | |
| 2396 | case ACB_ADAPTER_TYPE_B: { |
Al Viro | 80da1ad | 2007-10-29 05:08:28 +0000 | [diff] [blame] | 2397 | struct MessageUnit_B *reg = acb->pmuB; |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2398 | /*clear interrupt and message state*/ |
| 2399 | writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN, reg->iop2drv_doorbell_reg); |
| 2400 | writel(ARCMSR_DRV2IOP_DATA_READ_OK, reg->drv2iop_doorbell_reg); |
| 2401 | /* let IOP know data has been read */ |
| 2402 | } |
| 2403 | break; |
| 2404 | } |
| 2405 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2406 | |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 2407 | static void arcmsr_enable_eoi_mode(struct AdapterControlBlock *acb) |
| 2408 | { |
| 2409 | switch (acb->adapter_type) { |
| 2410 | case ACB_ADAPTER_TYPE_A: |
| 2411 | return; |
| 2412 | case ACB_ADAPTER_TYPE_B: |
| 2413 | { |
| 2414 | struct MessageUnit_B *reg = acb->pmuB; |
| 2415 | writel(ARCMSR_MESSAGE_ACTIVE_EOI_MODE, reg->drv2iop_doorbell_reg); |
| 2416 | if(arcmsr_hbb_wait_msgint_ready(acb)) { |
| 2417 | printk(KERN_NOTICE "ARCMSR IOP enables EOI_MODE TIMEOUT"); |
| 2418 | return; |
| 2419 | } |
| 2420 | } |
| 2421 | break; |
| 2422 | } |
| 2423 | return; |
| 2424 | } |
| 2425 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2426 | static void arcmsr_hardware_reset(struct AdapterControlBlock *acb) |
| 2427 | { |
| 2428 | uint8_t value[64]; |
| 2429 | int i; |
| 2430 | |
| 2431 | /* backup pci config data */ |
| 2432 | for (i = 0; i < 64; i++) { |
| 2433 | pci_read_config_byte(acb->pdev, i, &value[i]); |
| 2434 | } |
| 2435 | /* hardware reset signal */ |
| 2436 | pci_write_config_byte(acb->pdev, 0x84, 0x20); |
| 2437 | msleep(1000); |
| 2438 | /* write back pci config data */ |
| 2439 | for (i = 0; i < 64; i++) { |
| 2440 | pci_write_config_byte(acb->pdev, i, value[i]); |
| 2441 | } |
| 2442 | msleep(1000); |
| 2443 | return; |
| 2444 | } |
| 2445 | /* |
| 2446 | **************************************************************************** |
| 2447 | **************************************************************************** |
| 2448 | */ |
| 2449 | #ifdef CONFIG_SCSI_ARCMSR_RESET |
| 2450 | int arcmsr_sleep_for_bus_reset(struct scsi_cmnd *cmd) |
| 2451 | { |
| 2452 | struct Scsi_Host *shost = NULL; |
| 2453 | spinlock_t *host_lock = NULL; |
| 2454 | int i, isleep; |
| 2455 | |
| 2456 | shost = cmd->device->host; |
| 2457 | host_lock = shost->host_lock; |
| 2458 | |
| 2459 | printk(KERN_NOTICE "Host %d bus reset over, sleep %d seconds (busy %d, can queue %d) ...........\n", |
| 2460 | shost->host_no, sleeptime, shost->host_busy, shost->can_queue); |
| 2461 | isleep = sleeptime / 10; |
| 2462 | spin_unlock_irq(host_lock); |
| 2463 | if (isleep > 0) { |
| 2464 | for (i = 0; i < isleep; i++) { |
| 2465 | msleep(10000); |
| 2466 | printk(KERN_NOTICE "^%d^\n", i); |
| 2467 | } |
| 2468 | } |
| 2469 | |
| 2470 | isleep = sleeptime % 10; |
| 2471 | if (isleep > 0) { |
| 2472 | msleep(isleep * 1000); |
| 2473 | printk(KERN_NOTICE "^v^\n"); |
| 2474 | } |
| 2475 | spin_lock_irq(host_lock); |
| 2476 | printk(KERN_NOTICE "***** wake up *****\n"); |
| 2477 | return 0; |
| 2478 | } |
| 2479 | #endif |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2480 | static void arcmsr_iop_init(struct AdapterControlBlock *acb) |
| 2481 | { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2482 | uint32_t intmask_org; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2483 | |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2484 | /* disable all outbound interrupt */ |
| 2485 | intmask_org = arcmsr_disable_outbound_ints(acb); |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 2486 | arcmsr_wait_firmware_ready(acb); |
| 2487 | arcmsr_iop_confirm(acb); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2488 | arcmsr_get_firmware_spec(acb, 1); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2489 | /*start background rebuild*/ |
| 2490 | arcmsr_start_adapter_bgrb(acb); |
| 2491 | /* empty doorbell Qbuffer if door bell ringed */ |
| 2492 | arcmsr_clear_doorbell_queue_buffer(acb); |
Nick Cheng | 76d7830 | 2008-02-04 23:53:24 -0800 | [diff] [blame] | 2493 | arcmsr_enable_eoi_mode(acb); |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2494 | /* enable outbound Post Queue,outbound doorbell Interrupt */ |
| 2495 | arcmsr_enable_outbound_ints(acb, intmask_org); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2496 | acb->acb_flags |= ACB_F_IOP_INITED; |
| 2497 | } |
| 2498 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2499 | static uint8_t arcmsr_iop_reset(struct AdapterControlBlock *acb) |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2500 | { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2501 | struct CommandControlBlock *ccb; |
| 2502 | uint32_t intmask_org; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2503 | uint8_t rtnval = 0x00; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2504 | int i = 0; |
| 2505 | |
| 2506 | if (atomic_read(&acb->ccboutstandingcount) != 0) { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2507 | /* disable all outbound interrupt */ |
| 2508 | intmask_org = arcmsr_disable_outbound_ints(acb); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2509 | /* talk to iop 331 outstanding command aborted */ |
| 2510 | rtnval = arcmsr_abort_allcmd(acb); |
| 2511 | /* wait for 3 sec for all command aborted*/ |
| 2512 | ssleep(3); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2513 | /* clear all outbound posted Q */ |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2514 | arcmsr_done4abort_postqueue(acb); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2515 | for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) { |
| 2516 | ccb = acb->pccb_pool[i]; |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 2517 | if (ccb->startdone == ARCMSR_CCB_START) { |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2518 | arcmsr_ccb_complete(ccb, 1); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2519 | } |
| 2520 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2521 | atomic_set(&acb->ccboutstandingcount, 0); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2522 | /* enable all outbound interrupt */ |
| 2523 | arcmsr_enable_outbound_ints(acb, intmask_org); |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2524 | return rtnval; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2525 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2526 | return rtnval; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | static int arcmsr_bus_reset(struct scsi_cmnd *cmd) |
| 2530 | { |
| 2531 | struct AdapterControlBlock *acb = |
| 2532 | (struct AdapterControlBlock *)cmd->device->host->hostdata; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2533 | int retry = 0; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2534 | |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2535 | if (acb->acb_flags & ACB_F_BUS_RESET) |
| 2536 | return SUCCESS; |
| 2537 | |
| 2538 | printk(KERN_NOTICE "arcmsr%d: bus reset ..... \n", acb->adapter_index); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2539 | acb->acb_flags |= ACB_F_BUS_RESET; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2540 | acb->num_resets++; |
| 2541 | while (atomic_read(&acb->ccboutstandingcount) != 0 && retry < 4) { |
| 2542 | arcmsr_interrupt(acb); |
| 2543 | retry++; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2544 | } |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2545 | |
| 2546 | if (arcmsr_iop_reset(acb)) { |
| 2547 | switch (acb->adapter_type) { |
| 2548 | case ACB_ADAPTER_TYPE_A: { |
| 2549 | printk(KERN_NOTICE "arcmsr%d: do hardware bus reset, num_resets = %d num_aborts = %d \n", |
| 2550 | acb->adapter_index, acb->num_resets, acb->num_aborts); |
| 2551 | arcmsr_hardware_reset(acb); |
| 2552 | acb->acb_flags |= ACB_F_FIRMWARE_TRAP; |
| 2553 | acb->acb_flags &= ~ACB_F_IOP_INITED; |
| 2554 | #ifdef CONFIG_SCSI_ARCMSR_RESET |
| 2555 | struct MessageUnit_A __iomem *reg = acb->pmuA; |
| 2556 | uint32_t intmask_org, outbound_doorbell; |
| 2557 | int retry_count = 0; |
| 2558 | sleep_again: |
| 2559 | arcmsr_sleep_for_bus_reset(cmd); |
| 2560 | if ((readl(®->outbound_msgaddr1) & |
| 2561 | ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK) == 0) { |
| 2562 | printk(KERN_NOTICE "arcmsr%d: hardware bus reset and return busy, retry=%d \n", |
| 2563 | acb->host->host_no, retry_count); |
| 2564 | if (retry_count > retrycount) { |
| 2565 | printk(KERN_NOTICE "arcmsr%d: hardware bus reset and return busy, retry aborted \n", |
| 2566 | acb->host->host_no); |
| 2567 | return SUCCESS; |
| 2568 | } |
| 2569 | retry_count++; |
| 2570 | goto sleep_again; |
| 2571 | } |
| 2572 | acb->acb_flags &= ~ACB_F_FIRMWARE_TRAP; |
| 2573 | acb->acb_flags |= ACB_F_IOP_INITED; |
| 2574 | acb->acb_flags &= ~ACB_F_BUS_RESET; |
| 2575 | printk(KERN_NOTICE "arcmsr%d: hardware bus reset and reset ok \n", |
| 2576 | acb->host->host_no); |
| 2577 | /* disable all outbound interrupt */ |
| 2578 | intmask_org = arcmsr_disable_outbound_ints(acb); |
| 2579 | arcmsr_get_firmware_spec(acb, 1); |
| 2580 | /*start background rebuild*/ |
| 2581 | arcmsr_start_adapter_bgrb(acb); |
| 2582 | /* clear Qbuffer if door bell ringed */ |
| 2583 | outbound_doorbell = readl(®->outbound_doorbell); |
| 2584 | writel(outbound_doorbell, ®->outbound_doorbell); /*clear interrupt */ |
| 2585 | writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK, ®->inbound_doorbell); |
| 2586 | /* enable outbound Post Queue,outbound doorbell Interrupt */ |
| 2587 | arcmsr_enable_outbound_ints(acb, intmask_org); |
| 2588 | atomic_set(&acb->rq_map_token, 16); |
| 2589 | init_timer(&acb->eternal_timer); |
| 2590 | acb->eternal_timer.expires = jiffies + msecs_to_jiffies(20*HZ); |
| 2591 | acb->eternal_timer.data = (unsigned long) acb; |
| 2592 | acb->eternal_timer.function = &arcmsr_request_device_map; |
| 2593 | add_timer(&acb->eternal_timer); |
| 2594 | #endif |
| 2595 | } |
| 2596 | break; |
| 2597 | case ACB_ADAPTER_TYPE_B: { |
| 2598 | } |
| 2599 | } |
| 2600 | } else { |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2601 | acb->acb_flags &= ~ACB_F_BUS_RESET; |
Nick Cheng | 36b83de | 2010-05-17 11:22:42 +0800 | [diff] [blame] | 2602 | } |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2603 | return SUCCESS; |
| 2604 | } |
| 2605 | |
| 2606 | static void arcmsr_abort_one_cmd(struct AdapterControlBlock *acb, |
| 2607 | struct CommandControlBlock *ccb) |
| 2608 | { |
| 2609 | u32 intmask; |
| 2610 | |
| 2611 | ccb->startdone = ARCMSR_CCB_ABORTED; |
| 2612 | |
| 2613 | /* |
| 2614 | ** Wait for 3 sec for all command done. |
| 2615 | */ |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2616 | ssleep(3); |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2617 | |
| 2618 | intmask = arcmsr_disable_outbound_ints(acb); |
| 2619 | arcmsr_polling_ccbdone(acb, ccb); |
| 2620 | arcmsr_enable_outbound_ints(acb, intmask); |
| 2621 | } |
| 2622 | |
| 2623 | static int arcmsr_abort(struct scsi_cmnd *cmd) |
| 2624 | { |
| 2625 | struct AdapterControlBlock *acb = |
| 2626 | (struct AdapterControlBlock *)cmd->device->host->hostdata; |
| 2627 | int i = 0; |
| 2628 | |
| 2629 | printk(KERN_NOTICE |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 2630 | "arcmsr%d: abort device command of scsi id = %d lun = %d \n", |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2631 | acb->host->host_no, cmd->device->id, cmd->device->lun); |
| 2632 | acb->num_aborts++; |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2633 | /* |
| 2634 | ************************************************ |
| 2635 | ** the all interrupt service routine is locked |
| 2636 | ** we need to handle it as soon as possible and exit |
| 2637 | ************************************************ |
| 2638 | */ |
| 2639 | if (!atomic_read(&acb->ccboutstandingcount)) |
| 2640 | return SUCCESS; |
| 2641 | |
| 2642 | for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) { |
| 2643 | struct CommandControlBlock *ccb = acb->pccb_pool[i]; |
| 2644 | if (ccb->startdone == ARCMSR_CCB_START && ccb->pcmd == cmd) { |
| 2645 | arcmsr_abort_one_cmd(acb, ccb); |
| 2646 | break; |
| 2647 | } |
| 2648 | } |
| 2649 | |
| 2650 | return SUCCESS; |
| 2651 | } |
| 2652 | |
| 2653 | static const char *arcmsr_info(struct Scsi_Host *host) |
| 2654 | { |
| 2655 | struct AdapterControlBlock *acb = |
| 2656 | (struct AdapterControlBlock *) host->hostdata; |
| 2657 | static char buf[256]; |
| 2658 | char *type; |
| 2659 | int raid6 = 1; |
| 2660 | |
| 2661 | switch (acb->pdev->device) { |
| 2662 | case PCI_DEVICE_ID_ARECA_1110: |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2663 | case PCI_DEVICE_ID_ARECA_1200: |
| 2664 | case PCI_DEVICE_ID_ARECA_1202: |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2665 | case PCI_DEVICE_ID_ARECA_1210: |
| 2666 | raid6 = 0; |
| 2667 | /*FALLTHRU*/ |
| 2668 | case PCI_DEVICE_ID_ARECA_1120: |
| 2669 | case PCI_DEVICE_ID_ARECA_1130: |
| 2670 | case PCI_DEVICE_ID_ARECA_1160: |
| 2671 | case PCI_DEVICE_ID_ARECA_1170: |
Nick Cheng | 1a4f550 | 2007-09-13 17:26:40 +0800 | [diff] [blame] | 2672 | case PCI_DEVICE_ID_ARECA_1201: |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2673 | case PCI_DEVICE_ID_ARECA_1220: |
| 2674 | case PCI_DEVICE_ID_ARECA_1230: |
| 2675 | case PCI_DEVICE_ID_ARECA_1260: |
| 2676 | case PCI_DEVICE_ID_ARECA_1270: |
| 2677 | case PCI_DEVICE_ID_ARECA_1280: |
| 2678 | type = "SATA"; |
| 2679 | break; |
| 2680 | case PCI_DEVICE_ID_ARECA_1380: |
| 2681 | case PCI_DEVICE_ID_ARECA_1381: |
| 2682 | case PCI_DEVICE_ID_ARECA_1680: |
| 2683 | case PCI_DEVICE_ID_ARECA_1681: |
| 2684 | type = "SAS"; |
| 2685 | break; |
| 2686 | default: |
| 2687 | type = "X-TYPE"; |
| 2688 | break; |
| 2689 | } |
nickcheng(鄭守謙 | a1f6e02 | 2007-06-15 11:43:32 +0800 | [diff] [blame] | 2690 | sprintf(buf, "Areca %s Host Adapter RAID Controller%s\n %s", |
Erich Chen | 1c57e86 | 2006-07-12 08:59:32 -0700 | [diff] [blame] | 2691 | type, raid6 ? "( RAID6 capable)" : "", |
| 2692 | ARCMSR_DRIVER_VERSION); |
| 2693 | return buf; |
| 2694 | } |