Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Adaptec AIC7xxx device driver for Linux. |
| 3 | * |
| 4 | * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.c#235 $ |
| 5 | * |
| 6 | * Copyright (c) 1994 John Aycock |
| 7 | * The University of Calgary Department of Computer Science. |
| 8 | * |
| 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) |
| 12 | * any later version. |
| 13 | * |
| 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. |
| 18 | * |
| 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. |
| 22 | * |
| 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), ... |
| 31 | * |
| 32 | * -------------------------------------------------------------------------- |
| 33 | * |
| 34 | * Modifications by Daniel M. Eischen (deischen@iworks.InterWorks.org): |
| 35 | * |
| 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. |
| 39 | * |
| 40 | * -------------------------------------------------------------------------- |
| 41 | * Copyright (c) 1994-2000 Justin T. Gibbs. |
| 42 | * Copyright (c) 2000-2001 Adaptec Inc. |
| 43 | * All rights reserved. |
| 44 | * |
| 45 | * Redistribution and use in source and binary forms, with or without |
| 46 | * modification, are permitted provided that the following conditions |
| 47 | * are met: |
| 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. |
| 59 | * |
| 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. |
| 63 | * |
| 64 | * NO WARRANTY |
| 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. |
| 76 | * |
| 77 | *--------------------------------------------------------------------------- |
| 78 | * |
| 79 | * Thanks also go to (in alphabetical order) the following: |
| 80 | * |
| 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 |
| 85 | * |
| 86 | * A Boot time option was also added for not resetting the scsi bus. |
| 87 | * |
| 88 | * Form: aic7xxx=extended |
| 89 | * aic7xxx=no_reset |
| 90 | * aic7xxx=verbose |
| 91 | * |
| 92 | * Daniel M. Eischen, deischen@iworks.InterWorks.org, 1/23/97 |
| 93 | * |
| 94 | * Id: aic7xxx.c,v 4.1 1997/06/12 08:23:42 deang Exp |
| 95 | */ |
| 96 | |
| 97 | /* |
| 98 | * Further driver modifications made by Doug Ledford <dledford@redhat.com> |
| 99 | * |
| 100 | * Copyright (c) 1997-1999 Doug Ledford |
| 101 | * |
| 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. |
| 106 | * |
| 107 | * Modifications made to the aic7xxx.c,v 4.1 driver from Dan Eischen include |
| 108 | * but are not limited to: |
| 109 | * |
| 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 |
| 119 | * |
| 120 | */ |
| 121 | |
| 122 | #include "aic7xxx_osm.h" |
| 123 | #include "aic7xxx_inline.h" |
| 124 | #include <scsi/scsicam.h> |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 125 | |
| 126 | static struct scsi_transport_template *ahc_linux_transport_template = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * Include aiclib.c as part of our |
| 130 | * "module dependencies are hard" work around. |
| 131 | */ |
| 132 | #include "aiclib.c" |
| 133 | |
| 134 | #include <linux/init.h> /* __setup */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | #include <linux/mm.h> /* For fetching system memory size */ |
| 136 | #include <linux/blkdev.h> /* For block_size() */ |
| 137 | #include <linux/delay.h> /* For ssleep/msleep */ |
| 138 | |
| 139 | /* |
| 140 | * Lock protecting manipulation of the ahc softc list. |
| 141 | */ |
| 142 | spinlock_t ahc_list_spinlock; |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* |
| 145 | * Set this to the delay in seconds after SCSI bus reset. |
| 146 | * Note, we honor this only for the initial bus reset. |
| 147 | * The scsi error recovery code performs its own bus settle |
| 148 | * delay handling for error recovery actions. |
| 149 | */ |
| 150 | #ifdef CONFIG_AIC7XXX_RESET_DELAY_MS |
| 151 | #define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RESET_DELAY_MS |
| 152 | #else |
| 153 | #define AIC7XXX_RESET_DELAY 5000 |
| 154 | #endif |
| 155 | |
| 156 | /* |
| 157 | * Control collection of SCSI transfer statistics for the /proc filesystem. |
| 158 | * |
| 159 | * NOTE: Do NOT enable this when running on kernels version 1.2.x and below. |
| 160 | * NOTE: This does affect performance since it has to maintain statistics. |
| 161 | */ |
| 162 | #ifdef CONFIG_AIC7XXX_PROC_STATS |
| 163 | #define AIC7XXX_PROC_STATS |
| 164 | #endif |
| 165 | |
| 166 | /* |
| 167 | * To change the default number of tagged transactions allowed per-device, |
| 168 | * add a line to the lilo.conf file like: |
| 169 | * append="aic7xxx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}" |
| 170 | * which will result in the first four devices on the first two |
| 171 | * controllers being set to a tagged queue depth of 32. |
| 172 | * |
| 173 | * The tag_commands is an array of 16 to allow for wide and twin adapters. |
| 174 | * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15 |
| 175 | * for channel 1. |
| 176 | */ |
| 177 | typedef struct { |
| 178 | uint8_t tag_commands[16]; /* Allow for wide/twin adapters. */ |
| 179 | } adapter_tag_info_t; |
| 180 | |
| 181 | /* |
| 182 | * Modify this as you see fit for your system. |
| 183 | * |
| 184 | * 0 tagged queuing disabled |
| 185 | * 1 <= n <= 253 n == max tags ever dispatched. |
| 186 | * |
| 187 | * The driver will throttle the number of commands dispatched to a |
| 188 | * device if it returns queue full. For devices with a fixed maximum |
| 189 | * queue depth, the driver will eventually determine this depth and |
| 190 | * lock it in (a console message is printed to indicate that a lock |
| 191 | * has occurred). On some devices, queue full is returned for a temporary |
| 192 | * resource shortage. These devices will return queue full at varying |
| 193 | * depths. The driver will throttle back when the queue fulls occur and |
| 194 | * attempt to slowly increase the depth over time as the device recovers |
| 195 | * from the resource shortage. |
| 196 | * |
| 197 | * In this example, the first line will disable tagged queueing for all |
| 198 | * the devices on the first probed aic7xxx adapter. |
| 199 | * |
| 200 | * The second line enables tagged queueing with 4 commands/LUN for IDs |
| 201 | * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the |
| 202 | * driver to attempt to use up to 64 tags for ID 1. |
| 203 | * |
| 204 | * The third line is the same as the first line. |
| 205 | * |
| 206 | * The fourth line disables tagged queueing for devices 0 and 3. It |
| 207 | * enables tagged queueing for the other IDs, with 16 commands/LUN |
| 208 | * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for |
| 209 | * IDs 2, 5-7, and 9-15. |
| 210 | */ |
| 211 | |
| 212 | /* |
| 213 | * NOTE: The below structure is for reference only, the actual structure |
| 214 | * to modify in order to change things is just below this comment block. |
| 215 | adapter_tag_info_t aic7xxx_tag_info[] = |
| 216 | { |
| 217 | {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, |
| 218 | {{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}}, |
| 219 | {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, |
| 220 | {{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}} |
| 221 | }; |
| 222 | */ |
| 223 | |
| 224 | #ifdef CONFIG_AIC7XXX_CMDS_PER_DEVICE |
| 225 | #define AIC7XXX_CMDS_PER_DEVICE CONFIG_AIC7XXX_CMDS_PER_DEVICE |
| 226 | #else |
| 227 | #define AIC7XXX_CMDS_PER_DEVICE AHC_MAX_QUEUE |
| 228 | #endif |
| 229 | |
| 230 | #define AIC7XXX_CONFIGED_TAG_COMMANDS { \ |
| 231 | AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ |
| 232 | AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ |
| 233 | AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ |
| 234 | AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ |
| 235 | AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ |
| 236 | AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ |
| 237 | AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ |
| 238 | AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE \ |
| 239 | } |
| 240 | |
| 241 | /* |
| 242 | * By default, use the number of commands specified by |
| 243 | * the users kernel configuration. |
| 244 | */ |
| 245 | static adapter_tag_info_t aic7xxx_tag_info[] = |
| 246 | { |
| 247 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 248 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 249 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 250 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 251 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 252 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 253 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 254 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 255 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 256 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 257 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 258 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 259 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 260 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 261 | {AIC7XXX_CONFIGED_TAG_COMMANDS}, |
| 262 | {AIC7XXX_CONFIGED_TAG_COMMANDS} |
| 263 | }; |
| 264 | |
| 265 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | * There should be a specific return value for this in scsi.h, but |
| 267 | * it seems that most drivers ignore it. |
| 268 | */ |
| 269 | #define DID_UNDERFLOW DID_ERROR |
| 270 | |
| 271 | void |
| 272 | ahc_print_path(struct ahc_softc *ahc, struct scb *scb) |
| 273 | { |
| 274 | printk("(scsi%d:%c:%d:%d): ", |
| 275 | ahc->platform_data->host->host_no, |
| 276 | scb != NULL ? SCB_GET_CHANNEL(ahc, scb) : 'X', |
| 277 | scb != NULL ? SCB_GET_TARGET(ahc, scb) : -1, |
| 278 | scb != NULL ? SCB_GET_LUN(scb) : -1); |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | * XXX - these options apply unilaterally to _all_ 274x/284x/294x |
| 283 | * cards in the system. This should be fixed. Exceptions to this |
| 284 | * rule are noted in the comments. |
| 285 | */ |
| 286 | |
| 287 | /* |
| 288 | * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This |
| 289 | * has no effect on any later resets that might occur due to things like |
| 290 | * SCSI bus timeouts. |
| 291 | */ |
| 292 | static uint32_t aic7xxx_no_reset; |
| 293 | |
| 294 | /* |
| 295 | * Certain PCI motherboards will scan PCI devices from highest to lowest, |
| 296 | * others scan from lowest to highest, and they tend to do all kinds of |
| 297 | * strange things when they come into contact with PCI bridge chips. The |
| 298 | * net result of all this is that the PCI card that is actually used to boot |
| 299 | * the machine is very hard to detect. Most motherboards go from lowest |
| 300 | * PCI slot number to highest, and the first SCSI controller found is the |
| 301 | * one you boot from. The only exceptions to this are when a controller |
| 302 | * has its BIOS disabled. So, we by default sort all of our SCSI controllers |
| 303 | * from lowest PCI slot number to highest PCI slot number. We also force |
| 304 | * all controllers with their BIOS disabled to the end of the list. This |
| 305 | * works on *almost* all computers. Where it doesn't work, we have this |
| 306 | * option. Setting this option to non-0 will reverse the order of the sort |
| 307 | * to highest first, then lowest, but will still leave cards with their BIOS |
| 308 | * disabled at the very end. That should fix everyone up unless there are |
| 309 | * really strange cirumstances. |
| 310 | */ |
| 311 | static uint32_t aic7xxx_reverse_scan; |
| 312 | |
| 313 | /* |
| 314 | * Should we force EXTENDED translation on a controller. |
| 315 | * 0 == Use whatever is in the SEEPROM or default to off |
| 316 | * 1 == Use whatever is in the SEEPROM or default to on |
| 317 | */ |
| 318 | static uint32_t aic7xxx_extended; |
| 319 | |
| 320 | /* |
| 321 | * PCI bus parity checking of the Adaptec controllers. This is somewhat |
| 322 | * dubious at best. To my knowledge, this option has never actually |
| 323 | * solved a PCI parity problem, but on certain machines with broken PCI |
| 324 | * chipset configurations where stray PCI transactions with bad parity are |
| 325 | * the norm rather than the exception, the error messages can be overwelming. |
| 326 | * It's included in the driver for completeness. |
| 327 | * 0 = Shut off PCI parity check |
| 328 | * non-0 = reverse polarity pci parity checking |
| 329 | */ |
| 330 | static uint32_t aic7xxx_pci_parity = ~0; |
| 331 | |
| 332 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | * There are lots of broken chipsets in the world. Some of them will |
| 334 | * violate the PCI spec when we issue byte sized memory writes to our |
| 335 | * controller. I/O mapped register access, if allowed by the given |
| 336 | * platform, will work in almost all cases. |
| 337 | */ |
| 338 | uint32_t aic7xxx_allow_memio = ~0; |
| 339 | |
| 340 | /* |
| 341 | * aic7xxx_detect() has been run, so register all device arrivals |
| 342 | * immediately with the system rather than deferring to the sorted |
| 343 | * attachment performed by aic7xxx_detect(). |
| 344 | */ |
| 345 | int aic7xxx_detect_complete; |
| 346 | |
| 347 | /* |
| 348 | * So that we can set how long each device is given as a selection timeout. |
| 349 | * The table of values goes like this: |
| 350 | * 0 - 256ms |
| 351 | * 1 - 128ms |
| 352 | * 2 - 64ms |
| 353 | * 3 - 32ms |
| 354 | * We default to 256ms because some older devices need a longer time |
| 355 | * to respond to initial selection. |
| 356 | */ |
| 357 | static uint32_t aic7xxx_seltime; |
| 358 | |
| 359 | /* |
| 360 | * Certain devices do not perform any aging on commands. Should the |
| 361 | * device be saturated by commands in one portion of the disk, it is |
| 362 | * possible for transactions on far away sectors to never be serviced. |
| 363 | * To handle these devices, we can periodically send an ordered tag to |
| 364 | * force all outstanding transactions to be serviced prior to a new |
| 365 | * transaction. |
| 366 | */ |
| 367 | uint32_t aic7xxx_periodic_otag; |
| 368 | |
| 369 | /* |
| 370 | * Module information and settable options. |
| 371 | */ |
| 372 | static char *aic7xxx = NULL; |
| 373 | |
| 374 | MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>"); |
| 375 | MODULE_DESCRIPTION("Adaptec Aic77XX/78XX SCSI Host Bus Adapter driver"); |
| 376 | MODULE_LICENSE("Dual BSD/GPL"); |
| 377 | MODULE_VERSION(AIC7XXX_DRIVER_VERSION); |
| 378 | module_param(aic7xxx, charp, 0444); |
| 379 | MODULE_PARM_DESC(aic7xxx, |
| 380 | "period delimited, options string.\n" |
| 381 | " verbose Enable verbose/diagnostic logging\n" |
| 382 | " allow_memio Allow device registers to be memory mapped\n" |
| 383 | " debug Bitmask of debug values to enable\n" |
| 384 | " no_probe Toggle EISA/VLB controller probing\n" |
| 385 | " probe_eisa_vl Toggle EISA/VLB controller probing\n" |
| 386 | " no_reset Supress initial bus resets\n" |
| 387 | " extended Enable extended geometry on all controllers\n" |
| 388 | " periodic_otag Send an ordered tagged transaction\n" |
| 389 | " periodically to prevent tag starvation.\n" |
| 390 | " This may be required by some older disk\n" |
| 391 | " drives or RAID arrays.\n" |
| 392 | " reverse_scan Sort PCI devices highest Bus/Slot to lowest\n" |
| 393 | " tag_info:<tag_str> Set per-target tag depth\n" |
| 394 | " global_tag_depth:<int> Global tag depth for every target\n" |
| 395 | " on every bus\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | " seltime:<int> Selection Timeout\n" |
| 397 | " (0/256ms,1/128ms,2/64ms,3/32ms)\n" |
| 398 | "\n" |
| 399 | " Sample /etc/modprobe.conf line:\n" |
| 400 | " Toggle EISA/VLB probing\n" |
| 401 | " Set tag depth on Controller 1/Target 1 to 10 tags\n" |
| 402 | " Shorten the selection timeout to 128ms\n" |
| 403 | "\n" |
| 404 | " options aic7xxx 'aic7xxx=probe_eisa_vl.tag_info:{{}.{.10}}.seltime:1'\n" |
| 405 | ); |
| 406 | |
| 407 | static void ahc_linux_handle_scsi_status(struct ahc_softc *, |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 408 | struct scsi_device *, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | struct scb *); |
| 410 | static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 411 | struct scsi_cmnd *cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | static void ahc_linux_sem_timeout(u_long arg); |
| 413 | static void ahc_linux_freeze_simq(struct ahc_softc *ahc); |
| 414 | static void ahc_linux_release_simq(u_long arg); |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 415 | static int ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | static void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc, |
| 418 | struct ahc_devinfo *devinfo); |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 419 | static void ahc_linux_device_queue_depth(struct scsi_device *); |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 420 | static int ahc_linux_run_command(struct ahc_softc*, |
| 421 | struct ahc_linux_device *, |
| 422 | struct scsi_cmnd *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | static void ahc_linux_setup_tag_info_global(char *p); |
| 424 | static aic_option_callback_t ahc_linux_setup_tag_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | static int aic7xxx_setup(char *s); |
| 426 | static int ahc_linux_next_unit(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
| 428 | /********************************* Inlines ************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | static __inline void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*); |
| 430 | |
| 431 | static __inline int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb, |
| 432 | struct ahc_dma_seg *sg, |
| 433 | dma_addr_t addr, bus_size_t len); |
| 434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | static __inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb) |
| 437 | { |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 438 | struct scsi_cmnd *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
| 440 | cmd = scb->io_ctx; |
| 441 | ahc_sync_sglist(ahc, scb, BUS_DMASYNC_POSTWRITE); |
| 442 | if (cmd->use_sg != 0) { |
| 443 | struct scatterlist *sg; |
| 444 | |
| 445 | sg = (struct scatterlist *)cmd->request_buffer; |
| 446 | pci_unmap_sg(ahc->dev_softc, sg, cmd->use_sg, |
| be7db05 | 2005-04-17 15:26:13 -0500 | [diff] [blame] | 447 | cmd->sc_data_direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } else if (cmd->request_bufflen != 0) { |
| 449 | pci_unmap_single(ahc->dev_softc, |
| 450 | scb->platform_data->buf_busaddr, |
| 451 | cmd->request_bufflen, |
| be7db05 | 2005-04-17 15:26:13 -0500 | [diff] [blame] | 452 | cmd->sc_data_direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
| 456 | static __inline int |
| 457 | ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb, |
| 458 | struct ahc_dma_seg *sg, dma_addr_t addr, bus_size_t len) |
| 459 | { |
| 460 | int consumed; |
| 461 | |
| 462 | if ((scb->sg_count + 1) > AHC_NSEG) |
| 463 | panic("Too few segs for dma mapping. " |
| 464 | "Increase AHC_NSEG\n"); |
| 465 | |
| 466 | consumed = 1; |
| 467 | sg->addr = ahc_htole32(addr & 0xFFFFFFFF); |
| 468 | scb->platform_data->xfer_len += len; |
| 469 | |
| 470 | if (sizeof(dma_addr_t) > 4 |
| 471 | && (ahc->flags & AHC_39BIT_ADDRESSING) != 0) |
| 472 | len |= (addr >> 8) & AHC_SG_HIGH_ADDR_MASK; |
| 473 | |
| 474 | sg->len = ahc_htole32(len); |
| 475 | return (consumed); |
| 476 | } |
| 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | * Try to detect an Adaptec 7XXX controller. |
| 480 | */ |
| 481 | static int |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 482 | ahc_linux_detect(struct scsi_host_template *template) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
| 484 | struct ahc_softc *ahc; |
| 485 | int found = 0; |
| 486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | * If we've been passed any parameters, process them now. |
| 489 | */ |
| 490 | if (aic7xxx) |
| 491 | aic7xxx_setup(aic7xxx); |
| 492 | |
| 493 | template->proc_name = "aic7xxx"; |
| 494 | |
| 495 | /* |
| 496 | * Initialize our softc list lock prior to |
| 497 | * probing for any adapters. |
| 498 | */ |
| 499 | ahc_list_lockinit(); |
| 500 | |
| 501 | found = ahc_linux_pci_init(); |
| 502 | if (!ahc_linux_eisa_init()) |
| 503 | found++; |
| 504 | |
| 505 | /* |
| 506 | * Register with the SCSI layer all |
| 507 | * controllers we've found. |
| 508 | */ |
| 509 | TAILQ_FOREACH(ahc, &ahc_tailq, links) { |
| 510 | |
| 511 | if (ahc_linux_register_host(ahc, template) == 0) |
| 512 | found++; |
| 513 | } |
| 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | aic7xxx_detect_complete++; |
| 516 | |
| 517 | return (found); |
| 518 | } |
| 519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | /* |
| 521 | * Return a string describing the driver. |
| 522 | */ |
| 523 | static const char * |
| 524 | ahc_linux_info(struct Scsi_Host *host) |
| 525 | { |
| 526 | static char buffer[512]; |
| 527 | char ahc_info[256]; |
| 528 | char *bp; |
| 529 | struct ahc_softc *ahc; |
| 530 | |
| 531 | bp = &buffer[0]; |
| 532 | ahc = *(struct ahc_softc **)host->hostdata; |
| 533 | memset(bp, 0, sizeof(buffer)); |
| 534 | strcpy(bp, "Adaptec AIC7XXX EISA/VLB/PCI SCSI HBA DRIVER, Rev "); |
| 535 | strcat(bp, AIC7XXX_DRIVER_VERSION); |
| 536 | strcat(bp, "\n"); |
| 537 | strcat(bp, " <"); |
| 538 | strcat(bp, ahc->description); |
| 539 | strcat(bp, ">\n"); |
| 540 | strcat(bp, " "); |
| 541 | ahc_controller_info(ahc, ahc_info); |
| 542 | strcat(bp, ahc_info); |
| 543 | strcat(bp, "\n"); |
| 544 | |
| 545 | return (bp); |
| 546 | } |
| 547 | |
| 548 | /* |
| 549 | * Queue an SCB to the controller. |
| 550 | */ |
| 551 | static int |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 552 | ahc_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | { |
| 554 | struct ahc_softc *ahc; |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 555 | struct ahc_linux_device *dev = scsi_transport_device_data(cmd->device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
| 557 | ahc = *(struct ahc_softc **)cmd->device->host->hostdata; |
| 558 | |
| 559 | /* |
| 560 | * Save the callback on completion function. |
| 561 | */ |
| 562 | cmd->scsi_done = scsi_done; |
| 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | /* |
| 565 | * Close the race of a command that was in the process of |
| 566 | * being queued to us just as our simq was frozen. Let |
| 567 | * DV commands through so long as we are only frozen to |
| 568 | * perform DV. |
| 569 | */ |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 570 | if (ahc->platform_data->qfrozen != 0) |
| 571 | return SCSI_MLQUEUE_HOST_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | cmd->result = CAM_REQ_INPROG << 16; |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 574 | |
| 575 | return ahc_linux_run_command(ahc, dev, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | } |
| 577 | |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 578 | static inline struct scsi_target ** |
| 579 | ahc_linux_target_in_softc(struct scsi_target *starget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | { |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 581 | struct ahc_softc *ahc = |
| 582 | *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata); |
James Bottomley | fb3089d | 2005-05-17 21:09:52 -0500 | [diff] [blame] | 583 | unsigned int target_offset; |
James Bottomley | c752523 | 2005-05-17 18:07:34 -0500 | [diff] [blame] | 584 | |
| 585 | target_offset = starget->id; |
| 586 | if (starget->channel != 0) |
| 587 | target_offset += 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 589 | return &ahc->platform_data->starget[target_offset]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | static int |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 593 | ahc_linux_target_alloc(struct scsi_target *starget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | { |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 595 | struct ahc_softc *ahc = |
| 596 | *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata); |
| 597 | struct seeprom_config *sc = ahc->seep_config; |
| 598 | unsigned long flags; |
| 599 | struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget); |
| 600 | struct ahc_linux_target *targ = scsi_transport_target_data(starget); |
| 601 | unsigned short scsirate; |
| 602 | struct ahc_devinfo devinfo; |
| 603 | struct ahc_initiator_tinfo *tinfo; |
| 604 | struct ahc_tmode_tstate *tstate; |
| 605 | char channel = starget->channel + 'A'; |
| 606 | unsigned int our_id = ahc->our_id; |
| 607 | unsigned int target_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 609 | target_offset = starget->id; |
| 610 | if (starget->channel != 0) |
| 611 | target_offset += 8; |
| 612 | |
| 613 | if (starget->channel) |
| 614 | our_id = ahc->our_id_b; |
James Bottomley | c752523 | 2005-05-17 18:07:34 -0500 | [diff] [blame] | 615 | |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 616 | ahc_lock(ahc, &flags); |
James Bottomley | c752523 | 2005-05-17 18:07:34 -0500 | [diff] [blame] | 617 | |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 618 | BUG_ON(*ahc_targp != NULL); |
| cb62402 | 2005-04-17 18:03:20 -0500 | [diff] [blame] | 619 | |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 620 | *ahc_targp = starget; |
| 621 | memset(targ, 0, sizeof(*targ)); |
| 622 | |
| 623 | if (sc) { |
| 624 | if ((ahc->features & AHC_ULTRA2) != 0) { |
| 625 | scsirate = sc->device_flags[target_offset] & CFXFER; |
| 626 | } else { |
| 627 | scsirate = (sc->device_flags[target_offset] & CFXFER) << 4; |
| 628 | if (sc->device_flags[target_offset] & CFSYNCH) |
| 629 | scsirate |= SOFS; |
| 630 | } |
| 631 | if (sc->device_flags[target_offset] & CFWIDEB) { |
| 632 | scsirate |= WIDEXFER; |
| 633 | spi_max_width(starget) = 1; |
| 634 | } else |
| 635 | spi_max_width(starget) = 0; |
| 636 | spi_min_period(starget) = |
| 637 | ahc_find_period(ahc, scsirate, AHC_SYNCRATE_DT); |
| 638 | tinfo = ahc_fetch_transinfo(ahc, channel, ahc->our_id, |
| 639 | starget->id, &tstate); |
| 640 | } |
| 641 | ahc_compile_devinfo(&devinfo, our_id, starget->id, |
| 642 | CAM_LUN_WILDCARD, channel, |
| 643 | ROLE_INITIATOR); |
| 644 | ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0, |
| 645 | AHC_TRANS_GOAL, /*paused*/FALSE); |
| 646 | ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT, |
| 647 | AHC_TRANS_GOAL, /*paused*/FALSE); |
| 648 | ahc_unlock(ahc, &flags); |
| cb62402 | 2005-04-17 18:03:20 -0500 | [diff] [blame] | 649 | |
James Bottomley | c752523 | 2005-05-17 18:07:34 -0500 | [diff] [blame] | 650 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | static void |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 654 | ahc_linux_target_destroy(struct scsi_target *starget) |
| 655 | { |
| 656 | struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget); |
| 657 | |
| 658 | *ahc_targp = NULL; |
| 659 | } |
| 660 | |
| 661 | static int |
| 662 | ahc_linux_slave_alloc(struct scsi_device *sdev) |
| 663 | { |
| 664 | struct ahc_softc *ahc = |
| 665 | *((struct ahc_softc **)sdev->host->hostdata); |
| 666 | struct scsi_target *starget = sdev->sdev_target; |
| 667 | struct ahc_linux_target *targ = scsi_transport_target_data(starget); |
| 668 | struct ahc_linux_device *dev; |
| 669 | |
| 670 | if (bootverbose) |
| 671 | printf("%s: Slave Alloc %d\n", ahc_name(ahc), sdev->id); |
| 672 | |
| 673 | BUG_ON(targ->sdev[sdev->lun] != NULL); |
| 674 | |
| 675 | dev = scsi_transport_device_data(sdev); |
| 676 | memset(dev, 0, sizeof(*dev)); |
| 677 | |
| 678 | /* |
| 679 | * We start out life using untagged |
| 680 | * transactions of which we allow one. |
| 681 | */ |
| 682 | dev->openings = 1; |
| 683 | |
| 684 | /* |
| 685 | * Set maxtags to 0. This will be changed if we |
| 686 | * later determine that we are dealing with |
| 687 | * a tagged queuing capable device. |
| 688 | */ |
| 689 | dev->maxtags = 0; |
| 690 | |
| 691 | targ->sdev[sdev->lun] = sdev; |
| 692 | |
| 693 | return 0; |
| 694 | } |
| 695 | |
| 696 | static int |
| 697 | ahc_linux_slave_configure(struct scsi_device *sdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | { |
| 699 | struct ahc_softc *ahc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 701 | ahc = *((struct ahc_softc **)sdev->host->hostdata); |
| 702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | if (bootverbose) |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 704 | printf("%s: Slave Configure %d\n", ahc_name(ahc), sdev->id); |
| 705 | |
| 706 | ahc_linux_device_queue_depth(sdev); |
| 707 | |
| 708 | /* Initial Domain Validation */ |
| 709 | if (!spi_initial_dv(sdev->sdev_target)) |
| 710 | spi_dv_device(sdev); |
| 711 | |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | static void |
| 716 | ahc_linux_slave_destroy(struct scsi_device *sdev) |
| 717 | { |
| 718 | struct ahc_softc *ahc; |
| 719 | struct ahc_linux_device *dev = scsi_transport_device_data(sdev); |
| 720 | struct ahc_linux_target *targ = scsi_transport_target_data(sdev->sdev_target); |
| 721 | |
| 722 | ahc = *((struct ahc_softc **)sdev->host->hostdata); |
| 723 | if (bootverbose) |
| 724 | printf("%s: Slave Destroy %d\n", ahc_name(ahc), sdev->id); |
James Bottomley | c752523 | 2005-05-17 18:07:34 -0500 | [diff] [blame] | 725 | |
| 726 | BUG_ON(dev->active); |
| 727 | |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 728 | targ->sdev[sdev->lun] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
| 731 | #if defined(__i386__) |
| 732 | /* |
| 733 | * Return the disk geometry for the given SCSI device. |
| 734 | */ |
| 735 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev, |
| 737 | sector_t capacity, int geom[]) |
| 738 | { |
| 739 | uint8_t *bh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | int heads; |
| 741 | int sectors; |
| 742 | int cylinders; |
| 743 | int ret; |
| 744 | int extended; |
| 745 | struct ahc_softc *ahc; |
| 746 | u_int channel; |
| 747 | |
| 748 | ahc = *((struct ahc_softc **)sdev->host->hostdata); |
| 749 | channel = sdev->channel; |
| 750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | bh = scsi_bios_ptable(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | if (bh) { |
| 753 | ret = scsi_partsize(bh, capacity, |
| 754 | &geom[2], &geom[0], &geom[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | kfree(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | if (ret != -1) |
| 757 | return (ret); |
| 758 | } |
| 759 | heads = 64; |
| 760 | sectors = 32; |
| 761 | cylinders = aic_sector_div(capacity, heads, sectors); |
| 762 | |
| 763 | if (aic7xxx_extended != 0) |
| 764 | extended = 1; |
| 765 | else if (channel == 0) |
| 766 | extended = (ahc->flags & AHC_EXTENDED_TRANS_A) != 0; |
| 767 | else |
| 768 | extended = (ahc->flags & AHC_EXTENDED_TRANS_B) != 0; |
| 769 | if (extended && cylinders >= 1024) { |
| 770 | heads = 255; |
| 771 | sectors = 63; |
| 772 | cylinders = aic_sector_div(capacity, heads, sectors); |
| 773 | } |
| 774 | geom[0] = heads; |
| 775 | geom[1] = sectors; |
| 776 | geom[2] = cylinders; |
| 777 | return (0); |
| 778 | } |
| 779 | #endif |
| 780 | |
| 781 | /* |
| 782 | * Abort the current SCSI command(s). |
| 783 | */ |
| 784 | static int |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 785 | ahc_linux_abort(struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | { |
| 787 | int error; |
| 788 | |
| 789 | error = ahc_linux_queue_recovery_cmd(cmd, SCB_ABORT); |
| 790 | if (error != 0) |
| 791 | printf("aic7xxx_abort returns 0x%x\n", error); |
| 792 | return (error); |
| 793 | } |
| 794 | |
| 795 | /* |
| 796 | * Attempt to send a target reset message to the device that timed out. |
| 797 | */ |
| 798 | static int |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 799 | ahc_linux_dev_reset(struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | { |
| 801 | int error; |
| 802 | |
| 803 | error = ahc_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET); |
| 804 | if (error != 0) |
| 805 | printf("aic7xxx_dev_reset returns 0x%x\n", error); |
| 806 | return (error); |
| 807 | } |
| 808 | |
| 809 | /* |
| 810 | * Reset the SCSI bus. |
| 811 | */ |
| 812 | static int |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 813 | ahc_linux_bus_reset(struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | { |
| 815 | struct ahc_softc *ahc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | int found; |
| 817 | |
| 818 | ahc = *(struct ahc_softc **)cmd->device->host->hostdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | found = ahc_reset_channel(ahc, cmd->device->channel + 'A', |
| 820 | /*initiate reset*/TRUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | |
| 822 | if (bootverbose) |
| 823 | printf("%s: SCSI bus reset delivered. " |
| 824 | "%d SCBs aborted.\n", ahc_name(ahc), found); |
| 825 | |
| 826 | return SUCCESS; |
| 827 | } |
| 828 | |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 829 | struct scsi_host_template aic7xxx_driver_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | .module = THIS_MODULE, |
| 831 | .name = "aic7xxx", |
| 832 | .proc_info = ahc_linux_proc_info, |
| 833 | .info = ahc_linux_info, |
| 834 | .queuecommand = ahc_linux_queue, |
| 835 | .eh_abort_handler = ahc_linux_abort, |
| 836 | .eh_device_reset_handler = ahc_linux_dev_reset, |
| 837 | .eh_bus_reset_handler = ahc_linux_bus_reset, |
| 838 | #if defined(__i386__) |
| 839 | .bios_param = ahc_linux_biosparam, |
| 840 | #endif |
| 841 | .can_queue = AHC_MAX_QUEUE, |
| 842 | .this_id = -1, |
| 843 | .cmd_per_lun = 2, |
| 844 | .use_clustering = ENABLE_CLUSTERING, |
| 845 | .slave_alloc = ahc_linux_slave_alloc, |
| 846 | .slave_configure = ahc_linux_slave_configure, |
| 847 | .slave_destroy = ahc_linux_slave_destroy, |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 848 | .target_alloc = ahc_linux_target_alloc, |
| 849 | .target_destroy = ahc_linux_target_destroy, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | }; |
| 851 | |
| 852 | /**************************** Tasklet Handler *********************************/ |
| 853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | /******************************** Macros **************************************/ |
| 855 | #define BUILD_SCSIID(ahc, cmd) \ |
| 856 | ((((cmd)->device->id << TID_SHIFT) & TID) \ |
| 857 | | (((cmd)->device->channel == 0) ? (ahc)->our_id : (ahc)->our_id_b) \ |
| 858 | | (((cmd)->device->channel == 0) ? 0 : TWIN_CHNLB)) |
| 859 | |
| 860 | /******************************** Bus DMA *************************************/ |
| 861 | int |
| 862 | ahc_dma_tag_create(struct ahc_softc *ahc, bus_dma_tag_t parent, |
| 863 | bus_size_t alignment, bus_size_t boundary, |
| 864 | dma_addr_t lowaddr, dma_addr_t highaddr, |
| 865 | bus_dma_filter_t *filter, void *filterarg, |
| 866 | bus_size_t maxsize, int nsegments, |
| 867 | bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag) |
| 868 | { |
| 869 | bus_dma_tag_t dmat; |
| 870 | |
| 871 | dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT); |
| 872 | if (dmat == NULL) |
| 873 | return (ENOMEM); |
| 874 | |
| 875 | /* |
| 876 | * Linux is very simplistic about DMA memory. For now don't |
| 877 | * maintain all specification information. Once Linux supplies |
| 878 | * better facilities for doing these operations, or the |
| 879 | * needs of this particular driver change, we might need to do |
| 880 | * more here. |
| 881 | */ |
| 882 | dmat->alignment = alignment; |
| 883 | dmat->boundary = boundary; |
| 884 | dmat->maxsize = maxsize; |
| 885 | *ret_tag = dmat; |
| 886 | return (0); |
| 887 | } |
| 888 | |
| 889 | void |
| 890 | ahc_dma_tag_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat) |
| 891 | { |
| 892 | free(dmat, M_DEVBUF); |
| 893 | } |
| 894 | |
| 895 | int |
| 896 | ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr, |
| 897 | int flags, bus_dmamap_t *mapp) |
| 898 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | *vaddr = pci_alloc_consistent(ahc->dev_softc, |
Christoph Hellwig | 7dfa0f2 | 2005-05-16 18:54:12 +0200 | [diff] [blame] | 900 | dmat->maxsize, mapp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | if (*vaddr == NULL) |
Christoph Hellwig | 7dfa0f2 | 2005-05-16 18:54:12 +0200 | [diff] [blame] | 902 | return ENOMEM; |
| 903 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | void |
| 907 | ahc_dmamem_free(struct ahc_softc *ahc, bus_dma_tag_t dmat, |
| 908 | void* vaddr, bus_dmamap_t map) |
| 909 | { |
| 910 | pci_free_consistent(ahc->dev_softc, dmat->maxsize, |
Christoph Hellwig | 7dfa0f2 | 2005-05-16 18:54:12 +0200 | [diff] [blame] | 911 | vaddr, map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | int |
| 915 | ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map, |
| 916 | void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb, |
| 917 | void *cb_arg, int flags) |
| 918 | { |
| 919 | /* |
| 920 | * Assume for now that this will only be used during |
| 921 | * initialization and not for per-transaction buffer mapping. |
| 922 | */ |
| 923 | bus_dma_segment_t stack_sg; |
| 924 | |
Christoph Hellwig | 7dfa0f2 | 2005-05-16 18:54:12 +0200 | [diff] [blame] | 925 | stack_sg.ds_addr = map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | stack_sg.ds_len = dmat->maxsize; |
| 927 | cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0); |
| 928 | return (0); |
| 929 | } |
| 930 | |
| 931 | void |
| 932 | ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map) |
| 933 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | int |
| 937 | ahc_dmamap_unload(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map) |
| 938 | { |
| 939 | /* Nothing to do */ |
| 940 | return (0); |
| 941 | } |
| 942 | |
| 943 | /********************* Platform Dependent Functions ***************************/ |
| 944 | /* |
| 945 | * Compare "left hand" softc with "right hand" softc, returning: |
| 946 | * < 0 - lahc has a lower priority than rahc |
| 947 | * 0 - Softcs are equal |
| 948 | * > 0 - lahc has a higher priority than rahc |
| 949 | */ |
| 950 | int |
| 951 | ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc) |
| 952 | { |
| 953 | int value; |
| 954 | int rvalue; |
| 955 | int lvalue; |
| 956 | |
| 957 | /* |
| 958 | * Under Linux, cards are ordered as follows: |
| 959 | * 1) VLB/EISA BIOS enabled devices sorted by BIOS address. |
| 960 | * 2) PCI devices with BIOS enabled sorted by bus/slot/func. |
| 961 | * 3) All remaining VLB/EISA devices sorted by ioport. |
| 962 | * 4) All remaining PCI devices sorted by bus/slot/func. |
| 963 | */ |
| 964 | value = (lahc->flags & AHC_BIOS_ENABLED) |
| 965 | - (rahc->flags & AHC_BIOS_ENABLED); |
| 966 | if (value != 0) |
| 967 | /* Controllers with BIOS enabled have a *higher* priority */ |
| 968 | return (value); |
| 969 | |
| 970 | /* |
| 971 | * Same BIOS setting, now sort based on bus type. |
| 972 | * EISA and VL controllers sort together. EISA/VL |
| 973 | * have higher priority than PCI. |
| 974 | */ |
| 975 | rvalue = (rahc->chip & AHC_BUS_MASK); |
| 976 | if (rvalue == AHC_VL) |
| 977 | rvalue = AHC_EISA; |
| 978 | lvalue = (lahc->chip & AHC_BUS_MASK); |
| 979 | if (lvalue == AHC_VL) |
| 980 | lvalue = AHC_EISA; |
| 981 | value = rvalue - lvalue; |
| 982 | if (value != 0) |
| 983 | return (value); |
| 984 | |
| 985 | /* Still equal. Sort by BIOS address, ioport, or bus/slot/func. */ |
| 986 | switch (rvalue) { |
| 987 | #ifdef CONFIG_PCI |
| 988 | case AHC_PCI: |
| 989 | { |
| 990 | char primary_channel; |
| 991 | |
| 992 | if (aic7xxx_reverse_scan != 0) |
| 993 | value = ahc_get_pci_bus(lahc->dev_softc) |
| 994 | - ahc_get_pci_bus(rahc->dev_softc); |
| 995 | else |
| 996 | value = ahc_get_pci_bus(rahc->dev_softc) |
| 997 | - ahc_get_pci_bus(lahc->dev_softc); |
| 998 | if (value != 0) |
| 999 | break; |
| 1000 | if (aic7xxx_reverse_scan != 0) |
| 1001 | value = ahc_get_pci_slot(lahc->dev_softc) |
| 1002 | - ahc_get_pci_slot(rahc->dev_softc); |
| 1003 | else |
| 1004 | value = ahc_get_pci_slot(rahc->dev_softc) |
| 1005 | - ahc_get_pci_slot(lahc->dev_softc); |
| 1006 | if (value != 0) |
| 1007 | break; |
| 1008 | /* |
| 1009 | * On multi-function devices, the user can choose |
| 1010 | * to have function 1 probed before function 0. |
| 1011 | * Give whichever channel is the primary channel |
| 1012 | * the highest priority. |
| 1013 | */ |
| 1014 | primary_channel = (lahc->flags & AHC_PRIMARY_CHANNEL) + 'A'; |
| 1015 | value = -1; |
| 1016 | if (lahc->channel == primary_channel) |
| 1017 | value = 1; |
| 1018 | break; |
| 1019 | } |
| 1020 | #endif |
| 1021 | case AHC_EISA: |
| 1022 | if ((rahc->flags & AHC_BIOS_ENABLED) != 0) { |
| 1023 | value = rahc->platform_data->bios_address |
| 1024 | - lahc->platform_data->bios_address; |
| 1025 | } else { |
| 1026 | value = rahc->bsh.ioport |
| 1027 | - lahc->bsh.ioport; |
| 1028 | } |
| 1029 | break; |
| 1030 | default: |
| 1031 | panic("ahc_softc_sort: invalid bus type"); |
| 1032 | } |
| 1033 | return (value); |
| 1034 | } |
| 1035 | |
| 1036 | static void |
| 1037 | ahc_linux_setup_tag_info_global(char *p) |
| 1038 | { |
| 1039 | int tags, i, j; |
| 1040 | |
| 1041 | tags = simple_strtoul(p + 1, NULL, 0) & 0xff; |
| 1042 | printf("Setting Global Tags= %d\n", tags); |
| 1043 | |
| 1044 | for (i = 0; i < NUM_ELEMENTS(aic7xxx_tag_info); i++) { |
| 1045 | for (j = 0; j < AHC_NUM_TARGETS; j++) { |
| 1046 | aic7xxx_tag_info[i].tag_commands[j] = tags; |
| 1047 | } |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | static void |
| 1052 | ahc_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value) |
| 1053 | { |
| 1054 | |
| 1055 | if ((instance >= 0) && (targ >= 0) |
| 1056 | && (instance < NUM_ELEMENTS(aic7xxx_tag_info)) |
| 1057 | && (targ < AHC_NUM_TARGETS)) { |
| 1058 | aic7xxx_tag_info[instance].tag_commands[targ] = value & 0xff; |
| 1059 | if (bootverbose) |
| 1060 | printf("tag_info[%d:%d] = %d\n", instance, targ, value); |
| 1061 | } |
| 1062 | } |
| 1063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | /* |
| 1065 | * Handle Linux boot parameters. This routine allows for assigning a value |
| 1066 | * to a parameter with a ':' between the parameter and the value. |
| 1067 | * ie. aic7xxx=stpwlev:1,extended |
| 1068 | */ |
| 1069 | static int |
| 1070 | aic7xxx_setup(char *s) |
| 1071 | { |
| 1072 | int i, n; |
| 1073 | char *p; |
| 1074 | char *end; |
| 1075 | |
| 1076 | static struct { |
| 1077 | const char *name; |
| 1078 | uint32_t *flag; |
| 1079 | } options[] = { |
| 1080 | { "extended", &aic7xxx_extended }, |
| 1081 | { "no_reset", &aic7xxx_no_reset }, |
| 1082 | { "verbose", &aic7xxx_verbose }, |
| 1083 | { "allow_memio", &aic7xxx_allow_memio}, |
| 1084 | #ifdef AHC_DEBUG |
| 1085 | { "debug", &ahc_debug }, |
| 1086 | #endif |
| 1087 | { "reverse_scan", &aic7xxx_reverse_scan }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | { "periodic_otag", &aic7xxx_periodic_otag }, |
| 1089 | { "pci_parity", &aic7xxx_pci_parity }, |
| 1090 | { "seltime", &aic7xxx_seltime }, |
| 1091 | { "tag_info", NULL }, |
| 1092 | { "global_tag_depth", NULL }, |
| 1093 | { "dv", NULL } |
| 1094 | }; |
| 1095 | |
| 1096 | end = strchr(s, '\0'); |
| 1097 | |
| 1098 | /* |
| 1099 | * XXX ia64 gcc isn't smart enough to know that NUM_ELEMENTS |
| 1100 | * will never be 0 in this case. |
| 1101 | */ |
| 1102 | n = 0; |
| 1103 | |
| 1104 | while ((p = strsep(&s, ",.")) != NULL) { |
| 1105 | if (*p == '\0') |
| 1106 | continue; |
| 1107 | for (i = 0; i < NUM_ELEMENTS(options); i++) { |
| 1108 | |
| 1109 | n = strlen(options[i].name); |
| 1110 | if (strncmp(options[i].name, p, n) == 0) |
| 1111 | break; |
| 1112 | } |
| 1113 | if (i == NUM_ELEMENTS(options)) |
| 1114 | continue; |
| 1115 | |
| 1116 | if (strncmp(p, "global_tag_depth", n) == 0) { |
| 1117 | ahc_linux_setup_tag_info_global(p + n); |
| 1118 | } else if (strncmp(p, "tag_info", n) == 0) { |
| 1119 | s = aic_parse_brace_option("tag_info", p + n, end, |
| 1120 | 2, ahc_linux_setup_tag_info, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | } else if (p[n] == ':') { |
| 1122 | *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0); |
| 1123 | } else if (strncmp(p, "verbose", n) == 0) { |
| 1124 | *(options[i].flag) = 1; |
| 1125 | } else { |
| 1126 | *(options[i].flag) ^= 0xFFFFFFFF; |
| 1127 | } |
| 1128 | } |
| 1129 | return 1; |
| 1130 | } |
| 1131 | |
| 1132 | __setup("aic7xxx=", aic7xxx_setup); |
| 1133 | |
| 1134 | uint32_t aic7xxx_verbose; |
| 1135 | |
| 1136 | int |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 1137 | ahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *template) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | { |
| 1139 | char buf[80]; |
| 1140 | struct Scsi_Host *host; |
| 1141 | char *new_name; |
| 1142 | u_long s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | |
| 1144 | template->name = ahc->description; |
| 1145 | host = scsi_host_alloc(template, sizeof(struct ahc_softc *)); |
| 1146 | if (host == NULL) |
| 1147 | return (ENOMEM); |
| 1148 | |
| 1149 | *((struct ahc_softc **)host->hostdata) = ahc; |
| 1150 | ahc_lock(ahc, &s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | scsi_assign_lock(host, &ahc->platform_data->spin_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | ahc->platform_data->host = host; |
| 1153 | host->can_queue = AHC_MAX_QUEUE; |
| 1154 | host->cmd_per_lun = 2; |
| 1155 | /* XXX No way to communicate the ID for multiple channels */ |
| 1156 | host->this_id = ahc->our_id; |
| 1157 | host->irq = ahc->platform_data->irq; |
| 1158 | host->max_id = (ahc->features & AHC_WIDE) ? 16 : 8; |
| 1159 | host->max_lun = AHC_NUM_LUNS; |
| 1160 | host->max_channel = (ahc->features & AHC_TWIN) ? 1 : 0; |
| 1161 | host->sg_tablesize = AHC_NSEG; |
| 1162 | ahc_set_unit(ahc, ahc_linux_next_unit()); |
| 1163 | sprintf(buf, "scsi%d", host->host_no); |
| 1164 | new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT); |
| 1165 | if (new_name != NULL) { |
| 1166 | strcpy(new_name, buf); |
| 1167 | ahc_set_name(ahc, new_name); |
| 1168 | } |
| 1169 | host->unique_id = ahc->unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | ahc_linux_initialize_scsi_bus(ahc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | ahc_intr_enable(ahc, TRUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | ahc_unlock(ahc, &s); |
| 1173 | |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 1174 | host->transportt = ahc_linux_transport_template; |
| 1175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | scsi_add_host(host, (ahc->dev_softc ? &ahc->dev_softc->dev : NULL)); /* XXX handle failure */ |
| 1177 | scsi_scan_host(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | return (0); |
| 1179 | } |
| 1180 | |
| 1181 | uint64_t |
| 1182 | ahc_linux_get_memsize(void) |
| 1183 | { |
| 1184 | struct sysinfo si; |
| 1185 | |
| 1186 | si_meminfo(&si); |
| 1187 | return ((uint64_t)si.totalram << PAGE_SHIFT); |
| 1188 | } |
| 1189 | |
| 1190 | /* |
| 1191 | * Find the smallest available unit number to use |
| 1192 | * for a new device. We don't just use a static |
| 1193 | * count to handle the "repeated hot-(un)plug" |
| 1194 | * scenario. |
| 1195 | */ |
| 1196 | static int |
| 1197 | ahc_linux_next_unit(void) |
| 1198 | { |
| 1199 | struct ahc_softc *ahc; |
| 1200 | int unit; |
| 1201 | |
| 1202 | unit = 0; |
| 1203 | retry: |
| 1204 | TAILQ_FOREACH(ahc, &ahc_tailq, links) { |
| 1205 | if (ahc->unit == unit) { |
| 1206 | unit++; |
| 1207 | goto retry; |
| 1208 | } |
| 1209 | } |
| 1210 | return (unit); |
| 1211 | } |
| 1212 | |
| 1213 | /* |
| 1214 | * Place the SCSI bus into a known state by either resetting it, |
| 1215 | * or forcing transfer negotiations on the next command to any |
| 1216 | * target. |
| 1217 | */ |
| 1218 | void |
| 1219 | ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc) |
| 1220 | { |
| 1221 | int i; |
| 1222 | int numtarg; |
| 1223 | |
| 1224 | i = 0; |
| 1225 | numtarg = 0; |
| 1226 | |
| 1227 | if (aic7xxx_no_reset != 0) |
| 1228 | ahc->flags &= ~(AHC_RESET_BUS_A|AHC_RESET_BUS_B); |
| 1229 | |
| 1230 | if ((ahc->flags & AHC_RESET_BUS_A) != 0) |
| 1231 | ahc_reset_channel(ahc, 'A', /*initiate_reset*/TRUE); |
| 1232 | else |
| 1233 | numtarg = (ahc->features & AHC_WIDE) ? 16 : 8; |
| 1234 | |
| 1235 | if ((ahc->features & AHC_TWIN) != 0) { |
| 1236 | |
| 1237 | if ((ahc->flags & AHC_RESET_BUS_B) != 0) { |
| 1238 | ahc_reset_channel(ahc, 'B', /*initiate_reset*/TRUE); |
| 1239 | } else { |
| 1240 | if (numtarg == 0) |
| 1241 | i = 8; |
| 1242 | numtarg += 8; |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | /* |
| 1247 | * Force negotiation to async for all targets that |
| 1248 | * will not see an initial bus reset. |
| 1249 | */ |
| 1250 | for (; i < numtarg; i++) { |
| 1251 | struct ahc_devinfo devinfo; |
| 1252 | struct ahc_initiator_tinfo *tinfo; |
| 1253 | struct ahc_tmode_tstate *tstate; |
| 1254 | u_int our_id; |
| 1255 | u_int target_id; |
| 1256 | char channel; |
| 1257 | |
| 1258 | channel = 'A'; |
| 1259 | our_id = ahc->our_id; |
| 1260 | target_id = i; |
| 1261 | if (i > 7 && (ahc->features & AHC_TWIN) != 0) { |
| 1262 | channel = 'B'; |
| 1263 | our_id = ahc->our_id_b; |
| 1264 | target_id = i % 8; |
| 1265 | } |
| 1266 | tinfo = ahc_fetch_transinfo(ahc, channel, our_id, |
| 1267 | target_id, &tstate); |
| 1268 | ahc_compile_devinfo(&devinfo, our_id, target_id, |
| 1269 | CAM_LUN_WILDCARD, channel, ROLE_INITIATOR); |
| 1270 | ahc_update_neg_request(ahc, &devinfo, tstate, |
| 1271 | tinfo, AHC_NEG_ALWAYS); |
| 1272 | } |
| 1273 | /* Give the bus some time to recover */ |
| 1274 | if ((ahc->flags & (AHC_RESET_BUS_A|AHC_RESET_BUS_B)) != 0) { |
| 1275 | ahc_linux_freeze_simq(ahc); |
| 1276 | init_timer(&ahc->platform_data->reset_timer); |
| 1277 | ahc->platform_data->reset_timer.data = (u_long)ahc; |
| 1278 | ahc->platform_data->reset_timer.expires = |
| 1279 | jiffies + (AIC7XXX_RESET_DELAY * HZ)/1000; |
| 1280 | ahc->platform_data->reset_timer.function = |
| 1281 | ahc_linux_release_simq; |
| 1282 | add_timer(&ahc->platform_data->reset_timer); |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | int |
| 1287 | ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg) |
| 1288 | { |
| 1289 | |
| 1290 | ahc->platform_data = |
| 1291 | malloc(sizeof(struct ahc_platform_data), M_DEVBUF, M_NOWAIT); |
| 1292 | if (ahc->platform_data == NULL) |
| 1293 | return (ENOMEM); |
| 1294 | memset(ahc->platform_data, 0, sizeof(struct ahc_platform_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | ahc->platform_data->irq = AHC_LINUX_NOIRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | ahc_lockinit(ahc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | init_MUTEX_LOCKED(&ahc->platform_data->eh_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | ahc->seltime = (aic7xxx_seltime & 0x3) << 4; |
| 1299 | ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4; |
| 1300 | if (aic7xxx_pci_parity == 0) |
| 1301 | ahc->flags |= AHC_DISABLE_PCI_PERR; |
| 1302 | |
| 1303 | return (0); |
| 1304 | } |
| 1305 | |
| 1306 | void |
| 1307 | ahc_platform_free(struct ahc_softc *ahc) |
| 1308 | { |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1309 | struct scsi_target *starget; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | int i, j; |
| 1311 | |
| 1312 | if (ahc->platform_data != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | if (ahc->platform_data->host != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | scsi_remove_host(ahc->platform_data->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | scsi_host_put(ahc->platform_data->host); |
| 1316 | } |
| 1317 | |
| 1318 | /* destroy all of the device and target objects */ |
| 1319 | for (i = 0; i < AHC_NUM_TARGETS; i++) { |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1320 | starget = ahc->platform_data->starget[i]; |
| 1321 | if (starget != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | for (j = 0; j < AHC_NUM_LUNS; j++) { |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1323 | struct ahc_linux_target *targ = |
| 1324 | scsi_transport_target_data(starget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1326 | if (targ->sdev[j] == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | continue; |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1328 | targ->sdev[j] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | } |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1330 | ahc->platform_data->starget[i] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | if (ahc->platform_data->irq != AHC_LINUX_NOIRQ) |
| 1335 | free_irq(ahc->platform_data->irq, ahc); |
| 1336 | if (ahc->tag == BUS_SPACE_PIO |
| 1337 | && ahc->bsh.ioport != 0) |
| 1338 | release_region(ahc->bsh.ioport, 256); |
| 1339 | if (ahc->tag == BUS_SPACE_MEMIO |
| 1340 | && ahc->bsh.maddr != NULL) { |
| 1341 | iounmap(ahc->bsh.maddr); |
| 1342 | release_mem_region(ahc->platform_data->mem_busaddr, |
| 1343 | 0x1000); |
| 1344 | } |
Christoph Hellwig | dedd831 | 2005-05-16 18:52:06 +0200 | [diff] [blame] | 1345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | free(ahc->platform_data, M_DEVBUF); |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | void |
| 1351 | ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb) |
| 1352 | { |
| 1353 | ahc_platform_abort_scbs(ahc, SCB_GET_TARGET(ahc, scb), |
| 1354 | SCB_GET_CHANNEL(ahc, scb), |
| 1355 | SCB_GET_LUN(scb), SCB_LIST_NULL, |
| 1356 | ROLE_UNKNOWN, CAM_REQUEUE_REQ); |
| 1357 | } |
| 1358 | |
| 1359 | void |
| 1360 | ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, |
| 1361 | ahc_queue_alg alg) |
| 1362 | { |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1363 | struct scsi_target *starget; |
| 1364 | struct ahc_linux_target *targ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | struct ahc_linux_device *dev; |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1366 | struct scsi_device *sdev; |
| 1367 | u_int target_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | int was_queuing; |
| 1369 | int now_queuing; |
| 1370 | |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1371 | target_offset = devinfo->target; |
| 1372 | if (devinfo->channel != 'A') |
| 1373 | target_offset += 8; |
| 1374 | starget = ahc->platform_data->starget[target_offset]; |
| 1375 | targ = scsi_transport_target_data(starget); |
| 1376 | BUG_ON(targ == NULL); |
| 1377 | sdev = targ->sdev[devinfo->lun]; |
| 1378 | if (sdev == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | return; |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1380 | dev = scsi_transport_device_data(sdev); |
| 1381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED); |
| 1383 | switch (alg) { |
| 1384 | default: |
| 1385 | case AHC_QUEUE_NONE: |
| 1386 | now_queuing = 0; |
| 1387 | break; |
| 1388 | case AHC_QUEUE_BASIC: |
| 1389 | now_queuing = AHC_DEV_Q_BASIC; |
| 1390 | break; |
| 1391 | case AHC_QUEUE_TAGGED: |
| 1392 | now_queuing = AHC_DEV_Q_TAGGED; |
| 1393 | break; |
| 1394 | } |
| 1395 | if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) == 0 |
| 1396 | && (was_queuing != now_queuing) |
| 1397 | && (dev->active != 0)) { |
| 1398 | dev->flags |= AHC_DEV_FREEZE_TIL_EMPTY; |
| 1399 | dev->qfrozen++; |
| 1400 | } |
| 1401 | |
| 1402 | dev->flags &= ~(AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED|AHC_DEV_PERIODIC_OTAG); |
| 1403 | if (now_queuing) { |
| 1404 | u_int usertags; |
| 1405 | |
| 1406 | usertags = ahc_linux_user_tagdepth(ahc, devinfo); |
| 1407 | if (!was_queuing) { |
| 1408 | /* |
| 1409 | * Start out agressively and allow our |
| 1410 | * dynamic queue depth algorithm to take |
| 1411 | * care of the rest. |
| 1412 | */ |
| 1413 | dev->maxtags = usertags; |
| 1414 | dev->openings = dev->maxtags - dev->active; |
| 1415 | } |
| 1416 | if (dev->maxtags == 0) { |
| 1417 | /* |
| 1418 | * Queueing is disabled by the user. |
| 1419 | */ |
| 1420 | dev->openings = 1; |
| 1421 | } else if (alg == AHC_QUEUE_TAGGED) { |
| 1422 | dev->flags |= AHC_DEV_Q_TAGGED; |
| 1423 | if (aic7xxx_periodic_otag != 0) |
| 1424 | dev->flags |= AHC_DEV_PERIODIC_OTAG; |
| 1425 | } else |
| 1426 | dev->flags |= AHC_DEV_Q_BASIC; |
| 1427 | } else { |
| 1428 | /* We can only have one opening. */ |
| 1429 | dev->maxtags = 0; |
| 1430 | dev->openings = 1 - dev->active; |
| 1431 | } |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1432 | switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) { |
| 1433 | case AHC_DEV_Q_BASIC: |
| 1434 | scsi_adjust_queue_depth(sdev, |
| 1435 | MSG_SIMPLE_TASK, |
| 1436 | dev->openings + dev->active); |
| 1437 | break; |
| 1438 | case AHC_DEV_Q_TAGGED: |
| 1439 | scsi_adjust_queue_depth(sdev, |
| 1440 | MSG_ORDERED_TASK, |
| 1441 | dev->openings + dev->active); |
| 1442 | break; |
| 1443 | default: |
| 1444 | /* |
| 1445 | * We allow the OS to queue 2 untagged transactions to |
| 1446 | * us at any time even though we can only execute them |
| 1447 | * serially on the controller/device. This should |
| 1448 | * remove some latency. |
| 1449 | */ |
| 1450 | scsi_adjust_queue_depth(sdev, |
| 1451 | /*NON-TAGGED*/0, |
| 1452 | /*queue depth*/2); |
| 1453 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | int |
| 1458 | ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, char channel, |
| 1459 | int lun, u_int tag, role_t role, uint32_t status) |
| 1460 | { |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 1461 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | static u_int |
| 1465 | ahc_linux_user_tagdepth(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) |
| 1466 | { |
| 1467 | static int warned_user; |
| 1468 | u_int tags; |
| 1469 | |
| 1470 | tags = 0; |
| 1471 | if ((ahc->user_discenable & devinfo->target_mask) != 0) { |
| 1472 | if (ahc->unit >= NUM_ELEMENTS(aic7xxx_tag_info)) { |
| 1473 | if (warned_user == 0) { |
| 1474 | |
| 1475 | printf(KERN_WARNING |
| 1476 | "aic7xxx: WARNING: Insufficient tag_info instances\n" |
| 1477 | "aic7xxx: for installed controllers. Using defaults\n" |
| 1478 | "aic7xxx: Please update the aic7xxx_tag_info array in\n" |
| 1479 | "aic7xxx: the aic7xxx_osm..c source file.\n"); |
| 1480 | warned_user++; |
| 1481 | } |
| 1482 | tags = AHC_MAX_QUEUE; |
| 1483 | } else { |
| 1484 | adapter_tag_info_t *tag_info; |
| 1485 | |
| 1486 | tag_info = &aic7xxx_tag_info[ahc->unit]; |
| 1487 | tags = tag_info->tag_commands[devinfo->target_offset]; |
| 1488 | if (tags > AHC_MAX_QUEUE) |
| 1489 | tags = AHC_MAX_QUEUE; |
| 1490 | } |
| 1491 | } |
| 1492 | return (tags); |
| 1493 | } |
| 1494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | /* |
| 1496 | * Determines the queue depth for a given device. |
| 1497 | */ |
| 1498 | static void |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1499 | ahc_linux_device_queue_depth(struct scsi_device *sdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | { |
| 1501 | struct ahc_devinfo devinfo; |
| 1502 | u_int tags; |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1503 | struct ahc_softc *ahc = *((struct ahc_softc **)sdev->host->hostdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | |
| 1505 | ahc_compile_devinfo(&devinfo, |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1506 | sdev->sdev_target->channel == 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | ? ahc->our_id : ahc->our_id_b, |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1508 | sdev->sdev_target->id, sdev->lun, |
| 1509 | sdev->sdev_target->channel == 0 ? 'A' : 'B', |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | ROLE_INITIATOR); |
| 1511 | tags = ahc_linux_user_tagdepth(ahc, &devinfo); |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1512 | if (tags != 0 && sdev->tagged_supported != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | |
| 1514 | ahc_set_tags(ahc, &devinfo, AHC_QUEUE_TAGGED); |
| 1515 | ahc_print_devinfo(ahc, &devinfo); |
| 1516 | printf("Tagged Queuing enabled. Depth %d\n", tags); |
| 1517 | } else { |
| 1518 | ahc_set_tags(ahc, &devinfo, AHC_QUEUE_NONE); |
| 1519 | } |
| 1520 | } |
| 1521 | |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 1522 | static int |
| 1523 | ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev, |
| 1524 | struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | struct scb *scb; |
| 1527 | struct hardware_scb *hscb; |
| 1528 | struct ahc_initiator_tinfo *tinfo; |
| 1529 | struct ahc_tmode_tstate *tstate; |
| 1530 | uint16_t mask; |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 1531 | struct scb_tailq *untagged_q = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 1533 | /* |
| 1534 | * Schedule us to run later. The only reason we are not |
| 1535 | * running is because the whole controller Q is frozen. |
| 1536 | */ |
| 1537 | if (ahc->platform_data->qfrozen != 0) |
| 1538 | return SCSI_MLQUEUE_HOST_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 1540 | /* |
| 1541 | * We only allow one untagged transaction |
| 1542 | * per target in the initiator role unless |
| 1543 | * we are storing a full busy target *lun* |
| 1544 | * table in SCB space. |
| 1545 | */ |
| 1546 | if (!blk_rq_tagged(cmd->request) |
| 1547 | && (ahc->features & AHC_SCB_BTT) == 0) { |
| 1548 | int target_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 1550 | target_offset = cmd->device->id + cmd->device->channel * 8; |
| 1551 | untagged_q = &(ahc->untagged_queues[target_offset]); |
| 1552 | if (!TAILQ_EMPTY(untagged_q)) |
| 1553 | /* if we're already executing an untagged command |
| 1554 | * we're busy to another */ |
| 1555 | return SCSI_MLQUEUE_DEVICE_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | } |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 1557 | |
| 1558 | /* |
| 1559 | * Get an scb to use. |
| 1560 | */ |
Christoph Hellwig | 8eb3794 | 2005-06-11 00:13:30 +0200 | [diff] [blame] | 1561 | scb = ahc_get_scb(ahc); |
| 1562 | if (!scb) |
| 1563 | return SCSI_MLQUEUE_HOST_BUSY; |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 1564 | |
| 1565 | scb->io_ctx = cmd; |
| 1566 | scb->platform_data->dev = dev; |
| 1567 | hscb = scb->hscb; |
| 1568 | cmd->host_scribble = (char *)scb; |
| 1569 | |
| 1570 | /* |
| 1571 | * Fill out basics of the HSCB. |
| 1572 | */ |
| 1573 | hscb->control = 0; |
| 1574 | hscb->scsiid = BUILD_SCSIID(ahc, cmd); |
| 1575 | hscb->lun = cmd->device->lun; |
| 1576 | mask = SCB_GET_TARGET_MASK(ahc, scb); |
| 1577 | tinfo = ahc_fetch_transinfo(ahc, SCB_GET_CHANNEL(ahc, scb), |
| 1578 | SCB_GET_OUR_ID(scb), |
| 1579 | SCB_GET_TARGET(ahc, scb), &tstate); |
| 1580 | hscb->scsirate = tinfo->scsirate; |
| 1581 | hscb->scsioffset = tinfo->curr.offset; |
| 1582 | if ((tstate->ultraenb & mask) != 0) |
| 1583 | hscb->control |= ULTRAENB; |
| 1584 | |
| 1585 | if ((ahc->user_discenable & mask) != 0) |
| 1586 | hscb->control |= DISCENB; |
| 1587 | |
| 1588 | if ((tstate->auto_negotiate & mask) != 0) { |
| 1589 | scb->flags |= SCB_AUTO_NEGOTIATE; |
| 1590 | scb->hscb->control |= MK_MESSAGE; |
| 1591 | } |
| 1592 | |
| 1593 | if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) { |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 1594 | int msg_bytes; |
| 1595 | uint8_t tag_msgs[2]; |
| 1596 | |
| 1597 | msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs); |
| 1598 | if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) { |
| 1599 | hscb->control |= tag_msgs[0]; |
| 1600 | if (tag_msgs[0] == MSG_ORDERED_TASK) |
| 1601 | dev->commands_since_idle_or_otag = 0; |
Christoph Hellwig | dedd831 | 2005-05-16 18:52:06 +0200 | [diff] [blame] | 1602 | } else if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH |
| 1603 | && (dev->flags & AHC_DEV_Q_TAGGED) != 0) { |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 1604 | hscb->control |= MSG_ORDERED_TASK; |
| 1605 | dev->commands_since_idle_or_otag = 0; |
| 1606 | } else { |
| 1607 | hscb->control |= MSG_SIMPLE_TASK; |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | hscb->cdb_len = cmd->cmd_len; |
| 1612 | if (hscb->cdb_len <= 12) { |
| 1613 | memcpy(hscb->shared_data.cdb, cmd->cmnd, hscb->cdb_len); |
| 1614 | } else { |
| 1615 | memcpy(hscb->cdb32, cmd->cmnd, hscb->cdb_len); |
| 1616 | scb->flags |= SCB_CDB32_PTR; |
| 1617 | } |
| 1618 | |
| 1619 | scb->platform_data->xfer_len = 0; |
| 1620 | ahc_set_residual(scb, 0); |
| 1621 | ahc_set_sense_residual(scb, 0); |
| 1622 | scb->sg_count = 0; |
| 1623 | if (cmd->use_sg != 0) { |
| 1624 | struct ahc_dma_seg *sg; |
| 1625 | struct scatterlist *cur_seg; |
| 1626 | struct scatterlist *end_seg; |
| 1627 | int nseg; |
| 1628 | |
| 1629 | cur_seg = (struct scatterlist *)cmd->request_buffer; |
| 1630 | nseg = pci_map_sg(ahc->dev_softc, cur_seg, cmd->use_sg, |
| 1631 | cmd->sc_data_direction); |
| 1632 | end_seg = cur_seg + nseg; |
| 1633 | /* Copy the segments into the SG list. */ |
| 1634 | sg = scb->sg_list; |
| 1635 | /* |
| 1636 | * The sg_count may be larger than nseg if |
| 1637 | * a transfer crosses a 32bit page. |
| 1638 | */ |
| 1639 | while (cur_seg < end_seg) { |
| 1640 | dma_addr_t addr; |
| 1641 | bus_size_t len; |
| 1642 | int consumed; |
| 1643 | |
| 1644 | addr = sg_dma_address(cur_seg); |
| 1645 | len = sg_dma_len(cur_seg); |
| 1646 | consumed = ahc_linux_map_seg(ahc, scb, |
| 1647 | sg, addr, len); |
| 1648 | sg += consumed; |
| 1649 | scb->sg_count += consumed; |
| 1650 | cur_seg++; |
| 1651 | } |
| 1652 | sg--; |
| 1653 | sg->len |= ahc_htole32(AHC_DMA_LAST_SEG); |
| 1654 | |
| 1655 | /* |
| 1656 | * Reset the sg list pointer. |
| 1657 | */ |
| 1658 | scb->hscb->sgptr = |
| 1659 | ahc_htole32(scb->sg_list_phys | SG_FULL_RESID); |
| 1660 | |
| 1661 | /* |
| 1662 | * Copy the first SG into the "current" |
| 1663 | * data pointer area. |
| 1664 | */ |
| 1665 | scb->hscb->dataptr = scb->sg_list->addr; |
| 1666 | scb->hscb->datacnt = scb->sg_list->len; |
| 1667 | } else if (cmd->request_bufflen != 0) { |
| 1668 | struct ahc_dma_seg *sg; |
| 1669 | dma_addr_t addr; |
| 1670 | |
| 1671 | sg = scb->sg_list; |
| 1672 | addr = pci_map_single(ahc->dev_softc, |
| 1673 | cmd->request_buffer, |
| 1674 | cmd->request_bufflen, |
| 1675 | cmd->sc_data_direction); |
| 1676 | scb->platform_data->buf_busaddr = addr; |
| 1677 | scb->sg_count = ahc_linux_map_seg(ahc, scb, |
| 1678 | sg, addr, |
| 1679 | cmd->request_bufflen); |
| 1680 | sg->len |= ahc_htole32(AHC_DMA_LAST_SEG); |
| 1681 | |
| 1682 | /* |
| 1683 | * Reset the sg list pointer. |
| 1684 | */ |
| 1685 | scb->hscb->sgptr = |
| 1686 | ahc_htole32(scb->sg_list_phys | SG_FULL_RESID); |
| 1687 | |
| 1688 | /* |
| 1689 | * Copy the first SG into the "current" |
| 1690 | * data pointer area. |
| 1691 | */ |
| 1692 | scb->hscb->dataptr = sg->addr; |
| 1693 | scb->hscb->datacnt = sg->len; |
| 1694 | } else { |
| 1695 | scb->hscb->sgptr = ahc_htole32(SG_LIST_NULL); |
| 1696 | scb->hscb->dataptr = 0; |
| 1697 | scb->hscb->datacnt = 0; |
| 1698 | scb->sg_count = 0; |
| 1699 | } |
| 1700 | |
| 1701 | LIST_INSERT_HEAD(&ahc->pending_scbs, scb, pending_links); |
| 1702 | dev->openings--; |
| 1703 | dev->active++; |
| 1704 | dev->commands_issued++; |
| 1705 | if ((dev->flags & AHC_DEV_PERIODIC_OTAG) != 0) |
| 1706 | dev->commands_since_idle_or_otag++; |
| 1707 | |
| 1708 | scb->flags |= SCB_ACTIVE; |
| 1709 | if (untagged_q) { |
| 1710 | TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe); |
| 1711 | scb->flags |= SCB_UNTAGGEDQ; |
| 1712 | } |
| 1713 | ahc_queue_scb(ahc, scb); |
| 1714 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | /* |
| 1718 | * SCSI controller interrupt handler. |
| 1719 | */ |
| 1720 | irqreturn_t |
| 1721 | ahc_linux_isr(int irq, void *dev_id, struct pt_regs * regs) |
| 1722 | { |
| 1723 | struct ahc_softc *ahc; |
| 1724 | u_long flags; |
| 1725 | int ours; |
| 1726 | |
| 1727 | ahc = (struct ahc_softc *) dev_id; |
| 1728 | ahc_lock(ahc, &flags); |
| 1729 | ours = ahc_intr(ahc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | ahc_unlock(ahc, &flags); |
| 1731 | return IRQ_RETVAL(ours); |
| 1732 | } |
| 1733 | |
| 1734 | void |
| 1735 | ahc_platform_flushwork(struct ahc_softc *ahc) |
| 1736 | { |
| 1737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | void |
| 1741 | ahc_send_async(struct ahc_softc *ahc, char channel, |
| 1742 | u_int target, u_int lun, ac_code code, void *arg) |
| 1743 | { |
| 1744 | switch (code) { |
| 1745 | case AC_TRANSFER_NEG: |
| 1746 | { |
| 1747 | char buf[80]; |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1748 | struct scsi_target *starget; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | struct ahc_linux_target *targ; |
| 1750 | struct info_str info; |
| 1751 | struct ahc_initiator_tinfo *tinfo; |
| 1752 | struct ahc_tmode_tstate *tstate; |
| 1753 | int target_offset; |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1754 | unsigned int target_ppr_options; |
| 1755 | |
| 1756 | BUG_ON(target == CAM_TARGET_WILDCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | |
| 1758 | info.buffer = buf; |
| 1759 | info.length = sizeof(buf); |
| 1760 | info.offset = 0; |
| 1761 | info.pos = 0; |
| 1762 | tinfo = ahc_fetch_transinfo(ahc, channel, |
| 1763 | channel == 'A' ? ahc->our_id |
| 1764 | : ahc->our_id_b, |
| 1765 | target, &tstate); |
| 1766 | |
| 1767 | /* |
| 1768 | * Don't bother reporting results while |
| 1769 | * negotiations are still pending. |
| 1770 | */ |
| 1771 | if (tinfo->curr.period != tinfo->goal.period |
| 1772 | || tinfo->curr.width != tinfo->goal.width |
| 1773 | || tinfo->curr.offset != tinfo->goal.offset |
| 1774 | || tinfo->curr.ppr_options != tinfo->goal.ppr_options) |
| 1775 | if (bootverbose == 0) |
| 1776 | break; |
| 1777 | |
| 1778 | /* |
| 1779 | * Don't bother reporting results that |
| 1780 | * are identical to those last reported. |
| 1781 | */ |
| 1782 | target_offset = target; |
| 1783 | if (channel == 'B') |
| 1784 | target_offset += 8; |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1785 | starget = ahc->platform_data->starget[target_offset]; |
| 1786 | targ = scsi_transport_target_data(starget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | if (targ == NULL) |
| 1788 | break; |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1789 | |
| 1790 | target_ppr_options = |
| 1791 | (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0) |
| 1792 | + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0) |
| 1793 | + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0); |
| 1794 | |
| 1795 | if (tinfo->curr.period == spi_period(starget) |
| 1796 | && tinfo->curr.width == spi_width(starget) |
| 1797 | && tinfo->curr.offset == spi_offset(starget) |
| 1798 | && tinfo->curr.ppr_options == target_ppr_options) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | if (bootverbose == 0) |
| 1800 | break; |
| 1801 | |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1802 | spi_period(starget) = tinfo->curr.period; |
| 1803 | spi_width(starget) = tinfo->curr.width; |
| 1804 | spi_offset(starget) = tinfo->curr.offset; |
| 1805 | spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ; |
| 1806 | spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ; |
| 1807 | spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ; |
| 1808 | spi_display_xfer_agreement(starget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | break; |
| 1810 | } |
| 1811 | case AC_SENT_BDR: |
| 1812 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | WARN_ON(lun != CAM_LUN_WILDCARD); |
| 1814 | scsi_report_device_reset(ahc->platform_data->host, |
| 1815 | channel - 'A', target); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | break; |
| 1817 | } |
| 1818 | case AC_BUS_RESET: |
| 1819 | if (ahc->platform_data->host != NULL) { |
| 1820 | scsi_report_bus_reset(ahc->platform_data->host, |
| 1821 | channel - 'A'); |
| 1822 | } |
| 1823 | break; |
| 1824 | default: |
| 1825 | panic("ahc_send_async: Unexpected async event"); |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | /* |
| 1830 | * Calls the higher level scsi done function and frees the scb. |
| 1831 | */ |
| 1832 | void |
| 1833 | ahc_done(struct ahc_softc *ahc, struct scb *scb) |
| 1834 | { |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 1835 | struct scsi_cmnd *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | struct ahc_linux_device *dev; |
| 1837 | |
| 1838 | LIST_REMOVE(scb, pending_links); |
| 1839 | if ((scb->flags & SCB_UNTAGGEDQ) != 0) { |
| 1840 | struct scb_tailq *untagged_q; |
| 1841 | int target_offset; |
| 1842 | |
| 1843 | target_offset = SCB_GET_TARGET_OFFSET(ahc, scb); |
| 1844 | untagged_q = &(ahc->untagged_queues[target_offset]); |
| 1845 | TAILQ_REMOVE(untagged_q, scb, links.tqe); |
James Bottomley | e4e360c | 2005-05-16 16:39:38 -0500 | [diff] [blame] | 1846 | BUG_ON(!TAILQ_EMPTY(untagged_q)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | if ((scb->flags & SCB_ACTIVE) == 0) { |
| 1850 | printf("SCB %d done'd twice\n", scb->hscb->tag); |
| 1851 | ahc_dump_card_state(ahc); |
| 1852 | panic("Stopping for safety"); |
| 1853 | } |
| 1854 | cmd = scb->io_ctx; |
| 1855 | dev = scb->platform_data->dev; |
| 1856 | dev->active--; |
| 1857 | dev->openings++; |
| 1858 | if ((cmd->result & (CAM_DEV_QFRZN << 16)) != 0) { |
| 1859 | cmd->result &= ~(CAM_DEV_QFRZN << 16); |
| 1860 | dev->qfrozen--; |
| 1861 | } |
| 1862 | ahc_linux_unmap_scb(ahc, scb); |
| 1863 | |
| 1864 | /* |
| 1865 | * Guard against stale sense data. |
| 1866 | * The Linux mid-layer assumes that sense |
| 1867 | * was retrieved anytime the first byte of |
| 1868 | * the sense buffer looks "sane". |
| 1869 | */ |
| 1870 | cmd->sense_buffer[0] = 0; |
| 1871 | if (ahc_get_transaction_status(scb) == CAM_REQ_INPROG) { |
| 1872 | uint32_t amount_xferred; |
| 1873 | |
| 1874 | amount_xferred = |
| 1875 | ahc_get_transfer_length(scb) - ahc_get_residual(scb); |
| 1876 | if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) { |
| 1877 | #ifdef AHC_DEBUG |
| 1878 | if ((ahc_debug & AHC_SHOW_MISC) != 0) { |
| 1879 | ahc_print_path(ahc, scb); |
| 1880 | printf("Set CAM_UNCOR_PARITY\n"); |
| 1881 | } |
| 1882 | #endif |
| 1883 | ahc_set_transaction_status(scb, CAM_UNCOR_PARITY); |
| 1884 | #ifdef AHC_REPORT_UNDERFLOWS |
| 1885 | /* |
| 1886 | * This code is disabled by default as some |
| 1887 | * clients of the SCSI system do not properly |
| 1888 | * initialize the underflow parameter. This |
| 1889 | * results in spurious termination of commands |
| 1890 | * that complete as expected (e.g. underflow is |
| 1891 | * allowed as command can return variable amounts |
| 1892 | * of data. |
| 1893 | */ |
| 1894 | } else if (amount_xferred < scb->io_ctx->underflow) { |
| 1895 | u_int i; |
| 1896 | |
| 1897 | ahc_print_path(ahc, scb); |
| 1898 | printf("CDB:"); |
| 1899 | for (i = 0; i < scb->io_ctx->cmd_len; i++) |
| 1900 | printf(" 0x%x", scb->io_ctx->cmnd[i]); |
| 1901 | printf("\n"); |
| 1902 | ahc_print_path(ahc, scb); |
| 1903 | printf("Saw underflow (%ld of %ld bytes). " |
| 1904 | "Treated as error\n", |
| 1905 | ahc_get_residual(scb), |
| 1906 | ahc_get_transfer_length(scb)); |
| 1907 | ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR); |
| 1908 | #endif |
| 1909 | } else { |
| 1910 | ahc_set_transaction_status(scb, CAM_REQ_CMP); |
| 1911 | } |
| 1912 | } else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) { |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1913 | ahc_linux_handle_scsi_status(ahc, cmd->device, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | |
| 1916 | if (dev->openings == 1 |
| 1917 | && ahc_get_transaction_status(scb) == CAM_REQ_CMP |
| 1918 | && ahc_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL) |
| 1919 | dev->tag_success_count++; |
| 1920 | /* |
| 1921 | * Some devices deal with temporary internal resource |
| 1922 | * shortages by returning queue full. When the queue |
| 1923 | * full occurrs, we throttle back. Slowly try to get |
| 1924 | * back to our previous queue depth. |
| 1925 | */ |
| 1926 | if ((dev->openings + dev->active) < dev->maxtags |
| 1927 | && dev->tag_success_count > AHC_TAG_SUCCESS_INTERVAL) { |
| 1928 | dev->tag_success_count = 0; |
| 1929 | dev->openings++; |
| 1930 | } |
| 1931 | |
| 1932 | if (dev->active == 0) |
| 1933 | dev->commands_since_idle_or_otag = 0; |
| 1934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | if ((scb->flags & SCB_RECOVERY_SCB) != 0) { |
| 1936 | printf("Recovery SCB completes\n"); |
| 1937 | if (ahc_get_transaction_status(scb) == CAM_BDR_SENT |
| 1938 | || ahc_get_transaction_status(scb) == CAM_REQ_ABORTED) |
| 1939 | ahc_set_transaction_status(scb, CAM_CMD_TIMEOUT); |
| 1940 | if ((ahc->platform_data->flags & AHC_UP_EH_SEMAPHORE) != 0) { |
| 1941 | ahc->platform_data->flags &= ~AHC_UP_EH_SEMAPHORE; |
| 1942 | up(&ahc->platform_data->eh_sem); |
| 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | ahc_free_scb(ahc, scb); |
| 1947 | ahc_linux_queue_cmd_complete(ahc, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | static void |
| 1951 | ahc_linux_handle_scsi_status(struct ahc_softc *ahc, |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1952 | struct scsi_device *sdev, struct scb *scb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | { |
| 1954 | struct ahc_devinfo devinfo; |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1955 | struct ahc_linux_device *dev = scsi_transport_device_data(sdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | |
| 1957 | ahc_compile_devinfo(&devinfo, |
| 1958 | ahc->our_id, |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 1959 | sdev->sdev_target->id, sdev->lun, |
| 1960 | sdev->sdev_target->channel == 0 ? 'A' : 'B', |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | ROLE_INITIATOR); |
| 1962 | |
| 1963 | /* |
| 1964 | * We don't currently trust the mid-layer to |
| 1965 | * properly deal with queue full or busy. So, |
| 1966 | * when one occurs, we tell the mid-layer to |
| 1967 | * unconditionally requeue the command to us |
| 1968 | * so that we can retry it ourselves. We also |
| 1969 | * implement our own throttling mechanism so |
| 1970 | * we don't clobber the device with too many |
| 1971 | * commands. |
| 1972 | */ |
| 1973 | switch (ahc_get_scsi_status(scb)) { |
| 1974 | default: |
| 1975 | break; |
| 1976 | case SCSI_STATUS_CHECK_COND: |
| 1977 | case SCSI_STATUS_CMD_TERMINATED: |
| 1978 | { |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 1979 | struct scsi_cmnd *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | |
| 1981 | /* |
| 1982 | * Copy sense information to the OS's cmd |
| 1983 | * structure if it is available. |
| 1984 | */ |
| 1985 | cmd = scb->io_ctx; |
| 1986 | if (scb->flags & SCB_SENSE) { |
| 1987 | u_int sense_size; |
| 1988 | |
| 1989 | sense_size = MIN(sizeof(struct scsi_sense_data) |
| 1990 | - ahc_get_sense_residual(scb), |
| 1991 | sizeof(cmd->sense_buffer)); |
| 1992 | memcpy(cmd->sense_buffer, |
| 1993 | ahc_get_sense_buf(ahc, scb), sense_size); |
| 1994 | if (sense_size < sizeof(cmd->sense_buffer)) |
| 1995 | memset(&cmd->sense_buffer[sense_size], 0, |
| 1996 | sizeof(cmd->sense_buffer) - sense_size); |
| 1997 | cmd->result |= (DRIVER_SENSE << 24); |
| 1998 | #ifdef AHC_DEBUG |
| 1999 | if (ahc_debug & AHC_SHOW_SENSE) { |
| 2000 | int i; |
| 2001 | |
| 2002 | printf("Copied %d bytes of sense data:", |
| 2003 | sense_size); |
| 2004 | for (i = 0; i < sense_size; i++) { |
| 2005 | if ((i & 0xF) == 0) |
| 2006 | printf("\n"); |
| 2007 | printf("0x%x ", cmd->sense_buffer[i]); |
| 2008 | } |
| 2009 | printf("\n"); |
| 2010 | } |
| 2011 | #endif |
| 2012 | } |
| 2013 | break; |
| 2014 | } |
| 2015 | case SCSI_STATUS_QUEUE_FULL: |
| 2016 | { |
| 2017 | /* |
| 2018 | * By the time the core driver has returned this |
| 2019 | * command, all other commands that were queued |
| 2020 | * to us but not the device have been returned. |
| 2021 | * This ensures that dev->active is equal to |
| 2022 | * the number of commands actually queued to |
| 2023 | * the device. |
| 2024 | */ |
| 2025 | dev->tag_success_count = 0; |
| 2026 | if (dev->active != 0) { |
| 2027 | /* |
| 2028 | * Drop our opening count to the number |
| 2029 | * of commands currently outstanding. |
| 2030 | */ |
| 2031 | dev->openings = 0; |
| 2032 | /* |
| 2033 | ahc_print_path(ahc, scb); |
| 2034 | printf("Dropping tag count to %d\n", dev->active); |
| 2035 | */ |
| 2036 | if (dev->active == dev->tags_on_last_queuefull) { |
| 2037 | |
| 2038 | dev->last_queuefull_same_count++; |
| 2039 | /* |
| 2040 | * If we repeatedly see a queue full |
| 2041 | * at the same queue depth, this |
| 2042 | * device has a fixed number of tag |
| 2043 | * slots. Lock in this tag depth |
| 2044 | * so we stop seeing queue fulls from |
| 2045 | * this device. |
| 2046 | */ |
| 2047 | if (dev->last_queuefull_same_count |
| 2048 | == AHC_LOCK_TAGS_COUNT) { |
| 2049 | dev->maxtags = dev->active; |
| 2050 | ahc_print_path(ahc, scb); |
| 2051 | printf("Locking max tag count at %d\n", |
| 2052 | dev->active); |
| 2053 | } |
| 2054 | } else { |
| 2055 | dev->tags_on_last_queuefull = dev->active; |
| 2056 | dev->last_queuefull_same_count = 0; |
| 2057 | } |
| 2058 | ahc_set_transaction_status(scb, CAM_REQUEUE_REQ); |
| 2059 | ahc_set_scsi_status(scb, SCSI_STATUS_OK); |
| 2060 | ahc_platform_set_tags(ahc, &devinfo, |
| 2061 | (dev->flags & AHC_DEV_Q_BASIC) |
| 2062 | ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED); |
| 2063 | break; |
| 2064 | } |
| 2065 | /* |
| 2066 | * Drop down to a single opening, and treat this |
| 2067 | * as if the target returned BUSY SCSI status. |
| 2068 | */ |
| 2069 | dev->openings = 1; |
| 2070 | ahc_set_scsi_status(scb, SCSI_STATUS_BUSY); |
| 2071 | ahc_platform_set_tags(ahc, &devinfo, |
| 2072 | (dev->flags & AHC_DEV_Q_BASIC) |
| 2073 | ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | break; |
| 2075 | } |
| 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | static void |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 2080 | ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | { |
| 2082 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | * Map CAM error codes into Linux Error codes. We |
| 2084 | * avoid the conversion so that the DV code has the |
| 2085 | * full error information available when making |
| 2086 | * state change decisions. |
| 2087 | */ |
| cb62402 | 2005-04-17 18:03:20 -0500 | [diff] [blame] | 2088 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | u_int new_status; |
| 2090 | |
| 2091 | switch (ahc_cmd_get_transaction_status(cmd)) { |
| 2092 | case CAM_REQ_INPROG: |
| 2093 | case CAM_REQ_CMP: |
| 2094 | case CAM_SCSI_STATUS_ERROR: |
| 2095 | new_status = DID_OK; |
| 2096 | break; |
| 2097 | case CAM_REQ_ABORTED: |
| 2098 | new_status = DID_ABORT; |
| 2099 | break; |
| 2100 | case CAM_BUSY: |
| 2101 | new_status = DID_BUS_BUSY; |
| 2102 | break; |
| 2103 | case CAM_REQ_INVALID: |
| 2104 | case CAM_PATH_INVALID: |
| 2105 | new_status = DID_BAD_TARGET; |
| 2106 | break; |
| 2107 | case CAM_SEL_TIMEOUT: |
| 2108 | new_status = DID_NO_CONNECT; |
| 2109 | break; |
| 2110 | case CAM_SCSI_BUS_RESET: |
| 2111 | case CAM_BDR_SENT: |
| 2112 | new_status = DID_RESET; |
| 2113 | break; |
| 2114 | case CAM_UNCOR_PARITY: |
| 2115 | new_status = DID_PARITY; |
| 2116 | break; |
| 2117 | case CAM_CMD_TIMEOUT: |
| 2118 | new_status = DID_TIME_OUT; |
| 2119 | break; |
| 2120 | case CAM_UA_ABORT: |
| 2121 | case CAM_REQ_CMP_ERR: |
| 2122 | case CAM_AUTOSENSE_FAIL: |
| 2123 | case CAM_NO_HBA: |
| 2124 | case CAM_DATA_RUN_ERR: |
| 2125 | case CAM_UNEXP_BUSFREE: |
| 2126 | case CAM_SEQUENCE_FAIL: |
| 2127 | case CAM_CCB_LEN_ERR: |
| 2128 | case CAM_PROVIDE_FAIL: |
| 2129 | case CAM_REQ_TERMIO: |
| 2130 | case CAM_UNREC_HBA_ERROR: |
| 2131 | case CAM_REQ_TOO_BIG: |
| 2132 | new_status = DID_ERROR; |
| 2133 | break; |
| 2134 | case CAM_REQUEUE_REQ: |
James Bottomley | 8e45ebc | 2005-05-17 00:06:08 -0500 | [diff] [blame] | 2135 | new_status = DID_REQUEUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | break; |
| 2137 | default: |
| 2138 | /* We should never get here */ |
| 2139 | new_status = DID_ERROR; |
| 2140 | break; |
| 2141 | } |
| 2142 | |
| 2143 | ahc_cmd_set_transaction_status(cmd, new_status); |
| 2144 | } |
| 2145 | |
James Bottomley | 8e45ebc | 2005-05-17 00:06:08 -0500 | [diff] [blame] | 2146 | cmd->scsi_done(cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | ahc_linux_sem_timeout(u_long arg) |
| 2151 | { |
| 2152 | struct ahc_softc *ahc; |
| 2153 | u_long s; |
| 2154 | |
| 2155 | ahc = (struct ahc_softc *)arg; |
| 2156 | |
| 2157 | ahc_lock(ahc, &s); |
| 2158 | if ((ahc->platform_data->flags & AHC_UP_EH_SEMAPHORE) != 0) { |
| 2159 | ahc->platform_data->flags &= ~AHC_UP_EH_SEMAPHORE; |
| 2160 | up(&ahc->platform_data->eh_sem); |
| 2161 | } |
| 2162 | ahc_unlock(ahc, &s); |
| 2163 | } |
| 2164 | |
| 2165 | static void |
| 2166 | ahc_linux_freeze_simq(struct ahc_softc *ahc) |
| 2167 | { |
| 2168 | ahc->platform_data->qfrozen++; |
| 2169 | if (ahc->platform_data->qfrozen == 1) { |
| 2170 | scsi_block_requests(ahc->platform_data->host); |
| 2171 | |
| 2172 | /* XXX What about Twin channels? */ |
| 2173 | ahc_platform_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS, |
| 2174 | CAM_LUN_WILDCARD, SCB_LIST_NULL, |
| 2175 | ROLE_INITIATOR, CAM_REQUEUE_REQ); |
| 2176 | } |
| 2177 | } |
| 2178 | |
| 2179 | static void |
| 2180 | ahc_linux_release_simq(u_long arg) |
| 2181 | { |
| 2182 | struct ahc_softc *ahc; |
| 2183 | u_long s; |
| 2184 | int unblock_reqs; |
| 2185 | |
| 2186 | ahc = (struct ahc_softc *)arg; |
| 2187 | |
| 2188 | unblock_reqs = 0; |
| 2189 | ahc_lock(ahc, &s); |
| 2190 | if (ahc->platform_data->qfrozen > 0) |
| 2191 | ahc->platform_data->qfrozen--; |
| 2192 | if (ahc->platform_data->qfrozen == 0) |
| 2193 | unblock_reqs = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | ahc_unlock(ahc, &s); |
| 2195 | /* |
| 2196 | * There is still a race here. The mid-layer |
| 2197 | * should keep its own freeze count and use |
| 2198 | * a bottom half handler to run the queues |
| 2199 | * so we can unblock with our own lock held. |
| 2200 | */ |
| 2201 | if (unblock_reqs) |
| 2202 | scsi_unblock_requests(ahc->platform_data->host); |
| 2203 | } |
| 2204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | static int |
Christoph Hellwig | 013791e | 2005-05-16 18:52:39 +0200 | [diff] [blame] | 2206 | ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | { |
| 2208 | struct ahc_softc *ahc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | struct ahc_linux_device *dev; |
| 2210 | struct scb *pending_scb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | u_int saved_scbptr; |
| 2212 | u_int active_scb_index; |
| 2213 | u_int last_phase; |
| 2214 | u_int saved_scsiid; |
| 2215 | u_int cdb_byte; |
| 2216 | int retval; |
| 2217 | int was_paused; |
| 2218 | int paused; |
| 2219 | int wait; |
| 2220 | int disconnected; |
| 2221 | |
| 2222 | pending_scb = NULL; |
| 2223 | paused = FALSE; |
| 2224 | wait = FALSE; |
| 2225 | ahc = *(struct ahc_softc **)cmd->device->host->hostdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | |
| 2227 | printf("%s:%d:%d:%d: Attempting to queue a%s message\n", |
| 2228 | ahc_name(ahc), cmd->device->channel, |
| 2229 | cmd->device->id, cmd->device->lun, |
| 2230 | flag == SCB_ABORT ? "n ABORT" : " TARGET RESET"); |
| 2231 | |
| 2232 | printf("CDB:"); |
| 2233 | for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++) |
| 2234 | printf(" 0x%x", cmd->cmnd[cdb_byte]); |
| 2235 | printf("\n"); |
| 2236 | |
| 2237 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | * First determine if we currently own this command. |
| 2239 | * Start by searching the device queue. If not found |
| 2240 | * there, check the pending_scb list. If not found |
| 2241 | * at all, and the system wanted us to just abort the |
| 2242 | * command, return success. |
| 2243 | */ |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 2244 | dev = scsi_transport_device_data(cmd->device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | |
| 2246 | if (dev == NULL) { |
| 2247 | /* |
| 2248 | * No target device for this command exists, |
| 2249 | * so we must not still own the command. |
| 2250 | */ |
| 2251 | printf("%s:%d:%d:%d: Is not an active device\n", |
| 2252 | ahc_name(ahc), cmd->device->channel, cmd->device->id, |
| 2253 | cmd->device->lun); |
| 2254 | retval = SUCCESS; |
| 2255 | goto no_cmd; |
| 2256 | } |
| 2257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | if ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED)) == 0 |
| 2259 | && ahc_search_untagged_queues(ahc, cmd, cmd->device->id, |
| 2260 | cmd->device->channel + 'A', |
| 2261 | cmd->device->lun, |
| 2262 | CAM_REQ_ABORTED, SEARCH_COMPLETE) != 0) { |
| 2263 | printf("%s:%d:%d:%d: Command found on untagged queue\n", |
| 2264 | ahc_name(ahc), cmd->device->channel, cmd->device->id, |
| 2265 | cmd->device->lun); |
| 2266 | retval = SUCCESS; |
| 2267 | goto done; |
| 2268 | } |
| 2269 | |
| 2270 | /* |
| 2271 | * See if we can find a matching cmd in the pending list. |
| 2272 | */ |
| 2273 | LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) { |
| 2274 | if (pending_scb->io_ctx == cmd) |
| 2275 | break; |
| 2276 | } |
| 2277 | |
| 2278 | if (pending_scb == NULL && flag == SCB_DEVICE_RESET) { |
| 2279 | |
| 2280 | /* Any SCB for this device will do for a target reset */ |
| 2281 | LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) { |
| 2282 | if (ahc_match_scb(ahc, pending_scb, cmd->device->id, |
| 2283 | cmd->device->channel + 'A', |
| 2284 | CAM_LUN_WILDCARD, |
| 2285 | SCB_LIST_NULL, ROLE_INITIATOR) == 0) |
| 2286 | break; |
| 2287 | } |
| 2288 | } |
| 2289 | |
| 2290 | if (pending_scb == NULL) { |
| 2291 | printf("%s:%d:%d:%d: Command not found\n", |
| 2292 | ahc_name(ahc), cmd->device->channel, cmd->device->id, |
| 2293 | cmd->device->lun); |
| 2294 | goto no_cmd; |
| 2295 | } |
| 2296 | |
| 2297 | if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) { |
| 2298 | /* |
| 2299 | * We can't queue two recovery actions using the same SCB |
| 2300 | */ |
| 2301 | retval = FAILED; |
| 2302 | goto done; |
| 2303 | } |
| 2304 | |
| 2305 | /* |
| 2306 | * Ensure that the card doesn't do anything |
| 2307 | * behind our back and that we didn't "just" miss |
| 2308 | * an interrupt that would affect this cmd. |
| 2309 | */ |
| 2310 | was_paused = ahc_is_paused(ahc); |
| 2311 | ahc_pause_and_flushwork(ahc); |
| 2312 | paused = TRUE; |
| 2313 | |
| 2314 | if ((pending_scb->flags & SCB_ACTIVE) == 0) { |
| 2315 | printf("%s:%d:%d:%d: Command already completed\n", |
| 2316 | ahc_name(ahc), cmd->device->channel, cmd->device->id, |
| 2317 | cmd->device->lun); |
| 2318 | goto no_cmd; |
| 2319 | } |
| 2320 | |
| 2321 | printf("%s: At time of recovery, card was %spaused\n", |
| 2322 | ahc_name(ahc), was_paused ? "" : "not "); |
| 2323 | ahc_dump_card_state(ahc); |
| 2324 | |
| 2325 | disconnected = TRUE; |
| 2326 | if (flag == SCB_ABORT) { |
| 2327 | if (ahc_search_qinfifo(ahc, cmd->device->id, |
| 2328 | cmd->device->channel + 'A', |
| 2329 | cmd->device->lun, |
| 2330 | pending_scb->hscb->tag, |
| 2331 | ROLE_INITIATOR, CAM_REQ_ABORTED, |
| 2332 | SEARCH_COMPLETE) > 0) { |
| 2333 | printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n", |
| 2334 | ahc_name(ahc), cmd->device->channel, |
| 2335 | cmd->device->id, cmd->device->lun); |
| 2336 | retval = SUCCESS; |
| 2337 | goto done; |
| 2338 | } |
| 2339 | } else if (ahc_search_qinfifo(ahc, cmd->device->id, |
| 2340 | cmd->device->channel + 'A', |
| 2341 | cmd->device->lun, pending_scb->hscb->tag, |
| 2342 | ROLE_INITIATOR, /*status*/0, |
| 2343 | SEARCH_COUNT) > 0) { |
| 2344 | disconnected = FALSE; |
| 2345 | } |
| 2346 | |
| 2347 | if (disconnected && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) { |
| 2348 | struct scb *bus_scb; |
| 2349 | |
| 2350 | bus_scb = ahc_lookup_scb(ahc, ahc_inb(ahc, SCB_TAG)); |
| 2351 | if (bus_scb == pending_scb) |
| 2352 | disconnected = FALSE; |
| 2353 | else if (flag != SCB_ABORT |
| 2354 | && ahc_inb(ahc, SAVED_SCSIID) == pending_scb->hscb->scsiid |
| 2355 | && ahc_inb(ahc, SAVED_LUN) == SCB_GET_LUN(pending_scb)) |
| 2356 | disconnected = FALSE; |
| 2357 | } |
| 2358 | |
| 2359 | /* |
| 2360 | * At this point, pending_scb is the scb associated with the |
| 2361 | * passed in command. That command is currently active on the |
| 2362 | * bus, is in the disconnected state, or we're hoping to find |
| 2363 | * a command for the same target active on the bus to abuse to |
| 2364 | * send a BDR. Queue the appropriate message based on which of |
| 2365 | * these states we are in. |
| 2366 | */ |
| 2367 | last_phase = ahc_inb(ahc, LASTPHASE); |
| 2368 | saved_scbptr = ahc_inb(ahc, SCBPTR); |
| 2369 | active_scb_index = ahc_inb(ahc, SCB_TAG); |
| 2370 | saved_scsiid = ahc_inb(ahc, SAVED_SCSIID); |
| 2371 | if (last_phase != P_BUSFREE |
| 2372 | && (pending_scb->hscb->tag == active_scb_index |
| 2373 | || (flag == SCB_DEVICE_RESET |
| 2374 | && SCSIID_TARGET(ahc, saved_scsiid) == cmd->device->id))) { |
| 2375 | |
| 2376 | /* |
| 2377 | * We're active on the bus, so assert ATN |
| 2378 | * and hope that the target responds. |
| 2379 | */ |
| 2380 | pending_scb = ahc_lookup_scb(ahc, active_scb_index); |
| 2381 | pending_scb->flags |= SCB_RECOVERY_SCB|flag; |
| 2382 | ahc_outb(ahc, MSG_OUT, HOST_MSG); |
| 2383 | ahc_outb(ahc, SCSISIGO, last_phase|ATNO); |
| 2384 | printf("%s:%d:%d:%d: Device is active, asserting ATN\n", |
| 2385 | ahc_name(ahc), cmd->device->channel, cmd->device->id, |
| 2386 | cmd->device->lun); |
| 2387 | wait = TRUE; |
| 2388 | } else if (disconnected) { |
| 2389 | |
| 2390 | /* |
| 2391 | * Actually re-queue this SCB in an attempt |
| 2392 | * to select the device before it reconnects. |
| 2393 | * In either case (selection or reselection), |
| 2394 | * we will now issue the approprate message |
| 2395 | * to the timed-out device. |
| 2396 | * |
| 2397 | * Set the MK_MESSAGE control bit indicating |
| 2398 | * that we desire to send a message. We |
| 2399 | * also set the disconnected flag since |
| 2400 | * in the paging case there is no guarantee |
| 2401 | * that our SCB control byte matches the |
| 2402 | * version on the card. We don't want the |
| 2403 | * sequencer to abort the command thinking |
| 2404 | * an unsolicited reselection occurred. |
| 2405 | */ |
| 2406 | pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED; |
| 2407 | pending_scb->flags |= SCB_RECOVERY_SCB|flag; |
| 2408 | |
| 2409 | /* |
| 2410 | * Remove any cached copy of this SCB in the |
| 2411 | * disconnected list in preparation for the |
| 2412 | * queuing of our abort SCB. We use the |
| 2413 | * same element in the SCB, SCB_NEXT, for |
| 2414 | * both the qinfifo and the disconnected list. |
| 2415 | */ |
| 2416 | ahc_search_disc_list(ahc, cmd->device->id, |
| 2417 | cmd->device->channel + 'A', |
| 2418 | cmd->device->lun, pending_scb->hscb->tag, |
| 2419 | /*stop_on_first*/TRUE, |
| 2420 | /*remove*/TRUE, |
| 2421 | /*save_state*/FALSE); |
| 2422 | |
| 2423 | /* |
| 2424 | * In the non-paging case, the sequencer will |
| 2425 | * never re-reference the in-core SCB. |
| 2426 | * To make sure we are notified during |
| 2427 | * reslection, set the MK_MESSAGE flag in |
| 2428 | * the card's copy of the SCB. |
| 2429 | */ |
| 2430 | if ((ahc->flags & AHC_PAGESCBS) == 0) { |
| 2431 | ahc_outb(ahc, SCBPTR, pending_scb->hscb->tag); |
| 2432 | ahc_outb(ahc, SCB_CONTROL, |
| 2433 | ahc_inb(ahc, SCB_CONTROL)|MK_MESSAGE); |
| 2434 | } |
| 2435 | |
| 2436 | /* |
| 2437 | * Clear out any entries in the QINFIFO first |
| 2438 | * so we are the next SCB for this target |
| 2439 | * to run. |
| 2440 | */ |
| 2441 | ahc_search_qinfifo(ahc, cmd->device->id, |
| 2442 | cmd->device->channel + 'A', |
| 2443 | cmd->device->lun, SCB_LIST_NULL, |
| 2444 | ROLE_INITIATOR, CAM_REQUEUE_REQ, |
| 2445 | SEARCH_COMPLETE); |
| 2446 | ahc_qinfifo_requeue_tail(ahc, pending_scb); |
| 2447 | ahc_outb(ahc, SCBPTR, saved_scbptr); |
| 2448 | ahc_print_path(ahc, pending_scb); |
| 2449 | printf("Device is disconnected, re-queuing SCB\n"); |
| 2450 | wait = TRUE; |
| 2451 | } else { |
| 2452 | printf("%s:%d:%d:%d: Unable to deliver message\n", |
| 2453 | ahc_name(ahc), cmd->device->channel, cmd->device->id, |
| 2454 | cmd->device->lun); |
| 2455 | retval = FAILED; |
| 2456 | goto done; |
| 2457 | } |
| 2458 | |
| 2459 | no_cmd: |
| 2460 | /* |
| 2461 | * Our assumption is that if we don't have the command, no |
| 2462 | * recovery action was required, so we return success. Again, |
| 2463 | * the semantics of the mid-layer recovery engine are not |
| 2464 | * well defined, so this may change in time. |
| 2465 | */ |
| 2466 | retval = SUCCESS; |
| 2467 | done: |
| 2468 | if (paused) |
| 2469 | ahc_unpause(ahc); |
| 2470 | if (wait) { |
| 2471 | struct timer_list timer; |
| 2472 | int ret; |
| 2473 | |
| 2474 | ahc->platform_data->flags |= AHC_UP_EH_SEMAPHORE; |
| 2475 | spin_unlock_irq(&ahc->platform_data->spin_lock); |
| 2476 | init_timer(&timer); |
| 2477 | timer.data = (u_long)ahc; |
| 2478 | timer.expires = jiffies + (5 * HZ); |
| 2479 | timer.function = ahc_linux_sem_timeout; |
| 2480 | add_timer(&timer); |
| 2481 | printf("Recovery code sleeping\n"); |
| 2482 | down(&ahc->platform_data->eh_sem); |
| 2483 | printf("Recovery code awake\n"); |
| 2484 | ret = del_timer_sync(&timer); |
| 2485 | if (ret == 0) { |
| 2486 | printf("Timer Expired\n"); |
| 2487 | retval = FAILED; |
| 2488 | } |
| 2489 | spin_lock_irq(&ahc->platform_data->spin_lock); |
| 2490 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | return (retval); |
| 2492 | } |
| 2493 | |
| 2494 | void |
| 2495 | ahc_platform_dump_card_state(struct ahc_softc *ahc) |
| 2496 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | static void ahc_linux_exit(void); |
| 2500 | |
James Bottomley | fad01ef | 2005-05-08 16:00:15 -0500 | [diff] [blame] | 2501 | static void ahc_linux_set_width(struct scsi_target *starget, int width) |
| 2502 | { |
| 2503 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 2504 | struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); |
| 2505 | struct ahc_devinfo devinfo; |
| 2506 | unsigned long flags; |
| 2507 | |
| 2508 | ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, |
| 2509 | starget->channel + 'A', ROLE_INITIATOR); |
| 2510 | ahc_lock(ahc, &flags); |
| 2511 | ahc_set_width(ahc, &devinfo, width, AHC_TRANS_GOAL, FALSE); |
| 2512 | ahc_unlock(ahc, &flags); |
| 2513 | } |
| 2514 | |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2515 | static void ahc_linux_set_period(struct scsi_target *starget, int period) |
| 2516 | { |
| 2517 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 2518 | struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); |
| 2519 | struct ahc_tmode_tstate *tstate; |
| 2520 | struct ahc_initiator_tinfo *tinfo |
| 2521 | = ahc_fetch_transinfo(ahc, |
| 2522 | starget->channel + 'A', |
| 2523 | shost->this_id, starget->id, &tstate); |
| 2524 | struct ahc_devinfo devinfo; |
James Bottomley | 597487b | 2005-06-03 09:49:01 -0500 | [diff] [blame] | 2525 | unsigned int ppr_options = tinfo->goal.ppr_options; |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2526 | unsigned long flags; |
James Bottomley | 597487b | 2005-06-03 09:49:01 -0500 | [diff] [blame] | 2527 | unsigned long offset = tinfo->goal.offset; |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2528 | struct ahc_syncrate *syncrate; |
| 2529 | |
| 2530 | if (offset == 0) |
| 2531 | offset = MAX_OFFSET; |
| 2532 | |
James Bottomley | 2bf2c56 | 2005-05-19 21:30:13 -0500 | [diff] [blame] | 2533 | if (period < 9) |
| 2534 | period = 9; /* 12.5ns is our minimum */ |
| 2535 | if (period == 9) |
| 2536 | ppr_options |= MSG_EXT_PPR_DT_REQ; |
| 2537 | |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2538 | ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, |
| 2539 | starget->channel + 'A', ROLE_INITIATOR); |
James Bottomley | fad01ef | 2005-05-08 16:00:15 -0500 | [diff] [blame] | 2540 | |
| 2541 | /* all PPR requests apart from QAS require wide transfers */ |
| 2542 | if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) { |
James Bottomley | fad01ef | 2005-05-08 16:00:15 -0500 | [diff] [blame] | 2543 | if (spi_width(starget) == 0) |
| 2544 | ppr_options &= MSG_EXT_PPR_QAS_REQ; |
| 2545 | } |
| 2546 | |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2547 | syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); |
| 2548 | ahc_lock(ahc, &flags); |
| 2549 | ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset, |
| 2550 | ppr_options, AHC_TRANS_GOAL, FALSE); |
| 2551 | ahc_unlock(ahc, &flags); |
| 2552 | } |
| 2553 | |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2554 | static void ahc_linux_set_offset(struct scsi_target *starget, int offset) |
| 2555 | { |
| 2556 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 2557 | struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); |
| 2558 | struct ahc_tmode_tstate *tstate; |
| 2559 | struct ahc_initiator_tinfo *tinfo |
| 2560 | = ahc_fetch_transinfo(ahc, |
| 2561 | starget->channel + 'A', |
| 2562 | shost->this_id, starget->id, &tstate); |
| 2563 | struct ahc_devinfo devinfo; |
| 2564 | unsigned int ppr_options = 0; |
| 2565 | unsigned int period = 0; |
| 2566 | unsigned long flags; |
| 2567 | struct ahc_syncrate *syncrate = NULL; |
| 2568 | |
| 2569 | ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, |
| 2570 | starget->channel + 'A', ROLE_INITIATOR); |
| 2571 | if (offset != 0) { |
| 2572 | syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); |
James Bottomley | 597487b | 2005-06-03 09:49:01 -0500 | [diff] [blame] | 2573 | period = tinfo->goal.period; |
| 2574 | ppr_options = tinfo->goal.ppr_options; |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2575 | } |
| 2576 | ahc_lock(ahc, &flags); |
| 2577 | ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset, |
| 2578 | ppr_options, AHC_TRANS_GOAL, FALSE); |
| 2579 | ahc_unlock(ahc, &flags); |
| 2580 | } |
| 2581 | |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2582 | static void ahc_linux_set_dt(struct scsi_target *starget, int dt) |
| 2583 | { |
| 2584 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 2585 | struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); |
| 2586 | struct ahc_tmode_tstate *tstate; |
| 2587 | struct ahc_initiator_tinfo *tinfo |
| 2588 | = ahc_fetch_transinfo(ahc, |
| 2589 | starget->channel + 'A', |
| 2590 | shost->this_id, starget->id, &tstate); |
| 2591 | struct ahc_devinfo devinfo; |
James Bottomley | 597487b | 2005-06-03 09:49:01 -0500 | [diff] [blame] | 2592 | unsigned int ppr_options = tinfo->goal.ppr_options |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2593 | & ~MSG_EXT_PPR_DT_REQ; |
James Bottomley | 597487b | 2005-06-03 09:49:01 -0500 | [diff] [blame] | 2594 | unsigned int period = tinfo->goal.period; |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2595 | unsigned long flags; |
| 2596 | struct ahc_syncrate *syncrate; |
| 2597 | |
James Bottomley | 2bf2c56 | 2005-05-19 21:30:13 -0500 | [diff] [blame] | 2598 | if (dt) { |
| 2599 | period = 9; /* 12.5ns is the only period valid for DT */ |
| 2600 | ppr_options |= MSG_EXT_PPR_DT_REQ; |
| 2601 | } else if (period == 9) |
| 2602 | period = 10; /* if resetting DT, period must be >= 25ns */ |
| 2603 | |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2604 | ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, |
| 2605 | starget->channel + 'A', ROLE_INITIATOR); |
James Bottomley | fad01ef | 2005-05-08 16:00:15 -0500 | [diff] [blame] | 2606 | syncrate = ahc_find_syncrate(ahc, &period, &ppr_options,AHC_SYNCRATE_DT); |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2607 | ahc_lock(ahc, &flags); |
James Bottomley | 597487b | 2005-06-03 09:49:01 -0500 | [diff] [blame] | 2608 | ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset, |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2609 | ppr_options, AHC_TRANS_GOAL, FALSE); |
| 2610 | ahc_unlock(ahc, &flags); |
| 2611 | } |
| 2612 | |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2613 | static void ahc_linux_set_qas(struct scsi_target *starget, int qas) |
| 2614 | { |
| 2615 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 2616 | struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); |
| 2617 | struct ahc_tmode_tstate *tstate; |
| 2618 | struct ahc_initiator_tinfo *tinfo |
| 2619 | = ahc_fetch_transinfo(ahc, |
| 2620 | starget->channel + 'A', |
| 2621 | shost->this_id, starget->id, &tstate); |
| 2622 | struct ahc_devinfo devinfo; |
James Bottomley | 597487b | 2005-06-03 09:49:01 -0500 | [diff] [blame] | 2623 | unsigned int ppr_options = tinfo->goal.ppr_options |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2624 | & ~MSG_EXT_PPR_QAS_REQ; |
James Bottomley | 597487b | 2005-06-03 09:49:01 -0500 | [diff] [blame] | 2625 | unsigned int period = tinfo->goal.period; |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2626 | unsigned long flags; |
| 2627 | struct ahc_syncrate *syncrate; |
| 2628 | |
| 2629 | if (qas) |
| 2630 | ppr_options |= MSG_EXT_PPR_QAS_REQ; |
| 2631 | |
| 2632 | ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, |
| 2633 | starget->channel + 'A', ROLE_INITIATOR); |
James Bottomley | fad01ef | 2005-05-08 16:00:15 -0500 | [diff] [blame] | 2634 | syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2635 | ahc_lock(ahc, &flags); |
James Bottomley | 597487b | 2005-06-03 09:49:01 -0500 | [diff] [blame] | 2636 | ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset, |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2637 | ppr_options, AHC_TRANS_GOAL, FALSE); |
| 2638 | ahc_unlock(ahc, &flags); |
| 2639 | } |
| 2640 | |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2641 | static void ahc_linux_set_iu(struct scsi_target *starget, int iu) |
| 2642 | { |
| 2643 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 2644 | struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); |
| 2645 | struct ahc_tmode_tstate *tstate; |
| 2646 | struct ahc_initiator_tinfo *tinfo |
| 2647 | = ahc_fetch_transinfo(ahc, |
| 2648 | starget->channel + 'A', |
| 2649 | shost->this_id, starget->id, &tstate); |
| 2650 | struct ahc_devinfo devinfo; |
James Bottomley | 597487b | 2005-06-03 09:49:01 -0500 | [diff] [blame] | 2651 | unsigned int ppr_options = tinfo->goal.ppr_options |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2652 | & ~MSG_EXT_PPR_IU_REQ; |
James Bottomley | 597487b | 2005-06-03 09:49:01 -0500 | [diff] [blame] | 2653 | unsigned int period = tinfo->goal.period; |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2654 | unsigned long flags; |
| 2655 | struct ahc_syncrate *syncrate; |
| 2656 | |
| 2657 | if (iu) |
| 2658 | ppr_options |= MSG_EXT_PPR_IU_REQ; |
| 2659 | |
| 2660 | ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, |
| 2661 | starget->channel + 'A', ROLE_INITIATOR); |
James Bottomley | fad01ef | 2005-05-08 16:00:15 -0500 | [diff] [blame] | 2662 | syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2663 | ahc_lock(ahc, &flags); |
James Bottomley | 597487b | 2005-06-03 09:49:01 -0500 | [diff] [blame] | 2664 | ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset, |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2665 | ppr_options, AHC_TRANS_GOAL, FALSE); |
| 2666 | ahc_unlock(ahc, &flags); |
| 2667 | } |
| 2668 | |
| 2669 | static struct spi_function_template ahc_linux_transport_functions = { |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2670 | .set_offset = ahc_linux_set_offset, |
| 2671 | .show_offset = 1, |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2672 | .set_period = ahc_linux_set_period, |
| 2673 | .show_period = 1, |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2674 | .set_width = ahc_linux_set_width, |
| 2675 | .show_width = 1, |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2676 | .set_dt = ahc_linux_set_dt, |
| 2677 | .show_dt = 1, |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2678 | .set_iu = ahc_linux_set_iu, |
| 2679 | .show_iu = 1, |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2680 | .set_qas = ahc_linux_set_qas, |
| 2681 | .show_qas = 1, |
| 2682 | }; |
| 2683 | |
| 2684 | |
| 2685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | static int __init |
| 2687 | ahc_linux_init(void) |
| 2688 | { |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2689 | ahc_linux_transport_template = spi_attach_transport(&ahc_linux_transport_functions); |
| 2690 | if (!ahc_linux_transport_template) |
| 2691 | return -ENODEV; |
James Bottomley | b1abb4d | 2005-05-24 17:15:43 -0500 | [diff] [blame] | 2692 | scsi_transport_reserve_target(ahc_linux_transport_template, |
| 2693 | sizeof(struct ahc_linux_target)); |
| 2694 | scsi_transport_reserve_device(ahc_linux_transport_template, |
| 2695 | sizeof(struct ahc_linux_device)); |
James Bottomley | 858eaca16 | 2005-04-21 07:35:45 -0700 | [diff] [blame] | 2696 | if (ahc_linux_detect(&aic7xxx_driver_template)) |
| 2697 | return 0; |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2698 | spi_release_transport(ahc_linux_transport_template); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | ahc_linux_exit(); |
| 2700 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | static void |
| 2704 | ahc_linux_exit(void) |
| 2705 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | ahc_linux_pci_exit(); |
| 2707 | ahc_linux_eisa_exit(); |
| 92d161c | 2005-04-17 16:59:33 -0500 | [diff] [blame] | 2708 | spi_release_transport(ahc_linux_transport_template); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | module_init(ahc_linux_init); |
| 2712 | module_exit(ahc_linux_exit); |