2 * Adaptec AIC7xxx device driver for Linux.
4 * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.c#235 $
6 * Copyright (c) 1994 John Aycock
7 * The University of Calgary Department of Computer Science.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; see the file COPYING. If not, write to
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Sources include the Adaptec 1740 driver (aha1740.c), the Ultrastor 24F
24 * driver (ultrastor.c), various Linux kernel source, the Adaptec EISA
25 * config file (!adp7771.cfg), the Adaptec AHA-2740A Series User's Guide,
26 * the Linux Kernel Hacker's Guide, Writing a SCSI Device Driver for Linux,
27 * the Adaptec 1542 driver (aha1542.c), the Adaptec EISA overlay file
28 * (adp7770.ovl), the Adaptec AHA-2740 Series Technical Reference Manual,
29 * the Adaptec AIC-7770 Data Book, the ANSI SCSI specification, the
30 * ANSI SCSI-2 specification (draft 10c), ...
32 * --------------------------------------------------------------------------
34 * Modifications by Daniel M. Eischen (deischen@iworks.InterWorks.org):
36 * Substantially modified to include support for wide and twin bus
37 * adapters, DMAing of SCBs, tagged queueing, IRQ sharing, bug fixes,
38 * SCB paging, and other rework of the code.
40 * --------------------------------------------------------------------------
41 * Copyright (c) 1994-2000 Justin T. Gibbs.
42 * Copyright (c) 2000-2001 Adaptec Inc.
43 * All rights reserved.
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions, and the following disclaimer,
50 * without modification.
51 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
52 * substantially similar to the "NO WARRANTY" disclaimer below
53 * ("Disclaimer") and any redistribution must be conditioned upon
54 * including a substantially similar Disclaimer requirement for further
55 * binary redistribution.
56 * 3. Neither the names of the above-listed copyright holders nor the names
57 * of any contributors may be used to endorse or promote products derived
58 * from this software without specific prior written permission.
60 * Alternatively, this software may be distributed under the terms of the
61 * GNU General Public License ("GPL") version 2 as published by the Free
62 * Software Foundation.
65 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
66 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
67 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
68 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
69 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
70 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
71 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
72 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
73 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
74 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
75 * POSSIBILITY OF SUCH DAMAGES.
77 *---------------------------------------------------------------------------
79 * Thanks also go to (in alphabetical order) the following:
81 * Rory Bolt - Sequencer bug fixes
82 * Jay Estabrook - Initial DEC Alpha support
83 * Doug Ledford - Much needed abort/reset bug fixes
84 * Kai Makisara - DMAing of SCBs
86 * A Boot time option was also added for not resetting the scsi bus.
88 * Form: aic7xxx=extended
92 * Daniel M. Eischen, deischen@iworks.InterWorks.org, 1/23/97
94 * Id: aic7xxx.c,v 4.1 1997/06/12 08:23:42 deang Exp
98 * Further driver modifications made by Doug Ledford <dledford@redhat.com>
100 * Copyright (c) 1997-1999 Doug Ledford
102 * These changes are released under the same licensing terms as the FreeBSD
103 * driver written by Justin Gibbs. Please see his Copyright notice above
104 * for the exact terms and conditions covering my changes as well as the
105 * warranty statement.
107 * Modifications made to the aic7xxx.c,v 4.1 driver from Dan Eischen include
108 * but are not limited to:
110 * 1: Import of the latest FreeBSD sequencer code for this driver
111 * 2: Modification of kernel code to accommodate different sequencer semantics
112 * 3: Extensive changes throughout kernel portion of driver to improve
113 * abort/reset processing and error hanndling
114 * 4: Other work contributed by various people on the Internet
115 * 5: Changes to printk information and verbosity selection code
116 * 6: General reliability related changes, especially in IRQ management
117 * 7: Modifications to the default probe/attach order for supported cards
118 * 8: SMP friendliness has been improved
122 #include "aic7xxx_osm.h"
123 #include "aic7xxx_inline.h"
124 #include <scsi/scsicam.h>
127 * Include aiclib.c as part of our
128 * "module dependencies are hard" work around.
132 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
133 #include <linux/init.h> /* __setup */
137 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
138 #include "sd.h" /* For geometry detection */
141 #include <linux/mm.h> /* For fetching system memory size */
142 #include <linux/blkdev.h> /* For block_size() */
143 #include <linux/delay.h> /* For ssleep/msleep */
146 * Lock protecting manipulation of the ahc softc list.
148 spinlock_t ahc_list_spinlock
;
150 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
151 /* For dynamic sglist size calculation. */
152 u_int ahc_linux_nseg
;
155 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
156 struct proc_dir_entry proc_scsi_aic7xxx
= {
157 PROC_SCSI_AIC7XXX
, 7, "aic7xxx",
158 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2,
159 0, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
164 * Set this to the delay in seconds after SCSI bus reset.
165 * Note, we honor this only for the initial bus reset.
166 * The scsi error recovery code performs its own bus settle
167 * delay handling for error recovery actions.
169 #ifdef CONFIG_AIC7XXX_RESET_DELAY_MS
170 #define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RESET_DELAY_MS
172 #define AIC7XXX_RESET_DELAY 5000
176 * Control collection of SCSI transfer statistics for the /proc filesystem.
178 * NOTE: Do NOT enable this when running on kernels version 1.2.x and below.
179 * NOTE: This does affect performance since it has to maintain statistics.
181 #ifdef CONFIG_AIC7XXX_PROC_STATS
182 #define AIC7XXX_PROC_STATS
186 * To change the default number of tagged transactions allowed per-device,
187 * add a line to the lilo.conf file like:
188 * append="aic7xxx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
189 * which will result in the first four devices on the first two
190 * controllers being set to a tagged queue depth of 32.
192 * The tag_commands is an array of 16 to allow for wide and twin adapters.
193 * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15
197 uint8_t tag_commands
[16]; /* Allow for wide/twin adapters. */
198 } adapter_tag_info_t
;
201 * Modify this as you see fit for your system.
203 * 0 tagged queuing disabled
204 * 1 <= n <= 253 n == max tags ever dispatched.
206 * The driver will throttle the number of commands dispatched to a
207 * device if it returns queue full. For devices with a fixed maximum
208 * queue depth, the driver will eventually determine this depth and
209 * lock it in (a console message is printed to indicate that a lock
210 * has occurred). On some devices, queue full is returned for a temporary
211 * resource shortage. These devices will return queue full at varying
212 * depths. The driver will throttle back when the queue fulls occur and
213 * attempt to slowly increase the depth over time as the device recovers
214 * from the resource shortage.
216 * In this example, the first line will disable tagged queueing for all
217 * the devices on the first probed aic7xxx adapter.
219 * The second line enables tagged queueing with 4 commands/LUN for IDs
220 * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
221 * driver to attempt to use up to 64 tags for ID 1.
223 * The third line is the same as the first line.
225 * The fourth line disables tagged queueing for devices 0 and 3. It
226 * enables tagged queueing for the other IDs, with 16 commands/LUN
227 * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
228 * IDs 2, 5-7, and 9-15.
232 * NOTE: The below structure is for reference only, the actual structure
233 * to modify in order to change things is just below this comment block.
234 adapter_tag_info_t aic7xxx_tag_info[] =
236 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
237 {{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}},
238 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
239 {{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
243 #ifdef CONFIG_AIC7XXX_CMDS_PER_DEVICE
244 #define AIC7XXX_CMDS_PER_DEVICE CONFIG_AIC7XXX_CMDS_PER_DEVICE
246 #define AIC7XXX_CMDS_PER_DEVICE AHC_MAX_QUEUE
249 #define AIC7XXX_CONFIGED_TAG_COMMANDS { \
250 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
251 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
252 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
253 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
254 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
255 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
256 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
257 AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE \
261 * By default, use the number of commands specified by
262 * the users kernel configuration.
264 static adapter_tag_info_t aic7xxx_tag_info
[] =
266 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
267 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
268 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
269 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
270 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
271 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
272 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
273 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
274 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
275 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
276 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
277 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
278 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
279 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
280 {AIC7XXX_CONFIGED_TAG_COMMANDS
},
281 {AIC7XXX_CONFIGED_TAG_COMMANDS
}
287 * positive value = DV Enabled
289 * negative value = DV Default for adapter type/seeprom
291 #ifdef CONFIG_AIC7XXX_DV_SETTING
292 #define AIC7XXX_CONFIGED_DV CONFIG_AIC7XXX_DV_SETTING
294 #define AIC7XXX_CONFIGED_DV -1
297 static int8_t aic7xxx_dv_settings
[] =
318 * There should be a specific return value for this in scsi.h, but
319 * it seems that most drivers ignore it.
321 #define DID_UNDERFLOW DID_ERROR
324 ahc_print_path(struct ahc_softc
*ahc
, struct scb
*scb
)
326 printk("(scsi%d:%c:%d:%d): ",
327 ahc
->platform_data
->host
->host_no
,
328 scb
!= NULL
? SCB_GET_CHANNEL(ahc
, scb
) : 'X',
329 scb
!= NULL
? SCB_GET_TARGET(ahc
, scb
) : -1,
330 scb
!= NULL
? SCB_GET_LUN(scb
) : -1);
334 * XXX - these options apply unilaterally to _all_ 274x/284x/294x
335 * cards in the system. This should be fixed. Exceptions to this
336 * rule are noted in the comments.
340 * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
341 * has no effect on any later resets that might occur due to things like
344 static uint32_t aic7xxx_no_reset
;
347 * Certain PCI motherboards will scan PCI devices from highest to lowest,
348 * others scan from lowest to highest, and they tend to do all kinds of
349 * strange things when they come into contact with PCI bridge chips. The
350 * net result of all this is that the PCI card that is actually used to boot
351 * the machine is very hard to detect. Most motherboards go from lowest
352 * PCI slot number to highest, and the first SCSI controller found is the
353 * one you boot from. The only exceptions to this are when a controller
354 * has its BIOS disabled. So, we by default sort all of our SCSI controllers
355 * from lowest PCI slot number to highest PCI slot number. We also force
356 * all controllers with their BIOS disabled to the end of the list. This
357 * works on *almost* all computers. Where it doesn't work, we have this
358 * option. Setting this option to non-0 will reverse the order of the sort
359 * to highest first, then lowest, but will still leave cards with their BIOS
360 * disabled at the very end. That should fix everyone up unless there are
361 * really strange cirumstances.
363 static uint32_t aic7xxx_reverse_scan
;
366 * Should we force EXTENDED translation on a controller.
367 * 0 == Use whatever is in the SEEPROM or default to off
368 * 1 == Use whatever is in the SEEPROM or default to on
370 static uint32_t aic7xxx_extended
;
373 * PCI bus parity checking of the Adaptec controllers. This is somewhat
374 * dubious at best. To my knowledge, this option has never actually
375 * solved a PCI parity problem, but on certain machines with broken PCI
376 * chipset configurations where stray PCI transactions with bad parity are
377 * the norm rather than the exception, the error messages can be overwelming.
378 * It's included in the driver for completeness.
379 * 0 = Shut off PCI parity check
380 * non-0 = reverse polarity pci parity checking
382 static uint32_t aic7xxx_pci_parity
= ~0;
385 * Certain newer motherboards have put new PCI based devices into the
386 * IO spaces that used to typically be occupied by VLB or EISA cards.
387 * This overlap can cause these newer motherboards to lock up when scanned
388 * for older EISA and VLB devices. Setting this option to non-0 will
389 * cause the driver to skip scanning for any VLB or EISA controllers and
390 * only support the PCI controllers. NOTE: this means that if the kernel
391 * os compiled with PCI support disabled, then setting this to non-0
392 * would result in never finding any devices :)
394 #ifndef CONFIG_AIC7XXX_PROBE_EISA_VL
395 uint32_t aic7xxx_probe_eisa_vl
;
397 uint32_t aic7xxx_probe_eisa_vl
= ~0;
401 * There are lots of broken chipsets in the world. Some of them will
402 * violate the PCI spec when we issue byte sized memory writes to our
403 * controller. I/O mapped register access, if allowed by the given
404 * platform, will work in almost all cases.
406 uint32_t aic7xxx_allow_memio
= ~0;
409 * aic7xxx_detect() has been run, so register all device arrivals
410 * immediately with the system rather than deferring to the sorted
411 * attachment performed by aic7xxx_detect().
413 int aic7xxx_detect_complete
;
416 * So that we can set how long each device is given as a selection timeout.
417 * The table of values goes like this:
422 * We default to 256ms because some older devices need a longer time
423 * to respond to initial selection.
425 static uint32_t aic7xxx_seltime
;
428 * Certain devices do not perform any aging on commands. Should the
429 * device be saturated by commands in one portion of the disk, it is
430 * possible for transactions on far away sectors to never be serviced.
431 * To handle these devices, we can periodically send an ordered tag to
432 * force all outstanding transactions to be serviced prior to a new
435 uint32_t aic7xxx_periodic_otag
;
438 * Module information and settable options.
440 static char *aic7xxx
= NULL
;
442 * Just in case someone uses commas to separate items on the insmod
443 * command line, we define a dummy buffer here to avoid having insmod
444 * write wild stuff into our code segment
446 static char dummy_buffer
[60] = "Please don't trounce on me insmod!!\n";
448 MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>");
449 MODULE_DESCRIPTION("Adaptec Aic77XX/78XX SCSI Host Bus Adapter driver");
450 MODULE_LICENSE("Dual BSD/GPL");
451 MODULE_VERSION(AIC7XXX_DRIVER_VERSION
);
452 MODULE_PARM(aic7xxx
, "s");
453 MODULE_PARM_DESC(aic7xxx
,
454 "period delimited, options string.\n"
455 " verbose Enable verbose/diagnostic logging\n"
456 " allow_memio Allow device registers to be memory mapped\n"
457 " debug Bitmask of debug values to enable\n"
458 " no_probe Toggle EISA/VLB controller probing\n"
459 " probe_eisa_vl Toggle EISA/VLB controller probing\n"
460 " no_reset Supress initial bus resets\n"
461 " extended Enable extended geometry on all controllers\n"
462 " periodic_otag Send an ordered tagged transaction\n"
463 " periodically to prevent tag starvation.\n"
464 " This may be required by some older disk\n"
465 " drives or RAID arrays.\n"
466 " reverse_scan Sort PCI devices highest Bus/Slot to lowest\n"
467 " tag_info:<tag_str> Set per-target tag depth\n"
468 " global_tag_depth:<int> Global tag depth for every target\n"
470 " dv:<dv_settings> Set per-controller Domain Validation Setting.\n"
471 " seltime:<int> Selection Timeout\n"
472 " (0/256ms,1/128ms,2/64ms,3/32ms)\n"
474 " Sample /etc/modprobe.conf line:\n"
475 " Toggle EISA/VLB probing\n"
476 " Set tag depth on Controller 1/Target 1 to 10 tags\n"
477 " Shorten the selection timeout to 128ms\n"
479 " options aic7xxx 'aic7xxx=probe_eisa_vl.tag_info:{{}.{.10}}.seltime:1'\n"
482 static void ahc_linux_handle_scsi_status(struct ahc_softc
*,
483 struct ahc_linux_device
*,
485 static void ahc_linux_queue_cmd_complete(struct ahc_softc
*ahc
,
487 static void ahc_linux_filter_inquiry(struct ahc_softc
*, struct ahc_devinfo
*);
488 static void ahc_linux_sem_timeout(u_long arg
);
489 static void ahc_linux_freeze_simq(struct ahc_softc
*ahc
);
490 static void ahc_linux_release_simq(u_long arg
);
491 static void ahc_linux_dev_timed_unfreeze(u_long arg
);
492 static int ahc_linux_queue_recovery_cmd(Scsi_Cmnd
*cmd
, scb_flag flag
);
493 static void ahc_linux_initialize_scsi_bus(struct ahc_softc
*ahc
);
494 static void ahc_linux_size_nseg(void);
495 static void ahc_linux_thread_run_complete_queue(struct ahc_softc
*ahc
);
496 static void ahc_linux_start_dv(struct ahc_softc
*ahc
);
497 static void ahc_linux_dv_timeout(struct scsi_cmnd
*cmd
);
498 static int ahc_linux_dv_thread(void *data
);
499 static void ahc_linux_kill_dv_thread(struct ahc_softc
*ahc
);
500 static void ahc_linux_dv_target(struct ahc_softc
*ahc
, u_int target
);
501 static void ahc_linux_dv_transition(struct ahc_softc
*ahc
,
502 struct scsi_cmnd
*cmd
,
503 struct ahc_devinfo
*devinfo
,
504 struct ahc_linux_target
*targ
);
505 static void ahc_linux_dv_fill_cmd(struct ahc_softc
*ahc
,
506 struct scsi_cmnd
*cmd
,
507 struct ahc_devinfo
*devinfo
);
508 static void ahc_linux_dv_inq(struct ahc_softc
*ahc
,
509 struct scsi_cmnd
*cmd
,
510 struct ahc_devinfo
*devinfo
,
511 struct ahc_linux_target
*targ
,
512 u_int request_length
);
513 static void ahc_linux_dv_tur(struct ahc_softc
*ahc
,
514 struct scsi_cmnd
*cmd
,
515 struct ahc_devinfo
*devinfo
);
516 static void ahc_linux_dv_rebd(struct ahc_softc
*ahc
,
517 struct scsi_cmnd
*cmd
,
518 struct ahc_devinfo
*devinfo
,
519 struct ahc_linux_target
*targ
);
520 static void ahc_linux_dv_web(struct ahc_softc
*ahc
,
521 struct scsi_cmnd
*cmd
,
522 struct ahc_devinfo
*devinfo
,
523 struct ahc_linux_target
*targ
);
524 static void ahc_linux_dv_reb(struct ahc_softc
*ahc
,
525 struct scsi_cmnd
*cmd
,
526 struct ahc_devinfo
*devinfo
,
527 struct ahc_linux_target
*targ
);
528 static void ahc_linux_dv_su(struct ahc_softc
*ahc
,
529 struct scsi_cmnd
*cmd
,
530 struct ahc_devinfo
*devinfo
,
531 struct ahc_linux_target
*targ
);
532 static int ahc_linux_fallback(struct ahc_softc
*ahc
,
533 struct ahc_devinfo
*devinfo
);
534 static void ahc_linux_dv_complete(Scsi_Cmnd
*cmd
);
535 static void ahc_linux_generate_dv_pattern(struct ahc_linux_target
*targ
);
536 static u_int
ahc_linux_user_tagdepth(struct ahc_softc
*ahc
,
537 struct ahc_devinfo
*devinfo
);
538 static u_int
ahc_linux_user_dv_setting(struct ahc_softc
*ahc
);
539 static void ahc_linux_device_queue_depth(struct ahc_softc
*ahc
,
540 struct ahc_linux_device
*dev
);
541 static struct ahc_linux_target
* ahc_linux_alloc_target(struct ahc_softc
*,
543 static void ahc_linux_free_target(struct ahc_softc
*,
544 struct ahc_linux_target
*);
545 static struct ahc_linux_device
* ahc_linux_alloc_device(struct ahc_softc
*,
546 struct ahc_linux_target
*,
548 static void ahc_linux_free_device(struct ahc_softc
*,
549 struct ahc_linux_device
*);
550 static void ahc_linux_run_device_queue(struct ahc_softc
*,
551 struct ahc_linux_device
*);
552 static void ahc_linux_setup_tag_info_global(char *p
);
553 static aic_option_callback_t ahc_linux_setup_tag_info
;
554 static aic_option_callback_t ahc_linux_setup_dv
;
555 static int aic7xxx_setup(char *s
);
556 static int ahc_linux_next_unit(void);
557 static void ahc_runq_tasklet(unsigned long data
);
558 static struct ahc_cmd
*ahc_linux_run_complete_queue(struct ahc_softc
*ahc
);
560 /********************************* Inlines ************************************/
561 static __inline
void ahc_schedule_runq(struct ahc_softc
*ahc
);
562 static __inline
struct ahc_linux_device
*
563 ahc_linux_get_device(struct ahc_softc
*ahc
, u_int channel
,
564 u_int target
, u_int lun
, int alloc
);
565 static __inline
void ahc_schedule_completeq(struct ahc_softc
*ahc
);
566 static __inline
void ahc_linux_check_device_queue(struct ahc_softc
*ahc
,
567 struct ahc_linux_device
*dev
);
568 static __inline
struct ahc_linux_device
*
569 ahc_linux_next_device_to_run(struct ahc_softc
*ahc
);
570 static __inline
void ahc_linux_run_device_queues(struct ahc_softc
*ahc
);
571 static __inline
void ahc_linux_unmap_scb(struct ahc_softc
*, struct scb
*);
573 static __inline
int ahc_linux_map_seg(struct ahc_softc
*ahc
, struct scb
*scb
,
574 struct ahc_dma_seg
*sg
,
575 bus_addr_t addr
, bus_size_t len
);
578 ahc_schedule_completeq(struct ahc_softc
*ahc
)
580 if ((ahc
->platform_data
->flags
& AHC_RUN_CMPLT_Q_TIMER
) == 0) {
581 ahc
->platform_data
->flags
|= AHC_RUN_CMPLT_Q_TIMER
;
582 ahc
->platform_data
->completeq_timer
.expires
= jiffies
;
583 add_timer(&ahc
->platform_data
->completeq_timer
);
588 * Must be called with our lock held.
591 ahc_schedule_runq(struct ahc_softc
*ahc
)
593 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
594 tasklet_schedule(&ahc
->platform_data
->runq_tasklet
);
597 * Tasklets are not available, so run inline.
599 ahc_runq_tasklet((unsigned long)ahc
);
603 static __inline
struct ahc_linux_device
*
604 ahc_linux_get_device(struct ahc_softc
*ahc
, u_int channel
, u_int target
,
605 u_int lun
, int alloc
)
607 struct ahc_linux_target
*targ
;
608 struct ahc_linux_device
*dev
;
611 target_offset
= target
;
614 targ
= ahc
->platform_data
->targets
[target_offset
];
617 targ
= ahc_linux_alloc_target(ahc
, channel
, target
);
623 dev
= targ
->devices
[lun
];
624 if (dev
== NULL
&& alloc
!= 0)
625 dev
= ahc_linux_alloc_device(ahc
, targ
, lun
);
629 #define AHC_LINUX_MAX_RETURNED_ERRORS 4
630 static struct ahc_cmd
*
631 ahc_linux_run_complete_queue(struct ahc_softc
*ahc
)
633 struct ahc_cmd
*acmd
;
638 ahc_done_lock(ahc
, &done_flags
);
639 while ((acmd
= TAILQ_FIRST(&ahc
->platform_data
->completeq
)) != NULL
) {
642 if (with_errors
> AHC_LINUX_MAX_RETURNED_ERRORS
) {
644 * Linux uses stack recursion to requeue
645 * commands that need to be retried. Avoid
646 * blowing out the stack by "spoon feeding"
647 * commands that completed with error back
648 * the operating system in case they are going
649 * to be retried. "ick"
651 ahc_schedule_completeq(ahc
);
654 TAILQ_REMOVE(&ahc
->platform_data
->completeq
,
655 acmd
, acmd_links
.tqe
);
656 cmd
= &acmd_scsi_cmd(acmd
);
657 cmd
->host_scribble
= NULL
;
658 if (ahc_cmd_get_transaction_status(cmd
) != DID_OK
659 || (cmd
->result
& 0xFF) != SCSI_STATUS_OK
)
664 ahc_done_unlock(ahc
, &done_flags
);
669 ahc_linux_check_device_queue(struct ahc_softc
*ahc
,
670 struct ahc_linux_device
*dev
)
672 if ((dev
->flags
& AHC_DEV_FREEZE_TIL_EMPTY
) != 0
673 && dev
->active
== 0) {
674 dev
->flags
&= ~AHC_DEV_FREEZE_TIL_EMPTY
;
678 if (TAILQ_FIRST(&dev
->busyq
) == NULL
679 || dev
->openings
== 0 || dev
->qfrozen
!= 0)
682 ahc_linux_run_device_queue(ahc
, dev
);
685 static __inline
struct ahc_linux_device
*
686 ahc_linux_next_device_to_run(struct ahc_softc
*ahc
)
689 if ((ahc
->flags
& AHC_RESOURCE_SHORTAGE
) != 0
690 || (ahc
->platform_data
->qfrozen
!= 0
691 && AHC_DV_SIMQ_FROZEN(ahc
) == 0))
693 return (TAILQ_FIRST(&ahc
->platform_data
->device_runq
));
697 ahc_linux_run_device_queues(struct ahc_softc
*ahc
)
699 struct ahc_linux_device
*dev
;
701 while ((dev
= ahc_linux_next_device_to_run(ahc
)) != NULL
) {
702 TAILQ_REMOVE(&ahc
->platform_data
->device_runq
, dev
, links
);
703 dev
->flags
&= ~AHC_DEV_ON_RUN_LIST
;
704 ahc_linux_check_device_queue(ahc
, dev
);
709 ahc_linux_unmap_scb(struct ahc_softc
*ahc
, struct scb
*scb
)
714 ahc_sync_sglist(ahc
, scb
, BUS_DMASYNC_POSTWRITE
);
715 if (cmd
->use_sg
!= 0) {
716 struct scatterlist
*sg
;
718 sg
= (struct scatterlist
*)cmd
->request_buffer
;
719 pci_unmap_sg(ahc
->dev_softc
, sg
, cmd
->use_sg
,
720 scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
721 } else if (cmd
->request_bufflen
!= 0) {
722 pci_unmap_single(ahc
->dev_softc
,
723 scb
->platform_data
->buf_busaddr
,
724 cmd
->request_bufflen
,
725 scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
730 ahc_linux_map_seg(struct ahc_softc
*ahc
, struct scb
*scb
,
731 struct ahc_dma_seg
*sg
, bus_addr_t addr
, bus_size_t len
)
735 if ((scb
->sg_count
+ 1) > AHC_NSEG
)
736 panic("Too few segs for dma mapping. "
737 "Increase AHC_NSEG\n");
740 sg
->addr
= ahc_htole32(addr
& 0xFFFFFFFF);
741 scb
->platform_data
->xfer_len
+= len
;
743 if (sizeof(bus_addr_t
) > 4
744 && (ahc
->flags
& AHC_39BIT_ADDRESSING
) != 0)
745 len
|= (addr
>> 8) & AHC_SG_HIGH_ADDR_MASK
;
747 sg
->len
= ahc_htole32(len
);
751 /************************ Host template entry points *************************/
752 static int ahc_linux_detect(Scsi_Host_Template
*);
753 static int ahc_linux_queue(Scsi_Cmnd
*, void (*)(Scsi_Cmnd
*));
754 static const char *ahc_linux_info(struct Scsi_Host
*);
755 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
756 static int ahc_linux_slave_alloc(Scsi_Device
*);
757 static int ahc_linux_slave_configure(Scsi_Device
*);
758 static void ahc_linux_slave_destroy(Scsi_Device
*);
759 #if defined(__i386__)
760 static int ahc_linux_biosparam(struct scsi_device
*,
761 struct block_device
*,
765 static int ahc_linux_release(struct Scsi_Host
*);
766 static void ahc_linux_select_queue_depth(struct Scsi_Host
*host
,
767 Scsi_Device
*scsi_devs
);
768 #if defined(__i386__)
769 static int ahc_linux_biosparam(Disk
*, kdev_t
, int[]);
772 static int ahc_linux_bus_reset(Scsi_Cmnd
*);
773 static int ahc_linux_dev_reset(Scsi_Cmnd
*);
774 static int ahc_linux_abort(Scsi_Cmnd
*);
777 * Calculate a safe value for AHC_NSEG (as expressed through ahc_linux_nseg).
780 * The midlayer allocates an S/G array dynamically when a command is issued
781 * using SCSI malloc. This array, which is in an OS dependent format that
782 * must later be copied to our private S/G list, is sized to house just the
783 * number of segments needed for the current transfer. Since the code that
784 * sizes the SCSI malloc pool does not take into consideration fragmentation
785 * of the pool, executing transactions numbering just a fraction of our
786 * concurrent transaction limit with list lengths aproaching AHC_NSEG will
787 * quickly depleat the SCSI malloc pool of usable space. Unfortunately, the
788 * mid-layer does not properly handle this scsi malloc failures for the S/G
789 * array and the result can be a lockup of the I/O subsystem. We try to size
790 * our S/G list so that it satisfies our drivers allocation requirements in
791 * addition to avoiding fragmentation of the SCSI malloc pool.
794 ahc_linux_size_nseg(void)
796 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
801 * The SCSI allocator rounds to the nearest 512 bytes
802 * an cannot allocate across a page boundary. Our algorithm
803 * is to start at 1K of scsi malloc space per-command and
804 * loop through all factors of the PAGE_SIZE and pick the best.
807 for (cur_size
= 1024; cur_size
<= PAGE_SIZE
; cur_size
*= 2) {
810 nseg
= cur_size
/ sizeof(struct scatterlist
);
811 if (nseg
< AHC_LINUX_MIN_NSEG
)
814 if (best_size
== 0) {
815 best_size
= cur_size
;
816 ahc_linux_nseg
= nseg
;
822 * Compare the traits of the current "best_size"
823 * with the current size to determine if the
824 * current size is a better size.
826 best_rem
= best_size
% sizeof(struct scatterlist
);
827 cur_rem
= cur_size
% sizeof(struct scatterlist
);
828 if (cur_rem
< best_rem
) {
829 best_size
= cur_size
;
830 ahc_linux_nseg
= nseg
;
838 * Try to detect an Adaptec 7XXX controller.
841 ahc_linux_detect(Scsi_Host_Template
*template)
843 struct ahc_softc
*ahc
;
846 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
848 * It is a bug that the upper layer takes
849 * this lock just prior to calling us.
851 spin_unlock_irq(&io_request_lock
);
855 * Sanity checking of Linux SCSI data structures so
856 * that some of our hacks^H^H^H^H^Hassumptions aren't
859 if (offsetof(struct ahc_cmd_internal
, end
)
860 > offsetof(struct scsi_cmnd
, host_scribble
)) {
861 printf("ahc_linux_detect: SCSI data structures changed.\n");
862 printf("ahc_linux_detect: Unable to attach\n");
865 ahc_linux_size_nseg();
868 * If we've been passed any parameters, process them now.
871 aic7xxx_setup(aic7xxx
);
872 if (dummy_buffer
[0] != 'P')
874 "aic7xxx: Please read the file /usr/src/linux/drivers/scsi/README.aic7xxx\n"
875 "aic7xxx: to see the proper way to specify options to the aic7xxx module\n"
876 "aic7xxx: Specifically, don't use any commas when passing arguments to\n"
877 "aic7xxx: insmod or else it might trash certain memory areas.\n");
880 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0)
881 template->proc_name
= "aic7xxx";
883 template->proc_dir
= &proc_scsi_aic7xxx
;
887 * Initialize our softc list lock prior to
888 * probing for any adapters.
892 found
= ahc_linux_pci_init();
893 if (!ahc_linux_eisa_init())
897 * Register with the SCSI layer all
898 * controllers we've found.
900 TAILQ_FOREACH(ahc
, &ahc_tailq
, links
) {
902 if (ahc_linux_register_host(ahc
, template) == 0)
906 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
907 spin_lock_irq(&io_request_lock
);
909 aic7xxx_detect_complete
++;
914 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
916 * Free the passed in Scsi_Host memory structures prior to unloading the
920 ahc_linux_release(struct Scsi_Host
* host
)
922 struct ahc_softc
*ahc
;
929 * We should be able to just perform
930 * the free directly, but check our
931 * list for extra sanity.
933 ahc
= ahc_find_softc(*(struct ahc_softc
**)host
->hostdata
);
938 ahc_intr_enable(ahc
, FALSE
);
949 * Return a string describing the driver.
952 ahc_linux_info(struct Scsi_Host
*host
)
954 static char buffer
[512];
957 struct ahc_softc
*ahc
;
960 ahc
= *(struct ahc_softc
**)host
->hostdata
;
961 memset(bp
, 0, sizeof(buffer
));
962 strcpy(bp
, "Adaptec AIC7XXX EISA/VLB/PCI SCSI HBA DRIVER, Rev ");
963 strcat(bp
, AIC7XXX_DRIVER_VERSION
);
966 strcat(bp
, ahc
->description
);
969 ahc_controller_info(ahc
, ahc_info
);
970 strcat(bp
, ahc_info
);
977 * Queue an SCB to the controller.
980 ahc_linux_queue(Scsi_Cmnd
* cmd
, void (*scsi_done
) (Scsi_Cmnd
*))
982 struct ahc_softc
*ahc
;
983 struct ahc_linux_device
*dev
;
986 ahc
= *(struct ahc_softc
**)cmd
->device
->host
->hostdata
;
989 * Save the callback on completion function.
991 cmd
->scsi_done
= scsi_done
;
993 ahc_midlayer_entrypoint_lock(ahc
, &flags
);
996 * Close the race of a command that was in the process of
997 * being queued to us just as our simq was frozen. Let
998 * DV commands through so long as we are only frozen to
1001 if (ahc
->platform_data
->qfrozen
!= 0
1002 && AHC_DV_CMD(cmd
) == 0) {
1004 ahc_cmd_set_transaction_status(cmd
, CAM_REQUEUE_REQ
);
1005 ahc_linux_queue_cmd_complete(ahc
, cmd
);
1006 ahc_schedule_completeq(ahc
);
1007 ahc_midlayer_entrypoint_unlock(ahc
, &flags
);
1010 dev
= ahc_linux_get_device(ahc
, cmd
->device
->channel
, cmd
->device
->id
,
1011 cmd
->device
->lun
, /*alloc*/TRUE
);
1013 ahc_cmd_set_transaction_status(cmd
, CAM_RESRC_UNAVAIL
);
1014 ahc_linux_queue_cmd_complete(ahc
, cmd
);
1015 ahc_schedule_completeq(ahc
);
1016 ahc_midlayer_entrypoint_unlock(ahc
, &flags
);
1017 printf("%s: aic7xxx_linux_queue - Unable to allocate device!\n",
1021 cmd
->result
= CAM_REQ_INPROG
<< 16;
1022 TAILQ_INSERT_TAIL(&dev
->busyq
, (struct ahc_cmd
*)cmd
, acmd_links
.tqe
);
1023 if ((dev
->flags
& AHC_DEV_ON_RUN_LIST
) == 0) {
1024 TAILQ_INSERT_TAIL(&ahc
->platform_data
->device_runq
, dev
, links
);
1025 dev
->flags
|= AHC_DEV_ON_RUN_LIST
;
1026 ahc_linux_run_device_queues(ahc
);
1028 ahc_midlayer_entrypoint_unlock(ahc
, &flags
);
1032 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1034 ahc_linux_slave_alloc(Scsi_Device
*device
)
1036 struct ahc_softc
*ahc
;
1038 ahc
= *((struct ahc_softc
**)device
->host
->hostdata
);
1040 printf("%s: Slave Alloc %d\n", ahc_name(ahc
), device
->id
);
1045 ahc_linux_slave_configure(Scsi_Device
*device
)
1047 struct ahc_softc
*ahc
;
1048 struct ahc_linux_device
*dev
;
1051 ahc
= *((struct ahc_softc
**)device
->host
->hostdata
);
1053 printf("%s: Slave Configure %d\n", ahc_name(ahc
), device
->id
);
1054 ahc_midlayer_entrypoint_lock(ahc
, &flags
);
1056 * Since Linux has attached to the device, configure
1057 * it so we don't free and allocate the device
1058 * structure on every command.
1060 dev
= ahc_linux_get_device(ahc
, device
->channel
,
1061 device
->id
, device
->lun
,
1064 dev
->flags
&= ~AHC_DEV_UNCONFIGURED
;
1065 dev
->scsi_device
= device
;
1066 ahc_linux_device_queue_depth(ahc
, dev
);
1068 ahc_midlayer_entrypoint_unlock(ahc
, &flags
);
1073 ahc_linux_slave_destroy(Scsi_Device
*device
)
1075 struct ahc_softc
*ahc
;
1076 struct ahc_linux_device
*dev
;
1079 ahc
= *((struct ahc_softc
**)device
->host
->hostdata
);
1081 printf("%s: Slave Destroy %d\n", ahc_name(ahc
), device
->id
);
1082 ahc_midlayer_entrypoint_lock(ahc
, &flags
);
1083 dev
= ahc_linux_get_device(ahc
, device
->channel
,
1084 device
->id
, device
->lun
,
1087 * Filter out "silly" deletions of real devices by only
1088 * deleting devices that have had slave_configure()
1089 * called on them. All other devices that have not
1090 * been configured will automatically be deleted by
1091 * the refcounting process.
1094 && (dev
->flags
& AHC_DEV_SLAVE_CONFIGURED
) != 0) {
1095 dev
->flags
|= AHC_DEV_UNCONFIGURED
;
1096 if (TAILQ_EMPTY(&dev
->busyq
)
1098 && (dev
->flags
& AHC_DEV_TIMER_ACTIVE
) == 0)
1099 ahc_linux_free_device(ahc
, dev
);
1101 ahc_midlayer_entrypoint_unlock(ahc
, &flags
);
1105 * Sets the queue depth for each SCSI device hanging
1106 * off the input host adapter.
1109 ahc_linux_select_queue_depth(struct Scsi_Host
*host
, Scsi_Device
*scsi_devs
)
1111 Scsi_Device
*device
;
1113 struct ahc_softc
*ahc
;
1116 ahc
= *((struct ahc_softc
**)host
->hostdata
);
1117 ahc_lock(ahc
, &flags
);
1118 for (device
= scsi_devs
; device
!= NULL
; device
= device
->next
) {
1121 * Watch out for duplicate devices. This works around
1122 * some quirks in how the SCSI scanning code does its
1123 * device management.
1125 for (ldev
= scsi_devs
; ldev
!= device
; ldev
= ldev
->next
) {
1126 if (ldev
->host
== device
->host
1127 && ldev
->channel
== device
->channel
1128 && ldev
->id
== device
->id
1129 && ldev
->lun
== device
->lun
)
1132 /* Skip duplicate. */
1136 if (device
->host
== host
) {
1137 struct ahc_linux_device
*dev
;
1140 * Since Linux has attached to the device, configure
1141 * it so we don't free and allocate the device
1142 * structure on every command.
1144 dev
= ahc_linux_get_device(ahc
, device
->channel
,
1145 device
->id
, device
->lun
,
1148 dev
->flags
&= ~AHC_DEV_UNCONFIGURED
;
1149 dev
->scsi_device
= device
;
1150 ahc_linux_device_queue_depth(ahc
, dev
);
1151 device
->queue_depth
= dev
->openings
1153 if ((dev
->flags
& (AHC_DEV_Q_BASIC
1154 | AHC_DEV_Q_TAGGED
)) == 0) {
1156 * We allow the OS to queue 2 untagged
1157 * transactions to us at any time even
1158 * though we can only execute them
1159 * serially on the controller/device.
1160 * This should remove some latency.
1162 device
->queue_depth
= 2;
1167 ahc_unlock(ahc
, &flags
);
1171 #if defined(__i386__)
1173 * Return the disk geometry for the given SCSI device.
1176 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1177 ahc_linux_biosparam(struct scsi_device
*sdev
, struct block_device
*bdev
,
1178 sector_t capacity
, int geom
[])
1182 ahc_linux_biosparam(Disk
*disk
, kdev_t dev
, int geom
[])
1184 struct scsi_device
*sdev
= disk
->device
;
1185 u_long capacity
= disk
->capacity
;
1186 struct buffer_head
*bh
;
1193 struct ahc_softc
*ahc
;
1196 ahc
= *((struct ahc_softc
**)sdev
->host
->hostdata
);
1197 channel
= sdev
->channel
;
1199 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1200 bh
= scsi_bios_ptable(bdev
);
1201 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,17)
1202 bh
= bread(MKDEV(MAJOR(dev
), MINOR(dev
) & ~0xf), 0, block_size(dev
));
1204 bh
= bread(MKDEV(MAJOR(dev
), MINOR(dev
) & ~0xf), 0, 1024);
1208 ret
= scsi_partsize(bh
, capacity
,
1209 &geom
[2], &geom
[0], &geom
[1]);
1210 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1220 cylinders
= aic_sector_div(capacity
, heads
, sectors
);
1222 if (aic7xxx_extended
!= 0)
1224 else if (channel
== 0)
1225 extended
= (ahc
->flags
& AHC_EXTENDED_TRANS_A
) != 0;
1227 extended
= (ahc
->flags
& AHC_EXTENDED_TRANS_B
) != 0;
1228 if (extended
&& cylinders
>= 1024) {
1231 cylinders
= aic_sector_div(capacity
, heads
, sectors
);
1235 geom
[2] = cylinders
;
1241 * Abort the current SCSI command(s).
1244 ahc_linux_abort(Scsi_Cmnd
*cmd
)
1248 error
= ahc_linux_queue_recovery_cmd(cmd
, SCB_ABORT
);
1250 printf("aic7xxx_abort returns 0x%x\n", error
);
1255 * Attempt to send a target reset message to the device that timed out.
1258 ahc_linux_dev_reset(Scsi_Cmnd
*cmd
)
1262 error
= ahc_linux_queue_recovery_cmd(cmd
, SCB_DEVICE_RESET
);
1264 printf("aic7xxx_dev_reset returns 0x%x\n", error
);
1269 * Reset the SCSI bus.
1272 ahc_linux_bus_reset(Scsi_Cmnd
*cmd
)
1274 struct ahc_softc
*ahc
;
1278 ahc
= *(struct ahc_softc
**)cmd
->device
->host
->hostdata
;
1279 ahc_midlayer_entrypoint_lock(ahc
, &s
);
1280 found
= ahc_reset_channel(ahc
, cmd
->device
->channel
+ 'A',
1281 /*initiate reset*/TRUE
);
1282 ahc_linux_run_complete_queue(ahc
);
1283 ahc_midlayer_entrypoint_unlock(ahc
, &s
);
1286 printf("%s: SCSI bus reset delivered. "
1287 "%d SCBs aborted.\n", ahc_name(ahc
), found
);
1292 Scsi_Host_Template aic7xxx_driver_template
= {
1293 .module
= THIS_MODULE
,
1295 .proc_info
= ahc_linux_proc_info
,
1296 .info
= ahc_linux_info
,
1297 .queuecommand
= ahc_linux_queue
,
1298 .eh_abort_handler
= ahc_linux_abort
,
1299 .eh_device_reset_handler
= ahc_linux_dev_reset
,
1300 .eh_bus_reset_handler
= ahc_linux_bus_reset
,
1301 #if defined(__i386__)
1302 .bios_param
= ahc_linux_biosparam
,
1304 .can_queue
= AHC_MAX_QUEUE
,
1307 .use_clustering
= ENABLE_CLUSTERING
,
1308 .slave_alloc
= ahc_linux_slave_alloc
,
1309 .slave_configure
= ahc_linux_slave_configure
,
1310 .slave_destroy
= ahc_linux_slave_destroy
,
1313 /**************************** Tasklet Handler *********************************/
1316 * In 2.4.X and above, this routine is called from a tasklet,
1317 * so we must re-acquire our lock prior to executing this code.
1318 * In all prior kernels, ahc_schedule_runq() calls this routine
1319 * directly and ahc_schedule_runq() is called with our lock held.
1322 ahc_runq_tasklet(unsigned long data
)
1324 struct ahc_softc
* ahc
;
1325 struct ahc_linux_device
*dev
;
1326 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1330 ahc
= (struct ahc_softc
*)data
;
1331 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1332 ahc_lock(ahc
, &flags
);
1334 while ((dev
= ahc_linux_next_device_to_run(ahc
)) != NULL
) {
1336 TAILQ_REMOVE(&ahc
->platform_data
->device_runq
, dev
, links
);
1337 dev
->flags
&= ~AHC_DEV_ON_RUN_LIST
;
1338 ahc_linux_check_device_queue(ahc
, dev
);
1339 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1340 /* Yeild to our interrupt handler */
1341 ahc_unlock(ahc
, &flags
);
1342 ahc_lock(ahc
, &flags
);
1345 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1346 ahc_unlock(ahc
, &flags
);
1350 /******************************** Macros **************************************/
1351 #define BUILD_SCSIID(ahc, cmd) \
1352 ((((cmd)->device->id << TID_SHIFT) & TID) \
1353 | (((cmd)->device->channel == 0) ? (ahc)->our_id : (ahc)->our_id_b) \
1354 | (((cmd)->device->channel == 0) ? 0 : TWIN_CHNLB))
1356 /******************************** Bus DMA *************************************/
1358 ahc_dma_tag_create(struct ahc_softc
*ahc
, bus_dma_tag_t parent
,
1359 bus_size_t alignment
, bus_size_t boundary
,
1360 bus_addr_t lowaddr
, bus_addr_t highaddr
,
1361 bus_dma_filter_t
*filter
, void *filterarg
,
1362 bus_size_t maxsize
, int nsegments
,
1363 bus_size_t maxsegsz
, int flags
, bus_dma_tag_t
*ret_tag
)
1367 dmat
= malloc(sizeof(*dmat
), M_DEVBUF
, M_NOWAIT
);
1372 * Linux is very simplistic about DMA memory. For now don't
1373 * maintain all specification information. Once Linux supplies
1374 * better facilities for doing these operations, or the
1375 * needs of this particular driver change, we might need to do
1378 dmat
->alignment
= alignment
;
1379 dmat
->boundary
= boundary
;
1380 dmat
->maxsize
= maxsize
;
1386 ahc_dma_tag_destroy(struct ahc_softc
*ahc
, bus_dma_tag_t dmat
)
1388 free(dmat
, M_DEVBUF
);
1392 ahc_dmamem_alloc(struct ahc_softc
*ahc
, bus_dma_tag_t dmat
, void** vaddr
,
1393 int flags
, bus_dmamap_t
*mapp
)
1397 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
1398 map
= malloc(sizeof(*map
), M_DEVBUF
, M_NOWAIT
);
1402 * Although we can dma data above 4GB, our
1403 * "consistent" memory is below 4GB for
1404 * space efficiency reasons (only need a 4byte
1405 * address). For this reason, we have to reset
1406 * our dma mask when doing allocations.
1408 if (ahc
->dev_softc
!= NULL
)
1409 if (ahc_pci_set_dma_mask(ahc
->dev_softc
, 0xFFFFFFFF)) {
1410 printk(KERN_WARNING
"aic7xxx: No suitable DMA available.\n");
1413 *vaddr
= pci_alloc_consistent(ahc
->dev_softc
,
1414 dmat
->maxsize
, &map
->bus_addr
);
1415 if (ahc
->dev_softc
!= NULL
)
1416 if (ahc_pci_set_dma_mask(ahc
->dev_softc
,
1417 ahc
->platform_data
->hw_dma_mask
)) {
1418 printk(KERN_WARNING
"aic7xxx: No suitable DMA available.\n");
1421 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */
1423 * At least in 2.2.14, malloc is a slab allocator so all
1424 * allocations are aligned. We assume for these kernel versions
1425 * that all allocations will be bellow 4Gig, physically contiguous,
1426 * and accessible via DMA by the controller.
1428 map
= NULL
; /* No additional information to store */
1429 *vaddr
= malloc(dmat
->maxsize
, M_DEVBUF
, M_NOWAIT
);
1438 ahc_dmamem_free(struct ahc_softc
*ahc
, bus_dma_tag_t dmat
,
1439 void* vaddr
, bus_dmamap_t map
)
1441 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
1442 pci_free_consistent(ahc
->dev_softc
, dmat
->maxsize
,
1443 vaddr
, map
->bus_addr
);
1445 free(vaddr
, M_DEVBUF
);
1450 ahc_dmamap_load(struct ahc_softc
*ahc
, bus_dma_tag_t dmat
, bus_dmamap_t map
,
1451 void *buf
, bus_size_t buflen
, bus_dmamap_callback_t
*cb
,
1452 void *cb_arg
, int flags
)
1455 * Assume for now that this will only be used during
1456 * initialization and not for per-transaction buffer mapping.
1458 bus_dma_segment_t stack_sg
;
1460 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
1461 stack_sg
.ds_addr
= map
->bus_addr
;
1463 #define VIRT_TO_BUS(a) (uint32_t)virt_to_bus((void *)(a))
1464 stack_sg
.ds_addr
= VIRT_TO_BUS(buf
);
1466 stack_sg
.ds_len
= dmat
->maxsize
;
1467 cb(cb_arg
, &stack_sg
, /*nseg*/1, /*error*/0);
1472 ahc_dmamap_destroy(struct ahc_softc
*ahc
, bus_dma_tag_t dmat
, bus_dmamap_t map
)
1475 * The map may is NULL in our < 2.3.X implementation.
1478 free(map
, M_DEVBUF
);
1482 ahc_dmamap_unload(struct ahc_softc
*ahc
, bus_dma_tag_t dmat
, bus_dmamap_t map
)
1488 /********************* Platform Dependent Functions ***************************/
1490 * Compare "left hand" softc with "right hand" softc, returning:
1491 * < 0 - lahc has a lower priority than rahc
1492 * 0 - Softcs are equal
1493 * > 0 - lahc has a higher priority than rahc
1496 ahc_softc_comp(struct ahc_softc
*lahc
, struct ahc_softc
*rahc
)
1503 * Under Linux, cards are ordered as follows:
1504 * 1) VLB/EISA BIOS enabled devices sorted by BIOS address.
1505 * 2) PCI devices with BIOS enabled sorted by bus/slot/func.
1506 * 3) All remaining VLB/EISA devices sorted by ioport.
1507 * 4) All remaining PCI devices sorted by bus/slot/func.
1509 value
= (lahc
->flags
& AHC_BIOS_ENABLED
)
1510 - (rahc
->flags
& AHC_BIOS_ENABLED
);
1512 /* Controllers with BIOS enabled have a *higher* priority */
1516 * Same BIOS setting, now sort based on bus type.
1517 * EISA and VL controllers sort together. EISA/VL
1518 * have higher priority than PCI.
1520 rvalue
= (rahc
->chip
& AHC_BUS_MASK
);
1521 if (rvalue
== AHC_VL
)
1523 lvalue
= (lahc
->chip
& AHC_BUS_MASK
);
1524 if (lvalue
== AHC_VL
)
1526 value
= rvalue
- lvalue
;
1530 /* Still equal. Sort by BIOS address, ioport, or bus/slot/func. */
1535 char primary_channel
;
1537 if (aic7xxx_reverse_scan
!= 0)
1538 value
= ahc_get_pci_bus(lahc
->dev_softc
)
1539 - ahc_get_pci_bus(rahc
->dev_softc
);
1541 value
= ahc_get_pci_bus(rahc
->dev_softc
)
1542 - ahc_get_pci_bus(lahc
->dev_softc
);
1545 if (aic7xxx_reverse_scan
!= 0)
1546 value
= ahc_get_pci_slot(lahc
->dev_softc
)
1547 - ahc_get_pci_slot(rahc
->dev_softc
);
1549 value
= ahc_get_pci_slot(rahc
->dev_softc
)
1550 - ahc_get_pci_slot(lahc
->dev_softc
);
1554 * On multi-function devices, the user can choose
1555 * to have function 1 probed before function 0.
1556 * Give whichever channel is the primary channel
1557 * the highest priority.
1559 primary_channel
= (lahc
->flags
& AHC_PRIMARY_CHANNEL
) + 'A';
1561 if (lahc
->channel
== primary_channel
)
1567 if ((rahc
->flags
& AHC_BIOS_ENABLED
) != 0) {
1568 value
= rahc
->platform_data
->bios_address
1569 - lahc
->platform_data
->bios_address
;
1571 value
= rahc
->bsh
.ioport
1576 panic("ahc_softc_sort: invalid bus type");
1582 ahc_linux_setup_tag_info_global(char *p
)
1586 tags
= simple_strtoul(p
+ 1, NULL
, 0) & 0xff;
1587 printf("Setting Global Tags= %d\n", tags
);
1589 for (i
= 0; i
< NUM_ELEMENTS(aic7xxx_tag_info
); i
++) {
1590 for (j
= 0; j
< AHC_NUM_TARGETS
; j
++) {
1591 aic7xxx_tag_info
[i
].tag_commands
[j
] = tags
;
1597 ahc_linux_setup_tag_info(u_long arg
, int instance
, int targ
, int32_t value
)
1600 if ((instance
>= 0) && (targ
>= 0)
1601 && (instance
< NUM_ELEMENTS(aic7xxx_tag_info
))
1602 && (targ
< AHC_NUM_TARGETS
)) {
1603 aic7xxx_tag_info
[instance
].tag_commands
[targ
] = value
& 0xff;
1605 printf("tag_info[%d:%d] = %d\n", instance
, targ
, value
);
1610 ahc_linux_setup_dv(u_long arg
, int instance
, int targ
, int32_t value
)
1614 && (instance
< NUM_ELEMENTS(aic7xxx_dv_settings
))) {
1615 aic7xxx_dv_settings
[instance
] = value
;
1617 printf("dv[%d] = %d\n", instance
, value
);
1622 * Handle Linux boot parameters. This routine allows for assigning a value
1623 * to a parameter with a ':' between the parameter and the value.
1624 * ie. aic7xxx=stpwlev:1,extended
1627 aic7xxx_setup(char *s
)
1637 { "extended", &aic7xxx_extended
},
1638 { "no_reset", &aic7xxx_no_reset
},
1639 { "verbose", &aic7xxx_verbose
},
1640 { "allow_memio", &aic7xxx_allow_memio
},
1642 { "debug", &ahc_debug
},
1644 { "reverse_scan", &aic7xxx_reverse_scan
},
1645 { "no_probe", &aic7xxx_probe_eisa_vl
},
1646 { "probe_eisa_vl", &aic7xxx_probe_eisa_vl
},
1647 { "periodic_otag", &aic7xxx_periodic_otag
},
1648 { "pci_parity", &aic7xxx_pci_parity
},
1649 { "seltime", &aic7xxx_seltime
},
1650 { "tag_info", NULL
},
1651 { "global_tag_depth", NULL
},
1655 end
= strchr(s
, '\0');
1658 * XXX ia64 gcc isn't smart enough to know that NUM_ELEMENTS
1659 * will never be 0 in this case.
1663 while ((p
= strsep(&s
, ",.")) != NULL
) {
1666 for (i
= 0; i
< NUM_ELEMENTS(options
); i
++) {
1668 n
= strlen(options
[i
].name
);
1669 if (strncmp(options
[i
].name
, p
, n
) == 0)
1672 if (i
== NUM_ELEMENTS(options
))
1675 if (strncmp(p
, "global_tag_depth", n
) == 0) {
1676 ahc_linux_setup_tag_info_global(p
+ n
);
1677 } else if (strncmp(p
, "tag_info", n
) == 0) {
1678 s
= aic_parse_brace_option("tag_info", p
+ n
, end
,
1679 2, ahc_linux_setup_tag_info
, 0);
1680 } else if (strncmp(p
, "dv", n
) == 0) {
1681 s
= aic_parse_brace_option("dv", p
+ n
, end
, 1,
1682 ahc_linux_setup_dv
, 0);
1683 } else if (p
[n
] == ':') {
1684 *(options
[i
].flag
) = simple_strtoul(p
+ n
+ 1, NULL
, 0);
1685 } else if (strncmp(p
, "verbose", n
) == 0) {
1686 *(options
[i
].flag
) = 1;
1688 *(options
[i
].flag
) ^= 0xFFFFFFFF;
1694 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0)
1695 __setup("aic7xxx=", aic7xxx_setup
);
1698 uint32_t aic7xxx_verbose
;
1701 ahc_linux_register_host(struct ahc_softc
*ahc
, Scsi_Host_Template
*template)
1704 struct Scsi_Host
*host
;
1709 template->name
= ahc
->description
;
1710 host
= scsi_host_alloc(template, sizeof(struct ahc_softc
*));
1714 *((struct ahc_softc
**)host
->hostdata
) = ahc
;
1716 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1717 scsi_assign_lock(host
, &ahc
->platform_data
->spin_lock
);
1718 #elif AHC_SCSI_HAS_HOST_LOCK != 0
1719 host
->lock
= &ahc
->platform_data
->spin_lock
;
1721 ahc
->platform_data
->host
= host
;
1722 host
->can_queue
= AHC_MAX_QUEUE
;
1723 host
->cmd_per_lun
= 2;
1724 /* XXX No way to communicate the ID for multiple channels */
1725 host
->this_id
= ahc
->our_id
;
1726 host
->irq
= ahc
->platform_data
->irq
;
1727 host
->max_id
= (ahc
->features
& AHC_WIDE
) ? 16 : 8;
1728 host
->max_lun
= AHC_NUM_LUNS
;
1729 host
->max_channel
= (ahc
->features
& AHC_TWIN
) ? 1 : 0;
1730 host
->sg_tablesize
= AHC_NSEG
;
1731 ahc_set_unit(ahc
, ahc_linux_next_unit());
1732 sprintf(buf
, "scsi%d", host
->host_no
);
1733 new_name
= malloc(strlen(buf
) + 1, M_DEVBUF
, M_NOWAIT
);
1734 if (new_name
!= NULL
) {
1735 strcpy(new_name
, buf
);
1736 ahc_set_name(ahc
, new_name
);
1738 host
->unique_id
= ahc
->unit
;
1739 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,4) && \
1740 LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1741 scsi_set_pci_device(host
, ahc
->dev_softc
);
1743 ahc_linux_initialize_scsi_bus(ahc
);
1744 ahc_unlock(ahc
, &s
);
1745 ahc
->platform_data
->dv_pid
= kernel_thread(ahc_linux_dv_thread
, ahc
, 0);
1747 if (ahc
->platform_data
->dv_pid
< 0) {
1748 printf("%s: Failed to create DV thread, error= %d\n",
1749 ahc_name(ahc
), ahc
->platform_data
->dv_pid
);
1750 return (-ahc
->platform_data
->dv_pid
);
1753 * Initially allocate *all* of our linux target objects
1754 * so that the DV thread will scan them all in parallel
1755 * just after driver initialization. Any device that
1756 * does not exist will have its target object destroyed
1757 * by the selection timeout handler. In the case of a
1758 * device that appears after the initial DV scan, async
1759 * negotiation will occur for the first command, and DV
1760 * will comence should that first command be successful.
1762 for (targ_offset
= 0;
1763 targ_offset
< host
->max_id
* (host
->max_channel
+ 1);
1769 target
= targ_offset
;
1771 && (ahc
->features
& AHC_TWIN
) != 0) {
1776 * Skip our own ID. Some Compaq/HP storage devices
1777 * have enclosure management devices that respond to
1778 * single bit selection (i.e. selecting ourselves).
1779 * It is expected that either an external application
1780 * or a modified kernel will be used to probe this
1781 * ID if it is appropriate. To accommodate these
1782 * installations, ahc_linux_alloc_target() will allocate
1783 * for our ID if asked to do so.
1785 if ((channel
== 0 && target
== ahc
->our_id
)
1786 || (channel
== 1 && target
== ahc
->our_id_b
))
1789 ahc_linux_alloc_target(ahc
, channel
, target
);
1791 ahc_intr_enable(ahc
, TRUE
);
1792 ahc_linux_start_dv(ahc
);
1793 ahc_unlock(ahc
, &s
);
1795 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1796 scsi_add_host(host
, (ahc
->dev_softc
? &ahc
->dev_softc
->dev
: NULL
)); /* XXX handle failure */
1797 scsi_scan_host(host
);
1803 ahc_linux_get_memsize(void)
1808 return ((uint64_t)si
.totalram
<< PAGE_SHIFT
);
1812 * Find the smallest available unit number to use
1813 * for a new device. We don't just use a static
1814 * count to handle the "repeated hot-(un)plug"
1818 ahc_linux_next_unit(void)
1820 struct ahc_softc
*ahc
;
1825 TAILQ_FOREACH(ahc
, &ahc_tailq
, links
) {
1826 if (ahc
->unit
== unit
) {
1835 * Place the SCSI bus into a known state by either resetting it,
1836 * or forcing transfer negotiations on the next command to any
1840 ahc_linux_initialize_scsi_bus(struct ahc_softc
*ahc
)
1848 if (aic7xxx_no_reset
!= 0)
1849 ahc
->flags
&= ~(AHC_RESET_BUS_A
|AHC_RESET_BUS_B
);
1851 if ((ahc
->flags
& AHC_RESET_BUS_A
) != 0)
1852 ahc_reset_channel(ahc
, 'A', /*initiate_reset*/TRUE
);
1854 numtarg
= (ahc
->features
& AHC_WIDE
) ? 16 : 8;
1856 if ((ahc
->features
& AHC_TWIN
) != 0) {
1858 if ((ahc
->flags
& AHC_RESET_BUS_B
) != 0) {
1859 ahc_reset_channel(ahc
, 'B', /*initiate_reset*/TRUE
);
1868 * Force negotiation to async for all targets that
1869 * will not see an initial bus reset.
1871 for (; i
< numtarg
; i
++) {
1872 struct ahc_devinfo devinfo
;
1873 struct ahc_initiator_tinfo
*tinfo
;
1874 struct ahc_tmode_tstate
*tstate
;
1880 our_id
= ahc
->our_id
;
1882 if (i
> 7 && (ahc
->features
& AHC_TWIN
) != 0) {
1884 our_id
= ahc
->our_id_b
;
1887 tinfo
= ahc_fetch_transinfo(ahc
, channel
, our_id
,
1888 target_id
, &tstate
);
1889 ahc_compile_devinfo(&devinfo
, our_id
, target_id
,
1890 CAM_LUN_WILDCARD
, channel
, ROLE_INITIATOR
);
1891 ahc_update_neg_request(ahc
, &devinfo
, tstate
,
1892 tinfo
, AHC_NEG_ALWAYS
);
1894 /* Give the bus some time to recover */
1895 if ((ahc
->flags
& (AHC_RESET_BUS_A
|AHC_RESET_BUS_B
)) != 0) {
1896 ahc_linux_freeze_simq(ahc
);
1897 init_timer(&ahc
->platform_data
->reset_timer
);
1898 ahc
->platform_data
->reset_timer
.data
= (u_long
)ahc
;
1899 ahc
->platform_data
->reset_timer
.expires
=
1900 jiffies
+ (AIC7XXX_RESET_DELAY
* HZ
)/1000;
1901 ahc
->platform_data
->reset_timer
.function
=
1902 ahc_linux_release_simq
;
1903 add_timer(&ahc
->platform_data
->reset_timer
);
1908 ahc_platform_alloc(struct ahc_softc
*ahc
, void *platform_arg
)
1911 ahc
->platform_data
=
1912 malloc(sizeof(struct ahc_platform_data
), M_DEVBUF
, M_NOWAIT
);
1913 if (ahc
->platform_data
== NULL
)
1915 memset(ahc
->platform_data
, 0, sizeof(struct ahc_platform_data
));
1916 TAILQ_INIT(&ahc
->platform_data
->completeq
);
1917 TAILQ_INIT(&ahc
->platform_data
->device_runq
);
1918 ahc
->platform_data
->irq
= AHC_LINUX_NOIRQ
;
1919 ahc
->platform_data
->hw_dma_mask
= 0xFFFFFFFF;
1921 ahc_done_lockinit(ahc
);
1922 init_timer(&ahc
->platform_data
->completeq_timer
);
1923 ahc
->platform_data
->completeq_timer
.data
= (u_long
)ahc
;
1924 ahc
->platform_data
->completeq_timer
.function
=
1925 (ahc_linux_callback_t
*)ahc_linux_thread_run_complete_queue
;
1926 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
1927 init_MUTEX_LOCKED(&ahc
->platform_data
->eh_sem
);
1928 init_MUTEX_LOCKED(&ahc
->platform_data
->dv_sem
);
1929 init_MUTEX_LOCKED(&ahc
->platform_data
->dv_cmd_sem
);
1931 ahc
->platform_data
->eh_sem
= MUTEX_LOCKED
;
1932 ahc
->platform_data
->dv_sem
= MUTEX_LOCKED
;
1933 ahc
->platform_data
->dv_cmd_sem
= MUTEX_LOCKED
;
1935 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1936 tasklet_init(&ahc
->platform_data
->runq_tasklet
, ahc_runq_tasklet
,
1937 (unsigned long)ahc
);
1939 ahc
->seltime
= (aic7xxx_seltime
& 0x3) << 4;
1940 ahc
->seltime_b
= (aic7xxx_seltime
& 0x3) << 4;
1941 if (aic7xxx_pci_parity
== 0)
1942 ahc
->flags
|= AHC_DISABLE_PCI_PERR
;
1948 ahc_platform_free(struct ahc_softc
*ahc
)
1950 struct ahc_linux_target
*targ
;
1951 struct ahc_linux_device
*dev
;
1954 if (ahc
->platform_data
!= NULL
) {
1955 del_timer_sync(&ahc
->platform_data
->completeq_timer
);
1956 ahc_linux_kill_dv_thread(ahc
);
1957 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1958 tasklet_kill(&ahc
->platform_data
->runq_tasklet
);
1960 if (ahc
->platform_data
->host
!= NULL
) {
1961 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1962 scsi_remove_host(ahc
->platform_data
->host
);
1964 scsi_host_put(ahc
->platform_data
->host
);
1967 /* destroy all of the device and target objects */
1968 for (i
= 0; i
< AHC_NUM_TARGETS
; i
++) {
1969 targ
= ahc
->platform_data
->targets
[i
];
1971 /* Keep target around through the loop. */
1973 for (j
= 0; j
< AHC_NUM_LUNS
; j
++) {
1975 if (targ
->devices
[j
] == NULL
)
1977 dev
= targ
->devices
[j
];
1978 ahc_linux_free_device(ahc
, dev
);
1981 * Forcibly free the target now that
1982 * all devices are gone.
1984 ahc_linux_free_target(ahc
, targ
);
1988 if (ahc
->platform_data
->irq
!= AHC_LINUX_NOIRQ
)
1989 free_irq(ahc
->platform_data
->irq
, ahc
);
1990 if (ahc
->tag
== BUS_SPACE_PIO
1991 && ahc
->bsh
.ioport
!= 0)
1992 release_region(ahc
->bsh
.ioport
, 256);
1993 if (ahc
->tag
== BUS_SPACE_MEMIO
1994 && ahc
->bsh
.maddr
!= NULL
) {
1997 base_addr
= (u_long
)ahc
->bsh
.maddr
;
1998 base_addr
&= PAGE_MASK
;
1999 iounmap((void *)base_addr
);
2000 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
2001 release_mem_region(ahc
->platform_data
->mem_busaddr
,
2005 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) && \
2006 LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
2008 * In 2.4 we detach from the scsi midlayer before the PCI
2009 * layer invokes our remove callback. No per-instance
2010 * detach is provided, so we must reach inside the PCI
2011 * subsystem's internals and detach our driver manually.
2013 if (ahc
->dev_softc
!= NULL
)
2014 ahc
->dev_softc
->driver
= NULL
;
2016 free(ahc
->platform_data
, M_DEVBUF
);
2021 ahc_platform_freeze_devq(struct ahc_softc
*ahc
, struct scb
*scb
)
2023 ahc_platform_abort_scbs(ahc
, SCB_GET_TARGET(ahc
, scb
),
2024 SCB_GET_CHANNEL(ahc
, scb
),
2025 SCB_GET_LUN(scb
), SCB_LIST_NULL
,
2026 ROLE_UNKNOWN
, CAM_REQUEUE_REQ
);
2030 ahc_platform_set_tags(struct ahc_softc
*ahc
, struct ahc_devinfo
*devinfo
,
2033 struct ahc_linux_device
*dev
;
2037 dev
= ahc_linux_get_device(ahc
, devinfo
->channel
- 'A',
2039 devinfo
->lun
, /*alloc*/FALSE
);
2042 was_queuing
= dev
->flags
& (AHC_DEV_Q_BASIC
|AHC_DEV_Q_TAGGED
);
2045 case AHC_QUEUE_NONE
:
2048 case AHC_QUEUE_BASIC
:
2049 now_queuing
= AHC_DEV_Q_BASIC
;
2051 case AHC_QUEUE_TAGGED
:
2052 now_queuing
= AHC_DEV_Q_TAGGED
;
2055 if ((dev
->flags
& AHC_DEV_FREEZE_TIL_EMPTY
) == 0
2056 && (was_queuing
!= now_queuing
)
2057 && (dev
->active
!= 0)) {
2058 dev
->flags
|= AHC_DEV_FREEZE_TIL_EMPTY
;
2062 dev
->flags
&= ~(AHC_DEV_Q_BASIC
|AHC_DEV_Q_TAGGED
|AHC_DEV_PERIODIC_OTAG
);
2066 usertags
= ahc_linux_user_tagdepth(ahc
, devinfo
);
2069 * Start out agressively and allow our
2070 * dynamic queue depth algorithm to take
2073 dev
->maxtags
= usertags
;
2074 dev
->openings
= dev
->maxtags
- dev
->active
;
2076 if (dev
->maxtags
== 0) {
2078 * Queueing is disabled by the user.
2081 } else if (alg
== AHC_QUEUE_TAGGED
) {
2082 dev
->flags
|= AHC_DEV_Q_TAGGED
;
2083 if (aic7xxx_periodic_otag
!= 0)
2084 dev
->flags
|= AHC_DEV_PERIODIC_OTAG
;
2086 dev
->flags
|= AHC_DEV_Q_BASIC
;
2088 /* We can only have one opening. */
2090 dev
->openings
= 1 - dev
->active
;
2092 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
2093 if (dev
->scsi_device
!= NULL
) {
2094 switch ((dev
->flags
& (AHC_DEV_Q_BASIC
|AHC_DEV_Q_TAGGED
))) {
2095 case AHC_DEV_Q_BASIC
:
2096 scsi_adjust_queue_depth(dev
->scsi_device
,
2098 dev
->openings
+ dev
->active
);
2100 case AHC_DEV_Q_TAGGED
:
2101 scsi_adjust_queue_depth(dev
->scsi_device
,
2103 dev
->openings
+ dev
->active
);
2107 * We allow the OS to queue 2 untagged transactions to
2108 * us at any time even though we can only execute them
2109 * serially on the controller/device. This should
2110 * remove some latency.
2112 scsi_adjust_queue_depth(dev
->scsi_device
,
2122 ahc_platform_abort_scbs(struct ahc_softc
*ahc
, int target
, char channel
,
2123 int lun
, u_int tag
, role_t role
, uint32_t status
)
2133 if (tag
!= SCB_LIST_NULL
)
2137 if (channel
!= ALL_CHANNELS
) {
2138 chan
= channel
- 'A';
2141 maxchan
= (ahc
->features
& AHC_TWIN
) ? 2 : 1;
2144 if (target
!= CAM_TARGET_WILDCARD
) {
2148 maxtarg
= (ahc
->features
& AHC_WIDE
) ? 16 : 8;
2151 if (lun
!= CAM_LUN_WILDCARD
) {
2155 maxlun
= AHC_NUM_LUNS
;
2159 for (; chan
< maxchan
; chan
++) {
2161 for (; targ
< maxtarg
; targ
++) {
2163 for (; clun
< maxlun
; clun
++) {
2164 struct ahc_linux_device
*dev
;
2165 struct ahc_busyq
*busyq
;
2166 struct ahc_cmd
*acmd
;
2168 dev
= ahc_linux_get_device(ahc
, chan
,
2174 busyq
= &dev
->busyq
;
2175 while ((acmd
= TAILQ_FIRST(busyq
)) != NULL
) {
2178 cmd
= &acmd_scsi_cmd(acmd
);
2179 TAILQ_REMOVE(busyq
, acmd
,
2182 cmd
->result
= status
<< 16;
2183 ahc_linux_queue_cmd_complete(ahc
, cmd
);
2193 ahc_linux_thread_run_complete_queue(struct ahc_softc
*ahc
)
2197 ahc_lock(ahc
, &flags
);
2198 del_timer(&ahc
->platform_data
->completeq_timer
);
2199 ahc
->platform_data
->flags
&= ~AHC_RUN_CMPLT_Q_TIMER
;
2200 ahc_linux_run_complete_queue(ahc
);
2201 ahc_unlock(ahc
, &flags
);
2205 ahc_linux_start_dv(struct ahc_softc
*ahc
)
2209 * Freeze the simq and signal ahc_linux_queue to not let any
2210 * more commands through.
2212 if ((ahc
->platform_data
->flags
& AHC_DV_ACTIVE
) == 0) {
2214 if (ahc_debug
& AHC_SHOW_DV
)
2215 printf("%s: Waking DV thread\n", ahc_name(ahc
));
2218 ahc
->platform_data
->flags
|= AHC_DV_ACTIVE
;
2219 ahc_linux_freeze_simq(ahc
);
2221 /* Wake up the DV kthread */
2222 up(&ahc
->platform_data
->dv_sem
);
2227 ahc_linux_kill_dv_thread(struct ahc_softc
*ahc
)
2232 if (ahc
->platform_data
->dv_pid
!= 0) {
2233 ahc
->platform_data
->flags
|= AHC_DV_SHUTDOWN
;
2234 ahc_unlock(ahc
, &s
);
2235 up(&ahc
->platform_data
->dv_sem
);
2238 * Use the eh_sem as an indicator that the
2239 * dv thread is exiting. Note that the dv
2240 * thread must still return after performing
2241 * the up on our semaphore before it has
2242 * completely exited this module. Unfortunately,
2243 * there seems to be no easy way to wait for the
2244 * exit of a thread for which you are not the
2245 * parent (dv threads are parented by init).
2246 * Cross your fingers...
2248 down(&ahc
->platform_data
->eh_sem
);
2251 * Mark the dv thread as already dead. This
2252 * avoids attempting to kill it a second time.
2253 * This is necessary because we must kill the
2254 * DV thread before calling ahc_free() in the
2255 * module shutdown case to avoid bogus locking
2256 * in the SCSI mid-layer, but we ahc_free() is
2257 * called without killing the DV thread in the
2258 * instance detach case, so ahc_platform_free()
2259 * calls us again to verify that the DV thread
2262 ahc
->platform_data
->dv_pid
= 0;
2264 ahc_unlock(ahc
, &s
);
2269 ahc_linux_dv_thread(void *data
)
2271 struct ahc_softc
*ahc
;
2275 ahc
= (struct ahc_softc
*)data
;
2278 if (ahc_debug
& AHC_SHOW_DV
)
2279 printf("Launching DV Thread\n");
2283 * Complete thread creation.
2286 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
2288 * Don't care about any signals.
2290 siginitsetinv(¤t
->blocked
, 0);
2293 sprintf(current
->comm
, "ahc_dv_%d", ahc
->unit
);
2295 daemonize("ahc_dv_%d", ahc
->unit
);
2296 current
->flags
|= PF_FREEZE
;
2302 * Use down_interruptible() rather than down() to
2303 * avoid inclusion in the load average.
2305 down_interruptible(&ahc
->platform_data
->dv_sem
);
2307 /* Check to see if we've been signaled to exit */
2309 if ((ahc
->platform_data
->flags
& AHC_DV_SHUTDOWN
) != 0) {
2310 ahc_unlock(ahc
, &s
);
2313 ahc_unlock(ahc
, &s
);
2316 if (ahc_debug
& AHC_SHOW_DV
)
2317 printf("%s: Beginning Domain Validation\n",
2322 * Wait for any pending commands to drain before proceeding.
2325 while (LIST_FIRST(&ahc
->pending_scbs
) != NULL
) {
2326 ahc
->platform_data
->flags
|= AHC_DV_WAIT_SIMQ_EMPTY
;
2327 ahc_unlock(ahc
, &s
);
2328 down_interruptible(&ahc
->platform_data
->dv_sem
);
2333 * Wait for the SIMQ to be released so that DV is the
2334 * only reason the queue is frozen.
2336 while (AHC_DV_SIMQ_FROZEN(ahc
) == 0) {
2337 ahc
->platform_data
->flags
|= AHC_DV_WAIT_SIMQ_RELEASE
;
2338 ahc_unlock(ahc
, &s
);
2339 down_interruptible(&ahc
->platform_data
->dv_sem
);
2342 ahc_unlock(ahc
, &s
);
2344 for (target
= 0; target
< AHC_NUM_TARGETS
; target
++)
2345 ahc_linux_dv_target(ahc
, target
);
2348 ahc
->platform_data
->flags
&= ~AHC_DV_ACTIVE
;
2349 ahc_unlock(ahc
, &s
);
2352 * Release the SIMQ so that normal commands are
2353 * allowed to continue on the bus.
2355 ahc_linux_release_simq((u_long
)ahc
);
2357 up(&ahc
->platform_data
->eh_sem
);
2361 #define AHC_LINUX_DV_INQ_SHORT_LEN 36
2362 #define AHC_LINUX_DV_INQ_LEN 256
2363 #define AHC_LINUX_DV_TIMEOUT (HZ / 4)
2365 #define AHC_SET_DV_STATE(ahc, targ, newstate) \
2366 ahc_set_dv_state(ahc, targ, newstate, __LINE__)
2368 static __inline
void
2369 ahc_set_dv_state(struct ahc_softc
*ahc
, struct ahc_linux_target
*targ
,
2370 ahc_dv_state newstate
, u_int line
)
2372 ahc_dv_state oldstate
;
2374 oldstate
= targ
->dv_state
;
2376 if (ahc_debug
& AHC_SHOW_DV
)
2377 printf("%s:%d: Going from state %d to state %d\n",
2378 ahc_name(ahc
), line
, oldstate
, newstate
);
2381 if (oldstate
== newstate
)
2382 targ
->dv_state_retry
++;
2384 targ
->dv_state_retry
= 0;
2385 targ
->dv_state
= newstate
;
2389 ahc_linux_dv_target(struct ahc_softc
*ahc
, u_int target_offset
)
2391 struct ahc_devinfo devinfo
;
2392 struct ahc_linux_target
*targ
;
2393 struct scsi_cmnd
*cmd
;
2394 struct scsi_device
*scsi_dev
;
2395 struct scsi_sense_data
*sense
;
2405 targ
= ahc
->platform_data
->targets
[target_offset
];
2406 if (targ
== NULL
|| (targ
->flags
& AHC_DV_REQUIRED
) == 0) {
2407 ahc_unlock(ahc
, &s
);
2410 ahc_compile_devinfo(&devinfo
,
2411 targ
->channel
== 0 ? ahc
->our_id
: ahc
->our_id_b
,
2412 targ
->target
, /*lun*/0, targ
->channel
+ 'A',
2415 if (ahc_debug
& AHC_SHOW_DV
) {
2416 ahc_print_devinfo(ahc
, &devinfo
);
2417 printf("Performing DV\n");
2421 ahc_unlock(ahc
, &s
);
2423 cmd
= malloc(sizeof(struct scsi_cmnd
), M_DEVBUF
, M_WAITOK
);
2424 scsi_dev
= malloc(sizeof(struct scsi_device
), M_DEVBUF
, M_WAITOK
);
2425 scsi_dev
->host
= ahc
->platform_data
->host
;
2426 scsi_dev
->id
= devinfo
.target
;
2427 scsi_dev
->lun
= devinfo
.lun
;
2428 scsi_dev
->channel
= devinfo
.channel
- 'A';
2429 ahc
->platform_data
->dv_scsi_dev
= scsi_dev
;
2431 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_INQ_SHORT_ASYNC
);
2433 while (targ
->dv_state
!= AHC_DV_STATE_EXIT
) {
2434 timeout
= AHC_LINUX_DV_TIMEOUT
;
2435 switch (targ
->dv_state
) {
2436 case AHC_DV_STATE_INQ_SHORT_ASYNC
:
2437 case AHC_DV_STATE_INQ_ASYNC
:
2438 case AHC_DV_STATE_INQ_ASYNC_VERIFY
:
2440 * Set things to async narrow to reduce the
2441 * chance that the INQ will fail.
2444 ahc_set_syncrate(ahc
, &devinfo
, NULL
, 0, 0, 0,
2445 AHC_TRANS_GOAL
, /*paused*/FALSE
);
2446 ahc_set_width(ahc
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
2447 AHC_TRANS_GOAL
, /*paused*/FALSE
);
2448 ahc_unlock(ahc
, &s
);
2450 targ
->flags
&= ~AHC_INQ_VALID
;
2452 case AHC_DV_STATE_INQ_VERIFY
:
2456 if (targ
->dv_state
== AHC_DV_STATE_INQ_SHORT_ASYNC
)
2457 inq_len
= AHC_LINUX_DV_INQ_SHORT_LEN
;
2459 inq_len
= targ
->inq_data
->additional_length
+ 5;
2460 ahc_linux_dv_inq(ahc
, cmd
, &devinfo
, targ
, inq_len
);
2463 case AHC_DV_STATE_TUR
:
2464 case AHC_DV_STATE_BUSY
:
2466 ahc_linux_dv_tur(ahc
, cmd
, &devinfo
);
2468 case AHC_DV_STATE_REBD
:
2469 ahc_linux_dv_rebd(ahc
, cmd
, &devinfo
, targ
);
2471 case AHC_DV_STATE_WEB
:
2472 ahc_linux_dv_web(ahc
, cmd
, &devinfo
, targ
);
2475 case AHC_DV_STATE_REB
:
2476 ahc_linux_dv_reb(ahc
, cmd
, &devinfo
, targ
);
2479 case AHC_DV_STATE_SU
:
2480 ahc_linux_dv_su(ahc
, cmd
, &devinfo
, targ
);
2485 ahc_print_devinfo(ahc
, &devinfo
);
2486 printf("Unknown DV state %d\n", targ
->dv_state
);
2490 /* Queue the command and wait for it to complete */
2491 /* Abuse eh_timeout in the scsi_cmnd struct for our purposes */
2492 init_timer(&cmd
->eh_timeout
);
2494 if ((ahc_debug
& AHC_SHOW_MESSAGES
) != 0)
2496 * All of the printfs during negotiation
2497 * really slow down the negotiation.
2498 * Add a bit of time just to be safe.
2502 scsi_add_timer(cmd
, timeout
, ahc_linux_dv_timeout
);
2504 * In 2.5.X, it is assumed that all calls from the
2505 * "midlayer" (which we are emulating) will have the
2506 * ahc host lock held. For other kernels, the
2507 * io_request_lock must be held.
2509 #if AHC_SCSI_HAS_HOST_LOCK != 0
2512 spin_lock_irqsave(&io_request_lock
, s
);
2514 ahc_linux_queue(cmd
, ahc_linux_dv_complete
);
2515 #if AHC_SCSI_HAS_HOST_LOCK != 0
2516 ahc_unlock(ahc
, &s
);
2518 spin_unlock_irqrestore(&io_request_lock
, s
);
2520 down_interruptible(&ahc
->platform_data
->dv_cmd_sem
);
2522 * Wait for the SIMQ to be released so that DV is the
2523 * only reason the queue is frozen.
2526 while (AHC_DV_SIMQ_FROZEN(ahc
) == 0) {
2527 ahc
->platform_data
->flags
|= AHC_DV_WAIT_SIMQ_RELEASE
;
2528 ahc_unlock(ahc
, &s
);
2529 down_interruptible(&ahc
->platform_data
->dv_sem
);
2532 ahc_unlock(ahc
, &s
);
2534 ahc_linux_dv_transition(ahc
, cmd
, &devinfo
, targ
);
2538 if ((targ
->flags
& AHC_INQ_VALID
) != 0
2539 && ahc_linux_get_device(ahc
, devinfo
.channel
- 'A',
2540 devinfo
.target
, devinfo
.lun
,
2541 /*alloc*/FALSE
) == NULL
) {
2543 * The DV state machine failed to configure this device.
2544 * This is normal if DV is disabled. Since we have inquiry
2545 * data, filter it and use the "optimistic" negotiation
2546 * parameters found in the inquiry string.
2548 ahc_linux_filter_inquiry(ahc
, &devinfo
);
2549 if ((targ
->flags
& (AHC_BASIC_DV
|AHC_ENHANCED_DV
)) != 0) {
2550 ahc_print_devinfo(ahc
, &devinfo
);
2551 printf("DV failed to configure device. "
2552 "Please file a bug report against "
2558 free(cmd
, M_DEVBUF
);
2560 if (ahc
->platform_data
->dv_scsi_dev
!= NULL
) {
2561 free(ahc
->platform_data
->dv_scsi_dev
, M_DEVBUF
);
2562 ahc
->platform_data
->dv_scsi_dev
= NULL
;
2566 if (targ
->dv_buffer
!= NULL
) {
2567 free(targ
->dv_buffer
, M_DEVBUF
);
2568 targ
->dv_buffer
= NULL
;
2570 if (targ
->dv_buffer1
!= NULL
) {
2571 free(targ
->dv_buffer1
, M_DEVBUF
);
2572 targ
->dv_buffer1
= NULL
;
2574 targ
->flags
&= ~AHC_DV_REQUIRED
;
2575 if (targ
->refcount
== 0)
2576 ahc_linux_free_target(ahc
, targ
);
2577 ahc_unlock(ahc
, &s
);
2581 ahc_linux_dv_transition(struct ahc_softc
*ahc
, struct scsi_cmnd
*cmd
,
2582 struct ahc_devinfo
*devinfo
,
2583 struct ahc_linux_target
*targ
)
2587 status
= aic_error_action(cmd
, targ
->inq_data
,
2588 ahc_cmd_get_transaction_status(cmd
),
2589 ahc_cmd_get_scsi_status(cmd
));
2592 if (ahc_debug
& AHC_SHOW_DV
) {
2593 ahc_print_devinfo(ahc
, devinfo
);
2594 printf("Entering ahc_linux_dv_transition, state= %d, "
2595 "status= 0x%x, cmd->result= 0x%x\n", targ
->dv_state
,
2596 status
, cmd
->result
);
2600 switch (targ
->dv_state
) {
2601 case AHC_DV_STATE_INQ_SHORT_ASYNC
:
2602 case AHC_DV_STATE_INQ_ASYNC
:
2603 switch (status
& SS_MASK
) {
2606 AHC_SET_DV_STATE(ahc
, targ
, targ
->dv_state
+1);
2609 case SS_INQ_REFRESH
:
2610 AHC_SET_DV_STATE(ahc
, targ
,
2611 AHC_DV_STATE_INQ_SHORT_ASYNC
);
2615 AHC_SET_DV_STATE(ahc
, targ
, targ
->dv_state
);
2616 if (ahc_cmd_get_transaction_status(cmd
)
2618 targ
->dv_state_retry
--;
2619 if ((status
& SS_ERRMASK
) == EBUSY
)
2620 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_BUSY
);
2621 if (targ
->dv_state_retry
< 10)
2625 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
2627 if (ahc_debug
& AHC_SHOW_DV
) {
2628 ahc_print_devinfo(ahc
, devinfo
);
2629 printf("Failed DV inquiry, skipping\n");
2635 case AHC_DV_STATE_INQ_ASYNC_VERIFY
:
2636 switch (status
& SS_MASK
) {
2642 if (memcmp(targ
->inq_data
, targ
->dv_buffer
,
2643 AHC_LINUX_DV_INQ_LEN
) != 0) {
2645 * Inquiry data must have changed.
2646 * Try from the top again.
2648 AHC_SET_DV_STATE(ahc
, targ
,
2649 AHC_DV_STATE_INQ_SHORT_ASYNC
);
2653 AHC_SET_DV_STATE(ahc
, targ
, targ
->dv_state
+1);
2654 targ
->flags
|= AHC_INQ_VALID
;
2655 if (ahc_linux_user_dv_setting(ahc
) == 0)
2658 xportflags
= targ
->inq_data
->flags
;
2659 if ((xportflags
& (SID_Sync
|SID_WBus16
)) == 0)
2662 spi3data
= targ
->inq_data
->spi3data
;
2663 switch (spi3data
& SID_SPI_CLOCK_DT_ST
) {
2665 case SID_SPI_CLOCK_ST
:
2666 /* Assume only basic DV is supported. */
2667 targ
->flags
|= AHC_BASIC_DV
;
2669 case SID_SPI_CLOCK_DT
:
2670 case SID_SPI_CLOCK_DT_ST
:
2671 targ
->flags
|= AHC_ENHANCED_DV
;
2676 case SS_INQ_REFRESH
:
2677 AHC_SET_DV_STATE(ahc
, targ
,
2678 AHC_DV_STATE_INQ_SHORT_ASYNC
);
2682 AHC_SET_DV_STATE(ahc
, targ
, targ
->dv_state
);
2683 if (ahc_cmd_get_transaction_status(cmd
)
2685 targ
->dv_state_retry
--;
2687 if ((status
& SS_ERRMASK
) == EBUSY
)
2688 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_BUSY
);
2689 if (targ
->dv_state_retry
< 10)
2693 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
2695 if (ahc_debug
& AHC_SHOW_DV
) {
2696 ahc_print_devinfo(ahc
, devinfo
);
2697 printf("Failed DV inquiry, skipping\n");
2703 case AHC_DV_STATE_INQ_VERIFY
:
2704 switch (status
& SS_MASK
) {
2708 if (memcmp(targ
->inq_data
, targ
->dv_buffer
,
2709 AHC_LINUX_DV_INQ_LEN
) == 0) {
2710 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
2714 if (ahc_debug
& AHC_SHOW_DV
) {
2717 ahc_print_devinfo(ahc
, devinfo
);
2718 printf("Inquiry buffer mismatch:");
2719 for (i
= 0; i
< AHC_LINUX_DV_INQ_LEN
; i
++) {
2722 printf("0x%x:0x0%x ",
2723 ((uint8_t *)targ
->inq_data
)[i
],
2724 targ
->dv_buffer
[i
]);
2730 if (ahc_linux_fallback(ahc
, devinfo
) != 0) {
2731 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
2735 * Do not count "falling back"
2736 * against our retries.
2738 targ
->dv_state_retry
= 0;
2739 AHC_SET_DV_STATE(ahc
, targ
, targ
->dv_state
);
2742 case SS_INQ_REFRESH
:
2743 AHC_SET_DV_STATE(ahc
, targ
,
2744 AHC_DV_STATE_INQ_SHORT_ASYNC
);
2748 AHC_SET_DV_STATE(ahc
, targ
, targ
->dv_state
);
2749 if (ahc_cmd_get_transaction_status(cmd
)
2750 == CAM_REQUEUE_REQ
) {
2751 targ
->dv_state_retry
--;
2752 } else if ((status
& SSQ_FALLBACK
) != 0) {
2753 if (ahc_linux_fallback(ahc
, devinfo
) != 0) {
2754 AHC_SET_DV_STATE(ahc
, targ
,
2759 * Do not count "falling back"
2760 * against our retries.
2762 targ
->dv_state_retry
= 0;
2763 } else if ((status
& SS_ERRMASK
) == EBUSY
)
2764 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_BUSY
);
2765 if (targ
->dv_state_retry
< 10)
2769 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
2771 if (ahc_debug
& AHC_SHOW_DV
) {
2772 ahc_print_devinfo(ahc
, devinfo
);
2773 printf("Failed DV inquiry, skipping\n");
2780 case AHC_DV_STATE_TUR
:
2781 switch (status
& SS_MASK
) {
2783 if ((targ
->flags
& AHC_BASIC_DV
) != 0) {
2784 ahc_linux_filter_inquiry(ahc
, devinfo
);
2785 AHC_SET_DV_STATE(ahc
, targ
,
2786 AHC_DV_STATE_INQ_VERIFY
);
2787 } else if ((targ
->flags
& AHC_ENHANCED_DV
) != 0) {
2788 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_REBD
);
2790 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
2795 if ((status
& SS_ERRMASK
) == EBUSY
) {
2796 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_BUSY
);
2799 AHC_SET_DV_STATE(ahc
, targ
, targ
->dv_state
);
2800 if (ahc_cmd_get_transaction_status(cmd
)
2801 == CAM_REQUEUE_REQ
) {
2802 targ
->dv_state_retry
--;
2803 } else if ((status
& SSQ_FALLBACK
) != 0) {
2804 if (ahc_linux_fallback(ahc
, devinfo
) != 0) {
2805 AHC_SET_DV_STATE(ahc
, targ
,
2810 * Do not count "falling back"
2811 * against our retries.
2813 targ
->dv_state_retry
= 0;
2815 if (targ
->dv_state_retry
>= 10) {
2817 if (ahc_debug
& AHC_SHOW_DV
) {
2818 ahc_print_devinfo(ahc
, devinfo
);
2819 printf("DV TUR reties exhausted\n");
2822 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
2825 if (status
& SSQ_DELAY
)
2830 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_SU
);
2832 case SS_INQ_REFRESH
:
2833 AHC_SET_DV_STATE(ahc
, targ
,
2834 AHC_DV_STATE_INQ_SHORT_ASYNC
);
2837 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
2842 case AHC_DV_STATE_REBD
:
2843 switch (status
& SS_MASK
) {
2848 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_WEB
);
2849 echo_size
= scsi_3btoul(&targ
->dv_buffer
[1]);
2850 echo_size
&= 0x1FFF;
2852 if (ahc_debug
& AHC_SHOW_DV
) {
2853 ahc_print_devinfo(ahc
, devinfo
);
2854 printf("Echo buffer size= %d\n", echo_size
);
2857 if (echo_size
== 0) {
2858 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
2862 /* Generate the buffer pattern */
2863 targ
->dv_echo_size
= echo_size
;
2864 ahc_linux_generate_dv_pattern(targ
);
2866 * Setup initial negotiation values.
2868 ahc_linux_filter_inquiry(ahc
, devinfo
);
2871 case SS_INQ_REFRESH
:
2872 AHC_SET_DV_STATE(ahc
, targ
,
2873 AHC_DV_STATE_INQ_SHORT_ASYNC
);
2876 AHC_SET_DV_STATE(ahc
, targ
, targ
->dv_state
);
2877 if (ahc_cmd_get_transaction_status(cmd
)
2879 targ
->dv_state_retry
--;
2880 if (targ
->dv_state_retry
<= 10)
2883 if (ahc_debug
& AHC_SHOW_DV
) {
2884 ahc_print_devinfo(ahc
, devinfo
);
2885 printf("DV REBD reties exhausted\n");
2892 * Setup initial negotiation values
2893 * and try level 1 DV.
2895 ahc_linux_filter_inquiry(ahc
, devinfo
);
2896 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_INQ_VERIFY
);
2897 targ
->dv_echo_size
= 0;
2902 case AHC_DV_STATE_WEB
:
2903 switch (status
& SS_MASK
) {
2905 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_REB
);
2907 case SS_INQ_REFRESH
:
2908 AHC_SET_DV_STATE(ahc
, targ
,
2909 AHC_DV_STATE_INQ_SHORT_ASYNC
);
2912 AHC_SET_DV_STATE(ahc
, targ
, targ
->dv_state
);
2913 if (ahc_cmd_get_transaction_status(cmd
)
2914 == CAM_REQUEUE_REQ
) {
2915 targ
->dv_state_retry
--;
2916 } else if ((status
& SSQ_FALLBACK
) != 0) {
2917 if (ahc_linux_fallback(ahc
, devinfo
) != 0) {
2918 AHC_SET_DV_STATE(ahc
, targ
,
2923 * Do not count "falling back"
2924 * against our retries.
2926 targ
->dv_state_retry
= 0;
2928 if (targ
->dv_state_retry
<= 10)
2932 if (ahc_debug
& AHC_SHOW_DV
) {
2933 ahc_print_devinfo(ahc
, devinfo
);
2934 printf("DV WEB reties exhausted\n");
2938 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
2943 case AHC_DV_STATE_REB
:
2944 switch (status
& SS_MASK
) {
2946 if (memcmp(targ
->dv_buffer
, targ
->dv_buffer1
,
2947 targ
->dv_echo_size
) != 0) {
2948 if (ahc_linux_fallback(ahc
, devinfo
) != 0)
2949 AHC_SET_DV_STATE(ahc
, targ
,
2952 AHC_SET_DV_STATE(ahc
, targ
,
2957 if (targ
->dv_buffer
!= NULL
) {
2958 free(targ
->dv_buffer
, M_DEVBUF
);
2959 targ
->dv_buffer
= NULL
;
2961 if (targ
->dv_buffer1
!= NULL
) {
2962 free(targ
->dv_buffer1
, M_DEVBUF
);
2963 targ
->dv_buffer1
= NULL
;
2965 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
2967 case SS_INQ_REFRESH
:
2968 AHC_SET_DV_STATE(ahc
, targ
,
2969 AHC_DV_STATE_INQ_SHORT_ASYNC
);
2972 AHC_SET_DV_STATE(ahc
, targ
, targ
->dv_state
);
2973 if (ahc_cmd_get_transaction_status(cmd
)
2974 == CAM_REQUEUE_REQ
) {
2975 targ
->dv_state_retry
--;
2976 } else if ((status
& SSQ_FALLBACK
) != 0) {
2977 if (ahc_linux_fallback(ahc
, devinfo
) != 0) {
2978 AHC_SET_DV_STATE(ahc
, targ
,
2982 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_WEB
);
2984 if (targ
->dv_state_retry
<= 10) {
2985 if ((status
& (SSQ_DELAY_RANDOM
|SSQ_DELAY
))!= 0)
2986 msleep(ahc
->our_id
*1000/10);
2990 if (ahc_debug
& AHC_SHOW_DV
) {
2991 ahc_print_devinfo(ahc
, devinfo
);
2992 printf("DV REB reties exhausted\n");
2997 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
3002 case AHC_DV_STATE_SU
:
3003 switch (status
& SS_MASK
) {
3005 case SS_INQ_REFRESH
:
3006 AHC_SET_DV_STATE(ahc
, targ
,
3007 AHC_DV_STATE_INQ_SHORT_ASYNC
);
3010 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
3015 case AHC_DV_STATE_BUSY
:
3016 switch (status
& SS_MASK
) {
3018 case SS_INQ_REFRESH
:
3019 AHC_SET_DV_STATE(ahc
, targ
,
3020 AHC_DV_STATE_INQ_SHORT_ASYNC
);
3024 AHC_SET_DV_STATE(ahc
, targ
, targ
->dv_state
);
3025 if (ahc_cmd_get_transaction_status(cmd
)
3026 == CAM_REQUEUE_REQ
) {
3027 targ
->dv_state_retry
--;
3028 } else if (targ
->dv_state_retry
< 60) {
3029 if ((status
& SSQ_DELAY
) != 0)
3033 if (ahc_debug
& AHC_SHOW_DV
) {
3034 ahc_print_devinfo(ahc
, devinfo
);
3035 printf("DV BUSY reties exhausted\n");
3038 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
3042 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
3048 printf("%s: Invalid DV completion state %d\n", ahc_name(ahc
),
3050 AHC_SET_DV_STATE(ahc
, targ
, AHC_DV_STATE_EXIT
);
3056 ahc_linux_dv_fill_cmd(struct ahc_softc
*ahc
, struct scsi_cmnd
*cmd
,
3057 struct ahc_devinfo
*devinfo
)
3059 memset(cmd
, 0, sizeof(struct scsi_cmnd
));
3060 cmd
->device
= ahc
->platform_data
->dv_scsi_dev
;
3061 cmd
->scsi_done
= ahc_linux_dv_complete
;
3065 * Synthesize an inquiry command. On the return trip, it'll be
3066 * sniffed and the device transfer settings set for us.
3069 ahc_linux_dv_inq(struct ahc_softc
*ahc
, struct scsi_cmnd
*cmd
,
3070 struct ahc_devinfo
*devinfo
, struct ahc_linux_target
*targ
,
3071 u_int request_length
)
3075 if (ahc_debug
& AHC_SHOW_DV
) {
3076 ahc_print_devinfo(ahc
, devinfo
);
3077 printf("Sending INQ\n");
3080 if (targ
->inq_data
== NULL
)
3081 targ
->inq_data
= malloc(AHC_LINUX_DV_INQ_LEN
,
3082 M_DEVBUF
, M_WAITOK
);
3083 if (targ
->dv_state
> AHC_DV_STATE_INQ_ASYNC
) {
3084 if (targ
->dv_buffer
!= NULL
)
3085 free(targ
->dv_buffer
, M_DEVBUF
);
3086 targ
->dv_buffer
= malloc(AHC_LINUX_DV_INQ_LEN
,
3087 M_DEVBUF
, M_WAITOK
);
3090 ahc_linux_dv_fill_cmd(ahc
, cmd
, devinfo
);
3091 cmd
->sc_data_direction
= SCSI_DATA_READ
;
3093 cmd
->cmnd
[0] = INQUIRY
;
3094 cmd
->cmnd
[4] = request_length
;
3095 cmd
->request_bufflen
= request_length
;
3096 if (targ
->dv_state
> AHC_DV_STATE_INQ_ASYNC
)
3097 cmd
->request_buffer
= targ
->dv_buffer
;
3099 cmd
->request_buffer
= targ
->inq_data
;
3100 memset(cmd
->request_buffer
, 0, AHC_LINUX_DV_INQ_LEN
);
3104 ahc_linux_dv_tur(struct ahc_softc
*ahc
, struct scsi_cmnd
*cmd
,
3105 struct ahc_devinfo
*devinfo
)
3109 if (ahc_debug
& AHC_SHOW_DV
) {
3110 ahc_print_devinfo(ahc
, devinfo
);
3111 printf("Sending TUR\n");
3114 /* Do a TUR to clear out any non-fatal transitional state */
3115 ahc_linux_dv_fill_cmd(ahc
, cmd
, devinfo
);
3116 cmd
->sc_data_direction
= SCSI_DATA_NONE
;
3118 cmd
->cmnd
[0] = TEST_UNIT_READY
;
3121 #define AHC_REBD_LEN 4
3124 ahc_linux_dv_rebd(struct ahc_softc
*ahc
, struct scsi_cmnd
*cmd
,
3125 struct ahc_devinfo
*devinfo
, struct ahc_linux_target
*targ
)
3129 if (ahc_debug
& AHC_SHOW_DV
) {
3130 ahc_print_devinfo(ahc
, devinfo
);
3131 printf("Sending REBD\n");
3134 if (targ
->dv_buffer
!= NULL
)
3135 free(targ
->dv_buffer
, M_DEVBUF
);
3136 targ
->dv_buffer
= malloc(AHC_REBD_LEN
, M_DEVBUF
, M_WAITOK
);
3137 ahc_linux_dv_fill_cmd(ahc
, cmd
, devinfo
);
3138 cmd
->sc_data_direction
= SCSI_DATA_READ
;
3140 cmd
->cmnd
[0] = READ_BUFFER
;
3141 cmd
->cmnd
[1] = 0x0b;
3142 scsi_ulto3b(AHC_REBD_LEN
, &cmd
->cmnd
[6]);
3143 cmd
->request_bufflen
= AHC_REBD_LEN
;
3144 cmd
->underflow
= cmd
->request_bufflen
;
3145 cmd
->request_buffer
= targ
->dv_buffer
;
3149 ahc_linux_dv_web(struct ahc_softc
*ahc
, struct scsi_cmnd
*cmd
,
3150 struct ahc_devinfo
*devinfo
, struct ahc_linux_target
*targ
)
3154 if (ahc_debug
& AHC_SHOW_DV
) {
3155 ahc_print_devinfo(ahc
, devinfo
);
3156 printf("Sending WEB\n");
3159 ahc_linux_dv_fill_cmd(ahc
, cmd
, devinfo
);
3160 cmd
->sc_data_direction
= SCSI_DATA_WRITE
;
3162 cmd
->cmnd
[0] = WRITE_BUFFER
;
3163 cmd
->cmnd
[1] = 0x0a;
3164 scsi_ulto3b(targ
->dv_echo_size
, &cmd
->cmnd
[6]);
3165 cmd
->request_bufflen
= targ
->dv_echo_size
;
3166 cmd
->underflow
= cmd
->request_bufflen
;
3167 cmd
->request_buffer
= targ
->dv_buffer
;
3171 ahc_linux_dv_reb(struct ahc_softc
*ahc
, struct scsi_cmnd
*cmd
,
3172 struct ahc_devinfo
*devinfo
, struct ahc_linux_target
*targ
)
3176 if (ahc_debug
& AHC_SHOW_DV
) {
3177 ahc_print_devinfo(ahc
, devinfo
);
3178 printf("Sending REB\n");
3181 ahc_linux_dv_fill_cmd(ahc
, cmd
, devinfo
);
3182 cmd
->sc_data_direction
= SCSI_DATA_READ
;
3184 cmd
->cmnd
[0] = READ_BUFFER
;
3185 cmd
->cmnd
[1] = 0x0a;
3186 scsi_ulto3b(targ
->dv_echo_size
, &cmd
->cmnd
[6]);
3187 cmd
->request_bufflen
= targ
->dv_echo_size
;
3188 cmd
->underflow
= cmd
->request_bufflen
;
3189 cmd
->request_buffer
= targ
->dv_buffer1
;
3193 ahc_linux_dv_su(struct ahc_softc
*ahc
, struct scsi_cmnd
*cmd
,
3194 struct ahc_devinfo
*devinfo
,
3195 struct ahc_linux_target
*targ
)
3199 le
= SID_IS_REMOVABLE(targ
->inq_data
) ? SSS_LOEJ
: 0;
3202 if (ahc_debug
& AHC_SHOW_DV
) {
3203 ahc_print_devinfo(ahc
, devinfo
);
3204 printf("Sending SU\n");
3207 ahc_linux_dv_fill_cmd(ahc
, cmd
, devinfo
);
3208 cmd
->sc_data_direction
= SCSI_DATA_NONE
;
3210 cmd
->cmnd
[0] = START_STOP_UNIT
;
3211 cmd
->cmnd
[4] = le
| SSS_START
;
3215 ahc_linux_fallback(struct ahc_softc
*ahc
, struct ahc_devinfo
*devinfo
)
3217 struct ahc_linux_target
*targ
;
3218 struct ahc_initiator_tinfo
*tinfo
;
3219 struct ahc_transinfo
*goal
;
3220 struct ahc_tmode_tstate
*tstate
;
3221 struct ahc_syncrate
*syncrate
;
3230 u_int fallback_speed
;
3233 if (ahc_debug
& AHC_SHOW_DV
) {
3234 ahc_print_devinfo(ahc
, devinfo
);
3235 printf("Trying to fallback\n");
3239 targ
= ahc
->platform_data
->targets
[devinfo
->target_offset
];
3240 tinfo
= ahc_fetch_transinfo(ahc
, devinfo
->channel
,
3241 devinfo
->our_scsiid
,
3242 devinfo
->target
, &tstate
);
3243 goal
= &tinfo
->goal
;
3244 width
= goal
->width
;
3245 period
= goal
->period
;
3246 offset
= goal
->offset
;
3247 ppr_options
= goal
->ppr_options
;
3249 period
= AHC_ASYNC_XFER_PERIOD
;
3250 if (targ
->dv_next_narrow_period
== 0)
3251 targ
->dv_next_narrow_period
= MAX(period
, AHC_SYNCRATE_ULTRA2
);
3252 if (targ
->dv_next_wide_period
== 0)
3253 targ
->dv_next_wide_period
= period
;
3254 if (targ
->dv_max_width
== 0)
3255 targ
->dv_max_width
= width
;
3256 if (targ
->dv_max_ppr_options
== 0)
3257 targ
->dv_max_ppr_options
= ppr_options
;
3258 if (targ
->dv_last_ppr_options
== 0)
3259 targ
->dv_last_ppr_options
= ppr_options
;
3261 cur_speed
= aic_calc_speed(width
, period
, offset
, AHC_SYNCRATE_MIN
);
3262 wide_speed
= aic_calc_speed(MSG_EXT_WDTR_BUS_16_BIT
,
3263 targ
->dv_next_wide_period
,
3266 narrow_speed
= aic_calc_speed(MSG_EXT_WDTR_BUS_8_BIT
,
3267 targ
->dv_next_narrow_period
,
3270 fallback_speed
= aic_calc_speed(width
, period
+1, offset
,
3273 if (ahc_debug
& AHC_SHOW_DV
) {
3274 printf("cur_speed= %d, wide_speed= %d, narrow_speed= %d, "
3275 "fallback_speed= %d\n", cur_speed
, wide_speed
,
3276 narrow_speed
, fallback_speed
);
3280 if (cur_speed
> 160000) {
3282 * Paced/DT/IU_REQ only transfer speeds. All we
3283 * can do is fallback in terms of syncrate.
3286 } else if (cur_speed
> 80000) {
3287 if ((ppr_options
& MSG_EXT_PPR_IU_REQ
) != 0) {
3289 * Try without IU_REQ as it may be confusing
3292 ppr_options
&= ~MSG_EXT_PPR_IU_REQ
;
3295 * Paced/DT only transfer speeds. All we
3296 * can do is fallback in terms of syncrate.
3299 ppr_options
= targ
->dv_max_ppr_options
;
3301 } else if (cur_speed
> 3300) {
3304 * In this range we the following
3305 * options ordered from highest to
3306 * lowest desireability:
3310 * o Narrow at a potentally higher sync rate.
3312 * All modes are tested with and without IU_REQ
3313 * set since using IUs may confuse an expander.
3315 if ((ppr_options
& MSG_EXT_PPR_IU_REQ
) != 0) {
3317 ppr_options
&= ~MSG_EXT_PPR_IU_REQ
;
3318 } else if ((ppr_options
& MSG_EXT_PPR_DT_REQ
) != 0) {
3322 ppr_options
= targ
->dv_max_ppr_options
;
3323 ppr_options
&= ~MSG_EXT_PPR_DT_REQ
;
3324 } else if (targ
->dv_last_ppr_options
!= 0) {
3326 * Try without QAS or any other PPR options.
3327 * We may need a non-PPR message to work with
3328 * an expander. We look at the "last PPR options"
3329 * so we will perform this fallback even if the
3330 * target responded to our PPR negotiation with
3331 * no option bits set.
3334 } else if (width
== MSG_EXT_WDTR_BUS_16_BIT
) {
3336 * If the next narrow speed is greater than
3337 * the next wide speed, fallback to narrow.
3338 * Otherwise fallback to the next DT/Wide setting.
3339 * The narrow async speed will always be smaller
3340 * than the wide async speed, so handle this case
3343 ppr_options
= targ
->dv_max_ppr_options
;
3344 if (narrow_speed
> fallback_speed
3345 || period
>= AHC_ASYNC_XFER_PERIOD
) {
3346 targ
->dv_next_wide_period
= period
+1;
3347 width
= MSG_EXT_WDTR_BUS_8_BIT
;
3348 period
= targ
->dv_next_narrow_period
;
3352 } else if ((ahc
->features
& AHC_WIDE
) != 0
3353 && targ
->dv_max_width
!= 0
3354 && wide_speed
>= fallback_speed
3355 && (targ
->dv_next_wide_period
<= AHC_ASYNC_XFER_PERIOD
3356 || period
>= AHC_ASYNC_XFER_PERIOD
)) {
3359 * We are narrow. Try falling back
3360 * to the next wide speed with
3361 * all supported ppr options set.
3363 targ
->dv_next_narrow_period
= period
+1;
3364 width
= MSG_EXT_WDTR_BUS_16_BIT
;
3365 period
= targ
->dv_next_wide_period
;
3366 ppr_options
= targ
->dv_max_ppr_options
;
3368 /* Only narrow fallback is allowed. */
3370 ppr_options
= targ
->dv_max_ppr_options
;
3373 ahc_unlock(ahc
, &s
);
3376 offset
= MAX_OFFSET
;
3377 syncrate
= ahc_find_syncrate(ahc
, &period
, &ppr_options
,
3379 ahc_set_width(ahc
, devinfo
, width
, AHC_TRANS_GOAL
, FALSE
);
3384 if (width
== MSG_EXT_WDTR_BUS_8_BIT
)
3385 targ
->dv_next_narrow_period
= AHC_ASYNC_XFER_PERIOD
;
3387 targ
->dv_next_wide_period
= AHC_ASYNC_XFER_PERIOD
;
3389 ahc_set_syncrate(ahc
, devinfo
, syncrate
, period
, offset
,
3390 ppr_options
, AHC_TRANS_GOAL
, FALSE
);
3391 targ
->dv_last_ppr_options
= ppr_options
;
3392 ahc_unlock(ahc
, &s
);
3397 ahc_linux_dv_timeout(struct scsi_cmnd
*cmd
)
3399 struct ahc_softc
*ahc
;
3403 ahc
= *((struct ahc_softc
**)cmd
->device
->host
->hostdata
);
3404 ahc_lock(ahc
, &flags
);
3407 if (ahc_debug
& AHC_SHOW_DV
) {
3408 printf("%s: Timeout while doing DV command %x.\n",
3409 ahc_name(ahc
), cmd
->cmnd
[0]);
3410 ahc_dump_card_state(ahc
);
3415 * Guard against "done race". No action is
3416 * required if we just completed.
3418 if ((scb
= (struct scb
*)cmd
->host_scribble
) == NULL
) {
3419 ahc_unlock(ahc
, &flags
);
3424 * Command has not completed. Mark this
3425 * SCB as having failing status prior to
3426 * resetting the bus, so we get the correct
3429 if ((scb
->flags
& SCB_SENSE
) != 0)
3430 ahc_set_transaction_status(scb
, CAM_AUTOSENSE_FAIL
);
3432 ahc_set_transaction_status(scb
, CAM_CMD_TIMEOUT
);
3433 ahc_reset_channel(ahc
, cmd
->device
->channel
+ 'A', /*initiate*/TRUE
);
3436 * Add a minimal bus settle delay for devices that are slow to
3437 * respond after bus resets.
3439 ahc_linux_freeze_simq(ahc
);
3440 init_timer(&ahc
->platform_data
->reset_timer
);
3441 ahc
->platform_data
->reset_timer
.data
= (u_long
)ahc
;
3442 ahc
->platform_data
->reset_timer
.expires
= jiffies
+ HZ
/ 2;
3443 ahc
->platform_data
->reset_timer
.function
=
3444 (ahc_linux_callback_t
*)ahc_linux_release_simq
;
3445 add_timer(&ahc
->platform_data
->reset_timer
);
3446 if (ahc_linux_next_device_to_run(ahc
) != NULL
)
3447 ahc_schedule_runq(ahc
);
3448 ahc_linux_run_complete_queue(ahc
);
3449 ahc_unlock(ahc
, &flags
);
3453 ahc_linux_dv_complete(struct scsi_cmnd
*cmd
)
3455 struct ahc_softc
*ahc
;
3457 ahc
= *((struct ahc_softc
**)cmd
->device
->host
->hostdata
);
3459 /* Delete the DV timer before it goes off! */
3460 scsi_delete_timer(cmd
);
3463 if (ahc_debug
& AHC_SHOW_DV
)
3464 printf("%s:%d:%d: Command completed, status= 0x%x\n",
3465 ahc_name(ahc
), cmd
->device
->channel
,
3466 cmd
->device
->id
, cmd
->result
);
3469 /* Wake up the state machine */
3470 up(&ahc
->platform_data
->dv_cmd_sem
);
3474 ahc_linux_generate_dv_pattern(struct ahc_linux_target
*targ
)
3480 if (targ
->dv_buffer
!= NULL
)
3481 free(targ
->dv_buffer
, M_DEVBUF
);
3482 targ
->dv_buffer
= malloc(targ
->dv_echo_size
, M_DEVBUF
, M_WAITOK
);
3483 if (targ
->dv_buffer1
!= NULL
)
3484 free(targ
->dv_buffer1
, M_DEVBUF
);
3485 targ
->dv_buffer1
= malloc(targ
->dv_echo_size
, M_DEVBUF
, M_WAITOK
);
3489 for (j
= 0 ; i
< targ
->dv_echo_size
; j
++) {
3492 * 32bytes of sequential numbers.
3494 targ
->dv_buffer
[i
++] = j
& 0xff;
3495 } else if (j
< 48) {
3497 * 32bytes of repeating 0x0000, 0xffff.
3499 targ
->dv_buffer
[i
++] = (j
& 0x02) ? 0xff : 0x00;
3500 } else if (j
< 64) {
3502 * 32bytes of repeating 0x5555, 0xaaaa.
3504 targ
->dv_buffer
[i
++] = (j
& 0x02) ? 0xaa : 0x55;
3507 * Remaining buffer is filled with a repeating
3511 * ~0x0001 << shifted once in each loop.
3515 targ
->dv_buffer
[i
++] = ~(b
>> 8) & 0xff;
3520 targ
->dv_buffer
[i
++] = (~b
& 0xff);
3523 targ
->dv_buffer
[i
++] = 0xff;
3530 ahc_linux_user_tagdepth(struct ahc_softc
*ahc
, struct ahc_devinfo
*devinfo
)
3532 static int warned_user
;
3536 if ((ahc
->user_discenable
& devinfo
->target_mask
) != 0) {
3537 if (ahc
->unit
>= NUM_ELEMENTS(aic7xxx_tag_info
)) {
3538 if (warned_user
== 0) {
3541 "aic7xxx: WARNING: Insufficient tag_info instances\n"
3542 "aic7xxx: for installed controllers. Using defaults\n"
3543 "aic7xxx: Please update the aic7xxx_tag_info array in\n"
3544 "aic7xxx: the aic7xxx_osm..c source file.\n");
3547 tags
= AHC_MAX_QUEUE
;
3549 adapter_tag_info_t
*tag_info
;
3551 tag_info
= &aic7xxx_tag_info
[ahc
->unit
];
3552 tags
= tag_info
->tag_commands
[devinfo
->target_offset
];
3553 if (tags
> AHC_MAX_QUEUE
)
3554 tags
= AHC_MAX_QUEUE
;
3561 ahc_linux_user_dv_setting(struct ahc_softc
*ahc
)
3563 static int warned_user
;
3566 if (ahc
->unit
>= NUM_ELEMENTS(aic7xxx_dv_settings
)) {
3567 if (warned_user
== 0) {
3570 "aic7xxx: WARNING: Insufficient dv settings instances\n"
3571 "aic7xxx: for installed controllers. Using defaults\n"
3572 "aic7xxx: Please update the aic7xxx_dv_settings array\n"
3573 "aic7xxx: in the aic7xxx_osm.c source file.\n");
3579 dv
= aic7xxx_dv_settings
[ahc
->unit
];
3586 * Apply the default.
3589 * XXX - Enable DV on non-U160 controllers once it
3590 * has been tested there.
3593 dv
= (ahc
->features
& AHC_DT
);
3594 if (ahc
->seep_config
!= 0
3595 && ahc
->seep_config
->signature
>= CFSIGNATURE2
)
3596 dv
= (ahc
->seep_config
->adapter_control
& CFENABLEDV
);
3597 ahc_unlock(ahc
, &s
);
3603 * Determines the queue depth for a given device.
3606 ahc_linux_device_queue_depth(struct ahc_softc
*ahc
,
3607 struct ahc_linux_device
*dev
)
3609 struct ahc_devinfo devinfo
;
3612 ahc_compile_devinfo(&devinfo
,
3613 dev
->target
->channel
== 0
3614 ? ahc
->our_id
: ahc
->our_id_b
,
3615 dev
->target
->target
, dev
->lun
,
3616 dev
->target
->channel
== 0 ? 'A' : 'B',
3618 tags
= ahc_linux_user_tagdepth(ahc
, &devinfo
);
3620 && dev
->scsi_device
!= NULL
3621 && dev
->scsi_device
->tagged_supported
!= 0) {
3623 ahc_set_tags(ahc
, &devinfo
, AHC_QUEUE_TAGGED
);
3624 ahc_print_devinfo(ahc
, &devinfo
);
3625 printf("Tagged Queuing enabled. Depth %d\n", tags
);
3627 ahc_set_tags(ahc
, &devinfo
, AHC_QUEUE_NONE
);
3632 ahc_linux_run_device_queue(struct ahc_softc
*ahc
, struct ahc_linux_device
*dev
)
3634 struct ahc_cmd
*acmd
;
3635 struct scsi_cmnd
*cmd
;
3637 struct hardware_scb
*hscb
;
3638 struct ahc_initiator_tinfo
*tinfo
;
3639 struct ahc_tmode_tstate
*tstate
;
3642 if ((dev
->flags
& AHC_DEV_ON_RUN_LIST
) != 0)
3643 panic("running device on run list");
3645 while ((acmd
= TAILQ_FIRST(&dev
->busyq
)) != NULL
3646 && dev
->openings
> 0 && dev
->qfrozen
== 0) {
3649 * Schedule us to run later. The only reason we are not
3650 * running is because the whole controller Q is frozen.
3652 if (ahc
->platform_data
->qfrozen
!= 0
3653 && AHC_DV_SIMQ_FROZEN(ahc
) == 0) {
3654 TAILQ_INSERT_TAIL(&ahc
->platform_data
->device_runq
,
3656 dev
->flags
|= AHC_DEV_ON_RUN_LIST
;
3660 * Get an scb to use.
3662 if ((scb
= ahc_get_scb(ahc
)) == NULL
) {
3663 TAILQ_INSERT_TAIL(&ahc
->platform_data
->device_runq
,
3665 dev
->flags
|= AHC_DEV_ON_RUN_LIST
;
3666 ahc
->flags
|= AHC_RESOURCE_SHORTAGE
;
3669 TAILQ_REMOVE(&dev
->busyq
, acmd
, acmd_links
.tqe
);
3670 cmd
= &acmd_scsi_cmd(acmd
);
3672 scb
->platform_data
->dev
= dev
;
3674 cmd
->host_scribble
= (char *)scb
;
3677 * Fill out basics of the HSCB.
3680 hscb
->scsiid
= BUILD_SCSIID(ahc
, cmd
);
3681 hscb
->lun
= cmd
->device
->lun
;
3682 mask
= SCB_GET_TARGET_MASK(ahc
, scb
);
3683 tinfo
= ahc_fetch_transinfo(ahc
, SCB_GET_CHANNEL(ahc
, scb
),
3684 SCB_GET_OUR_ID(scb
),
3685 SCB_GET_TARGET(ahc
, scb
), &tstate
);
3686 hscb
->scsirate
= tinfo
->scsirate
;
3687 hscb
->scsioffset
= tinfo
->curr
.offset
;
3688 if ((tstate
->ultraenb
& mask
) != 0)
3689 hscb
->control
|= ULTRAENB
;
3691 if ((ahc
->user_discenable
& mask
) != 0)
3692 hscb
->control
|= DISCENB
;
3694 if (AHC_DV_CMD(cmd
) != 0)
3695 scb
->flags
|= SCB_SILENT
;
3697 if ((tstate
->auto_negotiate
& mask
) != 0) {
3698 scb
->flags
|= SCB_AUTO_NEGOTIATE
;
3699 scb
->hscb
->control
|= MK_MESSAGE
;
3702 if ((dev
->flags
& (AHC_DEV_Q_TAGGED
|AHC_DEV_Q_BASIC
)) != 0) {
3703 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
3705 uint8_t tag_msgs
[2];
3707 msg_bytes
= scsi_populate_tag_msg(cmd
, tag_msgs
);
3708 if (msg_bytes
&& tag_msgs
[0] != MSG_SIMPLE_TASK
) {
3709 hscb
->control
|= tag_msgs
[0];
3710 if (tag_msgs
[0] == MSG_ORDERED_TASK
)
3711 dev
->commands_since_idle_or_otag
= 0;
3714 if (dev
->commands_since_idle_or_otag
== AHC_OTAG_THRESH
3715 && (dev
->flags
& AHC_DEV_Q_TAGGED
) != 0) {
3716 hscb
->control
|= MSG_ORDERED_TASK
;
3717 dev
->commands_since_idle_or_otag
= 0;
3719 hscb
->control
|= MSG_SIMPLE_TASK
;
3723 hscb
->cdb_len
= cmd
->cmd_len
;
3724 if (hscb
->cdb_len
<= 12) {
3725 memcpy(hscb
->shared_data
.cdb
, cmd
->cmnd
, hscb
->cdb_len
);
3727 memcpy(hscb
->cdb32
, cmd
->cmnd
, hscb
->cdb_len
);
3728 scb
->flags
|= SCB_CDB32_PTR
;
3731 scb
->platform_data
->xfer_len
= 0;
3732 ahc_set_residual(scb
, 0);
3733 ahc_set_sense_residual(scb
, 0);
3735 if (cmd
->use_sg
!= 0) {
3736 struct ahc_dma_seg
*sg
;
3737 struct scatterlist
*cur_seg
;
3738 struct scatterlist
*end_seg
;
3741 cur_seg
= (struct scatterlist
*)cmd
->request_buffer
;
3742 nseg
= pci_map_sg(ahc
->dev_softc
, cur_seg
, cmd
->use_sg
,
3743 scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
3744 end_seg
= cur_seg
+ nseg
;
3745 /* Copy the segments into the SG list. */
3748 * The sg_count may be larger than nseg if
3749 * a transfer crosses a 32bit page.
3751 while (cur_seg
< end_seg
) {
3756 addr
= sg_dma_address(cur_seg
);
3757 len
= sg_dma_len(cur_seg
);
3758 consumed
= ahc_linux_map_seg(ahc
, scb
,
3761 scb
->sg_count
+= consumed
;
3765 sg
->len
|= ahc_htole32(AHC_DMA_LAST_SEG
);
3768 * Reset the sg list pointer.
3771 ahc_htole32(scb
->sg_list_phys
| SG_FULL_RESID
);
3774 * Copy the first SG into the "current"
3775 * data pointer area.
3777 scb
->hscb
->dataptr
= scb
->sg_list
->addr
;
3778 scb
->hscb
->datacnt
= scb
->sg_list
->len
;
3779 } else if (cmd
->request_bufflen
!= 0) {
3780 struct ahc_dma_seg
*sg
;
3784 addr
= pci_map_single(ahc
->dev_softc
,
3785 cmd
->request_buffer
,
3786 cmd
->request_bufflen
,
3787 scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
3788 scb
->platform_data
->buf_busaddr
= addr
;
3789 scb
->sg_count
= ahc_linux_map_seg(ahc
, scb
,
3791 cmd
->request_bufflen
);
3792 sg
->len
|= ahc_htole32(AHC_DMA_LAST_SEG
);
3795 * Reset the sg list pointer.
3798 ahc_htole32(scb
->sg_list_phys
| SG_FULL_RESID
);
3801 * Copy the first SG into the "current"
3802 * data pointer area.
3804 scb
->hscb
->dataptr
= sg
->addr
;
3805 scb
->hscb
->datacnt
= sg
->len
;
3807 scb
->hscb
->sgptr
= ahc_htole32(SG_LIST_NULL
);
3808 scb
->hscb
->dataptr
= 0;
3809 scb
->hscb
->datacnt
= 0;
3813 ahc_sync_sglist(ahc
, scb
, BUS_DMASYNC_PREWRITE
);
3814 LIST_INSERT_HEAD(&ahc
->pending_scbs
, scb
, pending_links
);
3817 dev
->commands_issued
++;
3818 if ((dev
->flags
& AHC_DEV_PERIODIC_OTAG
) != 0)
3819 dev
->commands_since_idle_or_otag
++;
3822 * We only allow one untagged transaction
3823 * per target in the initiator role unless
3824 * we are storing a full busy target *lun*
3825 * table in SCB space.
3827 if ((scb
->hscb
->control
& (TARGET_SCB
|TAG_ENB
)) == 0
3828 && (ahc
->features
& AHC_SCB_BTT
) == 0) {
3829 struct scb_tailq
*untagged_q
;
3832 target_offset
= SCB_GET_TARGET_OFFSET(ahc
, scb
);
3833 untagged_q
= &(ahc
->untagged_queues
[target_offset
]);
3834 TAILQ_INSERT_TAIL(untagged_q
, scb
, links
.tqe
);
3835 scb
->flags
|= SCB_UNTAGGEDQ
;
3836 if (TAILQ_FIRST(untagged_q
) != scb
)
3839 scb
->flags
|= SCB_ACTIVE
;
3840 ahc_queue_scb(ahc
, scb
);
3845 * SCSI controller interrupt handler.
3848 ahc_linux_isr(int irq
, void *dev_id
, struct pt_regs
* regs
)
3850 struct ahc_softc
*ahc
;
3854 ahc
= (struct ahc_softc
*) dev_id
;
3855 ahc_lock(ahc
, &flags
);
3856 ours
= ahc_intr(ahc
);
3857 if (ahc_linux_next_device_to_run(ahc
) != NULL
)
3858 ahc_schedule_runq(ahc
);
3859 ahc_linux_run_complete_queue(ahc
);
3860 ahc_unlock(ahc
, &flags
);
3861 return IRQ_RETVAL(ours
);
3865 ahc_platform_flushwork(struct ahc_softc
*ahc
)
3868 while (ahc_linux_run_complete_queue(ahc
) != NULL
)
3872 static struct ahc_linux_target
*
3873 ahc_linux_alloc_target(struct ahc_softc
*ahc
, u_int channel
, u_int target
)
3875 struct ahc_linux_target
*targ
;
3876 u_int target_offset
;
3878 target_offset
= target
;
3882 targ
= malloc(sizeof(*targ
), M_DEVBUG
, M_NOWAIT
);
3885 memset(targ
, 0, sizeof(*targ
));
3886 targ
->channel
= channel
;
3887 targ
->target
= target
;
3889 targ
->flags
= AHC_DV_REQUIRED
;
3890 ahc
->platform_data
->targets
[target_offset
] = targ
;
3895 ahc_linux_free_target(struct ahc_softc
*ahc
, struct ahc_linux_target
*targ
)
3897 struct ahc_devinfo devinfo
;
3898 struct ahc_initiator_tinfo
*tinfo
;
3899 struct ahc_tmode_tstate
*tstate
;
3901 u_int target_offset
;
3905 * Force a negotiation to async/narrow on any
3906 * future command to this device unless a bus
3907 * reset occurs between now and that command.
3909 channel
= 'A' + targ
->channel
;
3910 our_id
= ahc
->our_id
;
3911 target_offset
= targ
->target
;
3912 if (targ
->channel
!= 0) {
3914 our_id
= ahc
->our_id_b
;
3916 tinfo
= ahc_fetch_transinfo(ahc
, channel
, our_id
,
3917 targ
->target
, &tstate
);
3918 ahc_compile_devinfo(&devinfo
, our_id
, targ
->target
, CAM_LUN_WILDCARD
,
3919 channel
, ROLE_INITIATOR
);
3920 ahc_set_syncrate(ahc
, &devinfo
, NULL
, 0, 0, 0,
3921 AHC_TRANS_GOAL
, /*paused*/FALSE
);
3922 ahc_set_width(ahc
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
3923 AHC_TRANS_GOAL
, /*paused*/FALSE
);
3924 ahc_update_neg_request(ahc
, &devinfo
, tstate
, tinfo
, AHC_NEG_ALWAYS
);
3925 ahc
->platform_data
->targets
[target_offset
] = NULL
;
3926 if (targ
->inq_data
!= NULL
)
3927 free(targ
->inq_data
, M_DEVBUF
);
3928 if (targ
->dv_buffer
!= NULL
)
3929 free(targ
->dv_buffer
, M_DEVBUF
);
3930 if (targ
->dv_buffer1
!= NULL
)
3931 free(targ
->dv_buffer1
, M_DEVBUF
);
3932 free(targ
, M_DEVBUF
);
3935 static struct ahc_linux_device
*
3936 ahc_linux_alloc_device(struct ahc_softc
*ahc
,
3937 struct ahc_linux_target
*targ
, u_int lun
)
3939 struct ahc_linux_device
*dev
;
3941 dev
= malloc(sizeof(*dev
), M_DEVBUG
, M_NOWAIT
);
3944 memset(dev
, 0, sizeof(*dev
));
3945 init_timer(&dev
->timer
);
3946 TAILQ_INIT(&dev
->busyq
);
3947 dev
->flags
= AHC_DEV_UNCONFIGURED
;
3952 * We start out life using untagged
3953 * transactions of which we allow one.
3958 * Set maxtags to 0. This will be changed if we
3959 * later determine that we are dealing with
3960 * a tagged queuing capable device.
3965 targ
->devices
[lun
] = dev
;
3970 __ahc_linux_free_device(struct ahc_softc
*ahc
, struct ahc_linux_device
*dev
)
3972 struct ahc_linux_target
*targ
;
3975 targ
->devices
[dev
->lun
] = NULL
;
3976 free(dev
, M_DEVBUF
);
3978 if (targ
->refcount
== 0
3979 && (targ
->flags
& AHC_DV_REQUIRED
) == 0)
3980 ahc_linux_free_target(ahc
, targ
);
3984 ahc_linux_free_device(struct ahc_softc
*ahc
, struct ahc_linux_device
*dev
)
3986 del_timer_sync(&dev
->timer
);
3987 __ahc_linux_free_device(ahc
, dev
);
3991 ahc_send_async(struct ahc_softc
*ahc
, char channel
,
3992 u_int target
, u_int lun
, ac_code code
, void *arg
)
3995 case AC_TRANSFER_NEG
:
3998 struct ahc_linux_target
*targ
;
3999 struct info_str info
;
4000 struct ahc_initiator_tinfo
*tinfo
;
4001 struct ahc_tmode_tstate
*tstate
;
4005 info
.length
= sizeof(buf
);
4008 tinfo
= ahc_fetch_transinfo(ahc
, channel
,
4009 channel
== 'A' ? ahc
->our_id
4014 * Don't bother reporting results while
4015 * negotiations are still pending.
4017 if (tinfo
->curr
.period
!= tinfo
->goal
.period
4018 || tinfo
->curr
.width
!= tinfo
->goal
.width
4019 || tinfo
->curr
.offset
!= tinfo
->goal
.offset
4020 || tinfo
->curr
.ppr_options
!= tinfo
->goal
.ppr_options
)
4021 if (bootverbose
== 0)
4025 * Don't bother reporting results that
4026 * are identical to those last reported.
4028 target_offset
= target
;
4031 targ
= ahc
->platform_data
->targets
[target_offset
];
4034 if (tinfo
->curr
.period
== targ
->last_tinfo
.period
4035 && tinfo
->curr
.width
== targ
->last_tinfo
.width
4036 && tinfo
->curr
.offset
== targ
->last_tinfo
.offset
4037 && tinfo
->curr
.ppr_options
== targ
->last_tinfo
.ppr_options
)
4038 if (bootverbose
== 0)
4041 targ
->last_tinfo
.period
= tinfo
->curr
.period
;
4042 targ
->last_tinfo
.width
= tinfo
->curr
.width
;
4043 targ
->last_tinfo
.offset
= tinfo
->curr
.offset
;
4044 targ
->last_tinfo
.ppr_options
= tinfo
->curr
.ppr_options
;
4046 printf("(%s:%c:", ahc_name(ahc
), channel
);
4047 if (target
== CAM_TARGET_WILDCARD
)
4050 printf("%d): ", target
);
4051 ahc_format_transinfo(&info
, &tinfo
->curr
);
4052 if (info
.pos
< info
.length
)
4053 *info
.buffer
= '\0';
4055 buf
[info
.length
- 1] = '\0';
4061 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
4062 WARN_ON(lun
!= CAM_LUN_WILDCARD
);
4063 scsi_report_device_reset(ahc
->platform_data
->host
,
4064 channel
- 'A', target
);
4065 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
4066 Scsi_Device
*scsi_dev
;
4069 * Find the SCSI device associated with this
4070 * request and indicate that a UA is expected.
4072 for (scsi_dev
= ahc
->platform_data
->host
->host_queue
;
4073 scsi_dev
!= NULL
; scsi_dev
= scsi_dev
->next
) {
4074 if (channel
- 'A' == scsi_dev
->channel
4075 && target
== scsi_dev
->id
4076 && (lun
== CAM_LUN_WILDCARD
4077 || lun
== scsi_dev
->lun
)) {
4078 scsi_dev
->was_reset
= 1;
4079 scsi_dev
->expecting_cc_ua
= 1;
4086 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
4087 if (ahc
->platform_data
->host
!= NULL
) {
4088 scsi_report_bus_reset(ahc
->platform_data
->host
,
4094 panic("ahc_send_async: Unexpected async event");
4099 * Calls the higher level scsi done function and frees the scb.
4102 ahc_done(struct ahc_softc
*ahc
, struct scb
*scb
)
4105 struct ahc_linux_device
*dev
;
4107 LIST_REMOVE(scb
, pending_links
);
4108 if ((scb
->flags
& SCB_UNTAGGEDQ
) != 0) {
4109 struct scb_tailq
*untagged_q
;
4112 target_offset
= SCB_GET_TARGET_OFFSET(ahc
, scb
);
4113 untagged_q
= &(ahc
->untagged_queues
[target_offset
]);
4114 TAILQ_REMOVE(untagged_q
, scb
, links
.tqe
);
4115 ahc_run_untagged_queue(ahc
, untagged_q
);
4118 if ((scb
->flags
& SCB_ACTIVE
) == 0) {
4119 printf("SCB %d done'd twice\n", scb
->hscb
->tag
);
4120 ahc_dump_card_state(ahc
);
4121 panic("Stopping for safety");
4124 dev
= scb
->platform_data
->dev
;
4127 if ((cmd
->result
& (CAM_DEV_QFRZN
<< 16)) != 0) {
4128 cmd
->result
&= ~(CAM_DEV_QFRZN
<< 16);
4131 ahc_linux_unmap_scb(ahc
, scb
);
4134 * Guard against stale sense data.
4135 * The Linux mid-layer assumes that sense
4136 * was retrieved anytime the first byte of
4137 * the sense buffer looks "sane".
4139 cmd
->sense_buffer
[0] = 0;
4140 if (ahc_get_transaction_status(scb
) == CAM_REQ_INPROG
) {
4141 uint32_t amount_xferred
;
4144 ahc_get_transfer_length(scb
) - ahc_get_residual(scb
);
4145 if ((scb
->flags
& SCB_TRANSMISSION_ERROR
) != 0) {
4147 if ((ahc_debug
& AHC_SHOW_MISC
) != 0) {
4148 ahc_print_path(ahc
, scb
);
4149 printf("Set CAM_UNCOR_PARITY\n");
4152 ahc_set_transaction_status(scb
, CAM_UNCOR_PARITY
);
4153 #ifdef AHC_REPORT_UNDERFLOWS
4155 * This code is disabled by default as some
4156 * clients of the SCSI system do not properly
4157 * initialize the underflow parameter. This
4158 * results in spurious termination of commands
4159 * that complete as expected (e.g. underflow is
4160 * allowed as command can return variable amounts
4163 } else if (amount_xferred
< scb
->io_ctx
->underflow
) {
4166 ahc_print_path(ahc
, scb
);
4168 for (i
= 0; i
< scb
->io_ctx
->cmd_len
; i
++)
4169 printf(" 0x%x", scb
->io_ctx
->cmnd
[i
]);
4171 ahc_print_path(ahc
, scb
);
4172 printf("Saw underflow (%ld of %ld bytes). "
4173 "Treated as error\n",
4174 ahc_get_residual(scb
),
4175 ahc_get_transfer_length(scb
));
4176 ahc_set_transaction_status(scb
, CAM_DATA_RUN_ERR
);
4179 ahc_set_transaction_status(scb
, CAM_REQ_CMP
);
4181 } else if (ahc_get_transaction_status(scb
) == CAM_SCSI_STATUS_ERROR
) {
4182 ahc_linux_handle_scsi_status(ahc
, dev
, scb
);
4183 } else if (ahc_get_transaction_status(scb
) == CAM_SEL_TIMEOUT
) {
4184 dev
->flags
|= AHC_DEV_UNCONFIGURED
;
4185 if (AHC_DV_CMD(cmd
) == FALSE
)
4186 dev
->target
->flags
&= ~AHC_DV_REQUIRED
;
4189 * Start DV for devices that require it assuming the first command
4190 * sent does not result in a selection timeout.
4192 if (ahc_get_transaction_status(scb
) != CAM_SEL_TIMEOUT
4193 && (dev
->target
->flags
& AHC_DV_REQUIRED
) != 0)
4194 ahc_linux_start_dv(ahc
);
4196 if (dev
->openings
== 1
4197 && ahc_get_transaction_status(scb
) == CAM_REQ_CMP
4198 && ahc_get_scsi_status(scb
) != SCSI_STATUS_QUEUE_FULL
)
4199 dev
->tag_success_count
++;
4201 * Some devices deal with temporary internal resource
4202 * shortages by returning queue full. When the queue
4203 * full occurrs, we throttle back. Slowly try to get
4204 * back to our previous queue depth.
4206 if ((dev
->openings
+ dev
->active
) < dev
->maxtags
4207 && dev
->tag_success_count
> AHC_TAG_SUCCESS_INTERVAL
) {
4208 dev
->tag_success_count
= 0;
4212 if (dev
->active
== 0)
4213 dev
->commands_since_idle_or_otag
= 0;
4215 if (TAILQ_EMPTY(&dev
->busyq
)) {
4216 if ((dev
->flags
& AHC_DEV_UNCONFIGURED
) != 0
4218 && (dev
->flags
& AHC_DEV_TIMER_ACTIVE
) == 0)
4219 ahc_linux_free_device(ahc
, dev
);
4220 } else if ((dev
->flags
& AHC_DEV_ON_RUN_LIST
) == 0) {
4221 TAILQ_INSERT_TAIL(&ahc
->platform_data
->device_runq
, dev
, links
);
4222 dev
->flags
|= AHC_DEV_ON_RUN_LIST
;
4225 if ((scb
->flags
& SCB_RECOVERY_SCB
) != 0) {
4226 printf("Recovery SCB completes\n");
4227 if (ahc_get_transaction_status(scb
) == CAM_BDR_SENT
4228 || ahc_get_transaction_status(scb
) == CAM_REQ_ABORTED
)
4229 ahc_set_transaction_status(scb
, CAM_CMD_TIMEOUT
);
4230 if ((ahc
->platform_data
->flags
& AHC_UP_EH_SEMAPHORE
) != 0) {
4231 ahc
->platform_data
->flags
&= ~AHC_UP_EH_SEMAPHORE
;
4232 up(&ahc
->platform_data
->eh_sem
);
4236 ahc_free_scb(ahc
, scb
);
4237 ahc_linux_queue_cmd_complete(ahc
, cmd
);
4239 if ((ahc
->platform_data
->flags
& AHC_DV_WAIT_SIMQ_EMPTY
) != 0
4240 && LIST_FIRST(&ahc
->pending_scbs
) == NULL
) {
4241 ahc
->platform_data
->flags
&= ~AHC_DV_WAIT_SIMQ_EMPTY
;
4242 up(&ahc
->platform_data
->dv_sem
);
4248 ahc_linux_handle_scsi_status(struct ahc_softc
*ahc
,
4249 struct ahc_linux_device
*dev
, struct scb
*scb
)
4251 struct ahc_devinfo devinfo
;
4253 ahc_compile_devinfo(&devinfo
,
4255 dev
->target
->target
, dev
->lun
,
4256 dev
->target
->channel
== 0 ? 'A' : 'B',
4260 * We don't currently trust the mid-layer to
4261 * properly deal with queue full or busy. So,
4262 * when one occurs, we tell the mid-layer to
4263 * unconditionally requeue the command to us
4264 * so that we can retry it ourselves. We also
4265 * implement our own throttling mechanism so
4266 * we don't clobber the device with too many
4269 switch (ahc_get_scsi_status(scb
)) {
4272 case SCSI_STATUS_CHECK_COND
:
4273 case SCSI_STATUS_CMD_TERMINATED
:
4278 * Copy sense information to the OS's cmd
4279 * structure if it is available.
4282 if (scb
->flags
& SCB_SENSE
) {
4285 sense_size
= MIN(sizeof(struct scsi_sense_data
)
4286 - ahc_get_sense_residual(scb
),
4287 sizeof(cmd
->sense_buffer
));
4288 memcpy(cmd
->sense_buffer
,
4289 ahc_get_sense_buf(ahc
, scb
), sense_size
);
4290 if (sense_size
< sizeof(cmd
->sense_buffer
))
4291 memset(&cmd
->sense_buffer
[sense_size
], 0,
4292 sizeof(cmd
->sense_buffer
) - sense_size
);
4293 cmd
->result
|= (DRIVER_SENSE
<< 24);
4295 if (ahc_debug
& AHC_SHOW_SENSE
) {
4298 printf("Copied %d bytes of sense data:",
4300 for (i
= 0; i
< sense_size
; i
++) {
4303 printf("0x%x ", cmd
->sense_buffer
[i
]);
4311 case SCSI_STATUS_QUEUE_FULL
:
4314 * By the time the core driver has returned this
4315 * command, all other commands that were queued
4316 * to us but not the device have been returned.
4317 * This ensures that dev->active is equal to
4318 * the number of commands actually queued to
4321 dev
->tag_success_count
= 0;
4322 if (dev
->active
!= 0) {
4324 * Drop our opening count to the number
4325 * of commands currently outstanding.
4329 ahc_print_path(ahc, scb);
4330 printf("Dropping tag count to %d\n", dev->active);
4332 if (dev
->active
== dev
->tags_on_last_queuefull
) {
4334 dev
->last_queuefull_same_count
++;
4336 * If we repeatedly see a queue full
4337 * at the same queue depth, this
4338 * device has a fixed number of tag
4339 * slots. Lock in this tag depth
4340 * so we stop seeing queue fulls from
4343 if (dev
->last_queuefull_same_count
4344 == AHC_LOCK_TAGS_COUNT
) {
4345 dev
->maxtags
= dev
->active
;
4346 ahc_print_path(ahc
, scb
);
4347 printf("Locking max tag count at %d\n",
4351 dev
->tags_on_last_queuefull
= dev
->active
;
4352 dev
->last_queuefull_same_count
= 0;
4354 ahc_set_transaction_status(scb
, CAM_REQUEUE_REQ
);
4355 ahc_set_scsi_status(scb
, SCSI_STATUS_OK
);
4356 ahc_platform_set_tags(ahc
, &devinfo
,
4357 (dev
->flags
& AHC_DEV_Q_BASIC
)
4358 ? AHC_QUEUE_BASIC
: AHC_QUEUE_TAGGED
);
4362 * Drop down to a single opening, and treat this
4363 * as if the target returned BUSY SCSI status.
4366 ahc_set_scsi_status(scb
, SCSI_STATUS_BUSY
);
4367 ahc_platform_set_tags(ahc
, &devinfo
,
4368 (dev
->flags
& AHC_DEV_Q_BASIC
)
4369 ? AHC_QUEUE_BASIC
: AHC_QUEUE_TAGGED
);
4372 case SCSI_STATUS_BUSY
:
4375 * Set a short timer to defer sending commands for
4376 * a bit since Linux will not delay in this case.
4378 if ((dev
->flags
& AHC_DEV_TIMER_ACTIVE
) != 0) {
4379 printf("%s:%c:%d: Device Timer still active during "
4380 "busy processing\n", ahc_name(ahc
),
4381 dev
->target
->channel
, dev
->target
->target
);
4384 dev
->flags
|= AHC_DEV_TIMER_ACTIVE
;
4386 init_timer(&dev
->timer
);
4387 dev
->timer
.data
= (u_long
)dev
;
4388 dev
->timer
.expires
= jiffies
+ (HZ
/2);
4389 dev
->timer
.function
= ahc_linux_dev_timed_unfreeze
;
4390 add_timer(&dev
->timer
);
4397 ahc_linux_queue_cmd_complete(struct ahc_softc
*ahc
, Scsi_Cmnd
*cmd
)
4400 * Typically, the complete queue has very few entries
4401 * queued to it before the queue is emptied by
4402 * ahc_linux_run_complete_queue, so sorting the entries
4403 * by generation number should be inexpensive.
4404 * We perform the sort so that commands that complete
4405 * with an error are retuned in the order origionally
4406 * queued to the controller so that any subsequent retries
4407 * are performed in order. The underlying ahc routines do
4408 * not guarantee the order that aborted commands will be
4411 struct ahc_completeq
*completeq
;
4412 struct ahc_cmd
*list_cmd
;
4413 struct ahc_cmd
*acmd
;
4416 * Map CAM error codes into Linux Error codes. We
4417 * avoid the conversion so that the DV code has the
4418 * full error information available when making
4419 * state change decisions.
4421 if (AHC_DV_CMD(cmd
) == FALSE
) {
4424 switch (ahc_cmd_get_transaction_status(cmd
)) {
4425 case CAM_REQ_INPROG
:
4427 case CAM_SCSI_STATUS_ERROR
:
4428 new_status
= DID_OK
;
4430 case CAM_REQ_ABORTED
:
4431 new_status
= DID_ABORT
;
4434 new_status
= DID_BUS_BUSY
;
4436 case CAM_REQ_INVALID
:
4437 case CAM_PATH_INVALID
:
4438 new_status
= DID_BAD_TARGET
;
4440 case CAM_SEL_TIMEOUT
:
4441 new_status
= DID_NO_CONNECT
;
4443 case CAM_SCSI_BUS_RESET
:
4445 new_status
= DID_RESET
;
4447 case CAM_UNCOR_PARITY
:
4448 new_status
= DID_PARITY
;
4450 case CAM_CMD_TIMEOUT
:
4451 new_status
= DID_TIME_OUT
;
4454 case CAM_REQ_CMP_ERR
:
4455 case CAM_AUTOSENSE_FAIL
:
4457 case CAM_DATA_RUN_ERR
:
4458 case CAM_UNEXP_BUSFREE
:
4459 case CAM_SEQUENCE_FAIL
:
4460 case CAM_CCB_LEN_ERR
:
4461 case CAM_PROVIDE_FAIL
:
4462 case CAM_REQ_TERMIO
:
4463 case CAM_UNREC_HBA_ERROR
:
4464 case CAM_REQ_TOO_BIG
:
4465 new_status
= DID_ERROR
;
4467 case CAM_REQUEUE_REQ
:
4469 * If we want the request requeued, make sure there
4470 * are sufficent retries. In the old scsi error code,
4471 * we used to be able to specify a result code that
4472 * bypassed the retry count. Now we must use this
4473 * hack. We also "fake" a check condition with
4474 * a sense code of ABORTED COMMAND. This seems to
4475 * evoke a retry even if this command is being sent
4476 * via the eh thread. Ick! Ick! Ick!
4478 if (cmd
->retries
> 0)
4480 new_status
= DID_OK
;
4481 ahc_cmd_set_scsi_status(cmd
, SCSI_STATUS_CHECK_COND
);
4482 cmd
->result
|= (DRIVER_SENSE
<< 24);
4483 memset(cmd
->sense_buffer
, 0,
4484 sizeof(cmd
->sense_buffer
));
4485 cmd
->sense_buffer
[0] = SSD_ERRCODE_VALID
4486 | SSD_CURRENT_ERROR
;
4487 cmd
->sense_buffer
[2] = SSD_KEY_ABORTED_COMMAND
;
4490 /* We should never get here */
4491 new_status
= DID_ERROR
;
4495 ahc_cmd_set_transaction_status(cmd
, new_status
);
4498 completeq
= &ahc
->platform_data
->completeq
;
4499 list_cmd
= TAILQ_FIRST(completeq
);
4500 acmd
= (struct ahc_cmd
*)cmd
;
4501 while (list_cmd
!= NULL
4502 && acmd_scsi_cmd(list_cmd
).serial_number
4503 < acmd_scsi_cmd(acmd
).serial_number
)
4504 list_cmd
= TAILQ_NEXT(list_cmd
, acmd_links
.tqe
);
4505 if (list_cmd
!= NULL
)
4506 TAILQ_INSERT_BEFORE(list_cmd
, acmd
, acmd_links
.tqe
);
4508 TAILQ_INSERT_TAIL(completeq
, acmd
, acmd_links
.tqe
);
4512 ahc_linux_filter_inquiry(struct ahc_softc
*ahc
, struct ahc_devinfo
*devinfo
)
4514 struct scsi_inquiry_data
*sid
;
4515 struct ahc_initiator_tinfo
*tinfo
;
4516 struct ahc_transinfo
*user
;
4517 struct ahc_transinfo
*goal
;
4518 struct ahc_transinfo
*curr
;
4519 struct ahc_tmode_tstate
*tstate
;
4520 struct ahc_syncrate
*syncrate
;
4521 struct ahc_linux_device
*dev
;
4527 u_int trans_version
;
4531 * Determine if this lun actually exists. If so,
4532 * hold on to its corresponding device structure.
4533 * If not, make sure we release the device and
4534 * don't bother processing the rest of this inquiry
4537 dev
= ahc_linux_get_device(ahc
, devinfo
->channel
- 'A',
4538 devinfo
->target
, devinfo
->lun
,
4541 sid
= (struct scsi_inquiry_data
*)dev
->target
->inq_data
;
4542 if (SID_QUAL(sid
) == SID_QUAL_LU_CONNECTED
) {
4544 dev
->flags
&= ~AHC_DEV_UNCONFIGURED
;
4546 dev
->flags
|= AHC_DEV_UNCONFIGURED
;
4551 * Update our notion of this device's transfer
4552 * negotiation capabilities.
4554 tinfo
= ahc_fetch_transinfo(ahc
, devinfo
->channel
,
4555 devinfo
->our_scsiid
,
4556 devinfo
->target
, &tstate
);
4557 user
= &tinfo
->user
;
4558 goal
= &tinfo
->goal
;
4559 curr
= &tinfo
->curr
;
4560 width
= user
->width
;
4561 period
= user
->period
;
4562 offset
= user
->offset
;
4563 ppr_options
= user
->ppr_options
;
4564 trans_version
= user
->transport_version
;
4565 prot_version
= MIN(user
->protocol_version
, SID_ANSI_REV(sid
));
4568 * Only attempt SPI3/4 once we've verified that
4569 * the device claims to support SPI3/4 features.
4571 if (prot_version
< SCSI_REV_2
)
4572 trans_version
= SID_ANSI_REV(sid
);
4574 trans_version
= SCSI_REV_2
;
4576 if ((sid
->flags
& SID_WBus16
) == 0)
4577 width
= MSG_EXT_WDTR_BUS_8_BIT
;
4578 if ((sid
->flags
& SID_Sync
) == 0) {
4583 if ((sid
->spi3data
& SID_SPI_QAS
) == 0)
4584 ppr_options
&= ~MSG_EXT_PPR_QAS_REQ
;
4585 if ((sid
->spi3data
& SID_SPI_CLOCK_DT
) == 0)
4586 ppr_options
&= MSG_EXT_PPR_QAS_REQ
;
4587 if ((sid
->spi3data
& SID_SPI_IUS
) == 0)
4588 ppr_options
&= (MSG_EXT_PPR_DT_REQ
4589 | MSG_EXT_PPR_QAS_REQ
);
4591 if (prot_version
> SCSI_REV_2
4592 && ppr_options
!= 0)
4593 trans_version
= user
->transport_version
;
4595 ahc_validate_width(ahc
, /*tinfo limit*/NULL
, &width
, ROLE_UNKNOWN
);
4596 if ((ahc
->features
& AHC_ULTRA2
) != 0)
4597 maxsync
= AHC_SYNCRATE_DT
;
4598 else if ((ahc
->features
& AHC_ULTRA
) != 0)
4599 maxsync
= AHC_SYNCRATE_ULTRA
;
4601 maxsync
= AHC_SYNCRATE_FAST
;
4603 syncrate
= ahc_find_syncrate(ahc
, &period
, &ppr_options
, maxsync
);
4604 ahc_validate_offset(ahc
, /*tinfo limit*/NULL
, syncrate
,
4605 &offset
, width
, ROLE_UNKNOWN
);
4606 if (offset
== 0 || period
== 0) {
4611 /* Apply our filtered user settings. */
4612 curr
->transport_version
= trans_version
;
4613 curr
->protocol_version
= prot_version
;
4614 ahc_set_width(ahc
, devinfo
, width
, AHC_TRANS_GOAL
, /*paused*/FALSE
);
4615 ahc_set_syncrate(ahc
, devinfo
, syncrate
, period
,
4616 offset
, ppr_options
, AHC_TRANS_GOAL
,
4621 ahc_linux_sem_timeout(u_long arg
)
4623 struct ahc_softc
*ahc
;
4626 ahc
= (struct ahc_softc
*)arg
;
4629 if ((ahc
->platform_data
->flags
& AHC_UP_EH_SEMAPHORE
) != 0) {
4630 ahc
->platform_data
->flags
&= ~AHC_UP_EH_SEMAPHORE
;
4631 up(&ahc
->platform_data
->eh_sem
);
4633 ahc_unlock(ahc
, &s
);
4637 ahc_linux_freeze_simq(struct ahc_softc
*ahc
)
4639 ahc
->platform_data
->qfrozen
++;
4640 if (ahc
->platform_data
->qfrozen
== 1) {
4641 scsi_block_requests(ahc
->platform_data
->host
);
4643 /* XXX What about Twin channels? */
4644 ahc_platform_abort_scbs(ahc
, CAM_TARGET_WILDCARD
, ALL_CHANNELS
,
4645 CAM_LUN_WILDCARD
, SCB_LIST_NULL
,
4646 ROLE_INITIATOR
, CAM_REQUEUE_REQ
);
4651 ahc_linux_release_simq(u_long arg
)
4653 struct ahc_softc
*ahc
;
4657 ahc
= (struct ahc_softc
*)arg
;
4661 if (ahc
->platform_data
->qfrozen
> 0)
4662 ahc
->platform_data
->qfrozen
--;
4663 if (ahc
->platform_data
->qfrozen
== 0)
4665 if (AHC_DV_SIMQ_FROZEN(ahc
)
4666 && ((ahc
->platform_data
->flags
& AHC_DV_WAIT_SIMQ_RELEASE
) != 0)) {
4667 ahc
->platform_data
->flags
&= ~AHC_DV_WAIT_SIMQ_RELEASE
;
4668 up(&ahc
->platform_data
->dv_sem
);
4670 ahc_schedule_runq(ahc
);
4671 ahc_unlock(ahc
, &s
);
4673 * There is still a race here. The mid-layer
4674 * should keep its own freeze count and use
4675 * a bottom half handler to run the queues
4676 * so we can unblock with our own lock held.
4679 scsi_unblock_requests(ahc
->platform_data
->host
);
4683 ahc_linux_dev_timed_unfreeze(u_long arg
)
4685 struct ahc_linux_device
*dev
;
4686 struct ahc_softc
*ahc
;
4689 dev
= (struct ahc_linux_device
*)arg
;
4690 ahc
= dev
->target
->ahc
;
4692 dev
->flags
&= ~AHC_DEV_TIMER_ACTIVE
;
4693 if (dev
->qfrozen
> 0)
4695 if (dev
->qfrozen
== 0
4696 && (dev
->flags
& AHC_DEV_ON_RUN_LIST
) == 0)
4697 ahc_linux_run_device_queue(ahc
, dev
);
4698 if (TAILQ_EMPTY(&dev
->busyq
)
4699 && dev
->active
== 0)
4700 __ahc_linux_free_device(ahc
, dev
);
4701 ahc_unlock(ahc
, &s
);
4705 ahc_linux_queue_recovery_cmd(Scsi_Cmnd
*cmd
, scb_flag flag
)
4707 struct ahc_softc
*ahc
;
4708 struct ahc_cmd
*acmd
;
4709 struct ahc_cmd
*list_acmd
;
4710 struct ahc_linux_device
*dev
;
4711 struct scb
*pending_scb
;
4714 u_int active_scb_index
;
4727 ahc
= *(struct ahc_softc
**)cmd
->device
->host
->hostdata
;
4728 acmd
= (struct ahc_cmd
*)cmd
;
4730 printf("%s:%d:%d:%d: Attempting to queue a%s message\n",
4731 ahc_name(ahc
), cmd
->device
->channel
,
4732 cmd
->device
->id
, cmd
->device
->lun
,
4733 flag
== SCB_ABORT
? "n ABORT" : " TARGET RESET");
4736 for (cdb_byte
= 0; cdb_byte
< cmd
->cmd_len
; cdb_byte
++)
4737 printf(" 0x%x", cmd
->cmnd
[cdb_byte
]);
4741 * In all versions of Linux, we have to work around
4742 * a major flaw in how the mid-layer is locked down
4743 * if we are to sleep successfully in our error handler
4744 * while allowing our interrupt handler to run. Since
4745 * the midlayer acquires either the io_request_lock or
4746 * our lock prior to calling us, we must use the
4747 * spin_unlock_irq() method for unlocking our lock.
4748 * This will force interrupts to be enabled on the
4749 * current CPU. Since the EH thread should not have
4750 * been running with CPU interrupts disabled other than
4751 * by acquiring either the io_request_lock or our own
4752 * lock, this *should* be safe.
4754 ahc_midlayer_entrypoint_lock(ahc
, &s
);
4757 * First determine if we currently own this command.
4758 * Start by searching the device queue. If not found
4759 * there, check the pending_scb list. If not found
4760 * at all, and the system wanted us to just abort the
4761 * command, return success.
4763 dev
= ahc_linux_get_device(ahc
, cmd
->device
->channel
, cmd
->device
->id
,
4764 cmd
->device
->lun
, /*alloc*/FALSE
);
4768 * No target device for this command exists,
4769 * so we must not still own the command.
4771 printf("%s:%d:%d:%d: Is not an active device\n",
4772 ahc_name(ahc
), cmd
->device
->channel
, cmd
->device
->id
,
4778 TAILQ_FOREACH(list_acmd
, &dev
->busyq
, acmd_links
.tqe
) {
4779 if (list_acmd
== acmd
)
4783 if (list_acmd
!= NULL
) {
4784 printf("%s:%d:%d:%d: Command found on device queue\n",
4785 ahc_name(ahc
), cmd
->device
->channel
, cmd
->device
->id
,
4787 if (flag
== SCB_ABORT
) {
4788 TAILQ_REMOVE(&dev
->busyq
, list_acmd
, acmd_links
.tqe
);
4789 cmd
->result
= DID_ABORT
<< 16;
4790 ahc_linux_queue_cmd_complete(ahc
, cmd
);
4796 if ((dev
->flags
& (AHC_DEV_Q_BASIC
|AHC_DEV_Q_TAGGED
)) == 0
4797 && ahc_search_untagged_queues(ahc
, cmd
, cmd
->device
->id
,
4798 cmd
->device
->channel
+ 'A',
4800 CAM_REQ_ABORTED
, SEARCH_COMPLETE
) != 0) {
4801 printf("%s:%d:%d:%d: Command found on untagged queue\n",
4802 ahc_name(ahc
), cmd
->device
->channel
, cmd
->device
->id
,
4809 * See if we can find a matching cmd in the pending list.
4811 LIST_FOREACH(pending_scb
, &ahc
->pending_scbs
, pending_links
) {
4812 if (pending_scb
->io_ctx
== cmd
)
4816 if (pending_scb
== NULL
&& flag
== SCB_DEVICE_RESET
) {
4818 /* Any SCB for this device will do for a target reset */
4819 LIST_FOREACH(pending_scb
, &ahc
->pending_scbs
, pending_links
) {
4820 if (ahc_match_scb(ahc
, pending_scb
, cmd
->device
->id
,
4821 cmd
->device
->channel
+ 'A',
4823 SCB_LIST_NULL
, ROLE_INITIATOR
) == 0)
4828 if (pending_scb
== NULL
) {
4829 printf("%s:%d:%d:%d: Command not found\n",
4830 ahc_name(ahc
), cmd
->device
->channel
, cmd
->device
->id
,
4835 if ((pending_scb
->flags
& SCB_RECOVERY_SCB
) != 0) {
4837 * We can't queue two recovery actions using the same SCB
4844 * Ensure that the card doesn't do anything
4845 * behind our back and that we didn't "just" miss
4846 * an interrupt that would affect this cmd.
4848 was_paused
= ahc_is_paused(ahc
);
4849 ahc_pause_and_flushwork(ahc
);
4852 if ((pending_scb
->flags
& SCB_ACTIVE
) == 0) {
4853 printf("%s:%d:%d:%d: Command already completed\n",
4854 ahc_name(ahc
), cmd
->device
->channel
, cmd
->device
->id
,
4859 printf("%s: At time of recovery, card was %spaused\n",
4860 ahc_name(ahc
), was_paused
? "" : "not ");
4861 ahc_dump_card_state(ahc
);
4863 disconnected
= TRUE
;
4864 if (flag
== SCB_ABORT
) {
4865 if (ahc_search_qinfifo(ahc
, cmd
->device
->id
,
4866 cmd
->device
->channel
+ 'A',
4868 pending_scb
->hscb
->tag
,
4869 ROLE_INITIATOR
, CAM_REQ_ABORTED
,
4870 SEARCH_COMPLETE
) > 0) {
4871 printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
4872 ahc_name(ahc
), cmd
->device
->channel
,
4873 cmd
->device
->id
, cmd
->device
->lun
);
4877 } else if (ahc_search_qinfifo(ahc
, cmd
->device
->id
,
4878 cmd
->device
->channel
+ 'A',
4879 cmd
->device
->lun
, pending_scb
->hscb
->tag
,
4880 ROLE_INITIATOR
, /*status*/0,
4881 SEARCH_COUNT
) > 0) {
4882 disconnected
= FALSE
;
4885 if (disconnected
&& (ahc_inb(ahc
, SEQ_FLAGS
) & NOT_IDENTIFIED
) == 0) {
4886 struct scb
*bus_scb
;
4888 bus_scb
= ahc_lookup_scb(ahc
, ahc_inb(ahc
, SCB_TAG
));
4889 if (bus_scb
== pending_scb
)
4890 disconnected
= FALSE
;
4891 else if (flag
!= SCB_ABORT
4892 && ahc_inb(ahc
, SAVED_SCSIID
) == pending_scb
->hscb
->scsiid
4893 && ahc_inb(ahc
, SAVED_LUN
) == SCB_GET_LUN(pending_scb
))
4894 disconnected
= FALSE
;
4898 * At this point, pending_scb is the scb associated with the
4899 * passed in command. That command is currently active on the
4900 * bus, is in the disconnected state, or we're hoping to find
4901 * a command for the same target active on the bus to abuse to
4902 * send a BDR. Queue the appropriate message based on which of
4903 * these states we are in.
4905 last_phase
= ahc_inb(ahc
, LASTPHASE
);
4906 saved_scbptr
= ahc_inb(ahc
, SCBPTR
);
4907 active_scb_index
= ahc_inb(ahc
, SCB_TAG
);
4908 saved_scsiid
= ahc_inb(ahc
, SAVED_SCSIID
);
4909 if (last_phase
!= P_BUSFREE
4910 && (pending_scb
->hscb
->tag
== active_scb_index
4911 || (flag
== SCB_DEVICE_RESET
4912 && SCSIID_TARGET(ahc
, saved_scsiid
) == cmd
->device
->id
))) {
4915 * We're active on the bus, so assert ATN
4916 * and hope that the target responds.
4918 pending_scb
= ahc_lookup_scb(ahc
, active_scb_index
);
4919 pending_scb
->flags
|= SCB_RECOVERY_SCB
|flag
;
4920 ahc_outb(ahc
, MSG_OUT
, HOST_MSG
);
4921 ahc_outb(ahc
, SCSISIGO
, last_phase
|ATNO
);
4922 printf("%s:%d:%d:%d: Device is active, asserting ATN\n",
4923 ahc_name(ahc
), cmd
->device
->channel
, cmd
->device
->id
,
4926 } else if (disconnected
) {
4929 * Actually re-queue this SCB in an attempt
4930 * to select the device before it reconnects.
4931 * In either case (selection or reselection),
4932 * we will now issue the approprate message
4933 * to the timed-out device.
4935 * Set the MK_MESSAGE control bit indicating
4936 * that we desire to send a message. We
4937 * also set the disconnected flag since
4938 * in the paging case there is no guarantee
4939 * that our SCB control byte matches the
4940 * version on the card. We don't want the
4941 * sequencer to abort the command thinking
4942 * an unsolicited reselection occurred.
4944 pending_scb
->hscb
->control
|= MK_MESSAGE
|DISCONNECTED
;
4945 pending_scb
->flags
|= SCB_RECOVERY_SCB
|flag
;
4948 * Remove any cached copy of this SCB in the
4949 * disconnected list in preparation for the
4950 * queuing of our abort SCB. We use the
4951 * same element in the SCB, SCB_NEXT, for
4952 * both the qinfifo and the disconnected list.
4954 ahc_search_disc_list(ahc
, cmd
->device
->id
,
4955 cmd
->device
->channel
+ 'A',
4956 cmd
->device
->lun
, pending_scb
->hscb
->tag
,
4957 /*stop_on_first*/TRUE
,
4959 /*save_state*/FALSE
);
4962 * In the non-paging case, the sequencer will
4963 * never re-reference the in-core SCB.
4964 * To make sure we are notified during
4965 * reslection, set the MK_MESSAGE flag in
4966 * the card's copy of the SCB.
4968 if ((ahc
->flags
& AHC_PAGESCBS
) == 0) {
4969 ahc_outb(ahc
, SCBPTR
, pending_scb
->hscb
->tag
);
4970 ahc_outb(ahc
, SCB_CONTROL
,
4971 ahc_inb(ahc
, SCB_CONTROL
)|MK_MESSAGE
);
4975 * Clear out any entries in the QINFIFO first
4976 * so we are the next SCB for this target
4979 ahc_search_qinfifo(ahc
, cmd
->device
->id
,
4980 cmd
->device
->channel
+ 'A',
4981 cmd
->device
->lun
, SCB_LIST_NULL
,
4982 ROLE_INITIATOR
, CAM_REQUEUE_REQ
,
4984 ahc_qinfifo_requeue_tail(ahc
, pending_scb
);
4985 ahc_outb(ahc
, SCBPTR
, saved_scbptr
);
4986 ahc_print_path(ahc
, pending_scb
);
4987 printf("Device is disconnected, re-queuing SCB\n");
4990 printf("%s:%d:%d:%d: Unable to deliver message\n",
4991 ahc_name(ahc
), cmd
->device
->channel
, cmd
->device
->id
,
4999 * Our assumption is that if we don't have the command, no
5000 * recovery action was required, so we return success. Again,
5001 * the semantics of the mid-layer recovery engine are not
5002 * well defined, so this may change in time.
5009 struct timer_list timer
;
5012 ahc
->platform_data
->flags
|= AHC_UP_EH_SEMAPHORE
;
5013 spin_unlock_irq(&ahc
->platform_data
->spin_lock
);
5015 timer
.data
= (u_long
)ahc
;
5016 timer
.expires
= jiffies
+ (5 * HZ
);
5017 timer
.function
= ahc_linux_sem_timeout
;
5019 printf("Recovery code sleeping\n");
5020 down(&ahc
->platform_data
->eh_sem
);
5021 printf("Recovery code awake\n");
5022 ret
= del_timer_sync(&timer
);
5024 printf("Timer Expired\n");
5027 spin_lock_irq(&ahc
->platform_data
->spin_lock
);
5029 ahc_schedule_runq(ahc
);
5030 ahc_linux_run_complete_queue(ahc
);
5031 ahc_midlayer_entrypoint_unlock(ahc
, &s
);
5036 ahc_platform_dump_card_state(struct ahc_softc
*ahc
)
5038 struct ahc_linux_device
*dev
;
5046 maxchannel
= (ahc
->features
& AHC_TWIN
) ? 1 : 0;
5047 maxtarget
= (ahc
->features
& AHC_WIDE
) ? 15 : 7;
5048 for (channel
= 0; channel
<= maxchannel
; channel
++) {
5050 for (target
= 0; target
<=maxtarget
; target
++) {
5052 for (lun
= 0; lun
< AHC_NUM_LUNS
; lun
++) {
5053 struct ahc_cmd
*acmd
;
5055 dev
= ahc_linux_get_device(ahc
, channel
, target
,
5056 lun
, /*alloc*/FALSE
);
5060 printf("DevQ(%d:%d:%d): ",
5061 channel
, target
, lun
);
5063 TAILQ_FOREACH(acmd
, &dev
->busyq
,
5065 if (i
++ > AHC_SCB_MAX
)
5068 printf("%d waiting\n", i
);
5074 static void ahc_linux_exit(void);
5077 ahc_linux_init(void)
5079 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
5080 int rc
= ahc_linux_detect(&aic7xxx_driver_template
);
5086 scsi_register_module(MODULE_SCSI_HA
, &aic7xxx_driver_template
);
5087 if (aic7xxx_driver_template
.present
== 0) {
5088 scsi_unregister_module(MODULE_SCSI_HA
,
5089 &aic7xxx_driver_template
);
5098 ahc_linux_exit(void)
5100 struct ahc_softc
*ahc
;
5104 * Shutdown DV threads before going into the SCSI mid-layer.
5105 * This avoids situations where the mid-layer locks the entire
5106 * kernel so that waiting for our DV threads to exit leads
5110 TAILQ_FOREACH(ahc
, &ahc_tailq
, links
) {
5112 ahc_linux_kill_dv_thread(ahc
);
5114 ahc_list_unlock(&l
);
5116 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
5118 * In 2.4 we have to unregister from the PCI core _after_
5119 * unregistering from the scsi midlayer to avoid dangling
5122 scsi_unregister_module(MODULE_SCSI_HA
, &aic7xxx_driver_template
);
5124 ahc_linux_pci_exit();
5125 ahc_linux_eisa_exit();
5128 module_init(ahc_linux_init
);
5129 module_exit(ahc_linux_exit
);