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>
24 #include <linux/errno.h>
29 #include <asm/uaccess.h>
31 #include <asm/div64.h>
34 #include <scsi/scsi.h>
44 static const char driver_name_long[] =
"RocketRAID 3xxx/4xxx Controller driver";
45 static const char driver_ver[] =
"v1.6 (091225)";
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);
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);
68 readl(&hba->
u.
itl.iop->outbound_intstatus);
75 static int iop_wait_ready_mv(
struct hptiop_hba *hba,
u32 millisec)
83 hptiop_host_request_callback_itl(hba,
84 tag & ~IOPMU_QUEUE_ADDR_HOST_BIT);
86 hptiop_iop_request_callback_itl(hba, tag);
89 static void hptiop_drain_outbound_queue_itl(
struct hptiop_hba *hba)
93 while ((req =
readl(&hba->
u.
itl.iop->outbound_queue)) !=
97 hptiop_request_callback_itl(hba, req);
106 hptiop_request_callback_itl(hba, req);
111 hptiop_request_callback_itl(hba, req);
116 static int iop_intr_itl(
struct hptiop_hba *hba)
123 if (plx &&
readl(plx + 0x11C5C) & 0xf)
131 dprintk(
"received outbound msg %x\n", msg);
133 hptiop_message_callback(hba, msg);
138 hptiop_drain_outbound_queue_itl(hba);
147 u32 outbound_tail =
readl(&mu->outbound_tail);
148 u32 outbound_head =
readl(&mu->outbound_head);
150 if (outbound_tail != outbound_head) {
158 writel(outbound_tail, &mu->outbound_tail);
166 u32 inbound_head =
readl(&hba->
u.
mv.mu->inbound_head);
173 writel(head, &hba->
u.
mv.mu->inbound_head);
175 &hba->
u.
mv.regs->inbound_doorbell);
178 static void hptiop_request_callback_mv(
struct hptiop_hba *hba,
u64 tag)
180 u32 req_type = (tag >> 5) & 0x7;
183 dprintk(
"hptiop_request_callback_mv: tag=%llx\n", tag);
194 req = hba->
reqs[tag >> 8].req_virt;
198 hptiop_finish_scsi_req(hba, tag>>8, req);
206 static int iop_intr_mv(
struct hptiop_hba *hba)
211 status =
readl(&hba->
u.
mv.regs->outbound_doorbell);
212 writel(~status, &hba->
u.
mv.regs->outbound_doorbell);
216 msg =
readl(&hba->
u.
mv.mu->outbound_msg);
217 dprintk(
"received outbound msg %x\n", msg);
218 hptiop_message_callback(hba, msg);
225 while ((tag = mv_outbound_read(hba->
u.
mv.mu)))
226 hptiop_request_callback_mv(hba, tag);
233 static int iop_send_sync_request_itl(
struct hptiop_hba *hba,
241 writel((
unsigned long)req - (
unsigned long)hba->
u.
itl.iop,
242 &hba->
u.
itl.iop->inbound_queue);
243 readl(&hba->
u.
itl.iop->outbound_intstatus);
245 for (i = 0; i < millisec; i++) {
255 static int iop_send_sync_request_mv(
struct hptiop_hba *hba,
256 u32 size_bits,
u32 millisec)
263 mv_inbound_write(hba->
u.
mv.internal_req_phy |
266 for (i = 0; i < millisec; i++) {
277 writel(msg, &hba->
u.
itl.iop->inbound_msgaddr0);
278 readl(&hba->
u.
itl.iop->outbound_intstatus);
285 readl(&hba->
u.
mv.regs->inbound_doorbell);
293 hba->
ops->post_msg(hba, msg);
295 for (i = 0; i < millisec; i++) {
296 spin_lock_irq(hba->
host->host_lock);
297 hba->
ops->iop_intr(hba);
298 spin_unlock_irq(hba->
host->host_lock);
307 static int iop_get_config_itl(
struct hptiop_hba *hba,
313 req32 =
readl(&hba->
u.
itl.iop->inbound_queue);
318 ((
unsigned long)hba->
u.
itl.iop + req32);
325 if (iop_send_sync_request_itl(hba, req, 20000)) {
326 dprintk(
"Get config send cmd failed\n");
331 writel(req32, &hba->
u.
itl.iop->outbound_queue);
335 static int iop_get_config_mv(
struct hptiop_hba *hba,
346 req->
header.context_hi32 = 0;
348 if (iop_send_sync_request_mv(hba, 0, 20000)) {
349 dprintk(
"Get config send cmd failed\n");
357 static int iop_set_config_itl(
struct hptiop_hba *hba,
363 req32 =
readl(&hba->
u.
itl.iop->inbound_queue);
368 ((
unsigned long)hba->
u.
itl.iop + req32);
380 if (iop_send_sync_request_itl(hba, req, 20000)) {
381 dprintk(
"Set config send cmd failed\n");
385 writel(req32, &hba->
u.
itl.iop->outbound_queue);
389 static int iop_set_config_mv(
struct hptiop_hba *hba,
401 req->
header.context_hi32 = 0;
403 if (iop_send_sync_request_mv(hba, 0, 20000)) {
404 dprintk(
"Set config send cmd failed\n");
411 static void hptiop_enable_intr_itl(
struct hptiop_hba *hba)
414 &hba->
u.
itl.iop->outbound_intmask);
417 static void hptiop_enable_intr_mv(
struct hptiop_hba *hba)
419 writel(MVIOP_MU_OUTBOUND_INT_POSTQUEUE | MVIOP_MU_OUTBOUND_INT_MSG,
420 &hba->
u.
mv.regs->outbound_intmask);
423 static int hptiop_initialize_iop(
struct hptiop_hba *hba)
426 hba->
ops->enable_intr(hba);
431 if (iop_send_sync_msg(hba,
456 mem_base_virt =
ioremap(mem_base_phy, length);
458 if (!mem_base_virt) {
463 return mem_base_virt;
466 static int hptiop_map_pci_bar_itl(
struct hptiop_hba *hba)
469 hba->
u.
itl.iop = hptiop_map_pci_bar(hba, 0);
472 if ((pcidev->
device & 0xff00) == 0x4400) {
474 hba->
u.
itl.iop = hptiop_map_pci_bar(hba, 2);
483 static void hptiop_unmap_pci_bar_itl(
struct hptiop_hba *hba)
490 static int hptiop_map_pci_bar_mv(
struct hptiop_hba *hba)
492 hba->
u.
mv.regs = hptiop_map_pci_bar(hba, 0);
496 hba->
u.
mv.mu = hptiop_map_pci_bar(hba, 2);
505 static void hptiop_unmap_pci_bar_mv(
struct hptiop_hba *hba)
511 static void hptiop_message_callback(
struct hptiop_hba *hba,
u32 msg)
513 dprintk(
"iop message 0x%x\n", msg);
549 static void hptiop_finish_scsi_req(
struct hptiop_hba *hba,
u32 tag,
554 dprintk(
"hptiop_finish_scsi_req: req=%p, type=%d, "
555 "result=%d, context=0x%x tag=%d\n",
557 req->
header.context, tag);
602 dprintk(
"scsi_done(%p)\n", scp);
604 free_req(hba, &hba->
reqs[tag]);
622 hptiop_finish_scsi_req(hba, tag, req);
625 void hptiop_iop_request_callback_itl(
struct hptiop_hba *hba,
u32 tag)
632 ((
unsigned long)hba->
u.
itl.iop +
tag);
633 dprintk(
"hptiop_iop_request_callback_itl: req=%p, type=%d, "
634 "result=%d, context=0x%x tag=%d\n",
671 handled = hba->
ops->iop_intr(hba);
672 spin_unlock_irqrestore(hba->
host->host_lock, flags);
703 static void hptiop_post_req_itl(
struct hptiop_hba *hba,
724 &hba->
u.
itl.iop->inbound_queue);
727 &hba->
u.
itl.iop->inbound_queue);
730 static void hptiop_post_req_mv(
struct hptiop_hba *hba,
743 else if (size <= 256*2)
745 else if (size <= 256*3)
754 static int hptiop_queuecommand_lck(
struct scsi_cmnd *scp,
768 dprintk(
"hptiop_queuecmd : no free req\n");
774 dprintk(
"hptiop_queuecmd(scp=%p) %d/%d/%d/%d cdb=(%x-%x-%x) "
775 "req_index=%d, req=%p\n",
796 sg_count = hptiop_buildsgl(scp, req->sg_list);
803 req->dataxfer_length =
cpu_to_le32(scsi_bufflen(scp));
804 req->channel = scp->
device->channel;
805 req->target = scp->
device->id;
806 req->lun = scp->
device->lun;
812 memcpy(req->cdb, scp->
cmnd,
sizeof(req->cdb));
813 hba->
ops->post_req(hba, _req);
817 dprintk(
"scsi_done(scp=%p)\n", scp);
826 return driver_name_long;
829 static int hptiop_reset_hba(
struct hptiop_hba *hba)
845 if (iop_send_sync_msg(hba,
847 dprintk(
"scsi%d: fail to start background task\n",
854 static int hptiop_reset(
struct scsi_cmnd *scp)
866 static int hptiop_adjust_disk_queue_depth(
struct scsi_device *sdev,
901 .name =
"driver-version",
904 .show = hptiop_show_version,
909 .name =
"firmware-version",
912 .show = hptiop_show_fw_version,
916 &hptiop_attr_version,
917 &hptiop_attr_fw_version,
924 .queuecommand = hptiop_queuecommand,
925 .eh_device_reset_handler = hptiop_reset,
926 .eh_bus_reset_handler = hptiop_reset,
931 .shost_attrs = hptiop_attrs,
933 .change_queue_depth = hptiop_adjust_disk_queue_depth,
936 static int hptiop_internal_memalloc_mv(
struct hptiop_hba *hba)
940 if (hba->
u.
mv.internal_req)
946 static int hptiop_internal_memfree_mv(
struct hptiop_hba *hba)
948 if (hba->
u.
mv.internal_req) {
950 hba->
u.
mv.internal_req, hba->
u.
mv.internal_req_phy);
968 dprintk(
"hptiop_probe(%p)\n", pcidev);
986 goto disable_pci_device;
992 goto disable_pci_device;
998 goto free_pci_regions;
1021 if (hba->
ops->map_pci_bar(hba))
1022 goto free_scsi_host;
1024 if (hba->
ops->iop_wait_ready(hba, 20000)) {
1026 hba->
host->host_no);
1030 if (hba->
ops->internal_memalloc) {
1031 if (hba->
ops->internal_memalloc(hba)) {
1033 hba->
host->host_no);
1038 if (hba->
ops->get_config(hba, &iop_config)) {
1040 hba->
host->host_no);
1066 if ((req_size & 0x1f) != 0)
1067 req_size = (req_size + 0x1f) & ~0x1f;
1072 set_config.max_host_request_size =
cpu_to_le16(req_size);
1074 if (hba->
ops->set_config(hba, &set_config)) {
1076 hba->
host->host_no);
1080 pci_set_drvdata(pcidev, host);
1085 hba->
host->host_no, pcidev->
irq);
1100 hba->
host->host_no);
1101 goto free_request_irq;
1107 if ((start_phy & 0x1f) != 0)
1109 offset = ((start_phy + 0x1f) & ~0x1f) - start_phy;
1117 hba->
reqs[
i].req_virt = start_virt;
1118 hba->
reqs[
i].req_shifted_phy = start_phy >> 5;
1120 free_req(hba, &hba->
reqs[i]);
1121 start_virt = (
char *)start_virt + hba->
req_size;
1122 start_phy = start_phy + hba->
req_size;
1126 if (hptiop_initialize_iop(hba))
1127 goto free_request_mem;
1129 if (scsi_add_host(host, &pcidev->
dev)) {
1131 hba->
host->host_no);
1132 goto free_request_mem;
1138 dprintk(
"scsi%d: hptiop_probe successfully\n", hba->
host->host_no);
1150 if (hba->
ops->internal_memfree)
1151 hba->
ops->internal_memfree(hba);
1153 hba->
ops->unmap_pci_bar(hba);
1164 dprintk(
"scsi%d: hptiop_probe fail\n", host ? host->
host_no : 0);
1168 static void hptiop_shutdown(
struct pci_dev *pcidev)
1170 struct Scsi_Host *host = pci_get_drvdata(pcidev);
1173 dprintk(
"hptiop_shutdown(%p)\n", hba);
1178 hba->
host->host_no);
1181 hba->
ops->disable_intr(hba);
1184 static void hptiop_disable_intr_itl(
struct hptiop_hba *hba)
1188 int_mask =
readl(&hba->
u.
itl.iop->outbound_intmask);
1191 &hba->
u.
itl.iop->outbound_intmask);
1192 readl(&hba->
u.
itl.iop->outbound_intmask);
1195 static void hptiop_disable_intr_mv(
struct hptiop_hba *hba)
1197 writel(0, &hba->
u.
mv.regs->outbound_intmask);
1198 readl(&hba->
u.
mv.regs->outbound_intmask);
1201 static void hptiop_remove(
struct pci_dev *pcidev)
1203 struct Scsi_Host *host = pci_get_drvdata(pcidev);
1206 dprintk(
"scsi%d: hptiop_remove\n", hba->
host->host_no);
1210 hptiop_shutdown(pcidev);
1219 if (hba->
ops->internal_memfree)
1220 hba->
ops->internal_memfree(hba);
1222 hba->
ops->unmap_pci_bar(hba);
1232 .iop_wait_ready = iop_wait_ready_itl,
1233 .internal_memalloc =
NULL,
1234 .internal_memfree =
NULL,
1235 .map_pci_bar = hptiop_map_pci_bar_itl,
1236 .unmap_pci_bar = hptiop_unmap_pci_bar_itl,
1237 .enable_intr = hptiop_enable_intr_itl,
1238 .disable_intr = hptiop_disable_intr_itl,
1239 .get_config = iop_get_config_itl,
1240 .set_config = iop_set_config_itl,
1241 .iop_intr = iop_intr_itl,
1242 .post_msg = hptiop_post_msg_itl,
1243 .post_req = hptiop_post_req_itl,
1244 .hw_dma_bit_mask = 64,
1248 .iop_wait_ready = iop_wait_ready_mv,
1249 .internal_memalloc = hptiop_internal_memalloc_mv,
1250 .internal_memfree = hptiop_internal_memfree_mv,
1251 .map_pci_bar = hptiop_map_pci_bar_mv,
1252 .unmap_pci_bar = hptiop_unmap_pci_bar_mv,
1253 .enable_intr = hptiop_enable_intr_mv,
1254 .disable_intr = hptiop_disable_intr_mv,
1255 .get_config = iop_get_config_mv,
1256 .set_config = iop_set_config_mv,
1257 .iop_intr = iop_intr_mv,
1258 .post_msg = hptiop_post_msg_mv,
1259 .post_req = hptiop_post_req_mv,
1260 .hw_dma_bit_mask = 33,
1291 static struct pci_driver hptiop_pci_driver = {
1293 .id_table = hptiop_id_table,
1294 .probe = hptiop_probe,
1295 .remove = hptiop_remove,
1296 .shutdown = hptiop_shutdown,
1299 static int __init hptiop_module_init(
void)
1302 return pci_register_driver(&hptiop_pci_driver);
1305 static void __exit hptiop_module_exit(
void)