2 * Adaptec AIC79xx device driver for Linux.
4 * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm.c#171 $
6 * --------------------------------------------------------------------------
7 * Copyright (c) 1994-2000 Justin T. Gibbs.
8 * Copyright (c) 1997-1999 Doug Ledford
9 * Copyright (c) 2000-2003 Adaptec Inc.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #include "aic79xx_osm.h"
46 #include "aic79xx_inline.h"
47 #include <scsi/scsicam.h>
50 * Include aiclib.c as part of our
51 * "module dependencies are hard" work around.
55 #include <linux/init.h> /* __setup */
57 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
58 #include "sd.h" /* For geometry detection */
61 #include <linux/mm.h> /* For fetching system memory size */
62 #include <linux/delay.h> /* For ssleep/msleep */
65 * Lock protecting manipulation of the ahd softc list.
67 spinlock_t ahd_list_spinlock;
69 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
70 /* For dynamic sglist size calculation. */
75 * Bucket size for counting good commands in between bad ones.
77 #define AHD_LINUX_ERR_THRESH 1000
80 * Set this to the delay in seconds after SCSI bus reset.
81 * Note, we honor this only for the initial bus reset.
82 * The scsi error recovery code performs its own bus settle
83 * delay handling for error recovery actions.
85 #ifdef CONFIG_AIC79XX_RESET_DELAY_MS
86 #define AIC79XX_RESET_DELAY CONFIG_AIC79XX_RESET_DELAY_MS
88 #define AIC79XX_RESET_DELAY 5000
92 * To change the default number of tagged transactions allowed per-device,
93 * add a line to the lilo.conf file like:
94 * append="aic79xx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
95 * which will result in the first four devices on the first two
96 * controllers being set to a tagged queue depth of 32.
98 * The tag_commands is an array of 16 to allow for wide and twin adapters.
99 * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15
103 uint16_t tag_commands[16]; /* Allow for wide/twin adapters. */
104 } adapter_tag_info_t;
107 * Modify this as you see fit for your system.
109 * 0 tagged queuing disabled
110 * 1 <= n <= 253 n == max tags ever dispatched.
112 * The driver will throttle the number of commands dispatched to a
113 * device if it returns queue full. For devices with a fixed maximum
114 * queue depth, the driver will eventually determine this depth and
115 * lock it in (a console message is printed to indicate that a lock
116 * has occurred). On some devices, queue full is returned for a temporary
117 * resource shortage. These devices will return queue full at varying
118 * depths. The driver will throttle back when the queue fulls occur and
119 * attempt to slowly increase the depth over time as the device recovers
120 * from the resource shortage.
122 * In this example, the first line will disable tagged queueing for all
123 * the devices on the first probed aic79xx adapter.
125 * The second line enables tagged queueing with 4 commands/LUN for IDs
126 * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
127 * driver to attempt to use up to 64 tags for ID 1.
129 * The third line is the same as the first line.
131 * The fourth line disables tagged queueing for devices 0 and 3. It
132 * enables tagged queueing for the other IDs, with 16 commands/LUN
133 * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
134 * IDs 2, 5-7, and 9-15.
138 * NOTE: The below structure is for reference only, the actual structure
139 * to modify in order to change things is just below this comment block.
140 adapter_tag_info_t aic79xx_tag_info[] =
142 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
143 {{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}},
144 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
145 {{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
149 #ifdef CONFIG_AIC79XX_CMDS_PER_DEVICE
150 #define AIC79XX_CMDS_PER_DEVICE CONFIG_AIC79XX_CMDS_PER_DEVICE
152 #define AIC79XX_CMDS_PER_DEVICE AHD_MAX_QUEUE
155 #define AIC79XX_CONFIGED_TAG_COMMANDS { \
156 AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
157 AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
158 AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
159 AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
160 AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
161 AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
162 AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
163 AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE \
167 * By default, use the number of commands specified by
168 * the users kernel configuration.
170 static adapter_tag_info_t aic79xx_tag_info[] =
172 {AIC79XX_CONFIGED_TAG_COMMANDS},
173 {AIC79XX_CONFIGED_TAG_COMMANDS},
174 {AIC79XX_CONFIGED_TAG_COMMANDS},
175 {AIC79XX_CONFIGED_TAG_COMMANDS},
176 {AIC79XX_CONFIGED_TAG_COMMANDS},
177 {AIC79XX_CONFIGED_TAG_COMMANDS},
178 {AIC79XX_CONFIGED_TAG_COMMANDS},
179 {AIC79XX_CONFIGED_TAG_COMMANDS},
180 {AIC79XX_CONFIGED_TAG_COMMANDS},
181 {AIC79XX_CONFIGED_TAG_COMMANDS},
182 {AIC79XX_CONFIGED_TAG_COMMANDS},
183 {AIC79XX_CONFIGED_TAG_COMMANDS},
184 {AIC79XX_CONFIGED_TAG_COMMANDS},
185 {AIC79XX_CONFIGED_TAG_COMMANDS},
186 {AIC79XX_CONFIGED_TAG_COMMANDS},
187 {AIC79XX_CONFIGED_TAG_COMMANDS}
191 * By default, read streaming is disabled. In theory,
192 * read streaming should enhance performance, but early
193 * U320 drive firmware actually performs slower with
194 * read streaming enabled.
196 #ifdef CONFIG_AIC79XX_ENABLE_RD_STRM
197 #define AIC79XX_CONFIGED_RD_STRM 0xFFFF
199 #define AIC79XX_CONFIGED_RD_STRM 0
202 static uint16_t aic79xx_rd_strm_info[] =
204 AIC79XX_CONFIGED_RD_STRM,
205 AIC79XX_CONFIGED_RD_STRM,
206 AIC79XX_CONFIGED_RD_STRM,
207 AIC79XX_CONFIGED_RD_STRM,
208 AIC79XX_CONFIGED_RD_STRM,
209 AIC79XX_CONFIGED_RD_STRM,
210 AIC79XX_CONFIGED_RD_STRM,
211 AIC79XX_CONFIGED_RD_STRM,
212 AIC79XX_CONFIGED_RD_STRM,
213 AIC79XX_CONFIGED_RD_STRM,
214 AIC79XX_CONFIGED_RD_STRM,
215 AIC79XX_CONFIGED_RD_STRM,
216 AIC79XX_CONFIGED_RD_STRM,
217 AIC79XX_CONFIGED_RD_STRM,
218 AIC79XX_CONFIGED_RD_STRM,
219 AIC79XX_CONFIGED_RD_STRM
225 * positive value = DV Enabled
227 * negative value = DV Default for adapter type/seeprom
229 #ifdef CONFIG_AIC79XX_DV_SETTING
230 #define AIC79XX_CONFIGED_DV CONFIG_AIC79XX_DV_SETTING
232 #define AIC79XX_CONFIGED_DV -1
235 static int8_t aic79xx_dv_settings[] =
256 * The I/O cell on the chip is very configurable in respect to its analog
257 * characteristics. Set the defaults here; they can be overriden with
258 * the proper insmod parameters.
260 struct ahd_linux_iocell_opts
266 #define AIC79XX_DEFAULT_PRECOMP 0xFF
267 #define AIC79XX_DEFAULT_SLEWRATE 0xFF
268 #define AIC79XX_DEFAULT_AMPLITUDE 0xFF
269 #define AIC79XX_DEFAULT_IOOPTS \
271 AIC79XX_DEFAULT_PRECOMP, \
272 AIC79XX_DEFAULT_SLEWRATE, \
273 AIC79XX_DEFAULT_AMPLITUDE \
275 #define AIC79XX_PRECOMP_INDEX 0
276 #define AIC79XX_SLEWRATE_INDEX 1
277 #define AIC79XX_AMPLITUDE_INDEX 2
278 static struct ahd_linux_iocell_opts aic79xx_iocell_info[] =
280 AIC79XX_DEFAULT_IOOPTS,
281 AIC79XX_DEFAULT_IOOPTS,
282 AIC79XX_DEFAULT_IOOPTS,
283 AIC79XX_DEFAULT_IOOPTS,
284 AIC79XX_DEFAULT_IOOPTS,
285 AIC79XX_DEFAULT_IOOPTS,
286 AIC79XX_DEFAULT_IOOPTS,
287 AIC79XX_DEFAULT_IOOPTS,
288 AIC79XX_DEFAULT_IOOPTS,
289 AIC79XX_DEFAULT_IOOPTS,
290 AIC79XX_DEFAULT_IOOPTS,
291 AIC79XX_DEFAULT_IOOPTS,
292 AIC79XX_DEFAULT_IOOPTS,
293 AIC79XX_DEFAULT_IOOPTS,
294 AIC79XX_DEFAULT_IOOPTS,
295 AIC79XX_DEFAULT_IOOPTS
299 * There should be a specific return value for this in scsi.h, but
300 * it seems that most drivers ignore it.
302 #define DID_UNDERFLOW DID_ERROR
305 ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
307 printk("(scsi%d:%c:%d:%d): ",
308 ahd->platform_data->host->host_no,
309 scb != NULL ? SCB_GET_CHANNEL(ahd, scb) : 'X',
310 scb != NULL ? SCB_GET_TARGET(ahd, scb) : -1,
311 scb != NULL ? SCB_GET_LUN(scb) : -1);
315 * XXX - these options apply unilaterally to _all_ adapters
316 * cards in the system. This should be fixed. Exceptions to this
317 * rule are noted in the comments.
321 * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
322 * has no effect on any later resets that might occur due to things like
325 static uint32_t aic79xx_no_reset;
328 * Certain PCI motherboards will scan PCI devices from highest to lowest,
329 * others scan from lowest to highest, and they tend to do all kinds of
330 * strange things when they come into contact with PCI bridge chips. The
331 * net result of all this is that the PCI card that is actually used to boot
332 * the machine is very hard to detect. Most motherboards go from lowest
333 * PCI slot number to highest, and the first SCSI controller found is the
334 * one you boot from. The only exceptions to this are when a controller
335 * has its BIOS disabled. So, we by default sort all of our SCSI controllers
336 * from lowest PCI slot number to highest PCI slot number. We also force
337 * all controllers with their BIOS disabled to the end of the list. This
338 * works on *almost* all computers. Where it doesn't work, we have this
339 * option. Setting this option to non-0 will reverse the order of the sort
340 * to highest first, then lowest, but will still leave cards with their BIOS
341 * disabled at the very end. That should fix everyone up unless there are
342 * really strange cirumstances.
344 static uint32_t aic79xx_reverse_scan;
347 * Should we force EXTENDED translation on a controller.
348 * 0 == Use whatever is in the SEEPROM or default to off
349 * 1 == Use whatever is in the SEEPROM or default to on
351 static uint32_t aic79xx_extended;
354 * PCI bus parity checking of the Adaptec controllers. This is somewhat
355 * dubious at best. To my knowledge, this option has never actually
356 * solved a PCI parity problem, but on certain machines with broken PCI
357 * chipset configurations, it can generate tons of false error messages.
358 * It's included in the driver for completeness.
359 * 0 = Shut off PCI parity check
360 * non-0 = Enable PCI parity check
362 * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
363 * variable to -1 you would actually want to simply pass the variable
364 * name without a number. That will invert the 0 which will result in
367 static uint32_t aic79xx_pci_parity = ~0;
370 * There are lots of broken chipsets in the world. Some of them will
371 * violate the PCI spec when we issue byte sized memory writes to our
372 * controller. I/O mapped register access, if allowed by the given
373 * platform, will work in almost all cases.
375 uint32_t aic79xx_allow_memio = ~0;
378 * aic79xx_detect() has been run, so register all device arrivals
379 * immediately with the system rather than deferring to the sorted
380 * attachment performed by aic79xx_detect().
382 int aic79xx_detect_complete;
385 * So that we can set how long each device is given as a selection timeout.
386 * The table of values goes like this:
391 * We default to 256ms because some older devices need a longer time
392 * to respond to initial selection.
394 static uint32_t aic79xx_seltime;
397 * Certain devices do not perform any aging on commands. Should the
398 * device be saturated by commands in one portion of the disk, it is
399 * possible for transactions on far away sectors to never be serviced.
400 * To handle these devices, we can periodically send an ordered tag to
401 * force all outstanding transactions to be serviced prior to a new
404 uint32_t aic79xx_periodic_otag;
407 * Module information and settable options.
409 static char *aic79xx = NULL;
411 MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>");
412 MODULE_DESCRIPTION("Adaptec Aic790X U320 SCSI Host Bus Adapter driver");
413 MODULE_LICENSE("Dual BSD/GPL");
414 MODULE_VERSION(AIC79XX_DRIVER_VERSION);
415 module_param(aic79xx, charp, 0);
416 MODULE_PARM_DESC(aic79xx,
417 "period delimited, options string.\n"
418 " verbose Enable verbose/diagnostic logging\n"
419 " allow_memio Allow device registers to be memory mapped\n"
420 " debug Bitmask of debug values to enable\n"
421 " no_reset Supress initial bus resets\n"
422 " extended Enable extended geometry on all controllers\n"
423 " periodic_otag Send an ordered tagged transaction\n"
424 " periodically to prevent tag starvation.\n"
425 " This may be required by some older disk\n"
426 " or drives/RAID arrays.\n"
427 " reverse_scan Sort PCI devices highest Bus/Slot to lowest\n"
428 " tag_info:<tag_str> Set per-target tag depth\n"
429 " global_tag_depth:<int> Global tag depth for all targets on all buses\n"
430 " rd_strm:<rd_strm_masks> Set per-target read streaming setting.\n"
431 " dv:<dv_settings> Set per-controller Domain Validation Setting.\n"
432 " slewrate:<slewrate_list>Set the signal slew rate (0-15).\n"
433 " precomp:<pcomp_list> Set the signal precompensation (0-7).\n"
434 " amplitude:<int> Set the signal amplitude (0-7).\n"
435 " seltime:<int> Selection Timeout:\n"
436 " (0/256ms,1/128ms,2/64ms,3/32ms)\n"
438 " Sample /etc/modprobe.conf line:\n"
439 " Enable verbose logging\n"
440 " Set tag depth on Controller 2/Target 2 to 10 tags\n"
441 " Shorten the selection timeout to 128ms\n"
443 " options aic79xx 'aic79xx=verbose.tag_info:{{}.{}.{..10}}.seltime:1'\n"
445 " Sample /etc/modprobe.conf line:\n"
446 " Change Read Streaming for Controller's 2 and 3\n"
448 " options aic79xx 'aic79xx=rd_strm:{..0xFFF0.0xC0F0}'");
450 static void ahd_linux_handle_scsi_status(struct ahd_softc *,
451 struct ahd_linux_device *,
453 static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd,
455 static void ahd_linux_filter_inquiry(struct ahd_softc *ahd,
456 struct ahd_devinfo *devinfo);
457 static void ahd_linux_dev_timed_unfreeze(u_long arg);
458 static void ahd_linux_sem_timeout(u_long arg);
459 static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd);
460 static void ahd_linux_size_nseg(void);
461 static void ahd_linux_thread_run_complete_queue(struct ahd_softc *ahd);
462 static void ahd_linux_start_dv(struct ahd_softc *ahd);
463 static void ahd_linux_dv_timeout(struct scsi_cmnd *cmd);
464 static int ahd_linux_dv_thread(void *data);
465 static void ahd_linux_kill_dv_thread(struct ahd_softc *ahd);
466 static void ahd_linux_dv_target(struct ahd_softc *ahd, u_int target);
467 static void ahd_linux_dv_transition(struct ahd_softc *ahd,
468 struct scsi_cmnd *cmd,
469 struct ahd_devinfo *devinfo,
470 struct ahd_linux_target *targ);
471 static void ahd_linux_dv_fill_cmd(struct ahd_softc *ahd,
472 struct scsi_cmnd *cmd,
473 struct ahd_devinfo *devinfo);
474 static void ahd_linux_dv_inq(struct ahd_softc *ahd,
475 struct scsi_cmnd *cmd,
476 struct ahd_devinfo *devinfo,
477 struct ahd_linux_target *targ,
478 u_int request_length);
479 static void ahd_linux_dv_tur(struct ahd_softc *ahd,
480 struct scsi_cmnd *cmd,
481 struct ahd_devinfo *devinfo);
482 static void ahd_linux_dv_rebd(struct ahd_softc *ahd,
483 struct scsi_cmnd *cmd,
484 struct ahd_devinfo *devinfo,
485 struct ahd_linux_target *targ);
486 static void ahd_linux_dv_web(struct ahd_softc *ahd,
487 struct scsi_cmnd *cmd,
488 struct ahd_devinfo *devinfo,
489 struct ahd_linux_target *targ);
490 static void ahd_linux_dv_reb(struct ahd_softc *ahd,
491 struct scsi_cmnd *cmd,
492 struct ahd_devinfo *devinfo,
493 struct ahd_linux_target *targ);
494 static void ahd_linux_dv_su(struct ahd_softc *ahd,
495 struct scsi_cmnd *cmd,
496 struct ahd_devinfo *devinfo,
497 struct ahd_linux_target *targ);
498 static int ahd_linux_fallback(struct ahd_softc *ahd,
499 struct ahd_devinfo *devinfo);
500 static __inline int ahd_linux_dv_fallback(struct ahd_softc *ahd,
501 struct ahd_devinfo *devinfo);
502 static void ahd_linux_dv_complete(Scsi_Cmnd *cmd);
503 static void ahd_linux_generate_dv_pattern(struct ahd_linux_target *targ);
504 static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd,
505 struct ahd_devinfo *devinfo);
506 static u_int ahd_linux_user_dv_setting(struct ahd_softc *ahd);
507 static void ahd_linux_setup_user_rd_strm_settings(struct ahd_softc *ahd);
508 static void ahd_linux_device_queue_depth(struct ahd_softc *ahd,
509 struct ahd_linux_device *dev);
510 static struct ahd_linux_target* ahd_linux_alloc_target(struct ahd_softc*,
512 static void ahd_linux_free_target(struct ahd_softc*,
513 struct ahd_linux_target*);
514 static struct ahd_linux_device* ahd_linux_alloc_device(struct ahd_softc*,
515 struct ahd_linux_target*,
517 static void ahd_linux_free_device(struct ahd_softc*,
518 struct ahd_linux_device*);
519 static void ahd_linux_run_device_queue(struct ahd_softc*,
520 struct ahd_linux_device*);
521 static void ahd_linux_setup_tag_info_global(char *p);
522 static aic_option_callback_t ahd_linux_setup_tag_info;
523 static aic_option_callback_t ahd_linux_setup_rd_strm_info;
524 static aic_option_callback_t ahd_linux_setup_dv;
525 static aic_option_callback_t ahd_linux_setup_iocell_info;
526 static int ahd_linux_next_unit(void);
527 static void ahd_runq_tasklet(unsigned long data);
528 static int aic79xx_setup(char *c);
530 /****************************** Inlines ***************************************/
531 static __inline void ahd_schedule_completeq(struct ahd_softc *ahd);
532 static __inline void ahd_schedule_runq(struct ahd_softc *ahd);
533 static __inline void ahd_setup_runq_tasklet(struct ahd_softc *ahd);
534 static __inline void ahd_teardown_runq_tasklet(struct ahd_softc *ahd);
535 static __inline struct ahd_linux_device*
536 ahd_linux_get_device(struct ahd_softc *ahd, u_int channel,
537 u_int target, u_int lun, int alloc);
538 static struct ahd_cmd *ahd_linux_run_complete_queue(struct ahd_softc *ahd);
539 static __inline void ahd_linux_check_device_queue(struct ahd_softc *ahd,
540 struct ahd_linux_device *dev);
541 static __inline struct ahd_linux_device *
542 ahd_linux_next_device_to_run(struct ahd_softc *ahd);
543 static __inline void ahd_linux_run_device_queues(struct ahd_softc *ahd);
544 static __inline void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*);
547 ahd_schedule_completeq(struct ahd_softc *ahd)
549 if ((ahd->platform_data->flags & AHD_RUN_CMPLT_Q_TIMER) == 0) {
550 ahd->platform_data->flags |= AHD_RUN_CMPLT_Q_TIMER;
551 ahd->platform_data->completeq_timer.expires = jiffies;
552 add_timer(&ahd->platform_data->completeq_timer);
557 * Must be called with our lock held.
560 ahd_schedule_runq(struct ahd_softc *ahd)
562 tasklet_schedule(&ahd->platform_data->runq_tasklet);
566 void ahd_setup_runq_tasklet(struct ahd_softc *ahd)
568 tasklet_init(&ahd->platform_data->runq_tasklet, ahd_runq_tasklet,
573 ahd_teardown_runq_tasklet(struct ahd_softc *ahd)
575 tasklet_kill(&ahd->platform_data->runq_tasklet);
578 static __inline struct ahd_linux_device*
579 ahd_linux_get_device(struct ahd_softc *ahd, u_int channel, u_int target,
580 u_int lun, int alloc)
582 struct ahd_linux_target *targ;
583 struct ahd_linux_device *dev;
586 target_offset = target;
589 targ = ahd->platform_data->targets[target_offset];
592 targ = ahd_linux_alloc_target(ahd, channel, target);
598 dev = targ->devices[lun];
599 if (dev == NULL && alloc != 0)
600 dev = ahd_linux_alloc_device(ahd, targ, lun);
604 #define AHD_LINUX_MAX_RETURNED_ERRORS 4
605 static struct ahd_cmd *
606 ahd_linux_run_complete_queue(struct ahd_softc *ahd)
608 struct ahd_cmd *acmd;
613 ahd_done_lock(ahd, &done_flags);
614 while ((acmd = TAILQ_FIRST(&ahd->platform_data->completeq)) != NULL) {
617 if (with_errors > AHD_LINUX_MAX_RETURNED_ERRORS) {
619 * Linux uses stack recursion to requeue
620 * commands that need to be retried. Avoid
621 * blowing out the stack by "spoon feeding"
622 * commands that completed with error back
623 * the operating system in case they are going
624 * to be retried. "ick"
626 ahd_schedule_completeq(ahd);
629 TAILQ_REMOVE(&ahd->platform_data->completeq,
630 acmd, acmd_links.tqe);
631 cmd = &acmd_scsi_cmd(acmd);
632 cmd->host_scribble = NULL;
633 if (ahd_cmd_get_transaction_status(cmd) != DID_OK
634 || (cmd->result & 0xFF) != SCSI_STATUS_OK)
639 ahd_done_unlock(ahd, &done_flags);
644 ahd_linux_check_device_queue(struct ahd_softc *ahd,
645 struct ahd_linux_device *dev)
647 if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) != 0
648 && dev->active == 0) {
649 dev->flags &= ~AHD_DEV_FREEZE_TIL_EMPTY;
653 if (TAILQ_FIRST(&dev->busyq) == NULL
654 || dev->openings == 0 || dev->qfrozen != 0)
657 ahd_linux_run_device_queue(ahd, dev);
660 static __inline struct ahd_linux_device *
661 ahd_linux_next_device_to_run(struct ahd_softc *ahd)
664 if ((ahd->flags & AHD_RESOURCE_SHORTAGE) != 0
665 || (ahd->platform_data->qfrozen != 0
666 && AHD_DV_SIMQ_FROZEN(ahd) == 0))
668 return (TAILQ_FIRST(&ahd->platform_data->device_runq));
672 ahd_linux_run_device_queues(struct ahd_softc *ahd)
674 struct ahd_linux_device *dev;
676 while ((dev = ahd_linux_next_device_to_run(ahd)) != NULL) {
677 TAILQ_REMOVE(&ahd->platform_data->device_runq, dev, links);
678 dev->flags &= ~AHD_DEV_ON_RUN_LIST;
679 ahd_linux_check_device_queue(ahd, dev);
684 ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb)
690 direction = cmd->sc_data_direction;
691 ahd_sync_sglist(ahd, scb, BUS_DMASYNC_POSTWRITE);
692 if (cmd->use_sg != 0) {
693 struct scatterlist *sg;
695 sg = (struct scatterlist *)cmd->request_buffer;
696 pci_unmap_sg(ahd->dev_softc, sg, cmd->use_sg, direction);
697 } else if (cmd->request_bufflen != 0) {
698 pci_unmap_single(ahd->dev_softc,
699 scb->platform_data->buf_busaddr,
700 cmd->request_bufflen, direction);
704 /******************************** Macros **************************************/
705 #define BUILD_SCSIID(ahd, cmd) \
706 ((((cmd)->device->id << TID_SHIFT) & TID) | (ahd)->our_id)
708 /************************ Host template entry points *************************/
709 static int ahd_linux_detect(Scsi_Host_Template *);
710 static const char *ahd_linux_info(struct Scsi_Host *);
711 static int ahd_linux_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
712 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
713 static int ahd_linux_slave_alloc(Scsi_Device *);
714 static int ahd_linux_slave_configure(Scsi_Device *);
715 static void ahd_linux_slave_destroy(Scsi_Device *);
716 #if defined(__i386__)
717 static int ahd_linux_biosparam(struct scsi_device*,
718 struct block_device*, sector_t, int[]);
721 static int ahd_linux_release(struct Scsi_Host *);
722 static void ahd_linux_select_queue_depth(struct Scsi_Host *host,
723 Scsi_Device *scsi_devs);
724 #if defined(__i386__)
725 static int ahd_linux_biosparam(Disk *, kdev_t, int[]);
728 static int ahd_linux_bus_reset(Scsi_Cmnd *);
729 static int ahd_linux_dev_reset(Scsi_Cmnd *);
730 static int ahd_linux_abort(Scsi_Cmnd *);
733 * Calculate a safe value for AHD_NSEG (as expressed through ahd_linux_nseg).
736 * The midlayer allocates an S/G array dynamically when a command is issued
737 * using SCSI malloc. This array, which is in an OS dependent format that
738 * must later be copied to our private S/G list, is sized to house just the
739 * number of segments needed for the current transfer. Since the code that
740 * sizes the SCSI malloc pool does not take into consideration fragmentation
741 * of the pool, executing transactions numbering just a fraction of our
742 * concurrent transaction limit with SG list lengths aproaching AHC_NSEG will
743 * quickly depleat the SCSI malloc pool of usable space. Unfortunately, the
744 * mid-layer does not properly handle this scsi malloc failures for the S/G
745 * array and the result can be a lockup of the I/O subsystem. We try to size
746 * our S/G list so that it satisfies our drivers allocation requirements in
747 * addition to avoiding fragmentation of the SCSI malloc pool.
750 ahd_linux_size_nseg(void)
752 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
757 * The SCSI allocator rounds to the nearest 512 bytes
758 * an cannot allocate across a page boundary. Our algorithm
759 * is to start at 1K of scsi malloc space per-command and
760 * loop through all factors of the PAGE_SIZE and pick the best.
763 for (cur_size = 1024; cur_size <= PAGE_SIZE; cur_size *= 2) {
766 nseg = cur_size / sizeof(struct scatterlist);
767 if (nseg < AHD_LINUX_MIN_NSEG)
770 if (best_size == 0) {
771 best_size = cur_size;
772 ahd_linux_nseg = nseg;
778 * Compare the traits of the current "best_size"
779 * with the current size to determine if the
780 * current size is a better size.
782 best_rem = best_size % sizeof(struct scatterlist);
783 cur_rem = cur_size % sizeof(struct scatterlist);
784 if (cur_rem < best_rem) {
785 best_size = cur_size;
786 ahd_linux_nseg = nseg;
794 * Try to detect an Adaptec 79XX controller.
797 ahd_linux_detect(Scsi_Host_Template *template)
799 struct ahd_softc *ahd;
803 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
805 * It is a bug that the upper layer takes
806 * this lock just prior to calling us.
808 spin_unlock_irq(&io_request_lock);
812 * Sanity checking of Linux SCSI data structures so
813 * that some of our hacks^H^H^H^H^Hassumptions aren't
816 if (offsetof(struct ahd_cmd_internal, end)
817 > offsetof(struct scsi_cmnd, host_scribble)) {
818 printf("ahd_linux_detect: SCSI data structures changed.\n");
819 printf("ahd_linux_detect: Unable to attach\n");
823 * Determine an appropriate size for our Scatter Gatther lists.
825 ahd_linux_size_nseg();
828 * If we've been passed any parameters, process them now.
831 aic79xx_setup(aic79xx);
834 template->proc_name = "aic79xx";
837 * Initialize our softc list lock prior to
838 * probing for any adapters.
843 error = ahd_linux_pci_init();
849 * Register with the SCSI layer all
850 * controllers we've found.
853 TAILQ_FOREACH(ahd, &ahd_tailq, links) {
855 if (ahd_linux_register_host(ahd, template) == 0)
858 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
859 spin_lock_irq(&io_request_lock);
861 aic79xx_detect_complete++;
865 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
867 * Free the passed in Scsi_Host memory structures prior to unloading the
871 ahd_linux_release(struct Scsi_Host * host)
873 struct ahd_softc *ahd;
880 * We should be able to just perform
881 * the free directly, but check our
882 * list for extra sanity.
884 ahd = ahd_find_softc(*(struct ahd_softc **)host->hostdata);
889 ahd_intr_enable(ahd, FALSE);
900 * Return a string describing the driver.
903 ahd_linux_info(struct Scsi_Host *host)
905 static char buffer[512];
908 struct ahd_softc *ahd;
911 ahd = *(struct ahd_softc **)host->hostdata;
912 memset(bp, 0, sizeof(buffer));
913 strcpy(bp, "Adaptec AIC79XX PCI-X SCSI HBA DRIVER, Rev ");
914 strcat(bp, AIC79XX_DRIVER_VERSION);
917 strcat(bp, ahd->description);
920 ahd_controller_info(ahd, ahd_info);
921 strcat(bp, ahd_info);
928 * Queue an SCB to the controller.
931 ahd_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
933 struct ahd_softc *ahd;
934 struct ahd_linux_device *dev;
937 ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
940 * Save the callback on completion function.
942 cmd->scsi_done = scsi_done;
944 ahd_midlayer_entrypoint_lock(ahd, &flags);
947 * Close the race of a command that was in the process of
948 * being queued to us just as our simq was frozen. Let
949 * DV commands through so long as we are only frozen to
952 if (ahd->platform_data->qfrozen != 0
953 && AHD_DV_CMD(cmd) == 0) {
955 ahd_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ);
956 ahd_linux_queue_cmd_complete(ahd, cmd);
957 ahd_schedule_completeq(ahd);
958 ahd_midlayer_entrypoint_unlock(ahd, &flags);
961 dev = ahd_linux_get_device(ahd, cmd->device->channel,
962 cmd->device->id, cmd->device->lun,
965 ahd_cmd_set_transaction_status(cmd, CAM_RESRC_UNAVAIL);
966 ahd_linux_queue_cmd_complete(ahd, cmd);
967 ahd_schedule_completeq(ahd);
968 ahd_midlayer_entrypoint_unlock(ahd, &flags);
969 printf("%s: aic79xx_linux_queue - Unable to allocate device!\n",
973 if (cmd->cmd_len > MAX_CDB_LEN)
975 cmd->result = CAM_REQ_INPROG << 16;
976 TAILQ_INSERT_TAIL(&dev->busyq, (struct ahd_cmd *)cmd, acmd_links.tqe);
977 if ((dev->flags & AHD_DEV_ON_RUN_LIST) == 0) {
978 TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, dev, links);
979 dev->flags |= AHD_DEV_ON_RUN_LIST;
980 ahd_linux_run_device_queues(ahd);
982 ahd_midlayer_entrypoint_unlock(ahd, &flags);
986 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
988 ahd_linux_slave_alloc(Scsi_Device *device)
990 struct ahd_softc *ahd;
992 ahd = *((struct ahd_softc **)device->host->hostdata);
994 printf("%s: Slave Alloc %d\n", ahd_name(ahd), device->id);
999 ahd_linux_slave_configure(Scsi_Device *device)
1001 struct ahd_softc *ahd;
1002 struct ahd_linux_device *dev;
1005 ahd = *((struct ahd_softc **)device->host->hostdata);
1007 printf("%s: Slave Configure %d\n", ahd_name(ahd), device->id);
1008 ahd_midlayer_entrypoint_lock(ahd, &flags);
1010 * Since Linux has attached to the device, configure
1011 * it so we don't free and allocate the device
1012 * structure on every command.
1014 dev = ahd_linux_get_device(ahd, device->channel,
1015 device->id, device->lun,
1018 dev->flags &= ~AHD_DEV_UNCONFIGURED;
1019 dev->flags |= AHD_DEV_SLAVE_CONFIGURED;
1020 dev->scsi_device = device;
1021 ahd_linux_device_queue_depth(ahd, dev);
1023 ahd_midlayer_entrypoint_unlock(ahd, &flags);
1028 ahd_linux_slave_destroy(Scsi_Device *device)
1030 struct ahd_softc *ahd;
1031 struct ahd_linux_device *dev;
1034 ahd = *((struct ahd_softc **)device->host->hostdata);
1036 printf("%s: Slave Destroy %d\n", ahd_name(ahd), device->id);
1037 ahd_midlayer_entrypoint_lock(ahd, &flags);
1038 dev = ahd_linux_get_device(ahd, device->channel,
1039 device->id, device->lun,
1043 * Filter out "silly" deletions of real devices by only
1044 * deleting devices that have had slave_configure()
1045 * called on them. All other devices that have not
1046 * been configured will automatically be deleted by
1047 * the refcounting process.
1050 && (dev->flags & AHD_DEV_SLAVE_CONFIGURED) != 0) {
1051 dev->flags |= AHD_DEV_UNCONFIGURED;
1052 if (TAILQ_EMPTY(&dev->busyq)
1054 && (dev->flags & AHD_DEV_TIMER_ACTIVE) == 0)
1055 ahd_linux_free_device(ahd, dev);
1057 ahd_midlayer_entrypoint_unlock(ahd, &flags);
1061 * Sets the queue depth for each SCSI device hanging
1062 * off the input host adapter.
1065 ahd_linux_select_queue_depth(struct Scsi_Host * host,
1066 Scsi_Device * scsi_devs)
1068 Scsi_Device *device;
1070 struct ahd_softc *ahd;
1073 ahd = *((struct ahd_softc **)host->hostdata);
1074 ahd_lock(ahd, &flags);
1075 for (device = scsi_devs; device != NULL; device = device->next) {
1078 * Watch out for duplicate devices. This works around
1079 * some quirks in how the SCSI scanning code does its
1080 * device management.
1082 for (ldev = scsi_devs; ldev != device; ldev = ldev->next) {
1083 if (ldev->host == device->host
1084 && ldev->channel == device->channel
1085 && ldev->id == device->id
1086 && ldev->lun == device->lun)
1089 /* Skip duplicate. */
1093 if (device->host == host) {
1094 struct ahd_linux_device *dev;
1097 * Since Linux has attached to the device, configure
1098 * it so we don't free and allocate the device
1099 * structure on every command.
1101 dev = ahd_linux_get_device(ahd, device->channel,
1102 device->id, device->lun,
1105 dev->flags &= ~AHD_DEV_UNCONFIGURED;
1106 dev->scsi_device = device;
1107 ahd_linux_device_queue_depth(ahd, dev);
1108 device->queue_depth = dev->openings
1110 if ((dev->flags & (AHD_DEV_Q_BASIC
1111 | AHD_DEV_Q_TAGGED)) == 0) {
1113 * We allow the OS to queue 2 untagged
1114 * transactions to us at any time even
1115 * though we can only execute them
1116 * serially on the controller/device.
1117 * This should remove some latency.
1119 device->queue_depth = 2;
1124 ahd_unlock(ahd, &flags);
1128 #if defined(__i386__)
1130 * Return the disk geometry for the given SCSI device.
1133 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1134 ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1135 sector_t capacity, int geom[])
1139 ahd_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
1141 struct scsi_device *sdev = disk->device;
1142 u_long capacity = disk->capacity;
1143 struct buffer_head *bh;
1150 struct ahd_softc *ahd;
1152 ahd = *((struct ahd_softc **)sdev->host->hostdata);
1154 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1155 bh = scsi_bios_ptable(bdev);
1156 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,17)
1157 bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, block_size(dev));
1159 bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, 1024);
1163 ret = scsi_partsize(bh, capacity,
1164 &geom[2], &geom[0], &geom[1]);
1165 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1175 cylinders = aic_sector_div(capacity, heads, sectors);
1177 if (aic79xx_extended != 0)
1180 extended = (ahd->flags & AHD_EXTENDED_TRANS_A) != 0;
1181 if (extended && cylinders >= 1024) {
1184 cylinders = aic_sector_div(capacity, heads, sectors);
1188 geom[2] = cylinders;
1194 * Abort the current SCSI command(s).
1197 ahd_linux_abort(Scsi_Cmnd *cmd)
1199 struct ahd_softc *ahd;
1200 struct ahd_cmd *acmd;
1201 struct ahd_cmd *list_acmd;
1202 struct ahd_linux_device *dev;
1203 struct scb *pending_scb;
1206 u_int active_scbptr;
1214 ahd_mode_state saved_modes;
1219 ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
1220 acmd = (struct ahd_cmd *)cmd;
1222 printf("%s:%d:%d:%d: Attempting to abort cmd %p:",
1223 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1224 cmd->device->lun, cmd);
1225 for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
1226 printf(" 0x%x", cmd->cmnd[cdb_byte]);
1230 * In all versions of Linux, we have to work around
1231 * a major flaw in how the mid-layer is locked down
1232 * if we are to sleep successfully in our error handler
1233 * while allowing our interrupt handler to run. Since
1234 * the midlayer acquires either the io_request_lock or
1235 * our lock prior to calling us, we must use the
1236 * spin_unlock_irq() method for unlocking our lock.
1237 * This will force interrupts to be enabled on the
1238 * current CPU. Since the EH thread should not have
1239 * been running with CPU interrupts disabled other than
1240 * by acquiring either the io_request_lock or our own
1241 * lock, this *should* be safe.
1243 ahd_midlayer_entrypoint_lock(ahd, &s);
1246 * First determine if we currently own this command.
1247 * Start by searching the device queue. If not found
1248 * there, check the pending_scb list. If not found
1249 * at all, and the system wanted us to just abort the
1250 * command, return success.
1252 dev = ahd_linux_get_device(ahd, cmd->device->channel,
1253 cmd->device->id, cmd->device->lun,
1258 * No target device for this command exists,
1259 * so we must not still own the command.
1261 printf("%s:%d:%d:%d: Is not an active device\n",
1262 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1268 TAILQ_FOREACH(list_acmd, &dev->busyq, acmd_links.tqe) {
1269 if (list_acmd == acmd)
1273 if (list_acmd != NULL) {
1274 printf("%s:%d:%d:%d: Command found on device queue\n",
1275 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1277 TAILQ_REMOVE(&dev->busyq, list_acmd, acmd_links.tqe);
1278 cmd->result = DID_ABORT << 16;
1279 ahd_linux_queue_cmd_complete(ahd, cmd);
1285 * See if we can find a matching cmd in the pending list.
1287 LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
1288 if (pending_scb->io_ctx == cmd)
1292 if (pending_scb == NULL) {
1293 printf("%s:%d:%d:%d: Command not found\n",
1294 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1299 if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
1301 * We can't queue two recovery actions using the same SCB
1308 * Ensure that the card doesn't do anything
1309 * behind our back. Also make sure that we
1310 * didn't "just" miss an interrupt that would
1313 was_paused = ahd_is_paused(ahd);
1314 ahd_pause_and_flushwork(ahd);
1317 if ((pending_scb->flags & SCB_ACTIVE) == 0) {
1318 printf("%s:%d:%d:%d: Command already completed\n",
1319 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1324 printf("%s: At time of recovery, card was %spaused\n",
1325 ahd_name(ahd), was_paused ? "" : "not ");
1326 ahd_dump_card_state(ahd);
1328 disconnected = TRUE;
1329 if (ahd_search_qinfifo(ahd, cmd->device->id, cmd->device->channel + 'A',
1330 cmd->device->lun, SCB_GET_TAG(pending_scb),
1331 ROLE_INITIATOR, CAM_REQ_ABORTED,
1332 SEARCH_COMPLETE) > 0) {
1333 printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
1334 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1340 saved_modes = ahd_save_modes(ahd);
1341 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1342 last_phase = ahd_inb(ahd, LASTPHASE);
1343 saved_scbptr = ahd_get_scbptr(ahd);
1344 active_scbptr = saved_scbptr;
1345 if (disconnected && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) {
1346 struct scb *bus_scb;
1348 bus_scb = ahd_lookup_scb(ahd, active_scbptr);
1349 if (bus_scb == pending_scb)
1350 disconnected = FALSE;
1354 * At this point, pending_scb is the scb associated with the
1355 * passed in command. That command is currently active on the
1356 * bus or is in the disconnected state.
1358 if (last_phase != P_BUSFREE
1359 && SCB_GET_TAG(pending_scb) == active_scbptr) {
1362 * We're active on the bus, so assert ATN
1363 * and hope that the target responds.
1365 pending_scb = ahd_lookup_scb(ahd, active_scbptr);
1366 pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
1367 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1368 ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
1369 printf("%s:%d:%d:%d: Device is active, asserting ATN\n",
1370 ahd_name(ahd), cmd->device->channel,
1371 cmd->device->id, cmd->device->lun);
1373 } else if (disconnected) {
1376 * Actually re-queue this SCB in an attempt
1377 * to select the device before it reconnects.
1379 pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
1380 ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb));
1381 pending_scb->hscb->cdb_len = 0;
1382 pending_scb->hscb->task_attribute = 0;
1383 pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK;
1385 if ((pending_scb->flags & SCB_PACKETIZED) != 0) {
1387 * Mark the SCB has having an outstanding
1388 * task management function. Should the command
1389 * complete normally before the task management
1390 * function can be sent, the host will be notified
1391 * to abort our requeued SCB.
1393 ahd_outb(ahd, SCB_TASK_MANAGEMENT,
1394 pending_scb->hscb->task_management);
1397 * If non-packetized, set the MK_MESSAGE control
1398 * bit indicating that we desire to send a message.
1399 * We also set the disconnected flag since there is
1400 * no guarantee that our SCB control byte matches
1401 * the version on the card. We don't want the
1402 * sequencer to abort the command thinking an
1403 * unsolicited reselection occurred.
1405 pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
1408 * The sequencer will never re-reference the
1409 * in-core SCB. To make sure we are notified
1410 * during reslection, set the MK_MESSAGE flag in
1411 * the card's copy of the SCB.
1413 ahd_outb(ahd, SCB_CONTROL,
1414 ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
1418 * Clear out any entries in the QINFIFO first
1419 * so we are the next SCB for this target
1422 ahd_search_qinfifo(ahd, cmd->device->id,
1423 cmd->device->channel + 'A', cmd->device->lun,
1424 SCB_LIST_NULL, ROLE_INITIATOR,
1425 CAM_REQUEUE_REQ, SEARCH_COMPLETE);
1426 ahd_qinfifo_requeue_tail(ahd, pending_scb);
1427 ahd_set_scbptr(ahd, saved_scbptr);
1428 ahd_print_path(ahd, pending_scb);
1429 printf("Device is disconnected, re-queuing SCB\n");
1432 printf("%s:%d:%d:%d: Unable to deliver message\n",
1433 ahd_name(ahd), cmd->device->channel,
1434 cmd->device->id, cmd->device->lun);
1441 * Our assumption is that if we don't have the command, no
1442 * recovery action was required, so we return success. Again,
1443 * the semantics of the mid-layer recovery engine are not
1444 * well defined, so this may change in time.
1451 struct timer_list timer;
1454 pending_scb->platform_data->flags |= AHD_SCB_UP_EH_SEM;
1455 spin_unlock_irq(&ahd->platform_data->spin_lock);
1457 timer.data = (u_long)pending_scb;
1458 timer.expires = jiffies + (5 * HZ);
1459 timer.function = ahd_linux_sem_timeout;
1461 printf("Recovery code sleeping\n");
1462 down(&ahd->platform_data->eh_sem);
1463 printf("Recovery code awake\n");
1464 ret = del_timer_sync(&timer);
1466 printf("Timer Expired\n");
1469 spin_lock_irq(&ahd->platform_data->spin_lock);
1471 ahd_schedule_runq(ahd);
1472 ahd_linux_run_complete_queue(ahd);
1473 ahd_midlayer_entrypoint_unlock(ahd, &s);
1479 ahd_linux_dev_reset_complete(Scsi_Cmnd *cmd)
1481 free(cmd, M_DEVBUF);
1485 * Attempt to send a target reset message to the device that timed out.
1488 ahd_linux_dev_reset(Scsi_Cmnd *cmd)
1490 struct ahd_softc *ahd;
1491 struct scsi_cmnd *recovery_cmd;
1492 struct ahd_linux_device *dev;
1493 struct ahd_initiator_tinfo *tinfo;
1494 struct ahd_tmode_tstate *tstate;
1496 struct hardware_scb *hscb;
1498 struct timer_list timer;
1501 ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
1502 recovery_cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK);
1505 memset(recovery_cmd, 0, sizeof(struct scsi_cmnd));
1506 recovery_cmd->device = cmd->device;
1507 recovery_cmd->scsi_done = ahd_linux_dev_reset_complete;
1509 if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
1510 printf("%s:%d:%d:%d: Device reset called for cmd %p\n",
1511 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1512 cmd->device->lun, cmd);
1516 dev = ahd_linux_get_device(ahd, cmd->device->channel, cmd->device->id,
1517 cmd->device->lun, /*alloc*/FALSE);
1519 ahd_unlock(ahd, &s);
1520 kfree(recovery_cmd);
1523 if ((scb = ahd_get_scb(ahd, AHD_NEVER_COL_IDX)) == NULL) {
1524 ahd_unlock(ahd, &s);
1525 kfree(recovery_cmd);
1528 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
1529 cmd->device->id, &tstate);
1530 recovery_cmd->result = CAM_REQ_INPROG << 16;
1531 recovery_cmd->host_scribble = (char *)scb;
1532 scb->io_ctx = recovery_cmd;
1533 scb->platform_data->dev = dev;
1535 ahd_set_residual(scb, 0);
1536 ahd_set_sense_residual(scb, 0);
1539 hscb->scsiid = BUILD_SCSIID(ahd, cmd);
1540 hscb->lun = cmd->device->lun;
1542 hscb->task_management = SIU_TASKMGMT_LUN_RESET;
1543 scb->flags |= SCB_DEVICE_RESET|SCB_RECOVERY_SCB|SCB_ACTIVE;
1544 if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
1545 scb->flags |= SCB_PACKETIZED;
1547 hscb->control |= MK_MESSAGE;
1551 dev->commands_issued++;
1552 LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
1553 ahd_queue_scb(ahd, scb);
1555 scb->platform_data->flags |= AHD_SCB_UP_EH_SEM;
1556 spin_unlock_irq(&ahd->platform_data->spin_lock);
1558 timer.data = (u_long)scb;
1559 timer.expires = jiffies + (5 * HZ);
1560 timer.function = ahd_linux_sem_timeout;
1562 printf("Recovery code sleeping\n");
1563 down(&ahd->platform_data->eh_sem);
1564 printf("Recovery code awake\n");
1566 if (del_timer_sync(&timer) == 0) {
1567 printf("Timer Expired\n");
1570 spin_lock_irq(&ahd->platform_data->spin_lock);
1571 ahd_schedule_runq(ahd);
1572 ahd_linux_run_complete_queue(ahd);
1573 ahd_unlock(ahd, &s);
1574 printf("%s: Device reset returning 0x%x\n", ahd_name(ahd), retval);
1579 * Reset the SCSI bus.
1582 ahd_linux_bus_reset(Scsi_Cmnd *cmd)
1584 struct ahd_softc *ahd;
1588 ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
1590 if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
1591 printf("%s: Bus reset called for cmd %p\n",
1592 ahd_name(ahd), cmd);
1595 found = ahd_reset_channel(ahd, cmd->device->channel + 'A',
1596 /*initiate reset*/TRUE);
1597 ahd_linux_run_complete_queue(ahd);
1598 ahd_unlock(ahd, &s);
1601 printf("%s: SCSI bus reset delivered. "
1602 "%d SCBs aborted.\n", ahd_name(ahd), found);
1607 Scsi_Host_Template aic79xx_driver_template = {
1608 .module = THIS_MODULE,
1610 .proc_info = ahd_linux_proc_info,
1611 .info = ahd_linux_info,
1612 .queuecommand = ahd_linux_queue,
1613 .eh_abort_handler = ahd_linux_abort,
1614 .eh_device_reset_handler = ahd_linux_dev_reset,
1615 .eh_bus_reset_handler = ahd_linux_bus_reset,
1616 #if defined(__i386__)
1617 .bios_param = ahd_linux_biosparam,
1619 .can_queue = AHD_MAX_QUEUE,
1622 .use_clustering = ENABLE_CLUSTERING,
1623 .slave_alloc = ahd_linux_slave_alloc,
1624 .slave_configure = ahd_linux_slave_configure,
1625 .slave_destroy = ahd_linux_slave_destroy,
1628 /**************************** Tasklet Handler *********************************/
1631 * In 2.4.X and above, this routine is called from a tasklet,
1632 * so we must re-acquire our lock prior to executing this code.
1633 * In all prior kernels, ahd_schedule_runq() calls this routine
1634 * directly and ahd_schedule_runq() is called with our lock held.
1637 ahd_runq_tasklet(unsigned long data)
1639 struct ahd_softc* ahd;
1640 struct ahd_linux_device *dev;
1643 ahd = (struct ahd_softc *)data;
1644 ahd_lock(ahd, &flags);
1645 while ((dev = ahd_linux_next_device_to_run(ahd)) != NULL) {
1647 TAILQ_REMOVE(&ahd->platform_data->device_runq, dev, links);
1648 dev->flags &= ~AHD_DEV_ON_RUN_LIST;
1649 ahd_linux_check_device_queue(ahd, dev);
1650 /* Yeild to our interrupt handler */
1651 ahd_unlock(ahd, &flags);
1652 ahd_lock(ahd, &flags);
1654 ahd_unlock(ahd, &flags);
1657 /******************************** Bus DMA *************************************/
1659 ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent,
1660 bus_size_t alignment, bus_size_t boundary,
1661 dma_addr_t lowaddr, dma_addr_t highaddr,
1662 bus_dma_filter_t *filter, void *filterarg,
1663 bus_size_t maxsize, int nsegments,
1664 bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
1668 dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT);
1673 * Linux is very simplistic about DMA memory. For now don't
1674 * maintain all specification information. Once Linux supplies
1675 * better facilities for doing these operations, or the
1676 * needs of this particular driver change, we might need to do
1679 dmat->alignment = alignment;
1680 dmat->boundary = boundary;
1681 dmat->maxsize = maxsize;
1687 ahd_dma_tag_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat)
1689 free(dmat, M_DEVBUF);
1693 ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr,
1694 int flags, bus_dmamap_t *mapp)
1698 map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT);
1702 * Although we can dma data above 4GB, our
1703 * "consistent" memory is below 4GB for
1704 * space efficiency reasons (only need a 4byte
1705 * address). For this reason, we have to reset
1706 * our dma mask when doing allocations.
1708 if (ahd->dev_softc != NULL)
1709 if (pci_set_dma_mask(ahd->dev_softc, 0xFFFFFFFF)) {
1710 printk(KERN_WARNING "aic79xx: No suitable DMA available.\n");
1714 *vaddr = pci_alloc_consistent(ahd->dev_softc,
1715 dmat->maxsize, &map->bus_addr);
1716 if (ahd->dev_softc != NULL)
1717 if (pci_set_dma_mask(ahd->dev_softc,
1718 ahd->platform_data->hw_dma_mask)) {
1719 printk(KERN_WARNING "aic79xx: No suitable DMA available.\n");
1730 ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat,
1731 void* vaddr, bus_dmamap_t map)
1733 pci_free_consistent(ahd->dev_softc, dmat->maxsize,
1734 vaddr, map->bus_addr);
1738 ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,
1739 void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
1740 void *cb_arg, int flags)
1743 * Assume for now that this will only be used during
1744 * initialization and not for per-transaction buffer mapping.
1746 bus_dma_segment_t stack_sg;
1748 stack_sg.ds_addr = map->bus_addr;
1749 stack_sg.ds_len = dmat->maxsize;
1750 cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
1755 ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
1758 * The map may is NULL in our < 2.3.X implementation.
1761 free(map, M_DEVBUF);
1765 ahd_dmamap_unload(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
1771 /********************* Platform Dependent Functions ***************************/
1773 * Compare "left hand" softc with "right hand" softc, returning:
1774 * < 0 - lahd has a lower priority than rahd
1775 * 0 - Softcs are equal
1776 * > 0 - lahd has a higher priority than rahd
1779 ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd)
1784 * Under Linux, cards are ordered as follows:
1785 * 1) PCI devices that are marked as the boot controller.
1786 * 2) PCI devices with BIOS enabled sorted by bus/slot/func.
1787 * 3) All remaining PCI devices sorted by bus/slot/func.
1790 value = (lahd->flags & AHD_BOOT_CHANNEL)
1791 - (rahd->flags & AHD_BOOT_CHANNEL);
1793 /* Controllers set for boot have a *higher* priority */
1797 value = (lahd->flags & AHD_BIOS_ENABLED)
1798 - (rahd->flags & AHD_BIOS_ENABLED);
1800 /* Controllers with BIOS enabled have a *higher* priority */
1803 /* Still equal. Sort by bus/slot/func. */
1804 if (aic79xx_reverse_scan != 0)
1805 value = ahd_get_pci_bus(lahd->dev_softc)
1806 - ahd_get_pci_bus(rahd->dev_softc);
1808 value = ahd_get_pci_bus(rahd->dev_softc)
1809 - ahd_get_pci_bus(lahd->dev_softc);
1812 if (aic79xx_reverse_scan != 0)
1813 value = ahd_get_pci_slot(lahd->dev_softc)
1814 - ahd_get_pci_slot(rahd->dev_softc);
1816 value = ahd_get_pci_slot(rahd->dev_softc)
1817 - ahd_get_pci_slot(lahd->dev_softc);
1821 value = rahd->channel - lahd->channel;
1826 ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
1829 if ((instance >= 0) && (targ >= 0)
1830 && (instance < NUM_ELEMENTS(aic79xx_tag_info))
1831 && (targ < AHD_NUM_TARGETS)) {
1832 aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF;
1834 printf("tag_info[%d:%d] = %d\n", instance, targ, value);
1839 ahd_linux_setup_rd_strm_info(u_long arg, int instance, int targ, int32_t value)
1842 && (instance < NUM_ELEMENTS(aic79xx_rd_strm_info))) {
1843 aic79xx_rd_strm_info[instance] = value & 0xFFFF;
1845 printf("rd_strm[%d] = 0x%x\n", instance, value);
1850 ahd_linux_setup_dv(u_long arg, int instance, int targ, int32_t value)
1853 && (instance < NUM_ELEMENTS(aic79xx_dv_settings))) {
1854 aic79xx_dv_settings[instance] = value;
1856 printf("dv[%d] = %d\n", instance, value);
1861 ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value)
1865 && (instance < NUM_ELEMENTS(aic79xx_iocell_info))) {
1866 uint8_t *iocell_info;
1868 iocell_info = (uint8_t*)&aic79xx_iocell_info[instance];
1869 iocell_info[index] = value & 0xFFFF;
1871 printf("iocell[%d:%ld] = %d\n", instance, index, value);
1876 ahd_linux_setup_tag_info_global(char *p)
1880 tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
1881 printf("Setting Global Tags= %d\n", tags);
1883 for (i = 0; i < NUM_ELEMENTS(aic79xx_tag_info); i++) {
1884 for (j = 0; j < AHD_NUM_TARGETS; j++) {
1885 aic79xx_tag_info[i].tag_commands[j] = tags;
1891 * Handle Linux boot parameters. This routine allows for assigning a value
1892 * to a parameter with a ':' between the parameter and the value.
1893 * ie. aic79xx=stpwlev:1,extended
1896 aic79xx_setup(char *s)
1906 { "extended", &aic79xx_extended },
1907 { "no_reset", &aic79xx_no_reset },
1908 { "verbose", &aic79xx_verbose },
1909 { "allow_memio", &aic79xx_allow_memio},
1911 { "debug", &ahd_debug },
1913 { "reverse_scan", &aic79xx_reverse_scan },
1914 { "periodic_otag", &aic79xx_periodic_otag },
1915 { "pci_parity", &aic79xx_pci_parity },
1916 { "seltime", &aic79xx_seltime },
1917 { "tag_info", NULL },
1918 { "global_tag_depth", NULL},
1919 { "rd_strm", NULL },
1921 { "slewrate", NULL },
1922 { "precomp", NULL },
1923 { "amplitude", NULL },
1926 end = strchr(s, '\0');
1929 * XXX ia64 gcc isn't smart enough to know that NUM_ELEMENTS
1930 * will never be 0 in this case.
1934 while ((p = strsep(&s, ",.")) != NULL) {
1937 for (i = 0; i < NUM_ELEMENTS(options); i++) {
1939 n = strlen(options[i].name);
1940 if (strncmp(options[i].name, p, n) == 0)
1943 if (i == NUM_ELEMENTS(options))
1946 if (strncmp(p, "global_tag_depth", n) == 0) {
1947 ahd_linux_setup_tag_info_global(p + n);
1948 } else if (strncmp(p, "tag_info", n) == 0) {
1949 s = aic_parse_brace_option("tag_info", p + n, end,
1950 2, ahd_linux_setup_tag_info, 0);
1951 } else if (strncmp(p, "rd_strm", n) == 0) {
1952 s = aic_parse_brace_option("rd_strm", p + n, end,
1953 1, ahd_linux_setup_rd_strm_info, 0);
1954 } else if (strncmp(p, "dv", n) == 0) {
1955 s = aic_parse_brace_option("dv", p + n, end, 1,
1956 ahd_linux_setup_dv, 0);
1957 } else if (strncmp(p, "slewrate", n) == 0) {
1958 s = aic_parse_brace_option("slewrate",
1959 p + n, end, 1, ahd_linux_setup_iocell_info,
1960 AIC79XX_SLEWRATE_INDEX);
1961 } else if (strncmp(p, "precomp", n) == 0) {
1962 s = aic_parse_brace_option("precomp",
1963 p + n, end, 1, ahd_linux_setup_iocell_info,
1964 AIC79XX_PRECOMP_INDEX);
1965 } else if (strncmp(p, "amplitude", n) == 0) {
1966 s = aic_parse_brace_option("amplitude",
1967 p + n, end, 1, ahd_linux_setup_iocell_info,
1968 AIC79XX_AMPLITUDE_INDEX);
1969 } else if (p[n] == ':') {
1970 *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
1971 } else if (!strncmp(p, "verbose", n)) {
1972 *(options[i].flag) = 1;
1974 *(options[i].flag) ^= 0xFFFFFFFF;
1980 __setup("aic79xx=", aic79xx_setup);
1982 uint32_t aic79xx_verbose;
1985 ahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template)
1988 struct Scsi_Host *host;
1993 template->name = ahd->description;
1994 host = scsi_host_alloc(template, sizeof(struct ahd_softc *));
1998 *((struct ahd_softc **)host->hostdata) = ahd;
2000 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
2001 scsi_assign_lock(host, &ahd->platform_data->spin_lock);
2002 #elif AHD_SCSI_HAS_HOST_LOCK != 0
2003 host->lock = &ahd->platform_data->spin_lock;
2005 ahd->platform_data->host = host;
2006 host->can_queue = AHD_MAX_QUEUE;
2007 host->cmd_per_lun = 2;
2008 host->sg_tablesize = AHD_NSEG;
2009 host->this_id = ahd->our_id;
2010 host->irq = ahd->platform_data->irq;
2011 host->max_id = (ahd->features & AHD_WIDE) ? 16 : 8;
2012 host->max_lun = AHD_NUM_LUNS;
2013 host->max_channel = 0;
2014 host->sg_tablesize = AHD_NSEG;
2015 ahd_set_unit(ahd, ahd_linux_next_unit());
2016 sprintf(buf, "scsi%d", host->host_no);
2017 new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
2018 if (new_name != NULL) {
2019 strcpy(new_name, buf);
2020 ahd_set_name(ahd, new_name);
2022 host->unique_id = ahd->unit;
2023 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
2024 scsi_set_pci_device(host, ahd->dev_softc);
2026 ahd_linux_setup_user_rd_strm_settings(ahd);
2027 ahd_linux_initialize_scsi_bus(ahd);
2028 ahd_unlock(ahd, &s);
2029 ahd->platform_data->dv_pid = kernel_thread(ahd_linux_dv_thread, ahd, 0);
2031 if (ahd->platform_data->dv_pid < 0) {
2032 printf("%s: Failed to create DV thread, error= %d\n",
2033 ahd_name(ahd), ahd->platform_data->dv_pid);
2034 return (-ahd->platform_data->dv_pid);
2037 * Initially allocate *all* of our linux target objects
2038 * so that the DV thread will scan them all in parallel
2039 * just after driver initialization. Any device that
2040 * does not exist will have its target object destroyed
2041 * by the selection timeout handler. In the case of a
2042 * device that appears after the initial DV scan, async
2043 * negotiation will occur for the first command, and DV
2044 * will comence should that first command be successful.
2046 for (target = 0; target < host->max_id; target++) {
2049 * Skip our own ID. Some Compaq/HP storage devices
2050 * have enclosure management devices that respond to
2051 * single bit selection (i.e. selecting ourselves).
2052 * It is expected that either an external application
2053 * or a modified kernel will be used to probe this
2054 * ID if it is appropriate. To accommodate these
2055 * installations, ahc_linux_alloc_target() will allocate
2056 * for our ID if asked to do so.
2058 if (target == ahd->our_id)
2061 ahd_linux_alloc_target(ahd, 0, target);
2063 ahd_intr_enable(ahd, TRUE);
2064 ahd_linux_start_dv(ahd);
2065 ahd_unlock(ahd, &s);
2067 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
2068 scsi_add_host(host, &ahd->dev_softc->dev); /* XXX handle failure */
2069 scsi_scan_host(host);
2075 ahd_linux_get_memsize(void)
2080 return ((uint64_t)si.totalram << PAGE_SHIFT);
2084 * Find the smallest available unit number to use
2085 * for a new device. We don't just use a static
2086 * count to handle the "repeated hot-(un)plug"
2090 ahd_linux_next_unit(void)
2092 struct ahd_softc *ahd;
2097 TAILQ_FOREACH(ahd, &ahd_tailq, links) {
2098 if (ahd->unit == unit) {
2107 * Place the SCSI bus into a known state by either resetting it,
2108 * or forcing transfer negotiations on the next command to any
2112 ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd)
2120 if (aic79xx_no_reset != 0)
2121 ahd->flags &= ~AHD_RESET_BUS_A;
2123 if ((ahd->flags & AHD_RESET_BUS_A) != 0)
2124 ahd_reset_channel(ahd, 'A', /*initiate_reset*/TRUE);
2126 numtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
2129 * Force negotiation to async for all targets that
2130 * will not see an initial bus reset.
2132 for (; target_id < numtarg; target_id++) {
2133 struct ahd_devinfo devinfo;
2134 struct ahd_initiator_tinfo *tinfo;
2135 struct ahd_tmode_tstate *tstate;
2137 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
2138 target_id, &tstate);
2139 ahd_compile_devinfo(&devinfo, ahd->our_id, target_id,
2140 CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR);
2141 ahd_update_neg_request(ahd, &devinfo, tstate,
2142 tinfo, AHD_NEG_ALWAYS);
2144 /* Give the bus some time to recover */
2145 if ((ahd->flags & AHD_RESET_BUS_A) != 0) {
2146 ahd_freeze_simq(ahd);
2147 init_timer(&ahd->platform_data->reset_timer);
2148 ahd->platform_data->reset_timer.data = (u_long)ahd;
2149 ahd->platform_data->reset_timer.expires =
2150 jiffies + (AIC79XX_RESET_DELAY * HZ)/1000;
2151 ahd->platform_data->reset_timer.function =
2152 (ahd_linux_callback_t *)ahd_release_simq;
2153 add_timer(&ahd->platform_data->reset_timer);
2158 ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
2160 ahd->platform_data =
2161 malloc(sizeof(struct ahd_platform_data), M_DEVBUF, M_NOWAIT);
2162 if (ahd->platform_data == NULL)
2164 memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data));
2165 TAILQ_INIT(&ahd->platform_data->completeq);
2166 TAILQ_INIT(&ahd->platform_data->device_runq);
2167 ahd->platform_data->irq = AHD_LINUX_NOIRQ;
2168 ahd->platform_data->hw_dma_mask = 0xFFFFFFFF;
2170 ahd_done_lockinit(ahd);
2171 init_timer(&ahd->platform_data->completeq_timer);
2172 ahd->platform_data->completeq_timer.data = (u_long)ahd;
2173 ahd->platform_data->completeq_timer.function =
2174 (ahd_linux_callback_t *)ahd_linux_thread_run_complete_queue;
2175 init_MUTEX_LOCKED(&ahd->platform_data->eh_sem);
2176 init_MUTEX_LOCKED(&ahd->platform_data->dv_sem);
2177 init_MUTEX_LOCKED(&ahd->platform_data->dv_cmd_sem);
2178 ahd_setup_runq_tasklet(ahd);
2179 ahd->seltime = (aic79xx_seltime & 0x3) << 4;
2184 ahd_platform_free(struct ahd_softc *ahd)
2186 struct ahd_linux_target *targ;
2187 struct ahd_linux_device *dev;
2190 if (ahd->platform_data != NULL) {
2191 del_timer_sync(&ahd->platform_data->completeq_timer);
2192 ahd_linux_kill_dv_thread(ahd);
2193 ahd_teardown_runq_tasklet(ahd);
2194 if (ahd->platform_data->host != NULL) {
2195 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
2196 scsi_remove_host(ahd->platform_data->host);
2198 scsi_host_put(ahd->platform_data->host);
2201 /* destroy all of the device and target objects */
2202 for (i = 0; i < AHD_NUM_TARGETS; i++) {
2203 targ = ahd->platform_data->targets[i];
2205 /* Keep target around through the loop. */
2207 for (j = 0; j < AHD_NUM_LUNS; j++) {
2209 if (targ->devices[j] == NULL)
2211 dev = targ->devices[j];
2212 ahd_linux_free_device(ahd, dev);
2215 * Forcibly free the target now that
2216 * all devices are gone.
2218 ahd_linux_free_target(ahd, targ);
2222 if (ahd->platform_data->irq != AHD_LINUX_NOIRQ)
2223 free_irq(ahd->platform_data->irq, ahd);
2224 if (ahd->tags[0] == BUS_SPACE_PIO
2225 && ahd->bshs[0].ioport != 0)
2226 release_region(ahd->bshs[0].ioport, 256);
2227 if (ahd->tags[1] == BUS_SPACE_PIO
2228 && ahd->bshs[1].ioport != 0)
2229 release_region(ahd->bshs[1].ioport, 256);
2230 if (ahd->tags[0] == BUS_SPACE_MEMIO
2231 && ahd->bshs[0].maddr != NULL) {
2232 iounmap(ahd->bshs[0].maddr);
2233 release_mem_region(ahd->platform_data->mem_busaddr,
2236 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
2238 * In 2.4 we detach from the scsi midlayer before the PCI
2239 * layer invokes our remove callback. No per-instance
2240 * detach is provided, so we must reach inside the PCI
2241 * subsystem's internals and detach our driver manually.
2243 if (ahd->dev_softc != NULL)
2244 ahd->dev_softc->driver = NULL;
2246 free(ahd->platform_data, M_DEVBUF);
2251 ahd_platform_init(struct ahd_softc *ahd)
2254 * Lookup and commit any modified IO Cell options.
2256 if (ahd->unit < NUM_ELEMENTS(aic79xx_iocell_info)) {
2257 struct ahd_linux_iocell_opts *iocell_opts;
2259 iocell_opts = &aic79xx_iocell_info[ahd->unit];
2260 if (iocell_opts->precomp != AIC79XX_DEFAULT_PRECOMP)
2261 AHD_SET_PRECOMP(ahd, iocell_opts->precomp);
2262 if (iocell_opts->slewrate != AIC79XX_DEFAULT_SLEWRATE)
2263 AHD_SET_SLEWRATE(ahd, iocell_opts->slewrate);
2264 if (iocell_opts->amplitude != AIC79XX_DEFAULT_AMPLITUDE)
2265 AHD_SET_AMPLITUDE(ahd, iocell_opts->amplitude);
2271 ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
2273 ahd_platform_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
2274 SCB_GET_CHANNEL(ahd, scb),
2275 SCB_GET_LUN(scb), SCB_LIST_NULL,
2276 ROLE_UNKNOWN, CAM_REQUEUE_REQ);
2280 ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
2283 struct ahd_linux_device *dev;
2287 dev = ahd_linux_get_device(ahd, devinfo->channel - 'A',
2289 devinfo->lun, /*alloc*/FALSE);
2292 was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED);
2295 case AHD_QUEUE_NONE:
2298 case AHD_QUEUE_BASIC:
2299 now_queuing = AHD_DEV_Q_BASIC;
2301 case AHD_QUEUE_TAGGED:
2302 now_queuing = AHD_DEV_Q_TAGGED;
2305 if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) == 0
2306 && (was_queuing != now_queuing)
2307 && (dev->active != 0)) {
2308 dev->flags |= AHD_DEV_FREEZE_TIL_EMPTY;
2312 dev->flags &= ~(AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED|AHD_DEV_PERIODIC_OTAG);
2316 usertags = ahd_linux_user_tagdepth(ahd, devinfo);
2319 * Start out agressively and allow our
2320 * dynamic queue depth algorithm to take
2323 dev->maxtags = usertags;
2324 dev->openings = dev->maxtags - dev->active;
2326 if (dev->maxtags == 0) {
2328 * Queueing is disabled by the user.
2331 } else if (alg == AHD_QUEUE_TAGGED) {
2332 dev->flags |= AHD_DEV_Q_TAGGED;
2333 if (aic79xx_periodic_otag != 0)
2334 dev->flags |= AHD_DEV_PERIODIC_OTAG;
2336 dev->flags |= AHD_DEV_Q_BASIC;
2338 /* We can only have one opening. */
2340 dev->openings = 1 - dev->active;
2342 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
2343 if (dev->scsi_device != NULL) {
2344 switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
2345 case AHD_DEV_Q_BASIC:
2346 scsi_adjust_queue_depth(dev->scsi_device,
2348 dev->openings + dev->active);
2350 case AHD_DEV_Q_TAGGED:
2351 scsi_adjust_queue_depth(dev->scsi_device,
2353 dev->openings + dev->active);
2357 * We allow the OS to queue 2 untagged transactions to
2358 * us at any time even though we can only execute them
2359 * serially on the controller/device. This should
2360 * remove some latency.
2362 scsi_adjust_queue_depth(dev->scsi_device,
2372 ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel,
2373 int lun, u_int tag, role_t role, uint32_t status)
2381 if (tag != SCB_LIST_NULL)
2385 if (target != CAM_TARGET_WILDCARD) {
2389 maxtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
2392 if (lun != CAM_LUN_WILDCARD) {
2396 maxlun = AHD_NUM_LUNS;
2400 for (; targ < maxtarg; targ++) {
2402 for (; clun < maxlun; clun++) {
2403 struct ahd_linux_device *dev;
2404 struct ahd_busyq *busyq;
2405 struct ahd_cmd *acmd;
2407 dev = ahd_linux_get_device(ahd, /*chan*/0, targ,
2408 clun, /*alloc*/FALSE);
2412 busyq = &dev->busyq;
2413 while ((acmd = TAILQ_FIRST(busyq)) != NULL) {
2416 cmd = &acmd_scsi_cmd(acmd);
2417 TAILQ_REMOVE(busyq, acmd,
2420 cmd->result = status << 16;
2421 ahd_linux_queue_cmd_complete(ahd, cmd);
2430 ahd_linux_thread_run_complete_queue(struct ahd_softc *ahd)
2434 ahd_lock(ahd, &flags);
2435 del_timer(&ahd->platform_data->completeq_timer);
2436 ahd->platform_data->flags &= ~AHD_RUN_CMPLT_Q_TIMER;
2437 ahd_linux_run_complete_queue(ahd);
2438 ahd_unlock(ahd, &flags);
2442 ahd_linux_start_dv(struct ahd_softc *ahd)
2446 * Freeze the simq and signal ahd_linux_queue to not let any
2447 * more commands through
2449 if ((ahd->platform_data->flags & AHD_DV_ACTIVE) == 0) {
2451 if (ahd_debug & AHD_SHOW_DV)
2452 printf("%s: Starting DV\n", ahd_name(ahd));
2455 ahd->platform_data->flags |= AHD_DV_ACTIVE;
2456 ahd_freeze_simq(ahd);
2458 /* Wake up the DV kthread */
2459 up(&ahd->platform_data->dv_sem);
2464 ahd_linux_dv_thread(void *data)
2466 struct ahd_softc *ahd;
2470 ahd = (struct ahd_softc *)data;
2473 if (ahd_debug & AHD_SHOW_DV)
2474 printf("In DV Thread\n");
2478 * Complete thread creation.
2481 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,60)
2483 * Don't care about any signals.
2485 siginitsetinv(¤t->blocked, 0);
2488 sprintf(current->comm, "ahd_dv_%d", ahd->unit);
2490 daemonize("ahd_dv_%d", ahd->unit);
2491 current->flags |= PF_NOFREEZE;
2497 * Use down_interruptible() rather than down() to
2498 * avoid inclusion in the load average.
2500 down_interruptible(&ahd->platform_data->dv_sem);
2502 /* Check to see if we've been signaled to exit */
2504 if ((ahd->platform_data->flags & AHD_DV_SHUTDOWN) != 0) {
2505 ahd_unlock(ahd, &s);
2508 ahd_unlock(ahd, &s);
2511 if (ahd_debug & AHD_SHOW_DV)
2512 printf("%s: Beginning Domain Validation\n",
2517 * Wait for any pending commands to drain before proceeding.
2520 while (LIST_FIRST(&ahd->pending_scbs) != NULL) {
2521 ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_EMPTY;
2522 ahd_unlock(ahd, &s);
2523 down_interruptible(&ahd->platform_data->dv_sem);
2528 * Wait for the SIMQ to be released so that DV is the
2529 * only reason the queue is frozen.
2531 while (AHD_DV_SIMQ_FROZEN(ahd) == 0) {
2532 ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE;
2533 ahd_unlock(ahd, &s);
2534 down_interruptible(&ahd->platform_data->dv_sem);
2537 ahd_unlock(ahd, &s);
2539 for (target = 0; target < AHD_NUM_TARGETS; target++)
2540 ahd_linux_dv_target(ahd, target);
2543 ahd->platform_data->flags &= ~AHD_DV_ACTIVE;
2544 ahd_unlock(ahd, &s);
2547 * Release the SIMQ so that normal commands are
2548 * allowed to continue on the bus.
2550 ahd_release_simq(ahd);
2552 up(&ahd->platform_data->eh_sem);
2557 ahd_linux_kill_dv_thread(struct ahd_softc *ahd)
2562 if (ahd->platform_data->dv_pid != 0) {
2563 ahd->platform_data->flags |= AHD_DV_SHUTDOWN;
2564 ahd_unlock(ahd, &s);
2565 up(&ahd->platform_data->dv_sem);
2568 * Use the eh_sem as an indicator that the
2569 * dv thread is exiting. Note that the dv
2570 * thread must still return after performing
2571 * the up on our semaphore before it has
2572 * completely exited this module. Unfortunately,
2573 * there seems to be no easy way to wait for the
2574 * exit of a thread for which you are not the
2575 * parent (dv threads are parented by init).
2576 * Cross your fingers...
2578 down(&ahd->platform_data->eh_sem);
2581 * Mark the dv thread as already dead. This
2582 * avoids attempting to kill it a second time.
2583 * This is necessary because we must kill the
2584 * DV thread before calling ahd_free() in the
2585 * module shutdown case to avoid bogus locking
2586 * in the SCSI mid-layer, but we ahd_free() is
2587 * called without killing the DV thread in the
2588 * instance detach case, so ahd_platform_free()
2589 * calls us again to verify that the DV thread
2592 ahd->platform_data->dv_pid = 0;
2594 ahd_unlock(ahd, &s);
2598 #define AHD_LINUX_DV_INQ_SHORT_LEN 36
2599 #define AHD_LINUX_DV_INQ_LEN 256
2600 #define AHD_LINUX_DV_TIMEOUT (HZ / 4)
2602 #define AHD_SET_DV_STATE(ahd, targ, newstate) \
2603 ahd_set_dv_state(ahd, targ, newstate, __LINE__)
2605 static __inline void
2606 ahd_set_dv_state(struct ahd_softc *ahd, struct ahd_linux_target *targ,
2607 ahd_dv_state newstate, u_int line)
2609 ahd_dv_state oldstate;
2611 oldstate = targ->dv_state;
2613 if (ahd_debug & AHD_SHOW_DV)
2614 printf("%s:%d: Going from state %d to state %d\n",
2615 ahd_name(ahd), line, oldstate, newstate);
2618 if (oldstate == newstate)
2619 targ->dv_state_retry++;
2621 targ->dv_state_retry = 0;
2622 targ->dv_state = newstate;
2626 ahd_linux_dv_target(struct ahd_softc *ahd, u_int target_offset)
2628 struct ahd_devinfo devinfo;
2629 struct ahd_linux_target *targ;
2630 struct scsi_cmnd *cmd;
2631 struct scsi_device *scsi_dev;
2632 struct scsi_sense_data *sense;
2642 targ = ahd->platform_data->targets[target_offset];
2643 if (targ == NULL || (targ->flags & AHD_DV_REQUIRED) == 0) {
2644 ahd_unlock(ahd, &s);
2647 ahd_compile_devinfo(&devinfo, ahd->our_id, targ->target, /*lun*/0,
2648 targ->channel + 'A', ROLE_INITIATOR);
2650 if (ahd_debug & AHD_SHOW_DV) {
2651 ahd_print_devinfo(ahd, &devinfo);
2652 printf("Performing DV\n");
2656 ahd_unlock(ahd, &s);
2658 cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK);
2659 scsi_dev = malloc(sizeof(struct scsi_device), M_DEVBUF, M_WAITOK);
2660 scsi_dev->host = ahd->platform_data->host;
2661 scsi_dev->id = devinfo.target;
2662 scsi_dev->lun = devinfo.lun;
2663 scsi_dev->channel = devinfo.channel - 'A';
2664 ahd->platform_data->dv_scsi_dev = scsi_dev;
2666 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_INQ_SHORT_ASYNC);
2668 while (targ->dv_state != AHD_DV_STATE_EXIT) {
2669 timeout = AHD_LINUX_DV_TIMEOUT;
2670 switch (targ->dv_state) {
2671 case AHD_DV_STATE_INQ_SHORT_ASYNC:
2672 case AHD_DV_STATE_INQ_ASYNC:
2673 case AHD_DV_STATE_INQ_ASYNC_VERIFY:
2675 * Set things to async narrow to reduce the
2676 * chance that the INQ will fail.
2679 ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
2680 AHD_TRANS_GOAL, /*paused*/FALSE);
2681 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
2682 AHD_TRANS_GOAL, /*paused*/FALSE);
2683 ahd_unlock(ahd, &s);
2685 targ->flags &= ~AHD_INQ_VALID;
2687 case AHD_DV_STATE_INQ_VERIFY:
2691 if (targ->dv_state == AHD_DV_STATE_INQ_SHORT_ASYNC)
2692 inq_len = AHD_LINUX_DV_INQ_SHORT_LEN;
2694 inq_len = targ->inq_data->additional_length + 5;
2695 ahd_linux_dv_inq(ahd, cmd, &devinfo, targ, inq_len);
2698 case AHD_DV_STATE_TUR:
2699 case AHD_DV_STATE_BUSY:
2701 ahd_linux_dv_tur(ahd, cmd, &devinfo);
2703 case AHD_DV_STATE_REBD:
2704 ahd_linux_dv_rebd(ahd, cmd, &devinfo, targ);
2706 case AHD_DV_STATE_WEB:
2707 ahd_linux_dv_web(ahd, cmd, &devinfo, targ);
2710 case AHD_DV_STATE_REB:
2711 ahd_linux_dv_reb(ahd, cmd, &devinfo, targ);
2714 case AHD_DV_STATE_SU:
2715 ahd_linux_dv_su(ahd, cmd, &devinfo, targ);
2720 ahd_print_devinfo(ahd, &devinfo);
2721 printf("Unknown DV state %d\n", targ->dv_state);
2725 /* Queue the command and wait for it to complete */
2726 /* Abuse eh_timeout in the scsi_cmnd struct for our purposes */
2727 init_timer(&cmd->eh_timeout);
2729 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
2731 * All of the printfs during negotiation
2732 * really slow down the negotiation.
2733 * Add a bit of time just to be safe.
2737 scsi_add_timer(cmd, timeout, ahd_linux_dv_timeout);
2739 * In 2.5.X, it is assumed that all calls from the
2740 * "midlayer" (which we are emulating) will have the
2741 * ahd host lock held. For other kernels, the
2742 * io_request_lock must be held.
2744 #if AHD_SCSI_HAS_HOST_LOCK != 0
2747 spin_lock_irqsave(&io_request_lock, s);
2749 ahd_linux_queue(cmd, ahd_linux_dv_complete);
2750 #if AHD_SCSI_HAS_HOST_LOCK != 0
2751 ahd_unlock(ahd, &s);
2753 spin_unlock_irqrestore(&io_request_lock, s);
2755 down_interruptible(&ahd->platform_data->dv_cmd_sem);
2757 * Wait for the SIMQ to be released so that DV is the
2758 * only reason the queue is frozen.
2761 while (AHD_DV_SIMQ_FROZEN(ahd) == 0) {
2762 ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE;
2763 ahd_unlock(ahd, &s);
2764 down_interruptible(&ahd->platform_data->dv_sem);
2767 ahd_unlock(ahd, &s);
2769 ahd_linux_dv_transition(ahd, cmd, &devinfo, targ);
2773 if ((targ->flags & AHD_INQ_VALID) != 0
2774 && ahd_linux_get_device(ahd, devinfo.channel - 'A',
2775 devinfo.target, devinfo.lun,
2776 /*alloc*/FALSE) == NULL) {
2778 * The DV state machine failed to configure this device.
2779 * This is normal if DV is disabled. Since we have inquiry
2780 * data, filter it and use the "optimistic" negotiation
2781 * parameters found in the inquiry string.
2783 ahd_linux_filter_inquiry(ahd, &devinfo);
2784 if ((targ->flags & (AHD_BASIC_DV|AHD_ENHANCED_DV)) != 0) {
2785 ahd_print_devinfo(ahd, &devinfo);
2786 printf("DV failed to configure device. "
2787 "Please file a bug report against "
2793 free(cmd, M_DEVBUF);
2795 if (ahd->platform_data->dv_scsi_dev != NULL) {
2796 free(ahd->platform_data->dv_scsi_dev, M_DEVBUF);
2797 ahd->platform_data->dv_scsi_dev = NULL;
2801 if (targ->dv_buffer != NULL) {
2802 free(targ->dv_buffer, M_DEVBUF);
2803 targ->dv_buffer = NULL;
2805 if (targ->dv_buffer1 != NULL) {
2806 free(targ->dv_buffer1, M_DEVBUF);
2807 targ->dv_buffer1 = NULL;
2809 targ->flags &= ~AHD_DV_REQUIRED;
2810 if (targ->refcount == 0)
2811 ahd_linux_free_target(ahd, targ);
2812 ahd_unlock(ahd, &s);
2816 ahd_linux_dv_fallback(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
2822 retval = ahd_linux_fallback(ahd, devinfo);
2823 ahd_unlock(ahd, &s);
2829 ahd_linux_dv_transition(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
2830 struct ahd_devinfo *devinfo,
2831 struct ahd_linux_target *targ)
2835 status = aic_error_action(cmd, targ->inq_data,
2836 ahd_cmd_get_transaction_status(cmd),
2837 ahd_cmd_get_scsi_status(cmd));
2841 if (ahd_debug & AHD_SHOW_DV) {
2842 ahd_print_devinfo(ahd, devinfo);
2843 printf("Entering ahd_linux_dv_transition, state= %d, "
2844 "status= 0x%x, cmd->result= 0x%x\n", targ->dv_state,
2845 status, cmd->result);
2849 switch (targ->dv_state) {
2850 case AHD_DV_STATE_INQ_SHORT_ASYNC:
2851 case AHD_DV_STATE_INQ_ASYNC:
2852 switch (status & SS_MASK) {
2855 AHD_SET_DV_STATE(ahd, targ, targ->dv_state+1);
2858 case SS_INQ_REFRESH:
2859 AHD_SET_DV_STATE(ahd, targ,
2860 AHD_DV_STATE_INQ_SHORT_ASYNC);
2864 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
2865 if (ahd_cmd_get_transaction_status(cmd)
2867 targ->dv_state_retry--;
2868 if ((status & SS_ERRMASK) == EBUSY)
2869 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
2870 if (targ->dv_state_retry < 10)
2874 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
2876 if (ahd_debug & AHD_SHOW_DV) {
2877 ahd_print_devinfo(ahd, devinfo);
2878 printf("Failed DV inquiry, skipping\n");
2884 case AHD_DV_STATE_INQ_ASYNC_VERIFY:
2885 switch (status & SS_MASK) {
2891 if (memcmp(targ->inq_data, targ->dv_buffer,
2892 AHD_LINUX_DV_INQ_LEN) != 0) {
2894 * Inquiry data must have changed.
2895 * Try from the top again.
2897 AHD_SET_DV_STATE(ahd, targ,
2898 AHD_DV_STATE_INQ_SHORT_ASYNC);
2902 AHD_SET_DV_STATE(ahd, targ, targ->dv_state+1);
2903 targ->flags |= AHD_INQ_VALID;
2904 if (ahd_linux_user_dv_setting(ahd) == 0)
2907 xportflags = targ->inq_data->flags;
2908 if ((xportflags & (SID_Sync|SID_WBus16)) == 0)
2911 spi3data = targ->inq_data->spi3data;
2912 switch (spi3data & SID_SPI_CLOCK_DT_ST) {
2914 case SID_SPI_CLOCK_ST:
2915 /* Assume only basic DV is supported. */
2916 targ->flags |= AHD_BASIC_DV;
2918 case SID_SPI_CLOCK_DT:
2919 case SID_SPI_CLOCK_DT_ST:
2920 targ->flags |= AHD_ENHANCED_DV;
2925 case SS_INQ_REFRESH:
2926 AHD_SET_DV_STATE(ahd, targ,
2927 AHD_DV_STATE_INQ_SHORT_ASYNC);
2931 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
2932 if (ahd_cmd_get_transaction_status(cmd)
2934 targ->dv_state_retry--;
2936 if ((status & SS_ERRMASK) == EBUSY)
2937 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
2938 if (targ->dv_state_retry < 10)
2942 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
2944 if (ahd_debug & AHD_SHOW_DV) {
2945 ahd_print_devinfo(ahd, devinfo);
2946 printf("Failed DV inquiry, skipping\n");
2952 case AHD_DV_STATE_INQ_VERIFY:
2953 switch (status & SS_MASK) {
2957 if (memcmp(targ->inq_data, targ->dv_buffer,
2958 AHD_LINUX_DV_INQ_LEN) == 0) {
2959 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
2964 if (ahd_debug & AHD_SHOW_DV) {
2967 ahd_print_devinfo(ahd, devinfo);
2968 printf("Inquiry buffer mismatch:");
2969 for (i = 0; i < AHD_LINUX_DV_INQ_LEN; i++) {
2972 printf("0x%x:0x0%x ",
2973 ((uint8_t *)targ->inq_data)[i],
2974 targ->dv_buffer[i]);
2980 if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
2981 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
2985 * Do not count "falling back"
2986 * against our retries.
2988 targ->dv_state_retry = 0;
2989 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
2992 case SS_INQ_REFRESH:
2993 AHD_SET_DV_STATE(ahd, targ,
2994 AHD_DV_STATE_INQ_SHORT_ASYNC);
2998 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
2999 if (ahd_cmd_get_transaction_status(cmd)
3000 == CAM_REQUEUE_REQ) {
3001 targ->dv_state_retry--;
3002 } else if ((status & SSQ_FALLBACK) != 0) {
3003 if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
3004 AHD_SET_DV_STATE(ahd, targ,
3009 * Do not count "falling back"
3010 * against our retries.
3012 targ->dv_state_retry = 0;
3013 } else if ((status & SS_ERRMASK) == EBUSY)
3014 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
3015 if (targ->dv_state_retry < 10)
3019 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3021 if (ahd_debug & AHD_SHOW_DV) {
3022 ahd_print_devinfo(ahd, devinfo);
3023 printf("Failed DV inquiry, skipping\n");
3030 case AHD_DV_STATE_TUR:
3031 switch (status & SS_MASK) {
3033 if ((targ->flags & AHD_BASIC_DV) != 0) {
3034 ahd_linux_filter_inquiry(ahd, devinfo);
3035 AHD_SET_DV_STATE(ahd, targ,
3036 AHD_DV_STATE_INQ_VERIFY);
3037 } else if ((targ->flags & AHD_ENHANCED_DV) != 0) {
3038 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_REBD);
3040 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3045 if ((status & SS_ERRMASK) == EBUSY) {
3046 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
3049 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
3050 if (ahd_cmd_get_transaction_status(cmd)
3051 == CAM_REQUEUE_REQ) {
3052 targ->dv_state_retry--;
3053 } else if ((status & SSQ_FALLBACK) != 0) {
3054 if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
3055 AHD_SET_DV_STATE(ahd, targ,
3060 * Do not count "falling back"
3061 * against our retries.
3063 targ->dv_state_retry = 0;
3065 if (targ->dv_state_retry >= 10) {
3067 if (ahd_debug & AHD_SHOW_DV) {
3068 ahd_print_devinfo(ahd, devinfo);
3069 printf("DV TUR reties exhausted\n");
3072 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3075 if (status & SSQ_DELAY)
3080 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_SU);
3082 case SS_INQ_REFRESH:
3083 AHD_SET_DV_STATE(ahd, targ,
3084 AHD_DV_STATE_INQ_SHORT_ASYNC);
3087 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3092 case AHD_DV_STATE_REBD:
3093 switch (status & SS_MASK) {