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.rst
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/circ_buf.h>
63 #include <linux/uaccess.h>
64 #include <scsi/scsi_host.h>
65 #include <scsi/scsi.h>
66 #include <scsi/scsi_cmnd.h>
67 #include <scsi/scsi_tcq.h>
68 #include <scsi/scsi_device.h>
69 #include <scsi/scsi_transport.h>
70 #include <scsi/scsicam.h>
72 MODULE_AUTHOR("Nick Cheng, C.L. Huang <support@areca.com.tw>");
73 MODULE_DESCRIPTION("Areca ARC11xx/12xx/16xx/188x SAS/SATA RAID Controller Driver");
74 MODULE_LICENSE("Dual BSD/GPL");
75 MODULE_VERSION(ARCMSR_DRIVER_VERSION
);
77 static int msix_enable
= 1;
78 module_param(msix_enable
, int, S_IRUGO
);
79 MODULE_PARM_DESC(msix_enable
, "Enable MSI-X interrupt(0 ~ 1), msix_enable=1(enable), =0(disable)");
81 static int msi_enable
= 1;
82 module_param(msi_enable
, int, S_IRUGO
);
83 MODULE_PARM_DESC(msi_enable
, "Enable MSI interrupt(0 ~ 1), msi_enable=1(enable), =0(disable)");
85 static int host_can_queue
= ARCMSR_DEFAULT_OUTSTANDING_CMD
;
86 module_param(host_can_queue
, int, S_IRUGO
);
87 MODULE_PARM_DESC(host_can_queue
, " adapter queue depth(32 ~ 1024), default is 128");
89 static int cmd_per_lun
= ARCMSR_DEFAULT_CMD_PERLUN
;
90 module_param(cmd_per_lun
, int, S_IRUGO
);
91 MODULE_PARM_DESC(cmd_per_lun
, " device queue depth(1 ~ 128), default is 32");
93 static int dma_mask_64
= 0;
94 module_param(dma_mask_64
, int, S_IRUGO
);
95 MODULE_PARM_DESC(dma_mask_64
, " set DMA mask to 64 bits(0 ~ 1), dma_mask_64=1(64 bits), =0(32 bits)");
97 static int set_date_time
= 0;
98 module_param(set_date_time
, int, S_IRUGO
);
99 MODULE_PARM_DESC(set_date_time
, " send date, time to iop(0 ~ 1), set_date_time=1(enable), default(=0) is disable");
101 static int cmd_timeout
= ARCMSR_DEFAULT_TIMEOUT
;
102 module_param(cmd_timeout
, int, S_IRUGO
);
103 MODULE_PARM_DESC(cmd_timeout
, " scsi cmd timeout(0 ~ 120 sec.), default is 90");
105 #define ARCMSR_SLEEPTIME 10
106 #define ARCMSR_RETRYCOUNT 12
108 static wait_queue_head_t wait_q
;
109 static int arcmsr_iop_message_xfer(struct AdapterControlBlock
*acb
,
110 struct scsi_cmnd
*cmd
);
111 static int arcmsr_iop_confirm(struct AdapterControlBlock
*acb
);
112 static int arcmsr_abort(struct scsi_cmnd
*);
113 static int arcmsr_bus_reset(struct scsi_cmnd
*);
114 static int arcmsr_bios_param(struct scsi_device
*sdev
,
115 struct block_device
*bdev
, sector_t capacity
, int *info
);
116 static int arcmsr_queue_command(struct Scsi_Host
*h
, struct scsi_cmnd
*cmd
);
117 static int arcmsr_probe(struct pci_dev
*pdev
,
118 const struct pci_device_id
*id
);
119 static int __maybe_unused
arcmsr_suspend(struct device
*dev
);
120 static int __maybe_unused
arcmsr_resume(struct device
*dev
);
121 static void arcmsr_remove(struct pci_dev
*pdev
);
122 static void arcmsr_shutdown(struct pci_dev
*pdev
);
123 static void arcmsr_iop_init(struct AdapterControlBlock
*acb
);
124 static void arcmsr_free_ccb_pool(struct AdapterControlBlock
*acb
);
125 static u32
arcmsr_disable_outbound_ints(struct AdapterControlBlock
*acb
);
126 static void arcmsr_enable_outbound_ints(struct AdapterControlBlock
*acb
,
128 static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock
*acb
);
129 static void arcmsr_hbaA_flush_cache(struct AdapterControlBlock
*acb
);
130 static void arcmsr_hbaB_flush_cache(struct AdapterControlBlock
*acb
);
131 static void arcmsr_request_device_map(struct timer_list
*t
);
132 static void arcmsr_message_isr_bh_fn(struct work_struct
*work
);
133 static bool arcmsr_get_firmware_spec(struct AdapterControlBlock
*acb
);
134 static void arcmsr_start_adapter_bgrb(struct AdapterControlBlock
*acb
);
135 static void arcmsr_hbaC_message_isr(struct AdapterControlBlock
*pACB
);
136 static void arcmsr_hbaD_message_isr(struct AdapterControlBlock
*acb
);
137 static void arcmsr_hbaE_message_isr(struct AdapterControlBlock
*acb
);
138 static void arcmsr_hbaE_postqueue_isr(struct AdapterControlBlock
*acb
);
139 static void arcmsr_hbaF_postqueue_isr(struct AdapterControlBlock
*acb
);
140 static void arcmsr_hardware_reset(struct AdapterControlBlock
*acb
);
141 static const char *arcmsr_info(struct Scsi_Host
*);
142 static irqreturn_t
arcmsr_interrupt(struct AdapterControlBlock
*acb
);
143 static void arcmsr_free_irq(struct pci_dev
*, struct AdapterControlBlock
*);
144 static void arcmsr_wait_firmware_ready(struct AdapterControlBlock
*acb
);
145 static void arcmsr_set_iop_datetime(struct timer_list
*);
146 static int arcmsr_slave_config(struct scsi_device
*sdev
);
147 static int arcmsr_adjust_disk_queue_depth(struct scsi_device
*sdev
, int queue_depth
)
149 if (queue_depth
> ARCMSR_MAX_CMD_PERLUN
)
150 queue_depth
= ARCMSR_MAX_CMD_PERLUN
;
151 return scsi_change_queue_depth(sdev
, queue_depth
);
154 static const struct scsi_host_template arcmsr_scsi_host_template
= {
155 .module
= THIS_MODULE
,
156 .proc_name
= ARCMSR_NAME
,
157 .name
= "Areca SAS/SATA RAID driver",
159 .queuecommand
= arcmsr_queue_command
,
160 .eh_abort_handler
= arcmsr_abort
,
161 .eh_bus_reset_handler
= arcmsr_bus_reset
,
162 .bios_param
= arcmsr_bios_param
,
163 .slave_configure
= arcmsr_slave_config
,
164 .change_queue_depth
= arcmsr_adjust_disk_queue_depth
,
165 .can_queue
= ARCMSR_DEFAULT_OUTSTANDING_CMD
,
166 .this_id
= ARCMSR_SCSI_INITIATOR_ID
,
167 .sg_tablesize
= ARCMSR_DEFAULT_SG_ENTRIES
,
168 .max_sectors
= ARCMSR_MAX_XFER_SECTORS_C
,
169 .cmd_per_lun
= ARCMSR_DEFAULT_CMD_PERLUN
,
170 .shost_groups
= arcmsr_host_groups
,
174 static struct pci_device_id arcmsr_device_id_table
[] = {
175 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1110
),
176 .driver_data
= ACB_ADAPTER_TYPE_A
},
177 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1120
),
178 .driver_data
= ACB_ADAPTER_TYPE_A
},
179 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1130
),
180 .driver_data
= ACB_ADAPTER_TYPE_A
},
181 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1160
),
182 .driver_data
= ACB_ADAPTER_TYPE_A
},
183 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1170
),
184 .driver_data
= ACB_ADAPTER_TYPE_A
},
185 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1200
),
186 .driver_data
= ACB_ADAPTER_TYPE_B
},
187 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1201
),
188 .driver_data
= ACB_ADAPTER_TYPE_B
},
189 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1202
),
190 .driver_data
= ACB_ADAPTER_TYPE_B
},
191 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1203
),
192 .driver_data
= ACB_ADAPTER_TYPE_B
},
193 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1210
),
194 .driver_data
= ACB_ADAPTER_TYPE_A
},
195 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1214
),
196 .driver_data
= ACB_ADAPTER_TYPE_D
},
197 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1220
),
198 .driver_data
= ACB_ADAPTER_TYPE_A
},
199 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1230
),
200 .driver_data
= ACB_ADAPTER_TYPE_A
},
201 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1260
),
202 .driver_data
= ACB_ADAPTER_TYPE_A
},
203 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1270
),
204 .driver_data
= ACB_ADAPTER_TYPE_A
},
205 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1280
),
206 .driver_data
= ACB_ADAPTER_TYPE_A
},
207 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1380
),
208 .driver_data
= ACB_ADAPTER_TYPE_A
},
209 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1381
),
210 .driver_data
= ACB_ADAPTER_TYPE_A
},
211 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1680
),
212 .driver_data
= ACB_ADAPTER_TYPE_A
},
213 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1681
),
214 .driver_data
= ACB_ADAPTER_TYPE_A
},
215 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1880
),
216 .driver_data
= ACB_ADAPTER_TYPE_C
},
217 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1883
),
218 .driver_data
= ACB_ADAPTER_TYPE_C
},
219 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1884
),
220 .driver_data
= ACB_ADAPTER_TYPE_E
},
221 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1886_0
),
222 .driver_data
= ACB_ADAPTER_TYPE_F
},
223 {PCI_DEVICE(PCI_VENDOR_ID_ARECA
, PCI_DEVICE_ID_ARECA_1886
),
224 .driver_data
= ACB_ADAPTER_TYPE_F
},
225 {0, 0}, /* Terminating entry */
227 MODULE_DEVICE_TABLE(pci
, arcmsr_device_id_table
);
229 static SIMPLE_DEV_PM_OPS(arcmsr_pm_ops
, arcmsr_suspend
, arcmsr_resume
);
231 static struct pci_driver arcmsr_pci_driver
= {
233 .id_table
= arcmsr_device_id_table
,
234 .probe
= arcmsr_probe
,
235 .remove
= arcmsr_remove
,
236 .driver
.pm
= &arcmsr_pm_ops
,
237 .shutdown
= arcmsr_shutdown
,
240 ****************************************************************************
241 ****************************************************************************
244 static void arcmsr_free_io_queue(struct AdapterControlBlock
*acb
)
246 switch (acb
->adapter_type
) {
247 case ACB_ADAPTER_TYPE_B
:
248 case ACB_ADAPTER_TYPE_D
:
249 case ACB_ADAPTER_TYPE_E
:
250 case ACB_ADAPTER_TYPE_F
:
251 dma_free_coherent(&acb
->pdev
->dev
, acb
->ioqueue_size
,
252 acb
->dma_coherent2
, acb
->dma_coherent_handle2
);
257 static bool arcmsr_remap_pciregion(struct AdapterControlBlock
*acb
)
259 struct pci_dev
*pdev
= acb
->pdev
;
260 switch (acb
->adapter_type
){
261 case ACB_ADAPTER_TYPE_A
:{
262 acb
->pmuA
= ioremap(pci_resource_start(pdev
,0), pci_resource_len(pdev
,0));
264 printk(KERN_NOTICE
"arcmsr%d: memory mapping region fail \n", acb
->host
->host_no
);
269 case ACB_ADAPTER_TYPE_B
:{
270 void __iomem
*mem_base0
, *mem_base1
;
271 mem_base0
= ioremap(pci_resource_start(pdev
, 0), pci_resource_len(pdev
, 0));
273 printk(KERN_NOTICE
"arcmsr%d: memory mapping region fail \n", acb
->host
->host_no
);
276 mem_base1
= ioremap(pci_resource_start(pdev
, 2), pci_resource_len(pdev
, 2));
279 printk(KERN_NOTICE
"arcmsr%d: memory mapping region fail \n", acb
->host
->host_no
);
282 acb
->mem_base0
= mem_base0
;
283 acb
->mem_base1
= mem_base1
;
286 case ACB_ADAPTER_TYPE_C
:{
287 acb
->pmuC
= ioremap(pci_resource_start(pdev
, 1), pci_resource_len(pdev
, 1));
289 printk(KERN_NOTICE
"arcmsr%d: memory mapping region fail \n", acb
->host
->host_no
);
292 if (readl(&acb
->pmuC
->outbound_doorbell
) & ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE
) {
293 writel(ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE_DOORBELL_CLEAR
, &acb
->pmuC
->outbound_doorbell_clear
);/*clear interrupt*/
298 case ACB_ADAPTER_TYPE_D
: {
299 void __iomem
*mem_base0
;
300 unsigned long addr
, range
;
302 addr
= (unsigned long)pci_resource_start(pdev
, 0);
303 range
= pci_resource_len(pdev
, 0);
304 mem_base0
= ioremap(addr
, range
);
306 pr_notice("arcmsr%d: memory mapping region fail\n",
310 acb
->mem_base0
= mem_base0
;
313 case ACB_ADAPTER_TYPE_E
: {
314 acb
->pmuE
= ioremap(pci_resource_start(pdev
, 1),
315 pci_resource_len(pdev
, 1));
317 pr_notice("arcmsr%d: memory mapping region fail \n",
321 writel(0, &acb
->pmuE
->host_int_status
); /*clear interrupt*/
322 writel(ARCMSR_HBEMU_DOORBELL_SYNC
, &acb
->pmuE
->iobound_doorbell
); /* synchronize doorbell to 0 */
323 acb
->in_doorbell
= 0;
324 acb
->out_doorbell
= 0;
327 case ACB_ADAPTER_TYPE_F
: {
328 acb
->pmuF
= ioremap(pci_resource_start(pdev
, 0), pci_resource_len(pdev
, 0));
330 pr_notice("arcmsr%d: memory mapping region fail\n",
334 writel(0, &acb
->pmuF
->host_int_status
); /* clear interrupt */
335 writel(ARCMSR_HBFMU_DOORBELL_SYNC
, &acb
->pmuF
->iobound_doorbell
);
336 acb
->in_doorbell
= 0;
337 acb
->out_doorbell
= 0;
344 static void arcmsr_unmap_pciregion(struct AdapterControlBlock
*acb
)
346 switch (acb
->adapter_type
) {
347 case ACB_ADAPTER_TYPE_A
:
350 case ACB_ADAPTER_TYPE_B
:
351 iounmap(acb
->mem_base0
);
352 iounmap(acb
->mem_base1
);
354 case ACB_ADAPTER_TYPE_C
:
357 case ACB_ADAPTER_TYPE_D
:
358 iounmap(acb
->mem_base0
);
360 case ACB_ADAPTER_TYPE_E
:
363 case ACB_ADAPTER_TYPE_F
:
369 static irqreturn_t
arcmsr_do_interrupt(int irq
, void *dev_id
)
371 irqreturn_t handle_state
;
372 struct AdapterControlBlock
*acb
= dev_id
;
374 handle_state
= arcmsr_interrupt(acb
);
378 static int arcmsr_bios_param(struct scsi_device
*sdev
,
379 struct block_device
*bdev
, sector_t capacity
, int *geom
)
381 int heads
, sectors
, cylinders
, total_capacity
;
383 if (scsi_partsize(bdev
, capacity
, geom
))
386 total_capacity
= capacity
;
389 cylinders
= total_capacity
/ (heads
* sectors
);
390 if (cylinders
> 1024) {
393 cylinders
= total_capacity
/ (heads
* sectors
);
401 static uint8_t arcmsr_hbaA_wait_msgint_ready(struct AdapterControlBlock
*acb
)
403 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
406 for (i
= 0; i
< 2000; i
++) {
407 if (readl(®
->outbound_intstatus
) &
408 ARCMSR_MU_OUTBOUND_MESSAGE0_INT
) {
409 writel(ARCMSR_MU_OUTBOUND_MESSAGE0_INT
,
410 ®
->outbound_intstatus
);
414 } /* max 20 seconds */
419 static uint8_t arcmsr_hbaB_wait_msgint_ready(struct AdapterControlBlock
*acb
)
421 struct MessageUnit_B
*reg
= acb
->pmuB
;
424 for (i
= 0; i
< 2000; i
++) {
425 if (readl(reg
->iop2drv_doorbell
)
426 & ARCMSR_IOP2DRV_MESSAGE_CMD_DONE
) {
427 writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN
,
428 reg
->iop2drv_doorbell
);
429 writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT
,
430 reg
->drv2iop_doorbell
);
434 } /* max 20 seconds */
439 static uint8_t arcmsr_hbaC_wait_msgint_ready(struct AdapterControlBlock
*pACB
)
441 struct MessageUnit_C __iomem
*phbcmu
= pACB
->pmuC
;
444 for (i
= 0; i
< 2000; i
++) {
445 if (readl(&phbcmu
->outbound_doorbell
)
446 & ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE
) {
447 writel(ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE_DOORBELL_CLEAR
,
448 &phbcmu
->outbound_doorbell_clear
); /*clear interrupt*/
452 } /* max 20 seconds */
457 static bool arcmsr_hbaD_wait_msgint_ready(struct AdapterControlBlock
*pACB
)
459 struct MessageUnit_D
*reg
= pACB
->pmuD
;
462 for (i
= 0; i
< 2000; i
++) {
463 if (readl(reg
->outbound_doorbell
)
464 & ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
) {
465 writel(ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
,
466 reg
->outbound_doorbell
);
470 } /* max 20 seconds */
474 static bool arcmsr_hbaE_wait_msgint_ready(struct AdapterControlBlock
*pACB
)
477 uint32_t read_doorbell
;
478 struct MessageUnit_E __iomem
*phbcmu
= pACB
->pmuE
;
480 for (i
= 0; i
< 2000; i
++) {
481 read_doorbell
= readl(&phbcmu
->iobound_doorbell
);
482 if ((read_doorbell
^ pACB
->in_doorbell
) & ARCMSR_HBEMU_IOP2DRV_MESSAGE_CMD_DONE
) {
483 writel(0, &phbcmu
->host_int_status
); /*clear interrupt*/
484 pACB
->in_doorbell
= read_doorbell
;
488 } /* max 20 seconds */
492 static void arcmsr_hbaA_flush_cache(struct AdapterControlBlock
*acb
)
494 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
495 int retry_count
= 30;
496 writel(ARCMSR_INBOUND_MESG0_FLUSH_CACHE
, ®
->inbound_msgaddr0
);
498 if (arcmsr_hbaA_wait_msgint_ready(acb
))
502 printk(KERN_NOTICE
"arcmsr%d: wait 'flush adapter cache' \
503 timeout, retry count down = %d \n", acb
->host
->host_no
, retry_count
);
505 } while (retry_count
!= 0);
508 static void arcmsr_hbaB_flush_cache(struct AdapterControlBlock
*acb
)
510 struct MessageUnit_B
*reg
= acb
->pmuB
;
511 int retry_count
= 30;
512 writel(ARCMSR_MESSAGE_FLUSH_CACHE
, reg
->drv2iop_doorbell
);
514 if (arcmsr_hbaB_wait_msgint_ready(acb
))
518 printk(KERN_NOTICE
"arcmsr%d: wait 'flush adapter cache' \
519 timeout,retry count down = %d \n", acb
->host
->host_no
, retry_count
);
521 } while (retry_count
!= 0);
524 static void arcmsr_hbaC_flush_cache(struct AdapterControlBlock
*pACB
)
526 struct MessageUnit_C __iomem
*reg
= pACB
->pmuC
;
527 int retry_count
= 30;/* enlarge wait flush adapter cache time: 10 minute */
528 writel(ARCMSR_INBOUND_MESG0_FLUSH_CACHE
, ®
->inbound_msgaddr0
);
529 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
531 if (arcmsr_hbaC_wait_msgint_ready(pACB
)) {
535 printk(KERN_NOTICE
"arcmsr%d: wait 'flush adapter cache' \
536 timeout,retry count down = %d \n", pACB
->host
->host_no
, retry_count
);
538 } while (retry_count
!= 0);
542 static void arcmsr_hbaD_flush_cache(struct AdapterControlBlock
*pACB
)
544 int retry_count
= 15;
545 struct MessageUnit_D
*reg
= pACB
->pmuD
;
547 writel(ARCMSR_INBOUND_MESG0_FLUSH_CACHE
, reg
->inbound_msgaddr0
);
549 if (arcmsr_hbaD_wait_msgint_ready(pACB
))
553 pr_notice("arcmsr%d: wait 'flush adapter "
554 "cache' timeout, retry count down = %d\n",
555 pACB
->host
->host_no
, retry_count
);
556 } while (retry_count
!= 0);
559 static void arcmsr_hbaE_flush_cache(struct AdapterControlBlock
*pACB
)
561 int retry_count
= 30;
562 struct MessageUnit_E __iomem
*reg
= pACB
->pmuE
;
564 writel(ARCMSR_INBOUND_MESG0_FLUSH_CACHE
, ®
->inbound_msgaddr0
);
565 pACB
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_MESSAGE_CMD_DONE
;
566 writel(pACB
->out_doorbell
, ®
->iobound_doorbell
);
568 if (arcmsr_hbaE_wait_msgint_ready(pACB
))
571 pr_notice("arcmsr%d: wait 'flush adapter "
572 "cache' timeout, retry count down = %d\n",
573 pACB
->host
->host_no
, retry_count
);
574 } while (retry_count
!= 0);
577 static void arcmsr_flush_adapter_cache(struct AdapterControlBlock
*acb
)
579 switch (acb
->adapter_type
) {
581 case ACB_ADAPTER_TYPE_A
:
582 arcmsr_hbaA_flush_cache(acb
);
584 case ACB_ADAPTER_TYPE_B
:
585 arcmsr_hbaB_flush_cache(acb
);
587 case ACB_ADAPTER_TYPE_C
:
588 arcmsr_hbaC_flush_cache(acb
);
590 case ACB_ADAPTER_TYPE_D
:
591 arcmsr_hbaD_flush_cache(acb
);
593 case ACB_ADAPTER_TYPE_E
:
594 case ACB_ADAPTER_TYPE_F
:
595 arcmsr_hbaE_flush_cache(acb
);
600 static void arcmsr_hbaB_assign_regAddr(struct AdapterControlBlock
*acb
)
602 struct MessageUnit_B
*reg
= acb
->pmuB
;
604 if (acb
->pdev
->device
== PCI_DEVICE_ID_ARECA_1203
) {
605 reg
->drv2iop_doorbell
= MEM_BASE0(ARCMSR_DRV2IOP_DOORBELL_1203
);
606 reg
->drv2iop_doorbell_mask
= MEM_BASE0(ARCMSR_DRV2IOP_DOORBELL_MASK_1203
);
607 reg
->iop2drv_doorbell
= MEM_BASE0(ARCMSR_IOP2DRV_DOORBELL_1203
);
608 reg
->iop2drv_doorbell_mask
= MEM_BASE0(ARCMSR_IOP2DRV_DOORBELL_MASK_1203
);
610 reg
->drv2iop_doorbell
= MEM_BASE0(ARCMSR_DRV2IOP_DOORBELL
);
611 reg
->drv2iop_doorbell_mask
= MEM_BASE0(ARCMSR_DRV2IOP_DOORBELL_MASK
);
612 reg
->iop2drv_doorbell
= MEM_BASE0(ARCMSR_IOP2DRV_DOORBELL
);
613 reg
->iop2drv_doorbell_mask
= MEM_BASE0(ARCMSR_IOP2DRV_DOORBELL_MASK
);
615 reg
->message_wbuffer
= MEM_BASE1(ARCMSR_MESSAGE_WBUFFER
);
616 reg
->message_rbuffer
= MEM_BASE1(ARCMSR_MESSAGE_RBUFFER
);
617 reg
->message_rwbuffer
= MEM_BASE1(ARCMSR_MESSAGE_RWBUFFER
);
620 static void arcmsr_hbaD_assign_regAddr(struct AdapterControlBlock
*acb
)
622 struct MessageUnit_D
*reg
= acb
->pmuD
;
624 reg
->chip_id
= MEM_BASE0(ARCMSR_ARC1214_CHIP_ID
);
625 reg
->cpu_mem_config
= MEM_BASE0(ARCMSR_ARC1214_CPU_MEMORY_CONFIGURATION
);
626 reg
->i2o_host_interrupt_mask
= MEM_BASE0(ARCMSR_ARC1214_I2_HOST_INTERRUPT_MASK
);
627 reg
->sample_at_reset
= MEM_BASE0(ARCMSR_ARC1214_SAMPLE_RESET
);
628 reg
->reset_request
= MEM_BASE0(ARCMSR_ARC1214_RESET_REQUEST
);
629 reg
->host_int_status
= MEM_BASE0(ARCMSR_ARC1214_MAIN_INTERRUPT_STATUS
);
630 reg
->pcief0_int_enable
= MEM_BASE0(ARCMSR_ARC1214_PCIE_F0_INTERRUPT_ENABLE
);
631 reg
->inbound_msgaddr0
= MEM_BASE0(ARCMSR_ARC1214_INBOUND_MESSAGE0
);
632 reg
->inbound_msgaddr1
= MEM_BASE0(ARCMSR_ARC1214_INBOUND_MESSAGE1
);
633 reg
->outbound_msgaddr0
= MEM_BASE0(ARCMSR_ARC1214_OUTBOUND_MESSAGE0
);
634 reg
->outbound_msgaddr1
= MEM_BASE0(ARCMSR_ARC1214_OUTBOUND_MESSAGE1
);
635 reg
->inbound_doorbell
= MEM_BASE0(ARCMSR_ARC1214_INBOUND_DOORBELL
);
636 reg
->outbound_doorbell
= MEM_BASE0(ARCMSR_ARC1214_OUTBOUND_DOORBELL
);
637 reg
->outbound_doorbell_enable
= MEM_BASE0(ARCMSR_ARC1214_OUTBOUND_DOORBELL_ENABLE
);
638 reg
->inboundlist_base_low
= MEM_BASE0(ARCMSR_ARC1214_INBOUND_LIST_BASE_LOW
);
639 reg
->inboundlist_base_high
= MEM_BASE0(ARCMSR_ARC1214_INBOUND_LIST_BASE_HIGH
);
640 reg
->inboundlist_write_pointer
= MEM_BASE0(ARCMSR_ARC1214_INBOUND_LIST_WRITE_POINTER
);
641 reg
->outboundlist_base_low
= MEM_BASE0(ARCMSR_ARC1214_OUTBOUND_LIST_BASE_LOW
);
642 reg
->outboundlist_base_high
= MEM_BASE0(ARCMSR_ARC1214_OUTBOUND_LIST_BASE_HIGH
);
643 reg
->outboundlist_copy_pointer
= MEM_BASE0(ARCMSR_ARC1214_OUTBOUND_LIST_COPY_POINTER
);
644 reg
->outboundlist_read_pointer
= MEM_BASE0(ARCMSR_ARC1214_OUTBOUND_LIST_READ_POINTER
);
645 reg
->outboundlist_interrupt_cause
= MEM_BASE0(ARCMSR_ARC1214_OUTBOUND_INTERRUPT_CAUSE
);
646 reg
->outboundlist_interrupt_enable
= MEM_BASE0(ARCMSR_ARC1214_OUTBOUND_INTERRUPT_ENABLE
);
647 reg
->message_wbuffer
= MEM_BASE0(ARCMSR_ARC1214_MESSAGE_WBUFFER
);
648 reg
->message_rbuffer
= MEM_BASE0(ARCMSR_ARC1214_MESSAGE_RBUFFER
);
649 reg
->msgcode_rwbuffer
= MEM_BASE0(ARCMSR_ARC1214_MESSAGE_RWBUFFER
);
652 static void arcmsr_hbaF_assign_regAddr(struct AdapterControlBlock
*acb
)
654 dma_addr_t host_buffer_dma
;
655 struct MessageUnit_F __iomem
*pmuF
;
657 memset(acb
->dma_coherent2
, 0xff, acb
->completeQ_size
);
658 acb
->message_wbuffer
= (uint32_t *)round_up((unsigned long)acb
->dma_coherent2
+
659 acb
->completeQ_size
, 4);
660 acb
->message_rbuffer
= ((void *)acb
->message_wbuffer
) + 0x100;
661 acb
->msgcode_rwbuffer
= ((void *)acb
->message_wbuffer
) + 0x200;
662 memset((void *)acb
->message_wbuffer
, 0, MESG_RW_BUFFER_SIZE
);
663 host_buffer_dma
= round_up(acb
->dma_coherent_handle2
+ acb
->completeQ_size
, 4);
665 /* host buffer low address, bit0:1 all buffer active */
666 writel(lower_32_bits(host_buffer_dma
| 1), &pmuF
->inbound_msgaddr0
);
667 /* host buffer high address */
668 writel(upper_32_bits(host_buffer_dma
), &pmuF
->inbound_msgaddr1
);
669 /* set host buffer physical address */
670 writel(ARCMSR_HBFMU_DOORBELL_SYNC1
, &pmuF
->iobound_doorbell
);
673 static bool arcmsr_alloc_io_queue(struct AdapterControlBlock
*acb
)
677 dma_addr_t dma_coherent_handle
;
678 struct pci_dev
*pdev
= acb
->pdev
;
680 switch (acb
->adapter_type
) {
681 case ACB_ADAPTER_TYPE_B
: {
682 acb
->ioqueue_size
= roundup(sizeof(struct MessageUnit_B
), 32);
683 dma_coherent
= dma_alloc_coherent(&pdev
->dev
, acb
->ioqueue_size
,
684 &dma_coherent_handle
, GFP_KERNEL
);
686 pr_notice("arcmsr%d: DMA allocation failed\n", acb
->host
->host_no
);
689 acb
->dma_coherent_handle2
= dma_coherent_handle
;
690 acb
->dma_coherent2
= dma_coherent
;
691 acb
->pmuB
= (struct MessageUnit_B
*)dma_coherent
;
692 arcmsr_hbaB_assign_regAddr(acb
);
695 case ACB_ADAPTER_TYPE_D
: {
696 acb
->ioqueue_size
= roundup(sizeof(struct MessageUnit_D
), 32);
697 dma_coherent
= dma_alloc_coherent(&pdev
->dev
, acb
->ioqueue_size
,
698 &dma_coherent_handle
, GFP_KERNEL
);
700 pr_notice("arcmsr%d: DMA allocation failed\n", acb
->host
->host_no
);
703 acb
->dma_coherent_handle2
= dma_coherent_handle
;
704 acb
->dma_coherent2
= dma_coherent
;
705 acb
->pmuD
= (struct MessageUnit_D
*)dma_coherent
;
706 arcmsr_hbaD_assign_regAddr(acb
);
709 case ACB_ADAPTER_TYPE_E
: {
710 uint32_t completeQ_size
;
711 completeQ_size
= sizeof(struct deliver_completeQ
) * ARCMSR_MAX_HBE_DONEQUEUE
+ 128;
712 acb
->ioqueue_size
= roundup(completeQ_size
, 32);
713 dma_coherent
= dma_alloc_coherent(&pdev
->dev
, acb
->ioqueue_size
,
714 &dma_coherent_handle
, GFP_KERNEL
);
716 pr_notice("arcmsr%d: DMA allocation failed\n", acb
->host
->host_no
);
719 acb
->dma_coherent_handle2
= dma_coherent_handle
;
720 acb
->dma_coherent2
= dma_coherent
;
721 acb
->pCompletionQ
= dma_coherent
;
722 acb
->completionQ_entry
= acb
->ioqueue_size
/ sizeof(struct deliver_completeQ
);
723 acb
->doneq_index
= 0;
726 case ACB_ADAPTER_TYPE_F
: {
728 uint32_t depthTbl
[] = {256, 512, 1024, 128, 64, 32};
730 arcmsr_wait_firmware_ready(acb
);
731 QueueDepth
= depthTbl
[readl(&acb
->pmuF
->outbound_msgaddr1
) & 7];
732 acb
->completeQ_size
= sizeof(struct deliver_completeQ
) * QueueDepth
+ 128;
733 acb
->ioqueue_size
= roundup(acb
->completeQ_size
+ MESG_RW_BUFFER_SIZE
, 32);
734 dma_coherent
= dma_alloc_coherent(&pdev
->dev
, acb
->ioqueue_size
,
735 &dma_coherent_handle
, GFP_KERNEL
);
737 pr_notice("arcmsr%d: DMA allocation failed\n", acb
->host
->host_no
);
740 acb
->dma_coherent_handle2
= dma_coherent_handle
;
741 acb
->dma_coherent2
= dma_coherent
;
742 acb
->pCompletionQ
= dma_coherent
;
743 acb
->completionQ_entry
= acb
->completeQ_size
/ sizeof(struct deliver_completeQ
);
744 acb
->doneq_index
= 0;
745 arcmsr_hbaF_assign_regAddr(acb
);
754 static int arcmsr_alloc_xor_buffer(struct AdapterControlBlock
*acb
)
757 struct pci_dev
*pdev
= acb
->pdev
;
759 dma_addr_t dma_coherent_handle
;
761 struct Xor_sg
*pXorPhys
;
763 struct HostRamBuf
*pRamBuf
;
765 // allocate 1 MB * N physically continuous memory for XOR engine.
766 xor_ram
= (acb
->firm_PicStatus
>> 24) & 0x0f;
767 acb
->xor_mega
= (xor_ram
- 1) * 32 + 128 + 3;
768 acb
->init2cfg_size
= sizeof(struct HostRamBuf
) +
769 (sizeof(struct XorHandle
) * acb
->xor_mega
);
770 dma_coherent
= dma_alloc_coherent(&pdev
->dev
, acb
->init2cfg_size
,
771 &dma_coherent_handle
, GFP_KERNEL
);
772 acb
->xorVirt
= dma_coherent
;
773 acb
->xorPhys
= dma_coherent_handle
;
774 pXorPhys
= (struct Xor_sg
*)((unsigned long)dma_coherent
+
775 sizeof(struct HostRamBuf
));
776 acb
->xorVirtOffset
= sizeof(struct HostRamBuf
) +
777 (sizeof(struct Xor_sg
) * acb
->xor_mega
);
778 pXorVirt
= (void **)((unsigned long)dma_coherent
+
779 (unsigned long)acb
->xorVirtOffset
);
780 for (i
= 0; i
< acb
->xor_mega
; i
++) {
781 dma_coherent
= dma_alloc_coherent(&pdev
->dev
,
783 &dma_coherent_handle
, GFP_KERNEL
);
785 pXorPhys
->xorPhys
= dma_coherent_handle
;
786 pXorPhys
->xorBufLen
= ARCMSR_XOR_SEG_SIZE
;
787 *pXorVirt
= dma_coherent
;
791 pr_info("arcmsr%d: alloc max XOR buffer = 0x%x MB\n",
792 acb
->host
->host_no
, i
);
797 pRamBuf
= (struct HostRamBuf
*)acb
->xorVirt
;
798 pRamBuf
->hrbSignature
= 0x53425248; //HRBS
799 pRamBuf
->hrbSize
= i
* ARCMSR_XOR_SEG_SIZE
;
800 pRamBuf
->hrbRes
[0] = 0;
801 pRamBuf
->hrbRes
[1] = 0;
805 static int arcmsr_alloc_ccb_pool(struct AdapterControlBlock
*acb
)
807 struct pci_dev
*pdev
= acb
->pdev
;
809 dma_addr_t dma_coherent_handle
;
810 struct CommandControlBlock
*ccb_tmp
;
812 unsigned long cdb_phyaddr
, next_ccb_phy
;
813 unsigned long roundup_ccbsize
;
814 unsigned long max_xfer_len
;
815 unsigned long max_sg_entrys
;
816 uint32_t firm_config_version
, curr_phy_upper32
;
818 for (i
= 0; i
< ARCMSR_MAX_TARGETID
; i
++)
819 for (j
= 0; j
< ARCMSR_MAX_TARGETLUN
; j
++)
820 acb
->devstate
[i
][j
] = ARECA_RAID_GONE
;
822 max_xfer_len
= ARCMSR_MAX_XFER_LEN
;
823 max_sg_entrys
= ARCMSR_DEFAULT_SG_ENTRIES
;
824 firm_config_version
= acb
->firm_cfg_version
;
825 if((firm_config_version
& 0xFF) >= 3){
826 max_xfer_len
= (ARCMSR_CDB_SG_PAGE_LENGTH
<< ((firm_config_version
>> 8) & 0xFF)) * 1024;/* max 4M byte */
827 max_sg_entrys
= (max_xfer_len
/4096);
829 acb
->host
->max_sectors
= max_xfer_len
/512;
830 acb
->host
->sg_tablesize
= max_sg_entrys
;
831 roundup_ccbsize
= roundup(sizeof(struct CommandControlBlock
) + (max_sg_entrys
- 1) * sizeof(struct SG64ENTRY
), 32);
832 acb
->uncache_size
= roundup_ccbsize
* acb
->maxFreeCCB
;
833 if (acb
->adapter_type
!= ACB_ADAPTER_TYPE_F
)
834 acb
->uncache_size
+= acb
->ioqueue_size
;
835 dma_coherent
= dma_alloc_coherent(&pdev
->dev
, acb
->uncache_size
, &dma_coherent_handle
, GFP_KERNEL
);
837 printk(KERN_NOTICE
"arcmsr%d: dma_alloc_coherent got error\n", acb
->host
->host_no
);
840 acb
->dma_coherent
= dma_coherent
;
841 acb
->dma_coherent_handle
= dma_coherent_handle
;
842 memset(dma_coherent
, 0, acb
->uncache_size
);
843 acb
->ccbsize
= roundup_ccbsize
;
844 ccb_tmp
= dma_coherent
;
845 curr_phy_upper32
= upper_32_bits(dma_coherent_handle
);
846 acb
->vir2phy_offset
= (unsigned long)dma_coherent
- (unsigned long)dma_coherent_handle
;
847 for(i
= 0; i
< acb
->maxFreeCCB
; i
++){
848 cdb_phyaddr
= (unsigned long)dma_coherent_handle
+ offsetof(struct CommandControlBlock
, arcmsr_cdb
);
849 switch (acb
->adapter_type
) {
850 case ACB_ADAPTER_TYPE_A
:
851 case ACB_ADAPTER_TYPE_B
:
852 ccb_tmp
->cdb_phyaddr
= cdb_phyaddr
>> 5;
854 case ACB_ADAPTER_TYPE_C
:
855 case ACB_ADAPTER_TYPE_D
:
856 case ACB_ADAPTER_TYPE_E
:
857 case ACB_ADAPTER_TYPE_F
:
858 ccb_tmp
->cdb_phyaddr
= cdb_phyaddr
;
861 acb
->pccb_pool
[i
] = ccb_tmp
;
863 ccb_tmp
->smid
= (u32
)i
<< 16;
864 INIT_LIST_HEAD(&ccb_tmp
->list
);
865 next_ccb_phy
= dma_coherent_handle
+ roundup_ccbsize
;
866 if (upper_32_bits(next_ccb_phy
) != curr_phy_upper32
) {
868 acb
->host
->can_queue
= i
;
872 list_add_tail(&ccb_tmp
->list
, &acb
->ccb_free_list
);
873 ccb_tmp
= (struct CommandControlBlock
*)((unsigned long)ccb_tmp
+ roundup_ccbsize
);
874 dma_coherent_handle
= next_ccb_phy
;
876 if (acb
->adapter_type
!= ACB_ADAPTER_TYPE_F
) {
877 acb
->dma_coherent_handle2
= dma_coherent_handle
;
878 acb
->dma_coherent2
= ccb_tmp
;
880 switch (acb
->adapter_type
) {
881 case ACB_ADAPTER_TYPE_B
:
882 acb
->pmuB
= (struct MessageUnit_B
*)acb
->dma_coherent2
;
883 arcmsr_hbaB_assign_regAddr(acb
);
885 case ACB_ADAPTER_TYPE_D
:
886 acb
->pmuD
= (struct MessageUnit_D
*)acb
->dma_coherent2
;
887 arcmsr_hbaD_assign_regAddr(acb
);
889 case ACB_ADAPTER_TYPE_E
:
890 acb
->pCompletionQ
= acb
->dma_coherent2
;
891 acb
->completionQ_entry
= acb
->ioqueue_size
/ sizeof(struct deliver_completeQ
);
892 acb
->doneq_index
= 0;
895 if ((acb
->firm_PicStatus
>> 24) & 0x0f) {
896 if (arcmsr_alloc_xor_buffer(acb
))
902 static void arcmsr_message_isr_bh_fn(struct work_struct
*work
)
904 struct AdapterControlBlock
*acb
= container_of(work
,
905 struct AdapterControlBlock
, arcmsr_do_message_isr_bh
);
906 char *acb_dev_map
= (char *)acb
->device_map
;
907 uint32_t __iomem
*signature
= NULL
;
908 char __iomem
*devicemap
= NULL
;
910 struct scsi_device
*psdev
;
913 switch (acb
->adapter_type
) {
914 case ACB_ADAPTER_TYPE_A
: {
915 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
917 signature
= (uint32_t __iomem
*)(®
->message_rwbuffer
[0]);
918 devicemap
= (char __iomem
*)(®
->message_rwbuffer
[21]);
921 case ACB_ADAPTER_TYPE_B
: {
922 struct MessageUnit_B
*reg
= acb
->pmuB
;
924 signature
= (uint32_t __iomem
*)(®
->message_rwbuffer
[0]);
925 devicemap
= (char __iomem
*)(®
->message_rwbuffer
[21]);
928 case ACB_ADAPTER_TYPE_C
: {
929 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
931 signature
= (uint32_t __iomem
*)(®
->msgcode_rwbuffer
[0]);
932 devicemap
= (char __iomem
*)(®
->msgcode_rwbuffer
[21]);
935 case ACB_ADAPTER_TYPE_D
: {
936 struct MessageUnit_D
*reg
= acb
->pmuD
;
938 signature
= (uint32_t __iomem
*)(®
->msgcode_rwbuffer
[0]);
939 devicemap
= (char __iomem
*)(®
->msgcode_rwbuffer
[21]);
942 case ACB_ADAPTER_TYPE_E
: {
943 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
945 signature
= (uint32_t __iomem
*)(®
->msgcode_rwbuffer
[0]);
946 devicemap
= (char __iomem
*)(®
->msgcode_rwbuffer
[21]);
949 case ACB_ADAPTER_TYPE_F
: {
950 signature
= (uint32_t __iomem
*)(&acb
->msgcode_rwbuffer
[0]);
951 devicemap
= (char __iomem
*)(&acb
->msgcode_rwbuffer
[21]);
955 if (readl(signature
) != ARCMSR_SIGNATURE_GET_CONFIG
)
957 for (target
= 0; target
< ARCMSR_MAX_TARGETID
- 1;
959 temp
= readb(devicemap
);
960 diff
= (*acb_dev_map
) ^ temp
;
963 for (lun
= 0; lun
< ARCMSR_MAX_TARGETLUN
;
965 if ((diff
& 0x01) == 1 &&
966 (temp
& 0x01) == 1) {
967 scsi_add_device(acb
->host
,
969 } else if ((diff
& 0x01) == 1
970 && (temp
& 0x01) == 0) {
971 psdev
= scsi_device_lookup(acb
->host
,
974 scsi_remove_device(psdev
);
975 scsi_device_put(psdev
);
985 acb
->acb_flags
&= ~ACB_F_MSG_GET_CONFIG
;
989 arcmsr_request_irq(struct pci_dev
*pdev
, struct AdapterControlBlock
*acb
)
994 if (msix_enable
== 0)
996 nvec
= pci_alloc_irq_vectors(pdev
, 1, ARCMST_NUM_MSIX_VECTORS
,
999 pr_info("arcmsr%d: msi-x enabled\n", acb
->host
->host_no
);
1003 if (msi_enable
== 1) {
1004 nvec
= pci_alloc_irq_vectors(pdev
, 1, 1, PCI_IRQ_MSI
);
1006 dev_info(&pdev
->dev
, "msi enabled\n");
1010 nvec
= pci_alloc_irq_vectors(pdev
, 1, 1, PCI_IRQ_INTX
);
1014 flags
= IRQF_SHARED
;
1017 acb
->vector_count
= nvec
;
1018 for (i
= 0; i
< nvec
; i
++) {
1019 if (request_irq(pci_irq_vector(pdev
, i
), arcmsr_do_interrupt
,
1020 flags
, "arcmsr", acb
)) {
1021 pr_warn("arcmsr%d: request_irq =%d failed!\n",
1022 acb
->host
->host_no
, pci_irq_vector(pdev
, i
));
1030 free_irq(pci_irq_vector(pdev
, i
), acb
);
1031 pci_free_irq_vectors(pdev
);
1035 static void arcmsr_init_get_devmap_timer(struct AdapterControlBlock
*pacb
)
1037 INIT_WORK(&pacb
->arcmsr_do_message_isr_bh
, arcmsr_message_isr_bh_fn
);
1038 pacb
->fw_flag
= FW_NORMAL
;
1039 timer_setup(&pacb
->eternal_timer
, arcmsr_request_device_map
, 0);
1040 pacb
->eternal_timer
.expires
= jiffies
+ msecs_to_jiffies(6 * HZ
);
1041 add_timer(&pacb
->eternal_timer
);
1044 static void arcmsr_init_set_datetime_timer(struct AdapterControlBlock
*pacb
)
1046 timer_setup(&pacb
->refresh_timer
, arcmsr_set_iop_datetime
, 0);
1047 pacb
->refresh_timer
.expires
= jiffies
+ msecs_to_jiffies(60 * 1000);
1048 add_timer(&pacb
->refresh_timer
);
1051 static int arcmsr_set_dma_mask(struct AdapterControlBlock
*acb
)
1053 struct pci_dev
*pcidev
= acb
->pdev
;
1056 if (((acb
->adapter_type
== ACB_ADAPTER_TYPE_A
) && !dma_mask_64
) ||
1057 dma_set_mask(&pcidev
->dev
, DMA_BIT_MASK(64)))
1059 if (acb
->adapter_type
<= ACB_ADAPTER_TYPE_B
)
1061 if (dma_set_coherent_mask(&pcidev
->dev
, DMA_BIT_MASK(64)) ||
1062 dma_set_mask_and_coherent(&pcidev
->dev
, DMA_BIT_MASK(64))) {
1063 printk("arcmsr: set DMA 64 mask failed\n");
1068 if (dma_set_mask(&pcidev
->dev
, DMA_BIT_MASK(32)) ||
1069 dma_set_coherent_mask(&pcidev
->dev
, DMA_BIT_MASK(32)) ||
1070 dma_set_mask_and_coherent(&pcidev
->dev
, DMA_BIT_MASK(32))) {
1071 printk("arcmsr: set DMA 32-bit mask failed\n");
1078 static int arcmsr_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1080 struct Scsi_Host
*host
;
1081 struct AdapterControlBlock
*acb
;
1082 uint8_t bus
,dev_fun
;
1084 error
= pci_enable_device(pdev
);
1088 host
= scsi_host_alloc(&arcmsr_scsi_host_template
, sizeof(struct AdapterControlBlock
));
1090 goto pci_disable_dev
;
1092 init_waitqueue_head(&wait_q
);
1093 bus
= pdev
->bus
->number
;
1094 dev_fun
= pdev
->devfn
;
1095 acb
= (struct AdapterControlBlock
*) host
->hostdata
;
1096 memset(acb
,0,sizeof(struct AdapterControlBlock
));
1098 acb
->adapter_type
= id
->driver_data
;
1099 if (arcmsr_set_dma_mask(acb
))
1100 goto scsi_host_release
;
1102 host
->max_lun
= ARCMSR_MAX_TARGETLUN
;
1103 host
->max_id
= ARCMSR_MAX_TARGETID
; /*16:8*/
1104 host
->max_cmd_len
= 16; /*this is issue of 64bit LBA ,over 2T byte*/
1105 if ((host_can_queue
< ARCMSR_MIN_OUTSTANDING_CMD
) || (host_can_queue
> ARCMSR_MAX_OUTSTANDING_CMD
))
1106 host_can_queue
= ARCMSR_DEFAULT_OUTSTANDING_CMD
;
1107 host
->can_queue
= host_can_queue
; /* max simultaneous cmds */
1108 if ((cmd_per_lun
< ARCMSR_MIN_CMD_PERLUN
) || (cmd_per_lun
> ARCMSR_MAX_CMD_PERLUN
))
1109 cmd_per_lun
= ARCMSR_DEFAULT_CMD_PERLUN
;
1110 host
->cmd_per_lun
= cmd_per_lun
;
1111 host
->this_id
= ARCMSR_SCSI_INITIATOR_ID
;
1112 host
->unique_id
= (bus
<< 8) | dev_fun
;
1113 pci_set_drvdata(pdev
, host
);
1114 pci_set_master(pdev
);
1115 error
= pci_request_regions(pdev
, "arcmsr");
1117 goto scsi_host_release
;
1119 spin_lock_init(&acb
->eh_lock
);
1120 spin_lock_init(&acb
->ccblist_lock
);
1121 spin_lock_init(&acb
->postq_lock
);
1122 spin_lock_init(&acb
->doneq_lock
);
1123 spin_lock_init(&acb
->rqbuffer_lock
);
1124 spin_lock_init(&acb
->wqbuffer_lock
);
1125 acb
->acb_flags
|= (ACB_F_MESSAGE_WQBUFFER_CLEARED
|
1126 ACB_F_MESSAGE_RQBUFFER_CLEARED
|
1127 ACB_F_MESSAGE_WQBUFFER_READED
);
1128 acb
->acb_flags
&= ~ACB_F_SCSISTOPADAPTER
;
1129 INIT_LIST_HEAD(&acb
->ccb_free_list
);
1130 error
= arcmsr_remap_pciregion(acb
);
1132 goto pci_release_regs
;
1134 error
= arcmsr_alloc_io_queue(acb
);
1136 goto unmap_pci_region
;
1137 error
= arcmsr_get_firmware_spec(acb
);
1141 if (acb
->adapter_type
!= ACB_ADAPTER_TYPE_F
)
1142 arcmsr_free_io_queue(acb
);
1143 error
= arcmsr_alloc_ccb_pool(acb
);
1145 goto unmap_pci_region
;
1147 error
= scsi_add_host(host
, &pdev
->dev
);
1151 if (arcmsr_request_irq(pdev
, acb
) == FAILED
)
1152 goto scsi_host_remove
;
1153 arcmsr_iop_init(acb
);
1154 arcmsr_init_get_devmap_timer(acb
);
1156 arcmsr_init_set_datetime_timer(acb
);
1157 if(arcmsr_alloc_sysfs_attr(acb
))
1158 goto out_free_sysfs
;
1159 scsi_scan_host(host
);
1163 del_timer_sync(&acb
->refresh_timer
);
1164 del_timer_sync(&acb
->eternal_timer
);
1165 flush_work(&acb
->arcmsr_do_message_isr_bh
);
1166 arcmsr_stop_adapter_bgrb(acb
);
1167 arcmsr_flush_adapter_cache(acb
);
1168 arcmsr_free_irq(pdev
, acb
);
1170 scsi_remove_host(host
);
1172 arcmsr_free_ccb_pool(acb
);
1173 goto unmap_pci_region
;
1175 arcmsr_free_io_queue(acb
);
1177 arcmsr_unmap_pciregion(acb
);
1179 pci_release_regions(pdev
);
1181 scsi_host_put(host
);
1183 pci_disable_device(pdev
);
1187 static void arcmsr_free_irq(struct pci_dev
*pdev
,
1188 struct AdapterControlBlock
*acb
)
1192 for (i
= 0; i
< acb
->vector_count
; i
++)
1193 free_irq(pci_irq_vector(pdev
, i
), acb
);
1194 pci_free_irq_vectors(pdev
);
1197 static int __maybe_unused
arcmsr_suspend(struct device
*dev
)
1199 struct pci_dev
*pdev
= to_pci_dev(dev
);
1200 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
1201 struct AdapterControlBlock
*acb
=
1202 (struct AdapterControlBlock
*)host
->hostdata
;
1204 arcmsr_disable_outbound_ints(acb
);
1205 arcmsr_free_irq(pdev
, acb
);
1206 del_timer_sync(&acb
->eternal_timer
);
1208 del_timer_sync(&acb
->refresh_timer
);
1209 flush_work(&acb
->arcmsr_do_message_isr_bh
);
1210 arcmsr_stop_adapter_bgrb(acb
);
1211 arcmsr_flush_adapter_cache(acb
);
1215 static int __maybe_unused
arcmsr_resume(struct device
*dev
)
1217 struct pci_dev
*pdev
= to_pci_dev(dev
);
1218 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
1219 struct AdapterControlBlock
*acb
=
1220 (struct AdapterControlBlock
*)host
->hostdata
;
1222 if (arcmsr_set_dma_mask(acb
))
1223 goto controller_unregister
;
1224 if (arcmsr_request_irq(pdev
, acb
) == FAILED
)
1225 goto controller_stop
;
1226 switch (acb
->adapter_type
) {
1227 case ACB_ADAPTER_TYPE_B
: {
1228 struct MessageUnit_B
*reg
= acb
->pmuB
;
1230 for (i
= 0; i
< ARCMSR_MAX_HBB_POSTQUEUE
; i
++) {
1231 reg
->post_qbuffer
[i
] = 0;
1232 reg
->done_qbuffer
[i
] = 0;
1234 reg
->postq_index
= 0;
1235 reg
->doneq_index
= 0;
1238 case ACB_ADAPTER_TYPE_E
:
1239 writel(0, &acb
->pmuE
->host_int_status
);
1240 writel(ARCMSR_HBEMU_DOORBELL_SYNC
, &acb
->pmuE
->iobound_doorbell
);
1241 acb
->in_doorbell
= 0;
1242 acb
->out_doorbell
= 0;
1243 acb
->doneq_index
= 0;
1245 case ACB_ADAPTER_TYPE_F
:
1246 writel(0, &acb
->pmuF
->host_int_status
);
1247 writel(ARCMSR_HBFMU_DOORBELL_SYNC
, &acb
->pmuF
->iobound_doorbell
);
1248 acb
->in_doorbell
= 0;
1249 acb
->out_doorbell
= 0;
1250 acb
->doneq_index
= 0;
1251 arcmsr_hbaF_assign_regAddr(acb
);
1254 arcmsr_iop_init(acb
);
1255 arcmsr_init_get_devmap_timer(acb
);
1257 arcmsr_init_set_datetime_timer(acb
);
1260 arcmsr_stop_adapter_bgrb(acb
);
1261 arcmsr_flush_adapter_cache(acb
);
1262 controller_unregister
:
1263 scsi_remove_host(host
);
1264 arcmsr_free_ccb_pool(acb
);
1265 if (acb
->adapter_type
== ACB_ADAPTER_TYPE_F
)
1266 arcmsr_free_io_queue(acb
);
1267 arcmsr_unmap_pciregion(acb
);
1268 scsi_host_put(host
);
1272 static uint8_t arcmsr_hbaA_abort_allcmd(struct AdapterControlBlock
*acb
)
1274 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1275 writel(ARCMSR_INBOUND_MESG0_ABORT_CMD
, ®
->inbound_msgaddr0
);
1276 if (!arcmsr_hbaA_wait_msgint_ready(acb
)) {
1278 "arcmsr%d: wait 'abort all outstanding command' timeout\n"
1279 , acb
->host
->host_no
);
1285 static uint8_t arcmsr_hbaB_abort_allcmd(struct AdapterControlBlock
*acb
)
1287 struct MessageUnit_B
*reg
= acb
->pmuB
;
1289 writel(ARCMSR_MESSAGE_ABORT_CMD
, reg
->drv2iop_doorbell
);
1290 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
1292 "arcmsr%d: wait 'abort all outstanding command' timeout\n"
1293 , acb
->host
->host_no
);
1298 static uint8_t arcmsr_hbaC_abort_allcmd(struct AdapterControlBlock
*pACB
)
1300 struct MessageUnit_C __iomem
*reg
= pACB
->pmuC
;
1301 writel(ARCMSR_INBOUND_MESG0_ABORT_CMD
, ®
->inbound_msgaddr0
);
1302 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
1303 if (!arcmsr_hbaC_wait_msgint_ready(pACB
)) {
1305 "arcmsr%d: wait 'abort all outstanding command' timeout\n"
1306 , pACB
->host
->host_no
);
1312 static uint8_t arcmsr_hbaD_abort_allcmd(struct AdapterControlBlock
*pACB
)
1314 struct MessageUnit_D
*reg
= pACB
->pmuD
;
1316 writel(ARCMSR_INBOUND_MESG0_ABORT_CMD
, reg
->inbound_msgaddr0
);
1317 if (!arcmsr_hbaD_wait_msgint_ready(pACB
)) {
1318 pr_notice("arcmsr%d: wait 'abort all outstanding "
1319 "command' timeout\n", pACB
->host
->host_no
);
1325 static uint8_t arcmsr_hbaE_abort_allcmd(struct AdapterControlBlock
*pACB
)
1327 struct MessageUnit_E __iomem
*reg
= pACB
->pmuE
;
1329 writel(ARCMSR_INBOUND_MESG0_ABORT_CMD
, ®
->inbound_msgaddr0
);
1330 pACB
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_MESSAGE_CMD_DONE
;
1331 writel(pACB
->out_doorbell
, ®
->iobound_doorbell
);
1332 if (!arcmsr_hbaE_wait_msgint_ready(pACB
)) {
1333 pr_notice("arcmsr%d: wait 'abort all outstanding "
1334 "command' timeout\n", pACB
->host
->host_no
);
1340 static uint8_t arcmsr_abort_allcmd(struct AdapterControlBlock
*acb
)
1343 switch (acb
->adapter_type
) {
1344 case ACB_ADAPTER_TYPE_A
:
1345 rtnval
= arcmsr_hbaA_abort_allcmd(acb
);
1347 case ACB_ADAPTER_TYPE_B
:
1348 rtnval
= arcmsr_hbaB_abort_allcmd(acb
);
1350 case ACB_ADAPTER_TYPE_C
:
1351 rtnval
= arcmsr_hbaC_abort_allcmd(acb
);
1353 case ACB_ADAPTER_TYPE_D
:
1354 rtnval
= arcmsr_hbaD_abort_allcmd(acb
);
1356 case ACB_ADAPTER_TYPE_E
:
1357 case ACB_ADAPTER_TYPE_F
:
1358 rtnval
= arcmsr_hbaE_abort_allcmd(acb
);
1364 static void arcmsr_ccb_complete(struct CommandControlBlock
*ccb
)
1366 struct AdapterControlBlock
*acb
= ccb
->acb
;
1367 struct scsi_cmnd
*pcmd
= ccb
->pcmd
;
1368 unsigned long flags
;
1369 atomic_dec(&acb
->ccboutstandingcount
);
1370 scsi_dma_unmap(ccb
->pcmd
);
1371 ccb
->startdone
= ARCMSR_CCB_DONE
;
1372 spin_lock_irqsave(&acb
->ccblist_lock
, flags
);
1373 list_add_tail(&ccb
->list
, &acb
->ccb_free_list
);
1374 spin_unlock_irqrestore(&acb
->ccblist_lock
, flags
);
1378 static void arcmsr_report_sense_info(struct CommandControlBlock
*ccb
)
1380 struct scsi_cmnd
*pcmd
= ccb
->pcmd
;
1382 pcmd
->result
= (DID_OK
<< 16) | SAM_STAT_CHECK_CONDITION
;
1383 if (pcmd
->sense_buffer
) {
1384 struct SENSE_DATA
*sensebuffer
;
1386 memcpy_and_pad(pcmd
->sense_buffer
,
1387 SCSI_SENSE_BUFFERSIZE
,
1388 ccb
->arcmsr_cdb
.SenseData
,
1389 sizeof(ccb
->arcmsr_cdb
.SenseData
),
1392 sensebuffer
= (struct SENSE_DATA
*)pcmd
->sense_buffer
;
1393 sensebuffer
->ErrorCode
= SCSI_SENSE_CURRENT_ERRORS
;
1394 sensebuffer
->Valid
= 1;
1398 static u32
arcmsr_disable_outbound_ints(struct AdapterControlBlock
*acb
)
1401 switch (acb
->adapter_type
) {
1402 case ACB_ADAPTER_TYPE_A
: {
1403 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1404 orig_mask
= readl(®
->outbound_intmask
);
1405 writel(orig_mask
|ARCMSR_MU_OUTBOUND_ALL_INTMASKENABLE
, \
1406 ®
->outbound_intmask
);
1409 case ACB_ADAPTER_TYPE_B
: {
1410 struct MessageUnit_B
*reg
= acb
->pmuB
;
1411 orig_mask
= readl(reg
->iop2drv_doorbell_mask
);
1412 writel(0, reg
->iop2drv_doorbell_mask
);
1415 case ACB_ADAPTER_TYPE_C
:{
1416 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
1417 /* disable all outbound interrupt */
1418 orig_mask
= readl(®
->host_int_mask
); /* disable outbound message0 int */
1419 writel(orig_mask
|ARCMSR_HBCMU_ALL_INTMASKENABLE
, ®
->host_int_mask
);
1422 case ACB_ADAPTER_TYPE_D
: {
1423 struct MessageUnit_D
*reg
= acb
->pmuD
;
1424 /* disable all outbound interrupt */
1425 writel(ARCMSR_ARC1214_ALL_INT_DISABLE
, reg
->pcief0_int_enable
);
1428 case ACB_ADAPTER_TYPE_E
:
1429 case ACB_ADAPTER_TYPE_F
: {
1430 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
1431 orig_mask
= readl(®
->host_int_mask
);
1432 writel(orig_mask
| ARCMSR_HBEMU_OUTBOUND_DOORBELL_ISR
| ARCMSR_HBEMU_OUTBOUND_POSTQUEUE_ISR
, ®
->host_int_mask
);
1433 readl(®
->host_int_mask
); /* Dummy readl to force pci flush */
1440 static void arcmsr_report_ccb_state(struct AdapterControlBlock
*acb
,
1441 struct CommandControlBlock
*ccb
, bool error
)
1444 id
= ccb
->pcmd
->device
->id
;
1445 lun
= ccb
->pcmd
->device
->lun
;
1447 if (acb
->devstate
[id
][lun
] == ARECA_RAID_GONE
)
1448 acb
->devstate
[id
][lun
] = ARECA_RAID_GOOD
;
1449 ccb
->pcmd
->result
= DID_OK
<< 16;
1450 arcmsr_ccb_complete(ccb
);
1452 switch (ccb
->arcmsr_cdb
.DeviceStatus
) {
1453 case ARCMSR_DEV_SELECT_TIMEOUT
: {
1454 acb
->devstate
[id
][lun
] = ARECA_RAID_GONE
;
1455 ccb
->pcmd
->result
= DID_NO_CONNECT
<< 16;
1456 arcmsr_ccb_complete(ccb
);
1460 case ARCMSR_DEV_ABORTED
:
1462 case ARCMSR_DEV_INIT_FAIL
: {
1463 acb
->devstate
[id
][lun
] = ARECA_RAID_GONE
;
1464 ccb
->pcmd
->result
= DID_BAD_TARGET
<< 16;
1465 arcmsr_ccb_complete(ccb
);
1469 case ARCMSR_DEV_CHECK_CONDITION
: {
1470 acb
->devstate
[id
][lun
] = ARECA_RAID_GOOD
;
1471 arcmsr_report_sense_info(ccb
);
1472 arcmsr_ccb_complete(ccb
);
1478 "arcmsr%d: scsi id = %d lun = %d isr get command error done, \
1479 but got unknown DeviceStatus = 0x%x \n"
1480 , acb
->host
->host_no
1483 , ccb
->arcmsr_cdb
.DeviceStatus
);
1484 acb
->devstate
[id
][lun
] = ARECA_RAID_GONE
;
1485 ccb
->pcmd
->result
= DID_NO_CONNECT
<< 16;
1486 arcmsr_ccb_complete(ccb
);
1492 static void arcmsr_drain_donequeue(struct AdapterControlBlock
*acb
, struct CommandControlBlock
*pCCB
, bool error
)
1494 if ((pCCB
->acb
!= acb
) || (pCCB
->startdone
!= ARCMSR_CCB_START
)) {
1495 if (pCCB
->startdone
== ARCMSR_CCB_ABORTED
) {
1496 struct scsi_cmnd
*abortcmd
= pCCB
->pcmd
;
1498 abortcmd
->result
|= DID_ABORT
<< 16;
1499 arcmsr_ccb_complete(pCCB
);
1500 printk(KERN_NOTICE
"arcmsr%d: pCCB ='0x%p' isr got aborted command \n",
1501 acb
->host
->host_no
, pCCB
);
1505 printk(KERN_NOTICE
"arcmsr%d: isr get an illegal ccb command \
1507 "ccb = '0x%p' ccbacb = '0x%p' startdone = 0x%x"
1508 " ccboutstandingcount = %d \n"
1509 , acb
->host
->host_no
1514 , atomic_read(&acb
->ccboutstandingcount
));
1517 arcmsr_report_ccb_state(acb
, pCCB
, error
);
1520 static void arcmsr_done4abort_postqueue(struct AdapterControlBlock
*acb
)
1524 struct ARCMSR_CDB
*pARCMSR_CDB
;
1526 struct CommandControlBlock
*pCCB
;
1527 unsigned long ccb_cdb_phy
;
1529 switch (acb
->adapter_type
) {
1531 case ACB_ADAPTER_TYPE_A
: {
1532 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1533 uint32_t outbound_intstatus
;
1534 outbound_intstatus
= readl(®
->outbound_intstatus
) &
1535 acb
->outbound_int_enable
;
1536 /*clear and abort all outbound posted Q*/
1537 writel(outbound_intstatus
, ®
->outbound_intstatus
);/*clear interrupt*/
1538 while(((flag_ccb
= readl(®
->outbound_queueport
)) != 0xFFFFFFFF)
1539 && (i
++ < acb
->maxOutstanding
)) {
1540 ccb_cdb_phy
= (flag_ccb
<< 5) & 0xffffffff;
1541 if (acb
->cdb_phyadd_hipart
)
1542 ccb_cdb_phy
= ccb_cdb_phy
| acb
->cdb_phyadd_hipart
;
1543 pARCMSR_CDB
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ ccb_cdb_phy
);
1544 pCCB
= container_of(pARCMSR_CDB
, struct CommandControlBlock
, arcmsr_cdb
);
1545 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
1546 arcmsr_drain_donequeue(acb
, pCCB
, error
);
1551 case ACB_ADAPTER_TYPE_B
: {
1552 struct MessageUnit_B
*reg
= acb
->pmuB
;
1553 /*clear all outbound posted Q*/
1554 writel(ARCMSR_DOORBELL_INT_CLEAR_PATTERN
, reg
->iop2drv_doorbell
); /* clear doorbell interrupt */
1555 for (i
= 0; i
< ARCMSR_MAX_HBB_POSTQUEUE
; i
++) {
1556 flag_ccb
= reg
->done_qbuffer
[i
];
1557 if (flag_ccb
!= 0) {
1558 reg
->done_qbuffer
[i
] = 0;
1559 ccb_cdb_phy
= (flag_ccb
<< 5) & 0xffffffff;
1560 if (acb
->cdb_phyadd_hipart
)
1561 ccb_cdb_phy
= ccb_cdb_phy
| acb
->cdb_phyadd_hipart
;
1562 pARCMSR_CDB
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ ccb_cdb_phy
);
1563 pCCB
= container_of(pARCMSR_CDB
, struct CommandControlBlock
, arcmsr_cdb
);
1564 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
1565 arcmsr_drain_donequeue(acb
, pCCB
, error
);
1567 reg
->post_qbuffer
[i
] = 0;
1569 reg
->doneq_index
= 0;
1570 reg
->postq_index
= 0;
1573 case ACB_ADAPTER_TYPE_C
: {
1574 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
1575 while ((readl(®
->host_int_status
) & ARCMSR_HBCMU_OUTBOUND_POSTQUEUE_ISR
) && (i
++ < acb
->maxOutstanding
)) {
1577 flag_ccb
= readl(®
->outbound_queueport_low
);
1578 ccb_cdb_phy
= (flag_ccb
& 0xFFFFFFF0);
1579 if (acb
->cdb_phyadd_hipart
)
1580 ccb_cdb_phy
= ccb_cdb_phy
| acb
->cdb_phyadd_hipart
;
1581 pARCMSR_CDB
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ ccb_cdb_phy
);
1582 pCCB
= container_of(pARCMSR_CDB
, struct CommandControlBlock
, arcmsr_cdb
);
1583 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
) ? true : false;
1584 arcmsr_drain_donequeue(acb
, pCCB
, error
);
1588 case ACB_ADAPTER_TYPE_D
: {
1589 struct MessageUnit_D
*pmu
= acb
->pmuD
;
1590 uint32_t outbound_write_pointer
;
1591 uint32_t doneq_index
, index_stripped
, addressLow
, residual
, toggle
;
1592 unsigned long flags
;
1594 residual
= atomic_read(&acb
->ccboutstandingcount
);
1595 for (i
= 0; i
< residual
; i
++) {
1596 spin_lock_irqsave(&acb
->doneq_lock
, flags
);
1597 outbound_write_pointer
=
1598 pmu
->done_qbuffer
[0].addressLow
+ 1;
1599 doneq_index
= pmu
->doneq_index
;
1600 if ((doneq_index
& 0xFFF) !=
1601 (outbound_write_pointer
& 0xFFF)) {
1602 toggle
= doneq_index
& 0x4000;
1603 index_stripped
= (doneq_index
& 0xFFF) + 1;
1604 index_stripped
%= ARCMSR_MAX_ARC1214_DONEQUEUE
;
1605 pmu
->doneq_index
= index_stripped
? (index_stripped
| toggle
) :
1606 ((toggle
^ 0x4000) + 1);
1607 doneq_index
= pmu
->doneq_index
;
1608 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
1609 addressLow
= pmu
->done_qbuffer
[doneq_index
&
1611 ccb_cdb_phy
= (addressLow
& 0xFFFFFFF0);
1612 if (acb
->cdb_phyadd_hipart
)
1613 ccb_cdb_phy
= ccb_cdb_phy
| acb
->cdb_phyadd_hipart
;
1614 pARCMSR_CDB
= (struct ARCMSR_CDB
*)
1615 (acb
->vir2phy_offset
+ ccb_cdb_phy
);
1616 pCCB
= container_of(pARCMSR_CDB
,
1617 struct CommandControlBlock
, arcmsr_cdb
);
1618 error
= (addressLow
&
1619 ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
) ?
1621 arcmsr_drain_donequeue(acb
, pCCB
, error
);
1623 pmu
->outboundlist_read_pointer
);
1625 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
1629 pmu
->postq_index
= 0;
1630 pmu
->doneq_index
= 0x40FF;
1633 case ACB_ADAPTER_TYPE_E
:
1634 arcmsr_hbaE_postqueue_isr(acb
);
1636 case ACB_ADAPTER_TYPE_F
:
1637 arcmsr_hbaF_postqueue_isr(acb
);
1642 static void arcmsr_remove_scsi_devices(struct AdapterControlBlock
*acb
)
1644 char *acb_dev_map
= (char *)acb
->device_map
;
1646 struct scsi_device
*psdev
;
1647 struct CommandControlBlock
*ccb
;
1650 for (i
= 0; i
< acb
->maxFreeCCB
; i
++) {
1651 ccb
= acb
->pccb_pool
[i
];
1652 if (ccb
->startdone
== ARCMSR_CCB_START
) {
1653 ccb
->pcmd
->result
= DID_NO_CONNECT
<< 16;
1654 scsi_dma_unmap(ccb
->pcmd
);
1655 scsi_done(ccb
->pcmd
);
1658 for (target
= 0; target
< ARCMSR_MAX_TARGETID
; target
++) {
1659 temp
= *acb_dev_map
;
1661 for (lun
= 0; lun
< ARCMSR_MAX_TARGETLUN
; lun
++) {
1663 psdev
= scsi_device_lookup(acb
->host
,
1665 if (psdev
!= NULL
) {
1666 scsi_remove_device(psdev
);
1667 scsi_device_put(psdev
);
1678 static void arcmsr_free_pcidev(struct AdapterControlBlock
*acb
)
1680 struct pci_dev
*pdev
;
1681 struct Scsi_Host
*host
;
1684 arcmsr_free_sysfs_attr(acb
);
1685 scsi_remove_host(host
);
1686 flush_work(&acb
->arcmsr_do_message_isr_bh
);
1687 del_timer_sync(&acb
->eternal_timer
);
1689 del_timer_sync(&acb
->refresh_timer
);
1691 arcmsr_free_irq(pdev
, acb
);
1692 arcmsr_free_ccb_pool(acb
);
1693 if (acb
->adapter_type
== ACB_ADAPTER_TYPE_F
)
1694 arcmsr_free_io_queue(acb
);
1695 arcmsr_unmap_pciregion(acb
);
1696 pci_release_regions(pdev
);
1697 scsi_host_put(host
);
1698 pci_disable_device(pdev
);
1701 static void arcmsr_remove(struct pci_dev
*pdev
)
1703 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
1704 struct AdapterControlBlock
*acb
=
1705 (struct AdapterControlBlock
*) host
->hostdata
;
1709 pci_read_config_word(pdev
, PCI_DEVICE_ID
, &dev_id
);
1710 if (dev_id
== 0xffff) {
1711 acb
->acb_flags
&= ~ACB_F_IOP_INITED
;
1712 acb
->acb_flags
|= ACB_F_ADAPTER_REMOVED
;
1713 arcmsr_remove_scsi_devices(acb
);
1714 arcmsr_free_pcidev(acb
);
1717 arcmsr_free_sysfs_attr(acb
);
1718 scsi_remove_host(host
);
1719 flush_work(&acb
->arcmsr_do_message_isr_bh
);
1720 del_timer_sync(&acb
->eternal_timer
);
1722 del_timer_sync(&acb
->refresh_timer
);
1723 arcmsr_disable_outbound_ints(acb
);
1724 arcmsr_stop_adapter_bgrb(acb
);
1725 arcmsr_flush_adapter_cache(acb
);
1726 acb
->acb_flags
|= ACB_F_SCSISTOPADAPTER
;
1727 acb
->acb_flags
&= ~ACB_F_IOP_INITED
;
1729 for (poll_count
= 0; poll_count
< acb
->maxOutstanding
; poll_count
++){
1730 if (!atomic_read(&acb
->ccboutstandingcount
))
1732 arcmsr_interrupt(acb
);/* FIXME: need spinlock */
1736 if (atomic_read(&acb
->ccboutstandingcount
)) {
1739 arcmsr_abort_allcmd(acb
);
1740 arcmsr_done4abort_postqueue(acb
);
1741 for (i
= 0; i
< acb
->maxFreeCCB
; i
++) {
1742 struct CommandControlBlock
*ccb
= acb
->pccb_pool
[i
];
1743 if (ccb
->startdone
== ARCMSR_CCB_START
) {
1744 ccb
->startdone
= ARCMSR_CCB_ABORTED
;
1745 ccb
->pcmd
->result
= DID_ABORT
<< 16;
1746 arcmsr_ccb_complete(ccb
);
1750 arcmsr_free_irq(pdev
, acb
);
1751 arcmsr_free_ccb_pool(acb
);
1752 if (acb
->adapter_type
== ACB_ADAPTER_TYPE_F
)
1753 arcmsr_free_io_queue(acb
);
1754 arcmsr_unmap_pciregion(acb
);
1755 pci_release_regions(pdev
);
1756 scsi_host_put(host
);
1757 pci_disable_device(pdev
);
1760 static void arcmsr_shutdown(struct pci_dev
*pdev
)
1762 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
1763 struct AdapterControlBlock
*acb
=
1764 (struct AdapterControlBlock
*)host
->hostdata
;
1765 if (acb
->acb_flags
& ACB_F_ADAPTER_REMOVED
)
1767 del_timer_sync(&acb
->eternal_timer
);
1769 del_timer_sync(&acb
->refresh_timer
);
1770 arcmsr_disable_outbound_ints(acb
);
1771 arcmsr_free_irq(pdev
, acb
);
1772 flush_work(&acb
->arcmsr_do_message_isr_bh
);
1773 arcmsr_stop_adapter_bgrb(acb
);
1774 arcmsr_flush_adapter_cache(acb
);
1777 static int __init
arcmsr_module_init(void)
1780 error
= pci_register_driver(&arcmsr_pci_driver
);
1784 static void __exit
arcmsr_module_exit(void)
1786 pci_unregister_driver(&arcmsr_pci_driver
);
1788 module_init(arcmsr_module_init
);
1789 module_exit(arcmsr_module_exit
);
1791 static void arcmsr_enable_outbound_ints(struct AdapterControlBlock
*acb
,
1795 switch (acb
->adapter_type
) {
1797 case ACB_ADAPTER_TYPE_A
: {
1798 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1799 mask
= intmask_org
& ~(ARCMSR_MU_OUTBOUND_POSTQUEUE_INTMASKENABLE
|
1800 ARCMSR_MU_OUTBOUND_DOORBELL_INTMASKENABLE
|
1801 ARCMSR_MU_OUTBOUND_MESSAGE0_INTMASKENABLE
);
1802 writel(mask
, ®
->outbound_intmask
);
1803 acb
->outbound_int_enable
= ~(intmask_org
& mask
) & 0x000000ff;
1807 case ACB_ADAPTER_TYPE_B
: {
1808 struct MessageUnit_B
*reg
= acb
->pmuB
;
1809 mask
= intmask_org
| (ARCMSR_IOP2DRV_DATA_WRITE_OK
|
1810 ARCMSR_IOP2DRV_DATA_READ_OK
|
1811 ARCMSR_IOP2DRV_CDB_DONE
|
1812 ARCMSR_IOP2DRV_MESSAGE_CMD_DONE
);
1813 writel(mask
, reg
->iop2drv_doorbell_mask
);
1814 acb
->outbound_int_enable
= (intmask_org
| mask
) & 0x0000000f;
1817 case ACB_ADAPTER_TYPE_C
: {
1818 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
1819 mask
= ~(ARCMSR_HBCMU_UTILITY_A_ISR_MASK
| ARCMSR_HBCMU_OUTBOUND_DOORBELL_ISR_MASK
|ARCMSR_HBCMU_OUTBOUND_POSTQUEUE_ISR_MASK
);
1820 writel(intmask_org
& mask
, ®
->host_int_mask
);
1821 acb
->outbound_int_enable
= ~(intmask_org
& mask
) & 0x0000000f;
1824 case ACB_ADAPTER_TYPE_D
: {
1825 struct MessageUnit_D
*reg
= acb
->pmuD
;
1827 mask
= ARCMSR_ARC1214_ALL_INT_ENABLE
;
1828 writel(intmask_org
| mask
, reg
->pcief0_int_enable
);
1831 case ACB_ADAPTER_TYPE_E
:
1832 case ACB_ADAPTER_TYPE_F
: {
1833 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
1835 mask
= ~(ARCMSR_HBEMU_OUTBOUND_DOORBELL_ISR
| ARCMSR_HBEMU_OUTBOUND_POSTQUEUE_ISR
);
1836 writel(intmask_org
& mask
, ®
->host_int_mask
);
1842 static int arcmsr_build_ccb(struct AdapterControlBlock
*acb
,
1843 struct CommandControlBlock
*ccb
, struct scsi_cmnd
*pcmd
)
1845 struct ARCMSR_CDB
*arcmsr_cdb
= (struct ARCMSR_CDB
*)&ccb
->arcmsr_cdb
;
1846 int8_t *psge
= (int8_t *)&arcmsr_cdb
->u
;
1847 __le32 address_lo
, address_hi
;
1848 int arccdbsize
= 0x30;
1851 struct scatterlist
*sg
;
1854 memset(arcmsr_cdb
, 0, sizeof(struct ARCMSR_CDB
));
1855 arcmsr_cdb
->TargetID
= pcmd
->device
->id
;
1856 arcmsr_cdb
->LUN
= pcmd
->device
->lun
;
1857 arcmsr_cdb
->Function
= 1;
1858 arcmsr_cdb
->msgContext
= 0;
1859 memcpy(arcmsr_cdb
->Cdb
, pcmd
->cmnd
, pcmd
->cmd_len
);
1861 nseg
= scsi_dma_map(pcmd
);
1862 if (unlikely(nseg
> acb
->host
->sg_tablesize
|| nseg
< 0))
1864 scsi_for_each_sg(pcmd
, sg
, nseg
, i
) {
1865 /* Get the physical address of the current data pointer */
1866 length
= cpu_to_le32(sg_dma_len(sg
));
1867 address_lo
= cpu_to_le32(dma_addr_lo32(sg_dma_address(sg
)));
1868 address_hi
= cpu_to_le32(dma_addr_hi32(sg_dma_address(sg
)));
1869 if (address_hi
== 0) {
1870 struct SG32ENTRY
*pdma_sg
= (struct SG32ENTRY
*)psge
;
1872 pdma_sg
->address
= address_lo
;
1873 pdma_sg
->length
= length
;
1874 psge
+= sizeof (struct SG32ENTRY
);
1875 arccdbsize
+= sizeof (struct SG32ENTRY
);
1877 struct SG64ENTRY
*pdma_sg
= (struct SG64ENTRY
*)psge
;
1879 pdma_sg
->addresshigh
= address_hi
;
1880 pdma_sg
->address
= address_lo
;
1881 pdma_sg
->length
= length
|cpu_to_le32(IS_SG64_ADDR
);
1882 psge
+= sizeof (struct SG64ENTRY
);
1883 arccdbsize
+= sizeof (struct SG64ENTRY
);
1886 arcmsr_cdb
->sgcount
= (uint8_t)nseg
;
1887 arcmsr_cdb
->DataLength
= scsi_bufflen(pcmd
);
1888 arcmsr_cdb
->msgPages
= arccdbsize
/0x100 + (arccdbsize
% 0x100 ? 1 : 0);
1889 if ( arccdbsize
> 256)
1890 arcmsr_cdb
->Flags
|= ARCMSR_CDB_FLAG_SGL_BSIZE
;
1891 if (pcmd
->sc_data_direction
== DMA_TO_DEVICE
)
1892 arcmsr_cdb
->Flags
|= ARCMSR_CDB_FLAG_WRITE
;
1893 ccb
->arc_cdb_size
= arccdbsize
;
1897 static void arcmsr_post_ccb(struct AdapterControlBlock
*acb
, struct CommandControlBlock
*ccb
)
1899 uint32_t cdb_phyaddr
= ccb
->cdb_phyaddr
;
1900 struct ARCMSR_CDB
*arcmsr_cdb
= (struct ARCMSR_CDB
*)&ccb
->arcmsr_cdb
;
1901 atomic_inc(&acb
->ccboutstandingcount
);
1902 ccb
->startdone
= ARCMSR_CCB_START
;
1903 switch (acb
->adapter_type
) {
1904 case ACB_ADAPTER_TYPE_A
: {
1905 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1907 if (arcmsr_cdb
->Flags
& ARCMSR_CDB_FLAG_SGL_BSIZE
)
1908 writel(cdb_phyaddr
| ARCMSR_CCBPOST_FLAG_SGL_BSIZE
,
1909 ®
->inbound_queueport
);
1911 writel(cdb_phyaddr
, ®
->inbound_queueport
);
1915 case ACB_ADAPTER_TYPE_B
: {
1916 struct MessageUnit_B
*reg
= acb
->pmuB
;
1917 uint32_t ending_index
, index
= reg
->postq_index
;
1919 ending_index
= ((index
+ 1) % ARCMSR_MAX_HBB_POSTQUEUE
);
1920 reg
->post_qbuffer
[ending_index
] = 0;
1921 if (arcmsr_cdb
->Flags
& ARCMSR_CDB_FLAG_SGL_BSIZE
) {
1922 reg
->post_qbuffer
[index
] =
1923 cdb_phyaddr
| ARCMSR_CCBPOST_FLAG_SGL_BSIZE
;
1925 reg
->post_qbuffer
[index
] = cdb_phyaddr
;
1928 index
%= ARCMSR_MAX_HBB_POSTQUEUE
;/*if last index number set it to 0 */
1929 reg
->postq_index
= index
;
1930 writel(ARCMSR_DRV2IOP_CDB_POSTED
, reg
->drv2iop_doorbell
);
1933 case ACB_ADAPTER_TYPE_C
: {
1934 struct MessageUnit_C __iomem
*phbcmu
= acb
->pmuC
;
1935 uint32_t ccb_post_stamp
, arc_cdb_size
;
1937 arc_cdb_size
= (ccb
->arc_cdb_size
> 0x300) ? 0x300 : ccb
->arc_cdb_size
;
1938 ccb_post_stamp
= (cdb_phyaddr
| ((arc_cdb_size
- 1) >> 6) | 1);
1939 writel(upper_32_bits(ccb
->cdb_phyaddr
), &phbcmu
->inbound_queueport_high
);
1940 writel(ccb_post_stamp
, &phbcmu
->inbound_queueport_low
);
1943 case ACB_ADAPTER_TYPE_D
: {
1944 struct MessageUnit_D
*pmu
= acb
->pmuD
;
1946 u16 postq_index
, toggle
;
1947 unsigned long flags
;
1948 struct InBound_SRB
*pinbound_srb
;
1950 spin_lock_irqsave(&acb
->postq_lock
, flags
);
1951 postq_index
= pmu
->postq_index
;
1952 pinbound_srb
= (struct InBound_SRB
*)&(pmu
->post_qbuffer
[postq_index
& 0xFF]);
1953 pinbound_srb
->addressHigh
= upper_32_bits(ccb
->cdb_phyaddr
);
1954 pinbound_srb
->addressLow
= cdb_phyaddr
;
1955 pinbound_srb
->length
= ccb
->arc_cdb_size
>> 2;
1956 arcmsr_cdb
->msgContext
= dma_addr_lo32(cdb_phyaddr
);
1957 toggle
= postq_index
& 0x4000;
1958 index_stripped
= postq_index
+ 1;
1959 index_stripped
&= (ARCMSR_MAX_ARC1214_POSTQUEUE
- 1);
1960 pmu
->postq_index
= index_stripped
? (index_stripped
| toggle
) :
1962 writel(postq_index
, pmu
->inboundlist_write_pointer
);
1963 spin_unlock_irqrestore(&acb
->postq_lock
, flags
);
1966 case ACB_ADAPTER_TYPE_E
: {
1967 struct MessageUnit_E __iomem
*pmu
= acb
->pmuE
;
1968 u32 ccb_post_stamp
, arc_cdb_size
;
1970 arc_cdb_size
= (ccb
->arc_cdb_size
> 0x300) ? 0x300 : ccb
->arc_cdb_size
;
1971 ccb_post_stamp
= (ccb
->smid
| ((arc_cdb_size
- 1) >> 6));
1972 writel(0, &pmu
->inbound_queueport_high
);
1973 writel(ccb_post_stamp
, &pmu
->inbound_queueport_low
);
1976 case ACB_ADAPTER_TYPE_F
: {
1977 struct MessageUnit_F __iomem
*pmu
= acb
->pmuF
;
1978 u32 ccb_post_stamp
, arc_cdb_size
;
1980 if (ccb
->arc_cdb_size
<= 0x300)
1981 arc_cdb_size
= (ccb
->arc_cdb_size
- 1) >> 6 | 1;
1983 arc_cdb_size
= ((ccb
->arc_cdb_size
+ 0xff) >> 8) + 2;
1984 if (arc_cdb_size
> 0xF)
1986 arc_cdb_size
= (arc_cdb_size
<< 1) | 1;
1988 ccb_post_stamp
= (ccb
->smid
| arc_cdb_size
);
1989 writel(0, &pmu
->inbound_queueport_high
);
1990 writel(ccb_post_stamp
, &pmu
->inbound_queueport_low
);
1996 static void arcmsr_hbaA_stop_bgrb(struct AdapterControlBlock
*acb
)
1998 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
1999 acb
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
2000 writel(ARCMSR_INBOUND_MESG0_STOP_BGRB
, ®
->inbound_msgaddr0
);
2001 if (!arcmsr_hbaA_wait_msgint_ready(acb
)) {
2003 "arcmsr%d: wait 'stop adapter background rebuild' timeout\n"
2004 , acb
->host
->host_no
);
2008 static void arcmsr_hbaB_stop_bgrb(struct AdapterControlBlock
*acb
)
2010 struct MessageUnit_B
*reg
= acb
->pmuB
;
2011 acb
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
2012 writel(ARCMSR_MESSAGE_STOP_BGRB
, reg
->drv2iop_doorbell
);
2014 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
2016 "arcmsr%d: wait 'stop adapter background rebuild' timeout\n"
2017 , acb
->host
->host_no
);
2021 static void arcmsr_hbaC_stop_bgrb(struct AdapterControlBlock
*pACB
)
2023 struct MessageUnit_C __iomem
*reg
= pACB
->pmuC
;
2024 pACB
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
2025 writel(ARCMSR_INBOUND_MESG0_STOP_BGRB
, ®
->inbound_msgaddr0
);
2026 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
2027 if (!arcmsr_hbaC_wait_msgint_ready(pACB
)) {
2029 "arcmsr%d: wait 'stop adapter background rebuild' timeout\n"
2030 , pACB
->host
->host_no
);
2035 static void arcmsr_hbaD_stop_bgrb(struct AdapterControlBlock
*pACB
)
2037 struct MessageUnit_D
*reg
= pACB
->pmuD
;
2039 pACB
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
2040 writel(ARCMSR_INBOUND_MESG0_STOP_BGRB
, reg
->inbound_msgaddr0
);
2041 if (!arcmsr_hbaD_wait_msgint_ready(pACB
))
2042 pr_notice("arcmsr%d: wait 'stop adapter background rebuild' "
2043 "timeout\n", pACB
->host
->host_no
);
2046 static void arcmsr_hbaE_stop_bgrb(struct AdapterControlBlock
*pACB
)
2048 struct MessageUnit_E __iomem
*reg
= pACB
->pmuE
;
2050 pACB
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
2051 writel(ARCMSR_INBOUND_MESG0_STOP_BGRB
, ®
->inbound_msgaddr0
);
2052 pACB
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_MESSAGE_CMD_DONE
;
2053 writel(pACB
->out_doorbell
, ®
->iobound_doorbell
);
2054 if (!arcmsr_hbaE_wait_msgint_ready(pACB
)) {
2055 pr_notice("arcmsr%d: wait 'stop adapter background rebuild' "
2056 "timeout\n", pACB
->host
->host_no
);
2060 static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock
*acb
)
2062 switch (acb
->adapter_type
) {
2063 case ACB_ADAPTER_TYPE_A
:
2064 arcmsr_hbaA_stop_bgrb(acb
);
2066 case ACB_ADAPTER_TYPE_B
:
2067 arcmsr_hbaB_stop_bgrb(acb
);
2069 case ACB_ADAPTER_TYPE_C
:
2070 arcmsr_hbaC_stop_bgrb(acb
);
2072 case ACB_ADAPTER_TYPE_D
:
2073 arcmsr_hbaD_stop_bgrb(acb
);
2075 case ACB_ADAPTER_TYPE_E
:
2076 case ACB_ADAPTER_TYPE_F
:
2077 arcmsr_hbaE_stop_bgrb(acb
);
2082 static void arcmsr_free_ccb_pool(struct AdapterControlBlock
*acb
)
2084 if (acb
->xor_mega
) {
2085 struct Xor_sg
*pXorPhys
;
2089 pXorPhys
= (struct Xor_sg
*)(acb
->xorVirt
+
2090 sizeof(struct HostRamBuf
));
2091 pXorVirt
= (void **)((unsigned long)acb
->xorVirt
+
2092 (unsigned long)acb
->xorVirtOffset
);
2093 for (i
= 0; i
< acb
->xor_mega
; i
++) {
2094 if (pXorPhys
->xorPhys
) {
2095 dma_free_coherent(&acb
->pdev
->dev
,
2096 ARCMSR_XOR_SEG_SIZE
,
2097 *pXorVirt
, pXorPhys
->xorPhys
);
2098 pXorPhys
->xorPhys
= 0;
2104 dma_free_coherent(&acb
->pdev
->dev
, acb
->init2cfg_size
,
2105 acb
->xorVirt
, acb
->xorPhys
);
2107 dma_free_coherent(&acb
->pdev
->dev
, acb
->uncache_size
, acb
->dma_coherent
, acb
->dma_coherent_handle
);
2110 static void arcmsr_iop_message_read(struct AdapterControlBlock
*acb
)
2112 switch (acb
->adapter_type
) {
2113 case ACB_ADAPTER_TYPE_A
: {
2114 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2115 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK
, ®
->inbound_doorbell
);
2118 case ACB_ADAPTER_TYPE_B
: {
2119 struct MessageUnit_B
*reg
= acb
->pmuB
;
2120 writel(ARCMSR_DRV2IOP_DATA_READ_OK
, reg
->drv2iop_doorbell
);
2123 case ACB_ADAPTER_TYPE_C
: {
2124 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
2126 writel(ARCMSR_HBCMU_DRV2IOP_DATA_READ_OK
, ®
->inbound_doorbell
);
2129 case ACB_ADAPTER_TYPE_D
: {
2130 struct MessageUnit_D
*reg
= acb
->pmuD
;
2131 writel(ARCMSR_ARC1214_DRV2IOP_DATA_OUT_READ
,
2132 reg
->inbound_doorbell
);
2135 case ACB_ADAPTER_TYPE_E
:
2136 case ACB_ADAPTER_TYPE_F
: {
2137 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
2138 acb
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_DATA_READ_OK
;
2139 writel(acb
->out_doorbell
, ®
->iobound_doorbell
);
2145 static void arcmsr_iop_message_wrote(struct AdapterControlBlock
*acb
)
2147 switch (acb
->adapter_type
) {
2148 case ACB_ADAPTER_TYPE_A
: {
2149 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2151 ** push inbound doorbell tell iop, driver data write ok
2152 ** and wait reply on next hwinterrupt for next Qbuffer post
2154 writel(ARCMSR_INBOUND_DRIVER_DATA_WRITE_OK
, ®
->inbound_doorbell
);
2158 case ACB_ADAPTER_TYPE_B
: {
2159 struct MessageUnit_B
*reg
= acb
->pmuB
;
2161 ** push inbound doorbell tell iop, driver data write ok
2162 ** and wait reply on next hwinterrupt for next Qbuffer post
2164 writel(ARCMSR_DRV2IOP_DATA_WRITE_OK
, reg
->drv2iop_doorbell
);
2167 case ACB_ADAPTER_TYPE_C
: {
2168 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
2170 ** push inbound doorbell tell iop, driver data write ok
2171 ** and wait reply on next hwinterrupt for next Qbuffer post
2173 writel(ARCMSR_HBCMU_DRV2IOP_DATA_WRITE_OK
, ®
->inbound_doorbell
);
2176 case ACB_ADAPTER_TYPE_D
: {
2177 struct MessageUnit_D
*reg
= acb
->pmuD
;
2178 writel(ARCMSR_ARC1214_DRV2IOP_DATA_IN_READY
,
2179 reg
->inbound_doorbell
);
2182 case ACB_ADAPTER_TYPE_E
:
2183 case ACB_ADAPTER_TYPE_F
: {
2184 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
2185 acb
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_DATA_WRITE_OK
;
2186 writel(acb
->out_doorbell
, ®
->iobound_doorbell
);
2192 struct QBUFFER __iomem
*arcmsr_get_iop_rqbuffer(struct AdapterControlBlock
*acb
)
2194 struct QBUFFER __iomem
*qbuffer
= NULL
;
2195 switch (acb
->adapter_type
) {
2197 case ACB_ADAPTER_TYPE_A
: {
2198 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2199 qbuffer
= (struct QBUFFER __iomem
*)®
->message_rbuffer
;
2202 case ACB_ADAPTER_TYPE_B
: {
2203 struct MessageUnit_B
*reg
= acb
->pmuB
;
2204 qbuffer
= (struct QBUFFER __iomem
*)reg
->message_rbuffer
;
2207 case ACB_ADAPTER_TYPE_C
: {
2208 struct MessageUnit_C __iomem
*phbcmu
= acb
->pmuC
;
2209 qbuffer
= (struct QBUFFER __iomem
*)&phbcmu
->message_rbuffer
;
2212 case ACB_ADAPTER_TYPE_D
: {
2213 struct MessageUnit_D
*reg
= acb
->pmuD
;
2214 qbuffer
= (struct QBUFFER __iomem
*)reg
->message_rbuffer
;
2217 case ACB_ADAPTER_TYPE_E
: {
2218 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
2219 qbuffer
= (struct QBUFFER __iomem
*)®
->message_rbuffer
;
2222 case ACB_ADAPTER_TYPE_F
: {
2223 qbuffer
= (struct QBUFFER __iomem
*)acb
->message_rbuffer
;
2230 static struct QBUFFER __iomem
*arcmsr_get_iop_wqbuffer(struct AdapterControlBlock
*acb
)
2232 struct QBUFFER __iomem
*pqbuffer
= NULL
;
2233 switch (acb
->adapter_type
) {
2235 case ACB_ADAPTER_TYPE_A
: {
2236 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2237 pqbuffer
= (struct QBUFFER __iomem
*) ®
->message_wbuffer
;
2240 case ACB_ADAPTER_TYPE_B
: {
2241 struct MessageUnit_B
*reg
= acb
->pmuB
;
2242 pqbuffer
= (struct QBUFFER __iomem
*)reg
->message_wbuffer
;
2245 case ACB_ADAPTER_TYPE_C
: {
2246 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
2247 pqbuffer
= (struct QBUFFER __iomem
*)®
->message_wbuffer
;
2250 case ACB_ADAPTER_TYPE_D
: {
2251 struct MessageUnit_D
*reg
= acb
->pmuD
;
2252 pqbuffer
= (struct QBUFFER __iomem
*)reg
->message_wbuffer
;
2255 case ACB_ADAPTER_TYPE_E
: {
2256 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
2257 pqbuffer
= (struct QBUFFER __iomem
*)®
->message_wbuffer
;
2260 case ACB_ADAPTER_TYPE_F
:
2261 pqbuffer
= (struct QBUFFER __iomem
*)acb
->message_wbuffer
;
2268 arcmsr_Read_iop_rqbuffer_in_DWORD(struct AdapterControlBlock
*acb
,
2269 struct QBUFFER __iomem
*prbuffer
)
2272 uint8_t *buf1
= NULL
;
2273 uint32_t __iomem
*iop_data
;
2274 uint32_t iop_len
, data_len
, *buf2
= NULL
;
2276 iop_data
= (uint32_t __iomem
*)prbuffer
->data
;
2277 iop_len
= readl(&prbuffer
->data_len
);
2279 buf1
= kmalloc(128, GFP_ATOMIC
);
2280 buf2
= (uint32_t *)buf1
;
2284 while (data_len
>= 4) {
2285 *buf2
++ = readl(iop_data
);
2290 *buf2
= readl(iop_data
);
2291 buf2
= (uint32_t *)buf1
;
2293 while (iop_len
> 0) {
2294 pQbuffer
= &acb
->rqbuffer
[acb
->rqbuf_putIndex
];
2296 acb
->rqbuf_putIndex
++;
2297 /* if last, index number set it to 0 */
2298 acb
->rqbuf_putIndex
%= ARCMSR_MAX_QBUFFER
;
2303 /* let IOP know data has been read */
2304 arcmsr_iop_message_read(acb
);
2309 arcmsr_Read_iop_rqbuffer_data(struct AdapterControlBlock
*acb
,
2310 struct QBUFFER __iomem
*prbuffer
) {
2313 uint8_t __iomem
*iop_data
;
2316 if (acb
->adapter_type
> ACB_ADAPTER_TYPE_B
)
2317 return arcmsr_Read_iop_rqbuffer_in_DWORD(acb
, prbuffer
);
2318 iop_data
= (uint8_t __iomem
*)prbuffer
->data
;
2319 iop_len
= readl(&prbuffer
->data_len
);
2320 while (iop_len
> 0) {
2321 pQbuffer
= &acb
->rqbuffer
[acb
->rqbuf_putIndex
];
2322 *pQbuffer
= readb(iop_data
);
2323 acb
->rqbuf_putIndex
++;
2324 acb
->rqbuf_putIndex
%= ARCMSR_MAX_QBUFFER
;
2328 arcmsr_iop_message_read(acb
);
2332 static void arcmsr_iop2drv_data_wrote_handle(struct AdapterControlBlock
*acb
)
2334 unsigned long flags
;
2335 struct QBUFFER __iomem
*prbuffer
;
2336 int32_t buf_empty_len
;
2338 spin_lock_irqsave(&acb
->rqbuffer_lock
, flags
);
2339 prbuffer
= arcmsr_get_iop_rqbuffer(acb
);
2340 if (acb
->rqbuf_putIndex
>= acb
->rqbuf_getIndex
) {
2341 buf_empty_len
= (ARCMSR_MAX_QBUFFER
- 1) -
2342 (acb
->rqbuf_putIndex
- acb
->rqbuf_getIndex
);
2344 buf_empty_len
= acb
->rqbuf_getIndex
- acb
->rqbuf_putIndex
- 1;
2345 if (buf_empty_len
>= readl(&prbuffer
->data_len
)) {
2346 if (arcmsr_Read_iop_rqbuffer_data(acb
, prbuffer
) == 0)
2347 acb
->acb_flags
|= ACB_F_IOPDATA_OVERFLOW
;
2349 acb
->acb_flags
|= ACB_F_IOPDATA_OVERFLOW
;
2350 spin_unlock_irqrestore(&acb
->rqbuffer_lock
, flags
);
2353 static void arcmsr_write_ioctldata2iop_in_DWORD(struct AdapterControlBlock
*acb
)
2356 struct QBUFFER __iomem
*pwbuffer
;
2357 uint8_t *buf1
= NULL
;
2358 uint32_t __iomem
*iop_data
;
2359 uint32_t allxfer_len
= 0, data_len
, *buf2
= NULL
, data
;
2361 if (acb
->acb_flags
& ACB_F_MESSAGE_WQBUFFER_READED
) {
2362 buf1
= kmalloc(128, GFP_ATOMIC
);
2363 buf2
= (uint32_t *)buf1
;
2367 acb
->acb_flags
&= (~ACB_F_MESSAGE_WQBUFFER_READED
);
2368 pwbuffer
= arcmsr_get_iop_wqbuffer(acb
);
2369 iop_data
= (uint32_t __iomem
*)pwbuffer
->data
;
2370 while ((acb
->wqbuf_getIndex
!= acb
->wqbuf_putIndex
)
2371 && (allxfer_len
< 124)) {
2372 pQbuffer
= &acb
->wqbuffer
[acb
->wqbuf_getIndex
];
2374 acb
->wqbuf_getIndex
++;
2375 acb
->wqbuf_getIndex
%= ARCMSR_MAX_QBUFFER
;
2379 data_len
= allxfer_len
;
2380 buf1
= (uint8_t *)buf2
;
2381 while (data_len
>= 4) {
2383 writel(data
, iop_data
);
2389 writel(data
, iop_data
);
2391 writel(allxfer_len
, &pwbuffer
->data_len
);
2393 arcmsr_iop_message_wrote(acb
);
2398 arcmsr_write_ioctldata2iop(struct AdapterControlBlock
*acb
)
2401 struct QBUFFER __iomem
*pwbuffer
;
2402 uint8_t __iomem
*iop_data
;
2403 int32_t allxfer_len
= 0;
2405 if (acb
->adapter_type
> ACB_ADAPTER_TYPE_B
) {
2406 arcmsr_write_ioctldata2iop_in_DWORD(acb
);
2409 if (acb
->acb_flags
& ACB_F_MESSAGE_WQBUFFER_READED
) {
2410 acb
->acb_flags
&= (~ACB_F_MESSAGE_WQBUFFER_READED
);
2411 pwbuffer
= arcmsr_get_iop_wqbuffer(acb
);
2412 iop_data
= (uint8_t __iomem
*)pwbuffer
->data
;
2413 while ((acb
->wqbuf_getIndex
!= acb
->wqbuf_putIndex
)
2414 && (allxfer_len
< 124)) {
2415 pQbuffer
= &acb
->wqbuffer
[acb
->wqbuf_getIndex
];
2416 writeb(*pQbuffer
, iop_data
);
2417 acb
->wqbuf_getIndex
++;
2418 acb
->wqbuf_getIndex
%= ARCMSR_MAX_QBUFFER
;
2422 writel(allxfer_len
, &pwbuffer
->data_len
);
2423 arcmsr_iop_message_wrote(acb
);
2427 static void arcmsr_iop2drv_data_read_handle(struct AdapterControlBlock
*acb
)
2429 unsigned long flags
;
2431 spin_lock_irqsave(&acb
->wqbuffer_lock
, flags
);
2432 acb
->acb_flags
|= ACB_F_MESSAGE_WQBUFFER_READED
;
2433 if (acb
->wqbuf_getIndex
!= acb
->wqbuf_putIndex
)
2434 arcmsr_write_ioctldata2iop(acb
);
2435 if (acb
->wqbuf_getIndex
== acb
->wqbuf_putIndex
)
2436 acb
->acb_flags
|= ACB_F_MESSAGE_WQBUFFER_CLEARED
;
2437 spin_unlock_irqrestore(&acb
->wqbuffer_lock
, flags
);
2440 static void arcmsr_hbaA_doorbell_isr(struct AdapterControlBlock
*acb
)
2442 uint32_t outbound_doorbell
;
2443 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2444 outbound_doorbell
= readl(®
->outbound_doorbell
);
2446 writel(outbound_doorbell
, ®
->outbound_doorbell
);
2447 if (outbound_doorbell
& ARCMSR_OUTBOUND_IOP331_DATA_WRITE_OK
)
2448 arcmsr_iop2drv_data_wrote_handle(acb
);
2449 if (outbound_doorbell
& ARCMSR_OUTBOUND_IOP331_DATA_READ_OK
)
2450 arcmsr_iop2drv_data_read_handle(acb
);
2451 outbound_doorbell
= readl(®
->outbound_doorbell
);
2452 } while (outbound_doorbell
& (ARCMSR_OUTBOUND_IOP331_DATA_WRITE_OK
2453 | ARCMSR_OUTBOUND_IOP331_DATA_READ_OK
));
2455 static void arcmsr_hbaC_doorbell_isr(struct AdapterControlBlock
*pACB
)
2457 uint32_t outbound_doorbell
;
2458 struct MessageUnit_C __iomem
*reg
= pACB
->pmuC
;
2460 *******************************************************************
2461 ** Maybe here we need to check wrqbuffer_lock is lock or not
2462 ** DOORBELL: din! don!
2463 ** check if there are any mail need to pack from firmware
2464 *******************************************************************
2466 outbound_doorbell
= readl(®
->outbound_doorbell
);
2468 writel(outbound_doorbell
, ®
->outbound_doorbell_clear
);
2469 readl(®
->outbound_doorbell_clear
);
2470 if (outbound_doorbell
& ARCMSR_HBCMU_IOP2DRV_DATA_WRITE_OK
)
2471 arcmsr_iop2drv_data_wrote_handle(pACB
);
2472 if (outbound_doorbell
& ARCMSR_HBCMU_IOP2DRV_DATA_READ_OK
)
2473 arcmsr_iop2drv_data_read_handle(pACB
);
2474 if (outbound_doorbell
& ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE
)
2475 arcmsr_hbaC_message_isr(pACB
);
2476 outbound_doorbell
= readl(®
->outbound_doorbell
);
2477 } while (outbound_doorbell
& (ARCMSR_HBCMU_IOP2DRV_DATA_WRITE_OK
2478 | ARCMSR_HBCMU_IOP2DRV_DATA_READ_OK
2479 | ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE
));
2482 static void arcmsr_hbaD_doorbell_isr(struct AdapterControlBlock
*pACB
)
2484 uint32_t outbound_doorbell
;
2485 struct MessageUnit_D
*pmu
= pACB
->pmuD
;
2487 outbound_doorbell
= readl(pmu
->outbound_doorbell
);
2489 writel(outbound_doorbell
, pmu
->outbound_doorbell
);
2490 if (outbound_doorbell
& ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
)
2491 arcmsr_hbaD_message_isr(pACB
);
2492 if (outbound_doorbell
& ARCMSR_ARC1214_IOP2DRV_DATA_WRITE_OK
)
2493 arcmsr_iop2drv_data_wrote_handle(pACB
);
2494 if (outbound_doorbell
& ARCMSR_ARC1214_IOP2DRV_DATA_READ_OK
)
2495 arcmsr_iop2drv_data_read_handle(pACB
);
2496 outbound_doorbell
= readl(pmu
->outbound_doorbell
);
2497 } while (outbound_doorbell
& (ARCMSR_ARC1214_IOP2DRV_DATA_WRITE_OK
2498 | ARCMSR_ARC1214_IOP2DRV_DATA_READ_OK
2499 | ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
));
2502 static void arcmsr_hbaE_doorbell_isr(struct AdapterControlBlock
*pACB
)
2504 uint32_t outbound_doorbell
, in_doorbell
, tmp
, i
;
2505 struct MessageUnit_E __iomem
*reg
= pACB
->pmuE
;
2507 if (pACB
->adapter_type
== ACB_ADAPTER_TYPE_F
) {
2508 for (i
= 0; i
< 5; i
++) {
2509 in_doorbell
= readl(®
->iobound_doorbell
);
2510 if (in_doorbell
!= 0)
2514 in_doorbell
= readl(®
->iobound_doorbell
);
2515 outbound_doorbell
= in_doorbell
^ pACB
->in_doorbell
;
2517 writel(0, ®
->host_int_status
); /* clear interrupt */
2518 if (outbound_doorbell
& ARCMSR_HBEMU_IOP2DRV_DATA_WRITE_OK
) {
2519 arcmsr_iop2drv_data_wrote_handle(pACB
);
2521 if (outbound_doorbell
& ARCMSR_HBEMU_IOP2DRV_DATA_READ_OK
) {
2522 arcmsr_iop2drv_data_read_handle(pACB
);
2524 if (outbound_doorbell
& ARCMSR_HBEMU_IOP2DRV_MESSAGE_CMD_DONE
) {
2525 arcmsr_hbaE_message_isr(pACB
);
2528 in_doorbell
= readl(®
->iobound_doorbell
);
2529 outbound_doorbell
= tmp
^ in_doorbell
;
2530 } while (outbound_doorbell
& (ARCMSR_HBEMU_IOP2DRV_DATA_WRITE_OK
2531 | ARCMSR_HBEMU_IOP2DRV_DATA_READ_OK
2532 | ARCMSR_HBEMU_IOP2DRV_MESSAGE_CMD_DONE
));
2533 pACB
->in_doorbell
= in_doorbell
;
2536 static void arcmsr_hbaA_postqueue_isr(struct AdapterControlBlock
*acb
)
2539 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2540 struct ARCMSR_CDB
*pARCMSR_CDB
;
2541 struct CommandControlBlock
*pCCB
;
2543 unsigned long cdb_phy_addr
;
2545 while ((flag_ccb
= readl(®
->outbound_queueport
)) != 0xFFFFFFFF) {
2546 cdb_phy_addr
= (flag_ccb
<< 5) & 0xffffffff;
2547 if (acb
->cdb_phyadd_hipart
)
2548 cdb_phy_addr
= cdb_phy_addr
| acb
->cdb_phyadd_hipart
;
2549 pARCMSR_CDB
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ cdb_phy_addr
);
2550 pCCB
= container_of(pARCMSR_CDB
, struct CommandControlBlock
, arcmsr_cdb
);
2551 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
2552 arcmsr_drain_donequeue(acb
, pCCB
, error
);
2555 static void arcmsr_hbaB_postqueue_isr(struct AdapterControlBlock
*acb
)
2559 struct MessageUnit_B
*reg
= acb
->pmuB
;
2560 struct ARCMSR_CDB
*pARCMSR_CDB
;
2561 struct CommandControlBlock
*pCCB
;
2563 unsigned long cdb_phy_addr
;
2565 index
= reg
->doneq_index
;
2566 while ((flag_ccb
= reg
->done_qbuffer
[index
]) != 0) {
2567 cdb_phy_addr
= (flag_ccb
<< 5) & 0xffffffff;
2568 if (acb
->cdb_phyadd_hipart
)
2569 cdb_phy_addr
= cdb_phy_addr
| acb
->cdb_phyadd_hipart
;
2570 pARCMSR_CDB
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ cdb_phy_addr
);
2571 pCCB
= container_of(pARCMSR_CDB
, struct CommandControlBlock
, arcmsr_cdb
);
2572 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
2573 arcmsr_drain_donequeue(acb
, pCCB
, error
);
2574 reg
->done_qbuffer
[index
] = 0;
2576 index
%= ARCMSR_MAX_HBB_POSTQUEUE
;
2577 reg
->doneq_index
= index
;
2581 static void arcmsr_hbaC_postqueue_isr(struct AdapterControlBlock
*acb
)
2583 struct MessageUnit_C __iomem
*phbcmu
;
2584 struct ARCMSR_CDB
*arcmsr_cdb
;
2585 struct CommandControlBlock
*ccb
;
2586 uint32_t flag_ccb
, throttling
= 0;
2587 unsigned long ccb_cdb_phy
;
2591 /* areca cdb command done */
2592 /* Use correct offset and size for syncing */
2594 while ((flag_ccb
= readl(&phbcmu
->outbound_queueport_low
)) !=
2596 ccb_cdb_phy
= (flag_ccb
& 0xFFFFFFF0);
2597 if (acb
->cdb_phyadd_hipart
)
2598 ccb_cdb_phy
= ccb_cdb_phy
| acb
->cdb_phyadd_hipart
;
2599 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
2601 ccb
= container_of(arcmsr_cdb
, struct CommandControlBlock
,
2603 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
)
2605 /* check if command done with no error */
2606 arcmsr_drain_donequeue(acb
, ccb
, error
);
2608 if (throttling
== ARCMSR_HBC_ISR_THROTTLING_LEVEL
) {
2609 writel(ARCMSR_HBCMU_DRV2IOP_POSTQUEUE_THROTTLING
,
2610 &phbcmu
->inbound_doorbell
);
2616 static void arcmsr_hbaD_postqueue_isr(struct AdapterControlBlock
*acb
)
2618 u32 outbound_write_pointer
, doneq_index
, index_stripped
, toggle
;
2619 uint32_t addressLow
;
2621 struct MessageUnit_D
*pmu
;
2622 struct ARCMSR_CDB
*arcmsr_cdb
;
2623 struct CommandControlBlock
*ccb
;
2624 unsigned long flags
, ccb_cdb_phy
;
2626 spin_lock_irqsave(&acb
->doneq_lock
, flags
);
2628 outbound_write_pointer
= pmu
->done_qbuffer
[0].addressLow
+ 1;
2629 doneq_index
= pmu
->doneq_index
;
2630 if ((doneq_index
& 0xFFF) != (outbound_write_pointer
& 0xFFF)) {
2632 toggle
= doneq_index
& 0x4000;
2633 index_stripped
= (doneq_index
& 0xFFF) + 1;
2634 index_stripped
%= ARCMSR_MAX_ARC1214_DONEQUEUE
;
2635 pmu
->doneq_index
= index_stripped
? (index_stripped
| toggle
) :
2636 ((toggle
^ 0x4000) + 1);
2637 doneq_index
= pmu
->doneq_index
;
2638 addressLow
= pmu
->done_qbuffer
[doneq_index
&
2640 ccb_cdb_phy
= (addressLow
& 0xFFFFFFF0);
2641 if (acb
->cdb_phyadd_hipart
)
2642 ccb_cdb_phy
= ccb_cdb_phy
| acb
->cdb_phyadd_hipart
;
2643 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
2645 ccb
= container_of(arcmsr_cdb
,
2646 struct CommandControlBlock
, arcmsr_cdb
);
2647 error
= (addressLow
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
)
2649 arcmsr_drain_donequeue(acb
, ccb
, error
);
2650 writel(doneq_index
, pmu
->outboundlist_read_pointer
);
2651 } while ((doneq_index
& 0xFFF) !=
2652 (outbound_write_pointer
& 0xFFF));
2654 writel(ARCMSR_ARC1214_OUTBOUND_LIST_INTERRUPT_CLEAR
,
2655 pmu
->outboundlist_interrupt_cause
);
2656 readl(pmu
->outboundlist_interrupt_cause
);
2657 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
2660 static void arcmsr_hbaE_postqueue_isr(struct AdapterControlBlock
*acb
)
2662 uint32_t doneq_index
;
2665 struct MessageUnit_E __iomem
*pmu
;
2666 struct CommandControlBlock
*ccb
;
2667 unsigned long flags
;
2669 spin_lock_irqsave(&acb
->doneq_lock
, flags
);
2670 doneq_index
= acb
->doneq_index
;
2672 while ((readl(&pmu
->reply_post_producer_index
) & 0xFFFF) != doneq_index
) {
2673 cmdSMID
= acb
->pCompletionQ
[doneq_index
].cmdSMID
;
2674 ccb
= acb
->pccb_pool
[cmdSMID
];
2675 error
= (acb
->pCompletionQ
[doneq_index
].cmdFlag
2676 & ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
) ? true : false;
2677 arcmsr_drain_donequeue(acb
, ccb
, error
);
2679 if (doneq_index
>= acb
->completionQ_entry
)
2682 acb
->doneq_index
= doneq_index
;
2683 writel(doneq_index
, &pmu
->reply_post_consumer_index
);
2684 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
2687 static void arcmsr_hbaF_postqueue_isr(struct AdapterControlBlock
*acb
)
2689 uint32_t doneq_index
;
2692 struct MessageUnit_F __iomem
*phbcmu
;
2693 struct CommandControlBlock
*ccb
;
2694 unsigned long flags
;
2696 spin_lock_irqsave(&acb
->doneq_lock
, flags
);
2697 doneq_index
= acb
->doneq_index
;
2700 cmdSMID
= acb
->pCompletionQ
[doneq_index
].cmdSMID
;
2701 if (cmdSMID
== 0xffff)
2703 ccb
= acb
->pccb_pool
[cmdSMID
];
2704 error
= (acb
->pCompletionQ
[doneq_index
].cmdFlag
&
2705 ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
) ? true : false;
2706 arcmsr_drain_donequeue(acb
, ccb
, error
);
2707 acb
->pCompletionQ
[doneq_index
].cmdSMID
= 0xffff;
2709 if (doneq_index
>= acb
->completionQ_entry
)
2712 acb
->doneq_index
= doneq_index
;
2713 writel(doneq_index
, &phbcmu
->reply_post_consumer_index
);
2714 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
2718 **********************************************************************************
2719 ** Handle a message interrupt
2721 ** The only message interrupt we expect is in response to a query for the current adapter config.
2722 ** We want this in order to compare the drivemap so that we can detect newly-attached drives.
2723 **********************************************************************************
2725 static void arcmsr_hbaA_message_isr(struct AdapterControlBlock
*acb
)
2727 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2728 /*clear interrupt and message state*/
2729 writel(ARCMSR_MU_OUTBOUND_MESSAGE0_INT
, ®
->outbound_intstatus
);
2730 if (acb
->acb_flags
& ACB_F_MSG_GET_CONFIG
)
2731 schedule_work(&acb
->arcmsr_do_message_isr_bh
);
2733 static void arcmsr_hbaB_message_isr(struct AdapterControlBlock
*acb
)
2735 struct MessageUnit_B
*reg
= acb
->pmuB
;
2737 /*clear interrupt and message state*/
2738 writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN
, reg
->iop2drv_doorbell
);
2739 if (acb
->acb_flags
& ACB_F_MSG_GET_CONFIG
)
2740 schedule_work(&acb
->arcmsr_do_message_isr_bh
);
2743 **********************************************************************************
2744 ** Handle a message interrupt
2746 ** The only message interrupt we expect is in response to a query for the
2747 ** current adapter config.
2748 ** We want this in order to compare the drivemap so that we can detect newly-attached drives.
2749 **********************************************************************************
2751 static void arcmsr_hbaC_message_isr(struct AdapterControlBlock
*acb
)
2753 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
2754 /*clear interrupt and message state*/
2755 writel(ARCMSR_HBCMU_IOP2DRV_MESSAGE_CMD_DONE_DOORBELL_CLEAR
, ®
->outbound_doorbell_clear
);
2756 if (acb
->acb_flags
& ACB_F_MSG_GET_CONFIG
)
2757 schedule_work(&acb
->arcmsr_do_message_isr_bh
);
2760 static void arcmsr_hbaD_message_isr(struct AdapterControlBlock
*acb
)
2762 struct MessageUnit_D
*reg
= acb
->pmuD
;
2764 writel(ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
, reg
->outbound_doorbell
);
2765 readl(reg
->outbound_doorbell
);
2766 if (acb
->acb_flags
& ACB_F_MSG_GET_CONFIG
)
2767 schedule_work(&acb
->arcmsr_do_message_isr_bh
);
2770 static void arcmsr_hbaE_message_isr(struct AdapterControlBlock
*acb
)
2772 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
2774 writel(0, ®
->host_int_status
);
2775 if (acb
->acb_flags
& ACB_F_MSG_GET_CONFIG
)
2776 schedule_work(&acb
->arcmsr_do_message_isr_bh
);
2779 static int arcmsr_hbaA_handle_isr(struct AdapterControlBlock
*acb
)
2781 uint32_t outbound_intstatus
;
2782 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
2783 outbound_intstatus
= readl(®
->outbound_intstatus
) &
2784 acb
->outbound_int_enable
;
2785 if (!(outbound_intstatus
& ARCMSR_MU_OUTBOUND_HANDLE_INT
))
2788 writel(outbound_intstatus
, ®
->outbound_intstatus
);
2789 if (outbound_intstatus
& ARCMSR_MU_OUTBOUND_DOORBELL_INT
)
2790 arcmsr_hbaA_doorbell_isr(acb
);
2791 if (outbound_intstatus
& ARCMSR_MU_OUTBOUND_POSTQUEUE_INT
)
2792 arcmsr_hbaA_postqueue_isr(acb
);
2793 if (outbound_intstatus
& ARCMSR_MU_OUTBOUND_MESSAGE0_INT
)
2794 arcmsr_hbaA_message_isr(acb
);
2795 outbound_intstatus
= readl(®
->outbound_intstatus
) &
2796 acb
->outbound_int_enable
;
2797 } while (outbound_intstatus
& (ARCMSR_MU_OUTBOUND_DOORBELL_INT
2798 | ARCMSR_MU_OUTBOUND_POSTQUEUE_INT
2799 | ARCMSR_MU_OUTBOUND_MESSAGE0_INT
));
2803 static int arcmsr_hbaB_handle_isr(struct AdapterControlBlock
*acb
)
2805 uint32_t outbound_doorbell
;
2806 struct MessageUnit_B
*reg
= acb
->pmuB
;
2807 outbound_doorbell
= readl(reg
->iop2drv_doorbell
) &
2808 acb
->outbound_int_enable
;
2809 if (!outbound_doorbell
)
2812 writel(~outbound_doorbell
, reg
->iop2drv_doorbell
);
2813 writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT
, reg
->drv2iop_doorbell
);
2814 if (outbound_doorbell
& ARCMSR_IOP2DRV_DATA_WRITE_OK
)
2815 arcmsr_iop2drv_data_wrote_handle(acb
);
2816 if (outbound_doorbell
& ARCMSR_IOP2DRV_DATA_READ_OK
)
2817 arcmsr_iop2drv_data_read_handle(acb
);
2818 if (outbound_doorbell
& ARCMSR_IOP2DRV_CDB_DONE
)
2819 arcmsr_hbaB_postqueue_isr(acb
);
2820 if (outbound_doorbell
& ARCMSR_IOP2DRV_MESSAGE_CMD_DONE
)
2821 arcmsr_hbaB_message_isr(acb
);
2822 outbound_doorbell
= readl(reg
->iop2drv_doorbell
) &
2823 acb
->outbound_int_enable
;
2824 } while (outbound_doorbell
& (ARCMSR_IOP2DRV_DATA_WRITE_OK
2825 | ARCMSR_IOP2DRV_DATA_READ_OK
2826 | ARCMSR_IOP2DRV_CDB_DONE
2827 | ARCMSR_IOP2DRV_MESSAGE_CMD_DONE
));
2831 static int arcmsr_hbaC_handle_isr(struct AdapterControlBlock
*pACB
)
2833 uint32_t host_interrupt_status
;
2834 struct MessageUnit_C __iomem
*phbcmu
= pACB
->pmuC
;
2836 *********************************************
2837 ** check outbound intstatus
2838 *********************************************
2840 host_interrupt_status
= readl(&phbcmu
->host_int_status
) &
2841 (ARCMSR_HBCMU_OUTBOUND_POSTQUEUE_ISR
|
2842 ARCMSR_HBCMU_OUTBOUND_DOORBELL_ISR
);
2843 if (!host_interrupt_status
)
2846 if (host_interrupt_status
& ARCMSR_HBCMU_OUTBOUND_DOORBELL_ISR
)
2847 arcmsr_hbaC_doorbell_isr(pACB
);
2848 /* MU post queue interrupts*/
2849 if (host_interrupt_status
& ARCMSR_HBCMU_OUTBOUND_POSTQUEUE_ISR
)
2850 arcmsr_hbaC_postqueue_isr(pACB
);
2851 host_interrupt_status
= readl(&phbcmu
->host_int_status
);
2852 } while (host_interrupt_status
& (ARCMSR_HBCMU_OUTBOUND_POSTQUEUE_ISR
|
2853 ARCMSR_HBCMU_OUTBOUND_DOORBELL_ISR
));
2857 static irqreturn_t
arcmsr_hbaD_handle_isr(struct AdapterControlBlock
*pACB
)
2859 u32 host_interrupt_status
;
2860 struct MessageUnit_D
*pmu
= pACB
->pmuD
;
2862 host_interrupt_status
= readl(pmu
->host_int_status
) &
2863 (ARCMSR_ARC1214_OUTBOUND_POSTQUEUE_ISR
|
2864 ARCMSR_ARC1214_OUTBOUND_DOORBELL_ISR
);
2865 if (!host_interrupt_status
)
2868 /* MU post queue interrupts*/
2869 if (host_interrupt_status
&
2870 ARCMSR_ARC1214_OUTBOUND_POSTQUEUE_ISR
)
2871 arcmsr_hbaD_postqueue_isr(pACB
);
2872 if (host_interrupt_status
&
2873 ARCMSR_ARC1214_OUTBOUND_DOORBELL_ISR
)
2874 arcmsr_hbaD_doorbell_isr(pACB
);
2875 host_interrupt_status
= readl(pmu
->host_int_status
);
2876 } while (host_interrupt_status
&
2877 (ARCMSR_ARC1214_OUTBOUND_POSTQUEUE_ISR
|
2878 ARCMSR_ARC1214_OUTBOUND_DOORBELL_ISR
));
2882 static irqreturn_t
arcmsr_hbaE_handle_isr(struct AdapterControlBlock
*pACB
)
2884 uint32_t host_interrupt_status
;
2885 struct MessageUnit_E __iomem
*pmu
= pACB
->pmuE
;
2887 host_interrupt_status
= readl(&pmu
->host_int_status
) &
2888 (ARCMSR_HBEMU_OUTBOUND_POSTQUEUE_ISR
|
2889 ARCMSR_HBEMU_OUTBOUND_DOORBELL_ISR
);
2890 if (!host_interrupt_status
)
2893 /* MU ioctl transfer doorbell interrupts*/
2894 if (host_interrupt_status
& ARCMSR_HBEMU_OUTBOUND_DOORBELL_ISR
) {
2895 arcmsr_hbaE_doorbell_isr(pACB
);
2897 /* MU post queue interrupts*/
2898 if (host_interrupt_status
& ARCMSR_HBEMU_OUTBOUND_POSTQUEUE_ISR
) {
2899 arcmsr_hbaE_postqueue_isr(pACB
);
2901 host_interrupt_status
= readl(&pmu
->host_int_status
);
2902 } while (host_interrupt_status
& (ARCMSR_HBEMU_OUTBOUND_POSTQUEUE_ISR
|
2903 ARCMSR_HBEMU_OUTBOUND_DOORBELL_ISR
));
2907 static irqreturn_t
arcmsr_hbaF_handle_isr(struct AdapterControlBlock
*pACB
)
2909 uint32_t host_interrupt_status
;
2910 struct MessageUnit_F __iomem
*phbcmu
= pACB
->pmuF
;
2912 host_interrupt_status
= readl(&phbcmu
->host_int_status
) &
2913 (ARCMSR_HBEMU_OUTBOUND_POSTQUEUE_ISR
|
2914 ARCMSR_HBEMU_OUTBOUND_DOORBELL_ISR
);
2915 if (!host_interrupt_status
)
2918 /* MU post queue interrupts*/
2919 if (host_interrupt_status
& ARCMSR_HBEMU_OUTBOUND_POSTQUEUE_ISR
)
2920 arcmsr_hbaF_postqueue_isr(pACB
);
2922 /* MU ioctl transfer doorbell interrupts*/
2923 if (host_interrupt_status
& ARCMSR_HBEMU_OUTBOUND_DOORBELL_ISR
)
2924 arcmsr_hbaE_doorbell_isr(pACB
);
2926 host_interrupt_status
= readl(&phbcmu
->host_int_status
);
2927 } while (host_interrupt_status
& (ARCMSR_HBEMU_OUTBOUND_POSTQUEUE_ISR
|
2928 ARCMSR_HBEMU_OUTBOUND_DOORBELL_ISR
));
2932 static irqreturn_t
arcmsr_interrupt(struct AdapterControlBlock
*acb
)
2934 switch (acb
->adapter_type
) {
2935 case ACB_ADAPTER_TYPE_A
:
2936 return arcmsr_hbaA_handle_isr(acb
);
2937 case ACB_ADAPTER_TYPE_B
:
2938 return arcmsr_hbaB_handle_isr(acb
);
2939 case ACB_ADAPTER_TYPE_C
:
2940 return arcmsr_hbaC_handle_isr(acb
);
2941 case ACB_ADAPTER_TYPE_D
:
2942 return arcmsr_hbaD_handle_isr(acb
);
2943 case ACB_ADAPTER_TYPE_E
:
2944 return arcmsr_hbaE_handle_isr(acb
);
2945 case ACB_ADAPTER_TYPE_F
:
2946 return arcmsr_hbaF_handle_isr(acb
);
2952 static void arcmsr_iop_parking(struct AdapterControlBlock
*acb
)
2955 /* stop adapter background rebuild */
2956 if (acb
->acb_flags
& ACB_F_MSG_START_BGRB
) {
2957 uint32_t intmask_org
;
2958 acb
->acb_flags
&= ~ACB_F_MSG_START_BGRB
;
2959 intmask_org
= arcmsr_disable_outbound_ints(acb
);
2960 arcmsr_stop_adapter_bgrb(acb
);
2961 arcmsr_flush_adapter_cache(acb
);
2962 arcmsr_enable_outbound_ints(acb
, intmask_org
);
2968 void arcmsr_clear_iop2drv_rqueue_buffer(struct AdapterControlBlock
*acb
)
2972 if (acb
->acb_flags
& ACB_F_IOPDATA_OVERFLOW
) {
2973 for (i
= 0; i
< 15; i
++) {
2974 if (acb
->acb_flags
& ACB_F_IOPDATA_OVERFLOW
) {
2975 acb
->acb_flags
&= ~ACB_F_IOPDATA_OVERFLOW
;
2976 acb
->rqbuf_getIndex
= 0;
2977 acb
->rqbuf_putIndex
= 0;
2978 arcmsr_iop_message_read(acb
);
2980 } else if (acb
->rqbuf_getIndex
!=
2981 acb
->rqbuf_putIndex
) {
2982 acb
->rqbuf_getIndex
= 0;
2983 acb
->rqbuf_putIndex
= 0;
2991 static int arcmsr_iop_message_xfer(struct AdapterControlBlock
*acb
,
2992 struct scsi_cmnd
*cmd
)
2995 unsigned short use_sg
;
2996 int retvalue
= 0, transfer_len
= 0;
2997 unsigned long flags
;
2998 struct CMD_MESSAGE_FIELD
*pcmdmessagefld
;
2999 uint32_t controlcode
= (uint32_t)cmd
->cmnd
[5] << 24 |
3000 (uint32_t)cmd
->cmnd
[6] << 16 |
3001 (uint32_t)cmd
->cmnd
[7] << 8 |
3002 (uint32_t)cmd
->cmnd
[8];
3003 struct scatterlist
*sg
;
3005 use_sg
= scsi_sg_count(cmd
);
3006 sg
= scsi_sglist(cmd
);
3007 buffer
= kmap_atomic(sg_page(sg
)) + sg
->offset
;
3009 retvalue
= ARCMSR_MESSAGE_FAIL
;
3012 transfer_len
+= sg
->length
;
3013 if (transfer_len
> sizeof(struct CMD_MESSAGE_FIELD
)) {
3014 retvalue
= ARCMSR_MESSAGE_FAIL
;
3015 pr_info("%s: ARCMSR_MESSAGE_FAIL!\n", __func__
);
3018 pcmdmessagefld
= (struct CMD_MESSAGE_FIELD
*)buffer
;
3019 switch (controlcode
) {
3020 case ARCMSR_MESSAGE_READ_RQBUFFER
: {
3021 unsigned char *ver_addr
;
3022 uint8_t *ptmpQbuffer
;
3023 uint32_t allxfer_len
= 0;
3024 ver_addr
= kmalloc(ARCMSR_API_DATA_BUFLEN
, GFP_ATOMIC
);
3026 retvalue
= ARCMSR_MESSAGE_FAIL
;
3027 pr_info("%s: memory not enough!\n", __func__
);
3030 ptmpQbuffer
= ver_addr
;
3031 spin_lock_irqsave(&acb
->rqbuffer_lock
, flags
);
3032 if (acb
->rqbuf_getIndex
!= acb
->rqbuf_putIndex
) {
3033 unsigned int tail
= acb
->rqbuf_getIndex
;
3034 unsigned int head
= acb
->rqbuf_putIndex
;
3035 unsigned int cnt_to_end
= CIRC_CNT_TO_END(head
, tail
, ARCMSR_MAX_QBUFFER
);
3037 allxfer_len
= CIRC_CNT(head
, tail
, ARCMSR_MAX_QBUFFER
);
3038 if (allxfer_len
> ARCMSR_API_DATA_BUFLEN
)
3039 allxfer_len
= ARCMSR_API_DATA_BUFLEN
;
3041 if (allxfer_len
<= cnt_to_end
)
3042 memcpy(ptmpQbuffer
, acb
->rqbuffer
+ tail
, allxfer_len
);
3044 memcpy(ptmpQbuffer
, acb
->rqbuffer
+ tail
, cnt_to_end
);
3045 memcpy(ptmpQbuffer
+ cnt_to_end
, acb
->rqbuffer
, allxfer_len
- cnt_to_end
);
3047 acb
->rqbuf_getIndex
= (acb
->rqbuf_getIndex
+ allxfer_len
) % ARCMSR_MAX_QBUFFER
;
3049 memcpy(pcmdmessagefld
->messagedatabuffer
, ver_addr
,
3051 if (acb
->acb_flags
& ACB_F_IOPDATA_OVERFLOW
) {
3052 struct QBUFFER __iomem
*prbuffer
;
3053 acb
->acb_flags
&= ~ACB_F_IOPDATA_OVERFLOW
;
3054 prbuffer
= arcmsr_get_iop_rqbuffer(acb
);
3055 if (arcmsr_Read_iop_rqbuffer_data(acb
, prbuffer
) == 0)
3056 acb
->acb_flags
|= ACB_F_IOPDATA_OVERFLOW
;
3058 spin_unlock_irqrestore(&acb
->rqbuffer_lock
, flags
);
3060 pcmdmessagefld
->cmdmessage
.Length
= allxfer_len
;
3061 if (acb
->fw_flag
== FW_DEADLOCK
)
3062 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3063 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
3065 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3066 ARCMSR_MESSAGE_RETURNCODE_OK
;
3069 case ARCMSR_MESSAGE_WRITE_WQBUFFER
: {
3070 unsigned char *ver_addr
;
3073 uint8_t *pQbuffer
, *ptmpuserbuffer
;
3075 user_len
= pcmdmessagefld
->cmdmessage
.Length
;
3076 if (user_len
> ARCMSR_API_DATA_BUFLEN
) {
3077 retvalue
= ARCMSR_MESSAGE_FAIL
;
3081 ver_addr
= kmalloc(ARCMSR_API_DATA_BUFLEN
, GFP_ATOMIC
);
3083 retvalue
= ARCMSR_MESSAGE_FAIL
;
3086 ptmpuserbuffer
= ver_addr
;
3088 memcpy(ptmpuserbuffer
,
3089 pcmdmessagefld
->messagedatabuffer
, user_len
);
3090 spin_lock_irqsave(&acb
->wqbuffer_lock
, flags
);
3091 if (acb
->wqbuf_putIndex
!= acb
->wqbuf_getIndex
) {
3092 struct SENSE_DATA
*sensebuffer
=
3093 (struct SENSE_DATA
*)cmd
->sense_buffer
;
3094 arcmsr_write_ioctldata2iop(acb
);
3095 /* has error report sensedata */
3096 sensebuffer
->ErrorCode
= SCSI_SENSE_CURRENT_ERRORS
;
3097 sensebuffer
->SenseKey
= ILLEGAL_REQUEST
;
3098 sensebuffer
->AdditionalSenseLength
= 0x0A;
3099 sensebuffer
->AdditionalSenseCode
= 0x20;
3100 sensebuffer
->Valid
= 1;
3101 retvalue
= ARCMSR_MESSAGE_FAIL
;
3103 pQbuffer
= &acb
->wqbuffer
[acb
->wqbuf_putIndex
];
3104 cnt2end
= ARCMSR_MAX_QBUFFER
- acb
->wqbuf_putIndex
;
3105 if (user_len
> cnt2end
) {
3106 memcpy(pQbuffer
, ptmpuserbuffer
, cnt2end
);
3107 ptmpuserbuffer
+= cnt2end
;
3108 user_len
-= cnt2end
;
3109 acb
->wqbuf_putIndex
= 0;
3110 pQbuffer
= acb
->wqbuffer
;
3112 memcpy(pQbuffer
, ptmpuserbuffer
, user_len
);
3113 acb
->wqbuf_putIndex
+= user_len
;
3114 acb
->wqbuf_putIndex
%= ARCMSR_MAX_QBUFFER
;
3115 if (acb
->acb_flags
& ACB_F_MESSAGE_WQBUFFER_CLEARED
) {
3117 ~ACB_F_MESSAGE_WQBUFFER_CLEARED
;
3118 arcmsr_write_ioctldata2iop(acb
);
3121 spin_unlock_irqrestore(&acb
->wqbuffer_lock
, flags
);
3123 if (acb
->fw_flag
== FW_DEADLOCK
)
3124 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3125 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
3127 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3128 ARCMSR_MESSAGE_RETURNCODE_OK
;
3131 case ARCMSR_MESSAGE_CLEAR_RQBUFFER
: {
3132 uint8_t *pQbuffer
= acb
->rqbuffer
;
3134 arcmsr_clear_iop2drv_rqueue_buffer(acb
);
3135 spin_lock_irqsave(&acb
->rqbuffer_lock
, flags
);
3136 acb
->acb_flags
|= ACB_F_MESSAGE_RQBUFFER_CLEARED
;
3137 acb
->rqbuf_getIndex
= 0;
3138 acb
->rqbuf_putIndex
= 0;
3139 memset(pQbuffer
, 0, ARCMSR_MAX_QBUFFER
);
3140 spin_unlock_irqrestore(&acb
->rqbuffer_lock
, flags
);
3141 if (acb
->fw_flag
== FW_DEADLOCK
)
3142 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3143 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
3145 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3146 ARCMSR_MESSAGE_RETURNCODE_OK
;
3149 case ARCMSR_MESSAGE_CLEAR_WQBUFFER
: {
3150 uint8_t *pQbuffer
= acb
->wqbuffer
;
3151 spin_lock_irqsave(&acb
->wqbuffer_lock
, flags
);
3152 acb
->acb_flags
|= (ACB_F_MESSAGE_WQBUFFER_CLEARED
|
3153 ACB_F_MESSAGE_WQBUFFER_READED
);
3154 acb
->wqbuf_getIndex
= 0;
3155 acb
->wqbuf_putIndex
= 0;
3156 memset(pQbuffer
, 0, ARCMSR_MAX_QBUFFER
);
3157 spin_unlock_irqrestore(&acb
->wqbuffer_lock
, flags
);
3158 if (acb
->fw_flag
== FW_DEADLOCK
)
3159 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3160 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
3162 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3163 ARCMSR_MESSAGE_RETURNCODE_OK
;
3166 case ARCMSR_MESSAGE_CLEAR_ALLQBUFFER
: {
3168 arcmsr_clear_iop2drv_rqueue_buffer(acb
);
3169 spin_lock_irqsave(&acb
->rqbuffer_lock
, flags
);
3170 acb
->acb_flags
|= ACB_F_MESSAGE_RQBUFFER_CLEARED
;
3171 acb
->rqbuf_getIndex
= 0;
3172 acb
->rqbuf_putIndex
= 0;
3173 pQbuffer
= acb
->rqbuffer
;
3174 memset(pQbuffer
, 0, sizeof(struct QBUFFER
));
3175 spin_unlock_irqrestore(&acb
->rqbuffer_lock
, flags
);
3176 spin_lock_irqsave(&acb
->wqbuffer_lock
, flags
);
3177 acb
->acb_flags
|= (ACB_F_MESSAGE_WQBUFFER_CLEARED
|
3178 ACB_F_MESSAGE_WQBUFFER_READED
);
3179 acb
->wqbuf_getIndex
= 0;
3180 acb
->wqbuf_putIndex
= 0;
3181 pQbuffer
= acb
->wqbuffer
;
3182 memset(pQbuffer
, 0, sizeof(struct QBUFFER
));
3183 spin_unlock_irqrestore(&acb
->wqbuffer_lock
, flags
);
3184 if (acb
->fw_flag
== FW_DEADLOCK
)
3185 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3186 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
3188 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3189 ARCMSR_MESSAGE_RETURNCODE_OK
;
3192 case ARCMSR_MESSAGE_RETURN_CODE_3F
: {
3193 if (acb
->fw_flag
== FW_DEADLOCK
)
3194 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3195 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
3197 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3198 ARCMSR_MESSAGE_RETURNCODE_3F
;
3201 case ARCMSR_MESSAGE_SAY_HELLO
: {
3202 int8_t *hello_string
= "Hello! I am ARCMSR";
3203 if (acb
->fw_flag
== FW_DEADLOCK
)
3204 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3205 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
3207 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3208 ARCMSR_MESSAGE_RETURNCODE_OK
;
3209 memcpy(pcmdmessagefld
->messagedatabuffer
,
3210 hello_string
, (int16_t)strlen(hello_string
));
3213 case ARCMSR_MESSAGE_SAY_GOODBYE
: {
3214 if (acb
->fw_flag
== FW_DEADLOCK
)
3215 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3216 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
3218 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3219 ARCMSR_MESSAGE_RETURNCODE_OK
;
3220 arcmsr_iop_parking(acb
);
3223 case ARCMSR_MESSAGE_FLUSH_ADAPTER_CACHE
: {
3224 if (acb
->fw_flag
== FW_DEADLOCK
)
3225 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3226 ARCMSR_MESSAGE_RETURNCODE_BUS_HANG_ON
;
3228 pcmdmessagefld
->cmdmessage
.ReturnCode
=
3229 ARCMSR_MESSAGE_RETURNCODE_OK
;
3230 arcmsr_flush_adapter_cache(acb
);
3234 retvalue
= ARCMSR_MESSAGE_FAIL
;
3235 pr_info("%s: unknown controlcode!\n", __func__
);
3239 struct scatterlist
*sg
= scsi_sglist(cmd
);
3240 kunmap_atomic(buffer
- sg
->offset
);
3245 static struct CommandControlBlock
*arcmsr_get_freeccb(struct AdapterControlBlock
*acb
)
3247 struct list_head
*head
;
3248 struct CommandControlBlock
*ccb
= NULL
;
3249 unsigned long flags
;
3251 spin_lock_irqsave(&acb
->ccblist_lock
, flags
);
3252 head
= &acb
->ccb_free_list
;
3253 if (!list_empty(head
)) {
3254 ccb
= list_entry(head
->next
, struct CommandControlBlock
, list
);
3255 list_del_init(&ccb
->list
);
3257 spin_unlock_irqrestore(&acb
->ccblist_lock
, flags
);
3260 spin_unlock_irqrestore(&acb
->ccblist_lock
, flags
);
3264 static void arcmsr_handle_virtual_command(struct AdapterControlBlock
*acb
,
3265 struct scsi_cmnd
*cmd
)
3267 switch (cmd
->cmnd
[0]) {
3269 unsigned char inqdata
[36];
3271 struct scatterlist
*sg
;
3273 if (cmd
->device
->lun
) {
3274 cmd
->result
= (DID_TIME_OUT
<< 16);
3278 inqdata
[0] = TYPE_PROCESSOR
;
3279 /* Periph Qualifier & Periph Dev Type */
3281 /* rem media bit & Dev Type Modifier */
3283 /* ISO, ECMA, & ANSI versions */
3285 /* length of additional data */
3286 memcpy(&inqdata
[8], "Areca ", 8);
3287 /* Vendor Identification */
3288 memcpy(&inqdata
[16], "RAID controller ", 16);
3289 /* Product Identification */
3290 memcpy(&inqdata
[32], "R001", 4); /* Product Revision */
3292 sg
= scsi_sglist(cmd
);
3293 buffer
= kmap_atomic(sg_page(sg
)) + sg
->offset
;
3295 memcpy(buffer
, inqdata
, sizeof(inqdata
));
3296 sg
= scsi_sglist(cmd
);
3297 kunmap_atomic(buffer
- sg
->offset
);
3304 if (arcmsr_iop_message_xfer(acb
, cmd
))
3305 cmd
->result
= (DID_ERROR
<< 16);
3314 static int arcmsr_queue_command_lck(struct scsi_cmnd
*cmd
)
3316 struct Scsi_Host
*host
= cmd
->device
->host
;
3317 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
3318 struct CommandControlBlock
*ccb
;
3319 int target
= cmd
->device
->id
;
3321 if (acb
->acb_flags
& ACB_F_ADAPTER_REMOVED
) {
3322 cmd
->result
= (DID_NO_CONNECT
<< 16);
3326 cmd
->host_scribble
= NULL
;
3329 /* virtual device for iop message transfer */
3330 arcmsr_handle_virtual_command(acb
, cmd
);
3333 ccb
= arcmsr_get_freeccb(acb
);
3335 return SCSI_MLQUEUE_HOST_BUSY
;
3336 if (arcmsr_build_ccb( acb
, ccb
, cmd
) == FAILED
) {
3337 cmd
->result
= (DID_ERROR
<< 16) | SAM_STAT_RESERVATION_CONFLICT
;
3341 arcmsr_post_ccb(acb
, ccb
);
3345 static DEF_SCSI_QCMD(arcmsr_queue_command
)
3347 static int arcmsr_slave_config(struct scsi_device
*sdev
)
3349 unsigned int dev_timeout
;
3351 dev_timeout
= sdev
->request_queue
->rq_timeout
;
3352 if ((cmd_timeout
> 0) && ((cmd_timeout
* HZ
) > dev_timeout
))
3353 blk_queue_rq_timeout(sdev
->request_queue
, cmd_timeout
* HZ
);
3357 static void arcmsr_get_adapter_config(struct AdapterControlBlock
*pACB
, uint32_t *rwbuffer
)
3360 uint32_t *acb_firm_model
= (uint32_t *)pACB
->firm_model
;
3361 uint32_t *acb_firm_version
= (uint32_t *)pACB
->firm_version
;
3362 uint32_t *acb_device_map
= (uint32_t *)pACB
->device_map
;
3363 uint32_t *firm_model
= &rwbuffer
[15];
3364 uint32_t *firm_version
= &rwbuffer
[17];
3365 uint32_t *device_map
= &rwbuffer
[21];
3369 *acb_firm_model
= readl(firm_model
);
3376 *acb_firm_version
= readl(firm_version
);
3383 *acb_device_map
= readl(device_map
);
3388 pACB
->signature
= readl(&rwbuffer
[0]);
3389 pACB
->firm_request_len
= readl(&rwbuffer
[1]);
3390 pACB
->firm_numbers_queue
= readl(&rwbuffer
[2]);
3391 pACB
->firm_sdram_size
= readl(&rwbuffer
[3]);
3392 pACB
->firm_hd_channels
= readl(&rwbuffer
[4]);
3393 pACB
->firm_cfg_version
= readl(&rwbuffer
[25]);
3394 if (pACB
->adapter_type
== ACB_ADAPTER_TYPE_F
)
3395 pACB
->firm_PicStatus
= readl(&rwbuffer
[30]);
3397 pACB
->firm_PicStatus
= 0;
3398 pr_notice("Areca RAID Controller%d: Model %s, F/W %s\n",
3399 pACB
->host
->host_no
,
3401 pACB
->firm_version
);
3404 static bool arcmsr_hbaA_get_config(struct AdapterControlBlock
*acb
)
3406 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
3408 arcmsr_wait_firmware_ready(acb
);
3409 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
3410 if (!arcmsr_hbaA_wait_msgint_ready(acb
)) {
3411 printk(KERN_NOTICE
"arcmsr%d: wait 'get adapter firmware \
3412 miscellaneous data' timeout \n", acb
->host
->host_no
);
3415 arcmsr_get_adapter_config(acb
, reg
->message_rwbuffer
);
3418 static bool arcmsr_hbaB_get_config(struct AdapterControlBlock
*acb
)
3420 struct MessageUnit_B
*reg
= acb
->pmuB
;
3422 arcmsr_wait_firmware_ready(acb
);
3423 writel(ARCMSR_MESSAGE_START_DRIVER_MODE
, reg
->drv2iop_doorbell
);
3424 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
3425 printk(KERN_ERR
"arcmsr%d: can't set driver mode.\n", acb
->host
->host_no
);
3428 writel(ARCMSR_MESSAGE_GET_CONFIG
, reg
->drv2iop_doorbell
);
3429 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
3430 printk(KERN_NOTICE
"arcmsr%d: wait 'get adapter firmware \
3431 miscellaneous data' timeout \n", acb
->host
->host_no
);
3434 arcmsr_get_adapter_config(acb
, reg
->message_rwbuffer
);
3438 static bool arcmsr_hbaC_get_config(struct AdapterControlBlock
*pACB
)
3440 uint32_t intmask_org
;
3441 struct MessageUnit_C __iomem
*reg
= pACB
->pmuC
;
3443 /* disable all outbound interrupt */
3444 intmask_org
= readl(®
->host_int_mask
); /* disable outbound message0 int */
3445 writel(intmask_org
|ARCMSR_HBCMU_ALL_INTMASKENABLE
, ®
->host_int_mask
);
3446 /* wait firmware ready */
3447 arcmsr_wait_firmware_ready(pACB
);
3448 /* post "get config" instruction */
3449 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
3450 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
3451 /* wait message ready */
3452 if (!arcmsr_hbaC_wait_msgint_ready(pACB
)) {
3453 printk(KERN_NOTICE
"arcmsr%d: wait 'get adapter firmware \
3454 miscellaneous data' timeout \n", pACB
->host
->host_no
);
3457 arcmsr_get_adapter_config(pACB
, reg
->msgcode_rwbuffer
);
3461 static bool arcmsr_hbaD_get_config(struct AdapterControlBlock
*acb
)
3463 struct MessageUnit_D
*reg
= acb
->pmuD
;
3465 if (readl(acb
->pmuD
->outbound_doorbell
) &
3466 ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
) {
3467 writel(ARCMSR_ARC1214_IOP2DRV_MESSAGE_CMD_DONE
,
3468 acb
->pmuD
->outbound_doorbell
);/*clear interrupt*/
3470 arcmsr_wait_firmware_ready(acb
);
3471 /* post "get config" instruction */
3472 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, reg
->inbound_msgaddr0
);
3473 /* wait message ready */
3474 if (!arcmsr_hbaD_wait_msgint_ready(acb
)) {
3475 pr_notice("arcmsr%d: wait get adapter firmware "
3476 "miscellaneous data timeout\n", acb
->host
->host_no
);
3479 arcmsr_get_adapter_config(acb
, reg
->msgcode_rwbuffer
);
3483 static bool arcmsr_hbaE_get_config(struct AdapterControlBlock
*pACB
)
3485 struct MessageUnit_E __iomem
*reg
= pACB
->pmuE
;
3486 uint32_t intmask_org
;
3488 /* disable all outbound interrupt */
3489 intmask_org
= readl(®
->host_int_mask
); /* disable outbound message0 int */
3490 writel(intmask_org
| ARCMSR_HBEMU_ALL_INTMASKENABLE
, ®
->host_int_mask
);
3491 /* wait firmware ready */
3492 arcmsr_wait_firmware_ready(pACB
);
3494 /* post "get config" instruction */
3495 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
3497 pACB
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_MESSAGE_CMD_DONE
;
3498 writel(pACB
->out_doorbell
, ®
->iobound_doorbell
);
3499 /* wait message ready */
3500 if (!arcmsr_hbaE_wait_msgint_ready(pACB
)) {
3501 pr_notice("arcmsr%d: wait get adapter firmware "
3502 "miscellaneous data timeout\n", pACB
->host
->host_no
);
3505 arcmsr_get_adapter_config(pACB
, reg
->msgcode_rwbuffer
);
3509 static bool arcmsr_hbaF_get_config(struct AdapterControlBlock
*pACB
)
3511 struct MessageUnit_F __iomem
*reg
= pACB
->pmuF
;
3512 uint32_t intmask_org
;
3514 /* disable all outbound interrupt */
3515 intmask_org
= readl(®
->host_int_mask
); /* disable outbound message0 int */
3516 writel(intmask_org
| ARCMSR_HBEMU_ALL_INTMASKENABLE
, ®
->host_int_mask
);
3517 /* wait firmware ready */
3518 arcmsr_wait_firmware_ready(pACB
);
3519 /* post "get config" instruction */
3520 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
3522 pACB
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_MESSAGE_CMD_DONE
;
3523 writel(pACB
->out_doorbell
, ®
->iobound_doorbell
);
3524 /* wait message ready */
3525 if (!arcmsr_hbaE_wait_msgint_ready(pACB
)) {
3526 pr_notice("arcmsr%d: wait get adapter firmware miscellaneous data timeout\n",
3527 pACB
->host
->host_no
);
3530 arcmsr_get_adapter_config(pACB
, pACB
->msgcode_rwbuffer
);
3534 static bool arcmsr_get_firmware_spec(struct AdapterControlBlock
*acb
)
3538 switch (acb
->adapter_type
) {
3539 case ACB_ADAPTER_TYPE_A
:
3540 rtn
= arcmsr_hbaA_get_config(acb
);
3542 case ACB_ADAPTER_TYPE_B
:
3543 rtn
= arcmsr_hbaB_get_config(acb
);
3545 case ACB_ADAPTER_TYPE_C
:
3546 rtn
= arcmsr_hbaC_get_config(acb
);
3548 case ACB_ADAPTER_TYPE_D
:
3549 rtn
= arcmsr_hbaD_get_config(acb
);
3551 case ACB_ADAPTER_TYPE_E
:
3552 rtn
= arcmsr_hbaE_get_config(acb
);
3554 case ACB_ADAPTER_TYPE_F
:
3555 rtn
= arcmsr_hbaF_get_config(acb
);
3560 acb
->maxOutstanding
= acb
->firm_numbers_queue
- 1;
3561 if (acb
->host
->can_queue
>= acb
->firm_numbers_queue
)
3562 acb
->host
->can_queue
= acb
->maxOutstanding
;
3564 acb
->maxOutstanding
= acb
->host
->can_queue
;
3565 acb
->maxFreeCCB
= acb
->host
->can_queue
;
3566 if (acb
->maxFreeCCB
< ARCMSR_MAX_FREECCB_NUM
)
3567 acb
->maxFreeCCB
+= 64;
3571 static int arcmsr_hbaA_polling_ccbdone(struct AdapterControlBlock
*acb
,
3572 struct CommandControlBlock
*poll_ccb
)
3574 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
3575 struct CommandControlBlock
*ccb
;
3576 struct ARCMSR_CDB
*arcmsr_cdb
;
3577 uint32_t flag_ccb
, outbound_intstatus
, poll_ccb_done
= 0, poll_count
= 0;
3580 unsigned long ccb_cdb_phy
;
3582 polling_hba_ccb_retry
:
3584 outbound_intstatus
= readl(®
->outbound_intstatus
) & acb
->outbound_int_enable
;
3585 writel(outbound_intstatus
, ®
->outbound_intstatus
);/*clear interrupt*/
3587 if ((flag_ccb
= readl(®
->outbound_queueport
)) == 0xFFFFFFFF) {
3593 if (poll_count
> 100){
3597 goto polling_hba_ccb_retry
;
3600 ccb_cdb_phy
= (flag_ccb
<< 5) & 0xffffffff;
3601 if (acb
->cdb_phyadd_hipart
)
3602 ccb_cdb_phy
= ccb_cdb_phy
| acb
->cdb_phyadd_hipart
;
3603 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ ccb_cdb_phy
);
3604 ccb
= container_of(arcmsr_cdb
, struct CommandControlBlock
, arcmsr_cdb
);
3605 poll_ccb_done
|= (ccb
== poll_ccb
) ? 1 : 0;
3606 if ((ccb
->acb
!= acb
) || (ccb
->startdone
!= ARCMSR_CCB_START
)) {
3607 if ((ccb
->startdone
== ARCMSR_CCB_ABORTED
) || (ccb
== poll_ccb
)) {
3608 printk(KERN_NOTICE
"arcmsr%d: scsi id = %d lun = %d ccb = '0x%p'"
3609 " poll command abort successfully \n"
3610 , acb
->host
->host_no
3611 , ccb
->pcmd
->device
->id
3612 , (u32
)ccb
->pcmd
->device
->lun
3614 ccb
->pcmd
->result
= DID_ABORT
<< 16;
3615 arcmsr_ccb_complete(ccb
);
3618 printk(KERN_NOTICE
"arcmsr%d: polling get an illegal ccb"
3619 " command done ccb = '0x%p'"
3620 "ccboutstandingcount = %d \n"
3621 , acb
->host
->host_no
3623 , atomic_read(&acb
->ccboutstandingcount
));
3626 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
3627 arcmsr_report_ccb_state(acb
, ccb
, error
);
3632 static int arcmsr_hbaB_polling_ccbdone(struct AdapterControlBlock
*acb
,
3633 struct CommandControlBlock
*poll_ccb
)
3635 struct MessageUnit_B
*reg
= acb
->pmuB
;
3636 struct ARCMSR_CDB
*arcmsr_cdb
;
3637 struct CommandControlBlock
*ccb
;
3638 uint32_t flag_ccb
, poll_ccb_done
= 0, poll_count
= 0;
3641 unsigned long ccb_cdb_phy
;
3643 polling_hbb_ccb_retry
:
3645 /* clear doorbell interrupt */
3646 writel(ARCMSR_DOORBELL_INT_CLEAR_PATTERN
, reg
->iop2drv_doorbell
);
3648 index
= reg
->doneq_index
;
3649 flag_ccb
= reg
->done_qbuffer
[index
];
3650 if (flag_ccb
== 0) {
3656 if (poll_count
> 100){
3660 goto polling_hbb_ccb_retry
;
3663 reg
->done_qbuffer
[index
] = 0;
3665 /*if last index number set it to 0 */
3666 index
%= ARCMSR_MAX_HBB_POSTQUEUE
;
3667 reg
->doneq_index
= index
;
3668 /* check if command done with no error*/
3669 ccb_cdb_phy
= (flag_ccb
<< 5) & 0xffffffff;
3670 if (acb
->cdb_phyadd_hipart
)
3671 ccb_cdb_phy
= ccb_cdb_phy
| acb
->cdb_phyadd_hipart
;
3672 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ ccb_cdb_phy
);
3673 ccb
= container_of(arcmsr_cdb
, struct CommandControlBlock
, arcmsr_cdb
);
3674 poll_ccb_done
|= (ccb
== poll_ccb
) ? 1 : 0;
3675 if ((ccb
->acb
!= acb
) || (ccb
->startdone
!= ARCMSR_CCB_START
)) {
3676 if ((ccb
->startdone
== ARCMSR_CCB_ABORTED
) || (ccb
== poll_ccb
)) {
3677 printk(KERN_NOTICE
"arcmsr%d: scsi id = %d lun = %d ccb = '0x%p'"
3678 " poll command abort successfully \n"
3680 ,ccb
->pcmd
->device
->id
3681 ,(u32
)ccb
->pcmd
->device
->lun
3683 ccb
->pcmd
->result
= DID_ABORT
<< 16;
3684 arcmsr_ccb_complete(ccb
);
3687 printk(KERN_NOTICE
"arcmsr%d: polling get an illegal ccb"
3688 " command done ccb = '0x%p'"
3689 "ccboutstandingcount = %d \n"
3690 , acb
->host
->host_no
3692 , atomic_read(&acb
->ccboutstandingcount
));
3695 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE0
) ? true : false;
3696 arcmsr_report_ccb_state(acb
, ccb
, error
);
3701 static int arcmsr_hbaC_polling_ccbdone(struct AdapterControlBlock
*acb
,
3702 struct CommandControlBlock
*poll_ccb
)
3704 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
3706 struct ARCMSR_CDB
*arcmsr_cdb
;
3708 struct CommandControlBlock
*pCCB
;
3709 uint32_t poll_ccb_done
= 0, poll_count
= 0;
3711 unsigned long ccb_cdb_phy
;
3713 polling_hbc_ccb_retry
:
3716 if ((readl(®
->host_int_status
) & ARCMSR_HBCMU_OUTBOUND_POSTQUEUE_ISR
) == 0) {
3717 if (poll_ccb_done
) {
3722 if (poll_count
> 100) {
3726 goto polling_hbc_ccb_retry
;
3729 flag_ccb
= readl(®
->outbound_queueport_low
);
3730 ccb_cdb_phy
= (flag_ccb
& 0xFFFFFFF0);
3731 if (acb
->cdb_phyadd_hipart
)
3732 ccb_cdb_phy
= ccb_cdb_phy
| acb
->cdb_phyadd_hipart
;
3733 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+ ccb_cdb_phy
);
3734 pCCB
= container_of(arcmsr_cdb
, struct CommandControlBlock
, arcmsr_cdb
);
3735 poll_ccb_done
|= (pCCB
== poll_ccb
) ? 1 : 0;
3736 /* check ifcommand done with no error*/
3737 if ((pCCB
->acb
!= acb
) || (pCCB
->startdone
!= ARCMSR_CCB_START
)) {
3738 if (pCCB
->startdone
== ARCMSR_CCB_ABORTED
) {
3739 printk(KERN_NOTICE
"arcmsr%d: scsi id = %d lun = %d ccb = '0x%p'"
3740 " poll command abort successfully \n"
3741 , acb
->host
->host_no
3742 , pCCB
->pcmd
->device
->id
3743 , (u32
)pCCB
->pcmd
->device
->lun
3745 pCCB
->pcmd
->result
= DID_ABORT
<< 16;
3746 arcmsr_ccb_complete(pCCB
);
3749 printk(KERN_NOTICE
"arcmsr%d: polling get an illegal ccb"
3750 " command done ccb = '0x%p'"
3751 "ccboutstandingcount = %d \n"
3752 , acb
->host
->host_no
3754 , atomic_read(&acb
->ccboutstandingcount
));
3757 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
) ? true : false;
3758 arcmsr_report_ccb_state(acb
, pCCB
, error
);
3763 static int arcmsr_hbaD_polling_ccbdone(struct AdapterControlBlock
*acb
,
3764 struct CommandControlBlock
*poll_ccb
)
3767 uint32_t poll_ccb_done
= 0, poll_count
= 0, flag_ccb
;
3768 int rtn
, doneq_index
, index_stripped
, outbound_write_pointer
, toggle
;
3769 unsigned long flags
, ccb_cdb_phy
;
3770 struct ARCMSR_CDB
*arcmsr_cdb
;
3771 struct CommandControlBlock
*pCCB
;
3772 struct MessageUnit_D
*pmu
= acb
->pmuD
;
3774 polling_hbaD_ccb_retry
:
3777 spin_lock_irqsave(&acb
->doneq_lock
, flags
);
3778 outbound_write_pointer
= pmu
->done_qbuffer
[0].addressLow
+ 1;
3779 doneq_index
= pmu
->doneq_index
;
3780 if ((outbound_write_pointer
& 0xFFF) == (doneq_index
& 0xFFF)) {
3781 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
3782 if (poll_ccb_done
) {
3787 if (poll_count
> 40) {
3791 goto polling_hbaD_ccb_retry
;
3794 toggle
= doneq_index
& 0x4000;
3795 index_stripped
= (doneq_index
& 0xFFF) + 1;
3796 index_stripped
%= ARCMSR_MAX_ARC1214_DONEQUEUE
;
3797 pmu
->doneq_index
= index_stripped
? (index_stripped
| toggle
) :
3798 ((toggle
^ 0x4000) + 1);
3799 doneq_index
= pmu
->doneq_index
;
3800 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
3801 flag_ccb
= pmu
->done_qbuffer
[doneq_index
& 0xFFF].addressLow
;
3802 ccb_cdb_phy
= (flag_ccb
& 0xFFFFFFF0);
3803 if (acb
->cdb_phyadd_hipart
)
3804 ccb_cdb_phy
= ccb_cdb_phy
| acb
->cdb_phyadd_hipart
;
3805 arcmsr_cdb
= (struct ARCMSR_CDB
*)(acb
->vir2phy_offset
+
3807 pCCB
= container_of(arcmsr_cdb
, struct CommandControlBlock
,
3809 poll_ccb_done
|= (pCCB
== poll_ccb
) ? 1 : 0;
3810 if ((pCCB
->acb
!= acb
) ||
3811 (pCCB
->startdone
!= ARCMSR_CCB_START
)) {
3812 if (pCCB
->startdone
== ARCMSR_CCB_ABORTED
) {
3813 pr_notice("arcmsr%d: scsi id = %d "
3814 "lun = %d ccb = '0x%p' poll command "
3815 "abort successfully\n"
3816 , acb
->host
->host_no
3817 , pCCB
->pcmd
->device
->id
3818 , (u32
)pCCB
->pcmd
->device
->lun
3820 pCCB
->pcmd
->result
= DID_ABORT
<< 16;
3821 arcmsr_ccb_complete(pCCB
);
3824 pr_notice("arcmsr%d: polling an illegal "
3825 "ccb command done ccb = '0x%p' "
3826 "ccboutstandingcount = %d\n"
3827 , acb
->host
->host_no
3829 , atomic_read(&acb
->ccboutstandingcount
));
3832 error
= (flag_ccb
& ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
)
3834 arcmsr_report_ccb_state(acb
, pCCB
, error
);
3839 static int arcmsr_hbaE_polling_ccbdone(struct AdapterControlBlock
*acb
,
3840 struct CommandControlBlock
*poll_ccb
)
3843 uint32_t poll_ccb_done
= 0, poll_count
= 0, doneq_index
;
3845 unsigned long flags
;
3847 struct CommandControlBlock
*pCCB
;
3848 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
3850 polling_hbaC_ccb_retry
:
3853 spin_lock_irqsave(&acb
->doneq_lock
, flags
);
3854 doneq_index
= acb
->doneq_index
;
3855 if ((readl(®
->reply_post_producer_index
) & 0xFFFF) ==
3857 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
3858 if (poll_ccb_done
) {
3863 if (poll_count
> 40) {
3867 goto polling_hbaC_ccb_retry
;
3870 cmdSMID
= acb
->pCompletionQ
[doneq_index
].cmdSMID
;
3872 if (doneq_index
>= acb
->completionQ_entry
)
3874 acb
->doneq_index
= doneq_index
;
3875 spin_unlock_irqrestore(&acb
->doneq_lock
, flags
);
3876 pCCB
= acb
->pccb_pool
[cmdSMID
];
3877 poll_ccb_done
|= (pCCB
== poll_ccb
) ? 1 : 0;
3878 /* check if command done with no error*/
3879 if ((pCCB
->acb
!= acb
) || (pCCB
->startdone
!= ARCMSR_CCB_START
)) {
3880 if (pCCB
->startdone
== ARCMSR_CCB_ABORTED
) {
3881 pr_notice("arcmsr%d: scsi id = %d "
3882 "lun = %d ccb = '0x%p' poll command "
3883 "abort successfully\n"
3884 , acb
->host
->host_no
3885 , pCCB
->pcmd
->device
->id
3886 , (u32
)pCCB
->pcmd
->device
->lun
3888 pCCB
->pcmd
->result
= DID_ABORT
<< 16;
3889 arcmsr_ccb_complete(pCCB
);
3892 pr_notice("arcmsr%d: polling an illegal "
3893 "ccb command done ccb = '0x%p' "
3894 "ccboutstandingcount = %d\n"
3895 , acb
->host
->host_no
3897 , atomic_read(&acb
->ccboutstandingcount
));
3900 error
= (acb
->pCompletionQ
[doneq_index
].cmdFlag
&
3901 ARCMSR_CCBREPLY_FLAG_ERROR_MODE1
) ? true : false;
3902 arcmsr_report_ccb_state(acb
, pCCB
, error
);
3904 writel(doneq_index
, ®
->reply_post_consumer_index
);
3908 static int arcmsr_polling_ccbdone(struct AdapterControlBlock
*acb
,
3909 struct CommandControlBlock
*poll_ccb
)
3912 switch (acb
->adapter_type
) {
3914 case ACB_ADAPTER_TYPE_A
:
3915 rtn
= arcmsr_hbaA_polling_ccbdone(acb
, poll_ccb
);
3917 case ACB_ADAPTER_TYPE_B
:
3918 rtn
= arcmsr_hbaB_polling_ccbdone(acb
, poll_ccb
);
3920 case ACB_ADAPTER_TYPE_C
:
3921 rtn
= arcmsr_hbaC_polling_ccbdone(acb
, poll_ccb
);
3923 case ACB_ADAPTER_TYPE_D
:
3924 rtn
= arcmsr_hbaD_polling_ccbdone(acb
, poll_ccb
);
3926 case ACB_ADAPTER_TYPE_E
:
3927 case ACB_ADAPTER_TYPE_F
:
3928 rtn
= arcmsr_hbaE_polling_ccbdone(acb
, poll_ccb
);
3934 static void arcmsr_set_iop_datetime(struct timer_list
*t
)
3936 struct AdapterControlBlock
*pacb
= from_timer(pacb
, t
, refresh_timer
);
3937 unsigned int next_time
;
3951 uint32_t msg_time
[2];
3955 time64_to_tm(ktime_get_real_seconds(), -sys_tz
.tz_minuteswest
* 60, &tm
);
3957 datetime
.a
.signature
= 0x55AA;
3958 datetime
.a
.year
= tm
.tm_year
- 100; /* base 2000 instead of 1900 */
3959 datetime
.a
.month
= tm
.tm_mon
;
3960 datetime
.a
.date
= tm
.tm_mday
;
3961 datetime
.a
.hour
= tm
.tm_hour
;
3962 datetime
.a
.minute
= tm
.tm_min
;
3963 datetime
.a
.second
= tm
.tm_sec
;
3965 switch (pacb
->adapter_type
) {
3966 case ACB_ADAPTER_TYPE_A
: {
3967 struct MessageUnit_A __iomem
*reg
= pacb
->pmuA
;
3968 writel(datetime
.b
.msg_time
[0], ®
->message_rwbuffer
[0]);
3969 writel(datetime
.b
.msg_time
[1], ®
->message_rwbuffer
[1]);
3970 writel(ARCMSR_INBOUND_MESG0_SYNC_TIMER
, ®
->inbound_msgaddr0
);
3973 case ACB_ADAPTER_TYPE_B
: {
3974 uint32_t __iomem
*rwbuffer
;
3975 struct MessageUnit_B
*reg
= pacb
->pmuB
;
3976 rwbuffer
= reg
->message_rwbuffer
;
3977 writel(datetime
.b
.msg_time
[0], rwbuffer
++);
3978 writel(datetime
.b
.msg_time
[1], rwbuffer
++);
3979 writel(ARCMSR_MESSAGE_SYNC_TIMER
, reg
->drv2iop_doorbell
);
3982 case ACB_ADAPTER_TYPE_C
: {
3983 struct MessageUnit_C __iomem
*reg
= pacb
->pmuC
;
3984 writel(datetime
.b
.msg_time
[0], ®
->msgcode_rwbuffer
[0]);
3985 writel(datetime
.b
.msg_time
[1], ®
->msgcode_rwbuffer
[1]);
3986 writel(ARCMSR_INBOUND_MESG0_SYNC_TIMER
, ®
->inbound_msgaddr0
);
3987 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
3990 case ACB_ADAPTER_TYPE_D
: {
3991 uint32_t __iomem
*rwbuffer
;
3992 struct MessageUnit_D
*reg
= pacb
->pmuD
;
3993 rwbuffer
= reg
->msgcode_rwbuffer
;
3994 writel(datetime
.b
.msg_time
[0], rwbuffer
++);
3995 writel(datetime
.b
.msg_time
[1], rwbuffer
++);
3996 writel(ARCMSR_INBOUND_MESG0_SYNC_TIMER
, reg
->inbound_msgaddr0
);
3999 case ACB_ADAPTER_TYPE_E
: {
4000 struct MessageUnit_E __iomem
*reg
= pacb
->pmuE
;
4001 writel(datetime
.b
.msg_time
[0], ®
->msgcode_rwbuffer
[0]);
4002 writel(datetime
.b
.msg_time
[1], ®
->msgcode_rwbuffer
[1]);
4003 writel(ARCMSR_INBOUND_MESG0_SYNC_TIMER
, ®
->inbound_msgaddr0
);
4004 pacb
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_MESSAGE_CMD_DONE
;
4005 writel(pacb
->out_doorbell
, ®
->iobound_doorbell
);
4008 case ACB_ADAPTER_TYPE_F
: {
4009 struct MessageUnit_F __iomem
*reg
= pacb
->pmuF
;
4011 pacb
->msgcode_rwbuffer
[0] = datetime
.b
.msg_time
[0];
4012 pacb
->msgcode_rwbuffer
[1] = datetime
.b
.msg_time
[1];
4013 writel(ARCMSR_INBOUND_MESG0_SYNC_TIMER
, ®
->inbound_msgaddr0
);
4014 pacb
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_MESSAGE_CMD_DONE
;
4015 writel(pacb
->out_doorbell
, ®
->iobound_doorbell
);
4019 if (sys_tz
.tz_minuteswest
)
4020 next_time
= ARCMSR_HOURS
;
4022 next_time
= ARCMSR_MINUTES
;
4023 mod_timer(&pacb
->refresh_timer
, jiffies
+ msecs_to_jiffies(next_time
));
4026 static int arcmsr_iop_confirm(struct AdapterControlBlock
*acb
)
4028 uint32_t cdb_phyaddr
, cdb_phyaddr_hi32
;
4029 dma_addr_t dma_coherent_handle
;
4032 ********************************************************************
4033 ** here we need to tell iop 331 our freeccb.HighPart
4034 ** if freeccb.HighPart is not zero
4035 ********************************************************************
4037 switch (acb
->adapter_type
) {
4038 case ACB_ADAPTER_TYPE_B
:
4039 case ACB_ADAPTER_TYPE_D
:
4040 dma_coherent_handle
= acb
->dma_coherent_handle2
;
4042 case ACB_ADAPTER_TYPE_E
:
4043 case ACB_ADAPTER_TYPE_F
:
4044 dma_coherent_handle
= acb
->dma_coherent_handle
+
4045 offsetof(struct CommandControlBlock
, arcmsr_cdb
);
4048 dma_coherent_handle
= acb
->dma_coherent_handle
;
4051 cdb_phyaddr
= lower_32_bits(dma_coherent_handle
);
4052 cdb_phyaddr_hi32
= upper_32_bits(dma_coherent_handle
);
4053 acb
->cdb_phyaddr_hi32
= cdb_phyaddr_hi32
;
4054 acb
->cdb_phyadd_hipart
= ((uint64_t)cdb_phyaddr_hi32
) << 32;
4056 ***********************************************************************
4057 ** if adapter type B, set window of "post command Q"
4058 ***********************************************************************
4060 switch (acb
->adapter_type
) {
4062 case ACB_ADAPTER_TYPE_A
: {
4063 if (cdb_phyaddr_hi32
!= 0) {
4064 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
4065 writel(ARCMSR_SIGNATURE_SET_CONFIG
, \
4066 ®
->message_rwbuffer
[0]);
4067 writel(cdb_phyaddr_hi32
, ®
->message_rwbuffer
[1]);
4068 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG
, \
4069 ®
->inbound_msgaddr0
);
4070 if (!arcmsr_hbaA_wait_msgint_ready(acb
)) {
4071 printk(KERN_NOTICE
"arcmsr%d: ""set ccb high \
4072 part physical address timeout\n",
4073 acb
->host
->host_no
);
4080 case ACB_ADAPTER_TYPE_B
: {
4081 uint32_t __iomem
*rwbuffer
;
4083 struct MessageUnit_B
*reg
= acb
->pmuB
;
4084 reg
->postq_index
= 0;
4085 reg
->doneq_index
= 0;
4086 writel(ARCMSR_MESSAGE_SET_POST_WINDOW
, reg
->drv2iop_doorbell
);
4087 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
4088 printk(KERN_NOTICE
"arcmsr%d: cannot set driver mode\n", \
4089 acb
->host
->host_no
);
4092 rwbuffer
= reg
->message_rwbuffer
;
4093 /* driver "set config" signature */
4094 writel(ARCMSR_SIGNATURE_SET_CONFIG
, rwbuffer
++);
4095 /* normal should be zero */
4096 writel(cdb_phyaddr_hi32
, rwbuffer
++);
4097 /* postQ size (256 + 8)*4 */
4098 writel(cdb_phyaddr
, rwbuffer
++);
4099 /* doneQ size (256 + 8)*4 */
4100 writel(cdb_phyaddr
+ 1056, rwbuffer
++);
4101 /* ccb maxQ size must be --> [(256 + 8)*4]*/
4102 writel(1056, rwbuffer
);
4104 writel(ARCMSR_MESSAGE_SET_CONFIG
, reg
->drv2iop_doorbell
);
4105 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
4106 printk(KERN_NOTICE
"arcmsr%d: 'set command Q window' \
4107 timeout \n",acb
->host
->host_no
);
4110 writel(ARCMSR_MESSAGE_START_DRIVER_MODE
, reg
->drv2iop_doorbell
);
4111 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
4112 pr_err("arcmsr%d: can't set driver mode.\n",
4113 acb
->host
->host_no
);
4118 case ACB_ADAPTER_TYPE_C
: {
4119 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
4121 printk(KERN_NOTICE
"arcmsr%d: cdb_phyaddr_hi32=0x%x\n",
4122 acb
->adapter_index
, cdb_phyaddr_hi32
);
4123 writel(ARCMSR_SIGNATURE_SET_CONFIG
, ®
->msgcode_rwbuffer
[0]);
4124 writel(cdb_phyaddr_hi32
, ®
->msgcode_rwbuffer
[1]);
4125 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG
, ®
->inbound_msgaddr0
);
4126 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
4127 if (!arcmsr_hbaC_wait_msgint_ready(acb
)) {
4128 printk(KERN_NOTICE
"arcmsr%d: 'set command Q window' \
4129 timeout \n", acb
->host
->host_no
);
4134 case ACB_ADAPTER_TYPE_D
: {
4135 uint32_t __iomem
*rwbuffer
;
4136 struct MessageUnit_D
*reg
= acb
->pmuD
;
4137 reg
->postq_index
= 0;
4138 reg
->doneq_index
= 0;
4139 rwbuffer
= reg
->msgcode_rwbuffer
;
4140 writel(ARCMSR_SIGNATURE_SET_CONFIG
, rwbuffer
++);
4141 writel(cdb_phyaddr_hi32
, rwbuffer
++);
4142 writel(cdb_phyaddr
, rwbuffer
++);
4143 writel(cdb_phyaddr
+ (ARCMSR_MAX_ARC1214_POSTQUEUE
*
4144 sizeof(struct InBound_SRB
)), rwbuffer
++);
4145 writel(0x100, rwbuffer
);
4146 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG
, reg
->inbound_msgaddr0
);
4147 if (!arcmsr_hbaD_wait_msgint_ready(acb
)) {
4148 pr_notice("arcmsr%d: 'set command Q window' timeout\n",
4149 acb
->host
->host_no
);
4154 case ACB_ADAPTER_TYPE_E
: {
4155 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
4156 writel(ARCMSR_SIGNATURE_SET_CONFIG
, ®
->msgcode_rwbuffer
[0]);
4157 writel(ARCMSR_SIGNATURE_1884
, ®
->msgcode_rwbuffer
[1]);
4158 writel(cdb_phyaddr
, ®
->msgcode_rwbuffer
[2]);
4159 writel(cdb_phyaddr_hi32
, ®
->msgcode_rwbuffer
[3]);
4160 writel(acb
->ccbsize
, ®
->msgcode_rwbuffer
[4]);
4161 writel(lower_32_bits(acb
->dma_coherent_handle2
), ®
->msgcode_rwbuffer
[5]);
4162 writel(upper_32_bits(acb
->dma_coherent_handle2
), ®
->msgcode_rwbuffer
[6]);
4163 writel(acb
->ioqueue_size
, ®
->msgcode_rwbuffer
[7]);
4164 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG
, ®
->inbound_msgaddr0
);
4165 acb
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_MESSAGE_CMD_DONE
;
4166 writel(acb
->out_doorbell
, ®
->iobound_doorbell
);
4167 if (!arcmsr_hbaE_wait_msgint_ready(acb
)) {
4168 pr_notice("arcmsr%d: 'set command Q window' timeout \n",
4169 acb
->host
->host_no
);
4174 case ACB_ADAPTER_TYPE_F
: {
4175 struct MessageUnit_F __iomem
*reg
= acb
->pmuF
;
4177 acb
->msgcode_rwbuffer
[0] = ARCMSR_SIGNATURE_SET_CONFIG
;
4178 acb
->msgcode_rwbuffer
[1] = ARCMSR_SIGNATURE_1886
;
4179 acb
->msgcode_rwbuffer
[2] = cdb_phyaddr
;
4180 acb
->msgcode_rwbuffer
[3] = cdb_phyaddr_hi32
;
4181 acb
->msgcode_rwbuffer
[4] = acb
->ccbsize
;
4182 acb
->msgcode_rwbuffer
[5] = lower_32_bits(acb
->dma_coherent_handle2
);
4183 acb
->msgcode_rwbuffer
[6] = upper_32_bits(acb
->dma_coherent_handle2
);
4184 acb
->msgcode_rwbuffer
[7] = acb
->completeQ_size
;
4185 if (acb
->xor_mega
) {
4186 acb
->msgcode_rwbuffer
[8] = 0x455AA; //Linux init 2
4187 acb
->msgcode_rwbuffer
[9] = 0;
4188 acb
->msgcode_rwbuffer
[10] = lower_32_bits(acb
->xorPhys
);
4189 acb
->msgcode_rwbuffer
[11] = upper_32_bits(acb
->xorPhys
);
4191 writel(ARCMSR_INBOUND_MESG0_SET_CONFIG
, ®
->inbound_msgaddr0
);
4192 acb
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_MESSAGE_CMD_DONE
;
4193 writel(acb
->out_doorbell
, ®
->iobound_doorbell
);
4194 if (!arcmsr_hbaE_wait_msgint_ready(acb
)) {
4195 pr_notice("arcmsr%d: 'set command Q window' timeout\n",
4196 acb
->host
->host_no
);
4205 static void arcmsr_wait_firmware_ready(struct AdapterControlBlock
*acb
)
4207 uint32_t firmware_state
= 0;
4208 switch (acb
->adapter_type
) {
4210 case ACB_ADAPTER_TYPE_A
: {
4211 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
4213 if (!(acb
->acb_flags
& ACB_F_IOP_INITED
))
4215 firmware_state
= readl(®
->outbound_msgaddr1
);
4216 } while ((firmware_state
& ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK
) == 0);
4220 case ACB_ADAPTER_TYPE_B
: {
4221 struct MessageUnit_B
*reg
= acb
->pmuB
;
4223 if (!(acb
->acb_flags
& ACB_F_IOP_INITED
))
4225 firmware_state
= readl(reg
->iop2drv_doorbell
);
4226 } while ((firmware_state
& ARCMSR_MESSAGE_FIRMWARE_OK
) == 0);
4227 writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT
, reg
->drv2iop_doorbell
);
4230 case ACB_ADAPTER_TYPE_C
: {
4231 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
4233 if (!(acb
->acb_flags
& ACB_F_IOP_INITED
))
4235 firmware_state
= readl(®
->outbound_msgaddr1
);
4236 } while ((firmware_state
& ARCMSR_HBCMU_MESSAGE_FIRMWARE_OK
) == 0);
4239 case ACB_ADAPTER_TYPE_D
: {
4240 struct MessageUnit_D
*reg
= acb
->pmuD
;
4242 if (!(acb
->acb_flags
& ACB_F_IOP_INITED
))
4244 firmware_state
= readl(reg
->outbound_msgaddr1
);
4245 } while ((firmware_state
&
4246 ARCMSR_ARC1214_MESSAGE_FIRMWARE_OK
) == 0);
4249 case ACB_ADAPTER_TYPE_E
:
4250 case ACB_ADAPTER_TYPE_F
: {
4251 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
4253 if (!(acb
->acb_flags
& ACB_F_IOP_INITED
))
4255 firmware_state
= readl(®
->outbound_msgaddr1
);
4256 } while ((firmware_state
& ARCMSR_HBEMU_MESSAGE_FIRMWARE_OK
) == 0);
4262 static void arcmsr_request_device_map(struct timer_list
*t
)
4264 struct AdapterControlBlock
*acb
= from_timer(acb
, t
, eternal_timer
);
4265 if (acb
->acb_flags
& (ACB_F_MSG_GET_CONFIG
| ACB_F_BUS_RESET
| ACB_F_ABORT
)) {
4266 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
4268 acb
->fw_flag
= FW_NORMAL
;
4269 switch (acb
->adapter_type
) {
4270 case ACB_ADAPTER_TYPE_A
: {
4271 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
4272 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
4275 case ACB_ADAPTER_TYPE_B
: {
4276 struct MessageUnit_B
*reg
= acb
->pmuB
;
4277 writel(ARCMSR_MESSAGE_GET_CONFIG
, reg
->drv2iop_doorbell
);
4280 case ACB_ADAPTER_TYPE_C
: {
4281 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
4282 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
4283 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, ®
->inbound_doorbell
);
4286 case ACB_ADAPTER_TYPE_D
: {
4287 struct MessageUnit_D
*reg
= acb
->pmuD
;
4288 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, reg
->inbound_msgaddr0
);
4291 case ACB_ADAPTER_TYPE_E
: {
4292 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
4293 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
4294 acb
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_MESSAGE_CMD_DONE
;
4295 writel(acb
->out_doorbell
, ®
->iobound_doorbell
);
4298 case ACB_ADAPTER_TYPE_F
: {
4299 struct MessageUnit_F __iomem
*reg
= acb
->pmuF
;
4300 uint32_t outMsg1
= readl(®
->outbound_msgaddr1
);
4302 if (!(outMsg1
& ARCMSR_HBFMU_MESSAGE_FIRMWARE_OK
) ||
4303 (outMsg1
& ARCMSR_HBFMU_MESSAGE_NO_VOLUME_CHANGE
))
4305 writel(ARCMSR_INBOUND_MESG0_GET_CONFIG
, ®
->inbound_msgaddr0
);
4306 acb
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_MESSAGE_CMD_DONE
;
4307 writel(acb
->out_doorbell
, ®
->iobound_doorbell
);
4313 acb
->acb_flags
|= ACB_F_MSG_GET_CONFIG
;
4315 mod_timer(&acb
->eternal_timer
, jiffies
+ msecs_to_jiffies(6 * HZ
));
4319 static void arcmsr_hbaA_start_bgrb(struct AdapterControlBlock
*acb
)
4321 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
4322 acb
->acb_flags
|= ACB_F_MSG_START_BGRB
;
4323 writel(ARCMSR_INBOUND_MESG0_START_BGRB
, ®
->inbound_msgaddr0
);
4324 if (!arcmsr_hbaA_wait_msgint_ready(acb
)) {
4325 printk(KERN_NOTICE
"arcmsr%d: wait 'start adapter background \
4326 rebuild' timeout \n", acb
->host
->host_no
);
4330 static void arcmsr_hbaB_start_bgrb(struct AdapterControlBlock
*acb
)
4332 struct MessageUnit_B
*reg
= acb
->pmuB
;
4333 acb
->acb_flags
|= ACB_F_MSG_START_BGRB
;
4334 writel(ARCMSR_MESSAGE_START_BGRB
, reg
->drv2iop_doorbell
);
4335 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
4336 printk(KERN_NOTICE
"arcmsr%d: wait 'start adapter background \
4337 rebuild' timeout \n",acb
->host
->host_no
);
4341 static void arcmsr_hbaC_start_bgrb(struct AdapterControlBlock
*pACB
)
4343 struct MessageUnit_C __iomem
*phbcmu
= pACB
->pmuC
;
4344 pACB
->acb_flags
|= ACB_F_MSG_START_BGRB
;
4345 writel(ARCMSR_INBOUND_MESG0_START_BGRB
, &phbcmu
->inbound_msgaddr0
);
4346 writel(ARCMSR_HBCMU_DRV2IOP_MESSAGE_CMD_DONE
, &phbcmu
->inbound_doorbell
);
4347 if (!arcmsr_hbaC_wait_msgint_ready(pACB
)) {
4348 printk(KERN_NOTICE
"arcmsr%d: wait 'start adapter background \
4349 rebuild' timeout \n", pACB
->host
->host_no
);
4354 static void arcmsr_hbaD_start_bgrb(struct AdapterControlBlock
*pACB
)
4356 struct MessageUnit_D
*pmu
= pACB
->pmuD
;
4358 pACB
->acb_flags
|= ACB_F_MSG_START_BGRB
;
4359 writel(ARCMSR_INBOUND_MESG0_START_BGRB
, pmu
->inbound_msgaddr0
);
4360 if (!arcmsr_hbaD_wait_msgint_ready(pACB
)) {
4361 pr_notice("arcmsr%d: wait 'start adapter "
4362 "background rebuild' timeout\n", pACB
->host
->host_no
);
4366 static void arcmsr_hbaE_start_bgrb(struct AdapterControlBlock
*pACB
)
4368 struct MessageUnit_E __iomem
*pmu
= pACB
->pmuE
;
4370 pACB
->acb_flags
|= ACB_F_MSG_START_BGRB
;
4371 writel(ARCMSR_INBOUND_MESG0_START_BGRB
, &pmu
->inbound_msgaddr0
);
4372 pACB
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_MESSAGE_CMD_DONE
;
4373 writel(pACB
->out_doorbell
, &pmu
->iobound_doorbell
);
4374 if (!arcmsr_hbaE_wait_msgint_ready(pACB
)) {
4375 pr_notice("arcmsr%d: wait 'start adapter "
4376 "background rebuild' timeout \n", pACB
->host
->host_no
);
4380 static void arcmsr_start_adapter_bgrb(struct AdapterControlBlock
*acb
)
4382 switch (acb
->adapter_type
) {
4383 case ACB_ADAPTER_TYPE_A
:
4384 arcmsr_hbaA_start_bgrb(acb
);
4386 case ACB_ADAPTER_TYPE_B
:
4387 arcmsr_hbaB_start_bgrb(acb
);
4389 case ACB_ADAPTER_TYPE_C
:
4390 arcmsr_hbaC_start_bgrb(acb
);
4392 case ACB_ADAPTER_TYPE_D
:
4393 arcmsr_hbaD_start_bgrb(acb
);
4395 case ACB_ADAPTER_TYPE_E
:
4396 case ACB_ADAPTER_TYPE_F
:
4397 arcmsr_hbaE_start_bgrb(acb
);
4402 static void arcmsr_clear_doorbell_queue_buffer(struct AdapterControlBlock
*acb
)
4404 switch (acb
->adapter_type
) {
4405 case ACB_ADAPTER_TYPE_A
: {
4406 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
4407 uint32_t outbound_doorbell
;
4408 /* empty doorbell Qbuffer if door bell ringed */
4409 outbound_doorbell
= readl(®
->outbound_doorbell
);
4410 /*clear doorbell interrupt */
4411 writel(outbound_doorbell
, ®
->outbound_doorbell
);
4412 writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK
, ®
->inbound_doorbell
);
4416 case ACB_ADAPTER_TYPE_B
: {
4417 struct MessageUnit_B
*reg
= acb
->pmuB
;
4418 uint32_t outbound_doorbell
, i
;
4419 writel(ARCMSR_DOORBELL_INT_CLEAR_PATTERN
, reg
->iop2drv_doorbell
);
4420 writel(ARCMSR_DRV2IOP_DATA_READ_OK
, reg
->drv2iop_doorbell
);
4421 /* let IOP know data has been read */
4422 for(i
=0; i
< 200; i
++) {
4424 outbound_doorbell
= readl(reg
->iop2drv_doorbell
);
4425 if( outbound_doorbell
& ARCMSR_IOP2DRV_DATA_WRITE_OK
) {
4426 writel(ARCMSR_DOORBELL_INT_CLEAR_PATTERN
, reg
->iop2drv_doorbell
);
4427 writel(ARCMSR_DRV2IOP_DATA_READ_OK
, reg
->drv2iop_doorbell
);
4433 case ACB_ADAPTER_TYPE_C
: {
4434 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
4435 uint32_t outbound_doorbell
, i
;
4436 /* empty doorbell Qbuffer if door bell ringed */
4437 outbound_doorbell
= readl(®
->outbound_doorbell
);
4438 writel(outbound_doorbell
, ®
->outbound_doorbell_clear
);
4439 writel(ARCMSR_HBCMU_DRV2IOP_DATA_READ_OK
, ®
->inbound_doorbell
);
4440 for (i
= 0; i
< 200; i
++) {
4442 outbound_doorbell
= readl(®
->outbound_doorbell
);
4443 if (outbound_doorbell
&
4444 ARCMSR_HBCMU_IOP2DRV_DATA_WRITE_OK
) {
4445 writel(outbound_doorbell
,
4446 ®
->outbound_doorbell_clear
);
4447 writel(ARCMSR_HBCMU_DRV2IOP_DATA_READ_OK
,
4448 ®
->inbound_doorbell
);
4454 case ACB_ADAPTER_TYPE_D
: {
4455 struct MessageUnit_D
*reg
= acb
->pmuD
;
4456 uint32_t outbound_doorbell
, i
;
4457 /* empty doorbell Qbuffer if door bell ringed */
4458 outbound_doorbell
= readl(reg
->outbound_doorbell
);
4459 writel(outbound_doorbell
, reg
->outbound_doorbell
);
4460 writel(ARCMSR_ARC1214_DRV2IOP_DATA_OUT_READ
,
4461 reg
->inbound_doorbell
);
4462 for (i
= 0; i
< 200; i
++) {
4464 outbound_doorbell
= readl(reg
->outbound_doorbell
);
4465 if (outbound_doorbell
&
4466 ARCMSR_ARC1214_IOP2DRV_DATA_WRITE_OK
) {
4467 writel(outbound_doorbell
,
4468 reg
->outbound_doorbell
);
4469 writel(ARCMSR_ARC1214_DRV2IOP_DATA_OUT_READ
,
4470 reg
->inbound_doorbell
);
4476 case ACB_ADAPTER_TYPE_E
:
4477 case ACB_ADAPTER_TYPE_F
: {
4478 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
4481 acb
->in_doorbell
= readl(®
->iobound_doorbell
);
4482 writel(0, ®
->host_int_status
); /*clear interrupt*/
4483 acb
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_DATA_READ_OK
;
4484 writel(acb
->out_doorbell
, ®
->iobound_doorbell
);
4485 for(i
=0; i
< 200; i
++) {
4487 tmp
= acb
->in_doorbell
;
4488 acb
->in_doorbell
= readl(®
->iobound_doorbell
);
4489 if((tmp
^ acb
->in_doorbell
) & ARCMSR_HBEMU_IOP2DRV_DATA_WRITE_OK
) {
4490 writel(0, ®
->host_int_status
); /*clear interrupt*/
4491 acb
->out_doorbell
^= ARCMSR_HBEMU_DRV2IOP_DATA_READ_OK
;
4492 writel(acb
->out_doorbell
, ®
->iobound_doorbell
);
4501 static void arcmsr_enable_eoi_mode(struct AdapterControlBlock
*acb
)
4503 switch (acb
->adapter_type
) {
4504 case ACB_ADAPTER_TYPE_A
:
4506 case ACB_ADAPTER_TYPE_B
:
4508 struct MessageUnit_B
*reg
= acb
->pmuB
;
4509 writel(ARCMSR_MESSAGE_ACTIVE_EOI_MODE
, reg
->drv2iop_doorbell
);
4510 if (!arcmsr_hbaB_wait_msgint_ready(acb
)) {
4511 printk(KERN_NOTICE
"ARCMSR IOP enables EOI_MODE TIMEOUT");
4516 case ACB_ADAPTER_TYPE_C
:
4522 static void arcmsr_hardware_reset(struct AdapterControlBlock
*acb
)
4526 struct MessageUnit_A __iomem
*pmuA
= acb
->pmuA
;
4527 struct MessageUnit_C __iomem
*pmuC
= acb
->pmuC
;
4528 struct MessageUnit_D
*pmuD
= acb
->pmuD
;
4530 /* backup pci config data */
4531 printk(KERN_NOTICE
"arcmsr%d: executing hw bus reset .....\n", acb
->host
->host_no
);
4532 for (i
= 0; i
< 64; i
++) {
4533 pci_read_config_byte(acb
->pdev
, i
, &value
[i
]);
4535 /* hardware reset signal */
4536 if (acb
->dev_id
== 0x1680) {
4537 writel(ARCMSR_ARC1680_BUS_RESET
, &pmuA
->reserved1
[0]);
4538 } else if (acb
->dev_id
== 0x1880) {
4541 writel(0xF, &pmuC
->write_sequence
);
4542 writel(0x4, &pmuC
->write_sequence
);
4543 writel(0xB, &pmuC
->write_sequence
);
4544 writel(0x2, &pmuC
->write_sequence
);
4545 writel(0x7, &pmuC
->write_sequence
);
4546 writel(0xD, &pmuC
->write_sequence
);
4547 } while (((readl(&pmuC
->host_diagnostic
) & ARCMSR_ARC1880_DiagWrite_ENABLE
) == 0) && (count
< 5));
4548 writel(ARCMSR_ARC1880_RESET_ADAPTER
, &pmuC
->host_diagnostic
);
4549 } else if (acb
->dev_id
== 0x1884) {
4550 struct MessageUnit_E __iomem
*pmuE
= acb
->pmuE
;
4553 writel(0x4, &pmuE
->write_sequence_3xxx
);
4554 writel(0xB, &pmuE
->write_sequence_3xxx
);
4555 writel(0x2, &pmuE
->write_sequence_3xxx
);
4556 writel(0x7, &pmuE
->write_sequence_3xxx
);
4557 writel(0xD, &pmuE
->write_sequence_3xxx
);
4559 } while (((readl(&pmuE
->host_diagnostic_3xxx
) &
4560 ARCMSR_ARC1884_DiagWrite_ENABLE
) == 0) && (count
< 5));
4561 writel(ARCMSR_ARC188X_RESET_ADAPTER
, &pmuE
->host_diagnostic_3xxx
);
4562 } else if (acb
->dev_id
== 0x1214) {
4563 writel(0x20, pmuD
->reset_request
);
4565 pci_write_config_byte(acb
->pdev
, 0x84, 0x20);
4568 /* write back pci config data */
4569 for (i
= 0; i
< 64; i
++) {
4570 pci_write_config_byte(acb
->pdev
, i
, value
[i
]);
4576 static bool arcmsr_reset_in_progress(struct AdapterControlBlock
*acb
)
4580 switch(acb
->adapter_type
) {
4581 case ACB_ADAPTER_TYPE_A
:{
4582 struct MessageUnit_A __iomem
*reg
= acb
->pmuA
;
4583 rtn
= ((readl(®
->outbound_msgaddr1
) &
4584 ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK
) == 0) ? true : false;
4587 case ACB_ADAPTER_TYPE_B
:{
4588 struct MessageUnit_B
*reg
= acb
->pmuB
;
4589 rtn
= ((readl(reg
->iop2drv_doorbell
) &
4590 ARCMSR_MESSAGE_FIRMWARE_OK
) == 0) ? true : false;
4593 case ACB_ADAPTER_TYPE_C
:{
4594 struct MessageUnit_C __iomem
*reg
= acb
->pmuC
;
4595 rtn
= (readl(®
->host_diagnostic
) & 0x04) ? true : false;
4598 case ACB_ADAPTER_TYPE_D
:{
4599 struct MessageUnit_D
*reg
= acb
->pmuD
;
4600 rtn
= ((readl(reg
->sample_at_reset
) & 0x80) == 0) ?
4604 case ACB_ADAPTER_TYPE_E
:
4605 case ACB_ADAPTER_TYPE_F
:{
4606 struct MessageUnit_E __iomem
*reg
= acb
->pmuE
;
4607 rtn
= (readl(®
->host_diagnostic_3xxx
) &
4608 ARCMSR_ARC188X_RESET_ADAPTER
) ? true : false;
4615 static void arcmsr_iop_init(struct AdapterControlBlock
*acb
)
4617 uint32_t intmask_org
;
4618 /* disable all outbound interrupt */
4619 intmask_org
= arcmsr_disable_outbound_ints(acb
);
4620 arcmsr_wait_firmware_ready(acb
);
4621 arcmsr_iop_confirm(acb
);
4622 /*start background rebuild*/
4623 arcmsr_start_adapter_bgrb(acb
);
4624 /* empty doorbell Qbuffer if door bell ringed */
4625 arcmsr_clear_doorbell_queue_buffer(acb
);
4626 arcmsr_enable_eoi_mode(acb
);
4627 /* enable outbound Post Queue,outbound doorbell Interrupt */
4628 arcmsr_enable_outbound_ints(acb
, intmask_org
);
4629 acb
->acb_flags
|= ACB_F_IOP_INITED
;
4632 static uint8_t arcmsr_iop_reset(struct AdapterControlBlock
*acb
)
4634 struct CommandControlBlock
*ccb
;
4635 uint32_t intmask_org
;
4636 uint8_t rtnval
= 0x00;
4638 unsigned long flags
;
4640 if (atomic_read(&acb
->ccboutstandingcount
) != 0) {
4641 /* disable all outbound interrupt */
4642 intmask_org
= arcmsr_disable_outbound_ints(acb
);
4643 /* talk to iop 331 outstanding command aborted */
4644 rtnval
= arcmsr_abort_allcmd(acb
);
4645 /* clear all outbound posted Q */
4646 arcmsr_done4abort_postqueue(acb
);
4647 for (i
= 0; i
< acb
->maxFreeCCB
; i
++) {
4648 ccb
= acb
->pccb_pool
[i
];
4649 if (ccb
->startdone
== ARCMSR_CCB_START
) {
4650 scsi_dma_unmap(ccb
->pcmd
);
4651 ccb
->startdone
= ARCMSR_CCB_DONE
;
4653 spin_lock_irqsave(&acb
->ccblist_lock
, flags
);
4654 list_add_tail(&ccb
->list
, &acb
->ccb_free_list
);
4655 spin_unlock_irqrestore(&acb
->ccblist_lock
, flags
);
4658 atomic_set(&acb
->ccboutstandingcount
, 0);
4659 /* enable all outbound interrupt */
4660 arcmsr_enable_outbound_ints(acb
, intmask_org
);
4666 static int arcmsr_bus_reset(struct scsi_cmnd
*cmd
)
4668 struct AdapterControlBlock
*acb
;
4669 int retry_count
= 0;
4671 acb
= (struct AdapterControlBlock
*) cmd
->device
->host
->hostdata
;
4672 if (acb
->acb_flags
& ACB_F_ADAPTER_REMOVED
)
4674 pr_notice("arcmsr: executing bus reset eh.....num_resets = %d,"
4675 " num_aborts = %d \n", acb
->num_resets
, acb
->num_aborts
);
4678 if (acb
->acb_flags
& ACB_F_BUS_RESET
) {
4680 pr_notice("arcmsr: there is a bus reset eh proceeding...\n");
4681 timeout
= wait_event_timeout(wait_q
, (acb
->acb_flags
4682 & ACB_F_BUS_RESET
) == 0, 220 * HZ
);
4686 acb
->acb_flags
|= ACB_F_BUS_RESET
;
4687 if (!arcmsr_iop_reset(acb
)) {
4688 arcmsr_hardware_reset(acb
);
4689 acb
->acb_flags
&= ~ACB_F_IOP_INITED
;
4691 ssleep(ARCMSR_SLEEPTIME
);
4692 if (arcmsr_reset_in_progress(acb
)) {
4693 if (retry_count
> ARCMSR_RETRYCOUNT
) {
4694 acb
->fw_flag
= FW_DEADLOCK
;
4695 pr_notice("arcmsr%d: waiting for hw bus reset"
4696 " return, RETRY TERMINATED!!\n",
4697 acb
->host
->host_no
);
4701 goto wait_reset_done
;
4703 arcmsr_iop_init(acb
);
4704 acb
->fw_flag
= FW_NORMAL
;
4705 mod_timer(&acb
->eternal_timer
, jiffies
+
4706 msecs_to_jiffies(6 * HZ
));
4707 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
4709 pr_notice("arcmsr: scsi bus reset eh returns with success\n");
4711 acb
->acb_flags
&= ~ACB_F_BUS_RESET
;
4712 acb
->fw_flag
= FW_NORMAL
;
4713 mod_timer(&acb
->eternal_timer
, jiffies
+
4714 msecs_to_jiffies(6 * HZ
));
4720 static int arcmsr_abort_one_cmd(struct AdapterControlBlock
*acb
,
4721 struct CommandControlBlock
*ccb
)
4724 rtn
= arcmsr_polling_ccbdone(acb
, ccb
);
4728 static int arcmsr_abort(struct scsi_cmnd
*cmd
)
4730 struct AdapterControlBlock
*acb
=
4731 (struct AdapterControlBlock
*)cmd
->device
->host
->hostdata
;
4734 uint32_t intmask_org
;
4736 if (acb
->acb_flags
& ACB_F_ADAPTER_REMOVED
)
4739 "arcmsr%d: abort device command of scsi id = %d lun = %d\n",
4740 acb
->host
->host_no
, cmd
->device
->id
, (u32
)cmd
->device
->lun
);
4741 acb
->acb_flags
|= ACB_F_ABORT
;
4744 ************************************************
4745 ** the all interrupt service routine is locked
4746 ** we need to handle it as soon as possible and exit
4747 ************************************************
4749 if (!atomic_read(&acb
->ccboutstandingcount
)) {
4750 acb
->acb_flags
&= ~ACB_F_ABORT
;
4754 intmask_org
= arcmsr_disable_outbound_ints(acb
);
4755 for (i
= 0; i
< acb
->maxFreeCCB
; i
++) {
4756 struct CommandControlBlock
*ccb
= acb
->pccb_pool
[i
];
4757 if (ccb
->startdone
== ARCMSR_CCB_START
&& ccb
->pcmd
== cmd
) {
4758 ccb
->startdone
= ARCMSR_CCB_ABORTED
;
4759 rtn
= arcmsr_abort_one_cmd(acb
, ccb
);
4763 acb
->acb_flags
&= ~ACB_F_ABORT
;
4764 arcmsr_enable_outbound_ints(acb
, intmask_org
);
4768 static const char *arcmsr_info(struct Scsi_Host
*host
)
4770 struct AdapterControlBlock
*acb
=
4771 (struct AdapterControlBlock
*) host
->hostdata
;
4772 static char buf
[256];
4775 switch (acb
->pdev
->device
) {
4776 case PCI_DEVICE_ID_ARECA_1110
:
4777 case PCI_DEVICE_ID_ARECA_1200
:
4778 case PCI_DEVICE_ID_ARECA_1202
:
4779 case PCI_DEVICE_ID_ARECA_1210
:
4782 case PCI_DEVICE_ID_ARECA_1120
:
4783 case PCI_DEVICE_ID_ARECA_1130
:
4784 case PCI_DEVICE_ID_ARECA_1160
:
4785 case PCI_DEVICE_ID_ARECA_1170
:
4786 case PCI_DEVICE_ID_ARECA_1201
:
4787 case PCI_DEVICE_ID_ARECA_1203
:
4788 case PCI_DEVICE_ID_ARECA_1220
:
4789 case PCI_DEVICE_ID_ARECA_1230
:
4790 case PCI_DEVICE_ID_ARECA_1260
:
4791 case PCI_DEVICE_ID_ARECA_1270
:
4792 case PCI_DEVICE_ID_ARECA_1280
:
4795 case PCI_DEVICE_ID_ARECA_1214
:
4796 case PCI_DEVICE_ID_ARECA_1380
:
4797 case PCI_DEVICE_ID_ARECA_1381
:
4798 case PCI_DEVICE_ID_ARECA_1680
:
4799 case PCI_DEVICE_ID_ARECA_1681
:
4800 case PCI_DEVICE_ID_ARECA_1880
:
4801 case PCI_DEVICE_ID_ARECA_1883
:
4802 case PCI_DEVICE_ID_ARECA_1884
:
4805 case PCI_DEVICE_ID_ARECA_1886_0
:
4806 case PCI_DEVICE_ID_ARECA_1886
:
4807 type
= "NVMe/SAS/SATA";
4814 sprintf(buf
, "Areca %s RAID Controller %s\narcmsr version %s\n",
4815 type
, raid6
? "(RAID6 capable)" : "", ARCMSR_DRIVER_VERSION
);