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