]> err.no Git - linux-2.6/blob - drivers/scsi/hptiop.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6
[linux-2.6] / drivers / scsi / hptiop.c
1 /*
2  * HighPoint RR3xxx/4xxx controller driver for Linux
3  * Copyright (C) 2006-2007 HighPoint Technologies, Inc. All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; version 2 of the License.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * Please report bugs/comments/suggestions to linux@highpoint-tech.com
15  *
16  * For more information, visit http://www.highpoint-tech.com
17  */
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/string.h>
21 #include <linux/kernel.h>
22 #include <linux/pci.h>
23 #include <linux/interrupt.h>
24 #include <linux/errno.h>
25 #include <linux/delay.h>
26 #include <linux/timer.h>
27 #include <linux/spinlock.h>
28 #include <linux/hdreg.h>
29 #include <asm/uaccess.h>
30 #include <asm/io.h>
31 #include <asm/div64.h>
32 #include <scsi/scsi_cmnd.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi.h>
35 #include <scsi/scsi_tcq.h>
36 #include <scsi/scsi_host.h>
37
38 #include "hptiop.h"
39
40 MODULE_AUTHOR("HighPoint Technologies, Inc.");
41 MODULE_DESCRIPTION("HighPoint RocketRAID 3xxx/4xxx Controller Driver");
42
43 static char driver_name[] = "hptiop";
44 static const char driver_name_long[] = "RocketRAID 3xxx/4xxx Controller driver";
45 static const char driver_ver[] = "v1.3 (071203)";
46
47 static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec);
48 static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
49                                 struct hpt_iop_request_scsi_command *req);
50 static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 tag);
51 static void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag);
52 static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg);
53
54 static int iop_wait_ready_itl(struct hptiop_hba *hba, u32 millisec)
55 {
56         u32 req = 0;
57         int i;
58
59         for (i = 0; i < millisec; i++) {
60                 req = readl(&hba->u.itl.iop->inbound_queue);
61                 if (req != IOPMU_QUEUE_EMPTY)
62                         break;
63                 msleep(1);
64         }
65
66         if (req != IOPMU_QUEUE_EMPTY) {
67                 writel(req, &hba->u.itl.iop->outbound_queue);
68                 readl(&hba->u.itl.iop->outbound_intstatus);
69                 return 0;
70         }
71
72         return -1;
73 }
74
75 static int iop_wait_ready_mv(struct hptiop_hba *hba, u32 millisec)
76 {
77         return iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_NOP, millisec);
78 }
79
80 static void hptiop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
81 {
82         if (tag & IOPMU_QUEUE_ADDR_HOST_BIT)
83                 hptiop_host_request_callback_itl(hba,
84                                 tag & ~IOPMU_QUEUE_ADDR_HOST_BIT);
85         else
86                 hptiop_iop_request_callback_itl(hba, tag);
87 }
88
89 static void hptiop_drain_outbound_queue_itl(struct hptiop_hba *hba)
90 {
91         u32 req;
92
93         while ((req = readl(&hba->u.itl.iop->outbound_queue)) !=
94                                                 IOPMU_QUEUE_EMPTY) {
95
96                 if (req & IOPMU_QUEUE_MASK_HOST_BITS)
97                         hptiop_request_callback_itl(hba, req);
98                 else {
99                         struct hpt_iop_request_header __iomem * p;
100
101                         p = (struct hpt_iop_request_header __iomem *)
102                                 ((char __iomem *)hba->u.itl.iop + req);
103
104                         if (readl(&p->flags) & IOP_REQUEST_FLAG_SYNC_REQUEST) {
105                                 if (readl(&p->context))
106                                         hptiop_request_callback_itl(hba, req);
107                                 else
108                                         writel(1, &p->context);
109                         }
110                         else
111                                 hptiop_request_callback_itl(hba, req);
112                 }
113         }
114 }
115
116 static int iop_intr_itl(struct hptiop_hba *hba)
117 {
118         struct hpt_iopmu_itl __iomem *iop = hba->u.itl.iop;
119         u32 status;
120         int ret = 0;
121
122         status = readl(&iop->outbound_intstatus);
123
124         if (status & IOPMU_OUTBOUND_INT_MSG0) {
125                 u32 msg = readl(&iop->outbound_msgaddr0);
126
127                 dprintk("received outbound msg %x\n", msg);
128                 writel(IOPMU_OUTBOUND_INT_MSG0, &iop->outbound_intstatus);
129                 hptiop_message_callback(hba, msg);
130                 ret = 1;
131         }
132
133         if (status & IOPMU_OUTBOUND_INT_POSTQUEUE) {
134                 hptiop_drain_outbound_queue_itl(hba);
135                 ret = 1;
136         }
137
138         return ret;
139 }
140
141 static u64 mv_outbound_read(struct hpt_iopmu_mv __iomem *mu)
142 {
143         u32 outbound_tail = readl(&mu->outbound_tail);
144         u32 outbound_head = readl(&mu->outbound_head);
145
146         if (outbound_tail != outbound_head) {
147                 u64 p;
148
149                 memcpy_fromio(&p, &mu->outbound_q[mu->outbound_tail], 8);
150                 outbound_tail++;
151
152                 if (outbound_tail == MVIOP_QUEUE_LEN)
153                         outbound_tail = 0;
154                 writel(outbound_tail, &mu->outbound_tail);
155                 return p;
156         } else
157                 return 0;
158 }
159
160 static void mv_inbound_write(u64 p, struct hptiop_hba *hba)
161 {
162         u32 inbound_head = readl(&hba->u.mv.mu->inbound_head);
163         u32 head = inbound_head + 1;
164
165         if (head == MVIOP_QUEUE_LEN)
166                 head = 0;
167
168         memcpy_toio(&hba->u.mv.mu->inbound_q[inbound_head], &p, 8);
169         writel(head, &hba->u.mv.mu->inbound_head);
170         writel(MVIOP_MU_INBOUND_INT_POSTQUEUE,
171                         &hba->u.mv.regs->inbound_doorbell);
172 }
173
174 static void hptiop_request_callback_mv(struct hptiop_hba *hba, u64 tag)
175 {
176         u32 req_type = (tag >> 5) & 0x7;
177         struct hpt_iop_request_scsi_command *req;
178
179         dprintk("hptiop_request_callback_mv: tag=%llx\n", tag);
180
181         BUG_ON((tag & MVIOP_MU_QUEUE_REQUEST_RETURN_CONTEXT) == 0);
182
183         switch (req_type) {
184         case IOP_REQUEST_TYPE_GET_CONFIG:
185         case IOP_REQUEST_TYPE_SET_CONFIG:
186                 hba->msg_done = 1;
187                 break;
188
189         case IOP_REQUEST_TYPE_SCSI_COMMAND:
190                 req = hba->reqs[tag >> 8].req_virt;
191                 if (likely(tag & MVIOP_MU_QUEUE_REQUEST_RESULT_BIT))
192                         req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
193
194                 hptiop_finish_scsi_req(hba, tag>>8, req);
195                 break;
196
197         default:
198                 break;
199         }
200 }
201
202 static int iop_intr_mv(struct hptiop_hba *hba)
203 {
204         u32 status;
205         int ret = 0;
206
207         status = readl(&hba->u.mv.regs->outbound_doorbell);
208         writel(~status, &hba->u.mv.regs->outbound_doorbell);
209
210         if (status & MVIOP_MU_OUTBOUND_INT_MSG) {
211                 u32 msg;
212                 msg = readl(&hba->u.mv.mu->outbound_msg);
213                 dprintk("received outbound msg %x\n", msg);
214                 hptiop_message_callback(hba, msg);
215                 ret = 1;
216         }
217
218         if (status & MVIOP_MU_OUTBOUND_INT_POSTQUEUE) {
219                 u64 tag;
220
221                 while ((tag = mv_outbound_read(hba->u.mv.mu)))
222                         hptiop_request_callback_mv(hba, tag);
223                 ret = 1;
224         }
225
226         return ret;
227 }
228
229 static int iop_send_sync_request_itl(struct hptiop_hba *hba,
230                                         void __iomem *_req, u32 millisec)
231 {
232         struct hpt_iop_request_header __iomem *req = _req;
233         u32 i;
234
235         writel(readl(&req->flags) | IOP_REQUEST_FLAG_SYNC_REQUEST, &req->flags);
236         writel(0, &req->context);
237         writel((unsigned long)req - (unsigned long)hba->u.itl.iop,
238                         &hba->u.itl.iop->inbound_queue);
239         readl(&hba->u.itl.iop->outbound_intstatus);
240
241         for (i = 0; i < millisec; i++) {
242                 iop_intr_itl(hba);
243                 if (readl(&req->context))
244                         return 0;
245                 msleep(1);
246         }
247
248         return -1;
249 }
250
251 static int iop_send_sync_request_mv(struct hptiop_hba *hba,
252                                         u32 size_bits, u32 millisec)
253 {
254         struct hpt_iop_request_header *reqhdr = hba->u.mv.internal_req;
255         u32 i;
256
257         hba->msg_done = 0;
258         reqhdr->flags |= cpu_to_le32(IOP_REQUEST_FLAG_SYNC_REQUEST);
259         mv_inbound_write(hba->u.mv.internal_req_phy |
260                         MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bits, hba);
261
262         for (i = 0; i < millisec; i++) {
263                 iop_intr_mv(hba);
264                 if (hba->msg_done)
265                         return 0;
266                 msleep(1);
267         }
268         return -1;
269 }
270
271 static void hptiop_post_msg_itl(struct hptiop_hba *hba, u32 msg)
272 {
273         writel(msg, &hba->u.itl.iop->inbound_msgaddr0);
274         readl(&hba->u.itl.iop->outbound_intstatus);
275 }
276
277 static void hptiop_post_msg_mv(struct hptiop_hba *hba, u32 msg)
278 {
279         writel(msg, &hba->u.mv.mu->inbound_msg);
280         writel(MVIOP_MU_INBOUND_INT_MSG, &hba->u.mv.regs->inbound_doorbell);
281         readl(&hba->u.mv.regs->inbound_doorbell);
282 }
283
284 static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec)
285 {
286         u32 i;
287
288         hba->msg_done = 0;
289         hba->ops->post_msg(hba, msg);
290
291         for (i = 0; i < millisec; i++) {
292                 spin_lock_irq(hba->host->host_lock);
293                 hba->ops->iop_intr(hba);
294                 spin_unlock_irq(hba->host->host_lock);
295                 if (hba->msg_done)
296                         break;
297                 msleep(1);
298         }
299
300         return hba->msg_done? 0 : -1;
301 }
302
303 static int iop_get_config_itl(struct hptiop_hba *hba,
304                                 struct hpt_iop_request_get_config *config)
305 {
306         u32 req32;
307         struct hpt_iop_request_get_config __iomem *req;
308
309         req32 = readl(&hba->u.itl.iop->inbound_queue);
310         if (req32 == IOPMU_QUEUE_EMPTY)
311                 return -1;
312
313         req = (struct hpt_iop_request_get_config __iomem *)
314                         ((unsigned long)hba->u.itl.iop + req32);
315
316         writel(0, &req->header.flags);
317         writel(IOP_REQUEST_TYPE_GET_CONFIG, &req->header.type);
318         writel(sizeof(struct hpt_iop_request_get_config), &req->header.size);
319         writel(IOP_RESULT_PENDING, &req->header.result);
320
321         if (iop_send_sync_request_itl(hba, req, 20000)) {
322                 dprintk("Get config send cmd failed\n");
323                 return -1;
324         }
325
326         memcpy_fromio(config, req, sizeof(*config));
327         writel(req32, &hba->u.itl.iop->outbound_queue);
328         return 0;
329 }
330
331 static int iop_get_config_mv(struct hptiop_hba *hba,
332                                 struct hpt_iop_request_get_config *config)
333 {
334         struct hpt_iop_request_get_config *req = hba->u.mv.internal_req;
335
336         req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
337         req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG);
338         req->header.size =
339                 cpu_to_le32(sizeof(struct hpt_iop_request_get_config));
340         req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
341         req->header.context = cpu_to_le64(IOP_REQUEST_TYPE_GET_CONFIG<<5);
342
343         if (iop_send_sync_request_mv(hba, 0, 20000)) {
344                 dprintk("Get config send cmd failed\n");
345                 return -1;
346         }
347
348         memcpy(config, req, sizeof(struct hpt_iop_request_get_config));
349         return 0;
350 }
351
352 static int iop_set_config_itl(struct hptiop_hba *hba,
353                                 struct hpt_iop_request_set_config *config)
354 {
355         u32 req32;
356         struct hpt_iop_request_set_config __iomem *req;
357
358         req32 = readl(&hba->u.itl.iop->inbound_queue);
359         if (req32 == IOPMU_QUEUE_EMPTY)
360                 return -1;
361
362         req = (struct hpt_iop_request_set_config __iomem *)
363                         ((unsigned long)hba->u.itl.iop + req32);
364
365         memcpy_toio((u8 __iomem *)req + sizeof(struct hpt_iop_request_header),
366                 (u8 *)config + sizeof(struct hpt_iop_request_header),
367                 sizeof(struct hpt_iop_request_set_config) -
368                         sizeof(struct hpt_iop_request_header));
369
370         writel(0, &req->header.flags);
371         writel(IOP_REQUEST_TYPE_SET_CONFIG, &req->header.type);
372         writel(sizeof(struct hpt_iop_request_set_config), &req->header.size);
373         writel(IOP_RESULT_PENDING, &req->header.result);
374
375         if (iop_send_sync_request_itl(hba, req, 20000)) {
376                 dprintk("Set config send cmd failed\n");
377                 return -1;
378         }
379
380         writel(req32, &hba->u.itl.iop->outbound_queue);
381         return 0;
382 }
383
384 static int iop_set_config_mv(struct hptiop_hba *hba,
385                                 struct hpt_iop_request_set_config *config)
386 {
387         struct hpt_iop_request_set_config *req = hba->u.mv.internal_req;
388
389         memcpy(req, config, sizeof(struct hpt_iop_request_set_config));
390         req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
391         req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG);
392         req->header.size =
393                 cpu_to_le32(sizeof(struct hpt_iop_request_set_config));
394         req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
395         req->header.context = cpu_to_le64(IOP_REQUEST_TYPE_SET_CONFIG<<5);
396
397         if (iop_send_sync_request_mv(hba, 0, 20000)) {
398                 dprintk("Set config send cmd failed\n");
399                 return -1;
400         }
401
402         return 0;
403 }
404
405 static void hptiop_enable_intr_itl(struct hptiop_hba *hba)
406 {
407         writel(~(IOPMU_OUTBOUND_INT_POSTQUEUE | IOPMU_OUTBOUND_INT_MSG0),
408                 &hba->u.itl.iop->outbound_intmask);
409 }
410
411 static void hptiop_enable_intr_mv(struct hptiop_hba *hba)
412 {
413         writel(MVIOP_MU_OUTBOUND_INT_POSTQUEUE | MVIOP_MU_OUTBOUND_INT_MSG,
414                 &hba->u.mv.regs->outbound_intmask);
415 }
416
417 static int hptiop_initialize_iop(struct hptiop_hba *hba)
418 {
419         /* enable interrupts */
420         hba->ops->enable_intr(hba);
421
422         hba->initialized = 1;
423
424         /* start background tasks */
425         if (iop_send_sync_msg(hba,
426                         IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
427                 printk(KERN_ERR "scsi%d: fail to start background task\n",
428                         hba->host->host_no);
429                 return -1;
430         }
431         return 0;
432 }
433
434 static void __iomem *hptiop_map_pci_bar(struct hptiop_hba *hba, int index)
435 {
436         u32 mem_base_phy, length;
437         void __iomem *mem_base_virt;
438
439         struct pci_dev *pcidev = hba->pcidev;
440
441
442         if (!(pci_resource_flags(pcidev, index) & IORESOURCE_MEM)) {
443                 printk(KERN_ERR "scsi%d: pci resource invalid\n",
444                                 hba->host->host_no);
445                 return 0;
446         }
447
448         mem_base_phy = pci_resource_start(pcidev, index);
449         length = pci_resource_len(pcidev, index);
450         mem_base_virt = ioremap(mem_base_phy, length);
451
452         if (!mem_base_virt) {
453                 printk(KERN_ERR "scsi%d: Fail to ioremap memory space\n",
454                                 hba->host->host_no);
455                 return 0;
456         }
457         return mem_base_virt;
458 }
459
460 static int hptiop_map_pci_bar_itl(struct hptiop_hba *hba)
461 {
462         hba->u.itl.iop = hptiop_map_pci_bar(hba, 0);
463         if (hba->u.itl.iop)
464                 return 0;
465         else
466                 return -1;
467 }
468
469 static void hptiop_unmap_pci_bar_itl(struct hptiop_hba *hba)
470 {
471         iounmap(hba->u.itl.iop);
472 }
473
474 static int hptiop_map_pci_bar_mv(struct hptiop_hba *hba)
475 {
476         hba->u.mv.regs = hptiop_map_pci_bar(hba, 0);
477         if (hba->u.mv.regs == 0)
478                 return -1;
479
480         hba->u.mv.mu = hptiop_map_pci_bar(hba, 2);
481         if (hba->u.mv.mu == 0) {
482                 iounmap(hba->u.mv.regs);
483                 return -1;
484         }
485
486         return 0;
487 }
488
489 static void hptiop_unmap_pci_bar_mv(struct hptiop_hba *hba)
490 {
491         iounmap(hba->u.mv.regs);
492         iounmap(hba->u.mv.mu);
493 }
494
495 static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg)
496 {
497         dprintk("iop message 0x%x\n", msg);
498
499         if (msg == IOPMU_INBOUND_MSG0_NOP)
500                 hba->msg_done = 1;
501
502         if (!hba->initialized)
503                 return;
504
505         if (msg == IOPMU_INBOUND_MSG0_RESET) {
506                 atomic_set(&hba->resetting, 0);
507                 wake_up(&hba->reset_wq);
508         }
509         else if (msg <= IOPMU_INBOUND_MSG0_MAX)
510                 hba->msg_done = 1;
511 }
512
513 static struct hptiop_request *get_req(struct hptiop_hba *hba)
514 {
515         struct hptiop_request *ret;
516
517         dprintk("get_req : req=%p\n", hba->req_list);
518
519         ret = hba->req_list;
520         if (ret)
521                 hba->req_list = ret->next;
522
523         return ret;
524 }
525
526 static void free_req(struct hptiop_hba *hba, struct hptiop_request *req)
527 {
528         dprintk("free_req(%d, %p)\n", req->index, req);
529         req->next = hba->req_list;
530         hba->req_list = req;
531 }
532
533 static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
534                                 struct hpt_iop_request_scsi_command *req)
535 {
536         struct scsi_cmnd *scp;
537
538         dprintk("hptiop_finish_scsi_req: req=%p, type=%d, "
539                         "result=%d, context=0x%x tag=%d\n",
540                         req, req->header.type, req->header.result,
541                         req->header.context, tag);
542
543         BUG_ON(!req->header.result);
544         BUG_ON(req->header.type != cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND));
545
546         scp = hba->reqs[tag].scp;
547
548         if (HPT_SCP(scp)->mapped)
549                 scsi_dma_unmap(scp);
550
551         switch (le32_to_cpu(req->header.result)) {
552         case IOP_RESULT_SUCCESS:
553                 scsi_set_resid(scp,
554                         scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
555                 scp->result = (DID_OK<<16);
556                 break;
557         case IOP_RESULT_BAD_TARGET:
558                 scp->result = (DID_BAD_TARGET<<16);
559                 break;
560         case IOP_RESULT_BUSY:
561                 scp->result = (DID_BUS_BUSY<<16);
562                 break;
563         case IOP_RESULT_RESET:
564                 scp->result = (DID_RESET<<16);
565                 break;
566         case IOP_RESULT_FAIL:
567                 scp->result = (DID_ERROR<<16);
568                 break;
569         case IOP_RESULT_INVALID_REQUEST:
570                 scp->result = (DID_ABORT<<16);
571                 break;
572         case IOP_RESULT_CHECK_CONDITION:
573                 scsi_set_resid(scp,
574                         scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
575                 scp->result = SAM_STAT_CHECK_CONDITION;
576                 memcpy(scp->sense_buffer, &req->sg_list,
577                                 min_t(size_t, SCSI_SENSE_BUFFERSIZE,
578                                         le32_to_cpu(req->dataxfer_length)));
579                 break;
580
581         default:
582                 scp->result = ((DRIVER_INVALID|SUGGEST_ABORT)<<24) |
583                                         (DID_ABORT<<16);
584                 break;
585         }
586
587         dprintk("scsi_done(%p)\n", scp);
588         scp->scsi_done(scp);
589         free_req(hba, &hba->reqs[tag]);
590 }
591
592 static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 _tag)
593 {
594         struct hpt_iop_request_scsi_command *req;
595         u32 tag;
596
597         if (hba->iopintf_v2) {
598                 tag = _tag & ~IOPMU_QUEUE_REQUEST_RESULT_BIT;
599                 req = hba->reqs[tag].req_virt;
600                 if (likely(_tag & IOPMU_QUEUE_REQUEST_RESULT_BIT))
601                         req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
602         } else {
603                 tag = _tag;
604                 req = hba->reqs[tag].req_virt;
605         }
606
607         hptiop_finish_scsi_req(hba, tag, req);
608 }
609
610 void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
611 {
612         struct hpt_iop_request_header __iomem *req;
613         struct hpt_iop_request_ioctl_command __iomem *p;
614         struct hpt_ioctl_k *arg;
615
616         req = (struct hpt_iop_request_header __iomem *)
617                         ((unsigned long)hba->u.itl.iop + tag);
618         dprintk("hptiop_iop_request_callback_itl: req=%p, type=%d, "
619                         "result=%d, context=0x%x tag=%d\n",
620                         req, readl(&req->type), readl(&req->result),
621                         readl(&req->context), tag);
622
623         BUG_ON(!readl(&req->result));
624         BUG_ON(readl(&req->type) != IOP_REQUEST_TYPE_IOCTL_COMMAND);
625
626         p = (struct hpt_iop_request_ioctl_command __iomem *)req;
627         arg = (struct hpt_ioctl_k *)(unsigned long)
628                 (readl(&req->context) |
629                         ((u64)readl(&req->context_hi32)<<32));
630
631         if (readl(&req->result) == IOP_RESULT_SUCCESS) {
632                 arg->result = HPT_IOCTL_RESULT_OK;
633
634                 if (arg->outbuf_size)
635                         memcpy_fromio(arg->outbuf,
636                                 &p->buf[(readl(&p->inbuf_size) + 3)& ~3],
637                                 arg->outbuf_size);
638
639                 if (arg->bytes_returned)
640                         *arg->bytes_returned = arg->outbuf_size;
641         }
642         else
643                 arg->result = HPT_IOCTL_RESULT_FAILED;
644
645         arg->done(arg);
646         writel(tag, &hba->u.itl.iop->outbound_queue);
647 }
648
649 static irqreturn_t hptiop_intr(int irq, void *dev_id)
650 {
651         struct hptiop_hba  *hba = dev_id;
652         int  handled;
653         unsigned long flags;
654
655         spin_lock_irqsave(hba->host->host_lock, flags);
656         handled = hba->ops->iop_intr(hba);
657         spin_unlock_irqrestore(hba->host->host_lock, flags);
658
659         return handled;
660 }
661
662 static int hptiop_buildsgl(struct scsi_cmnd *scp, struct hpt_iopsg *psg)
663 {
664         struct Scsi_Host *host = scp->device->host;
665         struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
666         struct scatterlist *sg;
667         int idx, nseg;
668
669         nseg = scsi_dma_map(scp);
670         BUG_ON(nseg < 0);
671         if (!nseg)
672                 return 0;
673
674         HPT_SCP(scp)->sgcnt = nseg;
675         HPT_SCP(scp)->mapped = 1;
676
677         BUG_ON(HPT_SCP(scp)->sgcnt > hba->max_sg_descriptors);
678
679         scsi_for_each_sg(scp, sg, HPT_SCP(scp)->sgcnt, idx) {
680                 psg[idx].pci_address = cpu_to_le64(sg_dma_address(sg));
681                 psg[idx].size = cpu_to_le32(sg_dma_len(sg));
682                 psg[idx].eot = (idx == HPT_SCP(scp)->sgcnt - 1) ?
683                         cpu_to_le32(1) : 0;
684         }
685         return HPT_SCP(scp)->sgcnt;
686 }
687
688 static void hptiop_post_req_itl(struct hptiop_hba *hba,
689                                         struct hptiop_request *_req)
690 {
691         struct hpt_iop_request_header *reqhdr = _req->req_virt;
692
693         reqhdr->context = cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT |
694                                                         (u32)_req->index);
695         reqhdr->context_hi32 = 0;
696
697         if (hba->iopintf_v2) {
698                 u32 size, size_bits;
699
700                 size = le32_to_cpu(reqhdr->size);
701                 if (size < 256)
702                         size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT;
703                 else if (size < 512)
704                         size_bits = IOPMU_QUEUE_ADDR_HOST_BIT;
705                 else
706                         size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT |
707                                                 IOPMU_QUEUE_ADDR_HOST_BIT;
708                 writel(_req->req_shifted_phy | size_bits,
709                         &hba->u.itl.iop->inbound_queue);
710         } else
711                 writel(_req->req_shifted_phy | IOPMU_QUEUE_ADDR_HOST_BIT,
712                                         &hba->u.itl.iop->inbound_queue);
713 }
714
715 static void hptiop_post_req_mv(struct hptiop_hba *hba,
716                                         struct hptiop_request *_req)
717 {
718         struct hpt_iop_request_header *reqhdr = _req->req_virt;
719         u32 size, size_bit;
720
721         reqhdr->context = cpu_to_le32(_req->index<<8 |
722                                         IOP_REQUEST_TYPE_SCSI_COMMAND<<5);
723         reqhdr->context_hi32 = 0;
724         size = le32_to_cpu(reqhdr->size);
725
726         if (size <= 256)
727                 size_bit = 0;
728         else if (size <= 256*2)
729                 size_bit = 1;
730         else if (size <= 256*3)
731                 size_bit = 2;
732         else
733                 size_bit = 3;
734
735         mv_inbound_write((_req->req_shifted_phy << 5) |
736                 MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bit, hba);
737 }
738
739 static int hptiop_queuecommand(struct scsi_cmnd *scp,
740                                 void (*done)(struct scsi_cmnd *))
741 {
742         struct Scsi_Host *host = scp->device->host;
743         struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
744         struct hpt_iop_request_scsi_command *req;
745         int sg_count = 0;
746         struct hptiop_request *_req;
747
748         BUG_ON(!done);
749         scp->scsi_done = done;
750
751         _req = get_req(hba);
752         if (_req == NULL) {
753                 dprintk("hptiop_queuecmd : no free req\n");
754                 return SCSI_MLQUEUE_HOST_BUSY;
755         }
756
757         _req->scp = scp;
758
759         dprintk("hptiop_queuecmd(scp=%p) %d/%d/%d/%d cdb=(%x-%x-%x) "
760                         "req_index=%d, req=%p\n",
761                         scp,
762                         host->host_no, scp->device->channel,
763                         scp->device->id, scp->device->lun,
764                         *((u32 *)&scp->cmnd),
765                         *((u32 *)&scp->cmnd + 1),
766                         *((u32 *)&scp->cmnd + 2),
767                         _req->index, _req->req_virt);
768
769         scp->result = 0;
770
771         if (scp->device->channel || scp->device->lun ||
772                         scp->device->id > hba->max_devices) {
773                 scp->result = DID_BAD_TARGET << 16;
774                 free_req(hba, _req);
775                 goto cmd_done;
776         }
777
778         req = _req->req_virt;
779
780         /* build S/G table */
781         sg_count = hptiop_buildsgl(scp, req->sg_list);
782         if (!sg_count)
783                 HPT_SCP(scp)->mapped = 0;
784
785         req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
786         req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND);
787         req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
788         req->dataxfer_length = cpu_to_le32(scsi_bufflen(scp));
789         req->channel = scp->device->channel;
790         req->target = scp->device->id;
791         req->lun = scp->device->lun;
792         req->header.size = cpu_to_le32(
793                                 sizeof(struct hpt_iop_request_scsi_command)
794                                  - sizeof(struct hpt_iopsg)
795                                  + sg_count * sizeof(struct hpt_iopsg));
796
797         memcpy(req->cdb, scp->cmnd, sizeof(req->cdb));
798         hba->ops->post_req(hba, _req);
799         return 0;
800
801 cmd_done:
802         dprintk("scsi_done(scp=%p)\n", scp);
803         scp->scsi_done(scp);
804         return 0;
805 }
806
807 static const char *hptiop_info(struct Scsi_Host *host)
808 {
809         return driver_name_long;
810 }
811
812 static int hptiop_reset_hba(struct hptiop_hba *hba)
813 {
814         if (atomic_xchg(&hba->resetting, 1) == 0) {
815                 atomic_inc(&hba->reset_count);
816                 hba->ops->post_msg(hba, IOPMU_INBOUND_MSG0_RESET);
817         }
818
819         wait_event_timeout(hba->reset_wq,
820                         atomic_read(&hba->resetting) == 0, 60 * HZ);
821
822         if (atomic_read(&hba->resetting)) {
823                 /* IOP is in unkown state, abort reset */
824                 printk(KERN_ERR "scsi%d: reset failed\n", hba->host->host_no);
825                 return -1;
826         }
827
828         if (iop_send_sync_msg(hba,
829                 IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
830                 dprintk("scsi%d: fail to start background task\n",
831                                 hba->host->host_no);
832         }
833
834         return 0;
835 }
836
837 static int hptiop_reset(struct scsi_cmnd *scp)
838 {
839         struct Scsi_Host * host = scp->device->host;
840         struct hptiop_hba * hba = (struct hptiop_hba *)host->hostdata;
841
842         printk(KERN_WARNING "hptiop_reset(%d/%d/%d) scp=%p\n",
843                         scp->device->host->host_no, scp->device->channel,
844                         scp->device->id, scp);
845
846         return hptiop_reset_hba(hba)? FAILED : SUCCESS;
847 }
848
849 static int hptiop_adjust_disk_queue_depth(struct scsi_device *sdev,
850                                                 int queue_depth)
851 {
852         struct hptiop_hba *hba = (struct hptiop_hba *)sdev->host->hostdata;
853
854         if (queue_depth > hba->max_requests)
855                 queue_depth = hba->max_requests;
856         scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth);
857         return queue_depth;
858 }
859
860 static ssize_t hptiop_show_version(struct class_device *class_dev, char *buf)
861 {
862         return snprintf(buf, PAGE_SIZE, "%s\n", driver_ver);
863 }
864
865 static ssize_t hptiop_show_fw_version(struct class_device *class_dev, char *buf)
866 {
867         struct Scsi_Host *host = class_to_shost(class_dev);
868         struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
869
870         return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
871                                 hba->firmware_version >> 24,
872                                 (hba->firmware_version >> 16) & 0xff,
873                                 (hba->firmware_version >> 8) & 0xff,
874                                 hba->firmware_version & 0xff);
875 }
876
877 static struct class_device_attribute hptiop_attr_version = {
878         .attr = {
879                 .name = "driver-version",
880                 .mode = S_IRUGO,
881         },
882         .show = hptiop_show_version,
883 };
884
885 static struct class_device_attribute hptiop_attr_fw_version = {
886         .attr = {
887                 .name = "firmware-version",
888                 .mode = S_IRUGO,
889         },
890         .show = hptiop_show_fw_version,
891 };
892
893 static struct class_device_attribute *hptiop_attrs[] = {
894         &hptiop_attr_version,
895         &hptiop_attr_fw_version,
896         NULL
897 };
898
899 static struct scsi_host_template driver_template = {
900         .module                     = THIS_MODULE,
901         .name                       = driver_name,
902         .queuecommand               = hptiop_queuecommand,
903         .eh_device_reset_handler    = hptiop_reset,
904         .eh_bus_reset_handler       = hptiop_reset,
905         .info                       = hptiop_info,
906         .unchecked_isa_dma          = 0,
907         .emulated                   = 0,
908         .use_clustering             = ENABLE_CLUSTERING,
909         .proc_name                  = driver_name,
910         .shost_attrs                = hptiop_attrs,
911         .this_id                    = -1,
912         .change_queue_depth         = hptiop_adjust_disk_queue_depth,
913 };
914
915 static int hptiop_internal_memalloc_mv(struct hptiop_hba *hba)
916 {
917         hba->u.mv.internal_req = dma_alloc_coherent(&hba->pcidev->dev,
918                         0x800, &hba->u.mv.internal_req_phy, GFP_KERNEL);
919         if (hba->u.mv.internal_req)
920                 return 0;
921         else
922                 return -1;
923 }
924
925 static int hptiop_internal_memfree_mv(struct hptiop_hba *hba)
926 {
927         if (hba->u.mv.internal_req) {
928                 dma_free_coherent(&hba->pcidev->dev, 0x800,
929                         hba->u.mv.internal_req, hba->u.mv.internal_req_phy);
930                 return 0;
931         } else
932                 return -1;
933 }
934
935 static int __devinit hptiop_probe(struct pci_dev *pcidev,
936                                         const struct pci_device_id *id)
937 {
938         struct Scsi_Host *host = NULL;
939         struct hptiop_hba *hba;
940         struct hpt_iop_request_get_config iop_config;
941         struct hpt_iop_request_set_config set_config;
942         dma_addr_t start_phy;
943         void *start_virt;
944         u32 offset, i, req_size;
945
946         dprintk("hptiop_probe(%p)\n", pcidev);
947
948         if (pci_enable_device(pcidev)) {
949                 printk(KERN_ERR "hptiop: fail to enable pci device\n");
950                 return -ENODEV;
951         }
952
953         printk(KERN_INFO "adapter at PCI %d:%d:%d, IRQ %d\n",
954                 pcidev->bus->number, pcidev->devfn >> 3, pcidev->devfn & 7,
955                 pcidev->irq);
956
957         pci_set_master(pcidev);
958
959         /* Enable 64bit DMA if possible */
960         if (pci_set_dma_mask(pcidev, DMA_64BIT_MASK)) {
961                 if (pci_set_dma_mask(pcidev, DMA_32BIT_MASK)) {
962                         printk(KERN_ERR "hptiop: fail to set dma_mask\n");
963                         goto disable_pci_device;
964                 }
965         }
966
967         if (pci_request_regions(pcidev, driver_name)) {
968                 printk(KERN_ERR "hptiop: pci_request_regions failed\n");
969                 goto disable_pci_device;
970         }
971
972         host = scsi_host_alloc(&driver_template, sizeof(struct hptiop_hba));
973         if (!host) {
974                 printk(KERN_ERR "hptiop: fail to alloc scsi host\n");
975                 goto free_pci_regions;
976         }
977
978         hba = (struct hptiop_hba *)host->hostdata;
979
980         hba->ops = (struct hptiop_adapter_ops *)id->driver_data;
981         hba->pcidev = pcidev;
982         hba->host = host;
983         hba->initialized = 0;
984         hba->iopintf_v2 = 0;
985
986         atomic_set(&hba->resetting, 0);
987         atomic_set(&hba->reset_count, 0);
988
989         init_waitqueue_head(&hba->reset_wq);
990         init_waitqueue_head(&hba->ioctl_wq);
991
992         host->max_lun = 1;
993         host->max_channel = 0;
994         host->io_port = 0;
995         host->n_io_port = 0;
996         host->irq = pcidev->irq;
997
998         if (hba->ops->map_pci_bar(hba))
999                 goto free_scsi_host;
1000
1001         if (hba->ops->iop_wait_ready(hba, 20000)) {
1002                 printk(KERN_ERR "scsi%d: firmware not ready\n",
1003                                 hba->host->host_no);
1004                 goto unmap_pci_bar;
1005         }
1006
1007         if (hba->ops->internal_memalloc) {
1008                 if (hba->ops->internal_memalloc(hba)) {
1009                         printk(KERN_ERR "scsi%d: internal_memalloc failed\n",
1010                                 hba->host->host_no);
1011                         goto unmap_pci_bar;
1012                 }
1013         }
1014
1015         if (hba->ops->get_config(hba, &iop_config)) {
1016                 printk(KERN_ERR "scsi%d: get config failed\n",
1017                                 hba->host->host_no);
1018                 goto unmap_pci_bar;
1019         }
1020
1021         hba->max_requests = min(le32_to_cpu(iop_config.max_requests),
1022                                 HPTIOP_MAX_REQUESTS);
1023         hba->max_devices = le32_to_cpu(iop_config.max_devices);
1024         hba->max_request_size = le32_to_cpu(iop_config.request_size);
1025         hba->max_sg_descriptors = le32_to_cpu(iop_config.max_sg_count);
1026         hba->firmware_version = le32_to_cpu(iop_config.firmware_version);
1027         hba->interface_version = le32_to_cpu(iop_config.interface_version);
1028         hba->sdram_size = le32_to_cpu(iop_config.sdram_size);
1029
1030         if (hba->firmware_version > 0x01020000 ||
1031                         hba->interface_version > 0x01020000)
1032                 hba->iopintf_v2 = 1;
1033
1034         host->max_sectors = le32_to_cpu(iop_config.data_transfer_length) >> 9;
1035         host->max_id = le32_to_cpu(iop_config.max_devices);
1036         host->sg_tablesize = le32_to_cpu(iop_config.max_sg_count);
1037         host->can_queue = le32_to_cpu(iop_config.max_requests);
1038         host->cmd_per_lun = le32_to_cpu(iop_config.max_requests);
1039         host->max_cmd_len = 16;
1040
1041         req_size = sizeof(struct hpt_iop_request_scsi_command)
1042                 + sizeof(struct hpt_iopsg) * (hba->max_sg_descriptors - 1);
1043         if ((req_size & 0x1f) != 0)
1044                 req_size = (req_size + 0x1f) & ~0x1f;
1045
1046         memset(&set_config, 0, sizeof(struct hpt_iop_request_set_config));
1047         set_config.iop_id = cpu_to_le32(host->host_no);
1048         set_config.vbus_id = cpu_to_le16(host->host_no);
1049         set_config.max_host_request_size = cpu_to_le16(req_size);
1050
1051         if (hba->ops->set_config(hba, &set_config)) {
1052                 printk(KERN_ERR "scsi%d: set config failed\n",
1053                                 hba->host->host_no);
1054                 goto unmap_pci_bar;
1055         }
1056
1057         pci_set_drvdata(pcidev, host);
1058
1059         if (request_irq(pcidev->irq, hptiop_intr, IRQF_SHARED,
1060                                         driver_name, hba)) {
1061                 printk(KERN_ERR "scsi%d: request irq %d failed\n",
1062                                         hba->host->host_no, pcidev->irq);
1063                 goto unmap_pci_bar;
1064         }
1065
1066         /* Allocate request mem */
1067
1068         dprintk("req_size=%d, max_requests=%d\n", req_size, hba->max_requests);
1069
1070         hba->req_size = req_size;
1071         start_virt = dma_alloc_coherent(&pcidev->dev,
1072                                 hba->req_size*hba->max_requests + 0x20,
1073                                 &start_phy, GFP_KERNEL);
1074
1075         if (!start_virt) {
1076                 printk(KERN_ERR "scsi%d: fail to alloc request mem\n",
1077                                         hba->host->host_no);
1078                 goto free_request_irq;
1079         }
1080
1081         hba->dma_coherent = start_virt;
1082         hba->dma_coherent_handle = start_phy;
1083
1084         if ((start_phy & 0x1f) != 0)
1085         {
1086                 offset = ((start_phy + 0x1f) & ~0x1f) - start_phy;
1087                 start_phy += offset;
1088                 start_virt += offset;
1089         }
1090
1091         hba->req_list = start_virt;
1092         for (i = 0; i < hba->max_requests; i++) {
1093                 hba->reqs[i].next = NULL;
1094                 hba->reqs[i].req_virt = start_virt;
1095                 hba->reqs[i].req_shifted_phy = start_phy >> 5;
1096                 hba->reqs[i].index = i;
1097                 free_req(hba, &hba->reqs[i]);
1098                 start_virt = (char *)start_virt + hba->req_size;
1099                 start_phy = start_phy + hba->req_size;
1100         }
1101
1102         /* Enable Interrupt and start background task */
1103         if (hptiop_initialize_iop(hba))
1104                 goto free_request_mem;
1105
1106         if (scsi_add_host(host, &pcidev->dev)) {
1107                 printk(KERN_ERR "scsi%d: scsi_add_host failed\n",
1108                                         hba->host->host_no);
1109                 goto free_request_mem;
1110         }
1111
1112
1113         scsi_scan_host(host);
1114
1115         dprintk("scsi%d: hptiop_probe successfully\n", hba->host->host_no);
1116         return 0;
1117
1118 free_request_mem:
1119         dma_free_coherent(&hba->pcidev->dev,
1120                         hba->req_size * hba->max_requests + 0x20,
1121                         hba->dma_coherent, hba->dma_coherent_handle);
1122
1123 free_request_irq:
1124         free_irq(hba->pcidev->irq, hba);
1125
1126 unmap_pci_bar:
1127         if (hba->ops->internal_memfree)
1128                 hba->ops->internal_memfree(hba);
1129
1130         hba->ops->unmap_pci_bar(hba);
1131
1132 free_scsi_host:
1133         scsi_host_put(host);
1134
1135 free_pci_regions:
1136         pci_release_regions(pcidev);
1137
1138 disable_pci_device:
1139         pci_disable_device(pcidev);
1140
1141         dprintk("scsi%d: hptiop_probe fail\n", host->host_no);
1142         return -ENODEV;
1143 }
1144
1145 static void hptiop_shutdown(struct pci_dev *pcidev)
1146 {
1147         struct Scsi_Host *host = pci_get_drvdata(pcidev);
1148         struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
1149
1150         dprintk("hptiop_shutdown(%p)\n", hba);
1151
1152         /* stop the iop */
1153         if (iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_SHUTDOWN, 60000))
1154                 printk(KERN_ERR "scsi%d: shutdown the iop timeout\n",
1155                                         hba->host->host_no);
1156
1157         /* disable all outbound interrupts */
1158         hba->ops->disable_intr(hba);
1159 }
1160
1161 static void hptiop_disable_intr_itl(struct hptiop_hba *hba)
1162 {
1163         u32 int_mask;
1164
1165         int_mask = readl(&hba->u.itl.iop->outbound_intmask);
1166         writel(int_mask |
1167                 IOPMU_OUTBOUND_INT_MSG0 | IOPMU_OUTBOUND_INT_POSTQUEUE,
1168                 &hba->u.itl.iop->outbound_intmask);
1169         readl(&hba->u.itl.iop->outbound_intmask);
1170 }
1171
1172 static void hptiop_disable_intr_mv(struct hptiop_hba *hba)
1173 {
1174         writel(0, &hba->u.mv.regs->outbound_intmask);
1175         readl(&hba->u.mv.regs->outbound_intmask);
1176 }
1177
1178 static void hptiop_remove(struct pci_dev *pcidev)
1179 {
1180         struct Scsi_Host *host = pci_get_drvdata(pcidev);
1181         struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
1182
1183         dprintk("scsi%d: hptiop_remove\n", hba->host->host_no);
1184
1185         scsi_remove_host(host);
1186
1187         hptiop_shutdown(pcidev);
1188
1189         free_irq(hba->pcidev->irq, hba);
1190
1191         dma_free_coherent(&hba->pcidev->dev,
1192                         hba->req_size * hba->max_requests + 0x20,
1193                         hba->dma_coherent,
1194                         hba->dma_coherent_handle);
1195
1196         if (hba->ops->internal_memfree)
1197                 hba->ops->internal_memfree(hba);
1198
1199         hba->ops->unmap_pci_bar(hba);
1200
1201         pci_release_regions(hba->pcidev);
1202         pci_set_drvdata(hba->pcidev, NULL);
1203         pci_disable_device(hba->pcidev);
1204
1205         scsi_host_put(host);
1206 }
1207
1208 static struct hptiop_adapter_ops hptiop_itl_ops = {
1209         .iop_wait_ready    = iop_wait_ready_itl,
1210         .internal_memalloc = 0,
1211         .internal_memfree  = 0,
1212         .map_pci_bar       = hptiop_map_pci_bar_itl,
1213         .unmap_pci_bar     = hptiop_unmap_pci_bar_itl,
1214         .enable_intr       = hptiop_enable_intr_itl,
1215         .disable_intr      = hptiop_disable_intr_itl,
1216         .get_config        = iop_get_config_itl,
1217         .set_config        = iop_set_config_itl,
1218         .iop_intr          = iop_intr_itl,
1219         .post_msg          = hptiop_post_msg_itl,
1220         .post_req          = hptiop_post_req_itl,
1221 };
1222
1223 static struct hptiop_adapter_ops hptiop_mv_ops = {
1224         .iop_wait_ready    = iop_wait_ready_mv,
1225         .internal_memalloc = hptiop_internal_memalloc_mv,
1226         .internal_memfree  = hptiop_internal_memfree_mv,
1227         .map_pci_bar       = hptiop_map_pci_bar_mv,
1228         .unmap_pci_bar     = hptiop_unmap_pci_bar_mv,
1229         .enable_intr       = hptiop_enable_intr_mv,
1230         .disable_intr      = hptiop_disable_intr_mv,
1231         .get_config        = iop_get_config_mv,
1232         .set_config        = iop_set_config_mv,
1233         .iop_intr          = iop_intr_mv,
1234         .post_msg          = hptiop_post_msg_mv,
1235         .post_req          = hptiop_post_req_mv,
1236 };
1237
1238 static struct pci_device_id hptiop_id_table[] = {
1239         { PCI_VDEVICE(TTI, 0x3220), (kernel_ulong_t)&hptiop_itl_ops },
1240         { PCI_VDEVICE(TTI, 0x3320), (kernel_ulong_t)&hptiop_itl_ops },
1241         { PCI_VDEVICE(TTI, 0x3520), (kernel_ulong_t)&hptiop_itl_ops },
1242         { PCI_VDEVICE(TTI, 0x4320), (kernel_ulong_t)&hptiop_itl_ops },
1243         { PCI_VDEVICE(TTI, 0x3510), (kernel_ulong_t)&hptiop_itl_ops },
1244         { PCI_VDEVICE(TTI, 0x3511), (kernel_ulong_t)&hptiop_itl_ops },
1245         { PCI_VDEVICE(TTI, 0x3521), (kernel_ulong_t)&hptiop_itl_ops },
1246         { PCI_VDEVICE(TTI, 0x3522), (kernel_ulong_t)&hptiop_itl_ops },
1247         { PCI_VDEVICE(TTI, 0x3410), (kernel_ulong_t)&hptiop_itl_ops },
1248         { PCI_VDEVICE(TTI, 0x3540), (kernel_ulong_t)&hptiop_itl_ops },
1249         { PCI_VDEVICE(TTI, 0x3120), (kernel_ulong_t)&hptiop_mv_ops },
1250         { PCI_VDEVICE(TTI, 0x3122), (kernel_ulong_t)&hptiop_mv_ops },
1251         { PCI_VDEVICE(TTI, 0x3020), (kernel_ulong_t)&hptiop_mv_ops },
1252         {},
1253 };
1254
1255 MODULE_DEVICE_TABLE(pci, hptiop_id_table);
1256
1257 static struct pci_driver hptiop_pci_driver = {
1258         .name       = driver_name,
1259         .id_table   = hptiop_id_table,
1260         .probe      = hptiop_probe,
1261         .remove     = hptiop_remove,
1262         .shutdown   = hptiop_shutdown,
1263 };
1264
1265 static int __init hptiop_module_init(void)
1266 {
1267         printk(KERN_INFO "%s %s\n", driver_name_long, driver_ver);
1268         return pci_register_driver(&hptiop_pci_driver);
1269 }
1270
1271 static void __exit hptiop_module_exit(void)
1272 {
1273         pci_unregister_driver(&hptiop_pci_driver);
1274 }
1275
1276
1277 module_init(hptiop_module_init);
1278 module_exit(hptiop_module_exit);
1279
1280 MODULE_LICENSE("GPL");
1281