[SCSI] Remove SUGGEST flags
[safe/jmp/linux-2.6] / drivers / scsi / hptiop.c
index f778083..af1f0af 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * HighPoint RR3xxx controller driver for Linux
- * Copyright (C) 2006 HighPoint Technologies, Inc. All Rights Reserved.
+ * HighPoint RR3xxx/4xxx controller driver for Linux
+ * Copyright (C) 2006-2007 HighPoint Technologies, Inc. All Rights Reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,6 @@
  *
  * For more information, visit http://www.highpoint-tech.com
  */
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/string.h>
@@ -26,7 +25,6 @@
 #include <linux/delay.h>
 #include <linux/timer.h>
 #include <linux/spinlock.h>
-#include <linux/hdreg.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <asm/div64.h>
 #include "hptiop.h"
 
 MODULE_AUTHOR("HighPoint Technologies, Inc.");
-MODULE_DESCRIPTION("HighPoint RocketRAID 3xxx SATA Controller Driver");
+MODULE_DESCRIPTION("HighPoint RocketRAID 3xxx/4xxx Controller Driver");
 
 static char driver_name[] = "hptiop";
-static const char driver_name_long[] = "RocketRAID 3xxx SATA Controller driver";
-static const char driver_ver[] = "v1.0 (060426)";
-
-static DEFINE_SPINLOCK(hptiop_hba_list_lock);
-static LIST_HEAD(hptiop_hba_list);
-static int hptiop_cdev_major = -1;
-
-static void hptiop_host_request_callback(struct hptiop_hba *hba, u32 tag);
-static void hptiop_iop_request_callback(struct hptiop_hba *hba, u32 tag);
+static const char driver_name_long[] = "RocketRAID 3xxx/4xxx Controller driver";
+static const char driver_ver[] = "v1.3 (071203)";
+
+static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec);
+static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
+                               struct hpt_iop_request_scsi_command *req);
+static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 tag);
+static void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag);
 static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg);
 
-static inline void hptiop_pci_posting_flush(struct hpt_iopmu __iomem *iop)
-{
-       readl(&iop->outbound_intstatus);
-}
-
-static int iop_wait_ready(struct hpt_iopmu __iomem *iop, u32 millisec)
+static int iop_wait_ready_itl(struct hptiop_hba *hba, u32 millisec)
 {
        u32 req = 0;
        int i;
 
        for (i = 0; i < millisec; i++) {
-               req = readl(&iop->inbound_queue);
+               req = readl(&hba->u.itl.iop->inbound_queue);
                if (req != IOPMU_QUEUE_EMPTY)
                        break;
                msleep(1);
        }
 
        if (req != IOPMU_QUEUE_EMPTY) {
-               writel(req, &iop->outbound_queue);
-               hptiop_pci_posting_flush(iop);
+               writel(req, &hba->u.itl.iop->outbound_queue);
+               readl(&hba->u.itl.iop->outbound_intstatus);
                return 0;
        }
 
        return -1;
 }
 
