| Linux kernel & device driver programming |
| [ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] |
1 /* 1 /*
2 * Adaptec AIC7xxx device driver for Linux. 2 * Adaptec AIC7xxx device driver for Linux.
3 * 3 *
4 * $Id: //depot/aic7xxx/linux/drivers/scsi/aic 4 * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.c#235 $
5 * 5 *
6 * Copyright (c) 1994 John Aycock 6 * Copyright (c) 1994 John Aycock
7 * The University of Calgary Department of C 7 * The University of Calgary Department of Computer Science.
8 * 8 *
9 * This program is free software; you can redi 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Publi 10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either versio 11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version. 12 * any later version.
13 * 13 *
14 * This program is distributed in the hope tha 14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details 17 * GNU General Public License for more details.
18 * 18 *
19 * You should have received a copy of the GNU 19 * You should have received a copy of the GNU General Public License
20 * along with this program; see the file COPYI 20 * along with this program; see the file COPYING. If not, write to
21 * the Free Software Foundation, 675 Mass Ave, 21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 * 22 *
23 * Sources include the Adaptec 1740 driver (ah 23 * Sources include the Adaptec 1740 driver (aha1740.c), the Ultrastor 24F
24 * driver (ultrastor.c), various Linux kernel 24 * driver (ultrastor.c), various Linux kernel source, the Adaptec EISA
25 * config file (!adp7771.cfg), the Adaptec AHA 25 * config file (!adp7771.cfg), the Adaptec AHA-2740A Series User's Guide,
26 * the Linux Kernel Hacker's Guide, Writing a 26 * the Linux Kernel Hacker's Guide, Writing a SCSI Device Driver for Linux,
27 * the Adaptec 1542 driver (aha1542.c), the Ad 27 * the Adaptec 1542 driver (aha1542.c), the Adaptec EISA overlay file
28 * (adp7770.ovl), the Adaptec AHA-2740 Series 28 * (adp7770.ovl), the Adaptec AHA-2740 Series Technical Reference Manual,
29 * the Adaptec AIC-7770 Data Book, the ANSI SC 29 * the Adaptec AIC-7770 Data Book, the ANSI SCSI specification, the
30 * ANSI SCSI-2 specification (draft 10c), ... 30 * ANSI SCSI-2 specification (draft 10c), ...
31 * 31 *
32 * ------------------------------------------- 32 * --------------------------------------------------------------------------
33 * 33 *
34 * Modifications by Daniel M. Eischen (deisch 34 * Modifications by Daniel M. Eischen (deischen@iworks.InterWorks.org):
35 * 35 *
36 * Substantially modified to include support 36 * Substantially modified to include support for wide and twin bus
37 * adapters, DMAing of SCBs, tagged queueing, 37 * adapters, DMAing of SCBs, tagged queueing, IRQ sharing, bug fixes,
38 * SCB paging, and other rework of the code. 38 * SCB paging, and other rework of the code.
39 * 39 *
40 * ------------------------------------------- 40 * --------------------------------------------------------------------------
41 * Copyright (c) 1994-2000 Justin T. Gibbs. 41 * Copyright (c) 1994-2000 Justin T. Gibbs.
42 * Copyright (c) 2000-2001 Adaptec Inc. 42 * Copyright (c) 2000-2001 Adaptec Inc.
43 * All rights reserved. 43 * All rights reserved.
44 * 44 *
45 * Redistribution and use in source and binary 45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that t 46 * modification, are permitted provided that the following conditions
47 * are met: 47 * are met:
48 * 1. Redistributions of source code must reta 48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions, and the 49 * notice, this list of conditions, and the following disclaimer,
50 * without modification. 50 * without modification.
51 * 2. Redistributions in binary form must repr 51 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
52 * substantially similar to the "NO WARRANT 52 * substantially similar to the "NO WARRANTY" disclaimer below
53 * ("Disclaimer") and any redistribution mu 53 * ("Disclaimer") and any redistribution must be conditioned upon
54 * including a substantially similar Discla 54 * including a substantially similar Disclaimer requirement for further
55 * binary redistribution. 55 * binary redistribution.
56 * 3. Neither the names of the above-listed co 56 * 3. Neither the names of the above-listed copyright holders nor the names
57 * of any contributors may be used to endor 57 * of any contributors may be used to endorse or promote products derived
58 * from this software without specific prio 58 * from this software without specific prior written permission.
59 * 59 *
60 * Alternatively, this software may be distrib 60 * Alternatively, this software may be distributed under the terms of the
61 * GNU General Public License ("GPL") version 61 * GNU General Public License ("GPL") version 2 as published by the Free
62 * Software Foundation. 62 * Software Foundation.
63 * 63 *
64 * NO WARRANTY 64 * NO WARRANTY
65 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 65 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
66 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTI 66 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
67 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCH 67 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
68 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 68 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
69 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECI 69 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
70 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PRO 70 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
71 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 71 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
72 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILI 72 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
73 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIG 73 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
74 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 74 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
75 * POSSIBILITY OF SUCH DAMAGES. 75 * POSSIBILITY OF SUCH DAMAGES.
76 * 76 *
77 *-------------------------------------------- 77 *---------------------------------------------------------------------------
78 * 78 *
79 * Thanks also go to (in alphabetical order) 79 * Thanks also go to (in alphabetical order) the following:
80 * 80 *
81 * Rory Bolt - Sequencer bug fixes 81 * Rory Bolt - Sequencer bug fixes
82 * Jay Estabrook - Initial DEC Alpha suppor 82 * Jay Estabrook - Initial DEC Alpha support
83 * Doug Ledford - Much needed abort/reset 83 * Doug Ledford - Much needed abort/reset bug fixes
84 * Kai Makisara - DMAing of SCBs 84 * Kai Makisara - DMAing of SCBs
85 * 85 *
86 * A Boot time option was also added for not 86 * A Boot time option was also added for not resetting the scsi bus.
87 * 87 *
88 * Form: aic7xxx=extended 88 * Form: aic7xxx=extended
89 * aic7xxx=no_reset 89 * aic7xxx=no_reset
90 * aic7xxx=verbose 90 * aic7xxx=verbose
91 * 91 *
92 * Daniel M. Eischen, deischen@iworks.InterWo 92 * Daniel M. Eischen, deischen@iworks.InterWorks.org, 1/23/97
93 * 93 *
94 * Id: aic7xxx.c,v 4.1 1997/06/12 08:23:42 de 94 * Id: aic7xxx.c,v 4.1 1997/06/12 08:23:42 deang Exp
95 */ 95 */
96 96
97 /* 97 /*
98 * Further driver modifications made by Doug L 98 * Further driver modifications made by Doug Ledford <dledford@redhat.com>
99 * 99 *
100 * Copyright (c) 1997-1999 Doug Ledford 100 * Copyright (c) 1997-1999 Doug Ledford
101 * 101 *
102 * These changes are released under the same l 102 * These changes are released under the same licensing terms as the FreeBSD
103 * driver written by Justin Gibbs. Please see 103 * driver written by Justin Gibbs. Please see his Copyright notice above
104 * for the exact terms and conditions covering 104 * for the exact terms and conditions covering my changes as well as the
105 * warranty statement. 105 * warranty statement.
106 * 106 *
107 * Modifications made to the aic7xxx.c,v 4.1 d 107 * Modifications made to the aic7xxx.c,v 4.1 driver from Dan Eischen include
108 * but are not limited to: 108 * but are not limited to:
109 * 109 *
110 * 1: Import of the latest FreeBSD sequencer 110 * 1: Import of the latest FreeBSD sequencer code for this driver
111 * 2: Modification of kernel code to accommod 111 * 2: Modification of kernel code to accommodate different sequencer semantics
112 * 3: Extensive changes throughout kernel por 112 * 3: Extensive changes throughout kernel portion of driver to improve
113 * abort/reset processing and error hanndl 113 * abort/reset processing and error hanndling
114 * 4: Other work contributed by various peopl 114 * 4: Other work contributed by various people on the Internet
115 * 5: Changes to printk information and verbo 115 * 5: Changes to printk information and verbosity selection code
116 * 6: General reliability related changes, es 116 * 6: General reliability related changes, especially in IRQ management
117 * 7: Modifications to the default probe/atta 117 * 7: Modifications to the default probe/attach order for supported cards
118 * 8: SMP friendliness has been improved 118 * 8: SMP friendliness has been improved
119 * 119 *
120 */ 120 */
121 121
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 125
126 static struct scsi_transport_template *ahc_lin !! 126 /*
>> 127 * Include aiclib.c as part of our
>> 128 * "module dependencies are hard" work around.
>> 129 */
>> 130 #include "aiclib.c"
127 131
128 #include <linux/init.h> /* __setup */ 132 #include <linux/init.h> /* __setup */
>> 133
>> 134 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
>> 135 #include "sd.h" /* For geometry detection */
>> 136 #endif
>> 137
129 #include <linux/mm.h> /* For fetchin 138 #include <linux/mm.h> /* For fetching system memory size */
130 #include <linux/blkdev.h> /* For 139 #include <linux/blkdev.h> /* For block_size() */
131 #include <linux/delay.h> /* For ssleep/ 140 #include <linux/delay.h> /* For ssleep/msleep */
132 141
>> 142 /*
>> 143 * Lock protecting manipulation of the ahc softc list.
>> 144 */
>> 145 spinlock_t ahc_list_spinlock;
>> 146
>> 147 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
>> 148 /* For dynamic sglist size calculation. */
>> 149 u_int ahc_linux_nseg;
>> 150 #endif
133 151
134 /* 152 /*
135 * Set this to the delay in seconds after SCSI 153 * Set this to the delay in seconds after SCSI bus reset.
136 * Note, we honor this only for the initial bu 154 * Note, we honor this only for the initial bus reset.
137 * The scsi error recovery code performs its o 155 * The scsi error recovery code performs its own bus settle
138 * delay handling for error recovery actions. 156 * delay handling for error recovery actions.
139 */ 157 */
140 #ifdef CONFIG_AIC7XXX_RESET_DELAY_MS 158 #ifdef CONFIG_AIC7XXX_RESET_DELAY_MS
141 #define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RES 159 #define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RESET_DELAY_MS
142 #else 160 #else
143 #define AIC7XXX_RESET_DELAY 5000 161 #define AIC7XXX_RESET_DELAY 5000
144 #endif 162 #endif
145 163
146 /* 164 /*
147 * Control collection of SCSI transfer statist 165 * Control collection of SCSI transfer statistics for the /proc filesystem.
148 * 166 *
149 * NOTE: Do NOT enable this when running on ke 167 * NOTE: Do NOT enable this when running on kernels version 1.2.x and below.
150 * NOTE: This does affect performance since it 168 * NOTE: This does affect performance since it has to maintain statistics.
151 */ 169 */
152 #ifdef CONFIG_AIC7XXX_PROC_STATS 170 #ifdef CONFIG_AIC7XXX_PROC_STATS
153 #define AIC7XXX_PROC_STATS 171 #define AIC7XXX_PROC_STATS
154 #endif 172 #endif
155 173
156 /* 174 /*
157 * To change the default number of tagged tran 175 * To change the default number of tagged transactions allowed per-device,
158 * add a line to the lilo.conf file like: 176 * add a line to the lilo.conf file like:
159 * append="aic7xxx=verbose,tag_info:{{32,32,32 177 * append="aic7xxx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
160 * which will result in the first four devices 178 * which will result in the first four devices on the first two
161 * controllers being set to a tagged queue dep 179 * controllers being set to a tagged queue depth of 32.
162 * 180 *
163 * The tag_commands is an array of 16 to allow 181 * The tag_commands is an array of 16 to allow for wide and twin adapters.
164 * Twin adapters will use indexes 0-7 for chan 182 * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15
165 * for channel 1. 183 * for channel 1.
166 */ 184 */
167 typedef struct { 185 typedef struct {
168 uint8_t tag_commands[16]; /* All 186 uint8_t tag_commands[16]; /* Allow for wide/twin adapters. */
169 } adapter_tag_info_t; 187 } adapter_tag_info_t;
170 188
171 /* 189 /*
172 * Modify this as you see fit for your system. 190 * Modify this as you see fit for your system.
173 * 191 *
174 * 0 tagged queuing disable 192 * 0 tagged queuing disabled
175 * 1 <= n <= 253 n == max tags ever dis 193 * 1 <= n <= 253 n == max tags ever dispatched.
176 * 194 *
177 * The driver will throttle the number of comm 195 * The driver will throttle the number of commands dispatched to a
178 * device if it returns queue full. For devic 196 * device if it returns queue full. For devices with a fixed maximum
179 * queue depth, the driver will eventually det 197 * queue depth, the driver will eventually determine this depth and
180 * lock it in (a console message is printed to 198 * lock it in (a console message is printed to indicate that a lock
181 * has occurred). On some devices, queue full 199 * has occurred). On some devices, queue full is returned for a temporary
182 * resource shortage. These devices will retu 200 * resource shortage. These devices will return queue full at varying
183 * depths. The driver will throttle back when 201 * depths. The driver will throttle back when the queue fulls occur and
184 * attempt to slowly increase the depth over t 202 * attempt to slowly increase the depth over time as the device recovers
185 * from the resource shortage. 203 * from the resource shortage.
186 * 204 *
187 * In this example, the first line will disabl 205 * In this example, the first line will disable tagged queueing for all
188 * the devices on the first probed aic7xxx ada 206 * the devices on the first probed aic7xxx adapter.
189 * 207 *
190 * The second line enables tagged queueing wit 208 * The second line enables tagged queueing with 4 commands/LUN for IDs
191 * (0, 2-11, 13-15), disables tagged queueing 209 * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
192 * driver to attempt to use up to 64 tags for 210 * driver to attempt to use up to 64 tags for ID 1.
193 * 211 *
194 * The third line is the same as the first lin 212 * The third line is the same as the first line.
195 * 213 *
196 * The fourth line disables tagged queueing fo 214 * The fourth line disables tagged queueing for devices 0 and 3. It
197 * enables tagged queueing for the other IDs, 215 * enables tagged queueing for the other IDs, with 16 commands/LUN
198 * for IDs 1 and 4, 127 commands/LUN for ID 8, 216 * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
199 * IDs 2, 5-7, and 9-15. 217 * IDs 2, 5-7, and 9-15.
200 */ 218 */
201 219
202 /* 220 /*
203 * NOTE: The below structure is for reference 221 * NOTE: The below structure is for reference only, the actual structure
204 * to modify in order to change things i 222 * to modify in order to change things is just below this comment block.
205 adapter_tag_info_t aic7xxx_tag_info[] = 223 adapter_tag_info_t aic7xxx_tag_info[] =
206 { 224 {
207 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 225 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
208 {{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 226 {{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}},
209 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 227 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
210 {{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 228 {{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
211 }; 229 };
212 */ 230 */
213 231
214 #ifdef CONFIG_AIC7XXX_CMDS_PER_DEVICE 232 #ifdef CONFIG_AIC7XXX_CMDS_PER_DEVICE
215 #define AIC7XXX_CMDS_PER_DEVICE CONFIG_AIC7XXX 233 #define AIC7XXX_CMDS_PER_DEVICE CONFIG_AIC7XXX_CMDS_PER_DEVICE
216 #else 234 #else
217 #define AIC7XXX_CMDS_PER_DEVICE AHC_MAX_QUEUE 235 #define AIC7XXX_CMDS_PER_DEVICE AHC_MAX_QUEUE
218 #endif 236 #endif
219 237
220 #define AIC7XXX_CONFIGED_TAG_COMMANDS { 238 #define AIC7XXX_CONFIGED_TAG_COMMANDS { \
221 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_ 239 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
222 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_ 240 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
223 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_ 241 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
224 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_ 242 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
225 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_ 243 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
226 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_ 244 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
227 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_ 245 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
228 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_ 246 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE \
229 } 247 }
230 248
231 /* 249 /*
232 * By default, use the number of commands spec 250 * By default, use the number of commands specified by
233 * the users kernel configuration. 251 * the users kernel configuration.
234 */ 252 */
235 static adapter_tag_info_t aic7xxx_tag_info[] = 253 static adapter_tag_info_t aic7xxx_tag_info[] =
236 { 254 {
237 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 255 {AIC7XXX_CONFIGED_TAG_COMMANDS},
238 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 256 {AIC7XXX_CONFIGED_TAG_COMMANDS},
239 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 257 {AIC7XXX_CONFIGED_TAG_COMMANDS},
240 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 258 {AIC7XXX_CONFIGED_TAG_COMMANDS},
241 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 259 {AIC7XXX_CONFIGED_TAG_COMMANDS},
242 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 260 {AIC7XXX_CONFIGED_TAG_COMMANDS},
243 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 261 {AIC7XXX_CONFIGED_TAG_COMMANDS},
244 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 262 {AIC7XXX_CONFIGED_TAG_COMMANDS},
245 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 263 {AIC7XXX_CONFIGED_TAG_COMMANDS},
246 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 264 {AIC7XXX_CONFIGED_TAG_COMMANDS},
247 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 265 {AIC7XXX_CONFIGED_TAG_COMMANDS},
248 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 266 {AIC7XXX_CONFIGED_TAG_COMMANDS},
249 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 267 {AIC7XXX_CONFIGED_TAG_COMMANDS},
250 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 268 {AIC7XXX_CONFIGED_TAG_COMMANDS},
251 {AIC7XXX_CONFIGED_TAG_COMMANDS}, 269 {AIC7XXX_CONFIGED_TAG_COMMANDS},
252 {AIC7XXX_CONFIGED_TAG_COMMANDS} 270 {AIC7XXX_CONFIGED_TAG_COMMANDS}
253 }; 271 };
254 272
255 /* 273 /*
>> 274 * DV option:
>> 275 *
>> 276 * positive value = DV Enabled
>> 277 * zero = DV Disabled
>> 278 * negative value = DV Default for adapter type/seeprom
>> 279 */
>> 280 #ifdef CONFIG_AIC7XXX_DV_SETTING
>> 281 #define AIC7XXX_CONFIGED_DV CONFIG_AIC7XXX_DV_SETTING
>> 282 #else
>> 283 #define AIC7XXX_CONFIGED_DV -1
>> 284 #endif
>> 285
>> 286 static int8_t aic7xxx_dv_settings[] =
>> 287 {
>> 288 AIC7XXX_CONFIGED_DV,
>> 289 AIC7XXX_CONFIGED_DV,
>> 290 AIC7XXX_CONFIGED_DV,
>> 291 AIC7XXX_CONFIGED_DV,
>> 292 AIC7XXX_CONFIGED_DV,
>> 293 AIC7XXX_CONFIGED_DV,
>> 294 AIC7XXX_CONFIGED_DV,
>> 295 AIC7XXX_CONFIGED_DV,
>> 296 AIC7XXX_CONFIGED_DV,
>> 297 AIC7XXX_CONFIGED_DV,
>> 298 AIC7XXX_CONFIGED_DV,
>> 299 AIC7XXX_CONFIGED_DV,
>> 300 AIC7XXX_CONFIGED_DV,
>> 301 AIC7XXX_CONFIGED_DV,
>> 302 AIC7XXX_CONFIGED_DV,
>> 303 AIC7XXX_CONFIGED_DV
>> 304 };
>> 305
>> 306 /*
256 * There should be a specific return value for 307 * There should be a specific return value for this in scsi.h, but
257 * it seems that most drivers ignore it. 308 * it seems that most drivers ignore it.
258 */ 309 */
259 #define DID_UNDERFLOW DID_ERROR 310 #define DID_UNDERFLOW DID_ERROR
260 311
261 void 312 void
262 ahc_print_path(struct ahc_softc *ahc, struct s 313 ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
263 { 314 {
264 printk("(scsi%d:%c:%d:%d): ", 315 printk("(scsi%d:%c:%d:%d): ",
265 ahc->platform_data->host->host_ 316 ahc->platform_data->host->host_no,
266 scb != NULL ? SCB_GET_CHANNEL(a 317 scb != NULL ? SCB_GET_CHANNEL(ahc, scb) : 'X',
267 scb != NULL ? SCB_GET_TARGET(ah 318 scb != NULL ? SCB_GET_TARGET(ahc, scb) : -1,
268 scb != NULL ? SCB_GET_LUN(scb) 319 scb != NULL ? SCB_GET_LUN(scb) : -1);
269 } 320 }
270 321
271 /* 322 /*
272 * XXX - these options apply unilaterally to _ 323 * XXX - these options apply unilaterally to _all_ 274x/284x/294x
273 * cards in the system. This should be 324 * cards in the system. This should be fixed. Exceptions to this
274 * rule are noted in the comments. 325 * rule are noted in the comments.
275 */ 326 */
276 327
277 /* 328 /*
278 * Skip the scsi bus reset. Non 0 make us ski 329 * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
279 * has no effect on any later resets that migh 330 * has no effect on any later resets that might occur due to things like
280 * SCSI bus timeouts. 331 * SCSI bus timeouts.
281 */ 332 */
282 static uint32_t aic7xxx_no_reset; 333 static uint32_t aic7xxx_no_reset;
283 334
284 /* 335 /*
>> 336 * Certain PCI motherboards will scan PCI devices from highest to lowest,
>> 337 * others scan from lowest to highest, and they tend to do all kinds of
>> 338 * strange things when they come into contact with PCI bridge chips. The
>> 339 * net result of all this is that the PCI card that is actually used to boot
>> 340 * the machine is very hard to detect. Most motherboards go from lowest
>> 341 * PCI slot number to highest, and the first SCSI controller found is the
>> 342 * one you boot from. The only exceptions to this are when a controller
>> 343 * has its BIOS disabled. So, we by default sort all of our SCSI controllers
>> 344 * from lowest PCI slot number to highest PCI slot number. We also force
>> 345 * all controllers with their BIOS disabled to the end of the list. This
>> 346 * works on *almost* all computers. Where it doesn't work, we have this
>> 347 * option. Setting this option to non-0 will reverse the order of the sort
>> 348 * to highest first, then lowest, but will still leave cards with their BIOS
>> 349 * disabled at the very end. That should fix everyone up unless there are
>> 350 * really strange cirumstances.
>> 351 */
>> 352 static uint32_t aic7xxx_reverse_scan;
>> 353
>> 354 /*
285 * Should we force EXTENDED translation on a c 355 * Should we force EXTENDED translation on a controller.
286 * 0 == Use whatever is in the SEEPROM or 356 * 0 == Use whatever is in the SEEPROM or default to off
287 * 1 == Use whatever is in the SEEPROM or 357 * 1 == Use whatever is in the SEEPROM or default to on
288 */ 358 */
289 static uint32_t aic7xxx_extended; 359 static uint32_t aic7xxx_extended;
290 360
291 /* 361 /*
292 * PCI bus parity checking of the Adaptec cont 362 * PCI bus parity checking of the Adaptec controllers. This is somewhat
293 * dubious at best. To my knowledge, this opt 363 * dubious at best. To my knowledge, this option has never actually
294 * solved a PCI parity problem, but on certain 364 * solved a PCI parity problem, but on certain machines with broken PCI
295 * chipset configurations where stray PCI tran 365 * chipset configurations where stray PCI transactions with bad parity are
296 * the norm rather than the exception, the err 366 * the norm rather than the exception, the error messages can be overwelming.
297 * It's included in the driver for completenes 367 * It's included in the driver for completeness.
298 * 0 = Shut off PCI parity check 368 * 0 = Shut off PCI parity check
299 * non-0 = reverse polarity pci parity check 369 * non-0 = reverse polarity pci parity checking
300 */ 370 */
301 static uint32_t aic7xxx_pci_parity = ~0; 371 static uint32_t aic7xxx_pci_parity = ~0;
302 372
303 /* 373 /*
>> 374 * Certain newer motherboards have put new PCI based devices into the
>> 375 * IO spaces that used to typically be occupied by VLB or EISA cards.
>> 376 * This overlap can cause these newer motherboards to lock up when scanned
>> 377 * for older EISA and VLB devices. Setting this option to non-0 will
>> 378 * cause the driver to skip scanning for any VLB or EISA controllers and
>> 379 * only support the PCI controllers. NOTE: this means that if the kernel
>> 380 * os compiled with PCI support disabled, then setting this to non-0
>> 381 * would result in never finding any devices :)
>> 382 */
>> 383 #ifndef CONFIG_AIC7XXX_PROBE_EISA_VL
>> 384 uint32_t aic7xxx_probe_eisa_vl;
>> 385 #else
>> 386 uint32_t aic7xxx_probe_eisa_vl = ~0;
>> 387 #endif
>> 388
>> 389 /*
304 * There are lots of broken chipsets in the wo 390 * There are lots of broken chipsets in the world. Some of them will
305 * violate the PCI spec when we issue byte siz 391 * violate the PCI spec when we issue byte sized memory writes to our
306 * controller. I/O mapped register access, if 392 * controller. I/O mapped register access, if allowed by the given
307 * platform, will work in almost all cases. 393 * platform, will work in almost all cases.
308 */ 394 */
309 uint32_t aic7xxx_allow_memio = ~0; 395 uint32_t aic7xxx_allow_memio = ~0;
310 396
311 /* 397 /*
>> 398 * aic7xxx_detect() has been run, so register all device arrivals
>> 399 * immediately with the system rather than deferring to the sorted
>> 400 * attachment performed by aic7xxx_detect().
>> 401 */
>> 402 int aic7xxx_detect_complete;
>> 403
>> 404 /*
312 * So that we can set how long each device is 405 * So that we can set how long each device is given as a selection timeout.
313 * The table of values goes like this: 406 * The table of values goes like this:
314 * 0 - 256ms 407 * 0 - 256ms
315 * 1 - 128ms 408 * 1 - 128ms
316 * 2 - 64ms 409 * 2 - 64ms
317 * 3 - 32ms 410 * 3 - 32ms
318 * We default to 256ms because some older devi 411 * We default to 256ms because some older devices need a longer time
319 * to respond to initial selection. 412 * to respond to initial selection.
320 */ 413 */
321 static uint32_t aic7xxx_seltime; 414 static uint32_t aic7xxx_seltime;
322 415
323 /* 416 /*
324 * Certain devices do not perform any aging on 417 * Certain devices do not perform any aging on commands. Should the
325 * device be saturated by commands in one port 418 * device be saturated by commands in one portion of the disk, it is
326 * possible for transactions on far away secto 419 * possible for transactions on far away sectors to never be serviced.
327 * To handle these devices, we can periodicall 420 * To handle these devices, we can periodically send an ordered tag to
328 * force all outstanding transactions to be se 421 * force all outstanding transactions to be serviced prior to a new
329 * transaction. 422 * transaction.
330 */ 423 */
331 static uint32_t aic7xxx_periodic_otag; !! 424 uint32_t aic7xxx_periodic_otag;
332 425
333 /* 426 /*
334 * Module information and settable options. 427 * Module information and settable options.
335 */ 428 */
336 static char *aic7xxx = NULL; 429 static char *aic7xxx = NULL;
337 430
338 MODULE_AUTHOR("Maintainer: Hannes Reinecke <ha !! 431 MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>");
339 MODULE_DESCRIPTION("Adaptec AIC77XX/78XX SCSI !! 432 MODULE_DESCRIPTION("Adaptec Aic77XX/78XX SCSI Host Bus Adapter driver");
340 MODULE_LICENSE("Dual BSD/GPL"); 433 MODULE_LICENSE("Dual BSD/GPL");
341 MODULE_VERSION(AIC7XXX_DRIVER_VERSION); 434 MODULE_VERSION(AIC7XXX_DRIVER_VERSION);
342 module_param(aic7xxx, charp, 0444); 435 module_param(aic7xxx, charp, 0444);
343 MODULE_PARM_DESC(aic7xxx, 436 MODULE_PARM_DESC(aic7xxx,
344 "period-delimited options string:\n" !! 437 "period delimited, options string.\n"
345 " verbose Enable verbose 438 " verbose Enable verbose/diagnostic logging\n"
346 " allow_memio Allow device r 439 " allow_memio Allow device registers to be memory mapped\n"
347 " debug Bitmask of deb 440 " debug Bitmask of debug values to enable\n"
348 " no_probe Toggle EISA/VL 441 " no_probe Toggle EISA/VLB controller probing\n"
349 " probe_eisa_vl Toggle EISA/VL 442 " probe_eisa_vl Toggle EISA/VLB controller probing\n"
350 " no_reset Suppress initi !! 443 " no_reset Supress initial bus resets\n"
351 " extended Enable extende 444 " extended Enable extended geometry on all controllers\n"
352 " periodic_otag Send an ordere 445 " periodic_otag Send an ordered tagged transaction\n"
353 " periodically t 446 " periodically to prevent tag starvation.\n"
354 " This may be re 447 " This may be required by some older disk\n"
355 " drives or RAID 448 " drives or RAID arrays.\n"
>> 449 " reverse_scan Sort PCI devices highest Bus/Slot to lowest\n"
356 " tag_info:<tag_str> Set per-target 450 " tag_info:<tag_str> Set per-target tag depth\n"
357 " global_tag_depth:<int> Global tag dep 451 " global_tag_depth:<int> Global tag depth for every target\n"
358 " on every bus\n 452 " on every bus\n"
>> 453 " dv:<dv_settings> Set per-controller Domain Validation Setting.\n"
359 " seltime:<int> Selection Time 454 " seltime:<int> Selection Timeout\n"
360 " (0/256ms,1/128 455 " (0/256ms,1/128ms,2/64ms,3/32ms)\n"
361 "\n" 456 "\n"
362 " Sample /etc/modprobe.conf line:\n" 457 " Sample /etc/modprobe.conf line:\n"
363 " Toggle EISA/VLB probing\n" 458 " Toggle EISA/VLB probing\n"
364 " Set tag depth on Controller 1/ 459 " Set tag depth on Controller 1/Target 1 to 10 tags\n"
365 " Shorten the selection timeout 460 " Shorten the selection timeout to 128ms\n"
366 "\n" 461 "\n"
367 " options aic7xxx 'aic7xxx=probe_eisa_vl 462 " options aic7xxx 'aic7xxx=probe_eisa_vl.tag_info:{{}.{.10}}.seltime:1'\n"
368 ); 463 );
369 464
370 static void ahc_linux_handle_scsi_status(struc 465 static void ahc_linux_handle_scsi_status(struct ahc_softc *,
371 struc !! 466 struct ahc_linux_device *,
372 struc 467 struct scb *);
373 static void ahc_linux_queue_cmd_complete(struc 468 static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc,
374 struc !! 469 Scsi_Cmnd *cmd);
>> 470 static void ahc_linux_filter_inquiry(struct ahc_softc*, struct ahc_devinfo*);
>> 471 static void ahc_linux_sem_timeout(u_long arg);
375 static void ahc_linux_freeze_simq(struct ahc_s 472 static void ahc_linux_freeze_simq(struct ahc_softc *ahc);
376 static void ahc_linux_release_simq(struct ahc_ !! 473 static void ahc_linux_release_simq(u_long arg);
377 static int ahc_linux_queue_recovery_cmd(struc !! 474 static void ahc_linux_dev_timed_unfreeze(u_long arg);
>> 475 static int ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag);
378 static void ahc_linux_initialize_scsi_bus(stru 476 static void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc);
>> 477 static void ahc_linux_size_nseg(void);
>> 478 static void ahc_linux_thread_run_complete_queue(struct ahc_softc *ahc);
>> 479 static void ahc_linux_start_dv(struct ahc_softc *ahc);
>> 480 static void ahc_linux_dv_timeout(struct scsi_cmnd *cmd);
>> 481 static int ahc_linux_dv_thread(void *data);
>> 482 static void ahc_linux_kill_dv_thread(struct ahc_softc *ahc);
>> 483 static void ahc_linux_dv_target(struct ahc_softc *ahc, u_int target);
>> 484 static void ahc_linux_dv_transition(struct ahc_softc *ahc,
>> 485 struct scsi_cmnd *cmd,
>> 486 struct ahc_devinfo *devinfo,
>> 487 struct ahc_linux_target *targ);
>> 488 static void ahc_linux_dv_fill_cmd(struct ahc_softc *ahc,
>> 489 struct scsi_cmnd *cmd,
>> 490 struct ahc_devinfo *devinfo);
>> 491 static void ahc_linux_dv_inq(struct ahc_softc *ahc,
>> 492 struct scsi_cmnd *cmd,
>> 493 struct ahc_devinfo *devinfo,
>> 494 struct ahc_linux_target *targ,
>> 495 u_int request_length);
>> 496 static void ahc_linux_dv_tur(struct ahc_softc *ahc,
>> 497 struct scsi_cmnd *cmd,
>> 498 struct ahc_devinfo *devinfo);
>> 499 static void ahc_linux_dv_rebd(struct ahc_softc *ahc,
>> 500 struct scsi_cmnd *cmd,
>> 501 struct ahc_devinfo *devinfo,
>> 502 struct ahc_linux_target *targ);
>> 503 static void ahc_linux_dv_web(struct ahc_softc *ahc,
>> 504 struct scsi_cmnd *cmd,
>> 505 struct ahc_devinfo *devinfo,
>> 506 struct ahc_linux_target *targ);
>> 507 static void ahc_linux_dv_reb(struct ahc_softc *ahc,
>> 508 struct scsi_cmnd *cmd,
>> 509 struct ahc_devinfo *devinfo,
>> 510 struct ahc_linux_target *targ);
>> 511 static void ahc_linux_dv_su(struct ahc_softc *ahc,
>> 512 struct scsi_cmnd *cmd,
>> 513 struct ahc_devinfo *devinfo,
>> 514 struct ahc_linux_target *targ);
>> 515 static int ahc_linux_fallback(struct ahc_softc *ahc,
>> 516 struct ahc_devinfo *devinfo);
>> 517 static void ahc_linux_dv_complete(Scsi_Cmnd *cmd);
>> 518 static void ahc_linux_generate_dv_pattern(struct ahc_linux_target *targ);
379 static u_int ahc_linux_user_tagdepth(struct ah 519 static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc,
380 struct ah 520 struct ahc_devinfo *devinfo);
381 static void ahc_linux_device_queue_depth(struc !! 521 static u_int ahc_linux_user_dv_setting(struct ahc_softc *ahc);
382 static int ahc_linux_run_command(struct ahc_so !! 522 static void ahc_linux_device_queue_depth(struct ahc_softc *ahc,
383 struct ahc_li !! 523 struct ahc_linux_device *dev);
384 struct scsi_c !! 524 static struct ahc_linux_target* ahc_linux_alloc_target(struct ahc_softc*,
>> 525 u_int, u_int);
>> 526 static void ahc_linux_free_target(struct ahc_softc*,
>> 527 struct ahc_linux_target*);
>> 528 static struct ahc_linux_device* ahc_linux_alloc_device(struct ahc_softc*,
>> 529 struct ahc_linux_target*,
>> 530 u_int);
>> 531 static void ahc_linux_free_device(struct ahc_softc*,
>> 532 struct ahc_linux_device*);
>> 533 static void ahc_linux_run_device_queue(struct ahc_softc*,
>> 534 struct ahc_linux_device*);
385 static void ahc_linux_setup_tag_info_global(ch 535 static void ahc_linux_setup_tag_info_global(char *p);
>> 536 static aic_option_callback_t ahc_linux_setup_tag_info;
>> 537 static aic_option_callback_t ahc_linux_setup_dv;
386 static int aic7xxx_setup(char *s); 538 static int aic7xxx_setup(char *s);
387 !! 539 static int ahc_linux_next_unit(void);
388 static int ahc_linux_unit; !! 540 static void ahc_runq_tasklet(unsigned long data);
389 !! 541 static struct ahc_cmd *ahc_linux_run_complete_queue(struct ahc_softc *ahc);
390 542
391 /********************************* Inlines *** 543 /********************************* Inlines ************************************/
>> 544 static __inline void ahc_schedule_runq(struct ahc_softc *ahc);
>> 545 static __inline struct ahc_linux_device*
>> 546 ahc_linux_get_device(struct ahc_softc *ahc, u_int channel,
>> 547 u_int target, u_int lun, int alloc);
>> 548 static __inline void ahc_schedule_completeq(struct ahc_softc *ahc);
>> 549 static __inline void ahc_linux_check_device_queue(struct ahc_softc *ahc,
>> 550 struct ahc_linux_device *dev);
>> 551 static __inline struct ahc_linux_device *
>> 552 ahc_linux_next_device_to_run(struct ahc_softc *ahc);
>> 553 static __inline void ahc_linux_run_device_queues(struct ahc_softc *ahc);
392 static __inline void ahc_linux_unmap_scb(struc 554 static __inline void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*);
393 555
394 static __inline int ahc_linux_map_seg(struct a 556 static __inline int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
395 struct a 557 struct ahc_dma_seg *sg,
396 dma_addr 558 dma_addr_t addr, bus_size_t len);
397 559
398 static __inline void 560 static __inline void
>> 561 ahc_schedule_completeq(struct ahc_softc *ahc)
>> 562 {
>> 563 if ((ahc->platform_data->flags & AHC_RUN_CMPLT_Q_TIMER) == 0) {
>> 564 ahc->platform_data->flags |= AHC_RUN_CMPLT_Q_TIMER;
>> 565 ahc->platform_data->completeq_timer.expires = jiffies;
>> 566 add_timer(&ahc->platform_data->completeq_timer);
>> 567 }
>> 568 }
>> 569
>> 570 /*
>> 571 * Must be called with our lock held.
>> 572 */
>> 573 static __inline void
>> 574 ahc_schedule_runq(struct ahc_softc *ahc)
>> 575 {
>> 576 tasklet_schedule(&ahc->platform_data->runq_tasklet);
>> 577 }
>> 578
>> 579 static __inline struct ahc_linux_device*
>> 580 ahc_linux_get_device(struct ahc_softc *ahc, u_int channel, u_int target,
>> 581 u_int lun, int alloc)
>> 582 {
>> 583 struct ahc_linux_target *targ;
>> 584 struct ahc_linux_device *dev;
>> 585 u_int target_offset;
>> 586
>> 587 target_offset = target;
>> 588 if (channel != 0)
>> 589 target_offset += 8;
>> 590 targ = ahc->platform_data->targets[target_offset];
>> 591 if (targ == NULL) {
>> 592 if (alloc != 0) {
>> 593 targ = ahc_linux_alloc_target(ahc, channel, target);
>> 594 if (targ == NULL)
>> 595 return (NULL);
>> 596 } else
>> 597 return (NULL);
>> 598 }
>> 599 dev = targ->devices[lun];
>> 600 if (dev == NULL && alloc != 0)
>> 601 dev = ahc_linux_alloc_device(ahc, targ, lun);
>> 602 return (dev);
>> 603 }
>> 604
>> 605 #define AHC_LINUX_MAX_RETURNED_ERRORS 4
>> 606 static struct ahc_cmd *
>> 607 ahc_linux_run_complete_queue(struct ahc_softc *ahc)
>> 608 {
>> 609 struct ahc_cmd *acmd;
>> 610 u_long done_flags;
>> 611 int with_errors;
>> 612
>> 613 with_errors = 0;
>> 614 ahc_done_lock(ahc, &done_flags);
>> 615 while ((acmd = TAILQ_FIRST(&ahc->platform_data->completeq)) != NULL) {
>> 616 Scsi_Cmnd *cmd;
>> 617
>> 618 if (with_errors > AHC_LINUX_MAX_RETURNED_ERRORS) {
>> 619 /*
>> 620 * Linux uses stack recursion to requeue
>> 621 * commands that need to be retried. Avoid
>> 622 * blowing out the stack by "spoon feeding"
>> 623 * commands that completed with error back
>> 624 * the operating system in case they are going
>> 625 * to be retried. "ick"
>> 626 */
>> 627 ahc_schedule_completeq(ahc);
>> 628 break;
>> 629 }
>> 630 TAILQ_REMOVE(&ahc->platform_data->completeq,
>> 631 acmd, acmd_links.tqe);
>> 632 cmd = &acmd_scsi_cmd(acmd);
>> 633 cmd->host_scribble = NULL;
>> 634 if (ahc_cmd_get_transaction_status(cmd) != DID_OK
>> 635 || (cmd->result & 0xFF) != SCSI_STATUS_OK)
>> 636 with_errors++;
>> 637
>> 638 cmd->scsi_done(cmd);
>> 639 }
>> 640 ahc_done_unlock(ahc, &done_flags);
>> 641 return (acmd);
>> 642 }
>> 643
>> 644 static __inline void
>> 645 ahc_linux_check_device_queue(struct ahc_softc *ahc,
>> 646 struct ahc_linux_device *dev)
>> 647 {
>> 648 if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) != 0
>> 649 && dev->active == 0) {
>> 650 dev->flags &= ~AHC_DEV_FREEZE_TIL_EMPTY;
>> 651 dev->qfrozen--;
>> 652 }
>> 653
>> 654 if (TAILQ_FIRST(&dev->busyq) == NULL
>> 655 || dev->openings == 0 || dev->qfrozen != 0)
>> 656 return;
>> 657
>> 658 ahc_linux_run_device_queue(ahc, dev);
>> 659 }
>> 660
>> 661 static __inline struct ahc_linux_device *
>> 662 ahc_linux_next_device_to_run(struct ahc_softc *ahc)
>> 663 {
>> 664
>> 665 if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0
>> 666 || (ahc->platform_data->qfrozen != 0
>> 667 && AHC_DV_SIMQ_FROZEN(ahc) == 0))
>> 668 return (NULL);
>> 669 return (TAILQ_FIRST(&ahc->platform_data->device_runq));
>> 670 }
>> 671
>> 672 static __inline void
>> 673 ahc_linux_run_device_queues(struct ahc_softc *ahc)
>> 674 {
>> 675 struct ahc_linux_device *dev;
>> 676
>> 677 while ((dev = ahc_linux_next_device_to_run(ahc)) != NULL) {
>> 678 TAILQ_REMOVE(&ahc->platform_data->device_runq, dev, links);
>> 679 dev->flags &= ~AHC_DEV_ON_RUN_LIST;
>> 680 ahc_linux_check_device_queue(ahc, dev);
>> 681 }
>> 682 }
>> 683
>> 684 static __inline void
399 ahc_linux_unmap_scb(struct ahc_softc *ahc, str 685 ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb)
400 { 686 {
401 struct scsi_cmnd *cmd; !! 687 Scsi_Cmnd *cmd;
402 688
403 cmd = scb->io_ctx; 689 cmd = scb->io_ctx;
404 ahc_sync_sglist(ahc, scb, BUS_DMASYNC_ 690 ahc_sync_sglist(ahc, scb, BUS_DMASYNC_POSTWRITE);
>> 691 if (cmd->use_sg != 0) {
>> 692 struct scatterlist *sg;
405 693
406 scsi_dma_unmap(cmd); !! 694 sg = (struct scatterlist *)cmd->request_buffer;
>> 695 pci_unmap_sg(ahc->dev_softc, sg, cmd->use_sg,
>> 696 scsi_to_pci_dma_dir(cmd->sc_data_direction));
>> 697 } else if (cmd->request_bufflen != 0) {
>> 698 pci_unmap_single(ahc->dev_softc,
>> 699 scb->platform_data->buf_busaddr,
>> 700 cmd->request_bufflen,
>> 701 scsi_to_pci_dma_dir(cmd->sc_data_direction));
>> 702 }
407 } 703 }
408 704
409 static __inline int 705 static __inline int
410 ahc_linux_map_seg(struct ahc_softc *ahc, struc 706 ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
411 struct ahc_dma_seg *sg, dma_ 707 struct ahc_dma_seg *sg, dma_addr_t addr, bus_size_t len)
412 { 708 {
413 int consumed; 709 int consumed;
414 710
415 if ((scb->sg_count + 1) > AHC_NSEG) 711 if ((scb->sg_count + 1) > AHC_NSEG)
416 panic("Too few segs for dma ma 712 panic("Too few segs for dma mapping. "
417 "Increase AHC_NSEG\n"); 713 "Increase AHC_NSEG\n");
418 714
419 consumed = 1; 715 consumed = 1;
420 sg->addr = ahc_htole32(addr & 0xFFFFFF 716 sg->addr = ahc_htole32(addr & 0xFFFFFFFF);
421 scb->platform_data->xfer_len += len; 717 scb->platform_data->xfer_len += len;
422 718
423 if (sizeof(dma_addr_t) > 4 719 if (sizeof(dma_addr_t) > 4
424 && (ahc->flags & AHC_39BIT_ADDRESSING 720 && (ahc->flags & AHC_39BIT_ADDRESSING) != 0)
425 len |= (addr >> 8) & AHC_SG_HI 721 len |= (addr >> 8) & AHC_SG_HIGH_ADDR_MASK;
426 722
427 sg->len = ahc_htole32(len); 723 sg->len = ahc_htole32(len);
428 return (consumed); 724 return (consumed);
429 } 725 }
430 726
>> 727 /************************ Host template entry points *************************/
>> 728 static int ahc_linux_detect(Scsi_Host_Template *);
>> 729 static int ahc_linux_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
>> 730 static const char *ahc_linux_info(struct Scsi_Host *);
>> 731 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
>> 732 static int ahc_linux_slave_alloc(Scsi_Device *);
>> 733 static int ahc_linux_slave_configure(Scsi_Device *);
>> 734 static void ahc_linux_slave_destroy(Scsi_Device *);
>> 735 #if defined(__i386__)
>> 736 static int ahc_linux_biosparam(struct scsi_device*,
>> 737 struct block_device*,
>> 738 sector_t, int[]);
>> 739 #endif
>> 740 #else
>> 741 static int ahc_linux_release(struct Scsi_Host *);
>> 742 static void ahc_linux_select_queue_depth(struct Scsi_Host *host,
>> 743 Scsi_Device *scsi_devs);
>> 744 #if defined(__i386__)
>> 745 static int ahc_linux_biosparam(Disk *, kdev_t, int[]);
>> 746 #endif
>> 747 #endif
>> 748 static int ahc_linux_bus_reset(Scsi_Cmnd *);
>> 749 static int ahc_linux_dev_reset(Scsi_Cmnd *);
>> 750 static int ahc_linux_abort(Scsi_Cmnd *);
>> 751
>> 752 /*
>> 753 * Calculate a safe value for AHC_NSEG (as expressed through ahc_linux_nseg).
>> 754 *
>> 755 * In pre-2.5.X...
>> 756 * The midlayer allocates an S/G array dynamically when a command is issued
>> 757 * using SCSI malloc. This array, which is in an OS dependent format that
>> 758 * must later be copied to our private S/G list, is sized to house just the
>> 759 * number of segments needed for the current transfer. Since the code that
>> 760 * sizes the SCSI malloc pool does not take into consideration fragmentation
>> 761 * of the pool, executing transactions numbering just a fraction of our
>> 762 * concurrent transaction limit with list lengths aproaching AHC_NSEG will
>> 763 * quickly depleat the SCSI malloc pool of usable space. Unfortunately, the
>> 764 * mid-layer does not properly handle this scsi malloc failures for the S/G
>> 765 * array and the result can be a lockup of the I/O subsystem. We try to size
>> 766 * our S/G list so that it satisfies our drivers allocation requirements in
>> 767 * addition to avoiding fragmentation of the SCSI malloc pool.
>> 768 */
>> 769 static void
>> 770 ahc_linux_size_nseg(void)
>> 771 {
>> 772 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
>> 773 u_int cur_size;
>> 774 u_int best_size;
>> 775
>> 776 /*
>> 777 * The SCSI allocator rounds to the nearest 512 bytes
>> 778 * an cannot allocate across a page boundary. Our algorithm
>> 779 * is to start at 1K of scsi malloc space per-command and
>> 780 * loop through all factors of the PAGE_SIZE and pick the best.
>> 781 */
>> 782 best_size = 0;
>> 783 for (cur_size = 1024; cur_size <= PAGE_SIZE; cur_size *= 2) {
>> 784 u_int nseg;
>> 785
>> 786 nseg = cur_size / sizeof(struct scatterlist);
>> 787 if (nseg < AHC_LINUX_MIN_NSEG)
>> 788 continue;
>> 789
>> 790 if (best_size == 0) {
>> 791 best_size = cur_size;
>> 792 ahc_linux_nseg = nseg;
>> 793 } else {
>> 794 u_int best_rem;
>> 795 u_int cur_rem;
>> 796
>> 797 /*
>> 798 * Compare the traits of the current "best_size"
>> 799 * with the current size to determine if the
>> 800 * current size is a better size.
>> 801 */
>> 802 best_rem = best_size % sizeof(struct scatterlist);
>> 803 cur_rem = cur_size % sizeof(struct scatterlist);
>> 804 if (cur_rem < best_rem) {
>> 805 best_size = cur_size;
>> 806 ahc_linux_nseg = nseg;
>> 807 }
>> 808 }
>> 809 }
>> 810 #endif
>> 811 }
>> 812
>> 813 /*
>> 814 * Try to detect an Adaptec 7XXX controller.
>> 815 */
>> 816 static int
>> 817 ahc_linux_detect(Scsi_Host_Template *template)
>> 818 {
>> 819 struct ahc_softc *ahc;
>> 820 int found = 0;
>> 821
>> 822 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
>> 823 /*
>> 824 * It is a bug that the upper layer takes
>> 825 * this lock just prior to calling us.
>> 826 */
>> 827 spin_unlock_irq(&io_request_lock);
>> 828 #endif
>> 829
>> 830 /*
>> 831 * Sanity checking of Linux SCSI data structures so
>> 832 * that some of our hacks^H^H^H^H^Hassumptions aren't
>> 833 * violated.
>> 834 */
>> 835 if (offsetof(struct ahc_cmd_internal, end)
>> 836 > offsetof(struct scsi_cmnd, host_scribble)) {
>> 837 printf("ahc_linux_detect: SCSI data structures changed.\n");
>> 838 printf("ahc_linux_detect: Unable to attach\n");
>> 839 return (0);
>> 840 }
>> 841 ahc_linux_size_nseg();
>> 842 /*
>> 843 * If we've been passed any parameters, process them now.
>> 844 */
>> 845 if (aic7xxx)
>> 846 aic7xxx_setup(aic7xxx);
>> 847
>> 848 template->proc_name = "aic7xxx";
>> 849
>> 850 /*
>> 851 * Initialize our softc list lock prior to
>> 852 * probing for any adapters.
>> 853 */
>> 854 ahc_list_lockinit();
>> 855
>> 856 found = ahc_linux_pci_init();
>> 857 if (!ahc_linux_eisa_init())
>> 858 found++;
>> 859
>> 860 /*
>> 861 * Register with the SCSI layer all
>> 862 * controllers we've found.
>> 863 */
>> 864 TAILQ_FOREACH(ahc, &ahc_tailq, links) {
>> 865
>> 866 if (ahc_linux_register_host(ahc, template) == 0)
>> 867 found++;
>> 868 }
>> 869
>> 870 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
>> 871 spin_lock_irq(&io_request_lock);
>> 872 #endif
>> 873 aic7xxx_detect_complete++;
>> 874
>> 875 return (found);
>> 876 }
>> 877
>> 878 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
>> 879 /*
>> 880 * Free the passed in Scsi_Host memory structures prior to unloading the
>> 881 * module.
>> 882 */
>> 883 int
>> 884 ahc_linux_release(struct Scsi_Host * host)
>> 885 {
>> 886 struct ahc_softc *ahc;
>> 887 u_long l;
>> 888
>> 889 ahc_list_lock(&l);
>> 890 if (host != NULL) {
>> 891
>> 892 /*
>> 893 * We should be able to just perform
>> 894 * the free directly, but check our
>> 895 * list for extra sanity.
>> 896 */
>> 897 ahc = ahc_find_softc(*(struct ahc_softc **)host->hostdata);
>> 898 if (ahc != NULL) {
>> 899 u_long s;
>> 900
>> 901 ahc_lock(ahc, &s);
>> 902 ahc_intr_enable(ahc, FALSE);
>> 903 ahc_unlock(ahc, &s);
>> 904 ahc_free(ahc);
>> 905 }
>> 906 }
>> 907 ahc_list_unlock(&l);
>> 908 return (0);
>> 909 }
>> 910 #endif
>> 911
431 /* 912 /*
432 * Return a string describing the driver. 913 * Return a string describing the driver.
433 */ 914 */
434 static const char * 915 static const char *
435 ahc_linux_info(struct Scsi_Host *host) 916 ahc_linux_info(struct Scsi_Host *host)
436 { 917 {
437 static char buffer[512]; 918 static char buffer[512];
438 char ahc_info[256]; 919 char ahc_info[256];
439 char *bp; 920 char *bp;
440 struct ahc_softc *ahc; 921 struct ahc_softc *ahc;
441 922
442 bp = &buffer[0]; 923 bp = &buffer[0];
443 ahc = *(struct ahc_softc **)host->host 924 ahc = *(struct ahc_softc **)host->hostdata;
444 memset(bp, 0, sizeof(buffer)); 925 memset(bp, 0, sizeof(buffer));
445 strcpy(bp, "Adaptec AIC7XXX EISA/VLB/P 926 strcpy(bp, "Adaptec AIC7XXX EISA/VLB/PCI SCSI HBA DRIVER, Rev ");
446 strcat(bp, AIC7XXX_DRIVER_VERSION); 927 strcat(bp, AIC7XXX_DRIVER_VERSION);
447 strcat(bp, "\n"); 928 strcat(bp, "\n");
448 strcat(bp, " <"); 929 strcat(bp, " <");
449 strcat(bp, ahc->description); 930 strcat(bp, ahc->description);
450 strcat(bp, ">\n"); 931 strcat(bp, ">\n");
451 strcat(bp, " "); 932 strcat(bp, " ");
452 ahc_controller_info(ahc, ahc_info); 933 ahc_controller_info(ahc, ahc_info);
453 strcat(bp, ahc_info); 934 strcat(bp, ahc_info);
454 strcat(bp, "\n"); 935 strcat(bp, "\n");
455 936
456 return (bp); 937 return (bp);
457 } 938 }
458 939
459 /* 940 /*
460 * Queue an SCB to the controller. 941 * Queue an SCB to the controller.
461 */ 942 */
462 static int 943 static int
463 ahc_linux_queue(struct scsi_cmnd * cmd, void ( !! 944 ahc_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
464 { 945 {
465 struct ahc_softc *ahc; 946 struct ahc_softc *ahc;
466 struct ahc_linux_device *dev = scsi_ !! 947 struct ahc_linux_device *dev;
467 int rtn = SCSI_MLQUEUE_HOST_BUSY; !! 948 u_long flags;
468 unsigned long flags; <<
469 949
470 ahc = *(struct ahc_softc **)cmd->devic 950 ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
471 951
472 ahc_lock(ahc, &flags); !! 952 /*
473 if (ahc->platform_data->qfrozen == 0) !! 953 * Save the callback on completion function.
474 cmd->scsi_done = scsi_done; !! 954 */
475 cmd->result = CAM_REQ_INPROG < !! 955 cmd->scsi_done = scsi_done;
476 rtn = ahc_linux_run_command(ah <<
477 } <<
478 ahc_unlock(ahc, &flags); <<
479 <<
480 return rtn; <<
481 } <<
482 <<
483 static inline struct scsi_target ** <<
484 ahc_linux_target_in_softc(struct scsi_target * <<
485 { <<
486 struct ahc_softc *ahc = <<
487 *((struct ahc_softc **)dev_to_ <<
488 unsigned int target_offset; <<
489 <<
490 target_offset = starget->id; <<
491 if (starget->channel != 0) <<
492 target_offset += 8; <<
493 <<
494 return &ahc->platform_data->starget[ta <<
495 } <<
496 <<
497 static int <<
498 ahc_linux_target_alloc(struct scsi_target *sta <<
499 { <<
500 struct ahc_softc *ahc = <<
501 *((struct ahc_softc **)dev_to_ <<
502 struct seeprom_config *sc = ahc->seep_ <<
503 unsigned long flags; <<
504 struct scsi_target **ahc_targp = ahc_l <<
505 unsigned short scsirate; <<
506 struct ahc_devinfo devinfo; <<
507 struct ahc_initiator_tinfo *tinfo; <<
508 struct ahc_tmode_tstate *tstate; <<
509 char channel = starget->channel + 'A'; <<
510 unsigned int our_id = ahc->our_id; <<
511 unsigned int target_offset; <<
512 <<
513 target_offset = starget->id; <<
514 if (starget->channel != 0) <<
515 target_offset += 8; <<
516 <<
517 if (starget->channel) <<
518 our_id = ahc->our_id_b; <<
519 <<
520 ahc_lock(ahc, &flags); <<
521 <<
522 BUG_ON(*ahc_targp != NULL); <<
523 956
524 *ahc_targp = starget; !! 957 ahc_midlayer_entrypoint_lock(ahc, &flags);
525 958
526 if (sc) { !! 959 /*
527 int maxsync = AHC_SYNCRATE_DT; !! 960 * Close the race of a command that was in the process of
528 int ultra = 0; !! 961 * being queued to us just as our simq was frozen. Let
529 int flags = sc->device_flags[t !! 962 * DV commands through so long as we are only frozen to
530 !! 963 * perform DV.
531 if (ahc->flags & AHC_NEWEEPROM !! 964 */
532 if (flags & CFSYNCHISULTRA !! 965 if (ahc->platform_data->qfrozen != 0
533 ultra = 1; !! 966 && AHC_DV_CMD(cmd) == 0) {
534 } else if (flags & CFULTRAEN) <<
535 ultra = 1; <<
536 /* AIC nutcase; 10MHz appears <<
537 * change it to ultra=0, CFXFE <<
538 if(ultra && (flags & CFXFER) = <<
539 ultra = 0; <<
540 flags &= ~CFXFER; <<
541 } <<
542 <<
543 if ((ahc->features & AHC_ULTRA <<
544 scsirate = (flags & CF <<
545 } else { <<
546 scsirate = (flags & CF <<
547 maxsync = ultra ? AHC_ <<
548 AHC_SYNCRATE_F <<
549 } <<
550 spi_max_width(starget) = (flag <<
551 if (!(flags & CFSYNCH)) <<
552 spi_max_offset(starget <<
553 spi_min_period(starget) = <<
554 ahc_find_period(ahc, s <<
555 967
556 tinfo = ahc_fetch_transinfo(ah !! 968 ahc_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ);
557 st !! 969 ahc_linux_queue_cmd_complete(ahc, cmd);
>> 970 ahc_schedule_completeq(ahc);
>> 971 ahc_midlayer_entrypoint_unlock(ahc, &flags);
>> 972 return (0);
558 } 973 }
559 ahc_compile_devinfo(&devinfo, our_id, !! 974 dev = ahc_linux_get_device(ahc, cmd->device->channel, cmd->device->id,
560 CAM_LUN_WILDCARD, !! 975 cmd->device->lun, /*alloc*/TRUE);
561 ROLE_INITIATOR); !! 976 if (dev == NULL) {
562 ahc_set_syncrate(ahc, &devinfo, NULL, !! 977 ahc_cmd_set_transaction_status(cmd, CAM_RESRC_UNAVAIL);
563 AHC_TRANS_GOAL, /*pau !! 978 ahc_linux_queue_cmd_complete(ahc, cmd);
564 ahc_set_width(ahc, &devinfo, MSG_EXT_W !! 979 ahc_schedule_completeq(ahc);
565 AHC_TRANS_GOAL, /*paused !! 980 ahc_midlayer_entrypoint_unlock(ahc, &flags);
566 ahc_unlock(ahc, &flags); !! 981 printf("%s: aic7xxx_linux_queue - Unable to allocate device!\n",
567 !! 982 ahc_name(ahc));
568 return 0; !! 983 return (0);
>> 984 }
>> 985 cmd->result = CAM_REQ_INPROG << 16;
>> 986 TAILQ_INSERT_TAIL(&dev->busyq, (struct ahc_cmd *)cmd, acmd_links.tqe);
>> 987 if ((dev->flags & AHC_DEV_ON_RUN_LIST) == 0) {
>> 988 TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, dev, links);
>> 989 dev->flags |= AHC_DEV_ON_RUN_LIST;
>> 990 ahc_linux_run_device_queues(ahc);
>> 991 }
>> 992 ahc_midlayer_entrypoint_unlock(ahc, &flags);
>> 993 return (0);
569 } 994 }
570 995
571 static void !! 996 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
572 ahc_linux_target_destroy(struct scsi_target *s !! 997 static int
>> 998 ahc_linux_slave_alloc(Scsi_Device *device)
573 { 999 {
574 struct scsi_target **ahc_targp = ahc_l !! 1000 struct ahc_softc *ahc;
575 1001
576 *ahc_targp = NULL; !! 1002 ahc = *((struct ahc_softc **)device->host->hostdata);
>> 1003 if (bootverbose)
>> 1004 printf("%s: Slave Alloc %d\n", ahc_name(ahc), device->id);
>> 1005 return (0);
577 } 1006 }
578 1007
579 static int 1008 static int
580 ahc_linux_slave_alloc(struct scsi_device *sdev !! 1009 ahc_linux_slave_configure(Scsi_Device *device)
581 { 1010 {
582 struct ahc_softc *ahc = !! 1011 struct ahc_softc *ahc;
583 *((struct ahc_softc **)sdev->h !! 1012 struct ahc_linux_device *dev;
584 struct scsi_target *starget = sdev->sd !! 1013 u_long flags;
585 struct ahc_linux_device *dev; <<
586 1014
>> 1015 ahc = *((struct ahc_softc **)device->host->hostdata);
587 if (bootverbose) 1016 if (bootverbose)
588 printf("%s: Slave Alloc %d\n", !! 1017 printf("%s: Slave Configure %d\n", ahc_name(ahc), device->id);
589 !! 1018 ahc_midlayer_entrypoint_lock(ahc, &flags);
590 dev = scsi_transport_device_data(sdev) <<
591 memset(dev, 0, sizeof(*dev)); <<
592 <<
593 /* 1019 /*
594 * We start out life using untagged !! 1020 * Since Linux has attached to the device, configure
595 * transactions of which we allow one. !! 1021 * it so we don't free and allocate the device
>> 1022 * structure on every command.
596 */ 1023 */
597 dev->openings = 1; !! 1024 dev = ahc_linux_get_device(ahc, device->channel,
>> 1025 device->id, device->lun,
>> 1026 /*alloc*/TRUE);
>> 1027 if (dev != NULL) {
>> 1028 dev->flags &= ~AHC_DEV_UNCONFIGURED;
>> 1029 dev->scsi_device = device;
>> 1030 ahc_linux_device_queue_depth(ahc, dev);
>> 1031 }
>> 1032 ahc_midlayer_entrypoint_unlock(ahc, &flags);
>> 1033 return (0);
>> 1034 }
>> 1035
>> 1036 static void
>> 1037 ahc_linux_slave_destroy(Scsi_Device *device)
>> 1038 {
>> 1039 struct ahc_softc *ahc;
>> 1040 struct ahc_linux_device *dev;
>> 1041 u_long flags;
598 1042
>> 1043 ahc = *((struct ahc_softc **)device->host->hostdata);
>> 1044 if (bootverbose)
>> 1045 printf("%s: Slave Destroy %d\n", ahc_name(ahc), device->id);
>> 1046 ahc_midlayer_entrypoint_lock(ahc, &flags);
>> 1047 dev = ahc_linux_get_device(ahc, device->channel,
>> 1048 device->id, device->lun,
>> 1049 /*alloc*/FALSE);
599 /* 1050 /*
600 * Set maxtags to 0. This will be cha !! 1051 * Filter out "silly" deletions of real devices by only
601 * later determine that we are dealing !! 1052 * deleting devices that have had slave_configure()
602 * a tagged queuing capable device. !! 1053 * called on them. All other devices that have not
>> 1054 * been configured will automatically be deleted by
>> 1055 * the refcounting process.
603 */ 1056 */
604 dev->maxtags = 0; !! 1057 if (dev != NULL
605 !! 1058 && (dev->flags & AHC_DEV_SLAVE_CONFIGURED) != 0) {
606 spi_period(starget) = 0; !! 1059 dev->flags |= AHC_DEV_UNCONFIGURED;
607 !! 1060 if (TAILQ_EMPTY(&dev->busyq)
608 return 0; !! 1061 && dev->active == 0
>> 1062 && (dev->flags & AHC_DEV_TIMER_ACTIVE) == 0)
>> 1063 ahc_linux_free_device(ahc, dev);
>> 1064 }
>> 1065 ahc_midlayer_entrypoint_unlock(ahc, &flags);
609 } 1066 }
610 !! 1067 #else
611 static int !! 1068 /*
612 ahc_linux_slave_configure(struct scsi_device * !! 1069 * Sets the queue depth for each SCSI device hanging
>> 1070 * off the input host adapter.
>> 1071 */
>> 1072 static void
>> 1073 ahc_linux_select_queue_depth(struct Scsi_Host *host, Scsi_Device *scsi_devs)
613 { 1074 {
>> 1075 Scsi_Device *device;
>> 1076 Scsi_Device *ldev;
614 struct ahc_softc *ahc; 1077 struct ahc_softc *ahc;
>> 1078 u_long flags;
615 1079
616 ahc = *((struct ahc_softc **)sdev->hos !! 1080 ahc = *((struct ahc_softc **)host->hostdata);
617 !! 1081 ahc_lock(ahc, &flags);
618 if (bootverbose) !! 1082 for (device = scsi_devs; device != NULL; device = device->next) {
619 sdev_printk(KERN_INFO, sdev, " <<
620 1083
621 ahc_linux_device_queue_depth(sdev); !! 1084 /*
>> 1085 * Watch out for duplicate devices. This works around
>> 1086 * some quirks in how the SCSI scanning code does its
>> 1087 * device management.
>> 1088 */
>> 1089 for (ldev = scsi_devs; ldev != device; ldev = ldev->next) {
>> 1090 if (ldev->host == device->host
>> 1091 && ldev->channel == device->channel
>> 1092 && ldev->id == device->id
>> 1093 && ldev->lun == device->lun)
>> 1094 break;
>> 1095 }
>> 1096 /* Skip duplicate. */
>> 1097 if (ldev != device)
>> 1098 continue;
622 1099
623 /* Initial Domain Validation */ !! 1100 if (device->host == host) {
624 if (!spi_initial_dv(sdev->sdev_target) !! 1101 struct ahc_linux_device *dev;
625 spi_dv_device(sdev); <<
626 1102
627 return 0; !! 1103 /*
>> 1104 * Since Linux has attached to the device, configure
>> 1105 * it so we don't free and allocate the device
>> 1106 * structure on every command.
>> 1107 */
>> 1108 dev = ahc_linux_get_device(ahc, device->channel,
>> 1109 device->id, device->lun,
>> 1110 /*alloc*/TRUE);
>> 1111 if (dev != NULL) {
>> 1112 dev->flags &= ~AHC_DEV_UNCONFIGURED;
>> 1113 dev->scsi_device = device;
>> 1114 ahc_linux_device_queue_depth(ahc, dev);
>> 1115 device->queue_depth = dev->openings
>> 1116 + dev->active;
>> 1117 if ((dev->flags & (AHC_DEV_Q_BASIC
>> 1118 | AHC_DEV_Q_TAGGED)) == 0) {
>> 1119 /*
>> 1120 * We allow the OS to queue 2 untagged
>> 1121 * transactions to us at any time even
>> 1122 * though we can only execute them
>> 1123 * serially on the controller/device.
>> 1124 * This should remove some latency.
>> 1125 */
>> 1126 device->queue_depth = 2;
>> 1127 }
>> 1128 }
>> 1129 }
>> 1130 }
>> 1131 ahc_unlock(ahc, &flags);
628 } 1132 }
>> 1133 #endif
629 1134
630 #if defined(__i386__) 1135 #if defined(__i386__)
631 /* 1136 /*
632 * Return the disk geometry for the given SCSI 1137 * Return the disk geometry for the given SCSI device.
633 */ 1138 */
634 static int 1139 static int
>> 1140 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
635 ahc_linux_biosparam(struct scsi_device *sdev, 1141 ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
636 sector_t capacity, int geo 1142 sector_t capacity, int geom[])
637 { 1143 {
638 uint8_t *bh; 1144 uint8_t *bh;
>> 1145 #else
>> 1146 ahc_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
>> 1147 {
>> 1148 struct scsi_device *sdev = disk->device;
>> 1149 u_long capacity = disk->capacity;
>> 1150 struct buffer_head *bh;
>> 1151 #endif
639 int heads; 1152 int heads;
640 int sectors; 1153 int sectors;
641 int cylinders; 1154 int cylinders;
642 int ret; 1155 int ret;
643 int extended; 1156 int extended;
644 struct ahc_softc *ahc; 1157 struct ahc_softc *ahc;
645 u_int channel; 1158 u_int channel;
646 1159
647 ahc = *((struct ahc_softc **)sdev->hos 1160 ahc = *((struct ahc_softc **)sdev->host->hostdata);
648 channel = sdev_channel(sdev); !! 1161 channel = sdev->channel;
649 1162
>> 1163 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
650 bh = scsi_bios_ptable(bdev); 1164 bh = scsi_bios_ptable(bdev);
>> 1165 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,17)
>> 1166 bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, block_size(dev));
>> 1167 #else
>> 1168 bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, 1024);
>> 1169 #endif
>> 1170
651 if (bh) { 1171 if (bh) {
652 ret = scsi_partsize(bh, capaci 1172 ret = scsi_partsize(bh, capacity,
653 &geom[2], 1173 &geom[2], &geom[0], &geom[1]);
>> 1174 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
654 kfree(bh); 1175 kfree(bh);
>> 1176 #else
>> 1177 brelse(bh);
>> 1178 #endif
655 if (ret != -1) 1179 if (ret != -1)
656 return (ret); 1180 return (ret);
657 } 1181 }
658 heads = 64; 1182 heads = 64;
659 sectors = 32; 1183 sectors = 32;
660 cylinders = aic_sector_div(capacity, h 1184 cylinders = aic_sector_div(capacity, heads, sectors);
661 1185
662 if (aic7xxx_extended != 0) 1186 if (aic7xxx_extended != 0)
663 extended = 1; 1187 extended = 1;
664 else if (channel == 0) 1188 else if (channel == 0)
665 extended = (ahc->flags & AHC_E 1189 extended = (ahc->flags & AHC_EXTENDED_TRANS_A) != 0;
666 else 1190 else
667 extended = (ahc->flags & AHC_E 1191 extended = (ahc->flags & AHC_EXTENDED_TRANS_B) != 0;
668 if (extended && cylinders >= 1024) { 1192 if (extended && cylinders >= 1024) {
669 heads = 255; 1193 heads = 255;
670 sectors = 63; 1194 sectors = 63;
671 cylinders = aic_sector_div(cap 1195 cylinders = aic_sector_div(capacity, heads, sectors);
672 } 1196 }
673 geom[0] = heads; 1197 geom[0] = heads;
674 geom[1] = sectors; 1198 geom[1] = sectors;
675 geom[2] = cylinders; 1199 geom[2] = cylinders;
676 return (0); 1200 return (0);
677 } 1201 }
678 #endif 1202 #endif
679 1203
680 /* 1204 /*
681 * Abort the current SCSI command(s). 1205 * Abort the current SCSI command(s).
682 */ 1206 */
683 static int 1207 static int
684 ahc_linux_abort(struct scsi_cmnd *cmd) !! 1208 ahc_linux_abort(Scsi_Cmnd *cmd)
685 { 1209 {
686 int error; 1210 int error;
687 1211
688 error = ahc_linux_queue_recovery_cmd(c 1212 error = ahc_linux_queue_recovery_cmd(cmd, SCB_ABORT);
689 if (error != 0) 1213 if (error != 0)
690 printf("aic7xxx_abort returns 1214 printf("aic7xxx_abort returns 0x%x\n", error);
691 return (error); 1215 return (error);
692 } 1216 }
693 1217
694 /* 1218 /*
695 * Attempt to send a target reset message to t 1219 * Attempt to send a target reset message to the device that timed out.
696 */ 1220 */
697 static int 1221 static int
698 ahc_linux_dev_reset(struct scsi_cmnd *cmd) !! 1222 ahc_linux_dev_reset(Scsi_Cmnd *cmd)
699 { 1223 {
700 int error; 1224 int error;
701 1225
702 error = ahc_linux_queue_recovery_cmd(c 1226 error = ahc_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET);
703 if (error != 0) 1227 if (error != 0)
704 printf("aic7xxx_dev_reset retu 1228 printf("aic7xxx_dev_reset returns 0x%x\n", error);
705 return (error); 1229 return (error);
706 } 1230 }
707 1231
708 /* 1232 /*
709 * Reset the SCSI bus. 1233 * Reset the SCSI bus.
710 */ 1234 */
711 static int 1235 static int
712 ahc_linux_bus_reset(struct scsi_cmnd *cmd) !! 1236 ahc_linux_bus_reset(Scsi_Cmnd *cmd)
713 { 1237 {
714 struct ahc_softc *ahc; 1238 struct ahc_softc *ahc;
>> 1239 u_long s;
715 int found; 1240 int found;
716 unsigned long flags; <<
717 1241
718 ahc = *(struct ahc_softc **)cmd->devic 1242 ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
719 !! 1243 ahc_midlayer_entrypoint_lock(ahc, &s);
720 ahc_lock(ahc, &flags); !! 1244 found = ahc_reset_channel(ahc, cmd->device->channel + 'A',
721 found = ahc_reset_channel(ahc, scmd_ch <<
722 /*initiate r 1245 /*initiate reset*/TRUE);
723 ahc_unlock(ahc, &flags); !! 1246 ahc_linux_run_complete_queue(ahc);
>> 1247 ahc_midlayer_entrypoint_unlock(ahc, &s);
724 1248
725 if (bootverbose) 1249 if (bootverbose)
726 printf("%s: SCSI bus reset del 1250 printf("%s: SCSI bus reset delivered. "
727 "%d SCBs aborted.\n", a 1251 "%d SCBs aborted.\n", ahc_name(ahc), found);
728 1252
729 return SUCCESS; 1253 return SUCCESS;
730 } 1254 }
731 1255
732 struct scsi_host_template aic7xxx_driver_templ !! 1256 Scsi_Host_Template aic7xxx_driver_template = {
733 .module = THIS_MODULE, 1257 .module = THIS_MODULE,
734 .name = "aic7xxx", 1258 .name = "aic7xxx",
735 .proc_name = "aic7xxx", <<
736 .proc_info = ahc_linux_pr 1259 .proc_info = ahc_linux_proc_info,
737 .info = ahc_linux_in 1260 .info = ahc_linux_info,
738 .queuecommand = ahc_linux_qu 1261 .queuecommand = ahc_linux_queue,
739 .eh_abort_handler = ahc_linux_ab 1262 .eh_abort_handler = ahc_linux_abort,
740 .eh_device_reset_handler = ahc_linux_d 1263 .eh_device_reset_handler = ahc_linux_dev_reset,
741 .eh_bus_reset_handler = ahc_linux_bu 1264 .eh_bus_reset_handler = ahc_linux_bus_reset,
742 #if defined(__i386__) 1265 #if defined(__i386__)
743 .bios_param = ahc_linux_bi 1266 .bios_param = ahc_linux_biosparam,
744 #endif 1267 #endif
745 .can_queue = AHC_MAX_QUEU 1268 .can_queue = AHC_MAX_QUEUE,
746 .this_id = -1, 1269 .this_id = -1,
747 .max_sectors = 8192, <<
748 .cmd_per_lun = 2, 1270 .cmd_per_lun = 2,
749 .use_clustering = ENABLE_CLUST 1271 .use_clustering = ENABLE_CLUSTERING,
750 .slave_alloc = ahc_linux_sl 1272 .slave_alloc = ahc_linux_slave_alloc,
751 .slave_configure = ahc_linux_sl 1273 .slave_configure = ahc_linux_slave_configure,
752 .target_alloc = ahc_linux_ta !! 1274 .slave_destroy = ahc_linux_slave_destroy,
753 .target_destroy = ahc_linux_ta <<
754 }; 1275 };
755 1276
756 /**************************** Tasklet Handler 1277 /**************************** Tasklet Handler *********************************/
757 1278
>> 1279 /*
>> 1280 * In 2.4.X and above, this routine is called from a tasklet,
>> 1281 * so we must re-acquire our lock prior to executing this code.
>> 1282 * In all prior kernels, ahc_schedule_runq() calls this routine
>> 1283 * directly and ahc_schedule_runq() is called with our lock held.
>> 1284 */
>> 1285 static void
>> 1286 ahc_runq_tasklet(unsigned long data)
>> 1287 {
>> 1288 struct ahc_softc* ahc;
>> 1289 struct ahc_linux_device *dev;
>> 1290 u_long flags;
>> 1291
>> 1292 ahc = (struct ahc_softc *)data;
>> 1293 ahc_lock(ahc, &flags);
>> 1294 while ((dev = ahc_linux_next_device_to_run(ahc)) != NULL) {
>> 1295
>> 1296 TAILQ_REMOVE(&ahc->platform_data->device_runq, dev, links);
>> 1297 dev->flags &= ~AHC_DEV_ON_RUN_LIST;
>> 1298 ahc_linux_check_device_queue(ahc, dev);
>> 1299 /* Yeild to our interrupt handler */
>> 1300 ahc_unlock(ahc, &flags);
>> 1301 ahc_lock(ahc, &flags);
>> 1302 }
>> 1303 ahc_unlock(ahc, &flags);
>> 1304 }
>> 1305
758 /******************************** Macros ***** 1306 /******************************** Macros **************************************/
759 #define BUILD_SCSIID(ahc, cmd) 1307 #define BUILD_SCSIID(ahc, cmd) \
760 ((((cmd)->device->id << TID_SHIFT) & T 1308 ((((cmd)->device->id << TID_SHIFT) & TID) \
761 | (((cmd)->device->channel == 0) ? (ah 1309 | (((cmd)->device->channel == 0) ? (ahc)->our_id : (ahc)->our_id_b) \
762 | (((cmd)->device->channel == 0) ? 0 : 1310 | (((cmd)->device->channel == 0) ? 0 : TWIN_CHNLB))
763 1311
764 /******************************** Bus DMA **** 1312 /******************************** Bus DMA *************************************/
765 int 1313 int
766 ahc_dma_tag_create(struct ahc_softc *ahc, bus_ 1314 ahc_dma_tag_create(struct ahc_softc *ahc, bus_dma_tag_t parent,
767 bus_size_t alignment, bus_s 1315 bus_size_t alignment, bus_size_t boundary,
768 dma_addr_t lowaddr, dma_add 1316 dma_addr_t lowaddr, dma_addr_t highaddr,
769 bus_dma_filter_t *filter, v 1317 bus_dma_filter_t *filter, void *filterarg,
770 bus_size_t maxsize, int nse 1318 bus_size_t maxsize, int nsegments,
771 bus_size_t maxsegsz, int fl 1319 bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
772 { 1320 {
773 bus_dma_tag_t dmat; 1321 bus_dma_tag_t dmat;
774 1322
775 dmat = malloc(sizeof(*dmat), M_DEVBUF, 1323 dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT);
776 if (dmat == NULL) 1324 if (dmat == NULL)
777 return (ENOMEM); 1325 return (ENOMEM);
778 1326
779 /* 1327 /*
780 * Linux is very simplistic about DMA 1328 * Linux is very simplistic about DMA memory. For now don't
781 * maintain all specification informat 1329 * maintain all specification information. Once Linux supplies
782 * better facilities for doing these o 1330 * better facilities for doing these operations, or the
783 * needs of this particular driver cha 1331 * needs of this particular driver change, we might need to do
784 * more here. 1332 * more here.
785 */ 1333 */
786 dmat->alignment = alignment; 1334 dmat->alignment = alignment;
787 dmat->boundary = boundary; 1335 dmat->boundary = boundary;
788 dmat->maxsize = maxsize; 1336 dmat->maxsize = maxsize;
789 *ret_tag = dmat; 1337 *ret_tag = dmat;
790 return (0); 1338 return (0);
791 } 1339 }
792 1340
793 void 1341 void
794 ahc_dma_tag_destroy(struct ahc_softc *ahc, bus 1342 ahc_dma_tag_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat)
795 { 1343 {
796 free(dmat, M_DEVBUF); 1344 free(dmat, M_DEVBUF);
797 } 1345 }
798 1346
799 int 1347 int
800 ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dm 1348 ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr,
801 int flags, bus_dmamap_t *mapp 1349 int flags, bus_dmamap_t *mapp)
802 { 1350 {
>> 1351 bus_dmamap_t map;
>> 1352
>> 1353 map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT);
>> 1354 if (map == NULL)
>> 1355 return (ENOMEM);
>> 1356 /*
>> 1357 * Although we can dma data above 4GB, our
>> 1358 * "consistent" memory is below 4GB for
>> 1359 * space efficiency reasons (only need a 4byte
>> 1360 * address). For this reason, we have to reset
>> 1361 * our dma mask when doing allocations.
>> 1362 */
>> 1363 if (ahc->dev_softc != NULL)
>> 1364 if (pci_set_dma_mask(ahc->dev_softc, 0xFFFFFFFF)) {
>> 1365 printk(KERN_WARNING "aic7xxx: No suitable DMA available.\n");
>> 1366 kfree(map);
>> 1367 return (ENODEV);
>> 1368 }
803 *vaddr = pci_alloc_consistent(ahc->dev 1369 *vaddr = pci_alloc_consistent(ahc->dev_softc,
804 dmat->ma !! 1370 dmat->maxsize, &map->bus_addr);
>> 1371 if (ahc->dev_softc != NULL)
>> 1372 if (pci_set_dma_mask(ahc->dev_softc,
>> 1373 ahc->platform_data->hw_dma_mask)) {
>> 1374 printk(KERN_WARNING "aic7xxx: No suitable DMA available.\n");
>> 1375 kfree(map);
>> 1376 return (ENODEV);
>> 1377 }
805 if (*vaddr == NULL) 1378 if (*vaddr == NULL)
806 return ENOMEM; !! 1379 return (ENOMEM);
807 return 0; !! 1380 *mapp = map;
>> 1381 return(0);
808 } 1382 }
809 1383
810 void 1384 void
811 ahc_dmamem_free(struct ahc_softc *ahc, bus_dma 1385 ahc_dmamem_free(struct ahc_softc *ahc, bus_dma_tag_t dmat,
812 void* vaddr, bus_dmamap_t map) 1386 void* vaddr, bus_dmamap_t map)
813 { 1387 {
814 pci_free_consistent(ahc->dev_softc, dm 1388 pci_free_consistent(ahc->dev_softc, dmat->maxsize,
815 vaddr, map); !! 1389 vaddr, map->bus_addr);
816 } 1390 }
817 1391
818 int 1392 int
819 ahc_dmamap_load(struct ahc_softc *ahc, bus_dma 1393 ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map,
820 void *buf, bus_size_t buflen, 1394 void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
821 void *cb_arg, int flags) 1395 void *cb_arg, int flags)
822 { 1396 {
823 /* 1397 /*
824 * Assume for now that this will only 1398 * Assume for now that this will only be used during
825 * initialization and not for per-tran 1399 * initialization and not for per-transaction buffer mapping.
826 */ 1400 */
827 bus_dma_segment_t stack_sg; 1401 bus_dma_segment_t stack_sg;
828 1402
829 stack_sg.ds_addr = map; !! 1403 stack_sg.ds_addr = map->bus_addr;
830 stack_sg.ds_len = dmat->maxsize; 1404 stack_sg.ds_len = dmat->maxsize;
831 cb(cb_arg, &stack_sg, /*nseg*/1, /*err 1405 cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
832 return (0); 1406 return (0);
833 } 1407 }
834 1408
835 void 1409 void
836 ahc_dmamap_destroy(struct ahc_softc *ahc, bus_ 1410 ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
837 { 1411 {
>> 1412 /*
>> 1413 * The map may is NULL in our < 2.3.X implementation.
>> 1414 * Now it's 2.6.5, but just in case...
>> 1415 */
>> 1416 BUG_ON(map == NULL);
>> 1417 free(map, M_DEVBUF);
838 } 1418 }
839 1419
840 int 1420 int
841 ahc_dmamap_unload(struct ahc_softc *ahc, bus_d 1421 ahc_dmamap_unload(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
842 { 1422 {
843 /* Nothing to do */ 1423 /* Nothing to do */
844 return (0); 1424 return (0);
845 } 1425 }
846 1426
>> 1427 /********************* Platform Dependent Functions ***************************/
>> 1428 /*
>> 1429 * Compare "left hand" softc with "right hand" softc, returning:
>> 1430 * < 0 - lahc has a lower priority than rahc
>> 1431 * 0 - Softcs are equal
>> 1432 * > 0 - lahc has a higher priority than rahc
>> 1433 */
>> 1434 int
>> 1435 ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc)
>> 1436 {
>> 1437 int value;
>> 1438 int rvalue;
>> 1439 int lvalue;
>> 1440
>> 1441 /*
>> 1442 * Under Linux, cards are ordered as follows:
>> 1443 * 1) VLB/EISA BIOS enabled devices sorted by BIOS address.
>> 1444 * 2) PCI devices with BIOS enabled sorted by bus/slot/func.
>> 1445 * 3) All remaining VLB/EISA devices sorted by ioport.
>> 1446 * 4) All remaining PCI devices sorted by bus/slot/func.
>> 1447 */
>> 1448 value = (lahc->flags & AHC_BIOS_ENABLED)
>> 1449 - (rahc->flags & AHC_BIOS_ENABLED);
>> 1450 if (value != 0)
>> 1451 /* Controllers with BIOS enabled have a *higher* priority */
>> 1452 return (value);
>> 1453
>> 1454 /*
>> 1455 * Same BIOS setting, now sort based on bus type.
>> 1456 * EISA and VL controllers sort together. EISA/VL
>> 1457 * have higher priority than PCI.
>> 1458 */
>> 1459 rvalue = (rahc->chip & AHC_BUS_MASK);
>> 1460 if (rvalue == AHC_VL)
>> 1461 rvalue = AHC_EISA;
>> 1462 lvalue = (lahc->chip & AHC_BUS_MASK);
>> 1463 if (lvalue == AHC_VL)
>> 1464 lvalue = AHC_EISA;
>> 1465 value = rvalue - lvalue;
>> 1466 if (value != 0)
>> 1467 return (value);
>> 1468
>> 1469 /* Still equal. Sort by BIOS address, ioport, or bus/slot/func. */
>> 1470 switch (rvalue) {
>> 1471 #ifdef CONFIG_PCI
>> 1472 case AHC_PCI:
>> 1473 {
>> 1474 char primary_channel;
>> 1475
>> 1476 if (aic7xxx_reverse_scan != 0)
>> 1477 value = ahc_get_pci_bus(lahc->dev_softc)
>> 1478 - ahc_get_pci_bus(rahc->dev_softc);
>> 1479 else
>> 1480 value = ahc_get_pci_bus(rahc->dev_softc)
>> 1481 - ahc_get_pci_bus(lahc->dev_softc);
>> 1482 if (value != 0)
>> 1483 break;
>> 1484 if (aic7xxx_reverse_scan != 0)
>> 1485 value = ahc_get_pci_slot(lahc->dev_softc)
>> 1486 - ahc_get_pci_slot(rahc->dev_softc);
>> 1487 else
>> 1488 value = ahc_get_pci_slot(rahc->dev_softc)
>> 1489 - ahc_get_pci_slot(lahc->dev_softc);
>> 1490 if (value != 0)
>> 1491 break;
>> 1492 /*
>> 1493 * On multi-function devices, the user can choose
>> 1494 * to have function 1 probed before function 0.
>> 1495 * Give whichever channel is the primary channel
>> 1496 * the highest priority.
>> 1497 */
>> 1498 primary_channel = (lahc->flags & AHC_PRIMARY_CHANNEL) + 'A';
>> 1499 value = -1;
>> 1500 if (lahc->channel == primary_channel)
>> 1501 value = 1;
>> 1502 break;
>> 1503 }
>> 1504 #endif
>> 1505 case AHC_EISA:
>> 1506 if ((rahc->flags & AHC_BIOS_ENABLED) != 0) {
>> 1507 value = rahc->platform_data->bios_address
>> 1508 - lahc->platform_data->bios_address;
>> 1509 } else {
>> 1510 value = rahc->bsh.ioport
>> 1511 - lahc->bsh.ioport;
>> 1512 }
>> 1513 break;
>> 1514 default:
>> 1515 panic("ahc_softc_sort: invalid bus type");
>> 1516 }
>> 1517 return (value);
>> 1518 }
>> 1519
847 static void 1520 static void
848 ahc_linux_setup_tag_info_global(char *p) 1521 ahc_linux_setup_tag_info_global(char *p)
849 { 1522 {
850 int tags, i, j; 1523 int tags, i, j;
851 1524
852 tags = simple_strtoul(p + 1, NULL, 0) 1525 tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
853 printf("Setting Global Tags= %d\n", ta 1526 printf("Setting Global Tags= %d\n", tags);
854 1527
855 for (i = 0; i < ARRAY_SIZE(aic7xxx_tag !! 1528 for (i = 0; i < NUM_ELEMENTS(aic7xxx_tag_info); i++) {
856 for (j = 0; j < AHC_NUM_TARGET 1529 for (j = 0; j < AHC_NUM_TARGETS; j++) {
857 aic7xxx_tag_info[i].ta 1530 aic7xxx_tag_info[i].tag_commands[j] = tags;
858 } 1531 }
859 } 1532 }
860 } 1533 }
861 1534
862 static void 1535 static void
863 ahc_linux_setup_tag_info(u_long arg, int insta 1536 ahc_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
864 { 1537 {
865 1538
866 if ((instance >= 0) && (targ >= 0) 1539 if ((instance >= 0) && (targ >= 0)
867 && (instance < ARRAY_SIZE(aic7xxx_tag !! 1540 && (instance < NUM_ELEMENTS(aic7xxx_tag_info))
868 && (targ < AHC_NUM_TARGETS)) { 1541 && (targ < AHC_NUM_TARGETS)) {
869 aic7xxx_tag_info[instance].tag 1542 aic7xxx_tag_info[instance].tag_commands[targ] = value & 0xff;
870 if (bootverbose) 1543 if (bootverbose)
871 printf("tag_info[%d:%d 1544 printf("tag_info[%d:%d] = %d\n", instance, targ, value);
872 } 1545 }
873 } 1546 }
874 1547
875 static char * !! 1548 static void
876 ahc_parse_brace_option(char *opt_name, char *o !! 1549 ahc_linux_setup_dv(u_long arg, int instance, int targ, int32_t value)
877 void (*callback)(u_long !! 1550 {
878 u_long callback_arg) !! 1551
879 { !! 1552 if ((instance >= 0)
880 char *tok_end; !! 1553 && (instance < NUM_ELEMENTS(aic7xxx_dv_settings))) {
881 char *tok_end2; !! 1554 aic7xxx_dv_settings[instance] = value;
882 int i; !! 1555 if (bootverbose)
883 int instance; !! 1556 printf("dv[%d] = %d\n", instance, value);
884 int targ; <<
885 int done; <<
886 char tok_list[] = {'.', ',', '{', <<
887 <<
888 /* All options use a ':' name/arg sepa <<
889 if (*opt_arg != ':') <<
890 return (opt_arg); <<
891 opt_arg++; <<
892 instance = -1; <<
893 targ = -1; <<
894 done = FALSE; <<
895 /* <<
896 * Restore separator that may be in <<
897 * the middle of our option argument. <<
898 */ <<
899 tok_end = strchr(opt_arg, '\0'); <<
900 if (tok_end < end) <<
901 *tok_end = ','; <<
902 while (!done) { <<
903 switch (*opt_arg) { <<
904 case '{': <<
905 if (instance == -1) { <<
906 instance = 0; <<
907 } else { <<
908 if (depth > 1) <<
909 if (ta <<
910 <<
911 } else { <<
912 printf <<
913 <<
914 done = <<
915 } <<
916 } <<
917 opt_arg++; <<
918 break; <<
919 case '}': <<
920 if (targ != -1) <<
921 targ = -1; <<
922 else if (instance != - <<
923 instance = -1; <<
924 opt_arg++; <<
925 break; <<
926 case ',': <<
927 case '.': <<
928 if (instance == -1) <<
929 done = TRUE; <<
930 else if (targ >= 0) <<
931 targ++; <<
932 else if (instance >= 0 <<
933 instance++; <<
934 opt_arg++; <<
935 break; <<
936 case '\0': <<
937 done = TRUE; <<
938 break; <<
939 default: <<
940 tok_end = end; <<
941 for (i = 0; tok_list[i <<
942 tok_end2 = str <<
943 if ((tok_end2) <<
944 tok_en <<
945 } <<
946 callback(callback_arg, <<
947 simple_strtol <<
948 opt_arg = tok_end; <<
949 break; <<
950 } <<
951 } 1557 }
952 return (opt_arg); <<
953 } 1558 }
954 1559
955 /* 1560 /*
956 * Handle Linux boot parameters. This routine 1561 * Handle Linux boot parameters. This routine allows for assigning a value
957 * to a parameter with a ':' between the param 1562 * to a parameter with a ':' between the parameter and the value.
958 * ie. aic7xxx=stpwlev:1,extended 1563 * ie. aic7xxx=stpwlev:1,extended
959 */ 1564 */
960 static int 1565 static int
961 aic7xxx_setup(char *s) 1566 aic7xxx_setup(char *s)
962 { 1567 {
963 int i, n; 1568 int i, n;
964 char *p; 1569 char *p;
965 char *end; 1570 char *end;
966 1571
967 static struct { 1572 static struct {
968 const char *name; 1573 const char *name;
969 uint32_t *flag; 1574 uint32_t *flag;
970 } options[] = { 1575 } options[] = {
971 { "extended", &aic7xxx_extende 1576 { "extended", &aic7xxx_extended },
972 { "no_reset", &aic7xxx_no_rese 1577 { "no_reset", &aic7xxx_no_reset },
973 { "verbose", &aic7xxx_verbose 1578 { "verbose", &aic7xxx_verbose },
974 { "allow_memio", &aic7xxx_allo 1579 { "allow_memio", &aic7xxx_allow_memio},
975 #ifdef AHC_DEBUG 1580 #ifdef AHC_DEBUG
976 { "debug", &ahc_debug }, 1581 { "debug", &ahc_debug },
977 #endif 1582 #endif
>> 1583 { "reverse_scan", &aic7xxx_reverse_scan },
>> 1584 { "no_probe", &aic7xxx_probe_eisa_vl },
>> 1585 { "probe_eisa_vl", &aic7xxx_probe_eisa_vl },
978 { "periodic_otag", &aic7xxx_pe 1586 { "periodic_otag", &aic7xxx_periodic_otag },
979 { "pci_parity", &aic7xxx_pci_p 1587 { "pci_parity", &aic7xxx_pci_parity },
980 { "seltime", &aic7xxx_seltime 1588 { "seltime", &aic7xxx_seltime },
981 { "tag_info", NULL }, 1589 { "tag_info", NULL },
982 { "global_tag_depth", NULL }, 1590 { "global_tag_depth", NULL },
983 { "dv", NULL } 1591 { "dv", NULL }
984 }; 1592 };
985 1593
986 end = strchr(s, '\0'); 1594 end = strchr(s, '\0');
987 1595
988 /* 1596 /*
989 * XXX ia64 gcc isn't smart enough to !! 1597 * XXX ia64 gcc isn't smart enough to know that NUM_ELEMENTS
990 * will never be 0 in this case. 1598 * will never be 0 in this case.
991 */ 1599 */
992 n = 0; 1600 n = 0;
993 1601
994 while ((p = strsep(&s, ",.")) != NULL) 1602 while ((p = strsep(&s, ",.")) != NULL) {
995 if (*p == '\0') 1603 if (*p == '\0')
996 continue; 1604 continue;
997 for (i = 0; i < ARRAY_SIZE(opt !! 1605 for (i = 0; i < NUM_ELEMENTS(options); i++) {
998 1606
999 n = strlen(options[i]. 1607 n = strlen(options[i].name);
1000 if (strncmp(options[i 1608 if (strncmp(options[i].name, p, n) == 0)
1001 break; 1609 break;
1002 } 1610 }
1003 if (i == ARRAY_SIZE(options)) !! 1611 if (i == NUM_ELEMENTS(options))
1004 continue; 1612 continue;
1005 1613
1006 if (strncmp(p, "global_tag_de 1614 if (strncmp(p, "global_tag_depth", n) == 0) {
1007 ahc_linux_setup_tag_i 1615 ahc_linux_setup_tag_info_global(p + n);
1008 } else if (strncmp(p, "tag_in 1616 } else if (strncmp(p, "tag_info", n) == 0) {
1009 s = ahc_parse_brace_o !! 1617 s = aic_parse_brace_option("tag_info", p + n, end,
1010 2, ahc_linux_setu 1618 2, ahc_linux_setup_tag_info, 0);
>> 1619 } else if (strncmp(p, "dv", n) == 0) {
>> 1620 s = aic_parse_brace_option("dv", p + n, end, 1,
>> 1621 ahc_linux_setup_dv, 0);
1011 } else if (p[n] == ':') { 1622 } else if (p[n] == ':') {
1012 *(options[i].flag) = 1623 *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
1013 } else if (strncmp(p, "verbos 1624 } else if (strncmp(p, "verbose", n) == 0) {
1014 *(options[i].flag) = 1625 *(options[i].flag) = 1;
1015 } else { 1626 } else {
1016 *(options[i].flag) ^= 1627 *(options[i].flag) ^= 0xFFFFFFFF;
1017 } 1628 }
1018 } 1629 }
1019 return 1; 1630 return 1;
1020 } 1631 }
1021 1632
1022 __setup("aic7xxx=", aic7xxx_setup); 1633 __setup("aic7xxx=", aic7xxx_setup);
1023 1634
1024 uint32_t aic7xxx_verbose; 1635 uint32_t aic7xxx_verbose;
1025 1636
1026 int 1637 int
1027 ahc_linux_register_host(struct ahc_softc *ahc !! 1638 ahc_linux_register_host(struct ahc_softc *ahc, Scsi_Host_Template *template)
1028 { 1639 {
1029 char buf[80]; !! 1640 char buf[80];
1030 struct Scsi_Host *host; !! 1641 struct Scsi_Host *host;
1031 char *new_name; 1642 char *new_name;
1032 u_long s; !! 1643 u_long s;
1033 int retval; !! 1644 u_int targ_offset;
1034 1645
1035 template->name = ahc->description; 1646 template->name = ahc->description;
1036 host = scsi_host_alloc(template, size 1647 host = scsi_host_alloc(template, sizeof(struct ahc_softc *));
1037 if (host == NULL) 1648 if (host == NULL)
1038 return (ENOMEM); 1649 return (ENOMEM);
1039 1650
1040 *((struct ahc_softc **)host->hostdata 1651 *((struct ahc_softc **)host->hostdata) = ahc;
>> 1652 ahc_lock(ahc, &s);
>> 1653 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
>> 1654 scsi_assign_lock(host, &ahc->platform_data->spin_lock);
>> 1655 #elif AHC_SCSI_HAS_HOST_LOCK != 0
>> 1656 host->lock = &ahc->platform_data->spin_lock;
>> 1657 #endif
1041 ahc->platform_data->host = host; 1658 ahc->platform_data->host = host;
1042 host->can_queue = AHC_MAX_QUEUE; 1659 host->can_queue = AHC_MAX_QUEUE;
1043 host->cmd_per_lun = 2; 1660 host->cmd_per_lun = 2;
1044 /* XXX No way to communicate the ID f 1661 /* XXX No way to communicate the ID for multiple channels */
1045 host->this_id = ahc->our_id; 1662 host->this_id = ahc->our_id;
1046 host->irq = ahc->platform_data->irq; 1663 host->irq = ahc->platform_data->irq;
1047 host->max_id = (ahc->features & AHC_W 1664 host->max_id = (ahc->features & AHC_WIDE) ? 16 : 8;
1048 host->max_lun = AHC_NUM_LUNS; 1665 host->max_lun = AHC_NUM_LUNS;
1049 host->max_channel = (ahc->features & 1666 host->max_channel = (ahc->features & AHC_TWIN) ? 1 : 0;
1050 host->sg_tablesize = AHC_NSEG; 1667 host->sg_tablesize = AHC_NSEG;
1051 ahc_lock(ahc, &s); !! 1668 ahc_set_unit(ahc, ahc_linux_next_unit());
1052 ahc_set_unit(ahc, ahc_linux_unit++); <<
1053 ahc_unlock(ahc, &s); <<
1054 sprintf(buf, "scsi%d", host->host_no) 1669 sprintf(buf, "scsi%d", host->host_no);
1055 new_name = malloc(strlen(buf) + 1, M_ 1670 new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
1056 if (new_name != NULL) { 1671 if (new_name != NULL) {
1057 strcpy(new_name, buf); 1672 strcpy(new_name, buf);
1058 ahc_set_name(ahc, new_name); 1673 ahc_set_name(ahc, new_name);
1059 } 1674 }
1060 host->unique_id = ahc->unit; 1675 host->unique_id = ahc->unit;
>> 1676 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
>> 1677 scsi_set_pci_device(host, ahc->dev_softc);
>> 1678 #endif
1061 ahc_linux_initialize_scsi_bus(ahc); 1679 ahc_linux_initialize_scsi_bus(ahc);
1062 ahc_intr_enable(ahc, TRUE); !! 1680 ahc_unlock(ahc, &s);
1063 !! 1681 ahc->platform_data->dv_pid = kernel_thread(ahc_linux_dv_thread, ahc, 0);
1064 host->transportt = ahc_linux_transpor !! 1682 ahc_lock(ahc, &s);
>> 1683 if (ahc->platform_data->dv_pid < 0) {
>> 1684 printf("%s: Failed to create DV thread, error= %d\n",
>> 1685 ahc_name(ahc), ahc->platform_data->dv_pid);
>> 1686 return (-ahc->platform_data->dv_pid);
>> 1687 }
>> 1688 /*
>> 1689 * Initially allocate *all* of our linux target objects
>> 1690 * so that the DV thread will scan them all in parallel
>> 1691 * just after driver initialization. Any device that
>> 1692 * does not exist will have its target object destroyed
>> 1693 * by the selection timeout handler. In the case of a
>> 1694 * device that appears after the initial DV scan, async
>> 1695 * negotiation will occur for the first command, and DV
>> 1696 * will comence should that first command be successful.
>> 1697 */
>> 1698 for (targ_offset = 0;
>> 1699 targ_offset < host->max_id * (host->max_channel + 1);
>> 1700 targ_offset++) {
>> 1701 u_int channel;
>> 1702 u_int target;
>> 1703
>> 1704 channel = 0;
>> 1705 target = targ_offset;
>> 1706 if (target > 7
>> 1707 && (ahc->features & AHC_TWIN) != 0) {
>> 1708 channel = 1;
>> 1709 target &= 0x7;
>> 1710 }
>> 1711 /*
>> 1712 * Skip our own ID. Some Compaq/HP storage devices
>> 1713 * have enclosure management devices that respond to
>> 1714 * single bit selection (i.e. selecting ourselves).
>> 1715 * It is expected that either an external application
>> 1716 * or a modified kernel will be used to probe this
>> 1717 * ID if it is appropriate. To accommodate these
>> 1718 * installations, ahc_linux_alloc_target() will allocate
>> 1719 * for our ID if asked to do so.
>> 1720 */
>> 1721 if ((channel == 0 && target == ahc->our_id)
>> 1722 || (channel == 1 && target == ahc->our_id_b))
>> 1723 continue;
1065 1724
1066 retval = scsi_add_host(host, !! 1725 ahc_linux_alloc_target(ahc, channel, target);
1067 (ahc->dev_softc ? &ah <<
1068 if (retval) { <<
1069 printk(KERN_WARNING "aic7xxx: <<
1070 scsi_host_put(host); <<
1071 return retval; <<
1072 } 1726 }
>> 1727 ahc_intr_enable(ahc, TRUE);
>> 1728 ahc_linux_start_dv(ahc);
>> 1729 ahc_unlock(ahc, &s);
1073 1730
>> 1731 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
>> 1732 scsi_add_host(host, (ahc->dev_softc ? &ahc->dev_softc->dev : NULL)); /* XXX handle failure */
1074 scsi_scan_host(host); 1733 scsi_scan_host(host);
1075 return 0; !! 1734 #endif
>> 1735 return (0);
>> 1736 }
>> 1737
>> 1738 uint64_t
>> 1739 ahc_linux_get_memsize(void)
>> 1740 {
>> 1741 struct sysinfo si;
>> 1742
>> 1743 si_meminfo(&si);
>> 1744 return ((uint64_t)si.totalram << PAGE_SHIFT);
>> 1745 }
>> 1746
>> 1747 /*
>> 1748 * Find the smallest available unit number to use
>> 1749 * for a new device. We don't just use a static
>> 1750 * count to handle the "repeated hot-(un)plug"
>> 1751 * scenario.
>> 1752 */
>> 1753 static int
>> 1754 ahc_linux_next_unit(void)
>> 1755 {
>> 1756 struct ahc_softc *ahc;
>> 1757 int unit;
>> 1758
>> 1759 unit = 0;
>> 1760 retry:
>> 1761 TAILQ_FOREACH(ahc, &ahc_tailq, links) {
>> 1762 if (ahc->unit == unit) {
>> 1763 unit++;
>> 1764 goto retry;
>> 1765 }
>> 1766 }
>> 1767 return (unit);
1076 } 1768 }
1077 1769
1078 /* 1770 /*
1079 * Place the SCSI bus into a known state by e 1771 * Place the SCSI bus into a known state by either resetting it,
1080 * or forcing transfer negotiations on the ne 1772 * or forcing transfer negotiations on the next command to any
1081 * target. 1773 * target.
1082 */ 1774 */
1083 void 1775 void
1084 ahc_linux_initialize_scsi_bus(struct ahc_soft 1776 ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc)
1085 { 1777 {
1086 int i; 1778 int i;
1087 int numtarg; 1779 int numtarg;
1088 unsigned long s; <<
1089 1780
1090 i = 0; 1781 i = 0;
1091 numtarg = 0; 1782 numtarg = 0;
1092 1783
1093 ahc_lock(ahc, &s); <<
1094 <<
1095 if (aic7xxx_no_reset != 0) 1784 if (aic7xxx_no_reset != 0)
1096 ahc->flags &= ~(AHC_RESET_BUS 1785 ahc->flags &= ~(AHC_RESET_BUS_A|AHC_RESET_BUS_B);
1097 1786
1098 if ((ahc->flags & AHC_RESET_BUS_A) != 1787 if ((ahc->flags & AHC_RESET_BUS_A) != 0)
1099 ahc_reset_channel(ahc, 'A', / 1788 ahc_reset_channel(ahc, 'A', /*initiate_reset*/TRUE);
1100 else 1789 else
1101 numtarg = (ahc->features & AH 1790 numtarg = (ahc->features & AHC_WIDE) ? 16 : 8;
1102 1791
1103 if ((ahc->features & AHC_TWIN) != 0) 1792 if ((ahc->features & AHC_TWIN) != 0) {
1104 1793
1105 if ((ahc->flags & AHC_RESET_B 1794 if ((ahc->flags & AHC_RESET_BUS_B) != 0) {
1106 ahc_reset_channel(ahc 1795 ahc_reset_channel(ahc, 'B', /*initiate_reset*/TRUE);
1107 } else { 1796 } else {
1108 if (numtarg == 0) 1797 if (numtarg == 0)
1109 i = 8; 1798 i = 8;
1110 numtarg += 8; 1799 numtarg += 8;
1111 } 1800 }
1112 } 1801 }
1113 1802
1114 /* 1803 /*
1115 * Force negotiation to async for all 1804 * Force negotiation to async for all targets that
1116 * will not see an initial bus reset. 1805 * will not see an initial bus reset.
1117 */ 1806 */
1118 for (; i < numtarg; i++) { 1807 for (; i < numtarg; i++) {
1119 struct ahc_devinfo devinfo; 1808 struct ahc_devinfo devinfo;
1120 struct ahc_initiator_tinfo *t 1809 struct ahc_initiator_tinfo *tinfo;
1121 struct ahc_tmode_tstate *tsta 1810 struct ahc_tmode_tstate *tstate;
1122 u_int our_id; 1811 u_int our_id;
1123 u_int target_id; 1812 u_int target_id;
1124 char channel; 1813 char channel;
1125 1814
1126 channel = 'A'; 1815 channel = 'A';
1127 our_id = ahc->our_id; 1816 our_id = ahc->our_id;
1128 target_id = i; 1817 target_id = i;
1129 if (i > 7 && (ahc->features & 1818 if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
1130 channel = 'B'; 1819 channel = 'B';
1131 our_id = ahc->our_id_ 1820 our_id = ahc->our_id_b;
1132 target_id = i % 8; 1821 target_id = i % 8;
1133 } 1822 }
1134 tinfo = ahc_fetch_transinfo(a 1823 tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
1135 t 1824 target_id, &tstate);
1136 ahc_compile_devinfo(&devinfo, 1825 ahc_compile_devinfo(&devinfo, our_id, target_id,
1137 CAM_LUN_W 1826 CAM_LUN_WILDCARD, channel, ROLE_INITIATOR);
1138 ahc_update_neg_request(ahc, & 1827 ahc_update_neg_request(ahc, &devinfo, tstate,
1139 tinfo, 1828 tinfo, AHC_NEG_ALWAYS);
1140 } 1829 }
1141 ahc_unlock(ahc, &s); <<
1142 /* Give the bus some time to recover 1830 /* Give the bus some time to recover */
1143 if ((ahc->flags & (AHC_RESET_BUS_A|AH 1831 if ((ahc->flags & (AHC_RESET_BUS_A|AHC_RESET_BUS_B)) != 0) {
1144 ahc_linux_freeze_simq(ahc); 1832 ahc_linux_freeze_simq(ahc);
1145 msleep(AIC7XXX_RESET_DELAY); !! 1833 init_timer(&ahc->platform_data->reset_timer);
1146 ahc_linux_release_simq(ahc); !! 1834 ahc->platform_data->reset_timer.data = (u_long)ahc;
>> 1835 ahc->platform_data->reset_timer.expires =
>> 1836 jiffies + (AIC7XXX_RESET_DELAY * HZ)/1000;
>> 1837 ahc->platform_data->reset_timer.function =
>> 1838 ahc_linux_release_simq;
>> 1839 add_timer(&ahc->platform_data->reset_timer);
1147 } 1840 }
1148 } 1841 }
1149 1842
1150 int 1843 int
1151 ahc_platform_alloc(struct ahc_softc *ahc, voi 1844 ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
1152 { 1845 {
1153 1846
1154 ahc->platform_data = 1847 ahc->platform_data =
1155 malloc(sizeof(struct ahc_platform 1848 malloc(sizeof(struct ahc_platform_data), M_DEVBUF, M_NOWAIT);
1156 if (ahc->platform_data == NULL) 1849 if (ahc->platform_data == NULL)
1157 return (ENOMEM); 1850 return (ENOMEM);
1158 memset(ahc->platform_data, 0, sizeof( 1851 memset(ahc->platform_data, 0, sizeof(struct ahc_platform_data));
>> 1852 TAILQ_INIT(&ahc->platform_data->completeq);
>> 1853 TAILQ_INIT(&ahc->platform_data->device_runq);
1159 ahc->platform_data->irq = AHC_LINUX_N 1854 ahc->platform_data->irq = AHC_LINUX_NOIRQ;
>> 1855 ahc->platform_data->hw_dma_mask = 0xFFFFFFFF;
1160 ahc_lockinit(ahc); 1856 ahc_lockinit(ahc);
>> 1857 ahc_done_lockinit(ahc);
>> 1858 init_timer(&ahc->platform_data->completeq_timer);
>> 1859 ahc->platform_data->completeq_timer.data = (u_long)ahc;
>> 1860 ahc->platform_data->completeq_timer.function =
>> 1861 (ahc_linux_callback_t *)ahc_linux_thread_run_complete_queue;
>> 1862 init_MUTEX_LOCKED(&ahc->platform_data->eh_sem);
>> 1863 init_MUTEX_LOCKED(&ahc->platform_data->dv_sem);
>> 1864 init_MUTEX_LOCKED(&ahc->platform_data->dv_cmd_sem);
>> 1865 tasklet_init(&ahc->platform_data->runq_tasklet, ahc_runq_tasklet,
>> 1866 (unsigned long)ahc);
1161 ahc->seltime = (aic7xxx_seltime & 0x3 1867 ahc->seltime = (aic7xxx_seltime & 0x3) << 4;
1162 ahc->seltime_b = (aic7xxx_seltime & 0 1868 ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4;
1163 if (aic7xxx_pci_parity == 0) 1869 if (aic7xxx_pci_parity == 0)
1164 ahc->flags |= AHC_DISABLE_PCI 1870 ahc->flags |= AHC_DISABLE_PCI_PERR;
1165 1871
1166 return (0); 1872 return (0);
1167 } 1873 }
1168 1874
1169 void 1875 void
1170 ahc_platform_free(struct ahc_softc *ahc) 1876 ahc_platform_free(struct ahc_softc *ahc)
1171 { 1877 {
1172 struct scsi_target *starget; !! 1878 struct ahc_linux_target *targ;
1173 int i; !! 1879 struct ahc_linux_device *dev;
>> 1880 int i, j;
1174 1881
1175 if (ahc->platform_data != NULL) { 1882 if (ahc->platform_data != NULL) {
>> 1883 del_timer_sync(&ahc->platform_data->completeq_timer);
>> 1884 ahc_linux_kill_dv_thread(ahc);
>> 1885 tasklet_kill(&ahc->platform_data->runq_tasklet);
>> 1886 if (ahc->platform_data->host != NULL) {
>> 1887 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
>> 1888 scsi_remove_host(ahc->platform_data->host);
>> 1889 #endif
>> 1890 scsi_host_put(ahc->platform_data->host);
>> 1891 }
>> 1892
1176 /* destroy all of the device 1893 /* destroy all of the device and target objects */
1177 for (i = 0; i < AHC_NUM_TARGE 1894 for (i = 0; i < AHC_NUM_TARGETS; i++) {
1178 starget = ahc->platfo !! 1895 targ = ahc->platform_data->targets[i];
1179 if (starget != NULL) !! 1896 if (targ != NULL) {
1180 ahc->platform !! 1897 /* Keep target around through the loop. */
>> 1898 targ->refcount++;
>> 1899 for (j = 0; j < AHC_NUM_LUNS; j++) {
>> 1900
>> 1901 if (targ->devices[j] == NULL)
>> 1902 continue;
>> 1903 dev = targ->devices[j];
>> 1904 ahc_linux_free_device(ahc, dev);
>> 1905 }
>> 1906 /*
>> 1907 * Forcibly free the target now that
>> 1908 * all devices are gone.
>> 1909 */
>> 1910 ahc_linux_free_target(ahc, targ);
1181 } 1911 }
1182 } 1912 }
1183 1913
1184 if (ahc->platform_data->irq ! 1914 if (ahc->platform_data->irq != AHC_LINUX_NOIRQ)
1185 free_irq(ahc->platfor 1915 free_irq(ahc->platform_data->irq, ahc);
1186 if (ahc->tag == BUS_SPACE_PIO 1916 if (ahc->tag == BUS_SPACE_PIO
1187 && ahc->bsh.ioport != 0) 1917 && ahc->bsh.ioport != 0)
1188 release_region(ahc->b 1918 release_region(ahc->bsh.ioport, 256);
1189 if (ahc->tag == BUS_SPACE_MEM 1919 if (ahc->tag == BUS_SPACE_MEMIO
1190 && ahc->bsh.maddr != NULL) { 1920 && ahc->bsh.maddr != NULL) {
1191 iounmap(ahc->bsh.madd 1921 iounmap(ahc->bsh.maddr);
1192 release_mem_region(ah 1922 release_mem_region(ahc->platform_data->mem_busaddr,
1193 0x 1923 0x1000);
1194 } 1924 }
1195 !! 1925 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1196 if (ahc->platform_data->host) !! 1926 /*
1197 scsi_host_put(ahc->pl !! 1927 * In 2.4 we detach from the scsi midlayer before the PCI
1198 !! 1928 * layer invokes our remove callback. No per-instance
>> 1929 * detach is provided, so we must reach inside the PCI
>> 1930 * subsystem's internals and detach our driver manually.
>> 1931 */
>> 1932 if (ahc->dev_softc != NULL)
>> 1933 ahc->dev_softc->driver = NULL;
>> 1934 #endif
1199 free(ahc->platform_data, M_DE 1935 free(ahc->platform_data, M_DEVBUF);
1200 } 1936 }
1201 } 1937 }
1202 1938
1203 void 1939 void
1204 ahc_platform_freeze_devq(struct ahc_softc *ah 1940 ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
1205 { 1941 {
1206 ahc_platform_abort_scbs(ahc, SCB_GET_ 1942 ahc_platform_abort_scbs(ahc, SCB_GET_TARGET(ahc, scb),
1207 SCB_GET_CHANN 1943 SCB_GET_CHANNEL(ahc, scb),
1208 SCB_GET_LUN(s 1944 SCB_GET_LUN(scb), SCB_LIST_NULL,
1209 ROLE_UNKNOWN, 1945 ROLE_UNKNOWN, CAM_REQUEUE_REQ);
1210 } 1946 }
1211 1947
1212 void 1948 void
1213 ahc_platform_set_tags(struct ahc_softc *ahc, !! 1949 ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1214 struct ahc_devinfo *dev !! 1950 ahc_queue_alg alg)
1215 { 1951 {
1216 struct ahc_linux_device *dev; 1952 struct ahc_linux_device *dev;
1217 int was_queuing; 1953 int was_queuing;
1218 int now_queuing; 1954 int now_queuing;
1219 1955
1220 if (sdev == NULL) !! 1956 dev = ahc_linux_get_device(ahc, devinfo->channel - 'A',
>> 1957 devinfo->target,
>> 1958 devinfo->lun, /*alloc*/FALSE);
>> 1959 if (dev == NULL)
1221 return; 1960 return;
1222 dev = scsi_transport_device_data(sdev <<
1223 <<
1224 was_queuing = dev->flags & (AHC_DEV_Q 1961 was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED);
1225 switch (alg) { 1962 switch (alg) {
1226 default: 1963 default:
1227 case AHC_QUEUE_NONE: 1964 case AHC_QUEUE_NONE:
1228 now_queuing = 0; 1965 now_queuing = 0;
1229 break; 1966 break;
1230 case AHC_QUEUE_BASIC: 1967 case AHC_QUEUE_BASIC:
1231 now_queuing = AHC_DEV_Q_BASIC 1968 now_queuing = AHC_DEV_Q_BASIC;
1232 break; 1969 break;
1233 case AHC_QUEUE_TAGGED: 1970 case AHC_QUEUE_TAGGED:
1234 now_queuing = AHC_DEV_Q_TAGGE 1971 now_queuing = AHC_DEV_Q_TAGGED;
1235 break; 1972 break;
1236 } 1973 }
1237 if ((dev->flags & AHC_DEV_FREEZE_TIL_ 1974 if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) == 0
1238 && (was_queuing != now_queuing) 1975 && (was_queuing != now_queuing)
1239 && (dev->active != 0)) { 1976 && (dev->active != 0)) {
1240 dev->flags |= AHC_DEV_FREEZE_ 1977 dev->flags |= AHC_DEV_FREEZE_TIL_EMPTY;
1241 dev->qfrozen++; 1978 dev->qfrozen++;
1242 } 1979 }
1243 1980
1244 dev->flags &= ~(AHC_DEV_Q_BASIC|AHC_D 1981 dev->flags &= ~(AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED|AHC_DEV_PERIODIC_OTAG);
1245 if (now_queuing) { 1982 if (now_queuing) {
1246 u_int usertags; 1983 u_int usertags;
1247 1984
1248 usertags = ahc_linux_user_tag 1985 usertags = ahc_linux_user_tagdepth(ahc, devinfo);
1249 if (!was_queuing) { 1986 if (!was_queuing) {
1250 /* 1987 /*
1251 * Start out agressiv 1988 * Start out agressively and allow our
1252 * dynamic queue dept 1989 * dynamic queue depth algorithm to take
1253 * care of the rest. 1990 * care of the rest.
1254 */ 1991 */
1255 dev->maxtags = userta 1992 dev->maxtags = usertags;
1256 dev->openings = dev-> 1993 dev->openings = dev->maxtags - dev->active;
1257 } 1994 }
1258 if (dev->maxtags == 0) { 1995 if (dev->maxtags == 0) {
1259 /* 1996 /*
1260 * Queueing is disabl 1997 * Queueing is disabled by the user.
1261 */ 1998 */
1262 dev->openings = 1; 1999 dev->openings = 1;
1263 } else if (alg == AHC_QUEUE_T 2000 } else if (alg == AHC_QUEUE_TAGGED) {
1264 dev->flags |= AHC_DEV 2001 dev->flags |= AHC_DEV_Q_TAGGED;
1265 if (aic7xxx_periodic_ 2002 if (aic7xxx_periodic_otag != 0)
1266 dev->flags |= 2003 dev->flags |= AHC_DEV_PERIODIC_OTAG;
1267 } else 2004 } else
1268 dev->flags |= AHC_DEV 2005 dev->flags |= AHC_DEV_Q_BASIC;
1269 } else { 2006 } else {
1270 /* We can only have one openi 2007 /* We can only have one opening. */
1271 dev->maxtags = 0; 2008 dev->maxtags = 0;
1272 dev->openings = 1 - dev->act 2009 dev->openings = 1 - dev->active;
1273 } 2010 }
1274 switch ((dev->flags & (AHC_DEV_Q_BASI !! 2011 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1275 case AHC_DEV_Q_BASIC: !! 2012 if (dev->scsi_device != NULL) {
1276 scsi_set_tag_type(sdev, MSG_S !! 2013 switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) {
1277 scsi_activate_tcq(sdev, dev-> !! 2014 case AHC_DEV_Q_BASIC:
1278 break; !! 2015 scsi_adjust_queue_depth(dev->scsi_device,
1279 case AHC_DEV_Q_TAGGED: !! 2016 MSG_SIMPLE_TASK,
1280 scsi_set_tag_type(sdev, MSG_O !! 2017 dev->openings + dev->active);
1281 scsi_activate_tcq(sdev, dev-> !! 2018 break;
1282 break; !! 2019 case AHC_DEV_Q_TAGGED:
1283 default: !! 2020 scsi_adjust_queue_depth(dev->scsi_device,
1284 /* !! 2021 MSG_ORDERED_TASK,
1285 * We allow the OS to queue 2 !! 2022 dev->openings + dev->active);
1286 * us at any time even though !! 2023 break;
1287 * serially on the controller !! 2024 default:
1288 * remove some latency. !! 2025 /*
1289 */ !! 2026 * We allow the OS to queue 2 untagged transactions to
1290 scsi_deactivate_tcq(sdev, 2); !! 2027 * us at any time even though we can only execute them
1291 break; !! 2028 * serially on the controller/device. This should
>> 2029 * remove some latency.
>> 2030 */
>> 2031 scsi_adjust_queue_depth(dev->scsi_device,
>> 2032 /*NON-TAGGED*/0,
>> 2033 /*queue depth*/2);
>> 2034 break;
>> 2035 }
1292 } 2036 }
>> 2037 #endif
1293 } 2038 }
1294 2039
1295 int 2040 int
1296 ahc_platform_abort_scbs(struct ahc_softc *ahc 2041 ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, char channel,
1297 int lun, u_int tag, r 2042 int lun, u_int tag, role_t role, uint32_t status)
1298 { 2043 {
1299 return 0; !! 2044 int chan;
>> 2045 int maxchan;
>> 2046 int targ;
>> 2047 int maxtarg;
>> 2048 int clun;
>> 2049 int maxlun;
>> 2050 int count;
>> 2051
>> 2052 if (tag != SCB_LIST_NULL)
>> 2053 return (0);
>> 2054
>> 2055 chan = 0;
>> 2056 if (channel != ALL_CHANNELS) {
>> 2057 chan = channel - 'A';
>> 2058 maxchan = chan + 1;
>> 2059 } else {
>> 2060 maxchan = (ahc->features & AHC_TWIN) ? 2 : 1;
>> 2061 }
>> 2062 targ = 0;
>> 2063 if (target != CAM_TARGET_WILDCARD) {
>> 2064 targ = target;
>> 2065 maxtarg = targ + 1;
>> 2066 } else {
>> 2067 maxtarg = (ahc->features & AHC_WIDE) ? 16 : 8;
>> 2068 }
>> 2069 clun = 0;
>> 2070 if (lun != CAM_LUN_WILDCARD) {
>> 2071 clun = lun;
>> 2072 maxlun = clun + 1;
>> 2073 } else {
>> 2074 maxlun = AHC_NUM_LUNS;
>> 2075 }
>> 2076
>> 2077 count = 0;
>> 2078 for (; chan < maxchan; chan++) {
>> 2079
>> 2080 for (; targ < maxtarg; targ++) {
>> 2081
>> 2082 for (; clun < maxlun; clun++) {
>> 2083 struct ahc_linux_device *dev;
>> 2084 struct ahc_busyq *busyq;
>> 2085 struct ahc_cmd *acmd;
>> 2086
>> 2087 dev = ahc_linux_get_device(ahc, chan,
>> 2088 targ, clun,
>> 2089 /*alloc*/FALSE);
>> 2090 if (dev == NULL)
>> 2091 continue;
>> 2092
>> 2093 busyq = &dev->busyq;
>> 2094 while ((acmd = TAILQ_FIRST(busyq)) != NULL) {
>> 2095 Scsi_Cmnd *cmd;
>> 2096
>> 2097 cmd = &acmd_scsi_cmd(acmd);
>> 2098 TAILQ_REMOVE(busyq, acmd,
>> 2099 acmd_links.tqe);
>> 2100 count++;
>> 2101 cmd->result = status << 16;
>> 2102 ahc_linux_queue_cmd_complete(ahc, cmd);
>> 2103 }
>> 2104 }
>> 2105 }
>> 2106 }
>> 2107
>> 2108 return (count);
1300 } 2109 }
1301 2110
1302 static u_int !! 2111 static void
1303 ahc_linux_user_tagdepth(struct ahc_softc *ahc !! 2112 ahc_linux_thread_run_complete_queue(struct ahc_softc *ahc)
1304 { 2113 {
1305 static int warned_user; !! 2114 u_long flags;
1306 u_int tags; <<
1307 2115
1308 tags = 0; !! 2116 ahc_lock(ahc, &flags);
1309 if ((ahc->user_discenable & devinfo-> !! 2117 del_timer(&ahc->platform_data->completeq_timer);
1310 if (ahc->unit >= ARRAY_SIZE(a !! 2118 ahc->platform_data->flags &= ~AHC_RUN_CMPLT_Q_TIMER;
1311 if (warned_user == 0) !! 2119 ahc_linux_run_complete_queue(ahc);
>> 2120 ahc_unlock(ahc, &flags);
>> 2121 }
1312 2122
1313 printf(KERN_W !! 2123 static void
1314 "aic7xxx: WARNING: Insufficient tag_info inst !! 2124 ahc_linux_start_dv(struct ahc_softc *ahc)
1315 "aic7xxx: for installed controllers. Using de !! 2125 {
1316 "aic7xxx: Please update the aic7xxx_tag_info <<
1317 "aic7xxx: the aic7xxx_osm..c source file.\n") <<
1318 warned_user++ <<
1319 } <<
1320 tags = AHC_MAX_QUEUE; <<
1321 } else { <<
1322 adapter_tag_info_t *t <<
1323 2126
1324 tag_info = &aic7xxx_t !! 2127 /*
1325 tags = tag_info->tag_ !! 2128 * Freeze the simq and signal ahc_linux_queue to not let any
1326 if (tags > AHC_MAX_QU !! 2129 * more commands through.
1327 tags = AHC_MA !! 2130 */
1328 } !! 2131 if ((ahc->platform_data->flags & AHC_DV_ACTIVE) == 0) {
>> 2132 #ifdef AHC_DEBUG
>> 2133 if (ahc_debug & AHC_SHOW_DV)
>> 2134 printf("%s: Waking DV thread\n", ahc_name(ahc));
>> 2135 #endif
>> 2136
>> 2137 ahc->platform_data->flags |= AHC_DV_ACTIVE;
>> 2138 ahc_linux_freeze_simq(ahc);
>> 2139
>> 2140 /* Wake up the DV kthread */
>> 2141 up(&ahc->platform_data->dv_sem);
1329 } 2142 }
1330 return (tags); <<
1331 } 2143 }
1332 2144
1333 /* <<
1334 * Determines the queue depth for a given dev <<
1335 */ <<
1336 static void 2145 static void
1337 ahc_linux_device_queue_depth(struct scsi_devi !! 2146 ahc_linux_kill_dv_thread(struct ahc_softc *ahc)
1338 { 2147 {
1339 struct ahc_devinfo devinfo; !! 2148 u_long s;
1340 u_int tags; <<
1341 struct ahc_softc *ahc = *((struct ahc <<
1342 2149
1343 ahc_compile_devinfo(&devinfo, !! 2150 ahc_lock(ahc, &s);
1344 sdev->sdev_target !! 2151 if (ahc->platform_data->dv_pid != 0) {
1345 ? ahc->our_id : ahc !! 2152 ahc->platform_data->flags |= AHC_DV_SHUTDOWN;
1346 sdev->sdev_target !! 2153 ahc_unlock(ahc, &s);
1347 sdev->sdev_target !! 2154 up(&ahc->platform_data->dv_sem);
1348 ROLE_INITIATOR); <<
1349 tags = ahc_linux_user_tagdepth(ahc, & <<
1350 if (tags != 0 && sdev->tagged_support <<
1351 2155
1352 ahc_platform_set_tags(ahc, sd !! 2156 /*
1353 ahc_send_async(ahc, devinfo.c !! 2157 * Use the eh_sem as an indicator that the
1354 devinfo.lun, A !! 2158 * dv thread is exiting. Note that the dv
1355 ahc_print_devinfo(ahc, &devin !! 2159 * thread must still return after performing
1356 printf("Tagged Queuing enable !! 2160 * the up on our semaphore before it has
>> 2161 * completely exited this module. Unfortunately,
>> 2162 * there seems to be no easy way to wait for the
>> 2163 * exit of a thread for which you are not the
>> 2164 * parent (dv threads are parented by init).
>> 2165 * Cross your fingers...
>> 2166 */
>> 2167 down(&ahc->platform_data->eh_sem);
>> 2168
>> 2169 /*
>> 2170 * Mark the dv thread as already dead. This
>> 2171 * avoids attempting to kill it a second time.
>> 2172 * This is necessary because we must kill the
>> 2173 * DV thread before calling ahc_free() in the
>> 2174 * module shutdown case to avoid bogus locking
>> 2175 * in the SCSI mid-layer, but we ahc_free() is
>> 2176 * called without killing the DV thread in the
>> 2177 * instance detach case, so ahc_platform_free()
>> 2178 * calls us again to verify that the DV thread
>> 2179 * is dead.
>> 2180 */
>> 2181 ahc->platform_data->dv_pid = 0;
1357 } else { 2182 } else {
1358 ahc_platform_set_tags(ahc, sd !! 2183 ahc_unlock(ahc, &s);
1359 ahc_send_async(ahc, devinfo.c <<
1360 devinfo.lun, A <<
1361 } 2184 }
1362 } 2185 }
1363 2186
1364 static int 2187 static int
1365 ahc_linux_run_command(struct ahc_softc *ahc, !! 2188 ahc_linux_dv_thread(void *data)
1366 struct scsi_cmnd *cmd) <<
1367 { 2189 {
1368 struct scb *scb; !! 2190 struct ahc_softc *ahc;
1369 struct hardware_scb *hscb; !! 2191 int target;
1370 struct ahc_initiator_tinfo *tinfo; !! 2192 u_long s;
1371 struct ahc_tmode_tstate *tstate; !! 2193
1372 uint16_t mask; !! 2194 ahc = (struct ahc_softc *)data;
1373 struct scb_tailq *untagged_q = NULL; !! 2195
1374 int nseg; !! 2196 #ifdef AHC_DEBUG
>> 2197 if (ahc_debug & AHC_SHOW_DV)
>> 2198 printf("Launching DV Thread\n");
>> 2199 #endif
1375 2200
1376 /* 2201 /*
1377 * Schedule us to run later. The onl !! 2202 * Complete thread creation.
1378 * running is because the whole contr <<
1379 */ 2203 */
1380 if (ahc->platform_data->qfrozen != 0) !! 2204 lock_kernel();
1381 return SCSI_MLQUEUE_HOST_BUSY !! 2205 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1382 <<
1383 /* 2206 /*
1384 * We only allow one untagged transac !! 2207 * Don't care about any signals.
1385 * per target in the initiator role u <<
1386 * we are storing a full busy target <<
1387 * table in SCB space. <<
1388 */ 2208 */
1389 if (!blk_rq_tagged(cmd->request) !! 2209 siginitsetinv(¤t->blocked, 0);
1390 && (ahc->features & AHC_SCB_BTT) <<
1391 int target_offset; <<
1392 2210
1393 target_offset = cmd->device-> !! 2211 daemonize();
1394 untagged_q = &(ahc->untagged_ !! 2212 sprintf(current->comm, "ahc_dv_%d", ahc->unit);
1395 if (!TAILQ_EMPTY(untagged_q)) !! 2213 #else
1396 /* if we're already e !! 2214 daemonize("ahc_dv_%d", ahc->unit);
1397 * we're busy to anot !! 2215 current->flags |= PF_FREEZE;
1398 return SCSI_MLQUEUE_D !! 2216 #endif
1399 } !! 2217 unlock_kernel();
1400 2218
1401 /* !! 2219 while (1) {
1402 * Get an scb to use. !! 2220 /*
1403 */ !! 2221 * Use down_interruptible() rather than down() to
1404 scb = ahc_get_scb(ahc); !! 2222 * avoid inclusion in the load average.
1405 if (!scb) !! 2223 */
1406 return SCSI_MLQUEUE_HOST_BUSY !! 2224 down_interruptible(&ahc->platform_data->dv_sem);
1407 <<
1408 scb->io_ctx = cmd; <<
1409 scb->platform_data->dev = dev; <<
1410 hscb = scb->hscb; <<
1411 cmd->host_scribble = (char *)scb; <<
1412 <<
1413 /* <<
1414 * Fill out basics of the HSCB. <<
1415 */ <<
1416 hscb->control = 0; <<
1417 hscb->scsiid = BUILD_SCSIID(ahc, cmd) <<
1418 hscb->lun = cmd->device->lun; <<
1419 mask = SCB_GET_TARGET_MASK(ahc, scb); <<
1420 tinfo = ahc_fetch_transinfo(ahc, SCB_ <<
1421 SCB_GET_O <<
1422 SCB_GET_T <<
1423 hscb->scsirate = tinfo->scsirate; <<
1424 hscb->scsioffset = tinfo->curr.offset <<
1425 if ((tstate->ultraenb & mask) != 0) <<
1426 hscb->control |= ULTRAENB; <<
1427 <<
1428 if ((ahc->user_discenable & mask) != <<
1429 hscb->control |= DISCENB; <<
1430 <<
1431 if ((tstate->auto_negotiate & mask) ! <<
1432 scb->flags |= SCB_AUTO_NEGOTI <<
1433 scb->hscb->control |= MK_MESS <<
1434 } <<
1435 2225
1436 if ((dev->flags & (AHC_DEV_Q_TAGGED|A !! 2226 /* Check to see if we've been signaled to exit */
1437 int msg_bytes; !! 2227 ahc_lock(ahc, &s);
1438 uint8_t tag_msgs[2]; !! 2228 if ((ahc->platform_data->flags & AHC_DV_SHUTDOWN) != 0) {
1439 !! 2229 ahc_unlock(ahc, &s);
1440 msg_bytes = scsi_populate_tag !! 2230 break;
1441 if (msg_bytes && tag_msgs[0] <<
1442 hscb->control |= tag_ <<
1443 if (tag_msgs[0] == MS <<
1444 dev->commands <<
1445 } else if (dev->commands_sinc <<
1446 && (dev->flag <<
1447 hscb->control |= MSG_ <<
1448 dev->commands_since_i <<
1449 } else { <<
1450 hscb->control |= MSG_ <<
1451 } 2231 }
1452 } !! 2232 ahc_unlock(ahc, &s);
1453 2233
1454 hscb->cdb_len = cmd->cmd_len; !! 2234 #ifdef AHC_DEBUG
1455 if (hscb->cdb_len <= 12) { !! 2235 if (ahc_debug & AHC_SHOW_DV)
1456 memcpy(hscb->shared_data.cdb, !! 2236 printf("%s: Beginning Domain Validation\n",
1457 } else { !! 2237 ahc_name(ahc));
1458 memcpy(hscb->cdb32, cmd->cmnd !! 2238 #endif
1459 scb->flags |= SCB_CDB32_PTR; !! 2239
>> 2240 /*
>> 2241 * Wait for any pending commands to drain before proceeding.
>> 2242 */
>> 2243 ahc_lock(ahc, &s);
>> 2244 while (LIST_FIRST(&ahc->pending_scbs) != NULL) {
>> 2245 ahc->platform_data->flags |= AHC_DV_WAIT_SIMQ_EMPTY;
>> 2246 ahc_unlock(ahc, &s);
>> 2247 down_interruptible(&ahc->platform_data->dv_sem);
>> 2248 ahc_lock(ahc, &s);
>> 2249 }
>> 2250
>> 2251 /*
>> 2252 * Wait for the SIMQ to be released so that DV is the
>> 2253 * only reason the queue is frozen.
>> 2254 */
>> 2255 while (AHC_DV_SIMQ_FROZEN(ahc) == 0) {
>> 2256 ahc->platform_data->flags |= AHC_DV_WAIT_SIMQ_RELEASE;
>> 2257 ahc_unlock(ahc, &s);
>> 2258 down_interruptible(&ahc->platform_data->dv_sem);
>> 2259 ahc_lock(ahc, &s);
>> 2260 }
>> 2261 ahc_unlock(ahc, &s);
>> 2262
>> 2263 for (target = 0; target < AHC_NUM_TARGETS; target++)
>> 2264 ahc_linux_dv_target(ahc, target);
>> 2265
>> 2266 ahc_lock(ahc, &s);
>> 2267 ahc->platform_data->flags &= ~AHC_DV_ACTIVE;
>> 2268 ahc_unlock(ahc, &s);
>> 2269
>> 2270 /*
>> 2271 * Release the SIMQ so that normal commands are
>> 2272 * allowed to continue on the bus.
>> 2273 */
>> 2274 ahc_linux_release_simq((u_long)ahc);
1460 } 2275 }
>> 2276 up(&ahc->platform_data->eh_sem);
>> 2277 return (0);
>> 2278 }
1461 2279
1462 scb->platform_data->xfer_len = 0; !! 2280 #define AHC_LINUX_DV_INQ_SHORT_LEN 36
1463 ahc_set_residual(scb, 0); !! 2281 #define AHC_LINUX_DV_INQ_LEN 256
1464 ahc_set_sense_residual(scb, 0); !! 2282 #define AHC_LINUX_DV_TIMEOUT (HZ / 4)
1465 scb->sg_count = 0; <<
1466 2283
1467 nseg = scsi_dma_map(cmd); !! 2284 #define AHC_SET_DV_STATE(ahc, targ, newstate) \
1468 BUG_ON(nseg < 0); !! 2285 ahc_set_dv_state(ahc, targ, newstate, __LINE__)
1469 if (nseg > 0) { !! 2286
1470 struct ahc_dma_seg *sg; !! 2287 static __inline void
1471 struct scatterlist *cur_seg; !! 2288 ahc_set_dv_state(struct ahc_softc *ahc, struct ahc_linux_target *targ,
1472 int i; !! 2289 ahc_dv_state newstate, u_int line)
>> 2290 {
>> 2291 ahc_dv_state oldstate;
>> 2292
>> 2293 oldstate = targ->dv_state;
>> 2294 #ifdef AHC_DEBUG
>> 2295 if (ahc_debug & AHC_SHOW_DV)
>> 2296 printf("%s:%d: Going from state %d to state %d\n",
>> 2297 ahc_name(ahc), line, oldstate, newstate);
>> 2298 #endif
>> 2299
>> 2300 if (oldstate == newstate)
>> 2301 targ->dv_state_retry++;
>> 2302 else
>> 2303 targ->dv_state_retry = 0;
>> 2304 targ->dv_state = newstate;
>> 2305 }
>> 2306
>> 2307 static void
>> 2308 ahc_linux_dv_target(struct ahc_softc *ahc, u_int target_offset)
>> 2309 {
>> 2310 struct ahc_devinfo devinfo;
>> 2311 struct ahc_linux_target *targ;
>> 2312 struct scsi_cmnd *cmd;
>> 2313 struct scsi_device *scsi_dev;
>> 2314 struct scsi_sense_data *sense;
>> 2315 uint8_t *buffer;
>> 2316 u_long s;
>> 2317 u_int timeout;
>> 2318 int echo_size;
>> 2319
>> 2320 sense = NULL;
>> 2321 buffer = NULL;
>> 2322 echo_size = 0;
>> 2323 ahc_lock(ahc, &s);
>> 2324 targ = ahc->platform_data->targets[target_offset];
>> 2325 if (targ == NULL || (targ->flags & AHC_DV_REQUIRED) == 0) {
>> 2326 ahc_unlock(ahc, &s);
>> 2327 return;
>> 2328 }
>> 2329 ahc_compile_devinfo(&devinfo,
>> 2330 targ->channel == 0 ? ahc->our_id : ahc->our_id_b,
>> 2331 targ->target, /*lun*/0, targ->channel + 'A',
>> 2332 ROLE_INITIATOR);
>> 2333 #ifdef AHC_DEBUG
>> 2334 if (ahc_debug & AHC_SHOW_DV) {
>> 2335 ahc_print_devinfo(ahc, &devinfo);
>> 2336 printf("Performing DV\n");
>> 2337 }
>> 2338 #endif
>> 2339
>> 2340 ahc_unlock(ahc, &s);
>> 2341
>> 2342 cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK);
>> 2343 scsi_dev = malloc(sizeof(struct scsi_device), M_DEVBUF, M_WAITOK);
>> 2344 scsi_dev->host = ahc->platform_data->host;
>> 2345 scsi_dev->id = devinfo.target;
>> 2346 scsi_dev->lun = devinfo.lun;
>> 2347 scsi_dev->channel = devinfo.channel - 'A';
>> 2348 ahc->platform_data->dv_scsi_dev = scsi_dev;
>> 2349
>> 2350 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_INQ_SHORT_ASYNC);
>> 2351
>> 2352 while (targ->dv_state != AHC_DV_STATE_EXIT) {
>> 2353 timeout = AHC_LINUX_DV_TIMEOUT;
>> 2354 switch (targ->dv_state) {
>> 2355 case AHC_DV_STATE_INQ_SHORT_ASYNC:
>> 2356 case AHC_DV_STATE_INQ_ASYNC:
>> 2357 case AHC_DV_STATE_INQ_ASYNC_VERIFY:
>> 2358 /*
>> 2359 * Set things to async narrow to reduce the
>> 2360 * chance that the INQ will fail.
>> 2361 */
>> 2362 ahc_lock(ahc, &s);
>> 2363 ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0,
>> 2364 AHC_TRANS_GOAL, /*paused*/FALSE);
>> 2365 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
>> 2366 AHC_TRANS_GOAL, /*paused*/FALSE);
>> 2367 ahc_unlock(ahc, &s);
>> 2368 timeout = 10 * HZ;
>> 2369 targ->flags &= ~AHC_INQ_VALID;
>> 2370 /* FALLTHROUGH */
>> 2371 case AHC_DV_STATE_INQ_VERIFY:
>> 2372 {
>> 2373 u_int inq_len;
>> 2374
>> 2375 if (targ->dv_state == AHC_DV_STATE_INQ_SHORT_ASYNC)
>> 2376 inq_len = AHC_LINUX_DV_INQ_SHORT_LEN;
>> 2377 else
>> 2378 inq_len = targ->inq_data->additional_length + 5;
>> 2379 ahc_linux_dv_inq(ahc, cmd, &devinfo, targ, inq_len);
>> 2380 break;
>> 2381 }
>> 2382 case AHC_DV_STATE_TUR:
>> 2383 case AHC_DV_STATE_BUSY:
>> 2384 timeout = 5 * HZ;
>> 2385 ahc_linux_dv_tur(ahc, cmd, &devinfo);
>> 2386 break;
>> 2387 case AHC_DV_STATE_REBD:
>> 2388 ahc_linux_dv_rebd(ahc, cmd, &devinfo, targ);
>> 2389 break;
>> 2390 case AHC_DV_STATE_WEB:
>> 2391 ahc_linux_dv_web(ahc, cmd, &devinfo, targ);
>> 2392 break;
>> 2393
>> 2394 case AHC_DV_STATE_REB:
>> 2395 ahc_linux_dv_reb(ahc, cmd, &devinfo, targ);
>> 2396 break;
>> 2397
>> 2398 case AHC_DV_STATE_SU:
>> 2399 ahc_linux_dv_su(ahc, cmd, &devinfo, targ);
>> 2400 timeout = 50 * HZ;
>> 2401 break;
>> 2402
>> 2403 default:
>> 2404 ahc_print_devinfo(ahc, &devinfo);
>> 2405 printf("Unknown DV state %d\n", targ->dv_state);
>> 2406 goto out;
>> 2407 }
>> 2408
>> 2409 /* Queue the command and wait for it to complete */
>> 2410 /* Abuse eh_timeout in the scsi_cmnd struct for our purposes */
>> 2411 init_timer(&cmd->eh_timeout);
>> 2412 #ifdef AHC_DEBUG
>> 2413 if ((ahc_debug & AHC_SHOW_MESSAGES) != 0)
>> 2414 /*
>> 2415 * All of the printfs during negotiation
>> 2416 * really slow down the negotiation.
>> 2417 * Add a bit of time just to be safe.
>> 2418 */
>> 2419 timeout += HZ;
>> 2420 #endif
>> 2421 scsi_add_timer(cmd, timeout, ahc_linux_dv_timeout);
>> 2422 /*
>> 2423 * In 2.5.X, it is assumed that all calls from the
>> 2424 * "midlayer" (which we are emulating) will have the
>> 2425 * ahc host lock held. For other kernels, the
>> 2426 * io_request_lock must be held.
>> 2427 */
>> 2428 #if AHC_SCSI_HAS_HOST_LOCK != 0
>> 2429 ahc_lock(ahc, &s);
>> 2430 #else
>> 2431 spin_lock_irqsave(&io_request_lock, s);
>> 2432 #endif
>> 2433 ahc_linux_queue(cmd, ahc_linux_dv_complete);
>> 2434 #if AHC_SCSI_HAS_HOST_LOCK != 0
>> 2435 ahc_unlock(ahc, &s);
>> 2436 #else
>> 2437 spin_unlock_irqrestore(&io_request_lock, s);
>> 2438 #endif
>> 2439 down_interruptible(&ahc->platform_data->dv_cmd_sem);
>> 2440 /*
>> 2441 * Wait for the SIMQ to be released so that DV is the
>> 2442 * only reason the queue is frozen.
>> 2443 */
>> 2444 ahc_lock(ahc, &s);
>> 2445 while (AHC_DV_SIMQ_FROZEN(ahc) == 0) {
>> 2446 ahc->platform_data->flags |= AHC_DV_WAIT_SIMQ_RELEASE;
>> 2447 ahc_unlock(ahc, &s);
>> 2448 down_interruptible(&ahc->platform_data->dv_sem);
>> 2449 ahc_lock(ahc, &s);
>> 2450 }
>> 2451 ahc_unlock(ahc, &s);
>> 2452
>> 2453 ahc_linux_dv_transition(ahc, cmd, &devinfo, targ);
>> 2454 }
>> 2455
>> 2456 out:
>> 2457 if ((targ->flags & AHC_INQ_VALID) != 0
>> 2458 && ahc_linux_get_device(ahc, devinfo.channel - 'A',
>> 2459 devinfo.target, devinfo.lun,
>> 2460 /*alloc*/FALSE) == NULL) {
>> 2461 /*
>> 2462 * The DV state machine failed to configure this device.
>> 2463 * This is normal if DV is disabled. Since we have inquiry
>> 2464 * data, filter it and use the "optimistic" negotiation
>> 2465 * parameters found in the inquiry string.
>> 2466 */
>> 2467 ahc_linux_filter_inquiry(ahc, &devinfo);
>> 2468 if ((targ->flags & (AHC_BASIC_DV|AHC_ENHANCED_DV)) != 0) {
>> 2469 ahc_print_devinfo(ahc, &devinfo);
>> 2470 printf("DV failed to configure device. "
>> 2471 "Please file a bug report against "
>> 2472 "this driver.\n");
>> 2473 }
>> 2474 }
>> 2475
>> 2476 if (cmd != NULL)
>> 2477 free(cmd, M_DEVBUF);
>> 2478
>> 2479 if (ahc->platform_data->dv_scsi_dev != NULL) {
>> 2480 free(ahc->platform_data->dv_scsi_dev, M_DEVBUF);
>> 2481 ahc->platform_data->dv_scsi_dev = NULL;
>> 2482 }
>> 2483
>> 2484 ahc_lock(ahc, &s);
>> 2485 if (targ->dv_buffer != NULL) {
>> 2486 free(targ->dv_buffer, M_DEVBUF);
>> 2487 targ->dv_buffer = NULL;
>> 2488 }
>> 2489 if (targ->dv_buffer1 != NULL) {
>> 2490 free(targ->dv_buffer1, M_DEVBUF);
>> 2491 targ->dv_buffer1 = NULL;
>> 2492 }
>> 2493 targ->flags &= ~AHC_DV_REQUIRED;
>> 2494 if (targ->refcount == 0)
>> 2495 ahc_linux_free_target(ahc, targ);
>> 2496 ahc_unlock(ahc, &s);
>> 2497 }
>> 2498
>> 2499 static void
>> 2500 ahc_linux_dv_transition(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
>> 2501 struct ahc_devinfo *devinfo,
>> 2502 struct ahc_linux_target *targ)
>> 2503 {
>> 2504 u_int32_t status;
>> 2505
>> 2506 status = aic_error_action(cmd, targ->inq_data,
>> 2507 ahc_cmd_get_transaction_status(cmd),
>> 2508 ahc_cmd_get_scsi_status(cmd));
>> 2509
>> 2510 #ifdef AHC_DEBUG
>> 2511 if (ahc_debug & AHC_SHOW_DV) {
>> 2512 ahc_print_devinfo(ahc, devinfo);
>> 2513 printf("Entering ahc_linux_dv_transition, state= %d, "
>> 2514 "status= 0x%x, cmd->result= 0x%x\n", targ->dv_state,
>> 2515 status, cmd->result);
>> 2516 }
>> 2517 #endif
>> 2518
>> 2519 switch (targ->dv_state) {
>> 2520 case AHC_DV_STATE_INQ_SHORT_ASYNC:
>> 2521 case AHC_DV_STATE_INQ_ASYNC:
>> 2522 switch (status & SS_MASK) {
>> 2523 case SS_NOP:
>> 2524 {
>> 2525 AHC_SET_DV_STATE(ahc, targ, targ->dv_state+1);
>> 2526 break;
>> 2527 }
>> 2528 case SS_INQ_REFRESH:
>> 2529 AHC_SET_DV_STATE(ahc, targ,
>> 2530 AHC_DV_STATE_INQ_SHORT_ASYNC);
>> 2531 break;
>> 2532 case SS_TUR:
>> 2533 case SS_RETRY:
>> 2534 AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
>> 2535 if (ahc_cmd_get_transaction_status(cmd)
>> 2536 == CAM_REQUEUE_REQ)
>> 2537 targ->dv_state_retry--;
>> 2538 if ((status & SS_ERRMASK) == EBUSY)
>> 2539 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY);
>> 2540 if (targ->dv_state_retry < 10)
>> 2541 break;
>> 2542 /* FALLTHROUGH */
>> 2543 default:
>> 2544 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2545 #ifdef AHC_DEBUG
>> 2546 if (ahc_debug & AHC_SHOW_DV) {
>> 2547 ahc_print_devinfo(ahc, devinfo);
>> 2548 printf("Failed DV inquiry, skipping\n");
>> 2549 }
>> 2550 #endif
>> 2551 break;
>> 2552 }
>> 2553 break;
>> 2554 case AHC_DV_STATE_INQ_ASYNC_VERIFY:
>> 2555 switch (status & SS_MASK) {
>> 2556 case SS_NOP:
>> 2557 {
>> 2558 u_int xportflags;
>> 2559 u_int spi3data;
>> 2560
>> 2561 if (memcmp(targ->inq_data, targ->dv_buffer,
>> 2562 AHC_LINUX_DV_INQ_LEN) != 0) {
>> 2563 /*
>> 2564 * Inquiry data must have changed.
>> 2565 * Try from the top again.
>> 2566 */
>> 2567 AHC_SET_DV_STATE(ahc, targ,
>> 2568 AHC_DV_STATE_INQ_SHORT_ASYNC);
>> 2569 break;
>> 2570 }
>> 2571
>> 2572 AHC_SET_DV_STATE(ahc, targ, targ->dv_state+1);
>> 2573 targ->flags |= AHC_INQ_VALID;
>> 2574 if (ahc_linux_user_dv_setting(ahc) == 0)
>> 2575 break;
>> 2576
>> 2577 xportflags = targ->inq_data->flags;
>> 2578 if ((xportflags & (SID_Sync|SID_WBus16)) == 0)
>> 2579 break;
>> 2580
>> 2581 spi3data = targ->inq_data->spi3data;
>> 2582 switch (spi3data & SID_SPI_CLOCK_DT_ST) {
>> 2583 default:
>> 2584 case SID_SPI_CLOCK_ST:
>> 2585 /* Assume only basic DV is supported. */
>> 2586 targ->flags |= AHC_BASIC_DV;
>> 2587 break;
>> 2588 case SID_SPI_CLOCK_DT:
>> 2589 case SID_SPI_CLOCK_DT_ST:
>> 2590 targ->flags |= AHC_ENHANCED_DV;
>> 2591 break;
>> 2592 }
>> 2593 break;
>> 2594 }
>> 2595 case SS_INQ_REFRESH:
>> 2596 AHC_SET_DV_STATE(ahc, targ,
>> 2597 AHC_DV_STATE_INQ_SHORT_ASYNC);
>> 2598 break;
>> 2599 case SS_TUR:
>> 2600 case SS_RETRY:
>> 2601 AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
>> 2602 if (ahc_cmd_get_transaction_status(cmd)
>> 2603 == CAM_REQUEUE_REQ)
>> 2604 targ->dv_state_retry--;
>> 2605
>> 2606 if ((status & SS_ERRMASK) == EBUSY)
>> 2607 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY);
>> 2608 if (targ->dv_state_retry < 10)
>> 2609 break;
>> 2610 /* FALLTHROUGH */
>> 2611 default:
>> 2612 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2613 #ifdef AHC_DEBUG
>> 2614 if (ahc_debug & AHC_SHOW_DV) {
>> 2615 ahc_print_devinfo(ahc, devinfo);
>> 2616 printf("Failed DV inquiry, skipping\n");
>> 2617 }
>> 2618 #endif
>> 2619 break;
>> 2620 }
>> 2621 break;
>> 2622 case AHC_DV_STATE_INQ_VERIFY:
>> 2623 switch (status & SS_MASK) {
>> 2624 case SS_NOP:
>> 2625 {
>> 2626
>> 2627 if (memcmp(targ->inq_data, targ->dv_buffer,
>> 2628 AHC_LINUX_DV_INQ_LEN) == 0) {
>> 2629 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2630 break;
>> 2631 }
>> 2632 #ifdef AHC_DEBUG
>> 2633 if (ahc_debug & AHC_SHOW_DV) {
>> 2634 int i;
>> 2635
>> 2636 ahc_print_devinfo(ahc, devinfo);
>> 2637 printf("Inquiry buffer mismatch:");
>> 2638 for (i = 0; i < AHC_LINUX_DV_INQ_LEN; i++) {
>> 2639 if ((i & 0xF) == 0)
>> 2640 printf("\n ");
>> 2641 printf("0x%x:0x0%x ",
>> 2642 ((uint8_t *)targ->inq_data)[i],
>> 2643 targ->dv_buffer[i]);
>> 2644 }
>> 2645 printf("\n");
>> 2646 }
>> 2647 #endif
>> 2648
>> 2649 if (ahc_linux_fallback(ahc, devinfo) != 0) {
>> 2650 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2651 break;
>> 2652 }
>> 2653 /*
>> 2654 * Do not count "falling back"
>> 2655 * against our retries.
>> 2656 */
>> 2657 targ->dv_state_retry = 0;
>> 2658 AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
>> 2659 break;
>> 2660 }
>> 2661 case SS_INQ_REFRESH:
>> 2662 AHC_SET_DV_STATE(ahc, targ,
>> 2663 AHC_DV_STATE_INQ_SHORT_ASYNC);
>> 2664 break;
>> 2665 case SS_TUR:
>> 2666 case SS_RETRY:
>> 2667 AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
>> 2668 if (ahc_cmd_get_transaction_status(cmd)
>> 2669 == CAM_REQUEUE_REQ) {
>> 2670 targ->dv_state_retry--;
>> 2671 } else if ((status & SSQ_FALLBACK) != 0) {
>> 2672 if (ahc_linux_fallback(ahc, devinfo) != 0) {
>> 2673 AHC_SET_DV_STATE(ahc, targ,
>> 2674 AHC_DV_STATE_EXIT);
>> 2675 break;
>> 2676 }
>> 2677 /*
>> 2678 * Do not count "falling back"
>> 2679 * against our retries.
>> 2680 */
>> 2681 targ->dv_state_retry = 0;
>> 2682 } else if ((status & SS_ERRMASK) == EBUSY)
>> 2683 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY);
>> 2684 if (targ->dv_state_retry < 10)
>> 2685 break;
>> 2686 /* FALLTHROUGH */
>> 2687 default:
>> 2688 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2689 #ifdef AHC_DEBUG
>> 2690 if (ahc_debug & AHC_SHOW_DV) {
>> 2691 ahc_print_devinfo(ahc, devinfo);
>> 2692 printf("Failed DV inquiry, skipping\n");
>> 2693 }
>> 2694 #endif
>> 2695 break;
>> 2696 }
>> 2697 break;
>> 2698
>> 2699 case AHC_DV_STATE_TUR:
>> 2700 switch (status & SS_MASK) {
>> 2701 case SS_NOP:
>> 2702 if ((targ->flags & AHC_BASIC_DV) != 0) {
>> 2703 ahc_linux_filter_inquiry(ahc, devinfo);
>> 2704 AHC_SET_DV_STATE(ahc, targ,
>> 2705 AHC_DV_STATE_INQ_VERIFY);
>> 2706 } else if ((targ->flags & AHC_ENHANCED_DV) != 0) {
>> 2707 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_REBD);
>> 2708 } else {
>> 2709 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2710 }
>> 2711 break;
>> 2712 case SS_RETRY:
>> 2713 case SS_TUR:
>> 2714 if ((status & SS_ERRMASK) == EBUSY) {
>> 2715 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY);
>> 2716 break;
>> 2717 }
>> 2718 AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
>> 2719 if (ahc_cmd_get_transaction_status(cmd)
>> 2720 == CAM_REQUEUE_REQ) {
>> 2721 targ->dv_state_retry--;
>> 2722 } else if ((status & SSQ_FALLBACK) != 0) {
>> 2723 if (ahc_linux_fallback(ahc, devinfo) != 0) {
>> 2724 AHC_SET_DV_STATE(ahc, targ,
>> 2725 AHC_DV_STATE_EXIT);
>> 2726 break;
>> 2727 }
>> 2728 /*
>> 2729 * Do not count "falling back"
>> 2730 * against our retries.
>> 2731 */
>> 2732 targ->dv_state_retry = 0;
>> 2733 }
>> 2734 if (targ->dv_state_retry >= 10) {
>> 2735 #ifdef AHC_DEBUG
>> 2736 if (ahc_debug & AHC_SHOW_DV) {
>> 2737 ahc_print_devinfo(ahc, devinfo);
>> 2738 printf("DV TUR reties exhausted\n");
>> 2739 }
>> 2740 #endif
>> 2741 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2742 break;
>> 2743 }
>> 2744 if (status & SSQ_DELAY)
>> 2745 ssleep(1);
>> 2746
>> 2747 break;
>> 2748 case SS_START:
>> 2749 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_SU);
>> 2750 break;
>> 2751 case SS_INQ_REFRESH:
>> 2752 AHC_SET_DV_STATE(ahc, targ,
>> 2753 AHC_DV_STATE_INQ_SHORT_ASYNC);
>> 2754 break;
>> 2755 default:
>> 2756 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2757 break;
>> 2758 }
>> 2759 break;
>> 2760
>> 2761 case AHC_DV_STATE_REBD:
>> 2762 switch (status & SS_MASK) {
>> 2763 case SS_NOP:
>> 2764 {
>> 2765 uint32_t echo_size;
>> 2766
>> 2767 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_WEB);
>> 2768 echo_size = scsi_3btoul(&targ->dv_buffer[1]);
>> 2769 echo_size &= 0x1FFF;
>> 2770 #ifdef AHC_DEBUG
>> 2771 if (ahc_debug & AHC_SHOW_DV) {
>> 2772 ahc_print_devinfo(ahc, devinfo);
>> 2773 printf("Echo buffer size= %d\n", echo_size);
>> 2774 }
>> 2775 #endif
>> 2776 if (echo_size == 0) {
>> 2777 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2778 break;
>> 2779 }
>> 2780
>> 2781 /* Generate the buffer pattern */
>> 2782 targ->dv_echo_size = echo_size;
>> 2783 ahc_linux_generate_dv_pattern(targ);
>> 2784 /*
>> 2785 * Setup initial negotiation values.
>> 2786 */
>> 2787 ahc_linux_filter_inquiry(ahc, devinfo);
>> 2788 break;
>> 2789 }
>> 2790 case SS_INQ_REFRESH:
>> 2791 AHC_SET_DV_STATE(ahc, targ,
>> 2792 AHC_DV_STATE_INQ_SHORT_ASYNC);
>> 2793 break;
>> 2794 case SS_RETRY:
>> 2795 AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
>> 2796 if (ahc_cmd_get_transaction_status(cmd)
>> 2797 == CAM_REQUEUE_REQ)
>> 2798 targ->dv_state_retry--;
>> 2799 if (targ->dv_state_retry <= 10)
>> 2800 break;
>> 2801 #ifdef AHC_DEBUG
>> 2802 if (ahc_debug & AHC_SHOW_DV) {
>> 2803 ahc_print_devinfo(ahc, devinfo);
>> 2804 printf("DV REBD reties exhausted\n");
>> 2805 }
>> 2806 #endif
>> 2807 /* FALLTHROUGH */
>> 2808 case SS_FATAL:
>> 2809 default:
>> 2810 /*
>> 2811 * Setup initial negotiation values
>> 2812 * and try level 1 DV.
>> 2813 */
>> 2814 ahc_linux_filter_inquiry(ahc, devinfo);
>> 2815 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_INQ_VERIFY);
>> 2816 targ->dv_echo_size = 0;
>> 2817 break;
>> 2818 }
>> 2819 break;
>> 2820
>> 2821 case AHC_DV_STATE_WEB:
>> 2822 switch (status & SS_MASK) {
>> 2823 case SS_NOP:
>> 2824 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_REB);
>> 2825 break;
>> 2826 case SS_INQ_REFRESH:
>> 2827 AHC_SET_DV_STATE(ahc, targ,
>> 2828 AHC_DV_STATE_INQ_SHORT_ASYNC);
>> 2829 break;
>> 2830 case SS_RETRY:
>> 2831 AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
>> 2832 if (ahc_cmd_get_transaction_status(cmd)
>> 2833 == CAM_REQUEUE_REQ) {
>> 2834 targ->dv_state_retry--;
>> 2835 } else if ((status & SSQ_FALLBACK) != 0) {
>> 2836 if (ahc_linux_fallback(ahc, devinfo) != 0) {
>> 2837 AHC_SET_DV_STATE(ahc, targ,
>> 2838 AHC_DV_STATE_EXIT);
>> 2839 break;
>> 2840 }
>> 2841 /*
>> 2842 * Do not count "falling back"
>> 2843 * against our retries.
>> 2844 */
>> 2845 targ->dv_state_retry = 0;
>> 2846 }
>> 2847 if (targ->dv_state_retry <= 10)
>> 2848 break;
>> 2849 /* FALLTHROUGH */
>> 2850 #ifdef AHC_DEBUG
>> 2851 if (ahc_debug & AHC_SHOW_DV) {
>> 2852 ahc_print_devinfo(ahc, devinfo);
>> 2853 printf("DV WEB reties exhausted\n");
>> 2854 }
>> 2855 #endif
>> 2856 default:
>> 2857 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2858 break;
>> 2859 }
>> 2860 break;
>> 2861
>> 2862 case AHC_DV_STATE_REB:
>> 2863 switch (status & SS_MASK) {
>> 2864 case SS_NOP:
>> 2865 if (memcmp(targ->dv_buffer, targ->dv_buffer1,
>> 2866 targ->dv_echo_size) != 0) {
>> 2867 if (ahc_linux_fallback(ahc, devinfo) != 0)
>> 2868 AHC_SET_DV_STATE(ahc, targ,
>> 2869 AHC_DV_STATE_EXIT);
>> 2870 else
>> 2871 AHC_SET_DV_STATE(ahc, targ,
>> 2872 AHC_DV_STATE_WEB);
>> 2873 break;
>> 2874 }
>> 2875
>> 2876 if (targ->dv_buffer != NULL) {
>> 2877 free(targ->dv_buffer, M_DEVBUF);
>> 2878 targ->dv_buffer = NULL;
>> 2879 }
>> 2880 if (targ->dv_buffer1 != NULL) {
>> 2881 free(targ->dv_buffer1, M_DEVBUF);
>> 2882 targ->dv_buffer1 = NULL;
>> 2883 }
>> 2884 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2885 break;
>> 2886 case SS_INQ_REFRESH:
>> 2887 AHC_SET_DV_STATE(ahc, targ,
>> 2888 AHC_DV_STATE_INQ_SHORT_ASYNC);
>> 2889 break;
>> 2890 case SS_RETRY:
>> 2891 AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
>> 2892 if (ahc_cmd_get_transaction_status(cmd)
>> 2893 == CAM_REQUEUE_REQ) {
>> 2894 targ->dv_state_retry--;
>> 2895 } else if ((status & SSQ_FALLBACK) != 0) {
>> 2896 if (ahc_linux_fallback(ahc, devinfo) != 0) {
>> 2897 AHC_SET_DV_STATE(ahc, targ,
>> 2898 AHC_DV_STATE_EXIT);
>> 2899 break;
>> 2900 }
>> 2901 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_WEB);
>> 2902 }
>> 2903 if (targ->dv_state_retry <= 10) {
>> 2904 if ((status & (SSQ_DELAY_RANDOM|SSQ_DELAY))!= 0)
>> 2905 msleep(ahc->our_id*1000/10);
>> 2906 break;
>> 2907 }
>> 2908 #ifdef AHC_DEBUG
>> 2909 if (ahc_debug & AHC_SHOW_DV) {
>> 2910 ahc_print_devinfo(ahc, devinfo);
>> 2911 printf("DV REB reties exhausted\n");
>> 2912 }
>> 2913 #endif
>> 2914 /* FALLTHROUGH */
>> 2915 default:
>> 2916 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2917 break;
>> 2918 }
>> 2919 break;
>> 2920
>> 2921 case AHC_DV_STATE_SU:
>> 2922 switch (status & SS_MASK) {
>> 2923 case SS_NOP:
>> 2924 case SS_INQ_REFRESH:
>> 2925 AHC_SET_DV_STATE(ahc, targ,
>> 2926 AHC_DV_STATE_INQ_SHORT_ASYNC);
>> 2927 break;
>> 2928 default:
>> 2929 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2930 break;
>> 2931 }
>> 2932 break;
>> 2933
>> 2934 case AHC_DV_STATE_BUSY:
>> 2935 switch (status & SS_MASK) {
>> 2936 case SS_NOP:
>> 2937 case SS_INQ_REFRESH:
>> 2938 AHC_SET_DV_STATE(ahc, targ,
>> 2939 AHC_DV_STATE_INQ_SHORT_ASYNC);
>> 2940 break;
>> 2941 case SS_TUR:
>> 2942 case SS_RETRY:
>> 2943 AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
>> 2944 if (ahc_cmd_get_transaction_status(cmd)
>> 2945 == CAM_REQUEUE_REQ) {
>> 2946 targ->dv_state_retry--;
>> 2947 } else if (targ->dv_state_retry < 60) {
>> 2948 if ((status & SSQ_DELAY) != 0)
>> 2949 ssleep(1);
>> 2950 } else {
>> 2951 #ifdef AHC_DEBUG
>> 2952 if (ahc_debug & AHC_SHOW_DV) {
>> 2953 ahc_print_devinfo(ahc, devinfo);
>> 2954 printf("DV BUSY reties exhausted\n");
>> 2955 }
>> 2956 #endif
>> 2957 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2958 }
>> 2959 break;
>> 2960 default:
>> 2961 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2962 break;
>> 2963 }
>> 2964 break;
>> 2965
>> 2966 default:
>> 2967 printf("%s: Invalid DV completion state %d\n", ahc_name(ahc),
>> 2968 targ->dv_state);
>> 2969 AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
>> 2970 break;
>> 2971 }
>> 2972 }
>> 2973
>> 2974 static void
>> 2975 ahc_linux_dv_fill_cmd(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
>> 2976 struct ahc_devinfo *devinfo)
>> 2977 {
>> 2978 memset(cmd, 0, sizeof(struct scsi_cmnd));
>> 2979 cmd->device = ahc->platform_data->dv_scsi_dev;
>> 2980 cmd->scsi_done = ahc_linux_dv_complete;
>> 2981 }
>> 2982
>> 2983 /*
>> 2984 * Synthesize an inquiry command. On the return trip, it'll be
>> 2985 * sniffed and the device transfer settings set for us.
>> 2986 */
>> 2987 static void
>> 2988 ahc_linux_dv_inq(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
>> 2989 struct ahc_devinfo *devinfo, struct ahc_linux_target *targ,
>> 2990 u_int request_length)
>> 2991 {
>> 2992
>> 2993 #ifdef AHC_DEBUG
>> 2994 if (ahc_debug & AHC_SHOW_DV) {
>> 2995 ahc_print_devinfo(ahc, devinfo);
>> 2996 printf("Sending INQ\n");
>> 2997 }
>> 2998 #endif
>> 2999 if (targ->inq_data == NULL)
>> 3000 targ->inq_data = malloc(AHC_LINUX_DV_INQ_LEN,
>> 3001 M_DEVBUF, M_WAITOK);
>> 3002 if (targ->dv_state > AHC_DV_STATE_INQ_ASYNC) {
>> 3003 if (targ->dv_buffer != NULL)
>> 3004 free(targ->dv_buffer, M_DEVBUF);
>> 3005 targ->dv_buffer = malloc(AHC_LINUX_DV_INQ_LEN,
>> 3006 M_DEVBUF, M_WAITOK);
>> 3007 }
>> 3008
>> 3009 ahc_linux_dv_fill_cmd(ahc, cmd, devinfo);
>> 3010 cmd->sc_data_direction = SCSI_DATA_READ;
>> 3011 cmd->cmd_len = 6;
>> 3012 cmd->cmnd[0] = INQUIRY;
>> 3013 cmd->cmnd[4] = request_length;
>> 3014 cmd->request_bufflen = request_length;
>> 3015 if (targ->dv_state > AHC_DV_STATE_INQ_ASYNC)
>> 3016 cmd->request_buffer = targ->dv_buffer;
>> 3017 else
>> 3018 cmd->request_buffer = targ->inq_data;
>> 3019 memset(cmd->request_buffer, 0, AHC_LINUX_DV_INQ_LEN);
>> 3020 }
>> 3021
>> 3022 static void
>> 3023 ahc_linux_dv_tur(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
>> 3024 struct ahc_devinfo *devinfo)
>> 3025 {
>> 3026
>> 3027 #ifdef AHC_DEBUG
>> 3028 if (ahc_debug & AHC_SHOW_DV) {
>> 3029 ahc_print_devinfo(ahc, devinfo);
>> 3030 printf("Sending TUR\n");
>> 3031 }
>> 3032 #endif
>> 3033 /* Do a TUR to clear out any non-fatal transitional state */
>> 3034 ahc_linux_dv_fill_cmd(ahc, cmd, devinfo);
>> 3035 cmd->sc_data_direction = SCSI_DATA_NONE;
>> 3036 cmd->cmd_len = 6;
>> 3037 cmd->cmnd[0] = TEST_UNIT_READY;
>> 3038 }
>> 3039
>> 3040 #define AHC_REBD_LEN 4
>> 3041
>> 3042 static void
>> 3043 ahc_linux_dv_rebd(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
>> 3044 struct ahc_devinfo *devinfo, struct ahc_linux_target *targ)
>> 3045 {
>> 3046
>> 3047 #ifdef AHC_DEBUG
>> 3048 if (ahc_debug & AHC_SHOW_DV) {
>> 3049 ahc_print_devinfo(ahc, devinfo);
>> 3050 printf("Sending REBD\n");
>> 3051 }
>> 3052 #endif
>> 3053 if (targ->dv_buffer != NULL)
>> 3054 free(targ->dv_buffer, M_DEVBUF);
>> 3055 targ->dv_buffer = malloc(AHC_REBD_LEN, M_DEVBUF, M_WAITOK);
>> 3056 ahc_linux_dv_fill_cmd(ahc, cmd, devinfo);
>> 3057 cmd->sc_data_direction = SCSI_DATA_READ;
>> 3058 cmd->cmd_len = 10;
>> 3059 cmd->cmnd[0] = READ_BUFFER;
>> 3060 cmd->cmnd[1] = 0x0b;
>> 3061 scsi_ulto3b(AHC_REBD_LEN, &cmd->cmnd[6]);
>> 3062 cmd->request_bufflen = AHC_REBD_LEN;
>> 3063 cmd->underflow = cmd->request_bufflen;
>> 3064 cmd->request_buffer = targ->dv_buffer;
>> 3065 }
>> 3066
>> 3067 static void
>> 3068 ahc_linux_dv_web(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
>> 3069 struct ahc_devinfo *devinfo, struct ahc_linux_target *targ)
>> 3070 {
>> 3071
>> 3072 #ifdef AHC_DEBUG
>> 3073 if (ahc_debug & AHC_SHOW_DV) {
>> 3074 ahc_print_devinfo(ahc, devinfo);
>> 3075 printf("Sending WEB\n");
>> 3076 }
>> 3077 #endif
>> 3078 ahc_linux_dv_fill_cmd(ahc, cmd, devinfo);
>> 3079 cmd->sc_data_direction = SCSI_DATA_WRITE;
>> 3080 cmd->cmd_len = 10;
>> 3081 cmd->cmnd[0] = WRITE_BUFFER;
>> 3082 cmd->cmnd[1] = 0x0a;
>> 3083 scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]);
>> 3084 cmd->request_bufflen = targ->dv_echo_size;
>> 3085 cmd->underflow = cmd->request_bufflen;
>> 3086 cmd->request_buffer = targ->dv_buffer;
>> 3087 }
>> 3088
>> 3089 static void
>> 3090 ahc_linux_dv_reb(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
>> 3091 struct ahc_devinfo *devinfo, struct ahc_linux_target *targ)
>> 3092 {
>> 3093
>> 3094 #ifdef AHC_DEBUG
>> 3095 if (ahc_debug & AHC_SHOW_DV) {
>> 3096 ahc_print_devinfo(ahc, devinfo);
>> 3097 printf("Sending REB\n");
>> 3098 }
>> 3099 #endif
>> 3100 ahc_linux_dv_fill_cmd(ahc, cmd, devinfo);
>> 3101 cmd->sc_data_direction = SCSI_DATA_READ;
>> 3102 cmd->cmd_len = 10;
>> 3103 cmd->cmnd[0] = READ_BUFFER;
>> 3104 cmd->cmnd[1] = 0x0a;
>> 3105 scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]);
>> 3106 cmd->request_bufflen = targ->dv_echo_size;
>> 3107 cmd->underflow = cmd->request_bufflen;
>> 3108 cmd->request_buffer = targ->dv_buffer1;
>> 3109 }
>> 3110
>> 3111 static void
>> 3112 ahc_linux_dv_su(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
>> 3113 struct ahc_devinfo *devinfo,
>> 3114 struct ahc_linux_target *targ)
>> 3115 {
>> 3116 u_int le;
>> 3117
>> 3118 le = SID_IS_REMOVABLE(targ->inq_data) ? SSS_LOEJ : 0;
>> 3119
>> 3120 #ifdef AHC_DEBUG
>> 3121 if (ahc_debug & AHC_SHOW_DV) {
>> 3122 ahc_print_devinfo(ahc, devinfo);
>> 3123 printf("Sending SU\n");
>> 3124 }
>> 3125 #endif
>> 3126 ahc_linux_dv_fill_cmd(ahc, cmd, devinfo);
>> 3127 cmd->sc_data_direction = SCSI_DATA_NONE;
>> 3128 cmd->cmd_len = 6;
>> 3129 cmd->cmnd[0] = START_STOP_UNIT;
>> 3130 cmd->cmnd[4] = le | SSS_START;
>> 3131 }
>> 3132
>> 3133 static int
>> 3134 ahc_linux_fallback(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
>> 3135 {
>> 3136 struct ahc_linux_target *targ;
>> 3137 struct ahc_initiator_tinfo *tinfo;
>> 3138 struct ahc_transinfo *goal;
>> 3139 struct ahc_tmode_tstate *tstate;
>> 3140 struct ahc_syncrate *syncrate;
>> 3141 u_long s;
>> 3142 u_int width;
>> 3143 u_int period;
>> 3144 u_int offset;
>> 3145 u_int ppr_options;
>> 3146 u_int cur_speed;
>> 3147 u_int wide_speed;
>> 3148 u_int narrow_speed;
>> 3149 u_int fallback_speed;
>> 3150
>> 3151 #ifdef AHC_DEBUG
>> 3152 if (ahc_debug & AHC_SHOW_DV) {
>> 3153 ahc_print_devinfo(ahc, devinfo);
>> 3154 printf("Trying to fallback\n");
>> 3155 }
>> 3156 #endif
>> 3157 ahc_lock(ahc, &s);
>> 3158 targ = ahc->platform_data->targets[devinfo->target_offset];
>> 3159 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel,
>> 3160 devinfo->our_scsiid,
>> 3161 devinfo->target, &tstate);
>> 3162 goal = &tinfo->goal;
>> 3163 width = goal->width;
>> 3164 period = goal->period;
>> 3165 offset = goal->offset;
>> 3166 ppr_options = goal->ppr_options;
>> 3167 if (offset == 0)
>> 3168 period = AHC_ASYNC_XFER_PERIOD;
>> 3169 if (targ->dv_next_narrow_period == 0)
>> 3170 targ->dv_next_narrow_period = MAX(period, AHC_SYNCRATE_ULTRA2);
>> 3171 if (targ->dv_next_wide_period == 0)
>> 3172 targ->dv_next_wide_period = period;
>> 3173 if (targ->dv_max_width == 0)
>> 3174 targ->dv_max_width = width;
>> 3175 if (targ->dv_max_ppr_options == 0)
>> 3176 targ->dv_max_ppr_options = ppr_options;
>> 3177 if (targ->dv_last_ppr_options == 0)
>> 3178 targ->dv_last_ppr_options = ppr_options;
>> 3179
>> 3180 cur_speed = aic_calc_speed(width, period, offset, AHC_SYNCRATE_MIN);
>> 3181 wide_speed = aic_calc_speed(MSG_EXT_WDTR_BUS_16_BIT,
>> 3182 targ->dv_next_wide_period,
>> 3183 MAX_OFFSET,
>> 3184 AHC_SYNCRATE_MIN);
>> 3185 narrow_speed = aic_calc_speed(MSG_EXT_WDTR_BUS_8_BIT,
>> 3186 targ->dv_next_narrow_period,
>> 3187 MAX_OFFSET,
>> 3188 AHC_SYNCRATE_MIN);
>> 3189 fallback_speed = aic_calc_speed(width, period+1, offset,
>> 3190 AHC_SYNCRATE_MIN);
>> 3191 #ifdef AHC_DEBUG
>> 3192 if (ahc_debug & AHC_SHOW_DV) {
>> 3193 printf("cur_speed= %d, wide_speed= %d, narrow_speed= %d, "
>> 3194 "fallback_speed= %d\n", cur_speed, wide_speed,
>> 3195 narrow_speed, fallback_speed);
>> 3196 }
>> 3197 #endif
>> 3198
>> 3199 if (cur_speed > 160000) {
>> 3200 /*
>> 3201 * Paced/DT/IU_REQ only transfer speeds. All we
>> 3202 * can do is fallback in terms of syncrate.
>> 3203 */
>> 3204 period++;
>> 3205 } else if (cur_speed > 80000) {
>> 3206 if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
>> 3207 /*
>> 3208 * Try without IU_REQ as it may be confusing
>> 3209 * an expander.
>> 3210 */
>> 3211 ppr_options &= ~MSG_EXT_PPR_IU_REQ;
>> 3212 } else {
>> 3213 /*
>> 3214 * Paced/DT only transfer speeds. All we
>> 3215 * can do is fallback in terms of syncrate.
>> 3216 */
>> 3217 period++;
>> 3218 ppr_options = targ->dv_max_ppr_options;
>> 3219 }
>> 3220 } else if (cur_speed > 3300) {
>> 3221
>> 3222 /*
>> 3223 * In this range we the following
>> 3224 * options ordered from highest to
>> 3225 * lowest desireability:
>> 3226 *
>> 3227 * o Wide/DT
>> 3228 * o Wide/non-DT
>> 3229 * o Narrow at a potentally higher sync rate.
>> 3230 *
>> 3231 * All modes are tested with and without IU_REQ
>> 3232 * set since using IUs may confuse an expander.
>> 3233 */
>> 3234 if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
>> 3235
>> 3236 ppr_options &= ~MSG_EXT_PPR_IU_REQ;
>> 3237 } else if ((ppr_options & MSG_EXT_PPR_DT_REQ) != 0) {
>> 3238 /*
>> 3239 * Try going non-DT.
>> 3240 */
>> 3241 ppr_options = targ->dv_max_ppr_options;
>> 3242 ppr_options &= ~MSG_EXT_PPR_DT_REQ;
>> 3243 } else if (targ->dv_last_ppr_options != 0) {
>> 3244 /*
>> 3245 * Try without QAS or any other PPR options.
>> 3246 * We may need a non-PPR message to work with
>> 3247 * an expander. We look at the "last PPR options"
>> 3248 * so we will perform this fallback even if the
>> 3249 * target responded to our PPR negotiation with
>> 3250 * no option bits set.
>> 3251 */
>> 3252 ppr_options = 0;
>> 3253 } else if (width == MSG_EXT_WDTR_BUS_16_BIT) {
>> 3254 /*
>> 3255 * If the next narrow speed is greater than
>> 3256 * the next wide speed, fallback to narrow.
>> 3257 * Otherwise fallback to the next DT/Wide setting.
>> 3258 * The narrow async speed will always be smaller
>> 3259 * than the wide async speed, so handle this case
>> 3260 * specifically.
>> 3261 */
>> 3262 ppr_options = targ->dv_max_ppr_options;
>> 3263 if (narrow_speed > fallback_speed
>> 3264 || period >= AHC_ASYNC_XFER_PERIOD) {
>> 3265 targ->dv_next_wide_period = period+1;
>> 3266 width = MSG_EXT_WDTR_BUS_8_BIT;
>> 3267 period = targ->dv_next_narrow_period;
>> 3268 } else {
>> 3269 period++;
>> 3270 }
>> 3271 } else if ((ahc->features & AHC_WIDE) != 0
>> 3272 && targ->dv_max_width != 0
>> 3273 && wide_speed >= fallback_speed
>> 3274 && (targ->dv_next_wide_period <= AHC_ASYNC_XFER_PERIOD
>> 3275 || period >= AHC_ASYNC_XFER_PERIOD)) {
>> 3276
>> 3277 /*
>> 3278 * We are narrow. Try falling back
>> 3279 * to the next wide speed with
>> 3280 * all supported ppr options set.
>> 3281 */
>> 3282 targ->dv_next_narrow_period = period+1;
>> 3283 width = MSG_EXT_WDTR_BUS_16_BIT;
>> 3284 period = targ->dv_next_wide_period;
>> 3285 ppr_options = targ->dv_max_ppr_options;
>> 3286 } else {
>> 3287 /* Only narrow fallback is allowed. */
>> 3288 period++;
>> 3289 ppr_options = targ->dv_max_ppr_options;
>> 3290 }
>> 3291 } else {
>> 3292 ahc_unlock(ahc, &s);
>> 3293 return (-1);
>> 3294 }
>> 3295 offset = MAX_OFFSET;
>> 3296 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options,
>> 3297 AHC_SYNCRATE_DT);
>> 3298 ahc_set_width(ahc, devinfo, width, AHC_TRANS_GOAL, FALSE);
>> 3299 if (period == 0) {
>> 3300 period = 0;
>> 3301 offset = 0;
>> 3302 ppr_options = 0;
>> 3303 if (width == MSG_EXT_WDTR_BUS_8_BIT)
>> 3304 targ->dv_next_narrow_period = AHC_ASYNC_XFER_PERIOD;
>> 3305 else
>> 3306 targ->dv_next_wide_period = AHC_ASYNC_XFER_PERIOD;
>> 3307 }
>> 3308 ahc_set_syncrate(ahc, devinfo, syncrate, period, offset,
>> 3309 ppr_options, AHC_TRANS_GOAL, FALSE);
>> 3310 targ->dv_last_ppr_options = ppr_options;
>> 3311 ahc_unlock(ahc, &s);
>> 3312 return (0);
>> 3313 }
>> 3314
>> 3315 static void
>> 3316 ahc_linux_dv_timeout(struct scsi_cmnd *cmd)
>> 3317 {
>> 3318 struct ahc_softc *ahc;
>> 3319 struct scb *scb;
>> 3320 u_long flags;
>> 3321
>> 3322 ahc = *((struct ahc_softc **)cmd->device->host->hostdata);
>> 3323 ahc_lock(ahc, &flags);
>> 3324
>> 3325 #ifdef AHC_DEBUG
>> 3326 if (ahc_debug & AHC_SHOW_DV) {
>> 3327 printf("%s: Timeout while doing DV command %x.\n",
>> 3328 ahc_name(ahc), cmd->cmnd[0]);
>> 3329 ahc_dump_card_state(ahc);
>> 3330 }
>> 3331 #endif
>> 3332
>> 3333 /*
>> 3334 * Guard against "done race". No action is
>> 3335 * required if we just completed.
>> 3336 */
>> 3337 if ((scb = (struct scb *)cmd->host_scribble) == NULL) {
>> 3338 ahc_unlock(ahc, &flags);
>> 3339 return;
>> 3340 }
>> 3341
>> 3342 /*
>> 3343 * Command has not completed. Mark this
>> 3344 * SCB as having failing status prior to
>> 3345 * resetting the bus, so we get the correct
>> 3346 * error code.
>> 3347 */
>> 3348 if ((scb->flags & SCB_SENSE) != 0)
>> 3349 ahc_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
>> 3350 else
>> 3351 ahc_set_transaction_status(scb, CAM_CMD_TIMEOUT);
>> 3352 ahc_reset_channel(ahc, cmd->device->channel + 'A', /*initiate*/TRUE);
>> 3353
>> 3354 /*
>> 3355 * Add a minimal bus settle delay for devices that are slow to
>> 3356 * respond after bus resets.
>> 3357 */