2 * SuperTrak EX Series Storage Controller driver for Linux
4 * Copyright (C) 2005-2009 Promise Technology Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 * Ed Lin <promise_linux@promise.com>
16 #include <linux/init.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
19 #include <linux/delay.h>
20 #include <linux/time.h>
21 #include <linux/pci.h>
22 #include <linux/blkdev.h>
23 #include <linux/interrupt.h>
24 #include <linux/types.h>
25 #include <linux/module.h>
26 #include <linux/spinlock.h>
29 #include <asm/byteorder.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_cmnd.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi_tcq.h>
35 #include <scsi/scsi_dbg.h>
36 #include <scsi/scsi_eh.h>
38 #define DRV_NAME "stex"
39 #define ST_DRIVER_VERSION "4.6.0000.3"
40 #define ST_VER_MAJOR 4
41 #define ST_VER_MINOR 6
43 #define ST_BUILD_VER 3
46 /* MU register offset */
47 IMR0
= 0x10, /* MU_INBOUND_MESSAGE_REG0 */
48 IMR1
= 0x14, /* MU_INBOUND_MESSAGE_REG1 */
49 OMR0
= 0x18, /* MU_OUTBOUND_MESSAGE_REG0 */
50 OMR1
= 0x1c, /* MU_OUTBOUND_MESSAGE_REG1 */
51 IDBL
= 0x20, /* MU_INBOUND_DOORBELL */
52 IIS
= 0x24, /* MU_INBOUND_INTERRUPT_STATUS */
53 IIM
= 0x28, /* MU_INBOUND_INTERRUPT_MASK */
54 ODBL
= 0x2c, /* MU_OUTBOUND_DOORBELL */
55 OIS
= 0x30, /* MU_OUTBOUND_INTERRUPT_STATUS */
56 OIM
= 0x3c, /* MU_OUTBOUND_INTERRUPT_MASK */
65 /* MU register value */
66 MU_INBOUND_DOORBELL_HANDSHAKE
= 1,
67 MU_INBOUND_DOORBELL_REQHEADCHANGED
= 2,
68 MU_INBOUND_DOORBELL_STATUSTAILCHANGED
= 4,
69 MU_INBOUND_DOORBELL_HMUSTOPPED
= 8,
70 MU_INBOUND_DOORBELL_RESET
= 16,
72 MU_OUTBOUND_DOORBELL_HANDSHAKE
= 1,
73 MU_OUTBOUND_DOORBELL_REQUESTTAILCHANGED
= 2,
74 MU_OUTBOUND_DOORBELL_STATUSHEADCHANGED
= 4,
75 MU_OUTBOUND_DOORBELL_BUSCHANGE
= 8,
76 MU_OUTBOUND_DOORBELL_HASEVENT
= 16,
79 MU_STATE_STARTING
= 1,
80 MU_STATE_FMU_READY_FOR_HANDSHAKE
= 2,
81 MU_STATE_SEND_HANDSHAKE_FRAME
= 3,
83 MU_STATE_RESETTING
= 5,
86 MU_HANDSHAKE_SIGNATURE
= 0x55aaaa55,
87 MU_HANDSHAKE_SIGNATURE_HALF
= 0x5a5a0000,
88 MU_HARD_RESET_WAIT
= 30000,
91 /* firmware returned values */
92 SRB_STATUS_SUCCESS
= 0x01,
93 SRB_STATUS_ERROR
= 0x04,
94 SRB_STATUS_BUSY
= 0x05,
95 SRB_STATUS_INVALID_REQUEST
= 0x06,
96 SRB_STATUS_SELECTION_TIMEOUT
= 0x0A,
100 TASK_ATTRIBUTE_SIMPLE
= 0x0,
101 TASK_ATTRIBUTE_HEADOFQUEUE
= 0x1,
102 TASK_ATTRIBUTE_ORDERED
= 0x2,
103 TASK_ATTRIBUTE_ACA
= 0x4,
105 SS_STS_NORMAL
= 0x80000000,
106 SS_STS_DONE
= 0x40000000,
107 SS_STS_HANDSHAKE
= 0x20000000,
109 SS_HEAD_HANDSHAKE
= 0x80,
111 STEX_CDB_LENGTH
= 16,
112 STATUS_VAR_LEN
= 128,
115 SG_CF_EOT
= 0x80, /* end of table */
116 SG_CF_64B
= 0x40, /* 64 bit item */
117 SG_CF_HOST
= 0x20, /* sg in host memory */
120 MSG_DATA_DIR_OUT
= 2,
128 PASSTHRU_REQ_TYPE
= 0x00000001,
129 PASSTHRU_REQ_NO_WAKEUP
= 0x00000100,
130 ST_INTERNAL_TIMEOUT
= 180,
135 /* vendor specific commands of Promise */
137 SINBAND_MGT_CMD
= 0xd9,
139 CONTROLLER_CMD
= 0xe1,
140 DEBUGGING_CMD
= 0xe2,
143 PASSTHRU_GET_ADAPTER
= 0x05,
144 PASSTHRU_GET_DRVVER
= 0x10,
146 CTLR_CONFIG_CMD
= 0x03,
147 CTLR_SHUTDOWN
= 0x0d,
149 CTLR_POWER_STATE_CHANGE
= 0x0e,
150 CTLR_POWER_SAVING
= 0x01,
152 PASSTHRU_SIGNATURE
= 0x4e415041,
153 MGT_CMD_SIGNATURE
= 0xba,
157 ST_ADDITIONAL_MEM
= 0x200000,
161 u8 ctrl
; /* SG_CF_xxx */
167 struct st_ss_sgitem
{
179 struct st_msg_header
{
187 struct handshake_frame
{
188 __le64 rb_phy
; /* request payload queue physical address */
189 __le16 req_sz
; /* size of each request payload */
190 __le16 req_cnt
; /* count of reqs the buffer can hold */
191 __le16 status_sz
; /* size of each status payload */
192 __le16 status_cnt
; /* count of status the buffer can hold */
193 __le64 hosttime
; /* seconds from Jan 1, 1970 (GMT) */
194 u8 partner_type
; /* who sends this frame */
196 __le32 partner_ver_major
;
197 __le32 partner_ver_minor
;
198 __le32 partner_ver_oem
;
199 __le32 partner_ver_build
;
200 __le32 extra_offset
; /* NEW */
201 __le32 extra_size
; /* NEW */
213 u8 payload_sz
; /* payload size in 4-byte, not used */
214 u8 cdb
[STEX_CDB_LENGTH
];
225 u8 payload_sz
; /* payload size in 4-byte */
226 u8 variable
[STATUS_VAR_LEN
];
241 struct ver_info drv_ver
;
242 struct ver_info bios_ver
;
273 struct scsi_cmnd
*cmd
;
276 unsigned int sense_bufflen
;
286 void __iomem
*mmio_base
; /* iomapped PCI memory space */
288 dma_addr_t dma_handle
;
291 struct Scsi_Host
*host
;
292 struct pci_dev
*pdev
;
294 struct req_msg
* (*alloc_rq
) (struct st_hba
*);
295 int (*map_sg
)(struct st_hba
*, struct req_msg
*, struct st_ccb
*);
296 void (*send
) (struct st_hba
*, struct req_msg
*, u16
);
303 struct status_msg
*status_buffer
;
304 void *copy_buffer
; /* temp buffer for driver-handled commands */
306 struct st_ccb
*wait_ccb
;
309 unsigned int mu_status
;
310 unsigned int cardtype
;
319 struct st_card_info
{
320 struct req_msg
* (*alloc_rq
) (struct st_hba
*);
321 int (*map_sg
)(struct st_hba
*, struct req_msg
*, struct st_ccb
*);
322 void (*send
) (struct st_hba
*, struct req_msg
*, u16
);
324 unsigned int max_lun
;
325 unsigned int max_channel
;
332 module_param(msi
, int, 0);
333 MODULE_PARM_DESC(msi
, "Enable Message Signaled Interrupts(0=off, 1=on)");
335 static const char console_inq_page
[] =
337 0x03,0x00,0x03,0x03,0xFA,0x00,0x00,0x30,
338 0x50,0x72,0x6F,0x6D,0x69,0x73,0x65,0x20, /* "Promise " */
339 0x52,0x41,0x49,0x44,0x20,0x43,0x6F,0x6E, /* "RAID Con" */
340 0x73,0x6F,0x6C,0x65,0x20,0x20,0x20,0x20, /* "sole " */
341 0x31,0x2E,0x30,0x30,0x20,0x20,0x20,0x20, /* "1.00 " */
342 0x53,0x58,0x2F,0x52,0x53,0x41,0x46,0x2D, /* "SX/RSAF-" */
343 0x54,0x45,0x31,0x2E,0x30,0x30,0x20,0x20, /* "TE1.00 " */
344 0x0C,0x20,0x20,0x20,0x20,0x20,0x20,0x20
347 MODULE_AUTHOR("Ed Lin");
348 MODULE_DESCRIPTION("Promise Technology SuperTrak EX Controllers");
349 MODULE_LICENSE("GPL");
350 MODULE_VERSION(ST_DRIVER_VERSION
);
352 static void stex_gettime(__le64
*time
)
356 do_gettimeofday(&tv
);
357 *time
= cpu_to_le64(tv
.tv_sec
);
360 static struct status_msg
*stex_get_status(struct st_hba
*hba
)
362 struct status_msg
*status
= hba
->status_buffer
+ hba
->status_tail
;
365 hba
->status_tail
%= hba
->sts_count
+1;
370 static void stex_invalid_field(struct scsi_cmnd
*cmd
,
371 void (*done
)(struct scsi_cmnd
*))
373 cmd
->result
= (DRIVER_SENSE
<< 24) | SAM_STAT_CHECK_CONDITION
;
375 /* "Invalid field in cdb" */
376 scsi_build_sense_buffer(0, cmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x24,
381 static struct req_msg
*stex_alloc_req(struct st_hba
*hba
)
383 struct req_msg
*req
= hba
->dma_mem
+ hba
->req_head
* hba
->rq_size
;
386 hba
->req_head
%= hba
->rq_count
+1;
391 static struct req_msg
*stex_ss_alloc_req(struct st_hba
*hba
)
393 return (struct req_msg
*)(hba
->dma_mem
+
394 hba
->req_head
* hba
->rq_size
+ sizeof(struct st_msg_header
));
397 static int stex_map_sg(struct st_hba
*hba
,
398 struct req_msg
*req
, struct st_ccb
*ccb
)
400 struct scsi_cmnd
*cmd
;
401 struct scatterlist
*sg
;
402 struct st_sgtable
*dst
;
403 struct st_sgitem
*table
;
407 nseg
= scsi_dma_map(cmd
);
410 dst
= (struct st_sgtable
*)req
->variable
;
412 ccb
->sg_count
= nseg
;
413 dst
->sg_count
= cpu_to_le16((u16
)nseg
);
414 dst
->max_sg_count
= cpu_to_le16(hba
->host
->sg_tablesize
);
415 dst
->sz_in_byte
= cpu_to_le32(scsi_bufflen(cmd
));
417 table
= (struct st_sgitem
*)(dst
+ 1);
418 scsi_for_each_sg(cmd
, sg
, nseg
, i
) {
419 table
[i
].count
= cpu_to_le32((u32
)sg_dma_len(sg
));
420 table
[i
].addr
= cpu_to_le64(sg_dma_address(sg
));
421 table
[i
].ctrl
= SG_CF_64B
| SG_CF_HOST
;
423 table
[--i
].ctrl
|= SG_CF_EOT
;
429 static int stex_ss_map_sg(struct st_hba
*hba
,
430 struct req_msg
*req
, struct st_ccb
*ccb
)
432 struct scsi_cmnd
*cmd
;
433 struct scatterlist
*sg
;
434 struct st_sgtable
*dst
;
435 struct st_ss_sgitem
*table
;
439 nseg
= scsi_dma_map(cmd
);
442 dst
= (struct st_sgtable
*)req
->variable
;
444 ccb
->sg_count
= nseg
;
445 dst
->sg_count
= cpu_to_le16((u16
)nseg
);
446 dst
->max_sg_count
= cpu_to_le16(hba
->host
->sg_tablesize
);
447 dst
->sz_in_byte
= cpu_to_le32(scsi_bufflen(cmd
));
449 table
= (struct st_ss_sgitem
*)(dst
+ 1);
450 scsi_for_each_sg(cmd
, sg
, nseg
, i
) {
451 table
[i
].count
= cpu_to_le32((u32
)sg_dma_len(sg
));
453 cpu_to_le32(sg_dma_address(sg
) & 0xffffffff);
455 cpu_to_le32((sg_dma_address(sg
) >> 16) >> 16);
462 static void stex_controller_info(struct st_hba
*hba
, struct st_ccb
*ccb
)
465 size_t count
= sizeof(struct st_frame
);
467 p
= hba
->copy_buffer
;
468 scsi_sg_copy_to_buffer(ccb
->cmd
, p
, count
);
469 memset(p
->base
, 0, sizeof(u32
)*6);
470 *(unsigned long *)(p
->base
) = pci_resource_start(hba
->pdev
, 0);
473 p
->drv_ver
.major
= ST_VER_MAJOR
;
474 p
->drv_ver
.minor
= ST_VER_MINOR
;
475 p
->drv_ver
.oem
= ST_OEM
;
476 p
->drv_ver
.build
= ST_BUILD_VER
;
478 p
->bus
= hba
->pdev
->bus
->number
;
479 p
->slot
= hba
->pdev
->devfn
;
481 p
->irq_vec
= hba
->pdev
->irq
;
482 p
->id
= hba
->pdev
->vendor
<< 16 | hba
->pdev
->device
;
484 hba
->pdev
->subsystem_vendor
<< 16 | hba
->pdev
->subsystem_device
;
486 scsi_sg_copy_from_buffer(ccb
->cmd
, p
, count
);
490 stex_send_cmd(struct st_hba
*hba
, struct req_msg
*req
, u16 tag
)
492 req
->tag
= cpu_to_le16(tag
);
494 hba
->ccb
[tag
].req
= req
;
497 writel(hba
->req_head
, hba
->mmio_base
+ IMR0
);
498 writel(MU_INBOUND_DOORBELL_REQHEADCHANGED
, hba
->mmio_base
+ IDBL
);
499 readl(hba
->mmio_base
+ IDBL
); /* flush */
503 stex_ss_send_cmd(struct st_hba
*hba
, struct req_msg
*req
, u16 tag
)
505 struct scsi_cmnd
*cmd
;
506 struct st_msg_header
*msg_h
;
509 req
->tag
= cpu_to_le16(tag
);
511 hba
->ccb
[tag
].req
= req
;
514 cmd
= hba
->ccb
[tag
].cmd
;
515 msg_h
= (struct st_msg_header
*)req
- 1;
517 msg_h
->channel
= (u8
)cmd
->device
->channel
;
518 msg_h
->timeout
= cpu_to_le16(cmd
->request
->timeout
/HZ
);
520 addr
= hba
->dma_handle
+ hba
->req_head
* hba
->rq_size
;
521 addr
+= (hba
->ccb
[tag
].sg_count
+4)/11;
522 msg_h
->handle
= cpu_to_le64(addr
);
525 hba
->req_head
%= hba
->rq_count
+1;
527 writel((addr
>> 16) >> 16, hba
->mmio_base
+ YH2I_REQ_HI
);
528 readl(hba
->mmio_base
+ YH2I_REQ_HI
); /* flush */
529 writel(addr
, hba
->mmio_base
+ YH2I_REQ
);
530 readl(hba
->mmio_base
+ YH2I_REQ
); /* flush */
534 stex_slave_alloc(struct scsi_device
*sdev
)
536 /* Cheat: usually extracted from Inquiry data */
537 sdev
->tagged_supported
= 1;
539 scsi_activate_tcq(sdev
, sdev
->host
->can_queue
);
545 stex_slave_config(struct scsi_device
*sdev
)
547 sdev
->use_10_for_rw
= 1;
548 sdev
->use_10_for_ms
= 1;
549 blk_queue_rq_timeout(sdev
->request_queue
, 60 * HZ
);
550 sdev
->tagged_supported
= 1;
556 stex_slave_destroy(struct scsi_device
*sdev
)
558 scsi_deactivate_tcq(sdev
, 1);
562 stex_queuecommand(struct scsi_cmnd
*cmd
, void (* done
)(struct scsi_cmnd
*))
565 struct Scsi_Host
*host
;
566 unsigned int id
, lun
;
570 host
= cmd
->device
->host
;
571 id
= cmd
->device
->id
;
572 lun
= cmd
->device
->lun
;
573 hba
= (struct st_hba
*) &host
->hostdata
[0];
575 switch (cmd
->cmnd
[0]) {
578 static char ms10_caching_page
[12] =
579 { 0, 0x12, 0, 0, 0, 0, 0, 0, 0x8, 0xa, 0x4, 0 };
582 page
= cmd
->cmnd
[2] & 0x3f;
583 if (page
== 0x8 || page
== 0x3f) {
584 scsi_sg_copy_from_buffer(cmd
, ms10_caching_page
,
585 sizeof(ms10_caching_page
));
586 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
589 stex_invalid_field(cmd
, done
);
594 * The shasta firmware does not report actual luns in the
595 * target, so fail the command to force sequential lun scan.
596 * Also, the console device does not support this command.
598 if (hba
->cardtype
== st_shasta
|| id
== host
->max_id
- 1) {
599 stex_invalid_field(cmd
, done
);
603 case TEST_UNIT_READY
:
604 if (id
== host
->max_id
- 1) {
605 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
611 if (id
!= host
->max_id
- 1)
613 if (!lun
&& !cmd
->device
->channel
&&
614 (cmd
->cmnd
[1] & INQUIRY_EVPD
) == 0) {
615 scsi_sg_copy_from_buffer(cmd
, (void *)console_inq_page
,
616 sizeof(console_inq_page
));
617 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
620 stex_invalid_field(cmd
, done
);
623 if (cmd
->cmnd
[1] == PASSTHRU_GET_DRVVER
) {
624 struct st_drvver ver
;
625 size_t cp_len
= sizeof(ver
);
627 ver
.major
= ST_VER_MAJOR
;
628 ver
.minor
= ST_VER_MINOR
;
630 ver
.build
= ST_BUILD_VER
;
631 ver
.signature
[0] = PASSTHRU_SIGNATURE
;
632 ver
.console_id
= host
->max_id
- 1;
633 ver
.host_no
= hba
->host
->host_no
;
634 cp_len
= scsi_sg_copy_from_buffer(cmd
, &ver
, cp_len
);
635 cmd
->result
= sizeof(ver
) == cp_len
?
636 DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 :
637 DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
645 cmd
->scsi_done
= done
;
647 tag
= cmd
->request
->tag
;
649 if (unlikely(tag
>= host
->can_queue
))
650 return SCSI_MLQUEUE_HOST_BUSY
;
652 req
= hba
->alloc_rq(hba
);
658 memcpy(req
->cdb
, cmd
->cmnd
, STEX_CDB_LENGTH
);
660 if (cmd
->sc_data_direction
== DMA_FROM_DEVICE
)
661 req
->data_dir
= MSG_DATA_DIR_IN
;
662 else if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
663 req
->data_dir
= MSG_DATA_DIR_OUT
;
665 req
->data_dir
= MSG_DATA_DIR_ND
;
667 hba
->ccb
[tag
].cmd
= cmd
;
668 hba
->ccb
[tag
].sense_bufflen
= SCSI_SENSE_BUFFERSIZE
;
669 hba
->ccb
[tag
].sense_buffer
= cmd
->sense_buffer
;
671 if (!hba
->map_sg(hba
, req
, &hba
->ccb
[tag
])) {
672 hba
->ccb
[tag
].sg_count
= 0;
673 memset(&req
->variable
[0], 0, 8);
676 hba
->send(hba
, req
, tag
);
680 static void stex_scsi_done(struct st_ccb
*ccb
)
682 struct scsi_cmnd
*cmd
= ccb
->cmd
;
685 if (ccb
->srb_status
== SRB_STATUS_SUCCESS
|| ccb
->srb_status
== 0) {
686 result
= ccb
->scsi_status
;
687 switch (ccb
->scsi_status
) {
689 result
|= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
691 case SAM_STAT_CHECK_CONDITION
:
692 result
|= DRIVER_SENSE
<< 24;
695 result
|= DID_BUS_BUSY
<< 16 | COMMAND_COMPLETE
<< 8;
698 result
|= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
702 else if (ccb
->srb_status
& SRB_SEE_SENSE
)
703 result
= DRIVER_SENSE
<< 24 | SAM_STAT_CHECK_CONDITION
;
704 else switch (ccb
->srb_status
) {
705 case SRB_STATUS_SELECTION_TIMEOUT
:
706 result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
708 case SRB_STATUS_BUSY
:
709 result
= DID_BUS_BUSY
<< 16 | COMMAND_COMPLETE
<< 8;
711 case SRB_STATUS_INVALID_REQUEST
:
712 case SRB_STATUS_ERROR
:
714 result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
718 cmd
->result
= result
;
722 static void stex_copy_data(struct st_ccb
*ccb
,
723 struct status_msg
*resp
, unsigned int variable
)
725 if (resp
->scsi_status
!= SAM_STAT_GOOD
) {
726 if (ccb
->sense_buffer
!= NULL
)
727 memcpy(ccb
->sense_buffer
, resp
->variable
,
728 min(variable
, ccb
->sense_bufflen
));
732 if (ccb
->cmd
== NULL
)
734 scsi_sg_copy_from_buffer(ccb
->cmd
, resp
->variable
, variable
);
737 static void stex_check_cmd(struct st_hba
*hba
,
738 struct st_ccb
*ccb
, struct status_msg
*resp
)
740 if (ccb
->cmd
->cmnd
[0] == MGT_CMD
&&
741 resp
->scsi_status
!= SAM_STAT_CHECK_CONDITION
)
742 scsi_set_resid(ccb
->cmd
, scsi_bufflen(ccb
->cmd
) -
743 le32_to_cpu(*(__le32
*)&resp
->variable
[0]));
746 static void stex_mu_intr(struct st_hba
*hba
, u32 doorbell
)
748 void __iomem
*base
= hba
->mmio_base
;
749 struct status_msg
*resp
;
754 if (unlikely(!(doorbell
& MU_OUTBOUND_DOORBELL_STATUSHEADCHANGED
)))
757 /* status payloads */
758 hba
->status_head
= readl(base
+ OMR1
);
759 if (unlikely(hba
->status_head
> hba
->sts_count
)) {
760 printk(KERN_WARNING DRV_NAME
"(%s): invalid status head\n",
761 pci_name(hba
->pdev
));
766 * it's not a valid status payload if:
767 * 1. there are no pending requests(e.g. during init stage)
768 * 2. there are some pending requests, but the controller is in
769 * reset status, and its type is not st_yosemite
770 * firmware of st_yosemite in reset status will return pending requests
771 * to driver, so we allow it to pass
773 if (unlikely(hba
->out_req_cnt
<= 0 ||
774 (hba
->mu_status
== MU_STATE_RESETTING
&&
775 hba
->cardtype
!= st_yosemite
))) {
776 hba
->status_tail
= hba
->status_head
;
780 while (hba
->status_tail
!= hba
->status_head
) {
781 resp
= stex_get_status(hba
);
782 tag
= le16_to_cpu(resp
->tag
);
783 if (unlikely(tag
>= hba
->host
->can_queue
)) {
784 printk(KERN_WARNING DRV_NAME
785 "(%s): invalid tag\n", pci_name(hba
->pdev
));
790 ccb
= &hba
->ccb
[tag
];
791 if (unlikely(hba
->wait_ccb
== ccb
))
792 hba
->wait_ccb
= NULL
;
793 if (unlikely(ccb
->req
== NULL
)) {
794 printk(KERN_WARNING DRV_NAME
795 "(%s): lagging req\n", pci_name(hba
->pdev
));
799 size
= resp
->payload_sz
* sizeof(u32
); /* payload size */
800 if (unlikely(size
< sizeof(*resp
) - STATUS_VAR_LEN
||
801 size
> sizeof(*resp
))) {
802 printk(KERN_WARNING DRV_NAME
"(%s): bad status size\n",
803 pci_name(hba
->pdev
));
805 size
-= sizeof(*resp
) - STATUS_VAR_LEN
; /* copy size */
807 stex_copy_data(ccb
, resp
, size
);
811 ccb
->srb_status
= resp
->srb_status
;
812 ccb
->scsi_status
= resp
->scsi_status
;
814 if (likely(ccb
->cmd
!= NULL
)) {
815 if (hba
->cardtype
== st_yosemite
)
816 stex_check_cmd(hba
, ccb
, resp
);
818 if (unlikely(ccb
->cmd
->cmnd
[0] == PASSTHRU_CMD
&&
819 ccb
->cmd
->cmnd
[1] == PASSTHRU_GET_ADAPTER
))
820 stex_controller_info(hba
, ccb
);
822 scsi_dma_unmap(ccb
->cmd
);
829 writel(hba
->status_head
, base
+ IMR1
);
830 readl(base
+ IMR1
); /* flush */
833 static irqreturn_t
stex_intr(int irq
, void *__hba
)
835 struct st_hba
*hba
= __hba
;
836 void __iomem
*base
= hba
->mmio_base
;
841 spin_lock_irqsave(hba
->host
->host_lock
, flags
);
843 data
= readl(base
+ ODBL
);
845 if (data
&& data
!= 0xffffffff) {
846 /* clear the interrupt */
847 writel(data
, base
+ ODBL
);
848 readl(base
+ ODBL
); /* flush */
849 stex_mu_intr(hba
, data
);
853 spin_unlock_irqrestore(hba
->host
->host_lock
, flags
);
855 return IRQ_RETVAL(handled
);
858 static void stex_ss_mu_intr(struct st_hba
*hba
)
860 struct status_msg
*resp
;
868 if (unlikely(hba
->out_req_cnt
<= 0 ||
869 hba
->mu_status
== MU_STATE_RESETTING
))
872 while (count
< hba
->sts_count
) {
873 scratch
= hba
->scratch
+ hba
->status_tail
;
874 value
= le32_to_cpu(*scratch
);
875 if (unlikely(!(value
& SS_STS_NORMAL
)))
878 resp
= hba
->status_buffer
+ hba
->status_tail
;
882 hba
->status_tail
%= hba
->sts_count
+1;
885 if (unlikely(tag
>= hba
->host
->can_queue
)) {
886 printk(KERN_WARNING DRV_NAME
887 "(%s): invalid tag\n", pci_name(hba
->pdev
));
892 ccb
= &hba
->ccb
[tag
];
893 if (unlikely(hba
->wait_ccb
== ccb
))
894 hba
->wait_ccb
= NULL
;
895 if (unlikely(ccb
->req
== NULL
)) {
896 printk(KERN_WARNING DRV_NAME
897 "(%s): lagging req\n", pci_name(hba
->pdev
));
902 if (likely(value
& SS_STS_DONE
)) { /* normal case */
903 ccb
->srb_status
= SRB_STATUS_SUCCESS
;
904 ccb
->scsi_status
= SAM_STAT_GOOD
;
906 ccb
->srb_status
= resp
->srb_status
;
907 ccb
->scsi_status
= resp
->scsi_status
;
908 size
= resp
->payload_sz
* sizeof(u32
);
909 if (unlikely(size
< sizeof(*resp
) - STATUS_VAR_LEN
||
910 size
> sizeof(*resp
))) {
911 printk(KERN_WARNING DRV_NAME
912 "(%s): bad status size\n",
913 pci_name(hba
->pdev
));
915 size
-= sizeof(*resp
) - STATUS_VAR_LEN
;
917 stex_copy_data(ccb
, resp
, size
);
919 if (likely(ccb
->cmd
!= NULL
))
920 stex_check_cmd(hba
, ccb
, resp
);
923 if (likely(ccb
->cmd
!= NULL
)) {
924 scsi_dma_unmap(ccb
->cmd
);
931 static irqreturn_t
stex_ss_intr(int irq
, void *__hba
)
933 struct st_hba
*hba
= __hba
;
934 void __iomem
*base
= hba
->mmio_base
;
939 spin_lock_irqsave(hba
->host
->host_lock
, flags
);
941 data
= readl(base
+ YI2H_INT
);
942 if (data
&& data
!= 0xffffffff) {
943 /* clear the interrupt */
944 writel(data
, base
+ YI2H_INT_C
);
945 stex_ss_mu_intr(hba
);
949 spin_unlock_irqrestore(hba
->host
->host_lock
, flags
);
951 return IRQ_RETVAL(handled
);
954 static int stex_common_handshake(struct st_hba
*hba
)
956 void __iomem
*base
= hba
->mmio_base
;
957 struct handshake_frame
*h
;
958 dma_addr_t status_phys
;
960 unsigned long before
;
962 if (readl(base
+ OMR0
) != MU_HANDSHAKE_SIGNATURE
) {
963 writel(MU_INBOUND_DOORBELL_HANDSHAKE
, base
+ IDBL
);
966 while (readl(base
+ OMR0
) != MU_HANDSHAKE_SIGNATURE
) {
967 if (time_after(jiffies
, before
+ MU_MAX_DELAY
* HZ
)) {
968 printk(KERN_ERR DRV_NAME
969 "(%s): no handshake signature\n",
970 pci_name(hba
->pdev
));
980 data
= readl(base
+ OMR1
);
981 if ((data
& 0xffff0000) == MU_HANDSHAKE_SIGNATURE_HALF
) {
983 if (hba
->host
->can_queue
> data
) {
984 hba
->host
->can_queue
= data
;
985 hba
->host
->cmd_per_lun
= data
;
989 h
= (struct handshake_frame
*)hba
->status_buffer
;
990 h
->rb_phy
= cpu_to_le64(hba
->dma_handle
);
991 h
->req_sz
= cpu_to_le16(hba
->rq_size
);
992 h
->req_cnt
= cpu_to_le16(hba
->rq_count
+1);
993 h
->status_sz
= cpu_to_le16(sizeof(struct status_msg
));
994 h
->status_cnt
= cpu_to_le16(hba
->sts_count
+1);
995 stex_gettime(&h
->hosttime
);
996 h
->partner_type
= HMU_PARTNER_TYPE
;
997 if (hba
->extra_offset
) {
998 h
->extra_offset
= cpu_to_le32(hba
->extra_offset
);
999 h
->extra_size
= cpu_to_le32(ST_ADDITIONAL_MEM
);
1001 h
->extra_offset
= h
->extra_size
= 0;
1003 status_phys
= hba
->dma_handle
+ (hba
->rq_count
+1) * hba
->rq_size
;
1004 writel(status_phys
, base
+ IMR0
);
1006 writel((status_phys
>> 16) >> 16, base
+ IMR1
);
1009 writel((status_phys
>> 16) >> 16, base
+ OMR0
); /* old fw compatible */
1011 writel(MU_INBOUND_DOORBELL_HANDSHAKE
, base
+ IDBL
);
1012 readl(base
+ IDBL
); /* flush */
1016 while (readl(base
+ OMR0
) != MU_HANDSHAKE_SIGNATURE
) {
1017 if (time_after(jiffies
, before
+ MU_MAX_DELAY
* HZ
)) {
1018 printk(KERN_ERR DRV_NAME
1019 "(%s): no signature after handshake frame\n",
1020 pci_name(hba
->pdev
));
1027 writel(0, base
+ IMR0
);
1029 writel(0, base
+ OMR0
);
1031 writel(0, base
+ IMR1
);
1033 writel(0, base
+ OMR1
);
1034 readl(base
+ OMR1
); /* flush */
1038 static int stex_ss_handshake(struct st_hba
*hba
)
1040 void __iomem
*base
= hba
->mmio_base
;
1041 struct st_msg_header
*msg_h
;
1042 struct handshake_frame
*h
;
1043 __le32
*scratch
= hba
->scratch
;
1045 unsigned long before
;
1048 h
= (struct handshake_frame
*)(hba
->alloc_rq(hba
));
1049 msg_h
= (struct st_msg_header
*)h
- 1;
1050 msg_h
->handle
= cpu_to_le64(hba
->dma_handle
);
1051 msg_h
->flag
= SS_HEAD_HANDSHAKE
;
1053 h
->rb_phy
= cpu_to_le64(hba
->dma_handle
);
1054 h
->req_sz
= cpu_to_le16(hba
->rq_size
);
1055 h
->req_cnt
= cpu_to_le16(hba
->rq_count
+1);
1056 h
->status_sz
= cpu_to_le16(sizeof(struct status_msg
));
1057 h
->status_cnt
= cpu_to_le16(hba
->sts_count
+1);
1058 stex_gettime(&h
->hosttime
);
1059 h
->partner_type
= HMU_PARTNER_TYPE
;
1060 h
->extra_offset
= h
->extra_size
= 0;
1061 h
->scratch_size
= cpu_to_le32((hba
->sts_count
+1)*sizeof(u32
));
1063 data
= readl(base
+ YINT_EN
);
1065 writel(data
, base
+ YINT_EN
);
1066 writel((hba
->dma_handle
>> 16) >> 16, base
+ YH2I_REQ_HI
);
1067 writel(hba
->dma_handle
, base
+ YH2I_REQ
);
1069 scratch
= hba
->scratch
;
1071 while (!(le32_to_cpu(*scratch
) & SS_STS_HANDSHAKE
)) {
1072 if (time_after(jiffies
, before
+ MU_MAX_DELAY
* HZ
)) {
1073 printk(KERN_ERR DRV_NAME
1074 "(%s): no signature after handshake frame\n",
1075 pci_name(hba
->pdev
));
1088 static int stex_handshake(struct st_hba
*hba
)
1091 unsigned long flags
;
1093 err
= (hba
->cardtype
== st_yel
) ?
1094 stex_ss_handshake(hba
) : stex_common_handshake(hba
);
1096 spin_lock_irqsave(hba
->host
->host_lock
, flags
);
1099 hba
->status_head
= 0;
1100 hba
->status_tail
= 0;
1101 hba
->out_req_cnt
= 0;
1102 hba
->mu_status
= MU_STATE_STARTED
;
1103 spin_unlock_irqrestore(hba
->host
->host_lock
, flags
);
1108 static int stex_abort(struct scsi_cmnd
*cmd
)
1110 struct Scsi_Host
*host
= cmd
->device
->host
;
1111 struct st_hba
*hba
= (struct st_hba
*)host
->hostdata
;
1112 u16 tag
= cmd
->request
->tag
;
1115 int result
= SUCCESS
;
1116 unsigned long flags
;
1118 printk(KERN_INFO DRV_NAME
1119 "(%s): aborting command\n", pci_name(hba
->pdev
));
1120 scsi_print_command(cmd
);
1122 base
= hba
->mmio_base
;
1123 spin_lock_irqsave(host
->host_lock
, flags
);
1124 if (tag
< host
->can_queue
&& hba
->ccb
[tag
].cmd
== cmd
)
1125 hba
->wait_ccb
= &hba
->ccb
[tag
];
1127 for (tag
= 0; tag
< host
->can_queue
; tag
++)
1128 if (hba
->ccb
[tag
].cmd
== cmd
) {
1129 hba
->wait_ccb
= &hba
->ccb
[tag
];
1132 if (tag
>= host
->can_queue
)
1136 if (hba
->cardtype
== st_yel
) {
1137 data
= readl(base
+ YI2H_INT
);
1138 if (data
== 0 || data
== 0xffffffff)
1141 writel(data
, base
+ YI2H_INT_C
);
1142 stex_ss_mu_intr(hba
);
1144 data
= readl(base
+ ODBL
);
1145 if (data
== 0 || data
== 0xffffffff)
1148 writel(data
, base
+ ODBL
);
1149 readl(base
+ ODBL
); /* flush */
1151 stex_mu_intr(hba
, data
);
1153 if (hba
->wait_ccb
== NULL
) {
1154 printk(KERN_WARNING DRV_NAME
1155 "(%s): lost interrupt\n", pci_name(hba
->pdev
));
1160 scsi_dma_unmap(cmd
);
1161 hba
->wait_ccb
->req
= NULL
; /* nullify the req's future return */
1162 hba
->wait_ccb
= NULL
;
1165 spin_unlock_irqrestore(host
->host_lock
, flags
);
1169 static void stex_hard_reset(struct st_hba
*hba
)
1171 struct pci_bus
*bus
;
1176 for (i
= 0; i
< 16; i
++)
1177 pci_read_config_dword(hba
->pdev
, i
* 4,
1178 &hba
->pdev
->saved_config_space
[i
]);
1180 /* Reset secondary bus. Our controller(MU/ATU) is the only device on
1181 secondary bus. Consult Intel 80331/3 developer's manual for detail */
1182 bus
= hba
->pdev
->bus
;
1183 pci_read_config_byte(bus
->self
, PCI_BRIDGE_CONTROL
, &pci_bctl
);
1184 pci_bctl
|= PCI_BRIDGE_CTL_BUS_RESET
;
1185 pci_write_config_byte(bus
->self
, PCI_BRIDGE_CONTROL
, pci_bctl
);
1188 * 1 ms may be enough for 8-port controllers. But 16-port controllers
1189 * require more time to finish bus reset. Use 100 ms here for safety
1192 pci_bctl
&= ~PCI_BRIDGE_CTL_BUS_RESET
;
1193 pci_write_config_byte(bus
->self
, PCI_BRIDGE_CONTROL
, pci_bctl
);
1195 for (i
= 0; i
< MU_HARD_RESET_WAIT
; i
++) {
1196 pci_read_config_word(hba
->pdev
, PCI_COMMAND
, &pci_cmd
);
1197 if (pci_cmd
!= 0xffff && (pci_cmd
& PCI_COMMAND_MASTER
))
1203 for (i
= 0; i
< 16; i
++)
1204 pci_write_config_dword(hba
->pdev
, i
* 4,
1205 hba
->pdev
->saved_config_space
[i
]);
1208 static int stex_reset(struct scsi_cmnd
*cmd
)
1212 unsigned long flags
, before
;
1214 hba
= (struct st_hba
*) &cmd
->device
->host
->hostdata
[0];
1216 printk(KERN_INFO DRV_NAME
1217 "(%s): resetting host\n", pci_name(hba
->pdev
));
1218 scsi_print_command(cmd
);
1220 hba
->mu_status
= MU_STATE_RESETTING
;
1222 if (hba
->cardtype
== st_shasta
)
1223 stex_hard_reset(hba
);
1225 if (hba
->cardtype
!= st_yosemite
) {
1226 if (stex_handshake(hba
)) {
1227 printk(KERN_WARNING DRV_NAME
1228 "(%s): resetting: handshake failed\n",
1229 pci_name(hba
->pdev
));
1236 writel(MU_INBOUND_DOORBELL_RESET
, hba
->mmio_base
+ IDBL
);
1237 readl(hba
->mmio_base
+ IDBL
); /* flush */
1239 while (hba
->out_req_cnt
> 0) {
1240 if (time_after(jiffies
, before
+ ST_INTERNAL_TIMEOUT
* HZ
)) {
1241 printk(KERN_WARNING DRV_NAME
1242 "(%s): reset timeout\n", pci_name(hba
->pdev
));
1248 base
= hba
->mmio_base
;
1249 writel(0, base
+ IMR0
);
1251 writel(0, base
+ OMR0
);
1253 writel(0, base
+ IMR1
);
1255 writel(0, base
+ OMR1
);
1256 readl(base
+ OMR1
); /* flush */
1257 spin_lock_irqsave(hba
->host
->host_lock
, flags
);
1260 hba
->status_head
= 0;
1261 hba
->status_tail
= 0;
1262 hba
->out_req_cnt
= 0;
1263 hba
->mu_status
= MU_STATE_STARTED
;
1264 spin_unlock_irqrestore(hba
->host
->host_lock
, flags
);
1268 static int stex_biosparam(struct scsi_device
*sdev
,
1269 struct block_device
*bdev
, sector_t capacity
, int geom
[])
1271 int heads
= 255, sectors
= 63;
1273 if (capacity
< 0x200000) {
1278 sector_div(capacity
, heads
* sectors
);
1287 static struct scsi_host_template driver_template
= {
1288 .module
= THIS_MODULE
,
1290 .proc_name
= DRV_NAME
,
1291 .bios_param
= stex_biosparam
,
1292 .queuecommand
= stex_queuecommand
,
1293 .slave_alloc
= stex_slave_alloc
,
1294 .slave_configure
= stex_slave_config
,
1295 .slave_destroy
= stex_slave_destroy
,
1296 .eh_abort_handler
= stex_abort
,
1297 .eh_host_reset_handler
= stex_reset
,
1301 static struct pci_device_id stex_pci_tbl
[] = {
1303 { 0x105a, 0x8350, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
1304 st_shasta
}, /* SuperTrak EX8350/8300/16350/16300 */
1305 { 0x105a, 0xc350, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
1306 st_shasta
}, /* SuperTrak EX12350 */
1307 { 0x105a, 0x4302, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
1308 st_shasta
}, /* SuperTrak EX4350 */
1309 { 0x105a, 0xe350, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
1310 st_shasta
}, /* SuperTrak EX24350 */
1313 { 0x105a, 0x7250, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, st_vsc
},
1316 { 0x105a, 0x8650, 0x105a, PCI_ANY_ID
, 0, 0, st_yosemite
},
1319 { 0x105a, 0x3360, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, st_seq
},
1322 { 0x105a, 0x8650, 0x1033, PCI_ANY_ID
, 0, 0, st_yel
},
1323 { 0x105a, 0x8760, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, st_yel
},
1324 { } /* terminate list */
1327 static struct st_card_info stex_card_info
[] = {
1336 .alloc_rq
= stex_alloc_req
,
1337 .map_sg
= stex_map_sg
,
1338 .send
= stex_send_cmd
,
1349 .alloc_rq
= stex_alloc_req
,
1350 .map_sg
= stex_map_sg
,
1351 .send
= stex_send_cmd
,
1362 .alloc_rq
= stex_alloc_req
,
1363 .map_sg
= stex_map_sg
,
1364 .send
= stex_send_cmd
,
1375 .alloc_rq
= stex_alloc_req
,
1376 .map_sg
= stex_map_sg
,
1377 .send
= stex_send_cmd
,
1388 .alloc_rq
= stex_ss_alloc_req
,
1389 .map_sg
= stex_ss_map_sg
,
1390 .send
= stex_ss_send_cmd
,
1394 static int stex_set_dma_mask(struct pci_dev
* pdev
)
1398 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64))
1399 && !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
1401 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
1403 ret
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
1407 static int stex_request_irq(struct st_hba
*hba
)
1409 struct pci_dev
*pdev
= hba
->pdev
;
1413 status
= pci_enable_msi(pdev
);
1415 printk(KERN_ERR DRV_NAME
1416 "(%s): error %d setting up MSI\n",
1417 pci_name(pdev
), status
);
1419 hba
->msi_enabled
= 1;
1421 hba
->msi_enabled
= 0;
1423 status
= request_irq(pdev
->irq
, hba
->cardtype
== st_yel
?
1424 stex_ss_intr
: stex_intr
, IRQF_SHARED
, DRV_NAME
, hba
);
1427 if (hba
->msi_enabled
)
1428 pci_disable_msi(pdev
);
1433 static void stex_free_irq(struct st_hba
*hba
)
1435 struct pci_dev
*pdev
= hba
->pdev
;
1437 free_irq(pdev
->irq
, hba
);
1438 if (hba
->msi_enabled
)
1439 pci_disable_msi(pdev
);
1442 static int __devinit
1443 stex_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1446 struct Scsi_Host
*host
;
1447 const struct st_card_info
*ci
= NULL
;
1448 u32 sts_offset
, cp_offset
, scratch_offset
;
1451 err
= pci_enable_device(pdev
);
1455 pci_set_master(pdev
);
1457 host
= scsi_host_alloc(&driver_template
, sizeof(struct st_hba
));
1460 printk(KERN_ERR DRV_NAME
"(%s): scsi_host_alloc failed\n",
1466 hba
= (struct st_hba
*)host
->hostdata
;
1467 memset(hba
, 0, sizeof(struct st_hba
));
1469 err
= pci_request_regions(pdev
, DRV_NAME
);
1471 printk(KERN_ERR DRV_NAME
"(%s): request regions failed\n",
1473 goto out_scsi_host_put
;
1476 hba
->mmio_base
= pci_ioremap_bar(pdev
, 0);
1477 if ( !hba
->mmio_base
) {
1478 printk(KERN_ERR DRV_NAME
"(%s): memory map failed\n",
1481 goto out_release_regions
;
1484 err
= stex_set_dma_mask(pdev
);
1486 printk(KERN_ERR DRV_NAME
"(%s): set dma mask failed\n",
1491 hba
->cardtype
= (unsigned int) id
->driver_data
;
1492 ci
= &stex_card_info
[hba
->cardtype
];
1493 sts_offset
= scratch_offset
= (ci
->rq_count
+1) * ci
->rq_size
;
1494 if (hba
->cardtype
== st_yel
)
1495 sts_offset
+= (ci
->sts_count
+1) * sizeof(u32
);
1496 cp_offset
= sts_offset
+ (ci
->sts_count
+1) * sizeof(struct status_msg
);
1497 hba
->dma_size
= cp_offset
+ sizeof(struct st_frame
);
1498 if (hba
->cardtype
== st_seq
||
1499 (hba
->cardtype
== st_vsc
&& (pdev
->subsystem_device
& 1))) {
1500 hba
->extra_offset
= hba
->dma_size
;
1501 hba
->dma_size
+= ST_ADDITIONAL_MEM
;
1503 hba
->dma_mem
= dma_alloc_coherent(&pdev
->dev
,
1504 hba
->dma_size
, &hba
->dma_handle
, GFP_KERNEL
);
1505 if (!hba
->dma_mem
) {
1507 printk(KERN_ERR DRV_NAME
"(%s): dma mem alloc failed\n",
1512 hba
->ccb
= kcalloc(ci
->rq_count
, sizeof(struct st_ccb
), GFP_KERNEL
);
1515 printk(KERN_ERR DRV_NAME
"(%s): ccb alloc failed\n",
1520 if (hba
->cardtype
== st_yel
)
1521 hba
->scratch
= (__le32
*)(hba
->dma_mem
+ scratch_offset
);
1522 hba
->status_buffer
= (struct status_msg
*)(hba
->dma_mem
+ sts_offset
);
1523 hba
->copy_buffer
= hba
->dma_mem
+ cp_offset
;
1524 hba
->rq_count
= ci
->rq_count
;
1525 hba
->rq_size
= ci
->rq_size
;
1526 hba
->sts_count
= ci
->sts_count
;
1527 hba
->alloc_rq
= ci
->alloc_rq
;
1528 hba
->map_sg
= ci
->map_sg
;
1529 hba
->send
= ci
->send
;
1530 hba
->mu_status
= MU_STATE_STARTING
;
1532 if (hba
->cardtype
== st_yel
)
1533 host
->sg_tablesize
= 38;
1535 host
->sg_tablesize
= 32;
1536 host
->can_queue
= ci
->rq_count
;
1537 host
->cmd_per_lun
= ci
->rq_count
;
1538 host
->max_id
= ci
->max_id
;
1539 host
->max_lun
= ci
->max_lun
;
1540 host
->max_channel
= ci
->max_channel
;
1541 host
->unique_id
= host
->host_no
;
1542 host
->max_cmd_len
= STEX_CDB_LENGTH
;
1547 err
= stex_request_irq(hba
);
1549 printk(KERN_ERR DRV_NAME
"(%s): request irq failed\n",
1554 err
= stex_handshake(hba
);
1558 err
= scsi_init_shared_tag_map(host
, host
->can_queue
);
1560 printk(KERN_ERR DRV_NAME
"(%s): init shared queue failed\n",
1565 pci_set_drvdata(pdev
, hba
);
1567 err
= scsi_add_host(host
, &pdev
->dev
);
1569 printk(KERN_ERR DRV_NAME
"(%s): scsi_add_host failed\n",
1574 scsi_scan_host(host
);
1583 dma_free_coherent(&pdev
->dev
, hba
->dma_size
,
1584 hba
->dma_mem
, hba
->dma_handle
);
1586 iounmap(hba
->mmio_base
);
1587 out_release_regions
:
1588 pci_release_regions(pdev
);
1590 scsi_host_put(host
);
1592 pci_disable_device(pdev
);
1597 static void stex_hba_stop(struct st_hba
*hba
)
1599 struct req_msg
*req
;
1600 struct st_msg_header
*msg_h
;
1601 unsigned long flags
;
1602 unsigned long before
;
1605 spin_lock_irqsave(hba
->host
->host_lock
, flags
);
1606 req
= hba
->alloc_rq(hba
);
1607 if (hba
->cardtype
== st_yel
) {
1608 msg_h
= (struct st_msg_header
*)req
- 1;
1609 memset(msg_h
, 0, hba
->rq_size
);
1611 memset(req
, 0, hba
->rq_size
);
1613 if (hba
->cardtype
== st_yosemite
|| hba
->cardtype
== st_yel
) {
1614 req
->cdb
[0] = MGT_CMD
;
1615 req
->cdb
[1] = MGT_CMD_SIGNATURE
;
1616 req
->cdb
[2] = CTLR_CONFIG_CMD
;
1617 req
->cdb
[3] = CTLR_SHUTDOWN
;
1619 req
->cdb
[0] = CONTROLLER_CMD
;
1620 req
->cdb
[1] = CTLR_POWER_STATE_CHANGE
;
1621 req
->cdb
[2] = CTLR_POWER_SAVING
;
1624 hba
->ccb
[tag
].cmd
= NULL
;
1625 hba
->ccb
[tag
].sg_count
= 0;
1626 hba
->ccb
[tag
].sense_bufflen
= 0;
1627 hba
->ccb
[tag
].sense_buffer
= NULL
;
1628 hba
->ccb
[tag
].req_type
= PASSTHRU_REQ_TYPE
;
1630 hba
->send(hba
, req
, tag
);
1631 spin_unlock_irqrestore(hba
->host
->host_lock
, flags
);
1634 while (hba
->ccb
[tag
].req_type
& PASSTHRU_REQ_TYPE
) {
1635 if (time_after(jiffies
, before
+ ST_INTERNAL_TIMEOUT
* HZ
)) {
1636 hba
->ccb
[tag
].req_type
= 0;
1643 static void stex_hba_free(struct st_hba
*hba
)
1647 iounmap(hba
->mmio_base
);
1649 pci_release_regions(hba
->pdev
);
1653 dma_free_coherent(&hba
->pdev
->dev
, hba
->dma_size
,
1654 hba
->dma_mem
, hba
->dma_handle
);
1657 static void stex_remove(struct pci_dev
*pdev
)
1659 struct st_hba
*hba
= pci_get_drvdata(pdev
);
1661 scsi_remove_host(hba
->host
);
1663 pci_set_drvdata(pdev
, NULL
);
1669 scsi_host_put(hba
->host
);
1671 pci_disable_device(pdev
);
1674 static void stex_shutdown(struct pci_dev
*pdev
)
1676 struct st_hba
*hba
= pci_get_drvdata(pdev
);
1681 MODULE_DEVICE_TABLE(pci
, stex_pci_tbl
);
1683 static struct pci_driver stex_pci_driver
= {
1685 .id_table
= stex_pci_tbl
,
1686 .probe
= stex_probe
,
1687 .remove
= __devexit_p(stex_remove
),
1688 .shutdown
= stex_shutdown
,
1691 static int __init
stex_init(void)
1693 printk(KERN_INFO DRV_NAME
1694 ": Promise SuperTrak EX Driver version: %s\n",
1697 return pci_register_driver(&stex_pci_driver
);
1700 static void __exit
stex_exit(void)
1702 pci_unregister_driver(&stex_pci_driver
);
1705 module_init(stex_init
);
1706 module_exit(stex_exit
);