-static void hptiop_request_callback(struct hptiop_hba *hba, u32 tag)
+static int iop_wait_ready_mv(struct hptiop_hba *hba, u32 millisec)
+{
+       return iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_NOP, millisec);
+}
+
+static void hptiop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
 {
-       if ((tag & IOPMU_QUEUE_MASK_HOST_BITS) == IOPMU_QUEUE_ADDR_HOST_BIT)
-               return hptiop_host_request_callback(hba,
+       if (tag & IOPMU_QUEUE_ADDR_HOST_BIT)
+               hptiop_host_request_callback_itl(hba,
                                tag & ~IOPMU_QUEUE_ADDR_HOST_BIT);
        else
-               return hptiop_iop_request_callback(hba, tag);
+               hptiop_iop_request_callback_itl(hba, tag);
 }
 
-static inline void hptiop_drain_outbound_queue(struct hptiop_hba *hba)
+static void hptiop_drain_outbound_queue_itl(struct hptiop_hba *hba)
 {
        u32 req;
 
-       while ((req = readl(&hba->iop->outbound_queue)) != IOPMU_QUEUE_EMPTY) {
+       while ((req = readl(&hba->u.itl.iop->outbound_queue)) !=
+                                               IOPMU_QUEUE_EMPTY) {
 
                if (req & IOPMU_QUEUE_MASK_HOST_BITS)
-                       hptiop_request_callback(hba, req);
+                       hptiop_request_callback_itl(hba, req);
                else {
                        struct hpt_iop_request_header __iomem * p;
 
                        p = (struct hpt_iop_request_header __iomem *)
-                               ((char __iomem *)hba->iop + req);
+                               ((char __iomem *)hba->u.itl.iop + req);
 
                        if (readl(&p->flags) & IOP_REQUEST_FLAG_SYNC_REQUEST) {
                                if (readl(&p->context))
-                                       hptiop_request_callback(hba, req);
+                                       hptiop_request_callback_itl(hba, req);
                                else
                                        writel(1, &p->context);
                        }
                        else
-                               hptiop_request_callback(hba, req);
+                               hptiop_request_callback_itl(hba, req);
                }
        }
 }
 
-static int __iop_intr(struct hptiop_hba *hba)
+static int iop_intr_itl(struct hptiop_hba *hba)
 {
-       struct hpt_iopmu __iomem *iop = hba->iop;
+       struct hpt_iopmu_itl __iomem *iop = hba->u.itl.iop;
        u32 status;
        int ret = 0;
 
@@ -124,6 +122,7 @@ static int __iop_intr(struct hptiop_hba *hba)
 
        if (status & IOPMU_OUTBOUND_INT_MSG0) {
                u32 msg = readl(&iop->outbound_msgaddr0);
+
                dprintk("received outbound msg %x\n", msg);
                writel(IOPMU_OUTBOUND_INT_MSG0, &iop->outbound_intstatus);
                hptiop_message_callback(hba, msg);
@@ -131,31 +130,115 @@ static int __iop_intr(struct hptiop_hba *hba)
        }
 
        if (status & IOPMU_OUTBOUND_INT_POSTQUEUE) {
-               hptiop_drain_outbound_queue(hba);
+               hptiop_drain_outbound_queue_itl(hba);
                ret = 1;
        }
 
        return ret;
 }
 
-static int iop_send_sync_request(struct hptiop_hba *hba,
+static u64 mv_outbound_read(struct hpt_iopmu_mv __iomem *mu)
+{
+       u32 outbound_tail = readl(&mu->outbound_tail);
+       u32 outbound_head = readl(&mu->outbound_head);
+
+       if (outbound_tail != outbound_head) {
+               u64 p;
+
+               memcpy_fromio(&p, &mu->outbound_q[mu->outbound_tail], 8);
+               outbound_tail++;
+
+               if (outbound_tail == MVIOP_QUEUE_LEN)
+                       outbound_tail = 0;
+               writel(outbound_tail, &mu->outbound_tail);
+               return p;
+       } else
+               return 0;
+}
+
+static void mv_inbound_write(u64 p, struct hptiop_hba *hba)
+{
+       u32 inbound_head = readl(&hba->u.mv.mu->inbound_head);
+       u32 head = inbound_head + 1;
+
+       if (head == MVIOP_QUEUE_LEN)
+               head = 0;
+
+       memcpy_toio(&hba->u.mv.mu->inbound_q[inbound_head], &p, 8);
+       writel(head, &hba->u.mv.mu->inbound_head);
+       writel(MVIOP_MU_INBOUND_INT_POSTQUEUE,
+                       &hba->u.mv.regs->inbound_doorbell);
+}
+
+static void hptiop_request_callback_mv(struct hptiop_hba *hba, u64 tag)
+{
+       u32 req_type = (tag >> 5) & 0x7;
+       struct hpt_iop_request_scsi_command *req;
+
+       dprintk("hptiop_request_callback_mv: tag=%llx\n", tag);
+
+       BUG_ON((tag & MVIOP_MU_QUEUE_REQUEST_RETURN_CONTEXT) == 0);
+
+       switch (req_type) {
+       case IOP_REQUEST_TYPE_GET_CONFIG:
+       case IOP_REQUEST_TYPE_SET_CONFIG:
+               hba->msg_done = 1;
+               break;
+
+       case IOP_REQUEST_TYPE_SCSI_COMMAND:
+               req = hba->reqs[tag >> 8].req_virt;
+               if (likely(tag & MVIOP_MU_QUEUE_REQUEST_RESULT_BIT))
+                       req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
+
+               hptiop_finish_scsi_req(hba, tag>>8, req);
+               break;
+
+       default:
+               break;
+       }
+}
+
+static int iop_intr_mv(struct hptiop_hba *hba)
+{
+       u32 status;
+       int ret = 0;
+
+       status = readl(&hba->u.mv.regs->outbound_doorbell);
+       writel(~status, &hba->u.mv.regs->outbound_doorbell);
+
+       if (status & MVIOP_MU_OUTBOUND_INT_MSG) {
+               u32 msg;
+               msg = readl(&hba->u.mv.mu->outbound_msg);
+               dprintk("received outbound msg %x\n", msg);
+               hptiop_message_callback(hba, msg);
+               ret = 1;
+       }
+
+       if (status & MVIOP_MU_OUTBOUND_INT_POSTQUEUE) {
+               u64 tag;
+
+               while ((tag = mv_outbound_read(hba->u.mv.mu)))
+                       hptiop_request_callback_mv(hba, tag);
+               ret = 1;
+       }
+
+       return ret;
+}
+
+static int iop_send_sync_request_itl(struct hptiop_hba *hba,
                                        void __iomem *_req, u32 millisec)
 {
        struct hpt_iop_request_header __iomem *req = _req;
        u32 i;
 
-       writel(readl(&req->flags) | IOP_REQUEST_FLAG_SYNC_REQUEST,
-                       &req->flags);
-
+       writel(readl(&req->flags) | IOP_REQUEST_FLAG_SYNC_REQUEST, &req->flags);
        writel(0, &req->context);
-
-       writel((unsigned long)req - (unsigned long)hba->iop,
-                       &hba->iop->inbound_queue);
-
-       hptiop_pci_posting_flush(hba->iop);
+       writel((unsigned long)req - (unsigned long)hba->u.itl.iop,
+                       &hba->u.itl.iop->inbound_queue);
+       readl(&hba->u.itl.iop->outbound_intstatus);
 
        for (i = 0; i < millisec; i++) {
-               __iop_intr(hba);
+               iop_intr_itl(hba);
                if (readl(&req->context))
                        return 0;
                msleep(1);
@@ -164,19 +247,49 @@ static int iop_send_sync_request(struct hptiop_hba *hba,
        return -1;
 }
 
-static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec)
+static int iop_send_sync_request_mv(struct hptiop_hba *hba,
+                                       u32 size_bits, u32 millisec)
 {
+       struct hpt_iop_request_header *reqhdr = hba->u.mv.internal_req;
        u32 i;
 
        hba->msg_done = 0;
+       reqhdr->flags |= cpu_to_le32(IOP_REQUEST_FLAG_SYNC_REQUEST);
+       mv_inbound_write(hba->u.mv.internal_req_phy |
+                       MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bits, hba);
+
+       for (i = 0; i < millisec; i++) {
+               iop_intr_mv(hba);
+               if (hba->msg_done)
+                       return 0;
+               msleep(1);
+       }
+       return -1;
+}
+
+static void hptiop_post_msg_itl(struct hptiop_hba *hba, u32 msg)
+{
+       writel(msg, &hba->u.itl.iop->inbound_msgaddr0);
+       readl(&hba->u.itl.iop->outbound_intstatus);
+}
+
+static void hptiop_post_msg_mv(struct hptiop_hba *hba, u32 msg)
+{
+       writel(msg, &hba->u.mv.mu->inbound_msg);
+       writel(MVIOP_MU_INBOUND_INT_MSG, &hba->u.mv.regs->inbound_doorbell);
+       readl(&hba->u.mv.regs->inbound_doorbell);
+}
 
-       writel(msg, &hba->iop->inbound_msgaddr0);
+static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec)
+{
+       u32 i;
 
-       hptiop_pci_posting_flush(hba->iop);
+       hba->msg_done = 0;
+       hba->ops->post_msg(hba, msg);
 
        for (i = 0; i < millisec; i++) {
                spin_lock_irq(hba->host->host_lock);
-               __iop_intr(hba);
+               hba->ops->iop_intr(hba);
                spin_unlock_irq(hba->host->host_lock);
                if (hba->msg_done)
                        break;
@@ -186,46 +299,68 @@ static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec)
        return hba->msg_done? 0 : -1;
 }
 
-static int iop_get_config(struct hptiop_hba *hba,
+static int iop_get_config_itl(struct hptiop_hba *hba,
                                struct hpt_iop_request_get_config *config)
 {
        u32 req32;
        struct hpt_iop_request_get_config __iomem *req;
 
-       req32 = readl(&hba->iop->inbound_queue);
+       req32 = readl(&hba->u.itl.iop->inbound_queue);
        if (req32 == IOPMU_QUEUE_EMPTY)
                return -1;
 
        req = (struct hpt_iop_request_get_config __iomem *)
-                       ((unsigned long)hba->iop + req32);
+                       ((unsigned long)hba->u.itl.iop + req32);
 
        writel(0, &req->header.flags);
        writel(IOP_REQUEST_TYPE_GET_CONFIG, &req->header.type);
        writel(sizeof(struct hpt_iop_request_get_config), &req->header.size);
        writel(IOP_RESULT_PENDING, &req->header.result);
 
-       if (iop_send_sync_request(hba, req, 20000)) {
+       if (iop_send_sync_request_itl(hba, req, 20000)) {
                dprintk("Get config send cmd failed\n");
                return -1;
        }
 
        memcpy_fromio(config, req, sizeof(*config));
-       writel(req32, &hba->iop->outbound_queue);
+       writel(req32, &hba->u.itl.iop->outbound_queue);
        return 0;
 }
 
-static int iop_set_config(struct hptiop_hba *hba,
+static int iop_get_config_mv(struct hptiop_hba *hba,
+                               struct hpt_iop_request_get_config *config)
+{
+       struct hpt_iop_request_get_config *req = hba->u.mv.internal_req;
+
+       req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
+       req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG);
+       req->header.size =
+               cpu_to_le32(sizeof(struct hpt_iop_request_get_config));
+       req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
+       req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG<<5);
+       req->header.context_hi32 = 0;
+
+       if (iop_send_sync_request_mv(hba, 0, 20000)) {
+               dprintk("Get config send cmd failed\n");
+               return -1;
+       }
+
+       memcpy(config, req, sizeof(struct hpt_iop_request_get_config));
+       return 0;
+}
+
+static int iop_set_config_itl(struct hptiop_hba *hba,
                                struct hpt_iop_request_set_config *config)
 {
        u32 req32;
        struct hpt_iop_request_set_config __iomem *req;
 
-       req32 = readl(&hba->iop->inbound_queue);
+       req32 = readl(&hba->u.itl.iop->inbound_queue);
        if (req32 == IOPMU_QUEUE_EMPTY)
                return -1;
 
        req = (struct hpt_iop_request_set_config __iomem *)
-                       ((unsigned long)hba->iop + req32);
+                       ((unsigned long)hba->u.itl.iop + req32);
 
        memcpy_toio((u8 __iomem *)req + sizeof(struct hpt_iop_request_header),
                (u8 *)config + sizeof(struct hpt_iop_request_header),
@@ -237,22 +372,53 @@ static int iop_set_config(struct hptiop_hba *hba,
        writel(sizeof(struct hpt_iop_request_set_config), &req->header.size);
        writel(IOP_RESULT_PENDING, &req->header.result);
 
-       if (iop_send_sync_request(hba, req, 20000)) {
+       if (iop_send_sync_request_itl(hba, req, 20000)) {
                dprintk("Set config send cmd failed\n");
                return -1;
        }
 
-       writel(req32, &hba->iop->outbound_queue);
+       writel(req32, &hba->u.itl.iop->outbound_queue);
        return 0;
 }
 
-static int hptiop_initialize_iop(struct hptiop_hba *hba)
+static int iop_set_config_mv(struct hptiop_hba *hba,
+                               struct hpt_iop_request_set_config *config)
 {
-       struct hpt_iopmu __iomem *iop = hba->iop;
+       struct hpt_iop_request_set_config *req = hba->u.mv.internal_req;
 
-       /* enable interrupts */
+       memcpy(req, config, sizeof(struct hpt_iop_request_set_config));
+       req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
+       req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG);
+       req->header.size =
+               cpu_to_le32(sizeof(struct hpt_iop_request_set_config));
+       req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
+       req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG<<5);
+       req->header.context_hi32 = 0;
+
+       if (iop_send_sync_request_mv(hba, 0, 20000)) {
+               dprintk("Set config send cmd failed\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+static void hptiop_enable_intr_itl(struct hptiop_hba *hba)
+{
        writel(~(IOPMU_OUTBOUND_INT_POSTQUEUE | IOPMU_OUTBOUND_INT_MSG0),
-                       &iop->outbound_intmask);
+               &hba->u.itl.iop->outbound_intmask);
+}
+
+static void hptiop_enable_intr_mv(struct hptiop_hba *hba)
+{
+       writel(MVIOP_MU_OUTBOUND_INT_POSTQUEUE | MVIOP_MU_OUTBOUND_INT_MSG,
+               &hba->u.mv.regs->outbound_intmask);
+}
+
+static int hptiop_initialize_iop(struct hptiop_hba *hba)
+{
+       /* enable interrupts */
+       hba->ops->enable_intr(hba);
 
        hba->initialized = 1;
 
@@ -266,37 +432,74 @@ static int hptiop_initialize_iop(struct hptiop_hba *hba)
        return 0;
 }
 
-static int hptiop_map_pci_bar(struct hptiop_hba *hba)
+static void __iomem *hptiop_map_pci_bar(struct hptiop_hba *hba, int index)
 {
        u32 mem_base_phy, length;
        void __iomem *mem_base_virt;
+
        struct pci_dev *pcidev = hba->pcidev;
 
-       if (!(pci_resource_flags(pcidev, 0) & IORESOURCE_MEM)) {
+
+       if (!(pci_resource_flags(pcidev, index) & IORESOURCE_MEM)) {
                printk(KERN_ERR "scsi%d: pci resource invalid\n",
                                hba->host->host_no);
-               return -1;
+               return NULL;
        }
 
-       mem_base_phy = pci_resource_start(pcidev, 0);
-       length = pci_resource_len(pcidev, 0);
+       mem_base_phy = pci_resource_start(pcidev, index);
+       length = pci_resource_len(pcidev, index);
        mem_base_virt = ioremap(mem_base_phy, length);
 
        if (!mem_base_virt) {
                printk(KERN_ERR "scsi%d: Fail to ioremap memory space\n",
                                hba->host->host_no);
+               return NULL;
+       }
+       return mem_base_virt;
+}
+
+static int hptiop_map_pci_bar_itl(struct hptiop_hba *hba)
+{
+       hba->u.itl.iop = hptiop_map_pci_bar(hba, 0);
+       if (hba->u.itl.iop)
+               return 0;
+       else
+               return -1;
+}
+
+static void hptiop_unmap_pci_bar_itl(struct hptiop_hba *hba)
+{
+       iounmap(hba->u.itl.iop);
+}
+
+static int hptiop_map_pci_bar_mv(struct hptiop_hba *hba)
+{
+       hba->u.mv.regs = hptiop_map_pci_bar(hba, 0);
+       if (hba->u.mv.regs == NULL)
+               return -1;
+
+       hba->u.mv.mu = hptiop_map_pci_bar(hba, 2);
+       if (hba->u.mv.mu == NULL) {
+               iounmap(hba->u.mv.regs);
                return -1;
        }
 
-       hba->iop = mem_base_virt;
-       dprintk("hptiop_map_pci_bar: iop=%p\n", hba->iop);
        return 0;
 }
 
+static void hptiop_unmap_pci_bar_mv(struct hptiop_hba *hba)
+{
+       iounmap(hba->u.mv.regs);
+       iounmap(hba->u.mv.mu);
+}
+
 static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg)
 {
        dprintk("iop message 0x%x\n", msg);
 
+       if (msg == IOPMU_INBOUND_MSG0_NOP)
+               hba->msg_done = 1;
+
        if (!hba->initialized)
                return;
 
@@ -308,7 +511,7 @@ static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg)
                hba->msg_done = 1;
 }
 
-static inline struct hptiop_request *get_req(struct hptiop_hba *hba)
+static struct hptiop_request *get_req(struct hptiop_hba *hba)
 {
        struct hptiop_request *ret;
 
@@ -321,20 +524,19 @@ static inline struct hptiop_request *get_req(struct hptiop_hba *hba)
        return ret;
 }
 
-static inline void free_req(struct hptiop_hba *hba, struct hptiop_request *req)
+static void free_req(struct hptiop_hba *hba, struct hptiop_request *req)
 {
        dprintk("free_req(%d, %p)\n", req->index, req);
        req->next = hba->req_list;
        hba->req_list = req;
 }
 
-static void hptiop_host_request_callback(struct hptiop_hba *hba, u32 tag)
+static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
+                               struct hpt_iop_request_scsi_command *req)
 {
-       struct hpt_iop_request_scsi_command *req;
        struct scsi_cmnd *scp;
 
-       req = (struct hpt_iop_request_scsi_command *)hba->reqs[tag].req_virt;
-       dprintk("hptiop_host_request_callback: req=%p, type=%d, "
+       dprintk("hptiop_finish_scsi_req: req=%p, type=%d, "
                        "result=%d, context=0x%x tag=%d\n",
                        req, req->header.type, req->header.result,
                        req->header.context, tag);
@@ -344,23 +546,13 @@ static void hptiop_host_request_callback(struct hptiop_hba *hba, u32 tag)
 
        scp = hba->reqs[tag].scp;
 
-       if (HPT_SCP(scp)->mapped) {
-               if (scp->use_sg)
-                       pci_unmap_sg(hba->pcidev,
-                               (struct scatterlist *)scp->request_buffer,
-                               scp->use_sg,
-                               scp->sc_data_direction
-                       );
-               else
-                       pci_unmap_single(hba->pcidev,
-                               HPT_SCP(scp)->dma_handle,
-                               scp->request_bufflen,
-                               scp->sc_data_direction
-                       );
-       }
+       if (HPT_SCP(scp)->mapped)
+               scsi_dma_unmap(scp);
 
        switch (le32_to_cpu(req->header.result)) {
        case IOP_RESULT_SUCCESS:
+               scsi_set_resid(scp,
+                       scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
                scp->result = (DID_OK<<16);
                break;
        case IOP_RESULT_BAD_TARGET:
@@ -378,17 +570,17 @@ static void hptiop_host_request_callback(struct hptiop_hba *hba, u32 tag)
        case IOP_RESULT_INVALID_REQUEST:
                scp->result = (DID_ABORT<<16);
                break;
-       case IOP_RESULT_MODE_SENSE_CHECK_CONDITION:
+       case IOP_RESULT_CHECK_CONDITION:
+               scsi_set_resid(scp,
+                       scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
                scp->result = SAM_STAT_CHECK_CONDITION;
-               memset(&scp->sense_buffer,
-                               0, sizeof(scp->sense_buffer));
-               memcpy(&scp->sense_buffer,
-                       &req->sg_list, le32_to_cpu(req->dataxfer_length));
+               memcpy(scp->sense_buffer, &req->sg_list,
+                               min_t(size_t, SCSI_SENSE_BUFFERSIZE,
+                                       le32_to_cpu(req->dataxfer_length)));
                break;
 
        default:
-               scp->result = ((DRIVER_INVALID|SUGGEST_ABORT)<<24) |
-                                       (DID_ABORT<<16);
+               scp->result = DRIVER_INVALID << 24 | DID_ABORT << 16;
                break;
        }
 
@@ -397,15 +589,33 @@ static void hptiop_host_request_callback(struct hptiop_hba *hba, u32 tag)
        free_req(hba, &hba->reqs[tag]);
 }
 
-void hptiop_iop_request_callback(struct hptiop_hba *hba, u32 tag)
+static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 _tag)
+{
+       struct hpt_iop_request_scsi_command *req;
+       u32 tag;
+
+       if (hba->iopintf_v2) {
+               tag = _tag & ~IOPMU_QUEUE_REQUEST_RESULT_BIT;
+               req = hba->reqs[tag].req_virt;
+               if (likely(_tag & IOPMU_QUEUE_REQUEST_RESULT_BIT))
+                       req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
+       } else {
+               tag = _tag;
+               req = hba->reqs[tag].req_virt;
+       }
+
+       hptiop_finish_scsi_req(hba, tag, req);
+}
+
+void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
 {
        struct hpt_iop_request_header __iomem *req;
        struct hpt_iop_request_ioctl_command __iomem *p;
        struct hpt_ioctl_k *arg;
 
        req = (struct hpt_iop_request_header __iomem *)
-                       ((unsigned long)hba->iop + tag);
-       dprintk("hptiop_iop_request_callback: req=%p, type=%d, "
+                       ((unsigned long)hba->u.itl.iop + tag);
+       dprintk("hptiop_iop_request_callback_itl: req=%p, type=%d, "
                        "result=%d, context=0x%x tag=%d\n",
                        req, readl(&req->type), readl(&req->result),
                        readl(&req->context), tag);
@@ -433,17 +643,17 @@ void hptiop_iop_request_callback(struct hptiop_hba *hba, u32 tag)
                arg->result = HPT_IOCTL_RESULT_FAILED;
 
        arg->done(arg);
-       writel(tag, &hba->iop->outbound_queue);
+       writel(tag, &hba->u.itl.iop->outbound_queue);
 }
 
-static irqreturn_t hptiop_intr(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t hptiop_intr(int irq, void *dev_id)
 {
        struct hptiop_hba  *hba = dev_id;
        int  handled;
        unsigned long flags;
 
        spin_lock_irqsave(hba->host->host_lock, flags);
-       handled = __iop_intr(hba);
+       handled = hba->ops->iop_intr(hba);
        spin_unlock_irqrestore(hba->host->host_lock, flags);
 
        return handled;
@@ -453,43 +663,77 @@ static int hptiop_buildsgl(struct scsi_cmnd *scp, struct hpt_iopsg *psg)
 {
        struct Scsi_Host *host = scp->device->host;
        struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
-       struct scatterlist *sglist = (struct scatterlist *)scp->request_buffer;
-
-       /*
-        * though we'll not get non-use_sg fields anymore,
-        * keep use_sg checking anyway
-        */
-       if (scp->use_sg) {
-               int idx;
-
-               HPT_SCP(scp)->sgcnt = pci_map_sg(hba->pcidev,
-                               sglist, scp->use_sg,
-                               scp->sc_data_direction);
-               HPT_SCP(scp)->mapped = 1;
-               BUG_ON(HPT_SCP(scp)->sgcnt > hba->max_sg_descriptors);
-
-               for (idx = 0; idx < HPT_SCP(scp)->sgcnt; idx++) {
-                       psg[idx].pci_address =
-                               cpu_to_le64(sg_dma_address(&sglist[idx]));
-                       psg[idx].size = cpu_to_le32(sg_dma_len(&sglist[idx]));
-                       psg[idx].eot = (idx == HPT_SCP(scp)->sgcnt - 1) ?
-                               cpu_to_le32(1) : 0;
-               }
+       struct scatterlist *sg;
+       int idx, nseg;
 
-               return HPT_SCP(scp)->sgcnt;
-       } else {
-               HPT_SCP(scp)->dma_handle = pci_map_single(
-                               hba->pcidev,
-                               scp->request_buffer,
-                               scp->request_bufflen,
-                               scp->sc_data_direction
-                       );
-               HPT_SCP(scp)->mapped = 1;
-               psg->pci_address = cpu_to_le64(HPT_SCP(scp)->dma_handle);
-               psg->size = cpu_to_le32(scp->request_bufflen);
-               psg->eot = cpu_to_le32(1);
-               return 1;
+       nseg = scsi_dma_map(scp);
+       BUG_ON(nseg < 0);
+       if (!nseg)
+               return 0;
+
+       HPT_SCP(scp)->sgcnt = nseg;
+       HPT_SCP(scp)->mapped = 1;
+
+       BUG_ON(HPT_SCP(scp)->sgcnt > hba->max_sg_descriptors);
+
+       scsi_for_each_sg(scp, sg, HPT_SCP(scp)->sgcnt, idx) {
+               psg[idx].pci_address = cpu_to_le64(sg_dma_address(sg));
+               psg[idx].size = cpu_to_le32(sg_dma_len(sg));
+               psg[idx].eot = (idx == HPT_SCP(scp)->sgcnt - 1) ?
+                       cpu_to_le32(1) : 0;
        }
+       return HPT_SCP(scp)->sgcnt;
+}
+
+static void hptiop_post_req_itl(struct hptiop_hba *hba,
+                                       struct hptiop_request *_req)
+{
+       struct hpt_iop_request_header *reqhdr = _req->req_virt;
+
+       reqhdr->context = cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT |
+                                                       (u32)_req->index);
+       reqhdr->context_hi32 = 0;
+
+       if (hba->iopintf_v2) {
+               u32 size, size_bits;
+
+               size = le32_to_cpu(reqhdr->size);
+               if (size < 256)
+                       size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT;
+               else if (size < 512)
+                       size_bits = IOPMU_QUEUE_ADDR_HOST_BIT;
+               else
+                       size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT |
+                                               IOPMU_QUEUE_ADDR_HOST_BIT;
+               writel(_req->req_shifted_phy | size_bits,
+                       &hba->u.itl.iop->inbound_queue);
+       } else
+               writel(_req->req_shifted_phy | IOPMU_QUEUE_ADDR_HOST_BIT,
+                                       &hba->u.itl.iop->inbound_queue);
+}
+
+static void hptiop_post_req_mv(struct hptiop_hba *hba,
+                                       struct hptiop_request *_req)
+{
+       struct hpt_iop_request_header *reqhdr = _req->req_virt;
+       u32 size, size_bit;
+
+       reqhdr->context = cpu_to_le32(_req->index<<8 |
+                                       IOP_REQUEST_TYPE_SCSI_COMMAND<<5);
+       reqhdr->context_hi32 = 0;
+       size = le32_to_cpu(reqhdr->size);
+
+       if (size <= 256)
+               size_bit = 0;
+       else if (size <= 256*2)
+               size_bit = 1;
+       else if (size <= 256*3)
+               size_bit = 2;
+       else
+               size_bit = 3;
+
+       mv_inbound_write((_req->req_shifted_phy << 5) |
+               MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bit, hba);
 }
 
 static int hptiop_queuecommand(struct scsi_cmnd *scp,
@@ -517,9 +761,9 @@ static int hptiop_queuecommand(struct scsi_cmnd *scp,
                        scp,
                        host->host_no, scp->device->channel,
                        scp->device->id, scp->device->lun,
-                       *((u32 *)&scp->cmnd),
-                       *((u32 *)&scp->cmnd + 1),
-                       *((u32 *)&scp->cmnd + 2),
+                       ((u32 *)scp->cmnd)[0],
+                       ((u32 *)scp->cmnd)[1],
+                       ((u32 *)scp->cmnd)[2],
                        _req->index, _req->req_virt);
 
        scp->result = 0;
@@ -531,21 +775,17 @@ static int hptiop_queuecommand(struct scsi_cmnd *scp,
                goto cmd_done;
        }
 
-       req = (struct hpt_iop_request_scsi_command *)_req->req_virt;
+       req = _req->req_virt;
 
        /* build S/G table */
-       if (scp->request_bufflen)
-               sg_count = hptiop_buildsgl(scp, req->sg_list);
-       else
+       sg_count = hptiop_buildsgl(scp, req->sg_list);
+       if (!sg_count)
                HPT_SCP(scp)->mapped = 0;
 
        req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
        req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND);
        req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
-       req->header.context = cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT |
-                                                       (u32)_req->index);
-       req->header.context_hi32 = 0;
-       req->dataxfer_length = cpu_to_le32(scp->request_bufflen);
+       req->dataxfer_length = cpu_to_le32(scsi_bufflen(scp));
        req->channel = scp->device->channel;
        req->target = scp->device->id;
        req->lun = scp->device->lun;
@@ -555,10 +795,7 @@ static int hptiop_queuecommand(struct scsi_cmnd *scp,
                                 + sg_count * sizeof(struct hpt_iopsg));
 
        memcpy(req->cdb, scp->cmnd, sizeof(req->cdb));
-
-       writel(IOPMU_QUEUE_ADDR_HOST_BIT | _req->req_shifted_phy,
-                       &hba->iop->inbound_queue);
-
+       hba->ops->post_req(hba, _req);
        return 0;
 
 cmd_done:
@@ -576,9 +813,7 @@ static int hptiop_reset_hba(struct hptiop_hba *hba)
 {
        if (atomic_xchg(&hba->resetting, 1) == 0) {
                atomic_inc(&hba->reset_count);
-               writel(IOPMU_INBOUND_MSG0_RESET,
-                               &hba->iop->outbound_msgaddr0);
-               hptiop_pci_posting_flush(hba->iop);
+               hba->ops->post_msg(hba, IOPMU_INBOUND_MSG0_RESET);
        }
 
        wait_event_timeout(hba->reset_wq,
@@ -614,541 +849,24 @@ static int hptiop_reset(struct scsi_cmnd *scp)
 static int hptiop_adjust_disk_queue_depth(struct scsi_device *sdev,
                                                int queue_depth)
 {
-       if(queue_depth > 256)
-               queue_depth = 256;
+       struct hptiop_hba *hba = (struct hptiop_hba *)sdev->host->hostdata;
+
+       if (queue_depth > hba->max_requests)
+               queue_depth = hba->max_requests;
        scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth);
        return queue_depth;
 }
 
-struct hptiop_getinfo {
-       char __user *buffer;
-       loff_t buflength;
-       loff_t bufoffset;
-       loff_t buffillen;
-       loff_t filpos;
-};
-
-static void hptiop_copy_mem_info(struct hptiop_getinfo *pinfo,
-                                       char *data, int datalen)
-{
-       if (pinfo->filpos < pinfo->bufoffset) {
-               if (pinfo->filpos + datalen <= pinfo->bufoffset) {
-                       pinfo->filpos += datalen;
-                       return;
-               } else {
-                       data += (pinfo->bufoffset - pinfo->filpos);
-                       datalen  -= (pinfo->bufoffset - pinfo->filpos);
-                       pinfo->filpos = pinfo->bufoffset;
-               }
-       }
-
-       pinfo->filpos += datalen;
-       if (pinfo->buffillen == pinfo->buflength)
-               return;
-
-       if (pinfo->buflength - pinfo->buffillen < datalen)
-               datalen = pinfo->buflength - pinfo->buffillen;
-
-       if (copy_to_user(pinfo->buffer + pinfo->buffillen, data, datalen))
-               return;
-
-       pinfo->buffillen += datalen;
-}
-
-static int hptiop_copy_info(struct hptiop_getinfo *pinfo, char *fmt, ...)
-{
-       va_list args;
-       char buf[128];
-       int len;
-
-       va_start(args, fmt);
-       len = vsnprintf(buf, sizeof(buf), fmt, args);
-       va_end(args);
-       hptiop_copy_mem_info(pinfo, buf, len);
-       return len;
-}
-
-static void hptiop_ioctl_done(struct hpt_ioctl_k *arg)
-{
-       arg->done = NULL;
-       wake_up(&arg->hba->ioctl_wq);
-}
-
-static void hptiop_do_ioctl(struct hpt_ioctl_k *arg)
-{
-       struct hptiop_hba *hba = arg->hba;
-       u32 val;
-       struct hpt_iop_request_ioctl_command __iomem *req;
-       int ioctl_retry = 0;
-
-       dprintk("scsi%d: hptiop_do_ioctl\n", hba->host->host_no);
-
-       /*
-        * check (in + out) buff size from application.
-        * outbuf must be dword aligned.
-        */
-       if (((arg->inbuf_size + 3) & ~3) + arg->outbuf_size >
-                       hba->max_request_size
-                               - sizeof(struct hpt_iop_request_header)
-                               - 4 * sizeof(u32)) {
-               dprintk("scsi%d: ioctl buf size (%d/%d) is too large\n",
-                               hba->host->host_no,
-                               arg->inbuf_size, arg->outbuf_size);
-               arg->result = HPT_IOCTL_RESULT_FAILED;
-               return;
-       }
-
-retry:
-       spin_lock_irq(hba->host->host_lock);
-
-       val = readl(&hba->iop->inbound_queue);
-       if (val == IOPMU_QUEUE_EMPTY) {
-               spin_unlock_irq(hba->host->host_lock);
-               dprintk("scsi%d: no free req for ioctl\n", hba->host->host_no);
-               arg->result = -1;
-               return;
-       }
-
-       req = (struct hpt_iop_request_ioctl_command __iomem *)
-                       ((unsigned long)hba->iop + val);
-
-       writel(HPT_CTL_CODE_LINUX_TO_IOP(arg->ioctl_code),
-                       &req->ioctl_code);
-       writel(arg->inbuf_size, &req->inbuf_size);
-       writel(arg->outbuf_size, &req->outbuf_size);
-
-       /*
-        * use the buffer on the IOP local memory first, then copy it
-        * back to host.
-        * the caller's request buffer shoudl be little-endian.
-        */
-       if (arg->inbuf_size)
-               memcpy_toio(req->buf, arg->inbuf, arg->inbuf_size);
-
-       /* correct the controller ID for IOP */
-       if ((arg->ioctl_code == HPT_IOCTL_GET_CHANNEL_INFO ||
-               arg->ioctl_code == HPT_IOCTL_GET_CONTROLLER_INFO_V2 ||
-               arg->ioctl_code == HPT_IOCTL_GET_CONTROLLER_INFO)
-               && arg->inbuf_size >= sizeof(u32))
-               writel(0, req->buf);
-
-       writel(IOP_REQUEST_TYPE_IOCTL_COMMAND, &req->header.type);
-       writel(0, &req->header.flags);
-       writel(offsetof(struct hpt_iop_request_ioctl_command, buf)
-                       + arg->inbuf_size, &req->header.size);
-       writel((u32)(unsigned long)arg, &req->header.context);
-       writel(BITS_PER_LONG > 32 ? (u32)((unsigned long)arg>>32) : 0,
-                       &req->header.context_hi32);
-       writel(IOP_RESULT_PENDING, &req->header.result);
-
-       arg->result = HPT_IOCTL_RESULT_FAILED;
-       arg->done = hptiop_ioctl_done;
-
-       writel(val, &hba->iop->inbound_queue);
-       hptiop_pci_posting_flush(hba->iop);
-
-       spin_unlock_irq(hba->host->host_lock);
-
-       wait_event_timeout(hba->ioctl_wq, arg->done == NULL, 60 * HZ);
-
-       if (arg->done != NULL) {
-               hptiop_reset_hba(hba);
-               if (ioctl_retry++ < 3)
-                       goto retry;
-       }
-
-       dprintk("hpt_iop_ioctl %x result %d\n",
-                       arg->ioctl_code, arg->result);
-}
-
-static int __hpt_do_ioctl(struct hptiop_hba *hba, u32 code, void *inbuf,
-                       u32 insize, void *outbuf, u32 outsize)
-{
-       struct hpt_ioctl_k arg;
-       arg.hba = hba;
-       arg.ioctl_code = code;
-       arg.inbuf = inbuf;
-       arg.outbuf = outbuf;
-       arg.inbuf_size = insize;
-       arg.outbuf_size = outsize;
-       arg.bytes_returned = NULL;
-       hptiop_do_ioctl(&arg);
-       return arg.result;
-}
-
-static inline int hpt_id_valid(__le32 id)
-{
-       return id != 0 && id != cpu_to_le32(0xffffffff);
-}
-
-static int hptiop_get_controller_info(struct hptiop_hba *hba,
-                                       struct hpt_controller_info *pinfo)
-{
-       int id = 0;
-
-       return __hpt_do_ioctl(hba, HPT_IOCTL_GET_CONTROLLER_INFO,
-               &id, sizeof(int), pinfo, sizeof(*pinfo));
-}
-
-
-static int hptiop_get_channel_info(struct hptiop_hba *hba, int bus,
-                                       struct hpt_channel_info *pinfo)
-{
-       u32 ids[2];
-
-       ids[0] = 0;
-       ids[1] = bus;
-       return __hpt_do_ioctl(hba, HPT_IOCTL_GET_CHANNEL_INFO,
-                               ids, sizeof(ids), pinfo, sizeof(*pinfo));
-
-}
-
-static int hptiop_get_logical_devices(struct hptiop_hba *hba,
-                                       __le32 *pids, int maxcount)
-{
-       int i;
-       u32 count = maxcount - 1;
-
-       if (__hpt_do_ioctl(hba, HPT_IOCTL_GET_LOGICAL_DEVICES,
-                       &count, sizeof(u32),
-                       pids, sizeof(u32) * maxcount))
-               return -1;
-
-       maxcount = le32_to_cpu(pids[0]);
-       for (i = 0; i < maxcount; i++)
-               pids[i] = pids[i+1];
-
-       return maxcount;
-}
-
-static int hptiop_get_device_info_v3(struct hptiop_hba *hba, __le32 id,
-                               struct hpt_logical_device_info_v3 *pinfo)
-{
-       return __hpt_do_ioctl(hba, HPT_IOCTL_GET_DEVICE_INFO_V3,
-                               &id, sizeof(u32),
-                               pinfo, sizeof(*pinfo));
-}
-
-static const char *get_array_status(struct hpt_logical_device_info_v3 *devinfo)
-{
-       static char s[64];
-       u32 flags = le32_to_cpu(devinfo->u.array.flags);
-       u32 trans_prog = le32_to_cpu(devinfo->u.array.transforming_progress);
-       u32 reb_prog = le32_to_cpu(devinfo->u.array.rebuilding_progress);
-
-       if (flags & ARRAY_FLAG_DISABLED)
-               return "Disabled";
-       else if (flags & ARRAY_FLAG_TRANSFORMING)
-               sprintf(s, "Expanding/Migrating %d.%d%%%s%s",
-                       trans_prog / 100,
-                       trans_prog % 100,
-                       (flags & (ARRAY_FLAG_NEEDBUILDING|ARRAY_FLAG_BROKEN))?
-                                       ", Critical" : "",
-                       ((flags & ARRAY_FLAG_NEEDINITIALIZING) &&
-                        !(flags & ARRAY_FLAG_REBUILDING) &&
-                        !(flags & ARRAY_FLAG_INITIALIZING))?
-                                       ", Unintialized" : "");
-       else if ((flags & ARRAY_FLAG_BROKEN) &&
-                               devinfo->u.array.array_type != AT_RAID6)
-               return "Critical";
-       else if (flags & ARRAY_FLAG_REBUILDING)
-               sprintf(s,
-                       (flags & ARRAY_FLAG_NEEDINITIALIZING)?
-                               "%sBackground initializing %d.%d%%" :
-                                       "%sRebuilding %d.%d%%",
-                       (flags & ARRAY_FLAG_BROKEN)? "Critical, " : "",
-                       reb_prog / 100,
-                       reb_prog % 100);
-       else if (flags & ARRAY_FLAG_VERIFYING)
-               sprintf(s, "%sVerifying %d.%d%%",
-                       (flags & ARRAY_FLAG_BROKEN)? "Critical, " : "",
-                       reb_prog / 100,
-                       reb_prog % 100);
-       else if (flags & ARRAY_FLAG_INITIALIZING)
-               sprintf(s, "%sForground initializing %d.%d%%",
-                       (flags & ARRAY_FLAG_BROKEN)? "Critical, " : "",
-                       reb_prog / 100,
-                       reb_prog % 100);
-       else if (flags & ARRAY_FLAG_NEEDTRANSFORM)
-               sprintf(s,"%s%s%s", "Need Expanding/Migrating",
-                       (flags & ARRAY_FLAG_BROKEN)? "Critical, " : "",
-                       ((flags & ARRAY_FLAG_NEEDINITIALIZING) &&
-                        !(flags & ARRAY_FLAG_REBUILDING) &&
-                        !(flags & ARRAY_FLAG_INITIALIZING))?
-                               ", Unintialized" : "");
-       else if (flags & ARRAY_FLAG_NEEDINITIALIZING &&
-               !(flags & ARRAY_FLAG_REBUILDING) &&
-               !(flags & ARRAY_FLAG_INITIALIZING))
-               sprintf(s,"%sUninitialized",
-                       (flags & ARRAY_FLAG_BROKEN)? "Critical, " : "");
-       else if ((flags & ARRAY_FLAG_NEEDBUILDING) ||
-                       (flags & ARRAY_FLAG_BROKEN))
-               return "Critical";
-       else
-               return "Normal";
-       return s;
-}
-
-static void hptiop_dump_devinfo(struct hptiop_hba *hba,
-                       struct hptiop_getinfo *pinfo, __le32 id, int indent)
-{
-       struct hpt_logical_device_info_v3 devinfo;
-       int i;
-       u64 capacity;
-
-       for (i = 0; i < indent; i++)
-               hptiop_copy_info(pinfo, "\t");
-
-       if (hptiop_get_device_info_v3(hba, id, &devinfo)) {
-               hptiop_copy_info(pinfo, "unknown\n");
-               return;
-       }
-
-       switch (devinfo.type) {
-
-       case LDT_DEVICE: {
-               struct hd_driveid *driveid;
-               u32 flags = le32_to_cpu(devinfo.u.device.flags);
-
-               driveid = (struct hd_driveid *)devinfo.u.device.ident;
-               /* model[] is 40 chars long, but we just want 20 chars here */
-               driveid->model[20] = 0;
-
-               if (indent)
-                       if (flags & DEVICE_FLAG_DISABLED)
-                               hptiop_copy_info(pinfo,"Missing\n");
-                       else
-                               hptiop_copy_info(pinfo, "CH%d %s\n",
-                                       devinfo.u.device.path_id + 1,
-                                       driveid->model);
-               else {
-                       capacity = le64_to_cpu(devinfo.capacity) * 512;
-                       do_div(capacity, 1000000);
-                       hptiop_copy_info(pinfo,
-                               "CH%d %s, %lluMB, %s %s%s%s%s\n",
-                               devinfo.u.device.path_id + 1,
-                               driveid->model,
-                               capacity,
-                               (flags & DEVICE_FLAG_DISABLED)?
-                                       "Disabled" : "Normal",
-                               devinfo.u.device.read_ahead_enabled?
-                                               "[RA]" : "",
-                               devinfo.u.device.write_cache_enabled?
-                                               "[WC]" : "",
-                               devinfo.u.device.TCQ_enabled?
-                                               "[TCQ]" : "",
-                               devinfo.u.device.NCQ_enabled?
-                                               "[NCQ]" : ""
-                       );
-               }
-               break;
-       }
-
-       case LDT_ARRAY:
-               if (devinfo.target_id != INVALID_TARGET_ID)
-                       hptiop_copy_info(pinfo, "[DISK %d_%d] ",
-                                       devinfo.vbus_id, devinfo.target_id);
-
-               capacity = le64_to_cpu(devinfo.capacity) * 512;
-               do_div(capacity, 1000000);
-               hptiop_copy_info(pinfo, "%s (%s), %lluMB, %s\n",
-                       devinfo.u.array.name,
-                       devinfo.u.array.array_type==AT_RAID0? "RAID0" :
-                               devinfo.u.array.array_type==AT_RAID1? "RAID1" :
-                               devinfo.u.array.array_type==AT_RAID5? "RAID5" :
-                               devinfo.u.array.array_type==AT_RAID6? "RAID6" :
-                               devinfo.u.array.array_type==AT_JBOD? "JBOD" :
-                                       "unknown",
-                       capacity,
-                       get_array_status(&devinfo));
-               for (i = 0; i < devinfo.u.array.ndisk; i++) {
-                       if (hpt_id_valid(devinfo.u.array.members[i])) {
-                               if (cpu_to_le16(1<<i) &
-                                       devinfo.u.array.critical_members)
-                                       hptiop_copy_info(pinfo, "\t*");
-                               hptiop_dump_devinfo(hba, pinfo,
-                                       devinfo.u.array.members[i], indent+1);
-                       }
-                       else
-                               hptiop_copy_info(pinfo, "\tMissing\n");
-               }
-               if (id == devinfo.u.array.transform_source) {
-                       hptiop_copy_info(pinfo, "\tExpanding/Migrating to:\n");
-                       hptiop_dump_devinfo(hba, pinfo,
-                               devinfo.u.array.transform_target, indent+1);
-               }
-               break;
-       }
-}
-
-static ssize_t hptiop_show_version(struct class_device *class_dev, char *buf)
+static ssize_t hptiop_show_version(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
 {
        return snprintf(buf, PAGE_SIZE, "%s\n", driver_ver);
 }
 
-static ssize_t hptiop_cdev_read(struct file *filp, char __user *buf,
-                               size_t count, loff_t *ppos)
-{
-       struct hptiop_hba *hba = filp->private_data;
-       struct hptiop_getinfo info;
-       int i, j, ndev;
-       struct hpt_controller_info con_info;
-       struct hpt_channel_info chan_info;
-       __le32 ids[32];
-
-       info.buffer     = buf;
-       info.buflength  = count;
-       info.bufoffset  = ppos ? *ppos : 0;
-       info.filpos     = 0;
-       info.buffillen  = 0;
-
-       if (hptiop_get_controller_info(hba, &con_info))
-               return -EIO;
-
-       for (i = 0; i < con_info.num_buses; i++) {
-               if (hptiop_get_channel_info(hba, i, &chan_info) == 0) {
-                       if (hpt_id_valid(chan_info.devices[0]))
-                               hptiop_dump_devinfo(hba, &info,
-                                               chan_info.devices[0], 0);
-                       if (hpt_id_valid(chan_info.devices[1]))
-                               hptiop_dump_devinfo(hba, &info,
-                                               chan_info.devices[1], 0);
-               }
-       }
-
-       ndev = hptiop_get_logical_devices(hba, ids,
-                                       sizeof(ids) / sizeof(ids[0]));
-
-       /*
-        * if hptiop_get_logical_devices fails, ndev==-1 and it just
-        * output nothing here
-        */
-       for (j = 0; j < ndev; j++)
-               hptiop_dump_devinfo(hba, &info, ids[j], 0);
-
-       if (ppos)
-               *ppos += info.buffillen;
-
-       return info.buffillen;
-}
-
-static int hptiop_cdev_ioctl(struct inode *inode,  struct file *file,
-                                       unsigned int cmd, unsigned long arg)
-{
-       struct hptiop_hba *hba = file->private_data;
-       struct hpt_ioctl_u ioctl_u;
-       struct hpt_ioctl_k ioctl_k;
-       u32 bytes_returned;
-       int err = -EINVAL;
-
-       if (copy_from_user(&ioctl_u,
-               (void __user *)arg, sizeof(struct hpt_ioctl_u)))
-               return -EINVAL;
-
-       if (ioctl_u.magic != HPT_IOCTL_MAGIC)
-               return -EINVAL;
-
-       ioctl_k.ioctl_code = ioctl_u.ioctl_code;
-       ioctl_k.inbuf = NULL;
-       ioctl_k.inbuf_size = ioctl_u.inbuf_size;
-       ioctl_k.outbuf = NULL;
-       ioctl_k.outbuf_size = ioctl_u.outbuf_size;
-       ioctl_k.hba = hba;
-       ioctl_k.bytes_returned = &bytes_returned;
-
-       /* verify user buffer */
-       if ((ioctl_k.inbuf_size && !access_ok(VERIFY_READ,
-                       ioctl_u.inbuf, ioctl_k.inbuf_size)) ||
-               (ioctl_k.outbuf_size && !access_ok(VERIFY_WRITE,
-                       ioctl_u.outbuf, ioctl_k.outbuf_size)) ||
-               (ioctl_u.bytes_returned && !access_ok(VERIFY_WRITE,
-                       ioctl_u.bytes_returned, sizeof(u32))) ||
-               ioctl_k.inbuf_size + ioctl_k.outbuf_size > 0x10000) {
-
-               dprintk("scsi%d: got bad user address\n", hba->host->host_no);
-               return -EINVAL;
-       }
-
-       /* map buffer to kernel. */
-       if (ioctl_k.inbuf_size) {
-               ioctl_k.inbuf = kmalloc(ioctl_k.inbuf_size, GFP_KERNEL);
-               if (!ioctl_k.inbuf) {
-                       dprintk("scsi%d: fail to alloc inbuf\n",
-                                       hba->host->host_no);
-                       err = -ENOMEM;
-                       goto err_exit;
-               }
-
-               if (copy_from_user(ioctl_k.inbuf,
-                               ioctl_u.inbuf, ioctl_k.inbuf_size)) {
-                       goto err_exit;
-               }
-       }
-
-       if (ioctl_k.outbuf_size) {
-               ioctl_k.outbuf = kmalloc(ioctl_k.outbuf_size, GFP_KERNEL);
-               if (!ioctl_k.outbuf) {
-                       dprintk("scsi%d: fail to alloc outbuf\n",
-                                       hba->host->host_no);
-                       err = -ENOMEM;
-                       goto err_exit;
-               }
-       }
-
-       hptiop_do_ioctl(&ioctl_k);
-
-       if (ioctl_k.result == HPT_IOCTL_RESULT_OK) {
-               if (ioctl_k.outbuf_size &&
-                       copy_to_user(ioctl_u.outbuf,
-                               ioctl_k.outbuf, ioctl_k.outbuf_size))
-                       goto err_exit;
-
-               if (ioctl_u.bytes_returned &&
-                       copy_to_user(ioctl_u.bytes_returned,
-                               &bytes_returned, sizeof(u32)))
-                       goto err_exit;
-
-               err = 0;
-       }
-
-err_exit:
-       kfree(ioctl_k.inbuf);
-       kfree(ioctl_k.outbuf);
-
-       return err;
-}
-
-static int hptiop_cdev_open(struct inode *inode, struct file *file)
-{
-       struct hptiop_hba *hba;
-       unsigned i = 0, minor = iminor(inode);
-       int ret = -ENODEV;
-
-       spin_lock(&hptiop_hba_list_lock);
-       list_for_each_entry(hba, &hptiop_hba_list, link) {
-               if (i == minor) {
-                       file->private_data = hba;
-                       ret = 0;
-                       goto out;
-               }
-               i++;
-       }
-
-out:
-       spin_unlock(&hptiop_hba_list_lock);
-       return ret;
-}
-
-static struct file_operations hptiop_cdev_fops = {
-       .owner = THIS_MODULE,
-       .read  = hptiop_cdev_read,
-       .ioctl = hptiop_cdev_ioctl,
-       .open  = hptiop_cdev_open,
-};
-
-static ssize_t hptiop_show_fw_version(struct class_device *class_dev, char *buf)
+static ssize_t hptiop_show_fw_version(struct device *dev,
+                                     struct device_attribute *attr, char *buf)
 {
-       struct Scsi_Host *host = class_to_shost(class_dev);
+       struct Scsi_Host *host = class_to_shost(dev);
        struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
 
        return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
@@ -1158,7 +876,7 @@ static ssize_t hptiop_show_fw_version(struct class_device *class_dev, char *buf)
                                hba->firmware_version & 0xff);
 }
 
-static struct class_device_attribute hptiop_attr_version = {
+static struct device_attribute hptiop_attr_version = {
        .attr = {
                .name = "driver-version",
                .mode = S_IRUGO,
@@ -1166,7 +884,7 @@ static struct class_device_attribute hptiop_attr_version = {
        .show = hptiop_show_version,
 };
 
-static struct class_device_attribute hptiop_attr_fw_version = {
+static struct device_attribute hptiop_attr_fw_version = {
        .attr = {
                .name = "firmware-version",
                .mode = S_IRUGO,
@@ -1174,7 +892,7 @@ static struct class_device_attribute hptiop_attr_fw_version = {
        .show = hptiop_show_fw_version,
 };
 
-static struct class_device_attribute *hptiop_attrs[] = {
+static struct device_attribute *hptiop_attrs[] = {
        &hptiop_attr_version,
        &hptiop_attr_fw_version,
        NULL
@@ -1187,7 +905,6 @@ static struct scsi_host_template driver_template = {
        .eh_device_reset_handler    = hptiop_reset,
        .eh_bus_reset_handler       = hptiop_reset,
        .info                       = hptiop_info,
-       .unchecked_isa_dma          = 0,
        .emulated                   = 0,
        .use_clustering             = ENABLE_CLUSTERING,
        .proc_name                  = driver_name,
@@ -1196,6 +913,26 @@ static struct scsi_host_template driver_template = {
        .change_queue_depth         = hptiop_adjust_disk_queue_depth,
 };
 
+static int hptiop_internal_memalloc_mv(struct hptiop_hba *hba)
+{
+       hba->u.mv.internal_req = dma_alloc_coherent(&hba->pcidev->dev,
+                       0x800, &hba->u.mv.internal_req_phy, GFP_KERNEL);
+       if (hba->u.mv.internal_req)
+               return 0;
+       else
+               return -1;
+}
+
+static int hptiop_internal_memfree_mv(struct hptiop_hba *hba)
+{
+       if (hba->u.mv.internal_req) {
+               dma_free_coherent(&hba->pcidev->dev, 0x800,
+                       hba->u.mv.internal_req, hba->u.mv.internal_req_phy);
+               return 0;
+       } else
+               return -1;
+}
+
 static int __devinit hptiop_probe(struct pci_dev *pcidev,
                                        const struct pci_device_id *id)
 {
@@ -1241,9 +978,11 @@ static int __devinit hptiop_probe(struct pci_dev *pcidev,
 
        hba = (struct hptiop_hba *)host->hostdata;
 
+       hba->ops = (struct hptiop_adapter_ops *)id->driver_data;
        hba->pcidev = pcidev;
        hba->host = host;
        hba->initialized = 0;
+       hba->iopintf_v2 = 0;
 
        atomic_set(&hba->resetting, 0);
        atomic_set(&hba->reset_count, 0);
@@ -1257,16 +996,24 @@ static int __devinit hptiop_probe(struct pci_dev *pcidev,
        host->n_io_port = 0;
        host->irq = pcidev->irq;
 
-       if (hptiop_map_pci_bar(hba))
+       if (hba->ops->map_pci_bar(hba))
                goto free_scsi_host;
 
-       if (iop_wait_ready(hba->iop, 20000)) {
+       if (hba->ops->iop_wait_ready(hba, 20000)) {
                printk(KERN_ERR "scsi%d: firmware not ready\n",
                                hba->host->host_no);
                goto unmap_pci_bar;
        }
 
-       if (iop_get_config(hba, &iop_config)) {
+       if (hba->ops->internal_memalloc) {
+               if (hba->ops->internal_memalloc(hba)) {
+                       printk(KERN_ERR "scsi%d: internal_memalloc failed\n",
+                               hba->host->host_no);
+                       goto unmap_pci_bar;
+               }
+       }
+
+       if (hba->ops->get_config(hba, &iop_config)) {
                printk(KERN_ERR "scsi%d: get config failed\n",
                                hba->host->host_no);
                goto unmap_pci_bar;
@@ -1278,8 +1025,13 @@ static int __devinit hptiop_probe(struct pci_dev *pcidev,
        hba->max_request_size = le32_to_cpu(iop_config.request_size);
        hba->max_sg_descriptors = le32_to_cpu(iop_config.max_sg_count);
        hba->firmware_version = le32_to_cpu(iop_config.firmware_version);
+       hba->interface_version = le32_to_cpu(iop_config.interface_version);
        hba->sdram_size = le32_to_cpu(iop_config.sdram_size);
 
+       if (hba->firmware_version > 0x01020000 ||
+                       hba->interface_version > 0x01020000)
+               hba->iopintf_v2 = 1;
+
        host->max_sectors = le32_to_cpu(iop_config.data_transfer_length) >> 9;
        host->max_id = le32_to_cpu(iop_config.max_devices);
        host->sg_tablesize = le32_to_cpu(iop_config.max_sg_count);
@@ -1287,35 +1039,32 @@ static int __devinit hptiop_probe(struct pci_dev *pcidev,
        host->cmd_per_lun = le32_to_cpu(iop_config.max_requests);
        host->max_cmd_len = 16;
 
-       set_config.vbus_id = cpu_to_le32(host->host_no);
+       req_size = sizeof(struct hpt_iop_request_scsi_command)
+               + sizeof(struct hpt_iopsg) * (hba->max_sg_descriptors - 1);
+       if ((req_size & 0x1f) != 0)
+               req_size = (req_size + 0x1f) & ~0x1f;
+
+       memset(&set_config, 0, sizeof(struct hpt_iop_request_set_config));
        set_config.iop_id = cpu_to_le32(host->host_no);
+       set_config.vbus_id = cpu_to_le16(host->host_no);
+       set_config.max_host_request_size = cpu_to_le16(req_size);
 
-       if (iop_set_config(hba, &set_config)) {
+       if (hba->ops->set_config(hba, &set_config)) {
                printk(KERN_ERR "scsi%d: set config failed\n",
                                hba->host->host_no);
                goto unmap_pci_bar;
        }
 
-       if (scsi_add_host(host, &pcidev->dev)) {
-               printk(KERN_ERR "scsi%d: scsi_add_host failed\n",
-                                       hba->host->host_no);
-               goto unmap_pci_bar;
-       }
-
        pci_set_drvdata(pcidev, host);
 
-       if (request_irq(pcidev->irq, hptiop_intr, SA_SHIRQ,
+       if (request_irq(pcidev->irq, hptiop_intr, IRQF_SHARED,
                                        driver_name, hba)) {
                printk(KERN_ERR "scsi%d: request irq %d failed\n",
                                        hba->host->host_no, pcidev->irq);
-               goto remove_scsi_host;
+               goto unmap_pci_bar;
        }
 
        /* Allocate request mem */
-       req_size = sizeof(struct hpt_iop_request_scsi_command)
-               + sizeof(struct hpt_iopsg) * (hba->max_sg_descriptors - 1);
-       if ((req_size& 0x1f) != 0)
-               req_size = (req_size + 0x1f) & ~0x1f;
 
        dprintk("req_size=%d, max_requests=%d\n", req_size, hba->max_requests);
 
@@ -1355,9 +1104,12 @@ static int __devinit hptiop_probe(struct pci_dev *pcidev,
        if (hptiop_initialize_iop(hba))
                goto free_request_mem;
 
-       spin_lock(&hptiop_hba_list_lock);
-       list_add_tail(&hba->link, &hptiop_hba_list);
-       spin_unlock(&hptiop_hba_list_lock);
+       if (scsi_add_host(host, &pcidev->dev)) {
+               printk(KERN_ERR "scsi%d: scsi_add_host failed\n",
+                                       hba->host->host_no);
+               goto free_request_mem;
+       }
+
 
        scsi_scan_host(host);
 
@@ -1366,24 +1118,24 @@ static int __devinit hptiop_probe(struct pci_dev *pcidev,
 
 free_request_mem:
        dma_free_coherent(&hba->pcidev->dev,
-                       hba->req_size*hba->max_requests + 0x20,
+                       hba->req_size * hba->max_requests + 0x20,
                        hba->dma_coherent, hba->dma_coherent_handle);
 
 free_request_irq:
        free_irq(hba->pcidev->irq, hba);
 
-remove_scsi_host:
-       scsi_remove_host(host);
-
 unmap_pci_bar:
-       iounmap(hba->iop);
+       if (hba->ops->internal_memfree)
+               hba->ops->internal_memfree(hba);
 
-free_pci_regions:
-       pci_release_regions(pcidev) ;
+       hba->ops->unmap_pci_bar(hba);
 
 free_scsi_host:
        scsi_host_put(host);
 
+free_pci_regions:
+       pci_release_regions(pcidev);
+
 disable_pci_device:
        pci_disable_device(pcidev);
 
@@ -1395,8 +1147,6 @@ static void hptiop_shutdown(struct pci_dev *pcidev)
 {
        struct Scsi_Host *host = pci_get_drvdata(pcidev);
        struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
-       struct hpt_iopmu __iomem *iop = hba->iop;
-       u32    int_mask;
 
        dprintk("hptiop_shutdown(%p)\n", hba);
 
@@ -1406,11 +1156,24 @@ static void hptiop_shutdown(struct pci_dev *pcidev)
                                        hba->host->host_no);
 
        /* disable all outbound interrupts */
-       int_mask = readl(&iop->outbound_intmask);
+       hba->ops->disable_intr(hba);
+}
+
+static void hptiop_disable_intr_itl(struct hptiop_hba *hba)
+{
+       u32 int_mask;
+
+       int_mask = readl(&hba->u.itl.iop->outbound_intmask);
        writel(int_mask |
                IOPMU_OUTBOUND_INT_MSG0 | IOPMU_OUTBOUND_INT_POSTQUEUE,
-               &iop->outbound_intmask);
-       hptiop_pci_posting_flush(iop);
+               &hba->u.itl.iop->outbound_intmask);
+       readl(&hba->u.itl.iop->outbound_intmask);
+}
+
+static void hptiop_disable_intr_mv(struct hptiop_hba *hba)
+{
+       writel(0, &hba->u.mv.regs->outbound_intmask);
+       readl(&hba->u.mv.regs->outbound_intmask);
 }
 
 static void hptiop_remove(struct pci_dev *pcidev)
@@ -1422,10 +1185,6 @@ static void hptiop_remove(struct pci_dev *pcidev)
 
        scsi_remove_host(host);
 
-       spin_lock(&hptiop_hba_list_lock);
-       list_del_init(&hba->link);
-       spin_unlock(&hptiop_hba_list_lock);
-
        hptiop_shutdown(pcidev);
 
        free_irq(hba->pcidev->irq, hba);
@@ -1435,7 +1194,10 @@ static void hptiop_remove(struct pci_dev *pcidev)
                        hba->dma_coherent,
                        hba->dma_coherent_handle);
 
-       iounmap(hba->iop);
+       if (hba->ops->internal_memfree)
+               hba->ops->internal_memfree(hba);
+
+       hba->ops->unmap_pci_bar(hba);
 
        pci_release_regions(hba->pcidev);
        pci_set_drvdata(hba->pcidev, NULL);
@@ -1444,9 +1206,58 @@ static void hptiop_remove(struct pci_dev *pcidev)
        scsi_host_put(host);
 }
 
+static struct hptiop_adapter_ops hptiop_itl_ops = {
+       .iop_wait_ready    = iop_wait_ready_itl,
+       .internal_memalloc = NULL,
+       .internal_memfree  = NULL,
+       .map_pci_bar       = hptiop_map_pci_bar_itl,
+       .unmap_pci_bar     = hptiop_unmap_pci_bar_itl,
+       .enable_intr       = hptiop_enable_intr_itl,
+       .disable_intr      = hptiop_disable_intr_itl,
+       .get_config        = iop_get_config_itl,
+       .set_config        = iop_set_config_itl,
+       .iop_intr          = iop_intr_itl,
+       .post_msg          = hptiop_post_msg_itl,
+       .post_req          = hptiop_post_req_itl,
+};
+
+static struct hptiop_adapter_ops hptiop_mv_ops = {
+       .iop_wait_ready    = iop_wait_ready_mv,
+       .internal_memalloc = hptiop_internal_memalloc_mv,
+       .internal_memfree  = hptiop_internal_memfree_mv,
+       .map_pci_bar       = hptiop_map_pci_bar_mv,
+       .unmap_pci_bar     = hptiop_unmap_pci_bar_mv,
+       .enable_intr       = hptiop_enable_intr_mv,
+       .disable_intr      = hptiop_disable_intr_mv,
+       .get_config        = iop_get_config_mv,
+       .set_config        = iop_set_config_mv,
+       .iop_intr          = iop_intr_mv,
+       .post_msg          = hptiop_post_msg_mv,
+       .post_req          = hptiop_post_req_mv,
+};
+
 static struct pci_device_id hptiop_id_table[] = {
-       { PCI_DEVICE(0x1103, 0x3220) },
-       { PCI_DEVICE(0x1103, 0x3320) },
+       { PCI_VDEVICE(TTI, 0x3220), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x3320), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x3520), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x4320), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x3510), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x3511), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x3521), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x3522), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x3410), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x3540), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x3530), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x3560), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x4322), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x4321), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x4210), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x4211), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x4310), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x4311), (kernel_ulong_t)&hptiop_itl_ops },
+       { PCI_VDEVICE(TTI, 0x3120), (kernel_ulong_t)&hptiop_mv_ops },
+       { PCI_VDEVICE(TTI, 0x3122), (kernel_ulong_t)&hptiop_mv_ops },
+       { PCI_VDEVICE(TTI, 0x3020), (kernel_ulong_t)&hptiop_mv_ops },
        {},
 };
 
@@ -1462,27 +1273,12 @@ static struct pci_driver hptiop_pci_driver = {
 
 static int __init hptiop_module_init(void)
 {
-       int error;
-
        printk(KERN_INFO "%s %s\n", driver_name_long, driver_ver);
-
-       error = pci_register_driver(&hptiop_pci_driver);
-       if (error < 0)
-               return error;
-
-       hptiop_cdev_major = register_chrdev(0, "hptiop", &hptiop_cdev_fops);
-       if (hptiop_cdev_major < 0) {
-               printk(KERN_WARNING "unable to register hptiop device.\n");
-               return hptiop_cdev_major;
-       }
-
-       return 0;
+       return pci_register_driver(&hptiop_pci_driver);
 }
 
 static void __exit hptiop_module_exit(void)
 {
-       dprintk("hptiop_module_exit\n");
-       unregister_chrdev(hptiop_cdev_major, "hptiop");
        pci_unregister_driver(&hptiop_pci_driver);
 }
 
@@ -1491,3 +1287,4 @@ module_init(hptiop_module_init);
 module_exit(hptiop_module_exit);
 
 MODULE_LICENSE("GPL");
+