2 * HighPoint RR3xxx/4xxx controller driver for Linux
3 * Copyright (C) 2006-2012 HighPoint Technologies, Inc. All Rights Reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * Please report bugs/comments/suggestions to linux@highpoint-tech.com
16 * For more information, visit http://www.highpoint-tech.com
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/string.h>
21 #include <linux/kernel.h>
22 #include <linux/pci.h>
23 #include <linux/interrupt.h>
24 #include <linux/errno.h>
25 #include <linux/delay.h>
26 #include <linux/timer.h>
27 #include <linux/spinlock.h>
28 #include <linux/gfp.h>
29 #include <asm/uaccess.h>
31 #include <asm/div64.h>
32 #include <scsi/scsi_cmnd.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi.h>
35 #include <scsi/scsi_tcq.h>
36 #include <scsi/scsi_host.h>
40 MODULE_AUTHOR("HighPoint Technologies, Inc.");
41 MODULE_DESCRIPTION("HighPoint RocketRAID 3xxx/4xxx Controller Driver");
43 static char driver_name
[] = "hptiop";
44 static const char driver_name_long
[] = "RocketRAID 3xxx/4xxx Controller driver";
45 static const char driver_ver
[] = "v1.8";
47 static int iop_send_sync_msg(struct hptiop_hba
*hba
, u32 msg
, u32 millisec
);
48 static void hptiop_finish_scsi_req(struct hptiop_hba
*hba
, u32 tag
,
49 struct hpt_iop_request_scsi_command
*req
);
50 static void hptiop_host_request_callback_itl(struct hptiop_hba
*hba
, u32 tag
);
51 static void hptiop_iop_request_callback_itl(struct hptiop_hba
*hba
, u32 tag
);
52 static void hptiop_message_callback(struct hptiop_hba
*hba
, u32 msg
);
54 static int iop_wait_ready_itl(struct hptiop_hba
*hba
, u32 millisec
)
59 for (i
= 0; i
< millisec
; i
++) {
60 req
= readl(&hba
->u
.itl
.iop
->inbound_queue
);
61 if (req
!= IOPMU_QUEUE_EMPTY
)
66 if (req
!= IOPMU_QUEUE_EMPTY
) {
67 writel(req
, &hba
->u
.itl
.iop
->outbound_queue
);
68 readl(&hba
->u
.itl
.iop
->outbound_intstatus
);
75 static int iop_wait_ready_mv(struct hptiop_hba
*hba
, u32 millisec
)
77 return iop_send_sync_msg(hba
, IOPMU_INBOUND_MSG0_NOP
, millisec
);
80 static int iop_wait_ready_mvfrey(struct hptiop_hba
*hba
, u32 millisec
)
82 return iop_send_sync_msg(hba
, IOPMU_INBOUND_MSG0_NOP
, millisec
);
85 static void hptiop_request_callback_itl(struct hptiop_hba
*hba
, u32 tag
)
87 if (tag
& IOPMU_QUEUE_ADDR_HOST_BIT
)
88 hptiop_host_request_callback_itl(hba
,
89 tag
& ~IOPMU_QUEUE_ADDR_HOST_BIT
);
91 hptiop_iop_request_callback_itl(hba
, tag
);
94 static void hptiop_drain_outbound_queue_itl(struct hptiop_hba
*hba
)
98 while ((req
= readl(&hba
->u
.itl
.iop
->outbound_queue
)) !=
101 if (req
& IOPMU_QUEUE_MASK_HOST_BITS
)
102 hptiop_request_callback_itl(hba
, req
);
104 struct hpt_iop_request_header __iomem
* p
;
106 p
= (struct hpt_iop_request_header __iomem
*)
107 ((char __iomem
*)hba
->u
.itl
.iop
+ req
);
109 if (readl(&p
->flags
) & IOP_REQUEST_FLAG_SYNC_REQUEST
) {
110 if (readl(&p
->context
))
111 hptiop_request_callback_itl(hba
, req
);
113 writel(1, &p
->context
);
116 hptiop_request_callback_itl(hba
, req
);
121 static int iop_intr_itl(struct hptiop_hba
*hba
)
123 struct hpt_iopmu_itl __iomem
*iop
= hba
->u
.itl
.iop
;
124 void __iomem
*plx
= hba
->u
.itl
.plx
;
128 if (plx
&& readl(plx
+ 0x11C5C) & 0xf)
129 writel(1, plx
+ 0x11C60);
131 status
= readl(&iop
->outbound_intstatus
);
133 if (status
& IOPMU_OUTBOUND_INT_MSG0
) {
134 u32 msg
= readl(&iop
->outbound_msgaddr0
);
136 dprintk("received outbound msg %x\n", msg
);
137 writel(IOPMU_OUTBOUND_INT_MSG0
, &iop
->outbound_intstatus
);
138 hptiop_message_callback(hba
, msg
);
142 if (status
& IOPMU_OUTBOUND_INT_POSTQUEUE
) {
143 hptiop_drain_outbound_queue_itl(hba
);
150 static u64
mv_outbound_read(struct hpt_iopmu_mv __iomem
*mu
)
152 u32 outbound_tail
= readl(&mu
->outbound_tail
);
153 u32 outbound_head
= readl(&mu
->outbound_head
);
155 if (outbound_tail
!= outbound_head
) {
158 memcpy_fromio(&p
, &mu
->outbound_q
[mu
->outbound_tail
], 8);
161 if (outbound_tail
== MVIOP_QUEUE_LEN
)
163 writel(outbound_tail
, &mu
->outbound_tail
);
169 static void mv_inbound_write(u64 p
, struct hptiop_hba
*hba
)
171 u32 inbound_head
= readl(&hba
->u
.mv
.mu
->inbound_head
);
172 u32 head
= inbound_head
+ 1;
174 if (head
== MVIOP_QUEUE_LEN
)
177 memcpy_toio(&hba
->u
.mv
.mu
->inbound_q
[inbound_head
], &p
, 8);
178 writel(head
, &hba
->u
.mv
.mu
->inbound_head
);
179 writel(MVIOP_MU_INBOUND_INT_POSTQUEUE
,
180 &hba
->u
.mv
.regs
->inbound_doorbell
);
183 static void hptiop_request_callback_mv(struct hptiop_hba
*hba
, u64 tag
)
185 u32 req_type
= (tag
>> 5) & 0x7;
186 struct hpt_iop_request_scsi_command
*req
;
188 dprintk("hptiop_request_callback_mv: tag=%llx\n", tag
);
190 BUG_ON((tag
& MVIOP_MU_QUEUE_REQUEST_RETURN_CONTEXT
) == 0);
193 case IOP_REQUEST_TYPE_GET_CONFIG
:
194 case IOP_REQUEST_TYPE_SET_CONFIG
:
198 case IOP_REQUEST_TYPE_SCSI_COMMAND
:
199 req
= hba
->reqs
[tag
>> 8].req_virt
;
200 if (likely(tag
& MVIOP_MU_QUEUE_REQUEST_RESULT_BIT
))
201 req
->header
.result
= cpu_to_le32(IOP_RESULT_SUCCESS
);
203 hptiop_finish_scsi_req(hba
, tag
>>8, req
);
211 static int iop_intr_mv(struct hptiop_hba
*hba
)
216 status
= readl(&hba
->u
.mv
.regs
->outbound_doorbell
);
217 writel(~status
, &hba
->u
.mv
.regs
->outbound_doorbell
);
219 if (status
& MVIOP_MU_OUTBOUND_INT_MSG
) {
221 msg
= readl(&hba
->u
.mv
.mu
->outbound_msg
);
222 dprintk("received outbound msg %x\n", msg
);
223 hptiop_message_callback(hba
, msg
);
227 if (status
& MVIOP_MU_OUTBOUND_INT_POSTQUEUE
) {
230 while ((tag
= mv_outbound_read(hba
->u
.mv
.mu
)))
231 hptiop_request_callback_mv(hba
, tag
);
238 static void hptiop_request_callback_mvfrey(struct hptiop_hba
*hba
, u32 _tag
)
240 u32 req_type
= _tag
& 0xf;
241 struct hpt_iop_request_scsi_command
*req
;
244 case IOP_REQUEST_TYPE_GET_CONFIG
:
245 case IOP_REQUEST_TYPE_SET_CONFIG
:
249 case IOP_REQUEST_TYPE_SCSI_COMMAND
:
250 req
= hba
->reqs
[(_tag
>> 4) & 0xff].req_virt
;
251 if (likely(_tag
& IOPMU_QUEUE_REQUEST_RESULT_BIT
))
252 req
->header
.result
= IOP_RESULT_SUCCESS
;
253 hptiop_finish_scsi_req(hba
, (_tag
>> 4) & 0xff, req
);
261 static int iop_intr_mvfrey(struct hptiop_hba
*hba
)
263 u32 _tag
, status
, cptr
, cur_rptr
;
266 if (hba
->initialized
)
267 writel(0, &(hba
->u
.mvfrey
.mu
->pcie_f0_int_enable
));
269 status
= readl(&(hba
->u
.mvfrey
.mu
->f0_doorbell
));
271 writel(status
, &(hba
->u
.mvfrey
.mu
->f0_doorbell
));
272 if (status
& CPU_TO_F0_DRBL_MSG_BIT
) {
273 u32 msg
= readl(&(hba
->u
.mvfrey
.mu
->cpu_to_f0_msg_a
));
274 dprintk("received outbound msg %x\n", msg
);
275 hptiop_message_callback(hba
, msg
);
280 status
= readl(&(hba
->u
.mvfrey
.mu
->isr_cause
));
282 writel(status
, &(hba
->u
.mvfrey
.mu
->isr_cause
));
284 cptr
= *hba
->u
.mvfrey
.outlist_cptr
& 0xff;
285 cur_rptr
= hba
->u
.mvfrey
.outlist_rptr
;
286 while (cur_rptr
!= cptr
) {
288 if (cur_rptr
== hba
->u
.mvfrey
.list_count
)
291 _tag
= hba
->u
.mvfrey
.outlist
[cur_rptr
].val
;
292 BUG_ON(!(_tag
& IOPMU_QUEUE_MASK_HOST_BITS
));
293 hptiop_request_callback_mvfrey(hba
, _tag
);
296 hba
->u
.mvfrey
.outlist_rptr
= cur_rptr
;
297 } while (cptr
!= (*hba
->u
.mvfrey
.outlist_cptr
& 0xff));
300 if (hba
->initialized
)
301 writel(0x1010, &(hba
->u
.mvfrey
.mu
->pcie_f0_int_enable
));
306 static int iop_send_sync_request_itl(struct hptiop_hba
*hba
,
307 void __iomem
*_req
, u32 millisec
)
309 struct hpt_iop_request_header __iomem
*req
= _req
;
312 writel(readl(&req
->flags
) | IOP_REQUEST_FLAG_SYNC_REQUEST
, &req
->flags
);
313 writel(0, &req
->context
);
314 writel((unsigned long)req
- (unsigned long)hba
->u
.itl
.iop
,
315 &hba
->u
.itl
.iop
->inbound_queue
);
316 readl(&hba
->u
.itl
.iop
->outbound_intstatus
);
318 for (i
= 0; i
< millisec
; i
++) {
320 if (readl(&req
->context
))
328 static int iop_send_sync_request_mv(struct hptiop_hba
*hba
,
329 u32 size_bits
, u32 millisec
)
331 struct hpt_iop_request_header
*reqhdr
= hba
->u
.mv
.internal_req
;
335 reqhdr
->flags
|= cpu_to_le32(IOP_REQUEST_FLAG_SYNC_REQUEST
);
336 mv_inbound_write(hba
->u
.mv
.internal_req_phy
|
337 MVIOP_MU_QUEUE_ADDR_HOST_BIT
| size_bits
, hba
);
339 for (i
= 0; i
< millisec
; i
++) {
348 static int iop_send_sync_request_mvfrey(struct hptiop_hba
*hba
,
349 u32 size_bits
, u32 millisec
)
351 struct hpt_iop_request_header
*reqhdr
=
352 hba
->u
.mvfrey
.internal_req
.req_virt
;
356 reqhdr
->flags
|= cpu_to_le32(IOP_REQUEST_FLAG_SYNC_REQUEST
);
357 hba
->ops
->post_req(hba
, &(hba
->u
.mvfrey
.internal_req
));
359 for (i
= 0; i
< millisec
; i
++) {
360 iop_intr_mvfrey(hba
);
365 return hba
->msg_done
? 0 : -1;
368 static void hptiop_post_msg_itl(struct hptiop_hba
*hba
, u32 msg
)
370 writel(msg
, &hba
->u
.itl
.iop
->inbound_msgaddr0
);
371 readl(&hba
->u
.itl
.iop
->outbound_intstatus
);
374 static void hptiop_post_msg_mv(struct hptiop_hba
*hba
, u32 msg
)
376 writel(msg
, &hba
->u
.mv
.mu
->inbound_msg
);
377 writel(MVIOP_MU_INBOUND_INT_MSG
, &hba
->u
.mv
.regs
->inbound_doorbell
);
378 readl(&hba
->u
.mv
.regs
->inbound_doorbell
);
381 static void hptiop_post_msg_mvfrey(struct hptiop_hba
*hba
, u32 msg
)
383 writel(msg
, &(hba
->u
.mvfrey
.mu
->f0_to_cpu_msg_a
));
384 readl(&(hba
->u
.mvfrey
.mu
->f0_to_cpu_msg_a
));
387 static int iop_send_sync_msg(struct hptiop_hba
*hba
, u32 msg
, u32 millisec
)
392 hba
->ops
->disable_intr(hba
);
393 hba
->ops
->post_msg(hba
, msg
);
395 for (i
= 0; i
< millisec
; i
++) {
396 spin_lock_irq(hba
->host
->host_lock
);
397 hba
->ops
->iop_intr(hba
);
398 spin_unlock_irq(hba
->host
->host_lock
);
404 hba
->ops
->enable_intr(hba
);
405 return hba
->msg_done
? 0 : -1;
408 static int iop_get_config_itl(struct hptiop_hba
*hba
,
409 struct hpt_iop_request_get_config
*config
)
412 struct hpt_iop_request_get_config __iomem
*req
;
414 req32
= readl(&hba
->u
.itl
.iop
->inbound_queue
);
415 if (req32
== IOPMU_QUEUE_EMPTY
)
418 req
= (struct hpt_iop_request_get_config __iomem
*)
419 ((unsigned long)hba
->u
.itl
.iop
+ req32
);
421 writel(0, &req
->header
.flags
);
422 writel(IOP_REQUEST_TYPE_GET_CONFIG
, &req
->header
.type
);
423 writel(sizeof(struct hpt_iop_request_get_config
), &req
->header
.size
);
424 writel(IOP_RESULT_PENDING
, &req
->header
.result
);
426 if (iop_send_sync_request_itl(hba
, req
, 20000)) {
427 dprintk("Get config send cmd failed\n");
431 memcpy_fromio(config
, req
, sizeof(*config
));
432 writel(req32
, &hba
->u
.itl
.iop
->outbound_queue
);
436 static int iop_get_config_mv(struct hptiop_hba
*hba
,
437 struct hpt_iop_request_get_config
*config
)
439 struct hpt_iop_request_get_config
*req
= hba
->u
.mv
.internal_req
;
441 req
->header
.flags
= cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT
);
442 req
->header
.type
= cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG
);
444 cpu_to_le32(sizeof(struct hpt_iop_request_get_config
));
445 req
->header
.result
= cpu_to_le32(IOP_RESULT_PENDING
);
446 req
->header
.context
= cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG
<<5);
447 req
->header
.context_hi32
= 0;
449 if (iop_send_sync_request_mv(hba
, 0, 20000)) {
450 dprintk("Get config send cmd failed\n");
454 memcpy(config
, req
, sizeof(struct hpt_iop_request_get_config
));
458 static int iop_get_config_mvfrey(struct hptiop_hba
*hba
,
459 struct hpt_iop_request_get_config
*config
)
461 struct hpt_iop_request_get_config
*info
= hba
->u
.mvfrey
.config
;
463 if (info
->header
.size
!= sizeof(struct hpt_iop_request_get_config
) ||
464 info
->header
.type
!= IOP_REQUEST_TYPE_GET_CONFIG
)
467 config
->interface_version
= info
->interface_version
;
468 config
->firmware_version
= info
->firmware_version
;
469 config
->max_requests
= info
->max_requests
;
470 config
->request_size
= info
->request_size
;
471 config
->max_sg_count
= info
->max_sg_count
;
472 config
->data_transfer_length
= info
->data_transfer_length
;
473 config
->alignment_mask
= info
->alignment_mask
;
474 config
->max_devices
= info
->max_devices
;
475 config
->sdram_size
= info
->sdram_size
;
480 static int iop_set_config_itl(struct hptiop_hba
*hba
,
481 struct hpt_iop_request_set_config
*config
)
484 struct hpt_iop_request_set_config __iomem
*req
;
486 req32
= readl(&hba
->u
.itl
.iop
->inbound_queue
);
487 if (req32
== IOPMU_QUEUE_EMPTY
)
490 req
= (struct hpt_iop_request_set_config __iomem
*)
491 ((unsigned long)hba
->u
.itl
.iop
+ req32
);
493 memcpy_toio((u8 __iomem
*)req
+ sizeof(struct hpt_iop_request_header
),
494 (u8
*)config
+ sizeof(struct hpt_iop_request_header
),
495 sizeof(struct hpt_iop_request_set_config
) -
496 sizeof(struct hpt_iop_request_header
));
498 writel(0, &req
->header
.flags
);
499 writel(IOP_REQUEST_TYPE_SET_CONFIG
, &req
->header
.type
);
500 writel(sizeof(struct hpt_iop_request_set_config
), &req
->header
.size
);
501 writel(IOP_RESULT_PENDING
, &req
->header
.result
);
503 if (iop_send_sync_request_itl(hba
, req
, 20000)) {
504 dprintk("Set config send cmd failed\n");
508 writel(req32
, &hba
->u
.itl
.iop
->outbound_queue
);
512 static int iop_set_config_mv(struct hptiop_hba
*hba
,
513 struct hpt_iop_request_set_config
*config
)
515 struct hpt_iop_request_set_config
*req
= hba
->u
.mv
.internal_req
;
517 memcpy(req
, config
, sizeof(struct hpt_iop_request_set_config
));
518 req
->header
.flags
= cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT
);
519 req
->header
.type
= cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG
);
521 cpu_to_le32(sizeof(struct hpt_iop_request_set_config
));
522 req
->header
.result
= cpu_to_le32(IOP_RESULT_PENDING
);
523 req
->header
.context
= cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG
<<5);
524 req
->header
.context_hi32
= 0;
526 if (iop_send_sync_request_mv(hba
, 0, 20000)) {
527 dprintk("Set config send cmd failed\n");
534 static int iop_set_config_mvfrey(struct hptiop_hba
*hba
,
535 struct hpt_iop_request_set_config
*config
)
537 struct hpt_iop_request_set_config
*req
=
538 hba
->u
.mvfrey
.internal_req
.req_virt
;
540 memcpy(req
, config
, sizeof(struct hpt_iop_request_set_config
));
541 req
->header
.flags
= cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT
);
542 req
->header
.type
= cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG
);
544 cpu_to_le32(sizeof(struct hpt_iop_request_set_config
));
545 req
->header
.result
= cpu_to_le32(IOP_RESULT_PENDING
);
546 req
->header
.context
= cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG
<<5);
547 req
->header
.context_hi32
= 0;
549 if (iop_send_sync_request_mvfrey(hba
, 0, 20000)) {
550 dprintk("Set config send cmd failed\n");
557 static void hptiop_enable_intr_itl(struct hptiop_hba
*hba
)
559 writel(~(IOPMU_OUTBOUND_INT_POSTQUEUE
| IOPMU_OUTBOUND_INT_MSG0
),
560 &hba
->u
.itl
.iop
->outbound_intmask
);
563 static void hptiop_enable_intr_mv(struct hptiop_hba
*hba
)
565 writel(MVIOP_MU_OUTBOUND_INT_POSTQUEUE
| MVIOP_MU_OUTBOUND_INT_MSG
,
566 &hba
->u
.mv
.regs
->outbound_intmask
);
569 static void hptiop_enable_intr_mvfrey(struct hptiop_hba
*hba
)
571 writel(CPU_TO_F0_DRBL_MSG_BIT
, &(hba
->u
.mvfrey
.mu
->f0_doorbell_enable
));
572 writel(0x1, &(hba
->u
.mvfrey
.mu
->isr_enable
));
573 writel(0x1010, &(hba
->u
.mvfrey
.mu
->pcie_f0_int_enable
));
576 static int hptiop_initialize_iop(struct hptiop_hba
*hba
)
578 /* enable interrupts */
579 hba
->ops
->enable_intr(hba
);
581 hba
->initialized
= 1;
583 /* start background tasks */
584 if (iop_send_sync_msg(hba
,
585 IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK
, 5000)) {
586 printk(KERN_ERR
"scsi%d: fail to start background task\n",
593 static void __iomem
*hptiop_map_pci_bar(struct hptiop_hba
*hba
, int index
)
595 u32 mem_base_phy
, length
;
596 void __iomem
*mem_base_virt
;
598 struct pci_dev
*pcidev
= hba
->pcidev
;
601 if (!(pci_resource_flags(pcidev
, index
) & IORESOURCE_MEM
)) {
602 printk(KERN_ERR
"scsi%d: pci resource invalid\n",
607 mem_base_phy
= pci_resource_start(pcidev
, index
);
608 length
= pci_resource_len(pcidev
, index
);
609 mem_base_virt
= ioremap(mem_base_phy
, length
);
611 if (!mem_base_virt
) {
612 printk(KERN_ERR
"scsi%d: Fail to ioremap memory space\n",
616 return mem_base_virt
;
619 static int hptiop_map_pci_bar_itl(struct hptiop_hba
*hba
)
621 struct pci_dev
*pcidev
= hba
->pcidev
;
622 hba
->u
.itl
.iop
= hptiop_map_pci_bar(hba
, 0);
623 if (hba
->u
.itl
.iop
== NULL
)
625 if ((pcidev
->device
& 0xff00) == 0x4400) {
626 hba
->u
.itl
.plx
= hba
->u
.itl
.iop
;
627 hba
->u
.itl
.iop
= hptiop_map_pci_bar(hba
, 2);
628 if (hba
->u
.itl
.iop
== NULL
) {
629 iounmap(hba
->u
.itl
.plx
);
636 static void hptiop_unmap_pci_bar_itl(struct hptiop_hba
*hba
)
639 iounmap(hba
->u
.itl
.plx
);
640 iounmap(hba
->u
.itl
.iop
);
643 static int hptiop_map_pci_bar_mv(struct hptiop_hba
*hba
)
645 hba
->u
.mv
.regs
= hptiop_map_pci_bar(hba
, 0);
646 if (hba
->u
.mv
.regs
== NULL
)
649 hba
->u
.mv
.mu
= hptiop_map_pci_bar(hba
, 2);
650 if (hba
->u
.mv
.mu
== NULL
) {
651 iounmap(hba
->u
.mv
.regs
);
658 static int hptiop_map_pci_bar_mvfrey(struct hptiop_hba
*hba
)
660 hba
->u
.mvfrey
.config
= hptiop_map_pci_bar(hba
, 0);
661 if (hba
->u
.mvfrey
.config
== NULL
)
664 hba
->u
.mvfrey
.mu
= hptiop_map_pci_bar(hba
, 2);
665 if (hba
->u
.mvfrey
.mu
== NULL
) {
666 iounmap(hba
->u
.mvfrey
.config
);
673 static void hptiop_unmap_pci_bar_mv(struct hptiop_hba
*hba
)
675 iounmap(hba
->u
.mv
.regs
);
676 iounmap(hba
->u
.mv
.mu
);
679 static void hptiop_unmap_pci_bar_mvfrey(struct hptiop_hba
*hba
)
681 iounmap(hba
->u
.mvfrey
.config
);
682 iounmap(hba
->u
.mvfrey
.mu
);
685 static void hptiop_message_callback(struct hptiop_hba
*hba
, u32 msg
)
687 dprintk("iop message 0x%x\n", msg
);
689 if (msg
== IOPMU_INBOUND_MSG0_NOP
||
690 msg
== IOPMU_INBOUND_MSG0_RESET_COMM
)
693 if (!hba
->initialized
)
696 if (msg
== IOPMU_INBOUND_MSG0_RESET
) {
697 atomic_set(&hba
->resetting
, 0);
698 wake_up(&hba
->reset_wq
);
700 else if (msg
<= IOPMU_INBOUND_MSG0_MAX
)
704 static struct hptiop_request
*get_req(struct hptiop_hba
*hba
)
706 struct hptiop_request
*ret
;
708 dprintk("get_req : req=%p\n", hba
->req_list
);
712 hba
->req_list
= ret
->next
;
717 static void free_req(struct hptiop_hba
*hba
, struct hptiop_request
*req
)
719 dprintk("free_req(%d, %p)\n", req
->index
, req
);
720 req
->next
= hba
->req_list
;
724 static void hptiop_finish_scsi_req(struct hptiop_hba
*hba
, u32 tag
,
725 struct hpt_iop_request_scsi_command
*req
)
727 struct scsi_cmnd
*scp
;
729 dprintk("hptiop_finish_scsi_req: req=%p, type=%d, "
730 "result=%d, context=0x%x tag=%d\n",
731 req
, req
->header
.type
, req
->header
.result
,
732 req
->header
.context
, tag
);
734 BUG_ON(!req
->header
.result
);
735 BUG_ON(req
->header
.type
!= cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND
));
737 scp
= hba
->reqs
[tag
].scp
;
739 if (HPT_SCP(scp
)->mapped
)
742 switch (le32_to_cpu(req
->header
.result
)) {
743 case IOP_RESULT_SUCCESS
:
745 scsi_bufflen(scp
) - le32_to_cpu(req
->dataxfer_length
));
746 scp
->result
= (DID_OK
<<16);
748 case IOP_RESULT_BAD_TARGET
:
749 scp
->result
= (DID_BAD_TARGET
<<16);
751 case IOP_RESULT_BUSY
:
752 scp
->result
= (DID_BUS_BUSY
<<16);
754 case IOP_RESULT_RESET
:
755 scp
->result
= (DID_RESET
<<16);
757 case IOP_RESULT_FAIL
:
758 scp
->result
= (DID_ERROR
<<16);
760 case IOP_RESULT_INVALID_REQUEST
:
761 scp
->result
= (DID_ABORT
<<16);
763 case IOP_RESULT_CHECK_CONDITION
:
765 scsi_bufflen(scp
) - le32_to_cpu(req
->dataxfer_length
));
766 scp
->result
= SAM_STAT_CHECK_CONDITION
;
767 memcpy(scp
->sense_buffer
, &req
->sg_list
,
768 min_t(size_t, SCSI_SENSE_BUFFERSIZE
,
769 le32_to_cpu(req
->dataxfer_length
)));
774 scp
->result
= DRIVER_INVALID
<< 24 | DID_ABORT
<< 16;
779 scsi_bufflen(scp
) - le32_to_cpu(req
->dataxfer_length
));
782 dprintk("scsi_done(%p)\n", scp
);
784 free_req(hba
, &hba
->reqs
[tag
]);
787 static void hptiop_host_request_callback_itl(struct hptiop_hba
*hba
, u32 _tag
)
789 struct hpt_iop_request_scsi_command
*req
;
792 if (hba
->iopintf_v2
) {
793 tag
= _tag
& ~IOPMU_QUEUE_REQUEST_RESULT_BIT
;
794 req
= hba
->reqs
[tag
].req_virt
;
795 if (likely(_tag
& IOPMU_QUEUE_REQUEST_RESULT_BIT
))
796 req
->header
.result
= cpu_to_le32(IOP_RESULT_SUCCESS
);
799 req
= hba
->reqs
[tag
].req_virt
;
802 hptiop_finish_scsi_req(hba
, tag
, req
);
805 void hptiop_iop_request_callback_itl(struct hptiop_hba
*hba
, u32 tag
)
807 struct hpt_iop_request_header __iomem
*req
;
808 struct hpt_iop_request_ioctl_command __iomem
*p
;
809 struct hpt_ioctl_k
*arg
;
811 req
= (struct hpt_iop_request_header __iomem
*)
812 ((unsigned long)hba
->u
.itl
.iop
+ tag
);
813 dprintk("hptiop_iop_request_callback_itl: req=%p, type=%d, "
814 "result=%d, context=0x%x tag=%d\n",
815 req
, readl(&req
->type
), readl(&req
->result
),
816 readl(&req
->context
), tag
);
818 BUG_ON(!readl(&req
->result
));
819 BUG_ON(readl(&req
->type
) != IOP_REQUEST_TYPE_IOCTL_COMMAND
);
821 p
= (struct hpt_iop_request_ioctl_command __iomem
*)req
;
822 arg
= (struct hpt_ioctl_k
*)(unsigned long)
823 (readl(&req
->context
) |
824 ((u64
)readl(&req
->context_hi32
)<<32));
826 if (readl(&req
->result
) == IOP_RESULT_SUCCESS
) {
827 arg
->result
= HPT_IOCTL_RESULT_OK
;
829 if (arg
->outbuf_size
)
830 memcpy_fromio(arg
->outbuf
,
831 &p
->buf
[(readl(&p
->inbuf_size
) + 3)& ~3],
834 if (arg
->bytes_returned
)
835 *arg
->bytes_returned
= arg
->outbuf_size
;
838 arg
->result
= HPT_IOCTL_RESULT_FAILED
;
841 writel(tag
, &hba
->u
.itl
.iop
->outbound_queue
);
844 static irqreturn_t
hptiop_intr(int irq
, void *dev_id
)
846 struct hptiop_hba
*hba
= dev_id
;
850 spin_lock_irqsave(hba
->host
->host_lock
, flags
);
851 handled
= hba
->ops
->iop_intr(hba
);
852 spin_unlock_irqrestore(hba
->host
->host_lock
, flags
);
857 static int hptiop_buildsgl(struct scsi_cmnd
*scp
, struct hpt_iopsg
*psg
)
859 struct Scsi_Host
*host
= scp
->device
->host
;
860 struct hptiop_hba
*hba
= (struct hptiop_hba
*)host
->hostdata
;
861 struct scatterlist
*sg
;
864 nseg
= scsi_dma_map(scp
);
869 HPT_SCP(scp
)->sgcnt
= nseg
;
870 HPT_SCP(scp
)->mapped
= 1;
872 BUG_ON(HPT_SCP(scp
)->sgcnt
> hba
->max_sg_descriptors
);
874 scsi_for_each_sg(scp
, sg
, HPT_SCP(scp
)->sgcnt
, idx
) {
875 psg
[idx
].pci_address
= cpu_to_le64(sg_dma_address(sg
)) |
876 hba
->ops
->host_phy_flag
;
877 psg
[idx
].size
= cpu_to_le32(sg_dma_len(sg
));
878 psg
[idx
].eot
= (idx
== HPT_SCP(scp
)->sgcnt
- 1) ?
881 return HPT_SCP(scp
)->sgcnt
;
884 static void hptiop_post_req_itl(struct hptiop_hba
*hba
,
885 struct hptiop_request
*_req
)
887 struct hpt_iop_request_header
*reqhdr
= _req
->req_virt
;
889 reqhdr
->context
= cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT
|
891 reqhdr
->context_hi32
= 0;
893 if (hba
->iopintf_v2
) {
896 size
= le32_to_cpu(reqhdr
->size
);
898 size_bits
= IOPMU_QUEUE_REQUEST_SIZE_BIT
;
900 size_bits
= IOPMU_QUEUE_ADDR_HOST_BIT
;
902 size_bits
= IOPMU_QUEUE_REQUEST_SIZE_BIT
|
903 IOPMU_QUEUE_ADDR_HOST_BIT
;
904 writel(_req
->req_shifted_phy
| size_bits
,
905 &hba
->u
.itl
.iop
->inbound_queue
);
907 writel(_req
->req_shifted_phy
| IOPMU_QUEUE_ADDR_HOST_BIT
,
908 &hba
->u
.itl
.iop
->inbound_queue
);
911 static void hptiop_post_req_mv(struct hptiop_hba
*hba
,
912 struct hptiop_request
*_req
)
914 struct hpt_iop_request_header
*reqhdr
= _req
->req_virt
;
917 reqhdr
->context
= cpu_to_le32(_req
->index
<<8 |
918 IOP_REQUEST_TYPE_SCSI_COMMAND
<<5);
919 reqhdr
->context_hi32
= 0;
920 size
= le32_to_cpu(reqhdr
->size
);
924 else if (size
<= 256*2)
926 else if (size
<= 256*3)
931 mv_inbound_write((_req
->req_shifted_phy
<< 5) |
932 MVIOP_MU_QUEUE_ADDR_HOST_BIT
| size_bit
, hba
);
935 static void hptiop_post_req_mvfrey(struct hptiop_hba
*hba
,
936 struct hptiop_request
*_req
)
938 struct hpt_iop_request_header
*reqhdr
= _req
->req_virt
;
941 reqhdr
->flags
|= cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT
|
942 IOP_REQUEST_FLAG_ADDR_BITS
|
943 ((_req
->req_shifted_phy
>> 11) & 0xffff0000));
944 reqhdr
->context
= cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT
|
945 (_req
->index
<< 4) | reqhdr
->type
);
946 reqhdr
->context_hi32
= cpu_to_le32((_req
->req_shifted_phy
<< 5) &
949 hba
->u
.mvfrey
.inlist_wptr
++;
950 index
= hba
->u
.mvfrey
.inlist_wptr
& 0x3fff;
952 if (index
== hba
->u
.mvfrey
.list_count
) {
954 hba
->u
.mvfrey
.inlist_wptr
&= ~0x3fff;
955 hba
->u
.mvfrey
.inlist_wptr
^= CL_POINTER_TOGGLE
;
958 hba
->u
.mvfrey
.inlist
[index
].addr
=
959 (dma_addr_t
)_req
->req_shifted_phy
<< 5;
960 hba
->u
.mvfrey
.inlist
[index
].intrfc_len
= (reqhdr
->size
+ 3) / 4;
961 writel(hba
->u
.mvfrey
.inlist_wptr
,
962 &(hba
->u
.mvfrey
.mu
->inbound_write_ptr
));
963 readl(&(hba
->u
.mvfrey
.mu
->inbound_write_ptr
));
966 static int hptiop_reset_comm_itl(struct hptiop_hba
*hba
)
971 static int hptiop_reset_comm_mv(struct hptiop_hba
*hba
)
976 static int hptiop_reset_comm_mvfrey(struct hptiop_hba
*hba
)
978 u32 list_count
= hba
->u
.mvfrey
.list_count
;
980 if (iop_send_sync_msg(hba
, IOPMU_INBOUND_MSG0_RESET_COMM
, 3000))
983 /* wait 100ms for MCU ready */
986 writel(cpu_to_le32(hba
->u
.mvfrey
.inlist_phy
& 0xffffffff),
987 &(hba
->u
.mvfrey
.mu
->inbound_base
));
988 writel(cpu_to_le32((hba
->u
.mvfrey
.inlist_phy
>> 16) >> 16),
989 &(hba
->u
.mvfrey
.mu
->inbound_base_high
));
991 writel(cpu_to_le32(hba
->u
.mvfrey
.outlist_phy
& 0xffffffff),
992 &(hba
->u
.mvfrey
.mu
->outbound_base
));
993 writel(cpu_to_le32((hba
->u
.mvfrey
.outlist_phy
>> 16) >> 16),
994 &(hba
->u
.mvfrey
.mu
->outbound_base_high
));
996 writel(cpu_to_le32(hba
->u
.mvfrey
.outlist_cptr_phy
& 0xffffffff),
997 &(hba
->u
.mvfrey
.mu
->outbound_shadow_base
));
998 writel(cpu_to_le32((hba
->u
.mvfrey
.outlist_cptr_phy
>> 16) >> 16),
999 &(hba
->u
.mvfrey
.mu
->outbound_shadow_base_high
));
1001 hba
->u
.mvfrey
.inlist_wptr
= (list_count
- 1) | CL_POINTER_TOGGLE
;
1002 *hba
->u
.mvfrey
.outlist_cptr
= (list_count
- 1) | CL_POINTER_TOGGLE
;
1003 hba
->u
.mvfrey
.outlist_rptr
= list_count
- 1;
1007 static int hptiop_queuecommand_lck(struct scsi_cmnd
*scp
,
1008 void (*done
)(struct scsi_cmnd
*))
1010 struct Scsi_Host
*host
= scp
->device
->host
;
1011 struct hptiop_hba
*hba
= (struct hptiop_hba
*)host
->hostdata
;
1012 struct hpt_iop_request_scsi_command
*req
;
1014 struct hptiop_request
*_req
;
1017 scp
->scsi_done
= done
;
1019 _req
= get_req(hba
);
1021 dprintk("hptiop_queuecmd : no free req\n");
1022 return SCSI_MLQUEUE_HOST_BUSY
;
1027 dprintk("hptiop_queuecmd(scp=%p) %d/%d/%d/%llu cdb=(%08x-%08x-%08x-%08x) "
1028 "req_index=%d, req=%p\n",
1030 host
->host_no
, scp
->device
->channel
,
1031 scp
->device
->id
, scp
->device
->lun
,
1032 cpu_to_be32(((u32
*)scp
->cmnd
)[0]),
1033 cpu_to_be32(((u32
*)scp
->cmnd
)[1]),
1034 cpu_to_be32(((u32
*)scp
->cmnd
)[2]),
1035 cpu_to_be32(((u32
*)scp
->cmnd
)[3]),
1036 _req
->index
, _req
->req_virt
);
1040 if (scp
->device
->channel
|| scp
->device
->lun
||
1041 scp
->device
->id
> hba
->max_devices
) {
1042 scp
->result
= DID_BAD_TARGET
<< 16;
1043 free_req(hba
, _req
);
1047 req
= _req
->req_virt
;
1049 /* build S/G table */
1050 sg_count
= hptiop_buildsgl(scp
, req
->sg_list
);
1052 HPT_SCP(scp
)->mapped
= 0;
1054 req
->header
.flags
= cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT
);
1055 req
->header
.type
= cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND
);
1056 req
->header
.result
= cpu_to_le32(IOP_RESULT_PENDING
);
1057 req
->dataxfer_length
= cpu_to_le32(scsi_bufflen(scp
));
1058 req
->channel
= scp
->device
->channel
;
1059 req
->target
= scp
->device
->id
;
1060 req
->lun
= scp
->device
->lun
;
1061 req
->header
.size
= cpu_to_le32(
1062 sizeof(struct hpt_iop_request_scsi_command
)
1063 - sizeof(struct hpt_iopsg
)
1064 + sg_count
* sizeof(struct hpt_iopsg
));
1066 memcpy(req
->cdb
, scp
->cmnd
, sizeof(req
->cdb
));
1067 hba
->ops
->post_req(hba
, _req
);
1071 dprintk("scsi_done(scp=%p)\n", scp
);
1072 scp
->scsi_done(scp
);
1076 static DEF_SCSI_QCMD(hptiop_queuecommand
)
1078 static const char *hptiop_info(struct Scsi_Host
*host
)
1080 return driver_name_long
;
1083 static int hptiop_reset_hba(struct hptiop_hba
*hba
)
1085 if (atomic_xchg(&hba
->resetting
, 1) == 0) {
1086 atomic_inc(&hba
->reset_count
);
1087 hba
->ops
->post_msg(hba
, IOPMU_INBOUND_MSG0_RESET
);
1090 wait_event_timeout(hba
->reset_wq
,
1091 atomic_read(&hba
->resetting
) == 0, 60 * HZ
);
1093 if (atomic_read(&hba
->resetting
)) {
1094 /* IOP is in unknown state, abort reset */
1095 printk(KERN_ERR
"scsi%d: reset failed\n", hba
->host
->host_no
);
1099 if (iop_send_sync_msg(hba
,
1100 IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK
, 5000)) {
1101 dprintk("scsi%d: fail to start background task\n",
1102 hba
->host
->host_no
);
1108 static int hptiop_reset(struct scsi_cmnd
*scp
)
1110 struct Scsi_Host
* host
= scp
->device
->host
;
1111 struct hptiop_hba
* hba
= (struct hptiop_hba
*)host
->hostdata
;
1113 printk(KERN_WARNING
"hptiop_reset(%d/%d/%d) scp=%p\n",
1114 scp
->device
->host
->host_no
, scp
->device
->channel
,
1115 scp
->device
->id
, scp
);
1117 return hptiop_reset_hba(hba
)? FAILED
: SUCCESS
;
1120 static int hptiop_adjust_disk_queue_depth(struct scsi_device
*sdev
,
1123 struct hptiop_hba
*hba
= (struct hptiop_hba
*)sdev
->host
->hostdata
;
1125 if (queue_depth
> hba
->max_requests
)
1126 queue_depth
= hba
->max_requests
;
1127 return scsi_change_queue_depth(sdev
, queue_depth
);
1130 static ssize_t
hptiop_show_version(struct device
*dev
,
1131 struct device_attribute
*attr
, char *buf
)
1133 return snprintf(buf
, PAGE_SIZE
, "%s\n", driver_ver
);
1136 static ssize_t
hptiop_show_fw_version(struct device
*dev
,
1137 struct device_attribute
*attr
, char *buf
)
1139 struct Scsi_Host
*host
= class_to_shost(dev
);
1140 struct hptiop_hba
*hba
= (struct hptiop_hba
*)host
->hostdata
;
1142 return snprintf(buf
, PAGE_SIZE
, "%d.%d.%d.%d\n",
1143 hba
->firmware_version
>> 24,
1144 (hba
->firmware_version
>> 16) & 0xff,
1145 (hba
->firmware_version
>> 8) & 0xff,
1146 hba
->firmware_version
& 0xff);
1149 static struct device_attribute hptiop_attr_version
= {
1151 .name
= "driver-version",
1154 .show
= hptiop_show_version
,
1157 static struct device_attribute hptiop_attr_fw_version
= {
1159 .name
= "firmware-version",
1162 .show
= hptiop_show_fw_version
,
1165 static struct device_attribute
*hptiop_attrs
[] = {
1166 &hptiop_attr_version
,
1167 &hptiop_attr_fw_version
,
1171 static struct scsi_host_template driver_template
= {
1172 .module
= THIS_MODULE
,
1173 .name
= driver_name
,
1174 .queuecommand
= hptiop_queuecommand
,
1175 .eh_device_reset_handler
= hptiop_reset
,
1176 .eh_bus_reset_handler
= hptiop_reset
,
1177 .info
= hptiop_info
,
1179 .use_clustering
= ENABLE_CLUSTERING
,
1180 .proc_name
= driver_name
,
1181 .shost_attrs
= hptiop_attrs
,
1183 .change_queue_depth
= hptiop_adjust_disk_queue_depth
,
1186 static int hptiop_internal_memalloc_itl(struct hptiop_hba
*hba
)
1191 static int hptiop_internal_memalloc_mv(struct hptiop_hba
*hba
)
1193 hba
->u
.mv
.internal_req
= dma_alloc_coherent(&hba
->pcidev
->dev
,
1194 0x800, &hba
->u
.mv
.internal_req_phy
, GFP_KERNEL
);
1195 if (hba
->u
.mv
.internal_req
)
1201 static int hptiop_internal_memalloc_mvfrey(struct hptiop_hba
*hba
)
1203 u32 list_count
= readl(&hba
->u
.mvfrey
.mu
->inbound_conf_ctl
);
1207 BUG_ON(hba
->max_request_size
== 0);
1209 if (list_count
== 0) {
1216 hba
->u
.mvfrey
.list_count
= list_count
;
1217 hba
->u
.mvfrey
.internal_mem_size
= 0x800 +
1218 list_count
* sizeof(struct mvfrey_inlist_entry
) +
1219 list_count
* sizeof(struct mvfrey_outlist_entry
) +
1222 p
= dma_alloc_coherent(&hba
->pcidev
->dev
,
1223 hba
->u
.mvfrey
.internal_mem_size
, &phy
, GFP_KERNEL
);
1227 hba
->u
.mvfrey
.internal_req
.req_virt
= p
;
1228 hba
->u
.mvfrey
.internal_req
.req_shifted_phy
= phy
>> 5;
1229 hba
->u
.mvfrey
.internal_req
.scp
= NULL
;
1230 hba
->u
.mvfrey
.internal_req
.next
= NULL
;
1235 hba
->u
.mvfrey
.inlist
= (struct mvfrey_inlist_entry
*)p
;
1236 hba
->u
.mvfrey
.inlist_phy
= phy
;
1238 p
+= list_count
* sizeof(struct mvfrey_inlist_entry
);
1239 phy
+= list_count
* sizeof(struct mvfrey_inlist_entry
);
1241 hba
->u
.mvfrey
.outlist
= (struct mvfrey_outlist_entry
*)p
;
1242 hba
->u
.mvfrey
.outlist_phy
= phy
;
1244 p
+= list_count
* sizeof(struct mvfrey_outlist_entry
);
1245 phy
+= list_count
* sizeof(struct mvfrey_outlist_entry
);
1247 hba
->u
.mvfrey
.outlist_cptr
= (__le32
*)p
;
1248 hba
->u
.mvfrey
.outlist_cptr_phy
= phy
;
1253 static int hptiop_internal_memfree_itl(struct hptiop_hba
*hba
)
1258 static int hptiop_internal_memfree_mv(struct hptiop_hba
*hba
)
1260 if (hba
->u
.mv
.internal_req
) {
1261 dma_free_coherent(&hba
->pcidev
->dev
, 0x800,
1262 hba
->u
.mv
.internal_req
, hba
->u
.mv
.internal_req_phy
);
1268 static int hptiop_internal_memfree_mvfrey(struct hptiop_hba
*hba
)
1270 if (hba
->u
.mvfrey
.internal_req
.req_virt
) {
1271 dma_free_coherent(&hba
->pcidev
->dev
,
1272 hba
->u
.mvfrey
.internal_mem_size
,
1273 hba
->u
.mvfrey
.internal_req
.req_virt
,
1275 hba
->u
.mvfrey
.internal_req
.req_shifted_phy
<< 5);
1281 static int hptiop_probe(struct pci_dev
*pcidev
, const struct pci_device_id
*id
)
1283 struct Scsi_Host
*host
= NULL
;
1284 struct hptiop_hba
*hba
;
1285 struct hptiop_adapter_ops
*iop_ops
;
1286 struct hpt_iop_request_get_config iop_config
;
1287 struct hpt_iop_request_set_config set_config
;
1288 dma_addr_t start_phy
;
1290 u32 offset
, i
, req_size
;
1292 dprintk("hptiop_probe(%p)\n", pcidev
);
1294 if (pci_enable_device(pcidev
)) {
1295 printk(KERN_ERR
"hptiop: fail to enable pci device\n");
1299 printk(KERN_INFO
"adapter at PCI %d:%d:%d, IRQ %d\n",
1300 pcidev
->bus
->number
, pcidev
->devfn
>> 3, pcidev
->devfn
& 7,
1303 pci_set_master(pcidev
);
1305 /* Enable 64bit DMA if possible */
1306 iop_ops
= (struct hptiop_adapter_ops
*)id
->driver_data
;
1307 if (pci_set_dma_mask(pcidev
, DMA_BIT_MASK(iop_ops
->hw_dma_bit_mask
))) {
1308 if (pci_set_dma_mask(pcidev
, DMA_BIT_MASK(32))) {
1309 printk(KERN_ERR
"hptiop: fail to set dma_mask\n");
1310 goto disable_pci_device
;
1314 if (pci_request_regions(pcidev
, driver_name
)) {
1315 printk(KERN_ERR
"hptiop: pci_request_regions failed\n");
1316 goto disable_pci_device
;
1319 host
= scsi_host_alloc(&driver_template
, sizeof(struct hptiop_hba
));
1321 printk(KERN_ERR
"hptiop: fail to alloc scsi host\n");
1322 goto free_pci_regions
;
1325 hba
= (struct hptiop_hba
*)host
->hostdata
;
1328 hba
->pcidev
= pcidev
;
1330 hba
->initialized
= 0;
1331 hba
->iopintf_v2
= 0;
1333 atomic_set(&hba
->resetting
, 0);
1334 atomic_set(&hba
->reset_count
, 0);
1336 init_waitqueue_head(&hba
->reset_wq
);
1337 init_waitqueue_head(&hba
->ioctl_wq
);
1340 host
->max_channel
= 0;
1342 host
->n_io_port
= 0;
1343 host
->irq
= pcidev
->irq
;
1345 if (hba
->ops
->map_pci_bar(hba
))
1346 goto free_scsi_host
;
1348 if (hba
->ops
->iop_wait_ready(hba
, 20000)) {
1349 printk(KERN_ERR
"scsi%d: firmware not ready\n",
1350 hba
->host
->host_no
);
1354 if (hba
->ops
->family
== MV_BASED_IOP
) {
1355 if (hba
->ops
->internal_memalloc(hba
)) {
1356 printk(KERN_ERR
"scsi%d: internal_memalloc failed\n",
1357 hba
->host
->host_no
);
1362 if (hba
->ops
->get_config(hba
, &iop_config
)) {
1363 printk(KERN_ERR
"scsi%d: get config failed\n",
1364 hba
->host
->host_no
);
1368 hba
->max_requests
= min(le32_to_cpu(iop_config
.max_requests
),
1369 HPTIOP_MAX_REQUESTS
);
1370 hba
->max_devices
= le32_to_cpu(iop_config
.max_devices
);
1371 hba
->max_request_size
= le32_to_cpu(iop_config
.request_size
);
1372 hba
->max_sg_descriptors
= le32_to_cpu(iop_config
.max_sg_count
);
1373 hba
->firmware_version
= le32_to_cpu(iop_config
.firmware_version
);
1374 hba
->interface_version
= le32_to_cpu(iop_config
.interface_version
);
1375 hba
->sdram_size
= le32_to_cpu(iop_config
.sdram_size
);
1377 if (hba
->ops
->family
== MVFREY_BASED_IOP
) {
1378 if (hba
->ops
->internal_memalloc(hba
)) {
1379 printk(KERN_ERR
"scsi%d: internal_memalloc failed\n",
1380 hba
->host
->host_no
);
1383 if (hba
->ops
->reset_comm(hba
)) {
1384 printk(KERN_ERR
"scsi%d: reset comm failed\n",
1385 hba
->host
->host_no
);
1390 if (hba
->firmware_version
> 0x01020000 ||
1391 hba
->interface_version
> 0x01020000)
1392 hba
->iopintf_v2
= 1;
1394 host
->max_sectors
= le32_to_cpu(iop_config
.data_transfer_length
) >> 9;
1395 host
->max_id
= le32_to_cpu(iop_config
.max_devices
);
1396 host
->sg_tablesize
= le32_to_cpu(iop_config
.max_sg_count
);
1397 host
->can_queue
= le32_to_cpu(iop_config
.max_requests
);
1398 host
->cmd_per_lun
= le32_to_cpu(iop_config
.max_requests
);
1399 host
->max_cmd_len
= 16;
1401 req_size
= sizeof(struct hpt_iop_request_scsi_command
)
1402 + sizeof(struct hpt_iopsg
) * (hba
->max_sg_descriptors
- 1);
1403 if ((req_size
& 0x1f) != 0)
1404 req_size
= (req_size
+ 0x1f) & ~0x1f;
1406 memset(&set_config
, 0, sizeof(struct hpt_iop_request_set_config
));
1407 set_config
.iop_id
= cpu_to_le32(host
->host_no
);
1408 set_config
.vbus_id
= cpu_to_le16(host
->host_no
);
1409 set_config
.max_host_request_size
= cpu_to_le16(req_size
);
1411 if (hba
->ops
->set_config(hba
, &set_config
)) {
1412 printk(KERN_ERR
"scsi%d: set config failed\n",
1413 hba
->host
->host_no
);
1417 pci_set_drvdata(pcidev
, host
);
1419 if (request_irq(pcidev
->irq
, hptiop_intr
, IRQF_SHARED
,
1420 driver_name
, hba
)) {
1421 printk(KERN_ERR
"scsi%d: request irq %d failed\n",
1422 hba
->host
->host_no
, pcidev
->irq
);
1426 /* Allocate request mem */
1428 dprintk("req_size=%d, max_requests=%d\n", req_size
, hba
->max_requests
);
1430 hba
->req_size
= req_size
;
1431 start_virt
= dma_alloc_coherent(&pcidev
->dev
,
1432 hba
->req_size
*hba
->max_requests
+ 0x20,
1433 &start_phy
, GFP_KERNEL
);
1436 printk(KERN_ERR
"scsi%d: fail to alloc request mem\n",
1437 hba
->host
->host_no
);
1438 goto free_request_irq
;
1441 hba
->dma_coherent
= start_virt
;
1442 hba
->dma_coherent_handle
= start_phy
;
1444 if ((start_phy
& 0x1f) != 0) {
1445 offset
= ((start_phy
+ 0x1f) & ~0x1f) - start_phy
;
1446 start_phy
+= offset
;
1447 start_virt
+= offset
;
1450 hba
->req_list
= NULL
;
1451 for (i
= 0; i
< hba
->max_requests
; i
++) {
1452 hba
->reqs
[i
].next
= NULL
;
1453 hba
->reqs
[i
].req_virt
= start_virt
;
1454 hba
->reqs
[i
].req_shifted_phy
= start_phy
>> 5;
1455 hba
->reqs
[i
].index
= i
;
1456 free_req(hba
, &hba
->reqs
[i
]);
1457 start_virt
= (char *)start_virt
+ hba
->req_size
;
1458 start_phy
= start_phy
+ hba
->req_size
;
1461 /* Enable Interrupt and start background task */
1462 if (hptiop_initialize_iop(hba
))
1463 goto free_request_mem
;
1465 if (scsi_add_host(host
, &pcidev
->dev
)) {
1466 printk(KERN_ERR
"scsi%d: scsi_add_host failed\n",
1467 hba
->host
->host_no
);
1468 goto free_request_mem
;
1471 scsi_scan_host(host
);
1473 dprintk("scsi%d: hptiop_probe successfully\n", hba
->host
->host_no
);
1477 dma_free_coherent(&hba
->pcidev
->dev
,
1478 hba
->req_size
* hba
->max_requests
+ 0x20,
1479 hba
->dma_coherent
, hba
->dma_coherent_handle
);
1482 free_irq(hba
->pcidev
->irq
, hba
);
1485 hba
->ops
->internal_memfree(hba
);
1487 hba
->ops
->unmap_pci_bar(hba
);
1490 scsi_host_put(host
);
1493 pci_release_regions(pcidev
);
1496 pci_disable_device(pcidev
);
1498 dprintk("scsi%d: hptiop_probe fail\n", host
? host
->host_no
: 0);
1502 static void hptiop_shutdown(struct pci_dev
*pcidev
)
1504 struct Scsi_Host
*host
= pci_get_drvdata(pcidev
);
1505 struct hptiop_hba
*hba
= (struct hptiop_hba
*)host
->hostdata
;
1507 dprintk("hptiop_shutdown(%p)\n", hba
);
1510 if (iop_send_sync_msg(hba
, IOPMU_INBOUND_MSG0_SHUTDOWN
, 60000))
1511 printk(KERN_ERR
"scsi%d: shutdown the iop timeout\n",
1512 hba
->host
->host_no
);
1514 /* disable all outbound interrupts */
1515 hba
->ops
->disable_intr(hba
);
1518 static void hptiop_disable_intr_itl(struct hptiop_hba
*hba
)
1522 int_mask
= readl(&hba
->u
.itl
.iop
->outbound_intmask
);
1524 IOPMU_OUTBOUND_INT_MSG0
| IOPMU_OUTBOUND_INT_POSTQUEUE
,
1525 &hba
->u
.itl
.iop
->outbound_intmask
);
1526 readl(&hba
->u
.itl
.iop
->outbound_intmask
);
1529 static void hptiop_disable_intr_mv(struct hptiop_hba
*hba
)
1531 writel(0, &hba
->u
.mv
.regs
->outbound_intmask
);
1532 readl(&hba
->u
.mv
.regs
->outbound_intmask
);
1535 static void hptiop_disable_intr_mvfrey(struct hptiop_hba
*hba
)
1537 writel(0, &(hba
->u
.mvfrey
.mu
->f0_doorbell_enable
));
1538 readl(&(hba
->u
.mvfrey
.mu
->f0_doorbell_enable
));
1539 writel(0, &(hba
->u
.mvfrey
.mu
->isr_enable
));
1540 readl(&(hba
->u
.mvfrey
.mu
->isr_enable
));
1541 writel(0, &(hba
->u
.mvfrey
.mu
->pcie_f0_int_enable
));
1542 readl(&(hba
->u
.mvfrey
.mu
->pcie_f0_int_enable
));
1545 static void hptiop_remove(struct pci_dev
*pcidev
)
1547 struct Scsi_Host
*host
= pci_get_drvdata(pcidev
);
1548 struct hptiop_hba
*hba
= (struct hptiop_hba
*)host
->hostdata
;
1550 dprintk("scsi%d: hptiop_remove\n", hba
->host
->host_no
);
1552 scsi_remove_host(host
);
1554 hptiop_shutdown(pcidev
);
1556 free_irq(hba
->pcidev
->irq
, hba
);
1558 dma_free_coherent(&hba
->pcidev
->dev
,
1559 hba
->req_size
* hba
->max_requests
+ 0x20,
1561 hba
->dma_coherent_handle
);
1563 hba
->ops
->internal_memfree(hba
);
1565 hba
->ops
->unmap_pci_bar(hba
);
1567 pci_release_regions(hba
->pcidev
);
1568 pci_set_drvdata(hba
->pcidev
, NULL
);
1569 pci_disable_device(hba
->pcidev
);
1571 scsi_host_put(host
);
1574 static struct hptiop_adapter_ops hptiop_itl_ops
= {
1575 .family
= INTEL_BASED_IOP
,
1576 .iop_wait_ready
= iop_wait_ready_itl
,
1577 .internal_memalloc
= hptiop_internal_memalloc_itl
,
1578 .internal_memfree
= hptiop_internal_memfree_itl
,
1579 .map_pci_bar
= hptiop_map_pci_bar_itl
,
1580 .unmap_pci_bar
= hptiop_unmap_pci_bar_itl
,
1581 .enable_intr
= hptiop_enable_intr_itl
,
1582 .disable_intr
= hptiop_disable_intr_itl
,
1583 .get_config
= iop_get_config_itl
,
1584 .set_config
= iop_set_config_itl
,
1585 .iop_intr
= iop_intr_itl
,
1586 .post_msg
= hptiop_post_msg_itl
,
1587 .post_req
= hptiop_post_req_itl
,
1588 .hw_dma_bit_mask
= 64,
1589 .reset_comm
= hptiop_reset_comm_itl
,
1590 .host_phy_flag
= cpu_to_le64(0),
1593 static struct hptiop_adapter_ops hptiop_mv_ops
= {
1594 .family
= MV_BASED_IOP
,
1595 .iop_wait_ready
= iop_wait_ready_mv
,
1596 .internal_memalloc
= hptiop_internal_memalloc_mv
,
1597 .internal_memfree
= hptiop_internal_memfree_mv
,
1598 .map_pci_bar
= hptiop_map_pci_bar_mv
,
1599 .unmap_pci_bar
= hptiop_unmap_pci_bar_mv
,
1600 .enable_intr
= hptiop_enable_intr_mv
,
1601 .disable_intr
= hptiop_disable_intr_mv
,
1602 .get_config
= iop_get_config_mv
,
1603 .set_config
= iop_set_config_mv
,
1604 .iop_intr
= iop_intr_mv
,
1605 .post_msg
= hptiop_post_msg_mv
,
1606 .post_req
= hptiop_post_req_mv
,
1607 .hw_dma_bit_mask
= 33,
1608 .reset_comm
= hptiop_reset_comm_mv
,
1609 .host_phy_flag
= cpu_to_le64(0),
1612 static struct hptiop_adapter_ops hptiop_mvfrey_ops
= {
1613 .family
= MVFREY_BASED_IOP
,
1614 .iop_wait_ready
= iop_wait_ready_mvfrey
,
1615 .internal_memalloc
= hptiop_internal_memalloc_mvfrey
,
1616 .internal_memfree
= hptiop_internal_memfree_mvfrey
,
1617 .map_pci_bar
= hptiop_map_pci_bar_mvfrey
,
1618 .unmap_pci_bar
= hptiop_unmap_pci_bar_mvfrey
,
1619 .enable_intr
= hptiop_enable_intr_mvfrey
,
1620 .disable_intr
= hptiop_disable_intr_mvfrey
,
1621 .get_config
= iop_get_config_mvfrey
,
1622 .set_config
= iop_set_config_mvfrey
,
1623 .iop_intr
= iop_intr_mvfrey
,
1624 .post_msg
= hptiop_post_msg_mvfrey
,
1625 .post_req
= hptiop_post_req_mvfrey
,
1626 .hw_dma_bit_mask
= 64,
1627 .reset_comm
= hptiop_reset_comm_mvfrey
,
1628 .host_phy_flag
= cpu_to_le64(1),
1631 static struct pci_device_id hptiop_id_table
[] = {
1632 { PCI_VDEVICE(TTI
, 0x3220), (kernel_ulong_t
)&hptiop_itl_ops
},
1633 { PCI_VDEVICE(TTI
, 0x3320), (kernel_ulong_t
)&hptiop_itl_ops
},
1634 { PCI_VDEVICE(TTI
, 0x3410), (kernel_ulong_t
)&hptiop_itl_ops
},
1635 { PCI_VDEVICE(TTI
, 0x3510), (kernel_ulong_t
)&hptiop_itl_ops
},
1636 { PCI_VDEVICE(TTI
, 0x3511), (kernel_ulong_t
)&hptiop_itl_ops
},
1637 { PCI_VDEVICE(TTI
, 0x3520), (kernel_ulong_t
)&hptiop_itl_ops
},
1638 { PCI_VDEVICE(TTI
, 0x3521), (kernel_ulong_t
)&hptiop_itl_ops
},
1639 { PCI_VDEVICE(TTI
, 0x3522), (kernel_ulong_t
)&hptiop_itl_ops
},
1640 { PCI_VDEVICE(TTI
, 0x3530), (kernel_ulong_t
)&hptiop_itl_ops
},
1641 { PCI_VDEVICE(TTI
, 0x3540), (kernel_ulong_t
)&hptiop_itl_ops
},
1642 { PCI_VDEVICE(TTI
, 0x3560), (kernel_ulong_t
)&hptiop_itl_ops
},
1643 { PCI_VDEVICE(TTI
, 0x4210), (kernel_ulong_t
)&hptiop_itl_ops
},
1644 { PCI_VDEVICE(TTI
, 0x4211), (kernel_ulong_t
)&hptiop_itl_ops
},
1645 { PCI_VDEVICE(TTI
, 0x4310), (kernel_ulong_t
)&hptiop_itl_ops
},
1646 { PCI_VDEVICE(TTI
, 0x4311), (kernel_ulong_t
)&hptiop_itl_ops
},
1647 { PCI_VDEVICE(TTI
, 0x4320), (kernel_ulong_t
)&hptiop_itl_ops
},
1648 { PCI_VDEVICE(TTI
, 0x4321), (kernel_ulong_t
)&hptiop_itl_ops
},
1649 { PCI_VDEVICE(TTI
, 0x4322), (kernel_ulong_t
)&hptiop_itl_ops
},
1650 { PCI_VDEVICE(TTI
, 0x4400), (kernel_ulong_t
)&hptiop_itl_ops
},
1651 { PCI_VDEVICE(TTI
, 0x3120), (kernel_ulong_t
)&hptiop_mv_ops
},
1652 { PCI_VDEVICE(TTI
, 0x3122), (kernel_ulong_t
)&hptiop_mv_ops
},
1653 { PCI_VDEVICE(TTI
, 0x3020), (kernel_ulong_t
)&hptiop_mv_ops
},
1654 { PCI_VDEVICE(TTI
, 0x4520), (kernel_ulong_t
)&hptiop_mvfrey_ops
},
1655 { PCI_VDEVICE(TTI
, 0x4522), (kernel_ulong_t
)&hptiop_mvfrey_ops
},
1659 MODULE_DEVICE_TABLE(pci
, hptiop_id_table
);
1661 static struct pci_driver hptiop_pci_driver
= {
1662 .name
= driver_name
,
1663 .id_table
= hptiop_id_table
,
1664 .probe
= hptiop_probe
,
1665 .remove
= hptiop_remove
,
1666 .shutdown
= hptiop_shutdown
,
1669 static int __init
hptiop_module_init(void)
1671 printk(KERN_INFO
"%s %s\n", driver_name_long
, driver_ver
);
1672 return pci_register_driver(&hptiop_pci_driver
);
1675 static void __exit
hptiop_module_exit(void)
1677 pci_unregister_driver(&hptiop_pci_driver
);
1681 module_init(hptiop_module_init
);
1682 module_exit(hptiop_module_exit
);
1684 MODULE_LICENSE("GPL");