17 #include <linux/errno.h>
18 #include <linux/kernel.h>
20 #include <linux/slab.h>
21 #include <linux/time.h>
22 #include <linux/pci.h>
25 #include <linux/types.h>
26 #include <linux/module.h>
30 #include <asm/byteorder.h>
31 #include <scsi/scsi.h>
39 #define DRV_NAME "stex"
40 #define ST_DRIVER_VERSION "4.6.0000.4"
41 #define ST_VER_MAJOR 4
42 #define ST_VER_MINOR 6
44 #define ST_BUILD_VER 4
348 static const char console_inq_page[] =
350 0x03,0x00,0x03,0x03,0xFA,0x00,0x00,0x30,
351 0x50,0x72,0x6F,0x6D,0x69,0x73,0x65,0x20,
352 0x52,0x41,0x49,0x44,0x20,0x43,0x6F,0x6E,
353 0x73,0x6F,0x6C,0x65,0x20,0x20,0x20,0x20,
354 0x31,0x2E,0x30,0x30,0x20,0x20,0x20,0x20,
355 0x53,0x58,0x2F,0x52,0x53,0x41,0x46,0x2D,
356 0x54,0x45,0x31,0x2E,0x30,0x30,0x20,0x20,
357 0x0C,0x20,0x20,0x20,0x20,0x20,0x20,0x20
410 static int stex_map_sg(
struct st_hba *hba,
442 static int stex_ss_map_sg(
struct st_hba *hba,
475 static void stex_controller_info(
struct st_hba *hba,
struct st_ccb *ccb)
481 scsi_sg_copy_to_buffer(ccb->
cmd, p, count);
491 p->
bus = hba->
pdev->bus->number;
495 p->
id = hba->
pdev->vendor << 16 | hba->
pdev->device;
497 hba->
pdev->subsystem_vendor << 16 | hba->
pdev->subsystem_device;
499 scsi_sg_copy_from_buffer(ccb->
cmd, p, count);
534 addr += (hba->
ccb[
tag].sg_count+4)/11;
552 scsi_activate_tcq(sdev, sdev->
host->can_queue);
571 scsi_deactivate_tcq(sdev, 1);
579 unsigned int id,
lun;
586 hba = (
struct st_hba *) &host->hostdata[0];
591 switch (cmd->
cmnd[0]) {
594 static char ms10_caching_page[12] =
595 { 0, 0x12, 0, 0, 0, 0, 0, 0, 0x8, 0xa, 0x4, 0 };
598 page = cmd->
cmnd[2] & 0x3f;
599 if (page == 0x8 || page == 0x3f) {
600 scsi_sg_copy_from_buffer(cmd, ms10_caching_page,
601 sizeof(ms10_caching_page));
605 stex_invalid_field(cmd,
done);
615 stex_invalid_field(cmd,
done);
620 if (
id == host->
max_id - 1) {
632 if (
id != host->
max_id - 1)
634 if (!lun && !cmd->
device->channel &&
636 scsi_sg_copy_from_buffer(cmd, (
void *)console_inq_page,
637 sizeof(console_inq_page));
641 stex_invalid_field(cmd,
done);
646 size_t cp_len =
sizeof(
ver);
654 ver.host_no = hba->
host->host_no;
655 cp_len = scsi_sg_copy_from_buffer(cmd, &
ver, cp_len);
692 if (!hba->
map_sg(hba, req, &hba->
ccb[tag])) {
693 hba->
ccb[
tag].sg_count = 0;
697 hba->
send(hba, req, tag);
709 result = ccb->scsi_status;
710 switch (ccb->scsi_status) {
727 else switch (ccb->srb_status) {
745 static void stex_copy_data(
struct st_ccb *ccb,
757 scsi_sg_copy_from_buffer(ccb->
cmd, resp->
variable, variable);
760 static void stex_check_cmd(
struct st_hba *hba,
765 scsi_set_resid(ccb->
cmd, scsi_bufflen(ccb->
cmd) -
784 pci_name(hba->
pdev));
804 resp = stex_get_status(hba);
808 "(%s): invalid tag\n", pci_name(hba->
pdev));
818 "(%s): lagging req\n", pci_name(hba->
pdev));
824 size >
sizeof(*resp))) {
826 pci_name(hba->
pdev));
830 stex_copy_data(ccb, resp, size);
839 stex_check_cmd(hba, ccb, resp);
843 stex_controller_info(hba, ccb);
858 struct st_hba *hba = __hba;
867 if (data && data != 0xffffffff) {
871 stex_mu_intr(hba, data);
872 spin_unlock_irqrestore(hba->
host->host_lock, flags);
879 spin_unlock_irqrestore(hba->
host->host_lock, flags);
884 static void stex_ss_mu_intr(
struct st_hba *hba)
898 while (count < hba->sts_count) {
913 "(%s): invalid tag\n", pci_name(hba->
pdev));
923 "(%s): lagging req\n", pci_name(hba->
pdev));
935 if (
unlikely(size <
sizeof(*resp) - STATUS_VAR_LEN ||
936 size >
sizeof(*resp))) {
938 "(%s): bad status size\n",
939 pci_name(hba->
pdev));
943 stex_copy_data(ccb, resp, size);
946 stex_check_cmd(hba, ccb, resp);
957 static irqreturn_t stex_ss_intr(
int irq,
void *__hba)
959 struct st_hba *hba = __hba;
967 if (data && data != 0xffffffff) {
970 stex_ss_mu_intr(hba);
971 spin_unlock_irqrestore(hba->
host->host_lock, flags);
977 spin_unlock_irqrestore(hba->
host->host_lock, flags);
982 static int stex_common_handshake(
struct st_hba *hba)
988 unsigned long before;
997 "(%s): no handshake signature\n",
998 pci_name(hba->
pdev));
1011 if (hba->
host->can_queue > data) {
1034 writel((status_phys >> 16) >> 16, base +
IMR1);
1037 writel((status_phys >> 16) >> 16, base +
OMR0);
1047 "(%s): no signature after handshake frame\n",
1048 pci_name(hba->
pdev));
1066 static int stex_ss_handshake(
struct st_hba *hba)
1073 unsigned long before;
1080 "(%s): firmware not operational\n",
1081 pci_name(hba->
pdev));
1116 "(%s): no signature after handshake frame\n",
1117 pci_name(hba->
pdev));
1125 memset(scratch, 0, scratch_size);
1130 static int stex_handshake(
struct st_hba *hba)
1133 unsigned long flags;
1134 unsigned int mu_status;
1137 stex_ss_handshake(hba) : stex_common_handshake(hba);
1151 spin_unlock_irqrestore(hba->
host->host_lock, flags);
1155 static int stex_abort(
struct scsi_cmnd *cmd)
1163 unsigned long flags;
1166 "(%s): aborting command\n", pci_name(hba->
pdev));
1172 hba->
ccb[tag].req && hba->
ccb[tag].cmd == cmd)
1179 if (data == 0 || data == 0xffffffff)
1183 stex_ss_mu_intr(hba);
1186 if (data == 0 || data == 0xffffffff)
1192 stex_mu_intr(hba, data);
1196 "(%s): lost interrupt\n", pci_name(hba->
pdev));
1206 spin_unlock_irqrestore(host->
host_lock, flags);
1210 static void stex_hard_reset(
struct st_hba *hba)
1217 for (i = 0; i < 16; i++)
1218 pci_read_config_dword(hba->
pdev, i * 4,
1219 &hba->
pdev->saved_config_space[i]);
1223 bus = hba->
pdev->bus;
1244 for (i = 0; i < 16; i++)
1245 pci_write_config_dword(hba->
pdev, i * 4,
1246 hba->
pdev->saved_config_space[i]);
1249 static int stex_yos_reset(
struct st_hba *hba)
1252 unsigned long flags, before;
1262 "(%s): reset timeout\n", pci_name(hba->
pdev));
1275 spin_unlock_irqrestore(hba->
host->host_lock, flags);
1280 static void stex_ss_reset(
struct st_hba *hba)
1287 static int stex_do_reset(
struct st_hba *hba)
1290 unsigned long flags;
1296 spin_unlock_irqrestore(hba->
host->host_lock, flags);
1298 pci_name(hba->
pdev));
1302 spin_unlock_irqrestore(hba->
host->host_lock, flags);
1311 spin_unlock_irqrestore(hba->
host->host_lock, flags);
1316 spin_unlock_irqrestore(hba->
host->host_lock, flags);
1319 return stex_yos_reset(hba);
1322 stex_hard_reset(hba);
1327 for (tag = 0; tag < hba->
host->can_queue; tag++) {
1335 ccb->
cmd->scsi_done(ccb->
cmd);
1339 spin_unlock_irqrestore(hba->
host->host_lock, flags);
1341 if (stex_handshake(hba) == 0)
1345 pci_name(hba->
pdev));
1349 static int stex_reset(
struct scsi_cmnd *cmd)
1353 hba = (
struct st_hba *) &cmd->
device->host->hostdata[0];
1356 "(%s): resetting host\n", pci_name(hba->
pdev));
1369 static int stex_biosparam(
struct scsi_device *sdev,
1374 if (capacity < 0x200000) {
1392 .bios_param = stex_biosparam,
1393 .queuecommand = stex_queuecommand,
1394 .slave_alloc = stex_slave_alloc,
1395 .slave_configure = stex_slave_config,
1396 .slave_destroy = stex_slave_destroy,
1397 .eh_abort_handler = stex_abort,
1398 .eh_host_reset_handler = stex_reset,
1437 .alloc_rq = stex_alloc_req,
1438 .map_sg = stex_map_sg,
1439 .send = stex_send_cmd,
1450 .alloc_rq = stex_alloc_req,
1451 .map_sg = stex_map_sg,
1452 .send = stex_send_cmd,
1463 .alloc_rq = stex_alloc_req,
1464 .map_sg = stex_map_sg,
1465 .send = stex_send_cmd,
1476 .alloc_rq = stex_alloc_req,
1477 .map_sg = stex_map_sg,
1478 .send = stex_send_cmd,
1489 .alloc_rq = stex_ss_alloc_req,
1490 .map_sg = stex_ss_map_sg,
1491 .send = stex_ss_send_cmd,
1495 static int stex_set_dma_mask(
struct pci_dev * pdev)
1500 && !pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(64)))
1504 ret = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32));
1508 static int stex_request_irq(
struct st_hba *hba)
1514 status = pci_enable_msi(pdev);
1517 "(%s): error %d setting up MSI\n",
1518 pci_name(pdev), status);
1525 stex_ss_intr : stex_intr,
IRQF_SHARED, DRV_NAME, hba);
1534 static void stex_free_irq(
struct st_hba *hba)
1549 u32 sts_offset, cp_offset, scratch_offset;
1567 hba = (
struct st_hba *)host->hostdata;
1574 goto out_scsi_host_put;
1582 goto out_release_regions;
1585 err = stex_set_dma_mask(pdev);
1593 ci = &stex_card_info[hba->
cardtype];
1611 "(%s): allocating min buffer for controller\n",
1674 err = stex_request_irq(hba);
1681 err = stex_handshake(hba);
1685 err = scsi_init_shared_tag_map(host, host->
can_queue);
1692 pci_set_drvdata(pdev, hba);
1694 err = scsi_add_host(host, &pdev->
dev);
1716 out_release_regions:
1726 static void stex_hba_stop(
struct st_hba *hba)
1730 unsigned long flags;
1731 unsigned long before;
1754 hba->
ccb[
tag].sg_count = 0;
1755 hba->
ccb[
tag].sense_bufflen = 0;
1759 hba->
send(hba, req, tag);
1760 spin_unlock_irqrestore(hba->
host->host_lock, flags);
1765 hba->
ccb[
tag].req_type = 0;
1772 static void stex_hba_free(
struct st_hba *hba)
1788 static void stex_remove(
struct pci_dev *pdev)
1790 struct st_hba *hba = pci_get_drvdata(pdev);
1794 pci_set_drvdata(pdev,
NULL);
1805 static void stex_shutdown(
struct pci_dev *pdev)
1807 struct st_hba *hba = pci_get_drvdata(pdev);
1816 .id_table = stex_pci_tbl,
1817 .probe = stex_probe,
1819 .shutdown = stex_shutdown,
1822 static int __init stex_init(
void)
1825 ": Promise SuperTrak EX Driver version: %s\n",
1828 return pci_register_driver(&stex_pci_driver);
1831 static void __exit stex_exit(
void)