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
;
2300 int32_t user_len
, cnt2end
;
2301 uint8_t *pQbuffer
, *ptmpuserbuffer
;
2302 ver_addr
= kmalloc(ARCMSR_API_DATA_BUFLEN
, GFP_ATOMIC
);
2304 retvalue
= ARCMSR_MESSAGE_FAIL
;
2307 ptmpuserbuffer
= ver_addr
;
2308 user_len
= pcmdmessagefld
->cmdmessage
.Length
;
2309 memcpy(ptmpuserbuffer
,
2310 pcmdmessagefld
->messagedatabuffer
, user_len
);
2311 spin_lock_irqsave(&acb
->wqbuffer_lock
, flags
);
2312 if (acb
->wqbuf_putIndex
!= acb
->wqbuf_getIndex
) {
2313 struct SENSE_DATA
*sensebuffer
=
2314 (struct SENSE_DATA
*)cmd
->sense_buffer
;
2315 arcmsr_write_ioctldata2iop(acb
);
2316 /* has error report sensedata */
2317 sensebuffer
->ErrorCode
= SCSI_SENSE_CURRENT_ERRORS
;
2318 sensebuffer
->SenseKey
= ILLEGAL_REQUEST
;
2319 sensebuffer
->AdditionalSenseLength
= 0x0A;
2320 sensebuffer
->AdditionalSenseCode
= 0x20;
2321 sensebuffer
->Valid
= 1;
2322 retvalue
= ARCMSR_MESSAGE_FAIL
;
2324 pQbuffer
= &acb
->wqbuffer
[acb
->wqbuf_putIndex
];
2325 cnt2end
= ARCMSR_MAX_QBUFFER
- acb
->wqbuf_putIndex
;
2326 if (user_len
> cnt2end
) {
2327 memcpy(pQbuffer
, ptmpuserbuffer
, cnt2end
);
2328 ptmpuserbuffer
+= cnt2end
;
2329 user_len
-= cnt2end
;
2330 acb
->wqbuf_putIndex
= 0;
2331 pQbuffer
= acb
->wqbuffer
;
2333 memcpy(pQbuffer
, ptmpuserbuffer
, user_len
);
2334 acb
->wqbuf_putIndex
+= user_len
;
2335 acb
->wqbuf_putIndex
%= ARCMSR_MAX_QBUFFER
;
2336 if (acb
->acb_flags
& ACB_F_MESSAGE_WQBUFFER_CLEARED
) {
2338 ~ACB_F_MESSAGE_WQBUFFER_CLEARED
;
2339 arcmsr_write_ioctldata2iop(acb
);
2342 spin_unlock_irqrestore(&acb
->wqbuffer_lock
, flags
);
2344 if (acb
->fw_flag
== FW_DEADLOCK
)
2345 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2346 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2348 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2349 ARCMSR_MESSAGE_RETURNCODE_OK
;
2352 case ARCMSR_MESSAGE_CLEAR_RQBUFFER
: {
2353 uint8_t *pQbuffer
= acb
->rqbuffer
;
2355 arcmsr_clear_iop2drv_rqueue_buffer(acb
);
2356 spin_lock_irqsave(&acb
->rqbuffer_lock
, flags
);
2357 acb
->acb_flags
|= ACB_F_MESSAGE_RQBUFFER_CLEARED
;
2358 acb
->rqbuf_getIndex
= 0;
2359 acb
->rqbuf_putIndex
= 0;
2360 memset(pQbuffer
, 0, ARCMSR_MAX_QBUFFER
);
2361 spin_unlock_irqrestore(&acb
->rqbuffer_lock
, flags
);
2362 if (acb
->fw_flag
== FW_DEADLOCK
)
2363 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2364 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2366 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2367 ARCMSR_MESSAGE_RETURNCODE_OK
;
2370 case ARCMSR_MESSAGE_CLEAR_WQBUFFER
: {
2371 uint8_t *pQbuffer
= acb
->wqbuffer
;
2372 spin_lock_irqsave(&acb
->wqbuffer_lock
, flags
);
2373 acb
->acb_flags
|= (ACB_F_MESSAGE_WQBUFFER_CLEARED
|
2374 ACB_F_MESSAGE_WQBUFFER_READED
);
2375 acb
->wqbuf_getIndex
= 0;
2376 acb
->wqbuf_putIndex
= 0;
2377 memset(pQbuffer
, 0, ARCMSR_MAX_QBUFFER
);
2378 spin_unlock_irqrestore(&acb
->wqbuffer_lock
, flags
);
2379 if (acb
->fw_flag
== FW_DEADLOCK
)
2380 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2381 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2383 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2384 ARCMSR_MESSAGE_RETURNCODE_OK
;
2387 case ARCMSR_MESSAGE_CLEAR_ALLQBUFFER
: {
2389 arcmsr_clear_iop2drv_rqueue_buffer(acb
);
2390 spin_lock_irqsave(&acb
->rqbuffer_lock
, flags
);
2391 acb
->acb_flags
|= ACB_F_MESSAGE_RQBUFFER_CLEARED
;
2392 acb
->rqbuf_getIndex
= 0;
2393 acb
->rqbuf_putIndex
= 0;
2394 pQbuffer
= acb
->rqbuffer
;
2395 memset(pQbuffer
, 0, sizeof(struct QBUFFER
));
2396 spin_unlock_irqrestore(&acb
->rqbuffer_lock
, flags
);
2397 spin_lock_irqsave(&acb
->wqbuffer_lock
, flags
);
2398 acb
->acb_flags
|= (ACB_F_MESSAGE_WQBUFFER_CLEARED
|
2399 ACB_F_MESSAGE_WQBUFFER_READED
);
2400 acb
->wqbuf_getIndex
= 0;
2401 acb
->wqbuf_putIndex
= 0;
2402 pQbuffer
= acb
->wqbuffer
;
2403 memset(pQbuffer
, 0, sizeof(struct QBUFFER
));
2404 spin_unlock_irqrestore(&acb
->wqbuffer_lock
, flags
);
2405 if (acb
->fw_flag
== FW_DEADLOCK
)
2406 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2407 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2409 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2410 ARCMSR_MESSAGE_RETURNCODE_OK
;
2413 case ARCMSR_MESSAGE_RETURN_CODE_3F
: {
2414 if (acb
->fw_flag
== FW_DEADLOCK
)
2415 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2416 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2418 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2419 ARCMSR_MESSAGE_RETURNCODE_3F
;
2422 case ARCMSR_MESSAGE_SAY_HELLO
: {
2423 int8_t *hello_string
= "Hello! I am ARCMSR";
2424 if (acb
->fw_flag
== FW_DEADLOCK
)
2425 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2426 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2428 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2429 ARCMSR_MESSAGE_RETURNCODE_OK
;
2430 memcpy(pcmdmessagefld
->messagedatabuffer
,
2431 hello_string
, (int16_t)strlen(hello_string
));
2434 case ARCMSR_MESSAGE_SAY_GOODBYE
: {
2435 if (acb
->fw_flag
== FW_DEADLOCK
)
2436 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2437 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2439 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2440 ARCMSR_MESSAGE_RETURNCODE_OK
;
2441 arcmsr_iop_parking(acb
);
2444 case ARCMSR_MESSAGE_FLUSH_ADAPTER_CACHE
: {
2445 if (acb
->fw_flag
== FW_DEADLOCK
)
2446 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2447 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
2449 pcmdmessagefld
->cmdmessage
.ReturnCode
=
2450 ARCMSR_MESSAGE_RETURNCODE_OK
;
2451 arcmsr_flush_adapter_cache(acb
);
2455 retvalue
= ARCMSR_MESSAGE_FAIL
;
2456 pr_info("%s: unknown controlcode!\n", __func__
);
2460 struct scatterlist
*sg
= scsi_sglist(cmd
);
2461 kunmap_atomic(buffer
- sg
->offset
);
2466 static struct CommandControlBlock
*arcmsr_get_freeccb(struct AdapterControlBlock
*acb
)
2468 struct list_head
*head
= &acb
->ccb_free_list
;
2469 struct CommandControlBlock
*ccb
= NULL
;
2470 unsigned long flags
;
2471 spin_lock_irqsave(&acb
->ccblist_lock
, flags
);
2472 if (!list_empty(head
)) {
2473 ccb
= list_entry(head
->next
, struct CommandControlBlock
, list
);
2474 list_del_init(&ccb
->list
);
2476 spin_unlock_irqrestore(&acb
->ccblist_lock
, flags
);
2479 spin_unlock_irqrestore(&acb
->ccblist_lock
, flags
);
2483 static void arcmsr_handle_virtual_command(struct AdapterControlBlock
*acb
,
2484 struct scsi_cmnd
*cmd
)
2486 switch (cmd
->cmnd
[0]) {
2488 unsigned char inqdata
[36];
2490 struct scatterlist
*sg
;
2492 if (cmd
->device
->lun
) {
2493 cmd
->result
= (DID_TIME_OUT
<< 16);
2494 cmd
->scsi_done(cmd
);
2497 inqdata
[0] = TYPE_PROCESSOR
;
2498 /* Periph Qualifier & Periph Dev Type */
2500 /* rem media bit & Dev Type Modifier */
2502 /* ISO, ECMA, & ANSI versions */
2504 /* length of additional data */
2505 strncpy(&inqdata
[8], "Areca ", 8);
2506 /* Vendor Identification */
2507 strncpy(&inqdata
[16], "RAID controller ", 16);
2508 /* Product Identification */
2509 strncpy(&inqdata
[32], "R001", 4); /* Product Revision */
2511 sg
= scsi_sglist(cmd
);
2512 buffer
= kmap_atomic(sg_page(sg
)) + sg
->offset
;
2514 memcpy(buffer
, inqdata
, sizeof(inqdata
));
2515 sg
= scsi_sglist(cmd
);
2516 kunmap_atomic(buffer
- sg
->offset
);
2518 cmd
->scsi_done(cmd
);
2523 if (arcmsr_iop_message_xfer(acb
, cmd
))
2524 cmd
->result
= (DID_ERROR
<< 16);
2525 cmd
->scsi_done(cmd
);
2529 cmd
->scsi_done(cmd
);
2533 static int arcmsr_queue_command_lck(struct scsi_cmnd
*cmd
,
2534 void (* done
)(struct scsi_cmnd
*))
2536 struct Scsi_Host
*host
= cmd
->device
->host
;
2537 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
2538 struct CommandControlBlock
*ccb
;
2539 int target
= cmd
->device
->id
;
2540 int lun
= cmd
->device
->lun
;
2541 uint8_t scsicmd
= cmd
->cmnd
[0];
2542 cmd
->scsi_done
= done
;
2543 cmd
->host_scribble
= NULL
;
2545 if ((scsicmd
== SYNCHRONIZE_CACHE
) ||(scsicmd
== SEND_DIAGNOSTIC
)){
2546 if(acb
->devstate
[target
][lun
] == ARECA_RAID_GONE
) {
2547 cmd
->result
= (DID_NO_CONNECT
<< 16);
2549 cmd
->scsi_done(cmd
);
2553 /* virtual device for iop message transfer */
2554 arcmsr_handle_virtual_command(acb
, cmd
);
2557 ccb
= arcmsr_get_freeccb(acb
);
2559 return SCSI_MLQUEUE_HOST_BUSY
;
2560 if (arcmsr_build_ccb( acb
, ccb
, cmd
) == FAILED
) {
2561 cmd
->result
= (DID_ERROR
<< 16) | (RESERVATION_CONFLICT
<< 1);
2562 cmd
->scsi_done(cmd
);
2565 arcmsr_post_ccb(acb
, ccb
);
2569 static DEF_SCSI_QCMD(arcmsr_queue_command
)
2571 static bool arcmsr_hbaA_get_config(struct AdapterControlBlock
*acb
)
2573 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2574 char *acb_firm_model
= acb
->firm_model
;
2575 char *acb_firm_version
= acb
->firm_version
;
2576 char *acb_device_map
= acb
->device_map
;
2577 char __iomem
*iop_firm_model
= (char __iomem
*)(®
->message_rwbuffer
[15]);
2578 char __iomem
*iop_firm_version
= (char __iomem
*)(®
->message_rwbuffer
[17]);
2579 char __iomem
*iop_device_map
= (char __iomem
*)(®
->message_rwbuffer
[21]);
2581 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
2582 if (!arcmsr_hbaA_wait_msgint_ready(acb
)) {
2583 printk(KERN_NOTICE
"arcmsr%d: wait 'get adapter firmware \
2584 miscellaneous data' timeout \n", acb
->host
->host_no
);
2589 *acb_firm_model
= readb(iop_firm_model
);
2597 *acb_firm_version
= readb(iop_firm_version
);
2605 *acb_device_map
= readb(iop_device_map
);
2610 pr_notice("Areca RAID Controller%d: Model %s, F/W %s\n",
2614 acb
->signature
= readl(®
->message_rwbuffer
[0]);
2615 acb
->firm_request_len
= readl(®
->message_rwbuffer
[1]);
2616 acb
->firm_numbers_queue
= readl(®
->message_rwbuffer
[2]);
2617 acb
->firm_sdram_size
= readl(®
->message_rwbuffer
[3]);
2618 acb
->firm_hd_channels
= readl(®
->message_rwbuffer
[4]);
2619 acb
->firm_cfg_version
= readl(®
->message_rwbuffer
[25]); /*firm_cfg_version,25,100-103*/
2622 static bool arcmsr_hbaB_get_config(struct AdapterControlBlock
*acb
)
2624 struct MessageUnit_B
*reg
= acb
->pmuB
;
2625 struct pci_dev
*pdev
= acb
->pdev
;
2627 dma_addr_t dma_coherent_handle
;
2628 char *acb_firm_model
= acb
->firm_model
;
2629 char *acb_firm_version
= acb
->firm_version
;
2630 char *acb_device_map
= acb
->device_map
;
2631 char __iomem
*iop_firm_model
;
2632 /*firm_model,15,60-67*/
2633 char __iomem
*iop_firm_version
;
2634 /*firm_version,17,68-83*/
2635 char __iomem
*iop_device_map
;
2636 /*firm_version,21,84-99*/
2639 acb
->roundup_ccbsize
= roundup(sizeof(struct MessageUnit_B
), 32);
2640 dma_coherent
= dma_alloc_coherent(&pdev
->dev
, acb
->roundup_ccbsize
,
2641 &dma_coherent_handle
, GFP_KERNEL
);
2644 "arcmsr%d: dma_alloc_coherent got error for hbb mu\n",
2645 acb
->host
->host_no
);
2648 acb
->dma_coherent_handle2
= dma_coherent_handle
;
2649 acb
->dma_coherent2
= dma_coherent
;
2650 reg
= (struct MessageUnit_B
*)dma_coherent
;
2652 reg
->drv2iop_doorbell
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base0
+ ARCMSR_DRV2IOP_DOORBELL
);
2653 reg
->drv2iop_doorbell_mask
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base0
+ ARCMSR_DRV2IOP_DOORBELL_MASK
);
2654 reg
->iop2drv_doorbell
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base0
+ ARCMSR_IOP2DRV_DOORBELL
);
2655 reg
->iop2drv_doorbell_mask
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base0
+ ARCMSR_IOP2DRV_DOORBELL_MASK
);
2656 reg
->message_wbuffer
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base1
+ ARCMSR_MESSAGE_WBUFFER
);
2657 reg
->message_rbuffer
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base1
+ ARCMSR_MESSAGE_RBUFFER
);
2658 reg
->message_rwbuffer
= (uint32_t __iomem
*)((unsigned long)acb
->mem_base1
+ ARCMSR_MESSAGE_RWBUFFER
);
2659 iop_firm_model
= (char __iomem
*)(®
->message_rwbuffer
[15]); /*firm_model,15,60-67*/
2660 iop_firm_version
= (char __iomem
*)(®
->message_rwbuffer
[17]); /*firm_version,17,68-83*/
2661 iop_device_map
= (char __iomem
*)(®
->message_rwbuffer
[21]); /*firm_version,21,84-99*/
2663 writel(ARCMSR_MESSAGE_GET_CONFIG
, reg
->drv2iop_doorbell
);
2664 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
2665 printk(KERN_NOTICE
"arcmsr%d: wait 'get adapter firmware \
2666 miscellaneous data' timeout \n", acb
->host
->host_no
);
2671 *acb_firm_model
= readb(iop_firm_model
);
2678 *acb_firm_version
= readb(iop_firm_version
);
2686 *acb_device_map
= readb(iop_device_map
);
2692 pr_notice("Areca RAID Controller%d: Model %s, F/W %s\n",
2697 acb
->signature
= readl(®
->message_rwbuffer
[1]);
2698 /*firm_signature,1,00-03*/
2699 acb
->firm_request_len
= readl(®
->message_rwbuffer
[2]);
2700 /*firm_request_len,1,04-07*/
2701 acb
->firm_numbers_queue
= readl(®
->message_rwbuffer
[3]);
2702 /*firm_numbers_queue,2,08-11*/
2703 acb
->firm_sdram_size
= readl(®
->message_rwbuffer
[4]);
2704 /*firm_sdram_size,3,12-15*/
2705 acb
->firm_hd_channels
= readl(®
->message_rwbuffer
[5]);
2706 /*firm_ide_channels,4,16-19*/
2707 acb
->firm_cfg_version
= readl(®
->message_rwbuffer
[25]); /*firm_cfg_version,25,100-103*/
2708 /*firm_ide_channels,4,16-19*/
2712 static bool arcmsr_hbaC_get_config(struct AdapterControlBlock
*pACB
)
2714 uint32_t intmask_org
, Index
, firmware_state
= 0;
2715 struct MessageUnit_C __iomem
*reg
= pACB
->pmuC
;
2716 char *acb_firm_model
= pACB
->firm_model
;
2717 char *acb_firm_version
= pACB
->firm_version
;
2718 char __iomem
*iop_firm_model
= (char __iomem
*)(®
->msgcode_rwbuffer
[15]); /*firm_model,15,60-67*/
2719 char __iomem
*iop_firm_version
= (char __iomem
*)(®
->msgcode_rwbuffer
[17]); /*firm_version,17,68-83*/
2721 /* disable all outbound interrupt */
2722 intmask_org
= readl(®
->host_int_mask
); /* disable outbound message0 int */
2723 writel(intmask_org
|ARCMSR_HBCMU_ALL_INTMASKENABLE
, ®
->host_int_mask
);
2724 /* wait firmware ready */
2726 firmware_state
= readl(®
->outbound_msgaddr1
);
2727 } while ((firmware_state
& ARCMSR_HBCMU_MESSAGE_FIRMWARE_OK
) == 0);
2728 /* post "get config" instruction */
2729 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
2730 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
2731 /* wait message ready */
2732 for (Index
= 0; Index
< 2000; Index
++) {
2733 if (readl(®
->outbound_doorbell
) & ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE
) {
2734 writel(ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE_DOORBELL_CLEAR
, ®
->outbound_doorbell_clear
);/*clear interrupt*/
2739 if (Index
>= 2000) {
2740 printk(KERN_NOTICE
"arcmsr%d: wait 'get adapter firmware \
2741 miscellaneous data' timeout \n", pACB
->host
->host_no
);
2746 *acb_firm_model
= readb(iop_firm_model
);
2753 *acb_firm_version
= readb(iop_firm_version
);
2758 pr_notice("Areca RAID Controller%d: Model %s, F/W %s\n",
2759 pACB
->host
->host_no
,
2761 pACB
->firm_version
);
2762 pACB
->firm_request_len
= readl(®
->msgcode_rwbuffer
[1]); /*firm_request_len,1,04-07*/
2763 pACB
->firm_numbers_queue
= readl(®
->msgcode_rwbuffer
[2]); /*firm_numbers_queue,2,08-11*/
2764 pACB
->firm_sdram_size
= readl(®
->msgcode_rwbuffer
[3]); /*firm_sdram_size,3,12-15*/
2765 pACB
->firm_hd_channels
= readl(®
->msgcode_rwbuffer
[4]); /*firm_ide_channels,4,16-19*/
2766 pACB
->firm_cfg_version
= readl(®
->msgcode_rwbuffer
[25]); /*firm_cfg_version,25,100-103*/
2767 /*all interrupt service will be enable at arcmsr_iop_init*/
2771 static bool arcmsr_hbaD_get_config(struct AdapterControlBlock
*acb
)
2773 char *acb_firm_model
= acb
->firm_model
;
2774 char *acb_firm_version
= acb
->firm_version
;
2775 char *acb_device_map
= acb
->device_map
;
2776 char __iomem
*iop_firm_model
;
2777 char __iomem
*iop_firm_version
;
2778 char __iomem
*iop_device_map
;
2780 struct MessageUnit_D
*reg
;
2781 void *dma_coherent2
;
2782 dma_addr_t dma_coherent_handle2
;
2783 struct pci_dev
*pdev
= acb
->pdev
;
2785 acb
->roundup_ccbsize
= roundup(sizeof(struct MessageUnit_D
), 32);
2786 dma_coherent2
= dma_alloc_coherent(&pdev
->dev
, acb
->roundup_ccbsize
,
2787 &dma_coherent_handle2
, GFP_KERNEL
);
2788 if (!dma_coherent2
) {
2789 pr_notice("DMA allocation failed...\n");
2792 memset(dma_coherent2
, 0, acb
->roundup_ccbsize
);
2793 acb
->dma_coherent_handle2
= dma_coherent_handle2
;
2794 acb
->dma_coherent2
= dma_coherent2
;
2795 reg
= (struct MessageUnit_D
*)dma_coherent2
;
2797 reg
->chip_id
= acb
->mem_base0
+ ARCMSR_ARC1214_CHIP_ID
;
2798 reg
->cpu_mem_config
= acb
->mem_base0
+
2799 ARCMSR_ARC1214_CPU_MEMORY_CONFIGURATION
;
2800 reg
->i2o_host_interrupt_mask
= acb
->mem_base0
+
2801 ARCMSR_ARC1214_I2_HOST_INTERRUPT_MASK
;
2802 reg
->sample_at_reset
= acb
->mem_base0
+ ARCMSR_ARC1214_SAMPLE_RESET
;
2803 reg
->reset_request
= acb
->mem_base0
+ ARCMSR_ARC1214_RESET_REQUEST
;
2804 reg
->host_int_status
= acb
->mem_base0
+
2805 ARCMSR_ARC1214_MAIN_INTERRUPT_STATUS
;
2806 reg
->pcief0_int_enable
= acb
->mem_base0
+
2807 ARCMSR_ARC1214_PCIE_F0_INTERRUPT_ENABLE
;
2808 reg
->inbound_msgaddr0
= acb
->mem_base0
+
2809 ARCMSR_ARC1214_INBOUND_MESSAGE0
;
2810 reg
->inbound_msgaddr1
= acb
->mem_base0
+
2811 ARCMSR_ARC1214_INBOUND_MESSAGE1
;
2812 reg
->outbound_msgaddr0
= acb
->mem_base0
+
2813 ARCMSR_ARC1214_OUTBOUND_MESSAGE0
;
2814 reg
->outbound_msgaddr1
= acb
->mem_base0
+
2815 ARCMSR_ARC1214_OUTBOUND_MESSAGE1
;
2816 reg
->inbound_doorbell
= acb
->mem_base0
+
2817 ARCMSR_ARC1214_INBOUND_DOORBELL
;
2818 reg
->outbound_doorbell
= acb
->mem_base0
+
2819 ARCMSR_ARC1214_OUTBOUND_DOORBELL
;
2820 reg
->outbound_doorbell_enable
= acb
->mem_base0
+
2821 ARCMSR_ARC1214_OUTBOUND_DOORBELL_ENABLE
;
2822 reg
->inboundlist_base_low
= acb
->mem_base0
+
2823 ARCMSR_ARC1214_INBOUND_LIST_BASE_LOW
;
2824 reg
->inboundlist_base_high
= acb
->mem_base0
+
2825 ARCMSR_ARC1214_INBOUND_LIST_BASE_HIGH
;
2826 reg
->inboundlist_write_pointer
= acb
->mem_base0
+
2827 ARCMSR_ARC1214_INBOUND_LIST_WRITE_POINTER
;
2828 reg
->outboundlist_base_low
= acb
->mem_base0
+
2829 ARCMSR_ARC1214_OUTBOUND_LIST_BASE_LOW
;
2830 reg
->outboundlist_base_high
= acb
->mem_base0
+
2831 ARCMSR_ARC1214_OUTBOUND_LIST_BASE_HIGH
;
2832 reg
->outboundlist_copy_pointer
= acb
->mem_base0
+
2833 ARCMSR_ARC1214_OUTBOUND_LIST_COPY_POINTER
;
2834 reg
->outboundlist_read_pointer
= acb
->mem_base0
+
2835 ARCMSR_ARC1214_OUTBOUND_LIST_READ_POINTER
;
2836 reg
->outboundlist_interrupt_cause
= acb
->mem_base0
+
2837 ARCMSR_ARC1214_OUTBOUND_INTERRUPT_CAUSE
;
2838 reg
->outboundlist_interrupt_enable
= acb
->mem_base0
+
2839 ARCMSR_ARC1214_OUTBOUND_INTERRUPT_ENABLE
;
2840 reg
->message_wbuffer
= acb
->mem_base0
+ ARCMSR_ARC1214_MESSAGE_WBUFFER
;
2841 reg
->message_rbuffer
= acb
->mem_base0
+ ARCMSR_ARC1214_MESSAGE_RBUFFER
;
2842 reg
->msgcode_rwbuffer
= acb
->mem_base0
+
2843 ARCMSR_ARC1214_MESSAGE_RWBUFFER
;
2844 iop_firm_model
= (char __iomem
*)(®
->msgcode_rwbuffer
[15]);
2845 iop_firm_version
= (char __iomem
*)(®
->msgcode_rwbuffer
[17]);
2846 iop_device_map
= (char __iomem
*)(®
->msgcode_rwbuffer
[21]);
2847 if (readl(acb
->pmuD
->outbound_doorbell
) &
2848 ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
) {
2849 writel(ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
,
2850 acb
->pmuD
->outbound_doorbell
);/*clear interrupt*/
2852 /* post "get config" instruction */
2853 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, reg
->inbound_msgaddr0
);
2854 /* wait message ready */
2855 if (!arcmsr_hbaD_wait_msgint_ready(acb
)) {
2856 pr_notice("arcmsr%d: wait get adapter firmware "
2857 "miscellaneous data timeout\n", acb
->host
->host_no
);
2858 dma_free_coherent(&acb
->pdev
->dev
, acb
->roundup_ccbsize
,
2859 acb
->dma_coherent2
, acb
->dma_coherent_handle2
);
2864 *acb_firm_model
= readb(iop_firm_model
);
2871 *acb_firm_version
= readb(iop_firm_version
);
2878 *acb_device_map
= readb(iop_device_map
);
2883 acb
->signature
= readl(®
->msgcode_rwbuffer
[1]);
2884 /*firm_signature,1,00-03*/
2885 acb
->firm_request_len
= readl(®
->msgcode_rwbuffer
[2]);
2886 /*firm_request_len,1,04-07*/
2887 acb
->firm_numbers_queue
= readl(®
->msgcode_rwbuffer
[3]);
2888 /*firm_numbers_queue,2,08-11*/
2889 acb
->firm_sdram_size
= readl(®
->msgcode_rwbuffer
[4]);
2890 /*firm_sdram_size,3,12-15*/
2891 acb
->firm_hd_channels
= readl(®
->msgcode_rwbuffer
[5]);
2892 /*firm_hd_channels,4,16-19*/
2893 acb
->firm_cfg_version
= readl(®
->msgcode_rwbuffer
[25]);
2894 pr_notice("Areca RAID Controller%d: Model %s, F/W %s\n",
2901 static bool arcmsr_get_firmware_spec(struct AdapterControlBlock
*acb
)
2905 switch (acb
->adapter_type
) {
2906 case ACB_ADAPTER_TYPE_A
:
2907 rtn
= arcmsr_hbaA_get_config(acb
);
2909 case ACB_ADAPTER_TYPE_B
:
2910 rtn
= arcmsr_hbaB_get_config(acb
);
2912 case ACB_ADAPTER_TYPE_C
:
2913 rtn
= arcmsr_hbaC_get_config(acb
);
2915 case ACB_ADAPTER_TYPE_D
:
2916 rtn
= arcmsr_hbaD_get_config(acb
);
2921 if (acb
->firm_numbers_queue
> ARCMSR_MAX_OUTSTANDING_CMD
)
2922 acb
->maxOutstanding
= ARCMSR_MAX_OUTSTANDING_CMD
;
2924 acb
->maxOutstanding
= acb
->firm_numbers_queue
- 1;
2925 acb
->host
->can_queue
= acb
->maxOutstanding
;
2929 static int arcmsr_hbaA_polling_ccbdone(struct AdapterControlBlock
*acb
,
2930 struct CommandControlBlock
*poll_ccb
)
2932 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2933 struct CommandControlBlock
*ccb
;
2934 struct ARCMSR_CDB
*arcmsr_cdb
;
2935 uint32_t flag_ccb
, outbound_intstatus
, poll_ccb_done
= 0, poll_count
= 0;
2938 polling_hba_ccb_retry
:
2940 outbound_intstatus
= readl(®
->outbound_intstatus
) & acb
->outbound_int_enable
;
2941 writel(outbound_intstatus
, ®
->outbound_intstatus
);/*clear interrupt*/
2943 if ((flag_ccb
= readl(®
->outbound_queueport
)) == 0xFFFFFFFF) {
2949 if (poll_count
> 100){
2953 goto polling_hba_ccb_retry
;
2956 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ (flag_ccb
<< 5));
2957 ccb
= container_of(arcmsr_cdb
, struct CommandControlBlock
, arcmsr_cdb
);
2958 poll_ccb_done
|= (ccb
== poll_ccb
) ? 1 : 0;
2959 if ((ccb
->acb
!= acb
) || (ccb
->startdone
!= ARCMSR_CCB_START
)) {
2960 if ((ccb
->startdone
== ARCMSR_CCB_ABORTED
) || (ccb
== poll_ccb
)) {
2961 printk(KERN_NOTICE
"arcmsr%d: scsi id = %d lun = %d ccb = '0x%p'"
2962 " poll command abort successfully \n"
2963 , acb
->host
->host_no
2964 , ccb
->pcmd
->device
->id
2965 , (u32
)ccb
->pcmd
->device
->lun
2967 ccb
->pcmd
->result
= DID_ABORT
<< 16;
2968 arcmsr_ccb_complete(ccb
);
2971 printk(KERN_NOTICE
"arcmsr%d: polling get an illegal ccb"
2972 " command done ccb = '0x%p'"
2973 "ccboutstandingcount = %d \n"
2974 , acb
->host
->host_no
2976 , atomic_read(&acb
->ccboutstandingcount
));
2979 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
2980 arcmsr_report_ccb_state(acb
, ccb
, error
);
2985 static int arcmsr_hbaB_polling_ccbdone(struct AdapterControlBlock
*acb
,
2986 struct CommandControlBlock
*poll_ccb
)
2988 struct MessageUnit_B
*reg
= acb
->pmuB
;
2989 struct ARCMSR_CDB
*arcmsr_cdb
;
2990 struct CommandControlBlock
*ccb
;
2991 uint32_t flag_ccb
, poll_ccb_done
= 0, poll_count
= 0;
2994 polling_hbb_ccb_retry
:
2997 /* clear doorbell interrupt */
2998 writel(ARCMSR_DOORBELL_INT_CLEAR_PATTERN
, reg
->iop2drv_doorbell
);
3000 index
= reg
->doneq_index
;
3001 flag_ccb
= reg
->done_qbuffer
[index
];
3002 if (flag_ccb
== 0) {
3008 if (poll_count
> 100){
3012 goto polling_hbb_ccb_retry
;
3015 reg
->done_qbuffer
[index
] = 0;
3017 /*if last index number set it to 0 */
3018 index
%= ARCMSR_MAX_HBB_POSTQUEUE
;
3019 reg
->doneq_index
= index
;
3020 /* check if command done with no error*/
3021 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ (flag_ccb
<< 5));
3022 ccb
= container_of(arcmsr_cdb
, struct CommandControlBlock
, arcmsr_cdb
);
3023 poll_ccb_done
|= (ccb
== poll_ccb
) ? 1 : 0;
3024 if ((ccb
->acb
!= acb
) || (ccb
->startdone
!= ARCMSR_CCB_START
)) {
3025 if ((ccb
->startdone
== ARCMSR_CCB_ABORTED
) || (ccb
== poll_ccb
)) {
3026 printk(KERN_NOTICE
"arcmsr%d: scsi id = %d lun = %d ccb = '0x%p'"
3027 " poll command abort successfully \n"
3029 ,ccb
->pcmd
->device
->id
3030 ,(u32
)ccb
->pcmd
->device
->lun
3032 ccb
->pcmd
->result
= DID_ABORT
<< 16;
3033 arcmsr_ccb_complete(ccb
);
3036 printk(KERN_NOTICE
"arcmsr%d: polling get an illegal ccb"
3037 " command done ccb = '0x%p'"
3038 "ccboutstandingcount = %d \n"
3039 , acb
->host
->host_no
3041 , atomic_read(&acb
->ccboutstandingcount
));
3044 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
3045 arcmsr_report_ccb_state(acb
, ccb
, error
);
3050 static int arcmsr_hbaC_polling_ccbdone(struct AdapterControlBlock
*acb
,
3051 struct CommandControlBlock
*poll_ccb
)
3053 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
3054 uint32_t flag_ccb
, ccb_cdb_phy
;
3055 struct ARCMSR_CDB
*arcmsr_cdb
;
3057 struct CommandControlBlock
*pCCB
;
3058 uint32_t poll_ccb_done
= 0, poll_count
= 0;
3060 polling_hbc_ccb_retry
:
3063 if ((readl(®
->host_int_status
) & ARCMSR_HBCMU_OUTBOUND_POSTQUEUE_ISR
) == 0) {
3064 if (poll_ccb_done
) {
3069 if (poll_count
> 100) {
3073 goto polling_hbc_ccb_retry
;
3076 flag_ccb
= readl(®
->outbound_queueport_low
);
3077 ccb_cdb_phy
= (flag_ccb
& 0xFFFFFFF0);
3078 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ ccb_cdb_phy
);/*frame must be 32 bytes aligned*/
3079 pCCB
= container_of(arcmsr_cdb
, struct CommandControlBlock
, arcmsr_cdb
);
3080 poll_ccb_done
|= (pCCB
== poll_ccb
) ? 1 : 0;
3081 /* check ifcommand done with no error*/
3082 if ((pCCB
->acb
!= acb
) || (pCCB
->startdone
!= ARCMSR_CCB_START
)) {
3083 if (pCCB
->startdone
== ARCMSR_CCB_ABORTED
) {
3084 printk(KERN_NOTICE
"arcmsr%d: scsi id = %d lun = %d ccb = '0x%p'"
3085 " poll command abort successfully \n"
3086 , acb
->host
->host_no
3087 , pCCB
->pcmd
->device
->id
3088 , (u32
)pCCB
->pcmd
->device
->lun
3090 pCCB
->pcmd
->result
= DID_ABORT
<< 16;
3091 arcmsr_ccb_complete(pCCB
);
3094 printk(KERN_NOTICE
"arcmsr%d: polling get an illegal ccb"
3095 " command done ccb = '0x%p'"
3096 "ccboutstandingcount = %d \n"
3097 , acb
->host
->host_no
3099 , atomic_read(&acb
->ccboutstandingcount
));
3102 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
) ? true : false;
3103 arcmsr_report_ccb_state(acb
, pCCB
, error
);
3108 static int arcmsr_hbaD_polling_ccbdone(struct AdapterControlBlock
*acb
,
3109 struct CommandControlBlock
*poll_ccb
)
3112 uint32_t poll_ccb_done
= 0, poll_count
= 0, flag_ccb
, ccb_cdb_phy
;
3113 int rtn
, doneq_index
, index_stripped
, outbound_write_pointer
, toggle
;
3114 unsigned long flags
;
3115 struct ARCMSR_CDB
*arcmsr_cdb
;
3116 struct CommandControlBlock
*pCCB
;
3117 struct MessageUnit_D
*pmu
= acb
->pmuD
;
3119 polling_hbaD_ccb_retry
:
3122 spin_lock_irqsave(&acb
->doneq_lock
, flags
);
3123 outbound_write_pointer
= pmu
->done_qbuffer
[0].addressLow
+ 1;
3124 doneq_index
= pmu
->doneq_index
;
3125 if ((outbound_write_pointer
& 0xFFF) == (doneq_index
& 0xFFF)) {
3126 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
3127 if (poll_ccb_done
) {
3132 if (poll_count
> 40) {
3136 goto polling_hbaD_ccb_retry
;
3139 toggle
= doneq_index
& 0x4000;
3140 index_stripped
= (doneq_index
& 0xFFF) + 1;
3141 index_stripped
%= ARCMSR_MAX_ARC1214_DONEQUEUE
;
3142 pmu
->doneq_index
= index_stripped
? (index_stripped
| toggle
) :
3143 ((toggle
^ 0x4000) + 1);
3144 doneq_index
= pmu
->doneq_index
;
3145 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
3146 flag_ccb
= pmu
->done_qbuffer
[doneq_index
& 0xFFF].addressLow
;
3147 ccb_cdb_phy
= (flag_ccb
& 0xFFFFFFF0);
3148 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+
3150 pCCB
= container_of(arcmsr_cdb
, struct CommandControlBlock
,
3152 poll_ccb_done
|= (pCCB
== poll_ccb
) ? 1 : 0;
3153 if ((pCCB
->acb
!= acb
) ||
3154 (pCCB
->startdone
!= ARCMSR_CCB_START
)) {
3155 if (pCCB
->startdone
== ARCMSR_CCB_ABORTED
) {
3156 pr_notice("arcmsr%d: scsi id = %d "
3157 "lun = %d ccb = '0x%p' poll command "
3158 "abort successfully\n"
3159 , acb
->host
->host_no
3160 , pCCB
->pcmd
->device
->id
3161 , (u32
)pCCB
->pcmd
->device
->lun
3163 pCCB
->pcmd
->result
= DID_ABORT
<< 16;
3164 arcmsr_ccb_complete(pCCB
);
3167 pr_notice("arcmsr%d: polling an illegal "
3168 "ccb command done ccb = '0x%p' "
3169 "ccboutstandingcount = %d\n"
3170 , acb
->host
->host_no
3172 , atomic_read(&acb
->ccboutstandingcount
));
3175 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
)
3177 arcmsr_report_ccb_state(acb
, pCCB
, error
);
3182 static int arcmsr_polling_ccbdone(struct AdapterControlBlock
*acb
,
3183 struct CommandControlBlock
*poll_ccb
)
3186 switch (acb
->adapter_type
) {
3188 case ACB_ADAPTER_TYPE_A
: {
3189 rtn
= arcmsr_hbaA_polling_ccbdone(acb
, poll_ccb
);
3193 case ACB_ADAPTER_TYPE_B
: {
3194 rtn
= arcmsr_hbaB_polling_ccbdone(acb
, poll_ccb
);
3197 case ACB_ADAPTER_TYPE_C
: {
3198 rtn
= arcmsr_hbaC_polling_ccbdone(acb
, poll_ccb
);
3201 case ACB_ADAPTER_TYPE_D
:
3202 rtn
= arcmsr_hbaD_polling_ccbdone(acb
, poll_ccb
);
3208 static int arcmsr_iop_confirm(struct AdapterControlBlock
*acb
)
3210 uint32_t cdb_phyaddr
, cdb_phyaddr_hi32
;
3211 dma_addr_t dma_coherent_handle
;
3214 ********************************************************************
3215 ** here we need to tell iop 331 our freeccb.HighPart
3216 ** if freeccb.HighPart is not zero
3217 ********************************************************************
3219 switch (acb
->adapter_type
) {
3220 case ACB_ADAPTER_TYPE_B
:
3221 case ACB_ADAPTER_TYPE_D
:
3222 dma_coherent_handle
= acb
->dma_coherent_handle2
;
3225 dma_coherent_handle
= acb
->dma_coherent_handle
;
3228 cdb_phyaddr
= lower_32_bits(dma_coherent_handle
);
3229 cdb_phyaddr_hi32
= upper_32_bits(dma_coherent_handle
);
3230 acb
->cdb_phyaddr_hi32
= cdb_phyaddr_hi32
;
3232 ***********************************************************************
3233 ** if adapter type B, set window of "post command Q"
3234 ***********************************************************************
3236 switch (acb
->adapter_type
) {
3238 case ACB_ADAPTER_TYPE_A
: {
3239 if (cdb_phyaddr_hi32
!= 0) {
3240 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
3241 writel(ARCMSR_SIGNATURE_SET_CONFIG
, \
3242 ®
->message_rwbuffer
[0]);
3243 writel(cdb_phyaddr_hi32
, ®
->message_rwbuffer
[1]);
3244 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG
, \
3245 ®
->inbound_msgaddr0
);
3246 if (!arcmsr_hbaA_wait_msgint_ready(acb
)) {
3247 printk(KERN_NOTICE
"arcmsr%d: ""set ccb high \
3248 part physical address timeout\n",
3249 acb
->host
->host_no
);
3256 case ACB_ADAPTER_TYPE_B
: {
3257 uint32_t __iomem
*rwbuffer
;
3259 struct MessageUnit_B
*reg
= acb
->pmuB
;
3260 reg
->postq_index
= 0;
3261 reg
->doneq_index
= 0;
3262 writel(ARCMSR_MESSAGE_SET_POST_WINDOW
, reg
->drv2iop_doorbell
);
3263 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
3264 printk(KERN_NOTICE
"arcmsr%d: cannot set driver mode\n", \
3265 acb
->host
->host_no
);
3268 rwbuffer
= reg
->message_rwbuffer
;
3269 /* driver "set config" signature */
3270 writel(ARCMSR_SIGNATURE_SET_CONFIG
, rwbuffer
++);
3271 /* normal should be zero */
3272 writel(cdb_phyaddr_hi32
, rwbuffer
++);
3273 /* postQ size (256 + 8)*4 */
3274 writel(cdb_phyaddr
, rwbuffer
++);
3275 /* doneQ size (256 + 8)*4 */
3276 writel(cdb_phyaddr
+ 1056, rwbuffer
++);
3277 /* ccb maxQ size must be --> [(256 + 8)*4]*/
3278 writel(1056, rwbuffer
);
3280 writel(ARCMSR_MESSAGE_SET_CONFIG
, reg
->drv2iop_doorbell
);
3281 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
3282 printk(KERN_NOTICE
"arcmsr%d: 'set command Q window' \
3283 timeout \n",acb
->host
->host_no
);
3286 writel(ARCMSR_MESSAGE_START_DRIVER_MODE
, reg
->drv2iop_doorbell
);
3287 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
3288 pr_err("arcmsr%d: can't set driver mode.\n",
3289 acb
->host
->host_no
);
3294 case ACB_ADAPTER_TYPE_C
: {
3295 if (cdb_phyaddr_hi32
!= 0) {
3296 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
3298 printk(KERN_NOTICE
"arcmsr%d: cdb_phyaddr_hi32=0x%x\n",
3299 acb
->adapter_index
, cdb_phyaddr_hi32
);
3300 writel(ARCMSR_SIGNATURE_SET_CONFIG
, ®
->msgcode_rwbuffer
[0]);
3301 writel(cdb_phyaddr_hi32
, ®
->msgcode_rwbuffer
[1]);
3302 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG
, ®
->inbound_msgaddr0
);
3303 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
3304 if (!arcmsr_hbaC_wait_msgint_ready(acb
)) {
3305 printk(KERN_NOTICE
"arcmsr%d: 'set command Q window' \
3306 timeout \n", acb
->host
->host_no
);
3312 case ACB_ADAPTER_TYPE_D
: {
3313 uint32_t __iomem
*rwbuffer
;
3314 struct MessageUnit_D
*reg
= acb
->pmuD
;
3315 reg
->postq_index
= 0;
3316 reg
->doneq_index
= 0;
3317 rwbuffer
= reg
->msgcode_rwbuffer
;
3318 writel(ARCMSR_SIGNATURE_SET_CONFIG
, rwbuffer
++);
3319 writel(cdb_phyaddr_hi32
, rwbuffer
++);
3320 writel(cdb_phyaddr
, rwbuffer
++);
3321 writel(cdb_phyaddr
+ (ARCMSR_MAX_ARC1214_POSTQUEUE
*
3322 sizeof(struct InBound_SRB
)), rwbuffer
++);
3323 writel(0x100, rwbuffer
);
3324 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG
, reg
->inbound_msgaddr0
);
3325 if (!arcmsr_hbaD_wait_msgint_ready(acb
)) {
3326 pr_notice("arcmsr%d: 'set command Q window' timeout\n",
3327 acb
->host
->host_no
);
3336 static void arcmsr_wait_firmware_ready(struct AdapterControlBlock
*acb
)
3338 uint32_t firmware_state
= 0;
3339 switch (acb
->adapter_type
) {
3341 case ACB_ADAPTER_TYPE_A
: {
3342 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
3344 firmware_state
= readl(®
->outbound_msgaddr1
);
3345 } while ((firmware_state
& ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK
) == 0);
3349 case ACB_ADAPTER_TYPE_B
: {
3350 struct MessageUnit_B
*reg
= acb
->pmuB
;
3352 firmware_state
= readl(reg
->iop2drv_doorbell
);
3353 } while ((firmware_state
& ARCMSR_MESSAGE_FIRMWARE_OK
) == 0);
3354 writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT
, reg
->drv2iop_doorbell
);
3357 case ACB_ADAPTER_TYPE_C
: {
3358 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
3360 firmware_state
= readl(®
->outbound_msgaddr1
);
3361 } while ((firmware_state
& ARCMSR_HBCMU_MESSAGE_FIRMWARE_OK
) == 0);
3364 case ACB_ADAPTER_TYPE_D
: {
3365 struct MessageUnit_D
*reg
= acb
->pmuD
;
3367 firmware_state
= readl(reg
->outbound_msgaddr1
);
3368 } while ((firmware_state
&
3369 ARCMSR_ARC1214_MESSAGE_FIRMWARE_OK
) == 0);
3375 static void arcmsr_hbaA_request_device_map(struct AdapterControlBlock
*acb
)
3377 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
3378 if (unlikely(atomic_read(&acb
->rq_map_token
) == 0) || ((acb
->acb_flags
& ACB_F_BUS_RESET
) != 0 ) || ((acb
->acb_flags
& ACB_F_ABORT
) != 0 )){
3379 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3382 acb
->fw_flag
= FW_NORMAL
;
3383 if (atomic_read(&acb
->ante_token_value
) == atomic_read(&acb
->rq_map_token
)){
3384 atomic_set(&acb
->rq_map_token
, 16);
3386 atomic_set(&acb
->ante_token_value
, atomic_read(&acb
->rq_map_token
));
3387 if (atomic_dec_and_test(&acb
->rq_map_token
)) {
3388 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3391 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
3392 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3397 static void arcmsr_hbaB_request_device_map(struct AdapterControlBlock
*acb
)
3399 struct MessageUnit_B
*reg
= acb
->pmuB
;
3400 if (unlikely(atomic_read(&acb
->rq_map_token
) == 0) || ((acb
->acb_flags
& ACB_F_BUS_RESET
) != 0 ) || ((acb
->acb_flags
& ACB_F_ABORT
) != 0 )){
3401 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3404 acb
->fw_flag
= FW_NORMAL
;
3405 if (atomic_read(&acb
->ante_token_value
) == atomic_read(&acb
->rq_map_token
)) {
3406 atomic_set(&acb
->rq_map_token
, 16);
3408 atomic_set(&acb
->ante_token_value
, atomic_read(&acb
->rq_map_token
));
3409 if (atomic_dec_and_test(&acb
->rq_map_token
)) {
3410 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3413 writel(ARCMSR_MESSAGE_GET_CONFIG
, reg
->drv2iop_doorbell
);
3414 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3419 static void arcmsr_hbaC_request_device_map(struct AdapterControlBlock
*acb
)
3421 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
3422 if (unlikely(atomic_read(&acb
->rq_map_token
) == 0) || ((acb
->acb_flags
& ACB_F_BUS_RESET
) != 0) || ((acb
->acb_flags
& ACB_F_ABORT
) != 0)) {
3423 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3426 acb
->fw_flag
= FW_NORMAL
;
3427 if (atomic_read(&acb
->ante_token_value
) == atomic_read(&acb
->rq_map_token
)) {
3428 atomic_set(&acb
->rq_map_token
, 16);
3430 atomic_set(&acb
->ante_token_value
, atomic_read(&acb
->rq_map_token
));
3431 if (atomic_dec_and_test(&acb
->rq_map_token
)) {
3432 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3435 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
3436 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
3437 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3442 static void arcmsr_hbaD_request_device_map(struct AdapterControlBlock
*acb
)
3444 struct MessageUnit_D
*reg
= acb
->pmuD
;
3446 if (unlikely(atomic_read(&acb
->rq_map_token
) == 0) ||
3447 ((acb
->acb_flags
& ACB_F_BUS_RESET
) != 0) ||
3448 ((acb
->acb_flags
& ACB_F_ABORT
) != 0)) {
3449 mod_timer(&acb
->eternal_timer
,
3450 jiffies
+ msecs_to_jiffies(6 * HZ
));
3452 acb
->fw_flag
= FW_NORMAL
;
3453 if (atomic_read(&acb
->ante_token_value
) ==
3454 atomic_read(&acb
->rq_map_token
)) {
3455 atomic_set(&acb
->rq_map_token
, 16);
3457 atomic_set(&acb
->ante_token_value
,
3458 atomic_read(&acb
->rq_map_token
));
3459 if (atomic_dec_and_test(&acb
->rq_map_token
)) {
3460 mod_timer(&acb
->eternal_timer
, jiffies
+
3461 msecs_to_jiffies(6 * HZ
));
3464 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
,
3465 reg
->inbound_msgaddr0
);
3466 mod_timer(&acb
->eternal_timer
, jiffies
+
3467 msecs_to_jiffies(6 * HZ
));
3471 static void arcmsr_request_device_map(unsigned long pacb
)
3473 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*)pacb
;
3474 switch (acb
->adapter_type
) {
3475 case ACB_ADAPTER_TYPE_A
: {
3476 arcmsr_hbaA_request_device_map(acb
);
3479 case ACB_ADAPTER_TYPE_B
: {
3480 arcmsr_hbaB_request_device_map(acb
);
3483 case ACB_ADAPTER_TYPE_C
: {
3484 arcmsr_hbaC_request_device_map(acb
);
3487 case ACB_ADAPTER_TYPE_D
:
3488 arcmsr_hbaD_request_device_map(acb
);
3493 static void arcmsr_hbaA_start_bgrb(struct AdapterControlBlock
*acb
)
3495 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
3496 acb
->acb_flags
|= ACB_F_MSG_START_BGRB
;
3497 writel(ARCMSR_INBOUND_MESG0_START_BGRB
, ®
->inbound_msgaddr0
);
3498 if (!arcmsr_hbaA_wait_msgint_ready(acb
)) {
3499 printk(KERN_NOTICE
"arcmsr%d: wait 'start adapter background \
3500 rebulid' timeout \n", acb
->host
->host_no
);
3504 static void arcmsr_hbaB_start_bgrb(struct AdapterControlBlock
*acb
)
3506 struct MessageUnit_B
*reg
= acb
->pmuB
;
3507 acb
->acb_flags
|= ACB_F_MSG_START_BGRB
;
3508 writel(ARCMSR_MESSAGE_START_BGRB
, reg
->drv2iop_doorbell
);
3509 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
3510 printk(KERN_NOTICE
"arcmsr%d: wait 'start adapter background \
3511 rebulid' timeout \n",acb
->host
->host_no
);
3515 static void arcmsr_hbaC_start_bgrb(struct AdapterControlBlock
*pACB
)
3517 struct MessageUnit_C __iomem
*phbcmu
= pACB
->pmuC
;
3518 pACB
->acb_flags
|= ACB_F_MSG_START_BGRB
;
3519 writel(ARCMSR_INBOUND_MESG0_START_BGRB
, &phbcmu
->inbound_msgaddr0
);
3520 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, &phbcmu
->inbound_doorbell
);
3521 if (!arcmsr_hbaC_wait_msgint_ready(pACB
)) {
3522 printk(KERN_NOTICE
"arcmsr%d: wait 'start adapter background \
3523 rebulid' timeout \n", pACB
->host
->host_no
);
3528 static void arcmsr_hbaD_start_bgrb(struct AdapterControlBlock
*pACB
)
3530 struct MessageUnit_D
*pmu
= pACB
->pmuD
;
3532 pACB
->acb_flags
|= ACB_F_MSG_START_BGRB
;
3533 writel(ARCMSR_INBOUND_MESG0_START_BGRB
, pmu
->inbound_msgaddr0
);
3534 if (!arcmsr_hbaD_wait_msgint_ready(pACB
)) {
3535 pr_notice("arcmsr%d: wait 'start adapter "
3536 "background rebulid' timeout\n", pACB
->host
->host_no
);
3540 static void arcmsr_start_adapter_bgrb(struct AdapterControlBlock
*acb
)
3542 switch (acb
->adapter_type
) {
3543 case ACB_ADAPTER_TYPE_A
:
3544 arcmsr_hbaA_start_bgrb(acb
);
3546 case ACB_ADAPTER_TYPE_B
:
3547 arcmsr_hbaB_start_bgrb(acb
);
3549 case ACB_ADAPTER_TYPE_C
:
3550 arcmsr_hbaC_start_bgrb(acb
);
3552 case ACB_ADAPTER_TYPE_D
:
3553 arcmsr_hbaD_start_bgrb(acb
);
3558 static void arcmsr_clear_doorbell_queue_buffer(struct AdapterControlBlock
*acb
)
3560 switch (acb
->adapter_type
) {
3561 case ACB_ADAPTER_TYPE_A
: {
3562 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
3563 uint32_t outbound_doorbell
;
3564 /* empty doorbell Qbuffer if door bell ringed */
3565 outbound_doorbell
= readl(®
->outbound_doorbell
);
3566 /*clear doorbell interrupt */
3567 writel(outbound_doorbell
, ®
->outbound_doorbell
);
3568 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK
, ®
->inbound_doorbell
);
3572 case ACB_ADAPTER_TYPE_B
: {
3573 struct MessageUnit_B
*reg
= acb
->pmuB
;
3574 /*clear interrupt and message state*/
3575 writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN
, reg
->iop2drv_doorbell
);
3576 writel(ARCMSR_DRV2IOP_DATA_READ_OK
, reg
->drv2iop_doorbell
);
3577 /* let IOP know data has been read */
3580 case ACB_ADAPTER_TYPE_C
: {
3581 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
3582 uint32_t outbound_doorbell
, i
;
3583 /* empty doorbell Qbuffer if door bell ringed */
3584 outbound_doorbell
= readl(®
->outbound_doorbell
);
3585 writel(outbound_doorbell
, ®
->outbound_doorbell_clear
);
3586 writel(ARCMSR_HBCMU_DRV2IOP_DATA_READ_OK
, ®
->inbound_doorbell
);
3587 for (i
= 0; i
< 200; i
++) {
3589 outbound_doorbell
= readl(®
->outbound_doorbell
);
3590 if (outbound_doorbell
&
3591 ARCMSR_HBCMU_IOP2DRV_DATA_WRITE_OK
) {
3592 writel(outbound_doorbell
,
3593 ®
->outbound_doorbell_clear
);
3594 writel(ARCMSR_HBCMU_DRV2IOP_DATA_READ_OK
,
3595 ®
->inbound_doorbell
);
3601 case ACB_ADAPTER_TYPE_D
: {
3602 struct MessageUnit_D
*reg
= acb
->pmuD
;
3603 uint32_t outbound_doorbell
, i
;
3604 /* empty doorbell Qbuffer if door bell ringed */
3605 outbound_doorbell
= readl(reg
->outbound_doorbell
);
3606 writel(outbound_doorbell
, reg
->outbound_doorbell
);
3607 writel(ARCMSR_ARC1214_DRV2IOP_DATA_OUT_READ
,
3608 reg
->inbound_doorbell
);
3609 for (i
= 0; i
< 200; i
++) {
3611 outbound_doorbell
= readl(reg
->outbound_doorbell
);
3612 if (outbound_doorbell
&
3613 ARCMSR_ARC1214_IOP2DRV_DATA_WRITE_OK
) {
3614 writel(outbound_doorbell
,
3615 reg
->outbound_doorbell
);
3616 writel(ARCMSR_ARC1214_DRV2IOP_DATA_OUT_READ
,
3617 reg
->inbound_doorbell
);
3626 static void arcmsr_enable_eoi_mode(struct AdapterControlBlock
*acb
)
3628 switch (acb
->adapter_type
) {
3629 case ACB_ADAPTER_TYPE_A
:
3631 case ACB_ADAPTER_TYPE_B
:
3633 struct MessageUnit_B
*reg
= acb
->pmuB
;
3634 writel(ARCMSR_MESSAGE_ACTIVE_EOI_MODE
, reg
->drv2iop_doorbell
);
3635 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
3636 printk(KERN_NOTICE
"ARCMSR IOP enables EOI_MODE TIMEOUT");
3641 case ACB_ADAPTER_TYPE_C
:
3647 static void arcmsr_hardware_reset(struct AdapterControlBlock
*acb
)
3651 struct MessageUnit_A __iomem
*pmuA
= acb
->pmuA
;
3652 struct MessageUnit_C __iomem
*pmuC
= acb
->pmuC
;
3653 struct MessageUnit_D
*pmuD
= acb
->pmuD
;
3655 /* backup pci config data */
3656 printk(KERN_NOTICE
"arcmsr%d: executing hw bus reset .....\n", acb
->host
->host_no
);
3657 for (i
= 0; i
< 64; i
++) {
3658 pci_read_config_byte(acb
->pdev
, i
, &value
[i
]);
3660 /* hardware reset signal */
3661 if ((acb
->dev_id
== 0x1680)) {
3662 writel(ARCMSR_ARC1680_BUS_RESET
, &pmuA
->reserved1
[0]);
3663 } else if ((acb
->dev_id
== 0x1880)) {
3666 writel(0xF, &pmuC
->write_sequence
);
3667 writel(0x4, &pmuC
->write_sequence
);
3668 writel(0xB, &pmuC
->write_sequence
);
3669 writel(0x2, &pmuC
->write_sequence
);
3670 writel(0x7, &pmuC
->write_sequence
);
3671 writel(0xD, &pmuC
->write_sequence
);
3672 } while (((readl(&pmuC
->host_diagnostic
) & ARCMSR_ARC1880_DiagWrite_ENABLE
) == 0) && (count
< 5));
3673 writel(ARCMSR_ARC1880_RESET_ADAPTER
, &pmuC
->host_diagnostic
);
3674 } else if ((acb
->dev_id
== 0x1214)) {
3675 writel(0x20, pmuD
->reset_request
);
3677 pci_write_config_byte(acb
->pdev
, 0x84, 0x20);
3680 /* write back pci config data */
3681 for (i
= 0; i
< 64; i
++) {
3682 pci_write_config_byte(acb
->pdev
, i
, value
[i
]);
3687 static void arcmsr_iop_init(struct AdapterControlBlock
*acb
)
3689 uint32_t intmask_org
;
3690 /* disable all outbound interrupt */
3691 intmask_org
= arcmsr_disable_outbound_ints(acb
);
3692 arcmsr_wait_firmware_ready(acb
);
3693 arcmsr_iop_confirm(acb
);
3694 /*start background rebuild*/
3695 arcmsr_start_adapter_bgrb(acb
);
3696 /* empty doorbell Qbuffer if door bell ringed */
3697 arcmsr_clear_doorbell_queue_buffer(acb
);
3698 arcmsr_enable_eoi_mode(acb
);
3699 /* enable outbound Post Queue,outbound doorbell Interrupt */
3700 arcmsr_enable_outbound_ints(acb
, intmask_org
);
3701 acb
->acb_flags
|= ACB_F_IOP_INITED
;
3704 static uint8_t arcmsr_iop_reset(struct AdapterControlBlock
*acb
)
3706 struct CommandControlBlock
*ccb
;
3707 uint32_t intmask_org
;
3708 uint8_t rtnval
= 0x00;
3710 unsigned long flags
;
3712 if (atomic_read(&acb
->ccboutstandingcount
) != 0) {
3713 /* disable all outbound interrupt */
3714 intmask_org
= arcmsr_disable_outbound_ints(acb
);
3715 /* talk to iop 331 outstanding command aborted */
3716 rtnval
= arcmsr_abort_allcmd(acb
);
3717 /* clear all outbound posted Q */
3718 arcmsr_done4abort_postqueue(acb
);
3719 for (i
= 0; i
< ARCMSR_MAX_FREECCB_NUM
; i
++) {
3720 ccb
= acb
->pccb_pool
[i
];
3721 if (ccb
->startdone
== ARCMSR_CCB_START
) {
3722 scsi_dma_unmap(ccb
->pcmd
);
3723 ccb
->startdone
= ARCMSR_CCB_DONE
;
3725 spin_lock_irqsave(&acb
->ccblist_lock
, flags
);
3726 list_add_tail(&ccb
->list
, &acb
->ccb_free_list
);
3727 spin_unlock_irqrestore(&acb
->ccblist_lock
, flags
);
3730 atomic_set(&acb
->ccboutstandingcount
, 0);
3731 /* enable all outbound interrupt */
3732 arcmsr_enable_outbound_ints(acb
, intmask_org
);
3738 static int arcmsr_bus_reset(struct scsi_cmnd
*cmd
)
3740 struct AdapterControlBlock
*acb
;
3741 uint32_t intmask_org
, outbound_doorbell
;
3742 int retry_count
= 0;
3744 acb
= (struct AdapterControlBlock
*) cmd
->device
->host
->hostdata
;
3745 printk(KERN_ERR
"arcmsr: executing bus reset eh.....num_resets = %d, num_aborts = %d \n", acb
->num_resets
, acb
->num_aborts
);
3748 switch(acb
->adapter_type
){
3749 case ACB_ADAPTER_TYPE_A
:{
3750 if (acb
->acb_flags
& ACB_F_BUS_RESET
){
3752 printk(KERN_ERR
"arcmsr: there is an bus reset eh proceeding.......\n");
3753 timeout
= wait_event_timeout(wait_q
, (acb
->acb_flags
& ACB_F_BUS_RESET
) == 0, 220*HZ
);
3758 acb
->acb_flags
|= ACB_F_BUS_RESET
;
3759 if (!arcmsr_iop_reset(acb
)) {
3760 struct MessageUnit_A __iomem
*reg
;
3762 arcmsr_hardware_reset(acb
);
3763 acb
->acb_flags
&= ~ACB_F_IOP_INITED
;
3765 ssleep(ARCMSR_SLEEPTIME
);
3766 if ((readl(®
->outbound_msgaddr1
) & ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK
) == 0) {
3767 printk(KERN_ERR
"arcmsr%d: waiting for hw bus reset return, retry=%d\n", acb
->host
->host_no
, retry_count
);
3768 if (retry_count
> ARCMSR_RETRYCOUNT
) {
3769 acb
->fw_flag
= FW_DEADLOCK
;
3770 printk(KERN_ERR
"arcmsr%d: waiting for hw bus reset return, RETRY TERMINATED!!\n", acb
->host
->host_no
);
3776 acb
->acb_flags
|= ACB_F_IOP_INITED
;
3777 /* disable all outbound interrupt */
3778 intmask_org
= arcmsr_disable_outbound_ints(acb
);
3779 arcmsr_get_firmware_spec(acb
);
3780 arcmsr_start_adapter_bgrb(acb
);
3781 /* clear Qbuffer if door bell ringed */
3782 outbound_doorbell
= readl(®
->outbound_doorbell
);
3783 writel(outbound_doorbell
, ®
->outbound_doorbell
); /*clear interrupt */
3784 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK
, ®
->inbound_doorbell
);
3785 /* enable outbound Post Queue,outbound doorbell Interrupt */
3786 arcmsr_enable_outbound_ints(acb
, intmask_org
);
3787 atomic_set(&acb
->rq_map_token
, 16);
3788 atomic_set(&acb
->ante_token_value
, 16);
3789 acb
->fw_flag
= FW_NORMAL
;
3790 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3791 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3793 printk(KERN_ERR
"arcmsr: scsi bus reset eh returns with success\n");
3795 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3796 atomic_set(&acb
->rq_map_token
, 16);
3797 atomic_set(&acb
->ante_token_value
, 16);
3798 acb
->fw_flag
= FW_NORMAL
;
3799 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6*HZ
));
3804 case ACB_ADAPTER_TYPE_B
:{
3805 acb
->acb_flags
|= ACB_F_BUS_RESET
;
3806 if (!arcmsr_iop_reset(acb
)) {
3807 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3810 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3811 atomic_set(&acb
->rq_map_token
, 16);
3812 atomic_set(&acb
->ante_token_value
, 16);
3813 acb
->fw_flag
= FW_NORMAL
;
3814 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3819 case ACB_ADAPTER_TYPE_C
:{
3820 if (acb
->acb_flags
& ACB_F_BUS_RESET
) {
3822 printk(KERN_ERR
"arcmsr: there is an bus reset eh proceeding.......\n");
3823 timeout
= wait_event_timeout(wait_q
, (acb
->acb_flags
& ACB_F_BUS_RESET
) == 0, 220*HZ
);
3828 acb
->acb_flags
|= ACB_F_BUS_RESET
;
3829 if (!arcmsr_iop_reset(acb
)) {
3830 struct MessageUnit_C __iomem
*reg
;
3832 arcmsr_hardware_reset(acb
);
3833 acb
->acb_flags
&= ~ACB_F_IOP_INITED
;
3835 ssleep(ARCMSR_SLEEPTIME
);
3836 if ((readl(®
->host_diagnostic
) & 0x04) != 0) {
3837 printk(KERN_ERR
"arcmsr%d: waiting for hw bus reset return, retry=%d\n", acb
->host
->host_no
, retry_count
);
3838 if (retry_count
> ARCMSR_RETRYCOUNT
) {
3839 acb
->fw_flag
= FW_DEADLOCK
;
3840 printk(KERN_ERR
"arcmsr%d: waiting for hw bus reset return, RETRY TERMINATED!!\n", acb
->host
->host_no
);
3846 acb
->acb_flags
|= ACB_F_IOP_INITED
;
3847 /* disable all outbound interrupt */
3848 intmask_org
= arcmsr_disable_outbound_ints(acb
);
3849 arcmsr_get_firmware_spec(acb
);
3850 arcmsr_start_adapter_bgrb(acb
);
3851 /* clear Qbuffer if door bell ringed */
3852 arcmsr_clear_doorbell_queue_buffer(acb
);
3853 /* enable outbound Post Queue,outbound doorbell Interrupt */
3854 arcmsr_enable_outbound_ints(acb
, intmask_org
);
3855 atomic_set(&acb
->rq_map_token
, 16);
3856 atomic_set(&acb
->ante_token_value
, 16);
3857 acb
->fw_flag
= FW_NORMAL
;
3858 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
3859 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3861 printk(KERN_ERR
"arcmsr: scsi bus reset eh returns with success\n");
3863 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3864 atomic_set(&acb
->rq_map_token
, 16);
3865 atomic_set(&acb
->ante_token_value
, 16);
3866 acb
->fw_flag
= FW_NORMAL
;
3867 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6*HZ
));
3872 case ACB_ADAPTER_TYPE_D
: {
3873 if (acb
->acb_flags
& ACB_F_BUS_RESET
) {
3875 pr_notice("arcmsr: there is an bus reset"
3876 " eh proceeding.......\n");
3877 timeout
= wait_event_timeout(wait_q
, (acb
->acb_flags
3878 & ACB_F_BUS_RESET
) == 0, 220 * HZ
);
3882 acb
->acb_flags
|= ACB_F_BUS_RESET
;
3883 if (!arcmsr_iop_reset(acb
)) {
3884 struct MessageUnit_D
*reg
;
3886 arcmsr_hardware_reset(acb
);
3887 acb
->acb_flags
&= ~ACB_F_IOP_INITED
;
3889 ssleep(ARCMSR_SLEEPTIME
);
3890 if ((readl(reg
->sample_at_reset
) & 0x80) != 0) {
3891 pr_err("arcmsr%d: waiting for "
3892 "hw bus reset return, retry=%d\n",
3893 acb
->host
->host_no
, retry_count
);
3894 if (retry_count
> ARCMSR_RETRYCOUNT
) {
3895 acb
->fw_flag
= FW_DEADLOCK
;
3896 pr_err("arcmsr%d: waiting for hw bus"
3898 "RETRY TERMINATED!!\n",
3899 acb
->host
->host_no
);
3905 acb
->acb_flags
|= ACB_F_IOP_INITED
;
3906 /* disable all outbound interrupt */
3907 intmask_org
= arcmsr_disable_outbound_ints(acb
);
3908 arcmsr_get_firmware_spec(acb
);
3909 arcmsr_start_adapter_bgrb(acb
);
3910 arcmsr_clear_doorbell_queue_buffer(acb
);
3911 arcmsr_enable_outbound_ints(acb
, intmask_org
);
3912 atomic_set(&acb
->rq_map_token
, 16);
3913 atomic_set(&acb
->ante_token_value
, 16);
3914 acb
->fw_flag
= FW_NORMAL
;
3915 mod_timer(&acb
->eternal_timer
,
3916 jiffies
+ msecs_to_jiffies(6 * HZ
));
3917 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3919 pr_err("arcmsr: scsi bus reset "
3920 "eh returns with success\n");
3922 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
3923 atomic_set(&acb
->rq_map_token
, 16);
3924 atomic_set(&acb
->ante_token_value
, 16);
3925 acb
->fw_flag
= FW_NORMAL
;
3926 mod_timer(&acb
->eternal_timer
,
3927 jiffies
+ msecs_to_jiffies(6 * HZ
));
3936 static int arcmsr_abort_one_cmd(struct AdapterControlBlock
*acb
,
3937 struct CommandControlBlock
*ccb
)
3940 rtn
= arcmsr_polling_ccbdone(acb
, ccb
);
3944 static int arcmsr_abort(struct scsi_cmnd
*cmd
)
3946 struct AdapterControlBlock
*acb
=
3947 (struct AdapterControlBlock
*)cmd
->device
->host
->hostdata
;
3950 uint32_t intmask_org
;
3953 "arcmsr%d: abort device command of scsi id = %d lun = %d\n",
3954 acb
->host
->host_no
, cmd
->device
->id
, (u32
)cmd
->device
->lun
);
3955 acb
->acb_flags
|= ACB_F_ABORT
;
3958 ************************************************
3959 ** the all interrupt service routine is locked
3960 ** we need to handle it as soon as possible and exit
3961 ************************************************
3963 if (!atomic_read(&acb
->ccboutstandingcount
)) {
3964 acb
->acb_flags
&= ~ACB_F_ABORT
;
3968 intmask_org
= arcmsr_disable_outbound_ints(acb
);
3969 for (i
= 0; i
< ARCMSR_MAX_FREECCB_NUM
; i
++) {
3970 struct CommandControlBlock
*ccb
= acb
->pccb_pool
[i
];
3971 if (ccb
->startdone
== ARCMSR_CCB_START
&& ccb
->pcmd
== cmd
) {
3972 ccb
->startdone
= ARCMSR_CCB_ABORTED
;
3973 rtn
= arcmsr_abort_one_cmd(acb
, ccb
);
3977 acb
->acb_flags
&= ~ACB_F_ABORT
;
3978 arcmsr_enable_outbound_ints(acb
, intmask_org
);
3982 static const char *arcmsr_info(struct Scsi_Host
*host
)
3984 struct AdapterControlBlock
*acb
=
3985 (struct AdapterControlBlock
*) host
->hostdata
;
3986 static char buf
[256];
3989 switch (acb
->pdev
->device
) {
3990 case PCI_DEVICE_ID_ARECA_1110
:
3991 case PCI_DEVICE_ID_ARECA_1200
:
3992 case PCI_DEVICE_ID_ARECA_1202
:
3993 case PCI_DEVICE_ID_ARECA_1210
:
3996 case PCI_DEVICE_ID_ARECA_1120
:
3997 case PCI_DEVICE_ID_ARECA_1130
:
3998 case PCI_DEVICE_ID_ARECA_1160
:
3999 case PCI_DEVICE_ID_ARECA_1170
:
4000 case PCI_DEVICE_ID_ARECA_1201
:
4001 case PCI_DEVICE_ID_ARECA_1220
:
4002 case PCI_DEVICE_ID_ARECA_1230
:
4003 case PCI_DEVICE_ID_ARECA_1260
:
4004 case PCI_DEVICE_ID_ARECA_1270
:
4005 case PCI_DEVICE_ID_ARECA_1280
:
4008 case PCI_DEVICE_ID_ARECA_1214
:
4009 case PCI_DEVICE_ID_ARECA_1380
:
4010 case PCI_DEVICE_ID_ARECA_1381
:
4011 case PCI_DEVICE_ID_ARECA_1680
:
4012 case PCI_DEVICE_ID_ARECA_1681
:
4013 case PCI_DEVICE_ID_ARECA_1880
:
4021 sprintf(buf
, "Areca %s RAID Controller %s\narcmsr version %s\n",
4022 type
, raid6
? "(RAID6 capable)" : "", ARCMSR_DRIVER_VERSION
);