2 *******************************************************************************
4 ** FILE NAME : arcmsr_hba.c
6 ** Description: SCSI RAID Device Driver for
7 ** ARECA RAID Host adapter
8 *******************************************************************************
9 ** Copyright (C) 2002 - 2005, Areca Technology Corporation All rights reserved
11 ** Web site: www.areca.com.tw
12 ** E-mail: support@areca.com.tw
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License version 2 as
16 ** published by the Free Software Foundation.
17 ** This program is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ** GNU General Public License for more details.
21 *******************************************************************************
22 ** Redistribution and use in source and binary forms, with or without
23 ** modification, are permitted provided that the following conditions
25 ** 1. Redistributions of source code must retain the above copyright
26 ** notice, this list of conditions and the following disclaimer.
27 ** 2. Redistributions in binary form must reproduce the above copyright
28 ** notice, this list of conditions and the following disclaimer in the
29 ** documentation and/or other materials provided with the distribution.
30 ** 3. The name of the author may not be used to endorse or promote products
31 ** derived from this software without specific prior written permission.
33 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
34 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
36 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
37 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING,BUT
38 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION)HOWEVER CAUSED AND ON ANY
40 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41 ** (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF
42 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 *******************************************************************************
44 ** For history of changes, see Documentation/scsi/ChangeLog.arcmsr
45 ** Firmware Specification, see Documentation/scsi/arcmsr_spec.txt
46 *******************************************************************************
48 #include <linux/module.h>
49 #include <linux/reboot.h>
50 #include <linux/spinlock.h>
51 #include <linux/pci_ids.h>
52 #include <linux/interrupt.h>
53 #include <linux/moduleparam.h>
54 #include <linux/errno.h>
55 #include <linux/types.h>
56 #include <linux/delay.h>
57 #include <linux/dma-mapping.h>
58 #include <linux/timer.h>
59 #include <linux/pci.h>
60 #include <linux/aer.h>
63 #include <asm/system.h>
64 #include <asm/uaccess.h>
65 #include <scsi/scsi_host.h>
66 #include <scsi/scsi.h>
67 #include <scsi/scsi_cmnd.h>
68 #include <scsi/scsi_tcq.h>
69 #include <scsi/scsi_device.h>
70 #include <scsi/scsi_transport.h>
71 #include <scsi/scsicam.h>
74 MODULE_AUTHOR("Erich Chen <support@areca.com.tw>");
75 MODULE_DESCRIPTION("ARECA (ARC11xx/12xx/13xx/16xx) SATA/SAS RAID HOST Adapter");
76 MODULE_LICENSE("Dual BSD/GPL");
77 MODULE_VERSION(ARCMSR_DRIVER_VERSION
);
79 static int arcmsr_iop_message_xfer(struct AdapterControlBlock
*acb
,
80 struct scsi_cmnd
*cmd
);
81 static int arcmsr_iop_confirm(struct AdapterControlBlock
*acb
);
82 static int arcmsr_abort(struct scsi_cmnd
*);
83 static int arcmsr_bus_reset(struct scsi_cmnd
*);
84 static int arcmsr_bios_param(struct scsi_device
*sdev
,
85 struct block_device
*bdev
, sector_t capacity
, int *info
);
86 static int arcmsr_queue_command(struct scsi_cmnd
*cmd
,
87 void (*done
) (struct scsi_cmnd
*));
88 static int arcmsr_probe(struct pci_dev
*pdev
,
89 const struct pci_device_id
*id
);
90 static void arcmsr_remove(struct pci_dev
*pdev
);
91 static void arcmsr_shutdown(struct pci_dev
*pdev
);
92 static void arcmsr_iop_init(struct AdapterControlBlock
*acb
);
93 static void arcmsr_free_ccb_pool(struct AdapterControlBlock
*acb
);
94 static u32
arcmsr_disable_outbound_ints(struct AdapterControlBlock
*acb
);
95 static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock
*acb
);
96 static void arcmsr_flush_hba_cache(struct AdapterControlBlock
*acb
);
97 static void arcmsr_flush_hbb_cache(struct AdapterControlBlock
*acb
);
98 static const char *arcmsr_info(struct Scsi_Host
*);
99 static irqreturn_t
arcmsr_interrupt(struct AdapterControlBlock
*acb
);
100 static int arcmsr_adjust_disk_queue_depth(struct scsi_device
*sdev
,
103 if (queue_depth
> ARCMSR_MAX_CMD_PERLUN
)
104 queue_depth
= ARCMSR_MAX_CMD_PERLUN
;
105 scsi_adjust_queue_depth(sdev
, MSG_ORDERED_TAG
, queue_depth
);
109 static struct scsi_host_template arcmsr_scsi_host_template
= {
110 .module
= THIS_MODULE
,
111 .name
= "ARCMSR ARECA SATA/SAS RAID HOST Adapter"
112 ARCMSR_DRIVER_VERSION
,
114 .queuecommand
= arcmsr_queue_command
,
115 .eh_abort_handler
= arcmsr_abort
,
116 .eh_bus_reset_handler
= arcmsr_bus_reset
,
117 .bios_param
= arcmsr_bios_param
,
118 .change_queue_depth
= arcmsr_adjust_disk_queue_depth
,
119 .can_queue
= ARCMSR_MAX_OUTSTANDING_CMD
,
120 .this_id
= ARCMSR_SCSI_INITIATOR_ID
,
121 .sg_tablesize
= ARCMSR_MAX_SG_ENTRIES
,
122 .max_sectors
= ARCMSR_MAX_XFER_SECTORS
,
123 .cmd_per_lun
= ARCMSR_MAX_CMD_PERLUN
,
124 .use_clustering
= ENABLE_CLUSTERING
,
125 .shost_attrs
= arcmsr_host_attrs
,
127 #ifdef CONFIG_SCSI_ARCMSR_AER
128 static pci_ers_result_t
arcmsr_pci_slot_reset(struct pci_dev
*pdev
);
129 static pci_ers_result_t
arcmsr_pci_error_detected(struct pci_dev
*pdev
,
130 pci_channel_state_t state
);
132 static struct pci_error_handlers arcmsr_pci_error_handlers
= {
133 .error_detected
= arcmsr_pci_error_detected
,
134 .slot_reset
= arcmsr_pci_slot_reset
,
137 static struct pci_device_id arcmsr_device_id_table
[] = {
138 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1110
)},
139 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1120
)},
140 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1130
)},
141 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1160
)},
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
)},
146 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1210
)},
147 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1220
)},
148 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1230
)},
149 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1260
)},
150 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1270
)},
151 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1280
)},
152 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1380
)},
153 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1381
)},
154 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1680
)},
155 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1681
)},
156 {0, 0}, /* Terminating entry */
158 MODULE_DEVICE_TABLE(pci
, arcmsr_device_id_table
);
159 static struct pci_driver arcmsr_pci_driver
= {
161 .id_table
= arcmsr_device_id_table
,
162 .probe
= arcmsr_probe
,
163 .remove
= arcmsr_remove
,
164 .shutdown
= arcmsr_shutdown
,
165 #ifdef CONFIG_SCSI_ARCMSR_AER
166 .err_handler
= &arcmsr_pci_error_handlers
,
170 static irqreturn_t
arcmsr_do_interrupt(int irq
, void *dev_id
)
172 irqreturn_t handle_state
;
173 struct AdapterControlBlock
*acb
= dev_id
;
175 spin_lock(acb
->host
->host_lock
);
176 handle_state
= arcmsr_interrupt(acb
);
177 spin_unlock(acb
->host
->host_lock
);
182 static int arcmsr_bios_param(struct scsi_device
*sdev
,
183 struct block_device
*bdev
, sector_t capacity
, int *geom
)
185 int ret
, heads
, sectors
, cylinders
, total_capacity
;
186 unsigned char *buffer
;/* return copy of block device's partition table */
188 buffer
= scsi_bios_ptable(bdev
);
190 ret
= scsi_partsize(buffer
, capacity
, &geom
[2], &geom
[0], &geom
[1]);
195 total_capacity
= capacity
;
198 cylinders
= total_capacity
/ (heads
* sectors
);
199 if (cylinders
> 1024) {
202 cylinders
= total_capacity
/ (heads
* sectors
);
210 static void arcmsr_define_adapter_type(struct AdapterControlBlock
*acb
)
212 struct pci_dev
*pdev
= acb
->pdev
;
214 pci_read_config_word(pdev
, PCI_DEVICE_ID
, &dev_id
);
217 acb
->adapter_type
= ACB_ADAPTER_TYPE_B
;
221 default : acb
->adapter_type
= ACB_ADAPTER_TYPE_A
;
225 static int arcmsr_alloc_ccb_pool(struct AdapterControlBlock
*acb
)
228 switch (acb
->adapter_type
) {
230 case ACB_ADAPTER_TYPE_A
: {
231 struct pci_dev
*pdev
= acb
->pdev
;
233 dma_addr_t dma_coherent_handle
, dma_addr
;
234 struct CommandControlBlock
*ccb_tmp
;
235 uint32_t intmask_org
;
238 acb
->pmuA
= ioremap(pci_resource_start(pdev
, 0), pci_resource_len(pdev
, 0));
240 printk(KERN_NOTICE
"arcmsr%d: memory mapping region fail \n",
245 dma_coherent
= dma_alloc_coherent(&pdev
->dev
,
246 ARCMSR_MAX_FREECCB_NUM
*
247 sizeof (struct CommandControlBlock
) + 0x20,
248 &dma_coherent_handle
, GFP_KERNEL
);
255 acb
->dma_coherent
= dma_coherent
;
256 acb
->dma_coherent_handle
= dma_coherent_handle
;
258 if (((unsigned long)dma_coherent
& 0x1F)) {
259 dma_coherent
= dma_coherent
+
260 (0x20 - ((unsigned long)dma_coherent
& 0x1F));
261 dma_coherent_handle
= dma_coherent_handle
+
262 (0x20 - ((unsigned long)dma_coherent_handle
& 0x1F));
265 dma_addr
= dma_coherent_handle
;
266 ccb_tmp
= (struct CommandControlBlock
*)dma_coherent
;
267 for (i
= 0; i
< ARCMSR_MAX_FREECCB_NUM
; i
++) {
268 ccb_tmp
->cdb_shifted_phyaddr
= dma_addr
>> 5;
270 acb
->pccb_pool
[i
] = ccb_tmp
;
271 list_add_tail(&ccb_tmp
->list
, &acb
->ccb_free_list
);
272 dma_addr
= dma_addr
+ sizeof(struct CommandControlBlock
);
276 acb
->vir2phy_offset
= (unsigned long)ccb_tmp
-(unsigned long)dma_addr
;
277 for (i
= 0; i
< ARCMSR_MAX_TARGETID
; i
++)
278 for (j
= 0; j
< ARCMSR_MAX_TARGETLUN
; j
++)
279 acb
->devstate
[i
][j
] = ARECA_RAID_GONE
;
282 ** here we need to tell iop 331 our ccb_tmp.HighPart
283 ** if ccb_tmp.HighPart is not zero
285 intmask_org
= arcmsr_disable_outbound_ints(acb
);
289 case ACB_ADAPTER_TYPE_B
: {
291 struct pci_dev
*pdev
= acb
->pdev
;
292 struct MessageUnit_B
*reg
;
293 void __iomem
*mem_base0
, *mem_base1
;
295 dma_addr_t dma_coherent_handle
, dma_addr
;
296 uint32_t intmask_org
;
297 struct CommandControlBlock
*ccb_tmp
;
300 dma_coherent
= dma_alloc_coherent(&pdev
->dev
,
301 ((ARCMSR_MAX_FREECCB_NUM
*
302 sizeof(struct CommandControlBlock
) + 0x20) +
303 sizeof(struct MessageUnit_B
)),
304 &dma_coherent_handle
, GFP_KERNEL
);
308 acb
->dma_coherent
= dma_coherent
;
309 acb
->dma_coherent_handle
= dma_coherent_handle
;
311 if (((unsigned long)dma_coherent
& 0x1F)) {
312 dma_coherent
= dma_coherent
+
313 (0x20 - ((unsigned long)dma_coherent
& 0x1F));
314 dma_coherent_handle
= dma_coherent_handle
+
315 (0x20 - ((unsigned long)dma_coherent_handle
& 0x1F));
318 dma_addr
= dma_coherent_handle
;
319 ccb_tmp
= (struct CommandControlBlock
*)dma_coherent
;
320 for (i
= 0; i
< ARCMSR_MAX_FREECCB_NUM
; i
++) {
321 ccb_tmp
->cdb_shifted_phyaddr
= dma_addr
>> 5;
323 acb
->pccb_pool
[i
] = ccb_tmp
;
324 list_add_tail(&ccb_tmp
->list
, &acb
->ccb_free_list
);
325 dma_addr
= dma_addr
+ sizeof(struct CommandControlBlock
);
329 reg
= (struct MessageUnit_B
*)(dma_coherent
+
330 ARCMSR_MAX_FREECCB_NUM
* sizeof(struct CommandControlBlock
));
332 mem_base0
= ioremap(pci_resource_start(pdev
, 0),
333 pci_resource_len(pdev
, 0));
337 mem_base1
= ioremap(pci_resource_start(pdev
, 2),
338 pci_resource_len(pdev
, 2));
344 reg
->drv2iop_doorbell_reg
= mem_base0
+ ARCMSR_DRV2IOP_DOORBELL
;
345 reg
->drv2iop_doorbell_mask_reg
= mem_base0
+
346 ARCMSR_DRV2IOP_DOORBELL_MASK
;
347 reg
->iop2drv_doorbell_reg
= mem_base0
+ ARCMSR_IOP2DRV_DOORBELL
;
348 reg
->iop2drv_doorbell_mask_reg
= mem_base0
+
349 ARCMSR_IOP2DRV_DOORBELL_MASK
;
350 reg
->ioctl_wbuffer_reg
= mem_base1
+ ARCMSR_IOCTL_WBUFFER
;
351 reg
->ioctl_rbuffer_reg
= mem_base1
+ ARCMSR_IOCTL_RBUFFER
;
352 reg
->msgcode_rwbuffer_reg
= mem_base1
+ ARCMSR_MSGCODE_RWBUFFER
;
354 acb
->vir2phy_offset
= (unsigned long)ccb_tmp
-(unsigned long)dma_addr
;
355 for (i
= 0; i
< ARCMSR_MAX_TARGETID
; i
++)
356 for (j
= 0; j
< ARCMSR_MAX_TARGETLUN
; j
++)
357 acb
->devstate
[i
][j
] = ARECA_RAID_GOOD
;
360 ** here we need to tell iop 331 our ccb_tmp.HighPart
361 ** if ccb_tmp.HighPart is not zero
363 intmask_org
= arcmsr_disable_outbound_ints(acb
);
370 dma_free_coherent(&acb
->pdev
->dev
,
371 (ARCMSR_MAX_FREECCB_NUM
* sizeof(struct CommandControlBlock
) + 0x20 +
372 sizeof(struct MessageUnit_B
)), acb
->dma_coherent
, acb
->dma_coherent_handle
);
376 static int arcmsr_probe(struct pci_dev
*pdev
,
377 const struct pci_device_id
*id
)
379 struct Scsi_Host
*host
;
380 struct AdapterControlBlock
*acb
;
381 uint8_t bus
, dev_fun
;
384 error
= pci_enable_device(pdev
);
387 pci_set_master(pdev
);
389 host
= scsi_host_alloc(&arcmsr_scsi_host_template
,
390 sizeof(struct AdapterControlBlock
));
393 goto out_disable_device
;
395 acb
= (struct AdapterControlBlock
*)host
->hostdata
;
396 memset(acb
, 0, sizeof (struct AdapterControlBlock
));
398 error
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
);
400 error
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
403 "scsi%d: No suitable DMA mask available\n",
408 bus
= pdev
->bus
->number
;
409 dev_fun
= pdev
->devfn
;
412 host
->max_sectors
= ARCMSR_MAX_XFER_SECTORS
;
413 host
->max_lun
= ARCMSR_MAX_TARGETLUN
;
414 host
->max_id
= ARCMSR_MAX_TARGETID
;/*16:8*/
415 host
->max_cmd_len
= 16; /*this is issue of 64bit LBA, over 2T byte*/
416 host
->sg_tablesize
= ARCMSR_MAX_SG_ENTRIES
;
417 host
->can_queue
= ARCMSR_MAX_FREECCB_NUM
; /* max simultaneous cmds */
418 host
->cmd_per_lun
= ARCMSR_MAX_CMD_PERLUN
;
419 host
->this_id
= ARCMSR_SCSI_INITIATOR_ID
;
420 host
->unique_id
= (bus
<< 8) | dev_fun
;
421 host
->irq
= pdev
->irq
;
422 error
= pci_request_regions(pdev
, "arcmsr");
426 arcmsr_define_adapter_type(acb
);
428 acb
->acb_flags
|= (ACB_F_MESSAGE_WQBUFFER_CLEARED
|
429 ACB_F_MESSAGE_RQBUFFER_CLEARED
|
430 ACB_F_MESSAGE_WQBUFFER_READED
);
431 acb
->acb_flags
&= ~ACB_F_SCSISTOPADAPTER
;
432 INIT_LIST_HEAD(&acb
->ccb_free_list
);
434 error
= arcmsr_alloc_ccb_pool(acb
);
436 goto out_release_regions
;
438 error
= request_irq(pdev
->irq
, arcmsr_do_interrupt
,
439 IRQF_SHARED
, "arcmsr", acb
);
441 goto out_free_ccb_pool
;
443 arcmsr_iop_init(acb
);
444 pci_set_drvdata(pdev
, host
);
445 if (strncmp(acb
->firm_version
, "V1.42", 5) >= 0)
446 host
->max_sectors
= ARCMSR_MAX_XFER_SECTORS_B
;
448 error
= scsi_add_host(host
, &pdev
->dev
);
452 error
= arcmsr_alloc_sysfs_attr(acb
);
456 scsi_scan_host(host
);
457 #ifdef CONFIG_SCSI_ARCMSR_AER
458 pci_enable_pcie_error_reporting(pdev
);
463 free_irq(pdev
->irq
, acb
);
465 arcmsr_free_ccb_pool(acb
);
467 pci_release_regions(pdev
);
471 pci_disable_device(pdev
);
476 static uint8_t arcmsr_hba_wait_msgint_ready(struct AdapterControlBlock
*acb
)
478 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
480 uint8_t Retries
= 0x00;
483 for (Index
= 0; Index
< 100; Index
++) {
484 if (readl(®
->outbound_intstatus
) &
485 ARCMSR_MU_OUTBOUND_MESSAGE0_INT
) {
486 writel(ARCMSR_MU_OUTBOUND_MESSAGE0_INT
,
487 ®
->outbound_intstatus
);
493 } while (Retries
++ < 20);/*max 20 sec*/
497 static uint8_t arcmsr_hbb_wait_msgint_ready(struct AdapterControlBlock
*acb
)
499 struct MessageUnit_B
*reg
= acb
->pmuB
;
501 uint8_t Retries
= 0x00;
504 for (Index
= 0; Index
< 100; Index
++) {
505 if (readl(reg
->iop2drv_doorbell_reg
)
506 & ARCMSR_IOP2DRV_MESSAGE_CMD_DONE
) {
507 writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN
508 , reg
->iop2drv_doorbell_reg
);
509 writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT
, reg
->drv2iop_doorbell_reg
);
515 } while (Retries
++ < 20);/*max 20 sec*/
519 static void arcmsr_abort_hba_allcmd(struct AdapterControlBlock
*acb
)
521 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
523 writel(ARCMSR_INBOUND_MESG0_ABORT_CMD
, ®
->inbound_msgaddr0
);
524 if (arcmsr_hba_wait_msgint_ready(acb
))
526 "arcmsr%d: wait 'abort all outstanding command' timeout \n"
527 , acb
->host
->host_no
);
530 static void arcmsr_abort_hbb_allcmd(struct AdapterControlBlock
*acb
)
532 struct MessageUnit_B
*reg
= acb
->pmuB
;
534 writel(ARCMSR_MESSAGE_ABORT_CMD
, reg
->drv2iop_doorbell_reg
);
535 if (arcmsr_hbb_wait_msgint_ready(acb
))
537 "arcmsr%d: wait 'abort all outstanding command' timeout \n"
538 , acb
->host
->host_no
);
541 static void arcmsr_abort_allcmd(struct AdapterControlBlock
*acb
)
543 switch (acb
->adapter_type
) {
544 case ACB_ADAPTER_TYPE_A
: {
545 arcmsr_abort_hba_allcmd(acb
);
549 case ACB_ADAPTER_TYPE_B
: {
550 arcmsr_abort_hbb_allcmd(acb
);
555 static void arcmsr_pci_unmap_dma(struct CommandControlBlock
*ccb
)
557 struct scsi_cmnd
*pcmd
= ccb
->pcmd
;
559 scsi_dma_unmap(pcmd
);
562 static void arcmsr_ccb_complete(struct CommandControlBlock
*ccb
, int stand_flag
)
564 struct AdapterControlBlock
*acb
= ccb
->acb
;
565 struct scsi_cmnd
*pcmd
= ccb
->pcmd
;
567 arcmsr_pci_unmap_dma(ccb
);
569 atomic_dec(&acb
->ccboutstandingcount
);
570 ccb
->startdone
= ARCMSR_CCB_DONE
;
572 list_add_tail(&ccb
->list
, &acb
->ccb_free_list
);
573 pcmd
->scsi_done(pcmd
);
576 static void arcmsr_flush_hba_cache(struct AdapterControlBlock
*acb
)
578 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
579 int retry_count
= 30;
581 writel(ARCMSR_INBOUND_MESG0_FLUSH_CACHE
, ®
->inbound_msgaddr0
);
583 if (!arcmsr_hba_wait_msgint_ready(acb
))
587 printk(KERN_NOTICE
"arcmsr%d: wait 'flush adapter cache' \
588 timeout, retry count down = %d \n", acb
->host
->host_no
, retry_count
);
590 } while (retry_count
!= 0);
593 static void arcmsr_flush_hbb_cache(struct AdapterControlBlock
*acb
)
595 struct MessageUnit_B
*reg
= acb
->pmuB
;
596 int retry_count
= 30;
598 writel(ARCMSR_MESSAGE_FLUSH_CACHE
, reg
->drv2iop_doorbell_reg
);
600 if (!arcmsr_hbb_wait_msgint_ready(acb
))
604 printk(KERN_NOTICE
"arcmsr%d: wait 'flush adapter cache' \
605 timeout,retry count down = %d \n", acb
->host
->host_no
, retry_count
);
607 } while (retry_count
!= 0);
610 static void arcmsr_flush_adapter_cache(struct AdapterControlBlock
*acb
)
612 switch (acb
->adapter_type
) {
614 case ACB_ADAPTER_TYPE_A
: {
615 arcmsr_flush_hba_cache(acb
);
619 case ACB_ADAPTER_TYPE_B
: {
620 arcmsr_flush_hbb_cache(acb
);
625 static void arcmsr_report_sense_info(struct CommandControlBlock
*ccb
)
628 struct scsi_cmnd
*pcmd
= ccb
->pcmd
;
629 struct SENSE_DATA
*sensebuffer
= (struct SENSE_DATA
*)pcmd
->sense_buffer
;
631 pcmd
->result
= DID_OK
<< 16;
633 int sense_data_length
=
634 sizeof(struct SENSE_DATA
) < SCSI_SENSE_BUFFERSIZE
635 ? sizeof(struct SENSE_DATA
) : SCSI_SENSE_BUFFERSIZE
;
636 memset(sensebuffer
, 0, SCSI_SENSE_BUFFERSIZE
);
637 memcpy(sensebuffer
, ccb
->arcmsr_cdb
.SenseData
, sense_data_length
);
638 sensebuffer
->ErrorCode
= SCSI_SENSE_CURRENT_ERRORS
;
639 sensebuffer
->Valid
= 1;
643 static u32
arcmsr_disable_outbound_ints(struct AdapterControlBlock
*acb
)
646 switch (acb
->adapter_type
) {
648 case ACB_ADAPTER_TYPE_A
: {
649 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
650 orig_mask
= readl(®
->outbound_intmask
)|\
651 ARCMSR_MU_OUTBOUND_MESSAGE0_INTMASKENABLE
;
652 writel(orig_mask
|ARCMSR_MU_OUTBOUND_ALL_INTMASKENABLE
, \
653 ®
->outbound_intmask
);
657 case ACB_ADAPTER_TYPE_B
: {
658 struct MessageUnit_B
*reg
= acb
->pmuB
;
659 orig_mask
= readl(reg
->iop2drv_doorbell_mask_reg
) & \
660 (~ARCMSR_IOP2DRV_MESSAGE_CMD_DONE
);
661 writel(0, reg
->iop2drv_doorbell_mask_reg
);
668 static void arcmsr_report_ccb_state(struct AdapterControlBlock
*acb
, \
669 struct CommandControlBlock
*ccb
, uint32_t flag_ccb
)
673 id
= ccb
->pcmd
->device
->id
;
674 lun
= ccb
->pcmd
->device
->lun
;
675 if (!(flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR
)) {
676 if (acb
->devstate
[id
][lun
] == ARECA_RAID_GONE
)
677 acb
->devstate
[id
][lun
] = ARECA_RAID_GOOD
;
678 ccb
->pcmd
->result
= DID_OK
<< 16;
679 arcmsr_ccb_complete(ccb
, 1);
681 switch (ccb
->arcmsr_cdb
.DeviceStatus
) {
682 case ARCMSR_DEV_SELECT_TIMEOUT
: {
683 acb
->devstate
[id
][lun
] = ARECA_RAID_GONE
;
684 ccb
->pcmd
->result
= DID_NO_CONNECT
<< 16;
685 arcmsr_ccb_complete(ccb
, 1);
689 case ARCMSR_DEV_ABORTED
:
691 case ARCMSR_DEV_INIT_FAIL
: {
692 acb
->devstate
[id
][lun
] = ARECA_RAID_GONE
;
693 ccb
->pcmd
->result
= DID_BAD_TARGET
<< 16;
694 arcmsr_ccb_complete(ccb
, 1);
698 case ARCMSR_DEV_CHECK_CONDITION
: {
699 acb
->devstate
[id
][lun
] = ARECA_RAID_GOOD
;
700 arcmsr_report_sense_info(ccb
);
701 arcmsr_ccb_complete(ccb
, 1);
707 "arcmsr%d: scsi id = %d lun = %d"
708 " isr get command error done, "
709 "but got unknown DeviceStatus = 0x%x \n"
713 , ccb
->arcmsr_cdb
.DeviceStatus
);
714 acb
->devstate
[id
][lun
] = ARECA_RAID_GONE
;
715 ccb
->pcmd
->result
= DID_NO_CONNECT
<< 16;
716 arcmsr_ccb_complete(ccb
, 1);
722 static void arcmsr_drain_donequeue(struct AdapterControlBlock
*acb
, uint32_t flag_ccb
)
725 struct CommandControlBlock
*ccb
;
727 ccb
= (struct CommandControlBlock
*)(acb
->vir2phy_offset
+ (flag_ccb
<< 5));
728 if ((ccb
->acb
!= acb
) || (ccb
->startdone
!= ARCMSR_CCB_START
)) {
729 if (ccb
->startdone
== ARCMSR_CCB_ABORTED
) {
730 struct scsi_cmnd
*abortcmd
= ccb
->pcmd
;
732 abortcmd
->result
|= DID_ABORT
<< 16;
733 arcmsr_ccb_complete(ccb
, 1);
734 printk(KERN_NOTICE
"arcmsr%d: ccb ='0x%p' \
735 isr got aborted command \n", acb
->host
->host_no
, ccb
);
738 printk(KERN_NOTICE
"arcmsr%d: isr get an illegal ccb command \
740 "ccb = '0x%p' ccbacb = '0x%p' startdone = 0x%x"
741 " ccboutstandingcount = %d \n"
747 , atomic_read(&acb
->ccboutstandingcount
));
750 arcmsr_report_ccb_state(acb
, ccb
, flag_ccb
);
753 static void arcmsr_done4abort_postqueue(struct AdapterControlBlock
*acb
)
758 switch (acb
->adapter_type
) {
760 case ACB_ADAPTER_TYPE_A
: {
761 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
762 uint32_t outbound_intstatus
;
763 outbound_intstatus
= readl(®
->outbound_intstatus
) &
764 acb
->outbound_int_enable
;
765 /*clear and abort all outbound posted Q*/
766 writel(outbound_intstatus
, ®
->outbound_intstatus
);/*clear interrupt*/
767 while (((flag_ccb
= readl(®
->outbound_queueport
)) != 0xFFFFFFFF)
768 && (i
++ < ARCMSR_MAX_OUTSTANDING_CMD
)) {
769 arcmsr_drain_donequeue(acb
, flag_ccb
);
774 case ACB_ADAPTER_TYPE_B
: {
775 struct MessageUnit_B
*reg
= acb
->pmuB
;
776 /*clear all outbound posted Q*/
777 for (i
= 0; i
< ARCMSR_MAX_HBB_POSTQUEUE
; i
++) {
778 if ((flag_ccb
= readl(®
->done_qbuffer
[i
])) != 0) {
779 writel(0, ®
->done_qbuffer
[i
]);
780 arcmsr_drain_donequeue(acb
, flag_ccb
);
782 writel(0, ®
->post_qbuffer
[i
]);
784 reg
->doneq_index
= 0;
785 reg
->postq_index
= 0;
790 static void arcmsr_remove(struct pci_dev
*pdev
)
792 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
793 struct AdapterControlBlock
*acb
=
794 (struct AdapterControlBlock
*) host
->hostdata
;
797 arcmsr_free_sysfs_attr(acb
);
798 scsi_remove_host(host
);
799 arcmsr_stop_adapter_bgrb(acb
);
800 arcmsr_flush_adapter_cache(acb
);
801 arcmsr_disable_outbound_ints(acb
);
802 acb
->acb_flags
|= ACB_F_SCSISTOPADAPTER
;
803 acb
->acb_flags
&= ~ACB_F_IOP_INITED
;
805 for (poll_count
= 0; poll_count
< ARCMSR_MAX_OUTSTANDING_CMD
; poll_count
++) {
806 if (!atomic_read(&acb
->ccboutstandingcount
))
808 arcmsr_interrupt(acb
);/* FIXME: need spinlock */
812 if (atomic_read(&acb
->ccboutstandingcount
)) {
815 arcmsr_abort_allcmd(acb
);
816 arcmsr_done4abort_postqueue(acb
);
817 for (i
= 0; i
< ARCMSR_MAX_FREECCB_NUM
; i
++) {
818 struct CommandControlBlock
*ccb
= acb
->pccb_pool
[i
];
819 if (ccb
->startdone
== ARCMSR_CCB_START
) {
820 ccb
->startdone
= ARCMSR_CCB_ABORTED
;
821 ccb
->pcmd
->result
= DID_ABORT
<< 16;
822 arcmsr_ccb_complete(ccb
, 1);
827 free_irq(pdev
->irq
, acb
);
828 arcmsr_free_ccb_pool(acb
);
829 pci_release_regions(pdev
);
833 pci_disable_device(pdev
);
834 pci_set_drvdata(pdev
, NULL
);
837 static void arcmsr_shutdown(struct pci_dev
*pdev
)
839 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
840 struct AdapterControlBlock
*acb
=
841 (struct AdapterControlBlock
*)host
->hostdata
;
843 arcmsr_stop_adapter_bgrb(acb
);
844 arcmsr_flush_adapter_cache(acb
);
847 static int arcmsr_module_init(void)
851 error
= pci_register_driver(&arcmsr_pci_driver
);
855 static void arcmsr_module_exit(void)
857 pci_unregister_driver(&arcmsr_pci_driver
);
859 module_init(arcmsr_module_init
);
860 module_exit(arcmsr_module_exit
);
862 static void arcmsr_enable_outbound_ints(struct AdapterControlBlock
*acb
, \
867 switch (acb
->adapter_type
) {
869 case ACB_ADAPTER_TYPE_A
: {
870 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
871 mask
= intmask_org
& ~(ARCMSR_MU_OUTBOUND_POSTQUEUE_INTMASKENABLE
|
872 ARCMSR_MU_OUTBOUND_DOORBELL_INTMASKENABLE
);
873 writel(mask
, ®
->outbound_intmask
);
874 acb
->outbound_int_enable
= ~(intmask_org
& mask
) & 0x000000ff;
878 case ACB_ADAPTER_TYPE_B
: {
879 struct MessageUnit_B
*reg
= acb
->pmuB
;
880 mask
= intmask_org
| (ARCMSR_IOP2DRV_DATA_WRITE_OK
| \
881 ARCMSR_IOP2DRV_DATA_READ_OK
| ARCMSR_IOP2DRV_CDB_DONE
);
882 writel(mask
, reg
->iop2drv_doorbell_mask_reg
);
883 acb
->outbound_int_enable
= (intmask_org
| mask
) & 0x0000000f;
888 static int arcmsr_build_ccb(struct AdapterControlBlock
*acb
,
889 struct CommandControlBlock
*ccb
, struct scsi_cmnd
*pcmd
)
891 struct ARCMSR_CDB
*arcmsr_cdb
= (struct ARCMSR_CDB
*)&ccb
->arcmsr_cdb
;
892 int8_t *psge
= (int8_t *)&arcmsr_cdb
->u
;
893 __le32 address_lo
, address_hi
;
894 int arccdbsize
= 0x30;
898 memset(arcmsr_cdb
, 0, sizeof(struct ARCMSR_CDB
));
900 arcmsr_cdb
->TargetID
= pcmd
->device
->id
;
901 arcmsr_cdb
->LUN
= pcmd
->device
->lun
;
902 arcmsr_cdb
->Function
= 1;
903 arcmsr_cdb
->CdbLength
= (uint8_t)pcmd
->cmd_len
;
904 arcmsr_cdb
->Context
= (unsigned long)arcmsr_cdb
;
905 memcpy(arcmsr_cdb
->Cdb
, pcmd
->cmnd
, pcmd
->cmd_len
);
907 nseg
= scsi_dma_map(pcmd
);
908 if (nseg
> ARCMSR_MAX_SG_ENTRIES
)
914 int i
, cdb_sgcount
= 0;
915 struct scatterlist
*sg
;
917 /* map stor port SG list to our iop SG List. */
918 scsi_for_each_sg(pcmd
, sg
, nseg
, i
) {
919 /* Get the physical address of the current data pointer */
920 length
= cpu_to_le32(sg_dma_len(sg
));
921 address_lo
= cpu_to_le32(dma_addr_lo32(sg_dma_address(sg
)));
922 address_hi
= cpu_to_le32(dma_addr_hi32(sg_dma_address(sg
)));
923 if (address_hi
== 0) {
924 struct SG32ENTRY
*pdma_sg
= (struct SG32ENTRY
*)psge
;
926 pdma_sg
->address
= address_lo
;
927 pdma_sg
->length
= length
;
928 psge
+= sizeof (struct SG32ENTRY
);
929 arccdbsize
+= sizeof (struct SG32ENTRY
);
931 struct SG64ENTRY
*pdma_sg
= (struct SG64ENTRY
*)psge
;
933 pdma_sg
->addresshigh
= address_hi
;
934 pdma_sg
->address
= address_lo
;
935 pdma_sg
->length
= length
|cpu_to_le32(IS_SG64_ADDR
);
936 psge
+= sizeof (struct SG64ENTRY
);
937 arccdbsize
+= sizeof (struct SG64ENTRY
);
941 arcmsr_cdb
->sgcount
= (uint8_t)cdb_sgcount
;
942 arcmsr_cdb
->DataLength
= scsi_bufflen(pcmd
);
943 if ( arccdbsize
> 256)
944 arcmsr_cdb
->Flags
|= ARCMSR_CDB_FLAG_SGL_BSIZE
;
946 if (pcmd
->sc_data_direction
== DMA_TO_DEVICE
) {
947 arcmsr_cdb
->Flags
|= ARCMSR_CDB_FLAG_WRITE
;
948 ccb
->ccb_flags
|= CCB_FLAG_WRITE
;
953 static void arcmsr_post_ccb(struct AdapterControlBlock
*acb
, struct CommandControlBlock
*ccb
)
955 uint32_t cdb_shifted_phyaddr
= ccb
->cdb_shifted_phyaddr
;
956 struct ARCMSR_CDB
*arcmsr_cdb
= (struct ARCMSR_CDB
*)&ccb
->arcmsr_cdb
;
957 atomic_inc(&acb
->ccboutstandingcount
);
958 ccb
->startdone
= ARCMSR_CCB_START
;
960 switch (acb
->adapter_type
) {
961 case ACB_ADAPTER_TYPE_A
: {
962 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
964 if (arcmsr_cdb
->Flags
& ARCMSR_CDB_FLAG_SGL_BSIZE
)
965 writel(cdb_shifted_phyaddr
| ARCMSR_CCBPOST_FLAG_SGL_BSIZE
,
966 ®
->inbound_queueport
);
968 writel(cdb_shifted_phyaddr
, ®
->inbound_queueport
);
973 case ACB_ADAPTER_TYPE_B
: {
974 struct MessageUnit_B
*reg
= acb
->pmuB
;
975 uint32_t ending_index
, index
= reg
->postq_index
;
977 ending_index
= ((index
+ 1) % ARCMSR_MAX_HBB_POSTQUEUE
);
978 writel(0, ®
->post_qbuffer
[ending_index
]);
979 if (arcmsr_cdb
->Flags
& ARCMSR_CDB_FLAG_SGL_BSIZE
) {
980 writel(cdb_shifted_phyaddr
| ARCMSR_CCBPOST_FLAG_SGL_BSIZE
,\
981 ®
->post_qbuffer
[index
]);
984 writel(cdb_shifted_phyaddr
, ®
->post_qbuffer
[index
]);
987 index
%= ARCMSR_MAX_HBB_POSTQUEUE
;/*if last index number set it to 0 */
988 reg
->postq_index
= index
;
989 writel(ARCMSR_DRV2IOP_CDB_POSTED
, reg
->drv2iop_doorbell_reg
);
995 static void arcmsr_stop_hba_bgrb(struct AdapterControlBlock
*acb
)
997 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
998 acb
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
999 writel(ARCMSR_INBOUND_MESG0_STOP_BGRB
, ®
->inbound_msgaddr0
);
1001 if (arcmsr_hba_wait_msgint_ready(acb
)) {
1003 "arcmsr%d: wait 'stop adapter background rebulid' timeout \n"
1004 , acb
->host
->host_no
);
1008 static void arcmsr_stop_hbb_bgrb(struct AdapterControlBlock
*acb
)
1010 struct MessageUnit_B
*reg
= acb
->pmuB
;
1011 acb
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
1012 writel(ARCMSR_MESSAGE_STOP_BGRB
, reg
->drv2iop_doorbell_reg
);
1014 if (arcmsr_hbb_wait_msgint_ready(acb
)) {
1016 "arcmsr%d: wait 'stop adapter background rebulid' timeout \n"
1017 , acb
->host
->host_no
);
1021 static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock
*acb
)
1023 switch (acb
->adapter_type
) {
1024 case ACB_ADAPTER_TYPE_A
: {
1025 arcmsr_stop_hba_bgrb(acb
);
1029 case ACB_ADAPTER_TYPE_B
: {
1030 arcmsr_stop_hbb_bgrb(acb
);
1036 static void arcmsr_free_ccb_pool(struct AdapterControlBlock
*acb
)
1038 switch (acb
->adapter_type
) {
1039 case ACB_ADAPTER_TYPE_A
: {
1041 dma_free_coherent(&acb
->pdev
->dev
,
1042 ARCMSR_MAX_FREECCB_NUM
* sizeof (struct CommandControlBlock
) + 0x20,
1044 acb
->dma_coherent_handle
);
1047 case ACB_ADAPTER_TYPE_B
: {
1048 struct MessageUnit_B
*reg
= acb
->pmuB
;
1049 iounmap(reg
->drv2iop_doorbell_reg
- ARCMSR_DRV2IOP_DOORBELL
);
1050 iounmap(reg
->ioctl_wbuffer_reg
- ARCMSR_IOCTL_WBUFFER
);
1051 dma_free_coherent(&acb
->pdev
->dev
,
1052 (ARCMSR_MAX_FREECCB_NUM
* sizeof(struct CommandControlBlock
) + 0x20 +
1053 sizeof(struct MessageUnit_B
)), acb
->dma_coherent
, acb
->dma_coherent_handle
);
1059 void arcmsr_iop_message_read(struct AdapterControlBlock
*acb
)
1061 switch (acb
->adapter_type
) {
1062 case ACB_ADAPTER_TYPE_A
: {
1063 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1064 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK
, ®
->inbound_doorbell
);
1068 case ACB_ADAPTER_TYPE_B
: {
1069 struct MessageUnit_B
*reg
= acb
->pmuB
;
1070 writel(ARCMSR_DRV2IOP_DATA_READ_OK
, reg
->drv2iop_doorbell_reg
);
1076 static void arcmsr_iop_message_wrote(struct AdapterControlBlock
*acb
)
1078 switch (acb
->adapter_type
) {
1079 case ACB_ADAPTER_TYPE_A
: {
1080 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1082 ** push inbound doorbell tell iop, driver data write ok
1083 ** and wait reply on next hwinterrupt for next Qbuffer post
1085 writel(ARCMSR_INBOUND_DRIVER_DATA_WRITE_OK
, ®
->inbound_doorbell
);
1089 case ACB_ADAPTER_TYPE_B
: {
1090 struct MessageUnit_B
*reg
= acb
->pmuB
;
1092 ** push inbound doorbell tell iop, driver data write ok
1093 ** and wait reply on next hwinterrupt for next Qbuffer post
1095 writel(ARCMSR_DRV2IOP_DATA_WRITE_OK
, reg
->drv2iop_doorbell_reg
);
1101 struct QBUFFER __iomem
*arcmsr_get_iop_rqbuffer(struct AdapterControlBlock
*acb
)
1103 struct QBUFFER __iomem
*qbuffer
= NULL
;
1105 switch (acb
->adapter_type
) {
1107 case ACB_ADAPTER_TYPE_A
: {
1108 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1109 qbuffer
= (struct QBUFFER __iomem
*)®
->message_rbuffer
;
1113 case ACB_ADAPTER_TYPE_B
: {
1114 struct MessageUnit_B
*reg
= acb
->pmuB
;
1115 qbuffer
= (struct QBUFFER __iomem
*)reg
->ioctl_rbuffer_reg
;
1122 static struct QBUFFER __iomem
*arcmsr_get_iop_wqbuffer(struct AdapterControlBlock
*acb
)
1124 struct QBUFFER __iomem
*pqbuffer
= NULL
;
1126 switch (acb
->adapter_type
) {
1128 case ACB_ADAPTER_TYPE_A
: {
1129 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1130 pqbuffer
= (struct QBUFFER __iomem
*) ®
->message_wbuffer
;
1134 case ACB_ADAPTER_TYPE_B
: {
1135 struct MessageUnit_B
*reg
= acb
->pmuB
;
1136 pqbuffer
= (struct QBUFFER __iomem
*)reg
->ioctl_wbuffer_reg
;
1143 static void arcmsr_iop2drv_data_wrote_handle(struct AdapterControlBlock
*acb
)
1145 struct QBUFFER __iomem
*prbuffer
;
1146 struct QBUFFER
*pQbuffer
;
1147 uint8_t __iomem
*iop_data
;
1148 int32_t my_empty_len
, iop_len
, rqbuf_firstindex
, rqbuf_lastindex
;
1150 rqbuf_lastindex
= acb
->rqbuf_lastindex
;
1151 rqbuf_firstindex
= acb
->rqbuf_firstindex
;
1152 prbuffer
= arcmsr_get_iop_rqbuffer(acb
);
1153 iop_data
= (uint8_t __iomem
*)prbuffer
->data
;
1154 iop_len
= prbuffer
->data_len
;
1155 my_empty_len
= (rqbuf_firstindex
- rqbuf_lastindex
-1)&(ARCMSR_MAX_QBUFFER
-1);
1157 if (my_empty_len
>= iop_len
)
1159 while (iop_len
> 0) {
1160 pQbuffer
= (struct QBUFFER
*)&acb
->rqbuffer
[rqbuf_lastindex
];
1161 memcpy(pQbuffer
, iop_data
,1);
1163 rqbuf_lastindex
%= ARCMSR_MAX_QBUFFER
;
1167 acb
->rqbuf_lastindex
= rqbuf_lastindex
;
1168 arcmsr_iop_message_read(acb
);
1172 acb
->acb_flags
|= ACB_F_IOPDATA_OVERFLOW
;
1176 static void arcmsr_iop2drv_data_read_handle(struct AdapterControlBlock
*acb
)
1178 acb
->acb_flags
|= ACB_F_MESSAGE_WQBUFFER_READED
;
1179 if (acb
->wqbuf_firstindex
!= acb
->wqbuf_lastindex
) {
1181 struct QBUFFER __iomem
*pwbuffer
;
1182 uint8_t __iomem
*iop_data
;
1183 int32_t allxfer_len
= 0;
1185 acb
->acb_flags
&= (~ACB_F_MESSAGE_WQBUFFER_READED
);
1186 pwbuffer
= arcmsr_get_iop_wqbuffer(acb
);
1187 iop_data
= (uint8_t __iomem
*)pwbuffer
->data
;
1189 while ((acb
->wqbuf_firstindex
!= acb
->wqbuf_lastindex
) && \
1190 (allxfer_len
< 124)) {
1191 pQbuffer
= &acb
->wqbuffer
[acb
->wqbuf_firstindex
];
1192 memcpy(iop_data
, pQbuffer
, 1);
1193 acb
->wqbuf_firstindex
++;
1194 acb
->wqbuf_firstindex
%= ARCMSR_MAX_QBUFFER
;
1198 pwbuffer
->data_len
= allxfer_len
;
1200 arcmsr_iop_message_wrote(acb
);
1203 if (acb
->wqbuf_firstindex
== acb
->wqbuf_lastindex
) {
1204 acb
->acb_flags
|= ACB_F_MESSAGE_WQBUFFER_CLEARED
;
1208 static void arcmsr_hba_doorbell_isr(struct AdapterControlBlock
*acb
)
1210 uint32_t outbound_doorbell
;
1211 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1213 outbound_doorbell
= readl(®
->outbound_doorbell
);
1214 writel(outbound_doorbell
, ®
->outbound_doorbell
);
1215 if (outbound_doorbell
& ARCMSR_OUTBOUND_IOP331_DATA_WRITE_OK
) {
1216 arcmsr_iop2drv_data_wrote_handle(acb
);
1219 if (outbound_doorbell
& ARCMSR_OUTBOUND_IOP331_DATA_READ_OK
) {
1220 arcmsr_iop2drv_data_read_handle(acb
);
1224 static void arcmsr_hba_postqueue_isr(struct AdapterControlBlock
*acb
)
1227 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1229 while ((flag_ccb
= readl(®
->outbound_queueport
)) != 0xFFFFFFFF) {
1230 arcmsr_drain_donequeue(acb
, flag_ccb
);
1234 static void arcmsr_hbb_postqueue_isr(struct AdapterControlBlock
*acb
)
1238 struct MessageUnit_B
*reg
= acb
->pmuB
;
1240 index
= reg
->doneq_index
;
1242 while ((flag_ccb
= readl(®
->done_qbuffer
[index
])) != 0) {
1243 writel(0, ®
->done_qbuffer
[index
]);
1244 arcmsr_drain_donequeue(acb
, flag_ccb
);
1246 index
%= ARCMSR_MAX_HBB_POSTQUEUE
;
1247 reg
->doneq_index
= index
;
1251 static int arcmsr_handle_hba_isr(struct AdapterControlBlock
*acb
)
1253 uint32_t outbound_intstatus
;
1254 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1256 outbound_intstatus
= readl(®
->outbound_intstatus
) & \
1257 acb
->outbound_int_enable
;
1258 if (!(outbound_intstatus
& ARCMSR_MU_OUTBOUND_HANDLE_INT
)) {
1261 writel(outbound_intstatus
, ®
->outbound_intstatus
);
1262 if (outbound_intstatus
& ARCMSR_MU_OUTBOUND_DOORBELL_INT
) {
1263 arcmsr_hba_doorbell_isr(acb
);
1265 if (outbound_intstatus
& ARCMSR_MU_OUTBOUND_POSTQUEUE_INT
) {
1266 arcmsr_hba_postqueue_isr(acb
);
1271 static int arcmsr_handle_hbb_isr(struct AdapterControlBlock
*acb
)
1273 uint32_t outbound_doorbell
;
1274 struct MessageUnit_B
*reg
= acb
->pmuB
;
1276 outbound_doorbell
= readl(reg
->iop2drv_doorbell_reg
) & \
1277 acb
->outbound_int_enable
;
1278 if (!outbound_doorbell
)
1281 writel(~outbound_doorbell
, reg
->iop2drv_doorbell_reg
);
1282 /*in case the last action of doorbell interrupt clearance is cached, this action can push HW to write down the clear bit*/
1283 readl(reg
->iop2drv_doorbell_reg
);
1284 writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT
, reg
->drv2iop_doorbell_reg
);
1285 if (outbound_doorbell
& ARCMSR_IOP2DRV_DATA_WRITE_OK
) {
1286 arcmsr_iop2drv_data_wrote_handle(acb
);
1288 if (outbound_doorbell
& ARCMSR_IOP2DRV_DATA_READ_OK
) {
1289 arcmsr_iop2drv_data_read_handle(acb
);
1291 if (outbound_doorbell
& ARCMSR_IOP2DRV_CDB_DONE
) {
1292 arcmsr_hbb_postqueue_isr(acb
);
1298 static irqreturn_t
arcmsr_interrupt(struct AdapterControlBlock
*acb
)
1300 switch (acb
->adapter_type
) {
1301 case ACB_ADAPTER_TYPE_A
: {
1302 if (arcmsr_handle_hba_isr(acb
)) {
1308 case ACB_ADAPTER_TYPE_B
: {
1309 if (arcmsr_handle_hbb_isr(acb
)) {
1318 static void arcmsr_iop_parking(struct AdapterControlBlock
*acb
)
1321 /* stop adapter background rebuild */
1322 if (acb
->acb_flags
& ACB_F_MSG_START_BGRB
) {
1323 uint32_t intmask_org
;
1324 acb
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
1325 intmask_org
= arcmsr_disable_outbound_ints(acb
);
1326 arcmsr_stop_adapter_bgrb(acb
);
1327 arcmsr_flush_adapter_cache(acb
);
1328 arcmsr_enable_outbound_ints(acb
, intmask_org
);
1333 void arcmsr_post_ioctldata2iop(struct AdapterControlBlock
*acb
)
1335 int32_t wqbuf_firstindex
, wqbuf_lastindex
;
1337 struct QBUFFER __iomem
*pwbuffer
;
1338 uint8_t __iomem
*iop_data
;
1339 int32_t allxfer_len
= 0;
1341 pwbuffer
= arcmsr_get_iop_wqbuffer(acb
);
1342 iop_data
= (uint8_t __iomem
*)pwbuffer
->data
;
1343 if (acb
->acb_flags
& ACB_F_MESSAGE_WQBUFFER_READED
) {
1344 acb
->acb_flags
&= (~ACB_F_MESSAGE_WQBUFFER_READED
);
1345 wqbuf_firstindex
= acb
->wqbuf_firstindex
;
1346 wqbuf_lastindex
= acb
->wqbuf_lastindex
;
1347 while ((wqbuf_firstindex
!= wqbuf_lastindex
) && (allxfer_len
< 124)) {
1348 pQbuffer
= &acb
->wqbuffer
[wqbuf_firstindex
];
1349 memcpy(iop_data
, pQbuffer
, 1);
1351 wqbuf_firstindex
%= ARCMSR_MAX_QBUFFER
;
1355 acb
->wqbuf_firstindex
= wqbuf_firstindex
;
1356 pwbuffer
->data_len
= allxfer_len
;
1357 arcmsr_iop_message_wrote(acb
);
1361 static int arcmsr_iop_message_xfer(struct AdapterControlBlock
*acb
, \
1362 struct scsi_cmnd
*cmd
)
1364 struct CMD_MESSAGE_FIELD
*pcmdmessagefld
;
1365 int retvalue
= 0, transfer_len
= 0;
1367 struct scatterlist
*sg
;
1368 uint32_t controlcode
= (uint32_t ) cmd
->cmnd
[5] << 24 |
1369 (uint32_t ) cmd
->cmnd
[6] << 16 |
1370 (uint32_t ) cmd
->cmnd
[7] << 8 |
1371 (uint32_t ) cmd
->cmnd
[8];
1372 /* 4 bytes: Areca io control code */
1374 sg
= scsi_sglist(cmd
);
1375 buffer
= kmap_atomic(sg_page(sg
), KM_IRQ0
) + sg
->offset
;
1376 if (scsi_sg_count(cmd
) > 1) {
1377 retvalue
= ARCMSR_MESSAGE_FAIL
;
1380 transfer_len
+= sg
->length
;
1382 if (transfer_len
> sizeof(struct CMD_MESSAGE_FIELD
)) {
1383 retvalue
= ARCMSR_MESSAGE_FAIL
;
1386 pcmdmessagefld
= (struct CMD_MESSAGE_FIELD
*) buffer
;
1387 switch(controlcode
) {
1389 case ARCMSR_MESSAGE_READ_RQBUFFER
: {
1390 <<<<<<< HEAD
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1391 unsigned long *ver_addr
;
1393 unsigned char *ver_addr
;
1394 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1395 uint8_t *pQbuffer
, *ptmpQbuffer
;
1396 int32_t allxfer_len
= 0;
1397 <<<<<<< HEAD
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1400 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1402 <<<<<<< HEAD
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1403 tmp
= kmalloc(1032, GFP_KERNEL
|GFP_DMA
);
1404 ver_addr
= (unsigned long *)tmp
;
1407 ver_addr
= kmalloc(1032, GFP_ATOMIC
);
1409 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1410 retvalue
= ARCMSR_MESSAGE_FAIL
;
1413 <<<<<<< HEAD
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1414 ptmpQbuffer
= (uint8_t *) ver_addr
;
1416 ptmpQbuffer
= ver_addr
;
1417 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1418 while ((acb
->rqbuf_firstindex
!= acb
->rqbuf_lastindex
)
1419 && (allxfer_len
< 1031)) {
1420 pQbuffer
= &acb
->rqbuffer
[acb
->rqbuf_firstindex
];
1421 memcpy(ptmpQbuffer
, pQbuffer
, 1);
1422 acb
->rqbuf_firstindex
++;
1423 acb
->rqbuf_firstindex
%= ARCMSR_MAX_QBUFFER
;
1427 if (acb
->acb_flags
& ACB_F_IOPDATA_OVERFLOW
) {
1429 struct QBUFFER __iomem
*prbuffer
;
1430 uint8_t __iomem
*iop_data
;
1433 acb
->acb_flags
&= ~ACB_F_IOPDATA_OVERFLOW
;
1434 prbuffer
= arcmsr_get_iop_rqbuffer(acb
);
1435 iop_data
= prbuffer
->data
;
1436 iop_len
= readl(&prbuffer
->data_len
);
1437 while (iop_len
> 0) {
1438 acb
->rqbuffer
[acb
->rqbuf_lastindex
] = readb(iop_data
);
1439 acb
->rqbuf_lastindex
++;
1440 acb
->rqbuf_lastindex
%= ARCMSR_MAX_QBUFFER
;
1444 arcmsr_iop_message_read(acb
);
1446 <<<<<<< HEAD
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1447 memcpy(pcmdmessagefld
->messagedatabuffer
, (uint8_t *)ver_addr
, allxfer_len
);
1449 memcpy(pcmdmessagefld
->messagedatabuffer
, ver_addr
, allxfer_len
);
1450 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1451 pcmdmessagefld
->cmdmessage
.Length
= allxfer_len
;
1452 pcmdmessagefld
->cmdmessage
.ReturnCode
= ARCMSR_MESSAGE_RETURNCODE_OK
;
1453 <<<<<<< HEAD
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1457 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1461 case ARCMSR_MESSAGE_WRITE_WQBUFFER
: {
1462 <<<<<<< HEAD
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1463 unsigned long *ver_addr
;
1465 unsigned char *ver_addr
;
1466 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1467 int32_t my_empty_len
, user_len
, wqbuf_firstindex
, wqbuf_lastindex
;
1468 uint8_t *pQbuffer
, *ptmpuserbuffer
;
1469 <<<<<<< HEAD
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1472 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1474 <<<<<<< HEAD
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1475 tmp
= kmalloc(1032, GFP_KERNEL
|GFP_DMA
);
1476 ver_addr
= (unsigned long *)tmp
;
1479 ver_addr
= kmalloc(1032, GFP_ATOMIC
);
1481 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1482 retvalue
= ARCMSR_MESSAGE_FAIL
;
1485 <<<<<<< HEAD
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1486 ptmpuserbuffer
= (uint8_t *)ver_addr
;
1488 ptmpuserbuffer
= ver_addr
;
1489 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1490 user_len
= pcmdmessagefld
->cmdmessage
.Length
;
1491 memcpy(ptmpuserbuffer
, pcmdmessagefld
->messagedatabuffer
, user_len
);
1492 wqbuf_lastindex
= acb
->wqbuf_lastindex
;
1493 wqbuf_firstindex
= acb
->wqbuf_firstindex
;
1494 if (wqbuf_lastindex
!= wqbuf_firstindex
) {
1495 struct SENSE_DATA
*sensebuffer
=
1496 (struct SENSE_DATA
*)cmd
->sense_buffer
;
1497 arcmsr_post_ioctldata2iop(acb
);
1498 /* has error report sensedata */
1499 sensebuffer
->ErrorCode
= 0x70;
1500 sensebuffer
->SenseKey
= ILLEGAL_REQUEST
;
1501 sensebuffer
->AdditionalSenseLength
= 0x0A;
1502 sensebuffer
->AdditionalSenseCode
= 0x20;
1503 sensebuffer
->Valid
= 1;
1504 retvalue
= ARCMSR_MESSAGE_FAIL
;
1506 my_empty_len
= (wqbuf_firstindex
-wqbuf_lastindex
- 1)
1507 &(ARCMSR_MAX_QBUFFER
- 1);
1508 if (my_empty_len
>= user_len
) {
1509 while (user_len
> 0) {
1511 &acb
->wqbuffer
[acb
->wqbuf_lastindex
];
1512 memcpy(pQbuffer
, ptmpuserbuffer
, 1);
1513 acb
->wqbuf_lastindex
++;
1514 acb
->wqbuf_lastindex
%= ARCMSR_MAX_QBUFFER
;
1518 if (acb
->acb_flags
& ACB_F_MESSAGE_WQBUFFER_CLEARED
) {
1520 ~ACB_F_MESSAGE_WQBUFFER_CLEARED
;
1521 arcmsr_post_ioctldata2iop(acb
);
1524 /* has error report sensedata */
1525 struct SENSE_DATA
*sensebuffer
=
1526 (struct SENSE_DATA
*)cmd
->sense_buffer
;
1527 sensebuffer
->ErrorCode
= 0x70;
1528 sensebuffer
->SenseKey
= ILLEGAL_REQUEST
;
1529 sensebuffer
->AdditionalSenseLength
= 0x0A;
1530 sensebuffer
->AdditionalSenseCode
= 0x20;
1531 sensebuffer
->Valid
= 1;
1532 retvalue
= ARCMSR_MESSAGE_FAIL
;
1535 <<<<<<< HEAD
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1539 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/arcmsr
/arcmsr_hba
.c
1543 case ARCMSR_MESSAGE_CLEAR_RQBUFFER
: {
1544 uint8_t *pQbuffer
= acb
->rqbuffer
;
1546 if (acb
->acb_flags
& ACB_F_IOPDATA_OVERFLOW
) {
1547 acb
->acb_flags
&= ~ACB_F_IOPDATA_OVERFLOW
;
1548 arcmsr_iop_message_read(acb
);
1550 acb
->acb_flags
|= ACB_F_MESSAGE_RQBUFFER_CLEARED
;
1551 acb
->rqbuf_firstindex
= 0;
1552 acb
->rqbuf_lastindex
= 0;
1553 memset(pQbuffer
, 0, ARCMSR_MAX_QBUFFER
);
1554 pcmdmessagefld
->cmdmessage
.ReturnCode
= ARCMSR_MESSAGE_RETURNCODE_OK
;
1558 case ARCMSR_MESSAGE_CLEAR_WQBUFFER
: {
1559 uint8_t *pQbuffer
= acb
->wqbuffer
;
1561 if (acb
->acb_flags
& ACB_F_IOPDATA_OVERFLOW
) {
1562 acb
->acb_flags
&= ~ACB_F_IOPDATA_OVERFLOW
;
1563 arcmsr_iop_message_read(acb
);
1566 (ACB_F_MESSAGE_WQBUFFER_CLEARED
|
1567 ACB_F_MESSAGE_WQBUFFER_READED
);
1568 acb
->wqbuf_firstindex
= 0;
1569 acb
->wqbuf_lastindex
= 0;
1570 memset(pQbuffer
, 0, ARCMSR_MAX_QBUFFER
);
1571 pcmdmessagefld
->cmdmessage
.ReturnCode
=
1572 ARCMSR_MESSAGE_RETURNCODE_OK
;
1576 case ARCMSR_MESSAGE_CLEAR_ALLQBUFFER
: {
1579 if (acb
->acb_flags
& ACB_F_IOPDATA_OVERFLOW
) {
1580 acb
->acb_flags
&= ~ACB_F_IOPDATA_OVERFLOW
;
1581 arcmsr_iop_message_read(acb
);
1584 (ACB_F_MESSAGE_WQBUFFER_CLEARED
1585 | ACB_F_MESSAGE_RQBUFFER_CLEARED
1586 | ACB_F_MESSAGE_WQBUFFER_READED
);
1587 acb
->rqbuf_firstindex
= 0;
1588 acb
->rqbuf_lastindex
= 0;
1589 acb
->wqbuf_firstindex
= 0;
1590 acb
->wqbuf_lastindex
= 0;
1591 pQbuffer
= acb
->rqbuffer
;
1592 memset(pQbuffer
, 0, sizeof(struct QBUFFER
));
1593 pQbuffer
= acb
->wqbuffer
;
1594 memset(pQbuffer
, 0, sizeof(struct QBUFFER
));
1595 pcmdmessagefld
->cmdmessage
.ReturnCode
= ARCMSR_MESSAGE_RETURNCODE_OK
;
1599 case ARCMSR_MESSAGE_RETURN_CODE_3F
: {
1600 pcmdmessagefld
->cmdmessage
.ReturnCode
= ARCMSR_MESSAGE_RETURNCODE_3F
;
1604 case ARCMSR_MESSAGE_SAY_HELLO
: {
1605 int8_t *hello_string
= "Hello! I am ARCMSR";
1607 memcpy(pcmdmessagefld
->messagedatabuffer
, hello_string
1608 , (int16_t)strlen(hello_string
));
1609 pcmdmessagefld
->cmdmessage
.ReturnCode
= ARCMSR_MESSAGE_RETURNCODE_OK
;
1613 case ARCMSR_MESSAGE_SAY_GOODBYE
:
1614 arcmsr_iop_parking(acb
);
1617 case ARCMSR_MESSAGE_FLUSH_ADAPTER_CACHE
:
1618 arcmsr_flush_adapter_cache(acb
);
1622 retvalue
= ARCMSR_MESSAGE_FAIL
;
1625 sg
= scsi_sglist(cmd
);
1626 kunmap_atomic(buffer
- sg
->offset
, KM_IRQ0
);
1630 static struct CommandControlBlock
*arcmsr_get_freeccb(struct AdapterControlBlock
*acb
)
1632 struct list_head
*head
= &acb
->ccb_free_list
;
1633 struct CommandControlBlock
*ccb
= NULL
;
1635 if (!list_empty(head
)) {
1636 ccb
= list_entry(head
->next
, struct CommandControlBlock
, list
);
1637 list_del(head
->next
);
1642 static void arcmsr_handle_virtual_command(struct AdapterControlBlock
*acb
,
1643 struct scsi_cmnd
*cmd
)
1645 switch (cmd
->cmnd
[0]) {
1647 unsigned char inqdata
[36];
1649 struct scatterlist
*sg
;
1651 if (cmd
->device
->lun
) {
1652 cmd
->result
= (DID_TIME_OUT
<< 16);
1653 cmd
->scsi_done(cmd
);
1656 inqdata
[0] = TYPE_PROCESSOR
;
1657 /* Periph Qualifier & Periph Dev Type */
1659 /* rem media bit & Dev Type Modifier */
1661 /* ISO, ECMA, & ANSI versions */
1663 /* length of additional data */
1664 strncpy(&inqdata
[8], "Areca ", 8);
1665 /* Vendor Identification */
1666 strncpy(&inqdata
[16], "RAID controller ", 16);
1667 /* Product Identification */
1668 strncpy(&inqdata
[32], "R001", 4); /* Product Revision */
1670 sg
= scsi_sglist(cmd
);
1671 buffer
= kmap_atomic(sg_page(sg
), KM_IRQ0
) + sg
->offset
;
1673 memcpy(buffer
, inqdata
, sizeof(inqdata
));
1674 sg
= scsi_sglist(cmd
);
1675 kunmap_atomic(buffer
- sg
->offset
, KM_IRQ0
);
1677 cmd
->scsi_done(cmd
);
1682 if (arcmsr_iop_message_xfer(acb
, cmd
))
1683 cmd
->result
= (DID_ERROR
<< 16);
1684 cmd
->scsi_done(cmd
);
1688 cmd
->scsi_done(cmd
);
1692 static int arcmsr_queue_command(struct scsi_cmnd
*cmd
,
1693 void (* done
)(struct scsi_cmnd
*))
1695 struct Scsi_Host
*host
= cmd
->device
->host
;
1696 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
1697 struct CommandControlBlock
*ccb
;
1698 int target
= cmd
->device
->id
;
1699 int lun
= cmd
->device
->lun
;
1701 cmd
->scsi_done
= done
;
1702 cmd
->host_scribble
= NULL
;
1704 if (acb
->acb_flags
& ACB_F_BUS_RESET
) {
1705 printk(KERN_NOTICE
"arcmsr%d: bus reset"
1706 " and return busy \n"
1707 , acb
->host
->host_no
);
1708 return SCSI_MLQUEUE_HOST_BUSY
;
1711 /* virtual device for iop message transfer */
1712 arcmsr_handle_virtual_command(acb
, cmd
);
1715 if (acb
->devstate
[target
][lun
] == ARECA_RAID_GONE
) {
1718 block_cmd
= cmd
->cmnd
[0] & 0x0f;
1719 if (block_cmd
== 0x08 || block_cmd
== 0x0a) {
1721 "arcmsr%d: block 'read/write'"
1722 "command with gone raid volume"
1723 " Cmd = %2x, TargetId = %d, Lun = %d \n"
1724 , acb
->host
->host_no
1727 cmd
->result
= (DID_NO_CONNECT
<< 16);
1728 cmd
->scsi_done(cmd
);
1732 if (atomic_read(&acb
->ccboutstandingcount
) >=
1733 ARCMSR_MAX_OUTSTANDING_CMD
)
1734 return SCSI_MLQUEUE_HOST_BUSY
;
1736 ccb
= arcmsr_get_freeccb(acb
);
1738 return SCSI_MLQUEUE_HOST_BUSY
;
1739 if ( arcmsr_build_ccb( acb
, ccb
, cmd
) == FAILED
) {
1740 cmd
->result
= (DID_ERROR
<< 16) | (RESERVATION_CONFLICT
<< 1);
1741 cmd
->scsi_done(cmd
);
1744 arcmsr_post_ccb(acb
, ccb
);
1748 static void arcmsr_get_hba_config(struct AdapterControlBlock
*acb
)
1750 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1751 char *acb_firm_model
= acb
->firm_model
;
1752 char *acb_firm_version
= acb
->firm_version
;
1753 char __iomem
*iop_firm_model
= (char __iomem
*)(®
->message_rwbuffer
[15]);
1754 char __iomem
*iop_firm_version
= (char __iomem
*)(®
->message_rwbuffer
[17]);
1757 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
1758 if (arcmsr_hba_wait_msgint_ready(acb
)) {
1759 printk(KERN_NOTICE
"arcmsr%d: wait 'get adapter firmware \
1760 miscellaneous data' timeout \n", acb
->host
->host_no
);
1765 *acb_firm_model
= readb(iop_firm_model
);
1773 *acb_firm_version
= readb(iop_firm_version
);
1779 printk(KERN_INFO
"ARECA RAID ADAPTER%d: FIRMWARE VERSION %s \n"
1780 , acb
->host
->host_no
1781 , acb
->firm_version
);
1783 acb
->firm_request_len
= readl(®
->message_rwbuffer
[1]);
1784 acb
->firm_numbers_queue
= readl(®
->message_rwbuffer
[2]);
1785 acb
->firm_sdram_size
= readl(®
->message_rwbuffer
[3]);
1786 acb
->firm_hd_channels
= readl(®
->message_rwbuffer
[4]);
1789 static void arcmsr_get_hbb_config(struct AdapterControlBlock
*acb
)
1791 struct MessageUnit_B
*reg
= acb
->pmuB
;
1792 uint32_t __iomem
*lrwbuffer
= reg
->msgcode_rwbuffer_reg
;
1793 char *acb_firm_model
= acb
->firm_model
;
1794 char *acb_firm_version
= acb
->firm_version
;
1795 char __iomem
*iop_firm_model
= (char __iomem
*)(&lrwbuffer
[15]);
1796 /*firm_model,15,60-67*/
1797 char __iomem
*iop_firm_version
= (char __iomem
*)(&lrwbuffer
[17]);
1798 /*firm_version,17,68-83*/
1801 writel(ARCMSR_MESSAGE_GET_CONFIG
, reg
->drv2iop_doorbell_reg
);
1802 if (arcmsr_hbb_wait_msgint_ready(acb
)) {
1803 printk(KERN_NOTICE
"arcmsr%d: wait 'get adapter firmware \
1804 miscellaneous data' timeout \n", acb
->host
->host_no
);
1810 *acb_firm_model
= readb(iop_firm_model
);
1819 *acb_firm_version
= readb(iop_firm_version
);
1825 printk(KERN_INFO
"ARECA RAID ADAPTER%d: FIRMWARE VERSION %s \n",
1830 acb
->firm_request_len
= readl(lrwbuffer
++);
1831 /*firm_request_len,1,04-07*/
1832 acb
->firm_numbers_queue
= readl(lrwbuffer
++);
1833 /*firm_numbers_queue,2,08-11*/
1834 acb
->firm_sdram_size
= readl(lrwbuffer
++);
1835 /*firm_sdram_size,3,12-15*/
1836 acb
->firm_hd_channels
= readl(lrwbuffer
);
1837 /*firm_ide_channels,4,16-19*/
1840 static void arcmsr_get_firmware_spec(struct AdapterControlBlock
*acb
)
1842 switch (acb
->adapter_type
) {
1843 case ACB_ADAPTER_TYPE_A
: {
1844 arcmsr_get_hba_config(acb
);
1848 case ACB_ADAPTER_TYPE_B
: {
1849 arcmsr_get_hbb_config(acb
);
1855 static void arcmsr_polling_hba_ccbdone(struct AdapterControlBlock
*acb
,
1856 struct CommandControlBlock
*poll_ccb
)
1858 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1859 struct CommandControlBlock
*ccb
;
1860 uint32_t flag_ccb
, outbound_intstatus
, poll_ccb_done
= 0, poll_count
= 0;
1862 polling_hba_ccb_retry
:
1864 outbound_intstatus
= readl(®
->outbound_intstatus
) & acb
->outbound_int_enable
;
1865 writel(outbound_intstatus
, ®
->outbound_intstatus
);/*clear interrupt*/
1867 if ((flag_ccb
= readl(®
->outbound_queueport
)) == 0xFFFFFFFF) {
1872 if (poll_count
> 100)
1874 goto polling_hba_ccb_retry
;
1877 ccb
= (struct CommandControlBlock
*)(acb
->vir2phy_offset
+ (flag_ccb
<< 5));
1878 poll_ccb_done
= (ccb
== poll_ccb
) ? 1:0;
1879 if ((ccb
->acb
!= acb
) || (ccb
->startdone
!= ARCMSR_CCB_START
)) {
1880 if ((ccb
->startdone
== ARCMSR_CCB_ABORTED
) || (ccb
== poll_ccb
)) {
1881 printk(KERN_NOTICE
"arcmsr%d: scsi id = %d lun = %d ccb = '0x%p'"
1882 " poll command abort successfully \n"
1883 , acb
->host
->host_no
1884 , ccb
->pcmd
->device
->id
1885 , ccb
->pcmd
->device
->lun
1887 ccb
->pcmd
->result
= DID_ABORT
<< 16;
1888 arcmsr_ccb_complete(ccb
, 1);
1892 printk(KERN_NOTICE
"arcmsr%d: polling get an illegal ccb"
1893 " command done ccb = '0x%p'"
1894 "ccboutstandingcount = %d \n"
1895 , acb
->host
->host_no
1897 , atomic_read(&acb
->ccboutstandingcount
));
1900 arcmsr_report_ccb_state(acb
, ccb
, flag_ccb
);
1904 static void arcmsr_polling_hbb_ccbdone(struct AdapterControlBlock
*acb
,
1905 struct CommandControlBlock
*poll_ccb
)
1907 struct MessageUnit_B
*reg
= acb
->pmuB
;
1908 struct CommandControlBlock
*ccb
;
1909 uint32_t flag_ccb
, poll_ccb_done
= 0, poll_count
= 0;
1912 polling_hbb_ccb_retry
:
1914 /* clear doorbell interrupt */
1915 writel(ARCMSR_DOORBELL_INT_CLEAR_PATTERN
, reg
->iop2drv_doorbell_reg
);
1917 index
= reg
->doneq_index
;
1918 if ((flag_ccb
= readl(®
->done_qbuffer
[index
])) == 0) {
1923 if (poll_count
> 100)
1925 goto polling_hbb_ccb_retry
;
1928 writel(0, ®
->done_qbuffer
[index
]);
1930 /*if last index number set it to 0 */
1931 index
%= ARCMSR_MAX_HBB_POSTQUEUE
;
1932 reg
->doneq_index
= index
;
1933 /* check ifcommand done with no error*/
1934 ccb
= (struct CommandControlBlock
*)\
1935 (acb
->vir2phy_offset
+ (flag_ccb
<< 5));/*frame must be 32 bytes aligned*/
1936 poll_ccb_done
= (ccb
== poll_ccb
) ? 1:0;
1937 if ((ccb
->acb
!= acb
) || (ccb
->startdone
!= ARCMSR_CCB_START
)) {
1938 if ((ccb
->startdone
== ARCMSR_CCB_ABORTED
) || (ccb
== poll_ccb
)) {
1939 printk(KERN_NOTICE
"arcmsr%d: \
1940 scsi id = %d lun = %d ccb = '0x%p' poll command abort successfully \n"
1942 ,ccb
->pcmd
->device
->id
1943 ,ccb
->pcmd
->device
->lun
1945 ccb
->pcmd
->result
= DID_ABORT
<< 16;
1946 arcmsr_ccb_complete(ccb
, 1);
1949 printk(KERN_NOTICE
"arcmsr%d: polling get an illegal ccb"
1950 " command done ccb = '0x%p'"
1951 "ccboutstandingcount = %d \n"
1952 , acb
->host
->host_no
1954 , atomic_read(&acb
->ccboutstandingcount
));
1957 arcmsr_report_ccb_state(acb
, ccb
, flag_ccb
);
1958 } /*drain reply FIFO*/
1961 static void arcmsr_polling_ccbdone(struct AdapterControlBlock
*acb
,
1962 struct CommandControlBlock
*poll_ccb
)
1964 switch (acb
->adapter_type
) {
1966 case ACB_ADAPTER_TYPE_A
: {
1967 arcmsr_polling_hba_ccbdone(acb
,poll_ccb
);
1971 case ACB_ADAPTER_TYPE_B
: {
1972 arcmsr_polling_hbb_ccbdone(acb
,poll_ccb
);
1977 static int arcmsr_iop_confirm(struct AdapterControlBlock
*acb
)
1979 uint32_t cdb_phyaddr
, ccb_phyaddr_hi32
;
1980 dma_addr_t dma_coherent_handle
;
1982 ********************************************************************
1983 ** here we need to tell iop 331 our freeccb.HighPart
1984 ** if freeccb.HighPart is not zero
1985 ********************************************************************
1987 dma_coherent_handle
= acb
->dma_coherent_handle
;
1988 cdb_phyaddr
= (uint32_t)(dma_coherent_handle
);
1989 ccb_phyaddr_hi32
= (uint32_t)((cdb_phyaddr
>> 16) >> 16);
1991 ***********************************************************************
1992 ** if adapter type B, set window of "post command Q"
1993 ***********************************************************************
1995 switch (acb
->adapter_type
) {
1997 case ACB_ADAPTER_TYPE_A
: {
1998 if (ccb_phyaddr_hi32
!= 0) {
1999 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2000 uint32_t intmask_org
;
2001 intmask_org
= arcmsr_disable_outbound_ints(acb
);
2002 writel(ARCMSR_SIGNATURE_SET_CONFIG
, \
2003 ®
->message_rwbuffer
[0]);
2004 writel(ccb_phyaddr_hi32
, ®
->message_rwbuffer
[1]);
2005 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG
, \
2006 ®
->inbound_msgaddr0
);
2007 if (arcmsr_hba_wait_msgint_ready(acb
)) {
2008 printk(KERN_NOTICE
"arcmsr%d: ""set ccb high \
2009 part physical address timeout\n",
2010 acb
->host
->host_no
);
2013 arcmsr_enable_outbound_ints(acb
, intmask_org
);
2018 case ACB_ADAPTER_TYPE_B
: {
2019 unsigned long post_queue_phyaddr
;
2020 uint32_t __iomem
*rwbuffer
;
2022 struct MessageUnit_B
*reg
= acb
->pmuB
;
2023 uint32_t intmask_org
;
2024 intmask_org
= arcmsr_disable_outbound_ints(acb
);
2025 reg
->postq_index
= 0;
2026 reg
->doneq_index
= 0;
2027 writel(ARCMSR_MESSAGE_SET_POST_WINDOW
, reg
->drv2iop_doorbell_reg
);
2028 if (arcmsr_hbb_wait_msgint_ready(acb
)) {
2029 printk(KERN_NOTICE
"arcmsr%d:can not set diver mode\n", \
2030 acb
->host
->host_no
);
2033 post_queue_phyaddr
= cdb_phyaddr
+ ARCMSR_MAX_FREECCB_NUM
* \
2034 sizeof(struct CommandControlBlock
) + offsetof(struct MessageUnit_B
, post_qbuffer
) ;
2035 rwbuffer
= reg
->msgcode_rwbuffer_reg
;
2036 /* driver "set config" signature */
2037 writel(ARCMSR_SIGNATURE_SET_CONFIG
, rwbuffer
++);
2038 /* normal should be zero */
2039 writel(ccb_phyaddr_hi32
, rwbuffer
++);
2040 /* postQ size (256 + 8)*4 */
2041 writel(post_queue_phyaddr
, rwbuffer
++);
2042 /* doneQ size (256 + 8)*4 */
2043 writel(post_queue_phyaddr
+ 1056, rwbuffer
++);
2044 /* ccb maxQ size must be --> [(256 + 8)*4]*/
2045 writel(1056, rwbuffer
);
2047 writel(ARCMSR_MESSAGE_SET_CONFIG
, reg
->drv2iop_doorbell_reg
);
2048 if (arcmsr_hbb_wait_msgint_ready(acb
)) {
2049 printk(KERN_NOTICE
"arcmsr%d: 'set command Q window' \
2050 timeout \n",acb
->host
->host_no
);
2054 writel(ARCMSR_MESSAGE_START_DRIVER_MODE
, reg
->drv2iop_doorbell_reg
);
2055 if (arcmsr_hbb_wait_msgint_ready(acb
)) {
2056 printk(KERN_NOTICE
"arcmsr%d: 'can not set diver mode \n"\
2057 ,acb
->host
->host_no
);
2060 arcmsr_enable_outbound_ints(acb
, intmask_org
);
2067 static void arcmsr_wait_firmware_ready(struct AdapterControlBlock
*acb
)
2069 uint32_t firmware_state
= 0;
2071 switch (acb
->adapter_type
) {
2073 case ACB_ADAPTER_TYPE_A
: {
2074 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2076 firmware_state
= readl(®
->outbound_msgaddr1
);
2077 } while ((firmware_state
& ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK
) == 0);
2081 case ACB_ADAPTER_TYPE_B
: {
2082 struct MessageUnit_B
*reg
= acb
->pmuB
;
2084 firmware_state
= readl(reg
->iop2drv_doorbell_reg
);
2085 } while ((firmware_state
& ARCMSR_MESSAGE_FIRMWARE_OK
) == 0);
2086 writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT
, reg
->drv2iop_doorbell_reg
);
2092 static void arcmsr_start_hba_bgrb(struct AdapterControlBlock
*acb
)
2094 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2095 acb
->acb_flags
|= ACB_F_MSG_START_BGRB
;
2096 writel(ARCMSR_INBOUND_MESG0_START_BGRB
, ®
->inbound_msgaddr0
);
2097 if (arcmsr_hba_wait_msgint_ready(acb
)) {
2098 printk(KERN_NOTICE
"arcmsr%d: wait 'start adapter background \
2099 rebulid' timeout \n", acb
->host
->host_no
);
2103 static void arcmsr_start_hbb_bgrb(struct AdapterControlBlock
*acb
)
2105 struct MessageUnit_B
*reg
= acb
->pmuB
;
2106 acb
->acb_flags
|= ACB_F_MSG_START_BGRB
;
2107 writel(ARCMSR_MESSAGE_START_BGRB
, reg
->drv2iop_doorbell_reg
);
2108 if (arcmsr_hbb_wait_msgint_ready(acb
)) {
2109 printk(KERN_NOTICE
"arcmsr%d: wait 'start adapter background \
2110 rebulid' timeout \n",acb
->host
->host_no
);
2114 static void arcmsr_start_adapter_bgrb(struct AdapterControlBlock
*acb
)
2116 switch (acb
->adapter_type
) {
2117 case ACB_ADAPTER_TYPE_A
:
2118 arcmsr_start_hba_bgrb(acb
);
2120 case ACB_ADAPTER_TYPE_B
:
2121 arcmsr_start_hbb_bgrb(acb
);
2126 static void arcmsr_clear_doorbell_queue_buffer(struct AdapterControlBlock
*acb
)
2128 switch (acb
->adapter_type
) {
2129 case ACB_ADAPTER_TYPE_A
: {
2130 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2131 uint32_t outbound_doorbell
;
2132 /* empty doorbell Qbuffer if door bell ringed */
2133 outbound_doorbell
= readl(®
->outbound_doorbell
);
2134 /*clear doorbell interrupt */
2135 writel(outbound_doorbell
, ®
->outbound_doorbell
);
2136 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK
, ®
->inbound_doorbell
);
2140 case ACB_ADAPTER_TYPE_B
: {
2141 struct MessageUnit_B
*reg
= acb
->pmuB
;
2142 /*clear interrupt and message state*/
2143 writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN
, reg
->iop2drv_doorbell_reg
);
2144 writel(ARCMSR_DRV2IOP_DATA_READ_OK
, reg
->drv2iop_doorbell_reg
);
2145 /* let IOP know data has been read */
2151 static void arcmsr_enable_eoi_mode(struct AdapterControlBlock
*acb
)
2153 switch (acb
->adapter_type
) {
2154 case ACB_ADAPTER_TYPE_A
:
2156 case ACB_ADAPTER_TYPE_B
:
2158 struct MessageUnit_B
*reg
= acb
->pmuB
;
2159 writel(ARCMSR_MESSAGE_ACTIVE_EOI_MODE
, reg
->drv2iop_doorbell_reg
);
2160 if(arcmsr_hbb_wait_msgint_ready(acb
)) {
2161 printk(KERN_NOTICE
"ARCMSR IOP enables EOI_MODE TIMEOUT");
2170 static void arcmsr_iop_init(struct AdapterControlBlock
*acb
)
2172 uint32_t intmask_org
;
2174 /* disable all outbound interrupt */
2175 intmask_org
= arcmsr_disable_outbound_ints(acb
);
2176 arcmsr_wait_firmware_ready(acb
);
2177 arcmsr_iop_confirm(acb
);
2178 arcmsr_get_firmware_spec(acb
);
2179 /*start background rebuild*/
2180 arcmsr_start_adapter_bgrb(acb
);
2181 /* empty doorbell Qbuffer if door bell ringed */
2182 arcmsr_clear_doorbell_queue_buffer(acb
);
2183 arcmsr_enable_eoi_mode(acb
);
2184 /* enable outbound Post Queue,outbound doorbell Interrupt */
2185 arcmsr_enable_outbound_ints(acb
, intmask_org
);
2186 acb
->acb_flags
|= ACB_F_IOP_INITED
;
2189 static void arcmsr_iop_reset(struct AdapterControlBlock
*acb
)
2191 struct CommandControlBlock
*ccb
;
2192 uint32_t intmask_org
;
2195 if (atomic_read(&acb
->ccboutstandingcount
) != 0) {
2196 /* talk to iop 331 outstanding command aborted */
2197 arcmsr_abort_allcmd(acb
);
2199 /* wait for 3 sec for all command aborted*/
2202 /* disable all outbound interrupt */
2203 intmask_org
= arcmsr_disable_outbound_ints(acb
);
2204 /* clear all outbound posted Q */
2205 arcmsr_done4abort_postqueue(acb
);
2206 for (i
= 0; i
< ARCMSR_MAX_FREECCB_NUM
; i
++) {
2207 ccb
= acb
->pccb_pool
[i
];
2208 if (ccb
->startdone
== ARCMSR_CCB_START
) {
2209 ccb
->startdone
= ARCMSR_CCB_ABORTED
;
2210 arcmsr_ccb_complete(ccb
, 1);
2213 /* enable all outbound interrupt */
2214 arcmsr_enable_outbound_ints(acb
, intmask_org
);
2218 static int arcmsr_bus_reset(struct scsi_cmnd
*cmd
)
2220 struct AdapterControlBlock
*acb
=
2221 (struct AdapterControlBlock
*)cmd
->device
->host
->hostdata
;
2225 acb
->acb_flags
|= ACB_F_BUS_RESET
;
2226 for (i
= 0; i
< 400; i
++) {
2227 if (!atomic_read(&acb
->ccboutstandingcount
))
2229 arcmsr_interrupt(acb
);/* FIXME: need spinlock */
2232 arcmsr_iop_reset(acb
);
2233 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
2237 static void arcmsr_abort_one_cmd(struct AdapterControlBlock
*acb
,
2238 struct CommandControlBlock
*ccb
)
2242 ccb
->startdone
= ARCMSR_CCB_ABORTED
;
2245 ** Wait for 3 sec for all command done.
2249 intmask
= arcmsr_disable_outbound_ints(acb
);
2250 arcmsr_polling_ccbdone(acb
, ccb
);
2251 arcmsr_enable_outbound_ints(acb
, intmask
);
2254 static int arcmsr_abort(struct scsi_cmnd
*cmd
)
2256 struct AdapterControlBlock
*acb
=
2257 (struct AdapterControlBlock
*)cmd
->device
->host
->hostdata
;
2261 "arcmsr%d: abort device command of scsi id = %d lun = %d \n",
2262 acb
->host
->host_no
, cmd
->device
->id
, cmd
->device
->lun
);
2265 ************************************************
2266 ** the all interrupt service routine is locked
2267 ** we need to handle it as soon as possible and exit
2268 ************************************************
2270 if (!atomic_read(&acb
->ccboutstandingcount
))
2273 for (i
= 0; i
< ARCMSR_MAX_FREECCB_NUM
; i
++) {
2274 struct CommandControlBlock
*ccb
= acb
->pccb_pool
[i
];
2275 if (ccb
->startdone
== ARCMSR_CCB_START
&& ccb
->pcmd
== cmd
) {
2276 arcmsr_abort_one_cmd(acb
, ccb
);
2284 static const char *arcmsr_info(struct Scsi_Host
*host
)
2286 struct AdapterControlBlock
*acb
=
2287 (struct AdapterControlBlock
*) host
->hostdata
;
2288 static char buf
[256];
2292 switch (acb
->pdev
->device
) {
2293 case PCI_DEVICE_ID_ARECA_1110
:
2294 case PCI_DEVICE_ID_ARECA_1200
:
2295 case PCI_DEVICE_ID_ARECA_1202
:
2296 case PCI_DEVICE_ID_ARECA_1210
:
2299 case PCI_DEVICE_ID_ARECA_1120
:
2300 case PCI_DEVICE_ID_ARECA_1130
:
2301 case PCI_DEVICE_ID_ARECA_1160
:
2302 case PCI_DEVICE_ID_ARECA_1170
:
2303 case PCI_DEVICE_ID_ARECA_1201
:
2304 case PCI_DEVICE_ID_ARECA_1220
:
2305 case PCI_DEVICE_ID_ARECA_1230
:
2306 case PCI_DEVICE_ID_ARECA_1260
:
2307 case PCI_DEVICE_ID_ARECA_1270
:
2308 case PCI_DEVICE_ID_ARECA_1280
:
2311 case PCI_DEVICE_ID_ARECA_1380
:
2312 case PCI_DEVICE_ID_ARECA_1381
:
2313 case PCI_DEVICE_ID_ARECA_1680
:
2314 case PCI_DEVICE_ID_ARECA_1681
:
2321 sprintf(buf
, "Areca %s Host Adapter RAID Controller%s\n %s",
2322 type
, raid6
? "( RAID6 capable)" : "",
2323 ARCMSR_DRIVER_VERSION
);
2326 #ifdef CONFIG_SCSI_ARCMSR_AER
2327 static pci_ers_result_t
arcmsr_pci_slot_reset(struct pci_dev
*pdev
)
2329 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
2330 struct AdapterControlBlock
*acb
=
2331 (struct AdapterControlBlock
*) host
->hostdata
;
2332 uint32_t intmask_org
;
2335 if (pci_enable_device(pdev
)) {
2336 return PCI_ERS_RESULT_DISCONNECT
;
2338 pci_set_master(pdev
);
2339 intmask_org
= arcmsr_disable_outbound_ints(acb
);
2340 acb
->acb_flags
|= (ACB_F_MESSAGE_WQBUFFER_CLEARED
|
2341 ACB_F_MESSAGE_RQBUFFER_CLEARED
|
2342 ACB_F_MESSAGE_WQBUFFER_READED
);
2343 acb
->acb_flags
&= ~ACB_F_SCSISTOPADAPTER
;
2344 for (i
= 0; i
< ARCMSR_MAX_TARGETID
; i
++)
2345 for (j
= 0; j
< ARCMSR_MAX_TARGETLUN
; j
++)
2346 acb
->devstate
[i
][j
] = ARECA_RAID_GONE
;
2348 arcmsr_wait_firmware_ready(acb
);
2349 arcmsr_iop_confirm(acb
);
2350 /* disable all outbound interrupt */
2351 arcmsr_get_firmware_spec(acb
);
2352 /*start background rebuild*/
2353 arcmsr_start_adapter_bgrb(acb
);
2354 /* empty doorbell Qbuffer if door bell ringed */
2355 arcmsr_clear_doorbell_queue_buffer(acb
);
2356 arcmsr_enable_eoi_mode(acb
);
2357 /* enable outbound Post Queue,outbound doorbell Interrupt */
2358 arcmsr_enable_outbound_ints(acb
, intmask_org
);
2359 acb
->acb_flags
|= ACB_F_IOP_INITED
;
2361 pci_enable_pcie_error_reporting(pdev
);
2362 return PCI_ERS_RESULT_RECOVERED
;
2365 static void arcmsr_pci_ers_need_reset_forepart(struct pci_dev
*pdev
)
2367 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
2368 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*)host
->hostdata
;
2369 struct CommandControlBlock
*ccb
;
2370 uint32_t intmask_org
;
2373 if (atomic_read(&acb
->ccboutstandingcount
) != 0) {
2374 /* talk to iop 331 outstanding command aborted */
2375 arcmsr_abort_allcmd(acb
);
2376 /* wait for 3 sec for all command aborted*/
2378 /* disable all outbound interrupt */
2379 intmask_org
= arcmsr_disable_outbound_ints(acb
);
2380 /* clear all outbound posted Q */
2381 arcmsr_done4abort_postqueue(acb
);
2382 for (i
= 0; i
< ARCMSR_MAX_FREECCB_NUM
; i
++) {
2383 ccb
= acb
->pccb_pool
[i
];
2384 if (ccb
->startdone
== ARCMSR_CCB_START
) {
2385 ccb
->startdone
= ARCMSR_CCB_ABORTED
;
2386 arcmsr_ccb_complete(ccb
, 1);
2389 /* enable all outbound interrupt */
2390 arcmsr_enable_outbound_ints(acb
, intmask_org
);
2392 pci_disable_device(pdev
);
2395 static void arcmsr_pci_ers_disconnect_forepart(struct pci_dev
*pdev
)
2397 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
2398 struct AdapterControlBlock
*acb
= \
2399 (struct AdapterControlBlock
*)host
->hostdata
;
2401 arcmsr_stop_adapter_bgrb(acb
);
2402 arcmsr_flush_adapter_cache(acb
);
2405 static pci_ers_result_t
arcmsr_pci_error_detected(struct pci_dev
*pdev
,
2406 pci_channel_state_t state
)
2409 case pci_channel_io_frozen
:
2410 arcmsr_pci_ers_need_reset_forepart(pdev
);
2411 return PCI_ERS_RESULT_NEED_RESET
;
2412 case pci_channel_io_perm_failure
:
2413 arcmsr_pci_ers_disconnect_forepart(pdev
);
2414 return PCI_ERS_RESULT_DISCONNECT
;
2417 return PCI_ERS_RESULT_NEED_RESET
;