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 */
66 /* MU register value */
67 MU_INBOUND_DOORBELL_HANDSHAKE
= 1,
68 MU_INBOUND_DOORBELL_REQHEADCHANGED
= 2,
69 MU_INBOUND_DOORBELL_STATUSTAILCHANGED
= 4,
70 MU_INBOUND_DOORBELL_HMUSTOPPED
= 8,
71 MU_INBOUND_DOORBELL_RESET
= 16,
73 MU_OUTBOUND_DOORBELL_HANDSHAKE
= 1,
74 MU_OUTBOUND_DOORBELL_REQUESTTAILCHANGED
= 2,
75 MU_OUTBOUND_DOORBELL_STATUSHEADCHANGED
= 4,
76 MU_OUTBOUND_DOORBELL_BUSCHANGE
= 8,
77 MU_OUTBOUND_DOORBELL_HASEVENT
= 16,
80 MU_STATE_STARTING
= 1,
81 MU_STATE_FMU_READY_FOR_HANDSHAKE
= 2,
82 MU_STATE_SEND_HANDSHAKE_FRAME
= 3,
84 MU_STATE_RESETTING
= 5,
87 MU_HANDSHAKE_SIGNATURE
= 0x55aaaa55,
88 MU_HANDSHAKE_SIGNATURE_HALF
= 0x5a5a0000,
89 MU_HARD_RESET_WAIT
= 30000,
92 /* firmware returned values */
93 SRB_STATUS_SUCCESS
= 0x01,
94 SRB_STATUS_ERROR
= 0x04,
95 SRB_STATUS_BUSY
= 0x05,
96 SRB_STATUS_INVALID_REQUEST
= 0x06,
97 SRB_STATUS_SELECTION_TIMEOUT
= 0x0A,
101 TASK_ATTRIBUTE_SIMPLE
= 0x0,
102 TASK_ATTRIBUTE_HEADOFQUEUE
= 0x1,
103 TASK_ATTRIBUTE_ORDERED
= 0x2,
104 TASK_ATTRIBUTE_ACA
= 0x4,
106 SS_STS_NORMAL
= 0x80000000,
107 SS_STS_DONE
= 0x40000000,
108 SS_STS_HANDSHAKE
= 0x20000000,
110 SS_HEAD_HANDSHAKE
= 0x80,
112 SS_H2I_INT_RESET
= 0x100,
114 SS_MU_OPERATIONAL
= 0x80000000,
116 STEX_CDB_LENGTH
= 16,
117 STATUS_VAR_LEN
= 128,
120 SG_CF_EOT
= 0x80, /* end of table */
121 SG_CF_64B
= 0x40, /* 64 bit item */
122 SG_CF_HOST
= 0x20, /* sg in host memory */
125 MSG_DATA_DIR_OUT
= 2,
133 PASSTHRU_REQ_TYPE
= 0x00000001,
134 PASSTHRU_REQ_NO_WAKEUP
= 0x00000100,
135 ST_INTERNAL_TIMEOUT
= 180,
140 /* vendor specific commands of Promise */
142 SINBAND_MGT_CMD
= 0xd9,
144 CONTROLLER_CMD
= 0xe1,
145 DEBUGGING_CMD
= 0xe2,
148 PASSTHRU_GET_ADAPTER
= 0x05,
149 PASSTHRU_GET_DRVVER
= 0x10,
151 CTLR_CONFIG_CMD
= 0x03,
152 CTLR_SHUTDOWN
= 0x0d,
154 CTLR_POWER_STATE_CHANGE
= 0x0e,
155 CTLR_POWER_SAVING
= 0x01,
157 PASSTHRU_SIGNATURE
= 0x4e415041,
158 MGT_CMD_SIGNATURE
= 0xba,
162 ST_ADDITIONAL_MEM
= 0x200000,
166 u8 ctrl
; /* SG_CF_xxx */
172 struct st_ss_sgitem
{
184 struct st_msg_header
{
192 struct handshake_frame
{
193 __le64 rb_phy
; /* request payload queue physical address */
194 __le16 req_sz
; /* size of each request payload */
195 __le16 req_cnt
; /* count of reqs the buffer can hold */
196 __le16 status_sz
; /* size of each status payload */
197 __le16 status_cnt
; /* count of status the buffer can hold */
198 __le64 hosttime
; /* seconds from Jan 1, 1970 (GMT) */
199 u8 partner_type
; /* who sends this frame */
201 __le32 partner_ver_major
;
202 __le32 partner_ver_minor
;
203 __le32 partner_ver_oem
;
204 __le32 partner_ver_build
;
205 __le32 extra_offset
; /* NEW */
206 __le32 extra_size
; /* NEW */
218 u8 payload_sz
; /* payload size in 4-byte, not used */
219 u8 cdb
[STEX_CDB_LENGTH
];
230 u8 payload_sz
; /* payload size in 4-byte */
231 u8 variable
[STATUS_VAR_LEN
];
246 struct ver_info drv_ver
;
247 struct ver_info bios_ver
;
278 struct scsi_cmnd
*cmd
;
281 unsigned int sense_bufflen
;
291 void __iomem
*mmio_base
; /* iomapped PCI memory space */
293 dma_addr_t dma_handle
;
296 struct Scsi_Host
*host
;
297 struct pci_dev
*pdev
;
299 struct req_msg
* (*alloc_rq
) (struct st_hba
*);
300 int (*map_sg
)(struct st_hba
*, struct req_msg
*, struct st_ccb
*);
301 void (*send
) (struct st_hba
*, struct req_msg
*, u16
);
308 struct status_msg
*status_buffer
;
309 void *copy_buffer
; /* temp buffer for driver-handled commands */
311 struct st_ccb
*wait_ccb
;
314 unsigned int mu_status
;
315 unsigned int cardtype
;
324 struct st_card_info
{
325 struct req_msg
* (*alloc_rq
) (struct st_hba
*);
326 int (*map_sg
)(struct st_hba
*, struct req_msg
*, struct st_ccb
*);
327 void (*send
) (struct st_hba
*, struct req_msg
*, u16
);
329 unsigned int max_lun
;
330 unsigned int max_channel
;
337 module_param(msi
, int, 0);
338 MODULE_PARM_DESC(msi
, "Enable Message Signaled Interrupts(0=off, 1=on)");
340 static const char console_inq_page
[] =
342 0x03,0x00,0x03,0x03,0xFA,0x00,0x00,0x30,
343 0x50,0x72,0x6F,0x6D,0x69,0x73,0x65,0x20, /* "Promise " */
344 0x52,0x41,0x49,0x44,0x20,0x43,0x6F,0x6E, /* "RAID Con" */
345 0x73,0x6F,0x6C,0x65,0x20,0x20,0x20,0x20, /* "sole " */
346 0x31,0x2E,0x30,0x30,0x20,0x20,0x20,0x20, /* "1.00 " */
347 0x53,0x58,0x2F,0x52,0x53,0x41,0x46,0x2D, /* "SX/RSAF-" */
348 0x54,0x45,0x31,0x2E,0x30,0x30,0x20,0x20, /* "TE1.00 " */
349 0x0C,0x20,0x20,0x20,0x20,0x20,0x20,0x20
352 MODULE_AUTHOR("Ed Lin");
353 MODULE_DESCRIPTION("Promise Technology SuperTrak EX Controllers");
354 MODULE_LICENSE("GPL");
355 MODULE_VERSION(ST_DRIVER_VERSION
);
357 static void stex_gettime(__le64
*time
)
361 do_gettimeofday(&tv
);
362 *time
= cpu_to_le64(tv
.tv_sec
);
365 static struct status_msg
*stex_get_status(struct st_hba
*hba
)
367 struct status_msg
*status
= hba
->status_buffer
+ hba
->status_tail
;
370 hba
->status_tail
%= hba
->sts_count
+1;
375 static void stex_invalid_field(struct scsi_cmnd
*cmd
,
376 void (*done
)(struct scsi_cmnd
*))
378 cmd
->result
= (DRIVER_SENSE
<< 24) | SAM_STAT_CHECK_CONDITION
;
380 /* "Invalid field in cdb" */
381 scsi_build_sense_buffer(0, cmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x24,
386 static struct req_msg
*stex_alloc_req(struct st_hba
*hba
)
388 struct req_msg
*req
= hba
->dma_mem
+ hba
->req_head
* hba
->rq_size
;
391 hba
->req_head
%= hba
->rq_count
+1;
396 static struct req_msg
*stex_ss_alloc_req(struct st_hba
*hba
)
398 return (struct req_msg
*)(hba
->dma_mem
+
399 hba
->req_head
* hba
->rq_size
+ sizeof(struct st_msg_header
));
402 static int stex_map_sg(struct st_hba
*hba
,
403 struct req_msg
*req
, struct st_ccb
*ccb
)
405 struct scsi_cmnd
*cmd
;
406 struct scatterlist
*sg
;
407 struct st_sgtable
*dst
;
408 struct st_sgitem
*table
;
412 nseg
= scsi_dma_map(cmd
);
415 dst
= (struct st_sgtable
*)req
->variable
;
417 ccb
->sg_count
= nseg
;
418 dst
->sg_count
= cpu_to_le16((u16
)nseg
);
419 dst
->max_sg_count
= cpu_to_le16(hba
->host
->sg_tablesize
);
420 dst
->sz_in_byte
= cpu_to_le32(scsi_bufflen(cmd
));
422 table
= (struct st_sgitem
*)(dst
+ 1);
423 scsi_for_each_sg(cmd
, sg
, nseg
, i
) {
424 table
[i
].count
= cpu_to_le32((u32
)sg_dma_len(sg
));
425 table
[i
].addr
= cpu_to_le64(sg_dma_address(sg
));
426 table
[i
].ctrl
= SG_CF_64B
| SG_CF_HOST
;
428 table
[--i
].ctrl
|= SG_CF_EOT
;
434 static int stex_ss_map_sg(struct st_hba
*hba
,
435 struct req_msg
*req
, struct st_ccb
*ccb
)
437 struct scsi_cmnd
*cmd
;
438 struct scatterlist
*sg
;
439 struct st_sgtable
*dst
;
440 struct st_ss_sgitem
*table
;
444 nseg
= scsi_dma_map(cmd
);
447 dst
= (struct st_sgtable
*)req
->variable
;
449 ccb
->sg_count
= nseg
;
450 dst
->sg_count
= cpu_to_le16((u16
)nseg
);
451 dst
->max_sg_count
= cpu_to_le16(hba
->host
->sg_tablesize
);
452 dst
->sz_in_byte
= cpu_to_le32(scsi_bufflen(cmd
));
454 table
= (struct st_ss_sgitem
*)(dst
+ 1);
455 scsi_for_each_sg(cmd
, sg
, nseg
, i
) {
456 table
[i
].count
= cpu_to_le32((u32
)sg_dma_len(sg
));
458 cpu_to_le32(sg_dma_address(sg
) & 0xffffffff);
460 cpu_to_le32((sg_dma_address(sg
) >> 16) >> 16);
467 static void stex_controller_info(struct st_hba
*hba
, struct st_ccb
*ccb
)
470 size_t count
= sizeof(struct st_frame
);
472 p
= hba
->copy_buffer
;
473 scsi_sg_copy_to_buffer(ccb
->cmd
, p
, count
);
474 memset(p
->base
, 0, sizeof(u32
)*6);
475 *(unsigned long *)(p
->base
) = pci_resource_start(hba
->pdev
, 0);
478 p
->drv_ver
.major
= ST_VER_MAJOR
;
479 p
->drv_ver
.minor
= ST_VER_MINOR
;
480 p
->drv_ver
.oem
= ST_OEM
;
481 p
->drv_ver
.build
= ST_BUILD_VER
;
483 p
->bus
= hba
->pdev
->bus
->number
;
484 p
->slot
= hba
->pdev
->devfn
;
486 p
->irq_vec
= hba
->pdev
->irq
;
487 p
->id
= hba
->pdev
->vendor
<< 16 | hba
->pdev
->device
;
489 hba
->pdev
->subsystem_vendor
<< 16 | hba
->pdev
->subsystem_device
;
491 scsi_sg_copy_from_buffer(ccb
->cmd
, p
, count
);
495 stex_send_cmd(struct st_hba
*hba
, struct req_msg
*req
, u16 tag
)
497 req
->tag
= cpu_to_le16(tag
);
499 hba
->ccb
[tag
].req
= req
;
502 writel(hba
->req_head
, hba
->mmio_base
+ IMR0
);
503 writel(MU_INBOUND_DOORBELL_REQHEADCHANGED
, hba
->mmio_base
+ IDBL
);
504 readl(hba
->mmio_base
+ IDBL
); /* flush */
508 stex_ss_send_cmd(struct st_hba
*hba
, struct req_msg
*req
, u16 tag
)
510 struct scsi_cmnd
*cmd
;
511 struct st_msg_header
*msg_h
;
514 req
->tag
= cpu_to_le16(tag
);
516 hba
->ccb
[tag
].req
= req
;
519 cmd
= hba
->ccb
[tag
].cmd
;
520 msg_h
= (struct st_msg_header
*)req
- 1;
522 msg_h
->channel
= (u8
)cmd
->device
->channel
;
523 msg_h
->timeout
= cpu_to_le16(cmd
->request
->timeout
/HZ
);
525 addr
= hba
->dma_handle
+ hba
->req_head
* hba
->rq_size
;
526 addr
+= (hba
->ccb
[tag
].sg_count
+4)/11;
527 msg_h
->handle
= cpu_to_le64(addr
);
530 hba
->req_head
%= hba
->rq_count
+1;
532 writel((addr
>> 16) >> 16, hba
->mmio_base
+ YH2I_REQ_HI
);
533 readl(hba
->mmio_base
+ YH2I_REQ_HI
); /* flush */
534 writel(addr
, hba
->mmio_base
+ YH2I_REQ
);
535 readl(hba
->mmio_base
+ YH2I_REQ
); /* flush */
539 stex_slave_alloc(struct scsi_device
*sdev
)
541 /* Cheat: usually extracted from Inquiry data */
542 sdev
->tagged_supported
= 1;
544 scsi_activate_tcq(sdev
, sdev
->host
->can_queue
);
550 stex_slave_config(struct scsi_device
*sdev
)
552 sdev
->use_10_for_rw
= 1;
553 sdev
->use_10_for_ms
= 1;
554 blk_queue_rq_timeout(sdev
->request_queue
, 60 * HZ
);
555 sdev
->tagged_supported
= 1;
561 stex_slave_destroy(struct scsi_device
*sdev
)
563 scsi_deactivate_tcq(sdev
, 1);
567 stex_queuecommand(struct scsi_cmnd
*cmd
, void (* done
)(struct scsi_cmnd
*))
570 struct Scsi_Host
*host
;
571 unsigned int id
, lun
;
575 host
= cmd
->device
->host
;
576 id
= cmd
->device
->id
;
577 lun
= cmd
->device
->lun
;
578 hba
= (struct st_hba
*) &host
->hostdata
[0];
580 switch (cmd
->cmnd
[0]) {
583 static char ms10_caching_page
[12] =
584 { 0, 0x12, 0, 0, 0, 0, 0, 0, 0x8, 0xa, 0x4, 0 };
587 page
= cmd
->cmnd
[2] & 0x3f;
588 if (page
== 0x8 || page
== 0x3f) {
589 scsi_sg_copy_from_buffer(cmd
, ms10_caching_page
,
590 sizeof(ms10_caching_page
));
591 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
594 stex_invalid_field(cmd
, done
);
599 * The shasta firmware does not report actual luns in the
600 * target, so fail the command to force sequential lun scan.
601 * Also, the console device does not support this command.
603 if (hba
->cardtype
== st_shasta
|| id
== host
->max_id
- 1) {
604 stex_invalid_field(cmd
, done
);
608 case TEST_UNIT_READY
:
609 if (id
== host
->max_id
- 1) {
610 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
616 if (id
!= host
->max_id
- 1)
618 if (!lun
&& !cmd
->device
->channel
&&
619 (cmd
->cmnd
[1] & INQUIRY_EVPD
) == 0) {
620 scsi_sg_copy_from_buffer(cmd
, (void *)console_inq_page
,
621 sizeof(console_inq_page
));
622 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
625 stex_invalid_field(cmd
, done
);
628 if (cmd
->cmnd
[1] == PASSTHRU_GET_DRVVER
) {
629 struct st_drvver ver
;
630 size_t cp_len
= sizeof(ver
);
632 ver
.major
= ST_VER_MAJOR
;
633 ver
.minor
= ST_VER_MINOR
;
635 ver
.build
= ST_BUILD_VER
;
636 ver
.signature
[0] = PASSTHRU_SIGNATURE
;
637 ver
.console_id
= host
->max_id
- 1;
638 ver
.host_no
= hba
->host
->host_no
;
639 cp_len
= scsi_sg_copy_from_buffer(cmd
, &ver
, cp_len
);
640 cmd
->result
= sizeof(ver
) == cp_len
?
641 DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 :
642 DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
650 cmd
->scsi_done
= done
;
652 tag
= cmd
->request
->tag
;
654 if (unlikely(tag
>= host
->can_queue
))
655 return SCSI_MLQUEUE_HOST_BUSY
;
657 req
= hba
->alloc_rq(hba
);
663 memcpy(req
->cdb
, cmd
->cmnd
, STEX_CDB_LENGTH
);
665 if (cmd
->sc_data_direction
== DMA_FROM_DEVICE
)
666 req
->data_dir
= MSG_DATA_DIR_IN
;
667 else if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
668 req
->data_dir
= MSG_DATA_DIR_OUT
;
670 req
->data_dir
= MSG_DATA_DIR_ND
;
672 hba
->ccb
[tag
].cmd
= cmd
;
673 hba
->ccb
[tag
].sense_bufflen
= SCSI_SENSE_BUFFERSIZE
;
674 hba
->ccb
[tag
].sense_buffer
= cmd
->sense_buffer
;
676 if (!hba
->map_sg(hba
, req
, &hba
->ccb
[tag
])) {
677 hba
->ccb
[tag
].sg_count
= 0;
678 memset(&req
->variable
[0], 0, 8);
681 hba
->send(hba
, req
, tag
);
685 static void stex_scsi_done(struct st_ccb
*ccb
)
687 struct scsi_cmnd
*cmd
= ccb
->cmd
;
690 if (ccb
->srb_status
== SRB_STATUS_SUCCESS
|| ccb
->srb_status
== 0) {
691 result
= ccb
->scsi_status
;
692 switch (ccb
->scsi_status
) {
694 result
|= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
696 case SAM_STAT_CHECK_CONDITION
:
697 result
|= DRIVER_SENSE
<< 24;
700 result
|= DID_BUS_BUSY
<< 16 | COMMAND_COMPLETE
<< 8;
703 result
|= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
707 else if (ccb
->srb_status
& SRB_SEE_SENSE
)
708 result
= DRIVER_SENSE
<< 24 | SAM_STAT_CHECK_CONDITION
;
709 else switch (ccb
->srb_status
) {
710 case SRB_STATUS_SELECTION_TIMEOUT
:
711 result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
713 case SRB_STATUS_BUSY
:
714 result
= DID_BUS_BUSY
<< 16 | COMMAND_COMPLETE
<< 8;
716 case SRB_STATUS_INVALID_REQUEST
:
717 case SRB_STATUS_ERROR
:
719 result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
723 cmd
->result
= result
;
727 static void stex_copy_data(struct st_ccb
*ccb
,
728 struct status_msg
*resp
, unsigned int variable
)
730 if (resp
->scsi_status
!= SAM_STAT_GOOD
) {
731 if (ccb
->sense_buffer
!= NULL
)
732 memcpy(ccb
->sense_buffer
, resp
->variable
,
733 min(variable
, ccb
->sense_bufflen
));
737 if (ccb
->cmd
== NULL
)
739 scsi_sg_copy_from_buffer(ccb
->cmd
, resp
->variable
, variable
);
742 static void stex_check_cmd(struct st_hba
*hba
,
743 struct st_ccb
*ccb
, struct status_msg
*resp
)
745 if (ccb
->cmd
->cmnd
[0] == MGT_CMD
&&
746 resp
->scsi_status
!= SAM_STAT_CHECK_CONDITION
)
747 scsi_set_resid(ccb
->cmd
, scsi_bufflen(ccb
->cmd
) -
748 le32_to_cpu(*(__le32
*)&resp
->variable
[0]));
751 static void stex_mu_intr(struct st_hba
*hba
, u32 doorbell
)
753 void __iomem
*base
= hba
->mmio_base
;
754 struct status_msg
*resp
;
759 if (unlikely(!(doorbell
& MU_OUTBOUND_DOORBELL_STATUSHEADCHANGED
)))
762 /* status payloads */
763 hba
->status_head
= readl(base
+ OMR1
);
764 if (unlikely(hba
->status_head
> hba
->sts_count
)) {
765 printk(KERN_WARNING DRV_NAME
"(%s): invalid status head\n",
766 pci_name(hba
->pdev
));
771 * it's not a valid status payload if:
772 * 1. there are no pending requests(e.g. during init stage)
773 * 2. there are some pending requests, but the controller is in
774 * reset status, and its type is not st_yosemite
775 * firmware of st_yosemite in reset status will return pending requests
776 * to driver, so we allow it to pass
778 if (unlikely(hba
->out_req_cnt
<= 0 ||
779 (hba
->mu_status
== MU_STATE_RESETTING
&&
780 hba
->cardtype
!= st_yosemite
))) {
781 hba
->status_tail
= hba
->status_head
;
785 while (hba
->status_tail
!= hba
->status_head
) {
786 resp
= stex_get_status(hba
);
787 tag
= le16_to_cpu(resp
->tag
);
788 if (unlikely(tag
>= hba
->host
->can_queue
)) {
789 printk(KERN_WARNING DRV_NAME
790 "(%s): invalid tag\n", pci_name(hba
->pdev
));
795 ccb
= &hba
->ccb
[tag
];
796 if (unlikely(hba
->wait_ccb
== ccb
))
797 hba
->wait_ccb
= NULL
;
798 if (unlikely(ccb
->req
== NULL
)) {
799 printk(KERN_WARNING DRV_NAME
800 "(%s): lagging req\n", pci_name(hba
->pdev
));
804 size
= resp
->payload_sz
* sizeof(u32
); /* payload size */
805 if (unlikely(size
< sizeof(*resp
) - STATUS_VAR_LEN
||
806 size
> sizeof(*resp
))) {
807 printk(KERN_WARNING DRV_NAME
"(%s): bad status size\n",
808 pci_name(hba
->pdev
));
810 size
-= sizeof(*resp
) - STATUS_VAR_LEN
; /* copy size */
812 stex_copy_data(ccb
, resp
, size
);
816 ccb
->srb_status
= resp
->srb_status
;
817 ccb
->scsi_status
= resp
->scsi_status
;
819 if (likely(ccb
->cmd
!= NULL
)) {
820 if (hba
->cardtype
== st_yosemite
)
821 stex_check_cmd(hba
, ccb
, resp
);
823 if (unlikely(ccb
->cmd
->cmnd
[0] == PASSTHRU_CMD
&&
824 ccb
->cmd
->cmnd
[1] == PASSTHRU_GET_ADAPTER
))
825 stex_controller_info(hba
, ccb
);
827 scsi_dma_unmap(ccb
->cmd
);
834 writel(hba
->status_head
, base
+ IMR1
);
835 readl(base
+ IMR1
); /* flush */
838 static irqreturn_t
stex_intr(int irq
, void *__hba
)
840 struct st_hba
*hba
= __hba
;
841 void __iomem
*base
= hba
->mmio_base
;
846 spin_lock_irqsave(hba
->host
->host_lock
, flags
);
848 data
= readl(base
+ ODBL
);
850 if (data
&& data
!= 0xffffffff) {
851 /* clear the interrupt */
852 writel(data
, base
+ ODBL
);
853 readl(base
+ ODBL
); /* flush */
854 stex_mu_intr(hba
, data
);
858 spin_unlock_irqrestore(hba
->host
->host_lock
, flags
);
860 return IRQ_RETVAL(handled
);
863 static void stex_ss_mu_intr(struct st_hba
*hba
)
865 struct status_msg
*resp
;
873 if (unlikely(hba
->out_req_cnt
<= 0 ||
874 hba
->mu_status
== MU_STATE_RESETTING
))
877 while (count
< hba
->sts_count
) {
878 scratch
= hba
->scratch
+ hba
->status_tail
;
879 value
= le32_to_cpu(*scratch
);
880 if (unlikely(!(value
& SS_STS_NORMAL
)))
883 resp
= hba
->status_buffer
+ hba
->status_tail
;
887 hba
->status_tail
%= hba
->sts_count
+1;
890 if (unlikely(tag
>= hba
->host
->can_queue
)) {
891 printk(KERN_WARNING DRV_NAME
892 "(%s): invalid tag\n", pci_name(hba
->pdev
));
897 ccb
= &hba
->ccb
[tag
];
898 if (unlikely(hba
->wait_ccb
== ccb
))
899 hba
->wait_ccb
= NULL
;
900 if (unlikely(ccb
->req
== NULL
)) {
901 printk(KERN_WARNING DRV_NAME
902 "(%s): lagging req\n", pci_name(hba
->pdev
));
907 if (likely(value
& SS_STS_DONE
)) { /* normal case */
908 ccb
->srb_status
= SRB_STATUS_SUCCESS
;
909 ccb
->scsi_status
= SAM_STAT_GOOD
;
911 ccb
->srb_status
= resp
->srb_status
;
912 ccb
->scsi_status
= resp
->scsi_status
;
913 size
= resp
->payload_sz
* sizeof(u32
);
914 if (unlikely(size
< sizeof(*resp
) - STATUS_VAR_LEN
||
915 size
> sizeof(*resp
))) {
916 printk(KERN_WARNING DRV_NAME
917 "(%s): bad status size\n",
918 pci_name(hba
->pdev
));
920 size
-= sizeof(*resp
) - STATUS_VAR_LEN
;
922 stex_copy_data(ccb
, resp
, size
);
924 if (likely(ccb
->cmd
!= NULL
))
925 stex_check_cmd(hba
, ccb
, resp
);
928 if (likely(ccb
->cmd
!= NULL
)) {
929 scsi_dma_unmap(ccb
->cmd
);
936 static irqreturn_t
stex_ss_intr(int irq
, void *__hba
)
938 struct st_hba
*hba
= __hba
;
939 void __iomem
*base
= hba
->mmio_base
;
944 spin_lock_irqsave(hba
->host
->host_lock
, flags
);
946 data
= readl(base
+ YI2H_INT
);
947 if (data
&& data
!= 0xffffffff) {
948 /* clear the interrupt */
949 writel(data
, base
+ YI2H_INT_C
);
950 stex_ss_mu_intr(hba
);
954 spin_unlock_irqrestore(hba
->host
->host_lock
, flags
);
956 return IRQ_RETVAL(handled
);
959 static int stex_common_handshake(struct st_hba
*hba
)
961 void __iomem
*base
= hba
->mmio_base
;
962 struct handshake_frame
*h
;
963 dma_addr_t status_phys
;
965 unsigned long before
;
967 if (readl(base
+ OMR0
) != MU_HANDSHAKE_SIGNATURE
) {
968 writel(MU_INBOUND_DOORBELL_HANDSHAKE
, base
+ IDBL
);
971 while (readl(base
+ OMR0
) != MU_HANDSHAKE_SIGNATURE
) {
972 if (time_after(jiffies
, before
+ MU_MAX_DELAY
* HZ
)) {
973 printk(KERN_ERR DRV_NAME
974 "(%s): no handshake signature\n",
975 pci_name(hba
->pdev
));
985 data
= readl(base
+ OMR1
);
986 if ((data
& 0xffff0000) == MU_HANDSHAKE_SIGNATURE_HALF
) {
988 if (hba
->host
->can_queue
> data
) {
989 hba
->host
->can_queue
= data
;
990 hba
->host
->cmd_per_lun
= data
;
994 h
= (struct handshake_frame
*)hba
->status_buffer
;
995 h
->rb_phy
= cpu_to_le64(hba
->dma_handle
);
996 h
->req_sz
= cpu_to_le16(hba
->rq_size
);
997 h
->req_cnt
= cpu_to_le16(hba
->rq_count
+1);
998 h
->status_sz
= cpu_to_le16(sizeof(struct status_msg
));
999 h
->status_cnt
= cpu_to_le16(hba
->sts_count
+1);
1000 stex_gettime(&h
->hosttime
);
1001 h
->partner_type
= HMU_PARTNER_TYPE
;
1002 if (hba
->extra_offset
) {
1003 h
->extra_offset
= cpu_to_le32(hba
->extra_offset
);
1004 h
->extra_size
= cpu_to_le32(ST_ADDITIONAL_MEM
);
1006 h
->extra_offset
= h
->extra_size
= 0;
1008 status_phys
= hba
->dma_handle
+ (hba
->rq_count
+1) * hba
->rq_size
;
1009 writel(status_phys
, base
+ IMR0
);
1011 writel((status_phys
>> 16) >> 16, base
+ IMR1
);
1014 writel((status_phys
>> 16) >> 16, base
+ OMR0
); /* old fw compatible */
1016 writel(MU_INBOUND_DOORBELL_HANDSHAKE
, base
+ IDBL
);
1017 readl(base
+ IDBL
); /* flush */
1021 while (readl(base
+ OMR0
) != MU_HANDSHAKE_SIGNATURE
) {
1022 if (time_after(jiffies
, before
+ MU_MAX_DELAY
* HZ
)) {
1023 printk(KERN_ERR DRV_NAME
1024 "(%s): no signature after handshake frame\n",
1025 pci_name(hba
->pdev
));
1032 writel(0, base
+ IMR0
);
1034 writel(0, base
+ OMR0
);
1036 writel(0, base
+ IMR1
);
1038 writel(0, base
+ OMR1
);
1039 readl(base
+ OMR1
); /* flush */
1043 static int stex_ss_handshake(struct st_hba
*hba
)
1045 void __iomem
*base
= hba
->mmio_base
;
1046 struct st_msg_header
*msg_h
;
1047 struct handshake_frame
*h
;
1050 unsigned long before
;
1054 while ((readl(base
+ YIOA_STATUS
) & SS_MU_OPERATIONAL
) == 0) {
1055 if (time_after(jiffies
, before
+ MU_MAX_DELAY
* HZ
)) {
1056 printk(KERN_ERR DRV_NAME
1057 "(%s): firmware not operational\n",
1058 pci_name(hba
->pdev
));
1064 msg_h
= (struct st_msg_header
*)hba
->dma_mem
;
1065 msg_h
->handle
= cpu_to_le64(hba
->dma_handle
);
1066 msg_h
->flag
= SS_HEAD_HANDSHAKE
;
1068 h
= (struct handshake_frame
*)(msg_h
+ 1);
1069 h
->rb_phy
= cpu_to_le64(hba
->dma_handle
);
1070 h
->req_sz
= cpu_to_le16(hba
->rq_size
);
1071 h
->req_cnt
= cpu_to_le16(hba
->rq_count
+1);
1072 h
->status_sz
= cpu_to_le16(sizeof(struct status_msg
));
1073 h
->status_cnt
= cpu_to_le16(hba
->sts_count
+1);
1074 stex_gettime(&h
->hosttime
);
1075 h
->partner_type
= HMU_PARTNER_TYPE
;
1076 h
->extra_offset
= h
->extra_size
= 0;
1077 h
->scratch_size
= cpu_to_le32((hba
->sts_count
+1)*sizeof(u32
));
1079 data
= readl(base
+ YINT_EN
);
1081 writel(data
, base
+ YINT_EN
);
1082 writel((hba
->dma_handle
>> 16) >> 16, base
+ YH2I_REQ_HI
);
1083 writel(hba
->dma_handle
, base
+ YH2I_REQ
);
1085 scratch
= hba
->scratch
;
1087 while (!(le32_to_cpu(*scratch
) & SS_STS_HANDSHAKE
)) {
1088 if (time_after(jiffies
, before
+ MU_MAX_DELAY
* HZ
)) {
1089 printk(KERN_ERR DRV_NAME
1090 "(%s): no signature after handshake frame\n",
1091 pci_name(hba
->pdev
));
1104 static int stex_handshake(struct st_hba
*hba
)
1107 unsigned long flags
;
1109 err
= (hba
->cardtype
== st_yel
) ?
1110 stex_ss_handshake(hba
) : stex_common_handshake(hba
);
1112 spin_lock_irqsave(hba
->host
->host_lock
, flags
);
1115 hba
->status_head
= 0;
1116 hba
->status_tail
= 0;
1117 hba
->out_req_cnt
= 0;
1118 hba
->mu_status
= MU_STATE_STARTED
;
1119 spin_unlock_irqrestore(hba
->host
->host_lock
, flags
);
1124 static int stex_abort(struct scsi_cmnd
*cmd
)
1126 struct Scsi_Host
*host
= cmd
->device
->host
;
1127 struct st_hba
*hba
= (struct st_hba
*)host
->hostdata
;
1128 u16 tag
= cmd
->request
->tag
;
1131 int result
= SUCCESS
;
1132 unsigned long flags
;
1134 printk(KERN_INFO DRV_NAME
1135 "(%s): aborting command\n", pci_name(hba
->pdev
));
1136 scsi_print_command(cmd
);
1138 base
= hba
->mmio_base
;
1139 spin_lock_irqsave(host
->host_lock
, flags
);
1140 if (tag
< host
->can_queue
&& hba
->ccb
[tag
].cmd
== cmd
)
1141 hba
->wait_ccb
= &hba
->ccb
[tag
];
1143 for (tag
= 0; tag
< host
->can_queue
; tag
++)
1144 if (hba
->ccb
[tag
].cmd
== cmd
) {
1145 hba
->wait_ccb
= &hba
->ccb
[tag
];
1148 if (tag
>= host
->can_queue
)
1152 if (hba
->cardtype
== st_yel
) {
1153 data
= readl(base
+ YI2H_INT
);
1154 if (data
== 0 || data
== 0xffffffff)
1157 writel(data
, base
+ YI2H_INT_C
);
1158 stex_ss_mu_intr(hba
);
1160 data
= readl(base
+ ODBL
);
1161 if (data
== 0 || data
== 0xffffffff)
1164 writel(data
, base
+ ODBL
);
1165 readl(base
+ ODBL
); /* flush */
1167 stex_mu_intr(hba
, data
);
1169 if (hba
->wait_ccb
== NULL
) {
1170 printk(KERN_WARNING DRV_NAME
1171 "(%s): lost interrupt\n", pci_name(hba
->pdev
));
1176 scsi_dma_unmap(cmd
);
1177 hba
->wait_ccb
->req
= NULL
; /* nullify the req's future return */
1178 hba
->wait_ccb
= NULL
;
1181 spin_unlock_irqrestore(host
->host_lock
, flags
);
1185 static void stex_hard_reset(struct st_hba
*hba
)
1187 struct pci_bus
*bus
;
1192 for (i
= 0; i
< 16; i
++)
1193 pci_read_config_dword(hba
->pdev
, i
* 4,
1194 &hba
->pdev
->saved_config_space
[i
]);
1196 /* Reset secondary bus. Our controller(MU/ATU) is the only device on
1197 secondary bus. Consult Intel 80331/3 developer's manual for detail */
1198 bus
= hba
->pdev
->bus
;
1199 pci_read_config_byte(bus
->self
, PCI_BRIDGE_CONTROL
, &pci_bctl
);
1200 pci_bctl
|= PCI_BRIDGE_CTL_BUS_RESET
;
1201 pci_write_config_byte(bus
->self
, PCI_BRIDGE_CONTROL
, pci_bctl
);
1204 * 1 ms may be enough for 8-port controllers. But 16-port controllers
1205 * require more time to finish bus reset. Use 100 ms here for safety
1208 pci_bctl
&= ~PCI_BRIDGE_CTL_BUS_RESET
;
1209 pci_write_config_byte(bus
->self
, PCI_BRIDGE_CONTROL
, pci_bctl
);
1211 for (i
= 0; i
< MU_HARD_RESET_WAIT
; i
++) {
1212 pci_read_config_word(hba
->pdev
, PCI_COMMAND
, &pci_cmd
);
1213 if (pci_cmd
!= 0xffff && (pci_cmd
& PCI_COMMAND_MASTER
))
1219 for (i
= 0; i
< 16; i
++)
1220 pci_write_config_dword(hba
->pdev
, i
* 4,
1221 hba
->pdev
->saved_config_space
[i
]);
1224 static void stex_ss_reset(struct st_hba
*hba
)
1226 writel(SS_H2I_INT_RESET
, hba
->mmio_base
+ YH2I_INT
);
1227 readl(hba
->mmio_base
+ YH2I_INT
);
1231 static int stex_reset(struct scsi_cmnd
*cmd
)
1235 unsigned long flags
, before
;
1237 hba
= (struct st_hba
*) &cmd
->device
->host
->hostdata
[0];
1239 printk(KERN_INFO DRV_NAME
1240 "(%s): resetting host\n", pci_name(hba
->pdev
));
1241 scsi_print_command(cmd
);
1243 hba
->mu_status
= MU_STATE_RESETTING
;
1245 if (hba
->cardtype
== st_shasta
)
1246 stex_hard_reset(hba
);
1247 else if (hba
->cardtype
== st_yel
)
1250 if (hba
->cardtype
!= st_yosemite
) {
1251 if (stex_handshake(hba
)) {
1252 printk(KERN_WARNING DRV_NAME
1253 "(%s): resetting: handshake failed\n",
1254 pci_name(hba
->pdev
));
1261 writel(MU_INBOUND_DOORBELL_RESET
, hba
->mmio_base
+ IDBL
);
1262 readl(hba
->mmio_base
+ IDBL
); /* flush */
1264 while (hba
->out_req_cnt
> 0) {
1265 if (time_after(jiffies
, before
+ ST_INTERNAL_TIMEOUT
* HZ
)) {
1266 printk(KERN_WARNING DRV_NAME
1267 "(%s): reset timeout\n", pci_name(hba
->pdev
));
1273 base
= hba
->mmio_base
;
1274 writel(0, base
+ IMR0
);
1276 writel(0, base
+ OMR0
);
1278 writel(0, base
+ IMR1
);
1280 writel(0, base
+ OMR1
);
1281 readl(base
+ OMR1
); /* flush */
1282 spin_lock_irqsave(hba
->host
->host_lock
, flags
);
1285 hba
->status_head
= 0;
1286 hba
->status_tail
= 0;
1287 hba
->out_req_cnt
= 0;
1288 hba
->mu_status
= MU_STATE_STARTED
;
1289 spin_unlock_irqrestore(hba
->host
->host_lock
, flags
);
1293 static int stex_biosparam(struct scsi_device
*sdev
,
1294 struct block_device
*bdev
, sector_t capacity
, int geom
[])
1296 int heads
= 255, sectors
= 63;
1298 if (capacity
< 0x200000) {
1303 sector_div(capacity
, heads
* sectors
);
1312 static struct scsi_host_template driver_template
= {
1313 .module
= THIS_MODULE
,
1315 .proc_name
= DRV_NAME
,
1316 .bios_param
= stex_biosparam
,
1317 .queuecommand
= stex_queuecommand
,
1318 .slave_alloc
= stex_slave_alloc
,
1319 .slave_configure
= stex_slave_config
,
1320 .slave_destroy
= stex_slave_destroy
,
1321 .eh_abort_handler
= stex_abort
,
1322 .eh_host_reset_handler
= stex_reset
,
1326 static struct pci_device_id stex_pci_tbl
[] = {
1328 { 0x105a, 0x8350, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
1329 st_shasta
}, /* SuperTrak EX8350/8300/16350/16300 */
1330 { 0x105a, 0xc350, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
1331 st_shasta
}, /* SuperTrak EX12350 */
1332 { 0x105a, 0x4302, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
1333 st_shasta
}, /* SuperTrak EX4350 */
1334 { 0x105a, 0xe350, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
1335 st_shasta
}, /* SuperTrak EX24350 */
1338 { 0x105a, 0x7250, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, st_vsc
},
1341 { 0x105a, 0x8650, 0x105a, PCI_ANY_ID
, 0, 0, st_yosemite
},
1344 { 0x105a, 0x3360, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, st_seq
},
1347 { 0x105a, 0x8650, 0x1033, PCI_ANY_ID
, 0, 0, st_yel
},
1348 { 0x105a, 0x8760, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, st_yel
},
1349 { } /* terminate list */
1352 static struct st_card_info stex_card_info
[] = {
1361 .alloc_rq
= stex_alloc_req
,
1362 .map_sg
= stex_map_sg
,
1363 .send
= stex_send_cmd
,
1374 .alloc_rq
= stex_alloc_req
,
1375 .map_sg
= stex_map_sg
,
1376 .send
= stex_send_cmd
,
1387 .alloc_rq
= stex_alloc_req
,
1388 .map_sg
= stex_map_sg
,
1389 .send
= stex_send_cmd
,
1400 .alloc_rq
= stex_alloc_req
,
1401 .map_sg
= stex_map_sg
,
1402 .send
= stex_send_cmd
,
1413 .alloc_rq
= stex_ss_alloc_req
,
1414 .map_sg
= stex_ss_map_sg
,
1415 .send
= stex_ss_send_cmd
,
1419 static int stex_set_dma_mask(struct pci_dev
* pdev
)
1423 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64))
1424 && !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
1426 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
1428 ret
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
1432 static int stex_request_irq(struct st_hba
*hba
)
1434 struct pci_dev
*pdev
= hba
->pdev
;
1438 status
= pci_enable_msi(pdev
);
1440 printk(KERN_ERR DRV_NAME
1441 "(%s): error %d setting up MSI\n",
1442 pci_name(pdev
), status
);
1444 hba
->msi_enabled
= 1;
1446 hba
->msi_enabled
= 0;
1448 status
= request_irq(pdev
->irq
, hba
->cardtype
== st_yel
?
1449 stex_ss_intr
: stex_intr
, IRQF_SHARED
, DRV_NAME
, hba
);
1452 if (hba
->msi_enabled
)
1453 pci_disable_msi(pdev
);
1458 static void stex_free_irq(struct st_hba
*hba
)
1460 struct pci_dev
*pdev
= hba
->pdev
;
1462 free_irq(pdev
->irq
, hba
);
1463 if (hba
->msi_enabled
)
1464 pci_disable_msi(pdev
);
1467 static int __devinit
1468 stex_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1471 struct Scsi_Host
*host
;
1472 const struct st_card_info
*ci
= NULL
;
1473 u32 sts_offset
, cp_offset
, scratch_offset
;
1476 err
= pci_enable_device(pdev
);
1480 pci_set_master(pdev
);
1482 host
= scsi_host_alloc(&driver_template
, sizeof(struct st_hba
));
1485 printk(KERN_ERR DRV_NAME
"(%s): scsi_host_alloc failed\n",
1491 hba
= (struct st_hba
*)host
->hostdata
;
1492 memset(hba
, 0, sizeof(struct st_hba
));
1494 err
= pci_request_regions(pdev
, DRV_NAME
);
1496 printk(KERN_ERR DRV_NAME
"(%s): request regions failed\n",
1498 goto out_scsi_host_put
;
1501 hba
->mmio_base
= pci_ioremap_bar(pdev
, 0);
1502 if ( !hba
->mmio_base
) {
1503 printk(KERN_ERR DRV_NAME
"(%s): memory map failed\n",
1506 goto out_release_regions
;
1509 err
= stex_set_dma_mask(pdev
);
1511 printk(KERN_ERR DRV_NAME
"(%s): set dma mask failed\n",
1516 hba
->cardtype
= (unsigned int) id
->driver_data
;
1517 ci
= &stex_card_info
[hba
->cardtype
];
1518 sts_offset
= scratch_offset
= (ci
->rq_count
+1) * ci
->rq_size
;
1519 if (hba
->cardtype
== st_yel
)
1520 sts_offset
+= (ci
->sts_count
+1) * sizeof(u32
);
1521 cp_offset
= sts_offset
+ (ci
->sts_count
+1) * sizeof(struct status_msg
);
1522 hba
->dma_size
= cp_offset
+ sizeof(struct st_frame
);
1523 if (hba
->cardtype
== st_seq
||
1524 (hba
->cardtype
== st_vsc
&& (pdev
->subsystem_device
& 1))) {
1525 hba
->extra_offset
= hba
->dma_size
;
1526 hba
->dma_size
+= ST_ADDITIONAL_MEM
;
1528 hba
->dma_mem
= dma_alloc_coherent(&pdev
->dev
,
1529 hba
->dma_size
, &hba
->dma_handle
, GFP_KERNEL
);
1530 if (!hba
->dma_mem
) {
1532 printk(KERN_ERR DRV_NAME
"(%s): dma mem alloc failed\n",
1537 hba
->ccb
= kcalloc(ci
->rq_count
, sizeof(struct st_ccb
), GFP_KERNEL
);
1540 printk(KERN_ERR DRV_NAME
"(%s): ccb alloc failed\n",
1545 if (hba
->cardtype
== st_yel
)
1546 hba
->scratch
= (__le32
*)(hba
->dma_mem
+ scratch_offset
);
1547 hba
->status_buffer
= (struct status_msg
*)(hba
->dma_mem
+ sts_offset
);
1548 hba
->copy_buffer
= hba
->dma_mem
+ cp_offset
;
1549 hba
->rq_count
= ci
->rq_count
;
1550 hba
->rq_size
= ci
->rq_size
;
1551 hba
->sts_count
= ci
->sts_count
;
1552 hba
->alloc_rq
= ci
->alloc_rq
;
1553 hba
->map_sg
= ci
->map_sg
;
1554 hba
->send
= ci
->send
;
1555 hba
->mu_status
= MU_STATE_STARTING
;
1557 if (hba
->cardtype
== st_yel
)
1558 host
->sg_tablesize
= 38;
1560 host
->sg_tablesize
= 32;
1561 host
->can_queue
= ci
->rq_count
;
1562 host
->cmd_per_lun
= ci
->rq_count
;
1563 host
->max_id
= ci
->max_id
;
1564 host
->max_lun
= ci
->max_lun
;
1565 host
->max_channel
= ci
->max_channel
;
1566 host
->unique_id
= host
->host_no
;
1567 host
->max_cmd_len
= STEX_CDB_LENGTH
;
1572 err
= stex_request_irq(hba
);
1574 printk(KERN_ERR DRV_NAME
"(%s): request irq failed\n",
1579 err
= stex_handshake(hba
);
1583 err
= scsi_init_shared_tag_map(host
, host
->can_queue
);
1585 printk(KERN_ERR DRV_NAME
"(%s): init shared queue failed\n",
1590 pci_set_drvdata(pdev
, hba
);
1592 err
= scsi_add_host(host
, &pdev
->dev
);
1594 printk(KERN_ERR DRV_NAME
"(%s): scsi_add_host failed\n",
1599 scsi_scan_host(host
);
1608 dma_free_coherent(&pdev
->dev
, hba
->dma_size
,
1609 hba
->dma_mem
, hba
->dma_handle
);
1611 iounmap(hba
->mmio_base
);
1612 out_release_regions
:
1613 pci_release_regions(pdev
);
1615 scsi_host_put(host
);
1617 pci_disable_device(pdev
);
1622 static void stex_hba_stop(struct st_hba
*hba
)
1624 struct req_msg
*req
;
1625 struct st_msg_header
*msg_h
;
1626 unsigned long flags
;
1627 unsigned long before
;
1630 spin_lock_irqsave(hba
->host
->host_lock
, flags
);
1631 req
= hba
->alloc_rq(hba
);
1632 if (hba
->cardtype
== st_yel
) {
1633 msg_h
= (struct st_msg_header
*)req
- 1;
1634 memset(msg_h
, 0, hba
->rq_size
);
1636 memset(req
, 0, hba
->rq_size
);
1638 if (hba
->cardtype
== st_yosemite
|| hba
->cardtype
== st_yel
) {
1639 req
->cdb
[0] = MGT_CMD
;
1640 req
->cdb
[1] = MGT_CMD_SIGNATURE
;
1641 req
->cdb
[2] = CTLR_CONFIG_CMD
;
1642 req
->cdb
[3] = CTLR_SHUTDOWN
;
1644 req
->cdb
[0] = CONTROLLER_CMD
;
1645 req
->cdb
[1] = CTLR_POWER_STATE_CHANGE
;
1646 req
->cdb
[2] = CTLR_POWER_SAVING
;
1649 hba
->ccb
[tag
].cmd
= NULL
;
1650 hba
->ccb
[tag
].sg_count
= 0;
1651 hba
->ccb
[tag
].sense_bufflen
= 0;
1652 hba
->ccb
[tag
].sense_buffer
= NULL
;
1653 hba
->ccb
[tag
].req_type
= PASSTHRU_REQ_TYPE
;
1655 hba
->send(hba
, req
, tag
);
1656 spin_unlock_irqrestore(hba
->host
->host_lock
, flags
);
1659 while (hba
->ccb
[tag
].req_type
& PASSTHRU_REQ_TYPE
) {
1660 if (time_after(jiffies
, before
+ ST_INTERNAL_TIMEOUT
* HZ
)) {
1661 hba
->ccb
[tag
].req_type
= 0;
1668 static void stex_hba_free(struct st_hba
*hba
)
1672 iounmap(hba
->mmio_base
);
1674 pci_release_regions(hba
->pdev
);
1678 dma_free_coherent(&hba
->pdev
->dev
, hba
->dma_size
,
1679 hba
->dma_mem
, hba
->dma_handle
);
1682 static void stex_remove(struct pci_dev
*pdev
)
1684 struct st_hba
*hba
= pci_get_drvdata(pdev
);
1686 scsi_remove_host(hba
->host
);
1688 pci_set_drvdata(pdev
, NULL
);
1694 scsi_host_put(hba
->host
);
1696 pci_disable_device(pdev
);
1699 static void stex_shutdown(struct pci_dev
*pdev
)
1701 struct st_hba
*hba
= pci_get_drvdata(pdev
);
1706 MODULE_DEVICE_TABLE(pci
, stex_pci_tbl
);
1708 static struct pci_driver stex_pci_driver
= {
1710 .id_table
= stex_pci_tbl
,
1711 .probe
= stex_probe
,
1712 .remove
= __devexit_p(stex_remove
),
1713 .shutdown
= stex_shutdown
,
1716 static int __init
stex_init(void)
1718 printk(KERN_INFO DRV_NAME
1719 ": Promise SuperTrak EX Driver version: %s\n",
1722 return pci_register_driver(&stex_pci_driver
);
1725 static void __exit
stex_exit(void)
1727 pci_unregister_driver(&stex_pci_driver
);
1730 module_init(stex_init
);
1731 module_exit(stex_exit
);