Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * HighPoint RR3xxx/4xxx controller driver for Linux
0004  * Copyright (C) 2006-2015 HighPoint Technologies, Inc. All Rights Reserved.
0005  *
0006  * Please report bugs/comments/suggestions to linux@highpoint-tech.com
0007  *
0008  * For more information, visit http://www.highpoint-tech.com
0009  */
0010 #include <linux/module.h>
0011 #include <linux/types.h>
0012 #include <linux/string.h>
0013 #include <linux/kernel.h>
0014 #include <linux/pci.h>
0015 #include <linux/interrupt.h>
0016 #include <linux/errno.h>
0017 #include <linux/delay.h>
0018 #include <linux/timer.h>
0019 #include <linux/spinlock.h>
0020 #include <linux/gfp.h>
0021 #include <linux/uaccess.h>
0022 #include <asm/io.h>
0023 #include <asm/div64.h>
0024 #include <scsi/scsi_cmnd.h>
0025 #include <scsi/scsi_device.h>
0026 #include <scsi/scsi.h>
0027 #include <scsi/scsi_tcq.h>
0028 #include <scsi/scsi_host.h>
0029 
0030 #include "hptiop.h"
0031 
0032 MODULE_AUTHOR("HighPoint Technologies, Inc.");
0033 MODULE_DESCRIPTION("HighPoint RocketRAID 3xxx/4xxx Controller Driver");
0034 
0035 static char driver_name[] = "hptiop";
0036 static const char driver_name_long[] = "RocketRAID 3xxx/4xxx Controller driver";
0037 static const char driver_ver[] = "v1.10.0";
0038 
0039 static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec);
0040 static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
0041                 struct hpt_iop_request_scsi_command *req);
0042 static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 tag);
0043 static void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag);
0044 static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg);
0045 
0046 static int iop_wait_ready_itl(struct hptiop_hba *hba, u32 millisec)
0047 {
0048     u32 req = 0;
0049     int i;
0050 
0051     for (i = 0; i < millisec; i++) {
0052         req = readl(&hba->u.itl.iop->inbound_queue);
0053         if (req != IOPMU_QUEUE_EMPTY)
0054             break;
0055         msleep(1);
0056     }
0057 
0058     if (req != IOPMU_QUEUE_EMPTY) {
0059         writel(req, &hba->u.itl.iop->outbound_queue);
0060         readl(&hba->u.itl.iop->outbound_intstatus);
0061         return 0;
0062     }
0063 
0064     return -1;
0065 }
0066 
0067 static int iop_wait_ready_mv(struct hptiop_hba *hba, u32 millisec)
0068 {
0069     return iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_NOP, millisec);
0070 }
0071 
0072 static int iop_wait_ready_mvfrey(struct hptiop_hba *hba, u32 millisec)
0073 {
0074     return iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_NOP, millisec);
0075 }
0076 
0077 static void hptiop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
0078 {
0079     if (tag & IOPMU_QUEUE_ADDR_HOST_BIT)
0080         hptiop_host_request_callback_itl(hba,
0081                 tag & ~IOPMU_QUEUE_ADDR_HOST_BIT);
0082     else
0083         hptiop_iop_request_callback_itl(hba, tag);
0084 }
0085 
0086 static void hptiop_drain_outbound_queue_itl(struct hptiop_hba *hba)
0087 {
0088     u32 req;
0089 
0090     while ((req = readl(&hba->u.itl.iop->outbound_queue)) !=
0091                         IOPMU_QUEUE_EMPTY) {
0092 
0093         if (req & IOPMU_QUEUE_MASK_HOST_BITS)
0094             hptiop_request_callback_itl(hba, req);
0095         else {
0096             struct hpt_iop_request_header __iomem * p;
0097 
0098             p = (struct hpt_iop_request_header __iomem *)
0099                 ((char __iomem *)hba->u.itl.iop + req);
0100 
0101             if (readl(&p->flags) & IOP_REQUEST_FLAG_SYNC_REQUEST) {
0102                 if (readl(&p->context))
0103                     hptiop_request_callback_itl(hba, req);
0104                 else
0105                     writel(1, &p->context);
0106             }
0107             else
0108                 hptiop_request_callback_itl(hba, req);
0109         }
0110     }
0111 }
0112 
0113 static int iop_intr_itl(struct hptiop_hba *hba)
0114 {
0115     struct hpt_iopmu_itl __iomem *iop = hba->u.itl.iop;
0116     void __iomem *plx = hba->u.itl.plx;
0117     u32 status;
0118     int ret = 0;
0119 
0120     if (plx && readl(plx + 0x11C5C) & 0xf)
0121         writel(1, plx + 0x11C60);
0122 
0123     status = readl(&iop->outbound_intstatus);
0124 
0125     if (status & IOPMU_OUTBOUND_INT_MSG0) {
0126         u32 msg = readl(&iop->outbound_msgaddr0);
0127 
0128         dprintk("received outbound msg %x\n", msg);
0129         writel(IOPMU_OUTBOUND_INT_MSG0, &iop->outbound_intstatus);
0130         hptiop_message_callback(hba, msg);
0131         ret = 1;
0132     }
0133 
0134     if (status & IOPMU_OUTBOUND_INT_POSTQUEUE) {
0135         hptiop_drain_outbound_queue_itl(hba);
0136         ret = 1;
0137     }
0138 
0139     return ret;
0140 }
0141 
0142 static u64 mv_outbound_read(struct hpt_iopmu_mv __iomem *mu)
0143 {
0144     u32 outbound_tail = readl(&mu->outbound_tail);
0145     u32 outbound_head = readl(&mu->outbound_head);
0146 
0147     if (outbound_tail != outbound_head) {
0148         u64 p;
0149 
0150         memcpy_fromio(&p, &mu->outbound_q[mu->outbound_tail], 8);
0151         outbound_tail++;
0152 
0153         if (outbound_tail == MVIOP_QUEUE_LEN)
0154             outbound_tail = 0;
0155         writel(outbound_tail, &mu->outbound_tail);
0156         return p;
0157     } else
0158         return 0;
0159 }
0160 
0161 static void mv_inbound_write(u64 p, struct hptiop_hba *hba)
0162 {
0163     u32 inbound_head = readl(&hba->u.mv.mu->inbound_head);
0164     u32 head = inbound_head + 1;
0165 
0166     if (head == MVIOP_QUEUE_LEN)
0167         head = 0;
0168 
0169     memcpy_toio(&hba->u.mv.mu->inbound_q[inbound_head], &p, 8);
0170     writel(head, &hba->u.mv.mu->inbound_head);
0171     writel(MVIOP_MU_INBOUND_INT_POSTQUEUE,
0172             &hba->u.mv.regs->inbound_doorbell);
0173 }
0174 
0175 static void hptiop_request_callback_mv(struct hptiop_hba *hba, u64 tag)
0176 {
0177     u32 req_type = (tag >> 5) & 0x7;
0178     struct hpt_iop_request_scsi_command *req;
0179 
0180     dprintk("hptiop_request_callback_mv: tag=%llx\n", tag);
0181 
0182     BUG_ON((tag & MVIOP_MU_QUEUE_REQUEST_RETURN_CONTEXT) == 0);
0183 
0184     switch (req_type) {
0185     case IOP_REQUEST_TYPE_GET_CONFIG:
0186     case IOP_REQUEST_TYPE_SET_CONFIG:
0187         hba->msg_done = 1;
0188         break;
0189 
0190     case IOP_REQUEST_TYPE_SCSI_COMMAND:
0191         req = hba->reqs[tag >> 8].req_virt;
0192         if (likely(tag & MVIOP_MU_QUEUE_REQUEST_RESULT_BIT))
0193             req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
0194 
0195         hptiop_finish_scsi_req(hba, tag>>8, req);
0196         break;
0197 
0198     default:
0199         break;
0200     }
0201 }
0202 
0203 static int iop_intr_mv(struct hptiop_hba *hba)
0204 {
0205     u32 status;
0206     int ret = 0;
0207 
0208     status = readl(&hba->u.mv.regs->outbound_doorbell);
0209     writel(~status, &hba->u.mv.regs->outbound_doorbell);
0210 
0211     if (status & MVIOP_MU_OUTBOUND_INT_MSG) {
0212         u32 msg;
0213         msg = readl(&hba->u.mv.mu->outbound_msg);
0214         dprintk("received outbound msg %x\n", msg);
0215         hptiop_message_callback(hba, msg);
0216         ret = 1;
0217     }
0218 
0219     if (status & MVIOP_MU_OUTBOUND_INT_POSTQUEUE) {
0220         u64 tag;
0221 
0222         while ((tag = mv_outbound_read(hba->u.mv.mu)))
0223             hptiop_request_callback_mv(hba, tag);
0224         ret = 1;
0225     }
0226 
0227     return ret;
0228 }
0229 
0230 static void hptiop_request_callback_mvfrey(struct hptiop_hba *hba, u32 _tag)
0231 {
0232     u32 req_type = _tag & 0xf;
0233     struct hpt_iop_request_scsi_command *req;
0234 
0235     switch (req_type) {
0236     case IOP_REQUEST_TYPE_GET_CONFIG:
0237     case IOP_REQUEST_TYPE_SET_CONFIG:
0238         hba->msg_done = 1;
0239         break;
0240 
0241     case IOP_REQUEST_TYPE_SCSI_COMMAND:
0242         req = hba->reqs[(_tag >> 4) & 0xff].req_virt;
0243         if (likely(_tag & IOPMU_QUEUE_REQUEST_RESULT_BIT))
0244             req->header.result = IOP_RESULT_SUCCESS;
0245         hptiop_finish_scsi_req(hba, (_tag >> 4) & 0xff, req);
0246         break;
0247 
0248     default:
0249         break;
0250     }
0251 }
0252 
0253 static int iop_intr_mvfrey(struct hptiop_hba *hba)
0254 {
0255     u32 _tag, status, cptr, cur_rptr;
0256     int ret = 0;
0257 
0258     if (hba->initialized)
0259         writel(0, &(hba->u.mvfrey.mu->pcie_f0_int_enable));
0260 
0261     status = readl(&(hba->u.mvfrey.mu->f0_doorbell));
0262     if (status) {
0263         writel(status, &(hba->u.mvfrey.mu->f0_doorbell));
0264         if (status & CPU_TO_F0_DRBL_MSG_BIT) {
0265             u32 msg = readl(&(hba->u.mvfrey.mu->cpu_to_f0_msg_a));
0266             dprintk("received outbound msg %x\n", msg);
0267             hptiop_message_callback(hba, msg);
0268         }
0269         ret = 1;
0270     }
0271 
0272     status = readl(&(hba->u.mvfrey.mu->isr_cause));
0273     if (status) {
0274         writel(status, &(hba->u.mvfrey.mu->isr_cause));
0275         do {
0276             cptr = *hba->u.mvfrey.outlist_cptr & 0xff;
0277             cur_rptr = hba->u.mvfrey.outlist_rptr;
0278             while (cur_rptr != cptr) {
0279                 cur_rptr++;
0280                 if (cur_rptr == hba->u.mvfrey.list_count)
0281                     cur_rptr = 0;
0282 
0283                 _tag = hba->u.mvfrey.outlist[cur_rptr].val;
0284                 BUG_ON(!(_tag & IOPMU_QUEUE_MASK_HOST_BITS));
0285                 hptiop_request_callback_mvfrey(hba, _tag);
0286                 ret = 1;
0287             }
0288             hba->u.mvfrey.outlist_rptr = cur_rptr;
0289         } while (cptr != (*hba->u.mvfrey.outlist_cptr & 0xff));
0290     }
0291 
0292     if (hba->initialized)
0293         writel(0x1010, &(hba->u.mvfrey.mu->pcie_f0_int_enable));
0294 
0295     return ret;
0296 }
0297 
0298 static int iop_send_sync_request_itl(struct hptiop_hba *hba,
0299                     void __iomem *_req, u32 millisec)
0300 {
0301     struct hpt_iop_request_header __iomem *req = _req;
0302     u32 i;
0303 
0304     writel(readl(&req->flags) | IOP_REQUEST_FLAG_SYNC_REQUEST, &req->flags);
0305     writel(0, &req->context);
0306     writel((unsigned long)req - (unsigned long)hba->u.itl.iop,
0307             &hba->u.itl.iop->inbound_queue);
0308     readl(&hba->u.itl.iop->outbound_intstatus);
0309 
0310     for (i = 0; i < millisec; i++) {
0311         iop_intr_itl(hba);
0312         if (readl(&req->context))
0313             return 0;
0314         msleep(1);
0315     }
0316 
0317     return -1;
0318 }
0319 
0320 static int iop_send_sync_request_mv(struct hptiop_hba *hba,
0321                     u32 size_bits, u32 millisec)
0322 {
0323     struct hpt_iop_request_header *reqhdr = hba->u.mv.internal_req;
0324     u32 i;
0325 
0326     hba->msg_done = 0;
0327     reqhdr->flags |= cpu_to_le32(IOP_REQUEST_FLAG_SYNC_REQUEST);
0328     mv_inbound_write(hba->u.mv.internal_req_phy |
0329             MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bits, hba);
0330 
0331     for (i = 0; i < millisec; i++) {
0332         iop_intr_mv(hba);
0333         if (hba->msg_done)
0334             return 0;
0335         msleep(1);
0336     }
0337     return -1;
0338 }
0339 
0340 static int iop_send_sync_request_mvfrey(struct hptiop_hba *hba,
0341                     u32 size_bits, u32 millisec)
0342 {
0343     struct hpt_iop_request_header *reqhdr =
0344         hba->u.mvfrey.internal_req.req_virt;
0345     u32 i;
0346 
0347     hba->msg_done = 0;
0348     reqhdr->flags |= cpu_to_le32(IOP_REQUEST_FLAG_SYNC_REQUEST);
0349     hba->ops->post_req(hba, &(hba->u.mvfrey.internal_req));
0350 
0351     for (i = 0; i < millisec; i++) {
0352         iop_intr_mvfrey(hba);
0353         if (hba->msg_done)
0354             break;
0355         msleep(1);
0356     }
0357     return hba->msg_done ? 0 : -1;
0358 }
0359 
0360 static void hptiop_post_msg_itl(struct hptiop_hba *hba, u32 msg)
0361 {
0362     writel(msg, &hba->u.itl.iop->inbound_msgaddr0);
0363     readl(&hba->u.itl.iop->outbound_intstatus);
0364 }
0365 
0366 static void hptiop_post_msg_mv(struct hptiop_hba *hba, u32 msg)
0367 {
0368     writel(msg, &hba->u.mv.mu->inbound_msg);
0369     writel(MVIOP_MU_INBOUND_INT_MSG, &hba->u.mv.regs->inbound_doorbell);
0370     readl(&hba->u.mv.regs->inbound_doorbell);
0371 }
0372 
0373 static void hptiop_post_msg_mvfrey(struct hptiop_hba *hba, u32 msg)
0374 {
0375     writel(msg, &(hba->u.mvfrey.mu->f0_to_cpu_msg_a));
0376     readl(&(hba->u.mvfrey.mu->f0_to_cpu_msg_a));
0377 }
0378 
0379 static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec)
0380 {
0381     u32 i;
0382 
0383     hba->msg_done = 0;
0384     hba->ops->disable_intr(hba);
0385     hba->ops->post_msg(hba, msg);
0386 
0387     for (i = 0; i < millisec; i++) {
0388         spin_lock_irq(hba->host->host_lock);
0389         hba->ops->iop_intr(hba);
0390         spin_unlock_irq(hba->host->host_lock);
0391         if (hba->msg_done)
0392             break;
0393         msleep(1);
0394     }
0395 
0396     hba->ops->enable_intr(hba);
0397     return hba->msg_done? 0 : -1;
0398 }
0399 
0400 static int iop_get_config_itl(struct hptiop_hba *hba,
0401                 struct hpt_iop_request_get_config *config)
0402 {
0403     u32 req32;
0404     struct hpt_iop_request_get_config __iomem *req;
0405 
0406     req32 = readl(&hba->u.itl.iop->inbound_queue);
0407     if (req32 == IOPMU_QUEUE_EMPTY)
0408         return -1;
0409 
0410     req = (struct hpt_iop_request_get_config __iomem *)
0411             ((unsigned long)hba->u.itl.iop + req32);
0412 
0413     writel(0, &req->header.flags);
0414     writel(IOP_REQUEST_TYPE_GET_CONFIG, &req->header.type);
0415     writel(sizeof(struct hpt_iop_request_get_config), &req->header.size);
0416     writel(IOP_RESULT_PENDING, &req->header.result);
0417 
0418     if (iop_send_sync_request_itl(hba, req, 20000)) {
0419         dprintk("Get config send cmd failed\n");
0420         return -1;
0421     }
0422 
0423     memcpy_fromio(config, req, sizeof(*config));
0424     writel(req32, &hba->u.itl.iop->outbound_queue);
0425     return 0;
0426 }
0427 
0428 static int iop_get_config_mv(struct hptiop_hba *hba,
0429                 struct hpt_iop_request_get_config *config)
0430 {
0431     struct hpt_iop_request_get_config *req = hba->u.mv.internal_req;
0432 
0433     req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
0434     req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG);
0435     req->header.size =
0436         cpu_to_le32(sizeof(struct hpt_iop_request_get_config));
0437     req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
0438     req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG<<5);
0439     req->header.context_hi32 = 0;
0440 
0441     if (iop_send_sync_request_mv(hba, 0, 20000)) {
0442         dprintk("Get config send cmd failed\n");
0443         return -1;
0444     }
0445 
0446     memcpy(config, req, sizeof(struct hpt_iop_request_get_config));
0447     return 0;
0448 }
0449 
0450 static int iop_get_config_mvfrey(struct hptiop_hba *hba,
0451                 struct hpt_iop_request_get_config *config)
0452 {
0453     struct hpt_iop_request_get_config *info = hba->u.mvfrey.config;
0454 
0455     if (info->header.size != sizeof(struct hpt_iop_request_get_config) ||
0456             info->header.type != IOP_REQUEST_TYPE_GET_CONFIG)
0457         return -1;
0458 
0459     config->interface_version = info->interface_version;
0460     config->firmware_version = info->firmware_version;
0461     config->max_requests = info->max_requests;
0462     config->request_size = info->request_size;
0463     config->max_sg_count = info->max_sg_count;
0464     config->data_transfer_length = info->data_transfer_length;
0465     config->alignment_mask = info->alignment_mask;
0466     config->max_devices = info->max_devices;
0467     config->sdram_size = info->sdram_size;
0468 
0469     return 0;
0470 }
0471 
0472 static int iop_set_config_itl(struct hptiop_hba *hba,
0473                 struct hpt_iop_request_set_config *config)
0474 {
0475     u32 req32;
0476     struct hpt_iop_request_set_config __iomem *req;
0477 
0478     req32 = readl(&hba->u.itl.iop->inbound_queue);
0479     if (req32 == IOPMU_QUEUE_EMPTY)
0480         return -1;
0481 
0482     req = (struct hpt_iop_request_set_config __iomem *)
0483             ((unsigned long)hba->u.itl.iop + req32);
0484 
0485     memcpy_toio((u8 __iomem *)req + sizeof(struct hpt_iop_request_header),
0486         (u8 *)config + sizeof(struct hpt_iop_request_header),
0487         sizeof(struct hpt_iop_request_set_config) -
0488             sizeof(struct hpt_iop_request_header));
0489 
0490     writel(0, &req->header.flags);
0491     writel(IOP_REQUEST_TYPE_SET_CONFIG, &req->header.type);
0492     writel(sizeof(struct hpt_iop_request_set_config), &req->header.size);
0493     writel(IOP_RESULT_PENDING, &req->header.result);
0494 
0495     if (iop_send_sync_request_itl(hba, req, 20000)) {
0496         dprintk("Set config send cmd failed\n");
0497         return -1;
0498     }
0499 
0500     writel(req32, &hba->u.itl.iop->outbound_queue);
0501     return 0;
0502 }
0503 
0504 static int iop_set_config_mv(struct hptiop_hba *hba,
0505                 struct hpt_iop_request_set_config *config)
0506 {
0507     struct hpt_iop_request_set_config *req = hba->u.mv.internal_req;
0508 
0509     memcpy(req, config, sizeof(struct hpt_iop_request_set_config));
0510     req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
0511     req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG);
0512     req->header.size =
0513         cpu_to_le32(sizeof(struct hpt_iop_request_set_config));
0514     req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
0515     req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG<<5);
0516     req->header.context_hi32 = 0;
0517 
0518     if (iop_send_sync_request_mv(hba, 0, 20000)) {
0519         dprintk("Set config send cmd failed\n");
0520         return -1;
0521     }
0522 
0523     return 0;
0524 }
0525 
0526 static int iop_set_config_mvfrey(struct hptiop_hba *hba,
0527                 struct hpt_iop_request_set_config *config)
0528 {
0529     struct hpt_iop_request_set_config *req =
0530         hba->u.mvfrey.internal_req.req_virt;
0531 
0532     memcpy(req, config, sizeof(struct hpt_iop_request_set_config));
0533     req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
0534     req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG);
0535     req->header.size =
0536         cpu_to_le32(sizeof(struct hpt_iop_request_set_config));
0537     req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
0538     req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG<<5);
0539     req->header.context_hi32 = 0;
0540 
0541     if (iop_send_sync_request_mvfrey(hba, 0, 20000)) {
0542         dprintk("Set config send cmd failed\n");
0543         return -1;
0544     }
0545 
0546     return 0;
0547 }
0548 
0549 static void hptiop_enable_intr_itl(struct hptiop_hba *hba)
0550 {
0551     writel(~(IOPMU_OUTBOUND_INT_POSTQUEUE | IOPMU_OUTBOUND_INT_MSG0),
0552         &hba->u.itl.iop->outbound_intmask);
0553 }
0554 
0555 static void hptiop_enable_intr_mv(struct hptiop_hba *hba)
0556 {
0557     writel(MVIOP_MU_OUTBOUND_INT_POSTQUEUE | MVIOP_MU_OUTBOUND_INT_MSG,
0558         &hba->u.mv.regs->outbound_intmask);
0559 }
0560 
0561 static void hptiop_enable_intr_mvfrey(struct hptiop_hba *hba)
0562 {
0563     writel(CPU_TO_F0_DRBL_MSG_BIT, &(hba->u.mvfrey.mu->f0_doorbell_enable));
0564     writel(0x1, &(hba->u.mvfrey.mu->isr_enable));
0565     writel(0x1010, &(hba->u.mvfrey.mu->pcie_f0_int_enable));
0566 }
0567 
0568 static int hptiop_initialize_iop(struct hptiop_hba *hba)
0569 {
0570     /* enable interrupts */
0571     hba->ops->enable_intr(hba);
0572 
0573     hba->initialized = 1;
0574 
0575     /* start background tasks */
0576     if (iop_send_sync_msg(hba,
0577             IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
0578         printk(KERN_ERR "scsi%d: fail to start background task\n",
0579             hba->host->host_no);
0580         return -1;
0581     }
0582     return 0;
0583 }
0584 
0585 static void __iomem *hptiop_map_pci_bar(struct hptiop_hba *hba, int index)
0586 {
0587     u32 mem_base_phy, length;
0588     void __iomem *mem_base_virt;
0589 
0590     struct pci_dev *pcidev = hba->pcidev;
0591 
0592 
0593     if (!(pci_resource_flags(pcidev, index) & IORESOURCE_MEM)) {
0594         printk(KERN_ERR "scsi%d: pci resource invalid\n",
0595                 hba->host->host_no);
0596         return NULL;
0597     }
0598 
0599     mem_base_phy = pci_resource_start(pcidev, index);
0600     length = pci_resource_len(pcidev, index);
0601     mem_base_virt = ioremap(mem_base_phy, length);
0602 
0603     if (!mem_base_virt) {
0604         printk(KERN_ERR "scsi%d: Fail to ioremap memory space\n",
0605                 hba->host->host_no);
0606         return NULL;
0607     }
0608     return mem_base_virt;
0609 }
0610 
0611 static int hptiop_map_pci_bar_itl(struct hptiop_hba *hba)
0612 {
0613     struct pci_dev *pcidev = hba->pcidev;
0614     hba->u.itl.iop = hptiop_map_pci_bar(hba, 0);
0615     if (hba->u.itl.iop == NULL)
0616         return -1;
0617     if ((pcidev->device & 0xff00) == 0x4400) {
0618         hba->u.itl.plx = hba->u.itl.iop;
0619         hba->u.itl.iop = hptiop_map_pci_bar(hba, 2);
0620         if (hba->u.itl.iop == NULL) {
0621             iounmap(hba->u.itl.plx);
0622             return -1;
0623         }
0624     }
0625     return 0;
0626 }
0627 
0628 static void hptiop_unmap_pci_bar_itl(struct hptiop_hba *hba)
0629 {
0630     if (hba->u.itl.plx)
0631         iounmap(hba->u.itl.plx);
0632     iounmap(hba->u.itl.iop);
0633 }
0634 
0635 static int hptiop_map_pci_bar_mv(struct hptiop_hba *hba)
0636 {
0637     hba->u.mv.regs = hptiop_map_pci_bar(hba, 0);
0638     if (hba->u.mv.regs == NULL)
0639         return -1;
0640 
0641     hba->u.mv.mu = hptiop_map_pci_bar(hba, 2);
0642     if (hba->u.mv.mu == NULL) {
0643         iounmap(hba->u.mv.regs);
0644         return -1;
0645     }
0646 
0647     return 0;
0648 }
0649 
0650 static int hptiop_map_pci_bar_mvfrey(struct hptiop_hba *hba)
0651 {
0652     hba->u.mvfrey.config = hptiop_map_pci_bar(hba, 0);
0653     if (hba->u.mvfrey.config == NULL)
0654         return -1;
0655 
0656     hba->u.mvfrey.mu = hptiop_map_pci_bar(hba, 2);
0657     if (hba->u.mvfrey.mu == NULL) {
0658         iounmap(hba->u.mvfrey.config);
0659         return -1;
0660     }
0661 
0662     return 0;
0663 }
0664 
0665 static void hptiop_unmap_pci_bar_mv(struct hptiop_hba *hba)
0666 {
0667     iounmap(hba->u.mv.regs);
0668     iounmap(hba->u.mv.mu);
0669 }
0670 
0671 static void hptiop_unmap_pci_bar_mvfrey(struct hptiop_hba *hba)
0672 {
0673     iounmap(hba->u.mvfrey.config);
0674     iounmap(hba->u.mvfrey.mu);
0675 }
0676 
0677 static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg)
0678 {
0679     dprintk("iop message 0x%x\n", msg);
0680 
0681     if (msg == IOPMU_INBOUND_MSG0_NOP ||
0682         msg == IOPMU_INBOUND_MSG0_RESET_COMM)
0683         hba->msg_done = 1;
0684 
0685     if (!hba->initialized)
0686         return;
0687 
0688     if (msg == IOPMU_INBOUND_MSG0_RESET) {
0689         atomic_set(&hba->resetting, 0);
0690         wake_up(&hba->reset_wq);
0691     }
0692     else if (msg <= IOPMU_INBOUND_MSG0_MAX)
0693         hba->msg_done = 1;
0694 }
0695 
0696 static struct hptiop_request *get_req(struct hptiop_hba *hba)
0697 {
0698     struct hptiop_request *ret;
0699 
0700     dprintk("get_req : req=%p\n", hba->req_list);
0701 
0702     ret = hba->req_list;
0703     if (ret)
0704         hba->req_list = ret->next;
0705 
0706     return ret;
0707 }
0708 
0709 static void free_req(struct hptiop_hba *hba, struct hptiop_request *req)
0710 {
0711     dprintk("free_req(%d, %p)\n", req->index, req);
0712     req->next = hba->req_list;
0713     hba->req_list = req;
0714 }
0715 
0716 static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
0717                 struct hpt_iop_request_scsi_command *req)
0718 {
0719     struct scsi_cmnd *scp;
0720 
0721     dprintk("hptiop_finish_scsi_req: req=%p, type=%d, "
0722             "result=%d, context=0x%x tag=%d\n",
0723             req, req->header.type, req->header.result,
0724             req->header.context, tag);
0725 
0726     BUG_ON(!req->header.result);
0727     BUG_ON(req->header.type != cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND));
0728 
0729     scp = hba->reqs[tag].scp;
0730 
0731     if (HPT_SCP(scp)->mapped)
0732         scsi_dma_unmap(scp);
0733 
0734     switch (le32_to_cpu(req->header.result)) {
0735     case IOP_RESULT_SUCCESS:
0736         scsi_set_resid(scp,
0737             scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
0738         scp->result = (DID_OK<<16);
0739         break;
0740     case IOP_RESULT_BAD_TARGET:
0741         scp->result = (DID_BAD_TARGET<<16);
0742         break;
0743     case IOP_RESULT_BUSY:
0744         scp->result = (DID_BUS_BUSY<<16);
0745         break;
0746     case IOP_RESULT_RESET:
0747         scp->result = (DID_RESET<<16);
0748         break;
0749     case IOP_RESULT_FAIL:
0750         scp->result = (DID_ERROR<<16);
0751         break;
0752     case IOP_RESULT_INVALID_REQUEST:
0753         scp->result = (DID_ABORT<<16);
0754         break;
0755     case IOP_RESULT_CHECK_CONDITION:
0756         scsi_set_resid(scp,
0757             scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
0758         scp->result = SAM_STAT_CHECK_CONDITION;
0759         memcpy(scp->sense_buffer, &req->sg_list, SCSI_SENSE_BUFFERSIZE);
0760         goto skip_resid;
0761 
0762     default:
0763         scp->result = DID_ABORT << 16;
0764         break;
0765     }
0766 
0767     scsi_set_resid(scp,
0768         scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
0769 
0770 skip_resid:
0771     dprintk("scsi_done(%p)\n", scp);
0772     scsi_done(scp);
0773     free_req(hba, &hba->reqs[tag]);
0774 }
0775 
0776 static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 _tag)
0777 {
0778     struct hpt_iop_request_scsi_command *req;
0779     u32 tag;
0780 
0781     if (hba->iopintf_v2) {
0782         tag = _tag & ~IOPMU_QUEUE_REQUEST_RESULT_BIT;
0783         req = hba->reqs[tag].req_virt;
0784         if (likely(_tag & IOPMU_QUEUE_REQUEST_RESULT_BIT))
0785             req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
0786     } else {
0787         tag = _tag;
0788         req = hba->reqs[tag].req_virt;
0789     }
0790 
0791     hptiop_finish_scsi_req(hba, tag, req);
0792 }
0793 
0794 static void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
0795 {
0796     struct hpt_iop_request_header __iomem *req;
0797     struct hpt_iop_request_ioctl_command __iomem *p;
0798     struct hpt_ioctl_k *arg;
0799 
0800     req = (struct hpt_iop_request_header __iomem *)
0801             ((unsigned long)hba->u.itl.iop + tag);
0802     dprintk("hptiop_iop_request_callback_itl: req=%p, type=%d, "
0803             "result=%d, context=0x%x tag=%d\n",
0804             req, readl(&req->type), readl(&req->result),
0805             readl(&req->context), tag);
0806 
0807     BUG_ON(!readl(&req->result));
0808     BUG_ON(readl(&req->type) != IOP_REQUEST_TYPE_IOCTL_COMMAND);
0809 
0810     p = (struct hpt_iop_request_ioctl_command __iomem *)req;
0811     arg = (struct hpt_ioctl_k *)(unsigned long)
0812         (readl(&req->context) |
0813             ((u64)readl(&req->context_hi32)<<32));
0814 
0815     if (readl(&req->result) == IOP_RESULT_SUCCESS) {
0816         arg->result = HPT_IOCTL_RESULT_OK;
0817 
0818         if (arg->outbuf_size)
0819             memcpy_fromio(arg->outbuf,
0820                 &p->buf[(readl(&p->inbuf_size) + 3)& ~3],
0821                 arg->outbuf_size);
0822 
0823         if (arg->bytes_returned)
0824             *arg->bytes_returned = arg->outbuf_size;
0825     }
0826     else
0827         arg->result = HPT_IOCTL_RESULT_FAILED;
0828 
0829     arg->done(arg);
0830     writel(tag, &hba->u.itl.iop->outbound_queue);
0831 }
0832 
0833 static irqreturn_t hptiop_intr(int irq, void *dev_id)
0834 {
0835     struct hptiop_hba  *hba = dev_id;
0836     int  handled;
0837     unsigned long flags;
0838 
0839     spin_lock_irqsave(hba->host->host_lock, flags);
0840     handled = hba->ops->iop_intr(hba);
0841     spin_unlock_irqrestore(hba->host->host_lock, flags);
0842 
0843     return handled;
0844 }
0845 
0846 static int hptiop_buildsgl(struct scsi_cmnd *scp, struct hpt_iopsg *psg)
0847 {
0848     struct Scsi_Host *host = scp->device->host;
0849     struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
0850     struct scatterlist *sg;
0851     int idx, nseg;
0852 
0853     nseg = scsi_dma_map(scp);
0854     BUG_ON(nseg < 0);
0855     if (!nseg)
0856         return 0;
0857 
0858     HPT_SCP(scp)->sgcnt = nseg;
0859     HPT_SCP(scp)->mapped = 1;
0860 
0861     BUG_ON(HPT_SCP(scp)->sgcnt > hba->max_sg_descriptors);
0862 
0863     scsi_for_each_sg(scp, sg, HPT_SCP(scp)->sgcnt, idx) {
0864         psg[idx].pci_address = cpu_to_le64(sg_dma_address(sg)) |
0865             hba->ops->host_phy_flag;
0866         psg[idx].size = cpu_to_le32(sg_dma_len(sg));
0867         psg[idx].eot = (idx == HPT_SCP(scp)->sgcnt - 1) ?
0868             cpu_to_le32(1) : 0;
0869     }
0870     return HPT_SCP(scp)->sgcnt;
0871 }
0872 
0873 static void hptiop_post_req_itl(struct hptiop_hba *hba,
0874                     struct hptiop_request *_req)
0875 {
0876     struct hpt_iop_request_header *reqhdr = _req->req_virt;
0877 
0878     reqhdr->context = cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT |
0879                             (u32)_req->index);
0880     reqhdr->context_hi32 = 0;
0881 
0882     if (hba->iopintf_v2) {
0883         u32 size, size_bits;
0884 
0885         size = le32_to_cpu(reqhdr->size);
0886         if (size < 256)
0887             size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT;
0888         else if (size < 512)
0889             size_bits = IOPMU_QUEUE_ADDR_HOST_BIT;
0890         else
0891             size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT |
0892                         IOPMU_QUEUE_ADDR_HOST_BIT;
0893         writel(_req->req_shifted_phy | size_bits,
0894             &hba->u.itl.iop->inbound_queue);
0895     } else
0896         writel(_req->req_shifted_phy | IOPMU_QUEUE_ADDR_HOST_BIT,
0897                     &hba->u.itl.iop->inbound_queue);
0898 }
0899 
0900 static void hptiop_post_req_mv(struct hptiop_hba *hba,
0901                     struct hptiop_request *_req)
0902 {
0903     struct hpt_iop_request_header *reqhdr = _req->req_virt;
0904     u32 size, size_bit;
0905 
0906     reqhdr->context = cpu_to_le32(_req->index<<8 |
0907                     IOP_REQUEST_TYPE_SCSI_COMMAND<<5);
0908     reqhdr->context_hi32 = 0;
0909     size = le32_to_cpu(reqhdr->size);
0910 
0911     if (size <= 256)
0912         size_bit = 0;
0913     else if (size <= 256*2)
0914         size_bit = 1;
0915     else if (size <= 256*3)
0916         size_bit = 2;
0917     else
0918         size_bit = 3;
0919 
0920     mv_inbound_write((_req->req_shifted_phy << 5) |
0921         MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bit, hba);
0922 }
0923 
0924 static void hptiop_post_req_mvfrey(struct hptiop_hba *hba,
0925                     struct hptiop_request *_req)
0926 {
0927     struct hpt_iop_request_header *reqhdr = _req->req_virt;
0928     u32 index;
0929 
0930     reqhdr->flags |= cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT |
0931             IOP_REQUEST_FLAG_ADDR_BITS |
0932             ((_req->req_shifted_phy >> 11) & 0xffff0000));
0933     reqhdr->context = cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT |
0934             (_req->index << 4) | reqhdr->type);
0935     reqhdr->context_hi32 = cpu_to_le32((_req->req_shifted_phy << 5) &
0936             0xffffffff);
0937 
0938     hba->u.mvfrey.inlist_wptr++;
0939     index = hba->u.mvfrey.inlist_wptr & 0x3fff;
0940 
0941     if (index == hba->u.mvfrey.list_count) {
0942         index = 0;
0943         hba->u.mvfrey.inlist_wptr &= ~0x3fff;
0944         hba->u.mvfrey.inlist_wptr ^= CL_POINTER_TOGGLE;
0945     }
0946 
0947     hba->u.mvfrey.inlist[index].addr =
0948             (dma_addr_t)_req->req_shifted_phy << 5;
0949     hba->u.mvfrey.inlist[index].intrfc_len = (reqhdr->size + 3) / 4;
0950     writel(hba->u.mvfrey.inlist_wptr,
0951         &(hba->u.mvfrey.mu->inbound_write_ptr));
0952     readl(&(hba->u.mvfrey.mu->inbound_write_ptr));
0953 }
0954 
0955 static int hptiop_reset_comm_itl(struct hptiop_hba *hba)
0956 {
0957     return 0;
0958 }
0959 
0960 static int hptiop_reset_comm_mv(struct hptiop_hba *hba)
0961 {
0962     return 0;
0963 }
0964 
0965 static int hptiop_reset_comm_mvfrey(struct hptiop_hba *hba)
0966 {
0967     u32 list_count = hba->u.mvfrey.list_count;
0968 
0969     if (iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_RESET_COMM, 3000))
0970         return -1;
0971 
0972     /* wait 100ms for MCU ready */
0973     msleep(100);
0974 
0975     writel(cpu_to_le32(hba->u.mvfrey.inlist_phy & 0xffffffff),
0976             &(hba->u.mvfrey.mu->inbound_base));
0977     writel(cpu_to_le32((hba->u.mvfrey.inlist_phy >> 16) >> 16),
0978             &(hba->u.mvfrey.mu->inbound_base_high));
0979 
0980     writel(cpu_to_le32(hba->u.mvfrey.outlist_phy & 0xffffffff),
0981             &(hba->u.mvfrey.mu->outbound_base));
0982     writel(cpu_to_le32((hba->u.mvfrey.outlist_phy >> 16) >> 16),
0983             &(hba->u.mvfrey.mu->outbound_base_high));
0984 
0985     writel(cpu_to_le32(hba->u.mvfrey.outlist_cptr_phy & 0xffffffff),
0986             &(hba->u.mvfrey.mu->outbound_shadow_base));
0987     writel(cpu_to_le32((hba->u.mvfrey.outlist_cptr_phy >> 16) >> 16),
0988             &(hba->u.mvfrey.mu->outbound_shadow_base_high));
0989 
0990     hba->u.mvfrey.inlist_wptr = (list_count - 1) | CL_POINTER_TOGGLE;
0991     *hba->u.mvfrey.outlist_cptr = (list_count - 1) | CL_POINTER_TOGGLE;
0992     hba->u.mvfrey.outlist_rptr = list_count - 1;
0993     return 0;
0994 }
0995 
0996 static int hptiop_queuecommand_lck(struct scsi_cmnd *scp)
0997 {
0998     struct Scsi_Host *host = scp->device->host;
0999     struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
1000     struct hpt_iop_request_scsi_command *req;
1001     int sg_count = 0;
1002     struct hptiop_request *_req;
1003 
1004     _req = get_req(hba);
1005     if (_req == NULL) {
1006         dprintk("hptiop_queuecmd : no free req\n");
1007         return SCSI_MLQUEUE_HOST_BUSY;
1008     }
1009 
1010     _req->scp = scp;
1011 
1012     dprintk("hptiop_queuecmd(scp=%p) %d/%d/%d/%llu cdb=(%08x-%08x-%08x-%08x) "
1013             "req_index=%d, req=%p\n",
1014             scp,
1015             host->host_no, scp->device->channel,
1016             scp->device->id, scp->device->lun,
1017             cpu_to_be32(((u32 *)scp->cmnd)[0]),
1018             cpu_to_be32(((u32 *)scp->cmnd)[1]),
1019             cpu_to_be32(((u32 *)scp->cmnd)[2]),
1020             cpu_to_be32(((u32 *)scp->cmnd)[3]),
1021             _req->index, _req->req_virt);
1022 
1023     scp->result = 0;
1024 
1025     if (scp->device->channel ||
1026             (scp->device->id > hba->max_devices) ||
1027             ((scp->device->id == (hba->max_devices-1)) && scp->device->lun)) {
1028         scp->result = DID_BAD_TARGET << 16;
1029         free_req(hba, _req);
1030         goto cmd_done;
1031     }
1032 
1033     req = _req->req_virt;
1034 
1035     /* build S/G table */
1036     sg_count = hptiop_buildsgl(scp, req->sg_list);
1037     if (!sg_count)
1038         HPT_SCP(scp)->mapped = 0;
1039 
1040     req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
1041     req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND);
1042     req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
1043     req->dataxfer_length = cpu_to_le32(scsi_bufflen(scp));
1044     req->channel = scp->device->channel;
1045     req->target = scp->device->id;
1046     req->lun = scp->device->lun;
1047     req->header.size = cpu_to_le32(
1048                 sizeof(struct hpt_iop_request_scsi_command)
1049                  - sizeof(struct hpt_iopsg)
1050                  + sg_count * sizeof(struct hpt_iopsg));
1051 
1052     memcpy(req->cdb, scp->cmnd, sizeof(req->cdb));
1053     hba->ops->post_req(hba, _req);
1054     return 0;
1055 
1056 cmd_done:
1057     dprintk("scsi_done(scp=%p)\n", scp);
1058     scsi_done(scp);
1059     return 0;
1060 }
1061 
1062 static DEF_SCSI_QCMD(hptiop_queuecommand)
1063 
1064 static const char *hptiop_info(struct Scsi_Host *host)
1065 {
1066     return driver_name_long;
1067 }
1068 
1069 static int hptiop_reset_hba(struct hptiop_hba *hba)
1070 {
1071     if (atomic_xchg(&hba->resetting, 1) == 0) {
1072         atomic_inc(&hba->reset_count);
1073         hba->ops->post_msg(hba, IOPMU_INBOUND_MSG0_RESET);
1074     }
1075 
1076     wait_event_timeout(hba->reset_wq,
1077             atomic_read(&hba->resetting) == 0, 60 * HZ);
1078 
1079     if (atomic_read(&hba->resetting)) {
1080         /* IOP is in unknown state, abort reset */
1081         printk(KERN_ERR "scsi%d: reset failed\n", hba->host->host_no);
1082         return -1;
1083     }
1084 
1085     if (iop_send_sync_msg(hba,
1086         IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
1087         dprintk("scsi%d: fail to start background task\n",
1088                 hba->host->host_no);
1089     }
1090 
1091     return 0;
1092 }
1093 
1094 static int hptiop_reset(struct scsi_cmnd *scp)
1095 {
1096     struct hptiop_hba * hba = (struct hptiop_hba *)scp->device->host->hostdata;
1097 
1098     printk(KERN_WARNING "hptiop_reset(%d/%d/%d)\n",
1099            scp->device->host->host_no, -1, -1);
1100 
1101     return hptiop_reset_hba(hba)? FAILED : SUCCESS;
1102 }
1103 
1104 static int hptiop_adjust_disk_queue_depth(struct scsi_device *sdev,
1105                       int queue_depth)
1106 {
1107     struct hptiop_hba *hba = (struct hptiop_hba *)sdev->host->hostdata;
1108 
1109     if (queue_depth > hba->max_requests)
1110         queue_depth = hba->max_requests;
1111     return scsi_change_queue_depth(sdev, queue_depth);
1112 }
1113 
1114 static ssize_t hptiop_show_version(struct device *dev,
1115                    struct device_attribute *attr, char *buf)
1116 {
1117     return snprintf(buf, PAGE_SIZE, "%s\n", driver_ver);
1118 }
1119 
1120 static ssize_t hptiop_show_fw_version(struct device *dev,
1121                       struct device_attribute *attr, char *buf)
1122 {
1123     struct Scsi_Host *host = class_to_shost(dev);
1124     struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
1125 
1126     return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
1127                 hba->firmware_version >> 24,
1128                 (hba->firmware_version >> 16) & 0xff,
1129                 (hba->firmware_version >> 8) & 0xff,
1130                 hba->firmware_version & 0xff);
1131 }
1132 
1133 static struct device_attribute hptiop_attr_version = {
1134     .attr = {
1135         .name = "driver-version",
1136         .mode = S_IRUGO,
1137     },
1138     .show = hptiop_show_version,
1139 };
1140 
1141 static struct device_attribute hptiop_attr_fw_version = {
1142     .attr = {
1143         .name = "firmware-version",
1144         .mode = S_IRUGO,
1145     },
1146     .show = hptiop_show_fw_version,
1147 };
1148 
1149 static struct attribute *hptiop_host_attrs[] = {
1150     &hptiop_attr_version.attr,
1151     &hptiop_attr_fw_version.attr,
1152     NULL
1153 };
1154 
1155 ATTRIBUTE_GROUPS(hptiop_host);
1156 
1157 static int hptiop_slave_config(struct scsi_device *sdev)
1158 {
1159     if (sdev->type == TYPE_TAPE)
1160         blk_queue_max_hw_sectors(sdev->request_queue, 8192);
1161 
1162     return 0;
1163 }
1164 
1165 static struct scsi_host_template driver_template = {
1166     .module                     = THIS_MODULE,
1167     .name                       = driver_name,
1168     .queuecommand               = hptiop_queuecommand,
1169     .eh_host_reset_handler      = hptiop_reset,
1170     .info                       = hptiop_info,
1171     .emulated                   = 0,
1172     .proc_name                  = driver_name,
1173     .shost_groups           = hptiop_host_groups,
1174     .slave_configure            = hptiop_slave_config,
1175     .this_id                    = -1,
1176     .change_queue_depth         = hptiop_adjust_disk_queue_depth,
1177     .cmd_size           = sizeof(struct hpt_cmd_priv),
1178 };
1179 
1180 static int hptiop_internal_memalloc_itl(struct hptiop_hba *hba)
1181 {
1182     return 0;
1183 }
1184 
1185 static int hptiop_internal_memalloc_mv(struct hptiop_hba *hba)
1186 {
1187     hba->u.mv.internal_req = dma_alloc_coherent(&hba->pcidev->dev,
1188             0x800, &hba->u.mv.internal_req_phy, GFP_KERNEL);
1189     if (hba->u.mv.internal_req)
1190         return 0;
1191     else
1192         return -1;
1193 }
1194 
1195 static int hptiop_internal_memalloc_mvfrey(struct hptiop_hba *hba)
1196 {
1197     u32 list_count = readl(&hba->u.mvfrey.mu->inbound_conf_ctl);
1198     char *p;
1199     dma_addr_t phy;
1200 
1201     BUG_ON(hba->max_request_size == 0);
1202 
1203     if (list_count == 0) {
1204         BUG_ON(1);
1205         return -1;
1206     }
1207 
1208     list_count >>= 16;
1209 
1210     hba->u.mvfrey.list_count = list_count;
1211     hba->u.mvfrey.internal_mem_size = 0x800 +
1212             list_count * sizeof(struct mvfrey_inlist_entry) +
1213             list_count * sizeof(struct mvfrey_outlist_entry) +
1214             sizeof(int);
1215 
1216     p = dma_alloc_coherent(&hba->pcidev->dev,
1217             hba->u.mvfrey.internal_mem_size, &phy, GFP_KERNEL);
1218     if (!p)
1219         return -1;
1220 
1221     hba->u.mvfrey.internal_req.req_virt = p;
1222     hba->u.mvfrey.internal_req.req_shifted_phy = phy >> 5;
1223     hba->u.mvfrey.internal_req.scp = NULL;
1224     hba->u.mvfrey.internal_req.next = NULL;
1225 
1226     p += 0x800;
1227     phy += 0x800;
1228 
1229     hba->u.mvfrey.inlist = (struct mvfrey_inlist_entry *)p;
1230     hba->u.mvfrey.inlist_phy = phy;
1231 
1232     p += list_count * sizeof(struct mvfrey_inlist_entry);
1233     phy += list_count * sizeof(struct mvfrey_inlist_entry);
1234 
1235     hba->u.mvfrey.outlist = (struct mvfrey_outlist_entry *)p;
1236     hba->u.mvfrey.outlist_phy = phy;
1237 
1238     p += list_count * sizeof(struct mvfrey_outlist_entry);
1239     phy += list_count * sizeof(struct mvfrey_outlist_entry);
1240 
1241     hba->u.mvfrey.outlist_cptr = (__le32 *)p;
1242     hba->u.mvfrey.outlist_cptr_phy = phy;
1243 
1244     return 0;
1245 }
1246 
1247 static int hptiop_internal_memfree_itl(struct hptiop_hba *hba)
1248 {
1249     return 0;
1250 }
1251 
1252 static int hptiop_internal_memfree_mv(struct hptiop_hba *hba)
1253 {
1254     if (hba->u.mv.internal_req) {
1255         dma_free_coherent(&hba->pcidev->dev, 0x800,
1256             hba->u.mv.internal_req, hba->u.mv.internal_req_phy);
1257         return 0;
1258     } else
1259         return -1;
1260 }
1261 
1262 static int hptiop_internal_memfree_mvfrey(struct hptiop_hba *hba)
1263 {
1264     if (hba->u.mvfrey.internal_req.req_virt) {
1265         dma_free_coherent(&hba->pcidev->dev,
1266             hba->u.mvfrey.internal_mem_size,
1267             hba->u.mvfrey.internal_req.req_virt,
1268             (dma_addr_t)
1269             hba->u.mvfrey.internal_req.req_shifted_phy << 5);
1270         return 0;
1271     } else
1272         return -1;
1273 }
1274 
1275 static int hptiop_probe(struct pci_dev *pcidev, const struct pci_device_id *id)
1276 {
1277     struct Scsi_Host *host = NULL;
1278     struct hptiop_hba *hba;
1279     struct hptiop_adapter_ops *iop_ops;
1280     struct hpt_iop_request_get_config iop_config;
1281     struct hpt_iop_request_set_config set_config;
1282     dma_addr_t start_phy;
1283     void *start_virt;
1284     u32 offset, i, req_size;
1285     int rc;
1286 
1287     dprintk("hptiop_probe(%p)\n", pcidev);
1288 
1289     if (pci_enable_device(pcidev)) {
1290         printk(KERN_ERR "hptiop: fail to enable pci device\n");
1291         return -ENODEV;
1292     }
1293 
1294     printk(KERN_INFO "adapter at PCI %d:%d:%d, IRQ %d\n",
1295         pcidev->bus->number, pcidev->devfn >> 3, pcidev->devfn & 7,
1296         pcidev->irq);
1297 
1298     pci_set_master(pcidev);
1299 
1300     /* Enable 64bit DMA if possible */
1301     iop_ops = (struct hptiop_adapter_ops *)id->driver_data;
1302     rc = dma_set_mask(&pcidev->dev,
1303               DMA_BIT_MASK(iop_ops->hw_dma_bit_mask));
1304     if (rc)
1305         rc = dma_set_mask(&pcidev->dev, DMA_BIT_MASK(32));
1306 
1307     if (rc) {
1308         printk(KERN_ERR "hptiop: fail to set dma_mask\n");
1309         goto disable_pci_device;
1310     }
1311 
1312     if (pci_request_regions(pcidev, driver_name)) {
1313         printk(KERN_ERR "hptiop: pci_request_regions failed\n");
1314         goto disable_pci_device;
1315     }
1316 
1317     host = scsi_host_alloc(&driver_template, sizeof(struct hptiop_hba));
1318     if (!host) {
1319         printk(KERN_ERR "hptiop: fail to alloc scsi host\n");
1320         goto free_pci_regions;
1321     }
1322 
1323     hba = (struct hptiop_hba *)host->hostdata;
1324     memset(hba, 0, sizeof(struct hptiop_hba));
1325 
1326     hba->ops = iop_ops;
1327     hba->pcidev = pcidev;
1328     hba->host = host;
1329     hba->initialized = 0;
1330     hba->iopintf_v2 = 0;
1331 
1332     atomic_set(&hba->resetting, 0);
1333     atomic_set(&hba->reset_count, 0);
1334 
1335     init_waitqueue_head(&hba->reset_wq);
1336     init_waitqueue_head(&hba->ioctl_wq);
1337 
1338     host->max_lun = 128;
1339     host->max_channel = 0;
1340     host->io_port = 0;
1341     host->n_io_port = 0;
1342     host->irq = pcidev->irq;
1343 
1344     if (hba->ops->map_pci_bar(hba))
1345         goto free_scsi_host;
1346 
1347     if (hba->ops->iop_wait_ready(hba, 20000)) {
1348         printk(KERN_ERR "scsi%d: firmware not ready\n",
1349                 hba->host->host_no);
1350         goto unmap_pci_bar;
1351     }
1352 
1353     if (hba->ops->family == MV_BASED_IOP) {
1354         if (hba->ops->internal_memalloc(hba)) {
1355             printk(KERN_ERR "scsi%d: internal_memalloc failed\n",
1356                 hba->host->host_no);
1357             goto unmap_pci_bar;
1358         }
1359     }
1360 
1361     if (hba->ops->get_config(hba, &iop_config)) {
1362         printk(KERN_ERR "scsi%d: get config failed\n",
1363                 hba->host->host_no);
1364         goto unmap_pci_bar;
1365     }
1366 
1367     hba->max_requests = min(le32_to_cpu(iop_config.max_requests),
1368                 HPTIOP_MAX_REQUESTS);
1369     hba->max_devices = le32_to_cpu(iop_config.max_devices);
1370     hba->max_request_size = le32_to_cpu(iop_config.request_size);
1371     hba->max_sg_descriptors = le32_to_cpu(iop_config.max_sg_count);
1372     hba->firmware_version = le32_to_cpu(iop_config.firmware_version);
1373     hba->interface_version = le32_to_cpu(iop_config.interface_version);
1374     hba->sdram_size = le32_to_cpu(iop_config.sdram_size);
1375 
1376     if (hba->ops->family == MVFREY_BASED_IOP) {
1377         if (hba->ops->internal_memalloc(hba)) {
1378             printk(KERN_ERR "scsi%d: internal_memalloc failed\n",
1379                 hba->host->host_no);
1380             goto unmap_pci_bar;
1381         }
1382         if (hba->ops->reset_comm(hba)) {
1383             printk(KERN_ERR "scsi%d: reset comm failed\n",
1384                     hba->host->host_no);
1385             goto unmap_pci_bar;
1386         }
1387     }
1388 
1389     if (hba->firmware_version > 0x01020000 ||
1390             hba->interface_version > 0x01020000)
1391         hba->iopintf_v2 = 1;
1392 
1393     host->max_sectors = le32_to_cpu(iop_config.data_transfer_length) >> 9;
1394     host->max_id = le32_to_cpu(iop_config.max_devices);
1395     host->sg_tablesize = le32_to_cpu(iop_config.max_sg_count);
1396     host->can_queue = le32_to_cpu(iop_config.max_requests);
1397     host->cmd_per_lun = le32_to_cpu(iop_config.max_requests);
1398     host->max_cmd_len = 16;
1399 
1400     req_size = sizeof(struct hpt_iop_request_scsi_command)
1401         + sizeof(struct hpt_iopsg) * (hba->max_sg_descriptors - 1);
1402     if ((req_size & 0x1f) != 0)
1403         req_size = (req_size + 0x1f) & ~0x1f;
1404 
1405     memset(&set_config, 0, sizeof(struct hpt_iop_request_set_config));
1406     set_config.iop_id = cpu_to_le32(host->host_no);
1407     set_config.vbus_id = cpu_to_le16(host->host_no);
1408     set_config.max_host_request_size = cpu_to_le16(req_size);
1409 
1410     if (hba->ops->set_config(hba, &set_config)) {
1411         printk(KERN_ERR "scsi%d: set config failed\n",
1412                 hba->host->host_no);
1413         goto unmap_pci_bar;
1414     }
1415 
1416     pci_set_drvdata(pcidev, host);
1417 
1418     if (request_irq(pcidev->irq, hptiop_intr, IRQF_SHARED,
1419                     driver_name, hba)) {
1420         printk(KERN_ERR "scsi%d: request irq %d failed\n",
1421                     hba->host->host_no, pcidev->irq);
1422         goto unmap_pci_bar;
1423     }
1424 
1425     /* Allocate request mem */
1426 
1427     dprintk("req_size=%d, max_requests=%d\n", req_size, hba->max_requests);
1428 
1429     hba->req_size = req_size;
1430     hba->req_list = NULL;
1431 
1432     for (i = 0; i < hba->max_requests; i++) {
1433         start_virt = dma_alloc_coherent(&pcidev->dev,
1434                     hba->req_size + 0x20,
1435                     &start_phy, GFP_KERNEL);
1436 
1437         if (!start_virt) {
1438             printk(KERN_ERR "scsi%d: fail to alloc request mem\n",
1439                         hba->host->host_no);
1440             goto free_request_mem;
1441         }
1442 
1443         hba->dma_coherent[i] = start_virt;
1444         hba->dma_coherent_handle[i] = start_phy;
1445 
1446         if ((start_phy & 0x1f) != 0) {
1447             offset = ((start_phy + 0x1f) & ~0x1f) - start_phy;
1448             start_phy += offset;
1449             start_virt += offset;
1450         }
1451 
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     }
1458 
1459     /* Enable Interrupt and start background task */
1460     if (hptiop_initialize_iop(hba))
1461         goto free_request_mem;
1462 
1463     if (scsi_add_host(host, &pcidev->dev)) {
1464         printk(KERN_ERR "scsi%d: scsi_add_host failed\n",
1465                     hba->host->host_no);
1466         goto free_request_mem;
1467     }
1468 
1469     scsi_scan_host(host);
1470 
1471     dprintk("scsi%d: hptiop_probe successfully\n", hba->host->host_no);
1472     return 0;
1473 
1474 free_request_mem:
1475     for (i = 0; i < hba->max_requests; i++) {
1476         if (hba->dma_coherent[i] && hba->dma_coherent_handle[i])
1477             dma_free_coherent(&hba->pcidev->dev,
1478                     hba->req_size + 0x20,
1479                     hba->dma_coherent[i],
1480                     hba->dma_coherent_handle[i]);
1481         else
1482             break;
1483     }
1484 
1485     free_irq(hba->pcidev->irq, hba);
1486 
1487 unmap_pci_bar:
1488     hba->ops->internal_memfree(hba);
1489 
1490     hba->ops->unmap_pci_bar(hba);
1491 
1492 free_scsi_host:
1493     scsi_host_put(host);
1494 
1495 free_pci_regions:
1496     pci_release_regions(pcidev);
1497 
1498 disable_pci_device:
1499     pci_disable_device(pcidev);
1500 
1501     dprintk("scsi%d: hptiop_probe fail\n", host ? host->host_no : 0);
1502     return -ENODEV;
1503 }
1504 
1505 static void hptiop_shutdown(struct pci_dev *pcidev)
1506 {
1507     struct Scsi_Host *host = pci_get_drvdata(pcidev);
1508     struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
1509 
1510     dprintk("hptiop_shutdown(%p)\n", hba);
1511 
1512     /* stop the iop */
1513     if (iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_SHUTDOWN, 60000))
1514         printk(KERN_ERR "scsi%d: shutdown the iop timeout\n",
1515                     hba->host->host_no);
1516 
1517     /* disable all outbound interrupts */
1518     hba->ops->disable_intr(hba);
1519 }
1520 
1521 static void hptiop_disable_intr_itl(struct hptiop_hba *hba)
1522 {
1523     u32 int_mask;
1524 
1525     int_mask = readl(&hba->u.itl.iop->outbound_intmask);
1526     writel(int_mask |
1527         IOPMU_OUTBOUND_INT_MSG0 | IOPMU_OUTBOUND_INT_POSTQUEUE,
1528         &hba->u.itl.iop->outbound_intmask);
1529     readl(&hba->u.itl.iop->outbound_intmask);
1530 }
1531 
1532 static void hptiop_disable_intr_mv(struct hptiop_hba *hba)
1533 {
1534     writel(0, &hba->u.mv.regs->outbound_intmask);
1535     readl(&hba->u.mv.regs->outbound_intmask);
1536 }
1537 
1538 static void hptiop_disable_intr_mvfrey(struct hptiop_hba *hba)
1539 {
1540     writel(0, &(hba->u.mvfrey.mu->f0_doorbell_enable));
1541     readl(&(hba->u.mvfrey.mu->f0_doorbell_enable));
1542     writel(0, &(hba->u.mvfrey.mu->isr_enable));
1543     readl(&(hba->u.mvfrey.mu->isr_enable));
1544     writel(0, &(hba->u.mvfrey.mu->pcie_f0_int_enable));
1545     readl(&(hba->u.mvfrey.mu->pcie_f0_int_enable));
1546 }
1547 
1548 static void hptiop_remove(struct pci_dev *pcidev)
1549 {
1550     struct Scsi_Host *host = pci_get_drvdata(pcidev);
1551     struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
1552     u32 i;
1553 
1554     dprintk("scsi%d: hptiop_remove\n", hba->host->host_no);
1555 
1556     scsi_remove_host(host);
1557 
1558     hptiop_shutdown(pcidev);
1559 
1560     free_irq(hba->pcidev->irq, hba);
1561 
1562     for (i = 0; i < hba->max_requests; i++) {
1563         if (hba->dma_coherent[i] && hba->dma_coherent_handle[i])
1564             dma_free_coherent(&hba->pcidev->dev,
1565                     hba->req_size + 0x20,
1566                     hba->dma_coherent[i],
1567                     hba->dma_coherent_handle[i]);
1568         else
1569             break;
1570     }
1571 
1572     hba->ops->internal_memfree(hba);
1573 
1574     hba->ops->unmap_pci_bar(hba);
1575 
1576     pci_release_regions(hba->pcidev);
1577     pci_set_drvdata(hba->pcidev, NULL);
1578     pci_disable_device(hba->pcidev);
1579 
1580     scsi_host_put(host);
1581 }
1582 
1583 static struct hptiop_adapter_ops hptiop_itl_ops = {
1584     .family            = INTEL_BASED_IOP,
1585     .iop_wait_ready    = iop_wait_ready_itl,
1586     .internal_memalloc = hptiop_internal_memalloc_itl,
1587     .internal_memfree  = hptiop_internal_memfree_itl,
1588     .map_pci_bar       = hptiop_map_pci_bar_itl,
1589     .unmap_pci_bar     = hptiop_unmap_pci_bar_itl,
1590     .enable_intr       = hptiop_enable_intr_itl,
1591     .disable_intr      = hptiop_disable_intr_itl,
1592     .get_config        = iop_get_config_itl,
1593     .set_config        = iop_set_config_itl,
1594     .iop_intr          = iop_intr_itl,
1595     .post_msg          = hptiop_post_msg_itl,
1596     .post_req          = hptiop_post_req_itl,
1597     .hw_dma_bit_mask   = 64,
1598     .reset_comm        = hptiop_reset_comm_itl,
1599     .host_phy_flag     = cpu_to_le64(0),
1600 };
1601 
1602 static struct hptiop_adapter_ops hptiop_mv_ops = {
1603     .family            = MV_BASED_IOP,
1604     .iop_wait_ready    = iop_wait_ready_mv,
1605     .internal_memalloc = hptiop_internal_memalloc_mv,
1606     .internal_memfree  = hptiop_internal_memfree_mv,
1607     .map_pci_bar       = hptiop_map_pci_bar_mv,
1608     .unmap_pci_bar     = hptiop_unmap_pci_bar_mv,
1609     .enable_intr       = hptiop_enable_intr_mv,
1610     .disable_intr      = hptiop_disable_intr_mv,
1611     .get_config        = iop_get_config_mv,
1612     .set_config        = iop_set_config_mv,
1613     .iop_intr          = iop_intr_mv,
1614     .post_msg          = hptiop_post_msg_mv,
1615     .post_req          = hptiop_post_req_mv,
1616     .hw_dma_bit_mask   = 33,
1617     .reset_comm        = hptiop_reset_comm_mv,
1618     .host_phy_flag     = cpu_to_le64(0),
1619 };
1620 
1621 static struct hptiop_adapter_ops hptiop_mvfrey_ops = {
1622     .family            = MVFREY_BASED_IOP,
1623     .iop_wait_ready    = iop_wait_ready_mvfrey,
1624     .internal_memalloc = hptiop_internal_memalloc_mvfrey,
1625     .internal_memfree  = hptiop_internal_memfree_mvfrey,
1626     .map_pci_bar       = hptiop_map_pci_bar_mvfrey,
1627     .unmap_pci_bar     = hptiop_unmap_pci_bar_mvfrey,
1628     .enable_intr       = hptiop_enable_intr_mvfrey,
1629     .disable_intr      = hptiop_disable_intr_mvfrey,
1630     .get_config        = iop_get_config_mvfrey,
1631     .set_config        = iop_set_config_mvfrey,
1632     .iop_intr          = iop_intr_mvfrey,
1633     .post_msg          = hptiop_post_msg_mvfrey,
1634     .post_req          = hptiop_post_req_mvfrey,
1635     .hw_dma_bit_mask   = 64,
1636     .reset_comm        = hptiop_reset_comm_mvfrey,
1637     .host_phy_flag     = cpu_to_le64(1),
1638 };
1639 
1640 static struct pci_device_id hptiop_id_table[] = {
1641     { PCI_VDEVICE(TTI, 0x3220), (kernel_ulong_t)&hptiop_itl_ops },
1642     { PCI_VDEVICE(TTI, 0x3320), (kernel_ulong_t)&hptiop_itl_ops },
1643     { PCI_VDEVICE(TTI, 0x3410), (kernel_ulong_t)&hptiop_itl_ops },
1644     { PCI_VDEVICE(TTI, 0x3510), (kernel_ulong_t)&hptiop_itl_ops },
1645     { PCI_VDEVICE(TTI, 0x3511), (kernel_ulong_t)&hptiop_itl_ops },
1646     { PCI_VDEVICE(TTI, 0x3520), (kernel_ulong_t)&hptiop_itl_ops },
1647     { PCI_VDEVICE(TTI, 0x3521), (kernel_ulong_t)&hptiop_itl_ops },
1648     { PCI_VDEVICE(TTI, 0x3522), (kernel_ulong_t)&hptiop_itl_ops },
1649     { PCI_VDEVICE(TTI, 0x3530), (kernel_ulong_t)&hptiop_itl_ops },
1650     { PCI_VDEVICE(TTI, 0x3540), (kernel_ulong_t)&hptiop_itl_ops },
1651     { PCI_VDEVICE(TTI, 0x3560), (kernel_ulong_t)&hptiop_itl_ops },
1652     { PCI_VDEVICE(TTI, 0x4210), (kernel_ulong_t)&hptiop_itl_ops },
1653     { PCI_VDEVICE(TTI, 0x4211), (kernel_ulong_t)&hptiop_itl_ops },
1654     { PCI_VDEVICE(TTI, 0x4310), (kernel_ulong_t)&hptiop_itl_ops },
1655     { PCI_VDEVICE(TTI, 0x4311), (kernel_ulong_t)&hptiop_itl_ops },
1656     { PCI_VDEVICE(TTI, 0x4320), (kernel_ulong_t)&hptiop_itl_ops },
1657     { PCI_VDEVICE(TTI, 0x4321), (kernel_ulong_t)&hptiop_itl_ops },
1658     { PCI_VDEVICE(TTI, 0x4322), (kernel_ulong_t)&hptiop_itl_ops },
1659     { PCI_VDEVICE(TTI, 0x4400), (kernel_ulong_t)&hptiop_itl_ops },
1660     { PCI_VDEVICE(TTI, 0x3120), (kernel_ulong_t)&hptiop_mv_ops },
1661     { PCI_VDEVICE(TTI, 0x3122), (kernel_ulong_t)&hptiop_mv_ops },
1662     { PCI_VDEVICE(TTI, 0x3020), (kernel_ulong_t)&hptiop_mv_ops },
1663     { PCI_VDEVICE(TTI, 0x4520), (kernel_ulong_t)&hptiop_mvfrey_ops },
1664     { PCI_VDEVICE(TTI, 0x4522), (kernel_ulong_t)&hptiop_mvfrey_ops },
1665     { PCI_VDEVICE(TTI, 0x3610), (kernel_ulong_t)&hptiop_mvfrey_ops },
1666     { PCI_VDEVICE(TTI, 0x3611), (kernel_ulong_t)&hptiop_mvfrey_ops },
1667     { PCI_VDEVICE(TTI, 0x3620), (kernel_ulong_t)&hptiop_mvfrey_ops },
1668     { PCI_VDEVICE(TTI, 0x3622), (kernel_ulong_t)&hptiop_mvfrey_ops },
1669     { PCI_VDEVICE(TTI, 0x3640), (kernel_ulong_t)&hptiop_mvfrey_ops },
1670     { PCI_VDEVICE(TTI, 0x3660), (kernel_ulong_t)&hptiop_mvfrey_ops },
1671     { PCI_VDEVICE(TTI, 0x3680), (kernel_ulong_t)&hptiop_mvfrey_ops },
1672     { PCI_VDEVICE(TTI, 0x3690), (kernel_ulong_t)&hptiop_mvfrey_ops },
1673     {},
1674 };
1675 
1676 MODULE_DEVICE_TABLE(pci, hptiop_id_table);
1677 
1678 static struct pci_driver hptiop_pci_driver = {
1679     .name       = driver_name,
1680     .id_table   = hptiop_id_table,
1681     .probe      = hptiop_probe,
1682     .remove     = hptiop_remove,
1683     .shutdown   = hptiop_shutdown,
1684 };
1685 
1686 static int __init hptiop_module_init(void)
1687 {
1688     printk(KERN_INFO "%s %s\n", driver_name_long, driver_ver);
1689     return pci_register_driver(&hptiop_pci_driver);
1690 }
1691 
1692 static void __exit hptiop_module_exit(void)
1693 {
1694     pci_unregister_driver(&hptiop_pci_driver);
1695 }
1696 
1697 
1698 module_init(hptiop_module_init);
1699 module_exit(hptiop_module_exit);
1700 
1701 MODULE_LICENSE("GPL");
1702