aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorOndrej Zary <linux@rainbow-software.org>2015-02-06 17:11:22 -0500
committerJames Bottomley <JBottomley@Odin.com>2015-04-09 21:00:37 -0400
commit643a7c43f11ee776701e06410d7b3f9a41e5d284 (patch)
treee2e388f9864a8bcfdb422112ec75f6b904c4ac9c /drivers/scsi
parentf20dffc7c67b1c88aedd600031229cc97a4ddb97 (diff)
aha1542: Stop using scsi_module.c
Convert aha1542 to use scsi_add_host instead of scsi_module.c Use pnp_driver and isa_driver to manage cards. Signed-off-by: Ondrej Zary <linux@rainbow-software.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: James Bottomley <JBottomley@Odin.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/aha1542.c300
-rw-r--r--drivers/scsi/aha1542.h2
2 files changed, 169 insertions, 133 deletions
diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c
index 770c48ddbe5e..b7a62daff063 100644
--- a/drivers/scsi/aha1542.c
+++ b/drivers/scsi/aha1542.c
@@ -35,7 +35,8 @@
35#include <linux/proc_fs.h> 35#include <linux/proc_fs.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/spinlock.h> 37#include <linux/spinlock.h>
38#include <linux/isapnp.h> 38#include <linux/isa.h>
39#include <linux/pnp.h>
39#include <linux/blkdev.h> 40#include <linux/blkdev.h>
40#include <linux/slab.h> 41#include <linux/slab.h>
41 42
@@ -71,7 +72,7 @@
71 72
72/* Boards 3,4 slots are reserved for ISAPnP scans */ 73/* Boards 3,4 slots are reserved for ISAPnP scans */
73 74
74static unsigned int bases[MAXBOARDS] __initdata = {0x330, 0x334, 0, 0}; 75static unsigned int bases[MAXBOARDS] = {0x330, 0x334, 0, 0};
75 76
76/* set by aha1542_setup according to the command line; they also may 77/* set by aha1542_setup according to the command line; they also may
77 be marked __initdata, but require zero initializers then */ 78 be marked __initdata, but require zero initializers then */
@@ -79,7 +80,7 @@ static unsigned int bases[MAXBOARDS] __initdata = {0x330, 0x334, 0, 0};
79static int setup_called[MAXBOARDS]; 80static int setup_called[MAXBOARDS];
80static int setup_buson[MAXBOARDS]; 81static int setup_buson[MAXBOARDS];
81static int setup_busoff[MAXBOARDS]; 82static int setup_busoff[MAXBOARDS];
82static int setup_dmaspeed[MAXBOARDS] __initdata = { -1, -1, -1, -1 }; 83static int setup_dmaspeed[MAXBOARDS] = { -1, -1, -1, -1 };
83 84
84/* 85/*
85 * LILO/Module params: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]] 86 * LILO/Module params: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]
@@ -103,18 +104,6 @@ static bool isapnp = 0;
103static int aha1542[] = {0x330, 11, 4, -1}; 104static int aha1542[] = {0x330, 11, 4, -1};
104module_param_array(aha1542, int, NULL, 0); 105module_param_array(aha1542, int, NULL, 0);
105module_param(isapnp, bool, 0); 106module_param(isapnp, bool, 0);
106
107static struct isapnp_device_id id_table[] __initdata = {
108 {
109 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
110 ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1542),
111 0
112 },
113 {0}
114};
115
116MODULE_DEVICE_TABLE(isapnp, id_table);
117
118#else 107#else
119static int isapnp = 1; 108static int isapnp = 1;
120#endif 109#endif
@@ -221,7 +210,7 @@ fail:
221/* Only used at boot time, so we do not need to worry about latency as much 210/* Only used at boot time, so we do not need to worry about latency as much
222 here */ 211 here */
223 212
224static int __init aha1542_in(unsigned int base, unchar * cmdp, int len) 213static int aha1542_in(unsigned int base, unchar *cmdp, int len)
225{ 214{
226 unsigned long flags; 215 unsigned long flags;
227 216
@@ -242,7 +231,7 @@ fail:
242/* Similar to aha1542_in, except that we wait a very short period of time. 231/* Similar to aha1542_in, except that we wait a very short period of time.
243 We use this if we know the board is alive and awake, but we are not sure 232 We use this if we know the board is alive and awake, but we are not sure
244 if the board will respond to the command we are about to send or not */ 233 if the board will respond to the command we are about to send or not */
245static int __init aha1542_in1(unsigned int base, unchar * cmdp, int len) 234static int aha1542_in1(unsigned int base, unchar *cmdp, int len)
246{ 235{
247 unsigned long flags; 236 unsigned long flags;
248 237
@@ -314,7 +303,7 @@ static int makecode(unsigned hosterr, unsigned scsierr)
314 return scsierr | (hosterr << 16); 303 return scsierr | (hosterr << 16);
315} 304}
316 305
317static int __init aha1542_test_port(int bse, struct Scsi_Host *shpnt) 306static int aha1542_test_port(int bse, struct Scsi_Host *shpnt)
318{ 307{
319 unchar inquiry_cmd[] = {CMD_INQUIRY}; 308 unchar inquiry_cmd[] = {CMD_INQUIRY};
320 unchar inquiry_result[4]; 309 unchar inquiry_result[4];
@@ -744,7 +733,7 @@ fail:
744 aha1542_intr_reset(bse); 733 aha1542_intr_reset(bse);
745} 734}
746 735
747static int __init aha1542_getconfig(int base_io, unsigned char *irq_level, unsigned char *dma_chan, unsigned char *scsi_id) 736static int aha1542_getconfig(int base_io, unsigned char *irq_level, unsigned char *dma_chan, unsigned char *scsi_id)
748{ 737{
749 unchar inquiry_cmd[] = {CMD_RETCONF}; 738 unchar inquiry_cmd[] = {CMD_RETCONF};
750 unchar inquiry_result[3]; 739 unchar inquiry_result[3];
@@ -813,7 +802,7 @@ fail:
813/* This function should only be called for 1542C boards - we can detect 802/* This function should only be called for 1542C boards - we can detect
814 the special firmware settings and unlock the board */ 803 the special firmware settings and unlock the board */
815 804
816static int __init aha1542_mbenable(int base) 805static int aha1542_mbenable(int base)
817{ 806{
818 static unchar mbenable_cmd[3]; 807 static unchar mbenable_cmd[3];
819 static unchar mbenable_result[2]; 808 static unchar mbenable_result[2];
@@ -848,7 +837,7 @@ fail:
848} 837}
849 838
850/* Query the board to find out if it is a 1542 or a 1740, or whatever. */ 839/* Query the board to find out if it is a 1542 or a 1740, or whatever. */
851static int __init aha1542_query(int base_io, int *transl) 840static int aha1542_query(int base_io, int *transl)
852{ 841{
853 unchar inquiry_cmd[] = {CMD_INQUIRY}; 842 unchar inquiry_cmd[] = {CMD_INQUIRY};
854 unchar inquiry_result[4]; 843 unchar inquiry_result[4];
@@ -963,7 +952,7 @@ __setup("aha1542=",do_setup);
963#endif 952#endif
964 953
965/* return non-zero on detection */ 954/* return non-zero on detection */
966static int __init aha1542_detect(struct scsi_host_template * tpnt) 955static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, struct device *pdev, int indx)
967{ 956{
968 unsigned char dma_chan; 957 unsigned char dma_chan;
969 unsigned char irq_level; 958 unsigned char irq_level;
@@ -972,87 +961,18 @@ static int __init aha1542_detect(struct scsi_host_template * tpnt)
972 unsigned int base_io; 961 unsigned int base_io;
973 int trans; 962 int trans;
974 struct Scsi_Host *shpnt = NULL; 963 struct Scsi_Host *shpnt = NULL;
975 int count = 0;
976 int indx;
977 964
978 DEB(printk("aha1542_detect: \n")); 965 DEB(printk("aha1542_detect: \n"));
979 966
980 tpnt->proc_name = "aha1542"; 967 tpnt->proc_name = "aha1542";
981 968
982#ifdef MODULE
983 bases[0] = aha1542[0];
984 setup_buson[0] = aha1542[1];
985 setup_busoff[0] = aha1542[2];
986 {
987 int atbt = -1;
988 switch (aha1542[3]) {
989 case 5:
990 atbt = 0x00;
991 break;
992 case 6:
993 atbt = 0x04;
994 break;
995 case 7:
996 atbt = 0x01;
997 break;
998 case 8:
999 atbt = 0x02;
1000 break;
1001 case 10:
1002 atbt = 0x03;
1003 break;
1004 };
1005 setup_dmaspeed[0] = atbt;
1006 }
1007#endif
1008
1009 /*
1010 * Hunt for ISA Plug'n'Pray Adaptecs (AHA1535)
1011 */
1012
1013 if(isapnp)
1014 {
1015 struct pnp_dev *pdev = NULL;
1016 for(indx = 0; indx < ARRAY_SIZE(bases); indx++) {
1017 if(bases[indx])
1018 continue;
1019 pdev = pnp_find_dev(NULL, ISAPNP_VENDOR('A', 'D', 'P'),
1020 ISAPNP_FUNCTION(0x1542), pdev);
1021 if(pdev==NULL)
1022 break;
1023 /*
1024 * Activate the PnP card
1025 */
1026
1027 if(pnp_device_attach(pdev)<0)
1028 continue;
1029
1030 if(pnp_activate_dev(pdev)<0) {
1031 pnp_device_detach(pdev);
1032 continue;
1033 }
1034
1035 if(!pnp_port_valid(pdev, 0)) {
1036 pnp_device_detach(pdev);
1037 continue;
1038 }
1039
1040 bases[indx] = pnp_port_start(pdev, 0);
1041
1042 /* The card can be queried for its DMA, we have
1043 the DMA set up that is enough */
1044
1045 printk(KERN_INFO "ISAPnP found an AHA1535 at I/O 0x%03X\n", bases[indx]);
1046 }
1047 }
1048 for (indx = 0; indx < ARRAY_SIZE(bases); indx++)
1049 if (bases[indx] != 0 && request_region(bases[indx], 4, "aha1542")) { 969 if (bases[indx] != 0 && request_region(bases[indx], 4, "aha1542")) {
1050 shpnt = scsi_register(tpnt, 970 shpnt = scsi_host_alloc(tpnt,
1051 sizeof(struct aha1542_hostdata)); 971 sizeof(struct aha1542_hostdata));
1052 972
1053 if(shpnt==NULL) { 973 if(shpnt==NULL) {
1054 release_region(bases[indx], 4); 974 release_region(bases[indx], 4);
1055 continue; 975 return NULL;
1056 } 976 }
1057 if (!aha1542_test_port(bases[indx], shpnt)) 977 if (!aha1542_test_port(bases[indx], shpnt))
1058 goto unregister; 978 goto unregister;
@@ -1137,60 +1057,37 @@ fail:
1137 HOSTDATA(shpnt)->aha1542_last_mbo_used = (AHA1542_MAILBOXES - 1); 1057 HOSTDATA(shpnt)->aha1542_last_mbo_used = (AHA1542_MAILBOXES - 1);
1138 memset(HOSTDATA(shpnt)->SCint, 0, sizeof(HOSTDATA(shpnt)->SCint)); 1058 memset(HOSTDATA(shpnt)->SCint, 0, sizeof(HOSTDATA(shpnt)->SCint));
1139 spin_unlock_irqrestore(&aha1542_lock, flags); 1059 spin_unlock_irqrestore(&aha1542_lock, flags);
1140#if 0
1141 DEB(printk(" *** READ CAPACITY ***\n"));
1142 1060
1143 { 1061 if (scsi_add_host(shpnt, pdev)) {
1144 unchar buf[8]; 1062 if (shpnt->dma_channel != 0xff)
1145 static unchar cmd[] = { READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1063 free_dma(shpnt->dma_channel);
1146 int i; 1064 free_irq(irq_level, shpnt);
1147 1065 goto unregister;
1148 for (i = 0; i < sizeof(buf); ++i)
1149 buf[i] = 0x87;
1150 for (i = 0; i < 2; ++i)
1151 if (!aha1542_command(i, cmd, buf, sizeof(buf))) {
1152 printk(KERN_DEBUG "aha_detect: LU %d sector_size %d device_size %d\n",
1153 i, xscsi2int(buf + 4), xscsi2int(buf));
1154 }
1155 } 1066 }
1156 1067
1157 DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n")); 1068 scsi_scan_host(shpnt);
1158 1069
1159 for (i = 0; i < 4; ++i) { 1070 return shpnt;
1160 unsigned char cmd[10];
1161 static buffer[512];
1162
1163 cmd[0] = READ_10;
1164 cmd[1] = 0;
1165 xany2scsi(cmd + 2, i);
1166 cmd[6] = 0;
1167 cmd[7] = 0;
1168 cmd[8] = 1;
1169 cmd[9] = 0;
1170 aha1542_command(0, cmd, buffer, 512);
1171 }
1172#endif
1173 count++;
1174 continue;
1175unregister: 1071unregister:
1176 release_region(bases[indx], 4); 1072 release_region(bases[indx], 4);
1177 scsi_unregister(shpnt); 1073 scsi_host_put(shpnt);
1178 continue; 1074 return NULL;
1179 1075
1180 }; 1076 };
1181 1077
1182 return count; 1078 return NULL;
1183} 1079}
1184 1080
1185static int aha1542_release(struct Scsi_Host *shost) 1081static int aha1542_release(struct Scsi_Host *shost)
1186{ 1082{
1083 scsi_remove_host(shost);
1187 if (shost->irq) 1084 if (shost->irq)
1188 free_irq(shost->irq, shost); 1085 free_irq(shost->irq, shost);
1189 if (shost->dma_channel != 0xff) 1086 if (shost->dma_channel != 0xff)
1190 free_dma(shost->dma_channel); 1087 free_dma(shost->dma_channel);
1191 if (shost->io_port && shost->n_io_port) 1088 if (shost->io_port && shost->n_io_port)
1192 release_region(shost->io_port, shost->n_io_port); 1089 release_region(shost->io_port, shost->n_io_port);
1193 scsi_unregister(shost); 1090 scsi_host_put(shost);
1194 return 0; 1091 return 0;
1195} 1092}
1196 1093
@@ -1661,12 +1558,10 @@ static int aha1542_biosparam(struct scsi_device *sdev,
1661} 1558}
1662MODULE_LICENSE("GPL"); 1559MODULE_LICENSE("GPL");
1663 1560
1664
1665static struct scsi_host_template driver_template = { 1561static struct scsi_host_template driver_template = {
1562 .module = THIS_MODULE,
1666 .proc_name = "aha1542", 1563 .proc_name = "aha1542",
1667 .name = "Adaptec 1542", 1564 .name = "Adaptec 1542",
1668 .detect = aha1542_detect,
1669 .release = aha1542_release,
1670 .queuecommand = aha1542_queuecommand, 1565 .queuecommand = aha1542_queuecommand,
1671 .eh_device_reset_handler= aha1542_dev_reset, 1566 .eh_device_reset_handler= aha1542_dev_reset,
1672 .eh_bus_reset_handler = aha1542_bus_reset, 1567 .eh_bus_reset_handler = aha1542_bus_reset,
@@ -1679,4 +1574,145 @@ static struct scsi_host_template driver_template = {
1679 .unchecked_isa_dma = 1, 1574 .unchecked_isa_dma = 1,
1680 .use_clustering = ENABLE_CLUSTERING, 1575 .use_clustering = ENABLE_CLUSTERING,
1681}; 1576};
1682#include "scsi_module.c" 1577
1578static int aha1542_isa_match(struct device *pdev, unsigned int ndev)
1579{
1580 struct Scsi_Host *sh = aha1542_hw_init(&driver_template, pdev, ndev);
1581
1582 if (!sh)
1583 return 0;
1584
1585 dev_set_drvdata(pdev, sh);
1586 return 1;
1587}
1588
1589static int aha1542_isa_remove(struct device *pdev,
1590 unsigned int ndev)
1591{
1592 aha1542_release(dev_get_drvdata(pdev));
1593 dev_set_drvdata(pdev, NULL);
1594 return 0;
1595}
1596
1597static struct isa_driver aha1542_isa_driver = {
1598 .match = aha1542_isa_match,
1599 .remove = aha1542_isa_remove,
1600 .driver = {
1601 .name = "aha1542"
1602 },
1603};
1604static int isa_registered;
1605
1606#ifdef CONFIG_PNP
1607static struct pnp_device_id aha1542_pnp_ids[] = {
1608 { .id = "ADP1542" },
1609 { .id = "" }
1610};
1611MODULE_DEVICE_TABLE(pnp, aha1542_pnp_ids);
1612
1613static int aha1542_pnp_probe(struct pnp_dev *pdev, const struct pnp_device_id *id)
1614{
1615 int indx;
1616 struct Scsi_Host *sh;
1617
1618 for (indx = 0; indx < ARRAY_SIZE(bases); indx++) {
1619 if (bases[indx])
1620 continue;
1621
1622 if (pnp_activate_dev(pdev) < 0)
1623 continue;
1624
1625 bases[indx] = pnp_port_start(pdev, 0);
1626
1627 /* The card can be queried for its DMA, we have
1628 the DMA set up that is enough */
1629
1630 printk(KERN_INFO "ISAPnP found an AHA1535 at I/O 0x%03X\n", bases[indx]);
1631 }
1632
1633 sh = aha1542_hw_init(&driver_template, &pdev->dev, indx);
1634 if (!sh)
1635 return -ENODEV;
1636
1637 pnp_set_drvdata(pdev, sh);
1638 return 0;
1639}
1640
1641static void aha1542_pnp_remove(struct pnp_dev *pdev)
1642{
1643 aha1542_release(pnp_get_drvdata(pdev));
1644 pnp_set_drvdata(pdev, NULL);
1645}
1646
1647static struct pnp_driver aha1542_pnp_driver = {
1648 .name = "aha1542",
1649 .id_table = aha1542_pnp_ids,
1650 .probe = aha1542_pnp_probe,
1651 .remove = aha1542_pnp_remove,
1652};
1653static int pnp_registered;
1654#endif /* CONFIG_PNP */
1655
1656static int __init aha1542_init(void)
1657{
1658 int ret = 0;
1659#ifdef MODULE
1660 int atbt = -1;
1661
1662 bases[0] = aha1542[0];
1663 setup_buson[0] = aha1542[1];
1664 setup_busoff[0] = aha1542[2];
1665
1666 switch (aha1542[3]) {
1667 case 5:
1668 atbt = 0x00;
1669 break;
1670 case 6:
1671 atbt = 0x04;
1672 break;
1673 case 7:
1674 atbt = 0x01;
1675 break;
1676 case 8:
1677 atbt = 0x02;
1678 break;
1679 case 10:
1680 atbt = 0x03;
1681 break;
1682 };
1683 setup_dmaspeed[0] = atbt;
1684#endif
1685
1686#ifdef CONFIG_PNP
1687 if (isapnp) {
1688 ret = pnp_register_driver(&aha1542_pnp_driver);
1689 if (!ret)
1690 pnp_registered = 1;
1691 }
1692#endif
1693 ret = isa_register_driver(&aha1542_isa_driver, MAXBOARDS);
1694 if (!ret)
1695 isa_registered = 1;
1696
1697#ifdef CONFIG_PNP
1698 if (pnp_registered)
1699 ret = 0;
1700#endif
1701 if (isa_registered)
1702 ret = 0;
1703
1704 return ret;
1705}
1706
1707static void __exit aha1542_exit(void)
1708{
1709#ifdef CONFIG_PNP
1710 if (pnp_registered)
1711 pnp_unregister_driver(&aha1542_pnp_driver);
1712#endif
1713 if (isa_registered)
1714 isa_unregister_driver(&aha1542_isa_driver);
1715}
1716
1717module_init(aha1542_init);
1718module_exit(aha1542_exit);
diff --git a/drivers/scsi/aha1542.h b/drivers/scsi/aha1542.h
index b871d2b57f93..76e6abc944e8 100644
--- a/drivers/scsi/aha1542.h
+++ b/drivers/scsi/aha1542.h
@@ -131,7 +131,7 @@ struct ccb { /* Command Control Block 5.3 */
131 /* REQUEST SENSE */ 131 /* REQUEST SENSE */
132}; 132};
133 133
134static int aha1542_detect(struct scsi_host_template *); 134static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, struct device *pdev, int indx);
135static int aha1542_queuecommand(struct Scsi_Host *, struct scsi_cmnd *); 135static int aha1542_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
136static int aha1542_bus_reset(Scsi_Cmnd * SCpnt); 136static int aha1542_bus_reset(Scsi_Cmnd * SCpnt);
137static int aha1542_dev_reset(Scsi_Cmnd * SCpnt); 137static int aha1542_dev_reset(Scsi_Cmnd * SCpnt);