2 *******************************************************************************
4 ** FILE NAME : arcmsr_hba.c
5 ** BY : Nick Cheng, C.L. Huang
6 ** Description: SCSI RAID Device Driver for Areca RAID Controller
7 *******************************************************************************
8 ** Copyright (C) 2002 - 2014, Areca Technology Corporation All rights reserved
10 ** Web site: www.areca.com.tw
11 ** E-mail: support@areca.com.tw
13 ** This program is free software; you can redistribute it and/or modify
14 ** it under the terms of the GNU General Public License version 2 as
15 ** published by the Free Software Foundation.
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ** GNU General Public License for more details.
20 *******************************************************************************
21 ** Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions
24 ** 1. Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** 2. Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in the
28 ** documentation and/or other materials provided with the distribution.
29 ** 3. The name of the author may not be used to endorse or promote products
30 ** derived from this software without specific prior written permission.
32 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
33 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
36 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING,BUT
37 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION)HOWEVER CAUSED AND ON ANY
39 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 ** (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF
41 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *******************************************************************************
43 ** For history of changes, see Documentation/scsi/ChangeLog.arcmsr
44 ** Firmware Specification, see Documentation/scsi/arcmsr_spec.txt
45 *******************************************************************************
47 #include <linux/module.h>
48 #include <linux/reboot.h>
49 #include <linux/spinlock.h>
50 #include <linux/pci_ids.h>
51 #include <linux/interrupt.h>
52 #include <linux/moduleparam.h>
53 #include <linux/errno.h>
54 #include <linux/types.h>
55 #include <linux/delay.h>
56 #include <linux/dma-mapping.h>
57 #include <linux/timer.h>
58 #include <linux/slab.h>
59 #include <linux/pci.h>
60 #include <linux/aer.h>
61 #include <linux/circ_buf.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>
73 MODULE_AUTHOR("Nick Cheng, C.L. Huang <support@areca.com.tw>");
74 MODULE_DESCRIPTION("Areca ARC11xx/12xx/16xx/188x SAS/SATA RAID Controller Driver");
75 MODULE_LICENSE("Dual BSD/GPL");
76 MODULE_VERSION(ARCMSR_DRIVER_VERSION
);
78 #define ARCMSR_SLEEPTIME 10
79 #define ARCMSR_RETRYCOUNT 12
81 static wait_queue_head_t wait_q
;
82 static int arcmsr_iop_message_xfer(struct AdapterControlBlock
*acb
,
83 struct scsi_cmnd
*cmd
);
84 static int arcmsr_iop_confirm(struct AdapterControlBlock
*acb
);
85 static int arcmsr_abort(struct scsi_cmnd
*);
86 static int arcmsr_bus_reset(struct scsi_cmnd
*);
87 static int arcmsr_bios_param(struct scsi_device
*sdev
,
88 struct block_device
*bdev
, sector_t capacity
, int *info
);
89 static int arcmsr_queue_command(struct Scsi_Host
*h
, struct scsi_cmnd
*cmd
);
90 static int arcmsr_probe(struct pci_dev
*pdev
,
91 const struct pci_device_id
*id
);
92 static int arcmsr_suspend(struct pci_dev
*pdev
, pm_message_t state
);
93 static int arcmsr_resume(struct pci_dev
*pdev
);
94 static void arcmsr_remove(struct pci_dev
*pdev
);
95 static void arcmsr_shutdown(struct pci_dev
*pdev
);
96 static void arcmsr_iop_init(struct AdapterControlBlock
*acb
);
97 static void arcmsr_free_ccb_pool(struct AdapterControlBlock
*acb
);
98 static u32
arcmsr_disable_outbound_ints(struct AdapterControlBlock
*acb
);
99 static void arcmsr_enable_outbound_ints(struct AdapterControlBlock
*acb
,
101 static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock
*acb
);
102 static void arcmsr_hbaA_flush_cache(struct AdapterControlBlock
*acb
);
103 static void arcmsr_hbaB_flush_cache(struct AdapterControlBlock
*acb
);
104 static void arcmsr_request_device_map(unsigned long pacb
);
105 static void arcmsr_hbaA_request_device_map(struct AdapterControlBlock
*acb
);
106 static void arcmsr_hbaB_request_device_map(struct AdapterControlBlock
*acb
);
107 static void arcmsr_hbaC_request_device_map(struct AdapterControlBlock
*acb
);
108 static void arcmsr_message_isr_bh_fn(struct work_struct
*work
);
109 static bool arcmsr_get_firmware_spec(struct AdapterControlBlock
*acb
);
110 static void arcmsr_start_adapter_bgrb(struct AdapterControlBlock
*acb
);
111 static void arcmsr_hbaC_message_isr(struct AdapterControlBlock
*pACB
);
112 static void arcmsr_hbaD_message_isr(struct AdapterControlBlock
*acb
);
113 static void arcmsr_hardware_reset(struct AdapterControlBlock
*acb
);
114 static const char *arcmsr_info(struct Scsi_Host
*);
115 static irqreturn_t
arcmsr_interrupt(struct AdapterControlBlock
*acb
);
116 static void arcmsr_free_irq(struct pci_dev
*, struct AdapterControlBlock
*);
117 static int arcmsr_adjust_disk_queue_depth(struct scsi_device
*sdev
, int queue_depth
)
119 if (queue_depth
> ARCMSR_MAX_CMD_PERLUN
)
120 queue_depth
= ARCMSR_MAX_CMD_PERLUN
;
121 return scsi_change_queue_depth(sdev
, queue_depth
);
124 static struct scsi_host_template arcmsr_scsi_host_template
= {
125 .module
= THIS_MODULE
,
126 .name
= "Areca SAS/SATA RAID driver",
128 .queuecommand
= arcmsr_queue_command
,
129 .eh_abort_handler
= arcmsr_abort
,
130 .eh_bus_reset_handler
= arcmsr_bus_reset
,
131 .bios_param
= arcmsr_bios_param
,
132 .change_queue_depth
= arcmsr_adjust_disk_queue_depth
,
133 .can_queue
= ARCMSR_MAX_OUTSTANDING_CMD
,
134 .this_id
= ARCMSR_SCSI_INITIATOR_ID
,
135 .sg_tablesize
= ARCMSR_DEFAULT_SG_ENTRIES
,
136 .max_sectors
= ARCMSR_MAX_XFER_SECTORS_C
,
137 .cmd_per_lun
= ARCMSR_MAX_CMD_PERLUN
,
138 .use_clustering
= ENABLE_CLUSTERING
,
139 .shost_attrs
= arcmsr_host_attrs
,
143 static struct pci_device_id arcmsr_device_id_table
[] = {
144 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1110
),
145 .driver_data
= ACB_ADAPTER_TYPE_A
},
146 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1120
),
147 .driver_data
= ACB_ADAPTER_TYPE_A
},
148 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1130
),
149 .driver_data
= ACB_ADAPTER_TYPE_A
},
150 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1160
),
151 .driver_data
= ACB_ADAPTER_TYPE_A
},
152 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1170
),
153 .driver_data
= ACB_ADAPTER_TYPE_A
},
154 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1200
),
155 .driver_data
= ACB_ADAPTER_TYPE_B
},
156 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1201
),
157 .driver_data
= ACB_ADAPTER_TYPE_B
},
158 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1202
),
159 .driver_data
= ACB_ADAPTER_TYPE_B
},
160 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1210
),
161 .driver_data
= ACB_ADAPTER_TYPE_A
},
162 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1214
),
163 .driver_data
= ACB_ADAPTER_TYPE_D
},
164 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1220
),
165 .driver_data
= ACB_ADAPTER_TYPE_A
},
166 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1230
),
167 .driver_data
= ACB_ADAPTER_TYPE_A
},
168 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1260
),
169 .driver_data
= ACB_ADAPTER_TYPE_A
},
170 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1270
),
171 .driver_data
= ACB_ADAPTER_TYPE_A
},
172 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1280
),
173 .driver_data
= ACB_ADAPTER_TYPE_A
},
174 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1380
),
175 .driver_data
= ACB_ADAPTER_TYPE_A
},
176 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1381
),
177 .driver_data
= ACB_ADAPTER_TYPE_A
},
178 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1680
),
179 .driver_data
= ACB_ADAPTER_TYPE_A
},
180 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1681
),
181 .driver_data
= ACB_ADAPTER_TYPE_A
},
182 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1880
),
183 .driver_data
= ACB_ADAPTER_TYPE_C
},
184 {0, 0}, /* Terminating entry */
186 MODULE_DEVICE_TABLE(pci
, arcmsr_device_id_table
);
188 static struct pci_driver arcmsr_pci_driver
= {
190 .id_table
= arcmsr_device_id_table
,
191 .probe
= arcmsr_probe
,
192 .remove
= arcmsr_remove
,
193 .suspend
= arcmsr_suspend
,
194 .resume
= arcmsr_resume
,
195 .shutdown
= arcmsr_shutdown
,
198 ****************************************************************************
199 ****************************************************************************
202 static void arcmsr_free_mu(struct AdapterControlBlock
*acb
)
204 switch (acb
->adapter_type
) {
205 case ACB_ADAPTER_TYPE_B
:
206 case ACB_ADAPTER_TYPE_D
: {
207 dma_free_coherent(&acb
->pdev
->dev
, acb
->roundup_ccbsize
,
208 acb
->dma_coherent2
, acb
->dma_coherent_handle2
);
214 static bool arcmsr_remap_pciregion(struct AdapterControlBlock
*acb
)
216 struct pci_dev
*pdev
= acb
->pdev
;
217 switch (acb
->adapter_type
){
218 case ACB_ADAPTER_TYPE_A
:{
219 acb
->pmuA
= ioremap(pci_resource_start(pdev
,0), pci_resource_len(pdev
,0));
221 printk(KERN_NOTICE
"arcmsr%d: memory mapping region fail \n", acb
->host
->host_no
);
226 case ACB_ADAPTER_TYPE_B
:{
227 void __iomem
*mem_base0
, *mem_base1
;
228 mem_base0
= ioremap(pci_resource_start(pdev
, 0), pci_resource_len(pdev
, 0));
230 printk(KERN_NOTICE
"arcmsr%d: memory mapping region fail \n", acb
->host
->host_no
);
233 mem_base1
= ioremap(pci_resource_start(pdev
, 2), pci_resource_len(pdev
, 2));
236 printk(KERN_NOTICE
"arcmsr%d: memory mapping region fail \n", acb
->host
->host_no
);
239 acb
->mem_base0
= mem_base0
;
240 acb
->mem_base1
= mem_base1
;
243 case ACB_ADAPTER_TYPE_C
:{
244 acb
->pmuC
= ioremap_nocache(pci_resource_start(pdev
, 1), pci_resource_len(pdev
, 1));
246 printk(KERN_NOTICE
"arcmsr%d: memory mapping region fail \n", acb
->host
->host_no
);
249 if (readl(&acb
->pmuC
->outbound_doorbell
) & ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE
) {
250 writel(ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE_DOORBELL_CLEAR
, &acb
->pmuC
->outbound_doorbell_clear
);/*clear interrupt*/
255 case ACB_ADAPTER_TYPE_D
: {
256 void __iomem
*mem_base0
;
257 unsigned long addr
, range
, flags
;
259 addr
= (unsigned long)pci_resource_start(pdev
, 0);
260 range
= pci_resource_len(pdev
, 0);
261 flags
= pci_resource_flags(pdev
, 0);
262 mem_base0
= ioremap(addr
, range
);
264 pr_notice("arcmsr%d: memory mapping region fail\n",
268 acb
->mem_base0
= mem_base0
;
275 static void arcmsr_unmap_pciregion(struct AdapterControlBlock
*acb
)
277 switch (acb
->adapter_type
) {
278 case ACB_ADAPTER_TYPE_A
:{
282 case ACB_ADAPTER_TYPE_B
:{
283 iounmap(acb
->mem_base0
);
284 iounmap(acb
->mem_base1
);
288 case ACB_ADAPTER_TYPE_C
:{
292 case ACB_ADAPTER_TYPE_D
:
293 iounmap(acb
->mem_base0
);
298 static irqreturn_t
arcmsr_do_interrupt(int irq
, void *dev_id
)
300 irqreturn_t handle_state
;
301 struct AdapterControlBlock
*acb
= dev_id
;
303 handle_state
= arcmsr_interrupt(acb
);
307 static int arcmsr_bios_param(struct scsi_device
*sdev
,
308 struct block_device
*bdev
, sector_t capacity
, int *geom
)
310 int ret
, heads
, sectors
, cylinders
, total_capacity
;
311 unsigned char *buffer
;/* return copy of block device's partition table */
313 buffer
= scsi_bios_ptable(bdev
);
315 ret
= scsi_partsize(buffer
, capacity
, &geom
[2], &geom
[0], &geom
[1]);
320 total_capacity
= capacity
;
323 cylinders
= total_capacity
/ (heads
* sectors
);
324 if (cylinders
> 1024) {
327 cylinders
= total_capacity
/ (heads
* sectors
);
335 static uint8_t arcmsr_hbaA_wait_msgint_ready(struct AdapterControlBlock
*acb
)
337 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
340 for (i
= 0; i
< 2000; i
++) {
341 if (readl(®
->outbound_intstatus
) &
342 ARCMSR_MU_OUTBOUND_MESSAGE0_INT
) {
343 writel(ARCMSR_MU_OUTBOUND_MESSAGE0_INT
,
344 ®
->outbound_intstatus
);
348 } /* max 20 seconds */
353 static uint8_t arcmsr_hbaB_wait_msgint_ready(struct AdapterControlBlock
*acb
)
355 struct MessageUnit_B
*reg
= acb
->pmuB
;
358 for (i
= 0; i
< 2000; i
++) {
359 if (readl(reg
->iop2drv_doorbell
)
360 & ARCMSR_IOP2DRV_MESSAGE_CMD_DONE
) {
361 writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN
,
362 reg
->iop2drv_doorbell
);
363 writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT
,
364 reg
->drv2iop_doorbell
);
368 } /* max 20 seconds */
373 static uint8_t arcmsr_hbaC_wait_msgint_ready(struct AdapterControlBlock
*pACB
)
375 struct MessageUnit_C __iomem
*phbcmu
= pACB
->pmuC
;
378 for (i
= 0; i
< 2000; i
++) {
379 if (readl(&phbcmu
->outbound_doorbell
)
380 & ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE
) {
381 writel(ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE_DOORBELL_CLEAR
,
382 &phbcmu
->outbound_doorbell_clear
); /*clear interrupt*/
386 } /* max 20 seconds */
391 static bool arcmsr_hbaD_wait_msgint_ready(struct AdapterControlBlock
*pACB
)
393 struct MessageUnit_D
*reg
= pACB
->pmuD
;
396 for (i
= 0; i
< 2000; i
++) {
397 if (readl(reg
->outbound_doorbell
)
398 & ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
) {
399 writel(ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
,
400 reg
->outbound_doorbell
);
404 } /* max 20 seconds */
408 static void arcmsr_hbaA_flush_cache(struct AdapterControlBlock
*acb
)
410 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
411 int retry_count
= 30;
412 writel(ARCMSR_INBOUND_MESG0_FLUSH_CACHE
, ®
->inbound_msgaddr0
);
414 if (arcmsr_hbaA_wait_msgint_ready(acb
))
418 printk(KERN_NOTICE
"arcmsr%d: wait 'flush adapter cache' \
419 timeout, retry count down = %d \n", acb
->host
->host_no
, retry_count
);
421 } while (retry_count
!= 0);
424 static void arcmsr_hbaB_flush_cache(struct AdapterControlBlock
*acb
)
426 struct MessageUnit_B
*reg
= acb
->pmuB
;
427 int retry_count
= 30;
428 writel(ARCMSR_MESSAGE_FLUSH_CACHE
, reg
->drv2iop_doorbell
);
430 if (arcmsr_hbaB_wait_msgint_ready(acb
))
434 printk(KERN_NOTICE
"arcmsr%d: wait 'flush adapter cache' \
435 timeout,retry count down = %d \n", acb
->host
->host_no
, retry_count
);
437 } while (retry_count
!= 0);
440 static void arcmsr_hbaC_flush_cache(struct AdapterControlBlock
*pACB
)
442 struct MessageUnit_C __iomem
*reg
= pACB
->pmuC
;
443 int retry_count
= 30;/* enlarge wait flush adapter cache time: 10 minute */
444 writel(ARCMSR_INBOUND_MESG0_FLUSH_CACHE
, ®
->inbound_msgaddr0
);
445 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
447 if (arcmsr_hbaC_wait_msgint_ready(pACB
)) {
451 printk(KERN_NOTICE
"arcmsr%d: wait 'flush adapter cache' \
452 timeout,retry count down = %d \n", pACB
->host
->host_no
, retry_count
);
454 } while (retry_count
!= 0);
458 static void arcmsr_hbaD_flush_cache(struct AdapterControlBlock
*pACB
)
460 int retry_count
= 15;
461 struct MessageUnit_D
*reg
= pACB
->pmuD
;
463 writel(ARCMSR_INBOUND_MESG0_FLUSH_CACHE
, reg
->inbound_msgaddr0
);
465 if (arcmsr_hbaD_wait_msgint_ready(pACB
))
469 pr_notice("arcmsr%d: wait 'flush adapter "
470 "cache' timeout, retry count down = %d\n",
471 pACB
->host
->host_no
, retry_count
);
472 } while (retry_count
!= 0);
475 static void arcmsr_flush_adapter_cache(struct AdapterControlBlock
*acb
)
477 switch (acb
->adapter_type
) {
479 case ACB_ADAPTER_TYPE_A
: {
480 arcmsr_hbaA_flush_cache(acb
);
484 case ACB_ADAPTER_TYPE_B
: {
485 arcmsr_hbaB_flush_cache(acb
);
488 case ACB_ADAPTER_TYPE_C
: {
489 arcmsr_hbaC_flush_cache(acb
);
492 case ACB_ADAPTER_TYPE_D
:
493 arcmsr_hbaD_flush_cache(acb
);
498 static int arcmsr_alloc_ccb_pool(struct AdapterControlBlock
*acb
)
500 struct pci_dev
*pdev
= acb
->pdev
;
502 dma_addr_t dma_coherent_handle
;
503 struct CommandControlBlock
*ccb_tmp
;
505 dma_addr_t cdb_phyaddr
;
506 unsigned long roundup_ccbsize
;
507 unsigned long max_xfer_len
;
508 unsigned long max_sg_entrys
;
509 uint32_t firm_config_version
;
511 for (i
= 0; i
< ARCMSR_MAX_TARGETID
; i
++)
512 for (j
= 0; j
< ARCMSR_MAX_TARGETLUN
; j
++)
513 acb
->devstate
[i
][j
] = ARECA_RAID_GONE
;
515 max_xfer_len
= ARCMSR_MAX_XFER_LEN
;
516 max_sg_entrys
= ARCMSR_DEFAULT_SG_ENTRIES
;
517 firm_config_version
= acb
->firm_cfg_version
;
518 if((firm_config_version
& 0xFF) >= 3){
519 max_xfer_len
= (ARCMSR_CDB_SG_PAGE_LENGTH
<< ((firm_config_version
>> 8) & 0xFF)) * 1024;/* max 4M byte */
520 max_sg_entrys
= (max_xfer_len
/4096);
522 acb
->host
->max_sectors
= max_xfer_len
/512;
523 acb
->host
->sg_tablesize
= max_sg_entrys
;
524 roundup_ccbsize
= roundup(sizeof(struct CommandControlBlock
) + (max_sg_entrys
- 1) * sizeof(struct SG64ENTRY
), 32);
525 acb
->uncache_size
= roundup_ccbsize
* ARCMSR_MAX_FREECCB_NUM
;
526 dma_coherent
= dma_alloc_coherent(&pdev
->dev
, acb
->uncache_size
, &dma_coherent_handle
, GFP_KERNEL
);
528 printk(KERN_NOTICE
"arcmsr%d: dma_alloc_coherent got error\n", acb
->host
->host_no
);
531 acb
->dma_coherent
= dma_coherent
;
532 acb
->dma_coherent_handle
= dma_coherent_handle
;
533 memset(dma_coherent
, 0, acb
->uncache_size
);
534 ccb_tmp
= dma_coherent
;
535 acb
->vir2phy_offset
= (unsigned long)dma_coherent
- (unsigned long)dma_coherent_handle
;
536 for(i
= 0; i
< ARCMSR_MAX_FREECCB_NUM
; i
++){
537 cdb_phyaddr
= dma_coherent_handle
+ offsetof(struct CommandControlBlock
, arcmsr_cdb
);
538 switch (acb
->adapter_type
) {
539 case ACB_ADAPTER_TYPE_A
:
540 case ACB_ADAPTER_TYPE_B
:
541 ccb_tmp
->cdb_phyaddr
= cdb_phyaddr
>> 5;
543 case ACB_ADAPTER_TYPE_C
:
544 case ACB_ADAPTER_TYPE_D
:
545 ccb_tmp
->cdb_phyaddr
= cdb_phyaddr
;
548 acb
->pccb_pool
[i
] = ccb_tmp
;
550 INIT_LIST_HEAD(&ccb_tmp
->list
);
551 list_add_tail(&ccb_tmp
->list
, &acb
->ccb_free_list
);
552 ccb_tmp
= (struct CommandControlBlock
*)((unsigned long)ccb_tmp
+ roundup_ccbsize
);
553 dma_coherent_handle
= dma_coherent_handle
+ roundup_ccbsize
;
558 static void arcmsr_message_isr_bh_fn(struct work_struct
*work
)
560 struct AdapterControlBlock
*acb
= container_of(work
,
561 struct AdapterControlBlock
, arcmsr_do_message_isr_bh
);
562 char *acb_dev_map
= (char *)acb
->device_map
;
563 uint32_t __iomem
*signature
= NULL
;
564 char __iomem
*devicemap
= NULL
;
566 struct scsi_device
*psdev
;
569 switch (acb
->adapter_type
) {
570 case ACB_ADAPTER_TYPE_A
: {
571 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
573 signature
= (uint32_t __iomem
*)(®
->message_rwbuffer
[0]);
574 devicemap
= (char __iomem
*)(®
->message_rwbuffer
[21]);
577 case ACB_ADAPTER_TYPE_B
: {
578 struct MessageUnit_B
*reg
= acb
->pmuB
;
580 signature
= (uint32_t __iomem
*)(®
->message_rwbuffer
[0]);
581 devicemap
= (char __iomem
*)(®
->message_rwbuffer
[21]);
584 case ACB_ADAPTER_TYPE_C
: {
585 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
587 signature
= (uint32_t __iomem
*)(®
->msgcode_rwbuffer
[0]);
588 devicemap
= (char __iomem
*)(®
->msgcode_rwbuffer
[21]);
591 case ACB_ADAPTER_TYPE_D
: {
592 struct MessageUnit_D
*reg
= acb
->pmuD
;
594 signature
= (uint32_t __iomem
*)(®
->msgcode_rwbuffer
[0]);
595 devicemap
= (char __iomem
*)(®
->msgcode_rwbuffer
[21]);
599 atomic_inc(&acb
->rq_map_token
);
600 if (readl(signature
) != ARCMSR_SIGNATURE_GET_CONFIG
)
602 for (target
= 0; target
< ARCMSR_MAX_TARGETID
- 1;
604 temp
= readb(devicemap
);
605 diff
= (*acb_dev_map
) ^ temp
;
608 for (lun
= 0; lun
< ARCMSR_MAX_TARGETLUN
;
610 if ((diff
& 0x01) == 1 &&
611 (temp
& 0x01) == 1) {
612 scsi_add_device(acb
->host
,
614 } else if ((diff
& 0x01) == 1
615 && (temp
& 0x01) == 0) {
616 psdev
= scsi_device_lookup(acb
->host
,
619 scsi_remove_device(psdev
);
620 scsi_device_put(psdev
);
633 arcmsr_request_irq(struct pci_dev
*pdev
, struct AdapterControlBlock
*acb
)
636 struct msix_entry entries
[ARCMST_NUM_MSIX_VECTORS
];
638 for (i
= 0; i
< ARCMST_NUM_MSIX_VECTORS
; i
++)
639 entries
[i
].entry
= i
;
640 r
= pci_enable_msix_range(pdev
, entries
, 1, ARCMST_NUM_MSIX_VECTORS
);
643 acb
->msix_vector_count
= r
;
644 for (i
= 0; i
< r
; i
++) {
645 if (request_irq(entries
[i
].vector
,
646 arcmsr_do_interrupt
, 0, "arcmsr", acb
)) {
647 pr_warn("arcmsr%d: request_irq =%d failed!\n",
648 acb
->host
->host_no
, entries
[i
].vector
);
649 for (j
= 0 ; j
< i
; j
++)
650 free_irq(entries
[j
].vector
, acb
);
651 pci_disable_msix(pdev
);
654 acb
->entries
[i
] = entries
[i
];
656 acb
->acb_flags
|= ACB_F_MSIX_ENABLED
;
657 pr_info("arcmsr%d: msi-x enabled\n", acb
->host
->host_no
);
660 if (pci_enable_msi_exact(pdev
, 1) < 0)
662 if (request_irq(pdev
->irq
, arcmsr_do_interrupt
,
663 IRQF_SHARED
, "arcmsr", acb
)) {
664 pr_warn("arcmsr%d: request_irq =%d failed!\n",
665 acb
->host
->host_no
, pdev
->irq
);
666 pci_disable_msi(pdev
);
669 acb
->acb_flags
|= ACB_F_MSI_ENABLED
;
670 pr_info("arcmsr%d: msi enabled\n", acb
->host
->host_no
);
673 if (request_irq(pdev
->irq
, arcmsr_do_interrupt
,
674 IRQF_SHARED
, "arcmsr", acb
)) {
675 pr_warn("arcmsr%d: request_irq = %d failed!\n",
676 acb
->host
->host_no
, pdev
->irq
);
682 static int arcmsr_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
684 struct Scsi_Host
*host
;
685 struct AdapterControlBlock
*acb
;
688 error
= pci_enable_device(pdev
);
692 host
= scsi_host_alloc(&arcmsr_scsi_host_template
, sizeof(struct AdapterControlBlock
));
694 goto pci_disable_dev
;
696 error
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(64));
698 error
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
701 "scsi%d: No suitable DMA mask available\n",
703 goto scsi_host_release
;
706 init_waitqueue_head(&wait_q
);
707 bus
= pdev
->bus
->number
;
708 dev_fun
= pdev
->devfn
;
709 acb
= (struct AdapterControlBlock
*) host
->hostdata
;
710 memset(acb
,0,sizeof(struct AdapterControlBlock
));
713 host
->max_lun
= ARCMSR_MAX_TARGETLUN
;
714 host
->max_id
= ARCMSR_MAX_TARGETID
; /*16:8*/
715 host
->max_cmd_len
= 16; /*this is issue of 64bit LBA ,over 2T byte*/
716 host
->can_queue
= ARCMSR_MAX_OUTSTANDING_CMD
;
717 host
->cmd_per_lun
= ARCMSR_MAX_CMD_PERLUN
;
718 host
->this_id
= ARCMSR_SCSI_INITIATOR_ID
;
719 host
->unique_id
= (bus
<< 8) | dev_fun
;
720 pci_set_drvdata(pdev
, host
);
721 pci_set_master(pdev
);
722 error
= pci_request_regions(pdev
, "arcmsr");
724 goto scsi_host_release
;
726 spin_lock_init(&acb
->eh_lock
);
727 spin_lock_init(&acb
->ccblist_lock
);
728 spin_lock_init(&acb
->postq_lock
);
729 spin_lock_init(&acb
->doneq_lock
);
730 spin_lock_init(&acb
->rqbuffer_lock
);
731 spin_lock_init(&acb
->wqbuffer_lock
);
732 acb
->acb_flags
|= (ACB_F_MESSAGE_WQBUFFER_CLEARED
|
733 ACB_F_MESSAGE_RQBUFFER_CLEARED
|
734 ACB_F_MESSAGE_WQBUFFER_READED
);
735 acb
->acb_flags
&= ~ACB_F_SCSISTOPADAPTER
;
736 INIT_LIST_HEAD(&acb
->ccb_free_list
);
737 acb
->adapter_type
= id
->driver_data
;
738 error
= arcmsr_remap_pciregion(acb
);
740 goto pci_release_regs
;
742 error
= arcmsr_get_firmware_spec(acb
);
744 goto unmap_pci_region
;
746 error
= arcmsr_alloc_ccb_pool(acb
);
750 error
= scsi_add_host(host
, &pdev
->dev
);
754 if (arcmsr_request_irq(pdev
, acb
) == FAILED
)
755 goto scsi_host_remove
;
756 arcmsr_iop_init(acb
);
757 INIT_WORK(&acb
->arcmsr_do_message_isr_bh
, arcmsr_message_isr_bh_fn
);
758 atomic_set(&acb
->rq_map_token
, 16);
759 atomic_set(&acb
->ante_token_value
, 16);
760 acb
->fw_flag
= FW_NORMAL
;
761 init_timer(&acb
->eternal_timer
);
762 acb
->eternal_timer
.expires
= jiffies
+ msecs_to_jiffies(6 * HZ
);
763 acb
->eternal_timer
.data
= (unsigned long) acb
;
764 acb
->eternal_timer
.function
= &arcmsr_request_device_map
;
765 add_timer(&acb
->eternal_timer
);
766 if(arcmsr_alloc_sysfs_attr(acb
))
768 scsi_scan_host(host
);
771 del_timer_sync(&acb
->eternal_timer
);
772 flush_work(&acb
->arcmsr_do_message_isr_bh
);
773 arcmsr_stop_adapter_bgrb(acb
);
774 arcmsr_flush_adapter_cache(acb
);
775 arcmsr_free_irq(pdev
, acb
);
777 scsi_remove_host(host
);
779 arcmsr_free_ccb_pool(acb
);
783 arcmsr_unmap_pciregion(acb
);
785 pci_release_regions(pdev
);
789 pci_disable_device(pdev
);
793 static void arcmsr_free_irq(struct pci_dev
*pdev
,
794 struct AdapterControlBlock
*acb
)
798 if (acb
->acb_flags
& ACB_F_MSI_ENABLED
) {
799 free_irq(pdev
->irq
, acb
);
800 pci_disable_msi(pdev
);
801 } else if (acb
->acb_flags
& ACB_F_MSIX_ENABLED
) {
802 for (i
= 0; i
< acb
->msix_vector_count
; i
++)
803 free_irq(acb
->entries
[i
].vector
, acb
);
804 pci_disable_msix(pdev
);
806 free_irq(pdev
->irq
, acb
);
809 static int arcmsr_suspend(struct pci_dev
*pdev
, pm_message_t state
)
811 uint32_t intmask_org
;
812 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
813 struct AdapterControlBlock
*acb
=
814 (struct AdapterControlBlock
*)host
->hostdata
;
816 intmask_org
= arcmsr_disable_outbound_ints(acb
);
817 arcmsr_free_irq(pdev
, acb
);
818 del_timer_sync(&acb
->eternal_timer
);
819 flush_work(&acb
->arcmsr_do_message_isr_bh
);
820 arcmsr_stop_adapter_bgrb(acb
);
821 arcmsr_flush_adapter_cache(acb
);
822 pci_set_drvdata(pdev
, host
);
823 pci_save_state(pdev
);
824 pci_disable_device(pdev
);
825 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
829 static int arcmsr_resume(struct pci_dev
*pdev
)
832 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
833 struct AdapterControlBlock
*acb
=
834 (struct AdapterControlBlock
*)host
->hostdata
;
836 pci_set_power_state(pdev
, PCI_D0
);
837 pci_enable_wake(pdev
, PCI_D0
, 0);
838 pci_restore_state(pdev
);
839 if (pci_enable_device(pdev
)) {
840 pr_warn("%s: pci_enable_device error\n", __func__
);
843 error
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(64));
845 error
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
847 pr_warn("scsi%d: No suitable DMA mask available\n",
849 goto controller_unregister
;
852 pci_set_master(pdev
);
853 if (arcmsr_request_irq(pdev
, acb
) == FAILED
)
854 goto controller_stop
;
855 arcmsr_iop_init(acb
);
856 INIT_WORK(&acb
->arcmsr_do_message_isr_bh
, arcmsr_message_isr_bh_fn
);
857 atomic_set(&acb
->rq_map_token
, 16);
858 atomic_set(&acb
->ante_token_value
, 16);
859 acb
->fw_flag
= FW_NORMAL
;
860 init_timer(&acb
->eternal_timer
);
861 acb
->eternal_timer
.expires
= jiffies
+ msecs_to_jiffies(6 * HZ
);
862 acb
->eternal_timer
.data
= (unsigned long) acb
;
863 acb
->eternal_timer
.function
= &arcmsr_request_device_map
;
864 add_timer(&acb
->eternal_timer
);
867 arcmsr_stop_adapter_bgrb(acb
);
868 arcmsr_flush_adapter_cache(acb
);
869 controller_unregister
:
870 scsi_remove_host(host
);
871 arcmsr_free_ccb_pool(acb
);
872 arcmsr_unmap_pciregion(acb
);
873 pci_release_regions(pdev
);
875 pci_disable_device(pdev
);
879 static uint8_t arcmsr_hbaA_abort_allcmd(struct AdapterControlBlock
*acb
)
881 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
882 writel(ARCMSR_INBOUND_MESG0_ABORT_CMD
, ®
->inbound_msgaddr0
);
883 if (!arcmsr_hbaA_wait_msgint_ready(acb
)) {
885 "arcmsr%d: wait 'abort all outstanding command' timeout\n"
886 , acb
->host
->host_no
);
892 static uint8_t arcmsr_hbaB_abort_allcmd(struct AdapterControlBlock
*acb
)
894 struct MessageUnit_B
*reg
= acb
->pmuB
;
896 writel(ARCMSR_MESSAGE_ABORT_CMD
, reg
->drv2iop_doorbell
);
897 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
899 "arcmsr%d: wait 'abort all outstanding command' timeout\n"
900 , acb
->host
->host_no
);
905 static uint8_t arcmsr_hbaC_abort_allcmd(struct AdapterControlBlock
*pACB
)
907 struct MessageUnit_C __iomem
*reg
= pACB
->pmuC
;
908 writel(ARCMSR_INBOUND_MESG0_ABORT_CMD
, ®
->inbound_msgaddr0
);
909 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
910 if (!arcmsr_hbaC_wait_msgint_ready(pACB
)) {
912 "arcmsr%d: wait 'abort all outstanding command' timeout\n"
913 , pACB
->host
->host_no
);
919 static uint8_t arcmsr_hbaD_abort_allcmd(struct AdapterControlBlock
*pACB
)
921 struct MessageUnit_D
*reg
= pACB
->pmuD
;
923 writel(ARCMSR_INBOUND_MESG0_ABORT_CMD
, reg
->inbound_msgaddr0
);
924 if (!arcmsr_hbaD_wait_msgint_ready(pACB
)) {
925 pr_notice("arcmsr%d: wait 'abort all outstanding "
926 "command' timeout\n", pACB
->host
->host_no
);
932 static uint8_t arcmsr_abort_allcmd(struct AdapterControlBlock
*acb
)
935 switch (acb
->adapter_type
) {
936 case ACB_ADAPTER_TYPE_A
: {
937 rtnval
= arcmsr_hbaA_abort_allcmd(acb
);
941 case ACB_ADAPTER_TYPE_B
: {
942 rtnval
= arcmsr_hbaB_abort_allcmd(acb
);
946 case ACB_ADAPTER_TYPE_C
: {
947 rtnval
= arcmsr_hbaC_abort_allcmd(acb
);
951 case ACB_ADAPTER_TYPE_D
:
952 rtnval
= arcmsr_hbaD_abort_allcmd(acb
);
958 static void arcmsr_pci_unmap_dma(struct CommandControlBlock
*ccb
)
960 struct scsi_cmnd
*pcmd
= ccb
->pcmd
;
962 scsi_dma_unmap(pcmd
);
965 static void arcmsr_ccb_complete(struct CommandControlBlock
*ccb
)
967 struct AdapterControlBlock
*acb
= ccb
->acb
;
968 struct scsi_cmnd
*pcmd
= ccb
->pcmd
;
970 atomic_dec(&acb
->ccboutstandingcount
);
971 arcmsr_pci_unmap_dma(ccb
);
972 ccb
->startdone
= ARCMSR_CCB_DONE
;
973 spin_lock_irqsave(&acb
->ccblist_lock
, flags
);
974 list_add_tail(&ccb
->list
, &acb
->ccb_free_list
);
975 spin_unlock_irqrestore(&acb
->ccblist_lock
, flags
);
976 pcmd
->scsi_done(pcmd
);
979 static void arcmsr_report_sense_info(struct CommandControlBlock
*ccb
)
982 struct scsi_cmnd
*pcmd
= ccb
->pcmd
;
983 struct SENSE_DATA
*sensebuffer
= (struct SENSE_DATA
*)pcmd
->sense_buffer
;
984 pcmd
->result
= DID_OK
<< 16;
986 int sense_data_length
=
987 sizeof(struct SENSE_DATA
) < SCSI_SENSE_BUFFERSIZE
988 ? sizeof(struct SENSE_DATA
) : SCSI_SENSE_BUFFERSIZE
;
989 memset(sensebuffer
, 0, SCSI_SENSE_BUFFERSIZE
);
990 memcpy(sensebuffer
, ccb
->arcmsr_cdb
.SenseData
, sense_data_length
);
991 sensebuffer
->ErrorCode
= SCSI_SENSE_CURRENT_ERRORS
;
992 sensebuffer
->Valid
= 1;
996 static u32
arcmsr_disable_outbound_ints(struct AdapterControlBlock
*acb
)
999 switch (acb
->adapter_type
) {
1000 case ACB_ADAPTER_TYPE_A
: {
1001 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1002 orig_mask
= readl(®
->outbound_intmask
);
1003 writel(orig_mask
|ARCMSR_MU_OUTBOUND_ALL_INTMASKENABLE
, \
1004 ®
->outbound_intmask
);
1007 case ACB_ADAPTER_TYPE_B
: {
1008 struct MessageUnit_B
*reg
= acb
->pmuB
;
1009 orig_mask
= readl(reg
->iop2drv_doorbell_mask
);
1010 writel(0, reg
->iop2drv_doorbell_mask
);
1013 case ACB_ADAPTER_TYPE_C
:{
1014 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
1015 /* disable all outbound interrupt */
1016 orig_mask
= readl(®
->host_int_mask
); /* disable outbound message0 int */
1017 writel(orig_mask
|ARCMSR_HBCMU_ALL_INTMASKENABLE
, ®
->host_int_mask
);
1020 case ACB_ADAPTER_TYPE_D
: {
1021 struct MessageUnit_D
*reg
= acb
->pmuD
;
1022 /* disable all outbound interrupt */
1023 writel(ARCMSR_ARC1214_ALL_INT_DISABLE
, reg
->pcief0_int_enable
);
1030 static void arcmsr_report_ccb_state(struct AdapterControlBlock
*acb
,
1031 struct CommandControlBlock
*ccb
, bool error
)
1034 id
= ccb
->pcmd
->device
->id
;
1035 lun
= ccb
->pcmd
->device
->lun
;
1037 if (acb
->devstate
[id
][lun
] == ARECA_RAID_GONE
)
1038 acb
->devstate
[id
][lun
] = ARECA_RAID_GOOD
;
1039 ccb
->pcmd
->result
= DID_OK
<< 16;
1040 arcmsr_ccb_complete(ccb
);
1042 switch (ccb
->arcmsr_cdb
.DeviceStatus
) {
1043 case ARCMSR_DEV_SELECT_TIMEOUT
: {
1044 acb
->devstate
[id
][lun
] = ARECA_RAID_GONE
;
1045 ccb
->pcmd
->result
= DID_NO_CONNECT
<< 16;
1046 arcmsr_ccb_complete(ccb
);
1050 case ARCMSR_DEV_ABORTED
:
1052 case ARCMSR_DEV_INIT_FAIL
: {
1053 acb
->devstate
[id
][lun
] = ARECA_RAID_GONE
;
1054 ccb
->pcmd
->result
= DID_BAD_TARGET
<< 16;
1055 arcmsr_ccb_complete(ccb
);
1059 case ARCMSR_DEV_CHECK_CONDITION
: {
1060 acb
->devstate
[id
][lun
] = ARECA_RAID_GOOD
;
1061 arcmsr_report_sense_info(ccb
);
1062 arcmsr_ccb_complete(ccb
);
1068 "arcmsr%d: scsi id = %d lun = %d isr get command error done, \
1069 but got unknown DeviceStatus = 0x%x \n"
1070 , acb
->host
->host_no
1073 , ccb
->arcmsr_cdb
.DeviceStatus
);
1074 acb
->devstate
[id
][lun
] = ARECA_RAID_GONE
;
1075 ccb
->pcmd
->result
= DID_NO_CONNECT
<< 16;
1076 arcmsr_ccb_complete(ccb
);
1082 static void arcmsr_drain_donequeue(struct AdapterControlBlock
*acb
, struct CommandControlBlock
*pCCB
, bool error
)
1085 if ((pCCB
->acb
!= acb
) || (pCCB
->startdone
!= ARCMSR_CCB_START
)) {
1086 if (pCCB
->startdone
== ARCMSR_CCB_ABORTED
) {
1087 struct scsi_cmnd
*abortcmd
= pCCB
->pcmd
;
1089 id
= abortcmd
->device
->id
;
1090 lun
= abortcmd
->device
->lun
;
1091 abortcmd
->result
|= DID_ABORT
<< 16;
1092 arcmsr_ccb_complete(pCCB
);
1093 printk(KERN_NOTICE
"arcmsr%d: pCCB ='0x%p' isr got aborted command \n",
1094 acb
->host
->host_no
, pCCB
);
1098 printk(KERN_NOTICE
"arcmsr%d: isr get an illegal ccb command \
1100 "ccb = '0x%p' ccbacb = '0x%p' startdone = 0x%x"
1101 " ccboutstandingcount = %d \n"
1102 , acb
->host
->host_no
1107 , atomic_read(&acb
->ccboutstandingcount
));
1110 arcmsr_report_ccb_state(acb
, pCCB
, error
);
1113 static void arcmsr_done4abort_postqueue(struct AdapterControlBlock
*acb
)
1116 uint32_t flag_ccb
, ccb_cdb_phy
;
1117 struct ARCMSR_CDB
*pARCMSR_CDB
;
1119 struct CommandControlBlock
*pCCB
;
1120 switch (acb
->adapter_type
) {
1122 case ACB_ADAPTER_TYPE_A
: {
1123 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1124 uint32_t outbound_intstatus
;
1125 outbound_intstatus
= readl(®
->outbound_intstatus
) &
1126 acb
->outbound_int_enable
;
1127 /*clear and abort all outbound posted Q*/
1128 writel(outbound_intstatus
, ®
->outbound_intstatus
);/*clear interrupt*/
1129 while(((flag_ccb
= readl(®
->outbound_queueport
)) != 0xFFFFFFFF)
1130 && (i
++ < ARCMSR_MAX_OUTSTANDING_CMD
)) {
1131 pARCMSR_CDB
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ (flag_ccb
<< 5));/*frame must be 32 bytes aligned*/
1132 pCCB
= container_of(pARCMSR_CDB
, struct CommandControlBlock
, arcmsr_cdb
);
1133 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
1134 arcmsr_drain_donequeue(acb
, pCCB
, error
);
1139 case ACB_ADAPTER_TYPE_B
: {
1140 struct MessageUnit_B
*reg
= acb
->pmuB
;
1141 /*clear all outbound posted Q*/
1142 writel(ARCMSR_DOORBELL_INT_CLEAR_PATTERN
, reg
->iop2drv_doorbell
); /* clear doorbell interrupt */
1143 for (i
= 0; i
< ARCMSR_MAX_HBB_POSTQUEUE
; i
++) {
1144 flag_ccb
= reg
->done_qbuffer
[i
];
1145 if (flag_ccb
!= 0) {
1146 reg
->done_qbuffer
[i
] = 0;
1147 pARCMSR_CDB
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+(flag_ccb
<< 5));/*frame must be 32 bytes aligned*/
1148 pCCB
= container_of(pARCMSR_CDB
, struct CommandControlBlock
, arcmsr_cdb
);
1149 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
1150 arcmsr_drain_donequeue(acb
, pCCB
, error
);
1152 reg
->post_qbuffer
[i
] = 0;
1154 reg
->doneq_index
= 0;
1155 reg
->postq_index
= 0;
1158 case ACB_ADAPTER_TYPE_C
: {
1159 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
1160 while ((readl(®
->host_int_status
) & ARCMSR_HBCMU_OUTBOUND_POSTQUEUE_ISR
) && (i
++ < ARCMSR_MAX_OUTSTANDING_CMD
)) {
1162 flag_ccb
= readl(®
->outbound_queueport_low
);
1163 ccb_cdb_phy
= (flag_ccb
& 0xFFFFFFF0);
1164 pARCMSR_CDB
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ccb_cdb_phy
);/*frame must be 32 bytes aligned*/
1165 pCCB
= container_of(pARCMSR_CDB
, struct CommandControlBlock
, arcmsr_cdb
);
1166 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
) ? true : false;
1167 arcmsr_drain_donequeue(acb
, pCCB
, error
);
1171 case ACB_ADAPTER_TYPE_D
: {
1172 struct MessageUnit_D
*pmu
= acb
->pmuD
;
1173 uint32_t outbound_write_pointer
;
1174 uint32_t doneq_index
, index_stripped
, addressLow
, residual
, toggle
;
1175 unsigned long flags
;
1177 residual
= atomic_read(&acb
->ccboutstandingcount
);
1178 for (i
= 0; i
< residual
; i
++) {
1179 spin_lock_irqsave(&acb
->doneq_lock
, flags
);
1180 outbound_write_pointer
=
1181 pmu
->done_qbuffer
[0].addressLow
+ 1;
1182 doneq_index
= pmu
->doneq_index
;
1183 if ((doneq_index
& 0xFFF) !=
1184 (outbound_write_pointer
& 0xFFF)) {
1185 toggle
= doneq_index
& 0x4000;
1186 index_stripped
= (doneq_index
& 0xFFF) + 1;
1187 index_stripped
%= ARCMSR_MAX_ARC1214_DONEQUEUE
;
1188 pmu
->doneq_index
= index_stripped
? (index_stripped
| toggle
) :
1189 ((toggle
^ 0x4000) + 1);
1190 doneq_index
= pmu
->doneq_index
;
1191 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
1192 addressLow
= pmu
->done_qbuffer
[doneq_index
&
1194 ccb_cdb_phy
= (addressLow
& 0xFFFFFFF0);
1195 pARCMSR_CDB
= (struct ARCMSR_CDB
*)
1196 (acb
->vir2phy_offset
+ ccb_cdb_phy
);
1197 pCCB
= container_of(pARCMSR_CDB
,
1198 struct CommandControlBlock
, arcmsr_cdb
);
1199 error
= (addressLow
&
1200 ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
) ?
1202 arcmsr_drain_donequeue(acb
, pCCB
, error
);
1204 pmu
->outboundlist_read_pointer
);
1206 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
1210 pmu
->postq_index
= 0;
1211 pmu
->doneq_index
= 0x40FF;
1217 static void arcmsr_remove(struct pci_dev
*pdev
)
1219 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
1220 struct AdapterControlBlock
*acb
=
1221 (struct AdapterControlBlock
*) host
->hostdata
;
1223 arcmsr_free_sysfs_attr(acb
);
1224 scsi_remove_host(host
);
1225 flush_work(&acb
->arcmsr_do_message_isr_bh
);
1226 del_timer_sync(&acb
->eternal_timer
);
1227 arcmsr_disable_outbound_ints(acb
);
1228 arcmsr_stop_adapter_bgrb(acb
);
1229 arcmsr_flush_adapter_cache(acb
);
1230 acb
->acb_flags
|= ACB_F_SCSISTOPADAPTER
;
1231 acb
->acb_flags
&= ~ACB_F_IOP_INITED
;
1233 for (poll_count
= 0; poll_count
< ARCMSR_MAX_OUTSTANDING_CMD
; poll_count
++){
1234 if (!atomic_read(&acb
->ccboutstandingcount
))
1236 arcmsr_interrupt(acb
);/* FIXME: need spinlock */
1240 if (atomic_read(&acb
->ccboutstandingcount
)) {
1243 arcmsr_abort_allcmd(acb
);
1244 arcmsr_done4abort_postqueue(acb
);
1245 for (i
= 0; i
< ARCMSR_MAX_FREECCB_NUM
; i
++) {
1246 struct CommandControlBlock
*ccb
= acb
->pccb_pool
[i
];
1247 if (ccb
->startdone
== ARCMSR_CCB_START
) {
1248 ccb
->startdone
= ARCMSR_CCB_ABORTED
;
1249 ccb
->pcmd
->result
= DID_ABORT
<< 16;
1250 arcmsr_ccb_complete(ccb
);
1254 arcmsr_free_irq(pdev
, acb
);
1255 arcmsr_free_ccb_pool(acb
);
1256 arcmsr_free_mu(acb
);
1257 arcmsr_unmap_pciregion(acb
);
1258 pci_release_regions(pdev
);
1259 scsi_host_put(host
);
1260 pci_disable_device(pdev
);
1263 static void arcmsr_shutdown(struct pci_dev
*pdev
)
1265 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
1266 struct AdapterControlBlock
*acb
=
1267 (struct AdapterControlBlock
*)host
->hostdata
;
1268 del_timer_sync(&acb
->eternal_timer
);
1269 arcmsr_disable_outbound_ints(acb
);
1270 arcmsr_free_irq(pdev
, acb
);
1271 flush_work(&acb
->arcmsr_do_message_isr_bh
);
1272 arcmsr_stop_adapter_bgrb(acb
);
1273 arcmsr_flush_adapter_cache(acb
);
1276 static int arcmsr_module_init(void)
1279 error
= pci_register_driver(&arcmsr_pci_driver
);
1283 static void arcmsr_module_exit(void)
1285 pci_unregister_driver(&arcmsr_pci_driver
);
1287 module_init(arcmsr_module_init
);
1288 module_exit(arcmsr_module_exit
);
1290 static void arcmsr_enable_outbound_ints(struct AdapterControlBlock
*acb
,
1294 switch (acb
->adapter_type
) {
1296 case ACB_ADAPTER_TYPE_A
: {
1297 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1298 mask
= intmask_org
& ~(ARCMSR_MU_OUTBOUND_POSTQUEUE_INTMASKENABLE
|
1299 ARCMSR_MU_OUTBOUND_DOORBELL_INTMASKENABLE
|
1300 ARCMSR_MU_OUTBOUND_MESSAGE0_INTMASKENABLE
);
1301 writel(mask
, ®
->outbound_intmask
);
1302 acb
->outbound_int_enable
= ~(intmask_org
& mask
) & 0x000000ff;
1306 case ACB_ADAPTER_TYPE_B
: {
1307 struct MessageUnit_B
*reg
= acb
->pmuB
;
1308 mask
= intmask_org
| (ARCMSR_IOP2DRV_DATA_WRITE_OK
|
1309 ARCMSR_IOP2DRV_DATA_READ_OK
|
1310 ARCMSR_IOP2DRV_CDB_DONE
|
1311 ARCMSR_IOP2DRV_MESSAGE_CMD_DONE
);
1312 writel(mask
, reg
->iop2drv_doorbell_mask
);
1313 acb
->outbound_int_enable
= (intmask_org
| mask
) & 0x0000000f;
1316 case ACB_ADAPTER_TYPE_C
: {
1317 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
1318 mask
= ~(ARCMSR_HBCMU_UTILITY_A_ISR_MASK
| ARCMSR_HBCMU_OUTBOUND_DOORBELL_ISR_MASK
|ARCMSR_HBCMU_OUTBOUND_POSTQUEUE_ISR_MASK
);
1319 writel(intmask_org
& mask
, ®
->host_int_mask
);
1320 acb
->outbound_int_enable
= ~(intmask_org
& mask
) & 0x0000000f;
1323 case ACB_ADAPTER_TYPE_D
: {
1324 struct MessageUnit_D
*reg
= acb
->pmuD
;
1326 mask
= ARCMSR_ARC1214_ALL_INT_ENABLE
;
1327 writel(intmask_org
| mask
, reg
->pcief0_int_enable
);
1333 static int arcmsr_build_ccb(struct AdapterControlBlock
*acb
,
1334 struct CommandControlBlock
*ccb
, struct scsi_cmnd
*pcmd
)
1336 struct ARCMSR_CDB
*arcmsr_cdb
= (struct ARCMSR_CDB
*)&ccb
->arcmsr_cdb
;
1337 int8_t *psge
= (int8_t *)&arcmsr_cdb
->u
;
1338 __le32 address_lo
, address_hi
;
1339 int arccdbsize
= 0x30;
1342 struct scatterlist
*sg
;
1345 memset(arcmsr_cdb
, 0, sizeof(struct ARCMSR_CDB
));
1346 arcmsr_cdb
->TargetID
= pcmd
->device
->id
;
1347 arcmsr_cdb
->LUN
= pcmd
->device
->lun
;
1348 arcmsr_cdb
->Function
= 1;
1349 arcmsr_cdb
->msgContext
= 0;
1350 memcpy(arcmsr_cdb
->Cdb
, pcmd
->cmnd
, pcmd
->cmd_len
);
1352 nseg
= scsi_dma_map(pcmd
);
1353 if (unlikely(nseg
> acb
->host
->sg_tablesize
|| nseg
< 0))
1355 scsi_for_each_sg(pcmd
, sg
, nseg
, i
) {
1356 /* Get the physical address of the current data pointer */
1357 length
= cpu_to_le32(sg_dma_len(sg
));
1358 address_lo
= cpu_to_le32(dma_addr_lo32(sg_dma_address(sg
)));
1359 address_hi
= cpu_to_le32(dma_addr_hi32(sg_dma_address(sg
)));
1360 if (address_hi
== 0) {
1361 struct SG32ENTRY
*pdma_sg
= (struct SG32ENTRY
*)psge
;
1363 pdma_sg
->address
= address_lo
;
1364 pdma_sg
->length
= length
;
1365 psge
+= sizeof (struct SG32ENTRY
);
1366 arccdbsize
+= sizeof (struct SG32ENTRY
);
1368 struct SG64ENTRY
*pdma_sg
= (struct SG64ENTRY
*)psge
;
1370 pdma_sg
->addresshigh
= address_hi
;
1371 pdma_sg
->address
= address_lo
;
1372 pdma_sg
->length
= length
|cpu_to_le32(IS_SG64_ADDR
);
1373 psge
+= sizeof (struct SG64ENTRY
);
1374 arccdbsize
+= sizeof (struct SG64ENTRY
);
1377 arcmsr_cdb
->sgcount
= (uint8_t)nseg
;
1378 arcmsr_cdb
->DataLength
= scsi_bufflen(pcmd
);
1379 arcmsr_cdb
->msgPages
= arccdbsize
/0x100 + (arccdbsize
% 0x100 ? 1 : 0);
1380 if ( arccdbsize
> 256)
1381 arcmsr_cdb
->Flags
|= ARCMSR_CDB_FLAG_SGL_BSIZE
;
1382 if (pcmd
->sc_data_direction
== DMA_TO_DEVICE
)
1383 arcmsr_cdb
->Flags
|= ARCMSR_CDB_FLAG_WRITE
;
1384 ccb
->arc_cdb_size
= arccdbsize
;
1388 static void arcmsr_post_ccb(struct AdapterControlBlock
*acb
, struct CommandControlBlock
*ccb
)
1390 uint32_t cdb_phyaddr
= ccb
->cdb_phyaddr
;
1391 struct ARCMSR_CDB
*arcmsr_cdb
= (struct ARCMSR_CDB
*)&ccb
->arcmsr_cdb
;
1392 atomic_inc(&acb
->ccboutstandingcount
);
1393 ccb
->startdone
= ARCMSR_CCB_START
;
1394 switch (acb
->adapter_type
) {
1395 case ACB_ADAPTER_TYPE_A
: {
1396 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1398 if (arcmsr_cdb
->Flags
& ARCMSR_CDB_FLAG_SGL_BSIZE
)
1399 writel(cdb_phyaddr
| ARCMSR_CCBPOST_FLAG_SGL_BSIZE
,
1400 ®
->inbound_queueport
);
1402 writel(cdb_phyaddr
, ®
->inbound_queueport
);
1406 case ACB_ADAPTER_TYPE_B
: {
1407 struct MessageUnit_B
*reg
= acb
->pmuB
;
1408 uint32_t ending_index
, index
= reg
->postq_index
;
1410 ending_index
= ((index
+ 1) % ARCMSR_MAX_HBB_POSTQUEUE
);
1411 reg
->post_qbuffer
[ending_index
] = 0;
1412 if (arcmsr_cdb
->Flags
& ARCMSR_CDB_FLAG_SGL_BSIZE
) {
1413 reg
->post_qbuffer
[index
] =
1414 cdb_phyaddr
| ARCMSR_CCBPOST_FLAG_SGL_BSIZE
;
1416 reg
->post_qbuffer
[index
] = cdb_phyaddr
;
1419 index
%= ARCMSR_MAX_HBB_POSTQUEUE
;/*if last index number set it to 0 */
1420 reg
->postq_index
= index
;
1421 writel(ARCMSR_DRV2IOP_CDB_POSTED
, reg
->drv2iop_doorbell
);
1424 case ACB_ADAPTER_TYPE_C
: {
1425 struct MessageUnit_C __iomem
*phbcmu
= acb
->pmuC
;
1426 uint32_t ccb_post_stamp
, arc_cdb_size
;
1428 arc_cdb_size
= (ccb
->arc_cdb_size
> 0x300) ? 0x300 : ccb
->arc_cdb_size
;
1429 ccb_post_stamp
= (cdb_phyaddr
| ((arc_cdb_size
- 1) >> 6) | 1);
1430 if (acb
->cdb_phyaddr_hi32
) {
1431 writel(acb
->cdb_phyaddr_hi32
, &phbcmu
->inbound_queueport_high
);
1432 writel(ccb_post_stamp
, &phbcmu
->inbound_queueport_low
);
1434 writel(ccb_post_stamp
, &phbcmu
->inbound_queueport_low
);
1438 case ACB_ADAPTER_TYPE_D
: {
1439 struct MessageUnit_D
*pmu
= acb
->pmuD
;
1441 u16 postq_index
, toggle
;
1442 unsigned long flags
;
1443 struct InBound_SRB
*pinbound_srb
;
1445 spin_lock_irqsave(&acb
->postq_lock
, flags
);
1446 postq_index
= pmu
->postq_index
;
1447 pinbound_srb
= (struct InBound_SRB
*)&(pmu
->post_qbuffer
[postq_index
& 0xFF]);
1448 pinbound_srb
->addressHigh
= dma_addr_hi32(cdb_phyaddr
);
1449 pinbound_srb
->addressLow
= dma_addr_lo32(cdb_phyaddr
);
1450 pinbound_srb
->length
= ccb
->arc_cdb_size
>> 2;
1451 arcmsr_cdb
->msgContext
= dma_addr_lo32(cdb_phyaddr
);
1452 toggle
= postq_index
& 0x4000;
1453 index_stripped
= postq_index
+ 1;
1454 index_stripped
&= (ARCMSR_MAX_ARC1214_POSTQUEUE
- 1);
1455 pmu
->postq_index
= index_stripped
? (index_stripped
| toggle
) :
1457 writel(postq_index
, pmu
->inboundlist_write_pointer
);
1458 spin_unlock_irqrestore(&acb
->postq_lock
, flags
);
1464 static void arcmsr_hbaA_stop_bgrb(struct AdapterControlBlock
*acb
)
1466 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1467 acb
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
1468 writel(ARCMSR_INBOUND_MESG0_STOP_BGRB
, ®
->inbound_msgaddr0
);
1469 if (!arcmsr_hbaA_wait_msgint_ready(acb
)) {
1471 "arcmsr%d: wait 'stop adapter background rebulid' timeout\n"
1472 , acb
->host
->host_no
);
1476 static void arcmsr_hbaB_stop_bgrb(struct AdapterControlBlock
*acb
)
1478 struct MessageUnit_B
*reg
= acb
->pmuB
;
1479 acb
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
1480 writel(ARCMSR_MESSAGE_STOP_BGRB
, reg
->drv2iop_doorbell
);
1482 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
1484 "arcmsr%d: wait 'stop adapter background rebulid' timeout\n"
1485 , acb
->host
->host_no
);
1489 static void arcmsr_hbaC_stop_bgrb(struct AdapterControlBlock
*pACB
)
1491 struct MessageUnit_C __iomem
*reg
= pACB
->pmuC
;
1492 pACB
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
1493 writel(ARCMSR_INBOUND_MESG0_STOP_BGRB
, ®
->inbound_msgaddr0
);
1494 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
1495 if (!arcmsr_hbaC_wait_msgint_ready(pACB
)) {
1497 "arcmsr%d: wait 'stop adapter background rebulid' timeout\n"
1498 , pACB
->host
->host_no
);
1503 static void arcmsr_hbaD_stop_bgrb(struct AdapterControlBlock
*pACB
)
1505 struct MessageUnit_D
*reg
= pACB
->pmuD
;
1507 pACB
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
1508 writel(ARCMSR_INBOUND_MESG0_STOP_BGRB
, reg
->inbound_msgaddr0
);
1509 if (!arcmsr_hbaD_wait_msgint_ready(pACB
))
1510 pr_notice("arcmsr%d: wait 'stop adapter background rebulid' "
1511 "timeout\n", pACB
->host
->host_no
);
1514 static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock
*acb
)
1516 switch (acb
->adapter_type
) {
1517 case ACB_ADAPTER_TYPE_A
: {
1518 arcmsr_hbaA_stop_bgrb(acb
);
1522 case ACB_ADAPTER_TYPE_B
: {
1523 arcmsr_hbaB_stop_bgrb(acb
);
1526 case ACB_ADAPTER_TYPE_C
: {
1527 arcmsr_hbaC_stop_bgrb(acb
);
1530 case ACB_ADAPTER_TYPE_D
:
1531 arcmsr_hbaD_stop_bgrb(acb
);
1536 static void arcmsr_free_ccb_pool(struct AdapterControlBlock
*acb
)
1538 dma_free_coherent(&acb
->pdev
->dev
, acb
->uncache_size
, acb
->dma_coherent
, acb
->dma_coherent_handle
);
1541 static void arcmsr_iop_message_read(struct AdapterControlBlock
*acb
)
1543 switch (acb
->adapter_type
) {
1544 case ACB_ADAPTER_TYPE_A
: {
1545 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1546 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK
, ®
->inbound_doorbell
);
1550 case ACB_ADAPTER_TYPE_B
: {
1551 struct MessageUnit_B
*reg
= acb
->pmuB
;
1552 writel(ARCMSR_DRV2IOP_DATA_READ_OK
, reg
->drv2iop_doorbell
);
1555 case ACB_ADAPTER_TYPE_C
: {
1556 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
1558 writel(ARCMSR_HBCMU_DRV2IOP_DATA_READ_OK
, ®
->inbound_doorbell
);
1561 case ACB_ADAPTER_TYPE_D
: {
1562 struct MessageUnit_D
*reg
= acb
->pmuD
;
1563 writel(ARCMSR_ARC1214_DRV2IOP_DATA_OUT_READ
,
1564 reg
->inbound_doorbell
);
1570 static void arcmsr_iop_message_wrote(struct AdapterControlBlock
*acb
)
1572 switch (acb
->adapter_type
) {
1573 case ACB_ADAPTER_TYPE_A
: {
1574 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1576 ** push inbound doorbell tell iop, driver data write ok
1577 ** and wait reply on next hwinterrupt for next Qbuffer post
1579 writel(ARCMSR_INBOUND_DRIVER_DATA_WRITE_OK
, ®
->inbound_doorbell
);
1583 case ACB_ADAPTER_TYPE_B
: {
1584 struct MessageUnit_B
*reg
= acb
->pmuB
;
1586 ** push inbound doorbell tell iop, driver data write ok
1587 ** and wait reply on next hwinterrupt for next Qbuffer post
1589 writel(ARCMSR_DRV2IOP_DATA_WRITE_OK
, reg
->drv2iop_doorbell
);
1592 case ACB_ADAPTER_TYPE_C
: {
1593 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
1595 ** push inbound doorbell tell iop, driver data write ok
1596 ** and wait reply on next hwinterrupt for next Qbuffer post
1598 writel(ARCMSR_HBCMU_DRV2IOP_DATA_WRITE_OK
, ®
->inbound_doorbell
);
1601 case ACB_ADAPTER_TYPE_D
: {
1602 struct MessageUnit_D
*reg
= acb
->pmuD
;
1603 writel(ARCMSR_ARC1214_DRV2IOP_DATA_IN_READY
,
1604 reg
->inbound_doorbell
);
1610 struct QBUFFER __iomem
*arcmsr_get_iop_rqbuffer(struct AdapterControlBlock
*acb
)
1612 struct QBUFFER __iomem
*qbuffer
= NULL
;
1613 switch (acb
->adapter_type
) {
1615 case ACB_ADAPTER_TYPE_A
: {
1616 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1617 qbuffer
= (struct QBUFFER __iomem
*)®
->message_rbuffer
;
1621 case ACB_ADAPTER_TYPE_B
: {
1622 struct MessageUnit_B
*reg
= acb
->pmuB
;
1623 qbuffer
= (struct QBUFFER __iomem
*)reg
->message_rbuffer
;
1626 case ACB_ADAPTER_TYPE_C
: {
1627 struct MessageUnit_C __iomem
*phbcmu
= acb
->pmuC
;
1628 qbuffer
= (struct QBUFFER __iomem
*)&phbcmu
->message_rbuffer
;
1631 case ACB_ADAPTER_TYPE_D
: {
1632 struct MessageUnit_D
*reg
= acb
->pmuD
;
1633 qbuffer
= (struct QBUFFER __iomem
*)reg
->message_rbuffer
;
1640 static struct QBUFFER __iomem
*arcmsr_get_iop_wqbuffer(struct AdapterControlBlock
*acb
)
1642 struct QBUFFER __iomem
*pqbuffer
= NULL
;
1643 switch (acb
->adapter_type
) {
1645 case ACB_ADAPTER_TYPE_A
: {
1646 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1647 pqbuffer
= (struct QBUFFER __iomem
*) ®
->message_wbuffer
;
1651 case ACB_ADAPTER_TYPE_B
: {
1652 struct MessageUnit_B
*reg
= acb
->pmuB
;
1653 pqbuffer
= (struct QBUFFER __iomem
*)reg
->message_wbuffer
;
1656 case ACB_ADAPTER_TYPE_C
: {
1657 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
1658 pqbuffer
= (struct QBUFFER __iomem
*)®
->message_wbuffer
;
1661 case ACB_ADAPTER_TYPE_D
: {
1662 struct MessageUnit_D
*reg
= acb
->pmuD
;
1663 pqbuffer
= (struct QBUFFER __iomem
*)reg
->message_wbuffer
;
1671 arcmsr_Read_iop_rqbuffer_in_DWORD(struct AdapterControlBlock
*acb
,
1672 struct QBUFFER __iomem
*prbuffer
)
1675 uint8_t *buf1
= NULL
;
1676 uint32_t __iomem
*iop_data
;
1677 uint32_t iop_len
, data_len
, *buf2
= NULL
;
1679 iop_data
= (uint32_t __iomem
*)prbuffer
->data
;
1680 iop_len
= readl(&prbuffer
->data_len
);
1682 buf1
= kmalloc(128, GFP_ATOMIC
);
1683 buf2
= (uint32_t *)buf1
;
1687 while (data_len
>= 4) {
1688 *buf2
++ = readl(iop_data
);
1693 *buf2
= readl(iop_data
);
1694 buf2
= (uint32_t *)buf1
;
1696 while (iop_len
> 0) {
1697 pQbuffer
= &acb
->rqbuffer
[acb
->rqbuf_putIndex
];
1699 acb
->rqbuf_putIndex
++;
1700 /* if last, index number set it to 0 */
1701 acb
->rqbuf_putIndex
%= ARCMSR_MAX_QBUFFER
;
1706 /* let IOP know data has been read */
1707 arcmsr_iop_message_read(acb
);
1712 arcmsr_Read_iop_rqbuffer_data(struct AdapterControlBlock
*acb
,
1713 struct QBUFFER __iomem
*prbuffer
) {
1716 uint8_t __iomem
*iop_data
;
1719 if (acb
->adapter_type
& (ACB_ADAPTER_TYPE_C
| ACB_ADAPTER_TYPE_D
))
1720 return arcmsr_Read_iop_rqbuffer_in_DWORD(acb
, prbuffer
);
1721 iop_data
= (uint8_t __iomem
*)prbuffer
->data
;
1722 iop_len
= readl(&prbuffer
->data_len
);
1723 while (iop_len
> 0) {
1724 pQbuffer
= &acb
->rqbuffer
[acb
->rqbuf_putIndex
];
1725 *pQbuffer
= readb(iop_data
);
1726 acb
->rqbuf_putIndex
++;
1727 acb
->rqbuf_putIndex
%= ARCMSR_MAX_QBUFFER
;
1731 arcmsr_iop_message_read(acb
);
1735 static void arcmsr_iop2drv_data_wrote_handle(struct AdapterControlBlock
*acb
)
1737 unsigned long flags
;
1738 struct QBUFFER __iomem
*prbuffer
;
1739 int32_t buf_empty_len
;
1741 spin_lock_irqsave(&acb
->rqbuffer_lock
, flags
);
1742 prbuffer
= arcmsr_get_iop_rqbuffer(acb
);
1743 buf_empty_len
= (acb
->rqbuf_putIndex
- acb
->rqbuf_getIndex
- 1) &
1744 (ARCMSR_MAX_QBUFFER
- 1);
1745 if (buf_empty_len
>= readl(&prbuffer
->data_len
)) {
1746 if (arcmsr_Read_iop_rqbuffer_data(acb
, prbuffer
) == 0)
1747 acb
->acb_flags
|= ACB_F_IOPDATA_OVERFLOW
;
1749 acb
->acb_flags
|= ACB_F_IOPDATA_OVERFLOW
;
1750 spin_unlock_irqrestore(&acb
->rqbuffer_lock
, flags
);
1753 static void arcmsr_write_ioctldata2iop_in_DWORD(struct AdapterControlBlock
*acb
)
1756 struct QBUFFER __iomem
*pwbuffer
;
1757 uint8_t *buf1
= NULL
;
1758 uint32_t __iomem
*iop_data
;
1759 uint32_t allxfer_len
= 0, data_len
, *buf2
= NULL
, data
;
1761 if (acb
->acb_flags
& ACB_F_MESSAGE_WQBUFFER_READED
) {
1762 buf1
= kmalloc(128, GFP_ATOMIC
);
1763 buf2
= (uint32_t *)buf1
;
1767 acb
->acb_flags
&= (~ACB_F_MESSAGE_WQBUFFER_READED
);
1768 pwbuffer
= arcmsr_get_iop_wqbuffer(acb
);
1769 iop_data
= (uint32_t __iomem
*)pwbuffer
->data
;
1770 while ((acb
->wqbuf_getIndex
!= acb
->wqbuf_putIndex
)
1771 && (allxfer_len
< 124)) {
1772 pQbuffer
= &acb
->wqbuffer
[acb
->wqbuf_getIndex
];
1774 acb
->wqbuf_getIndex
++;
1775 acb
->wqbuf_getIndex
%= ARCMSR_MAX_QBUFFER
;
1779 data_len
= allxfer_len
;
1780 buf1
= (uint8_t *)buf2
;
1781 while (data_len
>= 4) {
1783 writel(data
, iop_data
);
1789 writel(data
, iop_data
);
1791 writel(allxfer_len
, &pwbuffer
->data_len
);
1793 arcmsr_iop_message_wrote(acb
);
1798 arcmsr_write_ioctldata2iop(struct AdapterControlBlock
*acb
)
1801 struct QBUFFER __iomem
*pwbuffer
;
1802 uint8_t __iomem
*iop_data
;
1803 int32_t allxfer_len
= 0;
1805 if (acb
->adapter_type
& (ACB_ADAPTER_TYPE_C
| ACB_ADAPTER_TYPE_D
)) {
1806 arcmsr_write_ioctldata2iop_in_DWORD(acb
);
1809 if (acb
->acb_flags
& ACB_F_MESSAGE_WQBUFFER_READED
) {
1810 acb
->acb_flags
&= (~ACB_F_MESSAGE_WQBUFFER_READED
);
1811 pwbuffer
= arcmsr_get_iop_wqbuffer(acb
);
1812 iop_data
= (uint8_t __iomem
*)pwbuffer
->data
;
1813 while ((acb
->wqbuf_getIndex
!= acb
->wqbuf_putIndex
)
1814 && (allxfer_len
< 124)) {
1815 pQbuffer
= &acb
->wqbuffer
[acb
->wqbuf_getIndex
];
1816 writeb(*pQbuffer
, iop_data
);
1817 acb
->wqbuf_getIndex
++;
1818 acb
->wqbuf_getIndex
%= ARCMSR_MAX_QBUFFER
;
1822 writel(allxfer_len
, &pwbuffer
->data_len
);
1823 arcmsr_iop_message_wrote(acb
);
1827 static void arcmsr_iop2drv_data_read_handle(struct AdapterControlBlock
*acb
)
1829 unsigned long flags
;
1831 spin_lock_irqsave(&acb
->wqbuffer_lock
, flags
);
1832 acb
->acb_flags
|= ACB_F_MESSAGE_WQBUFFER_READED
;
1833 if (acb
->wqbuf_getIndex
!= acb
->wqbuf_putIndex
)
1834 arcmsr_write_ioctldata2iop(acb
);
1835 if (acb
->wqbuf_getIndex
== acb
->wqbuf_putIndex
)
1836 acb
->acb_flags
|= ACB_F_MESSAGE_WQBUFFER_CLEARED
;
1837 spin_unlock_irqrestore(&acb
->wqbuffer_lock
, flags
);
1840 static void arcmsr_hbaA_doorbell_isr(struct AdapterControlBlock
*acb
)
1842 uint32_t outbound_doorbell
;
1843 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1844 outbound_doorbell
= readl(®
->outbound_doorbell
);
1846 writel(outbound_doorbell
, ®
->outbound_doorbell
);
1847 if (outbound_doorbell
& ARCMSR_OUTBOUND_IOP331_DATA_WRITE_OK
)
1848 arcmsr_iop2drv_data_wrote_handle(acb
);
1849 if (outbound_doorbell
& ARCMSR_OUTBOUND_IOP331_DATA_READ_OK
)
1850 arcmsr_iop2drv_data_read_handle(acb
);
1851 outbound_doorbell
= readl(®
->outbound_doorbell
);
1852 } while (outbound_doorbell
& (ARCMSR_OUTBOUND_IOP331_DATA_WRITE_OK
1853 | ARCMSR_OUTBOUND_IOP331_DATA_READ_OK
));
1855 static void arcmsr_hbaC_doorbell_isr(struct AdapterControlBlock
*pACB
)
1857 uint32_t outbound_doorbell
;
1858 struct MessageUnit_C __iomem
*reg
= pACB
->pmuC
;
1860 *******************************************************************
1861 ** Maybe here we need to check wrqbuffer_lock is lock or not
1862 ** DOORBELL: din! don!
1863 ** check if there are any mail need to pack from firmware
1864 *******************************************************************
1866 outbound_doorbell
= readl(®
->outbound_doorbell
);
1868 writel(outbound_doorbell
, ®
->outbound_doorbell_clear
);
1869 readl(®
->outbound_doorbell_clear
);
1870 if (outbound_doorbell
& ARCMSR_HBCMU_IOP2DRV_DATA_WRITE_OK
)
1871 arcmsr_iop2drv_data_wrote_handle(pACB
);
1872 if (outbound_doorbell
& ARCMSR_HBCMU_IOP2DRV_DATA_READ_OK
)
1873 arcmsr_iop2drv_data_read_handle(pACB
);
1874 if (outbound_doorbell
& ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE
)
1875 arcmsr_hbaC_message_isr(pACB
);
1876 outbound_doorbell
= readl(®
->outbound_doorbell
);
1877 } while (outbound_doorbell
& (ARCMSR_HBCMU_IOP2DRV_DATA_WRITE_OK
1878 | ARCMSR_HBCMU_IOP2DRV_DATA_READ_OK
1879 | ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE
));
1882 static void arcmsr_hbaD_doorbell_isr(struct AdapterControlBlock
*pACB
)
1884 uint32_t outbound_doorbell
;
1885 struct MessageUnit_D
*pmu
= pACB
->pmuD
;
1887 outbound_doorbell
= readl(pmu
->outbound_doorbell
);
1889 writel(outbound_doorbell
, pmu
->outbound_doorbell
);
1890 if (outbound_doorbell
& ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
)
1891 arcmsr_hbaD_message_isr(pACB
);
1892 if (outbound_doorbell
& ARCMSR_ARC1214_IOP2DRV_DATA_WRITE_OK
)
1893 arcmsr_iop2drv_data_wrote_handle(pACB
);
1894 if (outbound_doorbell
& ARCMSR_ARC1214_IOP2DRV_DATA_READ_OK
)
1895 arcmsr_iop2drv_data_read_handle(pACB
);
1896 outbound_doorbell
= readl(pmu
->outbound_doorbell
);
1897 } while (outbound_doorbell
& (ARCMSR_ARC1214_IOP2DRV_DATA_WRITE_OK
1898 | ARCMSR_ARC1214_IOP2DRV_DATA_READ_OK
1899 | ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
));
1902 static void arcmsr_hbaA_postqueue_isr(struct AdapterControlBlock
*acb
)
1905 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1906 struct ARCMSR_CDB
*pARCMSR_CDB
;
1907 struct CommandControlBlock
*pCCB
;
1909 while ((flag_ccb
= readl(®
->outbound_queueport
)) != 0xFFFFFFFF) {
1910 pARCMSR_CDB
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ (flag_ccb
<< 5));/*frame must be 32 bytes aligned*/
1911 pCCB
= container_of(pARCMSR_CDB
, struct CommandControlBlock
, arcmsr_cdb
);
1912 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
1913 arcmsr_drain_donequeue(acb
, pCCB
, error
);
1916 static void arcmsr_hbaB_postqueue_isr(struct AdapterControlBlock
*acb
)
1920 struct MessageUnit_B
*reg
= acb
->pmuB
;
1921 struct ARCMSR_CDB
*pARCMSR_CDB
;
1922 struct CommandControlBlock
*pCCB
;
1924 index
= reg
->doneq_index
;
1925 while ((flag_ccb
= reg
->done_qbuffer
[index
]) != 0) {
1926 reg
->done_qbuffer
[index
] = 0;
1927 pARCMSR_CDB
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+(flag_ccb
<< 5));/*frame must be 32 bytes aligned*/
1928 pCCB
= container_of(pARCMSR_CDB
, struct CommandControlBlock
, arcmsr_cdb
);
1929 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
1930 arcmsr_drain_donequeue(acb
, pCCB
, error
);
1932 index
%= ARCMSR_MAX_HBB_POSTQUEUE
;
1933 reg
->doneq_index
= index
;
1937 static void arcmsr_hbaC_postqueue_isr(struct AdapterControlBlock
*acb
)
1939 struct MessageUnit_C __iomem
*phbcmu
;
1940 struct ARCMSR_CDB
*arcmsr_cdb
;
1941 struct CommandControlBlock
*ccb
;
1942 uint32_t flag_ccb
, ccb_cdb_phy
, throttling
= 0;
1946 /* areca cdb command done */
1947 /* Use correct offset and size for syncing */
1949 while ((flag_ccb
= readl(&phbcmu
->outbound_queueport_low
)) !=
1951 ccb_cdb_phy
= (flag_ccb
& 0xFFFFFFF0);
1952 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
1954 ccb
= container_of(arcmsr_cdb
, struct CommandControlBlock
,
1956 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
)
1958 /* check if command done with no error */
1959 arcmsr_drain_donequeue(acb
, ccb
, error
);
1961 if (throttling
== ARCMSR_HBC_ISR_THROTTLING_LEVEL
) {
1962 writel(ARCMSR_HBCMU_DRV2IOP_POSTQUEUE_THROTTLING
,
1963 &phbcmu
->inbound_doorbell
);
1969 static void arcmsr_hbaD_postqueue_isr(struct AdapterControlBlock
*acb
)
1971 u32 outbound_write_pointer
, doneq_index
, index_stripped
, toggle
;
1972 uint32_t addressLow
, ccb_cdb_phy
;
1974 struct MessageUnit_D
*pmu
;
1975 struct ARCMSR_CDB
*arcmsr_cdb
;
1976 struct CommandControlBlock
*ccb
;
1977 unsigned long flags
;
1979 spin_lock_irqsave(&acb
->doneq_lock
, flags
);
1981 outbound_write_pointer
= pmu
->done_qbuffer
[0].addressLow
+ 1;
1982 doneq_index
= pmu
->doneq_index
;
1983 if ((doneq_index
& 0xFFF) != (outbound_write_pointer
& 0xFFF)) {
1985 toggle
= doneq_index
& 0x4000;
1986 index_stripped
= (doneq_index
& 0xFFF) + 1;
1987 index_stripped
%= ARCMSR_MAX_ARC1214_DONEQUEUE
;
1988 pmu
->doneq_index
= index_stripped
? (index_stripped
| toggle
) :
1989 ((toggle
^ 0x4000) + 1);
1990 doneq_index
= pmu
->doneq_index
;
1991 addressLow
= pmu
->done_qbuffer
[doneq_index
&
1993 ccb_cdb_phy
= (addressLow
& 0xFFFFFFF0);
1994 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
1996 ccb
= container_of(arcmsr_cdb
,
1997 struct CommandControlBlock
, arcmsr_cdb
);
1998 error
= (addressLow
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
)
2000 arcmsr_drain_donequeue(acb
, ccb
, error
);
2001 writel(doneq_index
, pmu
->outboundlist_read_pointer
);
2002 } while ((doneq_index
& 0xFFF) !=
2003 (outbound_write_pointer
& 0xFFF));
2005 writel(ARCMSR_ARC1214_OUTBOUND_LIST_INTERRUPT_CLEAR
,
2006 pmu
->outboundlist_interrupt_cause
);
2007 readl(pmu
->outboundlist_interrupt_cause
);
2008 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
2012 **********************************************************************************
2013 ** Handle a message interrupt
2015 ** The only message interrupt we expect is in response to a query for the current adapter config.
2016 ** We want this in order to compare the drivemap so that we can detect newly-attached drives.
2017 **********************************************************************************
2019 static void arcmsr_hbaA_message_isr(struct AdapterControlBlock
*acb
)
2021 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2022 /*clear interrupt and message state*/
2023 writel(ARCMSR_MU_OUTBOUND_MESSAGE0_INT
, ®
->outbound_intstatus
);
2024 schedule_work(&acb
->arcmsr_do_message_isr_bh
);
2026 static void arcmsr_hbaB_message_isr(struct AdapterControlBlock
*acb
)
2028 struct MessageUnit_B
*reg
= acb
->pmuB
;
2030 /*clear interrupt and message state*/
2031 writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN
, reg
->iop2drv_doorbell
);
2032 schedule_work(&acb
->arcmsr_do_message_isr_bh
);
2035 **********************************************************************************
2036 ** Handle a message interrupt
2038 ** The only message interrupt we expect is in response to a query for the
2039 ** current adapter config.
2040 ** We want this in order to compare the drivemap so that we can detect newly-attached drives.
2041 **********************************************************************************
2043 static void arcmsr_hbaC_message_isr(struct AdapterControlBlock
*acb
)
2045 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
2046 /*clear interrupt and message state*/
2047 writel(ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE_DOORBELL_CLEAR
, ®
->outbound_doorbell_clear
);
2048 schedule_work(&acb
->arcmsr_do_message_isr_bh
);
2051 static void arcmsr_hbaD_message_isr(struct AdapterControlBlock
*acb
)
2053 struct MessageUnit_D
*reg
= acb
->pmuD
;
2055 writel(ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
, reg
->outbound_doorbell
);
2056 readl(reg
->outbound_doorbell
);
2057 schedule_work(&acb
->arcmsr_do_message_isr_bh
);
2060 static int arcmsr_hbaA_handle_isr(struct AdapterControlBlock
*acb
)
2062 uint32_t outbound_intstatus
;
2063 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2064 outbound_intstatus
= readl(®
->outbound_intstatus
) &
2065 acb
->outbound_int_enable
;
2066 if (!(outbound_intstatus
& ARCMSR_MU_OUTBOUND_HANDLE_INT
))
2069 writel(outbound_intstatus
, ®
->outbound_intstatus
);
2070 if (outbound_intstatus
& ARCMSR_MU_OUTBOUND_DOORBELL_INT
)
2071 arcmsr_hbaA_doorbell_isr(acb
);
2072 if (outbound_intstatus
& ARCMSR_MU_OUTBOUND_POSTQUEUE_INT
)
2073 arcmsr_hbaA_postqueue_isr(acb
);
2074 if (outbound_intstatus
& ARCMSR_MU_OUTBOUND_MESSAGE0_INT
)
2075 arcmsr_hbaA_message_isr(acb
);
2076 outbound_intstatus
= readl(®
->outbound_intstatus
) &
2077 acb
->outbound_int_enable
;
2078 } while (outbound_intstatus
& (ARCMSR_MU_OUTBOUND_DOORBELL_INT
2079 | ARCMSR_MU_OUTBOUND_POSTQUEUE_INT
2080 | ARCMSR_MU_OUTBOUND_MESSAGE0_INT
));
2084 static int arcmsr_hbaB_handle_isr(struct AdapterControlBlock
*acb
)
2086 uint32_t outbound_doorbell
;
2087 struct MessageUnit_B
*reg
= acb
->pmuB
;
2088 outbound_doorbell
= readl(reg
->iop2drv_doorbell
) &
2089 acb
->outbound_int_enable
;
2090 if (!outbound_doorbell
)
2093 writel(~outbound_doorbell
, reg
->iop2drv_doorbell
);
2094 writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT
, reg
->drv2iop_doorbell
);
2095 if (outbound_doorbell
& ARCMSR_IOP2DRV_DATA_WRITE_OK
)
2096 arcmsr_iop2drv_data_wrote_handle(acb
);
2097 if (outbound_doorbell
& ARCMSR_IOP2DRV_DATA_READ_OK
)
2098 arcmsr_iop2drv_data_read_handle(acb
);
2099 if (outbound_doorbell
& ARCMSR_IOP2DRV_CDB_DONE
)
2100 arcmsr_hbaB_postqueue_isr(acb
);
2101 if (outbound_doorbell
& ARCMSR_IOP2DRV_MESSAGE_CMD_DONE
)
2102 arcmsr_hbaB_message_isr(acb
);
2103 outbound_doorbell
= readl(reg
->iop2drv_doorbell
) &
2104 acb
->outbound_int_enable
;
2105 } while (outbound_doorbell
& (ARCMSR_IOP2DRV_DATA_WRITE_OK
2106 | ARCMSR_IOP2DRV_DATA_READ_OK
2107 | ARCMSR_IOP2DRV_CDB_DONE
2108 | ARCMSR_IOP2DRV_MESSAGE_CMD_DONE
));
2112 static int arcmsr_hbaC_handle_isr(struct AdapterControlBlock
*pACB
)
2114 uint32_t host_interrupt_status
;
2115 struct MessageUnit_C __iomem
*phbcmu
= pACB
->pmuC
;
2117 *********************************************
2118 ** check outbound intstatus
2119 *********************************************
2121 host_interrupt_status
= readl(&phbcmu
->host_int_status
) &
2122 (ARCMSR_HBCMU_OUTBOUND_POSTQUEUE_ISR
|
2123 ARCMSR_HBCMU_OUTBOUND_DOORBELL_ISR
);
2124 if (!host_interrupt_status
)
2127 if (host_interrupt_status
& ARCMSR_HBCMU_OUTBOUND_DOORBELL_ISR
)
2128 arcmsr_hbaC_doorbell_isr(pACB
);
2129 /* MU post queue interrupts*/
2130 if (host_interrupt_status
& ARCMSR_HBCMU_OUTBOUND_POSTQUEUE_ISR
)
2131 arcmsr_hbaC_postqueue_isr(pACB
);
2132 host_interrupt_status
= readl(&phbcmu
->host_int_status
);
2133 } while (host_interrupt_status
& (ARCMSR_HBCMU_OUTBOUND_POSTQUEUE_ISR
|
2134 ARCMSR_HBCMU_OUTBOUND_DOORBELL_ISR
));
2138 static irqreturn_t
arcmsr_hbaD_handle_isr(struct AdapterControlBlock
*pACB
)
2140 u32 host_interrupt_status
;
2141 struct MessageUnit_D
*pmu
= pACB
->pmuD
;
2143 host_interrupt_status
= readl(pmu
->host_int_status
) &
2144 (ARCMSR_ARC1214_OUTBOUND_POSTQUEUE_ISR
|
2145 ARCMSR_ARC1214_OUTBOUND_DOORBELL_ISR
);
2146 if (!host_interrupt_status
)
2149 /* MU post queue interrupts*/
2150 if (host_interrupt_status
&
2151 ARCMSR_ARC1214_OUTBOUND_POSTQUEUE_ISR
)
2152 arcmsr_hbaD_postqueue_isr(pACB
);
2153 if (host_interrupt_status
&
2154 ARCMSR_ARC1214_OUTBOUND_DOORBELL_ISR
)
2155 arcmsr_hbaD_doorbell_isr(pACB
);
2156 host_interrupt_status
= readl(pmu
->host_int_status
);
2157 } while (host_interrupt_status
&
2158 (ARCMSR_ARC1214_OUTBOUND_POSTQUEUE_ISR
|
2159 ARCMSR_ARC1214_OUTBOUND_DOORBELL_ISR
));
2163 static irqreturn_t
arcmsr_interrupt(struct AdapterControlBlock
*acb
)
2165 switch (acb
->adapter_type
) {
2166 case ACB_ADAPTER_TYPE_A
:
2167 return arcmsr_hbaA_handle_isr(acb
);
2169 case ACB_ADAPTER_TYPE_B
:
2170 return arcmsr_hbaB_handle_isr(acb
);
2172 case ACB_ADAPTER_TYPE_C
:
2173 return arcmsr_hbaC_handle_isr(acb
);
2174 case ACB_ADAPTER_TYPE_D
:
2175 return arcmsr_hbaD_handle_isr(acb
);
2181 static void arcmsr_iop_parking(struct AdapterControlBlock
*acb
)
2184 /* stop adapter background rebuild */
2185 if (acb
->acb_flags
& ACB_F_MSG_START_BGRB
) {
2186 uint32_t intmask_org
;
2187 acb
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
2188 intmask_org
= arcmsr_disable_outbound_ints(acb
);
2189 arcmsr_stop_adapter_bgrb(acb
);
2190 arcmsr_flush_adapter_cache(acb
);
2191 arcmsr_enable_outbound_ints(acb
, intmask_org
);
2197 void arcmsr_clear_iop2drv_rqueue_buffer(struct AdapterControlBlock
*acb
)
2201 if (acb
->acb_flags
& ACB_F_IOPDATA_OVERFLOW
) {
2202 for (i
= 0; i
< 15; i
++) {
2203 if (acb
->acb_flags
& ACB_F_IOPDATA_OVERFLOW
) {
2204 acb
->acb_flags
&= ~ACB_F_IOPDATA_OVERFLOW
;
2205 acb
->rqbuf_getIndex
= 0;
2206 acb
->rqbuf_putIndex
= 0;
2207 arcmsr_iop_message_read(acb
);
2209 } else if (acb
->rqbuf_getIndex
!=
2210 acb
->rqbuf_putIndex
) {
2211 acb
->rqbuf_getIndex
= 0;
2212 acb
->rqbuf_putIndex
= 0;
2220 static int arcmsr_iop_message_xfer(struct AdapterControlBlock
*acb
,
2221 struct scsi_cmnd
*cmd
)
2224 unsigned short use_sg
;
2225 int retvalue
= 0, transfer_len
= 0;
2226 unsigned long flags
;
2227 struct CMD_MESSAGE_FIELD
*pcmdmessagefld
;
2228 uint32_t controlcode
= (uint32_t)cmd
->cmnd
[5] << 24 |
2229 (uint32_t)cmd
->cmnd
[6] << 16 |
2230 (uint32_t)cmd
->cmnd
[7] << 8 |
2231 (uint32_t)cmd
->cmnd
[8];
2232 struct scatterlist
*sg
;
2234 use_sg
= scsi_sg_count(cmd
);
2235 sg
= scsi_sglist(cmd
);
2236 buffer
= kmap_atomic(sg_page(sg
)) + sg
->offset
;
2238 retvalue
= ARCMSR_MESSAGE_FAIL
;
2241 transfer_len
+= sg
->length
;
2242 if (transfer_len
> sizeof(struct CMD_MESSAGE_FIELD
)) {
2243 retvalue
= ARCMSR_MESSAGE_FAIL
;
2244 pr_info("%s: ARCMSR_MESSAGE_FAIL!\n", __func__
);
2247 pcmdmessagefld
= (struct CMD_MESSAGE_FIELD
*)buffer
;
2248 switch (controlcode
) {
2249 case ARCMSR_MESSAGE_READ_RQBUFFER
: {
2250 unsigned char *ver_addr
;
2251 uint8_t *ptmpQbuffer
;
2252 uint32_t allxfer_len
= 0;
2253 ver_addr
= kmalloc(ARCMSR_API_DATA_BUFLEN
, GFP_ATOMIC
);
2255 retvalue
= ARCMSR_MESSAGE_FAIL
;
2256 pr_info("%s: memory not enough!\n", __func__
);
2259 ptmpQbuffer
= ver_addr
;
2260 spin_lock_irqsave(&acb
->rqbuffer_lock
, flags
);
2261 if (acb
->rqbuf_getIndex
!= acb
->rqbuf_putIndex
) {
2262 unsigned int tail
= acb
->rqbuf_getIndex
;
2263 unsigned int head
= acb
->rqbuf_putIndex
;
2264 unsigned int cnt_to_end
= CIRC_CNT_TO_END(head
, tail
, ARCMSR_MAX_QBUFFER
);
2266 allxfer_len
= CIRC_CNT(head
, tail
, ARCMSR_MAX_QBUFFER
);
2267 if (allxfer_len
> ARCMSR_API_DATA_BUFLEN
)
2268 allxfer_len
= ARCMSR_API_DATA_BUFLEN
;
2270 if (allxfer_len
<= cnt_to_end
)
2271 memcpy(ptmpQbuffer
, acb
->rqbuffer
+ tail
, allxfer_len
);
2273 memcpy(ptmpQbuffer
, acb
->rqbuffer
+ tail
, cnt_to_end
);
2274 memcpy(ptmpQbuffer
+ cnt_to_end
, acb
->rqbuffer
, allxfer_len
- cnt_to_end
);
2276 acb
->rqbuf_getIndex
= (acb
->rqbuf_getIndex
+ allxfer_len
) % ARCMSR_MAX_QBUFFER
;
2278 memcpy(pcmdmessagefld
->messagedatabuffer
, ver_addr
,
2280 if (acb
->acb_flags
& ACB_F_IOPDATA_OVERFLOW
) {
2281 struct QBUFFER __iomem
*prbuffer
;
2282 acb
->acb_flags
&= ~ACB_F_IOPDATA_OVERFLOW
;
2283 prbuffer
= arcmsr_get_iop_rqbuffer(acb
);
2284 if (arcmsr_Read_iop_rqbuffer_data(acb
, prbuffer
) == 0)
2285 acb
->acb_flags
|= ACB_F_IOPDATA_OVERFLOW
;
2287 spin_unlock_irqrestore(&acb
->rqbuffer_lock
, flags
);
2289 pcmdmessagefld
->cmdmessage
.Length
= allxfer_len
;
2290 if (acb
->fw_flag
== FW_DEADLOCK
)
2291 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2292 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2294 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2295 ARCMSR_MESSAGE_RETURNCODE_OK
;
2298 case ARCMSR_MESSAGE_WRITE_WQBUFFER
: {
2299 unsigned char *ver_addr
;
2302 uint8_t *pQbuffer
, *ptmpuserbuffer
;
2304 user_len
= pcmdmessagefld
->cmdmessage
.Length
;
2305 if (user_len
> ARCMSR_API_DATA_BUFLEN
) {
2306 retvalue
= ARCMSR_MESSAGE_FAIL
;
2310 ver_addr
= kmalloc(ARCMSR_API_DATA_BUFLEN
, GFP_ATOMIC
);
2312 retvalue
= ARCMSR_MESSAGE_FAIL
;
2315 ptmpuserbuffer
= ver_addr
;
2317 memcpy(ptmpuserbuffer
,
2318 pcmdmessagefld
->messagedatabuffer
, user_len
);
2319 spin_lock_irqsave(&acb
->wqbuffer_lock
, flags
);
2320 if (acb
->wqbuf_putIndex
!= acb
->wqbuf_getIndex
) {
2321 struct SENSE_DATA
*sensebuffer
=
2322 (struct SENSE_DATA
*)cmd
->sense_buffer
;
2323 arcmsr_write_ioctldata2iop(acb
);
2324 /* has error report sensedata */
2325 sensebuffer
->ErrorCode
= SCSI_SENSE_CURRENT_ERRORS
;
2326 sensebuffer
->SenseKey
= ILLEGAL_REQUEST
;
2327 sensebuffer
->AdditionalSenseLength
= 0x0A;
2328 sensebuffer
->AdditionalSenseCode
= 0x20;
2329 sensebuffer
->Valid
= 1;
2330 retvalue
= ARCMSR_MESSAGE_FAIL
;
2332 pQbuffer
= &acb
->wqbuffer
[acb
->wqbuf_putIndex
];
2333 cnt2end
= ARCMSR_MAX_QBUFFER
- acb
->wqbuf_putIndex
;
2334 if (user_len
> cnt2end
) {
2335 memcpy(pQbuffer
, ptmpuserbuffer
, cnt2end
);
2336 ptmpuserbuffer
+= cnt2end
;
2337 user_len
-= cnt2end
;
2338 acb
->wqbuf_putIndex
= 0;
2339 pQbuffer
= acb
->wqbuffer
;
2341 memcpy(pQbuffer
, ptmpuserbuffer
, user_len
);
2342 acb
->wqbuf_putIndex
+= user_len
;
2343 acb
->wqbuf_putIndex
%= ARCMSR_MAX_QBUFFER
;
2344 if (acb
->acb_flags
& ACB_F_MESSAGE_WQBUFFER_CLEARED
) {
2346 ~ACB_F_MESSAGE_WQBUFFER_CLEARED
;
2347 arcmsr_write_ioctldata2iop(acb
);
2350 spin_unlock_irqrestore(&acb
->wqbuffer_lock
, flags
);
2352 if (acb
->fw_flag
== FW_DEADLOCK
)
2353 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2354 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2356 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2357 ARCMSR_MESSAGE_RETURNCODE_OK
;
2360 case ARCMSR_MESSAGE_CLEAR_RQBUFFER
: {
2361 uint8_t *pQbuffer
= acb
->rqbuffer
;
2363 arcmsr_clear_iop2drv_rqueue_buffer(acb
);
2364 spin_lock_irqsave(&acb
->rqbuffer_lock
, flags
);
2365 acb
->acb_flags
|= ACB_F_MESSAGE_RQBUFFER_CLEARED
;
2366 acb
->rqbuf_getIndex
= 0;
2367 acb
->rqbuf_putIndex
= 0;
2368 memset(pQbuffer
, 0, ARCMSR_MAX_QBUFFER
);
2369 spin_unlock_irqrestore(&acb
->rqbuffer_lock
, flags
);
2370 if (acb
->fw_flag
== FW_DEADLOCK
)
2371 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2372 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2374 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2375 ARCMSR_MESSAGE_RETURNCODE_OK
;
2378 case ARCMSR_MESSAGE_CLEAR_WQBUFFER
: {
2379 uint8_t *pQbuffer
= acb
->wqbuffer
;
2380 spin_lock_irqsave(&acb
->wqbuffer_lock
, flags
);
2381 acb
->acb_flags
|= (ACB_F_MESSAGE_WQBUFFER_CLEARED
|
2382 ACB_F_MESSAGE_WQBUFFER_READED
);
2383 acb
->wqbuf_getIndex
= 0;
2384 acb
->wqbuf_putIndex
= 0;
2385 memset(pQbuffer
, 0, ARCMSR_MAX_QBUFFER
);
2386 spin_unlock_irqrestore(&acb
->wqbuffer_lock
, flags
);
2387 if (acb
->fw_flag
== FW_DEADLOCK
)
2388 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2389 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2391 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2392 ARCMSR_MESSAGE_RETURNCODE_OK
;
2395 case ARCMSR_MESSAGE_CLEAR_ALLQBUFFER
: {
2397 arcmsr_clear_iop2drv_rqueue_buffer(acb
);
2398 spin_lock_irqsave(&acb
->rqbuffer_lock
, flags
);
2399 acb
->acb_flags
|= ACB_F_MESSAGE_RQBUFFER_CLEARED
;
2400 acb
->rqbuf_getIndex
= 0;
2401 acb
->rqbuf_putIndex
= 0;
2402 pQbuffer
= acb
->rqbuffer
;
2403 memset(pQbuffer
, 0, sizeof(struct QBUFFER
));
2404 spin_unlock_irqrestore(&acb
->rqbuffer_lock
, flags
);
2405 spin_lock_irqsave(&acb
->wqbuffer_lock
, flags
);
2406 acb
->acb_flags
|= (ACB_F_MESSAGE_WQBUFFER_CLEARED
|
2407 ACB_F_MESSAGE_WQBUFFER_READED
);
2408 acb
->wqbuf_getIndex
= 0;
2409 acb
->wqbuf_putIndex
= 0;
2410 pQbuffer
= acb
->wqbuffer
;
2411 memset(pQbuffer
, 0, sizeof(struct QBUFFER
));
2412 spin_unlock_irqrestore(&acb
->wqbuffer_lock
, flags
);
2413 if (acb
->fw_flag
== FW_DEADLOCK
)
2414 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2415 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2417 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2418 ARCMSR_MESSAGE_RETURNCODE_OK
;
2421 case ARCMSR_MESSAGE_RETURN_CODE_3F
: {
2422 if (acb
->fw_flag
== FW_DEADLOCK
)
2423 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2424 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2426 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2427 ARCMSR_MESSAGE_RETURNCODE_3F
;
2430 case ARCMSR_MESSAGE_SAY_HELLO
: {
2431 int8_t *hello_string
= "Hello! I am ARCMSR";
2432 if (acb
->fw_flag
== FW_DEADLOCK
)
2433 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2434 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2436 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2437 ARCMSR_MESSAGE_RETURNCODE_OK
;
2438 memcpy(pcmdmessagefld
->messagedatabuffer
,
2439 hello_string
, (int16_t)strlen(hello_string
));
2442 case ARCMSR_MESSAGE_SAY_GOODBYE
: {
2443 if (acb
->fw_flag
== FW_DEADLOCK
)
2444 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2445 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2447 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2448 ARCMSR_MESSAGE_RETURNCODE_OK
;
2449 arcmsr_iop_parking(acb
);
2452 case ARCMSR_MESSAGE_FLUSH_ADAPTER_CACHE
: {
2453 if (acb
->fw_flag
== FW_DEADLOCK
)
2454 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2455 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2457 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2458 ARCMSR_MESSAGE_RETURNCODE_OK
;
2459 arcmsr_flush_adapter_cache(acb
);
2463 retvalue
= ARCMSR_MESSAGE_FAIL
;
2464 pr_info("%s: unknown controlcode!\n", __func__
);
2468 struct scatterlist
*sg
= scsi_sglist(cmd
);
2469 kunmap_atomic(buffer
- sg
->offset
);
2474 static struct CommandControlBlock
*arcmsr_get_freeccb(struct AdapterControlBlock
*acb
)
2476 struct list_head
*head
= &acb
->ccb_free_list
;
2477 struct CommandControlBlock
*ccb
= NULL
;
2478 unsigned long flags
;
2479 spin_lock_irqsave(&acb
->ccblist_lock
, flags
);
2480 if (!list_empty(head
)) {
2481 ccb
= list_entry(head
->next
, struct CommandControlBlock
, list
);
2482 list_del_init(&ccb
->list
);
2484 spin_unlock_irqrestore(&acb
->ccblist_lock
, flags
);
2487 spin_unlock_irqrestore(&acb
->ccblist_lock
, flags
);
2491 static void arcmsr_handle_virtual_command(struct AdapterControlBlock
*acb
,
2492 struct scsi_cmnd
*cmd
)
2494 switch (cmd
->cmnd
[0]) {
2496 unsigned char inqdata
[36];
2498 struct scatterlist
*sg
;
2500 if (cmd
->device
->lun
) {
2501 cmd
->result
= (DID_TIME_OUT
<< 16);
2502 cmd
->scsi_done(cmd
);
2505 inqdata
[0] = TYPE_PROCESSOR
;
2506 /* Periph Qualifier & Periph Dev Type */
2508 /* rem media bit & Dev Type Modifier */
2510 /* ISO, ECMA, & ANSI versions */
2512 /* length of additional data */
2513 strncpy(&inqdata
[8], "Areca ", 8);
2514 /* Vendor Identification */
2515 strncpy(&inqdata
[16], "RAID controller ", 16);
2516 /* Product Identification */
2517 strncpy(&inqdata
[32], "R001", 4); /* Product Revision */
2519 sg
= scsi_sglist(cmd
);
2520 buffer
= kmap_atomic(sg_page(sg
)) + sg
->offset
;
2522 memcpy(buffer
, inqdata
, sizeof(inqdata
));
2523 sg
= scsi_sglist(cmd
);
2524 kunmap_atomic(buffer
- sg
->offset
);
2526 cmd
->scsi_done(cmd
);
2531 if (arcmsr_iop_message_xfer(acb
, cmd
))
2532 cmd
->result
= (DID_ERROR
<< 16);
2533 cmd
->scsi_done(cmd
);
2537 cmd
->scsi_done(cmd
);
2541 static int arcmsr_queue_command_lck(struct scsi_cmnd
*cmd
,
2542 void (* done
)(struct scsi_cmnd
*))
2544 struct Scsi_Host
*host
= cmd
->device
->host
;
2545 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
2546 struct CommandControlBlock
*ccb
;
2547 int target
= cmd
->device
->id
;
2548 cmd
->scsi_done
= done
;
2549 cmd
->host_scribble
= NULL
;
2552 /* virtual device for iop message transfer */
2553 arcmsr_handle_virtual_command(acb
, cmd
);
2556 ccb
= arcmsr_get_freeccb(acb
);
2558 return SCSI_MLQUEUE_HOST_BUSY
;
2559 if (arcmsr_build_ccb( acb
, ccb
, cmd
) == FAILED
) {
2560 cmd
->result
= (DID_ERROR
<< 16) | (RESERVATION_CONFLICT
<< 1);
2561 cmd
->scsi_done(cmd
);
2564 arcmsr_post_ccb(acb
, ccb
);
2568 static DEF_SCSI_QCMD(arcmsr_queue_command
)
2570 static bool arcmsr_hbaA_get_config(struct AdapterControlBlock
*acb
)
2572 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2573 char *acb_firm_model
= acb
->firm_model
;
2574 char *acb_firm_version
= acb
->firm_version
;
2575 char *acb_device_map
= acb
->device_map
;
2576 char __iomem
*iop_firm_model
= (char __iomem
*)(®
->message_rwbuffer
[15]);
2577 char __iomem
*iop_firm_version
= (char __iomem
*)(®
->message_rwbuffer
[17]);
2578 char __iomem
*iop_device_map
= (char __iomem
*)(®
->message_rwbuffer
[21]);
2580 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
2581 if (!arcmsr_hbaA_wait_msgint_ready(acb
)) {
2582 printk(KERN_NOTICE
"arcmsr%d: wait 'get adapter firmware \
2583 miscellaneous data' timeout \n", acb
->host
->host_no
);
2588 *acb_firm_model
= readb(iop_firm_model
);
2596 *acb_firm_version
= readb(iop_firm_version
);
2604 *acb_device_map
= readb(iop_device_map
);
2609 pr_notice("Areca RAID Controller%d: Model %s, F/W %s\n",
2613 acb
->signature
= readl(®
->message_rwbuffer
[0]);
2614 acb
->firm_request_len
= readl(®
->message_rwbuffer
[1]);
2615 acb
->firm_numbers_queue
= readl(®
->message_rwbuffer
[2]);
2616 acb
->firm_sdram_size
= readl(®
->message_rwbuffer
[3]);
2617 acb
->firm_hd_channels
= readl(®
->message_rwbuffer
[4]);
2618 acb
->firm_cfg_version
= readl(®
->message_rwbuffer
[25]); /*firm_cfg_version,25,100-103*/
2621 static bool arcmsr_hbaB_get_config(struct AdapterControlBlock
*acb
)
2623 struct MessageUnit_B
*reg
= acb
->pmuB
;
2624 struct pci_dev
*pdev
= acb
->pdev
;
2626 dma_addr_t dma_coherent_handle
;
2627 char *acb_firm_model
= acb
->firm_model
;
2628 char *acb_firm_version
= acb
->firm_version
;
2629 char *acb_device_map
= acb
->device_map
;
2630 char __iomem
*iop_firm_model
;
2631 /*firm_model,15,60-67*/
2632 char __iomem
*iop_firm_version
;
2633 /*firm_version,17,68-83*/
2634 char __iomem
*iop_device_map
;
2635 /*firm_version,21,84-99*/
2638 acb
->roundup_ccbsize
= roundup(sizeof(struct MessageUnit_B
), 32);
2639 dma_coherent
= dma_alloc_coherent(&pdev
->dev
, acb
->roundup_ccbsize
,
2640 &dma_coherent_handle
, GFP_KERNEL
);
2643 "arcmsr%d: dma_alloc_coherent got error for hbb mu\n",
2644 acb
->host
->host_no
);
2647 acb
->dma_coherent_handle2
= dma_coherent_handle
;
2648 acb
->dma_coherent2
= dma_coherent
;
2649 reg
= (struct MessageUnit_B
*)dma_coherent
;
2651 reg
->drv2iop_doorbell
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base0
+ ARCMSR_DRV2IOP_DOORBELL
);
2652 reg
->drv2iop_doorbell_mask
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base0
+ ARCMSR_DRV2IOP_DOORBELL_MASK
);
2653 reg
->iop2drv_doorbell
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base0
+ ARCMSR_IOP2DRV_DOORBELL
);
2654 reg
->iop2drv_doorbell_mask
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base0
+ ARCMSR_IOP2DRV_DOORBELL_MASK
);
2655 reg
->message_wbuffer
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base1
+ ARCMSR_MESSAGE_WBUFFER
);
2656 reg
->message_rbuffer
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base1
+ ARCMSR_MESSAGE_RBUFFER
);
2657 reg
->message_rwbuffer
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base1
+ ARCMSR_MESSAGE_RWBUFFER
);
2658 iop_firm_model
= (char __iomem
*)(®
->message_rwbuffer
[15]); /*firm_model,15,60-67*/
2659 iop_firm_version
= (char __iomem
*)(®
->message_rwbuffer
[17]); /*firm_version,17,68-83*/
2660 iop_device_map
= (char __iomem
*)(®
->message_rwbuffer
[21]); /*firm_version,21,84-99*/
2662 writel(ARCMSR_MESSAGE_GET_CONFIG
, reg
->drv2iop_doorbell
);
2663 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
2664 printk(KERN_NOTICE
"arcmsr%d: wait 'get adapter firmware \
2665 miscellaneous data' timeout \n", acb
->host
->host_no
);
2670 *acb_firm_model
= readb(iop_firm_model
);
2677 *acb_firm_version
= readb(iop_firm_version
);
2685 *acb_device_map
= readb(iop_device_map
);
2691 pr_notice("Areca RAID Controller%d: Model %s, F/W %s\n",
2696 acb
->signature
= readl(®
->message_rwbuffer
[0]);
2697 /*firm_signature,1,00-03*/
2698 acb
->firm_request_len
= readl(®
->message_rwbuffer
[1]);
2699 /*firm_request_len,1,04-07*/
2700 acb
->firm_numbers_queue
= readl(®
->message_rwbuffer
[2]);
2701 /*firm_numbers_queue,2,08-11*/
2702 acb
->firm_sdram_size
= readl(®
->message_rwbuffer
[3]);
2703 /*firm_sdram_size,3,12-15*/
2704 acb
->firm_hd_channels
= readl(®
->message_rwbuffer
[4]);
2705 /*firm_ide_channels,4,16-19*/
2706 acb
->firm_cfg_version
= readl(®
->message_rwbuffer
[25]); /*firm_cfg_version,25,100-103*/
2707 /*firm_ide_channels,4,16-19*/
2710 dma_free_coherent(&acb
->pdev
->dev
, acb
->roundup_ccbsize
,
2711 acb
->dma_coherent2
, acb
->dma_coherent_handle2
);
2715 static bool arcmsr_hbaC_get_config(struct AdapterControlBlock
*pACB
)
2717 uint32_t intmask_org
, Index
, firmware_state
= 0;
2718 struct MessageUnit_C __iomem
*reg
= pACB
->pmuC
;
2719 char *acb_firm_model
= pACB
->firm_model
;
2720 char *acb_firm_version
= pACB
->firm_version
;
2721 char __iomem
*iop_firm_model
= (char __iomem
*)(®
->msgcode_rwbuffer
[15]); /*firm_model,15,60-67*/
2722 char __iomem
*iop_firm_version
= (char __iomem
*)(®
->msgcode_rwbuffer
[17]); /*firm_version,17,68-83*/
2724 /* disable all outbound interrupt */
2725 intmask_org
= readl(®
->host_int_mask
); /* disable outbound message0 int */
2726 writel(intmask_org
|ARCMSR_HBCMU_ALL_INTMASKENABLE
, ®
->host_int_mask
);
2727 /* wait firmware ready */
2729 firmware_state
= readl(®
->outbound_msgaddr1
);
2730 } while ((firmware_state
& ARCMSR_HBCMU_MESSAGE_FIRMWARE_OK
) == 0);
2731 /* post "get config" instruction */
2732 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
2733 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
2734 /* wait message ready */
2735 for (Index
= 0; Index
< 2000; Index
++) {
2736 if (readl(®
->outbound_doorbell
) & ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE
) {
2737 writel(ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE_DOORBELL_CLEAR
, ®
->outbound_doorbell_clear
);/*clear interrupt*/
2742 if (Index
>= 2000) {
2743 printk(KERN_NOTICE
"arcmsr%d: wait 'get adapter firmware \
2744 miscellaneous data' timeout \n", pACB
->host
->host_no
);
2749 *acb_firm_model
= readb(iop_firm_model
);
2756 *acb_firm_version
= readb(iop_firm_version
);
2761 pr_notice("Areca RAID Controller%d: Model %s, F/W %s\n",
2762 pACB
->host
->host_no
,
2764 pACB
->firm_version
);
2765 pACB
->firm_request_len
= readl(®
->msgcode_rwbuffer
[1]); /*firm_request_len,1,04-07*/
2766 pACB
->firm_numbers_queue
= readl(®
->msgcode_rwbuffer
[2]); /*firm_numbers_queue,2,08-11*/
2767 pACB
->firm_sdram_size
= readl(®
->msgcode_rwbuffer
[3]); /*firm_sdram_size,3,12-15*/
2768 pACB
->firm_hd_channels
= readl(®
->msgcode_rwbuffer
[4]); /*firm_ide_channels,4,16-19*/
2769 pACB
->firm_cfg_version
= readl(®
->msgcode_rwbuffer
[25]); /*firm_cfg_version,25,100-103*/
2770 /*all interrupt service will be enable at arcmsr_iop_init*/
2774 static bool arcmsr_hbaD_get_config(struct AdapterControlBlock
*acb
)
2776 char *acb_firm_model
= acb
->firm_model
;
2777 char *acb_firm_version
= acb
->firm_version
;
2778 char *acb_device_map
= acb
->device_map
;
2779 char __iomem
*iop_firm_model
;
2780 char __iomem
*iop_firm_version
;
2781 char __iomem
*iop_device_map
;
2783 struct MessageUnit_D
*reg
;
2784 void *dma_coherent2
;
2785 dma_addr_t dma_coherent_handle2
;
2786 struct pci_dev
*pdev
= acb
->pdev
;
2788 acb
->roundup_ccbsize
= roundup(sizeof(struct MessageUnit_D
), 32);
2789 dma_coherent2
= dma_alloc_coherent(&pdev
->dev
, acb
->roundup_ccbsize
,
2790 &dma_coherent_handle2
, GFP_KERNEL
);
2791 if (!dma_coherent2
) {
2792 pr_notice("DMA allocation failed...\n");
2795 memset(dma_coherent2
, 0, acb
->roundup_ccbsize
);
2796 acb
->dma_coherent_handle2
= dma_coherent_handle2
;
2797 acb
->dma_coherent2
= dma_coherent2
;
2798 reg
= (struct MessageUnit_D
*)dma_coherent2
;
2800 reg
->chip_id
= acb
->mem_base0
+ ARCMSR_ARC1214_CHIP_ID
;
2801 reg
->cpu_mem_config
= acb
->mem_base0
+
2802 ARCMSR_ARC1214_CPU_MEMORY_CONFIGURATION
;
2803 reg
->i2o_host_interrupt_mask
= acb
->mem_base0
+
2804 ARCMSR_ARC1214_I2_HOST_INTERRUPT_MASK
;
2805 reg
->sample_at_reset
= acb
->mem_base0
+ ARCMSR_ARC1214_SAMPLE_RESET
;
2806 reg
->reset_request
= acb
->mem_base0
+ ARCMSR_ARC1214_RESET_REQUEST
;
2807 reg
->host_int_status
= acb
->mem_base0
+
2808 ARCMSR_ARC1214_MAIN_INTERRUPT_STATUS
;
2809 reg
->pcief0_int_enable
= acb
->mem_base0
+
2810 ARCMSR_ARC1214_PCIE_F0_INTERRUPT_ENABLE
;
2811 reg
->inbound_msgaddr0
= acb
->mem_base0
+
2812 ARCMSR_ARC1214_INBOUND_MESSAGE0
;
2813 reg
->inbound_msgaddr1
= acb
->mem_base0
+
2814 ARCMSR_ARC1214_INBOUND_MESSAGE1
;
2815 reg
->outbound_msgaddr0
= acb
->mem_base0
+
2816 ARCMSR_ARC1214_OUTBOUND_MESSAGE0
;
2817 reg
->outbound_msgaddr1
= acb
->mem_base0
+
2818 ARCMSR_ARC1214_OUTBOUND_MESSAGE1
;
2819 reg
->inbound_doorbell
= acb
->mem_base0
+
2820 ARCMSR_ARC1214_INBOUND_DOORBELL
;
2821 reg
->outbound_doorbell
= acb
->mem_base0
+
2822 ARCMSR_ARC1214_OUTBOUND_DOORBELL
;
2823 reg
->outbound_doorbell_enable
= acb
->mem_base0
+
2824 ARCMSR_ARC1214_OUTBOUND_DOORBELL_ENABLE
;
2825 reg
->inboundlist_base_low
= acb
->mem_base0
+
2826 ARCMSR_ARC1214_INBOUND_LIST_BASE_LOW
;
2827 reg
->inboundlist_base_high
= acb
->mem_base0
+
2828 ARCMSR_ARC1214_INBOUND_LIST_BASE_HIGH
;
2829 reg
->inboundlist_write_pointer
= acb
->mem_base0
+
2830 ARCMSR_ARC1214_INBOUND_LIST_WRITE_POINTER
;
2831 reg
->outboundlist_base_low
= acb
->mem_base0
+
2832 ARCMSR_ARC1214_OUTBOUND_LIST_BASE_LOW
;
2833 reg
->outboundlist_base_high
= acb
->mem_base0
+
2834 ARCMSR_ARC1214_OUTBOUND_LIST_BASE_HIGH
;
2835 reg
->outboundlist_copy_pointer
= acb
->mem_base0
+
2836 ARCMSR_ARC1214_OUTBOUND_LIST_COPY_POINTER
;
2837 reg
->outboundlist_read_pointer
= acb
->mem_base0
+
2838 ARCMSR_ARC1214_OUTBOUND_LIST_READ_POINTER
;
2839 reg
->outboundlist_interrupt_cause
= acb
->mem_base0
+
2840 ARCMSR_ARC1214_OUTBOUND_INTERRUPT_CAUSE
;
2841 reg
->outboundlist_interrupt_enable
= acb
->mem_base0
+
2842 ARCMSR_ARC1214_OUTBOUND_INTERRUPT_ENABLE
;
2843 reg
->message_wbuffer
= acb
->mem_base0
+ ARCMSR_ARC1214_MESSAGE_WBUFFER
;
2844 reg
->message_rbuffer
= acb
->mem_base0
+ ARCMSR_ARC1214_MESSAGE_RBUFFER
;
2845 reg
->msgcode_rwbuffer
= acb
->mem_base0
+
2846 ARCMSR_ARC1214_MESSAGE_RWBUFFER
;
2847 iop_firm_model
= (char __iomem
*)(®
->msgcode_rwbuffer
[15]);
2848 iop_firm_version
= (char __iomem
*)(®
->msgcode_rwbuffer
[17]);
2849 iop_device_map
= (char __iomem
*)(®
->msgcode_rwbuffer
[21]);
2850 if (readl(acb
->pmuD
->outbound_doorbell
) &
2851 ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
) {
2852 writel(ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
,
2853 acb
->pmuD
->outbound_doorbell
);/*clear interrupt*/
2855 /* post "get config" instruction */
2856 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, reg
->inbound_msgaddr0
);
2857 /* wait message ready */
2858 if (!arcmsr_hbaD_wait_msgint_ready(acb
)) {
2859 pr_notice("arcmsr%d: wait get adapter firmware "
2860 "miscellaneous data timeout\n", acb
->host
->host_no
);
2861 dma_free_coherent(&acb
->pdev
->dev
, acb
->roundup_ccbsize
,
2862 acb
->dma_coherent2
, acb
->dma_coherent_handle2
);
2867 *acb_firm_model
= readb(iop_firm_model
);
2874 *acb_firm_version
= readb(iop_firm_version
);
2881 *acb_device_map
= readb(iop_device_map
);
2886 acb
->signature
= readl(®
->msgcode_rwbuffer
[0]);
2887 /*firm_signature,1,00-03*/
2888 acb
->firm_request_len
= readl(®
->msgcode_rwbuffer
[1]);
2889 /*firm_request_len,1,04-07*/
2890 acb
->firm_numbers_queue
= readl(®
->msgcode_rwbuffer
[2]);
2891 /*firm_numbers_queue,2,08-11*/
2892 acb
->firm_sdram_size
= readl(®
->msgcode_rwbuffer
[3]);
2893 /*firm_sdram_size,3,12-15*/
2894 acb
->firm_hd_channels
= readl(®
->msgcode_rwbuffer
[4]);
2895 /*firm_hd_channels,4,16-19*/
2896 acb
->firm_cfg_version
= readl(®
->msgcode_rwbuffer
[25]);
2897 pr_notice("Areca RAID Controller%d: Model %s, F/W %s\n",
2904 static bool arcmsr_get_firmware_spec(struct AdapterControlBlock
*acb
)
2908 switch (acb
->adapter_type
) {
2909 case ACB_ADAPTER_TYPE_A
:
2910 rtn
= arcmsr_hbaA_get_config(acb
);
2912 case ACB_ADAPTER_TYPE_B
:
2913 rtn
= arcmsr_hbaB_get_config(acb
);
2915 case ACB_ADAPTER_TYPE_C
:
2916 rtn
= arcmsr_hbaC_get_config(acb
);
2918 case ACB_ADAPTER_TYPE_D
:
2919 rtn
= arcmsr_hbaD_get_config(acb
);
2924 if (acb
->firm_numbers_queue
> ARCMSR_MAX_OUTSTANDING_CMD
)
2925 acb
->maxOutstanding
= ARCMSR_MAX_OUTSTANDING_CMD
;
2927 acb
->maxOutstanding
= acb
->firm_numbers_queue
- 1;
2928 acb
->host
->can_queue
= acb
->maxOutstanding
;
2932 static int arcmsr_hbaA_polling_ccbdone(struct AdapterControlBlock
*acb
,
2933 struct CommandControlBlock
*poll_ccb
)
2935 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2936 struct CommandControlBlock
*ccb
;
2937 struct ARCMSR_CDB
*arcmsr_cdb
;
2938 uint32_t flag_ccb
, outbound_intstatus
, poll_ccb_done
= 0, poll_count
= 0;
2941 polling_hba_ccb_retry
:
2943 outbound_intstatus
= readl(®
->outbound_intstatus
) & acb
->outbound_int_enable
;
2944 writel(outbound_intstatus
, ®
->outbound_intstatus
);/*clear interrupt*/
2946 if ((flag_ccb
= readl(®
->outbound_queueport
)) == 0xFFFFFFFF) {
2952 if (poll_count
> 100){
2956 goto polling_hba_ccb_retry
;
2959 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ (flag_ccb
<< 5));
2960 ccb
= container_of(arcmsr_cdb
, struct CommandControlBlock
, arcmsr_cdb
);
2961 poll_ccb_done
|= (ccb
== poll_ccb
) ? 1 : 0;
2962 if ((ccb
->acb
!= acb
) || (ccb
->startdone
!= ARCMSR_CCB_START
)) {
2963 if ((ccb
->startdone
== ARCMSR_CCB_ABORTED
) || (ccb
== poll_ccb
)) {
2964 printk(KERN_NOTICE
"arcmsr%d: scsi id = %d lun = %d ccb = '0x%p'"
2965 " poll command abort successfully \n"
2966 , acb
->host
->host_no
2967 , ccb
->pcmd
->device
->id
2968 , (u32
)ccb
->pcmd
->device
->lun
2970 ccb
->pcmd
->result
= DID_ABORT
<< 16;
2971 arcmsr_ccb_complete(ccb
);
2974 printk(KERN_NOTICE
"arcmsr%d: polling get an illegal ccb"
2975 " command done ccb = '0x%p'"
2976 "ccboutstandingcount = %d \n"
2977 , acb
->host
->host_no
2979 , atomic_read(&acb
->ccboutstandingcount
));
2982 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
2983 arcmsr_report_ccb_state(acb
, ccb
, error
);
2988 static int arcmsr_hbaB_polling_ccbdone(struct AdapterControlBlock
*acb
,
2989 struct CommandControlBlock
*poll_ccb
)
2991 struct MessageUnit_B
*reg
= acb
->pmuB
;
2992 struct ARCMSR_CDB
*arcmsr_cdb
;
2993 struct CommandControlBlock
*ccb
;
2994 uint32_t flag_ccb
, poll_ccb_done
= 0, poll_count
= 0;
2997 polling_hbb_ccb_retry
:
3000 /* clear doorbell interrupt */
3001 writel(ARCMSR_DOORBELL_INT_CLEAR_PATTERN
, reg
->iop2drv_doorbell
);
3003 index
= reg
->doneq_index
;
3004 flag_ccb
= reg
->done_qbuffer
[index
];
3005 if (flag_ccb
== 0) {
3011 if (poll_count
> 100){
3015 goto polling_hbb_ccb_retry
;
3018 reg
->done_qbuffer
[index
] = 0;
3020 /*if last index number set it to 0 */
3021 index
%= ARCMSR_MAX_HBB_POSTQUEUE
;
3022 reg
->doneq_index
= index
;
3023 /* check if command done with no error*/
3024 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ (flag_ccb
<< 5));
3025 ccb
= container_of(arcmsr_cdb
, struct CommandControlBlock
, arcmsr_cdb
);
3026 poll_ccb_done
|= (ccb
== poll_ccb
) ? 1 : 0;
3027 if ((ccb
->acb
!= acb
) || (ccb
->startdone
!= ARCMSR_CCB_START
)) {
3028 if ((ccb
->startdone
== ARCMSR_CCB_ABORTED
) || (ccb
== poll_ccb
)) {
3029 printk(KERN_NOTICE
"arcmsr%d: scsi id = %d lun = %d ccb = '0x%p'"
3030 " poll command abort successfully \n"
3032 ,ccb
->pcmd
->device
->id
3033 ,(u32
)ccb
->pcmd
->device
->lun
3035 ccb
->pcmd
->result
= DID_ABORT
<< 16;
3036 arcmsr_ccb_complete(ccb
);
3039 printk(KERN_NOTICE
"arcmsr%d: polling get an illegal ccb"
3040 " command done ccb = '0x%p'"
3041 "ccboutstandingcount = %d \n"
3042 , acb
->host
->host_no
3044 , atomic_read(&acb
->ccboutstandingcount
));
3047 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
3048 arcmsr_report_ccb_state(acb
, ccb
, error
);
3053 static int arcmsr_hbaC_polling_ccbdone(struct AdapterControlBlock
*acb
,
3054 struct CommandControlBlock
*poll_ccb
)
3056 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
3057 uint32_t flag_ccb
, ccb_cdb_phy
;
3058 struct ARCMSR_CDB
*arcmsr_cdb
;
3060 struct CommandControlBlock
*pCCB
;
3061 uint32_t poll_ccb_done
= 0, poll_count
= 0;
3063 polling_hbc_ccb_retry
:
3066 if ((readl(®
->host_int_status
) & ARCMSR_HBCMU_OUTBOUND_POSTQUEUE_ISR
) == 0) {
3067 if (poll_ccb_done
) {
3072 if (poll_count
> 100) {
3076 goto polling_hbc_ccb_retry
;
3079 flag_ccb
= readl(®
->outbound_queueport_low
);
3080 ccb_cdb_phy
= (flag_ccb
& 0xFFFFFFF0);
3081 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ ccb_cdb_phy
);/*frame must be 32 bytes aligned*/
3082 pCCB
= container_of(arcmsr_cdb
, struct CommandControlBlock
, arcmsr_cdb
);
3083 poll_ccb_done
|= (pCCB
== poll_ccb
) ? 1 : 0;
3084 /* check ifcommand done with no error*/
3085 if ((pCCB
->acb
!= acb
) || (pCCB
->startdone
!= ARCMSR_CCB_START
)) {
3086 if (pCCB
->startdone
== ARCMSR_CCB_ABORTED
) {
3087 printk(KERN_NOTICE
"arcmsr%d: scsi id = %d lun = %d ccb = '0x%p'"
3088 " poll command abort successfully \n"
3089 , acb
->host
->host_no
3090 , pCCB
->pcmd
->device
->id
3091 , (u32
)pCCB
->pcmd
->device
->lun
3093 pCCB
->pcmd
->result
= DID_ABORT
<< 16;
3094 arcmsr_ccb_complete(pCCB
);
3097 printk(KERN_NOTICE
"arcmsr%d: polling get an illegal ccb"
3098 " command done ccb = '0x%p'"
3099 "ccboutstandingcount = %d \n"
3100 , acb
->host
->host_no
3102 , atomic_read(&acb
->ccboutstandingcount
));
3105 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
) ? true : false;
3106 arcmsr_report_ccb_state(acb
, pCCB
, error
);
3111 static int arcmsr_hbaD_polling_ccbdone(struct AdapterControlBlock
*acb
,
3112 struct CommandControlBlock
*poll_ccb
)
3115 uint32_t poll_ccb_done
= 0, poll_count
= 0, flag_ccb
, ccb_cdb_phy
;
3116 int rtn
, doneq_index
, index_stripped
, outbound_write_pointer
, toggle
;
3117 unsigned long flags
;
3118 struct ARCMSR_CDB
*arcmsr_cdb
;
3119 struct CommandControlBlock
*pCCB
;
3120 struct MessageUnit_D
*pmu
= acb
->pmuD
;
3122 polling_hbaD_ccb_retry
:
3125 spin_lock_irqsave(&acb
->doneq_lock
, flags
);
3126 outbound_write_pointer
= pmu
->done_qbuffer
[0].addressLow
+ 1;
3127 doneq_index
= pmu
->doneq_index
;
3128 if ((outbound_write_pointer
& 0xFFF) == (doneq_index
& 0xFFF)) {
3129 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
3130 if (poll_ccb_done
) {
3135 if (poll_count
> 40) {
3139 goto polling_hbaD_ccb_retry
;
3142 toggle
= doneq_index
& 0x4000;
3143 index_stripped
= (doneq_index
& 0xFFF) + 1;
3144 index_stripped
%= ARCMSR_MAX_ARC1214_DONEQUEUE
;
3145 pmu
->doneq_index
= index_stripped
? (index_stripped
| toggle
) :
3146 ((toggle
^ 0x4000) + 1);
3147 doneq_index
= pmu
->doneq_index
;
3148 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
3149 flag_ccb
= pmu
->done_qbuffer
[doneq_index
& 0xFFF].addressLow
;
3150 ccb_cdb_phy
= (flag_ccb
& 0xFFFFFFF0);
3151 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+
3153 pCCB
= container_of(arcmsr_cdb
, struct CommandControlBlock
,
3155 poll_ccb_done
|= (pCCB
== poll_ccb
) ? 1 : 0;
3156 if ((pCCB
->acb
!= acb
) ||
3157 (pCCB
->startdone
!= ARCMSR_CCB_START
)) {
3158 if (pCCB
->startdone
== ARCMSR_CCB_ABORTED
) {
3159 pr_notice("arcmsr%d: scsi id = %d "
3160 "lun = %d ccb = '0x%p' poll command "
3161 "abort successfully\n"
3162 , acb
->host
->host_no
3163 , pCCB
->pcmd
->device
->id
3164 , (u32
)pCCB
->pcmd
->device
->lun
3166 pCCB
->pcmd
->result
= DID_ABORT
<< 16;
3167 arcmsr_ccb_complete(pCCB
);
3170 pr_notice("arcmsr%d: polling an illegal "
3171 "ccb command done ccb = '0x%p' "
3172 "ccboutstandingcount = %d\n"
3173 , acb
->host
->host_no
3175 , atomic_read(&acb
->ccboutstandingcount
));
3178 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
)
3180 arcmsr_report_ccb_state(acb
, pCCB
, error
);
3185 static int arcmsr_polling_ccbdone(struct AdapterControlBlock
*acb
,
3186 struct CommandControlBlock
*poll_ccb
)
3189 switch (acb
->adapter_type
) {
3191 case ACB_ADAPTER_TYPE_A
: {
3192 rtn
= arcmsr_hbaA_polling_ccbdone(acb
, poll_ccb
);
3196 case ACB_ADAPTER_TYPE_B
: {
3197 rtn
= arcmsr_hbaB_polling_ccbdone(acb
, poll_ccb
);
3200 case ACB_ADAPTER_TYPE_C
: {
3201 rtn
= arcmsr_hbaC_polling_ccbdone(acb
, poll_ccb
);
3204 case ACB_ADAPTER_TYPE_D
:
3205 rtn
= arcmsr_hbaD_polling_ccbdone(acb
, poll_ccb
);
3211 static int arcmsr_iop_confirm(struct AdapterControlBlock
*acb
)
3213 uint32_t cdb_phyaddr
, cdb_phyaddr_hi32
;
3214 dma_addr_t dma_coherent_handle
;
3217 ********************************************************************
3218 ** here we need to tell iop 331 our freeccb.HighPart
3219 ** if freeccb.HighPart is not zero
3220 ********************************************************************
3222 switch (acb
->adapter_type
) {
3223 case ACB_ADAPTER_TYPE_B
:
3224 case ACB_ADAPTER_TYPE_D
:
3225 dma_coherent_handle
= acb
->dma_coherent_handle2
;
3228 dma_coherent_handle
= acb
->dma_coherent_handle
;
3231 cdb_phyaddr
= lower_32_bits(dma_coherent_handle
);
3232 cdb_phyaddr_hi32
= upper_32_bits(dma_coherent_handle
);
3233 acb
->cdb_phyaddr_hi32
= cdb_phyaddr_hi32
;
3235 ***********************************************************************
3236 ** if adapter type B, set window of "post command Q"
3237 ***********************************************************************
3239 switch (acb
->adapter_type
) {
3241 case ACB_ADAPTER_TYPE_A
: {
3242 if (cdb_phyaddr_hi32
!= 0) {
3243 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
3244 writel(ARCMSR_SIGNATURE_SET_CONFIG
, \
3245 ®
->message_rwbuffer
[0]);
3246 writel(cdb_phyaddr_hi32
, ®
->message_rwbuffer
[1]);
3247 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG
, \
3248 ®
->inbound_msgaddr0
);
3249 if (!arcmsr_hbaA_wait_msgint_ready(acb
)) {
3250 printk(KERN_NOTICE
"arcmsr%d: ""set ccb high \
3251 part physical address timeout\n",
3252 acb
->host
->host_no
);
3259 case ACB_ADAPTER_TYPE_B
: {
3260 uint32_t __iomem
*rwbuffer
;
3262 struct MessageUnit_B
*reg
= acb
->pmuB
;
3263 reg
->postq_index
= 0;
3264 reg
->doneq_index
= 0;
3265 writel(ARCMSR_MESSAGE_SET_POST_WINDOW
, reg
->drv2iop_doorbell
);
3266 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
3267 printk(KERN_NOTICE
"arcmsr%d: cannot set driver mode\n", \
3268 acb
->host
->host_no
);
3271 rwbuffer
= reg
->message_rwbuffer
;
3272 /* driver "set config" signature */
3273 writel(ARCMSR_SIGNATURE_SET_CONFIG
, rwbuffer
++);
3274 /* normal should be zero */
3275 writel(cdb_phyaddr_hi32
, rwbuffer
++);
3276 /* postQ size (256 + 8)*4 */
3277 writel(cdb_phyaddr
, rwbuffer
++);
3278 /* doneQ size (256 + 8)*4 */
3279 writel(cdb_phyaddr
+ 1056, rwbuffer
++);
3280 /* ccb maxQ size must be --> [(256 + 8)*4]*/
3281 writel(1056, rwbuffer
);
3283 writel(ARCMSR_MESSAGE_SET_CONFIG
, reg
->drv2iop_doorbell
);
3284 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
3285 printk(KERN_NOTICE
"arcmsr%d: 'set command Q window' \
3286 timeout \n",acb
->host
->host_no
);
3289 writel(ARCMSR_MESSAGE_START_DRIVER_MODE
, reg
->drv2iop_doorbell
);
3290 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
3291 pr_err("arcmsr%d: can't set driver mode.\n",
3292 acb
->host
->host_no
);
3297 case ACB_ADAPTER_TYPE_C
: {
3298 if (cdb_phyaddr_hi32
!= 0) {
3299 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
3301 printk(KERN_NOTICE
"arcmsr%d: cdb_phyaddr_hi32=0x%x\n",
3302 acb
->adapter_index
, cdb_phyaddr_hi32
);
3303 writel(ARCMSR_SIGNATURE_SET_CONFIG
, ®
->msgcode_rwbuffer
[0]);
3304 writel(cdb_phyaddr_hi32
, ®
->msgcode_rwbuffer
[1]);
3305 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG
, ®
->inbound_msgaddr0
);
3306 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
3307 if (!arcmsr_hbaC_wait_msgint_ready(acb
)) {
3308 printk(KERN_NOTICE
"arcmsr%d: 'set command Q window' \
3309 timeout \n", acb
->host
->host_no
);
3315 case ACB_ADAPTER_TYPE_D
: {
3316 uint32_t __iomem
*rwbuffer
;
3317 struct MessageUnit_D
*reg
= acb
->pmuD
;
3318 reg
->postq_index
= 0;
3319 reg
->doneq_index
= 0;
3320 rwbuffer
= reg
->msgcode_rwbuffer
;
3321 writel(ARCMSR_SIGNATURE_SET_CONFIG
, rwbuffer
++);
3322 writel(cdb_phyaddr_hi32
, rwbuffer
++);
3323 writel(cdb_phyaddr
, rwbuffer
++);
3324 writel(cdb_phyaddr
+ (ARCMSR_MAX_ARC1214_POSTQUEUE
*
3325 sizeof(struct InBound_SRB
)), rwbuffer
++);
3326 writel(0x100, rwbuffer
);
3327 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG
, reg
->inbound_msgaddr0
);
3328 if (!arcmsr_hbaD_wait_msgint_ready(acb
)) {
3329 pr_notice("arcmsr%d: 'set command Q window' timeout\n",
3330 acb
->host
->host_no
);
3339 static void arcmsr_wait_firmware_ready(struct AdapterControlBlock
*acb
)
3341 uint32_t firmware_state
= 0;
3342 switch (acb
->adapter_type
) {
3344 case ACB_ADAPTER_TYPE_A
: {
3345 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
3347 firmware_state
= readl(®
->outbound_msgaddr1
);
3348 } while ((firmware_state
& ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK
) == 0);
3352 case ACB_ADAPTER_TYPE_B
: {
3353 struct MessageUnit_B
*reg
= acb
->pmuB
;
3355 firmware_state
= readl(reg
->iop2drv_doorbell
);
3356 } while ((firmware_state
& ARCMSR_MESSAGE_FIRMWARE_OK
) == 0);
3357 writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT
, reg
->drv2iop_doorbell
);
3360 case ACB_ADAPTER_TYPE_C
: {
3361 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
3363 firmware_state
= readl(®
->outbound_msgaddr1
);
3364 } while ((firmware_state
& ARCMSR_HBCMU_MESSAGE_FIRMWARE_OK
) == 0);
3367 case ACB_ADAPTER_TYPE_D
: {
3368 struct MessageUnit_D
*reg
= acb
->pmuD
;
3370 firmware_state
= readl(reg
->outbound_msgaddr1
);
3371 } while ((firmware_state
&
3372 ARCMSR_ARC1214_MESSAGE_FIRMWARE_OK
) == 0);
3378 static void arcmsr_hbaA_request_device_map(struct AdapterControlBlock
*acb
)
3380 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
3381 if (unlikely(atomic_read(&acb
->rq_map_token
) == 0) || ((acb
->acb_flags
& ACB_F_BUS_RESET
) != 0 ) || ((acb
->acb_flags
& ACB_F_ABORT
) != 0 )){
3382 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3385 acb
->fw_flag
= FW_NORMAL
;
3386 if (atomic_read(&acb
->ante_token_value
) == atomic_read(&acb
->rq_map_token
)){
3387 atomic_set(&acb
->rq_map_token
, 16);
3389 atomic_set(&acb
->ante_token_value
, atomic_read(&acb
->rq_map_token
));
3390 if (atomic_dec_and_test(&acb
->rq_map_token
)) {
3391 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3394 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
3395 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3400 static void arcmsr_hbaB_request_device_map(struct AdapterControlBlock
*acb
)
3402 struct MessageUnit_B
*reg
= acb
->pmuB
;
3403 if (unlikely(atomic_read(&acb
->rq_map_token
) == 0) || ((acb
->acb_flags
& ACB_F_BUS_RESET
) != 0 ) || ((acb
->acb_flags
& ACB_F_ABORT
) != 0 )){
3404 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3407 acb
->fw_flag
= FW_NORMAL
;
3408 if (atomic_read(&acb
->ante_token_value
) == atomic_read(&acb
->rq_map_token
)) {
3409 atomic_set(&acb
->rq_map_token
, 16);
3411 atomic_set(&acb
->ante_token_value
, atomic_read(&acb
->rq_map_token
));
3412 if (atomic_dec_and_test(&acb
->rq_map_token
)) {
3413 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3416 writel(ARCMSR_MESSAGE_GET_CONFIG
, reg
->drv2iop_doorbell
);
3417 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3422 static void arcmsr_hbaC_request_device_map(struct AdapterControlBlock
*acb
)
3424 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
3425 if (unlikely(atomic_read(&acb
->rq_map_token
) == 0) || ((acb
->acb_flags
& ACB_F_BUS_RESET
) != 0) || ((acb
->acb_flags
& ACB_F_ABORT
) != 0)) {
3426 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3429 acb
->fw_flag
= FW_NORMAL
;
3430 if (atomic_read(&acb
->ante_token_value
) == atomic_read(&acb
->rq_map_token
)) {
3431 atomic_set(&acb
->rq_map_token
, 16);
3433 atomic_set(&acb
->ante_token_value
, atomic_read(&acb
->rq_map_token
));
3434 if (atomic_dec_and_test(&acb
->rq_map_token
)) {
3435 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3438 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
3439 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
3440 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3445 static void arcmsr_hbaD_request_device_map(struct AdapterControlBlock
*acb
)
3447 struct MessageUnit_D
*reg
= acb
->pmuD
;
3449 if (unlikely(atomic_read(&acb
->rq_map_token
) == 0) ||
3450 ((acb
->acb_flags
& ACB_F_BUS_RESET
) != 0) ||
3451 ((acb
->acb_flags
& ACB_F_ABORT
) != 0)) {
3452 mod_timer(&acb
->eternal_timer
,
3453 jiffies
+ msecs_to_jiffies(6 * HZ
));
3455 acb
->fw_flag
= FW_NORMAL
;
3456 if (atomic_read(&acb
->ante_token_value
) ==
3457 atomic_read(&acb
->rq_map_token
)) {
3458 atomic_set(&acb
->rq_map_token
, 16);
3460 atomic_set(&acb
->ante_token_value
,
3461 atomic_read(&acb
->rq_map_token
));
3462 if (atomic_dec_and_test(&acb
->rq_map_token
)) {
3463 mod_timer(&acb
->eternal_timer
, jiffies
+
3464 msecs_to_jiffies(6 * HZ
));
3467 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
,
3468 reg
->inbound_msgaddr0
);
3469 mod_timer(&acb
->eternal_timer
, jiffies
+
3470 msecs_to_jiffies(6 * HZ
));
3474 static void arcmsr_request_device_map(unsigned long pacb
)
3476 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*)pacb
;
3477 switch (acb
->adapter_type
) {
3478 case ACB_ADAPTER_TYPE_A
: {
3479 arcmsr_hbaA_request_device_map(acb
);
3482 case ACB_ADAPTER_TYPE_B
: {
3483 arcmsr_hbaB_request_device_map(acb
);
3486 case ACB_ADAPTER_TYPE_C
: {
3487 arcmsr_hbaC_request_device_map(acb
);
3490 case ACB_ADAPTER_TYPE_D
:
3491 arcmsr_hbaD_request_device_map(acb
);
3496 static void arcmsr_hbaA_start_bgrb(struct AdapterControlBlock
*acb
)
3498 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
3499 acb
->acb_flags
|= ACB_F_MSG_START_BGRB
;
3500 writel(ARCMSR_INBOUND_MESG0_START_BGRB
, ®
->inbound_msgaddr0
);
3501 if (!arcmsr_hbaA_wait_msgint_ready(acb
)) {
3502 printk(KERN_NOTICE
"arcmsr%d: wait 'start adapter background \
3503 rebulid' timeout \n", acb
->host
->host_no
);
3507 static void arcmsr_hbaB_start_bgrb(struct AdapterControlBlock
*acb
)
3509 struct MessageUnit_B
*reg
= acb
->pmuB
;
3510 acb
->acb_flags
|= ACB_F_MSG_START_BGRB
;
3511 writel(ARCMSR_MESSAGE_START_BGRB
, reg
->drv2iop_doorbell
);
3512 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
3513 printk(KERN_NOTICE
"arcmsr%d: wait 'start adapter background \
3514 rebulid' timeout \n",acb
->host
->host_no
);
3518 static void arcmsr_hbaC_start_bgrb(struct AdapterControlBlock
*pACB
)
3520 struct MessageUnit_C __iomem
*phbcmu
= pACB
->pmuC
;
3521 pACB
->acb_flags
|= ACB_F_MSG_START_BGRB
;
3522 writel(ARCMSR_INBOUND_MESG0_START_BGRB
, &phbcmu
->inbound_msgaddr0
);
3523 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, &phbcmu
->inbound_doorbell
);
3524 if (!arcmsr_hbaC_wait_msgint_ready(pACB
)) {
3525 printk(KERN_NOTICE
"arcmsr%d: wait 'start adapter background \
3526 rebulid' timeout \n", pACB
->host
->host_no
);
3531 static void arcmsr_hbaD_start_bgrb(struct AdapterControlBlock
*pACB
)
3533 struct MessageUnit_D
*pmu
= pACB
->pmuD
;
3535 pACB
->acb_flags
|= ACB_F_MSG_START_BGRB
;
3536 writel(ARCMSR_INBOUND_MESG0_START_BGRB
, pmu
->inbound_msgaddr0
);
3537 if (!arcmsr_hbaD_wait_msgint_ready(pACB
)) {
3538 pr_notice("arcmsr%d: wait 'start adapter "
3539 "background rebulid' timeout\n", pACB
->host
->host_no
);
3543 static void arcmsr_start_adapter_bgrb(struct AdapterControlBlock
*acb
)
3545 switch (acb
->adapter_type
) {
3546 case ACB_ADAPTER_TYPE_A
:
3547 arcmsr_hbaA_start_bgrb(acb
);
3549 case ACB_ADAPTER_TYPE_B
:
3550 arcmsr_hbaB_start_bgrb(acb
);
3552 case ACB_ADAPTER_TYPE_C
:
3553 arcmsr_hbaC_start_bgrb(acb
);
3555 case ACB_ADAPTER_TYPE_D
:
3556 arcmsr_hbaD_start_bgrb(acb
);
3561 static void arcmsr_clear_doorbell_queue_buffer(struct AdapterControlBlock
*acb
)
3563 switch (acb
->adapter_type
) {
3564 case ACB_ADAPTER_TYPE_A
: {
3565 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
3566 uint32_t outbound_doorbell
;
3567 /* empty doorbell Qbuffer if door bell ringed */
3568 outbound_doorbell
= readl(®
->outbound_doorbell
);
3569 /*clear doorbell interrupt */
3570 writel(outbound_doorbell
, ®
->outbound_doorbell
);
3571 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK
, ®
->inbound_doorbell
);
3575 case ACB_ADAPTER_TYPE_B
: {
3576 struct MessageUnit_B
*reg
= acb
->pmuB
;
3577 /*clear interrupt and message state*/
3578 writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN
, reg
->iop2drv_doorbell
);
3579 writel(ARCMSR_DRV2IOP_DATA_READ_OK
, reg
->drv2iop_doorbell
);
3580 /* let IOP know data has been read */
3583 case ACB_ADAPTER_TYPE_C
: {
3584 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
3585 uint32_t outbound_doorbell
, i
;
3586 /* empty doorbell Qbuffer if door bell ringed */
3587 outbound_doorbell
= readl(®
->outbound_doorbell
);
3588 writel(outbound_doorbell
, ®
->outbound_doorbell_clear
);
3589 writel(ARCMSR_HBCMU_DRV2IOP_DATA_READ_OK
, ®
->inbound_doorbell
);
3590 for (i
= 0; i
< 200; i
++) {
3592 outbound_doorbell
= readl(®
->outbound_doorbell
);
3593 if (outbound_doorbell
&
3594 ARCMSR_HBCMU_IOP2DRV_DATA_WRITE_OK
) {
3595 writel(outbound_doorbell
,
3596 ®
->outbound_doorbell_clear
);
3597 writel(ARCMSR_HBCMU_DRV2IOP_DATA_READ_OK
,
3598 ®
->inbound_doorbell
);
3604 case ACB_ADAPTER_TYPE_D
: {
3605 struct MessageUnit_D
*reg
= acb
->pmuD
;
3606 uint32_t outbound_doorbell
, i
;
3607 /* empty doorbell Qbuffer if door bell ringed */
3608 outbound_doorbell
= readl(reg
->outbound_doorbell
);
3609 writel(outbound_doorbell
, reg
->outbound_doorbell
);
3610 writel(ARCMSR_ARC1214_DRV2IOP_DATA_OUT_READ
,
3611 reg
->inbound_doorbell
);
3612 for (i
= 0; i
< 200; i
++) {
3614 outbound_doorbell
= readl(reg
->outbound_doorbell
);
3615 if (outbound_doorbell
&
3616 ARCMSR_ARC1214_IOP2DRV_DATA_WRITE_OK
) {
3617 writel(outbound_doorbell
,
3618 reg
->outbound_doorbell
);
3619 writel(ARCMSR_ARC1214_DRV2IOP_DATA_OUT_READ
,
3620 reg
->inbound_doorbell
);
3629 static void arcmsr_enable_eoi_mode(struct AdapterControlBlock
*acb
)
3631 switch (acb
->adapter_type
) {
3632 case ACB_ADAPTER_TYPE_A
:
3634 case ACB_ADAPTER_TYPE_B
:
3636 struct MessageUnit_B
*reg
= acb
->pmuB
;
3637 writel(ARCMSR_MESSAGE_ACTIVE_EOI_MODE
, reg
->drv2iop_doorbell
);
3638 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
3639 printk(KERN_NOTICE
"ARCMSR IOP enables EOI_MODE TIMEOUT");
3644 case ACB_ADAPTER_TYPE_C
:
3650 static void arcmsr_hardware_reset(struct AdapterControlBlock
*acb
)
3654 struct MessageUnit_A __iomem
*pmuA
= acb
->pmuA
;
3655 struct MessageUnit_C __iomem
*pmuC
= acb
->pmuC
;
3656 struct MessageUnit_D
*pmuD
= acb
->pmuD
;
3658 /* backup pci config data */
3659 printk(KERN_NOTICE
"arcmsr%d: executing hw bus reset .....\n", acb
->host
->host_no
);
3660 for (i
= 0; i
< 64; i
++) {
3661 pci_read_config_byte(acb
->pdev
, i
, &value
[i
]);
3663 /* hardware reset signal */
3664 if ((acb
->dev_id
== 0x1680)) {
3665 writel(ARCMSR_ARC1680_BUS_RESET
, &pmuA
->reserved1
[0]);
3666 } else if ((acb
->dev_id
== 0x1880)) {
3669 writel(0xF, &pmuC
->write_sequence
);
3670 writel(0x4, &pmuC
->write_sequence
);
3671 writel(0xB, &pmuC
->write_sequence
);
3672 writel(0x2, &pmuC
->write_sequence
);
3673 writel(0x7, &pmuC
->write_sequence
);
3674 writel(0xD, &pmuC
->write_sequence
);
3675 } while (((readl(&pmuC
->host_diagnostic
) & ARCMSR_ARC1880_DiagWrite_ENABLE
) == 0) && (count
< 5));
3676 writel(ARCMSR_ARC1880_RESET_ADAPTER
, &pmuC
->host_diagnostic
);
3677 } else if ((acb
->dev_id
== 0x1214)) {
3678 writel(0x20, pmuD
->reset_request
);
3680 pci_write_config_byte(acb
->pdev
, 0x84, 0x20);
3683 /* write back pci config data */
3684 for (i
= 0; i
< 64; i
++) {
3685 pci_write_config_byte(acb
->pdev
, i
, value
[i
]);
3690 static void arcmsr_iop_init(struct AdapterControlBlock
*acb
)
3692 uint32_t intmask_org
;
3693 /* disable all outbound interrupt */
3694 intmask_org
= arcmsr_disable_outbound_ints(acb
);
3695 arcmsr_wait_firmware_ready(acb
);
3696 arcmsr_iop_confirm(acb
);
3697 /*start background rebuild*/
3698 arcmsr_start_adapter_bgrb(acb
);
3699 /* empty doorbell Qbuffer if door bell ringed */
3700 arcmsr_clear_doorbell_queue_buffer(acb
);
3701 arcmsr_enable_eoi_mode(acb
);
3702 /* enable outbound Post Queue,outbound doorbell Interrupt */
3703 arcmsr_enable_outbound_ints(acb
, intmask_org
);
3704 acb
->acb_flags
|= ACB_F_IOP_INITED
;
3707 static uint8_t arcmsr_iop_reset(struct AdapterControlBlock
*acb
)
3709 struct CommandControlBlock
*ccb
;
3710 uint32_t intmask_org
;
3711 uint8_t rtnval
= 0x00;
3713 unsigned long flags
;
3715 if (atomic_read(&acb
->ccboutstandingcount
) != 0) {
3716 /* disable all outbound interrupt */
3717 intmask_org
= arcmsr_disable_outbound_ints(acb
);
3718 /* talk to iop 331 outstanding command aborted */
3719 rtnval
= arcmsr_abort_allcmd(acb
);
3720 /* clear all outbound posted Q */
3721 arcmsr_done4abort_postqueue(acb
);
3722 for (i
= 0; i
< ARCMSR_MAX_FREECCB_NUM
; i
++) {
3723 ccb
= acb
->pccb_pool
[i
];
3724 if (ccb
->startdone
== ARCMSR_CCB_START
) {
3725 scsi_dma_unmap(ccb
->pcmd
);
3726 ccb
->startdone
= ARCMSR_CCB_DONE
;
3728 spin_lock_irqsave(&acb
->ccblist_lock
, flags
);
3729 list_add_tail(&ccb
->list
, &acb
->ccb_free_list
);
3730 spin_unlock_irqrestore(&acb
->ccblist_lock
, flags
);
3733 atomic_set(&acb
->ccboutstandingcount
, 0);
3734 /* enable all outbound interrupt */
3735 arcmsr_enable_outbound_ints(acb
, intmask_org
);
3741 static int arcmsr_bus_reset(struct scsi_cmnd
*cmd
)
3743 struct AdapterControlBlock
*acb
;
3744 uint32_t intmask_org
, outbound_doorbell
;
3745 int retry_count
= 0;
3747 acb
= (struct AdapterControlBlock
*) cmd
->device
->host
->hostdata
;
3748 printk(KERN_ERR
"arcmsr: executing bus reset eh.....num_resets = %d, num_aborts = %d \n", acb
->num_resets
, acb
->num_aborts
);
3751 switch(acb
->adapter_type
){
3752 case ACB_ADAPTER_TYPE_A
:{
3753 if (acb
->acb_flags
& ACB_F_BUS_RESET
){
3755 printk(KERN_ERR
"arcmsr: there is an bus reset eh proceeding.......\n");
3756 timeout
= wait_event_timeout(wait_q
, (acb
->acb_flags
& ACB_F_BUS_RESET
) == 0, 220*HZ
);
3761 acb
->acb_flags
|= ACB_F_BUS_RESET
;
3762 if (!arcmsr_iop_reset(acb
)) {
3763 struct MessageUnit_A __iomem
*reg
;
3765 arcmsr_hardware_reset(acb
);
3766 acb
->acb_flags
&= ~ACB_F_IOP_INITED
;
3768 ssleep(ARCMSR_SLEEPTIME
);
3769 if ((readl(®
->outbound_msgaddr1
) & ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK
) == 0) {
3770 printk(KERN_ERR
"arcmsr%d: waiting for hw bus reset return, retry=%d\n", acb
->host
->host_no
, retry_count
);
3771 if (retry_count
> ARCMSR_RETRYCOUNT
) {
3772 acb
->fw_flag
= FW_DEADLOCK
;
3773 printk(KERN_ERR
"arcmsr%d: waiting for hw bus reset return, RETRY TERMINATED!!\n", acb
->host
->host_no
);
3779 acb
->acb_flags
|= ACB_F_IOP_INITED
;
3780 /* disable all outbound interrupt */
3781 intmask_org
= arcmsr_disable_outbound_ints(acb
);
3782 arcmsr_get_firmware_spec(acb
);
3783 arcmsr_start_adapter_bgrb(acb
);
3784 /* clear Qbuffer if door bell ringed */
3785 outbound_doorbell
= readl(®
->outbound_doorbell
);
3786 writel(outbound_doorbell
, ®
->outbound_doorbell
); /*clear interrupt */
3787 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK
, ®
->inbound_doorbell
);
3788 /* enable outbound Post Queue,outbound doorbell Interrupt */
3789 arcmsr_enable_outbound_ints(acb
, intmask_org
);
3790 atomic_set(&acb
->rq_map_token
, 16);
3791 atomic_set(&acb
->ante_token_value
, 16);
3792 acb
->fw_flag
= FW_NORMAL
;
3793 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3794 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3796 printk(KERN_ERR
"arcmsr: scsi bus reset eh returns with success\n");
3798 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3799 atomic_set(&acb
->rq_map_token
, 16);
3800 atomic_set(&acb
->ante_token_value
, 16);
3801 acb
->fw_flag
= FW_NORMAL
;
3802 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6*HZ
));
3807 case ACB_ADAPTER_TYPE_B
:{
3808 acb
->acb_flags
|= ACB_F_BUS_RESET
;
3809 if (!arcmsr_iop_reset(acb
)) {
3810 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3813 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3814 atomic_set(&acb
->rq_map_token
, 16);
3815 atomic_set(&acb
->ante_token_value
, 16);
3816 acb
->fw_flag
= FW_NORMAL
;
3817 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3822 case ACB_ADAPTER_TYPE_C
:{
3823 if (acb
->acb_flags
& ACB_F_BUS_RESET
) {
3825 printk(KERN_ERR
"arcmsr: there is an bus reset eh proceeding.......\n");
3826 timeout
= wait_event_timeout(wait_q
, (acb
->acb_flags
& ACB_F_BUS_RESET
) == 0, 220*HZ
);
3831 acb
->acb_flags
|= ACB_F_BUS_RESET
;
3832 if (!arcmsr_iop_reset(acb
)) {
3833 struct MessageUnit_C __iomem
*reg
;
3835 arcmsr_hardware_reset(acb
);
3836 acb
->acb_flags
&= ~ACB_F_IOP_INITED
;
3838 ssleep(ARCMSR_SLEEPTIME
);
3839 if ((readl(®
->host_diagnostic
) & 0x04) != 0) {
3840 printk(KERN_ERR
"arcmsr%d: waiting for hw bus reset return, retry=%d\n", acb
->host
->host_no
, retry_count
);
3841 if (retry_count
> ARCMSR_RETRYCOUNT
) {
3842 acb
->fw_flag
= FW_DEADLOCK
;
3843 printk(KERN_ERR
"arcmsr%d: waiting for hw bus reset return, RETRY TERMINATED!!\n", acb
->host
->host_no
);
3849 acb
->acb_flags
|= ACB_F_IOP_INITED
;
3850 /* disable all outbound interrupt */
3851 intmask_org
= arcmsr_disable_outbound_ints(acb
);
3852 arcmsr_get_firmware_spec(acb
);
3853 arcmsr_start_adapter_bgrb(acb
);
3854 /* clear Qbuffer if door bell ringed */
3855 arcmsr_clear_doorbell_queue_buffer(acb
);
3856 /* enable outbound Post Queue,outbound doorbell Interrupt */
3857 arcmsr_enable_outbound_ints(acb
, intmask_org
);
3858 atomic_set(&acb
->rq_map_token
, 16);
3859 atomic_set(&acb
->ante_token_value
, 16);
3860 acb
->fw_flag
= FW_NORMAL
;
3861 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3862 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3864 printk(KERN_ERR
"arcmsr: scsi bus reset eh returns with success\n");
3866 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3867 atomic_set(&acb
->rq_map_token
, 16);
3868 atomic_set(&acb
->ante_token_value
, 16);
3869 acb
->fw_flag
= FW_NORMAL
;
3870 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6*HZ
));
3875 case ACB_ADAPTER_TYPE_D
: {
3876 if (acb
->acb_flags
& ACB_F_BUS_RESET
) {
3878 pr_notice("arcmsr: there is an bus reset"
3879 " eh proceeding.......\n");
3880 timeout
= wait_event_timeout(wait_q
, (acb
->acb_flags
3881 & ACB_F_BUS_RESET
) == 0, 220 * HZ
);
3885 acb
->acb_flags
|= ACB_F_BUS_RESET
;
3886 if (!arcmsr_iop_reset(acb
)) {
3887 struct MessageUnit_D
*reg
;
3889 arcmsr_hardware_reset(acb
);
3890 acb
->acb_flags
&= ~ACB_F_IOP_INITED
;
3892 ssleep(ARCMSR_SLEEPTIME
);
3893 if ((readl(reg
->sample_at_reset
) & 0x80) != 0) {
3894 pr_err("arcmsr%d: waiting for "
3895 "hw bus reset return, retry=%d\n",
3896 acb
->host
->host_no
, retry_count
);
3897 if (retry_count
> ARCMSR_RETRYCOUNT
) {
3898 acb
->fw_flag
= FW_DEADLOCK
;
3899 pr_err("arcmsr%d: waiting for hw bus"
3901 "RETRY TERMINATED!!\n",
3902 acb
->host
->host_no
);
3908 acb
->acb_flags
|= ACB_F_IOP_INITED
;
3909 /* disable all outbound interrupt */
3910 intmask_org
= arcmsr_disable_outbound_ints(acb
);
3911 arcmsr_get_firmware_spec(acb
);
3912 arcmsr_start_adapter_bgrb(acb
);
3913 arcmsr_clear_doorbell_queue_buffer(acb
);
3914 arcmsr_enable_outbound_ints(acb
, intmask_org
);
3915 atomic_set(&acb
->rq_map_token
, 16);
3916 atomic_set(&acb
->ante_token_value
, 16);
3917 acb
->fw_flag
= FW_NORMAL
;
3918 mod_timer(&acb
->eternal_timer
,
3919 jiffies
+ msecs_to_jiffies(6 * HZ
));
3920 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3922 pr_err("arcmsr: scsi bus reset "
3923 "eh returns with success\n");
3925 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3926 atomic_set(&acb
->rq_map_token
, 16);
3927 atomic_set(&acb
->ante_token_value
, 16);
3928 acb
->fw_flag
= FW_NORMAL
;
3929 mod_timer(&acb
->eternal_timer
,
3930 jiffies
+ msecs_to_jiffies(6 * HZ
));
3939 static int arcmsr_abort_one_cmd(struct AdapterControlBlock
*acb
,
3940 struct CommandControlBlock
*ccb
)
3943 rtn
= arcmsr_polling_ccbdone(acb
, ccb
);
3947 static int arcmsr_abort(struct scsi_cmnd
*cmd
)
3949 struct AdapterControlBlock
*acb
=
3950 (struct AdapterControlBlock
*)cmd
->device
->host
->hostdata
;
3953 uint32_t intmask_org
;
3956 "arcmsr%d: abort device command of scsi id = %d lun = %d\n",
3957 acb
->host
->host_no
, cmd
->device
->id
, (u32
)cmd
->device
->lun
);
3958 acb
->acb_flags
|= ACB_F_ABORT
;
3961 ************************************************
3962 ** the all interrupt service routine is locked
3963 ** we need to handle it as soon as possible and exit
3964 ************************************************
3966 if (!atomic_read(&acb
->ccboutstandingcount
)) {
3967 acb
->acb_flags
&= ~ACB_F_ABORT
;
3971 intmask_org
= arcmsr_disable_outbound_ints(acb
);
3972 for (i
= 0; i
< ARCMSR_MAX_FREECCB_NUM
; i
++) {
3973 struct CommandControlBlock
*ccb
= acb
->pccb_pool
[i
];
3974 if (ccb
->startdone
== ARCMSR_CCB_START
&& ccb
->pcmd
== cmd
) {
3975 ccb
->startdone
= ARCMSR_CCB_ABORTED
;
3976 rtn
= arcmsr_abort_one_cmd(acb
, ccb
);
3980 acb
->acb_flags
&= ~ACB_F_ABORT
;
3981 arcmsr_enable_outbound_ints(acb
, intmask_org
);
3985 static const char *arcmsr_info(struct Scsi_Host
*host
)
3987 struct AdapterControlBlock
*acb
=
3988 (struct AdapterControlBlock
*) host
->hostdata
;
3989 static char buf
[256];
3992 switch (acb
->pdev
->device
) {
3993 case PCI_DEVICE_ID_ARECA_1110
:
3994 case PCI_DEVICE_ID_ARECA_1200
:
3995 case PCI_DEVICE_ID_ARECA_1202
:
3996 case PCI_DEVICE_ID_ARECA_1210
:
3999 case PCI_DEVICE_ID_ARECA_1120
:
4000 case PCI_DEVICE_ID_ARECA_1130
:
4001 case PCI_DEVICE_ID_ARECA_1160
:
4002 case PCI_DEVICE_ID_ARECA_1170
:
4003 case PCI_DEVICE_ID_ARECA_1201
:
4004 case PCI_DEVICE_ID_ARECA_1220
:
4005 case PCI_DEVICE_ID_ARECA_1230
:
4006 case PCI_DEVICE_ID_ARECA_1260
:
4007 case PCI_DEVICE_ID_ARECA_1270
:
4008 case PCI_DEVICE_ID_ARECA_1280
:
4011 case PCI_DEVICE_ID_ARECA_1214
:
4012 case PCI_DEVICE_ID_ARECA_1380
:
4013 case PCI_DEVICE_ID_ARECA_1381
:
4014 case PCI_DEVICE_ID_ARECA_1680
:
4015 case PCI_DEVICE_ID_ARECA_1681
:
4016 case PCI_DEVICE_ID_ARECA_1880
:
4024 sprintf(buf
, "Areca %s RAID Controller %s\narcmsr version %s\n",
4025 type
, raid6
? "(RAID6 capable)" : "", ARCMSR_DRIVER_VERSION
);