aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/arcmsr/arcmsr_hba.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/arcmsr/arcmsr_hba.c')
-rw-r--r--drivers/scsi/arcmsr/arcmsr_hba.c2258
1 files changed, 1367 insertions, 891 deletions
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 0ddfc21e9f7d..cfcf40159eab 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -9,7 +9,7 @@
9** Copyright (C) 2002 - 2005, Areca Technology Corporation All rights reserved 9** Copyright (C) 2002 - 2005, Areca Technology Corporation All rights reserved
10** 10**
11** Web site: www.areca.com.tw 11** Web site: www.areca.com.tw
12** E-mail: erich@areca.com.tw 12** E-mail: support@areca.com.tw
13** 13**
14** This program is free software; you can redistribute it and/or modify 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 15** it under the terms of the GNU General Public License version 2 as
@@ -71,33 +71,34 @@
71#include <scsi/scsicam.h> 71#include <scsi/scsicam.h>
72#include "arcmsr.h" 72#include "arcmsr.h"
73 73
74MODULE_AUTHOR("Erich Chen <erich@areca.com.tw>"); 74MODULE_AUTHOR("Erich Chen <support@areca.com.tw>");
75MODULE_DESCRIPTION("ARECA (ARC11xx/12xx/13xx/16xx) SATA/SAS RAID HOST Adapter"); 75MODULE_DESCRIPTION("ARECA (ARC11xx/12xx/13xx/16xx) SATA/SAS RAID HOST Adapter");
76MODULE_LICENSE("Dual BSD/GPL"); 76MODULE_LICENSE("Dual BSD/GPL");
77MODULE_VERSION(ARCMSR_DRIVER_VERSION); 77MODULE_VERSION(ARCMSR_DRIVER_VERSION);
78 78
79static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, struct scsi_cmnd *cmd); 79static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb,
80 struct scsi_cmnd *cmd);
81static int arcmsr_iop_confirm(struct AdapterControlBlock *acb);
80static int arcmsr_abort(struct scsi_cmnd *); 82static int arcmsr_abort(struct scsi_cmnd *);
81static int arcmsr_bus_reset(struct scsi_cmnd *); 83static int arcmsr_bus_reset(struct scsi_cmnd *);
82static int arcmsr_bios_param(struct scsi_device *sdev, 84static int arcmsr_bios_param(struct scsi_device *sdev,
83 struct block_device *bdev, sector_t capacity, int *info); 85 struct block_device *bdev, sector_t capacity, int *info);
84static int arcmsr_queue_command(struct scsi_cmnd * cmd, 86static int arcmsr_queue_command(struct scsi_cmnd *cmd,
85 void (*done) (struct scsi_cmnd *)); 87 void (*done) (struct scsi_cmnd *));
86static int arcmsr_probe(struct pci_dev *pdev, 88static int arcmsr_probe(struct pci_dev *pdev,
87 const struct pci_device_id *id); 89 const struct pci_device_id *id);
88static void arcmsr_remove(struct pci_dev *pdev); 90static void arcmsr_remove(struct pci_dev *pdev);
89static void arcmsr_shutdown(struct pci_dev *pdev); 91static void arcmsr_shutdown(struct pci_dev *pdev);
90static void arcmsr_iop_init(struct AdapterControlBlock *acb); 92static void arcmsr_iop_init(struct AdapterControlBlock *acb);
91static void arcmsr_free_ccb_pool(struct AdapterControlBlock *acb); 93static void arcmsr_free_ccb_pool(struct AdapterControlBlock *acb);
94static u32 arcmsr_disable_outbound_ints(struct AdapterControlBlock *acb);
92static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock *acb); 95static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock *acb);
93static void arcmsr_flush_adapter_cache(struct AdapterControlBlock *acb); 96static void arcmsr_flush_hba_cache(struct AdapterControlBlock *acb);
94static uint8_t arcmsr_wait_msgint_ready(struct AdapterControlBlock *acb); 97static void arcmsr_flush_hbb_cache(struct AdapterControlBlock *acb);
95static const char *arcmsr_info(struct Scsi_Host *); 98static const char *arcmsr_info(struct Scsi_Host *);
96static irqreturn_t arcmsr_interrupt(struct AdapterControlBlock *acb); 99static irqreturn_t arcmsr_interrupt(struct AdapterControlBlock *acb);
97static pci_ers_result_t arcmsr_pci_error_detected(struct pci_dev *pdev, 100static int arcmsr_adjust_disk_queue_depth(struct scsi_device *sdev,
98 pci_channel_state_t state); 101 int queue_depth)
99static pci_ers_result_t arcmsr_pci_slot_reset(struct pci_dev *pdev);
100static int arcmsr_adjust_disk_queue_depth(struct scsi_device *sdev, int queue_depth)
101{ 102{
102 if (queue_depth > ARCMSR_MAX_CMD_PERLUN) 103 if (queue_depth > ARCMSR_MAX_CMD_PERLUN)
103 queue_depth = ARCMSR_MAX_CMD_PERLUN; 104 queue_depth = ARCMSR_MAX_CMD_PERLUN;
@@ -123,17 +124,25 @@ static struct scsi_host_template arcmsr_scsi_host_template = {
123 .use_clustering = ENABLE_CLUSTERING, 124 .use_clustering = ENABLE_CLUSTERING,
124 .shost_attrs = arcmsr_host_attrs, 125 .shost_attrs = arcmsr_host_attrs,
125}; 126};
127#ifdef CONFIG_SCSI_ARCMSR_AER
128static pci_ers_result_t arcmsr_pci_slot_reset(struct pci_dev *pdev);
129static pci_ers_result_t arcmsr_pci_error_detected(struct pci_dev *pdev,
130 pci_channel_state_t state);
131
126static struct pci_error_handlers arcmsr_pci_error_handlers = { 132static struct pci_error_handlers arcmsr_pci_error_handlers = {
127 .error_detected = arcmsr_pci_error_detected, 133 .error_detected = arcmsr_pci_error_detected,
128 .slot_reset = arcmsr_pci_slot_reset, 134 .slot_reset = arcmsr_pci_slot_reset,
129}; 135};
130 136#endif
131static struct pci_device_id arcmsr_device_id_table[] = { 137static struct pci_device_id arcmsr_device_id_table[] = {
132 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1110)}, 138 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1110)},
133 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1120)}, 139 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1120)},
134 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1130)}, 140 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1130)},
135 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1160)}, 141 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1160)},
136 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1170)}, 142 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1170)},
143 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1200)},
144 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1201)},
145 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1202)},
137 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1210)}, 146 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1210)},
138 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1220)}, 147 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1220)},
139 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1230)}, 148 {PCI_DEVICE(PCI_VENDOR_ID_ARECA, PCI_DEVICE_ID_ARECA_1230)},
@@ -153,20 +162,20 @@ static struct pci_driver arcmsr_pci_driver = {
153 .probe = arcmsr_probe, 162 .probe = arcmsr_probe,
154 .remove = arcmsr_remove, 163 .remove = arcmsr_remove,
155 .shutdown = arcmsr_shutdown, 164 .shutdown = arcmsr_shutdown,
165 #ifdef CONFIG_SCSI_ARCMSR_AER
156 .err_handler = &arcmsr_pci_error_handlers, 166 .err_handler = &arcmsr_pci_error_handlers,
167 #endif
157}; 168};
158 169
159static irqreturn_t arcmsr_do_interrupt(int irq, void *dev_id) 170static irqreturn_t arcmsr_do_interrupt(int irq, void *dev_id)
160{ 171{
161 irqreturn_t handle_state; 172 irqreturn_t handle_state;
162 struct AdapterControlBlock *acb; 173 struct AdapterControlBlock *acb = dev_id;
163 unsigned long flags;
164 174
165 acb = (struct AdapterControlBlock *)dev_id; 175 spin_lock(acb->host->host_lock);
166
167 spin_lock_irqsave(acb->host->host_lock, flags);
168 handle_state = arcmsr_interrupt(acb); 176 handle_state = arcmsr_interrupt(acb);
169 spin_unlock_irqrestore(acb->host->host_lock, flags); 177 spin_unlock(acb->host->host_lock);
178
170 return handle_state; 179 return handle_state;
171} 180}
172 181
@@ -198,68 +207,159 @@ static int arcmsr_bios_param(struct scsi_device *sdev,
198 return 0; 207 return 0;
199} 208}
200 209
201static int arcmsr_alloc_ccb_pool(struct AdapterControlBlock *acb) 210static void arcmsr_define_adapter_type(struct AdapterControlBlock *acb)
202{ 211{
203 struct pci_dev *pdev = acb->pdev; 212 struct pci_dev *pdev = acb->pdev;
204 struct MessageUnit __iomem *reg = acb->pmu; 213 u16 dev_id;
205 u32 ccb_phyaddr_hi32; 214 pci_read_config_word(pdev, PCI_DEVICE_ID, &dev_id);
206 void *dma_coherent; 215 switch (dev_id) {
207 dma_addr_t dma_coherent_handle, dma_addr; 216 case 0x1201 : {
208 struct CommandControlBlock *ccb_tmp; 217 acb->adapter_type = ACB_ADAPTER_TYPE_B;
209 int i, j; 218 }
219 break;
220
221 default : acb->adapter_type = ACB_ADAPTER_TYPE_A;
222 }
223}
224
225static int arcmsr_alloc_ccb_pool(struct AdapterControlBlock *acb)
226{
227
228 switch (acb->adapter_type) {
229
230 case ACB_ADAPTER_TYPE_A: {
231 struct pci_dev *pdev = acb->pdev;
232 void *dma_coherent;
233 dma_addr_t dma_coherent_handle, dma_addr;
234 struct CommandControlBlock *ccb_tmp;
235 uint32_t intmask_org;
236 int i, j;
237
238 acb->pmu = ioremap(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
239 if (!acb->pmu) {
240 printk(KERN_NOTICE "arcmsr%d: memory mapping region fail \n",
241 acb->host->host_no);
242 }
210 243
211 dma_coherent = dma_alloc_coherent(&pdev->dev, 244 dma_coherent = dma_alloc_coherent(&pdev->dev,
212 ARCMSR_MAX_FREECCB_NUM * 245 ARCMSR_MAX_FREECCB_NUM *
213 sizeof (struct CommandControlBlock) + 0x20, 246 sizeof (struct CommandControlBlock) + 0x20,
214 &dma_coherent_handle, GFP_KERNEL); 247 &dma_coherent_handle, GFP_KERNEL);
215 if (!dma_coherent) 248 if (!dma_coherent)
216 return -ENOMEM; 249 return -ENOMEM;
217 250
218 acb->dma_coherent = dma_coherent; 251 acb->dma_coherent = dma_coherent;
219 acb->dma_coherent_handle = dma_coherent_handle; 252 acb->dma_coherent_handle = dma_coherent_handle;
220 253
221 if (((unsigned long)dma_coherent & 0x1F)) { 254 if (((unsigned long)dma_coherent & 0x1F)) {
222 dma_coherent = dma_coherent + 255 dma_coherent = dma_coherent +
223 (0x20 - ((unsigned long)dma_coherent & 0x1F)); 256 (0x20 - ((unsigned long)dma_coherent & 0x1F));
224 dma_coherent_handle = dma_coherent_handle + 257 dma_coherent_handle = dma_coherent_handle +
225 (0x20 - ((unsigned long)dma_coherent_handle & 0x1F)); 258 (0x20 - ((unsigned long)dma_coherent_handle & 0x1F));
226 } 259 }
227 260
228 dma_addr = dma_coherent_handle; 261 dma_addr = dma_coherent_handle;
229 ccb_tmp = (struct CommandControlBlock *)dma_coherent; 262 ccb_tmp = (struct CommandControlBlock *)dma_coherent;
230 for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) { 263 for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) {
231 ccb_tmp->cdb_shifted_phyaddr = dma_addr >> 5; 264 ccb_tmp->cdb_shifted_phyaddr = dma_addr >> 5;
232 ccb_tmp->acb = acb; 265 ccb_tmp->acb = acb;
233 acb->pccb_pool[i] = ccb_tmp; 266 acb->pccb_pool[i] = ccb_tmp;
234 list_add_tail(&ccb_tmp->list, &acb->ccb_free_list); 267 list_add_tail(&ccb_tmp->list, &acb->ccb_free_list);
235 dma_addr = dma_addr + sizeof (struct CommandControlBlock); 268 dma_addr = dma_addr + sizeof(struct CommandControlBlock);
236 ccb_tmp++; 269 ccb_tmp++;
237 } 270 }
238 271
239 acb->vir2phy_offset = (unsigned long)ccb_tmp - 272 acb->vir2phy_offset = (unsigned long)ccb_tmp -(unsigned long)dma_addr;
240 (unsigned long)dma_addr; 273 for (i = 0; i < ARCMSR_MAX_TARGETID; i++)
241 for (i = 0; i < ARCMSR_MAX_TARGETID; i++) 274 for (j = 0; j < ARCMSR_MAX_TARGETLUN; j++)
242 for (j = 0; j < ARCMSR_MAX_TARGETLUN; j++) 275 acb->devstate[i][j] = ARECA_RAID_GONE;
243 acb->devstate[i][j] = ARECA_RAID_GOOD;
244 276
245 /* 277 /*
246 ** here we need to tell iop 331 our ccb_tmp.HighPart 278 ** here we need to tell iop 331 our ccb_tmp.HighPart
247 ** if ccb_tmp.HighPart is not zero 279 ** if ccb_tmp.HighPart is not zero
248 */ 280 */
249 ccb_phyaddr_hi32 = (uint32_t) ((dma_coherent_handle >> 16) >> 16); 281 intmask_org = arcmsr_disable_outbound_ints(acb);
250 if (ccb_phyaddr_hi32 != 0) { 282 }
251 writel(ARCMSR_SIGNATURE_SET_CONFIG, &reg->message_rwbuffer[0]); 283 break;
252 writel(ccb_phyaddr_hi32, &reg->message_rwbuffer[1]); 284
253 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG, &reg->inbound_msgaddr0); 285 case ACB_ADAPTER_TYPE_B: {
254 if (arcmsr_wait_msgint_ready(acb)) 286
255 printk(KERN_NOTICE "arcmsr%d: " 287 struct pci_dev *pdev = acb->pdev;
256 "'set ccb high part physical address' timeout\n", 288 struct MessageUnit_B *reg;
257 acb->host->host_no); 289 void *mem_base0, *mem_base1;
258 } 290 void *dma_coherent;
291 dma_addr_t dma_coherent_handle, dma_addr;
292 uint32_t intmask_org;
293 struct CommandControlBlock *ccb_tmp;
294 int i, j;
295
296 dma_coherent = dma_alloc_coherent(&pdev->dev,
297 ((ARCMSR_MAX_FREECCB_NUM *
298 sizeof(struct CommandControlBlock) + 0x20) +
299 sizeof(struct MessageUnit_B)),
300 &dma_coherent_handle, GFP_KERNEL);
301 if (!dma_coherent)
302 return -ENOMEM;
259 303
260 writel(readl(&reg->outbound_intmask) | 304 acb->dma_coherent = dma_coherent;
261 ARCMSR_MU_OUTBOUND_ALL_INTMASKENABLE, 305 acb->dma_coherent_handle = dma_coherent_handle;
262 &reg->outbound_intmask); 306
307 if (((unsigned long)dma_coherent & 0x1F)) {
308 dma_coherent = dma_coherent +
309 (0x20 - ((unsigned long)dma_coherent & 0x1F));
310 dma_coherent_handle = dma_coherent_handle +
311 (0x20 - ((unsigned long)dma_coherent_handle & 0x1F));
312 }
313
314 reg = (struct MessageUnit_B *)(dma_coherent +
315 ARCMSR_MAX_FREECCB_NUM * sizeof(struct CommandControlBlock));
316
317 dma_addr = dma_coherent_handle;
318 ccb_tmp = (struct CommandControlBlock *)dma_coherent;
319 for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) {
320 ccb_tmp->cdb_shifted_phyaddr = dma_addr >> 5;
321 ccb_tmp->acb = acb;
322 acb->pccb_pool[i] = ccb_tmp;
323 list_add_tail(&ccb_tmp->list, &acb->ccb_free_list);
324 dma_addr = dma_addr + sizeof(struct CommandControlBlock);
325 ccb_tmp++;
326 }
327
328 reg = (struct MessageUnit_B *)(dma_coherent +
329 ARCMSR_MAX_FREECCB_NUM * sizeof(struct CommandControlBlock));
330 acb->pmu = (struct MessageUnit *)reg;
331 mem_base0 = ioremap(pci_resource_start(pdev, 0),
332 pci_resource_len(pdev, 0));
333 mem_base1 = ioremap(pci_resource_start(pdev, 2),
334 pci_resource_len(pdev, 2));
335 reg->drv2iop_doorbell_reg = (uint32_t *)((char *)mem_base0 +
336 ARCMSR_DRV2IOP_DOORBELL);
337 reg->drv2iop_doorbell_mask_reg = (uint32_t *)((char *)mem_base0 +
338 ARCMSR_DRV2IOP_DOORBELL_MASK);
339 reg->iop2drv_doorbell_reg = (uint32_t *)((char *)mem_base0 +
340 ARCMSR_IOP2DRV_DOORBELL);
341 reg->iop2drv_doorbell_mask_reg = (uint32_t *)((char *)mem_base0 +
342 ARCMSR_IOP2DRV_DOORBELL_MASK);
343 reg->ioctl_wbuffer_reg = (uint32_t *)((char *)mem_base1 +
344 ARCMSR_IOCTL_WBUFFER);
345 reg->ioctl_rbuffer_reg = (uint32_t *)((char *)mem_base1 +
346 ARCMSR_IOCTL_RBUFFER);
347 reg->msgcode_rwbuffer_reg = (uint32_t *)((char *)mem_base1 +
348 ARCMSR_MSGCODE_RWBUFFER);
349
350 acb->vir2phy_offset = (unsigned long)ccb_tmp -(unsigned long)dma_addr;
351 for (i = 0; i < ARCMSR_MAX_TARGETID; i++)
352 for (j = 0; j < ARCMSR_MAX_TARGETLUN; j++)
353 acb->devstate[i][j] = ARECA_RAID_GOOD;
354
355 /*
356 ** here we need to tell iop 331 our ccb_tmp.HighPart
357 ** if ccb_tmp.HighPart is not zero
358 */
359 intmask_org = arcmsr_disable_outbound_ints(acb);
360 }
361 break;
362 }
263 return 0; 363 return 0;
264} 364}
265 365
@@ -310,16 +410,11 @@ static int arcmsr_probe(struct pci_dev *pdev,
310 host->unique_id = (bus << 8) | dev_fun; 410 host->unique_id = (bus << 8) | dev_fun;
311 host->irq = pdev->irq; 411 host->irq = pdev->irq;
312 error = pci_request_regions(pdev, "arcmsr"); 412 error = pci_request_regions(pdev, "arcmsr");
313 if (error) 413 if (error) {
314 goto out_host_put; 414 goto out_host_put;
315
316 acb->pmu = ioremap(pci_resource_start(pdev, 0),
317 pci_resource_len(pdev, 0));
318 if (!acb->pmu) {
319 printk(KERN_NOTICE "arcmsr%d: memory"
320 " mapping region fail \n", acb->host->host_no);
321 goto out_release_regions;
322 } 415 }
416 arcmsr_define_adapter_type(acb);
417
323 acb->acb_flags |= (ACB_F_MESSAGE_WQBUFFER_CLEARED | 418 acb->acb_flags |= (ACB_F_MESSAGE_WQBUFFER_CLEARED |
324 ACB_F_MESSAGE_RQBUFFER_CLEARED | 419 ACB_F_MESSAGE_RQBUFFER_CLEARED |
325 ACB_F_MESSAGE_WQBUFFER_READED); 420 ACB_F_MESSAGE_WQBUFFER_READED);
@@ -328,10 +423,10 @@ static int arcmsr_probe(struct pci_dev *pdev,
328 423
329 error = arcmsr_alloc_ccb_pool(acb); 424 error = arcmsr_alloc_ccb_pool(acb);
330 if (error) 425 if (error)
331 goto out_iounmap; 426 goto out_release_regions;
332 427
333 error = request_irq(pdev->irq, arcmsr_do_interrupt, 428 error = request_irq(pdev->irq, arcmsr_do_interrupt,
334 IRQF_DISABLED | IRQF_SHARED, "arcmsr", acb); 429 IRQF_SHARED, "arcmsr", acb);
335 if (error) 430 if (error)
336 goto out_free_ccb_pool; 431 goto out_free_ccb_pool;
337 432
@@ -349,14 +444,15 @@ static int arcmsr_probe(struct pci_dev *pdev,
349 goto out_free_sysfs; 444 goto out_free_sysfs;
350 445
351 scsi_scan_host(host); 446 scsi_scan_host(host);
447 #ifdef CONFIG_SCSI_ARCMSR_AER
352 pci_enable_pcie_error_reporting(pdev); 448 pci_enable_pcie_error_reporting(pdev);
449 #endif
353 return 0; 450 return 0;
354 out_free_sysfs: 451 out_free_sysfs:
355 out_free_irq: 452 out_free_irq:
356 free_irq(pdev->irq, acb); 453 free_irq(pdev->irq, acb);
357 out_free_ccb_pool: 454 out_free_ccb_pool:
358 arcmsr_free_ccb_pool(acb); 455 arcmsr_free_ccb_pool(acb);
359 out_iounmap:
360 iounmap(acb->pmu); 456 iounmap(acb->pmu);
361 out_release_regions: 457 out_release_regions:
362 pci_release_regions(pdev); 458 pci_release_regions(pdev);
@@ -368,17 +464,84 @@ static int arcmsr_probe(struct pci_dev *pdev,
368 return error; 464 return error;
369} 465}
370 466
371static void arcmsr_abort_allcmd(struct AdapterControlBlock *acb) 467static uint8_t arcmsr_hba_wait_msgint_ready(struct AdapterControlBlock *acb)
468{
469 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
470 uint32_t Index;
471 uint8_t Retries = 0x00;
472
473 do {
474 for (Index = 0; Index < 100; Index++) {
475 if (readl(&reg->outbound_intstatus) &
476 ARCMSR_MU_OUTBOUND_MESSAGE0_INT) {
477 writel(ARCMSR_MU_OUTBOUND_MESSAGE0_INT,
478 &reg->outbound_intstatus);
479 return 0x00;
480 }
481 msleep(10);
482 }/*max 1 seconds*/
483
484 } while (Retries++ < 20);/*max 20 sec*/
485 return 0xff;
486}
487
488static uint8_t arcmsr_hbb_wait_msgint_ready(struct AdapterControlBlock *acb)
372{ 489{
373 struct MessageUnit __iomem *reg = acb->pmu; 490 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
491 uint32_t Index;
492 uint8_t Retries = 0x00;
493
494 do {
495 for (Index = 0; Index < 100; Index++) {
496 if (readl(reg->iop2drv_doorbell_reg)
497 & ARCMSR_IOP2DRV_MESSAGE_CMD_DONE) {
498 writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN
499 , reg->iop2drv_doorbell_reg);
500 return 0x00;
501 }
502 msleep(10);
503 }/*max 1 seconds*/
504
505 } while (Retries++ < 20);/*max 20 sec*/
506 return 0xff;
507}
508
509static void arcmsr_abort_hba_allcmd(struct AdapterControlBlock *acb)
510{
511 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
374 512
375 writel(ARCMSR_INBOUND_MESG0_ABORT_CMD, &reg->inbound_msgaddr0); 513 writel(ARCMSR_INBOUND_MESG0_ABORT_CMD, &reg->inbound_msgaddr0);
376 if (arcmsr_wait_msgint_ready(acb)) 514 if (arcmsr_hba_wait_msgint_ready(acb))
515 printk(KERN_NOTICE
516 "arcmsr%d: wait 'abort all outstanding command' timeout \n"
517 , acb->host->host_no);
518}
519
520static void arcmsr_abort_hbb_allcmd(struct AdapterControlBlock *acb)
521{
522 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
523
524 writel(ARCMSR_MESSAGE_ABORT_CMD, reg->drv2iop_doorbell_reg);
525 if (arcmsr_hbb_wait_msgint_ready(acb))
377 printk(KERN_NOTICE 526 printk(KERN_NOTICE
378 "arcmsr%d: wait 'abort all outstanding command' timeout \n" 527 "arcmsr%d: wait 'abort all outstanding command' timeout \n"
379 , acb->host->host_no); 528 , acb->host->host_no);
380} 529}
381 530
531static void arcmsr_abort_allcmd(struct AdapterControlBlock *acb)
532{
533 switch (acb->adapter_type) {
534 case ACB_ADAPTER_TYPE_A: {
535 arcmsr_abort_hba_allcmd(acb);
536 }
537 break;
538
539 case ACB_ADAPTER_TYPE_B: {
540 arcmsr_abort_hbb_allcmd(acb);
541 }
542 }
543}
544
382static void arcmsr_pci_unmap_dma(struct CommandControlBlock *ccb) 545static void arcmsr_pci_unmap_dma(struct CommandControlBlock *ccb)
383{ 546{
384 struct scsi_cmnd *pcmd = ccb->pcmd; 547 struct scsi_cmnd *pcmd = ccb->pcmd;
@@ -400,28 +563,239 @@ static void arcmsr_ccb_complete(struct CommandControlBlock *ccb, int stand_flag)
400 pcmd->scsi_done(pcmd); 563 pcmd->scsi_done(pcmd);
401} 564}
402 565
566static void arcmsr_flush_hba_cache(struct AdapterControlBlock *acb)
567{
568 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
569 int retry_count = 30;
570
571 writel(ARCMSR_INBOUND_MESG0_FLUSH_CACHE, &reg->inbound_msgaddr0);
572 do {
573 if (!arcmsr_hba_wait_msgint_ready(acb))
574 break;
575 else {
576 retry_count--;
577 printk(KERN_NOTICE "arcmsr%d: wait 'flush adapter cache' \
578 timeout, retry count down = %d \n", acb->host->host_no, retry_count);
579 }
580 } while (retry_count != 0);
581}
582
583static void arcmsr_flush_hbb_cache(struct AdapterControlBlock *acb)
584{
585 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
586 int retry_count = 30;
587
588 writel(ARCMSR_MESSAGE_FLUSH_CACHE, reg->drv2iop_doorbell_reg);
589 do {
590 if (!arcmsr_hbb_wait_msgint_ready(acb))
591 break;
592 else {
593 retry_count--;
594 printk(KERN_NOTICE "arcmsr%d: wait 'flush adapter cache' \
595 timeout,retry count down = %d \n", acb->host->host_no, retry_count);
596 }
597 } while (retry_count != 0);
598}
599
600static void arcmsr_flush_adapter_cache(struct AdapterControlBlock *acb)
601{
602 switch (acb->adapter_type) {
603
604 case ACB_ADAPTER_TYPE_A: {
605 arcmsr_flush_hba_cache(acb);
606 }
607 break;
608
609 case ACB_ADAPTER_TYPE_B: {
610 arcmsr_flush_hbb_cache(acb);
611 }
612 }
613}
614
615static void arcmsr_report_sense_info(struct CommandControlBlock *ccb)
616{
617
618 struct scsi_cmnd *pcmd = ccb->pcmd;
619 struct SENSE_DATA *sensebuffer = (struct SENSE_DATA *)pcmd->sense_buffer;
620
621 pcmd->result = DID_OK << 16;
622 if (sensebuffer) {
623 int sense_data_length =
624 sizeof(struct SENSE_DATA) < sizeof(pcmd->sense_buffer)
625 ? sizeof(struct SENSE_DATA) : sizeof(pcmd->sense_buffer);
626 memset(sensebuffer, 0, sizeof(pcmd->sense_buffer));
627 memcpy(sensebuffer, ccb->arcmsr_cdb.SenseData, sense_data_length);
628 sensebuffer->ErrorCode = SCSI_SENSE_CURRENT_ERRORS;
629 sensebuffer->Valid = 1;
630 }
631}
632
633static u32 arcmsr_disable_outbound_ints(struct AdapterControlBlock *acb)
634{
635 u32 orig_mask = 0;
636 switch (acb->adapter_type) {
637
638 case ACB_ADAPTER_TYPE_A : {
639 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
640 orig_mask = readl(&reg->outbound_intmask)|\
641 ARCMSR_MU_OUTBOUND_MESSAGE0_INTMASKENABLE;
642 writel(orig_mask|ARCMSR_MU_OUTBOUND_ALL_INTMASKENABLE, \
643 &reg->outbound_intmask);
644 }
645 break;
646
647 case ACB_ADAPTER_TYPE_B : {
648 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
649 orig_mask = readl(reg->iop2drv_doorbell_mask_reg) & \
650 (~ARCMSR_IOP2DRV_MESSAGE_CMD_DONE);
651 writel(0, reg->iop2drv_doorbell_mask_reg);
652 }
653 break;
654 }
655 return orig_mask;
656}
657
658static void arcmsr_report_ccb_state(struct AdapterControlBlock *acb, \
659 struct CommandControlBlock *ccb, uint32_t flag_ccb)
660{
661
662 uint8_t id, lun;
663 id = ccb->pcmd->device->id;
664 lun = ccb->pcmd->device->lun;
665 if (!(flag_ccb & ARCMSR_CCBREPLY_FLAG_ERROR)) {
666 if (acb->devstate[id][lun] == ARECA_RAID_GONE)
667 acb->devstate[id][lun] = ARECA_RAID_GOOD;
668 ccb->pcmd->result = DID_OK << 16;
669 arcmsr_ccb_complete(ccb, 1);
670 } else {
671 switch (ccb->arcmsr_cdb.DeviceStatus) {
672 case ARCMSR_DEV_SELECT_TIMEOUT: {
673 acb->devstate[id][lun] = ARECA_RAID_GONE;
674 ccb->pcmd->result = DID_NO_CONNECT << 16;
675 arcmsr_ccb_complete(ccb, 1);
676 }
677 break;
678
679 case ARCMSR_DEV_ABORTED:
680
681 case ARCMSR_DEV_INIT_FAIL: {
682 acb->devstate[id][lun] = ARECA_RAID_GONE;
683 ccb->pcmd->result = DID_BAD_TARGET << 16;
684 arcmsr_ccb_complete(ccb, 1);
685 }
686 break;
687
688 case ARCMSR_DEV_CHECK_CONDITION: {
689 acb->devstate[id][lun] = ARECA_RAID_GOOD;
690 arcmsr_report_sense_info(ccb);
691 arcmsr_ccb_complete(ccb, 1);
692 }
693 break;
694
695 default:
696 printk(KERN_NOTICE
697 "arcmsr%d: scsi id = %d lun = %d"
698 " isr get command error done, "
699 "but got unknown DeviceStatus = 0x%x \n"
700 , acb->host->host_no
701 , id
702 , lun
703 , ccb->arcmsr_cdb.DeviceStatus);
704 acb->devstate[id][lun] = ARECA_RAID_GONE;
705 ccb->pcmd->result = DID_NO_CONNECT << 16;
706 arcmsr_ccb_complete(ccb, 1);
707 break;
708 }
709 }
710}
711
712static void arcmsr_drain_donequeue(struct AdapterControlBlock *acb, uint32_t flag_ccb)
713
714{
715 struct CommandControlBlock *ccb;
716
717 ccb = (struct CommandControlBlock *)(acb->vir2phy_offset + (flag_ccb << 5));
718 if ((ccb->acb != acb) || (ccb->startdone != ARCMSR_CCB_START)) {
719 if (ccb->startdone == ARCMSR_CCB_ABORTED) {
720 struct scsi_cmnd *abortcmd = ccb->pcmd;
721 if (abortcmd) {
722 abortcmd->result |= DID_ABORT << 16;
723 arcmsr_ccb_complete(ccb, 1);
724 printk(KERN_NOTICE "arcmsr%d: ccb ='0x%p' \
725 isr got aborted command \n", acb->host->host_no, ccb);
726 }
727 }
728 printk(KERN_NOTICE "arcmsr%d: isr get an illegal ccb command \
729 done acb = '0x%p'"
730 "ccb = '0x%p' ccbacb = '0x%p' startdone = 0x%x"
731 " ccboutstandingcount = %d \n"
732 , acb->host->host_no
733 , acb
734 , ccb
735 , ccb->acb
736 , ccb->startdone
737 , atomic_read(&acb->ccboutstandingcount));
738 }
739 arcmsr_report_ccb_state(acb, ccb, flag_ccb);
740}
741
742static void arcmsr_done4abort_postqueue(struct AdapterControlBlock *acb)
743{
744 int i = 0;
745 uint32_t flag_ccb;
746
747 switch (acb->adapter_type) {
748
749 case ACB_ADAPTER_TYPE_A: {
750 struct MessageUnit_A __iomem *reg = \
751 (struct MessageUnit_A *)acb->pmu;
752 uint32_t outbound_intstatus;
753 outbound_intstatus = readl(&reg->outbound_intstatus) & \
754 acb->outbound_int_enable;
755 /*clear and abort all outbound posted Q*/
756 writel(outbound_intstatus, &reg->outbound_intstatus);/*clear interrupt*/
757 while (((flag_ccb = readl(&reg->outbound_queueport)) != 0xFFFFFFFF) \
758 && (i++ < ARCMSR_MAX_OUTSTANDING_CMD)) {
759 arcmsr_drain_donequeue(acb, flag_ccb);
760 }
761 }
762 break;
763
764 case ACB_ADAPTER_TYPE_B: {
765 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
766 /*clear all outbound posted Q*/
767 for (i = 0; i < ARCMSR_MAX_HBB_POSTQUEUE; i++) {
768 if ((flag_ccb = readl(&reg->done_qbuffer[i])) != 0) {
769 writel(0, &reg->done_qbuffer[i]);
770 arcmsr_drain_donequeue(acb, flag_ccb);
771 }
772 writel(0, &reg->post_qbuffer[i]);
773 }
774 reg->doneq_index = 0;
775 reg->postq_index = 0;
776 }
777 break;
778 }
779}
403static void arcmsr_remove(struct pci_dev *pdev) 780static void arcmsr_remove(struct pci_dev *pdev)
404{ 781{
405 struct Scsi_Host *host = pci_get_drvdata(pdev); 782 struct Scsi_Host *host = pci_get_drvdata(pdev);
406 struct AdapterControlBlock *acb = 783 struct AdapterControlBlock *acb =
407 (struct AdapterControlBlock *) host->hostdata; 784 (struct AdapterControlBlock *) host->hostdata;
408 struct MessageUnit __iomem *reg = acb->pmu;
409 int poll_count = 0; 785 int poll_count = 0;
410 786
411 arcmsr_free_sysfs_attr(acb); 787 arcmsr_free_sysfs_attr(acb);
412 scsi_remove_host(host); 788 scsi_remove_host(host);
413 arcmsr_stop_adapter_bgrb(acb); 789 arcmsr_stop_adapter_bgrb(acb);
414 arcmsr_flush_adapter_cache(acb); 790 arcmsr_flush_adapter_cache(acb);
415 writel(readl(&reg->outbound_intmask) | 791 arcmsr_disable_outbound_ints(acb);
416 ARCMSR_MU_OUTBOUND_ALL_INTMASKENABLE,
417 &reg->outbound_intmask);
418 acb->acb_flags |= ACB_F_SCSISTOPADAPTER; 792 acb->acb_flags |= ACB_F_SCSISTOPADAPTER;
419 acb->acb_flags &= ~ACB_F_IOP_INITED; 793 acb->acb_flags &= ~ACB_F_IOP_INITED;
420 794
421 for (poll_count = 0; poll_count < 256; poll_count++) { 795 for (poll_count = 0; poll_count < ARCMSR_MAX_OUTSTANDING_CMD; poll_count++) {
422 if (!atomic_read(&acb->ccboutstandingcount)) 796 if (!atomic_read(&acb->ccboutstandingcount))
423 break; 797 break;
424 arcmsr_interrupt(acb); 798 arcmsr_interrupt(acb);/* FIXME: need spinlock */
425 msleep(25); 799 msleep(25);
426 } 800 }
427 801
@@ -429,8 +803,7 @@ static void arcmsr_remove(struct pci_dev *pdev)
429 int i; 803 int i;
430 804
431 arcmsr_abort_allcmd(acb); 805 arcmsr_abort_allcmd(acb);
432 for (i = 0; i < ARCMSR_MAX_OUTSTANDING_CMD; i++) 806 arcmsr_done4abort_postqueue(acb);
433 readl(&reg->outbound_queueport);
434 for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) { 807 for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) {
435 struct CommandControlBlock *ccb = acb->pccb_pool[i]; 808 struct CommandControlBlock *ccb = acb->pccb_pool[i];
436 if (ccb->startdone == ARCMSR_CCB_START) { 809 if (ccb->startdone == ARCMSR_CCB_START) {
@@ -477,75 +850,32 @@ static void arcmsr_module_exit(void)
477module_init(arcmsr_module_init); 850module_init(arcmsr_module_init);
478module_exit(arcmsr_module_exit); 851module_exit(arcmsr_module_exit);
479 852
480static u32 arcmsr_disable_outbound_ints(struct AdapterControlBlock *acb) 853static void arcmsr_enable_outbound_ints(struct AdapterControlBlock *acb, \
481{ 854 u32 intmask_org)
482 struct MessageUnit __iomem *reg = acb->pmu;
483 u32 orig_mask = readl(&reg->outbound_intmask);
484
485 writel(orig_mask | ARCMSR_MU_OUTBOUND_ALL_INTMASKENABLE,
486 &reg->outbound_intmask);
487 return orig_mask;
488}
489
490static void arcmsr_enable_outbound_ints(struct AdapterControlBlock *acb,
491 u32 orig_mask)
492{ 855{
493 struct MessageUnit __iomem *reg = acb->pmu;
494 u32 mask; 856 u32 mask;
495 857
496 mask = orig_mask & ~(ARCMSR_MU_OUTBOUND_POSTQUEUE_INTMASKENABLE | 858 switch (acb->adapter_type) {
497 ARCMSR_MU_OUTBOUND_DOORBELL_INTMASKENABLE);
498 writel(mask, &reg->outbound_intmask);
499}
500 859
501static void arcmsr_flush_adapter_cache(struct AdapterControlBlock *acb) 860 case ACB_ADAPTER_TYPE_A : {
502{ 861 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
503 struct MessageUnit __iomem *reg = acb->pmu; 862 mask = intmask_org & ~(ARCMSR_MU_OUTBOUND_POSTQUEUE_INTMASKENABLE |
504 863 ARCMSR_MU_OUTBOUND_DOORBELL_INTMASKENABLE);
505 writel(ARCMSR_INBOUND_MESG0_FLUSH_CACHE, &reg->inbound_msgaddr0); 864 writel(mask, &reg->outbound_intmask);
506 if (arcmsr_wait_msgint_ready(acb)) 865 acb->outbound_int_enable = ~(intmask_org & mask) & 0x000000ff;
507 printk(KERN_NOTICE 866 }
508 "arcmsr%d: wait 'flush adapter cache' timeout \n" 867 break;
509 , acb->host->host_no);
510}
511
512static void arcmsr_report_sense_info(struct CommandControlBlock *ccb)
513{
514 struct scsi_cmnd *pcmd = ccb->pcmd;
515 struct SENSE_DATA *sensebuffer = (struct SENSE_DATA *)pcmd->sense_buffer;
516 868
517 pcmd->result = DID_OK << 16; 869 case ACB_ADAPTER_TYPE_B : {
518 if (sensebuffer) { 870 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
519 int sense_data_length = 871 mask = intmask_org | (ARCMSR_IOP2DRV_DATA_WRITE_OK | \
520 sizeof (struct SENSE_DATA) < sizeof (pcmd->sense_buffer) 872 ARCMSR_IOP2DRV_DATA_READ_OK | ARCMSR_IOP2DRV_CDB_DONE);
521 ? sizeof (struct SENSE_DATA) : sizeof (pcmd->sense_buffer); 873 writel(mask, reg->iop2drv_doorbell_mask_reg);
522 memset(sensebuffer, 0, sizeof (pcmd->sense_buffer)); 874 acb->outbound_int_enable = (intmask_org | mask) & 0x0000000f;
523 memcpy(sensebuffer, ccb->arcmsr_cdb.SenseData, sense_data_length); 875 }
524 sensebuffer->ErrorCode = SCSI_SENSE_CURRENT_ERRORS;
525 sensebuffer->Valid = 1;
526 } 876 }
527} 877}
528 878
529static uint8_t arcmsr_wait_msgint_ready(struct AdapterControlBlock *acb)
530{
531 struct MessageUnit __iomem *reg = acb->pmu;
532 uint32_t Index;
533 uint8_t Retries = 0x00;
534
535 do {
536 for (Index = 0; Index < 100; Index++) {
537 if (readl(&reg->outbound_intstatus)
538 & ARCMSR_MU_OUTBOUND_MESSAGE0_INT) {
539 writel(ARCMSR_MU_OUTBOUND_MESSAGE0_INT
540 , &reg->outbound_intstatus);
541 return 0x00;
542 }
543 msleep_interruptible(10);
544 }/*max 1 seconds*/
545 } while (Retries++ < 20);/*max 20 sec*/
546 return 0xff;
547}
548
549static void arcmsr_build_ccb(struct AdapterControlBlock *acb, 879static void arcmsr_build_ccb(struct AdapterControlBlock *acb,
550 struct CommandControlBlock *ccb, struct scsi_cmnd *pcmd) 880 struct CommandControlBlock *ccb, struct scsi_cmnd *pcmd)
551{ 881{
@@ -556,7 +886,7 @@ static void arcmsr_build_ccb(struct AdapterControlBlock *acb,
556 int nseg; 886 int nseg;
557 887
558 ccb->pcmd = pcmd; 888 ccb->pcmd = pcmd;
559 memset(arcmsr_cdb, 0, sizeof (struct ARCMSR_CDB)); 889 memset(arcmsr_cdb, 0, sizeof(struct ARCMSR_CDB));
560 arcmsr_cdb->Bus = 0; 890 arcmsr_cdb->Bus = 0;
561 arcmsr_cdb->TargetID = pcmd->device->id; 891 arcmsr_cdb->TargetID = pcmd->device->id;
562 arcmsr_cdb->LUN = pcmd->device->lun; 892 arcmsr_cdb->LUN = pcmd->device->lun;
@@ -609,52 +939,85 @@ static void arcmsr_build_ccb(struct AdapterControlBlock *acb,
609 939
610static void arcmsr_post_ccb(struct AdapterControlBlock *acb, struct CommandControlBlock *ccb) 940static void arcmsr_post_ccb(struct AdapterControlBlock *acb, struct CommandControlBlock *ccb)
611{ 941{
612 struct MessageUnit __iomem *reg = acb->pmu;
613 uint32_t cdb_shifted_phyaddr = ccb->cdb_shifted_phyaddr; 942 uint32_t cdb_shifted_phyaddr = ccb->cdb_shifted_phyaddr;
614 struct ARCMSR_CDB *arcmsr_cdb = (struct ARCMSR_CDB *)&ccb->arcmsr_cdb; 943 struct ARCMSR_CDB *arcmsr_cdb = (struct ARCMSR_CDB *)&ccb->arcmsr_cdb;
615
616 atomic_inc(&acb->ccboutstandingcount); 944 atomic_inc(&acb->ccboutstandingcount);
617 ccb->startdone = ARCMSR_CCB_START; 945 ccb->startdone = ARCMSR_CCB_START;
618 if (arcmsr_cdb->Flags & ARCMSR_CDB_FLAG_SGL_BSIZE) 946
619 writel(cdb_shifted_phyaddr | ARCMSR_CCBPOST_FLAG_SGL_BSIZE, 947 switch (acb->adapter_type) {
948 case ACB_ADAPTER_TYPE_A: {
949 struct MessageUnit_A *reg = (struct MessageUnit_A *)acb->pmu;
950
951 if (arcmsr_cdb->Flags & ARCMSR_CDB_FLAG_SGL_BSIZE)
952 writel(cdb_shifted_phyaddr | ARCMSR_CCBPOST_FLAG_SGL_BSIZE,
620 &reg->inbound_queueport); 953 &reg->inbound_queueport);
621 else 954 else {
622 writel(cdb_shifted_phyaddr, &reg->inbound_queueport); 955 writel(cdb_shifted_phyaddr, &reg->inbound_queueport);
623} 956 }
957 }
958 break;
624 959
625void arcmsr_post_Qbuffer(struct AdapterControlBlock *acb) 960 case ACB_ADAPTER_TYPE_B: {
626{ 961 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
627 struct MessageUnit __iomem *reg = acb->pmu; 962 uint32_t ending_index, index = reg->postq_index;
628 struct QBUFFER __iomem *pwbuffer = (struct QBUFFER __iomem *) &reg->message_wbuffer;
629 uint8_t __iomem *iop_data = (uint8_t __iomem *) pwbuffer->data;
630 int32_t allxfer_len = 0;
631 963
632 if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_READED) { 964 ending_index = ((index + 1) % ARCMSR_MAX_HBB_POSTQUEUE);
633 acb->acb_flags &= (~ACB_F_MESSAGE_WQBUFFER_READED); 965 writel(0, &reg->post_qbuffer[ending_index]);
634 while ((acb->wqbuf_firstindex != acb->wqbuf_lastindex) 966 if (arcmsr_cdb->Flags & ARCMSR_CDB_FLAG_SGL_BSIZE) {
635 && (allxfer_len < 124)) { 967 writel(cdb_shifted_phyaddr | ARCMSR_CCBPOST_FLAG_SGL_BSIZE,\
636 writeb(acb->wqbuffer[acb->wqbuf_firstindex], iop_data); 968 &reg->post_qbuffer[index]);
637 acb->wqbuf_firstindex++; 969 }
638 acb->wqbuf_firstindex %= ARCMSR_MAX_QBUFFER; 970 else {
639 iop_data++; 971 writel(cdb_shifted_phyaddr, &reg->post_qbuffer[index]);
640 allxfer_len++;
641 } 972 }
642 writel(allxfer_len, &pwbuffer->data_len); 973 index++;
643 writel(ARCMSR_INBOUND_DRIVER_DATA_WRITE_OK 974 index %= ARCMSR_MAX_HBB_POSTQUEUE;/*if last index number set it to 0 */
644 , &reg->inbound_doorbell); 975 reg->postq_index = index;
976 writel(ARCMSR_DRV2IOP_CDB_POSTED, reg->drv2iop_doorbell_reg);
977 }
978 break;
645 } 979 }
646} 980}
647 981
648static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock *acb) 982static void arcmsr_stop_hba_bgrb(struct AdapterControlBlock *acb)
649{ 983{
650 struct MessageUnit __iomem *reg = acb->pmu; 984 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
651
652 acb->acb_flags &= ~ACB_F_MSG_START_BGRB; 985 acb->acb_flags &= ~ACB_F_MSG_START_BGRB;
653 writel(ARCMSR_INBOUND_MESG0_STOP_BGRB, &reg->inbound_msgaddr0); 986 writel(ARCMSR_INBOUND_MESG0_STOP_BGRB, &reg->inbound_msgaddr0);
654 if (arcmsr_wait_msgint_ready(acb)) 987
988 if (arcmsr_hba_wait_msgint_ready(acb)) {
655 printk(KERN_NOTICE 989 printk(KERN_NOTICE
656 "arcmsr%d: wait 'stop adapter background rebulid' timeout \n" 990 "arcmsr%d: wait 'stop adapter background rebulid' timeout \n"
657 , acb->host->host_no); 991 , acb->host->host_no);
992 }
993}
994
995static void arcmsr_stop_hbb_bgrb(struct AdapterControlBlock *acb)
996{
997 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
998 acb->acb_flags &= ~ACB_F_MSG_START_BGRB;
999 writel(ARCMSR_MESSAGE_STOP_BGRB, reg->drv2iop_doorbell_reg);
1000
1001 if (arcmsr_hbb_wait_msgint_ready(acb)) {
1002 printk(KERN_NOTICE
1003 "arcmsr%d: wait 'stop adapter background rebulid' timeout \n"
1004 , acb->host->host_no);
1005 }
1006}
1007
1008static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock *acb)
1009{
1010 switch (acb->adapter_type) {
1011 case ACB_ADAPTER_TYPE_A: {
1012 arcmsr_stop_hba_bgrb(acb);
1013 }
1014 break;
1015
1016 case ACB_ADAPTER_TYPE_B: {
1017 arcmsr_stop_hbb_bgrb(acb);
1018 }
1019 break;
1020 }
658} 1021}
659 1022
660static void arcmsr_free_ccb_pool(struct AdapterControlBlock *acb) 1023static void arcmsr_free_ccb_pool(struct AdapterControlBlock *acb)
@@ -665,151 +1028,260 @@ static void arcmsr_free_ccb_pool(struct AdapterControlBlock *acb)
665 acb->dma_coherent_handle); 1028 acb->dma_coherent_handle);
666} 1029}
667 1030
668static irqreturn_t arcmsr_interrupt(struct AdapterControlBlock *acb) 1031void arcmsr_iop_message_read(struct AdapterControlBlock *acb)
669{ 1032{
670 struct MessageUnit __iomem *reg = acb->pmu; 1033 switch (acb->adapter_type) {
671 struct CommandControlBlock *ccb; 1034 case ACB_ADAPTER_TYPE_A: {
672 uint32_t flag_ccb, outbound_intstatus, outbound_doorbell; 1035 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
1036 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK, &reg->inbound_doorbell);
1037 }
1038 break;
673 1039
674 outbound_intstatus = readl(&reg->outbound_intstatus) 1040 case ACB_ADAPTER_TYPE_B: {
675 & acb->outbound_int_enable; 1041 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
676 writel(outbound_intstatus, &reg->outbound_intstatus); 1042 writel(ARCMSR_DRV2IOP_DATA_READ_OK, reg->drv2iop_doorbell_reg);
677 if (outbound_intstatus & ARCMSR_MU_OUTBOUND_DOORBELL_INT) {
678 outbound_doorbell = readl(&reg->outbound_doorbell);
679 writel(outbound_doorbell, &reg->outbound_doorbell);
680 if (outbound_doorbell & ARCMSR_OUTBOUND_IOP331_DATA_WRITE_OK) {
681 struct QBUFFER __iomem * prbuffer =
682 (struct QBUFFER __iomem *) &reg->message_rbuffer;
683 uint8_t __iomem * iop_data = (uint8_t __iomem *)prbuffer->data;
684 int32_t my_empty_len, iop_len, rqbuf_firstindex, rqbuf_lastindex;
685
686 rqbuf_lastindex = acb->rqbuf_lastindex;
687 rqbuf_firstindex = acb->rqbuf_firstindex;
688 iop_len = readl(&prbuffer->data_len);
689 my_empty_len = (rqbuf_firstindex - rqbuf_lastindex - 1)
690 &(ARCMSR_MAX_QBUFFER - 1);
691 if (my_empty_len >= iop_len) {
692 while (iop_len > 0) {
693 acb->rqbuffer[acb->rqbuf_lastindex] = readb(iop_data);
694 acb->rqbuf_lastindex++;
695 acb->rqbuf_lastindex %= ARCMSR_MAX_QBUFFER;
696 iop_data++;
697 iop_len--;
698 }
699 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK,
700 &reg->inbound_doorbell);
701 } else
702 acb->acb_flags |= ACB_F_IOPDATA_OVERFLOW;
703 }
704 if (outbound_doorbell & ARCMSR_OUTBOUND_IOP331_DATA_READ_OK) {
705 acb->acb_flags |= ACB_F_MESSAGE_WQBUFFER_READED;
706 if (acb->wqbuf_firstindex != acb->wqbuf_lastindex) {
707 struct QBUFFER __iomem * pwbuffer =
708 (struct QBUFFER __iomem *) &reg->message_wbuffer;
709 uint8_t __iomem * iop_data = (uint8_t __iomem *) pwbuffer->data;
710 int32_t allxfer_len = 0;
711
712 acb->acb_flags &= (~ACB_F_MESSAGE_WQBUFFER_READED);
713 while ((acb->wqbuf_firstindex != acb->wqbuf_lastindex)
714 && (allxfer_len < 124)) {
715 writeb(acb->wqbuffer[acb->wqbuf_firstindex], iop_data);
716 acb->wqbuf_firstindex++;
717 acb->wqbuf_firstindex %= ARCMSR_MAX_QBUFFER;
718 iop_data++;
719 allxfer_len++;
720 }
721 writel(allxfer_len, &pwbuffer->data_len);
722 writel(ARCMSR_INBOUND_DRIVER_DATA_WRITE_OK,
723 &reg->inbound_doorbell);
724 }
725 if (acb->wqbuf_firstindex == acb->wqbuf_lastindex)
726 acb->acb_flags |= ACB_F_MESSAGE_WQBUFFER_CLEARED;
727 } 1043 }
1044 break;
728 } 1045 }
729 if (outbound_intstatus & ARCMSR_MU_OUTBOUND_POSTQUEUE_INT) { 1046}
730 int id, lun; 1047
1048static void arcmsr_iop_message_wrote(struct AdapterControlBlock *acb)
1049{
1050 switch (acb->adapter_type) {
1051 case ACB_ADAPTER_TYPE_A: {
1052 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
731 /* 1053 /*
732 **************************************************************** 1054 ** push inbound doorbell tell iop, driver data write ok
733 ** areca cdb command done 1055 ** and wait reply on next hwinterrupt for next Qbuffer post
734 ****************************************************************
735 */ 1056 */
736 while (1) { 1057 writel(ARCMSR_INBOUND_DRIVER_DATA_WRITE_OK, &reg->inbound_doorbell);
737 if ((flag_ccb = readl(&reg->outbound_queueport)) == 0xFFFFFFFF) 1058 }
738 break;/*chip FIFO no ccb for completion already*/ 1059 break;
739 /* check if command done with no error*/ 1060
740 ccb = (struct CommandControlBlock *)(acb->vir2phy_offset + 1061 case ACB_ADAPTER_TYPE_B: {
741 (flag_ccb << 5)); 1062 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
742 if ((ccb->acb != acb) || (ccb->startdone != ARCMSR_CCB_START)) { 1063 /*
743 if (ccb->startdone == ARCMSR_CCB_ABORTED) { 1064 ** push inbound doorbell tell iop, driver data write ok
744 struct scsi_cmnd *abortcmd = ccb->pcmd; 1065 ** and wait reply on next hwinterrupt for next Qbuffer post
745 if (abortcmd) { 1066 */
746 abortcmd->result |= DID_ABORT >> 16; 1067 writel(ARCMSR_DRV2IOP_DATA_WRITE_OK, reg->drv2iop_doorbell_reg);
747 arcmsr_ccb_complete(ccb, 1); 1068 }
748 printk(KERN_NOTICE 1069 break;
749 "arcmsr%d: ccb ='0x%p' isr got aborted command \n" 1070 }
750 , acb->host->host_no, ccb); 1071}
751 } 1072
752 continue; 1073struct QBUFFER *arcmsr_get_iop_rqbuffer(struct AdapterControlBlock *acb)
753 } 1074{
754 printk(KERN_NOTICE 1075 static struct QBUFFER *qbuffer;
755 "arcmsr%d: isr get an illegal ccb command done acb = '0x%p'" 1076
756 "ccb = '0x%p' ccbacb = '0x%p' startdone = 0x%x" 1077 switch (acb->adapter_type) {
757 " ccboutstandingcount = %d \n" 1078
758 , acb->host->host_no 1079 case ACB_ADAPTER_TYPE_A: {
759 , acb 1080 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
760 , ccb 1081 qbuffer = (struct QBUFFER __iomem *) &reg->message_rbuffer;
761 , ccb->acb 1082 }
762 , ccb->startdone 1083 break;
763 , atomic_read(&acb->ccboutstandingcount)); 1084
764 continue; 1085 case ACB_ADAPTER_TYPE_B: {
765 } 1086 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
766 id = ccb->pcmd->device->id; 1087 qbuffer = (struct QBUFFER __iomem *) reg->ioctl_rbuffer_reg;
767 lun = ccb->pcmd->device->lun; 1088 }
768 if (!(flag_ccb & ARCMSR_CCBREPLY_FLAG_ERROR)) { 1089 break;
769 if (acb->devstate[id][lun] == ARECA_RAID_GONE) 1090 }
770 acb->devstate[id][lun] = ARECA_RAID_GOOD; 1091 return qbuffer;
771 ccb->pcmd->result = DID_OK << 16; 1092}
772 arcmsr_ccb_complete(ccb, 1); 1093
773 } else { 1094static struct QBUFFER *arcmsr_get_iop_wqbuffer(struct AdapterControlBlock *acb)
774 switch(ccb->arcmsr_cdb.DeviceStatus) { 1095{
775 case ARCMSR_DEV_SELECT_TIMEOUT: { 1096 static struct QBUFFER *pqbuffer;
776 acb->devstate[id][lun] = ARECA_RAID_GONE; 1097
777 ccb->pcmd->result = DID_NO_CONNECT << 16; 1098 switch (acb->adapter_type) {
778 arcmsr_ccb_complete(ccb, 1); 1099
779 } 1100 case ACB_ADAPTER_TYPE_A: {
780 break; 1101 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
781 case ARCMSR_DEV_ABORTED: 1102 pqbuffer = (struct QBUFFER *) &reg->message_wbuffer;
782 case ARCMSR_DEV_INIT_FAIL: { 1103 }
783 acb->devstate[id][lun] = ARECA_RAID_GONE; 1104 break;
784 ccb->pcmd->result = DID_BAD_TARGET << 16; 1105
785 arcmsr_ccb_complete(ccb, 1); 1106 case ACB_ADAPTER_TYPE_B: {
786 } 1107 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
787 break; 1108 pqbuffer = (struct QBUFFER __iomem *)reg->ioctl_wbuffer_reg;
788 case ARCMSR_DEV_CHECK_CONDITION: { 1109 }
789 acb->devstate[id][lun] = ARECA_RAID_GOOD; 1110 break;
790 arcmsr_report_sense_info(ccb); 1111 }
791 arcmsr_ccb_complete(ccb, 1); 1112 return pqbuffer;
792 } 1113}
793 break; 1114
794 default: 1115static void arcmsr_iop2drv_data_wrote_handle(struct AdapterControlBlock *acb)
795 printk(KERN_NOTICE 1116{
796 "arcmsr%d: scsi id = %d lun = %d" 1117 struct QBUFFER *prbuffer;
797 " isr get command error done, " 1118 struct QBUFFER *pQbuffer;
798 "but got unknown DeviceStatus = 0x%x \n" 1119 uint8_t *iop_data;
799 , acb->host->host_no 1120 int32_t my_empty_len, iop_len, rqbuf_firstindex, rqbuf_lastindex;
800 , id 1121
801 , lun 1122 rqbuf_lastindex = acb->rqbuf_lastindex;
802 , ccb->arcmsr_cdb.DeviceStatus); 1123 rqbuf_firstindex = acb->rqbuf_firstindex;
803 acb->devstate[id][lun] = ARECA_RAID_GONE; 1124 prbuffer = arcmsr_get_iop_rqbuffer(acb);
804 ccb->pcmd->result = DID_NO_CONNECT << 16; 1125 iop_data = (uint8_t *)prbuffer->data;
805 arcmsr_ccb_complete(ccb, 1); 1126 iop_len = prbuffer->data_len;
806 break; 1127 my_empty_len = (rqbuf_firstindex - rqbuf_lastindex -1)&(ARCMSR_MAX_QBUFFER -1);
807 } 1128
808 } 1129 if (my_empty_len >= iop_len)
809 }/*drain reply FIFO*/ 1130 {
1131 while (iop_len > 0) {
1132 pQbuffer = (struct QBUFFER *)&acb->rqbuffer[rqbuf_lastindex];
1133 memcpy(pQbuffer, iop_data,1);
1134 rqbuf_lastindex++;
1135 rqbuf_lastindex %= ARCMSR_MAX_QBUFFER;
1136 iop_data++;
1137 iop_len--;
1138 }
1139 acb->rqbuf_lastindex = rqbuf_lastindex;
1140 arcmsr_iop_message_read(acb);
1141 }
1142
1143 else {
1144 acb->acb_flags |= ACB_F_IOPDATA_OVERFLOW;
1145 }
1146}
1147
1148static void arcmsr_iop2drv_data_read_handle(struct AdapterControlBlock *acb)
1149{
1150 acb->acb_flags |= ACB_F_MESSAGE_WQBUFFER_READED;
1151 if (acb->wqbuf_firstindex != acb->wqbuf_lastindex) {
1152 uint8_t *pQbuffer;
1153 struct QBUFFER *pwbuffer;
1154 uint8_t *iop_data;
1155 int32_t allxfer_len = 0;
1156
1157 acb->acb_flags &= (~ACB_F_MESSAGE_WQBUFFER_READED);
1158 pwbuffer = arcmsr_get_iop_wqbuffer(acb);
1159 iop_data = (uint8_t __iomem *)pwbuffer->data;
1160
1161 while ((acb->wqbuf_firstindex != acb->wqbuf_lastindex) && \
1162 (allxfer_len < 124)) {
1163 pQbuffer = &acb->wqbuffer[acb->wqbuf_firstindex];
1164 memcpy(iop_data, pQbuffer, 1);
1165 acb->wqbuf_firstindex++;
1166 acb->wqbuf_firstindex %= ARCMSR_MAX_QBUFFER;
1167 iop_data++;
1168 allxfer_len++;
1169 }
1170 pwbuffer->data_len = allxfer_len;
1171
1172 arcmsr_iop_message_wrote(acb);
1173 }
1174
1175 if (acb->wqbuf_firstindex == acb->wqbuf_lastindex) {
1176 acb->acb_flags |= ACB_F_MESSAGE_WQBUFFER_CLEARED;
1177 }
1178}
1179
1180static void arcmsr_hba_doorbell_isr(struct AdapterControlBlock *acb)
1181{
1182 uint32_t outbound_doorbell;
1183 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
1184
1185 outbound_doorbell = readl(&reg->outbound_doorbell);
1186 writel(outbound_doorbell, &reg->outbound_doorbell);
1187 if (outbound_doorbell & ARCMSR_OUTBOUND_IOP331_DATA_WRITE_OK) {
1188 arcmsr_iop2drv_data_wrote_handle(acb);
1189 }
1190
1191 if (outbound_doorbell & ARCMSR_OUTBOUND_IOP331_DATA_READ_OK) {
1192 arcmsr_iop2drv_data_read_handle(acb);
1193 }
1194}
1195
1196static void arcmsr_hba_postqueue_isr(struct AdapterControlBlock *acb)
1197{
1198 uint32_t flag_ccb;
1199 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
1200
1201 while ((flag_ccb = readl(&reg->outbound_queueport)) != 0xFFFFFFFF) {
1202 arcmsr_drain_donequeue(acb, flag_ccb);
1203 }
1204}
1205
1206static void arcmsr_hbb_postqueue_isr(struct AdapterControlBlock *acb)
1207{
1208 uint32_t index;
1209 uint32_t flag_ccb;
1210 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
1211
1212 index = reg->doneq_index;
1213
1214 while ((flag_ccb = readl(&reg->done_qbuffer[index])) != 0) {
1215 writel(0, &reg->done_qbuffer[index]);
1216 arcmsr_drain_donequeue(acb, flag_ccb);
1217 index++;
1218 index %= ARCMSR_MAX_HBB_POSTQUEUE;
1219 reg->doneq_index = index;
1220 }
1221}
1222
1223static int arcmsr_handle_hba_isr(struct AdapterControlBlock *acb)
1224{
1225 uint32_t outbound_intstatus;
1226 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
1227
1228 outbound_intstatus = readl(&reg->outbound_intstatus) & \
1229 acb->outbound_int_enable;
1230 if (!(outbound_intstatus & ARCMSR_MU_OUTBOUND_HANDLE_INT)) {
1231 return 1;
1232 }
1233 writel(outbound_intstatus, &reg->outbound_intstatus);
1234 if (outbound_intstatus & ARCMSR_MU_OUTBOUND_DOORBELL_INT) {
1235 arcmsr_hba_doorbell_isr(acb);
1236 }
1237 if (outbound_intstatus & ARCMSR_MU_OUTBOUND_POSTQUEUE_INT) {
1238 arcmsr_hba_postqueue_isr(acb);
1239 }
1240 return 0;
1241}
1242
1243static int arcmsr_handle_hbb_isr(struct AdapterControlBlock *acb)
1244{
1245 uint32_t outbound_doorbell;
1246 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
1247
1248 outbound_doorbell = readl(reg->iop2drv_doorbell_reg) & \
1249 acb->outbound_int_enable;
1250 if (!outbound_doorbell)
1251 return 1;
1252
1253 writel(~outbound_doorbell, reg->iop2drv_doorbell_reg);
1254
1255 if (outbound_doorbell & ARCMSR_IOP2DRV_DATA_WRITE_OK) {
1256 arcmsr_iop2drv_data_wrote_handle(acb);
1257 }
1258 if (outbound_doorbell & ARCMSR_IOP2DRV_DATA_READ_OK) {
1259 arcmsr_iop2drv_data_read_handle(acb);
1260 }
1261 if (outbound_doorbell & ARCMSR_IOP2DRV_CDB_DONE) {
1262 arcmsr_hbb_postqueue_isr(acb);
1263 }
1264
1265 return 0;
1266}
1267
1268static irqreturn_t arcmsr_interrupt(struct AdapterControlBlock *acb)
1269{
1270 switch (acb->adapter_type) {
1271 case ACB_ADAPTER_TYPE_A: {
1272 if (arcmsr_handle_hba_isr(acb)) {
1273 return IRQ_NONE;
1274 }
1275 }
1276 break;
1277
1278 case ACB_ADAPTER_TYPE_B: {
1279 if (arcmsr_handle_hbb_isr(acb)) {
1280 return IRQ_NONE;
1281 }
1282 }
1283 break;
810 } 1284 }
811 if (!(outbound_intstatus & ARCMSR_MU_OUTBOUND_HANDLE_INT))
812 return IRQ_NONE;
813 return IRQ_HANDLED; 1285 return IRQ_HANDLED;
814} 1286}
815 1287
@@ -818,16 +1290,47 @@ static void arcmsr_iop_parking(struct AdapterControlBlock *acb)
818 if (acb) { 1290 if (acb) {
819 /* stop adapter background rebuild */ 1291 /* stop adapter background rebuild */
820 if (acb->acb_flags & ACB_F_MSG_START_BGRB) { 1292 if (acb->acb_flags & ACB_F_MSG_START_BGRB) {
1293 uint32_t intmask_org;
821 acb->acb_flags &= ~ACB_F_MSG_START_BGRB; 1294 acb->acb_flags &= ~ACB_F_MSG_START_BGRB;
1295 intmask_org = arcmsr_disable_outbound_ints(acb);
822 arcmsr_stop_adapter_bgrb(acb); 1296 arcmsr_stop_adapter_bgrb(acb);
823 arcmsr_flush_adapter_cache(acb); 1297 arcmsr_flush_adapter_cache(acb);
1298 arcmsr_enable_outbound_ints(acb, intmask_org);
824 } 1299 }
825 } 1300 }
826} 1301}
827 1302
828static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, struct scsi_cmnd *cmd) 1303void arcmsr_post_ioctldata2iop(struct AdapterControlBlock *acb)
1304{
1305 int32_t wqbuf_firstindex, wqbuf_lastindex;
1306 uint8_t *pQbuffer;
1307 struct QBUFFER *pwbuffer;
1308 uint8_t *iop_data;
1309 int32_t allxfer_len = 0;
1310
1311 pwbuffer = arcmsr_get_iop_wqbuffer(acb);
1312 iop_data = (uint8_t __iomem *)pwbuffer->data;
1313 if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_READED) {
1314 acb->acb_flags &= (~ACB_F_MESSAGE_WQBUFFER_READED);
1315 wqbuf_firstindex = acb->wqbuf_firstindex;
1316 wqbuf_lastindex = acb->wqbuf_lastindex;
1317 while ((wqbuf_firstindex != wqbuf_lastindex) && (allxfer_len < 124)) {
1318 pQbuffer = &acb->wqbuffer[wqbuf_firstindex];
1319 memcpy(iop_data, pQbuffer, 1);
1320 wqbuf_firstindex++;
1321 wqbuf_firstindex %= ARCMSR_MAX_QBUFFER;
1322 iop_data++;
1323 allxfer_len++;
1324 }
1325 acb->wqbuf_firstindex = wqbuf_firstindex;
1326 pwbuffer->data_len = allxfer_len;
1327 arcmsr_iop_message_wrote(acb);
1328 }
1329}
1330
1331static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, \
1332 struct scsi_cmnd *cmd)
829{ 1333{
830 struct MessageUnit __iomem *reg = acb->pmu;
831 struct CMD_MESSAGE_FIELD *pcmdmessagefld; 1334 struct CMD_MESSAGE_FIELD *pcmdmessagefld;
832 int retvalue = 0, transfer_len = 0; 1335 int retvalue = 0, transfer_len = 0;
833 char *buffer; 1336 char *buffer;
@@ -836,7 +1339,7 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, struct scsi_
836 (uint32_t ) cmd->cmnd[6] << 16 | 1339 (uint32_t ) cmd->cmnd[6] << 16 |
837 (uint32_t ) cmd->cmnd[7] << 8 | 1340 (uint32_t ) cmd->cmnd[7] << 8 |
838 (uint32_t ) cmd->cmnd[8]; 1341 (uint32_t ) cmd->cmnd[8];
839 /* 4 bytes: Areca io control code */ 1342 /* 4 bytes: Areca io control code */
840 1343
841 sg = scsi_sglist(cmd); 1344 sg = scsi_sglist(cmd);
842 buffer = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; 1345 buffer = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
@@ -852,194 +1355,199 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, struct scsi_
852 } 1355 }
853 pcmdmessagefld = (struct CMD_MESSAGE_FIELD *) buffer; 1356 pcmdmessagefld = (struct CMD_MESSAGE_FIELD *) buffer;
854 switch(controlcode) { 1357 switch(controlcode) {
1358
855 case ARCMSR_MESSAGE_READ_RQBUFFER: { 1359 case ARCMSR_MESSAGE_READ_RQBUFFER: {
856 unsigned long *ver_addr; 1360 unsigned long *ver_addr;
857 dma_addr_t buf_handle; 1361 dma_addr_t buf_handle;
858 uint8_t *pQbuffer, *ptmpQbuffer; 1362 uint8_t *pQbuffer, *ptmpQbuffer;
859 int32_t allxfer_len = 0; 1363 int32_t allxfer_len = 0;
1364
1365 ver_addr = pci_alloc_consistent(acb->pdev, 1032, &buf_handle);
1366 if (!ver_addr) {
1367 retvalue = ARCMSR_MESSAGE_FAIL;
1368 goto message_out;
1369 }
1370 ptmpQbuffer = (uint8_t *) ver_addr;
1371 while ((acb->rqbuf_firstindex != acb->rqbuf_lastindex)
1372 && (allxfer_len < 1031)) {
1373 pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex];
1374 memcpy(ptmpQbuffer, pQbuffer, 1);
1375 acb->rqbuf_firstindex++;
1376 acb->rqbuf_firstindex %= ARCMSR_MAX_QBUFFER;
1377 ptmpQbuffer++;
1378 allxfer_len++;
1379 }
1380 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) {
860 1381
861 ver_addr = pci_alloc_consistent(acb->pdev, 1032, &buf_handle); 1382 struct QBUFFER *prbuffer;
862 if (!ver_addr) { 1383 uint8_t *iop_data;
863 retvalue = ARCMSR_MESSAGE_FAIL; 1384 int32_t iop_len;
864 goto message_out; 1385
865 } 1386 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW;
866 ptmpQbuffer = (uint8_t *) ver_addr; 1387 prbuffer = arcmsr_get_iop_rqbuffer(acb);
867 while ((acb->rqbuf_firstindex != acb->rqbuf_lastindex) 1388 iop_data = (uint8_t *)prbuffer->data;
868 && (allxfer_len < 1031)) { 1389 iop_len = readl(&prbuffer->data_len);
869 pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; 1390 while (iop_len > 0) {
870 memcpy(ptmpQbuffer, pQbuffer, 1); 1391 acb->rqbuffer[acb->rqbuf_lastindex] = readb(iop_data);
871 acb->rqbuf_firstindex++; 1392 acb->rqbuf_lastindex++;
872 acb->rqbuf_firstindex %= ARCMSR_MAX_QBUFFER; 1393 acb->rqbuf_lastindex %= ARCMSR_MAX_QBUFFER;
873 ptmpQbuffer++; 1394 iop_data++;
874 allxfer_len++; 1395 iop_len--;
875 }
876 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) {
877 struct QBUFFER __iomem * prbuffer = (struct QBUFFER __iomem *)
878 &reg->message_rbuffer;
879 uint8_t __iomem * iop_data = (uint8_t __iomem *)prbuffer->data;
880 int32_t iop_len;
881
882 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW;
883 iop_len = readl(&prbuffer->data_len);
884 while (iop_len > 0) {
885 acb->rqbuffer[acb->rqbuf_lastindex] = readb(iop_data);
886 acb->rqbuf_lastindex++;
887 acb->rqbuf_lastindex %= ARCMSR_MAX_QBUFFER;
888 iop_data++;
889 iop_len--;
890 }
891 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK,
892 &reg->inbound_doorbell);
893 } 1396 }
894 memcpy(pcmdmessagefld->messagedatabuffer, 1397 arcmsr_iop_message_read(acb);
895 (uint8_t *)ver_addr, allxfer_len); 1398 }
896 pcmdmessagefld->cmdmessage.Length = allxfer_len; 1399 memcpy(pcmdmessagefld->messagedatabuffer, (uint8_t *)ver_addr, allxfer_len);
897 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK; 1400 pcmdmessagefld->cmdmessage.Length = allxfer_len;
898 pci_free_consistent(acb->pdev, 1032, ver_addr, buf_handle); 1401 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK;
1402 pci_free_consistent(acb->pdev, 1032, ver_addr, buf_handle);
899 } 1403 }
900 break; 1404 break;
901 case ARCMSR_MESSAGE_WRITE_WQBUFFER: {
902 unsigned long *ver_addr;
903 dma_addr_t buf_handle;
904 int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex;
905 uint8_t *pQbuffer, *ptmpuserbuffer;
906 1405
907 ver_addr = pci_alloc_consistent(acb->pdev, 1032, &buf_handle); 1406 case ARCMSR_MESSAGE_WRITE_WQBUFFER: {
908 if (!ver_addr) { 1407 unsigned long *ver_addr;
909 retvalue = ARCMSR_MESSAGE_FAIL; 1408 dma_addr_t buf_handle;
910 goto message_out; 1409 int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex;
911 } 1410 uint8_t *pQbuffer, *ptmpuserbuffer;
912 ptmpuserbuffer = (uint8_t *)ver_addr; 1411
913 user_len = pcmdmessagefld->cmdmessage.Length; 1412 ver_addr = pci_alloc_consistent(acb->pdev, 1032, &buf_handle);
914 memcpy(ptmpuserbuffer, pcmdmessagefld->messagedatabuffer, user_len); 1413 if (!ver_addr) {
915 wqbuf_lastindex = acb->wqbuf_lastindex; 1414 retvalue = ARCMSR_MESSAGE_FAIL;
916 wqbuf_firstindex = acb->wqbuf_firstindex; 1415 goto message_out;
917 if (wqbuf_lastindex != wqbuf_firstindex) { 1416 }
1417 ptmpuserbuffer = (uint8_t *)ver_addr;
1418 user_len = pcmdmessagefld->cmdmessage.Length;
1419 memcpy(ptmpuserbuffer, pcmdmessagefld->messagedatabuffer, user_len);
1420 wqbuf_lastindex = acb->wqbuf_lastindex;
1421 wqbuf_firstindex = acb->wqbuf_firstindex;
1422 if (wqbuf_lastindex != wqbuf_firstindex) {
1423 struct SENSE_DATA *sensebuffer =
1424 (struct SENSE_DATA *)cmd->sense_buffer;
1425 arcmsr_post_ioctldata2iop(acb);
1426 /* has error report sensedata */
1427 sensebuffer->ErrorCode = 0x70;
1428 sensebuffer->SenseKey = ILLEGAL_REQUEST;
1429 sensebuffer->AdditionalSenseLength = 0x0A;
1430 sensebuffer->AdditionalSenseCode = 0x20;
1431 sensebuffer->Valid = 1;
1432 retvalue = ARCMSR_MESSAGE_FAIL;
1433 } else {
1434 my_empty_len = (wqbuf_firstindex-wqbuf_lastindex - 1)
1435 &(ARCMSR_MAX_QBUFFER - 1);
1436 if (my_empty_len >= user_len) {
1437 while (user_len > 0) {
1438 pQbuffer =
1439 &acb->wqbuffer[acb->wqbuf_lastindex];
1440 memcpy(pQbuffer, ptmpuserbuffer, 1);
1441 acb->wqbuf_lastindex++;
1442 acb->wqbuf_lastindex %= ARCMSR_MAX_QBUFFER;
1443 ptmpuserbuffer++;
1444 user_len--;
1445 }
1446 if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_CLEARED) {
1447 acb->acb_flags &=
1448 ~ACB_F_MESSAGE_WQBUFFER_CLEARED;
1449 arcmsr_post_ioctldata2iop(acb);
1450 }
1451 } else {
1452 /* has error report sensedata */
918 struct SENSE_DATA *sensebuffer = 1453 struct SENSE_DATA *sensebuffer =
919 (struct SENSE_DATA *)cmd->sense_buffer; 1454 (struct SENSE_DATA *)cmd->sense_buffer;
920 arcmsr_post_Qbuffer(acb);
921 /* has error report sensedata */
922 sensebuffer->ErrorCode = 0x70; 1455 sensebuffer->ErrorCode = 0x70;
923 sensebuffer->SenseKey = ILLEGAL_REQUEST; 1456 sensebuffer->SenseKey = ILLEGAL_REQUEST;
924 sensebuffer->AdditionalSenseLength = 0x0A; 1457 sensebuffer->AdditionalSenseLength = 0x0A;
925 sensebuffer->AdditionalSenseCode = 0x20; 1458 sensebuffer->AdditionalSenseCode = 0x20;
926 sensebuffer->Valid = 1; 1459 sensebuffer->Valid = 1;
927 retvalue = ARCMSR_MESSAGE_FAIL; 1460 retvalue = ARCMSR_MESSAGE_FAIL;
928 } else { 1461 }
929 my_empty_len = (wqbuf_firstindex-wqbuf_lastindex - 1)
930 &(ARCMSR_MAX_QBUFFER - 1);
931 if (my_empty_len >= user_len) {
932 while (user_len > 0) {
933 pQbuffer =
934 &acb->wqbuffer[acb->wqbuf_lastindex];
935 memcpy(pQbuffer, ptmpuserbuffer, 1);
936 acb->wqbuf_lastindex++;
937 acb->wqbuf_lastindex %= ARCMSR_MAX_QBUFFER;
938 ptmpuserbuffer++;
939 user_len--;
940 }
941 if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_CLEARED) {
942 acb->acb_flags &=
943 ~ACB_F_MESSAGE_WQBUFFER_CLEARED;
944 arcmsr_post_Qbuffer(acb);
945 }
946 } else {
947 /* has error report sensedata */
948 struct SENSE_DATA *sensebuffer =
949 (struct SENSE_DATA *)cmd->sense_buffer;
950 sensebuffer->ErrorCode = 0x70;
951 sensebuffer->SenseKey = ILLEGAL_REQUEST;
952 sensebuffer->AdditionalSenseLength = 0x0A;
953 sensebuffer->AdditionalSenseCode = 0x20;
954 sensebuffer->Valid = 1;
955 retvalue = ARCMSR_MESSAGE_FAIL;
956 }
957 } 1462 }
958 pci_free_consistent(acb->pdev, 1032, ver_addr, buf_handle); 1463 pci_free_consistent(acb->pdev, 1032, ver_addr, buf_handle);
959 } 1464 }
960 break; 1465 break;
1466
961 case ARCMSR_MESSAGE_CLEAR_RQBUFFER: { 1467 case ARCMSR_MESSAGE_CLEAR_RQBUFFER: {
962 uint8_t *pQbuffer = acb->rqbuffer; 1468 uint8_t *pQbuffer = acb->rqbuffer;
963 1469
964 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { 1470 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) {
965 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; 1471 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW;
966 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK, 1472 arcmsr_iop_message_read(acb);
967 &reg->inbound_doorbell); 1473 }
968 } 1474 acb->acb_flags |= ACB_F_MESSAGE_RQBUFFER_CLEARED;
969 acb->acb_flags |= ACB_F_MESSAGE_RQBUFFER_CLEARED; 1475 acb->rqbuf_firstindex = 0;
970 acb->rqbuf_firstindex = 0; 1476 acb->rqbuf_lastindex = 0;
971 acb->rqbuf_lastindex = 0; 1477 memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER);
972 memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER); 1478 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK;
973 pcmdmessagefld->cmdmessage.ReturnCode =
974 ARCMSR_MESSAGE_RETURNCODE_OK;
975 } 1479 }
976 break; 1480 break;
1481
977 case ARCMSR_MESSAGE_CLEAR_WQBUFFER: { 1482 case ARCMSR_MESSAGE_CLEAR_WQBUFFER: {
978 uint8_t *pQbuffer = acb->wqbuffer; 1483 uint8_t *pQbuffer = acb->wqbuffer;
979 1484
980 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { 1485 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) {
981 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; 1486 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW;
982 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK 1487 arcmsr_iop_message_read(acb);
983 , &reg->inbound_doorbell); 1488 }
984 } 1489 acb->acb_flags |=
985 acb->acb_flags |= 1490 (ACB_F_MESSAGE_WQBUFFER_CLEARED |
986 (ACB_F_MESSAGE_WQBUFFER_CLEARED | 1491 ACB_F_MESSAGE_WQBUFFER_READED);
987 ACB_F_MESSAGE_WQBUFFER_READED); 1492 acb->wqbuf_firstindex = 0;
988 acb->wqbuf_firstindex = 0; 1493 acb->wqbuf_lastindex = 0;
989 acb->wqbuf_lastindex = 0; 1494 memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER);
990 memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER); 1495 pcmdmessagefld->cmdmessage.ReturnCode =
991 pcmdmessagefld->cmdmessage.ReturnCode = 1496 ARCMSR_MESSAGE_RETURNCODE_OK;
992 ARCMSR_MESSAGE_RETURNCODE_OK;
993 } 1497 }
994 break; 1498 break;
1499
995 case ARCMSR_MESSAGE_CLEAR_ALLQBUFFER: { 1500 case ARCMSR_MESSAGE_CLEAR_ALLQBUFFER: {
996 uint8_t *pQbuffer; 1501 uint8_t *pQbuffer;
997 1502
998 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { 1503 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) {
999 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; 1504 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW;
1000 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK 1505 arcmsr_iop_message_read(acb);
1001 , &reg->inbound_doorbell); 1506 }
1002 } 1507 acb->acb_flags |=
1003 acb->acb_flags |= 1508 (ACB_F_MESSAGE_WQBUFFER_CLEARED
1004 (ACB_F_MESSAGE_WQBUFFER_CLEARED 1509 | ACB_F_MESSAGE_RQBUFFER_CLEARED
1005 | ACB_F_MESSAGE_RQBUFFER_CLEARED 1510 | ACB_F_MESSAGE_WQBUFFER_READED);
1006 | ACB_F_MESSAGE_WQBUFFER_READED); 1511 acb->rqbuf_firstindex = 0;
1007 acb->rqbuf_firstindex = 0; 1512 acb->rqbuf_lastindex = 0;
1008 acb->rqbuf_lastindex = 0; 1513 acb->wqbuf_firstindex = 0;
1009 acb->wqbuf_firstindex = 0; 1514 acb->wqbuf_lastindex = 0;
1010 acb->wqbuf_lastindex = 0; 1515 pQbuffer = acb->rqbuffer;
1011 pQbuffer = acb->rqbuffer; 1516 memset(pQbuffer, 0, sizeof(struct QBUFFER));
1012 memset(pQbuffer, 0, sizeof (struct QBUFFER)); 1517 pQbuffer = acb->wqbuffer;
1013 pQbuffer = acb->wqbuffer; 1518 memset(pQbuffer, 0, sizeof(struct QBUFFER));
1014 memset(pQbuffer, 0, sizeof (struct QBUFFER)); 1519 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK;
1015 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK;
1016 } 1520 }
1017 break; 1521 break;
1522
1018 case ARCMSR_MESSAGE_RETURN_CODE_3F: { 1523 case ARCMSR_MESSAGE_RETURN_CODE_3F: {
1019 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_3F; 1524 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_3F;
1020 } 1525 }
1021 break; 1526 break;
1527
1022 case ARCMSR_MESSAGE_SAY_HELLO: { 1528 case ARCMSR_MESSAGE_SAY_HELLO: {
1023 int8_t * hello_string = "Hello! I am ARCMSR"; 1529 int8_t *hello_string = "Hello! I am ARCMSR";
1024 1530
1025 memcpy(pcmdmessagefld->messagedatabuffer, hello_string 1531 memcpy(pcmdmessagefld->messagedatabuffer, hello_string
1026 , (int16_t)strlen(hello_string)); 1532 , (int16_t)strlen(hello_string));
1027 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK; 1533 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK;
1028 } 1534 }
1029 break; 1535 break;
1536
1030 case ARCMSR_MESSAGE_SAY_GOODBYE: 1537 case ARCMSR_MESSAGE_SAY_GOODBYE:
1031 arcmsr_iop_parking(acb); 1538 arcmsr_iop_parking(acb);
1032 break; 1539 break;
1540
1033 case ARCMSR_MESSAGE_FLUSH_ADAPTER_CACHE: 1541 case ARCMSR_MESSAGE_FLUSH_ADAPTER_CACHE:
1034 arcmsr_flush_adapter_cache(acb); 1542 arcmsr_flush_adapter_cache(acb);
1035 break; 1543 break;
1544
1036 default: 1545 default:
1037 retvalue = ARCMSR_MESSAGE_FAIL; 1546 retvalue = ARCMSR_MESSAGE_FAIL;
1038 } 1547 }
1039 message_out: 1548 message_out:
1040 sg = scsi_sglist(cmd); 1549 sg = scsi_sglist(cmd);
1041 kunmap_atomic(buffer - sg->offset, KM_IRQ0); 1550 kunmap_atomic(buffer - sg->offset, KM_IRQ0);
1042
1043 return retvalue; 1551 return retvalue;
1044} 1552}
1045 1553
@@ -1109,8 +1617,7 @@ static int arcmsr_queue_command(struct scsi_cmnd *cmd,
1109 void (* done)(struct scsi_cmnd *)) 1617 void (* done)(struct scsi_cmnd *))
1110{ 1618{
1111 struct Scsi_Host *host = cmd->device->host; 1619 struct Scsi_Host *host = cmd->device->host;
1112 struct AdapterControlBlock *acb = 1620 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata;
1113 (struct AdapterControlBlock *) host->hostdata;
1114 struct CommandControlBlock *ccb; 1621 struct CommandControlBlock *ccb;
1115 int target = cmd->device->id; 1622 int target = cmd->device->id;
1116 int lun = cmd->device->lun; 1623 int lun = cmd->device->lun;
@@ -1153,26 +1660,27 @@ static int arcmsr_queue_command(struct scsi_cmnd *cmd,
1153 ccb = arcmsr_get_freeccb(acb); 1660 ccb = arcmsr_get_freeccb(acb);
1154 if (!ccb) 1661 if (!ccb)
1155 return SCSI_MLQUEUE_HOST_BUSY; 1662 return SCSI_MLQUEUE_HOST_BUSY;
1663
1156 arcmsr_build_ccb(acb, ccb, cmd); 1664 arcmsr_build_ccb(acb, ccb, cmd);
1157 arcmsr_post_ccb(acb, ccb); 1665 arcmsr_post_ccb(acb, ccb);
1158 return 0; 1666 return 0;
1159} 1667}
1160 1668
1161static void arcmsr_get_firmware_spec(struct AdapterControlBlock *acb) 1669static void arcmsr_get_hba_config(struct AdapterControlBlock *acb)
1162{ 1670{
1163 struct MessageUnit __iomem *reg = acb->pmu; 1671 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
1164 char *acb_firm_model = acb->firm_model; 1672 char *acb_firm_model = acb->firm_model;
1165 char *acb_firm_version = acb->firm_version; 1673 char *acb_firm_version = acb->firm_version;
1166 char __iomem *iop_firm_model = (char __iomem *) &reg->message_rwbuffer[15]; 1674 char *iop_firm_model = (char *) (&reg->message_rwbuffer[15]);
1167 char __iomem *iop_firm_version = (char __iomem *) &reg->message_rwbuffer[17]; 1675 char *iop_firm_version = (char *) (&reg->message_rwbuffer[17]);
1168 int count; 1676 int count;
1169 1677
1170 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG, &reg->inbound_msgaddr0); 1678 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG, &reg->inbound_msgaddr0);
1171 if (arcmsr_wait_msgint_ready(acb)) 1679 if (arcmsr_hba_wait_msgint_ready(acb)) {
1172 printk(KERN_NOTICE 1680 printk(KERN_NOTICE "arcmsr%d: wait 'get adapter firmware \
1173 "arcmsr%d: wait " 1681 miscellaneous data' timeout \n", acb->host->host_no);
1174 "'get adapter firmware miscellaneous data' timeout \n" 1682 }
1175 , acb->host->host_no); 1683
1176 count = 8; 1684 count = 8;
1177 while (count) { 1685 while (count) {
1178 *acb_firm_model = readb(iop_firm_model); 1686 *acb_firm_model = readb(iop_firm_model);
@@ -1180,6 +1688,7 @@ static void arcmsr_get_firmware_spec(struct AdapterControlBlock *acb)
1180 iop_firm_model++; 1688 iop_firm_model++;
1181 count--; 1689 count--;
1182 } 1690 }
1691
1183 count = 16; 1692 count = 16;
1184 while (count) { 1693 while (count) {
1185 *acb_firm_version = readb(iop_firm_version); 1694 *acb_firm_version = readb(iop_firm_version);
@@ -1187,28 +1696,93 @@ static void arcmsr_get_firmware_spec(struct AdapterControlBlock *acb)
1187 iop_firm_version++; 1696 iop_firm_version++;
1188 count--; 1697 count--;
1189 } 1698 }
1190 printk(KERN_INFO 1699
1191 "ARECA RAID ADAPTER%d: FIRMWARE VERSION %s \n" 1700 printk(KERN_INFO "ARECA RAID ADAPTER%d: FIRMWARE VERSION %s \n"
1192 , acb->host->host_no 1701 , acb->host->host_no
1193 , acb->firm_version); 1702 , acb->firm_version);
1703
1194 acb->firm_request_len = readl(&reg->message_rwbuffer[1]); 1704 acb->firm_request_len = readl(&reg->message_rwbuffer[1]);
1195 acb->firm_numbers_queue = readl(&reg->message_rwbuffer[2]); 1705 acb->firm_numbers_queue = readl(&reg->message_rwbuffer[2]);
1196 acb->firm_sdram_size = readl(&reg->message_rwbuffer[3]); 1706 acb->firm_sdram_size = readl(&reg->message_rwbuffer[3]);
1197 acb->firm_hd_channels = readl(&reg->message_rwbuffer[4]); 1707 acb->firm_hd_channels = readl(&reg->message_rwbuffer[4]);
1198} 1708}
1199 1709
1200static void arcmsr_polling_ccbdone(struct AdapterControlBlock *acb, 1710static void arcmsr_get_hbb_config(struct AdapterControlBlock *acb)
1711{
1712 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
1713 uint32_t *lrwbuffer = reg->msgcode_rwbuffer_reg;
1714 char *acb_firm_model = acb->firm_model;
1715 char *acb_firm_version = acb->firm_version;
1716 char *iop_firm_model = (char *) (&lrwbuffer[15]);
1717 /*firm_model,15,60-67*/
1718 char *iop_firm_version = (char *) (&lrwbuffer[17]);
1719 /*firm_version,17,68-83*/
1720 int count;
1721
1722 writel(ARCMSR_MESSAGE_GET_CONFIG, reg->drv2iop_doorbell_reg);
1723 if (arcmsr_hbb_wait_msgint_ready(acb)) {
1724 printk(KERN_NOTICE "arcmsr%d: wait 'get adapter firmware \
1725 miscellaneous data' timeout \n", acb->host->host_no);
1726 }
1727
1728 count = 8;
1729 while (count)
1730 {
1731 *acb_firm_model = readb(iop_firm_model);
1732 acb_firm_model++;
1733 iop_firm_model++;
1734 count--;
1735 }
1736
1737 count = 16;
1738 while (count)
1739 {
1740 *acb_firm_version = readb(iop_firm_version);
1741 acb_firm_version++;
1742 iop_firm_version++;
1743 count--;
1744 }
1745
1746 printk(KERN_INFO "ARECA RAID ADAPTER%d: FIRMWARE VERSION %s \n",
1747 acb->host->host_no,
1748 acb->firm_version);
1749
1750 lrwbuffer++;
1751 acb->firm_request_len = readl(lrwbuffer++);
1752 /*firm_request_len,1,04-07*/
1753 acb->firm_numbers_queue = readl(lrwbuffer++);
1754 /*firm_numbers_queue,2,08-11*/
1755 acb->firm_sdram_size = readl(lrwbuffer++);
1756 /*firm_sdram_size,3,12-15*/
1757 acb->firm_hd_channels = readl(lrwbuffer);
1758 /*firm_ide_channels,4,16-19*/
1759}
1760
1761static void arcmsr_get_firmware_spec(struct AdapterControlBlock *acb)
1762{
1763 switch (acb->adapter_type) {
1764 case ACB_ADAPTER_TYPE_A: {
1765 arcmsr_get_hba_config(acb);
1766 }
1767 break;
1768
1769 case ACB_ADAPTER_TYPE_B: {
1770 arcmsr_get_hbb_config(acb);
1771 }
1772 break;
1773 }
1774}
1775
1776static void arcmsr_polling_hba_ccbdone(struct AdapterControlBlock *acb,
1201 struct CommandControlBlock *poll_ccb) 1777 struct CommandControlBlock *poll_ccb)
1202{ 1778{
1203 struct MessageUnit __iomem *reg = acb->pmu; 1779 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
1204 struct CommandControlBlock *ccb; 1780 struct CommandControlBlock *ccb;
1205 uint32_t flag_ccb, outbound_intstatus, poll_ccb_done = 0, poll_count = 0; 1781 uint32_t flag_ccb, outbound_intstatus, poll_ccb_done = 0, poll_count = 0;
1206 int id, lun;
1207 1782
1208 polling_ccb_retry: 1783 polling_hba_ccb_retry:
1209 poll_count++; 1784 poll_count++;
1210 outbound_intstatus = readl(&reg->outbound_intstatus) 1785 outbound_intstatus = readl(&reg->outbound_intstatus) & acb->outbound_int_enable;
1211 & acb->outbound_int_enable;
1212 writel(outbound_intstatus, &reg->outbound_intstatus);/*clear interrupt*/ 1786 writel(outbound_intstatus, &reg->outbound_intstatus);/*clear interrupt*/
1213 while (1) { 1787 while (1) {
1214 if ((flag_ccb = readl(&reg->outbound_queueport)) == 0xFFFFFFFF) { 1788 if ((flag_ccb = readl(&reg->outbound_queueport)) == 0xFFFFFFFF) {
@@ -1218,17 +1792,14 @@ static void arcmsr_polling_ccbdone(struct AdapterControlBlock *acb,
1218 msleep(25); 1792 msleep(25);
1219 if (poll_count > 100) 1793 if (poll_count > 100)
1220 break; 1794 break;
1221 goto polling_ccb_retry; 1795 goto polling_hba_ccb_retry;
1222 } 1796 }
1223 } 1797 }
1224 ccb = (struct CommandControlBlock *) 1798 ccb = (struct CommandControlBlock *)(acb->vir2phy_offset + (flag_ccb << 5));
1225 (acb->vir2phy_offset + (flag_ccb << 5)); 1799 poll_ccb_done = (ccb == poll_ccb) ? 1:0;
1226 if ((ccb->acb != acb) || 1800 if ((ccb->acb != acb) || (ccb->startdone != ARCMSR_CCB_START)) {
1227 (ccb->startdone != ARCMSR_CCB_START)) { 1801 if ((ccb->startdone == ARCMSR_CCB_ABORTED) || (ccb == poll_ccb)) {
1228 if ((ccb->startdone == ARCMSR_CCB_ABORTED) || 1802 printk(KERN_NOTICE "arcmsr%d: scsi id = %d lun = %d ccb = '0x%p'"
1229 (ccb == poll_ccb)) {
1230 printk(KERN_NOTICE
1231 "arcmsr%d: scsi id = %d lun = %d ccb = '0x%p'"
1232 " poll command abort successfully \n" 1803 " poll command abort successfully \n"
1233 , acb->host->host_no 1804 , acb->host->host_no
1234 , ccb->pcmd->device->id 1805 , ccb->pcmd->device->id
@@ -1239,176 +1810,280 @@ static void arcmsr_polling_ccbdone(struct AdapterControlBlock *acb,
1239 poll_ccb_done = 1; 1810 poll_ccb_done = 1;
1240 continue; 1811 continue;
1241 } 1812 }
1242 printk(KERN_NOTICE 1813 printk(KERN_NOTICE "arcmsr%d: polling get an illegal ccb"
1243 "arcmsr%d: polling get an illegal ccb" 1814 " command done ccb = '0x%p'"
1244 " command done ccb ='0x%p'"
1245 "ccboutstandingcount = %d \n" 1815 "ccboutstandingcount = %d \n"
1246 , acb->host->host_no 1816 , acb->host->host_no
1247 , ccb 1817 , ccb
1248 , atomic_read(&acb->ccboutstandingcount)); 1818 , atomic_read(&acb->ccboutstandingcount));
1249 continue; 1819 continue;
1250 } 1820 }
1251 id = ccb->pcmd->device->id; 1821 arcmsr_report_ccb_state(acb, ccb, flag_ccb);
1252 lun = ccb->pcmd->device->lun; 1822 }
1253 if (!(flag_ccb & ARCMSR_CCBREPLY_FLAG_ERROR)) { 1823}
1254 if (acb->devstate[id][lun] == ARECA_RAID_GONE) 1824
1255 acb->devstate[id][lun] = ARECA_RAID_GOOD; 1825static void arcmsr_polling_hbb_ccbdone(struct AdapterControlBlock *acb, \
1256 ccb->pcmd->result = DID_OK << 16; 1826 struct CommandControlBlock *poll_ccb)
1257 arcmsr_ccb_complete(ccb, 1); 1827{
1258 } else { 1828 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
1259 switch(ccb->arcmsr_cdb.DeviceStatus) { 1829 struct CommandControlBlock *ccb;
1260 case ARCMSR_DEV_SELECT_TIMEOUT: { 1830 uint32_t flag_ccb, poll_ccb_done = 0, poll_count = 0;
1261 acb->devstate[id][lun] = ARECA_RAID_GONE; 1831 int index;
1262 ccb->pcmd->result = DID_NO_CONNECT << 16; 1832
1263 arcmsr_ccb_complete(ccb, 1); 1833 polling_hbb_ccb_retry:
1264 } 1834 poll_count++;
1265 break; 1835 /* clear doorbell interrupt */
1266 case ARCMSR_DEV_ABORTED: 1836 writel(ARCMSR_DOORBELL_INT_CLEAR_PATTERN, reg->iop2drv_doorbell_reg);
1267 case ARCMSR_DEV_INIT_FAIL: { 1837 while (1) {
1268 acb->devstate[id][lun] = ARECA_RAID_GONE; 1838 index = reg->doneq_index;
1269 ccb->pcmd->result = DID_BAD_TARGET << 16; 1839 if ((flag_ccb = readl(&reg->done_qbuffer[index])) == 0) {
1270 arcmsr_ccb_complete(ccb, 1); 1840 if (poll_ccb_done)
1841 break;
1842 else {
1843 msleep(25);
1844 if (poll_count > 100)
1845 break;
1846 goto polling_hbb_ccb_retry;
1271 } 1847 }
1272 break; 1848 }
1273 case ARCMSR_DEV_CHECK_CONDITION: { 1849 writel(0, &reg->done_qbuffer[index]);
1274 acb->devstate[id][lun] = ARECA_RAID_GOOD; 1850 index++;
1275 arcmsr_report_sense_info(ccb); 1851 /*if last index number set it to 0 */
1852 index %= ARCMSR_MAX_HBB_POSTQUEUE;
1853 reg->doneq_index = index;
1854 /* check ifcommand done with no error*/
1855 ccb = (struct CommandControlBlock *)\
1856 (acb->vir2phy_offset + (flag_ccb << 5));/*frame must be 32 bytes aligned*/
1857 poll_ccb_done = (ccb == poll_ccb) ? 1:0;
1858 if ((ccb->acb != acb) || (ccb->startdone != ARCMSR_CCB_START)) {
1859 if (ccb->startdone == ARCMSR_CCB_ABORTED) {
1860 printk(KERN_NOTICE "arcmsr%d: \
1861 scsi id = %d lun = %d ccb = '0x%p' poll command abort successfully \n"
1862 ,acb->host->host_no
1863 ,ccb->pcmd->device->id
1864 ,ccb->pcmd->device->lun
1865 ,ccb);
1866 ccb->pcmd->result = DID_ABORT << 16;
1276 arcmsr_ccb_complete(ccb, 1); 1867 arcmsr_ccb_complete(ccb, 1);
1868 continue;
1277 } 1869 }
1278 break; 1870 printk(KERN_NOTICE "arcmsr%d: polling get an illegal ccb"
1279 default: 1871 " command done ccb = '0x%p'"
1280 printk(KERN_NOTICE 1872 "ccboutstandingcount = %d \n"
1281 "arcmsr%d: scsi id = %d lun = %d"
1282 " polling and getting command error done"
1283 "but got unknown DeviceStatus = 0x%x \n"
1284 , acb->host->host_no 1873 , acb->host->host_no
1285 , id 1874 , ccb
1286 , lun 1875 , atomic_read(&acb->ccboutstandingcount));
1287 , ccb->arcmsr_cdb.DeviceStatus); 1876 continue;
1288 acb->devstate[id][lun] = ARECA_RAID_GONE;
1289 ccb->pcmd->result = DID_BAD_TARGET << 16;
1290 arcmsr_ccb_complete(ccb, 1);
1291 break;
1292 } 1877 }
1878 arcmsr_report_ccb_state(acb, ccb, flag_ccb);
1879 } /*drain reply FIFO*/
1880}
1881
1882static void arcmsr_polling_ccbdone(struct AdapterControlBlock *acb, \
1883 struct CommandControlBlock *poll_ccb)
1884{
1885 switch (acb->adapter_type) {
1886
1887 case ACB_ADAPTER_TYPE_A: {
1888 arcmsr_polling_hba_ccbdone(acb,poll_ccb);
1889 }
1890 break;
1891
1892 case ACB_ADAPTER_TYPE_B: {
1893 arcmsr_polling_hbb_ccbdone(acb,poll_ccb);
1293 } 1894 }
1294 } 1895 }
1295} 1896}
1296static void arcmsr_done4_abort_postqueue(struct AdapterControlBlock *acb) 1897
1898static int arcmsr_iop_confirm(struct AdapterControlBlock *acb)
1297{ 1899{
1298 int i = 0, found = 0; 1900 uint32_t cdb_phyaddr, ccb_phyaddr_hi32;
1299 int id, lun; 1901 dma_addr_t dma_coherent_handle;
1300 uint32_t flag_ccb, outbound_intstatus; 1902 /*
1301 struct MessageUnit __iomem *reg = acb->pmu; 1903 ********************************************************************
1302 struct CommandControlBlock *ccb; 1904 ** here we need to tell iop 331 our freeccb.HighPart
1303 /*clear and abort all outbound posted Q*/ 1905 ** if freeccb.HighPart is not zero
1304 1906 ********************************************************************
1305 while (((flag_ccb = readl(&reg->outbound_queueport)) != 0xFFFFFFFF) && 1907 */
1306(i++ < 256)){ 1908 dma_coherent_handle = acb->dma_coherent_handle;
1307 ccb = (struct CommandControlBlock *)(acb->vir2phy_offset + 1909 cdb_phyaddr = (uint32_t)(dma_coherent_handle);
1308(flag_ccb << 5)); 1910 ccb_phyaddr_hi32 = (uint32_t)((cdb_phyaddr >> 16) >> 16);
1309 if (ccb){ 1911 /*
1310 if ((ccb->acb != acb)||(ccb->startdone != \ 1912 ***********************************************************************
1311ARCMSR_CCB_START)){ 1913 ** if adapter type B, set window of "post command Q"
1312 printk(KERN_NOTICE "arcmsr%d: polling get \ 1914 ***********************************************************************
1313an illegal ccb" "command done ccb = '0x%p'""ccboutstandingcount = %d \n", 1915 */
1314 acb->host->host_no, ccb, 1916 switch (acb->adapter_type) {
1315 atomic_read(&acb->ccboutstandingcount)); 1917
1316 continue; 1918 case ACB_ADAPTER_TYPE_A: {
1919 if (ccb_phyaddr_hi32 != 0) {
1920 struct MessageUnit_A __iomem *reg = \
1921 (struct MessageUnit_A *)acb->pmu;
1922 uint32_t intmask_org;
1923 intmask_org = arcmsr_disable_outbound_ints(acb);
1924 writel(ARCMSR_SIGNATURE_SET_CONFIG, \
1925 &reg->message_rwbuffer[0]);
1926 writel(ccb_phyaddr_hi32, &reg->message_rwbuffer[1]);
1927 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG, \
1928 &reg->inbound_msgaddr0);
1929 if (arcmsr_hba_wait_msgint_ready(acb)) {
1930 printk(KERN_NOTICE "arcmsr%d: ""set ccb high \
1931 part physical address timeout\n",
1932 acb->host->host_no);
1933 return 1;
1317 } 1934 }
1935 arcmsr_enable_outbound_ints(acb, intmask_org);
1936 }
1937 }
1938 break;
1318 1939
1319 id = ccb->pcmd->device->id; 1940 case ACB_ADAPTER_TYPE_B: {
1320 lun = ccb->pcmd->device->lun; 1941 unsigned long post_queue_phyaddr;
1321 if (!(flag_ccb & ARCMSR_CCBREPLY_FLAG_ERROR)){ 1942 uint32_t *rwbuffer;
1322 if (acb->devstate[id][lun] == ARECA_RAID_GONE)
1323 acb->devstate[id][lun] = ARECA_RAID_GOOD;
1324 ccb->pcmd->result = DID_OK << 16;
1325 arcmsr_ccb_complete(ccb, 1);
1326 }
1327 else {
1328 switch(ccb->arcmsr_cdb.DeviceStatus) {
1329 case ARCMSR_DEV_SELECT_TIMEOUT: {
1330 acb->devstate[id][lun] = ARECA_RAID_GONE;
1331 ccb->pcmd->result = DID_NO_CONNECT << 16;
1332 arcmsr_ccb_complete(ccb, 1);
1333 }
1334 break;
1335 1943
1336 case ARCMSR_DEV_ABORTED: 1944 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
1945 uint32_t intmask_org;
1946 intmask_org = arcmsr_disable_outbound_ints(acb);
1947 reg->postq_index = 0;
1948 reg->doneq_index = 0;
1949 writel(ARCMSR_MESSAGE_SET_POST_WINDOW, reg->drv2iop_doorbell_reg);
1950 if (arcmsr_hbb_wait_msgint_ready(acb)) {
1951 printk(KERN_NOTICE "arcmsr%d:can not set diver mode\n", \
1952 acb->host->host_no);
1953 return 1;
1954 }
1955 post_queue_phyaddr = cdb_phyaddr + ARCMSR_MAX_FREECCB_NUM * \
1956 sizeof(struct CommandControlBlock) + offsetof(struct MessageUnit_B, post_qbuffer) ;
1957 rwbuffer = reg->msgcode_rwbuffer_reg;
1958 /* driver "set config" signature */
1959 writel(ARCMSR_SIGNATURE_SET_CONFIG, rwbuffer++);
1960 /* normal should be zero */
1961 writel(ccb_phyaddr_hi32, rwbuffer++);
1962 /* postQ size (256 + 8)*4 */
1963 writel(post_queue_phyaddr, rwbuffer++);
1964 /* doneQ size (256 + 8)*4 */
1965 writel(post_queue_phyaddr + 1056, rwbuffer++);
1966 /* ccb maxQ size must be --> [(256 + 8)*4]*/
1967 writel(1056, rwbuffer);
1968
1969 writel(ARCMSR_MESSAGE_SET_CONFIG, reg->drv2iop_doorbell_reg);
1970 if (arcmsr_hbb_wait_msgint_ready(acb)) {
1971 printk(KERN_NOTICE "arcmsr%d: 'set command Q window' \
1972 timeout \n",acb->host->host_no);
1973 return 1;
1974 }
1337 1975
1338 case ARCMSR_DEV_INIT_FAIL: { 1976 writel(ARCMSR_MESSAGE_START_DRIVER_MODE, reg->drv2iop_doorbell_reg);
1339 acb->devstate[id][lun] = 1977 if (arcmsr_hbb_wait_msgint_ready(acb)) {
1340 ARECA_RAID_GONE; 1978 printk(KERN_NOTICE "arcmsr%d: 'can not set diver mode \n"\
1341 ccb->pcmd->result = 1979 ,acb->host->host_no);
1342 DID_BAD_TARGET << 16; 1980 return 1;
1343 arcmsr_ccb_complete(ccb, 1); 1981 }
1344 } 1982 arcmsr_enable_outbound_ints(acb, intmask_org);
1345 break; 1983 }
1984 break;
1985 }
1986 return 0;
1987}
1346 1988
1347 case ARCMSR_DEV_CHECK_CONDITION: { 1989static void arcmsr_wait_firmware_ready(struct AdapterControlBlock *acb)
1348 acb->devstate[id][lun] = 1990{
1349 ARECA_RAID_GOOD; 1991 uint32_t firmware_state = 0;
1350 arcmsr_report_sense_info(ccb);
1351 arcmsr_ccb_complete(ccb, 1);
1352 }
1353 break;
1354 1992
1355 default: 1993 switch (acb->adapter_type) {
1356 printk(KERN_NOTICE 1994
1357 "arcmsr%d: scsi id = %d \ 1995 case ACB_ADAPTER_TYPE_A: {
1358 lun = %d""polling and \ 1996 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
1359 getting command error \ 1997 do {
1360 done""but got unknown \ 1998 firmware_state = readl(&reg->outbound_msgaddr1);
1361 DeviceStatus = 0x%x \n", 1999 } while ((firmware_state & ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK) == 0);
1362 acb->host->host_no, id, 2000 }
1363 lun, ccb->arcmsr_cdb.DeviceStatus); 2001 break;
1364 acb->devstate[id][lun] = 2002
1365 ARECA_RAID_GONE; 2003 case ACB_ADAPTER_TYPE_B: {
1366 ccb->pcmd->result = 2004 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
1367 DID_BAD_TARGET << 16; 2005 do {
1368 arcmsr_ccb_complete(ccb, 1); 2006 firmware_state = readl(reg->iop2drv_doorbell_reg);
1369 break; 2007 } while ((firmware_state & ARCMSR_MESSAGE_FIRMWARE_OK) == 0);
1370 } 2008 }
1371 } 2009 break;
1372 found = 1;
1373 }
1374 } 2010 }
1375 if (found){ 2011}
1376 outbound_intstatus = readl(&reg->outbound_intstatus) & \ 2012
1377 acb->outbound_int_enable; 2013static void arcmsr_start_hba_bgrb(struct AdapterControlBlock *acb)
1378 writel(outbound_intstatus, &reg->outbound_intstatus); 2014{
1379 /*clear interrupt*/ 2015 struct MessageUnit_A __iomem *reg = (struct MessageUnit_A *)acb->pmu;
2016 acb->acb_flags |= ACB_F_MSG_START_BGRB;
2017 writel(ARCMSR_INBOUND_MESG0_START_BGRB, &reg->inbound_msgaddr0);
2018 if (arcmsr_hba_wait_msgint_ready(acb)) {
2019 printk(KERN_NOTICE "arcmsr%d: wait 'start adapter background \
2020 rebulid' timeout \n", acb->host->host_no);
1380 } 2021 }
1381 return;
1382} 2022}
1383 2023
2024static void arcmsr_start_hbb_bgrb(struct AdapterControlBlock *acb)
2025{
2026 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
2027 acb->acb_flags |= ACB_F_MSG_START_BGRB;
2028 writel(ARCMSR_MESSAGE_START_BGRB, reg->drv2iop_doorbell_reg);
2029 if (arcmsr_hbb_wait_msgint_ready(acb)) {
2030 printk(KERN_NOTICE "arcmsr%d: wait 'start adapter background \
2031 rebulid' timeout \n",acb->host->host_no);
2032 }
2033}
1384 2034
1385static void arcmsr_iop_init(struct AdapterControlBlock *acb) 2035static void arcmsr_start_adapter_bgrb(struct AdapterControlBlock *acb)
1386{ 2036{
1387 struct MessageUnit __iomem *reg = acb->pmu; 2037 switch (acb->adapter_type) {
1388 uint32_t intmask_org, mask, outbound_doorbell, firmware_state = 0; 2038 case ACB_ADAPTER_TYPE_A:
2039 arcmsr_start_hba_bgrb(acb);
2040 break;
2041 case ACB_ADAPTER_TYPE_B:
2042 arcmsr_start_hbb_bgrb(acb);
2043 break;
2044 }
2045}
1389 2046
1390 do { 2047static void arcmsr_clear_doorbell_queue_buffer(struct AdapterControlBlock *acb)
1391 firmware_state = readl(&reg->outbound_msgaddr1); 2048{
1392 } while (!(firmware_state & ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK)); 2049 switch (acb->adapter_type) {
1393 intmask_org = readl(&reg->outbound_intmask) 2050 case ACB_ADAPTER_TYPE_A: {
1394 | ARCMSR_MU_OUTBOUND_MESSAGE0_INTMASKENABLE; 2051 struct MessageUnit_A *reg = (struct MessageUnit_A *)acb->pmu;
1395 arcmsr_get_firmware_spec(acb); 2052 uint32_t outbound_doorbell;
2053 /* empty doorbell Qbuffer if door bell ringed */
2054 outbound_doorbell = readl(&reg->outbound_doorbell);
2055 /*clear doorbell interrupt */
2056 writel(outbound_doorbell, &reg->outbound_doorbell);
2057 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK, &reg->inbound_doorbell);
2058 }
2059 break;
1396 2060
1397 acb->acb_flags |= ACB_F_MSG_START_BGRB; 2061 case ACB_ADAPTER_TYPE_B: {
1398 writel(ARCMSR_INBOUND_MESG0_START_BGRB, &reg->inbound_msgaddr0); 2062 struct MessageUnit_B *reg = (struct MessageUnit_B *)acb->pmu;
1399 if (arcmsr_wait_msgint_ready(acb)) { 2063 /*clear interrupt and message state*/
1400 printk(KERN_NOTICE "arcmsr%d: " 2064 writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN, reg->iop2drv_doorbell_reg);
1401 "wait 'start adapter background rebulid' timeout\n", 2065 writel(ARCMSR_DRV2IOP_DATA_READ_OK, reg->drv2iop_doorbell_reg);
1402 acb->host->host_no); 2066 /* let IOP know data has been read */
2067 }
2068 break;
1403 } 2069 }
2070}
1404 2071
1405 outbound_doorbell = readl(&reg->outbound_doorbell); 2072static void arcmsr_iop_init(struct AdapterControlBlock *acb)
1406 writel(outbound_doorbell, &reg->outbound_doorbell); 2073{
1407 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK, &reg->inbound_doorbell); 2074 uint32_t intmask_org;
1408 mask = ~(ARCMSR_MU_OUTBOUND_POSTQUEUE_INTMASKENABLE 2075
1409 | ARCMSR_MU_OUTBOUND_DOORBELL_INTMASKENABLE); 2076 arcmsr_wait_firmware_ready(acb);
1410 writel(intmask_org & mask, &reg->outbound_intmask); 2077 arcmsr_iop_confirm(acb);
1411 acb->outbound_int_enable = ~(intmask_org & mask) & 0x000000ff; 2078 /* disable all outbound interrupt */
2079 intmask_org = arcmsr_disable_outbound_ints(acb);
2080 arcmsr_get_firmware_spec(acb);
2081 /*start background rebuild*/
2082 arcmsr_start_adapter_bgrb(acb);
2083 /* empty doorbell Qbuffer if door bell ringed */
2084 arcmsr_clear_doorbell_queue_buffer(acb);
2085 /* enable outbound Post Queue,outbound doorbell Interrupt */
2086 arcmsr_enable_outbound_ints(acb, intmask_org);
1412 acb->acb_flags |= ACB_F_IOP_INITED; 2087 acb->acb_flags |= ACB_F_IOP_INITED;
1413} 2088}
1414 2089
@@ -1421,22 +2096,24 @@ static void arcmsr_iop_reset(struct AdapterControlBlock *acb)
1421 if (atomic_read(&acb->ccboutstandingcount) != 0) { 2096 if (atomic_read(&acb->ccboutstandingcount) != 0) {
1422 /* talk to iop 331 outstanding command aborted */ 2097 /* talk to iop 331 outstanding command aborted */
1423 arcmsr_abort_allcmd(acb); 2098 arcmsr_abort_allcmd(acb);
2099
1424 /* wait for 3 sec for all command aborted*/ 2100 /* wait for 3 sec for all command aborted*/
1425 msleep_interruptible(3000); 2101 ssleep(3);
2102
1426 /* disable all outbound interrupt */ 2103 /* disable all outbound interrupt */
1427 intmask_org = arcmsr_disable_outbound_ints(acb); 2104 intmask_org = arcmsr_disable_outbound_ints(acb);
1428 /* clear all outbound posted Q */ 2105 /* clear all outbound posted Q */
1429 arcmsr_done4_abort_postqueue(acb); 2106 arcmsr_done4abort_postqueue(acb);
1430 for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) { 2107 for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) {
1431 ccb = acb->pccb_pool[i]; 2108 ccb = acb->pccb_pool[i];
1432 if (ccb->startdone == ARCMSR_CCB_START) { 2109 if (ccb->startdone == ARCMSR_CCB_START) {
1433 ccb->startdone = ARCMSR_CCB_ABORTED; 2110 ccb->startdone = ARCMSR_CCB_ABORTED;
2111 arcmsr_ccb_complete(ccb, 1);
1434 } 2112 }
1435 } 2113 }
1436 /* enable all outbound interrupt */ 2114 /* enable all outbound interrupt */
1437 arcmsr_enable_outbound_ints(acb, intmask_org); 2115 arcmsr_enable_outbound_ints(acb, intmask_org);
1438 } 2116 }
1439
1440} 2117}
1441 2118
1442static int arcmsr_bus_reset(struct scsi_cmnd *cmd) 2119static int arcmsr_bus_reset(struct scsi_cmnd *cmd)
@@ -1450,7 +2127,7 @@ static int arcmsr_bus_reset(struct scsi_cmnd *cmd)
1450 for (i = 0; i < 400; i++) { 2127 for (i = 0; i < 400; i++) {
1451 if (!atomic_read(&acb->ccboutstandingcount)) 2128 if (!atomic_read(&acb->ccboutstandingcount))
1452 break; 2129 break;
1453 arcmsr_interrupt(acb); 2130 arcmsr_interrupt(acb);/* FIXME: need spinlock */
1454 msleep(25); 2131 msleep(25);
1455 } 2132 }
1456 arcmsr_iop_reset(acb); 2133 arcmsr_iop_reset(acb);
@@ -1468,7 +2145,7 @@ static void arcmsr_abort_one_cmd(struct AdapterControlBlock *acb,
1468 /* 2145 /*
1469 ** Wait for 3 sec for all command done. 2146 ** Wait for 3 sec for all command done.
1470 */ 2147 */
1471 msleep_interruptible(3000); 2148 ssleep(3);
1472 2149
1473 intmask = arcmsr_disable_outbound_ints(acb); 2150 intmask = arcmsr_disable_outbound_ints(acb);
1474 arcmsr_polling_ccbdone(acb, ccb); 2151 arcmsr_polling_ccbdone(acb, ccb);
@@ -1515,6 +2192,8 @@ static const char *arcmsr_info(struct Scsi_Host *host)
1515 2192
1516 switch (acb->pdev->device) { 2193 switch (acb->pdev->device) {
1517 case PCI_DEVICE_ID_ARECA_1110: 2194 case PCI_DEVICE_ID_ARECA_1110:
2195 case PCI_DEVICE_ID_ARECA_1200:
2196 case PCI_DEVICE_ID_ARECA_1202:
1518 case PCI_DEVICE_ID_ARECA_1210: 2197 case PCI_DEVICE_ID_ARECA_1210:
1519 raid6 = 0; 2198 raid6 = 0;
1520 /*FALLTHRU*/ 2199 /*FALLTHRU*/
@@ -1522,6 +2201,7 @@ static const char *arcmsr_info(struct Scsi_Host *host)
1522 case PCI_DEVICE_ID_ARECA_1130: 2201 case PCI_DEVICE_ID_ARECA_1130:
1523 case PCI_DEVICE_ID_ARECA_1160: 2202 case PCI_DEVICE_ID_ARECA_1160:
1524 case PCI_DEVICE_ID_ARECA_1170: 2203 case PCI_DEVICE_ID_ARECA_1170:
2204 case PCI_DEVICE_ID_ARECA_1201:
1525 case PCI_DEVICE_ID_ARECA_1220: 2205 case PCI_DEVICE_ID_ARECA_1220:
1526 case PCI_DEVICE_ID_ARECA_1230: 2206 case PCI_DEVICE_ID_ARECA_1230:
1527 case PCI_DEVICE_ID_ARECA_1260: 2207 case PCI_DEVICE_ID_ARECA_1260:
@@ -1544,287 +2224,82 @@ static const char *arcmsr_info(struct Scsi_Host *host)
1544 ARCMSR_DRIVER_VERSION); 2224 ARCMSR_DRIVER_VERSION);
1545 return buf; 2225 return buf;
1546} 2226}
1547 2227#ifdef CONFIG_SCSI_ARCMSR_AER
1548static pci_ers_result_t arcmsr_pci_slot_reset(struct pci_dev *pdev) 2228static pci_ers_result_t arcmsr_pci_slot_reset(struct pci_dev *pdev)
1549{ 2229{
1550 struct Scsi_Host *host; 2230 struct Scsi_Host *host = pci_get_drvdata(pdev);
1551 struct AdapterControlBlock *acb; 2231 struct AdapterControlBlock *acb =
1552 uint8_t bus, dev_fun; 2232 (struct AdapterControlBlock *) host->hostdata;
1553 int error; 2233 uint32_t intmask_org;
1554 2234 int i, j;
1555 error = pci_enable_device(pdev);
1556 if (error)
1557 return PCI_ERS_RESULT_DISCONNECT;
1558 pci_set_master(pdev);
1559
1560 host = scsi_host_alloc(&arcmsr_scsi_host_template, sizeof \
1561(struct AdapterControlBlock));
1562 if (!host)
1563 return PCI_ERS_RESULT_DISCONNECT;
1564 acb = (struct AdapterControlBlock *)host->hostdata;
1565 memset(acb, 0, sizeof (struct AdapterControlBlock));
1566
1567 error = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
1568 if (error) {
1569 error = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
1570 if (error) {
1571 printk(KERN_WARNING
1572 "scsi%d: No suitable DMA mask available\n",
1573 host->host_no);
1574 return PCI_ERS_RESULT_DISCONNECT;
1575 }
1576 }
1577 bus = pdev->bus->number;
1578 dev_fun = pdev->devfn;
1579 acb = (struct AdapterControlBlock *) host->hostdata;
1580 memset(acb, 0, sizeof(struct AdapterControlBlock));
1581 acb->pdev = pdev;
1582 acb->host = host;
1583 host->max_sectors = ARCMSR_MAX_XFER_SECTORS;
1584 host->max_lun = ARCMSR_MAX_TARGETLUN;
1585 host->max_id = ARCMSR_MAX_TARGETID;/*16:8*/
1586 host->max_cmd_len = 16; /*this is issue of 64bit LBA, over 2T byte*/
1587 host->sg_tablesize = ARCMSR_MAX_SG_ENTRIES;
1588 host->can_queue = ARCMSR_MAX_FREECCB_NUM; /* max simultaneous cmds */
1589 host->cmd_per_lun = ARCMSR_MAX_CMD_PERLUN;
1590 host->this_id = ARCMSR_SCSI_INITIATOR_ID;
1591 host->unique_id = (bus << 8) | dev_fun;
1592 host->irq = pdev->irq;
1593 error = pci_request_regions(pdev, "arcmsr");
1594 if (error)
1595 return PCI_ERS_RESULT_DISCONNECT;
1596 2235
1597 acb->pmu = ioremap(pci_resource_start(pdev, 0), 2236 if (pci_enable_device(pdev)) {
1598 pci_resource_len(pdev, 0));
1599 if (!acb->pmu) {
1600 printk(KERN_NOTICE "arcmsr%d: memory"
1601 " mapping region fail \n", acb->host->host_no);
1602 return PCI_ERS_RESULT_DISCONNECT; 2237 return PCI_ERS_RESULT_DISCONNECT;
1603 } 2238 }
2239 pci_set_master(pdev);
2240 intmask_org = arcmsr_disable_outbound_ints(acb);
1604 acb->acb_flags |= (ACB_F_MESSAGE_WQBUFFER_CLEARED | 2241 acb->acb_flags |= (ACB_F_MESSAGE_WQBUFFER_CLEARED |
1605 ACB_F_MESSAGE_RQBUFFER_CLEARED | 2242 ACB_F_MESSAGE_RQBUFFER_CLEARED |
1606 ACB_F_MESSAGE_WQBUFFER_READED); 2243 ACB_F_MESSAGE_WQBUFFER_READED);
1607 acb->acb_flags &= ~ACB_F_SCSISTOPADAPTER; 2244 acb->acb_flags &= ~ACB_F_SCSISTOPADAPTER;
1608 INIT_LIST_HEAD(&acb->ccb_free_list); 2245 for (i = 0; i < ARCMSR_MAX_TARGETID; i++)
1609 2246 for (j = 0; j < ARCMSR_MAX_TARGETLUN; j++)
1610 error = arcmsr_alloc_ccb_pool(acb); 2247 acb->devstate[i][j] = ARECA_RAID_GONE;
1611 if (error)
1612 return PCI_ERS_RESULT_DISCONNECT;
1613
1614 error = request_irq(pdev->irq, arcmsr_do_interrupt,
1615 IRQF_DISABLED | IRQF_SHARED, "arcmsr", acb);
1616 if (error)
1617 return PCI_ERS_RESULT_DISCONNECT;
1618
1619 arcmsr_iop_init(acb);
1620 if (strncmp(acb->firm_version, "V1.42", 5) >= 0)
1621 host->max_sectors = ARCMSR_MAX_XFER_SECTORS_B;
1622
1623 pci_set_drvdata(pdev, host);
1624
1625 error = scsi_add_host(host, &pdev->dev);
1626 if (error)
1627 return PCI_ERS_RESULT_DISCONNECT;
1628 2248
1629 error = arcmsr_alloc_sysfs_attr(acb); 2249 arcmsr_wait_firmware_ready(acb);
1630 if (error) 2250 arcmsr_iop_confirm(acb);
1631 return PCI_ERS_RESULT_DISCONNECT; 2251 /* disable all outbound interrupt */
2252 arcmsr_get_firmware_spec(acb);
2253 /*start background rebuild*/
2254 arcmsr_start_adapter_bgrb(acb);
2255 /* empty doorbell Qbuffer if door bell ringed */
2256 arcmsr_clear_doorbell_queue_buffer(acb);
2257 /* enable outbound Post Queue,outbound doorbell Interrupt */
2258 arcmsr_enable_outbound_ints(acb, intmask_org);
2259 acb->acb_flags |= ACB_F_IOP_INITED;
1632 2260
1633 scsi_scan_host(host); 2261 pci_enable_pcie_error_reporting(pdev);
1634 return PCI_ERS_RESULT_RECOVERED; 2262 return PCI_ERS_RESULT_RECOVERED;
1635} 2263}
1636 2264
1637static void arcmsr_pci_ers_need_reset_forepart(struct pci_dev *pdev) 2265static void arcmsr_pci_ers_need_reset_forepart(struct pci_dev *pdev)
1638{ 2266{
1639 struct Scsi_Host *host = pci_get_drvdata(pdev); 2267 struct Scsi_Host *host = pci_get_drvdata(pdev);
1640 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; 2268 struct AdapterControlBlock *acb = (struct AdapterControlBlock *)host->hostdata;
1641 struct MessageUnit __iomem *reg = acb->pmu;
1642 struct CommandControlBlock *ccb; 2269 struct CommandControlBlock *ccb;
1643 /*clear and abort all outbound posted Q*/ 2270 uint32_t intmask_org;
1644 int i = 0, found = 0; 2271 int i = 0;
1645 int id, lun;
1646 uint32_t flag_ccb, outbound_intstatus;
1647
1648 while (((flag_ccb = readl(&reg->outbound_queueport)) != 0xFFFFFFFF) &&
1649 (i++ < 256)){
1650 ccb = (struct CommandControlBlock *)(acb->vir2phy_offset
1651 + (flag_ccb << 5));
1652 if (ccb){
1653 if ((ccb->acb != acb)||(ccb->startdone !=
1654 ARCMSR_CCB_START)){
1655 printk(KERN_NOTICE "arcmsr%d: polling \
1656 get an illegal ccb"" command done ccb = '0x%p'"
1657 "ccboutstandingcount = %d \n",
1658 acb->host->host_no, ccb,
1659 atomic_read(&acb->ccboutstandingcount));
1660 continue;
1661 }
1662
1663 id = ccb->pcmd->device->id;
1664 lun = ccb->pcmd->device->lun;
1665 if (!(flag_ccb & ARCMSR_CCBREPLY_FLAG_ERROR)) {
1666 if (acb->devstate[id][lun] ==
1667 ARECA_RAID_GONE)
1668 acb->devstate[id][lun] =
1669 ARECA_RAID_GOOD;
1670 ccb->pcmd->result = DID_OK << 16;
1671 arcmsr_ccb_complete(ccb, 1);
1672 }
1673 else {
1674 switch(ccb->arcmsr_cdb.DeviceStatus) {
1675 case ARCMSR_DEV_SELECT_TIMEOUT: {
1676 acb->devstate[id][lun] =
1677 ARECA_RAID_GONE;
1678 ccb->pcmd->result =
1679 DID_NO_CONNECT << 16;
1680 arcmsr_ccb_complete(ccb, 1);
1681 }
1682 break;
1683
1684 case ARCMSR_DEV_ABORTED:
1685
1686 case ARCMSR_DEV_INIT_FAIL: {
1687 acb->devstate[id][lun] =
1688 ARECA_RAID_GONE;
1689 ccb->pcmd->result =
1690 DID_BAD_TARGET << 16;
1691 arcmsr_ccb_complete(ccb, 1);
1692 }
1693 break;
1694
1695 case ARCMSR_DEV_CHECK_CONDITION: {
1696 acb->devstate[id][lun] =
1697 ARECA_RAID_GOOD;
1698 arcmsr_report_sense_info(ccb);
1699 arcmsr_ccb_complete(ccb, 1);
1700 }
1701 break;
1702 2272
1703 default: 2273 if (atomic_read(&acb->ccboutstandingcount) != 0) {
1704 printk(KERN_NOTICE 2274 /* talk to iop 331 outstanding command aborted */
1705 "arcmsr%d: scsi \ 2275 arcmsr_abort_allcmd(acb);
1706 id = %d lun = %d" 2276 /* wait for 3 sec for all command aborted*/
1707 " polling and \ 2277 ssleep(3);
1708 getting command \ 2278 /* disable all outbound interrupt */
1709 error done" 2279 intmask_org = arcmsr_disable_outbound_ints(acb);
1710 "but got unknown \ 2280 /* clear all outbound posted Q */
1711 DeviceStatus = 0x%x \n" 2281 arcmsr_done4abort_postqueue(acb);
1712 , acb->host->host_no, 2282 for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) {
1713 id, lun, 2283 ccb = acb->pccb_pool[i];
1714 ccb->arcmsr_cdb.DeviceStatus); 2284 if (ccb->startdone == ARCMSR_CCB_START) {
1715 acb->devstate[id][lun] = 2285 ccb->startdone = ARCMSR_CCB_ABORTED;
1716 ARECA_RAID_GONE; 2286 arcmsr_ccb_complete(ccb, 1);
1717 ccb->pcmd->result =
1718 DID_BAD_TARGET << 16;
1719 arcmsr_ccb_complete(ccb, 1);
1720 break;
1721 }
1722 }
1723 found = 1;
1724 } 2287 }
1725 } 2288 }
1726 if (found){ 2289 /* enable all outbound interrupt */
1727 outbound_intstatus = readl(&reg->outbound_intstatus) & 2290 arcmsr_enable_outbound_ints(acb, intmask_org);
1728 acb->outbound_int_enable; 2291 }
1729 writel(outbound_intstatus, &reg->outbound_intstatus); 2292 pci_disable_device(pdev);
1730 /*clear interrupt*/
1731 }
1732 return;
1733} 2293}
1734 2294
1735
1736static void arcmsr_pci_ers_disconnect_forepart(struct pci_dev *pdev) 2295static void arcmsr_pci_ers_disconnect_forepart(struct pci_dev *pdev)
1737{ 2296{
1738 struct Scsi_Host *host = pci_get_drvdata(pdev); 2297 struct Scsi_Host *host = pci_get_drvdata(pdev);
1739 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; 2298 struct AdapterControlBlock *acb = \
1740 struct MessageUnit __iomem *reg = acb->pmu; 2299 (struct AdapterControlBlock *)host->hostdata;
1741 struct CommandControlBlock *ccb;
1742 /*clear and abort all outbound posted Q*/
1743 int i = 0, found = 0;
1744 int id, lun;
1745 uint32_t flag_ccb, outbound_intstatus;
1746
1747 while (((flag_ccb = readl(&reg->outbound_queueport)) != 0xFFFFFFFF) &&
1748 (i++ < 256)){
1749 ccb = (struct CommandControlBlock *)(acb->vir2phy_offset +
1750 (flag_ccb << 5));
1751 if (ccb){
1752 if ((ccb->acb != acb)||(ccb->startdone !=
1753 ARCMSR_CCB_START)){
1754 printk(KERN_NOTICE
1755 "arcmsr%d: polling get an illegal ccb"
1756 " command done ccb = '0x%p'"
1757 "ccboutstandingcount = %d \n",
1758 acb->host->host_no, ccb,
1759 atomic_read(&acb->ccboutstandingcount));
1760 continue;
1761 }
1762
1763 id = ccb->pcmd->device->id;
1764 lun = ccb->pcmd->device->lun;
1765 if (!(flag_ccb & ARCMSR_CCBREPLY_FLAG_ERROR)) {
1766 if (acb->devstate[id][lun] == ARECA_RAID_GONE)
1767 acb->devstate[id][lun] = ARECA_RAID_GOOD;
1768 ccb->pcmd->result = DID_OK << 16;
1769 arcmsr_ccb_complete(ccb, 1);
1770 }
1771 else {
1772 switch(ccb->arcmsr_cdb.DeviceStatus) {
1773 case ARCMSR_DEV_SELECT_TIMEOUT: {
1774 acb->devstate[id][lun] =
1775 ARECA_RAID_GONE;
1776 ccb->pcmd->result =
1777 DID_NO_CONNECT << 16;
1778 arcmsr_ccb_complete(ccb, 1);
1779 }
1780 break;
1781
1782 case ARCMSR_DEV_ABORTED:
1783
1784 case ARCMSR_DEV_INIT_FAIL: {
1785 acb->devstate[id][lun] =
1786 ARECA_RAID_GONE;
1787 ccb->pcmd->result =
1788 DID_BAD_TARGET << 16;
1789 arcmsr_ccb_complete(ccb, 1);
1790 }
1791 break;
1792 2300
1793 case ARCMSR_DEV_CHECK_CONDITION: { 2301 arcmsr_stop_adapter_bgrb(acb);
1794 acb->devstate[id][lun] = 2302 arcmsr_flush_adapter_cache(acb);
1795 ARECA_RAID_GOOD;
1796 arcmsr_report_sense_info(ccb);
1797 arcmsr_ccb_complete(ccb, 1);
1798 }
1799 break;
1800
1801 default:
1802 printk(KERN_NOTICE "arcmsr%d: \
1803 scsi id = %d lun = %d"
1804 " polling and \
1805 getting command error done"
1806 "but got unknown \
1807 DeviceStatus = 0x%x \n"
1808 , acb->host->host_no,
1809 id, lun, ccb->arcmsr_cdb.DeviceStatus);
1810 acb->devstate[id][lun] =
1811 ARECA_RAID_GONE;
1812 ccb->pcmd->result =
1813 DID_BAD_TARGET << 16;
1814 arcmsr_ccb_complete(ccb, 1);
1815 break;
1816 }
1817 }
1818 found = 1;
1819 }
1820 }
1821 if (found){
1822 outbound_intstatus = readl(&reg->outbound_intstatus) &
1823 acb->outbound_int_enable;
1824 writel(outbound_intstatus, &reg->outbound_intstatus);
1825 /*clear interrupt*/
1826 }
1827 return;
1828} 2303}
1829 2304
1830static pci_ers_result_t arcmsr_pci_error_detected(struct pci_dev *pdev, 2305static pci_ers_result_t arcmsr_pci_error_detected(struct pci_dev *pdev,
@@ -1840,5 +2315,6 @@ static pci_ers_result_t arcmsr_pci_error_detected(struct pci_dev *pdev,
1840 break; 2315 break;
1841 default: 2316 default:
1842 return PCI_ERS_RESULT_NEED_RESET; 2317 return PCI_ERS_RESULT_NEED_RESET;
1843 } 2318 }
1844} 2319}
2320#endif