40 #include <linux/ctype.h>
42 #include <linux/module.h>
45 #include <scsi/scsi.h>
53 #define NAME53C "sym53c"
54 #define NAME53C8XX "sym53c8xx"
59 static char *excl_string;
60 static char *safe_string;
75 MODULE_PARM_DESC(cmd_per_lun,
"The maximum number of tags to use by default");
76 MODULE_PARM_DESC(burst,
"Maximum burst. 0 to disable, 255 to read from registers");
78 MODULE_PARM_DESC(diff,
"0 for no differential mode, 1 for BIOS, 2 for always, 3 for not GPIO3");
79 MODULE_PARM_DESC(irqm,
"0 for open drain, 1 to leave alone, 2 for totem pole");
80 MODULE_PARM_DESC(buschk,
"0 to not check, 1 for detach on error, 2 for warn on error");
94 static void sym2_setup_params(
void)
96 char *
p = excl_string;
99 while (p && (xi < 8)) {
107 if (*safe_string ==
'y') {
118 }
else if (*safe_string !=
'n') {
120 " passed to safe option", safe_string);
134 #define SYM_UCMD_PTR(cmd) ((struct sym_ucmd *)(&(cmd)->SCp))
135 #define SYM_SOFTC_PTR(cmd) sym_get_hcb(cmd->device->host)
159 np->
s.settle_time_valid = 1;
161 printf_info(
"%s: command processing suspended for %d seconds\n",
169 static int sym_xerr_cam_status(
int cam_status,
int x_status)
194 scsi_status = cp->ssss_status;
202 cp->ssss_status ==
S_GOOD &&
204 cam_status = sym_xerr_cam_status(
DID_OK,
221 p = (
u_char *) cmd->sense_data;
222 if (p[0]==0x70 && p[2]==0x6 && p[12]==0x29)
246 cp->host_status, cp->ssss_status,
254 scsi_set_resid(cmd, resid);
282 if ((len & 1) && (tp->
head.wval &
EWS)) {
353 if (sym_setup_cdb(np, cmd, cp))
361 cp->
segments = sym_scatter(np, cp, cmd);
387 lastp = goalp - 8 - (cp->
segments * (2*4));
392 lastp = goalp - 8 - (cp->
segments * (2*4));
416 case 0x0A:
case 0x2A:
case 0xAA:
417 panic(
"XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n");
443 static void sym_timer(
struct sym_hcb *np)
445 unsigned long thistime =
jiffies;
457 if (np->
s.settle_time_valid) {
460 printk(
"%s: command processing resumed\n",
462 np->
s.settle_time_valid = 0;
470 if (np->
s.lasttime + 4*
HZ < thistime) {
471 np->
s.lasttime = thistime;
474 #ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
495 unsigned short pci_sts;
496 pci_read_config_word(pdev,
PCI_STATUS, &pci_sts);
497 if (pci_sts & 0xf900) {
498 pci_write_config_word(pdev,
PCI_STATUS, pci_sts);
500 "PCI bus error: status = 0x%04x\n", pci_sts & 0xf900);
508 static int sym53c8xx_queue_command_lck(
struct scsi_cmnd *cmd,
516 memset(ucp, 0,
sizeof(*ucp));
522 if (np->
s.settle_time_valid && cmd->
request->timeout) {
524 tlimit -= SYM_CONF_TIMER_INTERVAL*2;
526 np->
s.settle_time = tlimit;
530 if (np->
s.settle_time_valid)
533 sts = sym_queue_command(np, cmd);
551 if (pci_channel_offline(sym_data->
pdev))
568 static void sym53c8xx_timer(
unsigned long npref)
575 spin_unlock_irqrestore(np->
s.host->host_lock, flags);
582 #define SYM_EH_ABORT 0
583 #define SYM_EH_DEVICE_RESET 1
584 #define SYM_EH_BUS_RESET 2
585 #define SYM_EH_HOST_RESET 3
591 static int sym_eh_handler(
int op,
char *opname,
struct scsi_cmnd *cmd)
595 struct sym_data *sym_data = shost_priv(shost);
611 #define WAIT_FOR_PCI_RECOVERY 35
612 if (pci_channel_offline(pdev)) {
613 int finished_reset = 0;
614 init_completion(&eh_done);
617 if (pci_channel_offline(pdev)) {
639 if (cp->
cmd == cmd) {
672 init_completion(&eh_done);
684 sts==0 ?
"complete" :sts==-2 ?
"timed-out" :
"failed");
692 static int sym53c8xx_eh_abort_handler(
struct scsi_cmnd *cmd)
697 static int sym53c8xx_eh_device_reset_handler(
struct scsi_cmnd *cmd)
702 static int sym53c8xx_eh_bus_reset_handler(
struct scsi_cmnd *cmd)
707 static int sym53c8xx_eh_host_reset_handler(
struct scsi_cmnd *cmd)
723 oldtags = lp->s.reqtags;
725 if (reqtags > lp->s.scdev_depth)
726 reqtags = lp->s.scdev_depth;
728 lp->s.reqtags = reqtags;
730 if (reqtags != oldtags) {
732 "tagged command queuing %s, command queue depth %d.\n",
733 lp->s.reqtags ?
"enabled" :
"disabled", reqtags);
737 static int sym53c8xx_slave_alloc(
struct scsi_device *sdev)
762 "Scan at boot disabled in NVRAM\n");
768 if (sdev->
lun != 0) {
773 "Multiple LUNs disabled in NVRAM\n");
789 spin_unlock_irqrestore(np->
s.host->host_lock, flags);
797 static int sym53c8xx_slave_configure(
struct scsi_device *sdev)
802 int reqtags, depth_to_use;
815 reqtags = sym_driver_setup.
max_tag;
822 depth_to_use = reqtags ? reqtags : 1;
826 lp->s.scdev_depth = depth_to_use;
827 sym_tune_dev_queuing(tp, sdev->
lun, reqtags);
835 static void sym53c8xx_slave_destroy(
struct scsi_device *sdev)
854 "Removing busy LCB (%d)\n", sdev->
lun);
865 tp->
tgoal.check_nego = 1;
869 spin_unlock_irqrestore(np->
s.host->host_lock, flags);
881 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
891 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
900 #define UC_SETSYNC 10
901 #define UC_SETTAGS 11
902 #define UC_SETDEBUG 12
903 #define UC_SETWIDE 14
904 #define UC_SETFLAG 15
905 #define UC_SETVERBOSE 17
906 #define UC_RESETDEV 18
907 #define UC_CLEARDEV 19
917 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
932 if (!((uc->
target >> t) & 1))
944 tp->
tgoal.offset = 0;
961 tp->
tgoal.check_nego = 1;
965 tp->
tgoal.check_nego = 1;
969 sym_tune_dev_queuing(tp, l, uc->
data);
993 static int sym_skip_spaces(
char *
ptr,
int len)
997 for (cnt = len; cnt > 0 && (c = *ptr++) &&
isspace(c); cnt--);
1002 static int get_int_arg(
char *ptr,
int len,
u_long *
pv)
1010 static int is_keyword(
char *ptr,
int len,
char *
verb)
1012 int verb_len =
strlen(verb);
1014 if (len >= verb_len && !
memcmp(verb, ptr, verb_len))
1020 #define SKIP_SPACES(ptr, len) \
1021 if ((arg_len = sym_skip_spaces(ptr, len)) < 1) \
1023 ptr += arg_len; len -= arg_len;
1025 #define GET_INT_ARG(ptr, len, v) \
1026 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
1028 ptr += arg_len; len -= arg_len;
1037 struct sym_hcb *np = sym_get_hcb(shost);
1044 memset(uc, 0,
sizeof(*uc));
1046 if (len > 0 && ptr[len-1] ==
'\n')
1049 if ((arg_len = is_keyword(ptr, len,
"setsync")) != 0)
1051 else if ((arg_len = is_keyword(ptr, len,
"settags")) != 0)
1053 else if ((arg_len = is_keyword(ptr, len,
"setverbose")) != 0)
1055 else if ((arg_len = is_keyword(ptr, len,
"setwide")) != 0)
1057 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1058 else if ((arg_len = is_keyword(ptr, len,
"setdebug")) != 0)
1061 else if ((arg_len = is_keyword(ptr, len,
"setflag")) != 0)
1063 else if ((arg_len = is_keyword(ptr, len,
"resetdev")) != 0)
1065 else if ((arg_len = is_keyword(ptr, len,
"cleardev")) != 0)
1070 #ifdef DEBUG_PROC_INFO
1071 printk(
"sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->
cmd);
1076 ptr += arg_len; len -= arg_len;
1086 if ((arg_len = is_keyword(ptr, len,
"all")) != 0) {
1087 ptr += arg_len; len -= arg_len;
1092 #ifdef DEBUG_PROC_INFO
1093 printk(
"sym_user_command: target=%ld\n", target);
1106 #ifdef DEBUG_PROC_INFO
1107 printk(
"sym_user_command: data=%ld\n", uc->
data);
1110 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1114 if ((arg_len = is_keyword(ptr, len,
"alloc")))
1116 else if ((arg_len = is_keyword(ptr, len,
"phase")))
1118 else if ((arg_len = is_keyword(ptr, len,
"queue")))
1120 else if ((arg_len = is_keyword(ptr, len,
"result")))
1122 else if ((arg_len = is_keyword(ptr, len,
"scatter")))
1124 else if ((arg_len = is_keyword(ptr, len,
"script")))
1126 else if ((arg_len = is_keyword(ptr, len,
"tiny")))
1128 else if ((arg_len = is_keyword(ptr, len,
"timing")))
1130 else if ((arg_len = is_keyword(ptr, len,
"nego")))
1132 else if ((arg_len = is_keyword(ptr, len,
"tags")))
1134 else if ((arg_len = is_keyword(ptr, len,
"pointer")))
1138 ptr += arg_len; len -= arg_len;
1140 #ifdef DEBUG_PROC_INFO
1141 printk(
"sym_user_command: data=%ld\n", uc->
data);
1148 if ((arg_len = is_keyword(ptr, len,
"no_disc")))
1152 ptr += arg_len; len -= arg_len;
1162 unsigned long flags;
1165 sym_exec_user_command(np, uc);
1166 spin_unlock_irqrestore(shost->
host_lock, flags);
1174 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1185 static void copy_mem_info(
struct info_str *
info,
char *data,
int len)
1205 static int copy_info(
struct info_str *info,
char *
fmt, ...)
1215 copy_mem_info(info, buf, len);
1222 static int sym_host_info(
struct Scsi_Host *shost,
char *ptr,
off_t offset,
int len)
1224 struct sym_data *sym_data = shost_priv(shost);
1234 copy_info(&info,
"Chip " NAME53C "%s, device id 0x%x, "
1235 "revision id 0x%x\n", np->
s.chip_name,
1237 copy_info(&info,
"At PCI address %s, IRQ %u\n",
1238 pci_name(pdev), pdev->
irq);
1239 copy_info(&info,
"Min. period factor %d, %s SCSI BUS%s\n",
1241 np->
maxwide ?
"Wide" :
"Narrow",
1244 copy_info(&info,
"Max. started commands %d, "
1245 "max. commands per LUN %d\n",
1263 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
1264 retv = sym_user_command(shost, buffer, length);
1271 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1272 retv = sym_host_info(shost, buffer, offset, length);
1290 if (device->
s.ioaddr)
1292 if (device->
s.ramaddr)
1299 static void sym_free_resources(
struct sym_hcb *np,
struct pci_dev *pdev,
1331 struct sym_data *sym_data;
1335 unsigned long flags;
1337 int do_free_irq = 0;
1353 sym_data = shost_priv(shost);
1366 sym_data->
pdev = pdev;
1369 pci_set_drvdata(pdev, shost);
1384 np->
s.ioaddr = dev->
s.ioaddr;
1385 np->
s.ramaddr = dev->
s.ramaddr;
1390 strlcpy(np->
s.chip_name, dev->
chip.name,
sizeof(np->
s.chip_name));
1391 sprintf(np->
s.inst_name,
"sym%d", np->
s.unit);
1434 np->
s.timer.data = (
unsigned long) np;
1435 np->
s.timer.function = sym53c8xx_timer;
1459 spin_unlock_irqrestore(shost->
host_lock, flags);
1464 printf_err(
"%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
1465 "TERMINATION, DEVICE POWER etc.!\n",
sym_name(np));
1466 spin_unlock_irqrestore(shost->
host_lock, flags);
1470 sym_free_resources(np, pdev, do_free_irq);
1472 sym_iounmap_device(dev);
1483 #if SYM_CONF_NVRAM_SUPPORT
1509 for (i = 0 ; i < 8 ; i++) {
1510 if (sym_driver_setup.
excludes[i] == io_port)
1538 if (!device->
s.ramaddr)
1546 ram_val =
readl(device->
s.ramaddr + ram_size - 16);
1547 if (ram_val != 0x52414944)
1551 "not initializing, driven by RAID controller.\n");
1587 pci_read_config_word(pdev,
PCI_STATUS, &status_reg);
1594 pci_write_config_word(pdev,
PCI_STATUS, status_reg);
1595 pci_read_config_word(pdev,
PCI_STATUS, &status_reg);
1626 #ifdef CONFIG_SCSI_SYM53C8XX_MMIO
1628 device->
s.ioaddr = pci_iomap(pdev, 1,
1631 if (!device->
s.ioaddr)
1632 device->
s.ioaddr = pci_iomap(pdev, 0,
1634 if (!device->
s.ioaddr) {
1635 dev_err(&pdev->
dev,
"could not map registers; giving up.\n");
1639 device->
s.ramaddr = pci_iomap(pdev, i,
1641 if (!device->
s.ramaddr) {
1643 "could not map SRAM; continuing anyway.\n");
1669 for (slot = 0; slot < 256; slot++) {
1672 if (!memc || memc->
vendor != 0x101a || memc->
device == 0x0009) {
1678 pci_read_config_byte(memc, 0x44, &tmp);
1679 if ((tmp & 0x2) == 0) {
1681 pci_write_config_byte(memc, 0x44, tmp);
1685 pci_read_config_byte(memc, 0x45, &tmp);
1686 if ((tmp & 0x4) == 0) {
1688 pci_write_config_byte(memc, 0x45, tmp);
1695 pci_read_config_byte(pdev, 0x84, &tmp);
1706 struct sym_hcb *np = sym_get_hcb(shost);
1720 OUTB(np, nc_istat, 0);
1722 sym_free_resources(np, pdev, 1);
1733 .name =
"sym53c8xx",
1734 .info = sym53c8xx_info,
1735 .queuecommand = sym53c8xx_queue_command,
1736 .slave_alloc = sym53c8xx_slave_alloc,
1737 .slave_configure = sym53c8xx_slave_configure,
1738 .slave_destroy = sym53c8xx_slave_destroy,
1739 .eh_abort_handler = sym53c8xx_eh_abort_handler,
1740 .eh_device_reset_handler = sym53c8xx_eh_device_reset_handler,
1741 .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler,
1742 .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler,
1745 .max_sectors = 0xFFFF,
1746 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
1747 .proc_info = sym53c8xx_proc_info,
1752 static int attach_count;
1761 int do_disable_device = 1;
1763 memset(&sym_dev, 0,
sizeof(sym_dev));
1765 sym_dev.
pdev = pdev;
1776 if (sym_check_supported(&sym_dev))
1779 if (sym_iomap_device(&sym_dev))
1783 if (sym_check_raid(&sym_dev)) {
1784 do_disable_device = 0;
1788 if (sym_set_workarounds(&sym_dev))
1791 sym_config_pqs(pdev, &sym_dev);
1793 sym_get_nvram(&sym_dev, &
nvram);
1796 shost = sym_attach(&sym2_template, attach_count, &sym_dev);
1800 if (scsi_add_host(shost, &pdev->
dev))
1809 sym_detach(pci_get_drvdata(pdev), pdev);
1812 sym_iounmap_device(&sym_dev);
1815 if (do_disable_device)
1821 static void sym2_remove(
struct pci_dev *pdev)
1823 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1826 sym_detach(shost, pdev);
1860 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1876 static void sym2_reset_workarounds(
struct pci_dev *pdev)
1886 pci_read_config_word(pdev,
PCI_STATUS, &status_reg);
1889 pci_write_config_word(pdev,
PCI_STATUS, status_reg);
1890 pci_read_config_word(pdev,
PCI_STATUS, &status_reg);
1902 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1903 struct sym_hcb *np = sym_get_hcb(shost);
1924 sym2_reset_workarounds(pdev);
1947 static void sym2_io_resume(
struct pci_dev *pdev)
1949 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1950 struct sym_data *sym_data = shost_priv(shost);
1958 static void sym2_get_signalling(
struct Scsi_Host *shost)
1960 struct sym_hcb *np = sym_get_hcb(shost);
1980 static void sym2_set_offset(
struct scsi_target *starget,
int offset)
1982 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
1983 struct sym_hcb *np = sym_get_hcb(shost);
1987 tp->
tgoal.check_nego = 1;
1992 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
1993 struct sym_hcb *np = sym_get_hcb(shost);
1998 if (period <= np->minsync &&
spi_width(starget))
2002 tp->
tgoal.check_nego = 1;
2007 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
2008 struct sym_hcb *np = sym_get_hcb(shost);
2017 tp->
tgoal.check_nego = 1;
2020 static void sym2_set_dt(
struct scsi_target *starget,
int dt)
2022 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
2023 struct sym_hcb *np = sym_get_hcb(shost);
2031 tp->
tgoal.check_nego = 1;
2035 static void sym2_set_iu(
struct scsi_target *starget,
int iu)
2037 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
2038 struct sym_hcb *np = sym_get_hcb(shost);
2045 tp->
tgoal.check_nego = 1;
2048 static void sym2_set_qas(
struct scsi_target *starget,
int qas)
2050 struct Scsi_Host *shost = dev_to_shost(starget->
dev.parent);
2051 struct sym_hcb *np = sym_get_hcb(shost);
2058 tp->
tgoal.check_nego = 1;
2063 .set_offset = sym2_set_offset,
2065 .set_period = sym2_set_period,
2067 .set_width = sym2_set_width,
2069 .set_dt = sym2_set_dt,
2072 .set_iu = sym2_set_iu,
2074 .set_qas = sym2_set_qas,
2077 .get_signalling = sym2_get_signalling,
2121 .error_detected = sym2_io_error_detected,
2122 .mmio_enabled = sym2_io_slot_dump,
2123 .slot_reset = sym2_io_slot_reset,
2124 .resume = sym2_io_resume,
2129 .id_table = sym2_id_table,
2130 .probe = sym2_probe,
2131 .remove = sym2_remove,
2132 .err_handler = &sym2_err_handler,
2135 static int __init sym2_init(
void)
2139 sym2_setup_params();
2141 if (!sym2_transport_template)
2144 error = pci_register_driver(&sym2_driver);
2150 static void __exit sym2_exit(
void)