2 * SuperTrak EX Series Storage Controller driver for Linux
4 * Copyright (C) 2005-2015 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/slab.h>
21 #include <linux/time.h>
22 #include <linux/pci.h>
23 #include <linux/blkdev.h>
24 #include <linux/interrupt.h>
25 #include <linux/types.h>
26 #include <linux/module.h>
27 #include <linux/spinlock.h>
28 #include <linux/ktime.h>
31 #include <asm/byteorder.h>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_cmnd.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_tcq.h>
37 #include <scsi/scsi_dbg.h>
38 #include <scsi/scsi_eh.h>
40 #define DRV_NAME "stex"
41 #define ST_DRIVER_VERSION "5.00.0000.01"
42 #define ST_VER_MAJOR 5
43 #define ST_VER_MINOR 00
45 #define ST_BUILD_VER 01
48 /* MU register offset */
49 IMR0 = 0x10, /* MU_INBOUND_MESSAGE_REG0 */
50 IMR1 = 0x14, /* MU_INBOUND_MESSAGE_REG1 */
51 OMR0 = 0x18, /* MU_OUTBOUND_MESSAGE_REG0 */
52 OMR1 = 0x1c, /* MU_OUTBOUND_MESSAGE_REG1 */
53 IDBL = 0x20, /* MU_INBOUND_DOORBELL */
54 IIS = 0x24, /* MU_INBOUND_INTERRUPT_STATUS */
55 IIM = 0x28, /* MU_INBOUND_INTERRUPT_MASK */
56 ODBL = 0x2c, /* MU_OUTBOUND_DOORBELL */
57 OIS = 0x30, /* MU_OUTBOUND_INTERRUPT_STATUS */
58 OIM = 0x3c, /* MU_OUTBOUND_INTERRUPT_MASK */
68 /* MU register value */
69 MU_INBOUND_DOORBELL_HANDSHAKE = (1 << 0),
70 MU_INBOUND_DOORBELL_REQHEADCHANGED = (1 << 1),
71 MU_INBOUND_DOORBELL_STATUSTAILCHANGED = (1 << 2),
72 MU_INBOUND_DOORBELL_HMUSTOPPED = (1 << 3),
73 MU_INBOUND_DOORBELL_RESET = (1 << 4),
75 MU_OUTBOUND_DOORBELL_HANDSHAKE = (1 << 0),
76 MU_OUTBOUND_DOORBELL_REQUESTTAILCHANGED = (1 << 1),
77 MU_OUTBOUND_DOORBELL_STATUSHEADCHANGED = (1 << 2),
78 MU_OUTBOUND_DOORBELL_BUSCHANGE = (1 << 3),
79 MU_OUTBOUND_DOORBELL_HASEVENT = (1 << 4),
80 MU_OUTBOUND_DOORBELL_REQUEST_RESET = (1 << 27),
83 MU_STATE_STARTING = 1,
85 MU_STATE_RESETTING = 3,
88 MU_STATE_NOCONNECT = 6,
91 MU_HANDSHAKE_SIGNATURE = 0x55aaaa55,
92 MU_HANDSHAKE_SIGNATURE_HALF = 0x5a5a0000,
93 MU_HARD_RESET_WAIT = 30000,
96 /* firmware returned values */
97 SRB_STATUS_SUCCESS = 0x01,
98 SRB_STATUS_ERROR = 0x04,
99 SRB_STATUS_BUSY = 0x05,
100 SRB_STATUS_INVALID_REQUEST = 0x06,
101 SRB_STATUS_SELECTION_TIMEOUT = 0x0A,
102 SRB_SEE_SENSE = 0x80,
105 TASK_ATTRIBUTE_SIMPLE = 0x0,
106 TASK_ATTRIBUTE_HEADOFQUEUE = 0x1,
107 TASK_ATTRIBUTE_ORDERED = 0x2,
108 TASK_ATTRIBUTE_ACA = 0x4,
110 SS_STS_NORMAL = 0x80000000,
111 SS_STS_DONE = 0x40000000,
112 SS_STS_HANDSHAKE = 0x20000000,
114 SS_HEAD_HANDSHAKE = 0x80,
116 SS_H2I_INT_RESET = 0x100,
118 SS_I2H_REQUEST_RESET = 0x2000,
120 SS_MU_OPERATIONAL = 0x80000000,
122 STEX_CDB_LENGTH = 16,
123 STATUS_VAR_LEN = 128,
126 SG_CF_EOT = 0x80, /* end of table */
127 SG_CF_64B = 0x40, /* 64 bit item */
128 SG_CF_HOST = 0x20, /* sg in host memory */
131 MSG_DATA_DIR_OUT = 2,
139 PASSTHRU_REQ_TYPE = 0x00000001,
140 PASSTHRU_REQ_NO_WAKEUP = 0x00000100,
141 ST_INTERNAL_TIMEOUT = 180,
146 /* vendor specific commands of Promise */
148 SINBAND_MGT_CMD = 0xd9,
150 CONTROLLER_CMD = 0xe1,
151 DEBUGGING_CMD = 0xe2,
154 PASSTHRU_GET_ADAPTER = 0x05,
155 PASSTHRU_GET_DRVVER = 0x10,
157 CTLR_CONFIG_CMD = 0x03,
158 CTLR_SHUTDOWN = 0x0d,
160 CTLR_POWER_STATE_CHANGE = 0x0e,
161 CTLR_POWER_SAVING = 0x01,
163 PASSTHRU_SIGNATURE = 0x4e415041,
164 MGT_CMD_SIGNATURE = 0xba,
168 ST_ADDITIONAL_MEM = 0x200000,
169 ST_ADDITIONAL_MEM_MIN = 0x80000,
173 u8 ctrl; /* SG_CF_xxx */
179 struct st_ss_sgitem {
191 struct st_msg_header {
199 struct handshake_frame {
200 __le64 rb_phy; /* request payload queue physical address */
201 __le16 req_sz; /* size of each request payload */
202 __le16 req_cnt; /* count of reqs the buffer can hold */
203 __le16 status_sz; /* size of each status payload */
204 __le16 status_cnt; /* count of status the buffer can hold */
205 __le64 hosttime; /* seconds from Jan 1, 1970 (GMT) */
206 u8 partner_type; /* who sends this frame */
208 __le32 partner_ver_major;
209 __le32 partner_ver_minor;
210 __le32 partner_ver_oem;
211 __le32 partner_ver_build;
212 __le32 extra_offset; /* NEW */
213 __le32 extra_size; /* NEW */
225 u8 payload_sz; /* payload size in 4-byte, not used */
226 u8 cdb[STEX_CDB_LENGTH];
237 u8 payload_sz; /* payload size in 4-byte */
238 u8 variable[STATUS_VAR_LEN];
253 struct ver_info drv_ver;
254 struct ver_info bios_ver;
285 struct scsi_cmnd *cmd;
288 unsigned int sense_bufflen;
298 void __iomem *mmio_base; /* iomapped PCI memory space */
300 dma_addr_t dma_handle;
303 struct Scsi_Host *host;
304 struct pci_dev *pdev;
306 struct req_msg * (*alloc_rq) (struct st_hba *);
307 int (*map_sg)(struct st_hba *, struct req_msg *, struct st_ccb *);
308 void (*send) (struct st_hba *, struct req_msg *, u16);
315 struct status_msg *status_buffer;
316 void *copy_buffer; /* temp buffer for driver-handled commands */
318 struct st_ccb *wait_ccb;
321 char work_q_name[20];
322 struct workqueue_struct *work_q;
323 struct work_struct reset_work;
324 wait_queue_head_t reset_waitq;
325 unsigned int mu_status;
326 unsigned int cardtype;
336 struct st_card_info {
337 struct req_msg * (*alloc_rq) (struct st_hba *);
338 int (*map_sg)(struct st_hba *, struct req_msg *, struct st_ccb *);
339 void (*send) (struct st_hba *, struct req_msg *, u16);
341 unsigned int max_lun;
342 unsigned int max_channel;
349 module_param(msi, int, 0);
350 MODULE_PARM_DESC(msi, "Enable Message Signaled Interrupts(0=off, 1=on)");
352 static const char console_inq_page[] =
354 0x03,0x00,0x03,0x03,0xFA,0x00,0x00,0x30,
355 0x50,0x72,0x6F,0x6D,0x69,0x73,0x65,0x20, /* "Promise " */
356 0x52,0x41,0x49,0x44,0x20,0x43,0x6F,0x6E, /* "RAID Con" */
357 0x73,0x6F,0x6C,0x65,0x20,0x20,0x20,0x20, /* "sole " */
358 0x31,0x2E,0x30,0x30,0x20,0x20,0x20,0x20, /* "1.00 " */
359 0x53,0x58,0x2F,0x52,0x53,0x41,0x46,0x2D, /* "SX/RSAF-" */
360 0x54,0x45,0x31,0x2E,0x30,0x30,0x20,0x20, /* "TE1.00 " */
361 0x0C,0x20,0x20,0x20,0x20,0x20,0x20,0x20
364 MODULE_AUTHOR("Ed Lin");
365 MODULE_DESCRIPTION("Promise Technology SuperTrak EX Controllers");
366 MODULE_LICENSE("GPL");
367 MODULE_VERSION(ST_DRIVER_VERSION);
369 static struct status_msg *stex_get_status(struct st_hba *hba)
371 struct status_msg *status = hba->status_buffer + hba->status_tail;
374 hba->status_tail %= hba->sts_count+1;
379 static void stex_invalid_field(struct scsi_cmnd *cmd,
380 void (*done)(struct scsi_cmnd *))
382 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
384 /* "Invalid field in cdb" */
385 scsi_build_sense_buffer(0, cmd->sense_buffer, ILLEGAL_REQUEST, 0x24,
390 static struct req_msg *stex_alloc_req(struct st_hba *hba)
392 struct req_msg *req = hba->dma_mem + hba->req_head * hba->rq_size;
395 hba->req_head %= hba->rq_count+1;
400 static struct req_msg *stex_ss_alloc_req(struct st_hba *hba)
402 return (struct req_msg *)(hba->dma_mem +
403 hba->req_head * hba->rq_size + sizeof(struct st_msg_header));
406 static int stex_map_sg(struct st_hba *hba,
407 struct req_msg *req, struct st_ccb *ccb)
409 struct scsi_cmnd *cmd;
410 struct scatterlist *sg;
411 struct st_sgtable *dst;
412 struct st_sgitem *table;
416 nseg = scsi_dma_map(cmd);
419 dst = (struct st_sgtable *)req->variable;
421 ccb->sg_count = nseg;
422 dst->sg_count = cpu_to_le16((u16)nseg);
423 dst->max_sg_count = cpu_to_le16(hba->host->sg_tablesize);
424 dst->sz_in_byte = cpu_to_le32(scsi_bufflen(cmd));
426 table = (struct st_sgitem *)(dst + 1);
427 scsi_for_each_sg(cmd, sg, nseg, i) {
428 table[i].count = cpu_to_le32((u32)sg_dma_len(sg));
429 table[i].addr = cpu_to_le64(sg_dma_address(sg));
430 table[i].ctrl = SG_CF_64B | SG_CF_HOST;
432 table[--i].ctrl |= SG_CF_EOT;
438 static int stex_ss_map_sg(struct st_hba *hba,
439 struct req_msg *req, struct st_ccb *ccb)
441 struct scsi_cmnd *cmd;
442 struct scatterlist *sg;
443 struct st_sgtable *dst;
444 struct st_ss_sgitem *table;
448 nseg = scsi_dma_map(cmd);
451 dst = (struct st_sgtable *)req->variable;
453 ccb->sg_count = nseg;
454 dst->sg_count = cpu_to_le16((u16)nseg);
455 dst->max_sg_count = cpu_to_le16(hba->host->sg_tablesize);
456 dst->sz_in_byte = cpu_to_le32(scsi_bufflen(cmd));
458 table = (struct st_ss_sgitem *)(dst + 1);
459 scsi_for_each_sg(cmd, sg, nseg, i) {
460 table[i].count = cpu_to_le32((u32)sg_dma_len(sg));
462 cpu_to_le32(sg_dma_address(sg) & 0xffffffff);
464 cpu_to_le32((sg_dma_address(sg) >> 16) >> 16);
471 static void stex_controller_info(struct st_hba *hba, struct st_ccb *ccb)
474 size_t count = sizeof(struct st_frame);
476 p = hba->copy_buffer;
477 scsi_sg_copy_to_buffer(ccb->cmd, p, count);
478 memset(p->base, 0, sizeof(u32)*6);
479 *(unsigned long *)(p->base) = pci_resource_start(hba->pdev, 0);
482 p->drv_ver.major = ST_VER_MAJOR;
483 p->drv_ver.minor = ST_VER_MINOR;
484 p->drv_ver.oem = ST_OEM;
485 p->drv_ver.build = ST_BUILD_VER;
487 p->bus = hba->pdev->bus->number;
488 p->slot = hba->pdev->devfn;
490 p->irq_vec = hba->pdev->irq;
491 p->id = hba->pdev->vendor << 16 | hba->pdev->device;
493 hba->pdev->subsystem_vendor << 16 | hba->pdev->subsystem_device;
495 scsi_sg_copy_from_buffer(ccb->cmd, p, count);
499 stex_send_cmd(struct st_hba *hba, struct req_msg *req, u16 tag)
501 req->tag = cpu_to_le16(tag);
503 hba->ccb[tag].req = req;
506 writel(hba->req_head, hba->mmio_base + IMR0);
507 writel(MU_INBOUND_DOORBELL_REQHEADCHANGED, hba->mmio_base + IDBL);
508 readl(hba->mmio_base + IDBL); /* flush */
512 stex_ss_send_cmd(struct st_hba *hba, struct req_msg *req, u16 tag)
514 struct scsi_cmnd *cmd;
515 struct st_msg_header *msg_h;
518 req->tag = cpu_to_le16(tag);
520 hba->ccb[tag].req = req;
523 cmd = hba->ccb[tag].cmd;
524 msg_h = (struct st_msg_header *)req - 1;
526 msg_h->channel = (u8)cmd->device->channel;
527 msg_h->timeout = cpu_to_le16(cmd->request->timeout/HZ);
529 addr = hba->dma_handle + hba->req_head * hba->rq_size;
530 addr += (hba->ccb[tag].sg_count+4)/11;
531 msg_h->handle = cpu_to_le64(addr);
534 hba->req_head %= hba->rq_count+1;
536 writel((addr >> 16) >> 16, hba->mmio_base + YH2I_REQ_HI);
537 readl(hba->mmio_base + YH2I_REQ_HI); /* flush */
538 writel(addr, hba->mmio_base + YH2I_REQ);
539 readl(hba->mmio_base + YH2I_REQ); /* flush */
542 static void return_abnormal_state(struct st_hba *hba, int status)
548 spin_lock_irqsave(hba->host->host_lock, flags);
549 for (tag = 0; tag < hba->host->can_queue; tag++) {
550 ccb = &hba->ccb[tag];
551 if (ccb->req == NULL)
555 scsi_dma_unmap(ccb->cmd);
556 ccb->cmd->result = status << 16;
557 ccb->cmd->scsi_done(ccb->cmd);
561 spin_unlock_irqrestore(hba->host->host_lock, flags);
564 stex_slave_config(struct scsi_device *sdev)
566 sdev->use_10_for_rw = 1;
567 sdev->use_10_for_ms = 1;
568 blk_queue_rq_timeout(sdev->request_queue, 60 * HZ);
574 stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
577 struct Scsi_Host *host;
578 unsigned int id, lun;
582 host = cmd->device->host;
583 id = cmd->device->id;
584 lun = cmd->device->lun;
585 hba = (struct st_hba *) &host->hostdata[0];
586 if (hba->mu_status == MU_STATE_NOCONNECT) {
587 cmd->result = DID_NO_CONNECT;
591 if (unlikely(hba->mu_status != MU_STATE_STARTED))
592 return SCSI_MLQUEUE_HOST_BUSY;
594 switch (cmd->cmnd[0]) {
597 static char ms10_caching_page[12] =
598 { 0, 0x12, 0, 0, 0, 0, 0, 0, 0x8, 0xa, 0x4, 0 };
601 page = cmd->cmnd[2] & 0x3f;
602 if (page == 0x8 || page == 0x3f) {
603 scsi_sg_copy_from_buffer(cmd, ms10_caching_page,
604 sizeof(ms10_caching_page));
605 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
608 stex_invalid_field(cmd, done);
613 * The shasta firmware does not report actual luns in the
614 * target, so fail the command to force sequential lun scan.
615 * Also, the console device does not support this command.
617 if (hba->cardtype == st_shasta || id == host->max_id - 1) {
618 stex_invalid_field(cmd, done);
622 case TEST_UNIT_READY:
623 if (id == host->max_id - 1) {
624 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
630 if (lun >= host->max_lun) {
631 cmd->result = DID_NO_CONNECT << 16;
635 if (id != host->max_id - 1)
637 if (!lun && !cmd->device->channel &&
638 (cmd->cmnd[1] & INQUIRY_EVPD) == 0) {
639 scsi_sg_copy_from_buffer(cmd, (void *)console_inq_page,
640 sizeof(console_inq_page));
641 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
644 stex_invalid_field(cmd, done);
647 if (cmd->cmnd[1] == PASSTHRU_GET_DRVVER) {
648 struct st_drvver ver;
649 size_t cp_len = sizeof(ver);
651 ver.major = ST_VER_MAJOR;
652 ver.minor = ST_VER_MINOR;
654 ver.build = ST_BUILD_VER;
655 ver.signature[0] = PASSTHRU_SIGNATURE;
656 ver.console_id = host->max_id - 1;
657 ver.host_no = hba->host->host_no;
658 cp_len = scsi_sg_copy_from_buffer(cmd, &ver, cp_len);
659 cmd->result = sizeof(ver) == cp_len ?
660 DID_OK << 16 | COMMAND_COMPLETE << 8 :
661 DID_ERROR << 16 | COMMAND_COMPLETE << 8;
669 cmd->scsi_done = done;
671 tag = cmd->request->tag;
673 if (unlikely(tag >= host->can_queue))
674 return SCSI_MLQUEUE_HOST_BUSY;
676 req = hba->alloc_rq(hba);
682 memcpy(req->cdb, cmd->cmnd, STEX_CDB_LENGTH);
684 if (cmd->sc_data_direction == DMA_FROM_DEVICE)
685 req->data_dir = MSG_DATA_DIR_IN;
686 else if (cmd->sc_data_direction == DMA_TO_DEVICE)
687 req->data_dir = MSG_DATA_DIR_OUT;
689 req->data_dir = MSG_DATA_DIR_ND;
691 hba->ccb[tag].cmd = cmd;
692 hba->ccb[tag].sense_bufflen = SCSI_SENSE_BUFFERSIZE;
693 hba->ccb[tag].sense_buffer = cmd->sense_buffer;
695 if (!hba->map_sg(hba, req, &hba->ccb[tag])) {
696 hba->ccb[tag].sg_count = 0;
697 memset(&req->variable[0], 0, 8);
700 hba->send(hba, req, tag);
704 static DEF_SCSI_QCMD(stex_queuecommand)
706 static void stex_scsi_done(struct st_ccb *ccb)
708 struct scsi_cmnd *cmd = ccb->cmd;
711 if (ccb->srb_status == SRB_STATUS_SUCCESS || ccb->srb_status == 0) {
712 result = ccb->scsi_status;
713 switch (ccb->scsi_status) {
715 result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
717 case SAM_STAT_CHECK_CONDITION:
718 result |= DRIVER_SENSE << 24;
721 result |= DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
724 result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
728 else if (ccb->srb_status & SRB_SEE_SENSE)
729 result = DRIVER_SENSE << 24 | SAM_STAT_CHECK_CONDITION;
730 else switch (ccb->srb_status) {
731 case SRB_STATUS_SELECTION_TIMEOUT:
732 result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
734 case SRB_STATUS_BUSY:
735 result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
737 case SRB_STATUS_INVALID_REQUEST:
738 case SRB_STATUS_ERROR:
740 result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
744 cmd->result = result;
748 static void stex_copy_data(struct st_ccb *ccb,
749 struct status_msg *resp, unsigned int variable)
751 if (resp->scsi_status != SAM_STAT_GOOD) {
752 if (ccb->sense_buffer != NULL)
753 memcpy(ccb->sense_buffer, resp->variable,
754 min(variable, ccb->sense_bufflen));
758 if (ccb->cmd == NULL)
760 scsi_sg_copy_from_buffer(ccb->cmd, resp->variable, variable);
763 static void stex_check_cmd(struct st_hba *hba,
764 struct st_ccb *ccb, struct status_msg *resp)
766 if (ccb->cmd->cmnd[0] == MGT_CMD &&
767 resp->scsi_status != SAM_STAT_CHECK_CONDITION)
768 scsi_set_resid(ccb->cmd, scsi_bufflen(ccb->cmd) -
769 le32_to_cpu(*(__le32 *)&resp->variable[0]));
772 static void stex_mu_intr(struct st_hba *hba, u32 doorbell)
774 void __iomem *base = hba->mmio_base;
775 struct status_msg *resp;
780 if (unlikely(!(doorbell & MU_OUTBOUND_DOORBELL_STATUSHEADCHANGED)))
783 /* status payloads */
784 hba->status_head = readl(base + OMR1);
785 if (unlikely(hba->status_head > hba->sts_count)) {
786 printk(KERN_WARNING DRV_NAME "(%s): invalid status head\n",
787 pci_name(hba->pdev));
792 * it's not a valid status payload if:
793 * 1. there are no pending requests(e.g. during init stage)
794 * 2. there are some pending requests, but the controller is in
795 * reset status, and its type is not st_yosemite
796 * firmware of st_yosemite in reset status will return pending requests
797 * to driver, so we allow it to pass
799 if (unlikely(hba->out_req_cnt <= 0 ||
800 (hba->mu_status == MU_STATE_RESETTING &&
801 hba->cardtype != st_yosemite))) {
802 hba->status_tail = hba->status_head;
806 while (hba->status_tail != hba->status_head) {
807 resp = stex_get_status(hba);
808 tag = le16_to_cpu(resp->tag);
809 if (unlikely(tag >= hba->host->can_queue)) {
810 printk(KERN_WARNING DRV_NAME
811 "(%s): invalid tag\n", pci_name(hba->pdev));
816 ccb = &hba->ccb[tag];
817 if (unlikely(hba->wait_ccb == ccb))
818 hba->wait_ccb = NULL;
819 if (unlikely(ccb->req == NULL)) {
820 printk(KERN_WARNING DRV_NAME
821 "(%s): lagging req\n", pci_name(hba->pdev));
825 size = resp->payload_sz * sizeof(u32); /* payload size */
826 if (unlikely(size < sizeof(*resp) - STATUS_VAR_LEN ||
827 size > sizeof(*resp))) {
828 printk(KERN_WARNING DRV_NAME "(%s): bad status size\n",
829 pci_name(hba->pdev));
831 size -= sizeof(*resp) - STATUS_VAR_LEN; /* copy size */
833 stex_copy_data(ccb, resp, size);
837 ccb->srb_status = resp->srb_status;
838 ccb->scsi_status = resp->scsi_status;
840 if (likely(ccb->cmd != NULL)) {
841 if (hba->cardtype == st_yosemite)
842 stex_check_cmd(hba, ccb, resp);
844 if (unlikely(ccb->cmd->cmnd[0] == PASSTHRU_CMD &&
845 ccb->cmd->cmnd[1] == PASSTHRU_GET_ADAPTER))
846 stex_controller_info(hba, ccb);
848 scsi_dma_unmap(ccb->cmd);
855 writel(hba->status_head, base + IMR1);
856 readl(base + IMR1); /* flush */
859 static irqreturn_t stex_intr(int irq, void *__hba)
861 struct st_hba *hba = __hba;
862 void __iomem *base = hba->mmio_base;
866 spin_lock_irqsave(hba->host->host_lock, flags);
868 data = readl(base + ODBL);
870 if (data && data != 0xffffffff) {
871 /* clear the interrupt */
872 writel(data, base + ODBL);
873 readl(base + ODBL); /* flush */
874 stex_mu_intr(hba, data);
875 spin_unlock_irqrestore(hba->host->host_lock, flags);
876 if (unlikely(data & MU_OUTBOUND_DOORBELL_REQUEST_RESET &&
877 hba->cardtype == st_shasta))
878 queue_work(hba->work_q, &hba->reset_work);
882 spin_unlock_irqrestore(hba->host->host_lock, flags);
887 static void stex_ss_mu_intr(struct st_hba *hba)
889 struct status_msg *resp;
897 if (unlikely(hba->out_req_cnt <= 0 ||
898 hba->mu_status == MU_STATE_RESETTING))
901 while (count < hba->sts_count) {
902 scratch = hba->scratch + hba->status_tail;
903 value = le32_to_cpu(*scratch);
904 if (unlikely(!(value & SS_STS_NORMAL)))
907 resp = hba->status_buffer + hba->status_tail;
911 hba->status_tail %= hba->sts_count+1;
914 if (unlikely(tag >= hba->host->can_queue)) {
915 printk(KERN_WARNING DRV_NAME
916 "(%s): invalid tag\n", pci_name(hba->pdev));
921 ccb = &hba->ccb[tag];
922 if (unlikely(hba->wait_ccb == ccb))
923 hba->wait_ccb = NULL;
924 if (unlikely(ccb->req == NULL)) {
925 printk(KERN_WARNING DRV_NAME
926 "(%s): lagging req\n", pci_name(hba->pdev));
931 if (likely(value & SS_STS_DONE)) { /* normal case */
932 ccb->srb_status = SRB_STATUS_SUCCESS;
933 ccb->scsi_status = SAM_STAT_GOOD;
935 ccb->srb_status = resp->srb_status;
936 ccb->scsi_status = resp->scsi_status;
937 size = resp->payload_sz * sizeof(u32);
938 if (unlikely(size < sizeof(*resp) - STATUS_VAR_LEN ||
939 size > sizeof(*resp))) {
940 printk(KERN_WARNING DRV_NAME
941 "(%s): bad status size\n",
942 pci_name(hba->pdev));
944 size -= sizeof(*resp) - STATUS_VAR_LEN;
946 stex_copy_data(ccb, resp, size);
948 if (likely(ccb->cmd != NULL))
949 stex_check_cmd(hba, ccb, resp);
952 if (likely(ccb->cmd != NULL)) {
953 scsi_dma_unmap(ccb->cmd);
960 static irqreturn_t stex_ss_intr(int irq, void *__hba)
962 struct st_hba *hba = __hba;
963 void __iomem *base = hba->mmio_base;
967 spin_lock_irqsave(hba->host->host_lock, flags);
969 data = readl(base + YI2H_INT);
970 if (data && data != 0xffffffff) {
971 /* clear the interrupt */
972 writel(data, base + YI2H_INT_C);
973 stex_ss_mu_intr(hba);
974 spin_unlock_irqrestore(hba->host->host_lock, flags);
975 if (unlikely(data & SS_I2H_REQUEST_RESET))
976 queue_work(hba->work_q, &hba->reset_work);
980 spin_unlock_irqrestore(hba->host->host_lock, flags);
985 static int stex_common_handshake(struct st_hba *hba)
987 void __iomem *base = hba->mmio_base;
988 struct handshake_frame *h;
989 dma_addr_t status_phys;
991 unsigned long before;
993 if (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) {
994 writel(MU_INBOUND_DOORBELL_HANDSHAKE, base + IDBL);
997 while (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) {
998 if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
999 printk(KERN_ERR DRV_NAME
1000 "(%s): no handshake signature\n",
1001 pci_name(hba->pdev));
1011 data = readl(base + OMR1);
1012 if ((data & 0xffff0000) == MU_HANDSHAKE_SIGNATURE_HALF) {
1014 if (hba->host->can_queue > data) {
1015 hba->host->can_queue = data;
1016 hba->host->cmd_per_lun = data;
1020 h = (struct handshake_frame *)hba->status_buffer;
1021 h->rb_phy = cpu_to_le64(hba->dma_handle);
1022 h->req_sz = cpu_to_le16(hba->rq_size);
1023 h->req_cnt = cpu_to_le16(hba->rq_count+1);
1024 h->status_sz = cpu_to_le16(sizeof(struct status_msg));
1025 h->status_cnt = cpu_to_le16(hba->sts_count+1);
1026 h->hosttime = cpu_to_le64(ktime_get_real_seconds());
1027 h->partner_type = HMU_PARTNER_TYPE;
1028 if (hba->extra_offset) {
1029 h->extra_offset = cpu_to_le32(hba->extra_offset);
1030 h->extra_size = cpu_to_le32(hba->dma_size - hba->extra_offset);
1032 h->extra_offset = h->extra_size = 0;
1034 status_phys = hba->dma_handle + (hba->rq_count+1) * hba->rq_size;
1035 writel(status_phys, base + IMR0);
1037 writel((status_phys >> 16) >> 16, base + IMR1);
1040 writel((status_phys >> 16) >> 16, base + OMR0); /* old fw compatible */
1042 writel(MU_INBOUND_DOORBELL_HANDSHAKE, base + IDBL);
1043 readl(base + IDBL); /* flush */
1047 while (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) {
1048 if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
1049 printk(KERN_ERR DRV_NAME
1050 "(%s): no signature after handshake frame\n",
1051 pci_name(hba->pdev));
1058 writel(0, base + IMR0);
1060 writel(0, base + OMR0);
1062 writel(0, base + IMR1);
1064 writel(0, base + OMR1);
1065 readl(base + OMR1); /* flush */
1069 static int stex_ss_handshake(struct st_hba *hba)
1071 void __iomem *base = hba->mmio_base;
1072 struct st_msg_header *msg_h;
1073 struct handshake_frame *h;
1075 u32 data, scratch_size;
1076 unsigned long before;
1080 while ((readl(base + YIOA_STATUS) & SS_MU_OPERATIONAL) == 0) {
1081 if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
1082 printk(KERN_ERR DRV_NAME
1083 "(%s): firmware not operational\n",
1084 pci_name(hba->pdev));
1090 msg_h = (struct st_msg_header *)hba->dma_mem;
1091 msg_h->handle = cpu_to_le64(hba->dma_handle);
1092 msg_h->flag = SS_HEAD_HANDSHAKE;
1094 h = (struct handshake_frame *)(msg_h + 1);
1095 h->rb_phy = cpu_to_le64(hba->dma_handle);
1096 h->req_sz = cpu_to_le16(hba->rq_size);
1097 h->req_cnt = cpu_to_le16(hba->rq_count+1);
1098 h->status_sz = cpu_to_le16(sizeof(struct status_msg));
1099 h->status_cnt = cpu_to_le16(hba->sts_count+1);
1100 h->hosttime = cpu_to_le64(ktime_get_real_seconds());
1101 h->partner_type = HMU_PARTNER_TYPE;
1102 h->extra_offset = h->extra_size = 0;
1103 scratch_size = (hba->sts_count+1)*sizeof(u32);
1104 h->scratch_size = cpu_to_le32(scratch_size);
1106 data = readl(base + YINT_EN);
1108 writel(data, base + YINT_EN);
1109 writel((hba->dma_handle >> 16) >> 16, base + YH2I_REQ_HI);
1110 readl(base + YH2I_REQ_HI);
1111 writel(hba->dma_handle, base + YH2I_REQ);
1112 readl(base + YH2I_REQ); /* flush */
1114 scratch = hba->scratch;
1116 while (!(le32_to_cpu(*scratch) & SS_STS_HANDSHAKE)) {
1117 if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
1118 printk(KERN_ERR DRV_NAME
1119 "(%s): no signature after handshake frame\n",
1120 pci_name(hba->pdev));
1128 memset(scratch, 0, scratch_size);
1133 static int stex_handshake(struct st_hba *hba)
1136 unsigned long flags;
1137 unsigned int mu_status;
1139 err = (hba->cardtype == st_yel) ?
1140 stex_ss_handshake(hba) : stex_common_handshake(hba);
1141 spin_lock_irqsave(hba->host->host_lock, flags);
1142 mu_status = hba->mu_status;
1146 hba->status_head = 0;
1147 hba->status_tail = 0;
1148 hba->out_req_cnt = 0;
1149 hba->mu_status = MU_STATE_STARTED;
1151 hba->mu_status = MU_STATE_FAILED;
1152 if (mu_status == MU_STATE_RESETTING)
1153 wake_up_all(&hba->reset_waitq);
1154 spin_unlock_irqrestore(hba->host->host_lock, flags);
1158 static int stex_abort(struct scsi_cmnd *cmd)
1160 struct Scsi_Host *host = cmd->device->host;
1161 struct st_hba *hba = (struct st_hba *)host->hostdata;
1162 u16 tag = cmd->request->tag;
1165 int result = SUCCESS;
1166 unsigned long flags;
1168 scmd_printk(KERN_INFO, cmd, "aborting command\n");
1170 base = hba->mmio_base;
1171 spin_lock_irqsave(host->host_lock, flags);
1172 if (tag < host->can_queue &&
1173 hba->ccb[tag].req && hba->ccb[tag].cmd == cmd)
1174 hba->wait_ccb = &hba->ccb[tag];
1178 if (hba->cardtype == st_yel) {
1179 data = readl(base + YI2H_INT);
1180 if (data == 0 || data == 0xffffffff)
1183 writel(data, base + YI2H_INT_C);
1184 stex_ss_mu_intr(hba);
1186 data = readl(base + ODBL);
1187 if (data == 0 || data == 0xffffffff)
1190 writel(data, base + ODBL);
1191 readl(base + ODBL); /* flush */
1193 stex_mu_intr(hba, data);
1195 if (hba->wait_ccb == NULL) {
1196 printk(KERN_WARNING DRV_NAME
1197 "(%s): lost interrupt\n", pci_name(hba->pdev));
1202 scsi_dma_unmap(cmd);
1203 hba->wait_ccb->req = NULL; /* nullify the req's future return */
1204 hba->wait_ccb = NULL;
1207 spin_unlock_irqrestore(host->host_lock, flags);
1211 static void stex_hard_reset(struct st_hba *hba)
1213 struct pci_bus *bus;
1218 for (i = 0; i < 16; i++)
1219 pci_read_config_dword(hba->pdev, i * 4,
1220 &hba->pdev->saved_config_space[i]);
1222 /* Reset secondary bus. Our controller(MU/ATU) is the only device on
1223 secondary bus. Consult Intel 80331/3 developer's manual for detail */
1224 bus = hba->pdev->bus;
1225 pci_read_config_byte(bus->self, PCI_BRIDGE_CONTROL, &pci_bctl);
1226 pci_bctl |= PCI_BRIDGE_CTL_BUS_RESET;
1227 pci_write_config_byte(bus->self, PCI_BRIDGE_CONTROL, pci_bctl);
1230 * 1 ms may be enough for 8-port controllers. But 16-port controllers
1231 * require more time to finish bus reset. Use 100 ms here for safety
1234 pci_bctl &= ~PCI_BRIDGE_CTL_BUS_RESET;
1235 pci_write_config_byte(bus->self, PCI_BRIDGE_CONTROL, pci_bctl);
1237 for (i = 0; i < MU_HARD_RESET_WAIT; i++) {
1238 pci_read_config_word(hba->pdev, PCI_COMMAND, &pci_cmd);
1239 if (pci_cmd != 0xffff && (pci_cmd & PCI_COMMAND_MASTER))
1245 for (i = 0; i < 16; i++)
1246 pci_write_config_dword(hba->pdev, i * 4,
1247 hba->pdev->saved_config_space[i]);
1250 static int stex_yos_reset(struct st_hba *hba)
1253 unsigned long flags, before;
1256 base = hba->mmio_base;
1257 writel(MU_INBOUND_DOORBELL_RESET, base + IDBL);
1258 readl(base + IDBL); /* flush */
1260 while (hba->out_req_cnt > 0) {
1261 if (time_after(jiffies, before + ST_INTERNAL_TIMEOUT * HZ)) {
1262 printk(KERN_WARNING DRV_NAME
1263 "(%s): reset timeout\n", pci_name(hba->pdev));
1270 spin_lock_irqsave(hba->host->host_lock, flags);
1272 hba->mu_status = MU_STATE_FAILED;
1274 hba->mu_status = MU_STATE_STARTED;
1275 wake_up_all(&hba->reset_waitq);
1276 spin_unlock_irqrestore(hba->host->host_lock, flags);
1281 static void stex_ss_reset(struct st_hba *hba)
1283 writel(SS_H2I_INT_RESET, hba->mmio_base + YH2I_INT);
1284 readl(hba->mmio_base + YH2I_INT);
1288 static int stex_do_reset(struct st_hba *hba)
1290 unsigned long flags;
1291 unsigned int mu_status = MU_STATE_RESETTING;
1293 spin_lock_irqsave(hba->host->host_lock, flags);
1294 if (hba->mu_status == MU_STATE_STARTING) {
1295 spin_unlock_irqrestore(hba->host->host_lock, flags);
1296 printk(KERN_INFO DRV_NAME "(%s): request reset during init\n",
1297 pci_name(hba->pdev));
1300 while (hba->mu_status == MU_STATE_RESETTING) {
1301 spin_unlock_irqrestore(hba->host->host_lock, flags);
1302 wait_event_timeout(hba->reset_waitq,
1303 hba->mu_status != MU_STATE_RESETTING,
1305 spin_lock_irqsave(hba->host->host_lock, flags);
1306 mu_status = hba->mu_status;
1309 if (mu_status != MU_STATE_RESETTING) {
1310 spin_unlock_irqrestore(hba->host->host_lock, flags);
1311 return (mu_status == MU_STATE_STARTED) ? 0 : -1;
1314 hba->mu_status = MU_STATE_RESETTING;
1315 spin_unlock_irqrestore(hba->host->host_lock, flags);
1317 if (hba->cardtype == st_yosemite)
1318 return stex_yos_reset(hba);
1320 if (hba->cardtype == st_shasta)
1321 stex_hard_reset(hba);
1322 else if (hba->cardtype == st_yel)
1326 return_abnormal_state(hba, DID_RESET);
1328 if (stex_handshake(hba) == 0)
1331 printk(KERN_WARNING DRV_NAME "(%s): resetting: handshake failed\n",
1332 pci_name(hba->pdev));
1336 static int stex_reset(struct scsi_cmnd *cmd)
1340 hba = (struct st_hba *) &cmd->device->host->hostdata[0];
1342 shost_printk(KERN_INFO, cmd->device->host,
1343 "resetting host\n");
1345 return stex_do_reset(hba) ? FAILED : SUCCESS;
1348 static void stex_reset_work(struct work_struct *work)
1350 struct st_hba *hba = container_of(work, struct st_hba, reset_work);
1355 static int stex_biosparam(struct scsi_device *sdev,
1356 struct block_device *bdev, sector_t capacity, int geom[])
1358 int heads = 255, sectors = 63;
1360 if (capacity < 0x200000) {
1365 sector_div(capacity, heads * sectors);
1374 static struct scsi_host_template driver_template = {
1375 .module = THIS_MODULE,
1377 .proc_name = DRV_NAME,
1378 .bios_param = stex_biosparam,
1379 .queuecommand = stex_queuecommand,
1380 .slave_configure = stex_slave_config,
1381 .eh_abort_handler = stex_abort,
1382 .eh_host_reset_handler = stex_reset,
1386 static struct pci_device_id stex_pci_tbl[] = {
1388 { 0x105a, 0x8350, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1389 st_shasta }, /* SuperTrak EX8350/8300/16350/16300 */
1390 { 0x105a, 0xc350, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1391 st_shasta }, /* SuperTrak EX12350 */
1392 { 0x105a, 0x4302, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1393 st_shasta }, /* SuperTrak EX4350 */
1394 { 0x105a, 0xe350, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1395 st_shasta }, /* SuperTrak EX24350 */
1398 { 0x105a, 0x7250, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_vsc },
1401 { 0x105a, 0x8650, 0x105a, PCI_ANY_ID, 0, 0, st_yosemite },
1404 { 0x105a, 0x3360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_seq },
1407 { 0x105a, 0x8650, 0x1033, PCI_ANY_ID, 0, 0, st_yel },
1408 { 0x105a, 0x8760, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_yel },
1409 { } /* terminate list */
1412 static struct st_card_info stex_card_info[] = {
1421 .alloc_rq = stex_alloc_req,
1422 .map_sg = stex_map_sg,
1423 .send = stex_send_cmd,
1434 .alloc_rq = stex_alloc_req,
1435 .map_sg = stex_map_sg,
1436 .send = stex_send_cmd,
1447 .alloc_rq = stex_alloc_req,
1448 .map_sg = stex_map_sg,
1449 .send = stex_send_cmd,
1460 .alloc_rq = stex_alloc_req,
1461 .map_sg = stex_map_sg,
1462 .send = stex_send_cmd,
1473 .alloc_rq = stex_ss_alloc_req,
1474 .map_sg = stex_ss_map_sg,
1475 .send = stex_ss_send_cmd,
1479 static int stex_set_dma_mask(struct pci_dev * pdev)
1483 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
1484 && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
1486 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
1488 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
1492 static int stex_request_irq(struct st_hba *hba)
1494 struct pci_dev *pdev = hba->pdev;
1498 status = pci_enable_msi(pdev);
1500 printk(KERN_ERR DRV_NAME
1501 "(%s): error %d setting up MSI\n",
1502 pci_name(pdev), status);
1504 hba->msi_enabled = 1;
1506 hba->msi_enabled = 0;
1508 status = request_irq(pdev->irq, hba->cardtype == st_yel ?
1509 stex_ss_intr : stex_intr, IRQF_SHARED, DRV_NAME, hba);
1512 if (hba->msi_enabled)
1513 pci_disable_msi(pdev);
1518 static void stex_free_irq(struct st_hba *hba)
1520 struct pci_dev *pdev = hba->pdev;
1522 free_irq(pdev->irq, hba);
1523 if (hba->msi_enabled)
1524 pci_disable_msi(pdev);
1527 static int stex_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1530 struct Scsi_Host *host;
1531 const struct st_card_info *ci = NULL;
1532 u32 sts_offset, cp_offset, scratch_offset;
1535 err = pci_enable_device(pdev);
1539 pci_set_master(pdev);
1541 host = scsi_host_alloc(&driver_template, sizeof(struct st_hba));
1544 printk(KERN_ERR DRV_NAME "(%s): scsi_host_alloc failed\n",
1550 hba = (struct st_hba *)host->hostdata;
1551 memset(hba, 0, sizeof(struct st_hba));
1553 err = pci_request_regions(pdev, DRV_NAME);
1555 printk(KERN_ERR DRV_NAME "(%s): request regions failed\n",
1557 goto out_scsi_host_put;
1560 hba->mmio_base = pci_ioremap_bar(pdev, 0);
1561 if ( !hba->mmio_base) {
1562 printk(KERN_ERR DRV_NAME "(%s): memory map failed\n",
1565 goto out_release_regions;
1568 err = stex_set_dma_mask(pdev);
1570 printk(KERN_ERR DRV_NAME "(%s): set dma mask failed\n",
1575 hba->cardtype = (unsigned int) id->driver_data;
1576 ci = &stex_card_info[hba->cardtype];
1577 switch (id->subdevice) {
1592 if (hba->cardtype == st_yel)
1593 hba->supports_pm = 1;
1596 sts_offset = scratch_offset = (ci->rq_count+1) * ci->rq_size;
1597 if (hba->cardtype == st_yel)
1598 sts_offset += (ci->sts_count+1) * sizeof(u32);
1599 cp_offset = sts_offset + (ci->sts_count+1) * sizeof(struct status_msg);
1600 hba->dma_size = cp_offset + sizeof(struct st_frame);
1601 if (hba->cardtype == st_seq ||
1602 (hba->cardtype == st_vsc && (pdev->subsystem_device & 1))) {
1603 hba->extra_offset = hba->dma_size;
1604 hba->dma_size += ST_ADDITIONAL_MEM;
1606 hba->dma_mem = dma_alloc_coherent(&pdev->dev,
1607 hba->dma_size, &hba->dma_handle, GFP_KERNEL);
1608 if (!hba->dma_mem) {
1609 /* Retry minimum coherent mapping for st_seq and st_vsc */
1610 if (hba->cardtype == st_seq ||
1611 (hba->cardtype == st_vsc && (pdev->subsystem_device & 1))) {
1612 printk(KERN_WARNING DRV_NAME
1613 "(%s): allocating min buffer for controller\n",
1615 hba->dma_size = hba->extra_offset
1616 + ST_ADDITIONAL_MEM_MIN;
1617 hba->dma_mem = dma_alloc_coherent(&pdev->dev,
1618 hba->dma_size, &hba->dma_handle, GFP_KERNEL);
1621 if (!hba->dma_mem) {
1623 printk(KERN_ERR DRV_NAME "(%s): dma mem alloc failed\n",
1629 hba->ccb = kcalloc(ci->rq_count, sizeof(struct st_ccb), GFP_KERNEL);
1632 printk(KERN_ERR DRV_NAME "(%s): ccb alloc failed\n",
1637 if (hba->cardtype == st_yel)
1638 hba->scratch = (__le32 *)(hba->dma_mem + scratch_offset);
1639 hba->status_buffer = (struct status_msg *)(hba->dma_mem + sts_offset);
1640 hba->copy_buffer = hba->dma_mem + cp_offset;
1641 hba->rq_count = ci->rq_count;
1642 hba->rq_size = ci->rq_size;
1643 hba->sts_count = ci->sts_count;
1644 hba->alloc_rq = ci->alloc_rq;
1645 hba->map_sg = ci->map_sg;
1646 hba->send = ci->send;
1647 hba->mu_status = MU_STATE_STARTING;
1649 if (hba->cardtype == st_yel)
1650 host->sg_tablesize = 38;
1652 host->sg_tablesize = 32;
1653 host->can_queue = ci->rq_count;
1654 host->cmd_per_lun = ci->rq_count;
1655 host->max_id = ci->max_id;
1656 host->max_lun = ci->max_lun;
1657 host->max_channel = ci->max_channel;
1658 host->unique_id = host->host_no;
1659 host->max_cmd_len = STEX_CDB_LENGTH;
1663 init_waitqueue_head(&hba->reset_waitq);
1665 snprintf(hba->work_q_name, sizeof(hba->work_q_name),
1666 "stex_wq_%d", host->host_no);
1667 hba->work_q = create_singlethread_workqueue(hba->work_q_name);
1669 printk(KERN_ERR DRV_NAME "(%s): create workqueue failed\n",
1674 INIT_WORK(&hba->reset_work, stex_reset_work);
1676 err = stex_request_irq(hba);
1678 printk(KERN_ERR DRV_NAME "(%s): request irq failed\n",
1683 err = stex_handshake(hba);
1687 pci_set_drvdata(pdev, hba);
1689 err = scsi_add_host(host, &pdev->dev);
1691 printk(KERN_ERR DRV_NAME "(%s): scsi_add_host failed\n",
1696 scsi_scan_host(host);
1703 destroy_workqueue(hba->work_q);
1707 dma_free_coherent(&pdev->dev, hba->dma_size,
1708 hba->dma_mem, hba->dma_handle);
1710 iounmap(hba->mmio_base);
1711 out_release_regions:
1712 pci_release_regions(pdev);
1714 scsi_host_put(host);
1716 pci_disable_device(pdev);
1721 static void stex_hba_stop(struct st_hba *hba)
1723 struct req_msg *req;
1724 struct st_msg_header *msg_h;
1725 unsigned long flags;
1726 unsigned long before;
1729 spin_lock_irqsave(hba->host->host_lock, flags);
1730 req = hba->alloc_rq(hba);
1731 if (hba->cardtype == st_yel) {
1732 msg_h = (struct st_msg_header *)req - 1;
1733 memset(msg_h, 0, hba->rq_size);
1735 memset(req, 0, hba->rq_size);
1737 if (hba->cardtype == st_yosemite || hba->cardtype == st_yel) {
1738 req->cdb[0] = MGT_CMD;
1739 req->cdb[1] = MGT_CMD_SIGNATURE;
1740 req->cdb[2] = CTLR_CONFIG_CMD;
1741 req->cdb[3] = CTLR_SHUTDOWN;
1743 req->cdb[0] = CONTROLLER_CMD;
1744 req->cdb[1] = CTLR_POWER_STATE_CHANGE;
1745 req->cdb[2] = CTLR_POWER_SAVING;
1748 hba->ccb[tag].cmd = NULL;
1749 hba->ccb[tag].sg_count = 0;
1750 hba->ccb[tag].sense_bufflen = 0;
1751 hba->ccb[tag].sense_buffer = NULL;
1752 hba->ccb[tag].req_type = PASSTHRU_REQ_TYPE;
1754 hba->send(hba, req, tag);
1755 spin_unlock_irqrestore(hba->host->host_lock, flags);
1758 while (hba->ccb[tag].req_type & PASSTHRU_REQ_TYPE) {
1759 if (time_after(jiffies, before + ST_INTERNAL_TIMEOUT * HZ)) {
1760 hba->ccb[tag].req_type = 0;
1767 static void stex_hba_free(struct st_hba *hba)
1771 destroy_workqueue(hba->work_q);
1773 iounmap(hba->mmio_base);
1775 pci_release_regions(hba->pdev);
1779 dma_free_coherent(&hba->pdev->dev, hba->dma_size,
1780 hba->dma_mem, hba->dma_handle);
1783 static void stex_remove(struct pci_dev *pdev)
1785 struct st_hba *hba = pci_get_drvdata(pdev);
1787 hba->mu_status = MU_STATE_NOCONNECT;
1788 return_abnormal_state(hba, DID_NO_CONNECT);
1789 scsi_remove_host(hba->host);
1791 scsi_block_requests(hba->host);
1795 scsi_host_put(hba->host);
1797 pci_disable_device(pdev);
1800 static void stex_shutdown(struct pci_dev *pdev)
1802 struct st_hba *hba = pci_get_drvdata(pdev);
1807 MODULE_DEVICE_TABLE(pci, stex_pci_tbl);
1809 static struct pci_driver stex_pci_driver = {
1811 .id_table = stex_pci_tbl,
1812 .probe = stex_probe,
1813 .remove = stex_remove,
1814 .shutdown = stex_shutdown,
1817 static int __init stex_init(void)
1819 printk(KERN_INFO DRV_NAME
1820 ": Promise SuperTrak EX Driver version: %s\n",
1823 return pci_register_driver(&stex_pci_driver);
1826 static void __exit stex_exit(void)
1828 pci_unregister_driver(&stex_pci_driver);
1831 module_init(stex_init);
1832 module_exit(stex_exit);