aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/aic7xxx
diff options
context:
space:
mode:
authorJames Bottomley <jejb@titanic.(none)>2005-06-17 19:42:23 -0400
committerJames Bottomley <jejb@titanic.(none)>2005-06-17 19:42:23 -0400
commit3237ee78fc00f786d5f5aec6f9310b0e39069f15 (patch)
tree4c94e70ab846ffcb8bb5715fb3c8d8473358a323 /drivers/scsi/aic7xxx
parent9ee1c939d1cb936b1f98e8d81aeffab57bae46ab (diff)
parentdf0ae2497ddefd72a87f3a3b34ff32455d7d4ae0 (diff)
merge by hand (fix up qla_os.c merge error)
Diffstat (limited to 'drivers/scsi/aic7xxx')
-rw-r--r--drivers/scsi/aic7xxx/aic7770_osm.c189
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c20
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.h17
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx.h2
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_core.c16
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.c660
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.h64
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm_pci.c44
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_proc.c31
9 files changed, 341 insertions, 702 deletions
diff --git a/drivers/scsi/aic7xxx/aic7770_osm.c b/drivers/scsi/aic7xxx/aic7770_osm.c
index 682ca0b32b44..d4ed5e9f830a 100644
--- a/drivers/scsi/aic7xxx/aic7770_osm.c
+++ b/drivers/scsi/aic7xxx/aic7770_osm.c
@@ -44,88 +44,46 @@
44#include <linux/device.h> 44#include <linux/device.h>
45#include <linux/eisa.h> 45#include <linux/eisa.h>
46 46
47#define EISA_MFCTR_CHAR0(ID) (char)(((ID>>26) & 0x1F) | '@') /* Bits 26-30 */
48#define EISA_MFCTR_CHAR1(ID) (char)(((ID>>21) & 0x1F) | '@') /* Bits 21-25 */
49#define EISA_MFCTR_CHAR2(ID) (char)(((ID>>16) & 0x1F) | '@') /* Bits 16-20 */
50#define EISA_PRODUCT_ID(ID) (short)((ID>>4) & 0xFFF) /* Bits 4-15 */
51#define EISA_REVISION_ID(ID) (uint8_t)(ID & 0x0F) /* Bits 0-3 */
52
53static int aic7770_eisa_dev_probe(struct device *dev);
54static int aic7770_eisa_dev_remove(struct device *dev);
55static struct eisa_driver aic7770_driver = {
56 .driver = {
57 .name = "aic7xxx",
58 .probe = aic7770_eisa_dev_probe,
59 .remove = aic7770_eisa_dev_remove,
60 }
61};
62
63typedef struct device *aic7770_dev_t;
64
65static int aic7770_linux_config(struct aic7770_identity *entry,
66 aic7770_dev_t dev, u_int eisaBase);
67
68int 47int
69ahc_linux_eisa_init(void) 48aic7770_map_registers(struct ahc_softc *ahc, u_int port)
70{ 49{
71 struct eisa_device_id *eid;
72 struct aic7770_identity *id;
73 int i;
74
75 if (aic7xxx_probe_eisa_vl == 0)
76 return -ENODEV;
77
78 /* 50 /*
79 * Linux requires the EISA IDs to be specified in 51 * Lock out other contenders for our i/o space.
80 * the EISA ID string format. Perform the conversion
81 * and setup a table with a NUL terminal entry.
82 */ 52 */
83 aic7770_driver.id_table = malloc(sizeof(struct eisa_device_id) * 53 if (request_region(port, AHC_EISA_IOSIZE, "aic7xxx") == 0)
84 (ahc_num_aic7770_devs + 1), 54 return (ENOMEM);
85 M_DEVBUF, M_NOWAIT); 55 ahc->tag = BUS_SPACE_PIO;
86 if (aic7770_driver.id_table == NULL) 56 ahc->bsh.ioport = port;
87 return -ENOMEM; 57 return (0);
88
89 for (eid = (struct eisa_device_id *)aic7770_driver.id_table,
90 id = aic7770_ident_table, i = 0;
91 i < ahc_num_aic7770_devs; eid++, id++, i++) {
92
93 sprintf(eid->sig, "%c%c%c%03X%01X",
94 EISA_MFCTR_CHAR0(id->full_id),
95 EISA_MFCTR_CHAR1(id->full_id),
96 EISA_MFCTR_CHAR2(id->full_id),
97 EISA_PRODUCT_ID(id->full_id),
98 EISA_REVISION_ID(id->full_id));
99 eid->driver_data = i;
100 }
101 eid->sig[0] = 0;
102
103 return eisa_driver_register(&aic7770_driver);
104} 58}
105 59
106void 60int
107ahc_linux_eisa_exit(void) 61aic7770_map_int(struct ahc_softc *ahc, u_int irq)
108{ 62{
109 if(aic7xxx_probe_eisa_vl != 0 && aic7770_driver.id_table != NULL) { 63 int error;
110 eisa_driver_unregister(&aic7770_driver); 64 int shared;
111 free(aic7770_driver.id_table, M_DEVBUF); 65
112 } 66 shared = 0;
67 if ((ahc->flags & AHC_EDGE_INTERRUPT) == 0)
68 shared = SA_SHIRQ;
69
70 error = request_irq(irq, ahc_linux_isr, shared, "aic7xxx", ahc);
71 if (error == 0)
72 ahc->platform_data->irq = irq;
73
74 return (-error);
113} 75}
114 76
115static int 77static int
116aic7770_linux_config(struct aic7770_identity *entry, aic7770_dev_t dev, 78aic7770_probe(struct device *dev)
117 u_int eisaBase)
118{ 79{
80 struct eisa_device *edev = to_eisa_device(dev);
81 u_int eisaBase = edev->base_addr+AHC_EISA_SLOT_OFFSET;
119 struct ahc_softc *ahc; 82 struct ahc_softc *ahc;
120 char buf[80]; 83 char buf[80];
121 char *name; 84 char *name;
122 int error; 85 int error;
123 86
124 /*
125 * Allocate a softc for this card and
126 * set it up for attachment by our
127 * common detect routine.
128 */
129 sprintf(buf, "ahc_eisa:%d", eisaBase >> 12); 87 sprintf(buf, "ahc_eisa:%d", eisaBase >> 12);
130 name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT); 88 name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
131 if (name == NULL) 89 if (name == NULL)
@@ -134,81 +92,62 @@ aic7770_linux_config(struct aic7770_identity *entry, aic7770_dev_t dev,
134 ahc = ahc_alloc(&aic7xxx_driver_template, name); 92 ahc = ahc_alloc(&aic7xxx_driver_template, name);
135 if (ahc == NULL) 93 if (ahc == NULL)
136 return (ENOMEM); 94 return (ENOMEM);
137 error = aic7770_config(ahc, entry, eisaBase); 95 error = aic7770_config(ahc, aic7770_ident_table + edev->id.driver_data,
96 eisaBase);
138 if (error != 0) { 97 if (error != 0) {
139 ahc->bsh.ioport = 0; 98 ahc->bsh.ioport = 0;
140 ahc_free(ahc); 99 ahc_free(ahc);
141 return (error); 100 return (error);
142 } 101 }
143 102
144 dev->driver_data = (void *)ahc; 103 dev_set_drvdata(dev, ahc);
104
145 if (aic7xxx_detect_complete) 105 if (aic7xxx_detect_complete)
146 error = ahc_linux_register_host(ahc, &aic7xxx_driver_template); 106 error = ahc_linux_register_host(ahc, &aic7xxx_driver_template);
147 return (error); 107 return (error);
148} 108}
149 109
150int 110static int
151aic7770_map_registers(struct ahc_softc *ahc, u_int port) 111aic7770_remove(struct device *dev)
152{
153 /*
154 * Lock out other contenders for our i/o space.
155 */
156 if (request_region(port, AHC_EISA_IOSIZE, "aic7xxx") == 0)
157 return (ENOMEM);
158 ahc->tag = BUS_SPACE_PIO;
159 ahc->bsh.ioport = port;
160 return (0);
161}
162
163int
164aic7770_map_int(struct ahc_softc *ahc, u_int irq)
165{ 112{
166 int error; 113 struct ahc_softc *ahc = dev_get_drvdata(dev);
167 int shared; 114 u_long s;
168 115
169 shared = 0; 116 ahc_lock(ahc, &s);
170 if ((ahc->flags & AHC_EDGE_INTERRUPT) == 0) 117 ahc_intr_enable(ahc, FALSE);
171 shared = SA_SHIRQ; 118 ahc_unlock(ahc, &s);
172 119
173 error = request_irq(irq, ahc_linux_isr, shared, "aic7xxx", ahc); 120 ahc_free(ahc);
174 if (error == 0) 121 return 0;
175 ahc->platform_data->irq = irq;
176
177 return (-error);
178} 122}
179 123
180static int 124static struct eisa_device_id aic7770_ids[] = {
181aic7770_eisa_dev_probe(struct device *dev) 125 { "ADP7771", 0 }, /* AHA 274x */
126 { "ADP7756", 1 }, /* AHA 284x BIOS enabled */
127 { "ADP7757", 2 }, /* AHA 284x BIOS disabled */
128 { "ADP7782", 3 }, /* AHA 274x Olivetti OEM */
129 { "ADP7783", 4 }, /* AHA 274x Olivetti OEM (Differential) */
130 { "ADP7770", 5 }, /* AIC7770 generic */
131 { "" }
132};
133
134static struct eisa_driver aic7770_driver = {
135 .id_table = aic7770_ids,
136 .driver = {
137 .name = "aic7xxx",
138 .probe = aic7770_probe,
139 .remove = aic7770_remove,
140 }
141};
142
143int
144ahc_linux_eisa_init(void)
182{ 145{
183 struct eisa_device *edev; 146 return eisa_driver_register(&aic7770_driver);
184
185 edev = to_eisa_device(dev);
186 return (aic7770_linux_config(aic7770_ident_table + edev->id.driver_data,
187 dev, edev->base_addr+AHC_EISA_SLOT_OFFSET));
188} 147}
189 148
190static int 149void
191aic7770_eisa_dev_remove(struct device *dev) 150ahc_linux_eisa_exit(void)
192{ 151{
193 struct ahc_softc *ahc; 152 eisa_driver_unregister(&aic7770_driver);
194 u_long l;
195
196 /*
197 * We should be able to just perform
198 * the free directly, but check our
199 * list for extra sanity.
200 */
201 ahc_list_lock(&l);
202 ahc = ahc_find_softc((struct ahc_softc *)dev->driver_data);
203 if (ahc != NULL) {
204 u_long s;
205
206 ahc_lock(ahc, &s);
207 ahc_intr_enable(ahc, FALSE);
208 ahc_unlock(ahc, &s);
209 ahc_free(ahc);
210 }
211 ahc_list_unlock(&l);
212
213 return (0);
214} 153}
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index 7c02b7dc7098..c4eaaad2c69b 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -941,7 +941,7 @@ ahd_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
941 */ 941 */
942 cmd->scsi_done = scsi_done; 942 cmd->scsi_done = scsi_done;
943 943
944 ahd_midlayer_entrypoint_lock(ahd, &flags); 944 ahd_lock(ahd, &flags);
945 945
946 /* 946 /*
947 * Close the race of a command that was in the process of 947 * Close the race of a command that was in the process of
@@ -955,7 +955,7 @@ ahd_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
955 ahd_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ); 955 ahd_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ);
956 ahd_linux_queue_cmd_complete(ahd, cmd); 956 ahd_linux_queue_cmd_complete(ahd, cmd);
957 ahd_schedule_completeq(ahd); 957 ahd_schedule_completeq(ahd);
958 ahd_midlayer_entrypoint_unlock(ahd, &flags); 958 ahd_unlock(ahd, &flags);
959 return (0); 959 return (0);
960 } 960 }
961 dev = ahd_linux_get_device(ahd, cmd->device->channel, 961 dev = ahd_linux_get_device(ahd, cmd->device->channel,
@@ -965,7 +965,7 @@ ahd_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
965 ahd_cmd_set_transaction_status(cmd, CAM_RESRC_UNAVAIL); 965 ahd_cmd_set_transaction_status(cmd, CAM_RESRC_UNAVAIL);
966 ahd_linux_queue_cmd_complete(ahd, cmd); 966 ahd_linux_queue_cmd_complete(ahd, cmd);
967 ahd_schedule_completeq(ahd); 967 ahd_schedule_completeq(ahd);
968 ahd_midlayer_entrypoint_unlock(ahd, &flags); 968 ahd_unlock(ahd, &flags);
969 printf("%s: aic79xx_linux_queue - Unable to allocate device!\n", 969 printf("%s: aic79xx_linux_queue - Unable to allocate device!\n",
970 ahd_name(ahd)); 970 ahd_name(ahd));
971 return (0); 971 return (0);
@@ -979,7 +979,7 @@ ahd_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
979 dev->flags |= AHD_DEV_ON_RUN_LIST; 979 dev->flags |= AHD_DEV_ON_RUN_LIST;
980 ahd_linux_run_device_queues(ahd); 980 ahd_linux_run_device_queues(ahd);
981 } 981 }
982 ahd_midlayer_entrypoint_unlock(ahd, &flags); 982 ahd_unlock(ahd, &flags);
983 return (0); 983 return (0);
984} 984}
985 985
@@ -1511,17 +1511,17 @@ ahd_linux_dev_reset(Scsi_Cmnd *cmd)
1511 ahd_name(ahd), cmd->device->channel, cmd->device->id, 1511 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1512 cmd->device->lun, cmd); 1512 cmd->device->lun, cmd);
1513#endif 1513#endif
1514 ahd_midlayer_entrypoint_lock(ahd, &s); 1514 ahd_lock(ahd, &s);
1515 1515
1516 dev = ahd_linux_get_device(ahd, cmd->device->channel, cmd->device->id, 1516 dev = ahd_linux_get_device(ahd, cmd->device->channel, cmd->device->id,
1517 cmd->device->lun, /*alloc*/FALSE); 1517 cmd->device->lun, /*alloc*/FALSE);
1518 if (dev == NULL) { 1518 if (dev == NULL) {
1519 ahd_midlayer_entrypoint_unlock(ahd, &s); 1519 ahd_unlock(ahd, &s);
1520 kfree(recovery_cmd); 1520 kfree(recovery_cmd);
1521 return (FAILED); 1521 return (FAILED);
1522 } 1522 }
1523 if ((scb = ahd_get_scb(ahd, AHD_NEVER_COL_IDX)) == NULL) { 1523 if ((scb = ahd_get_scb(ahd, AHD_NEVER_COL_IDX)) == NULL) {
1524 ahd_midlayer_entrypoint_unlock(ahd, &s); 1524 ahd_unlock(ahd, &s);
1525 kfree(recovery_cmd); 1525 kfree(recovery_cmd);
1526 return (FAILED); 1526 return (FAILED);
1527 } 1527 }
@@ -1570,7 +1570,7 @@ ahd_linux_dev_reset(Scsi_Cmnd *cmd)
1570 spin_lock_irq(&ahd->platform_data->spin_lock); 1570 spin_lock_irq(&ahd->platform_data->spin_lock);
1571 ahd_schedule_runq(ahd); 1571 ahd_schedule_runq(ahd);
1572 ahd_linux_run_complete_queue(ahd); 1572 ahd_linux_run_complete_queue(ahd);
1573 ahd_midlayer_entrypoint_unlock(ahd, &s); 1573 ahd_unlock(ahd, &s);
1574 printf("%s: Device reset returning 0x%x\n", ahd_name(ahd), retval); 1574 printf("%s: Device reset returning 0x%x\n", ahd_name(ahd), retval);
1575 return (retval); 1575 return (retval);
1576} 1576}
@@ -1591,11 +1591,11 @@ ahd_linux_bus_reset(Scsi_Cmnd *cmd)
1591 printf("%s: Bus reset called for cmd %p\n", 1591 printf("%s: Bus reset called for cmd %p\n",
1592 ahd_name(ahd), cmd); 1592 ahd_name(ahd), cmd);
1593#endif 1593#endif
1594 ahd_midlayer_entrypoint_lock(ahd, &s); 1594 ahd_lock(ahd, &s);
1595 found = ahd_reset_channel(ahd, cmd->device->channel + 'A', 1595 found = ahd_reset_channel(ahd, cmd->device->channel + 'A',
1596 /*initiate reset*/TRUE); 1596 /*initiate reset*/TRUE);
1597 ahd_linux_run_complete_queue(ahd); 1597 ahd_linux_run_complete_queue(ahd);
1598 ahd_midlayer_entrypoint_unlock(ahd, &s); 1598 ahd_unlock(ahd, &s);
1599 1599
1600 if (bootverbose) 1600 if (bootverbose)
1601 printf("%s: SCSI bus reset delivered. " 1601 printf("%s: SCSI bus reset delivered. "
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.h b/drivers/scsi/aic7xxx/aic79xx_osm.h
index 605f92b6c5ca..7823e52e99ab 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.h
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.h
@@ -112,23 +112,6 @@ typedef Scsi_Cmnd *ahd_io_ctx_t;
112#define ahd_le32toh(x) le32_to_cpu(x) 112#define ahd_le32toh(x) le32_to_cpu(x)
113#define ahd_le64toh(x) le64_to_cpu(x) 113#define ahd_le64toh(x) le64_to_cpu(x)
114 114
115#ifndef LITTLE_ENDIAN
116#define LITTLE_ENDIAN 1234
117#endif
118
119#ifndef BIG_ENDIAN
120#define BIG_ENDIAN 4321
121#endif
122
123#ifndef BYTE_ORDER
124#if defined(__BIG_ENDIAN)
125#define BYTE_ORDER BIG_ENDIAN
126#endif
127#if defined(__LITTLE_ENDIAN)
128#define BYTE_ORDER LITTLE_ENDIAN
129#endif
130#endif /* BYTE_ORDER */
131
132/************************* Configuration Data *********************************/ 115/************************* Configuration Data *********************************/
133extern uint32_t aic79xx_allow_memio; 116extern uint32_t aic79xx_allow_memio;
134extern int aic79xx_detect_complete; 117extern int aic79xx_detect_complete;
diff --git a/drivers/scsi/aic7xxx/aic7xxx.h b/drivers/scsi/aic7xxx/aic7xxx.h
index 8ff16fd8ed49..0948d50ae75c 100644
--- a/drivers/scsi/aic7xxx/aic7xxx.h
+++ b/drivers/scsi/aic7xxx/aic7xxx.h
@@ -346,7 +346,6 @@ typedef enum {
346 * controller. 346 * controller.
347 */ 347 */
348 AHC_NEWEEPROM_FMT = 0x4000, 348 AHC_NEWEEPROM_FMT = 0x4000,
349 AHC_RESOURCE_SHORTAGE = 0x8000,
350 AHC_TQINFIFO_BLOCKED = 0x10000, /* Blocked waiting for ATIOs */ 349 AHC_TQINFIFO_BLOCKED = 0x10000, /* Blocked waiting for ATIOs */
351 AHC_INT50_SPEEDFLEX = 0x20000, /* 350 AHC_INT50_SPEEDFLEX = 0x20000, /*
352 * Internal 50pin connector 351 * Internal 50pin connector
@@ -1200,7 +1199,6 @@ void ahc_pause_and_flushwork(struct ahc_softc *ahc);
1200int ahc_suspend(struct ahc_softc *ahc); 1199int ahc_suspend(struct ahc_softc *ahc);
1201int ahc_resume(struct ahc_softc *ahc); 1200int ahc_resume(struct ahc_softc *ahc);
1202void ahc_softc_insert(struct ahc_softc *); 1201void ahc_softc_insert(struct ahc_softc *);
1203struct ahc_softc *ahc_find_softc(struct ahc_softc *ahc);
1204void ahc_set_unit(struct ahc_softc *, int); 1202void ahc_set_unit(struct ahc_softc *, int);
1205void ahc_set_name(struct ahc_softc *, char *); 1203void ahc_set_name(struct ahc_softc *, char *);
1206void ahc_alloc_scbs(struct ahc_softc *ahc); 1204void ahc_alloc_scbs(struct ahc_softc *ahc);
diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c
index 9a6b4a570aa7..8a2bb6f8d77b 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_core.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
@@ -3934,22 +3934,6 @@ ahc_softc_insert(struct ahc_softc *ahc)
3934 ahc->init_level++; 3934 ahc->init_level++;
3935} 3935}
3936 3936
3937/*
3938 * Verify that the passed in softc pointer is for a
3939 * controller that is still configured.
3940 */
3941struct ahc_softc *
3942ahc_find_softc(struct ahc_softc *ahc)
3943{
3944 struct ahc_softc *list_ahc;
3945
3946 TAILQ_FOREACH(list_ahc, &ahc_tailq, links) {
3947 if (list_ahc == ahc)
3948 return (ahc);
3949 }
3950 return (NULL);
3951}
3952
3953void 3937void
3954ahc_set_unit(struct ahc_softc *ahc, int unit) 3938ahc_set_unit(struct ahc_softc *ahc, int unit)
3955{ 3939{
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index c13e56320010..b89094db14c1 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -122,8 +122,6 @@
122#include "aic7xxx_osm.h" 122#include "aic7xxx_osm.h"
123#include "aic7xxx_inline.h" 123#include "aic7xxx_inline.h"
124#include <scsi/scsicam.h> 124#include <scsi/scsicam.h>
125#include <scsi/scsi_transport.h>
126#include <scsi/scsi_transport_spi.h>
127 125
128static struct scsi_transport_template *ahc_linux_transport_template = NULL; 126static struct scsi_transport_template *ahc_linux_transport_template = NULL;
129 127
@@ -332,22 +330,6 @@ static uint32_t aic7xxx_extended;
332static uint32_t aic7xxx_pci_parity = ~0; 330static uint32_t aic7xxx_pci_parity = ~0;
333 331
334/* 332/*
335 * Certain newer motherboards have put new PCI based devices into the
336 * IO spaces that used to typically be occupied by VLB or EISA cards.
337 * This overlap can cause these newer motherboards to lock up when scanned
338 * for older EISA and VLB devices. Setting this option to non-0 will
339 * cause the driver to skip scanning for any VLB or EISA controllers and
340 * only support the PCI controllers. NOTE: this means that if the kernel
341 * os compiled with PCI support disabled, then setting this to non-0
342 * would result in never finding any devices :)
343 */
344#ifndef CONFIG_AIC7XXX_PROBE_EISA_VL
345uint32_t aic7xxx_probe_eisa_vl;
346#else
347uint32_t aic7xxx_probe_eisa_vl = ~0;
348#endif
349
350/*
351 * There are lots of broken chipsets in the world. Some of them will 333 * There are lots of broken chipsets in the world. Some of them will
352 * violate the PCI spec when we issue byte sized memory writes to our 334 * violate the PCI spec when we issue byte sized memory writes to our
353 * controller. I/O mapped register access, if allowed by the given 335 * controller. I/O mapped register access, if allowed by the given
@@ -423,7 +405,7 @@ MODULE_PARM_DESC(aic7xxx,
423); 405);
424 406
425static void ahc_linux_handle_scsi_status(struct ahc_softc *, 407static void ahc_linux_handle_scsi_status(struct ahc_softc *,
426 struct ahc_linux_device *, 408 struct scsi_device *,
427 struct scb *); 409 struct scb *);
428static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, 410static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc,
429 struct scsi_cmnd *cmd); 411 struct scsi_cmnd *cmd);
@@ -434,17 +416,7 @@ static int ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag);
434static void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc); 416static void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc);
435static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc, 417static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc,
436 struct ahc_devinfo *devinfo); 418 struct ahc_devinfo *devinfo);
437static void ahc_linux_device_queue_depth(struct ahc_softc *ahc, 419static void ahc_linux_device_queue_depth(struct scsi_device *);
438 struct ahc_linux_device *dev);
439static struct ahc_linux_target* ahc_linux_alloc_target(struct ahc_softc*,
440 u_int, u_int);
441static void ahc_linux_free_target(struct ahc_softc*,
442 struct ahc_linux_target*);
443static struct ahc_linux_device* ahc_linux_alloc_device(struct ahc_softc*,
444 struct ahc_linux_target*,
445 u_int);
446static void ahc_linux_free_device(struct ahc_softc*,
447 struct ahc_linux_device*);
448static int ahc_linux_run_command(struct ahc_softc*, 420static int ahc_linux_run_command(struct ahc_softc*,
449 struct ahc_linux_device *, 421 struct ahc_linux_device *,
450 struct scsi_cmnd *); 422 struct scsi_cmnd *);
@@ -454,32 +426,12 @@ static int aic7xxx_setup(char *s);
454static int ahc_linux_next_unit(void); 426static int ahc_linux_next_unit(void);
455 427
456/********************************* Inlines ************************************/ 428/********************************* Inlines ************************************/
457static __inline struct ahc_linux_device*
458 ahc_linux_get_device(struct ahc_softc *ahc, u_int channel,
459 u_int target, u_int lun);
460static __inline void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*); 429static __inline void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*);
461 430
462static __inline int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb, 431static __inline int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
463 struct ahc_dma_seg *sg, 432 struct ahc_dma_seg *sg,
464 dma_addr_t addr, bus_size_t len); 433 dma_addr_t addr, bus_size_t len);
465 434
466static __inline struct ahc_linux_device*
467ahc_linux_get_device(struct ahc_softc *ahc, u_int channel, u_int target,
468 u_int lun)
469{
470 struct ahc_linux_target *targ;
471 struct ahc_linux_device *dev;
472 u_int target_offset;
473
474 target_offset = target;
475 if (channel != 0)
476 target_offset += 8;
477 targ = ahc->platform_data->targets[target_offset];
478 BUG_ON(targ == NULL);
479 dev = targ->devices[lun];
480 return dev;
481}
482
483static __inline void 435static __inline void
484ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb) 436ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb)
485{ 437{
@@ -533,17 +485,6 @@ ahc_linux_detect(struct scsi_host_template *template)
533 int found = 0; 485 int found = 0;
534 486
535 /* 487 /*
536 * Sanity checking of Linux SCSI data structures so
537 * that some of our hacks^H^H^H^H^Hassumptions aren't
538 * violated.
539 */
540 if (offsetof(struct ahc_cmd_internal, end)
541 > offsetof(struct scsi_cmnd, host_scribble)) {
542 printf("ahc_linux_detect: SCSI data structures changed.\n");
543 printf("ahc_linux_detect: Unable to attach\n");
544 return (0);
545 }
546 /*
547 * If we've been passed any parameters, process them now. 488 * If we've been passed any parameters, process them now.
548 */ 489 */
549 if (aic7xxx) 490 if (aic7xxx)
@@ -611,7 +552,7 @@ static int
611ahc_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *)) 552ahc_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
612{ 553{
613 struct ahc_softc *ahc; 554 struct ahc_softc *ahc;
614 struct ahc_linux_device *dev; 555 struct ahc_linux_device *dev = scsi_transport_device_data(cmd->device);
615 556
616 ahc = *(struct ahc_softc **)cmd->device->host->hostdata; 557 ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
617 558
@@ -629,132 +570,177 @@ ahc_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
629 if (ahc->platform_data->qfrozen != 0) 570 if (ahc->platform_data->qfrozen != 0)
630 return SCSI_MLQUEUE_HOST_BUSY; 571 return SCSI_MLQUEUE_HOST_BUSY;
631 572
632 dev = ahc_linux_get_device(ahc, cmd->device->channel, cmd->device->id,
633 cmd->device->lun);
634 BUG_ON(dev == NULL);
635
636 cmd->result = CAM_REQ_INPROG << 16; 573 cmd->result = CAM_REQ_INPROG << 16;
637 574
638 return ahc_linux_run_command(ahc, dev, cmd); 575 return ahc_linux_run_command(ahc, dev, cmd);
639} 576}
640 577
641static int 578static inline struct scsi_target **
642ahc_linux_slave_alloc(struct scsi_device *device) 579ahc_linux_target_in_softc(struct scsi_target *starget)
643{ 580{
644 struct ahc_softc *ahc; 581 struct ahc_softc *ahc =
645 struct ahc_linux_target *targ; 582 *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata);
646 struct scsi_target *starget = device->sdev_target;
647 struct ahc_linux_device *dev;
648 unsigned int target_offset; 583 unsigned int target_offset;
584
585 target_offset = starget->id;
586 if (starget->channel != 0)
587 target_offset += 8;
588
589 return &ahc->platform_data->starget[target_offset];
590}
591
592static int
593ahc_linux_target_alloc(struct scsi_target *starget)
594{
595 struct ahc_softc *ahc =
596 *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata);
597 struct seeprom_config *sc = ahc->seep_config;
649 unsigned long flags; 598 unsigned long flags;
650 int retval = -ENOMEM; 599 struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget);
600 struct ahc_linux_target *targ = scsi_transport_target_data(starget);
601 unsigned short scsirate;
602 struct ahc_devinfo devinfo;
603 struct ahc_initiator_tinfo *tinfo;
604 struct ahc_tmode_tstate *tstate;
605 char channel = starget->channel + 'A';
606 unsigned int our_id = ahc->our_id;
607 unsigned int target_offset;
651 608
652 target_offset = starget->id; 609 target_offset = starget->id;
653 if (starget->channel != 0) 610 if (starget->channel != 0)
654 target_offset += 8; 611 target_offset += 8;
612
613 if (starget->channel)
614 our_id = ahc->our_id_b;
655 615
656 ahc = *((struct ahc_softc **)device->host->hostdata);
657 if (bootverbose)
658 printf("%s: Slave Alloc %d\n", ahc_name(ahc), device->id);
659 ahc_lock(ahc, &flags); 616 ahc_lock(ahc, &flags);
660 targ = ahc->platform_data->targets[target_offset];
661 if (targ == NULL) {
662 struct seeprom_config *sc;
663 617
664 targ = ahc_linux_alloc_target(ahc, starget->channel, 618 BUG_ON(*ahc_targp != NULL);
665 starget->id);
666 sc = ahc->seep_config;
667 if (targ == NULL)
668 goto out;
669 619
670 if (sc) { 620 *ahc_targp = starget;
671 unsigned short scsirate; 621 memset(targ, 0, sizeof(*targ));
672 struct ahc_devinfo devinfo;
673 struct ahc_initiator_tinfo *tinfo;
674 struct ahc_tmode_tstate *tstate;
675 char channel = starget->channel + 'A';
676 unsigned int our_id = ahc->our_id;
677
678 if (starget->channel)
679 our_id = ahc->our_id_b;
680 622
681 if ((ahc->features & AHC_ULTRA2) != 0) { 623 if (sc) {
682 scsirate = sc->device_flags[target_offset] & CFXFER; 624 int maxsync = AHC_SYNCRATE_DT;
683 } else { 625 int ultra = 0;
684 scsirate = (sc->device_flags[target_offset] & CFXFER) << 4; 626 int flags = sc->device_flags[target_offset];
685 if (sc->device_flags[target_offset] & CFSYNCH) 627
686 scsirate |= SOFS; 628 if (ahc->flags & AHC_NEWEEPROM_FMT) {
687 } 629 if (flags & CFSYNCHISULTRA)
688 if (sc->device_flags[target_offset] & CFWIDEB) { 630 ultra = 1;
689 scsirate |= WIDEXFER; 631 } else if (flags & CFULTRAEN)
690 spi_max_width(starget) = 1; 632 ultra = 1;
691 } else 633 /* AIC nutcase; 10MHz appears as ultra = 1, CFXFER = 0x04
692 spi_max_width(starget) = 0; 634 * change it to ultra=0, CFXFER = 0 */
693 spi_min_period(starget) = 635 if(ultra && (flags & CFXFER) == 0x04) {
694 ahc_find_period(ahc, scsirate, AHC_SYNCRATE_DT); 636 ultra = 0;
695 tinfo = ahc_fetch_transinfo(ahc, channel, ahc->our_id, 637 flags &= ~CFXFER;
696 targ->target, &tstate);
697 ahc_compile_devinfo(&devinfo, our_id, targ->target,
698 CAM_LUN_WILDCARD, channel,
699 ROLE_INITIATOR);
700 ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0,
701 AHC_TRANS_GOAL, /*paused*/FALSE);
702 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
703 AHC_TRANS_GOAL, /*paused*/FALSE);
704 } 638 }
705 639
706 } 640 if ((ahc->features & AHC_ULTRA2) != 0) {
707 dev = targ->devices[device->lun]; 641 scsirate = (flags & CFXFER) | (ultra ? 0x8 : 0);
708 if (dev == NULL) { 642 } else {
709 dev = ahc_linux_alloc_device(ahc, targ, device->lun); 643 scsirate = (flags & CFXFER) << 4;
710 if (dev == NULL) 644 maxsync = ultra ? AHC_SYNCRATE_ULTRA :
711 goto out; 645 AHC_SYNCRATE_FAST;
646 }
647 spi_max_width(starget) = (flags & CFWIDEB) ? 1 : 0;
648 if (!(flags & CFSYNCH))
649 spi_max_offset(starget) = 0;
650 spi_min_period(starget) =
651 ahc_find_period(ahc, scsirate, maxsync);
652
653 tinfo = ahc_fetch_transinfo(ahc, channel, ahc->our_id,
654 starget->id, &tstate);
712 } 655 }
713 retval = 0; 656 ahc_compile_devinfo(&devinfo, our_id, starget->id,
714 657 CAM_LUN_WILDCARD, channel,
715 out: 658 ROLE_INITIATOR);
659 ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0,
660 AHC_TRANS_GOAL, /*paused*/FALSE);
661 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
662 AHC_TRANS_GOAL, /*paused*/FALSE);
716 ahc_unlock(ahc, &flags); 663 ahc_unlock(ahc, &flags);
717 return retval; 664
665 return 0;
666}
667
668static void
669ahc_linux_target_destroy(struct scsi_target *starget)
670{
671 struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget);
672
673 *ahc_targp = NULL;
718} 674}
719 675
720static int 676static int
721ahc_linux_slave_configure(struct scsi_device *device) 677ahc_linux_slave_alloc(struct scsi_device *sdev)
678{
679 struct ahc_softc *ahc =
680 *((struct ahc_softc **)sdev->host->hostdata);
681 struct scsi_target *starget = sdev->sdev_target;
682 struct ahc_linux_target *targ = scsi_transport_target_data(starget);
683 struct ahc_linux_device *dev;
684
685 if (bootverbose)
686 printf("%s: Slave Alloc %d\n", ahc_name(ahc), sdev->id);
687
688 BUG_ON(targ->sdev[sdev->lun] != NULL);
689
690 dev = scsi_transport_device_data(sdev);
691 memset(dev, 0, sizeof(*dev));
692
693 /*
694 * We start out life using untagged
695 * transactions of which we allow one.
696 */
697 dev->openings = 1;
698
699 /*
700 * Set maxtags to 0. This will be changed if we
701 * later determine that we are dealing with
702 * a tagged queuing capable device.
703 */
704 dev->maxtags = 0;
705
706 targ->sdev[sdev->lun] = sdev;
707
708 return 0;
709}
710
711static int
712ahc_linux_slave_configure(struct scsi_device *sdev)
722{ 713{
723 struct ahc_softc *ahc; 714 struct ahc_softc *ahc;
724 struct ahc_linux_device *dev;
725 715
726 ahc = *((struct ahc_softc **)device->host->hostdata); 716 ahc = *((struct ahc_softc **)sdev->host->hostdata);
727 717
728 if (bootverbose) 718 if (bootverbose)
729 printf("%s: Slave Configure %d\n", ahc_name(ahc), device->id); 719 printf("%s: Slave Configure %d\n", ahc_name(ahc), sdev->id);
730 720
731 dev = ahc_linux_get_device(ahc, device->channel, device->id, 721 ahc_linux_device_queue_depth(sdev);
732 device->lun);
733 dev->scsi_device = device;
734 ahc_linux_device_queue_depth(ahc, dev);
735 722
736 /* Initial Domain Validation */ 723 /* Initial Domain Validation */
737 if (!spi_initial_dv(device->sdev_target)) 724 if (!spi_initial_dv(sdev->sdev_target))
738 spi_dv_device(device); 725 spi_dv_device(sdev);
739 726
740 return 0; 727 return 0;
741} 728}
742 729
743static void 730static void
744ahc_linux_slave_destroy(struct scsi_device *device) 731ahc_linux_slave_destroy(struct scsi_device *sdev)
745{ 732{
746 struct ahc_softc *ahc; 733 struct ahc_softc *ahc;
747 struct ahc_linux_device *dev; 734 struct ahc_linux_device *dev = scsi_transport_device_data(sdev);
735 struct ahc_linux_target *targ = scsi_transport_target_data(sdev->sdev_target);
748 736
749 ahc = *((struct ahc_softc **)device->host->hostdata); 737 ahc = *((struct ahc_softc **)sdev->host->hostdata);
750 if (bootverbose) 738 if (bootverbose)
751 printf("%s: Slave Destroy %d\n", ahc_name(ahc), device->id); 739 printf("%s: Slave Destroy %d\n", ahc_name(ahc), sdev->id);
752 dev = ahc_linux_get_device(ahc, device->channel,
753 device->id, device->lun);
754 740
755 BUG_ON(dev->active); 741 BUG_ON(dev->active);
756 742
757 ahc_linux_free_device(ahc, dev); 743 targ->sdev[sdev->lun] = NULL;
758} 744}
759 745
760#if defined(__i386__) 746#if defined(__i386__)
@@ -843,10 +829,14 @@ ahc_linux_bus_reset(struct scsi_cmnd *cmd)
843{ 829{
844 struct ahc_softc *ahc; 830 struct ahc_softc *ahc;
845 int found; 831 int found;
832 unsigned long flags;
846 833
847 ahc = *(struct ahc_softc **)cmd->device->host->hostdata; 834 ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
835
836 ahc_lock(ahc, &flags);
848 found = ahc_reset_channel(ahc, cmd->device->channel + 'A', 837 found = ahc_reset_channel(ahc, cmd->device->channel + 'A',
849 /*initiate reset*/TRUE); 838 /*initiate reset*/TRUE);
839 ahc_unlock(ahc, &flags);
850 840
851 if (bootverbose) 841 if (bootverbose)
852 printf("%s: SCSI bus reset delivered. " 842 printf("%s: SCSI bus reset delivered. "
@@ -874,6 +864,8 @@ struct scsi_host_template aic7xxx_driver_template = {
874 .slave_alloc = ahc_linux_slave_alloc, 864 .slave_alloc = ahc_linux_slave_alloc,
875 .slave_configure = ahc_linux_slave_configure, 865 .slave_configure = ahc_linux_slave_configure,
876 .slave_destroy = ahc_linux_slave_destroy, 866 .slave_destroy = ahc_linux_slave_destroy,
867 .target_alloc = ahc_linux_target_alloc,
868 .target_destroy = ahc_linux_target_destroy,
877}; 869};
878 870
879/**************************** Tasklet Handler *********************************/ 871/**************************** Tasklet Handler *********************************/
@@ -1112,8 +1104,6 @@ aic7xxx_setup(char *s)
1112 { "debug", &ahc_debug }, 1104 { "debug", &ahc_debug },
1113#endif 1105#endif
1114 { "reverse_scan", &aic7xxx_reverse_scan }, 1106 { "reverse_scan", &aic7xxx_reverse_scan },
1115 { "no_probe", &aic7xxx_probe_eisa_vl },
1116 { "probe_eisa_vl", &aic7xxx_probe_eisa_vl },
1117 { "periodic_otag", &aic7xxx_periodic_otag }, 1107 { "periodic_otag", &aic7xxx_periodic_otag },
1118 { "pci_parity", &aic7xxx_pci_parity }, 1108 { "pci_parity", &aic7xxx_pci_parity },
1119 { "seltime", &aic7xxx_seltime }, 1109 { "seltime", &aic7xxx_seltime },
@@ -1335,8 +1325,7 @@ ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
1335void 1325void
1336ahc_platform_free(struct ahc_softc *ahc) 1326ahc_platform_free(struct ahc_softc *ahc)
1337{ 1327{
1338 struct ahc_linux_target *targ; 1328 struct scsi_target *starget;
1339 struct ahc_linux_device *dev;
1340 int i, j; 1329 int i, j;
1341 1330
1342 if (ahc->platform_data != NULL) { 1331 if (ahc->platform_data != NULL) {
@@ -1347,22 +1336,17 @@ ahc_platform_free(struct ahc_softc *ahc)
1347 1336
1348 /* destroy all of the device and target objects */ 1337 /* destroy all of the device and target objects */
1349 for (i = 0; i < AHC_NUM_TARGETS; i++) { 1338 for (i = 0; i < AHC_NUM_TARGETS; i++) {
1350 targ = ahc->platform_data->targets[i]; 1339 starget = ahc->platform_data->starget[i];
1351 if (targ != NULL) { 1340 if (starget != NULL) {
1352 /* Keep target around through the loop. */
1353 targ->refcount++;
1354 for (j = 0; j < AHC_NUM_LUNS; j++) { 1341 for (j = 0; j < AHC_NUM_LUNS; j++) {
1342 struct ahc_linux_target *targ =
1343 scsi_transport_target_data(starget);
1355 1344
1356 if (targ->devices[j] == NULL) 1345 if (targ->sdev[j] == NULL)
1357 continue; 1346 continue;
1358 dev = targ->devices[j]; 1347 targ->sdev[j] = NULL;
1359 ahc_linux_free_device(ahc, dev);
1360 } 1348 }
1361 /* 1349 ahc->platform_data->starget[i] = NULL;
1362 * Forcibly free the target now that
1363 * all devices are gone.
1364 */
1365 ahc_linux_free_target(ahc, targ);
1366 } 1350 }
1367 } 1351 }
1368 1352
@@ -1395,15 +1379,25 @@ void
1395ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, 1379ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1396 ahc_queue_alg alg) 1380 ahc_queue_alg alg)
1397{ 1381{
1382 struct scsi_target *starget;
1383 struct ahc_linux_target *targ;
1398 struct ahc_linux_device *dev; 1384 struct ahc_linux_device *dev;
1385 struct scsi_device *sdev;
1386 u_int target_offset;
1399 int was_queuing; 1387 int was_queuing;
1400 int now_queuing; 1388 int now_queuing;
1401 1389
1402 dev = ahc_linux_get_device(ahc, devinfo->channel - 'A', 1390 target_offset = devinfo->target;
1403 devinfo->target, 1391 if (devinfo->channel != 'A')
1404 devinfo->lun); 1392 target_offset += 8;
1405 if (dev == NULL) 1393 starget = ahc->platform_data->starget[target_offset];
1394 targ = scsi_transport_target_data(starget);
1395 BUG_ON(targ == NULL);
1396 sdev = targ->sdev[devinfo->lun];
1397 if (sdev == NULL)
1406 return; 1398 return;
1399 dev = scsi_transport_device_data(sdev);
1400
1407 was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED); 1401 was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED);
1408 switch (alg) { 1402 switch (alg) {
1409 default: 1403 default:
@@ -1454,30 +1448,28 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1454 dev->maxtags = 0; 1448 dev->maxtags = 0;
1455 dev->openings = 1 - dev->active; 1449 dev->openings = 1 - dev->active;
1456 } 1450 }
1457 if (dev->scsi_device != NULL) { 1451 switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) {
1458 switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) { 1452 case AHC_DEV_Q_BASIC:
1459 case AHC_DEV_Q_BASIC: 1453 scsi_adjust_queue_depth(sdev,
1460 scsi_adjust_queue_depth(dev->scsi_device, 1454 MSG_SIMPLE_TASK,
1461 MSG_SIMPLE_TASK, 1455 dev->openings + dev->active);
1462 dev->openings + dev->active); 1456 break;
1463 break; 1457 case AHC_DEV_Q_TAGGED:
1464 case AHC_DEV_Q_TAGGED: 1458 scsi_adjust_queue_depth(sdev,
1465 scsi_adjust_queue_depth(dev->scsi_device, 1459 MSG_ORDERED_TASK,
1466 MSG_ORDERED_TASK, 1460 dev->openings + dev->active);
1467 dev->openings + dev->active); 1461 break;
1468 break; 1462 default:
1469 default: 1463 /*
1470 /* 1464 * We allow the OS to queue 2 untagged transactions to
1471 * We allow the OS to queue 2 untagged transactions to 1465 * us at any time even though we can only execute them
1472 * us at any time even though we can only execute them 1466 * serially on the controller/device. This should
1473 * serially on the controller/device. This should 1467 * remove some latency.
1474 * remove some latency. 1468 */
1475 */ 1469 scsi_adjust_queue_depth(sdev,
1476 scsi_adjust_queue_depth(dev->scsi_device, 1470 /*NON-TAGGED*/0,
1477 /*NON-TAGGED*/0, 1471 /*queue depth*/2);
1478 /*queue depth*/2); 1472 break;
1479 break;
1480 }
1481 } 1473 }
1482} 1474}
1483 1475
@@ -1523,22 +1515,20 @@ ahc_linux_user_tagdepth(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
1523 * Determines the queue depth for a given device. 1515 * Determines the queue depth for a given device.
1524 */ 1516 */
1525static void 1517static void
1526ahc_linux_device_queue_depth(struct ahc_softc *ahc, 1518ahc_linux_device_queue_depth(struct scsi_device *sdev)
1527 struct ahc_linux_device *dev)
1528{ 1519{
1529 struct ahc_devinfo devinfo; 1520 struct ahc_devinfo devinfo;
1530 u_int tags; 1521 u_int tags;
1522 struct ahc_softc *ahc = *((struct ahc_softc **)sdev->host->hostdata);
1531 1523
1532 ahc_compile_devinfo(&devinfo, 1524 ahc_compile_devinfo(&devinfo,
1533 dev->target->channel == 0 1525 sdev->sdev_target->channel == 0
1534 ? ahc->our_id : ahc->our_id_b, 1526 ? ahc->our_id : ahc->our_id_b,
1535 dev->target->target, dev->lun, 1527 sdev->sdev_target->id, sdev->lun,
1536 dev->target->channel == 0 ? 'A' : 'B', 1528 sdev->sdev_target->channel == 0 ? 'A' : 'B',
1537 ROLE_INITIATOR); 1529 ROLE_INITIATOR);
1538 tags = ahc_linux_user_tagdepth(ahc, &devinfo); 1530 tags = ahc_linux_user_tagdepth(ahc, &devinfo);
1539 if (tags != 0 1531 if (tags != 0 && sdev->tagged_supported != 0) {
1540 && dev->scsi_device != NULL
1541 && dev->scsi_device->tagged_supported != 0) {
1542 1532
1543 ahc_set_tags(ahc, &devinfo, AHC_QUEUE_TAGGED); 1533 ahc_set_tags(ahc, &devinfo, AHC_QUEUE_TAGGED);
1544 ahc_print_devinfo(ahc, &devinfo); 1534 ahc_print_devinfo(ahc, &devinfo);
@@ -1587,10 +1577,9 @@ ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev,
1587 /* 1577 /*
1588 * Get an scb to use. 1578 * Get an scb to use.
1589 */ 1579 */
1590 if ((scb = ahc_get_scb(ahc)) == NULL) { 1580 scb = ahc_get_scb(ahc);
1591 ahc->flags |= AHC_RESOURCE_SHORTAGE; 1581 if (!scb)
1592 return SCSI_MLQUEUE_HOST_BUSY; 1582 return SCSI_MLQUEUE_HOST_BUSY;
1593 }
1594 1583
1595 scb->io_ctx = cmd; 1584 scb->io_ctx = cmd;
1596 scb->platform_data->dev = dev; 1585 scb->platform_data->dev = dev;
@@ -1767,106 +1756,6 @@ ahc_platform_flushwork(struct ahc_softc *ahc)
1767 1756
1768} 1757}
1769 1758
1770static struct ahc_linux_target*
1771ahc_linux_alloc_target(struct ahc_softc *ahc, u_int channel, u_int target)
1772{
1773 struct ahc_linux_target *targ;
1774 u_int target_offset;
1775
1776 target_offset = target;
1777 if (channel != 0)
1778 target_offset += 8;
1779
1780 targ = malloc(sizeof(*targ), M_DEVBUG, M_NOWAIT);
1781 if (targ == NULL)
1782 return (NULL);
1783 memset(targ, 0, sizeof(*targ));
1784 targ->channel = channel;
1785 targ->target = target;
1786 targ->ahc = ahc;
1787 ahc->platform_data->targets[target_offset] = targ;
1788 return (targ);
1789}
1790
1791static void
1792ahc_linux_free_target(struct ahc_softc *ahc, struct ahc_linux_target *targ)
1793{
1794 struct ahc_devinfo devinfo;
1795 struct ahc_initiator_tinfo *tinfo;
1796 struct ahc_tmode_tstate *tstate;
1797 u_int our_id;
1798 u_int target_offset;
1799 char channel;
1800
1801 /*
1802 * Force a negotiation to async/narrow on any
1803 * future command to this device unless a bus
1804 * reset occurs between now and that command.
1805 */
1806 channel = 'A' + targ->channel;
1807 our_id = ahc->our_id;
1808 target_offset = targ->target;
1809 if (targ->channel != 0) {
1810 target_offset += 8;
1811 our_id = ahc->our_id_b;
1812 }
1813 tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
1814 targ->target, &tstate);
1815 ahc_compile_devinfo(&devinfo, our_id, targ->target, CAM_LUN_WILDCARD,
1816 channel, ROLE_INITIATOR);
1817 ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0,
1818 AHC_TRANS_GOAL, /*paused*/FALSE);
1819 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
1820 AHC_TRANS_GOAL, /*paused*/FALSE);
1821 ahc_update_neg_request(ahc, &devinfo, tstate, tinfo, AHC_NEG_ALWAYS);
1822 ahc->platform_data->targets[target_offset] = NULL;
1823 free(targ, M_DEVBUF);
1824}
1825
1826static struct ahc_linux_device*
1827ahc_linux_alloc_device(struct ahc_softc *ahc,
1828 struct ahc_linux_target *targ, u_int lun)
1829{
1830 struct ahc_linux_device *dev;
1831
1832 dev = malloc(sizeof(*dev), M_DEVBUG, M_NOWAIT);
1833 if (dev == NULL)
1834 return (NULL);
1835 memset(dev, 0, sizeof(*dev));
1836 dev->lun = lun;
1837 dev->target = targ;
1838
1839 /*
1840 * We start out life using untagged
1841 * transactions of which we allow one.
1842 */
1843 dev->openings = 1;
1844
1845 /*
1846 * Set maxtags to 0. This will be changed if we
1847 * later determine that we are dealing with
1848 * a tagged queuing capable device.
1849 */
1850 dev->maxtags = 0;
1851
1852 targ->refcount++;
1853 targ->devices[lun] = dev;
1854 return (dev);
1855}
1856
1857static void
1858ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev)
1859{
1860 struct ahc_linux_target *targ;
1861
1862 targ = dev->target;
1863 targ->devices[dev->lun] = NULL;
1864 free(dev, M_DEVBUF);
1865 targ->refcount--;
1866 if (targ->refcount == 0)
1867 ahc_linux_free_target(ahc, targ);
1868}
1869
1870void 1759void
1871ahc_send_async(struct ahc_softc *ahc, char channel, 1760ahc_send_async(struct ahc_softc *ahc, char channel,
1872 u_int target, u_int lun, ac_code code, void *arg) 1761 u_int target, u_int lun, ac_code code, void *arg)
@@ -1875,11 +1764,15 @@ ahc_send_async(struct ahc_softc *ahc, char channel,
1875 case AC_TRANSFER_NEG: 1764 case AC_TRANSFER_NEG:
1876 { 1765 {
1877 char buf[80]; 1766 char buf[80];
1767 struct scsi_target *starget;
1878 struct ahc_linux_target *targ; 1768 struct ahc_linux_target *targ;
1879 struct info_str info; 1769 struct info_str info;
1880 struct ahc_initiator_tinfo *tinfo; 1770 struct ahc_initiator_tinfo *tinfo;
1881 struct ahc_tmode_tstate *tstate; 1771 struct ahc_tmode_tstate *tstate;
1882 int target_offset; 1772 int target_offset;
1773 unsigned int target_ppr_options;
1774
1775 BUG_ON(target == CAM_TARGET_WILDCARD);
1883 1776
1884 info.buffer = buf; 1777 info.buffer = buf;
1885 info.length = sizeof(buf); 1778 info.length = sizeof(buf);
@@ -1908,32 +1801,30 @@ ahc_send_async(struct ahc_softc *ahc, char channel,
1908 target_offset = target; 1801 target_offset = target;
1909 if (channel == 'B') 1802 if (channel == 'B')
1910 target_offset += 8; 1803 target_offset += 8;
1911 targ = ahc->platform_data->targets[target_offset]; 1804 starget = ahc->platform_data->starget[target_offset];
1805 targ = scsi_transport_target_data(starget);
1912 if (targ == NULL) 1806 if (targ == NULL)
1913 break; 1807 break;
1914 if (tinfo->curr.period == targ->last_tinfo.period 1808
1915 && tinfo->curr.width == targ->last_tinfo.width 1809 target_ppr_options =
1916 && tinfo->curr.offset == targ->last_tinfo.offset 1810 (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0)
1917 && tinfo->curr.ppr_options == targ->last_tinfo.ppr_options) 1811 + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0)
1812 + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0);
1813
1814 if (tinfo->curr.period == spi_period(starget)
1815 && tinfo->curr.width == spi_width(starget)
1816 && tinfo->curr.offset == spi_offset(starget)
1817 && tinfo->curr.ppr_options == target_ppr_options)
1918 if (bootverbose == 0) 1818 if (bootverbose == 0)
1919 break; 1819 break;
1920 1820
1921 targ->last_tinfo.period = tinfo->curr.period; 1821 spi_period(starget) = tinfo->curr.period;
1922 targ->last_tinfo.width = tinfo->curr.width; 1822 spi_width(starget) = tinfo->curr.width;
1923 targ->last_tinfo.offset = tinfo->curr.offset; 1823 spi_offset(starget) = tinfo->curr.offset;
1924 targ->last_tinfo.ppr_options = tinfo->curr.ppr_options; 1824 spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ;
1925 1825 spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ;
1926 printf("(%s:%c:", ahc_name(ahc), channel); 1826 spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ;
1927 if (target == CAM_TARGET_WILDCARD) 1827 spi_display_xfer_agreement(starget);
1928 printf("*): ");
1929 else
1930 printf("%d): ", target);
1931 ahc_format_transinfo(&info, &tinfo->curr);
1932 if (info.pos < info.length)
1933 *info.buffer = '\0';
1934 else
1935 buf[info.length - 1] = '\0';
1936 printf("%s", buf);
1937 break; 1828 break;
1938 } 1829 }
1939 case AC_SENT_BDR: 1830 case AC_SENT_BDR:
@@ -2038,7 +1929,7 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
2038 ahc_set_transaction_status(scb, CAM_REQ_CMP); 1929 ahc_set_transaction_status(scb, CAM_REQ_CMP);
2039 } 1930 }
2040 } else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) { 1931 } else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
2041 ahc_linux_handle_scsi_status(ahc, dev, scb); 1932 ahc_linux_handle_scsi_status(ahc, cmd->device, scb);
2042 } 1933 }
2043 1934
2044 if (dev->openings == 1 1935 if (dev->openings == 1
@@ -2077,14 +1968,15 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
2077 1968
2078static void 1969static void
2079ahc_linux_handle_scsi_status(struct ahc_softc *ahc, 1970ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
2080 struct ahc_linux_device *dev, struct scb *scb) 1971 struct scsi_device *sdev, struct scb *scb)
2081{ 1972{
2082 struct ahc_devinfo devinfo; 1973 struct ahc_devinfo devinfo;
1974 struct ahc_linux_device *dev = scsi_transport_device_data(sdev);
2083 1975
2084 ahc_compile_devinfo(&devinfo, 1976 ahc_compile_devinfo(&devinfo,
2085 ahc->our_id, 1977 ahc->our_id,
2086 dev->target->target, dev->lun, 1978 sdev->sdev_target->id, sdev->lun,
2087 dev->target->channel == 0 ? 'A' : 'B', 1979 sdev->sdev_target->channel == 0 ? 'A' : 'B',
2088 ROLE_INITIATOR); 1980 ROLE_INITIATOR);
2089 1981
2090 /* 1982 /*
@@ -2361,6 +2253,8 @@ ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag)
2361 printf(" 0x%x", cmd->cmnd[cdb_byte]); 2253 printf(" 0x%x", cmd->cmnd[cdb_byte]);
2362 printf("\n"); 2254 printf("\n");
2363 2255
2256 spin_lock_irq(&ahc->platform_data->spin_lock);
2257
2364 /* 2258 /*
2365 * First determine if we currently own this command. 2259 * First determine if we currently own this command.
2366 * Start by searching the device queue. If not found 2260 * Start by searching the device queue. If not found
@@ -2368,8 +2262,7 @@ ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag)
2368 * at all, and the system wanted us to just abort the 2262 * at all, and the system wanted us to just abort the
2369 * command, return success. 2263 * command, return success.
2370 */ 2264 */
2371 dev = ahc_linux_get_device(ahc, cmd->device->channel, cmd->device->id, 2265 dev = scsi_transport_device_data(cmd->device);
2372 cmd->device->lun);
2373 2266
2374 if (dev == NULL) { 2267 if (dev == NULL) {
2375 /* 2268 /*
@@ -2616,6 +2509,8 @@ done:
2616 } 2509 }
2617 spin_lock_irq(&ahc->platform_data->spin_lock); 2510 spin_lock_irq(&ahc->platform_data->spin_lock);
2618 } 2511 }
2512
2513 spin_unlock_irq(&ahc->platform_data->spin_lock);
2619 return (retval); 2514 return (retval);
2620} 2515}
2621 2516
@@ -2626,18 +2521,6 @@ ahc_platform_dump_card_state(struct ahc_softc *ahc)
2626 2521
2627static void ahc_linux_exit(void); 2522static void ahc_linux_exit(void);
2628 2523
2629static void ahc_linux_get_width(struct scsi_target *starget)
2630{
2631 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2632 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
2633 struct ahc_tmode_tstate *tstate;
2634 struct ahc_initiator_tinfo *tinfo
2635 = ahc_fetch_transinfo(ahc,
2636 starget->channel + 'A',
2637 shost->this_id, starget->id, &tstate);
2638 spi_width(starget) = tinfo->curr.width;
2639}
2640
2641static void ahc_linux_set_width(struct scsi_target *starget, int width) 2524static void ahc_linux_set_width(struct scsi_target *starget, int width)
2642{ 2525{
2643 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2526 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
@@ -2652,18 +2535,6 @@ static void ahc_linux_set_width(struct scsi_target *starget, int width)
2652 ahc_unlock(ahc, &flags); 2535 ahc_unlock(ahc, &flags);
2653} 2536}
2654 2537
2655static void ahc_linux_get_period(struct scsi_target *starget)
2656{
2657 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2658 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
2659 struct ahc_tmode_tstate *tstate;
2660 struct ahc_initiator_tinfo *tinfo
2661 = ahc_fetch_transinfo(ahc,
2662 starget->channel + 'A',
2663 shost->this_id, starget->id, &tstate);
2664 spi_period(starget) = tinfo->curr.period;
2665}
2666
2667static void ahc_linux_set_period(struct scsi_target *starget, int period) 2538static void ahc_linux_set_period(struct scsi_target *starget, int period)
2668{ 2539{
2669 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2540 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
@@ -2674,9 +2545,9 @@ static void ahc_linux_set_period(struct scsi_target *starget, int period)
2674 starget->channel + 'A', 2545 starget->channel + 'A',
2675 shost->this_id, starget->id, &tstate); 2546 shost->this_id, starget->id, &tstate);
2676 struct ahc_devinfo devinfo; 2547 struct ahc_devinfo devinfo;
2677 unsigned int ppr_options = tinfo->curr.ppr_options; 2548 unsigned int ppr_options = tinfo->goal.ppr_options;
2678 unsigned long flags; 2549 unsigned long flags;
2679 unsigned long offset = tinfo->curr.offset; 2550 unsigned long offset = tinfo->goal.offset;
2680 struct ahc_syncrate *syncrate; 2551 struct ahc_syncrate *syncrate;
2681 2552
2682 if (offset == 0) 2553 if (offset == 0)
@@ -2692,7 +2563,6 @@ static void ahc_linux_set_period(struct scsi_target *starget, int period)
2692 2563
2693 /* all PPR requests apart from QAS require wide transfers */ 2564 /* all PPR requests apart from QAS require wide transfers */
2694 if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) { 2565 if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) {
2695 ahc_linux_get_width(starget);
2696 if (spi_width(starget) == 0) 2566 if (spi_width(starget) == 0)
2697 ppr_options &= MSG_EXT_PPR_QAS_REQ; 2567 ppr_options &= MSG_EXT_PPR_QAS_REQ;
2698 } 2568 }
@@ -2704,18 +2574,6 @@ static void ahc_linux_set_period(struct scsi_target *starget, int period)
2704 ahc_unlock(ahc, &flags); 2574 ahc_unlock(ahc, &flags);
2705} 2575}
2706 2576
2707static void ahc_linux_get_offset(struct scsi_target *starget)
2708{
2709 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2710 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
2711 struct ahc_tmode_tstate *tstate;
2712 struct ahc_initiator_tinfo *tinfo
2713 = ahc_fetch_transinfo(ahc,
2714 starget->channel + 'A',
2715 shost->this_id, starget->id, &tstate);
2716 spi_offset(starget) = tinfo->curr.offset;
2717}
2718
2719static void ahc_linux_set_offset(struct scsi_target *starget, int offset) 2577static void ahc_linux_set_offset(struct scsi_target *starget, int offset)
2720{ 2578{
2721 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2579 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
@@ -2735,8 +2593,8 @@ static void ahc_linux_set_offset(struct scsi_target *starget, int offset)
2735 starget->channel + 'A', ROLE_INITIATOR); 2593 starget->channel + 'A', ROLE_INITIATOR);
2736 if (offset != 0) { 2594 if (offset != 0) {
2737 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); 2595 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
2738 period = tinfo->curr.period; 2596 period = tinfo->goal.period;
2739 ppr_options = tinfo->curr.ppr_options; 2597 ppr_options = tinfo->goal.ppr_options;
2740 } 2598 }
2741 ahc_lock(ahc, &flags); 2599 ahc_lock(ahc, &flags);
2742 ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset, 2600 ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset,
@@ -2744,18 +2602,6 @@ static void ahc_linux_set_offset(struct scsi_target *starget, int offset)
2744 ahc_unlock(ahc, &flags); 2602 ahc_unlock(ahc, &flags);
2745} 2603}
2746 2604
2747static void ahc_linux_get_dt(struct scsi_target *starget)
2748{
2749 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2750 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
2751 struct ahc_tmode_tstate *tstate;
2752 struct ahc_initiator_tinfo *tinfo
2753 = ahc_fetch_transinfo(ahc,
2754 starget->channel + 'A',
2755 shost->this_id, starget->id, &tstate);
2756 spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ;
2757}
2758
2759static void ahc_linux_set_dt(struct scsi_target *starget, int dt) 2605static void ahc_linux_set_dt(struct scsi_target *starget, int dt)
2760{ 2606{
2761 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2607 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
@@ -2766,9 +2612,9 @@ static void ahc_linux_set_dt(struct scsi_target *starget, int dt)
2766 starget->channel + 'A', 2612 starget->channel + 'A',
2767 shost->this_id, starget->id, &tstate); 2613 shost->this_id, starget->id, &tstate);
2768 struct ahc_devinfo devinfo; 2614 struct ahc_devinfo devinfo;
2769 unsigned int ppr_options = tinfo->curr.ppr_options 2615 unsigned int ppr_options = tinfo->goal.ppr_options
2770 & ~MSG_EXT_PPR_DT_REQ; 2616 & ~MSG_EXT_PPR_DT_REQ;
2771 unsigned int period = tinfo->curr.period; 2617 unsigned int period = tinfo->goal.period;
2772 unsigned long flags; 2618 unsigned long flags;
2773 struct ahc_syncrate *syncrate; 2619 struct ahc_syncrate *syncrate;
2774 2620
@@ -2782,23 +2628,11 @@ static void ahc_linux_set_dt(struct scsi_target *starget, int dt)
2782 starget->channel + 'A', ROLE_INITIATOR); 2628 starget->channel + 'A', ROLE_INITIATOR);
2783 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options,AHC_SYNCRATE_DT); 2629 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options,AHC_SYNCRATE_DT);
2784 ahc_lock(ahc, &flags); 2630 ahc_lock(ahc, &flags);
2785 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->curr.offset, 2631 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset,
2786 ppr_options, AHC_TRANS_GOAL, FALSE); 2632 ppr_options, AHC_TRANS_GOAL, FALSE);
2787 ahc_unlock(ahc, &flags); 2633 ahc_unlock(ahc, &flags);
2788} 2634}
2789 2635
2790static void ahc_linux_get_qas(struct scsi_target *starget)
2791{
2792 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2793 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
2794 struct ahc_tmode_tstate *tstate;
2795 struct ahc_initiator_tinfo *tinfo
2796 = ahc_fetch_transinfo(ahc,
2797 starget->channel + 'A',
2798 shost->this_id, starget->id, &tstate);
2799 spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ;
2800}
2801
2802static void ahc_linux_set_qas(struct scsi_target *starget, int qas) 2636static void ahc_linux_set_qas(struct scsi_target *starget, int qas)
2803{ 2637{
2804 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2638 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
@@ -2809,9 +2643,9 @@ static void ahc_linux_set_qas(struct scsi_target *starget, int qas)
2809 starget->channel + 'A', 2643 starget->channel + 'A',
2810 shost->this_id, starget->id, &tstate); 2644 shost->this_id, starget->id, &tstate);
2811 struct ahc_devinfo devinfo; 2645 struct ahc_devinfo devinfo;
2812 unsigned int ppr_options = tinfo->curr.ppr_options 2646 unsigned int ppr_options = tinfo->goal.ppr_options
2813 & ~MSG_EXT_PPR_QAS_REQ; 2647 & ~MSG_EXT_PPR_QAS_REQ;
2814 unsigned int period = tinfo->curr.period; 2648 unsigned int period = tinfo->goal.period;
2815 unsigned long flags; 2649 unsigned long flags;
2816 struct ahc_syncrate *syncrate; 2650 struct ahc_syncrate *syncrate;
2817 2651
@@ -2822,23 +2656,11 @@ static void ahc_linux_set_qas(struct scsi_target *starget, int qas)
2822 starget->channel + 'A', ROLE_INITIATOR); 2656 starget->channel + 'A', ROLE_INITIATOR);
2823 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); 2657 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
2824 ahc_lock(ahc, &flags); 2658 ahc_lock(ahc, &flags);
2825 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->curr.offset, 2659 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset,
2826 ppr_options, AHC_TRANS_GOAL, FALSE); 2660 ppr_options, AHC_TRANS_GOAL, FALSE);
2827 ahc_unlock(ahc, &flags); 2661 ahc_unlock(ahc, &flags);
2828} 2662}
2829 2663
2830static void ahc_linux_get_iu(struct scsi_target *starget)
2831{
2832 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2833 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
2834 struct ahc_tmode_tstate *tstate;
2835 struct ahc_initiator_tinfo *tinfo
2836 = ahc_fetch_transinfo(ahc,
2837 starget->channel + 'A',
2838 shost->this_id, starget->id, &tstate);
2839 spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ;
2840}
2841
2842static void ahc_linux_set_iu(struct scsi_target *starget, int iu) 2664static void ahc_linux_set_iu(struct scsi_target *starget, int iu)
2843{ 2665{
2844 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2666 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
@@ -2849,9 +2671,9 @@ static void ahc_linux_set_iu(struct scsi_target *starget, int iu)
2849 starget->channel + 'A', 2671 starget->channel + 'A',
2850 shost->this_id, starget->id, &tstate); 2672 shost->this_id, starget->id, &tstate);
2851 struct ahc_devinfo devinfo; 2673 struct ahc_devinfo devinfo;
2852 unsigned int ppr_options = tinfo->curr.ppr_options 2674 unsigned int ppr_options = tinfo->goal.ppr_options
2853 & ~MSG_EXT_PPR_IU_REQ; 2675 & ~MSG_EXT_PPR_IU_REQ;
2854 unsigned int period = tinfo->curr.period; 2676 unsigned int period = tinfo->goal.period;
2855 unsigned long flags; 2677 unsigned long flags;
2856 struct ahc_syncrate *syncrate; 2678 struct ahc_syncrate *syncrate;
2857 2679
@@ -2862,28 +2684,22 @@ static void ahc_linux_set_iu(struct scsi_target *starget, int iu)
2862 starget->channel + 'A', ROLE_INITIATOR); 2684 starget->channel + 'A', ROLE_INITIATOR);
2863 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); 2685 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
2864 ahc_lock(ahc, &flags); 2686 ahc_lock(ahc, &flags);
2865 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->curr.offset, 2687 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset,
2866 ppr_options, AHC_TRANS_GOAL, FALSE); 2688 ppr_options, AHC_TRANS_GOAL, FALSE);
2867 ahc_unlock(ahc, &flags); 2689 ahc_unlock(ahc, &flags);
2868} 2690}
2869 2691
2870static struct spi_function_template ahc_linux_transport_functions = { 2692static struct spi_function_template ahc_linux_transport_functions = {
2871 .get_offset = ahc_linux_get_offset,
2872 .set_offset = ahc_linux_set_offset, 2693 .set_offset = ahc_linux_set_offset,
2873 .show_offset = 1, 2694 .show_offset = 1,
2874 .get_period = ahc_linux_get_period,
2875 .set_period = ahc_linux_set_period, 2695 .set_period = ahc_linux_set_period,
2876 .show_period = 1, 2696 .show_period = 1,
2877 .get_width = ahc_linux_get_width,
2878 .set_width = ahc_linux_set_width, 2697 .set_width = ahc_linux_set_width,
2879 .show_width = 1, 2698 .show_width = 1,
2880 .get_dt = ahc_linux_get_dt,
2881 .set_dt = ahc_linux_set_dt, 2699 .set_dt = ahc_linux_set_dt,
2882 .show_dt = 1, 2700 .show_dt = 1,
2883 .get_iu = ahc_linux_get_iu,
2884 .set_iu = ahc_linux_set_iu, 2701 .set_iu = ahc_linux_set_iu,
2885 .show_iu = 1, 2702 .show_iu = 1,
2886 .get_qas = ahc_linux_get_qas,
2887 .set_qas = ahc_linux_set_qas, 2703 .set_qas = ahc_linux_set_qas,
2888 .show_qas = 1, 2704 .show_qas = 1,
2889}; 2705};
@@ -2896,6 +2712,10 @@ ahc_linux_init(void)
2896 ahc_linux_transport_template = spi_attach_transport(&ahc_linux_transport_functions); 2712 ahc_linux_transport_template = spi_attach_transport(&ahc_linux_transport_functions);
2897 if (!ahc_linux_transport_template) 2713 if (!ahc_linux_transport_template)
2898 return -ENODEV; 2714 return -ENODEV;
2715 scsi_transport_reserve_target(ahc_linux_transport_template,
2716 sizeof(struct ahc_linux_target));
2717 scsi_transport_reserve_device(ahc_linux_transport_template,
2718 sizeof(struct ahc_linux_device));
2899 if (ahc_linux_detect(&aic7xxx_driver_template)) 2719 if (ahc_linux_detect(&aic7xxx_driver_template))
2900 return 0; 2720 return 0;
2901 spi_release_transport(ahc_linux_transport_template); 2721 spi_release_transport(ahc_linux_transport_template);
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.h b/drivers/scsi/aic7xxx/aic7xxx_osm.h
index 30c200d5bcd5..8ffe2d3e1d95 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.h
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.h
@@ -79,6 +79,8 @@
79#include <scsi/scsi_device.h> 79#include <scsi/scsi_device.h>
80#include <scsi/scsi_host.h> 80#include <scsi/scsi_host.h>
81#include <scsi/scsi_tcq.h> 81#include <scsi/scsi_tcq.h>
82#include <scsi/scsi_transport.h>
83#include <scsi/scsi_transport_spi.h>
82 84
83/* Core SCSI definitions */ 85/* Core SCSI definitions */
84#define AIC_LIB_PREFIX ahc 86#define AIC_LIB_PREFIX ahc
@@ -127,23 +129,6 @@ typedef struct scsi_cmnd *ahc_io_ctx_t;
127#define ahc_le32toh(x) le32_to_cpu(x) 129#define ahc_le32toh(x) le32_to_cpu(x)
128#define ahc_le64toh(x) le64_to_cpu(x) 130#define ahc_le64toh(x) le64_to_cpu(x)
129 131
130#ifndef LITTLE_ENDIAN
131#define LITTLE_ENDIAN 1234
132#endif
133
134#ifndef BIG_ENDIAN
135#define BIG_ENDIAN 4321
136#endif
137
138#ifndef BYTE_ORDER
139#if defined(__BIG_ENDIAN)
140#define BYTE_ORDER BIG_ENDIAN
141#endif
142#if defined(__LITTLE_ENDIAN)
143#define BYTE_ORDER LITTLE_ENDIAN
144#endif
145#endif /* BYTE_ORDER */
146
147/************************* Configuration Data *********************************/ 132/************************* Configuration Data *********************************/
148extern u_int aic7xxx_no_probe; 133extern u_int aic7xxx_no_probe;
149extern u_int aic7xxx_allow_memio; 134extern u_int aic7xxx_allow_memio;
@@ -283,35 +268,6 @@ ahc_scb_timer_reset(struct scb *scb, u_int usec)
283 268
284#define AIC7XXX_DRIVER_VERSION "6.2.36" 269#define AIC7XXX_DRIVER_VERSION "6.2.36"
285 270
286/**************************** Front End Queues ********************************/
287/*
288 * Data structure used to cast the Linux struct scsi_cmnd to something
289 * that allows us to use the queue macros. The linux structure has
290 * plenty of space to hold the links fields as required by the queue
291 * macros, but the queue macors require them to have the correct type.
292 */
293struct ahc_cmd_internal {
294 /* Area owned by the Linux scsi layer. */
295 uint8_t private[offsetof(struct scsi_cmnd, SCp.Status)];
296 union {
297 STAILQ_ENTRY(ahc_cmd) ste;
298 LIST_ENTRY(ahc_cmd) le;
299 TAILQ_ENTRY(ahc_cmd) tqe;
300 } links;
301 uint32_t end;
302};
303
304struct ahc_cmd {
305 union {
306 struct ahc_cmd_internal icmd;
307 struct scsi_cmnd scsi_cmd;
308 } un;
309};
310
311#define acmd_icmd(cmd) ((cmd)->un.icmd)
312#define acmd_scsi_cmd(cmd) ((cmd)->un.scsi_cmd)
313#define acmd_links un.icmd.links
314
315/*************************** Device Data Structures ***************************/ 271/*************************** Device Data Structures ***************************/
316/* 272/*
317 * A per probed device structure used to deal with some error recovery 273 * A per probed device structure used to deal with some error recovery
@@ -320,7 +276,6 @@ struct ahc_cmd {
320 * after a successfully completed inquiry command to the target when 276 * after a successfully completed inquiry command to the target when
321 * that inquiry data indicates a lun is present. 277 * that inquiry data indicates a lun is present.
322 */ 278 */
323TAILQ_HEAD(ahc_busyq, ahc_cmd);
324typedef enum { 279typedef enum {
325 AHC_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */ 280 AHC_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
326 AHC_DEV_Q_BASIC = 0x10, /* Allow basic device queuing */ 281 AHC_DEV_Q_BASIC = 0x10, /* Allow basic device queuing */
@@ -330,8 +285,6 @@ typedef enum {
330 285
331struct ahc_linux_target; 286struct ahc_linux_target;
332struct ahc_linux_device { 287struct ahc_linux_device {
333 TAILQ_ENTRY(ahc_linux_device) links;
334
335 /* 288 /*
336 * The number of transactions currently 289 * The number of transactions currently
337 * queued to the device. 290 * queued to the device.
@@ -401,17 +354,10 @@ struct ahc_linux_device {
401 */ 354 */
402 u_int commands_since_idle_or_otag; 355 u_int commands_since_idle_or_otag;
403#define AHC_OTAG_THRESH 500 356#define AHC_OTAG_THRESH 500
404
405 int lun;
406 struct scsi_device *scsi_device;
407 struct ahc_linux_target *target;
408}; 357};
409 358
410struct ahc_linux_target { 359struct ahc_linux_target {
411 struct ahc_linux_device *devices[AHC_NUM_LUNS]; 360 struct scsi_device *sdev[AHC_NUM_LUNS];
412 int channel;
413 int target;
414 int refcount;
415 struct ahc_transinfo last_tinfo; 361 struct ahc_transinfo last_tinfo;
416 struct ahc_softc *ahc; 362 struct ahc_softc *ahc;
417}; 363};
@@ -445,7 +391,7 @@ struct ahc_platform_data {
445 /* 391 /*
446 * Fields accessed from interrupt context. 392 * Fields accessed from interrupt context.
447 */ 393 */
448 struct ahc_linux_target *targets[AHC_NUM_TARGETS]; 394 struct scsi_target *starget[AHC_NUM_TARGETS];
449 395
450 spinlock_t spin_lock; 396 spinlock_t spin_lock;
451 u_int qfrozen; 397 u_int qfrozen;
@@ -659,7 +605,6 @@ typedef enum
659 605
660/**************************** VL/EISA Routines ********************************/ 606/**************************** VL/EISA Routines ********************************/
661#ifdef CONFIG_EISA 607#ifdef CONFIG_EISA
662extern uint32_t aic7xxx_probe_eisa_vl;
663int ahc_linux_eisa_init(void); 608int ahc_linux_eisa_init(void);
664void ahc_linux_eisa_exit(void); 609void ahc_linux_eisa_exit(void);
665int aic7770_map_registers(struct ahc_softc *ahc, 610int aic7770_map_registers(struct ahc_softc *ahc,
@@ -924,7 +869,6 @@ ahc_notify_xfer_settings_change(struct ahc_softc *ahc,
924static __inline void 869static __inline void
925ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb) 870ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
926{ 871{
927 ahc->flags &= ~AHC_RESOURCE_SHORTAGE;
928} 872}
929 873
930int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg); 874int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
index 2a0ebce83e7a..89d737ee551a 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
@@ -140,27 +140,17 @@ struct pci_driver aic7xxx_pci_driver = {
140static void 140static void
141ahc_linux_pci_dev_remove(struct pci_dev *pdev) 141ahc_linux_pci_dev_remove(struct pci_dev *pdev)
142{ 142{
143 struct ahc_softc *ahc; 143 struct ahc_softc *ahc = pci_get_drvdata(pdev);
144 u_long l; 144 u_long s;
145 145
146 /* 146 ahc_list_lock(&s);
147 * We should be able to just perform 147 TAILQ_REMOVE(&ahc_tailq, ahc, links);
148 * the free directly, but check our 148 ahc_list_unlock(&s);
149 * list for extra sanity.
150 */
151 ahc_list_lock(&l);
152 ahc = ahc_find_softc((struct ahc_softc *)pci_get_drvdata(pdev));
153 if (ahc != NULL) {
154 u_long s;
155 149
156 TAILQ_REMOVE(&ahc_tailq, ahc, links); 150 ahc_lock(ahc, &s);
157 ahc_list_unlock(&l); 151 ahc_intr_enable(ahc, FALSE);
158 ahc_lock(ahc, &s); 152 ahc_unlock(ahc, &s);
159 ahc_intr_enable(ahc, FALSE); 153 ahc_free(ahc);
160 ahc_unlock(ahc, &s);
161 ahc_free(ahc);
162 } else
163 ahc_list_unlock(&l);
164} 154}
165 155
166static int 156static int
@@ -174,22 +164,6 @@ ahc_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
174 char *name; 164 char *name;
175 int error; 165 int error;
176 166
177 /*
178 * Some BIOSen report the same device multiple times.
179 */
180 TAILQ_FOREACH(ahc, &ahc_tailq, links) {
181 struct pci_dev *probed_pdev;
182
183 probed_pdev = ahc->dev_softc;
184 if (probed_pdev->bus->number == pdev->bus->number
185 && probed_pdev->devfn == pdev->devfn)
186 break;
187 }
188 if (ahc != NULL) {
189 /* Skip duplicate. */
190 return (-ENODEV);
191 }
192
193 pci = pdev; 167 pci = pdev;
194 entry = ahc_find_pci_device(pci); 168 entry = ahc_find_pci_device(pci);
195 if (entry == NULL) 169 if (entry == NULL)
diff --git a/drivers/scsi/aic7xxx/aic7xxx_proc.c b/drivers/scsi/aic7xxx/aic7xxx_proc.c
index 5fece859fbd9..ab4469d83fb1 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_proc.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_proc.c
@@ -50,7 +50,7 @@ static void ahc_dump_target_state(struct ahc_softc *ahc,
50 u_int our_id, char channel, 50 u_int our_id, char channel,
51 u_int target_id, u_int target_offset); 51 u_int target_id, u_int target_offset);
52static void ahc_dump_device_state(struct info_str *info, 52static void ahc_dump_device_state(struct info_str *info,
53 struct ahc_linux_device *dev); 53 struct scsi_device *dev);
54static int ahc_proc_write_seeprom(struct ahc_softc *ahc, 54static int ahc_proc_write_seeprom(struct ahc_softc *ahc,
55 char *buffer, int length); 55 char *buffer, int length);
56 56
@@ -142,6 +142,7 @@ ahc_dump_target_state(struct ahc_softc *ahc, struct info_str *info,
142 u_int target_offset) 142 u_int target_offset)
143{ 143{
144 struct ahc_linux_target *targ; 144 struct ahc_linux_target *targ;
145 struct scsi_target *starget;
145 struct ahc_initiator_tinfo *tinfo; 146 struct ahc_initiator_tinfo *tinfo;
146 struct ahc_tmode_tstate *tstate; 147 struct ahc_tmode_tstate *tstate;
147 int lun; 148 int lun;
@@ -153,7 +154,8 @@ ahc_dump_target_state(struct ahc_softc *ahc, struct info_str *info,
153 copy_info(info, "Target %d Negotiation Settings\n", target_id); 154 copy_info(info, "Target %d Negotiation Settings\n", target_id);
154 copy_info(info, "\tUser: "); 155 copy_info(info, "\tUser: ");
155 ahc_format_transinfo(info, &tinfo->user); 156 ahc_format_transinfo(info, &tinfo->user);
156 targ = ahc->platform_data->targets[target_offset]; 157 starget = ahc->platform_data->starget[target_offset];
158 targ = scsi_transport_target_data(starget);
157 if (targ == NULL) 159 if (targ == NULL)
158 return; 160 return;
159 161
@@ -163,22 +165,25 @@ ahc_dump_target_state(struct ahc_softc *ahc, struct info_str *info,
163 ahc_format_transinfo(info, &tinfo->curr); 165 ahc_format_transinfo(info, &tinfo->curr);
164 166
165 for (lun = 0; lun < AHC_NUM_LUNS; lun++) { 167 for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
166 struct ahc_linux_device *dev; 168 struct scsi_device *sdev;
167 169
168 dev = targ->devices[lun]; 170 sdev = targ->sdev[lun];
169 171
170 if (dev == NULL) 172 if (sdev == NULL)
171 continue; 173 continue;
172 174
173 ahc_dump_device_state(info, dev); 175 ahc_dump_device_state(info, sdev);
174 } 176 }
175} 177}
176 178
177static void 179static void
178ahc_dump_device_state(struct info_str *info, struct ahc_linux_device *dev) 180ahc_dump_device_state(struct info_str *info, struct scsi_device *sdev)
179{ 181{
182 struct ahc_linux_device *dev = scsi_transport_device_data(sdev);
183
180 copy_info(info, "\tChannel %c Target %d Lun %d Settings\n", 184 copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
181 dev->target->channel + 'A', dev->target->target, dev->lun); 185 sdev->sdev_target->channel + 'A',
186 sdev->sdev_target->id, sdev->lun);
182 187
183 copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued); 188 copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued);
184 copy_info(info, "\t\tCommands Active %d\n", dev->active); 189 copy_info(info, "\t\tCommands Active %d\n", dev->active);
@@ -292,20 +297,13 @@ int
292ahc_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start, 297ahc_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
293 off_t offset, int length, int inout) 298 off_t offset, int length, int inout)
294{ 299{
295 struct ahc_softc *ahc; 300 struct ahc_softc *ahc = *(struct ahc_softc **)shost->hostdata;
296 struct info_str info; 301 struct info_str info;
297 char ahc_info[256]; 302 char ahc_info[256];
298 u_long s;
299 u_int max_targ; 303 u_int max_targ;
300 u_int i; 304 u_int i;
301 int retval; 305 int retval;
302 306
303 retval = -EINVAL;
304 ahc_list_lock(&s);
305 ahc = ahc_find_softc(*(struct ahc_softc **)shost->hostdata);
306 if (ahc == NULL)
307 goto done;
308
309 /* Has data been written to the file? */ 307 /* Has data been written to the file? */
310 if (inout == TRUE) { 308 if (inout == TRUE) {
311 retval = ahc_proc_write_seeprom(ahc, buffer, length); 309 retval = ahc_proc_write_seeprom(ahc, buffer, length);
@@ -367,6 +365,5 @@ ahc_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
367 } 365 }
368 retval = info.pos > info.offset ? info.pos - info.offset : 0; 366 retval = info.pos > info.offset ? info.pos - info.offset : 0;
369done: 367done:
370 ahc_list_unlock(&s);
371 return (retval); 368 return (retval);
372} 369}