diff options
author | Hannes Reinecke <hare@suse.de> | 2005-07-22 10:44:04 -0400 |
---|---|---|
committer | James Bottomley <jejb@mulgrave.(none)> | 2005-08-03 12:45:14 -0400 |
commit | 73a25462100772b72a5d62fd66dff01b53018618 (patch) | |
tree | de112862069bcef5786b9878ca89bdcda9a0097c /drivers/scsi/aic7xxx/aic79xx_osm.c | |
parent | 60a13213840296b1e32d6781653a0eaa83d04382 (diff) |
[SCSI] aic79xx: update to use scsi_transport_spi
This patch updates the aic79xx driver to take advantage of the
scsi_transport_spi infrastructure. Patch is quite a mess as some
procedures have been reshuffled to be closer to the aic7xxx driver.
Rejections fixed and
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/aic7xxx/aic79xx_osm.c')
-rw-r--r-- | drivers/scsi/aic7xxx/aic79xx_osm.c | 3421 |
1 files changed, 759 insertions, 2662 deletions
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c index 7463dd515d11..70997ca28baa 100644 --- a/drivers/scsi/aic7xxx/aic79xx_osm.c +++ b/drivers/scsi/aic7xxx/aic79xx_osm.c | |||
@@ -46,6 +46,8 @@ | |||
46 | #include "aic79xx_inline.h" | 46 | #include "aic79xx_inline.h" |
47 | #include <scsi/scsicam.h> | 47 | #include <scsi/scsicam.h> |
48 | 48 | ||
49 | static struct scsi_transport_template *ahd_linux_transport_template = NULL; | ||
50 | |||
49 | /* | 51 | /* |
50 | * Include aiclib.c as part of our | 52 | * Include aiclib.c as part of our |
51 | * "module dependencies are hard" work around. | 53 | * "module dependencies are hard" work around. |
@@ -54,6 +56,7 @@ | |||
54 | 56 | ||
55 | #include <linux/init.h> /* __setup */ | 57 | #include <linux/init.h> /* __setup */ |
56 | #include <linux/mm.h> /* For fetching system memory size */ | 58 | #include <linux/mm.h> /* For fetching system memory size */ |
59 | #include <linux/blkdev.h> /* For block_size() */ | ||
57 | #include <linux/delay.h> /* For ssleep/msleep */ | 60 | #include <linux/delay.h> /* For ssleep/msleep */ |
58 | 61 | ||
59 | /* | 62 | /* |
@@ -178,71 +181,6 @@ static adapter_tag_info_t aic79xx_tag_info[] = | |||
178 | }; | 181 | }; |
179 | 182 | ||
180 | /* | 183 | /* |
181 | * By default, read streaming is disabled. In theory, | ||
182 | * read streaming should enhance performance, but early | ||
183 | * U320 drive firmware actually performs slower with | ||
184 | * read streaming enabled. | ||
185 | */ | ||
186 | #ifdef CONFIG_AIC79XX_ENABLE_RD_STRM | ||
187 | #define AIC79XX_CONFIGED_RD_STRM 0xFFFF | ||
188 | #else | ||
189 | #define AIC79XX_CONFIGED_RD_STRM 0 | ||
190 | #endif | ||
191 | |||
192 | static uint16_t aic79xx_rd_strm_info[] = | ||
193 | { | ||
194 | AIC79XX_CONFIGED_RD_STRM, | ||
195 | AIC79XX_CONFIGED_RD_STRM, | ||
196 | AIC79XX_CONFIGED_RD_STRM, | ||
197 | AIC79XX_CONFIGED_RD_STRM, | ||
198 | AIC79XX_CONFIGED_RD_STRM, | ||
199 | AIC79XX_CONFIGED_RD_STRM, | ||
200 | AIC79XX_CONFIGED_RD_STRM, | ||
201 | AIC79XX_CONFIGED_RD_STRM, | ||
202 | AIC79XX_CONFIGED_RD_STRM, | ||
203 | AIC79XX_CONFIGED_RD_STRM, | ||
204 | AIC79XX_CONFIGED_RD_STRM, | ||
205 | AIC79XX_CONFIGED_RD_STRM, | ||
206 | AIC79XX_CONFIGED_RD_STRM, | ||
207 | AIC79XX_CONFIGED_RD_STRM, | ||
208 | AIC79XX_CONFIGED_RD_STRM, | ||
209 | AIC79XX_CONFIGED_RD_STRM | ||
210 | }; | ||
211 | |||
212 | /* | ||
213 | * DV option: | ||
214 | * | ||
215 | * positive value = DV Enabled | ||
216 | * zero = DV Disabled | ||
217 | * negative value = DV Default for adapter type/seeprom | ||
218 | */ | ||
219 | #ifdef CONFIG_AIC79XX_DV_SETTING | ||
220 | #define AIC79XX_CONFIGED_DV CONFIG_AIC79XX_DV_SETTING | ||
221 | #else | ||
222 | #define AIC79XX_CONFIGED_DV -1 | ||
223 | #endif | ||
224 | |||
225 | static int8_t aic79xx_dv_settings[] = | ||
226 | { | ||
227 | AIC79XX_CONFIGED_DV, | ||
228 | AIC79XX_CONFIGED_DV, | ||
229 | AIC79XX_CONFIGED_DV, | ||
230 | AIC79XX_CONFIGED_DV, | ||
231 | AIC79XX_CONFIGED_DV, | ||
232 | AIC79XX_CONFIGED_DV, | ||
233 | AIC79XX_CONFIGED_DV, | ||
234 | AIC79XX_CONFIGED_DV, | ||
235 | AIC79XX_CONFIGED_DV, | ||
236 | AIC79XX_CONFIGED_DV, | ||
237 | AIC79XX_CONFIGED_DV, | ||
238 | AIC79XX_CONFIGED_DV, | ||
239 | AIC79XX_CONFIGED_DV, | ||
240 | AIC79XX_CONFIGED_DV, | ||
241 | AIC79XX_CONFIGED_DV, | ||
242 | AIC79XX_CONFIGED_DV | ||
243 | }; | ||
244 | |||
245 | /* | ||
246 | * The I/O cell on the chip is very configurable in respect to its analog | 184 | * The I/O cell on the chip is very configurable in respect to its analog |
247 | * characteristics. Set the defaults here; they can be overriden with | 185 | * characteristics. Set the defaults here; they can be overriden with |
248 | * the proper insmod parameters. | 186 | * the proper insmod parameters. |
@@ -402,7 +340,7 @@ MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>"); | |||
402 | MODULE_DESCRIPTION("Adaptec Aic790X U320 SCSI Host Bus Adapter driver"); | 340 | MODULE_DESCRIPTION("Adaptec Aic790X U320 SCSI Host Bus Adapter driver"); |
403 | MODULE_LICENSE("Dual BSD/GPL"); | 341 | MODULE_LICENSE("Dual BSD/GPL"); |
404 | MODULE_VERSION(AIC79XX_DRIVER_VERSION); | 342 | MODULE_VERSION(AIC79XX_DRIVER_VERSION); |
405 | module_param(aic79xx, charp, 0); | 343 | module_param(aic79xx, charp, 0444); |
406 | MODULE_PARM_DESC(aic79xx, | 344 | MODULE_PARM_DESC(aic79xx, |
407 | "period delimited, options string.\n" | 345 | "period delimited, options string.\n" |
408 | " verbose Enable verbose/diagnostic logging\n" | 346 | " verbose Enable verbose/diagnostic logging\n" |
@@ -417,8 +355,6 @@ MODULE_PARM_DESC(aic79xx, | |||
417 | " reverse_scan Sort PCI devices highest Bus/Slot to lowest\n" | 355 | " reverse_scan Sort PCI devices highest Bus/Slot to lowest\n" |
418 | " tag_info:<tag_str> Set per-target tag depth\n" | 356 | " tag_info:<tag_str> Set per-target tag depth\n" |
419 | " global_tag_depth:<int> Global tag depth for all targets on all buses\n" | 357 | " global_tag_depth:<int> Global tag depth for all targets on all buses\n" |
420 | " rd_strm:<rd_strm_masks> Set per-target read streaming setting.\n" | ||
421 | " dv:<dv_settings> Set per-controller Domain Validation Setting.\n" | ||
422 | " slewrate:<slewrate_list>Set the signal slew rate (0-15).\n" | 358 | " slewrate:<slewrate_list>Set the signal slew rate (0-15).\n" |
423 | " precomp:<pcomp_list> Set the signal precompensation (0-7).\n" | 359 | " precomp:<pcomp_list> Set the signal precompensation (0-7).\n" |
424 | " amplitude:<int> Set the signal amplitude (0-7).\n" | 360 | " amplitude:<int> Set the signal amplitude (0-7).\n" |
@@ -431,178 +367,35 @@ MODULE_PARM_DESC(aic79xx, | |||
431 | " Shorten the selection timeout to 128ms\n" | 367 | " Shorten the selection timeout to 128ms\n" |
432 | "\n" | 368 | "\n" |
433 | " options aic79xx 'aic79xx=verbose.tag_info:{{}.{}.{..10}}.seltime:1'\n" | 369 | " options aic79xx 'aic79xx=verbose.tag_info:{{}.{}.{..10}}.seltime:1'\n" |
434 | "\n" | 370 | "\n"); |
435 | " Sample /etc/modprobe.conf line:\n" | ||
436 | " Change Read Streaming for Controller's 2 and 3\n" | ||
437 | "\n" | ||
438 | " options aic79xx 'aic79xx=rd_strm:{..0xFFF0.0xC0F0}'"); | ||
439 | 371 | ||
440 | static void ahd_linux_handle_scsi_status(struct ahd_softc *, | 372 | static void ahd_linux_handle_scsi_status(struct ahd_softc *, |
441 | struct ahd_linux_device *, | 373 | struct scsi_device *, |
442 | struct scb *); | 374 | struct scb *); |
443 | static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, | 375 | static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, |
444 | Scsi_Cmnd *cmd); | 376 | struct scsi_cmnd *cmd); |
445 | static void ahd_linux_filter_inquiry(struct ahd_softc *ahd, | ||
446 | struct ahd_devinfo *devinfo); | ||
447 | static void ahd_linux_dev_timed_unfreeze(u_long arg); | ||
448 | static void ahd_linux_sem_timeout(u_long arg); | 377 | static void ahd_linux_sem_timeout(u_long arg); |
378 | static int ahd_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag); | ||
449 | static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd); | 379 | static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd); |
450 | static void ahd_linux_thread_run_complete_queue(struct ahd_softc *ahd); | ||
451 | static void ahd_linux_start_dv(struct ahd_softc *ahd); | ||
452 | static void ahd_linux_dv_timeout(struct scsi_cmnd *cmd); | ||
453 | static int ahd_linux_dv_thread(void *data); | ||
454 | static void ahd_linux_kill_dv_thread(struct ahd_softc *ahd); | ||
455 | static void ahd_linux_dv_target(struct ahd_softc *ahd, u_int target); | ||
456 | static void ahd_linux_dv_transition(struct ahd_softc *ahd, | ||
457 | struct scsi_cmnd *cmd, | ||
458 | struct ahd_devinfo *devinfo, | ||
459 | struct ahd_linux_target *targ); | ||
460 | static void ahd_linux_dv_fill_cmd(struct ahd_softc *ahd, | ||
461 | struct scsi_cmnd *cmd, | ||
462 | struct ahd_devinfo *devinfo); | ||
463 | static void ahd_linux_dv_inq(struct ahd_softc *ahd, | ||
464 | struct scsi_cmnd *cmd, | ||
465 | struct ahd_devinfo *devinfo, | ||
466 | struct ahd_linux_target *targ, | ||
467 | u_int request_length); | ||
468 | static void ahd_linux_dv_tur(struct ahd_softc *ahd, | ||
469 | struct scsi_cmnd *cmd, | ||
470 | struct ahd_devinfo *devinfo); | ||
471 | static void ahd_linux_dv_rebd(struct ahd_softc *ahd, | ||
472 | struct scsi_cmnd *cmd, | ||
473 | struct ahd_devinfo *devinfo, | ||
474 | struct ahd_linux_target *targ); | ||
475 | static void ahd_linux_dv_web(struct ahd_softc *ahd, | ||
476 | struct scsi_cmnd *cmd, | ||
477 | struct ahd_devinfo *devinfo, | ||
478 | struct ahd_linux_target *targ); | ||
479 | static void ahd_linux_dv_reb(struct ahd_softc *ahd, | ||
480 | struct scsi_cmnd *cmd, | ||
481 | struct ahd_devinfo *devinfo, | ||
482 | struct ahd_linux_target *targ); | ||
483 | static void ahd_linux_dv_su(struct ahd_softc *ahd, | ||
484 | struct scsi_cmnd *cmd, | ||
485 | struct ahd_devinfo *devinfo, | ||
486 | struct ahd_linux_target *targ); | ||
487 | static int ahd_linux_fallback(struct ahd_softc *ahd, | ||
488 | struct ahd_devinfo *devinfo); | ||
489 | static __inline int ahd_linux_dv_fallback(struct ahd_softc *ahd, | ||
490 | struct ahd_devinfo *devinfo); | ||
491 | static void ahd_linux_dv_complete(Scsi_Cmnd *cmd); | ||
492 | static void ahd_linux_generate_dv_pattern(struct ahd_linux_target *targ); | ||
493 | static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd, | 380 | static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd, |
494 | struct ahd_devinfo *devinfo); | 381 | struct ahd_devinfo *devinfo); |
495 | static u_int ahd_linux_user_dv_setting(struct ahd_softc *ahd); | 382 | static void ahd_linux_device_queue_depth(struct scsi_device *); |
496 | static void ahd_linux_setup_user_rd_strm_settings(struct ahd_softc *ahd); | ||
497 | static void ahd_linux_device_queue_depth(struct ahd_softc *ahd, | ||
498 | struct ahd_linux_device *dev); | ||
499 | static struct ahd_linux_target* ahd_linux_alloc_target(struct ahd_softc*, | ||
500 | u_int, u_int); | ||
501 | static void ahd_linux_free_target(struct ahd_softc*, | ||
502 | struct ahd_linux_target*); | ||
503 | static struct ahd_linux_device* ahd_linux_alloc_device(struct ahd_softc*, | ||
504 | struct ahd_linux_target*, | ||
505 | u_int); | ||
506 | static void ahd_linux_free_device(struct ahd_softc*, | ||
507 | struct ahd_linux_device*); | ||
508 | static int ahd_linux_run_command(struct ahd_softc*, | 383 | static int ahd_linux_run_command(struct ahd_softc*, |
509 | struct ahd_linux_device*, | 384 | struct ahd_linux_device *, |
510 | struct scsi_cmnd *); | 385 | struct scsi_cmnd *); |
511 | static void ahd_linux_setup_tag_info_global(char *p); | 386 | static void ahd_linux_setup_tag_info_global(char *p); |
512 | static aic_option_callback_t ahd_linux_setup_tag_info; | 387 | static aic_option_callback_t ahd_linux_setup_tag_info; |
513 | static aic_option_callback_t ahd_linux_setup_rd_strm_info; | ||
514 | static aic_option_callback_t ahd_linux_setup_dv; | ||
515 | static aic_option_callback_t ahd_linux_setup_iocell_info; | 388 | static aic_option_callback_t ahd_linux_setup_iocell_info; |
516 | static int ahd_linux_next_unit(void); | 389 | static int aic79xx_setup(char *c); |
517 | static int aic79xx_setup(char *c); | 390 | static int ahd_linux_next_unit(void); |
518 | 391 | ||
519 | /****************************** Inlines ***************************************/ | 392 | /****************************** Inlines ***************************************/ |
520 | static __inline void ahd_schedule_completeq(struct ahd_softc *ahd); | ||
521 | static __inline struct ahd_linux_device* | ||
522 | ahd_linux_get_device(struct ahd_softc *ahd, u_int channel, | ||
523 | u_int target, u_int lun, int alloc); | ||
524 | static struct ahd_cmd *ahd_linux_run_complete_queue(struct ahd_softc *ahd); | ||
525 | static __inline void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*); | 393 | static __inline void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*); |
526 | 394 | ||
527 | static __inline void | 395 | static __inline void |
528 | ahd_schedule_completeq(struct ahd_softc *ahd) | ||
529 | { | ||
530 | if ((ahd->platform_data->flags & AHD_RUN_CMPLT_Q_TIMER) == 0) { | ||
531 | ahd->platform_data->flags |= AHD_RUN_CMPLT_Q_TIMER; | ||
532 | ahd->platform_data->completeq_timer.expires = jiffies; | ||
533 | add_timer(&ahd->platform_data->completeq_timer); | ||
534 | } | ||
535 | } | ||
536 | |||
537 | static __inline struct ahd_linux_device* | ||
538 | ahd_linux_get_device(struct ahd_softc *ahd, u_int channel, u_int target, | ||
539 | u_int lun, int alloc) | ||
540 | { | ||
541 | struct ahd_linux_target *targ; | ||
542 | struct ahd_linux_device *dev; | ||
543 | u_int target_offset; | ||
544 | |||
545 | target_offset = target; | ||
546 | if (channel != 0) | ||
547 | target_offset += 8; | ||
548 | targ = ahd->platform_data->targets[target_offset]; | ||
549 | if (targ == NULL) { | ||
550 | if (alloc != 0) { | ||
551 | targ = ahd_linux_alloc_target(ahd, channel, target); | ||
552 | if (targ == NULL) | ||
553 | return (NULL); | ||
554 | } else | ||
555 | return (NULL); | ||
556 | } | ||
557 | dev = targ->devices[lun]; | ||
558 | if (dev == NULL && alloc != 0) | ||
559 | dev = ahd_linux_alloc_device(ahd, targ, lun); | ||
560 | return (dev); | ||
561 | } | ||
562 | |||
563 | #define AHD_LINUX_MAX_RETURNED_ERRORS 4 | ||
564 | static struct ahd_cmd * | ||
565 | ahd_linux_run_complete_queue(struct ahd_softc *ahd) | ||
566 | { | ||
567 | struct ahd_cmd *acmd; | ||
568 | u_long done_flags; | ||
569 | int with_errors; | ||
570 | |||
571 | with_errors = 0; | ||
572 | ahd_done_lock(ahd, &done_flags); | ||
573 | while ((acmd = TAILQ_FIRST(&ahd->platform_data->completeq)) != NULL) { | ||
574 | Scsi_Cmnd *cmd; | ||
575 | |||
576 | if (with_errors > AHD_LINUX_MAX_RETURNED_ERRORS) { | ||
577 | /* | ||
578 | * Linux uses stack recursion to requeue | ||
579 | * commands that need to be retried. Avoid | ||
580 | * blowing out the stack by "spoon feeding" | ||
581 | * commands that completed with error back | ||
582 | * the operating system in case they are going | ||
583 | * to be retried. "ick" | ||
584 | */ | ||
585 | ahd_schedule_completeq(ahd); | ||
586 | break; | ||
587 | } | ||
588 | TAILQ_REMOVE(&ahd->platform_data->completeq, | ||
589 | acmd, acmd_links.tqe); | ||
590 | cmd = &acmd_scsi_cmd(acmd); | ||
591 | cmd->host_scribble = NULL; | ||
592 | if (ahd_cmd_get_transaction_status(cmd) != DID_OK | ||
593 | || (cmd->result & 0xFF) != SCSI_STATUS_OK) | ||
594 | with_errors++; | ||
595 | |||
596 | cmd->scsi_done(cmd); | ||
597 | } | ||
598 | ahd_done_unlock(ahd, &done_flags); | ||
599 | return (acmd); | ||
600 | } | ||
601 | |||
602 | static __inline void | ||
603 | ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb) | 396 | ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb) |
604 | { | 397 | { |
605 | Scsi_Cmnd *cmd; | 398 | struct scsi_cmnd *cmd; |
606 | int direction; | 399 | int direction; |
607 | 400 | ||
608 | cmd = scb->io_ctx; | 401 | cmd = scb->io_ctx; |
@@ -624,51 +417,21 @@ ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb) | |||
624 | #define BUILD_SCSIID(ahd, cmd) \ | 417 | #define BUILD_SCSIID(ahd, cmd) \ |
625 | ((((cmd)->device->id << TID_SHIFT) & TID) | (ahd)->our_id) | 418 | ((((cmd)->device->id << TID_SHIFT) & TID) | (ahd)->our_id) |
626 | 419 | ||
627 | /************************ Host template entry points *************************/ | ||
628 | static int ahd_linux_detect(Scsi_Host_Template *); | ||
629 | static const char *ahd_linux_info(struct Scsi_Host *); | ||
630 | static int ahd_linux_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *)); | ||
631 | static int ahd_linux_slave_alloc(Scsi_Device *); | ||
632 | static int ahd_linux_slave_configure(Scsi_Device *); | ||
633 | static void ahd_linux_slave_destroy(Scsi_Device *); | ||
634 | #if defined(__i386__) | ||
635 | static int ahd_linux_biosparam(struct scsi_device*, | ||
636 | struct block_device*, sector_t, int[]); | ||
637 | #endif | ||
638 | static int ahd_linux_bus_reset(Scsi_Cmnd *); | ||
639 | static int ahd_linux_dev_reset(Scsi_Cmnd *); | ||
640 | static int ahd_linux_abort(Scsi_Cmnd *); | ||
641 | |||
642 | |||
643 | /* | 420 | /* |
644 | * Try to detect an Adaptec 79XX controller. | 421 | * Try to detect an Adaptec 79XX controller. |
645 | */ | 422 | */ |
646 | static int | 423 | static int |
647 | ahd_linux_detect(Scsi_Host_Template *template) | 424 | ahd_linux_detect(struct scsi_host_template *template) |
648 | { | 425 | { |
649 | struct ahd_softc *ahd; | 426 | struct ahd_softc *ahd; |
650 | int found; | 427 | int found; |
651 | int error = 0; | 428 | int error = 0; |
652 | 429 | ||
653 | /* | 430 | /* |
654 | * Sanity checking of Linux SCSI data structures so | ||
655 | * that some of our hacks^H^H^H^H^Hassumptions aren't | ||
656 | * violated. | ||
657 | */ | ||
658 | if (offsetof(struct ahd_cmd_internal, end) | ||
659 | > offsetof(struct scsi_cmnd, host_scribble)) { | ||
660 | printf("ahd_linux_detect: SCSI data structures changed.\n"); | ||
661 | printf("ahd_linux_detect: Unable to attach\n"); | ||
662 | return (0); | ||
663 | } | ||
664 | |||
665 | #ifdef MODULE | ||
666 | /* | ||
667 | * If we've been passed any parameters, process them now. | 431 | * If we've been passed any parameters, process them now. |
668 | */ | 432 | */ |
669 | if (aic79xx) | 433 | if (aic79xx) |
670 | aic79xx_setup(aic79xx); | 434 | aic79xx_setup(aic79xx); |
671 | #endif | ||
672 | 435 | ||
673 | template->proc_name = "aic79xx"; | 436 | template->proc_name = "aic79xx"; |
674 | 437 | ||
@@ -695,7 +458,7 @@ ahd_linux_detect(Scsi_Host_Template *template) | |||
695 | found++; | 458 | found++; |
696 | } | 459 | } |
697 | aic79xx_detect_complete++; | 460 | aic79xx_detect_complete++; |
698 | return 0; | 461 | return found; |
699 | } | 462 | } |
700 | 463 | ||
701 | /* | 464 | /* |
@@ -730,10 +493,10 @@ ahd_linux_info(struct Scsi_Host *host) | |||
730 | * Queue an SCB to the controller. | 493 | * Queue an SCB to the controller. |
731 | */ | 494 | */ |
732 | static int | 495 | static int |
733 | ahd_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *)) | 496 | ahd_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *)) |
734 | { | 497 | { |
735 | struct ahd_softc *ahd; | 498 | struct ahd_softc *ahd; |
736 | struct ahd_linux_device *dev; | 499 | struct ahd_linux_device *dev = scsi_transport_device_data(cmd->device); |
737 | 500 | ||
738 | ahd = *(struct ahd_softc **)cmd->device->host->hostdata; | 501 | ahd = *(struct ahd_softc **)cmd->device->host->hostdata; |
739 | 502 | ||
@@ -743,8 +506,7 @@ ahd_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *)) | |||
743 | * DV commands through so long as we are only frozen to | 506 | * DV commands through so long as we are only frozen to |
744 | * perform DV. | 507 | * perform DV. |
745 | */ | 508 | */ |
746 | if (ahd->platform_data->qfrozen != 0 | 509 | if (ahd->platform_data->qfrozen != 0) { |
747 | && AHD_DV_CMD(cmd) == 0) { | ||
748 | printf("%s: queue frozen\n", ahd_name(ahd)); | 510 | printf("%s: queue frozen\n", ahd_name(ahd)); |
749 | 511 | ||
750 | return SCSI_MLQUEUE_HOST_BUSY; | 512 | return SCSI_MLQUEUE_HOST_BUSY; |
@@ -755,86 +517,142 @@ ahd_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *)) | |||
755 | */ | 517 | */ |
756 | cmd->scsi_done = scsi_done; | 518 | cmd->scsi_done = scsi_done; |
757 | 519 | ||
758 | dev = ahd_linux_get_device(ahd, cmd->device->channel, | ||
759 | cmd->device->id, cmd->device->lun, | ||
760 | /*alloc*/TRUE); | ||
761 | BUG_ON(dev == NULL); | ||
762 | |||
763 | cmd->result = CAM_REQ_INPROG << 16; | 520 | cmd->result = CAM_REQ_INPROG << 16; |
764 | 521 | ||
765 | return ahd_linux_run_command(ahd, dev, cmd); | 522 | return ahd_linux_run_command(ahd, dev, cmd); |
766 | } | 523 | } |
767 | 524 | ||
525 | static inline struct scsi_target ** | ||
526 | ahd_linux_target_in_softc(struct scsi_target *starget) | ||
527 | { | ||
528 | struct ahd_softc *ahd = | ||
529 | *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata); | ||
530 | unsigned int target_offset; | ||
531 | |||
532 | target_offset = starget->id; | ||
533 | if (starget->channel != 0) | ||
534 | target_offset += 8; | ||
535 | |||
536 | return &ahd->platform_data->starget[target_offset]; | ||
537 | } | ||
538 | |||
768 | static int | 539 | static int |
769 | ahd_linux_slave_alloc(Scsi_Device *device) | 540 | ahd_linux_target_alloc(struct scsi_target *starget) |
770 | { | 541 | { |
771 | struct ahd_softc *ahd; | 542 | struct ahd_softc *ahd = |
543 | *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata); | ||
544 | unsigned long flags; | ||
545 | struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget); | ||
546 | struct ahd_linux_target *targ = scsi_transport_target_data(starget); | ||
547 | struct ahd_devinfo devinfo; | ||
548 | struct ahd_initiator_tinfo *tinfo; | ||
549 | struct ahd_tmode_tstate *tstate; | ||
550 | char channel = starget->channel + 'A'; | ||
772 | 551 | ||
773 | ahd = *((struct ahd_softc **)device->host->hostdata); | 552 | ahd_lock(ahd, &flags); |
774 | if (bootverbose) | 553 | |
775 | printf("%s: Slave Alloc %d\n", ahd_name(ahd), device->id); | 554 | BUG_ON(*ahd_targp != NULL); |
776 | return (0); | 555 | |
556 | *ahd_targp = starget; | ||
557 | memset(targ, 0, sizeof(*targ)); | ||
558 | |||
559 | tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id, | ||
560 | starget->id, &tstate); | ||
561 | ahd_compile_devinfo(&devinfo, ahd->our_id, starget->id, | ||
562 | CAM_LUN_WILDCARD, channel, | ||
563 | ROLE_INITIATOR); | ||
564 | spi_min_period(starget) = AHD_SYNCRATE_MAX; /* We can do U320 */ | ||
565 | if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) | ||
566 | spi_max_offset(starget) = MAX_OFFSET_PACED_BUG; | ||
567 | else | ||
568 | spi_max_offset(starget) = MAX_OFFSET_PACED; | ||
569 | spi_max_width(starget) = ahd->features & AHD_WIDE; | ||
570 | |||
571 | ahd_set_syncrate(ahd, &devinfo, 0, 0, 0, | ||
572 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
573 | ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT, | ||
574 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
575 | ahd_unlock(ahd, &flags); | ||
576 | |||
577 | return 0; | ||
578 | } | ||
579 | |||
580 | static void | ||
581 | ahd_linux_target_destroy(struct scsi_target *starget) | ||
582 | { | ||
583 | struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget); | ||
584 | |||
585 | *ahd_targp = NULL; | ||
777 | } | 586 | } |
778 | 587 | ||
779 | static int | 588 | static int |
780 | ahd_linux_slave_configure(Scsi_Device *device) | 589 | ahd_linux_slave_alloc(struct scsi_device *sdev) |
781 | { | 590 | { |
782 | struct ahd_softc *ahd; | 591 | struct ahd_softc *ahd = |
783 | struct ahd_linux_device *dev; | 592 | *((struct ahd_softc **)sdev->host->hostdata); |
784 | u_long flags; | 593 | struct scsi_target *starget = sdev->sdev_target; |
594 | struct ahd_linux_target *targ = scsi_transport_target_data(starget); | ||
595 | struct ahd_linux_device *dev; | ||
785 | 596 | ||
786 | ahd = *((struct ahd_softc **)device->host->hostdata); | ||
787 | if (bootverbose) | 597 | if (bootverbose) |
788 | printf("%s: Slave Configure %d\n", ahd_name(ahd), device->id); | 598 | printf("%s: Slave Alloc %d\n", ahd_name(ahd), sdev->id); |
789 | ahd_midlayer_entrypoint_lock(ahd, &flags); | 599 | |
600 | BUG_ON(targ->sdev[sdev->lun] != NULL); | ||
601 | |||
602 | dev = scsi_transport_device_data(sdev); | ||
603 | memset(dev, 0, sizeof(*dev)); | ||
604 | |||
790 | /* | 605 | /* |
791 | * Since Linux has attached to the device, configure | 606 | * We start out life using untagged |
792 | * it so we don't free and allocate the device | 607 | * transactions of which we allow one. |
793 | * structure on every command. | ||
794 | */ | 608 | */ |
795 | dev = ahd_linux_get_device(ahd, device->channel, | 609 | dev->openings = 1; |
796 | device->id, device->lun, | 610 | |
797 | /*alloc*/TRUE); | 611 | /* |
798 | if (dev != NULL) { | 612 | * Set maxtags to 0. This will be changed if we |
799 | dev->flags &= ~AHD_DEV_UNCONFIGURED; | 613 | * later determine that we are dealing with |
800 | dev->flags |= AHD_DEV_SLAVE_CONFIGURED; | 614 | * a tagged queuing capable device. |
801 | dev->scsi_device = device; | 615 | */ |
802 | ahd_linux_device_queue_depth(ahd, dev); | 616 | dev->maxtags = 0; |
803 | } | 617 | |
804 | ahd_midlayer_entrypoint_unlock(ahd, &flags); | 618 | targ->sdev[sdev->lun] = sdev; |
619 | |||
805 | return (0); | 620 | return (0); |
806 | } | 621 | } |
807 | 622 | ||
623 | static int | ||
624 | ahd_linux_slave_configure(struct scsi_device *sdev) | ||
625 | { | ||
626 | struct ahd_softc *ahd; | ||
627 | |||
628 | ahd = *((struct ahd_softc **)sdev->host->hostdata); | ||
629 | if (bootverbose) | ||
630 | printf("%s: Slave Configure %d\n", ahd_name(ahd), sdev->id); | ||
631 | |||
632 | ahd_linux_device_queue_depth(sdev); | ||
633 | |||
634 | /* Initial Domain Validation */ | ||
635 | if (!spi_initial_dv(sdev->sdev_target)) | ||
636 | spi_dv_device(sdev); | ||
637 | |||
638 | return 0; | ||
639 | } | ||
640 | |||
808 | static void | 641 | static void |
809 | ahd_linux_slave_destroy(Scsi_Device *device) | 642 | ahd_linux_slave_destroy(struct scsi_device *sdev) |
810 | { | 643 | { |
811 | struct ahd_softc *ahd; | 644 | struct ahd_softc *ahd; |
812 | struct ahd_linux_device *dev; | 645 | struct ahd_linux_device *dev = scsi_transport_device_data(sdev); |
813 | u_long flags; | 646 | struct ahd_linux_target *targ = scsi_transport_target_data(sdev->sdev_target); |
814 | 647 | ||
815 | ahd = *((struct ahd_softc **)device->host->hostdata); | 648 | ahd = *((struct ahd_softc **)sdev->host->hostdata); |
816 | if (bootverbose) | 649 | if (bootverbose) |
817 | printf("%s: Slave Destroy %d\n", ahd_name(ahd), device->id); | 650 | printf("%s: Slave Destroy %d\n", ahd_name(ahd), sdev->id); |
818 | ahd_midlayer_entrypoint_lock(ahd, &flags); | 651 | |
819 | dev = ahd_linux_get_device(ahd, device->channel, | 652 | BUG_ON(dev->active); |
820 | device->id, device->lun, | 653 | |
821 | /*alloc*/FALSE); | 654 | targ->sdev[sdev->lun] = NULL; |
822 | 655 | ||
823 | /* | ||
824 | * Filter out "silly" deletions of real devices by only | ||
825 | * deleting devices that have had slave_configure() | ||
826 | * called on them. All other devices that have not | ||
827 | * been configured will automatically be deleted by | ||
828 | * the refcounting process. | ||
829 | */ | ||
830 | if (dev != NULL | ||
831 | && (dev->flags & AHD_DEV_SLAVE_CONFIGURED) != 0) { | ||
832 | dev->flags |= AHD_DEV_UNCONFIGURED; | ||
833 | if (dev->active == 0 | ||
834 | && (dev->flags & AHD_DEV_TIMER_ACTIVE) == 0) | ||
835 | ahd_linux_free_device(ahd, dev); | ||
836 | } | ||
837 | ahd_midlayer_entrypoint_unlock(ahd, &flags); | ||
838 | } | 656 | } |
839 | 657 | ||
840 | #if defined(__i386__) | 658 | #if defined(__i386__) |
@@ -887,373 +705,35 @@ ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev, | |||
887 | * Abort the current SCSI command(s). | 705 | * Abort the current SCSI command(s). |
888 | */ | 706 | */ |
889 | static int | 707 | static int |
890 | ahd_linux_abort(Scsi_Cmnd *cmd) | 708 | ahd_linux_abort(struct scsi_cmnd *cmd) |
891 | { | 709 | { |
892 | struct ahd_softc *ahd; | 710 | int error; |
893 | struct ahd_cmd *acmd; | ||
894 | struct ahd_linux_device *dev; | ||
895 | struct scb *pending_scb; | ||
896 | u_long s; | ||
897 | u_int saved_scbptr; | ||
898 | u_int active_scbptr; | ||
899 | u_int last_phase; | ||
900 | u_int cdb_byte; | ||
901 | int retval; | ||
902 | int was_paused; | ||
903 | int paused; | ||
904 | int wait; | ||
905 | int disconnected; | ||
906 | ahd_mode_state saved_modes; | ||
907 | |||
908 | pending_scb = NULL; | ||
909 | paused = FALSE; | ||
910 | wait = FALSE; | ||
911 | ahd = *(struct ahd_softc **)cmd->device->host->hostdata; | ||
912 | acmd = (struct ahd_cmd *)cmd; | ||
913 | |||
914 | printf("%s:%d:%d:%d: Attempting to abort cmd %p:", | ||
915 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
916 | cmd->device->lun, cmd); | ||
917 | for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++) | ||
918 | printf(" 0x%x", cmd->cmnd[cdb_byte]); | ||
919 | printf("\n"); | ||
920 | |||
921 | /* | ||
922 | * In all versions of Linux, we have to work around | ||
923 | * a major flaw in how the mid-layer is locked down | ||
924 | * if we are to sleep successfully in our error handler | ||
925 | * while allowing our interrupt handler to run. Since | ||
926 | * the midlayer acquires either the io_request_lock or | ||
927 | * our lock prior to calling us, we must use the | ||
928 | * spin_unlock_irq() method for unlocking our lock. | ||
929 | * This will force interrupts to be enabled on the | ||
930 | * current CPU. Since the EH thread should not have | ||
931 | * been running with CPU interrupts disabled other than | ||
932 | * by acquiring either the io_request_lock or our own | ||
933 | * lock, this *should* be safe. | ||
934 | */ | ||
935 | ahd_midlayer_entrypoint_lock(ahd, &s); | ||
936 | |||
937 | /* | ||
938 | * First determine if we currently own this command. | ||
939 | * Start by searching the device queue. If not found | ||
940 | * there, check the pending_scb list. If not found | ||
941 | * at all, and the system wanted us to just abort the | ||
942 | * command, return success. | ||
943 | */ | ||
944 | dev = ahd_linux_get_device(ahd, cmd->device->channel, | ||
945 | cmd->device->id, cmd->device->lun, | ||
946 | /*alloc*/FALSE); | ||
947 | |||
948 | if (dev == NULL) { | ||
949 | /* | ||
950 | * No target device for this command exists, | ||
951 | * so we must not still own the command. | ||
952 | */ | ||
953 | printf("%s:%d:%d:%d: Is not an active device\n", | ||
954 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
955 | cmd->device->lun); | ||
956 | retval = SUCCESS; | ||
957 | goto no_cmd; | ||
958 | } | ||
959 | |||
960 | /* | ||
961 | * See if we can find a matching cmd in the pending list. | ||
962 | */ | ||
963 | LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) { | ||
964 | if (pending_scb->io_ctx == cmd) | ||
965 | break; | ||
966 | } | ||
967 | |||
968 | if (pending_scb == NULL) { | ||
969 | printf("%s:%d:%d:%d: Command not found\n", | ||
970 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
971 | cmd->device->lun); | ||
972 | goto no_cmd; | ||
973 | } | ||
974 | |||
975 | if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) { | ||
976 | /* | ||
977 | * We can't queue two recovery actions using the same SCB | ||
978 | */ | ||
979 | retval = FAILED; | ||
980 | goto done; | ||
981 | } | ||
982 | |||
983 | /* | ||
984 | * Ensure that the card doesn't do anything | ||
985 | * behind our back. Also make sure that we | ||
986 | * didn't "just" miss an interrupt that would | ||
987 | * affect this cmd. | ||
988 | */ | ||
989 | was_paused = ahd_is_paused(ahd); | ||
990 | ahd_pause_and_flushwork(ahd); | ||
991 | paused = TRUE; | ||
992 | |||
993 | if ((pending_scb->flags & SCB_ACTIVE) == 0) { | ||
994 | printf("%s:%d:%d:%d: Command already completed\n", | ||
995 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
996 | cmd->device->lun); | ||
997 | goto no_cmd; | ||
998 | } | ||
999 | |||
1000 | printf("%s: At time of recovery, card was %spaused\n", | ||
1001 | ahd_name(ahd), was_paused ? "" : "not "); | ||
1002 | ahd_dump_card_state(ahd); | ||
1003 | |||
1004 | disconnected = TRUE; | ||
1005 | if (ahd_search_qinfifo(ahd, cmd->device->id, cmd->device->channel + 'A', | ||
1006 | cmd->device->lun, SCB_GET_TAG(pending_scb), | ||
1007 | ROLE_INITIATOR, CAM_REQ_ABORTED, | ||
1008 | SEARCH_COMPLETE) > 0) { | ||
1009 | printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n", | ||
1010 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
1011 | cmd->device->lun); | ||
1012 | retval = SUCCESS; | ||
1013 | goto done; | ||
1014 | } | ||
1015 | |||
1016 | saved_modes = ahd_save_modes(ahd); | ||
1017 | ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI); | ||
1018 | last_phase = ahd_inb(ahd, LASTPHASE); | ||
1019 | saved_scbptr = ahd_get_scbptr(ahd); | ||
1020 | active_scbptr = saved_scbptr; | ||
1021 | if (disconnected && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) { | ||
1022 | struct scb *bus_scb; | ||
1023 | |||
1024 | bus_scb = ahd_lookup_scb(ahd, active_scbptr); | ||
1025 | if (bus_scb == pending_scb) | ||
1026 | disconnected = FALSE; | ||
1027 | } | ||
1028 | |||
1029 | /* | ||
1030 | * At this point, pending_scb is the scb associated with the | ||
1031 | * passed in command. That command is currently active on the | ||
1032 | * bus or is in the disconnected state. | ||
1033 | */ | ||
1034 | if (last_phase != P_BUSFREE | ||
1035 | && SCB_GET_TAG(pending_scb) == active_scbptr) { | ||
1036 | |||
1037 | /* | ||
1038 | * We're active on the bus, so assert ATN | ||
1039 | * and hope that the target responds. | ||
1040 | */ | ||
1041 | pending_scb = ahd_lookup_scb(ahd, active_scbptr); | ||
1042 | pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT; | ||
1043 | ahd_outb(ahd, MSG_OUT, HOST_MSG); | ||
1044 | ahd_outb(ahd, SCSISIGO, last_phase|ATNO); | ||
1045 | printf("%s:%d:%d:%d: Device is active, asserting ATN\n", | ||
1046 | ahd_name(ahd), cmd->device->channel, | ||
1047 | cmd->device->id, cmd->device->lun); | ||
1048 | wait = TRUE; | ||
1049 | } else if (disconnected) { | ||
1050 | |||
1051 | /* | ||
1052 | * Actually re-queue this SCB in an attempt | ||
1053 | * to select the device before it reconnects. | ||
1054 | */ | ||
1055 | pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT; | ||
1056 | ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb)); | ||
1057 | pending_scb->hscb->cdb_len = 0; | ||
1058 | pending_scb->hscb->task_attribute = 0; | ||
1059 | pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK; | ||
1060 | |||
1061 | if ((pending_scb->flags & SCB_PACKETIZED) != 0) { | ||
1062 | /* | ||
1063 | * Mark the SCB has having an outstanding | ||
1064 | * task management function. Should the command | ||
1065 | * complete normally before the task management | ||
1066 | * function can be sent, the host will be notified | ||
1067 | * to abort our requeued SCB. | ||
1068 | */ | ||
1069 | ahd_outb(ahd, SCB_TASK_MANAGEMENT, | ||
1070 | pending_scb->hscb->task_management); | ||
1071 | } else { | ||
1072 | /* | ||
1073 | * If non-packetized, set the MK_MESSAGE control | ||
1074 | * bit indicating that we desire to send a message. | ||
1075 | * We also set the disconnected flag since there is | ||
1076 | * no guarantee that our SCB control byte matches | ||
1077 | * the version on the card. We don't want the | ||
1078 | * sequencer to abort the command thinking an | ||
1079 | * unsolicited reselection occurred. | ||
1080 | */ | ||
1081 | pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED; | ||
1082 | |||
1083 | /* | ||
1084 | * The sequencer will never re-reference the | ||
1085 | * in-core SCB. To make sure we are notified | ||
1086 | * during reslection, set the MK_MESSAGE flag in | ||
1087 | * the card's copy of the SCB. | ||
1088 | */ | ||
1089 | ahd_outb(ahd, SCB_CONTROL, | ||
1090 | ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE); | ||
1091 | } | ||
1092 | |||
1093 | /* | ||
1094 | * Clear out any entries in the QINFIFO first | ||
1095 | * so we are the next SCB for this target | ||
1096 | * to run. | ||
1097 | */ | ||
1098 | ahd_search_qinfifo(ahd, cmd->device->id, | ||
1099 | cmd->device->channel + 'A', cmd->device->lun, | ||
1100 | SCB_LIST_NULL, ROLE_INITIATOR, | ||
1101 | CAM_REQUEUE_REQ, SEARCH_COMPLETE); | ||
1102 | ahd_qinfifo_requeue_tail(ahd, pending_scb); | ||
1103 | ahd_set_scbptr(ahd, saved_scbptr); | ||
1104 | ahd_print_path(ahd, pending_scb); | ||
1105 | printf("Device is disconnected, re-queuing SCB\n"); | ||
1106 | wait = TRUE; | ||
1107 | } else { | ||
1108 | printf("%s:%d:%d:%d: Unable to deliver message\n", | ||
1109 | ahd_name(ahd), cmd->device->channel, | ||
1110 | cmd->device->id, cmd->device->lun); | ||
1111 | retval = FAILED; | ||
1112 | goto done; | ||
1113 | } | ||
1114 | |||
1115 | no_cmd: | ||
1116 | /* | ||
1117 | * Our assumption is that if we don't have the command, no | ||
1118 | * recovery action was required, so we return success. Again, | ||
1119 | * the semantics of the mid-layer recovery engine are not | ||
1120 | * well defined, so this may change in time. | ||
1121 | */ | ||
1122 | retval = SUCCESS; | ||
1123 | done: | ||
1124 | if (paused) | ||
1125 | ahd_unpause(ahd); | ||
1126 | if (wait) { | ||
1127 | struct timer_list timer; | ||
1128 | int ret; | ||
1129 | |||
1130 | pending_scb->platform_data->flags |= AHD_SCB_UP_EH_SEM; | ||
1131 | spin_unlock_irq(&ahd->platform_data->spin_lock); | ||
1132 | init_timer(&timer); | ||
1133 | timer.data = (u_long)pending_scb; | ||
1134 | timer.expires = jiffies + (5 * HZ); | ||
1135 | timer.function = ahd_linux_sem_timeout; | ||
1136 | add_timer(&timer); | ||
1137 | printf("Recovery code sleeping\n"); | ||
1138 | down(&ahd->platform_data->eh_sem); | ||
1139 | printf("Recovery code awake\n"); | ||
1140 | ret = del_timer_sync(&timer); | ||
1141 | if (ret == 0) { | ||
1142 | printf("Timer Expired\n"); | ||
1143 | retval = FAILED; | ||
1144 | } | ||
1145 | spin_lock_irq(&ahd->platform_data->spin_lock); | ||
1146 | } | ||
1147 | ahd_linux_run_complete_queue(ahd); | ||
1148 | ahd_midlayer_entrypoint_unlock(ahd, &s); | ||
1149 | return (retval); | ||
1150 | } | ||
1151 | 711 | ||
1152 | 712 | error = ahd_linux_queue_recovery_cmd(cmd, SCB_ABORT); | |
1153 | static void | 713 | if (error != 0) |
1154 | ahd_linux_dev_reset_complete(Scsi_Cmnd *cmd) | 714 | printf("aic79xx_abort returns 0x%x\n", error); |
1155 | { | 715 | return error; |
1156 | free(cmd, M_DEVBUF); | ||
1157 | } | 716 | } |
1158 | 717 | ||
1159 | /* | 718 | /* |
1160 | * Attempt to send a target reset message to the device that timed out. | 719 | * Attempt to send a target reset message to the device that timed out. |
1161 | */ | 720 | */ |
1162 | static int | 721 | static int |
1163 | ahd_linux_dev_reset(Scsi_Cmnd *cmd) | 722 | ahd_linux_dev_reset(struct scsi_cmnd *cmd) |
1164 | { | 723 | { |
1165 | struct ahd_softc *ahd; | 724 | int error; |
1166 | struct scsi_cmnd *recovery_cmd; | ||
1167 | struct ahd_linux_device *dev; | ||
1168 | struct ahd_initiator_tinfo *tinfo; | ||
1169 | struct ahd_tmode_tstate *tstate; | ||
1170 | struct scb *scb; | ||
1171 | struct hardware_scb *hscb; | ||
1172 | u_long s; | ||
1173 | struct timer_list timer; | ||
1174 | int retval; | ||
1175 | |||
1176 | ahd = *(struct ahd_softc **)cmd->device->host->hostdata; | ||
1177 | recovery_cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK); | ||
1178 | if (!recovery_cmd) | ||
1179 | return (FAILED); | ||
1180 | memset(recovery_cmd, 0, sizeof(struct scsi_cmnd)); | ||
1181 | recovery_cmd->device = cmd->device; | ||
1182 | recovery_cmd->scsi_done = ahd_linux_dev_reset_complete; | ||
1183 | #ifdef AHD_DEBUG | ||
1184 | if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) | ||
1185 | printf("%s:%d:%d:%d: Device reset called for cmd %p\n", | ||
1186 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
1187 | cmd->device->lun, cmd); | ||
1188 | #endif | ||
1189 | ahd_lock(ahd, &s); | ||
1190 | 725 | ||
1191 | dev = ahd_linux_get_device(ahd, cmd->device->channel, cmd->device->id, | 726 | error = ahd_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET); |
1192 | cmd->device->lun, /*alloc*/FALSE); | 727 | if (error != 0) |
1193 | if (dev == NULL) { | 728 | printf("aic79xx_dev_reset returns 0x%x\n", error); |
1194 | ahd_unlock(ahd, &s); | 729 | return error; |
1195 | kfree(recovery_cmd); | ||
1196 | return (FAILED); | ||
1197 | } | ||
1198 | if ((scb = ahd_get_scb(ahd, AHD_NEVER_COL_IDX)) == NULL) { | ||
1199 | ahd_unlock(ahd, &s); | ||
1200 | kfree(recovery_cmd); | ||
1201 | return (FAILED); | ||
1202 | } | ||
1203 | tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id, | ||
1204 | cmd->device->id, &tstate); | ||
1205 | recovery_cmd->result = CAM_REQ_INPROG << 16; | ||
1206 | recovery_cmd->host_scribble = (char *)scb; | ||
1207 | scb->io_ctx = recovery_cmd; | ||
1208 | scb->platform_data->dev = dev; | ||
1209 | scb->sg_count = 0; | ||
1210 | ahd_set_residual(scb, 0); | ||
1211 | ahd_set_sense_residual(scb, 0); | ||
1212 | hscb = scb->hscb; | ||
1213 | hscb->control = 0; | ||
1214 | hscb->scsiid = BUILD_SCSIID(ahd, cmd); | ||
1215 | hscb->lun = cmd->device->lun; | ||
1216 | hscb->cdb_len = 0; | ||
1217 | hscb->task_management = SIU_TASKMGMT_LUN_RESET; | ||
1218 | scb->flags |= SCB_DEVICE_RESET|SCB_RECOVERY_SCB|SCB_ACTIVE; | ||
1219 | if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) { | ||
1220 | scb->flags |= SCB_PACKETIZED; | ||
1221 | } else { | ||
1222 | hscb->control |= MK_MESSAGE; | ||
1223 | } | ||
1224 | dev->openings--; | ||
1225 | dev->active++; | ||
1226 | dev->commands_issued++; | ||
1227 | LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links); | ||
1228 | ahd_queue_scb(ahd, scb); | ||
1229 | |||
1230 | scb->platform_data->flags |= AHD_SCB_UP_EH_SEM; | ||
1231 | ahd_unlock(ahd, &s); | ||
1232 | init_timer(&timer); | ||
1233 | timer.data = (u_long)scb; | ||
1234 | timer.expires = jiffies + (5 * HZ); | ||
1235 | timer.function = ahd_linux_sem_timeout; | ||
1236 | add_timer(&timer); | ||
1237 | printf("Recovery code sleeping\n"); | ||
1238 | down(&ahd->platform_data->eh_sem); | ||
1239 | printf("Recovery code awake\n"); | ||
1240 | retval = SUCCESS; | ||
1241 | if (del_timer_sync(&timer) == 0) { | ||
1242 | printf("Timer Expired\n"); | ||
1243 | retval = FAILED; | ||
1244 | } | ||
1245 | ahd_lock(ahd, &s); | ||
1246 | ahd_linux_run_complete_queue(ahd); | ||
1247 | ahd_unlock(ahd, &s); | ||
1248 | printf("%s: Device reset returning 0x%x\n", ahd_name(ahd), retval); | ||
1249 | return (retval); | ||
1250 | } | 730 | } |
1251 | 731 | ||
1252 | /* | 732 | /* |
1253 | * Reset the SCSI bus. | 733 | * Reset the SCSI bus. |
1254 | */ | 734 | */ |
1255 | static int | 735 | static int |
1256 | ahd_linux_bus_reset(Scsi_Cmnd *cmd) | 736 | ahd_linux_bus_reset(struct scsi_cmnd *cmd) |
1257 | { | 737 | { |
1258 | struct ahd_softc *ahd; | 738 | struct ahd_softc *ahd; |
1259 | u_long s; | 739 | u_long s; |
@@ -1268,7 +748,6 @@ ahd_linux_bus_reset(Scsi_Cmnd *cmd) | |||
1268 | ahd_lock(ahd, &s); | 748 | ahd_lock(ahd, &s); |
1269 | found = ahd_reset_channel(ahd, cmd->device->channel + 'A', | 749 | found = ahd_reset_channel(ahd, cmd->device->channel + 'A', |
1270 | /*initiate reset*/TRUE); | 750 | /*initiate reset*/TRUE); |
1271 | ahd_linux_run_complete_queue(ahd); | ||
1272 | ahd_unlock(ahd, &s); | 751 | ahd_unlock(ahd, &s); |
1273 | 752 | ||
1274 | if (bootverbose) | 753 | if (bootverbose) |
@@ -1278,7 +757,7 @@ ahd_linux_bus_reset(Scsi_Cmnd *cmd) | |||
1278 | return (SUCCESS); | 757 | return (SUCCESS); |
1279 | } | 758 | } |
1280 | 759 | ||
1281 | Scsi_Host_Template aic79xx_driver_template = { | 760 | struct scsi_host_template aic79xx_driver_template = { |
1282 | .module = THIS_MODULE, | 761 | .module = THIS_MODULE, |
1283 | .name = "aic79xx", | 762 | .name = "aic79xx", |
1284 | .proc_info = ahd_linux_proc_info, | 763 | .proc_info = ahd_linux_proc_info, |
@@ -1297,6 +776,8 @@ Scsi_Host_Template aic79xx_driver_template = { | |||
1297 | .slave_alloc = ahd_linux_slave_alloc, | 776 | .slave_alloc = ahd_linux_slave_alloc, |
1298 | .slave_configure = ahd_linux_slave_configure, | 777 | .slave_configure = ahd_linux_slave_configure, |
1299 | .slave_destroy = ahd_linux_slave_destroy, | 778 | .slave_destroy = ahd_linux_slave_destroy, |
779 | .target_alloc = ahd_linux_target_alloc, | ||
780 | .target_destroy = ahd_linux_target_destroy, | ||
1300 | }; | 781 | }; |
1301 | 782 | ||
1302 | /******************************** Bus DMA *************************************/ | 783 | /******************************** Bus DMA *************************************/ |
@@ -1338,36 +819,10 @@ int | |||
1338 | ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr, | 819 | ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr, |
1339 | int flags, bus_dmamap_t *mapp) | 820 | int flags, bus_dmamap_t *mapp) |
1340 | { | 821 | { |
1341 | bus_dmamap_t map; | ||
1342 | |||
1343 | map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT); | ||
1344 | if (map == NULL) | ||
1345 | return (ENOMEM); | ||
1346 | /* | ||
1347 | * Although we can dma data above 4GB, our | ||
1348 | * "consistent" memory is below 4GB for | ||
1349 | * space efficiency reasons (only need a 4byte | ||
1350 | * address). For this reason, we have to reset | ||
1351 | * our dma mask when doing allocations. | ||
1352 | */ | ||
1353 | if (ahd->dev_softc != NULL) | ||
1354 | if (pci_set_dma_mask(ahd->dev_softc, 0xFFFFFFFF)) { | ||
1355 | printk(KERN_WARNING "aic79xx: No suitable DMA available.\n"); | ||
1356 | kfree(map); | ||
1357 | return (ENODEV); | ||
1358 | } | ||
1359 | *vaddr = pci_alloc_consistent(ahd->dev_softc, | 822 | *vaddr = pci_alloc_consistent(ahd->dev_softc, |
1360 | dmat->maxsize, &map->bus_addr); | 823 | dmat->maxsize, mapp); |
1361 | if (ahd->dev_softc != NULL) | ||
1362 | if (pci_set_dma_mask(ahd->dev_softc, | ||
1363 | ahd->platform_data->hw_dma_mask)) { | ||
1364 | printk(KERN_WARNING "aic79xx: No suitable DMA available.\n"); | ||
1365 | kfree(map); | ||
1366 | return (ENODEV); | ||
1367 | } | ||
1368 | if (*vaddr == NULL) | 824 | if (*vaddr == NULL) |
1369 | return (ENOMEM); | 825 | return (ENOMEM); |
1370 | *mapp = map; | ||
1371 | return(0); | 826 | return(0); |
1372 | } | 827 | } |
1373 | 828 | ||
@@ -1376,7 +831,7 @@ ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat, | |||
1376 | void* vaddr, bus_dmamap_t map) | 831 | void* vaddr, bus_dmamap_t map) |
1377 | { | 832 | { |
1378 | pci_free_consistent(ahd->dev_softc, dmat->maxsize, | 833 | pci_free_consistent(ahd->dev_softc, dmat->maxsize, |
1379 | vaddr, map->bus_addr); | 834 | vaddr, map); |
1380 | } | 835 | } |
1381 | 836 | ||
1382 | int | 837 | int |
@@ -1390,7 +845,7 @@ ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map, | |||
1390 | */ | 845 | */ |
1391 | bus_dma_segment_t stack_sg; | 846 | bus_dma_segment_t stack_sg; |
1392 | 847 | ||
1393 | stack_sg.ds_addr = map->bus_addr; | 848 | stack_sg.ds_addr = map; |
1394 | stack_sg.ds_len = dmat->maxsize; | 849 | stack_sg.ds_len = dmat->maxsize; |
1395 | cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0); | 850 | cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0); |
1396 | return (0); | 851 | return (0); |
@@ -1399,11 +854,6 @@ ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map, | |||
1399 | void | 854 | void |
1400 | ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map) | 855 | ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map) |
1401 | { | 856 | { |
1402 | /* | ||
1403 | * The map may is NULL in our < 2.3.X implementation. | ||
1404 | */ | ||
1405 | if (map != NULL) | ||
1406 | free(map, M_DEVBUF); | ||
1407 | } | 857 | } |
1408 | 858 | ||
1409 | int | 859 | int |
@@ -1468,41 +918,6 @@ ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd) | |||
1468 | } | 918 | } |
1469 | 919 | ||
1470 | static void | 920 | static void |
1471 | ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value) | ||
1472 | { | ||
1473 | |||
1474 | if ((instance >= 0) && (targ >= 0) | ||
1475 | && (instance < NUM_ELEMENTS(aic79xx_tag_info)) | ||
1476 | && (targ < AHD_NUM_TARGETS)) { | ||
1477 | aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF; | ||
1478 | if (bootverbose) | ||
1479 | printf("tag_info[%d:%d] = %d\n", instance, targ, value); | ||
1480 | } | ||
1481 | } | ||
1482 | |||
1483 | static void | ||
1484 | ahd_linux_setup_rd_strm_info(u_long arg, int instance, int targ, int32_t value) | ||
1485 | { | ||
1486 | if ((instance >= 0) | ||
1487 | && (instance < NUM_ELEMENTS(aic79xx_rd_strm_info))) { | ||
1488 | aic79xx_rd_strm_info[instance] = value & 0xFFFF; | ||
1489 | if (bootverbose) | ||
1490 | printf("rd_strm[%d] = 0x%x\n", instance, value); | ||
1491 | } | ||
1492 | } | ||
1493 | |||
1494 | static void | ||
1495 | ahd_linux_setup_dv(u_long arg, int instance, int targ, int32_t value) | ||
1496 | { | ||
1497 | if ((instance >= 0) | ||
1498 | && (instance < NUM_ELEMENTS(aic79xx_dv_settings))) { | ||
1499 | aic79xx_dv_settings[instance] = value; | ||
1500 | if (bootverbose) | ||
1501 | printf("dv[%d] = %d\n", instance, value); | ||
1502 | } | ||
1503 | } | ||
1504 | |||
1505 | static void | ||
1506 | ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value) | 921 | ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value) |
1507 | { | 922 | { |
1508 | 923 | ||
@@ -1532,6 +947,19 @@ ahd_linux_setup_tag_info_global(char *p) | |||
1532 | } | 947 | } |
1533 | } | 948 | } |
1534 | 949 | ||
950 | static void | ||
951 | ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value) | ||
952 | { | ||
953 | |||
954 | if ((instance >= 0) && (targ >= 0) | ||
955 | && (instance < NUM_ELEMENTS(aic79xx_tag_info)) | ||
956 | && (targ < AHD_NUM_TARGETS)) { | ||
957 | aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF; | ||
958 | if (bootverbose) | ||
959 | printf("tag_info[%d:%d] = %d\n", instance, targ, value); | ||
960 | } | ||
961 | } | ||
962 | |||
1535 | /* | 963 | /* |
1536 | * Handle Linux boot parameters. This routine allows for assigning a value | 964 | * Handle Linux boot parameters. This routine allows for assigning a value |
1537 | * to a parameter with a ':' between the parameter and the value. | 965 | * to a parameter with a ':' between the parameter and the value. |
@@ -1561,8 +989,6 @@ aic79xx_setup(char *s) | |||
1561 | { "seltime", &aic79xx_seltime }, | 989 | { "seltime", &aic79xx_seltime }, |
1562 | { "tag_info", NULL }, | 990 | { "tag_info", NULL }, |
1563 | { "global_tag_depth", NULL}, | 991 | { "global_tag_depth", NULL}, |
1564 | { "rd_strm", NULL }, | ||
1565 | { "dv", NULL }, | ||
1566 | { "slewrate", NULL }, | 992 | { "slewrate", NULL }, |
1567 | { "precomp", NULL }, | 993 | { "precomp", NULL }, |
1568 | { "amplitude", NULL }, | 994 | { "amplitude", NULL }, |
@@ -1593,12 +1019,6 @@ aic79xx_setup(char *s) | |||
1593 | } else if (strncmp(p, "tag_info", n) == 0) { | 1019 | } else if (strncmp(p, "tag_info", n) == 0) { |
1594 | s = aic_parse_brace_option("tag_info", p + n, end, | 1020 | s = aic_parse_brace_option("tag_info", p + n, end, |
1595 | 2, ahd_linux_setup_tag_info, 0); | 1021 | 2, ahd_linux_setup_tag_info, 0); |
1596 | } else if (strncmp(p, "rd_strm", n) == 0) { | ||
1597 | s = aic_parse_brace_option("rd_strm", p + n, end, | ||
1598 | 1, ahd_linux_setup_rd_strm_info, 0); | ||
1599 | } else if (strncmp(p, "dv", n) == 0) { | ||
1600 | s = aic_parse_brace_option("dv", p + n, end, 1, | ||
1601 | ahd_linux_setup_dv, 0); | ||
1602 | } else if (strncmp(p, "slewrate", n) == 0) { | 1022 | } else if (strncmp(p, "slewrate", n) == 0) { |
1603 | s = aic_parse_brace_option("slewrate", | 1023 | s = aic_parse_brace_option("slewrate", |
1604 | p + n, end, 1, ahd_linux_setup_iocell_info, | 1024 | p + n, end, 1, ahd_linux_setup_iocell_info, |
@@ -1627,13 +1047,12 @@ __setup("aic79xx=", aic79xx_setup); | |||
1627 | uint32_t aic79xx_verbose; | 1047 | uint32_t aic79xx_verbose; |
1628 | 1048 | ||
1629 | int | 1049 | int |
1630 | ahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template) | 1050 | ahd_linux_register_host(struct ahd_softc *ahd, struct scsi_host_template *template) |
1631 | { | 1051 | { |
1632 | char buf[80]; | 1052 | char buf[80]; |
1633 | struct Scsi_Host *host; | 1053 | struct Scsi_Host *host; |
1634 | char *new_name; | 1054 | char *new_name; |
1635 | u_long s; | 1055 | u_long s; |
1636 | u_long target; | ||
1637 | 1056 | ||
1638 | template->name = ahd->description; | 1057 | template->name = ahd->description; |
1639 | host = scsi_host_alloc(template, sizeof(struct ahd_softc *)); | 1058 | host = scsi_host_alloc(template, sizeof(struct ahd_softc *)); |
@@ -1661,47 +1080,12 @@ ahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template) | |||
1661 | ahd_set_name(ahd, new_name); | 1080 | ahd_set_name(ahd, new_name); |
1662 | } | 1081 | } |
1663 | host->unique_id = ahd->unit; | 1082 | host->unique_id = ahd->unit; |
1664 | ahd_linux_setup_user_rd_strm_settings(ahd); | ||
1665 | ahd_linux_initialize_scsi_bus(ahd); | 1083 | ahd_linux_initialize_scsi_bus(ahd); |
1666 | ahd_unlock(ahd, &s); | ||
1667 | ahd->platform_data->dv_pid = kernel_thread(ahd_linux_dv_thread, ahd, 0); | ||
1668 | ahd_lock(ahd, &s); | ||
1669 | if (ahd->platform_data->dv_pid < 0) { | ||
1670 | printf("%s: Failed to create DV thread, error= %d\n", | ||
1671 | ahd_name(ahd), ahd->platform_data->dv_pid); | ||
1672 | return (-ahd->platform_data->dv_pid); | ||
1673 | } | ||
1674 | /* | ||
1675 | * Initially allocate *all* of our linux target objects | ||
1676 | * so that the DV thread will scan them all in parallel | ||
1677 | * just after driver initialization. Any device that | ||
1678 | * does not exist will have its target object destroyed | ||
1679 | * by the selection timeout handler. In the case of a | ||
1680 | * device that appears after the initial DV scan, async | ||
1681 | * negotiation will occur for the first command, and DV | ||
1682 | * will comence should that first command be successful. | ||
1683 | */ | ||
1684 | for (target = 0; target < host->max_id; target++) { | ||
1685 | |||
1686 | /* | ||
1687 | * Skip our own ID. Some Compaq/HP storage devices | ||
1688 | * have enclosure management devices that respond to | ||
1689 | * single bit selection (i.e. selecting ourselves). | ||
1690 | * It is expected that either an external application | ||
1691 | * or a modified kernel will be used to probe this | ||
1692 | * ID if it is appropriate. To accommodate these | ||
1693 | * installations, ahc_linux_alloc_target() will allocate | ||
1694 | * for our ID if asked to do so. | ||
1695 | */ | ||
1696 | if (target == ahd->our_id) | ||
1697 | continue; | ||
1698 | |||
1699 | ahd_linux_alloc_target(ahd, 0, target); | ||
1700 | } | ||
1701 | ahd_intr_enable(ahd, TRUE); | 1084 | ahd_intr_enable(ahd, TRUE); |
1702 | ahd_linux_start_dv(ahd); | ||
1703 | ahd_unlock(ahd, &s); | 1085 | ahd_unlock(ahd, &s); |
1704 | 1086 | ||
1087 | host->transportt = ahd_linux_transport_template; | ||
1088 | |||
1705 | scsi_add_host(host, &ahd->dev_softc->dev); /* XXX handle failure */ | 1089 | scsi_add_host(host, &ahd->dev_softc->dev); /* XXX handle failure */ |
1706 | scsi_scan_host(host); | 1090 | scsi_scan_host(host); |
1707 | return (0); | 1091 | return (0); |
@@ -1798,18 +1182,9 @@ ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg) | |||
1798 | if (ahd->platform_data == NULL) | 1182 | if (ahd->platform_data == NULL) |
1799 | return (ENOMEM); | 1183 | return (ENOMEM); |
1800 | memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data)); | 1184 | memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data)); |
1801 | TAILQ_INIT(&ahd->platform_data->completeq); | ||
1802 | ahd->platform_data->irq = AHD_LINUX_NOIRQ; | 1185 | ahd->platform_data->irq = AHD_LINUX_NOIRQ; |
1803 | ahd->platform_data->hw_dma_mask = 0xFFFFFFFF; | ||
1804 | ahd_lockinit(ahd); | 1186 | ahd_lockinit(ahd); |
1805 | ahd_done_lockinit(ahd); | ||
1806 | init_timer(&ahd->platform_data->completeq_timer); | ||
1807 | ahd->platform_data->completeq_timer.data = (u_long)ahd; | ||
1808 | ahd->platform_data->completeq_timer.function = | ||
1809 | (ahd_linux_callback_t *)ahd_linux_thread_run_complete_queue; | ||
1810 | init_MUTEX_LOCKED(&ahd->platform_data->eh_sem); | 1187 | init_MUTEX_LOCKED(&ahd->platform_data->eh_sem); |
1811 | init_MUTEX_LOCKED(&ahd->platform_data->dv_sem); | ||
1812 | init_MUTEX_LOCKED(&ahd->platform_data->dv_cmd_sem); | ||
1813 | ahd->seltime = (aic79xx_seltime & 0x3) << 4; | 1188 | ahd->seltime = (aic79xx_seltime & 0x3) << 4; |
1814 | return (0); | 1189 | return (0); |
1815 | } | 1190 | } |
@@ -1817,13 +1192,10 @@ ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg) | |||
1817 | void | 1192 | void |
1818 | ahd_platform_free(struct ahd_softc *ahd) | 1193 | ahd_platform_free(struct ahd_softc *ahd) |
1819 | { | 1194 | { |
1820 | struct ahd_linux_target *targ; | 1195 | struct scsi_target *starget; |
1821 | struct ahd_linux_device *dev; | ||
1822 | int i, j; | 1196 | int i, j; |
1823 | 1197 | ||
1824 | if (ahd->platform_data != NULL) { | 1198 | if (ahd->platform_data != NULL) { |
1825 | del_timer_sync(&ahd->platform_data->completeq_timer); | ||
1826 | ahd_linux_kill_dv_thread(ahd); | ||
1827 | if (ahd->platform_data->host != NULL) { | 1199 | if (ahd->platform_data->host != NULL) { |
1828 | scsi_remove_host(ahd->platform_data->host); | 1200 | scsi_remove_host(ahd->platform_data->host); |
1829 | scsi_host_put(ahd->platform_data->host); | 1201 | scsi_host_put(ahd->platform_data->host); |
@@ -1831,22 +1203,16 @@ ahd_platform_free(struct ahd_softc *ahd) | |||
1831 | 1203 | ||
1832 | /* destroy all of the device and target objects */ | 1204 | /* destroy all of the device and target objects */ |
1833 | for (i = 0; i < AHD_NUM_TARGETS; i++) { | 1205 | for (i = 0; i < AHD_NUM_TARGETS; i++) { |
1834 | targ = ahd->platform_data->targets[i]; | 1206 | starget = ahd->platform_data->starget[i]; |
1835 | if (targ != NULL) { | 1207 | if (starget != NULL) { |
1836 | /* Keep target around through the loop. */ | ||
1837 | targ->refcount++; | ||
1838 | for (j = 0; j < AHD_NUM_LUNS; j++) { | 1208 | for (j = 0; j < AHD_NUM_LUNS; j++) { |
1839 | 1209 | struct ahd_linux_target *targ = | |
1840 | if (targ->devices[j] == NULL) | 1210 | scsi_transport_target_data(starget); |
1211 | if (targ->sdev[j] == NULL) | ||
1841 | continue; | 1212 | continue; |
1842 | dev = targ->devices[j]; | 1213 | targ->sdev[j] = NULL; |
1843 | ahd_linux_free_device(ahd, dev); | ||
1844 | } | 1214 | } |
1845 | /* | 1215 | ahd->platform_data->starget[i] = NULL; |
1846 | * Forcibly free the target now that | ||
1847 | * all devices are gone. | ||
1848 | */ | ||
1849 | ahd_linux_free_target(ahd, targ); | ||
1850 | } | 1216 | } |
1851 | } | 1217 | } |
1852 | 1218 | ||
@@ -1901,13 +1267,22 @@ void | |||
1901 | ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo, | 1267 | ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo, |
1902 | ahd_queue_alg alg) | 1268 | ahd_queue_alg alg) |
1903 | { | 1269 | { |
1270 | struct scsi_target *starget; | ||
1271 | struct ahd_linux_target *targ; | ||
1904 | struct ahd_linux_device *dev; | 1272 | struct ahd_linux_device *dev; |
1273 | struct scsi_device *sdev; | ||
1905 | int was_queuing; | 1274 | int was_queuing; |
1906 | int now_queuing; | 1275 | int now_queuing; |
1907 | 1276 | ||
1908 | dev = ahd_linux_get_device(ahd, devinfo->channel - 'A', | 1277 | starget = ahd->platform_data->starget[devinfo->target]; |
1909 | devinfo->target, | 1278 | targ = scsi_transport_target_data(starget); |
1910 | devinfo->lun, /*alloc*/FALSE); | 1279 | BUG_ON(targ == NULL); |
1280 | sdev = targ->sdev[devinfo->lun]; | ||
1281 | if (sdev == NULL) | ||
1282 | return; | ||
1283 | |||
1284 | dev = scsi_transport_device_data(sdev); | ||
1285 | |||
1911 | if (dev == NULL) | 1286 | if (dev == NULL) |
1912 | return; | 1287 | return; |
1913 | was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED); | 1288 | was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED); |
@@ -1961,1371 +1336,36 @@ ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo, | |||
1961 | dev->openings = 1 - dev->active; | 1336 | dev->openings = 1 - dev->active; |
1962 | } | 1337 | } |
1963 | 1338 | ||
1964 | if (dev->scsi_device != NULL) { | 1339 | switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) { |
1965 | switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) { | 1340 | case AHD_DEV_Q_BASIC: |
1966 | case AHD_DEV_Q_BASIC: | 1341 | scsi_adjust_queue_depth(sdev, |
1967 | scsi_adjust_queue_depth(dev->scsi_device, | 1342 | MSG_SIMPLE_TASK, |
1968 | MSG_SIMPLE_TASK, | 1343 | dev->openings + dev->active); |
1969 | dev->openings + dev->active); | ||
1970 | break; | ||
1971 | case AHD_DEV_Q_TAGGED: | ||
1972 | scsi_adjust_queue_depth(dev->scsi_device, | ||
1973 | MSG_ORDERED_TASK, | ||
1974 | dev->openings + dev->active); | ||
1975 | break; | ||
1976 | default: | ||
1977 | /* | ||
1978 | * We allow the OS to queue 2 untagged transactions to | ||
1979 | * us at any time even though we can only execute them | ||
1980 | * serially on the controller/device. This should | ||
1981 | * remove some latency. | ||
1982 | */ | ||
1983 | scsi_adjust_queue_depth(dev->scsi_device, | ||
1984 | /*NON-TAGGED*/0, | ||
1985 | /*queue depth*/2); | ||
1986 | break; | ||
1987 | } | ||
1988 | } | ||
1989 | } | ||
1990 | |||
1991 | int | ||
1992 | ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel, | ||
1993 | int lun, u_int tag, role_t role, uint32_t status) | ||
1994 | { | ||
1995 | return 0; | ||
1996 | } | ||
1997 | |||
1998 | static void | ||
1999 | ahd_linux_thread_run_complete_queue(struct ahd_softc *ahd) | ||
2000 | { | ||
2001 | u_long flags; | ||
2002 | |||
2003 | ahd_lock(ahd, &flags); | ||
2004 | del_timer(&ahd->platform_data->completeq_timer); | ||
2005 | ahd->platform_data->flags &= ~AHD_RUN_CMPLT_Q_TIMER; | ||
2006 | ahd_linux_run_complete_queue(ahd); | ||
2007 | ahd_unlock(ahd, &flags); | ||
2008 | } | ||
2009 | |||
2010 | static void | ||
2011 | ahd_linux_start_dv(struct ahd_softc *ahd) | ||
2012 | { | ||
2013 | |||
2014 | /* | ||
2015 | * Freeze the simq and signal ahd_linux_queue to not let any | ||
2016 | * more commands through | ||
2017 | */ | ||
2018 | if ((ahd->platform_data->flags & AHD_DV_ACTIVE) == 0) { | ||
2019 | #ifdef AHD_DEBUG | ||
2020 | if (ahd_debug & AHD_SHOW_DV) | ||
2021 | printf("%s: Starting DV\n", ahd_name(ahd)); | ||
2022 | #endif | ||
2023 | |||
2024 | ahd->platform_data->flags |= AHD_DV_ACTIVE; | ||
2025 | ahd_freeze_simq(ahd); | ||
2026 | |||
2027 | /* Wake up the DV kthread */ | ||
2028 | up(&ahd->platform_data->dv_sem); | ||
2029 | } | ||
2030 | } | ||
2031 | |||
2032 | static int | ||
2033 | ahd_linux_dv_thread(void *data) | ||
2034 | { | ||
2035 | struct ahd_softc *ahd; | ||
2036 | int target; | ||
2037 | u_long s; | ||
2038 | |||
2039 | ahd = (struct ahd_softc *)data; | ||
2040 | |||
2041 | #ifdef AHD_DEBUG | ||
2042 | if (ahd_debug & AHD_SHOW_DV) | ||
2043 | printf("In DV Thread\n"); | ||
2044 | #endif | ||
2045 | |||
2046 | /* | ||
2047 | * Complete thread creation. | ||
2048 | */ | ||
2049 | lock_kernel(); | ||
2050 | |||
2051 | daemonize("ahd_dv_%d", ahd->unit); | ||
2052 | current->flags |= PF_FREEZE; | ||
2053 | |||
2054 | unlock_kernel(); | ||
2055 | |||
2056 | while (1) { | ||
2057 | /* | ||
2058 | * Use down_interruptible() rather than down() to | ||
2059 | * avoid inclusion in the load average. | ||
2060 | */ | ||
2061 | down_interruptible(&ahd->platform_data->dv_sem); | ||
2062 | |||
2063 | /* Check to see if we've been signaled to exit */ | ||
2064 | ahd_lock(ahd, &s); | ||
2065 | if ((ahd->platform_data->flags & AHD_DV_SHUTDOWN) != 0) { | ||
2066 | ahd_unlock(ahd, &s); | ||
2067 | break; | ||
2068 | } | ||
2069 | ahd_unlock(ahd, &s); | ||
2070 | |||
2071 | #ifdef AHD_DEBUG | ||
2072 | if (ahd_debug & AHD_SHOW_DV) | ||
2073 | printf("%s: Beginning Domain Validation\n", | ||
2074 | ahd_name(ahd)); | ||
2075 | #endif | ||
2076 | |||
2077 | /* | ||
2078 | * Wait for any pending commands to drain before proceeding. | ||
2079 | */ | ||
2080 | ahd_lock(ahd, &s); | ||
2081 | while (LIST_FIRST(&ahd->pending_scbs) != NULL) { | ||
2082 | ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_EMPTY; | ||
2083 | ahd_unlock(ahd, &s); | ||
2084 | down_interruptible(&ahd->platform_data->dv_sem); | ||
2085 | ahd_lock(ahd, &s); | ||
2086 | } | ||
2087 | |||
2088 | /* | ||
2089 | * Wait for the SIMQ to be released so that DV is the | ||
2090 | * only reason the queue is frozen. | ||
2091 | */ | ||
2092 | while (AHD_DV_SIMQ_FROZEN(ahd) == 0) { | ||
2093 | ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE; | ||
2094 | ahd_unlock(ahd, &s); | ||
2095 | down_interruptible(&ahd->platform_data->dv_sem); | ||
2096 | ahd_lock(ahd, &s); | ||
2097 | } | ||
2098 | ahd_unlock(ahd, &s); | ||
2099 | |||
2100 | for (target = 0; target < AHD_NUM_TARGETS; target++) | ||
2101 | ahd_linux_dv_target(ahd, target); | ||
2102 | |||
2103 | ahd_lock(ahd, &s); | ||
2104 | ahd->platform_data->flags &= ~AHD_DV_ACTIVE; | ||
2105 | ahd_unlock(ahd, &s); | ||
2106 | |||
2107 | /* | ||
2108 | * Release the SIMQ so that normal commands are | ||
2109 | * allowed to continue on the bus. | ||
2110 | */ | ||
2111 | ahd_release_simq(ahd); | ||
2112 | } | ||
2113 | up(&ahd->platform_data->eh_sem); | ||
2114 | return (0); | ||
2115 | } | ||
2116 | |||
2117 | static void | ||
2118 | ahd_linux_kill_dv_thread(struct ahd_softc *ahd) | ||
2119 | { | ||
2120 | u_long s; | ||
2121 | |||
2122 | ahd_lock(ahd, &s); | ||
2123 | if (ahd->platform_data->dv_pid != 0) { | ||
2124 | ahd->platform_data->flags |= AHD_DV_SHUTDOWN; | ||
2125 | ahd_unlock(ahd, &s); | ||
2126 | up(&ahd->platform_data->dv_sem); | ||
2127 | |||
2128 | /* | ||
2129 | * Use the eh_sem as an indicator that the | ||
2130 | * dv thread is exiting. Note that the dv | ||
2131 | * thread must still return after performing | ||
2132 | * the up on our semaphore before it has | ||
2133 | * completely exited this module. Unfortunately, | ||
2134 | * there seems to be no easy way to wait for the | ||
2135 | * exit of a thread for which you are not the | ||
2136 | * parent (dv threads are parented by init). | ||
2137 | * Cross your fingers... | ||
2138 | */ | ||
2139 | down(&ahd->platform_data->eh_sem); | ||
2140 | |||
2141 | /* | ||
2142 | * Mark the dv thread as already dead. This | ||
2143 | * avoids attempting to kill it a second time. | ||
2144 | * This is necessary because we must kill the | ||
2145 | * DV thread before calling ahd_free() in the | ||
2146 | * module shutdown case to avoid bogus locking | ||
2147 | * in the SCSI mid-layer, but we ahd_free() is | ||
2148 | * called without killing the DV thread in the | ||
2149 | * instance detach case, so ahd_platform_free() | ||
2150 | * calls us again to verify that the DV thread | ||
2151 | * is dead. | ||
2152 | */ | ||
2153 | ahd->platform_data->dv_pid = 0; | ||
2154 | } else { | ||
2155 | ahd_unlock(ahd, &s); | ||
2156 | } | ||
2157 | } | ||
2158 | |||
2159 | #define AHD_LINUX_DV_INQ_SHORT_LEN 36 | ||
2160 | #define AHD_LINUX_DV_INQ_LEN 256 | ||
2161 | #define AHD_LINUX_DV_TIMEOUT (HZ / 4) | ||
2162 | |||
2163 | #define AHD_SET_DV_STATE(ahd, targ, newstate) \ | ||
2164 | ahd_set_dv_state(ahd, targ, newstate, __LINE__) | ||
2165 | |||
2166 | static __inline void | ||
2167 | ahd_set_dv_state(struct ahd_softc *ahd, struct ahd_linux_target *targ, | ||
2168 | ahd_dv_state newstate, u_int line) | ||
2169 | { | ||
2170 | ahd_dv_state oldstate; | ||
2171 | |||
2172 | oldstate = targ->dv_state; | ||
2173 | #ifdef AHD_DEBUG | ||
2174 | if (ahd_debug & AHD_SHOW_DV) | ||
2175 | printf("%s:%d: Going from state %d to state %d\n", | ||
2176 | ahd_name(ahd), line, oldstate, newstate); | ||
2177 | #endif | ||
2178 | |||
2179 | if (oldstate == newstate) | ||
2180 | targ->dv_state_retry++; | ||
2181 | else | ||
2182 | targ->dv_state_retry = 0; | ||
2183 | targ->dv_state = newstate; | ||
2184 | } | ||
2185 | |||
2186 | static void | ||
2187 | ahd_linux_dv_target(struct ahd_softc *ahd, u_int target_offset) | ||
2188 | { | ||
2189 | struct ahd_devinfo devinfo; | ||
2190 | struct ahd_linux_target *targ; | ||
2191 | struct scsi_cmnd *cmd; | ||
2192 | struct scsi_device *scsi_dev; | ||
2193 | struct scsi_sense_data *sense; | ||
2194 | uint8_t *buffer; | ||
2195 | u_long s; | ||
2196 | u_int timeout; | ||
2197 | int echo_size; | ||
2198 | |||
2199 | sense = NULL; | ||
2200 | buffer = NULL; | ||
2201 | echo_size = 0; | ||
2202 | ahd_lock(ahd, &s); | ||
2203 | targ = ahd->platform_data->targets[target_offset]; | ||
2204 | if (targ == NULL || (targ->flags & AHD_DV_REQUIRED) == 0) { | ||
2205 | ahd_unlock(ahd, &s); | ||
2206 | return; | ||
2207 | } | ||
2208 | ahd_compile_devinfo(&devinfo, ahd->our_id, targ->target, /*lun*/0, | ||
2209 | targ->channel + 'A', ROLE_INITIATOR); | ||
2210 | #ifdef AHD_DEBUG | ||
2211 | if (ahd_debug & AHD_SHOW_DV) { | ||
2212 | ahd_print_devinfo(ahd, &devinfo); | ||
2213 | printf("Performing DV\n"); | ||
2214 | } | ||
2215 | #endif | ||
2216 | |||
2217 | ahd_unlock(ahd, &s); | ||
2218 | |||
2219 | cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK); | ||
2220 | scsi_dev = malloc(sizeof(struct scsi_device), M_DEVBUF, M_WAITOK); | ||
2221 | scsi_dev->host = ahd->platform_data->host; | ||
2222 | scsi_dev->id = devinfo.target; | ||
2223 | scsi_dev->lun = devinfo.lun; | ||
2224 | scsi_dev->channel = devinfo.channel - 'A'; | ||
2225 | ahd->platform_data->dv_scsi_dev = scsi_dev; | ||
2226 | |||
2227 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2228 | |||
2229 | while (targ->dv_state != AHD_DV_STATE_EXIT) { | ||
2230 | timeout = AHD_LINUX_DV_TIMEOUT; | ||
2231 | switch (targ->dv_state) { | ||
2232 | case AHD_DV_STATE_INQ_SHORT_ASYNC: | ||
2233 | case AHD_DV_STATE_INQ_ASYNC: | ||
2234 | case AHD_DV_STATE_INQ_ASYNC_VERIFY: | ||
2235 | /* | ||
2236 | * Set things to async narrow to reduce the | ||
2237 | * chance that the INQ will fail. | ||
2238 | */ | ||
2239 | ahd_lock(ahd, &s); | ||
2240 | ahd_set_syncrate(ahd, &devinfo, 0, 0, 0, | ||
2241 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
2242 | ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT, | ||
2243 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
2244 | ahd_unlock(ahd, &s); | ||
2245 | timeout = 10 * HZ; | ||
2246 | targ->flags &= ~AHD_INQ_VALID; | ||
2247 | /* FALLTHROUGH */ | ||
2248 | case AHD_DV_STATE_INQ_VERIFY: | ||
2249 | { | ||
2250 | u_int inq_len; | ||
2251 | |||
2252 | if (targ->dv_state == AHD_DV_STATE_INQ_SHORT_ASYNC) | ||
2253 | inq_len = AHD_LINUX_DV_INQ_SHORT_LEN; | ||
2254 | else | ||
2255 | inq_len = targ->inq_data->additional_length + 5; | ||
2256 | ahd_linux_dv_inq(ahd, cmd, &devinfo, targ, inq_len); | ||
2257 | break; | ||
2258 | } | ||
2259 | case AHD_DV_STATE_TUR: | ||
2260 | case AHD_DV_STATE_BUSY: | ||
2261 | timeout = 5 * HZ; | ||
2262 | ahd_linux_dv_tur(ahd, cmd, &devinfo); | ||
2263 | break; | ||
2264 | case AHD_DV_STATE_REBD: | ||
2265 | ahd_linux_dv_rebd(ahd, cmd, &devinfo, targ); | ||
2266 | break; | ||
2267 | case AHD_DV_STATE_WEB: | ||
2268 | ahd_linux_dv_web(ahd, cmd, &devinfo, targ); | ||
2269 | break; | ||
2270 | |||
2271 | case AHD_DV_STATE_REB: | ||
2272 | ahd_linux_dv_reb(ahd, cmd, &devinfo, targ); | ||
2273 | break; | ||
2274 | |||
2275 | case AHD_DV_STATE_SU: | ||
2276 | ahd_linux_dv_su(ahd, cmd, &devinfo, targ); | ||
2277 | timeout = 50 * HZ; | ||
2278 | break; | ||
2279 | |||
2280 | default: | ||
2281 | ahd_print_devinfo(ahd, &devinfo); | ||
2282 | printf("Unknown DV state %d\n", targ->dv_state); | ||
2283 | goto out; | ||
2284 | } | ||
2285 | |||
2286 | /* Queue the command and wait for it to complete */ | ||
2287 | /* Abuse eh_timeout in the scsi_cmnd struct for our purposes */ | ||
2288 | init_timer(&cmd->eh_timeout); | ||
2289 | #ifdef AHD_DEBUG | ||
2290 | if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) | ||
2291 | /* | ||
2292 | * All of the printfs during negotiation | ||
2293 | * really slow down the negotiation. | ||
2294 | * Add a bit of time just to be safe. | ||
2295 | */ | ||
2296 | timeout += HZ; | ||
2297 | #endif | ||
2298 | scsi_add_timer(cmd, timeout, ahd_linux_dv_timeout); | ||
2299 | /* | ||
2300 | * In 2.5.X, it is assumed that all calls from the | ||
2301 | * "midlayer" (which we are emulating) will have the | ||
2302 | * ahd host lock held. For other kernels, the | ||
2303 | * io_request_lock must be held. | ||
2304 | */ | ||
2305 | #if AHD_SCSI_HAS_HOST_LOCK != 0 | ||
2306 | ahd_lock(ahd, &s); | ||
2307 | #else | ||
2308 | spin_lock_irqsave(&io_request_lock, s); | ||
2309 | #endif | ||
2310 | ahd_linux_queue(cmd, ahd_linux_dv_complete); | ||
2311 | #if AHD_SCSI_HAS_HOST_LOCK != 0 | ||
2312 | ahd_unlock(ahd, &s); | ||
2313 | #else | ||
2314 | spin_unlock_irqrestore(&io_request_lock, s); | ||
2315 | #endif | ||
2316 | down_interruptible(&ahd->platform_data->dv_cmd_sem); | ||
2317 | /* | ||
2318 | * Wait for the SIMQ to be released so that DV is the | ||
2319 | * only reason the queue is frozen. | ||
2320 | */ | ||
2321 | ahd_lock(ahd, &s); | ||
2322 | while (AHD_DV_SIMQ_FROZEN(ahd) == 0) { | ||
2323 | ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE; | ||
2324 | ahd_unlock(ahd, &s); | ||
2325 | down_interruptible(&ahd->platform_data->dv_sem); | ||
2326 | ahd_lock(ahd, &s); | ||
2327 | } | ||
2328 | ahd_unlock(ahd, &s); | ||
2329 | |||
2330 | ahd_linux_dv_transition(ahd, cmd, &devinfo, targ); | ||
2331 | } | ||
2332 | |||
2333 | out: | ||
2334 | if ((targ->flags & AHD_INQ_VALID) != 0 | ||
2335 | && ahd_linux_get_device(ahd, devinfo.channel - 'A', | ||
2336 | devinfo.target, devinfo.lun, | ||
2337 | /*alloc*/FALSE) == NULL) { | ||
2338 | /* | ||
2339 | * The DV state machine failed to configure this device. | ||
2340 | * This is normal if DV is disabled. Since we have inquiry | ||
2341 | * data, filter it and use the "optimistic" negotiation | ||
2342 | * parameters found in the inquiry string. | ||
2343 | */ | ||
2344 | ahd_linux_filter_inquiry(ahd, &devinfo); | ||
2345 | if ((targ->flags & (AHD_BASIC_DV|AHD_ENHANCED_DV)) != 0) { | ||
2346 | ahd_print_devinfo(ahd, &devinfo); | ||
2347 | printf("DV failed to configure device. " | ||
2348 | "Please file a bug report against " | ||
2349 | "this driver.\n"); | ||
2350 | } | ||
2351 | } | ||
2352 | |||
2353 | if (cmd != NULL) | ||
2354 | free(cmd, M_DEVBUF); | ||
2355 | |||
2356 | if (ahd->platform_data->dv_scsi_dev != NULL) { | ||
2357 | free(ahd->platform_data->dv_scsi_dev, M_DEVBUF); | ||
2358 | ahd->platform_data->dv_scsi_dev = NULL; | ||
2359 | } | ||
2360 | |||
2361 | ahd_lock(ahd, &s); | ||
2362 | if (targ->dv_buffer != NULL) { | ||
2363 | free(targ->dv_buffer, M_DEVBUF); | ||
2364 | targ->dv_buffer = NULL; | ||
2365 | } | ||
2366 | if (targ->dv_buffer1 != NULL) { | ||
2367 | free(targ->dv_buffer1, M_DEVBUF); | ||
2368 | targ->dv_buffer1 = NULL; | ||
2369 | } | ||
2370 | targ->flags &= ~AHD_DV_REQUIRED; | ||
2371 | if (targ->refcount == 0) | ||
2372 | ahd_linux_free_target(ahd, targ); | ||
2373 | ahd_unlock(ahd, &s); | ||
2374 | } | ||
2375 | |||
2376 | static __inline int | ||
2377 | ahd_linux_dv_fallback(struct ahd_softc *ahd, struct ahd_devinfo *devinfo) | ||
2378 | { | ||
2379 | u_long s; | ||
2380 | int retval; | ||
2381 | |||
2382 | ahd_lock(ahd, &s); | ||
2383 | retval = ahd_linux_fallback(ahd, devinfo); | ||
2384 | ahd_unlock(ahd, &s); | ||
2385 | |||
2386 | return (retval); | ||
2387 | } | ||
2388 | |||
2389 | static void | ||
2390 | ahd_linux_dv_transition(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
2391 | struct ahd_devinfo *devinfo, | ||
2392 | struct ahd_linux_target *targ) | ||
2393 | { | ||
2394 | u_int32_t status; | ||
2395 | |||
2396 | status = aic_error_action(cmd, targ->inq_data, | ||
2397 | ahd_cmd_get_transaction_status(cmd), | ||
2398 | ahd_cmd_get_scsi_status(cmd)); | ||
2399 | |||
2400 | |||
2401 | #ifdef AHD_DEBUG | ||
2402 | if (ahd_debug & AHD_SHOW_DV) { | ||
2403 | ahd_print_devinfo(ahd, devinfo); | ||
2404 | printf("Entering ahd_linux_dv_transition, state= %d, " | ||
2405 | "status= 0x%x, cmd->result= 0x%x\n", targ->dv_state, | ||
2406 | status, cmd->result); | ||
2407 | } | ||
2408 | #endif | ||
2409 | |||
2410 | switch (targ->dv_state) { | ||
2411 | case AHD_DV_STATE_INQ_SHORT_ASYNC: | ||
2412 | case AHD_DV_STATE_INQ_ASYNC: | ||
2413 | switch (status & SS_MASK) { | ||
2414 | case SS_NOP: | ||
2415 | { | ||
2416 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state+1); | ||
2417 | break; | ||
2418 | } | ||
2419 | case SS_INQ_REFRESH: | ||
2420 | AHD_SET_DV_STATE(ahd, targ, | ||
2421 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2422 | break; | ||
2423 | case SS_TUR: | ||
2424 | case SS_RETRY: | ||
2425 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
2426 | if (ahd_cmd_get_transaction_status(cmd) | ||
2427 | == CAM_REQUEUE_REQ) | ||
2428 | targ->dv_state_retry--; | ||
2429 | if ((status & SS_ERRMASK) == EBUSY) | ||
2430 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY); | ||
2431 | if (targ->dv_state_retry < 10) | ||
2432 | break; | ||
2433 | /* FALLTHROUGH */ | ||
2434 | default: | ||
2435 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2436 | #ifdef AHD_DEBUG | ||
2437 | if (ahd_debug & AHD_SHOW_DV) { | ||
2438 | ahd_print_devinfo(ahd, devinfo); | ||
2439 | printf("Failed DV inquiry, skipping\n"); | ||
2440 | } | ||
2441 | #endif | ||
2442 | break; | ||
2443 | } | ||
2444 | break; | ||
2445 | case AHD_DV_STATE_INQ_ASYNC_VERIFY: | ||
2446 | switch (status & SS_MASK) { | ||
2447 | case SS_NOP: | ||
2448 | { | ||
2449 | u_int xportflags; | ||
2450 | u_int spi3data; | ||
2451 | |||
2452 | if (memcmp(targ->inq_data, targ->dv_buffer, | ||
2453 | AHD_LINUX_DV_INQ_LEN) != 0) { | ||
2454 | /* | ||
2455 | * Inquiry data must have changed. | ||
2456 | * Try from the top again. | ||
2457 | */ | ||
2458 | AHD_SET_DV_STATE(ahd, targ, | ||
2459 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2460 | break; | ||
2461 | } | ||
2462 | |||
2463 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state+1); | ||
2464 | targ->flags |= AHD_INQ_VALID; | ||
2465 | if (ahd_linux_user_dv_setting(ahd) == 0) | ||
2466 | break; | ||
2467 | |||
2468 | xportflags = targ->inq_data->flags; | ||
2469 | if ((xportflags & (SID_Sync|SID_WBus16)) == 0) | ||
2470 | break; | ||
2471 | |||
2472 | spi3data = targ->inq_data->spi3data; | ||
2473 | switch (spi3data & SID_SPI_CLOCK_DT_ST) { | ||
2474 | default: | ||
2475 | case SID_SPI_CLOCK_ST: | ||
2476 | /* Assume only basic DV is supported. */ | ||
2477 | targ->flags |= AHD_BASIC_DV; | ||
2478 | break; | ||
2479 | case SID_SPI_CLOCK_DT: | ||
2480 | case SID_SPI_CLOCK_DT_ST: | ||
2481 | targ->flags |= AHD_ENHANCED_DV; | ||
2482 | break; | ||
2483 | } | ||
2484 | break; | ||
2485 | } | ||
2486 | case SS_INQ_REFRESH: | ||
2487 | AHD_SET_DV_STATE(ahd, targ, | ||
2488 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2489 | break; | ||
2490 | case SS_TUR: | ||
2491 | case SS_RETRY: | ||
2492 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
2493 | if (ahd_cmd_get_transaction_status(cmd) | ||
2494 | == CAM_REQUEUE_REQ) | ||
2495 | targ->dv_state_retry--; | ||
2496 | |||
2497 | if ((status & SS_ERRMASK) == EBUSY) | ||
2498 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY); | ||
2499 | if (targ->dv_state_retry < 10) | ||
2500 | break; | ||
2501 | /* FALLTHROUGH */ | ||
2502 | default: | ||
2503 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2504 | #ifdef AHD_DEBUG | ||
2505 | if (ahd_debug & AHD_SHOW_DV) { | ||
2506 | ahd_print_devinfo(ahd, devinfo); | ||
2507 | printf("Failed DV inquiry, skipping\n"); | ||
2508 | } | ||
2509 | #endif | ||
2510 | break; | ||
2511 | } | ||
2512 | break; | ||
2513 | case AHD_DV_STATE_INQ_VERIFY: | ||
2514 | switch (status & SS_MASK) { | ||
2515 | case SS_NOP: | ||
2516 | { | ||
2517 | |||
2518 | if (memcmp(targ->inq_data, targ->dv_buffer, | ||
2519 | AHD_LINUX_DV_INQ_LEN) == 0) { | ||
2520 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2521 | break; | ||
2522 | } | ||
2523 | |||
2524 | #ifdef AHD_DEBUG | ||
2525 | if (ahd_debug & AHD_SHOW_DV) { | ||
2526 | int i; | ||
2527 | |||
2528 | ahd_print_devinfo(ahd, devinfo); | ||
2529 | printf("Inquiry buffer mismatch:"); | ||
2530 | for (i = 0; i < AHD_LINUX_DV_INQ_LEN; i++) { | ||
2531 | if ((i & 0xF) == 0) | ||
2532 | printf("\n "); | ||
2533 | printf("0x%x:0x0%x ", | ||
2534 | ((uint8_t *)targ->inq_data)[i], | ||
2535 | targ->dv_buffer[i]); | ||
2536 | } | ||
2537 | printf("\n"); | ||
2538 | } | ||
2539 | #endif | ||
2540 | |||
2541 | if (ahd_linux_dv_fallback(ahd, devinfo) != 0) { | ||
2542 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2543 | break; | ||
2544 | } | ||
2545 | /* | ||
2546 | * Do not count "falling back" | ||
2547 | * against our retries. | ||
2548 | */ | ||
2549 | targ->dv_state_retry = 0; | ||
2550 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
2551 | break; | ||
2552 | } | ||
2553 | case SS_INQ_REFRESH: | ||
2554 | AHD_SET_DV_STATE(ahd, targ, | ||
2555 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2556 | break; | ||
2557 | case SS_TUR: | ||
2558 | case SS_RETRY: | ||
2559 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
2560 | if (ahd_cmd_get_transaction_status(cmd) | ||
2561 | == CAM_REQUEUE_REQ) { | ||
2562 | targ->dv_state_retry--; | ||
2563 | } else if ((status & SSQ_FALLBACK) != 0) { | ||
2564 | if (ahd_linux_dv_fallback(ahd, devinfo) != 0) { | ||
2565 | AHD_SET_DV_STATE(ahd, targ, | ||
2566 | AHD_DV_STATE_EXIT); | ||
2567 | break; | ||
2568 | } | ||
2569 | /* | ||
2570 | * Do not count "falling back" | ||
2571 | * against our retries. | ||
2572 | */ | ||
2573 | targ->dv_state_retry = 0; | ||
2574 | } else if ((status & SS_ERRMASK) == EBUSY) | ||
2575 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY); | ||
2576 | if (targ->dv_state_retry < 10) | ||
2577 | break; | ||
2578 | /* FALLTHROUGH */ | ||
2579 | default: | ||
2580 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2581 | #ifdef AHD_DEBUG | ||
2582 | if (ahd_debug & AHD_SHOW_DV) { | ||
2583 | ahd_print_devinfo(ahd, devinfo); | ||
2584 | printf("Failed DV inquiry, skipping\n"); | ||
2585 | } | ||
2586 | #endif | ||
2587 | break; | ||
2588 | } | ||
2589 | break; | ||
2590 | |||
2591 | case AHD_DV_STATE_TUR: | ||
2592 | switch (status & SS_MASK) { | ||
2593 | case SS_NOP: | ||
2594 | if ((targ->flags & AHD_BASIC_DV) != 0) { | ||
2595 | ahd_linux_filter_inquiry(ahd, devinfo); | ||
2596 | AHD_SET_DV_STATE(ahd, targ, | ||
2597 | AHD_DV_STATE_INQ_VERIFY); | ||
2598 | } else if ((targ->flags & AHD_ENHANCED_DV) != 0) { | ||
2599 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_REBD); | ||
2600 | } else { | ||
2601 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2602 | } | ||
2603 | break; | ||
2604 | case SS_RETRY: | ||
2605 | case SS_TUR: | ||
2606 | if ((status & SS_ERRMASK) == EBUSY) { | ||
2607 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY); | ||
2608 | break; | ||
2609 | } | ||
2610 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
2611 | if (ahd_cmd_get_transaction_status(cmd) | ||
2612 | == CAM_REQUEUE_REQ) { | ||
2613 | targ->dv_state_retry--; | ||
2614 | } else if ((status & SSQ_FALLBACK) != 0) { | ||
2615 | if (ahd_linux_dv_fallback(ahd, devinfo) != 0) { | ||
2616 | AHD_SET_DV_STATE(ahd, targ, | ||
2617 | AHD_DV_STATE_EXIT); | ||
2618 | break; | ||
2619 | } | ||
2620 | /* | ||
2621 | * Do not count "falling back" | ||
2622 | * against our retries. | ||
2623 | */ | ||
2624 | targ->dv_state_retry = 0; | ||
2625 | } | ||
2626 | if (targ->dv_state_retry >= 10) { | ||
2627 | #ifdef AHD_DEBUG | ||
2628 | if (ahd_debug & AHD_SHOW_DV) { | ||
2629 | ahd_print_devinfo(ahd, devinfo); | ||
2630 | printf("DV TUR reties exhausted\n"); | ||
2631 | } | ||
2632 | #endif | ||
2633 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2634 | break; | ||
2635 | } | ||
2636 | if (status & SSQ_DELAY) | ||
2637 | ssleep(1); | ||
2638 | |||
2639 | break; | ||
2640 | case SS_START: | ||
2641 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_SU); | ||
2642 | break; | ||
2643 | case SS_INQ_REFRESH: | ||
2644 | AHD_SET_DV_STATE(ahd, targ, | ||
2645 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2646 | break; | ||
2647 | default: | ||
2648 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2649 | break; | ||
2650 | } | ||
2651 | break; | 1344 | break; |
2652 | 1345 | case AHD_DEV_Q_TAGGED: | |
2653 | case AHD_DV_STATE_REBD: | 1346 | scsi_adjust_queue_depth(sdev, |
2654 | switch (status & SS_MASK) { | 1347 | MSG_ORDERED_TASK, |
2655 | case SS_NOP: | 1348 | dev->openings + dev->active); |
2656 | { | ||
2657 | uint32_t echo_size; | ||
2658 | |||
2659 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_WEB); | ||
2660 | echo_size = scsi_3btoul(&targ->dv_buffer[1]); | ||
2661 | echo_size &= 0x1FFF; | ||
2662 | #ifdef AHD_DEBUG | ||
2663 | if (ahd_debug & AHD_SHOW_DV) { | ||
2664 | ahd_print_devinfo(ahd, devinfo); | ||
2665 | printf("Echo buffer size= %d\n", echo_size); | ||
2666 | } | ||
2667 | #endif | ||
2668 | if (echo_size == 0) { | ||
2669 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2670 | break; | ||
2671 | } | ||
2672 | |||
2673 | /* Generate the buffer pattern */ | ||
2674 | targ->dv_echo_size = echo_size; | ||
2675 | ahd_linux_generate_dv_pattern(targ); | ||
2676 | /* | ||
2677 | * Setup initial negotiation values. | ||
2678 | */ | ||
2679 | ahd_linux_filter_inquiry(ahd, devinfo); | ||
2680 | break; | ||
2681 | } | ||
2682 | case SS_INQ_REFRESH: | ||
2683 | AHD_SET_DV_STATE(ahd, targ, | ||
2684 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2685 | break; | ||
2686 | case SS_RETRY: | ||
2687 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
2688 | if (ahd_cmd_get_transaction_status(cmd) | ||
2689 | == CAM_REQUEUE_REQ) | ||
2690 | targ->dv_state_retry--; | ||
2691 | if (targ->dv_state_retry <= 10) | ||
2692 | break; | ||
2693 | #ifdef AHD_DEBUG | ||
2694 | if (ahd_debug & AHD_SHOW_DV) { | ||
2695 | ahd_print_devinfo(ahd, devinfo); | ||
2696 | printf("DV REBD reties exhausted\n"); | ||
2697 | } | ||
2698 | #endif | ||
2699 | /* FALLTHROUGH */ | ||
2700 | case SS_FATAL: | ||
2701 | default: | ||
2702 | /* | ||
2703 | * Setup initial negotiation values | ||
2704 | * and try level 1 DV. | ||
2705 | */ | ||
2706 | ahd_linux_filter_inquiry(ahd, devinfo); | ||
2707 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_INQ_VERIFY); | ||
2708 | targ->dv_echo_size = 0; | ||
2709 | break; | ||
2710 | } | ||
2711 | break; | 1349 | break; |
2712 | |||
2713 | case AHD_DV_STATE_WEB: | ||
2714 | switch (status & SS_MASK) { | ||
2715 | case SS_NOP: | ||
2716 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_REB); | ||
2717 | break; | ||
2718 | case SS_INQ_REFRESH: | ||
2719 | AHD_SET_DV_STATE(ahd, targ, | ||
2720 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2721 | break; | ||
2722 | case SS_RETRY: | ||
2723 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
2724 | if (ahd_cmd_get_transaction_status(cmd) | ||
2725 | == CAM_REQUEUE_REQ) { | ||
2726 | targ->dv_state_retry--; | ||
2727 | } else if ((status & SSQ_FALLBACK) != 0) { | ||
2728 | if (ahd_linux_dv_fallback(ahd, devinfo) != 0) { | ||
2729 | AHD_SET_DV_STATE(ahd, targ, | ||
2730 | AHD_DV_STATE_EXIT); | ||
2731 | break; | ||
2732 | } | ||
2733 | /* | ||
2734 | * Do not count "falling back" | ||
2735 | * against our retries. | ||
2736 | */ | ||
2737 | targ->dv_state_retry = 0; | ||
2738 | } | ||
2739 | if (targ->dv_state_retry <= 10) | ||
2740 | break; | ||
2741 | /* FALLTHROUGH */ | ||
2742 | #ifdef AHD_DEBUG | ||
2743 | if (ahd_debug & AHD_SHOW_DV) { | ||
2744 | ahd_print_devinfo(ahd, devinfo); | ||
2745 | printf("DV WEB reties exhausted\n"); | ||
2746 | } | ||
2747 | #endif | ||
2748 | default: | ||
2749 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2750 | break; | ||
2751 | } | ||
2752 | break; | ||
2753 | |||
2754 | case AHD_DV_STATE_REB: | ||
2755 | switch (status & SS_MASK) { | ||
2756 | case SS_NOP: | ||
2757 | if (memcmp(targ->dv_buffer, targ->dv_buffer1, | ||
2758 | targ->dv_echo_size) != 0) { | ||
2759 | if (ahd_linux_dv_fallback(ahd, devinfo) != 0) | ||
2760 | AHD_SET_DV_STATE(ahd, targ, | ||
2761 | AHD_DV_STATE_EXIT); | ||
2762 | else | ||
2763 | AHD_SET_DV_STATE(ahd, targ, | ||
2764 | AHD_DV_STATE_WEB); | ||
2765 | break; | ||
2766 | } | ||
2767 | |||
2768 | if (targ->dv_buffer != NULL) { | ||
2769 | free(targ->dv_buffer, M_DEVBUF); | ||
2770 | targ->dv_buffer = NULL; | ||
2771 | } | ||
2772 | if (targ->dv_buffer1 != NULL) { | ||
2773 | free(targ->dv_buffer1, M_DEVBUF); | ||
2774 | targ->dv_buffer1 = NULL; | ||
2775 | } | ||
2776 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2777 | break; | ||
2778 | case SS_INQ_REFRESH: | ||
2779 | AHD_SET_DV_STATE(ahd, targ, | ||
2780 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2781 | break; | ||
2782 | case SS_RETRY: | ||
2783 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
2784 | if (ahd_cmd_get_transaction_status(cmd) | ||
2785 | == CAM_REQUEUE_REQ) { | ||
2786 | targ->dv_state_retry--; | ||
2787 | } else if ((status & SSQ_FALLBACK) != 0) { | ||
2788 | if (ahd_linux_dv_fallback(ahd, devinfo) != 0) { | ||
2789 | AHD_SET_DV_STATE(ahd, targ, | ||
2790 | AHD_DV_STATE_EXIT); | ||
2791 | break; | ||
2792 | } | ||
2793 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_WEB); | ||
2794 | } | ||
2795 | if (targ->dv_state_retry <= 10) { | ||
2796 | if ((status & (SSQ_DELAY_RANDOM|SSQ_DELAY))!= 0) | ||
2797 | msleep(ahd->our_id*1000/10); | ||
2798 | break; | ||
2799 | } | ||
2800 | #ifdef AHD_DEBUG | ||
2801 | if (ahd_debug & AHD_SHOW_DV) { | ||
2802 | ahd_print_devinfo(ahd, devinfo); | ||
2803 | printf("DV REB reties exhausted\n"); | ||
2804 | } | ||
2805 | #endif | ||
2806 | /* FALLTHROUGH */ | ||
2807 | default: | ||
2808 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2809 | break; | ||
2810 | } | ||
2811 | break; | ||
2812 | |||
2813 | case AHD_DV_STATE_SU: | ||
2814 | switch (status & SS_MASK) { | ||
2815 | case SS_NOP: | ||
2816 | case SS_INQ_REFRESH: | ||
2817 | AHD_SET_DV_STATE(ahd, targ, | ||
2818 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2819 | break; | ||
2820 | default: | ||
2821 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2822 | break; | ||
2823 | } | ||
2824 | break; | ||
2825 | |||
2826 | case AHD_DV_STATE_BUSY: | ||
2827 | switch (status & SS_MASK) { | ||
2828 | case SS_NOP: | ||
2829 | case SS_INQ_REFRESH: | ||
2830 | AHD_SET_DV_STATE(ahd, targ, | ||
2831 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2832 | break; | ||
2833 | case SS_TUR: | ||
2834 | case SS_RETRY: | ||
2835 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
2836 | if (ahd_cmd_get_transaction_status(cmd) | ||
2837 | == CAM_REQUEUE_REQ) { | ||
2838 | targ->dv_state_retry--; | ||
2839 | } else if (targ->dv_state_retry < 60) { | ||
2840 | if ((status & SSQ_DELAY) != 0) | ||
2841 | ssleep(1); | ||
2842 | } else { | ||
2843 | #ifdef AHD_DEBUG | ||
2844 | if (ahd_debug & AHD_SHOW_DV) { | ||
2845 | ahd_print_devinfo(ahd, devinfo); | ||
2846 | printf("DV BUSY reties exhausted\n"); | ||
2847 | } | ||
2848 | #endif | ||
2849 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2850 | } | ||
2851 | break; | ||
2852 | default: | ||
2853 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2854 | break; | ||
2855 | } | ||
2856 | break; | ||
2857 | |||
2858 | default: | 1350 | default: |
2859 | printf("%s: Invalid DV completion state %d\n", ahd_name(ahd), | ||
2860 | targ->dv_state); | ||
2861 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2862 | break; | ||
2863 | } | ||
2864 | } | ||
2865 | |||
2866 | static void | ||
2867 | ahd_linux_dv_fill_cmd(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
2868 | struct ahd_devinfo *devinfo) | ||
2869 | { | ||
2870 | memset(cmd, 0, sizeof(struct scsi_cmnd)); | ||
2871 | cmd->device = ahd->platform_data->dv_scsi_dev; | ||
2872 | cmd->scsi_done = ahd_linux_dv_complete; | ||
2873 | } | ||
2874 | |||
2875 | /* | ||
2876 | * Synthesize an inquiry command. On the return trip, it'll be | ||
2877 | * sniffed and the device transfer settings set for us. | ||
2878 | */ | ||
2879 | static void | ||
2880 | ahd_linux_dv_inq(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
2881 | struct ahd_devinfo *devinfo, struct ahd_linux_target *targ, | ||
2882 | u_int request_length) | ||
2883 | { | ||
2884 | |||
2885 | #ifdef AHD_DEBUG | ||
2886 | if (ahd_debug & AHD_SHOW_DV) { | ||
2887 | ahd_print_devinfo(ahd, devinfo); | ||
2888 | printf("Sending INQ\n"); | ||
2889 | } | ||
2890 | #endif | ||
2891 | if (targ->inq_data == NULL) | ||
2892 | targ->inq_data = malloc(AHD_LINUX_DV_INQ_LEN, | ||
2893 | M_DEVBUF, M_WAITOK); | ||
2894 | if (targ->dv_state > AHD_DV_STATE_INQ_ASYNC) { | ||
2895 | if (targ->dv_buffer != NULL) | ||
2896 | free(targ->dv_buffer, M_DEVBUF); | ||
2897 | targ->dv_buffer = malloc(AHD_LINUX_DV_INQ_LEN, | ||
2898 | M_DEVBUF, M_WAITOK); | ||
2899 | } | ||
2900 | |||
2901 | ahd_linux_dv_fill_cmd(ahd, cmd, devinfo); | ||
2902 | cmd->sc_data_direction = DMA_FROM_DEVICE; | ||
2903 | cmd->cmd_len = 6; | ||
2904 | cmd->cmnd[0] = INQUIRY; | ||
2905 | cmd->cmnd[4] = request_length; | ||
2906 | cmd->request_bufflen = request_length; | ||
2907 | if (targ->dv_state > AHD_DV_STATE_INQ_ASYNC) | ||
2908 | cmd->request_buffer = targ->dv_buffer; | ||
2909 | else | ||
2910 | cmd->request_buffer = targ->inq_data; | ||
2911 | memset(cmd->request_buffer, 0, AHD_LINUX_DV_INQ_LEN); | ||
2912 | } | ||
2913 | |||
2914 | static void | ||
2915 | ahd_linux_dv_tur(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
2916 | struct ahd_devinfo *devinfo) | ||
2917 | { | ||
2918 | |||
2919 | #ifdef AHD_DEBUG | ||
2920 | if (ahd_debug & AHD_SHOW_DV) { | ||
2921 | ahd_print_devinfo(ahd, devinfo); | ||
2922 | printf("Sending TUR\n"); | ||
2923 | } | ||
2924 | #endif | ||
2925 | /* Do a TUR to clear out any non-fatal transitional state */ | ||
2926 | ahd_linux_dv_fill_cmd(ahd, cmd, devinfo); | ||
2927 | cmd->sc_data_direction = DMA_NONE; | ||
2928 | cmd->cmd_len = 6; | ||
2929 | cmd->cmnd[0] = TEST_UNIT_READY; | ||
2930 | } | ||
2931 | |||
2932 | #define AHD_REBD_LEN 4 | ||
2933 | |||
2934 | static void | ||
2935 | ahd_linux_dv_rebd(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
2936 | struct ahd_devinfo *devinfo, struct ahd_linux_target *targ) | ||
2937 | { | ||
2938 | |||
2939 | #ifdef AHD_DEBUG | ||
2940 | if (ahd_debug & AHD_SHOW_DV) { | ||
2941 | ahd_print_devinfo(ahd, devinfo); | ||
2942 | printf("Sending REBD\n"); | ||
2943 | } | ||
2944 | #endif | ||
2945 | if (targ->dv_buffer != NULL) | ||
2946 | free(targ->dv_buffer, M_DEVBUF); | ||
2947 | targ->dv_buffer = malloc(AHD_REBD_LEN, M_DEVBUF, M_WAITOK); | ||
2948 | ahd_linux_dv_fill_cmd(ahd, cmd, devinfo); | ||
2949 | cmd->sc_data_direction = DMA_FROM_DEVICE; | ||
2950 | cmd->cmd_len = 10; | ||
2951 | cmd->cmnd[0] = READ_BUFFER; | ||
2952 | cmd->cmnd[1] = 0x0b; | ||
2953 | scsi_ulto3b(AHD_REBD_LEN, &cmd->cmnd[6]); | ||
2954 | cmd->request_bufflen = AHD_REBD_LEN; | ||
2955 | cmd->underflow = cmd->request_bufflen; | ||
2956 | cmd->request_buffer = targ->dv_buffer; | ||
2957 | } | ||
2958 | |||
2959 | static void | ||
2960 | ahd_linux_dv_web(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
2961 | struct ahd_devinfo *devinfo, struct ahd_linux_target *targ) | ||
2962 | { | ||
2963 | |||
2964 | #ifdef AHD_DEBUG | ||
2965 | if (ahd_debug & AHD_SHOW_DV) { | ||
2966 | ahd_print_devinfo(ahd, devinfo); | ||
2967 | printf("Sending WEB\n"); | ||
2968 | } | ||
2969 | #endif | ||
2970 | ahd_linux_dv_fill_cmd(ahd, cmd, devinfo); | ||
2971 | cmd->sc_data_direction = DMA_TO_DEVICE; | ||
2972 | cmd->cmd_len = 10; | ||
2973 | cmd->cmnd[0] = WRITE_BUFFER; | ||
2974 | cmd->cmnd[1] = 0x0a; | ||
2975 | scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]); | ||
2976 | cmd->request_bufflen = targ->dv_echo_size; | ||
2977 | cmd->underflow = cmd->request_bufflen; | ||
2978 | cmd->request_buffer = targ->dv_buffer; | ||
2979 | } | ||
2980 | |||
2981 | static void | ||
2982 | ahd_linux_dv_reb(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
2983 | struct ahd_devinfo *devinfo, struct ahd_linux_target *targ) | ||
2984 | { | ||
2985 | |||
2986 | #ifdef AHD_DEBUG | ||
2987 | if (ahd_debug & AHD_SHOW_DV) { | ||
2988 | ahd_print_devinfo(ahd, devinfo); | ||
2989 | printf("Sending REB\n"); | ||
2990 | } | ||
2991 | #endif | ||
2992 | ahd_linux_dv_fill_cmd(ahd, cmd, devinfo); | ||
2993 | cmd->sc_data_direction = DMA_FROM_DEVICE; | ||
2994 | cmd->cmd_len = 10; | ||
2995 | cmd->cmnd[0] = READ_BUFFER; | ||
2996 | cmd->cmnd[1] = 0x0a; | ||
2997 | scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]); | ||
2998 | cmd->request_bufflen = targ->dv_echo_size; | ||
2999 | cmd->underflow = cmd->request_bufflen; | ||
3000 | cmd->request_buffer = targ->dv_buffer1; | ||
3001 | } | ||
3002 | |||
3003 | static void | ||
3004 | ahd_linux_dv_su(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
3005 | struct ahd_devinfo *devinfo, | ||
3006 | struct ahd_linux_target *targ) | ||
3007 | { | ||
3008 | u_int le; | ||
3009 | |||
3010 | le = SID_IS_REMOVABLE(targ->inq_data) ? SSS_LOEJ : 0; | ||
3011 | |||
3012 | #ifdef AHD_DEBUG | ||
3013 | if (ahd_debug & AHD_SHOW_DV) { | ||
3014 | ahd_print_devinfo(ahd, devinfo); | ||
3015 | printf("Sending SU\n"); | ||
3016 | } | ||
3017 | #endif | ||
3018 | ahd_linux_dv_fill_cmd(ahd, cmd, devinfo); | ||
3019 | cmd->sc_data_direction = DMA_NONE; | ||
3020 | cmd->cmd_len = 6; | ||
3021 | cmd->cmnd[0] = START_STOP_UNIT; | ||
3022 | cmd->cmnd[4] = le | SSS_START; | ||
3023 | } | ||
3024 | |||
3025 | static int | ||
3026 | ahd_linux_fallback(struct ahd_softc *ahd, struct ahd_devinfo *devinfo) | ||
3027 | { | ||
3028 | struct ahd_linux_target *targ; | ||
3029 | struct ahd_initiator_tinfo *tinfo; | ||
3030 | struct ahd_transinfo *goal; | ||
3031 | struct ahd_tmode_tstate *tstate; | ||
3032 | u_int width; | ||
3033 | u_int period; | ||
3034 | u_int offset; | ||
3035 | u_int ppr_options; | ||
3036 | u_int cur_speed; | ||
3037 | u_int wide_speed; | ||
3038 | u_int narrow_speed; | ||
3039 | u_int fallback_speed; | ||
3040 | |||
3041 | #ifdef AHD_DEBUG | ||
3042 | if (ahd_debug & AHD_SHOW_DV) { | ||
3043 | ahd_print_devinfo(ahd, devinfo); | ||
3044 | printf("Trying to fallback\n"); | ||
3045 | } | ||
3046 | #endif | ||
3047 | targ = ahd->platform_data->targets[devinfo->target_offset]; | ||
3048 | tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, | ||
3049 | devinfo->our_scsiid, | ||
3050 | devinfo->target, &tstate); | ||
3051 | goal = &tinfo->goal; | ||
3052 | width = goal->width; | ||
3053 | period = goal->period; | ||
3054 | offset = goal->offset; | ||
3055 | ppr_options = goal->ppr_options; | ||
3056 | if (offset == 0) | ||
3057 | period = AHD_ASYNC_XFER_PERIOD; | ||
3058 | if (targ->dv_next_narrow_period == 0) | ||
3059 | targ->dv_next_narrow_period = MAX(period, AHD_SYNCRATE_ULTRA2); | ||
3060 | if (targ->dv_next_wide_period == 0) | ||
3061 | targ->dv_next_wide_period = period; | ||
3062 | if (targ->dv_max_width == 0) | ||
3063 | targ->dv_max_width = width; | ||
3064 | if (targ->dv_max_ppr_options == 0) | ||
3065 | targ->dv_max_ppr_options = ppr_options; | ||
3066 | if (targ->dv_last_ppr_options == 0) | ||
3067 | targ->dv_last_ppr_options = ppr_options; | ||
3068 | |||
3069 | cur_speed = aic_calc_speed(width, period, offset, AHD_SYNCRATE_MIN); | ||
3070 | wide_speed = aic_calc_speed(MSG_EXT_WDTR_BUS_16_BIT, | ||
3071 | targ->dv_next_wide_period, | ||
3072 | MAX_OFFSET, AHD_SYNCRATE_MIN); | ||
3073 | narrow_speed = aic_calc_speed(MSG_EXT_WDTR_BUS_8_BIT, | ||
3074 | targ->dv_next_narrow_period, | ||
3075 | MAX_OFFSET, AHD_SYNCRATE_MIN); | ||
3076 | fallback_speed = aic_calc_speed(width, period+1, offset, | ||
3077 | AHD_SYNCRATE_MIN); | ||
3078 | #ifdef AHD_DEBUG | ||
3079 | if (ahd_debug & AHD_SHOW_DV) { | ||
3080 | printf("cur_speed= %d, wide_speed= %d, narrow_speed= %d, " | ||
3081 | "fallback_speed= %d\n", cur_speed, wide_speed, | ||
3082 | narrow_speed, fallback_speed); | ||
3083 | } | ||
3084 | #endif | ||
3085 | |||
3086 | if (cur_speed > 160000) { | ||
3087 | /* | ||
3088 | * Paced/DT/IU_REQ only transfer speeds. All we | ||
3089 | * can do is fallback in terms of syncrate. | ||
3090 | */ | ||
3091 | period++; | ||
3092 | } else if (cur_speed > 80000) { | ||
3093 | if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) { | ||
3094 | /* | ||
3095 | * Try without IU_REQ as it may be confusing | ||
3096 | * an expander. | ||
3097 | */ | ||
3098 | ppr_options &= ~MSG_EXT_PPR_IU_REQ; | ||
3099 | } else { | ||
3100 | /* | ||
3101 | * Paced/DT only transfer speeds. All we | ||
3102 | * can do is fallback in terms of syncrate. | ||
3103 | */ | ||
3104 | period++; | ||
3105 | ppr_options = targ->dv_max_ppr_options; | ||
3106 | } | ||
3107 | } else if (cur_speed > 3300) { | ||
3108 | |||
3109 | /* | 1351 | /* |
3110 | * In this range we the following | 1352 | * We allow the OS to queue 2 untagged transactions to |
3111 | * options ordered from highest to | 1353 | * us at any time even though we can only execute them |
3112 | * lowest desireability: | 1354 | * serially on the controller/device. This should |
3113 | * | 1355 | * remove some latency. |
3114 | * o Wide/DT | ||
3115 | * o Wide/non-DT | ||
3116 | * o Narrow at a potentally higher sync rate. | ||
3117 | * | ||
3118 | * All modes are tested with and without IU_REQ | ||
3119 | * set since using IUs may confuse an expander. | ||
3120 | */ | 1356 | */ |
3121 | if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) { | 1357 | scsi_adjust_queue_depth(sdev, |
3122 | 1358 | /*NON-TAGGED*/0, | |
3123 | ppr_options &= ~MSG_EXT_PPR_IU_REQ; | 1359 | /*queue depth*/2); |
3124 | } else if ((ppr_options & MSG_EXT_PPR_DT_REQ) != 0) { | 1360 | break; |
3125 | /* | ||
3126 | * Try going non-DT. | ||
3127 | */ | ||
3128 | ppr_options = targ->dv_max_ppr_options; | ||
3129 | ppr_options &= ~MSG_EXT_PPR_DT_REQ; | ||
3130 | } else if (targ->dv_last_ppr_options != 0) { | ||
3131 | /* | ||
3132 | * Try without QAS or any other PPR options. | ||
3133 | * We may need a non-PPR message to work with | ||
3134 | * an expander. We look at the "last PPR options" | ||
3135 | * so we will perform this fallback even if the | ||
3136 | * target responded to our PPR negotiation with | ||
3137 | * no option bits set. | ||
3138 | */ | ||
3139 | ppr_options = 0; | ||
3140 | } else if (width == MSG_EXT_WDTR_BUS_16_BIT) { | ||
3141 | /* | ||
3142 | * If the next narrow speed is greater than | ||
3143 | * the next wide speed, fallback to narrow. | ||
3144 | * Otherwise fallback to the next DT/Wide setting. | ||
3145 | * The narrow async speed will always be smaller | ||
3146 | * than the wide async speed, so handle this case | ||
3147 | * specifically. | ||
3148 | */ | ||
3149 | ppr_options = targ->dv_max_ppr_options; | ||
3150 | if (narrow_speed > fallback_speed | ||
3151 | || period >= AHD_ASYNC_XFER_PERIOD) { | ||
3152 | targ->dv_next_wide_period = period+1; | ||
3153 | width = MSG_EXT_WDTR_BUS_8_BIT; | ||
3154 | period = targ->dv_next_narrow_period; | ||
3155 | } else { | ||
3156 | period++; | ||
3157 | } | ||
3158 | } else if ((ahd->features & AHD_WIDE) != 0 | ||
3159 | && targ->dv_max_width != 0 | ||
3160 | && wide_speed >= fallback_speed | ||
3161 | && (targ->dv_next_wide_period <= AHD_ASYNC_XFER_PERIOD | ||
3162 | || period >= AHD_ASYNC_XFER_PERIOD)) { | ||
3163 | |||
3164 | /* | ||
3165 | * We are narrow. Try falling back | ||
3166 | * to the next wide speed with | ||
3167 | * all supported ppr options set. | ||
3168 | */ | ||
3169 | targ->dv_next_narrow_period = period+1; | ||
3170 | width = MSG_EXT_WDTR_BUS_16_BIT; | ||
3171 | period = targ->dv_next_wide_period; | ||
3172 | ppr_options = targ->dv_max_ppr_options; | ||
3173 | } else { | ||
3174 | /* Only narrow fallback is allowed. */ | ||
3175 | period++; | ||
3176 | ppr_options = targ->dv_max_ppr_options; | ||
3177 | } | ||
3178 | } else { | ||
3179 | return (-1); | ||
3180 | } | ||
3181 | offset = MAX_OFFSET; | ||
3182 | ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_PACED); | ||
3183 | ahd_set_width(ahd, devinfo, width, AHD_TRANS_GOAL, FALSE); | ||
3184 | if (period == 0) { | ||
3185 | period = 0; | ||
3186 | offset = 0; | ||
3187 | ppr_options = 0; | ||
3188 | if (width == MSG_EXT_WDTR_BUS_8_BIT) | ||
3189 | targ->dv_next_narrow_period = AHD_ASYNC_XFER_PERIOD; | ||
3190 | else | ||
3191 | targ->dv_next_wide_period = AHD_ASYNC_XFER_PERIOD; | ||
3192 | } | ||
3193 | ahd_set_syncrate(ahd, devinfo, period, offset, | ||
3194 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
3195 | targ->dv_last_ppr_options = ppr_options; | ||
3196 | return (0); | ||
3197 | } | ||
3198 | |||
3199 | static void | ||
3200 | ahd_linux_dv_timeout(struct scsi_cmnd *cmd) | ||
3201 | { | ||
3202 | struct ahd_softc *ahd; | ||
3203 | struct scb *scb; | ||
3204 | u_long flags; | ||
3205 | |||
3206 | ahd = *((struct ahd_softc **)cmd->device->host->hostdata); | ||
3207 | ahd_lock(ahd, &flags); | ||
3208 | |||
3209 | #ifdef AHD_DEBUG | ||
3210 | if (ahd_debug & AHD_SHOW_DV) { | ||
3211 | printf("%s: Timeout while doing DV command %x.\n", | ||
3212 | ahd_name(ahd), cmd->cmnd[0]); | ||
3213 | ahd_dump_card_state(ahd); | ||
3214 | } | ||
3215 | #endif | ||
3216 | |||
3217 | /* | ||
3218 | * Guard against "done race". No action is | ||
3219 | * required if we just completed. | ||
3220 | */ | ||
3221 | if ((scb = (struct scb *)cmd->host_scribble) == NULL) { | ||
3222 | ahd_unlock(ahd, &flags); | ||
3223 | return; | ||
3224 | } | 1361 | } |
3225 | |||
3226 | /* | ||
3227 | * Command has not completed. Mark this | ||
3228 | * SCB as having failing status prior to | ||
3229 | * resetting the bus, so we get the correct | ||
3230 | * error code. | ||
3231 | */ | ||
3232 | if ((scb->flags & SCB_SENSE) != 0) | ||
3233 | ahd_set_transaction_status(scb, CAM_AUTOSENSE_FAIL); | ||
3234 | else | ||
3235 | ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT); | ||
3236 | ahd_reset_channel(ahd, cmd->device->channel + 'A', /*initiate*/TRUE); | ||
3237 | |||
3238 | /* | ||
3239 | * Add a minimal bus settle delay for devices that are slow to | ||
3240 | * respond after bus resets. | ||
3241 | */ | ||
3242 | ahd_freeze_simq(ahd); | ||
3243 | init_timer(&ahd->platform_data->reset_timer); | ||
3244 | ahd->platform_data->reset_timer.data = (u_long)ahd; | ||
3245 | ahd->platform_data->reset_timer.expires = jiffies + HZ / 2; | ||
3246 | ahd->platform_data->reset_timer.function = | ||
3247 | (ahd_linux_callback_t *)ahd_release_simq; | ||
3248 | add_timer(&ahd->platform_data->reset_timer); | ||
3249 | ahd_linux_run_complete_queue(ahd); | ||
3250 | ahd_unlock(ahd, &flags); | ||
3251 | } | 1362 | } |
3252 | 1363 | ||
3253 | static void | 1364 | int |
3254 | ahd_linux_dv_complete(struct scsi_cmnd *cmd) | 1365 | ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel, |
3255 | { | 1366 | int lun, u_int tag, role_t role, uint32_t status) |
3256 | struct ahd_softc *ahd; | ||
3257 | |||
3258 | ahd = *((struct ahd_softc **)cmd->device->host->hostdata); | ||
3259 | |||
3260 | /* Delete the DV timer before it goes off! */ | ||
3261 | scsi_delete_timer(cmd); | ||
3262 | |||
3263 | #ifdef AHD_DEBUG | ||
3264 | if (ahd_debug & AHD_SHOW_DV) | ||
3265 | printf("%s:%c:%d: Command completed, status= 0x%x\n", | ||
3266 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
3267 | cmd->result); | ||
3268 | #endif | ||
3269 | |||
3270 | /* Wake up the state machine */ | ||
3271 | up(&ahd->platform_data->dv_cmd_sem); | ||
3272 | } | ||
3273 | |||
3274 | static void | ||
3275 | ahd_linux_generate_dv_pattern(struct ahd_linux_target *targ) | ||
3276 | { | 1367 | { |
3277 | uint16_t b; | 1368 | return 0; |
3278 | u_int i; | ||
3279 | u_int j; | ||
3280 | |||
3281 | if (targ->dv_buffer != NULL) | ||
3282 | free(targ->dv_buffer, M_DEVBUF); | ||
3283 | targ->dv_buffer = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK); | ||
3284 | if (targ->dv_buffer1 != NULL) | ||
3285 | free(targ->dv_buffer1, M_DEVBUF); | ||
3286 | targ->dv_buffer1 = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK); | ||
3287 | |||
3288 | i = 0; | ||
3289 | |||
3290 | b = 0x0001; | ||
3291 | for (j = 0 ; i < targ->dv_echo_size; j++) { | ||
3292 | if (j < 32) { | ||
3293 | /* | ||
3294 | * 32bytes of sequential numbers. | ||
3295 | */ | ||
3296 | targ->dv_buffer[i++] = j & 0xff; | ||
3297 | } else if (j < 48) { | ||
3298 | /* | ||
3299 | * 32bytes of repeating 0x0000, 0xffff. | ||
3300 | */ | ||
3301 | targ->dv_buffer[i++] = (j & 0x02) ? 0xff : 0x00; | ||
3302 | } else if (j < 64) { | ||
3303 | /* | ||
3304 | * 32bytes of repeating 0x5555, 0xaaaa. | ||
3305 | */ | ||
3306 | targ->dv_buffer[i++] = (j & 0x02) ? 0xaa : 0x55; | ||
3307 | } else { | ||
3308 | /* | ||
3309 | * Remaining buffer is filled with a repeating | ||
3310 | * patter of: | ||
3311 | * | ||
3312 | * 0xffff | ||
3313 | * ~0x0001 << shifted once in each loop. | ||
3314 | */ | ||
3315 | if (j & 0x02) { | ||
3316 | if (j & 0x01) { | ||
3317 | targ->dv_buffer[i++] = ~(b >> 8) & 0xff; | ||
3318 | b <<= 1; | ||
3319 | if (b == 0x0000) | ||
3320 | b = 0x0001; | ||
3321 | } else { | ||
3322 | targ->dv_buffer[i++] = (~b & 0xff); | ||
3323 | } | ||
3324 | } else { | ||
3325 | targ->dv_buffer[i++] = 0xff; | ||
3326 | } | ||
3327 | } | ||
3328 | } | ||
3329 | } | 1369 | } |
3330 | 1370 | ||
3331 | static u_int | 1371 | static u_int |
@@ -3359,100 +1399,23 @@ ahd_linux_user_tagdepth(struct ahd_softc *ahd, struct ahd_devinfo *devinfo) | |||
3359 | return (tags); | 1399 | return (tags); |
3360 | } | 1400 | } |
3361 | 1401 | ||
3362 | static u_int | ||
3363 | ahd_linux_user_dv_setting(struct ahd_softc *ahd) | ||
3364 | { | ||
3365 | static int warned_user; | ||
3366 | int dv; | ||
3367 | |||
3368 | if (ahd->unit >= NUM_ELEMENTS(aic79xx_dv_settings)) { | ||
3369 | |||
3370 | if (warned_user == 0) { | ||
3371 | printf(KERN_WARNING | ||
3372 | "aic79xx: WARNING: Insufficient dv settings instances\n" | ||
3373 | "aic79xx: for installed controllers. Using defaults\n" | ||
3374 | "aic79xx: Please update the aic79xx_dv_settings array in" | ||
3375 | "aic79xx: the aic79xx_osm.c source file.\n"); | ||
3376 | warned_user++; | ||
3377 | } | ||
3378 | dv = -1; | ||
3379 | } else { | ||
3380 | |||
3381 | dv = aic79xx_dv_settings[ahd->unit]; | ||
3382 | } | ||
3383 | |||
3384 | if (dv < 0) { | ||
3385 | /* | ||
3386 | * Apply the default. | ||
3387 | */ | ||
3388 | dv = 1; | ||
3389 | if (ahd->seep_config != 0) | ||
3390 | dv = (ahd->seep_config->bios_control & CFENABLEDV); | ||
3391 | } | ||
3392 | return (dv); | ||
3393 | } | ||
3394 | |||
3395 | static void | ||
3396 | ahd_linux_setup_user_rd_strm_settings(struct ahd_softc *ahd) | ||
3397 | { | ||
3398 | static int warned_user; | ||
3399 | u_int rd_strm_mask; | ||
3400 | u_int target_id; | ||
3401 | |||
3402 | /* | ||
3403 | * If we have specific read streaming info for this controller, | ||
3404 | * apply it. Otherwise use the defaults. | ||
3405 | */ | ||
3406 | if (ahd->unit >= NUM_ELEMENTS(aic79xx_rd_strm_info)) { | ||
3407 | |||
3408 | if (warned_user == 0) { | ||
3409 | |||
3410 | printf(KERN_WARNING | ||
3411 | "aic79xx: WARNING: Insufficient rd_strm instances\n" | ||
3412 | "aic79xx: for installed controllers. Using defaults\n" | ||
3413 | "aic79xx: Please update the aic79xx_rd_strm_info array\n" | ||
3414 | "aic79xx: in the aic79xx_osm.c source file.\n"); | ||
3415 | warned_user++; | ||
3416 | } | ||
3417 | rd_strm_mask = AIC79XX_CONFIGED_RD_STRM; | ||
3418 | } else { | ||
3419 | |||
3420 | rd_strm_mask = aic79xx_rd_strm_info[ahd->unit]; | ||
3421 | } | ||
3422 | for (target_id = 0; target_id < 16; target_id++) { | ||
3423 | struct ahd_devinfo devinfo; | ||
3424 | struct ahd_initiator_tinfo *tinfo; | ||
3425 | struct ahd_tmode_tstate *tstate; | ||
3426 | |||
3427 | tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id, | ||
3428 | target_id, &tstate); | ||
3429 | ahd_compile_devinfo(&devinfo, ahd->our_id, target_id, | ||
3430 | CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR); | ||
3431 | tinfo->user.ppr_options &= ~MSG_EXT_PPR_RD_STRM; | ||
3432 | if ((rd_strm_mask & devinfo.target_mask) != 0) | ||
3433 | tinfo->user.ppr_options |= MSG_EXT_PPR_RD_STRM; | ||
3434 | } | ||
3435 | } | ||
3436 | |||
3437 | /* | 1402 | /* |
3438 | * Determines the queue depth for a given device. | 1403 | * Determines the queue depth for a given device. |
3439 | */ | 1404 | */ |
3440 | static void | 1405 | static void |
3441 | ahd_linux_device_queue_depth(struct ahd_softc *ahd, | 1406 | ahd_linux_device_queue_depth(struct scsi_device *sdev) |
3442 | struct ahd_linux_device *dev) | ||
3443 | { | 1407 | { |
3444 | struct ahd_devinfo devinfo; | 1408 | struct ahd_devinfo devinfo; |
3445 | u_int tags; | 1409 | u_int tags; |
1410 | struct ahd_softc *ahd = *((struct ahd_softc **)sdev->host->hostdata); | ||
3446 | 1411 | ||
3447 | ahd_compile_devinfo(&devinfo, | 1412 | ahd_compile_devinfo(&devinfo, |
3448 | ahd->our_id, | 1413 | ahd->our_id, |
3449 | dev->target->target, dev->lun, | 1414 | sdev->sdev_target->id, sdev->lun, |
3450 | dev->target->channel == 0 ? 'A' : 'B', | 1415 | sdev->sdev_target->channel == 0 ? 'A' : 'B', |
3451 | ROLE_INITIATOR); | 1416 | ROLE_INITIATOR); |
3452 | tags = ahd_linux_user_tagdepth(ahd, &devinfo); | 1417 | tags = ahd_linux_user_tagdepth(ahd, &devinfo); |
3453 | if (tags != 0 | 1418 | if (tags != 0 && sdev->tagged_supported != 0) { |
3454 | && dev->scsi_device != NULL | ||
3455 | && dev->scsi_device->tagged_supported != 0) { | ||
3456 | 1419 | ||
3457 | ahd_set_tags(ahd, &devinfo, AHD_QUEUE_TAGGED); | 1420 | ahd_set_tags(ahd, &devinfo, AHD_QUEUE_TAGGED); |
3458 | ahd_print_devinfo(ahd, &devinfo); | 1421 | ahd_print_devinfo(ahd, &devinfo); |
@@ -3507,9 +1470,6 @@ ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev, | |||
3507 | if ((ahd->user_discenable & mask) != 0) | 1470 | if ((ahd->user_discenable & mask) != 0) |
3508 | hscb->control |= DISCENB; | 1471 | hscb->control |= DISCENB; |
3509 | 1472 | ||
3510 | if (AHD_DV_CMD(cmd) != 0) | ||
3511 | scb->flags |= SCB_SILENT; | ||
3512 | |||
3513 | if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) | 1473 | if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) |
3514 | scb->flags |= SCB_PACKETIZED; | 1474 | scb->flags |= SCB_PACKETIZED; |
3515 | 1475 | ||
@@ -3540,9 +1500,10 @@ ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev, | |||
3540 | hscb->cdb_len = cmd->cmd_len; | 1500 | hscb->cdb_len = cmd->cmd_len; |
3541 | memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len); | 1501 | memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len); |
3542 | 1502 | ||
3543 | scb->sg_count = 0; | 1503 | scb->platform_data->xfer_len = 0; |
3544 | ahd_set_residual(scb, 0); | 1504 | ahd_set_residual(scb, 0); |
3545 | ahd_set_sense_residual(scb, 0); | 1505 | ahd_set_sense_residual(scb, 0); |
1506 | scb->sg_count = 0; | ||
3546 | if (cmd->use_sg != 0) { | 1507 | if (cmd->use_sg != 0) { |
3547 | void *sg; | 1508 | void *sg; |
3548 | struct scatterlist *cur_seg; | 1509 | struct scatterlist *cur_seg; |
@@ -3585,14 +1546,6 @@ ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev, | |||
3585 | dev->active++; | 1546 | dev->active++; |
3586 | dev->commands_issued++; | 1547 | dev->commands_issued++; |
3587 | 1548 | ||
3588 | /* Update the error counting bucket and dump if needed */ | ||
3589 | if (dev->target->cmds_since_error) { | ||
3590 | dev->target->cmds_since_error++; | ||
3591 | if (dev->target->cmds_since_error > | ||
3592 | AHD_LINUX_ERR_THRESH) | ||
3593 | dev->target->cmds_since_error = 0; | ||
3594 | } | ||
3595 | |||
3596 | if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0) | 1549 | if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0) |
3597 | dev->commands_since_idle_or_otag++; | 1550 | dev->commands_since_idle_or_otag++; |
3598 | scb->flags |= SCB_ACTIVE; | 1551 | scb->flags |= SCB_ACTIVE; |
@@ -3614,7 +1567,6 @@ ahd_linux_isr(int irq, void *dev_id, struct pt_regs * regs) | |||
3614 | ahd = (struct ahd_softc *) dev_id; | 1567 | ahd = (struct ahd_softc *) dev_id; |
3615 | ahd_lock(ahd, &flags); | 1568 | ahd_lock(ahd, &flags); |
3616 | ours = ahd_intr(ahd); | 1569 | ours = ahd_intr(ahd); |
3617 | ahd_linux_run_complete_queue(ahd); | ||
3618 | ahd_unlock(ahd, &flags); | 1570 | ahd_unlock(ahd, &flags); |
3619 | return IRQ_RETVAL(ours); | 1571 | return IRQ_RETVAL(ours); |
3620 | } | 1572 | } |
@@ -3623,110 +1575,6 @@ void | |||
3623 | ahd_platform_flushwork(struct ahd_softc *ahd) | 1575 | ahd_platform_flushwork(struct ahd_softc *ahd) |
3624 | { | 1576 | { |
3625 | 1577 | ||
3626 | while (ahd_linux_run_complete_queue(ahd) != NULL) | ||
3627 | ; | ||
3628 | } | ||
3629 | |||
3630 | static struct ahd_linux_target* | ||
3631 | ahd_linux_alloc_target(struct ahd_softc *ahd, u_int channel, u_int target) | ||
3632 | { | ||
3633 | struct ahd_linux_target *targ; | ||
3634 | |||
3635 | targ = malloc(sizeof(*targ), M_DEVBUF, M_NOWAIT); | ||
3636 | if (targ == NULL) | ||
3637 | return (NULL); | ||
3638 | memset(targ, 0, sizeof(*targ)); | ||
3639 | targ->channel = channel; | ||
3640 | targ->target = target; | ||
3641 | targ->ahd = ahd; | ||
3642 | targ->flags = AHD_DV_REQUIRED; | ||
3643 | ahd->platform_data->targets[target] = targ; | ||
3644 | return (targ); | ||
3645 | } | ||
3646 | |||
3647 | static void | ||
3648 | ahd_linux_free_target(struct ahd_softc *ahd, struct ahd_linux_target *targ) | ||
3649 | { | ||
3650 | struct ahd_devinfo devinfo; | ||
3651 | struct ahd_initiator_tinfo *tinfo; | ||
3652 | struct ahd_tmode_tstate *tstate; | ||
3653 | u_int our_id; | ||
3654 | u_int target_offset; | ||
3655 | char channel; | ||
3656 | |||
3657 | /* | ||
3658 | * Force a negotiation to async/narrow on any | ||
3659 | * future command to this device unless a bus | ||
3660 | * reset occurs between now and that command. | ||
3661 | */ | ||
3662 | channel = 'A' + targ->channel; | ||
3663 | our_id = ahd->our_id; | ||
3664 | target_offset = targ->target; | ||
3665 | tinfo = ahd_fetch_transinfo(ahd, channel, our_id, | ||
3666 | targ->target, &tstate); | ||
3667 | ahd_compile_devinfo(&devinfo, our_id, targ->target, CAM_LUN_WILDCARD, | ||
3668 | channel, ROLE_INITIATOR); | ||
3669 | ahd_set_syncrate(ahd, &devinfo, 0, 0, 0, | ||
3670 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
3671 | ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT, | ||
3672 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
3673 | ahd_update_neg_request(ahd, &devinfo, tstate, tinfo, AHD_NEG_ALWAYS); | ||
3674 | ahd->platform_data->targets[target_offset] = NULL; | ||
3675 | if (targ->inq_data != NULL) | ||
3676 | free(targ->inq_data, M_DEVBUF); | ||
3677 | if (targ->dv_buffer != NULL) | ||
3678 | free(targ->dv_buffer, M_DEVBUF); | ||
3679 | if (targ->dv_buffer1 != NULL) | ||
3680 | free(targ->dv_buffer1, M_DEVBUF); | ||
3681 | free(targ, M_DEVBUF); | ||
3682 | } | ||
3683 | |||
3684 | static struct ahd_linux_device* | ||
3685 | ahd_linux_alloc_device(struct ahd_softc *ahd, | ||
3686 | struct ahd_linux_target *targ, u_int lun) | ||
3687 | { | ||
3688 | struct ahd_linux_device *dev; | ||
3689 | |||
3690 | dev = malloc(sizeof(*dev), M_DEVBUG, M_NOWAIT); | ||
3691 | if (dev == NULL) | ||
3692 | return (NULL); | ||
3693 | memset(dev, 0, sizeof(*dev)); | ||
3694 | init_timer(&dev->timer); | ||
3695 | dev->flags = AHD_DEV_UNCONFIGURED; | ||
3696 | dev->lun = lun; | ||
3697 | dev->target = targ; | ||
3698 | |||
3699 | /* | ||
3700 | * We start out life using untagged | ||
3701 | * transactions of which we allow one. | ||
3702 | */ | ||
3703 | dev->openings = 1; | ||
3704 | |||
3705 | /* | ||
3706 | * Set maxtags to 0. This will be changed if we | ||
3707 | * later determine that we are dealing with | ||
3708 | * a tagged queuing capable device. | ||
3709 | */ | ||
3710 | dev->maxtags = 0; | ||
3711 | |||
3712 | targ->refcount++; | ||
3713 | targ->devices[lun] = dev; | ||
3714 | return (dev); | ||
3715 | } | ||
3716 | |||
3717 | static void | ||
3718 | ahd_linux_free_device(struct ahd_softc *ahd, struct ahd_linux_device *dev) | ||
3719 | { | ||
3720 | struct ahd_linux_target *targ; | ||
3721 | |||
3722 | del_timer(&dev->timer); | ||
3723 | targ = dev->target; | ||
3724 | targ->devices[dev->lun] = NULL; | ||
3725 | free(dev, M_DEVBUF); | ||
3726 | targ->refcount--; | ||
3727 | if (targ->refcount == 0 | ||
3728 | && (targ->flags & AHD_DV_REQUIRED) == 0) | ||
3729 | ahd_linux_free_target(ahd, targ); | ||
3730 | } | 1578 | } |
3731 | 1579 | ||
3732 | void | 1580 | void |
@@ -3737,10 +1585,14 @@ ahd_send_async(struct ahd_softc *ahd, char channel, | |||
3737 | case AC_TRANSFER_NEG: | 1585 | case AC_TRANSFER_NEG: |
3738 | { | 1586 | { |
3739 | char buf[80]; | 1587 | char buf[80]; |
1588 | struct scsi_target *starget; | ||
3740 | struct ahd_linux_target *targ; | 1589 | struct ahd_linux_target *targ; |
3741 | struct info_str info; | 1590 | struct info_str info; |
3742 | struct ahd_initiator_tinfo *tinfo; | 1591 | struct ahd_initiator_tinfo *tinfo; |
3743 | struct ahd_tmode_tstate *tstate; | 1592 | struct ahd_tmode_tstate *tstate; |
1593 | unsigned int target_ppr_options; | ||
1594 | |||
1595 | BUG_ON(target == CAM_TARGET_WILDCARD); | ||
3744 | 1596 | ||
3745 | info.buffer = buf; | 1597 | info.buffer = buf; |
3746 | info.length = sizeof(buf); | 1598 | info.length = sizeof(buf); |
@@ -3764,32 +1616,30 @@ ahd_send_async(struct ahd_softc *ahd, char channel, | |||
3764 | * Don't bother reporting results that | 1616 | * Don't bother reporting results that |
3765 | * are identical to those last reported. | 1617 | * are identical to those last reported. |
3766 | */ | 1618 | */ |
3767 | targ = ahd->platform_data->targets[target]; | 1619 | starget = ahd->platform_data->starget[target]; |
1620 | targ = scsi_transport_target_data(starget); | ||
3768 | if (targ == NULL) | 1621 | if (targ == NULL) |
3769 | break; | 1622 | break; |
3770 | if (tinfo->curr.period == targ->last_tinfo.period | 1623 | |
3771 | && tinfo->curr.width == targ->last_tinfo.width | 1624 | target_ppr_options = |
3772 | && tinfo->curr.offset == targ->last_tinfo.offset | 1625 | (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0) |
3773 | && tinfo->curr.ppr_options == targ->last_tinfo.ppr_options) | 1626 | + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0) |
1627 | + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0); | ||
1628 | |||
1629 | if (tinfo->curr.period == spi_period(starget) | ||
1630 | && tinfo->curr.width == spi_width(starget) | ||
1631 | && tinfo->curr.offset == spi_offset(starget) | ||
1632 | && tinfo->curr.ppr_options == target_ppr_options) | ||
3774 | if (bootverbose == 0) | 1633 | if (bootverbose == 0) |
3775 | break; | 1634 | break; |
3776 | 1635 | ||
3777 | targ->last_tinfo.period = tinfo->curr.period; | 1636 | spi_period(starget) = tinfo->curr.period; |
3778 | targ->last_tinfo.width = tinfo->curr.width; | 1637 | spi_width(starget) = tinfo->curr.width; |
3779 | targ->last_tinfo.offset = tinfo->curr.offset; | 1638 | spi_offset(starget) = tinfo->curr.offset; |
3780 | targ->last_tinfo.ppr_options = tinfo->curr.ppr_options; | 1639 | spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ; |
3781 | 1640 | spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ; | |
3782 | printf("(%s:%c:", ahd_name(ahd), channel); | 1641 | spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ; |
3783 | if (target == CAM_TARGET_WILDCARD) | 1642 | spi_display_xfer_agreement(starget); |
3784 | printf("*): "); | ||
3785 | else | ||
3786 | printf("%d): ", target); | ||
3787 | ahd_format_transinfo(&info, &tinfo->curr); | ||
3788 | if (info.pos < info.length) | ||
3789 | *info.buffer = '\0'; | ||
3790 | else | ||
3791 | buf[info.length - 1] = '\0'; | ||
3792 | printf("%s", buf); | ||
3793 | break; | 1643 | break; |
3794 | } | 1644 | } |
3795 | case AC_SENT_BDR: | 1645 | case AC_SENT_BDR: |
@@ -3816,7 +1666,7 @@ ahd_send_async(struct ahd_softc *ahd, char channel, | |||
3816 | void | 1666 | void |
3817 | ahd_done(struct ahd_softc *ahd, struct scb *scb) | 1667 | ahd_done(struct ahd_softc *ahd, struct scb *scb) |
3818 | { | 1668 | { |
3819 | Scsi_Cmnd *cmd; | 1669 | struct scsi_cmnd *cmd; |
3820 | struct ahd_linux_device *dev; | 1670 | struct ahd_linux_device *dev; |
3821 | 1671 | ||
3822 | if ((scb->flags & SCB_ACTIVE) == 0) { | 1672 | if ((scb->flags & SCB_ACTIVE) == 0) { |
@@ -3884,19 +1734,8 @@ ahd_done(struct ahd_softc *ahd, struct scb *scb) | |||
3884 | ahd_set_transaction_status(scb, CAM_REQ_CMP); | 1734 | ahd_set_transaction_status(scb, CAM_REQ_CMP); |
3885 | } | 1735 | } |
3886 | } else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) { | 1736 | } else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) { |
3887 | ahd_linux_handle_scsi_status(ahd, dev, scb); | 1737 | ahd_linux_handle_scsi_status(ahd, cmd->device, scb); |
3888 | } else if (ahd_get_transaction_status(scb) == CAM_SEL_TIMEOUT) { | ||
3889 | dev->flags |= AHD_DEV_UNCONFIGURED; | ||
3890 | if (AHD_DV_CMD(cmd) == FALSE) | ||
3891 | dev->target->flags &= ~AHD_DV_REQUIRED; | ||
3892 | } | 1738 | } |
3893 | /* | ||
3894 | * Start DV for devices that require it assuming the first command | ||
3895 | * sent does not result in a selection timeout. | ||
3896 | */ | ||
3897 | if (ahd_get_transaction_status(scb) != CAM_SEL_TIMEOUT | ||
3898 | && (dev->target->flags & AHD_DV_REQUIRED) != 0) | ||
3899 | ahd_linux_start_dv(ahd); | ||
3900 | 1739 | ||
3901 | if (dev->openings == 1 | 1740 | if (dev->openings == 1 |
3902 | && ahd_get_transaction_status(scb) == CAM_REQ_CMP | 1741 | && ahd_get_transaction_status(scb) == CAM_REQ_CMP |
@@ -3917,42 +1756,32 @@ ahd_done(struct ahd_softc *ahd, struct scb *scb) | |||
3917 | if (dev->active == 0) | 1756 | if (dev->active == 0) |
3918 | dev->commands_since_idle_or_otag = 0; | 1757 | dev->commands_since_idle_or_otag = 0; |
3919 | 1758 | ||
3920 | if ((dev->flags & AHD_DEV_UNCONFIGURED) != 0 | ||
3921 | && dev->active == 0 | ||
3922 | && (dev->flags & AHD_DEV_TIMER_ACTIVE) == 0) | ||
3923 | ahd_linux_free_device(ahd, dev); | ||
3924 | |||
3925 | if ((scb->flags & SCB_RECOVERY_SCB) != 0) { | 1759 | if ((scb->flags & SCB_RECOVERY_SCB) != 0) { |
3926 | printf("Recovery SCB completes\n"); | 1760 | printf("Recovery SCB completes\n"); |
3927 | if (ahd_get_transaction_status(scb) == CAM_BDR_SENT | 1761 | if (ahd_get_transaction_status(scb) == CAM_BDR_SENT |
3928 | || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED) | 1762 | || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED) |
3929 | ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT); | 1763 | ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT); |
3930 | if ((scb->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) { | 1764 | if ((ahd->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) { |
3931 | scb->platform_data->flags &= ~AHD_SCB_UP_EH_SEM; | 1765 | ahd->platform_data->flags &= ~AHD_SCB_UP_EH_SEM; |
3932 | up(&ahd->platform_data->eh_sem); | 1766 | up(&ahd->platform_data->eh_sem); |
3933 | } | 1767 | } |
3934 | } | 1768 | } |
3935 | 1769 | ||
3936 | ahd_free_scb(ahd, scb); | 1770 | ahd_free_scb(ahd, scb); |
3937 | ahd_linux_queue_cmd_complete(ahd, cmd); | 1771 | ahd_linux_queue_cmd_complete(ahd, cmd); |
3938 | |||
3939 | if ((ahd->platform_data->flags & AHD_DV_WAIT_SIMQ_EMPTY) != 0 | ||
3940 | && LIST_FIRST(&ahd->pending_scbs) == NULL) { | ||
3941 | ahd->platform_data->flags &= ~AHD_DV_WAIT_SIMQ_EMPTY; | ||
3942 | up(&ahd->platform_data->dv_sem); | ||
3943 | } | ||
3944 | } | 1772 | } |
3945 | 1773 | ||
3946 | static void | 1774 | static void |
3947 | ahd_linux_handle_scsi_status(struct ahd_softc *ahd, | 1775 | ahd_linux_handle_scsi_status(struct ahd_softc *ahd, |
3948 | struct ahd_linux_device *dev, struct scb *scb) | 1776 | struct scsi_device *sdev, struct scb *scb) |
3949 | { | 1777 | { |
3950 | struct ahd_devinfo devinfo; | 1778 | struct ahd_devinfo devinfo; |
1779 | struct ahd_linux_device *dev = scsi_transport_device_data(sdev); | ||
3951 | 1780 | ||
3952 | ahd_compile_devinfo(&devinfo, | 1781 | ahd_compile_devinfo(&devinfo, |
3953 | ahd->our_id, | 1782 | ahd->our_id, |
3954 | dev->target->target, dev->lun, | 1783 | sdev->sdev_target->id, sdev->lun, |
3955 | dev->target->channel == 0 ? 'A' : 'B', | 1784 | sdev->sdev_target->channel == 0 ? 'A' : 'B', |
3956 | ROLE_INITIATOR); | 1785 | ROLE_INITIATOR); |
3957 | 1786 | ||
3958 | /* | 1787 | /* |
@@ -3971,7 +1800,7 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd, | |||
3971 | case SCSI_STATUS_CHECK_COND: | 1800 | case SCSI_STATUS_CHECK_COND: |
3972 | case SCSI_STATUS_CMD_TERMINATED: | 1801 | case SCSI_STATUS_CMD_TERMINATED: |
3973 | { | 1802 | { |
3974 | Scsi_Cmnd *cmd; | 1803 | struct scsi_cmnd *cmd; |
3975 | 1804 | ||
3976 | /* | 1805 | /* |
3977 | * Copy sense information to the OS's cmd | 1806 | * Copy sense information to the OS's cmd |
@@ -4024,7 +1853,6 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd, | |||
4024 | break; | 1853 | break; |
4025 | } | 1854 | } |
4026 | case SCSI_STATUS_QUEUE_FULL: | 1855 | case SCSI_STATUS_QUEUE_FULL: |
4027 | { | ||
4028 | /* | 1856 | /* |
4029 | * By the time the core driver has returned this | 1857 | * By the time the core driver has returned this |
4030 | * command, all other commands that were queued | 1858 | * command, all other commands that were queued |
@@ -4085,98 +1913,23 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd, | |||
4085 | (dev->flags & AHD_DEV_Q_BASIC) | 1913 | (dev->flags & AHD_DEV_Q_BASIC) |
4086 | ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED); | 1914 | ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED); |
4087 | ahd_set_scsi_status(scb, SCSI_STATUS_BUSY); | 1915 | ahd_set_scsi_status(scb, SCSI_STATUS_BUSY); |
4088 | /* FALLTHROUGH */ | ||
4089 | } | ||
4090 | case SCSI_STATUS_BUSY: | ||
4091 | /* | ||
4092 | * Set a short timer to defer sending commands for | ||
4093 | * a bit since Linux will not delay in this case. | ||
4094 | */ | ||
4095 | if ((dev->flags & AHD_DEV_TIMER_ACTIVE) != 0) { | ||
4096 | printf("%s:%c:%d: Device Timer still active during " | ||
4097 | "busy processing\n", ahd_name(ahd), | ||
4098 | dev->target->channel, dev->target->target); | ||
4099 | break; | ||
4100 | } | ||
4101 | dev->flags |= AHD_DEV_TIMER_ACTIVE; | ||
4102 | dev->qfrozen++; | ||
4103 | init_timer(&dev->timer); | ||
4104 | dev->timer.data = (u_long)dev; | ||
4105 | dev->timer.expires = jiffies + (HZ/2); | ||
4106 | dev->timer.function = ahd_linux_dev_timed_unfreeze; | ||
4107 | add_timer(&dev->timer); | ||
4108 | break; | ||
4109 | } | 1916 | } |
4110 | } | 1917 | } |
4111 | 1918 | ||
4112 | static void | 1919 | static void |
4113 | ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, Scsi_Cmnd *cmd) | 1920 | ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd) |
4114 | { | 1921 | { |
4115 | /* | 1922 | /* |
4116 | * Typically, the complete queue has very few entries | ||
4117 | * queued to it before the queue is emptied by | ||
4118 | * ahd_linux_run_complete_queue, so sorting the entries | ||
4119 | * by generation number should be inexpensive. | ||
4120 | * We perform the sort so that commands that complete | ||
4121 | * with an error are retuned in the order origionally | ||
4122 | * queued to the controller so that any subsequent retries | ||
4123 | * are performed in order. The underlying ahd routines do | ||
4124 | * not guarantee the order that aborted commands will be | ||
4125 | * returned to us. | ||
4126 | */ | ||
4127 | struct ahd_completeq *completeq; | ||
4128 | struct ahd_cmd *list_cmd; | ||
4129 | struct ahd_cmd *acmd; | ||
4130 | |||
4131 | /* | ||
4132 | * Map CAM error codes into Linux Error codes. We | 1923 | * Map CAM error codes into Linux Error codes. We |
4133 | * avoid the conversion so that the DV code has the | 1924 | * avoid the conversion so that the DV code has the |
4134 | * full error information available when making | 1925 | * full error information available when making |
4135 | * state change decisions. | 1926 | * state change decisions. |
4136 | */ | 1927 | */ |
4137 | if (AHD_DV_CMD(cmd) == FALSE) { | 1928 | { |
4138 | uint32_t status; | 1929 | uint32_t status; |
4139 | u_int new_status; | 1930 | u_int new_status; |
4140 | 1931 | ||
4141 | status = ahd_cmd_get_transaction_status(cmd); | 1932 | status = ahd_cmd_get_transaction_status(cmd); |
4142 | if (status != CAM_REQ_CMP) { | ||
4143 | struct ahd_linux_device *dev; | ||
4144 | struct ahd_devinfo devinfo; | ||
4145 | cam_status cam_status; | ||
4146 | uint32_t action; | ||
4147 | u_int scsi_status; | ||
4148 | |||
4149 | dev = ahd_linux_get_device(ahd, cmd->device->channel, | ||
4150 | cmd->device->id, | ||
4151 | cmd->device->lun, | ||
4152 | /*alloc*/FALSE); | ||
4153 | |||
4154 | if (dev == NULL) | ||
4155 | goto no_fallback; | ||
4156 | |||
4157 | ahd_compile_devinfo(&devinfo, | ||
4158 | ahd->our_id, | ||
4159 | dev->target->target, dev->lun, | ||
4160 | dev->target->channel == 0 ? 'A':'B', | ||
4161 | ROLE_INITIATOR); | ||
4162 | |||
4163 | scsi_status = ahd_cmd_get_scsi_status(cmd); | ||
4164 | cam_status = ahd_cmd_get_transaction_status(cmd); | ||
4165 | action = aic_error_action(cmd, dev->target->inq_data, | ||
4166 | cam_status, scsi_status); | ||
4167 | if ((action & SSQ_FALLBACK) != 0) { | ||
4168 | |||
4169 | /* Update stats */ | ||
4170 | dev->target->errors_detected++; | ||
4171 | if (dev->target->cmds_since_error == 0) | ||
4172 | dev->target->cmds_since_error++; | ||
4173 | else { | ||
4174 | dev->target->cmds_since_error = 0; | ||
4175 | ahd_linux_fallback(ahd, &devinfo); | ||
4176 | } | ||
4177 | } | ||
4178 | } | ||
4179 | no_fallback: | ||
4180 | switch (status) { | 1933 | switch (status) { |
4181 | case CAM_REQ_INPROG: | 1934 | case CAM_REQ_INPROG: |
4182 | case CAM_REQ_CMP: | 1935 | case CAM_REQ_CMP: |
@@ -4221,26 +1974,7 @@ no_fallback: | |||
4221 | new_status = DID_ERROR; | 1974 | new_status = DID_ERROR; |
4222 | break; | 1975 | break; |
4223 | case CAM_REQUEUE_REQ: | 1976 | case CAM_REQUEUE_REQ: |
4224 | /* | 1977 | new_status = DID_REQUEUE; |
4225 | * If we want the request requeued, make sure there | ||
4226 | * are sufficent retries. In the old scsi error code, | ||
4227 | * we used to be able to specify a result code that | ||
4228 | * bypassed the retry count. Now we must use this | ||
4229 | * hack. We also "fake" a check condition with | ||
4230 | * a sense code of ABORTED COMMAND. This seems to | ||
4231 | * evoke a retry even if this command is being sent | ||
4232 | * via the eh thread. Ick! Ick! Ick! | ||
4233 | */ | ||
4234 | if (cmd->retries > 0) | ||
4235 | cmd->retries--; | ||
4236 | new_status = DID_OK; | ||
4237 | ahd_cmd_set_scsi_status(cmd, SCSI_STATUS_CHECK_COND); | ||
4238 | cmd->result |= (DRIVER_SENSE << 24); | ||
4239 | memset(cmd->sense_buffer, 0, | ||
4240 | sizeof(cmd->sense_buffer)); | ||
4241 | cmd->sense_buffer[0] = SSD_ERRCODE_VALID | ||
4242 | | SSD_CURRENT_ERROR; | ||
4243 | cmd->sense_buffer[2] = SSD_KEY_ABORTED_COMMAND; | ||
4244 | break; | 1978 | break; |
4245 | default: | 1979 | default: |
4246 | /* We should never get here */ | 1980 | /* We should never get here */ |
@@ -4251,116 +1985,23 @@ no_fallback: | |||
4251 | ahd_cmd_set_transaction_status(cmd, new_status); | 1985 | ahd_cmd_set_transaction_status(cmd, new_status); |
4252 | } | 1986 | } |
4253 | 1987 | ||
4254 | completeq = &ahd->platform_data->completeq; | 1988 | cmd->scsi_done(cmd); |
4255 | list_cmd = TAILQ_FIRST(completeq); | ||
4256 | acmd = (struct ahd_cmd *)cmd; | ||
4257 | while (list_cmd != NULL | ||
4258 | && acmd_scsi_cmd(list_cmd).serial_number | ||
4259 | < acmd_scsi_cmd(acmd).serial_number) | ||
4260 | list_cmd = TAILQ_NEXT(list_cmd, acmd_links.tqe); | ||
4261 | if (list_cmd != NULL) | ||
4262 | TAILQ_INSERT_BEFORE(list_cmd, acmd, acmd_links.tqe); | ||
4263 | else | ||
4264 | TAILQ_INSERT_TAIL(completeq, acmd, acmd_links.tqe); | ||
4265 | } | 1989 | } |
4266 | 1990 | ||
4267 | static void | 1991 | static void |
4268 | ahd_linux_filter_inquiry(struct ahd_softc *ahd, struct ahd_devinfo *devinfo) | 1992 | ahd_linux_sem_timeout(u_long arg) |
4269 | { | 1993 | { |
4270 | struct scsi_inquiry_data *sid; | 1994 | struct ahd_softc *ahd; |
4271 | struct ahd_initiator_tinfo *tinfo; | 1995 | u_long s; |
4272 | struct ahd_transinfo *user; | ||
4273 | struct ahd_transinfo *goal; | ||
4274 | struct ahd_transinfo *curr; | ||
4275 | struct ahd_tmode_tstate *tstate; | ||
4276 | struct ahd_linux_device *dev; | ||
4277 | u_int width; | ||
4278 | u_int period; | ||
4279 | u_int offset; | ||
4280 | u_int ppr_options; | ||
4281 | u_int trans_version; | ||
4282 | u_int prot_version; | ||
4283 | |||
4284 | /* | ||
4285 | * Determine if this lun actually exists. If so, | ||
4286 | * hold on to its corresponding device structure. | ||
4287 | * If not, make sure we release the device and | ||
4288 | * don't bother processing the rest of this inquiry | ||
4289 | * command. | ||
4290 | */ | ||
4291 | dev = ahd_linux_get_device(ahd, devinfo->channel - 'A', | ||
4292 | devinfo->target, devinfo->lun, | ||
4293 | /*alloc*/TRUE); | ||
4294 | |||
4295 | sid = (struct scsi_inquiry_data *)dev->target->inq_data; | ||
4296 | if (SID_QUAL(sid) == SID_QUAL_LU_CONNECTED) { | ||
4297 | |||
4298 | dev->flags &= ~AHD_DEV_UNCONFIGURED; | ||
4299 | } else { | ||
4300 | dev->flags |= AHD_DEV_UNCONFIGURED; | ||
4301 | return; | ||
4302 | } | ||
4303 | 1996 | ||
4304 | /* | 1997 | ahd = (struct ahd_softc *)arg; |
4305 | * Update our notion of this device's transfer | ||
4306 | * negotiation capabilities. | ||
4307 | */ | ||
4308 | tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, | ||
4309 | devinfo->our_scsiid, | ||
4310 | devinfo->target, &tstate); | ||
4311 | user = &tinfo->user; | ||
4312 | goal = &tinfo->goal; | ||
4313 | curr = &tinfo->curr; | ||
4314 | width = user->width; | ||
4315 | period = user->period; | ||
4316 | offset = user->offset; | ||
4317 | ppr_options = user->ppr_options; | ||
4318 | trans_version = user->transport_version; | ||
4319 | prot_version = MIN(user->protocol_version, SID_ANSI_REV(sid)); | ||
4320 | 1998 | ||
4321 | /* | 1999 | ahd_lock(ahd, &s); |
4322 | * Only attempt SPI3/4 once we've verified that | 2000 | if ((ahd->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) { |
4323 | * the device claims to support SPI3/4 features. | 2001 | ahd->platform_data->flags &= ~AHD_SCB_UP_EH_SEM; |
4324 | */ | 2002 | up(&ahd->platform_data->eh_sem); |
4325 | if (prot_version < SCSI_REV_2) | ||
4326 | trans_version = SID_ANSI_REV(sid); | ||
4327 | else | ||
4328 | trans_version = SCSI_REV_2; | ||
4329 | |||
4330 | if ((sid->flags & SID_WBus16) == 0) | ||
4331 | width = MSG_EXT_WDTR_BUS_8_BIT; | ||
4332 | if ((sid->flags & SID_Sync) == 0) { | ||
4333 | period = 0; | ||
4334 | offset = 0; | ||
4335 | ppr_options = 0; | ||
4336 | } | ||
4337 | if ((sid->spi3data & SID_SPI_QAS) == 0) | ||
4338 | ppr_options &= ~MSG_EXT_PPR_QAS_REQ; | ||
4339 | if ((sid->spi3data & SID_SPI_CLOCK_DT) == 0) | ||
4340 | ppr_options &= MSG_EXT_PPR_QAS_REQ; | ||
4341 | if ((sid->spi3data & SID_SPI_IUS) == 0) | ||
4342 | ppr_options &= (MSG_EXT_PPR_DT_REQ | ||
4343 | | MSG_EXT_PPR_QAS_REQ); | ||
4344 | |||
4345 | if (prot_version > SCSI_REV_2 | ||
4346 | && ppr_options != 0) | ||
4347 | trans_version = user->transport_version; | ||
4348 | |||
4349 | ahd_validate_width(ahd, /*tinfo limit*/NULL, &width, ROLE_UNKNOWN); | ||
4350 | ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_MAX); | ||
4351 | ahd_validate_offset(ahd, /*tinfo limit*/NULL, period, | ||
4352 | &offset, width, ROLE_UNKNOWN); | ||
4353 | if (offset == 0 || period == 0) { | ||
4354 | period = 0; | ||
4355 | offset = 0; | ||
4356 | ppr_options = 0; | ||
4357 | } | 2003 | } |
4358 | /* Apply our filtered user settings. */ | 2004 | ahd_unlock(ahd, &s); |
4359 | curr->transport_version = trans_version; | ||
4360 | curr->protocol_version = prot_version; | ||
4361 | ahd_set_width(ahd, devinfo, width, AHD_TRANS_GOAL, /*paused*/FALSE); | ||
4362 | ahd_set_syncrate(ahd, devinfo, period, offset, ppr_options, | ||
4363 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
4364 | } | 2005 | } |
4365 | 2006 | ||
4366 | void | 2007 | void |
@@ -4388,11 +2029,6 @@ ahd_release_simq(struct ahd_softc *ahd) | |||
4388 | if (ahd->platform_data->qfrozen == 0) { | 2029 | if (ahd->platform_data->qfrozen == 0) { |
4389 | unblock_reqs = 1; | 2030 | unblock_reqs = 1; |
4390 | } | 2031 | } |
4391 | if (AHD_DV_SIMQ_FROZEN(ahd) | ||
4392 | && ((ahd->platform_data->flags & AHD_DV_WAIT_SIMQ_RELEASE) != 0)) { | ||
4393 | ahd->platform_data->flags &= ~AHD_DV_WAIT_SIMQ_RELEASE; | ||
4394 | up(&ahd->platform_data->dv_sem); | ||
4395 | } | ||
4396 | ahd_unlock(ahd, &s); | 2032 | ahd_unlock(ahd, &s); |
4397 | /* | 2033 | /* |
4398 | * There is still a race here. The mid-layer | 2034 | * There is still a race here. The mid-layer |
@@ -4404,65 +2040,526 @@ ahd_release_simq(struct ahd_softc *ahd) | |||
4404 | scsi_unblock_requests(ahd->platform_data->host); | 2040 | scsi_unblock_requests(ahd->platform_data->host); |
4405 | } | 2041 | } |
4406 | 2042 | ||
4407 | static void | 2043 | static int |
4408 | ahd_linux_sem_timeout(u_long arg) | 2044 | ahd_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag) |
4409 | { | 2045 | { |
4410 | struct scb *scb; | 2046 | struct ahd_softc *ahd; |
4411 | struct ahd_softc *ahd; | 2047 | struct ahd_linux_device *dev; |
4412 | u_long s; | 2048 | struct scb *pending_scb; |
2049 | u_int saved_scbptr; | ||
2050 | u_int active_scbptr; | ||
2051 | u_int last_phase; | ||
2052 | u_int saved_scsiid; | ||
2053 | u_int cdb_byte; | ||
2054 | int retval; | ||
2055 | int was_paused; | ||
2056 | int paused; | ||
2057 | int wait; | ||
2058 | int disconnected; | ||
2059 | ahd_mode_state saved_modes; | ||
4413 | 2060 | ||
4414 | scb = (struct scb *)arg; | 2061 | pending_scb = NULL; |
4415 | ahd = scb->ahd_softc; | 2062 | paused = FALSE; |
4416 | ahd_lock(ahd, &s); | 2063 | wait = FALSE; |
4417 | if ((scb->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) { | 2064 | ahd = *(struct ahd_softc **)cmd->device->host->hostdata; |
4418 | scb->platform_data->flags &= ~AHD_SCB_UP_EH_SEM; | 2065 | |
4419 | up(&ahd->platform_data->eh_sem); | 2066 | printf("%s:%d:%d:%d: Attempting to queue a%s message:", |
2067 | ahd_name(ahd), cmd->device->channel, | ||
2068 | cmd->device->id, cmd->device->lun, | ||
2069 | flag == SCB_ABORT ? "n ABORT" : " TARGET RESET"); | ||
2070 | |||
2071 | printf("CDB:"); | ||
2072 | for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++) | ||
2073 | printf(" 0x%x", cmd->cmnd[cdb_byte]); | ||
2074 | printf("\n"); | ||
2075 | |||
2076 | spin_lock_irq(&ahd->platform_data->spin_lock); | ||
2077 | |||
2078 | /* | ||
2079 | * First determine if we currently own this command. | ||
2080 | * Start by searching the device queue. If not found | ||
2081 | * there, check the pending_scb list. If not found | ||
2082 | * at all, and the system wanted us to just abort the | ||
2083 | * command, return success. | ||
2084 | */ | ||
2085 | dev = scsi_transport_device_data(cmd->device); | ||
2086 | |||
2087 | if (dev == NULL) { | ||
2088 | /* | ||
2089 | * No target device for this command exists, | ||
2090 | * so we must not still own the command. | ||
2091 | */ | ||
2092 | printf("%s:%d:%d:%d: Is not an active device\n", | ||
2093 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
2094 | cmd->device->lun); | ||
2095 | retval = SUCCESS; | ||
2096 | goto no_cmd; | ||
4420 | } | 2097 | } |
4421 | ahd_unlock(ahd, &s); | 2098 | |
2099 | /* | ||
2100 | * See if we can find a matching cmd in the pending list. | ||
2101 | */ | ||
2102 | LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) { | ||
2103 | if (pending_scb->io_ctx == cmd) | ||
2104 | break; | ||
2105 | } | ||
2106 | |||
2107 | if (pending_scb == NULL && flag == SCB_DEVICE_RESET) { | ||
2108 | |||
2109 | /* Any SCB for this device will do for a target reset */ | ||
2110 | LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) { | ||
2111 | if (ahd_match_scb(ahd, pending_scb, cmd->device->id, | ||
2112 | cmd->device->channel + 'A', | ||
2113 | CAM_LUN_WILDCARD, | ||
2114 | SCB_LIST_NULL, ROLE_INITIATOR) == 0) | ||
2115 | break; | ||
2116 | } | ||
2117 | } | ||
2118 | |||
2119 | if (pending_scb == NULL) { | ||
2120 | printf("%s:%d:%d:%d: Command not found\n", | ||
2121 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
2122 | cmd->device->lun); | ||
2123 | goto no_cmd; | ||
2124 | } | ||
2125 | |||
2126 | if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) { | ||
2127 | /* | ||
2128 | * We can't queue two recovery actions using the same SCB | ||
2129 | */ | ||
2130 | retval = FAILED; | ||
2131 | goto done; | ||
2132 | } | ||
2133 | |||
2134 | /* | ||
2135 | * Ensure that the card doesn't do anything | ||
2136 | * behind our back. Also make sure that we | ||
2137 | * didn't "just" miss an interrupt that would | ||
2138 | * affect this cmd. | ||
2139 | */ | ||
2140 | was_paused = ahd_is_paused(ahd); | ||
2141 | ahd_pause_and_flushwork(ahd); | ||
2142 | paused = TRUE; | ||
2143 | |||
2144 | if ((pending_scb->flags & SCB_ACTIVE) == 0) { | ||
2145 | printf("%s:%d:%d:%d: Command already completed\n", | ||
2146 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
2147 | cmd->device->lun); | ||
2148 | goto no_cmd; | ||
2149 | } | ||
2150 | |||
2151 | printf("%s: At time of recovery, card was %spaused\n", | ||
2152 | ahd_name(ahd), was_paused ? "" : "not "); | ||
2153 | ahd_dump_card_state(ahd); | ||
2154 | |||
2155 | disconnected = TRUE; | ||
2156 | if (flag == SCB_ABORT) { | ||
2157 | if (ahd_search_qinfifo(ahd, cmd->device->id, | ||
2158 | cmd->device->channel + 'A', | ||
2159 | cmd->device->lun, | ||
2160 | pending_scb->hscb->tag, | ||
2161 | ROLE_INITIATOR, CAM_REQ_ABORTED, | ||
2162 | SEARCH_COMPLETE) > 0) { | ||
2163 | printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n", | ||
2164 | ahd_name(ahd), cmd->device->channel, | ||
2165 | cmd->device->id, cmd->device->lun); | ||
2166 | retval = SUCCESS; | ||
2167 | goto done; | ||
2168 | } | ||
2169 | } else if (ahd_search_qinfifo(ahd, cmd->device->id, | ||
2170 | cmd->device->channel + 'A', | ||
2171 | cmd->device->lun, pending_scb->hscb->tag, | ||
2172 | ROLE_INITIATOR, /*status*/0, | ||
2173 | SEARCH_COUNT) > 0) { | ||
2174 | disconnected = FALSE; | ||
2175 | } | ||
2176 | |||
2177 | saved_modes = ahd_save_modes(ahd); | ||
2178 | ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI); | ||
2179 | last_phase = ahd_inb(ahd, LASTPHASE); | ||
2180 | saved_scbptr = ahd_get_scbptr(ahd); | ||
2181 | active_scbptr = saved_scbptr; | ||
2182 | if (disconnected && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) { | ||
2183 | struct scb *bus_scb; | ||
2184 | |||
2185 | bus_scb = ahd_lookup_scb(ahd, active_scbptr); | ||
2186 | if (bus_scb == pending_scb) | ||
2187 | disconnected = FALSE; | ||
2188 | else if (flag != SCB_ABORT | ||
2189 | && ahd_inb(ahd, SAVED_SCSIID) == pending_scb->hscb->scsiid | ||
2190 | && ahd_inb(ahd, SAVED_LUN) == SCB_GET_LUN(pending_scb)) | ||
2191 | disconnected = FALSE; | ||
2192 | } | ||
2193 | |||
2194 | /* | ||
2195 | * At this point, pending_scb is the scb associated with the | ||
2196 | * passed in command. That command is currently active on the | ||
2197 | * bus or is in the disconnected state. | ||
2198 | */ | ||
2199 | saved_scsiid = ahd_inb(ahd, SAVED_SCSIID); | ||
2200 | if (last_phase != P_BUSFREE | ||
2201 | && (SCB_GET_TAG(pending_scb) == active_scbptr | ||
2202 | || (flag == SCB_DEVICE_RESET | ||
2203 | && SCSIID_TARGET(ahd, saved_scsiid) == cmd->device->id))) { | ||
2204 | |||
2205 | /* | ||
2206 | * We're active on the bus, so assert ATN | ||
2207 | * and hope that the target responds. | ||
2208 | */ | ||
2209 | pending_scb = ahd_lookup_scb(ahd, active_scbptr); | ||
2210 | pending_scb->flags |= SCB_RECOVERY_SCB|flag; | ||
2211 | ahd_outb(ahd, MSG_OUT, HOST_MSG); | ||
2212 | ahd_outb(ahd, SCSISIGO, last_phase|ATNO); | ||
2213 | printf("%s:%d:%d:%d: Device is active, asserting ATN\n", | ||
2214 | ahd_name(ahd), cmd->device->channel, | ||
2215 | cmd->device->id, cmd->device->lun); | ||
2216 | wait = TRUE; | ||
2217 | } else if (disconnected) { | ||
2218 | |||
2219 | /* | ||
2220 | * Actually re-queue this SCB in an attempt | ||
2221 | * to select the device before it reconnects. | ||
2222 | */ | ||
2223 | pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT; | ||
2224 | ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb)); | ||
2225 | pending_scb->hscb->cdb_len = 0; | ||
2226 | pending_scb->hscb->task_attribute = 0; | ||
2227 | pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK; | ||
2228 | |||
2229 | if ((pending_scb->flags & SCB_PACKETIZED) != 0) { | ||
2230 | /* | ||
2231 | * Mark the SCB has having an outstanding | ||
2232 | * task management function. Should the command | ||
2233 | * complete normally before the task management | ||
2234 | * function can be sent, the host will be notified | ||
2235 | * to abort our requeued SCB. | ||
2236 | */ | ||
2237 | ahd_outb(ahd, SCB_TASK_MANAGEMENT, | ||
2238 | pending_scb->hscb->task_management); | ||
2239 | } else { | ||
2240 | /* | ||
2241 | * If non-packetized, set the MK_MESSAGE control | ||
2242 | * bit indicating that we desire to send a message. | ||
2243 | * We also set the disconnected flag since there is | ||
2244 | * no guarantee that our SCB control byte matches | ||
2245 | * the version on the card. We don't want the | ||
2246 | * sequencer to abort the command thinking an | ||
2247 | * unsolicited reselection occurred. | ||
2248 | */ | ||
2249 | pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED; | ||
2250 | |||
2251 | /* | ||
2252 | * The sequencer will never re-reference the | ||
2253 | * in-core SCB. To make sure we are notified | ||
2254 | * during reslection, set the MK_MESSAGE flag in | ||
2255 | * the card's copy of the SCB. | ||
2256 | */ | ||
2257 | ahd_outb(ahd, SCB_CONTROL, | ||
2258 | ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE); | ||
2259 | } | ||
2260 | |||
2261 | /* | ||
2262 | * Clear out any entries in the QINFIFO first | ||
2263 | * so we are the next SCB for this target | ||
2264 | * to run. | ||
2265 | */ | ||
2266 | ahd_search_qinfifo(ahd, cmd->device->id, | ||
2267 | cmd->device->channel + 'A', cmd->device->lun, | ||
2268 | SCB_LIST_NULL, ROLE_INITIATOR, | ||
2269 | CAM_REQUEUE_REQ, SEARCH_COMPLETE); | ||
2270 | ahd_qinfifo_requeue_tail(ahd, pending_scb); | ||
2271 | ahd_set_scbptr(ahd, saved_scbptr); | ||
2272 | ahd_print_path(ahd, pending_scb); | ||
2273 | printf("Device is disconnected, re-queuing SCB\n"); | ||
2274 | wait = TRUE; | ||
2275 | } else { | ||
2276 | printf("%s:%d:%d:%d: Unable to deliver message\n", | ||
2277 | ahd_name(ahd), cmd->device->channel, | ||
2278 | cmd->device->id, cmd->device->lun); | ||
2279 | retval = FAILED; | ||
2280 | goto done; | ||
2281 | } | ||
2282 | |||
2283 | no_cmd: | ||
2284 | /* | ||
2285 | * Our assumption is that if we don't have the command, no | ||
2286 | * recovery action was required, so we return success. Again, | ||
2287 | * the semantics of the mid-layer recovery engine are not | ||
2288 | * well defined, so this may change in time. | ||
2289 | */ | ||
2290 | retval = SUCCESS; | ||
2291 | done: | ||
2292 | if (paused) | ||
2293 | ahd_unpause(ahd); | ||
2294 | if (wait) { | ||
2295 | struct timer_list timer; | ||
2296 | int ret; | ||
2297 | |||
2298 | ahd->platform_data->flags |= AHD_SCB_UP_EH_SEM; | ||
2299 | spin_unlock_irq(&ahd->platform_data->spin_lock); | ||
2300 | init_timer(&timer); | ||
2301 | timer.data = (u_long)ahd; | ||
2302 | timer.expires = jiffies + (5 * HZ); | ||
2303 | timer.function = ahd_linux_sem_timeout; | ||
2304 | add_timer(&timer); | ||
2305 | printf("Recovery code sleeping\n"); | ||
2306 | down(&ahd->platform_data->eh_sem); | ||
2307 | printf("Recovery code awake\n"); | ||
2308 | ret = del_timer_sync(&timer); | ||
2309 | if (ret == 0) { | ||
2310 | printf("Timer Expired\n"); | ||
2311 | retval = FAILED; | ||
2312 | } | ||
2313 | spin_lock_irq(&ahd->platform_data->spin_lock); | ||
2314 | } | ||
2315 | spin_unlock_irq(&ahd->platform_data->spin_lock); | ||
2316 | return (retval); | ||
4422 | } | 2317 | } |
4423 | 2318 | ||
4424 | static void | 2319 | static void ahd_linux_exit(void); |
4425 | ahd_linux_dev_timed_unfreeze(u_long arg) | 2320 | |
2321 | static void ahd_linux_set_width(struct scsi_target *starget, int width) | ||
4426 | { | 2322 | { |
4427 | struct ahd_linux_device *dev; | 2323 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
4428 | struct ahd_softc *ahd; | 2324 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); |
4429 | u_long s; | 2325 | struct ahd_devinfo devinfo; |
2326 | unsigned long flags; | ||
4430 | 2327 | ||
4431 | dev = (struct ahd_linux_device *)arg; | 2328 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, |
4432 | ahd = dev->target->ahd; | 2329 | starget->channel + 'A', ROLE_INITIATOR); |
4433 | ahd_lock(ahd, &s); | 2330 | ahd_lock(ahd, &flags); |
4434 | dev->flags &= ~AHD_DEV_TIMER_ACTIVE; | 2331 | ahd_set_width(ahd, &devinfo, width, AHD_TRANS_GOAL, FALSE); |
4435 | if (dev->qfrozen > 0) | 2332 | ahd_unlock(ahd, &flags); |
4436 | dev->qfrozen--; | 2333 | } |
4437 | if ((dev->flags & AHD_DEV_UNCONFIGURED) != 0 | 2334 | |
4438 | && dev->active == 0) | 2335 | static void ahd_linux_set_period(struct scsi_target *starget, int period) |
4439 | ahd_linux_free_device(ahd, dev); | 2336 | { |
4440 | ahd_unlock(ahd, &s); | 2337 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
2338 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2339 | struct ahd_tmode_tstate *tstate; | ||
2340 | struct ahd_initiator_tinfo *tinfo | ||
2341 | = ahd_fetch_transinfo(ahd, | ||
2342 | starget->channel + 'A', | ||
2343 | shost->this_id, starget->id, &tstate); | ||
2344 | struct ahd_devinfo devinfo; | ||
2345 | unsigned int ppr_options = tinfo->goal.ppr_options; | ||
2346 | unsigned long flags; | ||
2347 | unsigned long offset = tinfo->goal.offset; | ||
2348 | |||
2349 | if (offset == 0) | ||
2350 | offset = MAX_OFFSET; | ||
2351 | |||
2352 | if (period < 8) | ||
2353 | period = 8; | ||
2354 | if (period < 10) { | ||
2355 | ppr_options |= MSG_EXT_PPR_DT_REQ; | ||
2356 | if (period == 8) | ||
2357 | ppr_options |= MSG_EXT_PPR_IU_REQ; | ||
2358 | } | ||
2359 | |||
2360 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2361 | starget->channel + 'A', ROLE_INITIATOR); | ||
2362 | |||
2363 | /* all PPR requests apart from QAS require wide transfers */ | ||
2364 | if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) { | ||
2365 | if (spi_width(starget) == 0) | ||
2366 | ppr_options &= MSG_EXT_PPR_QAS_REQ; | ||
2367 | } | ||
2368 | |||
2369 | ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_MAX); | ||
2370 | ahd_lock(ahd, &flags); | ||
2371 | ahd_set_syncrate(ahd, &devinfo, period, offset, | ||
2372 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2373 | ahd_unlock(ahd, &flags); | ||
2374 | } | ||
2375 | |||
2376 | static void ahd_linux_set_offset(struct scsi_target *starget, int offset) | ||
2377 | { | ||
2378 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | ||
2379 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2380 | struct ahd_tmode_tstate *tstate; | ||
2381 | struct ahd_initiator_tinfo *tinfo | ||
2382 | = ahd_fetch_transinfo(ahd, | ||
2383 | starget->channel + 'A', | ||
2384 | shost->this_id, starget->id, &tstate); | ||
2385 | struct ahd_devinfo devinfo; | ||
2386 | unsigned int ppr_options = 0; | ||
2387 | unsigned int period = 0; | ||
2388 | unsigned long flags; | ||
2389 | |||
2390 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2391 | starget->channel + 'A', ROLE_INITIATOR); | ||
2392 | if (offset != 0) { | ||
2393 | period = tinfo->goal.period; | ||
2394 | ppr_options = tinfo->goal.ppr_options; | ||
2395 | ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_MAX); | ||
2396 | } | ||
2397 | ahd_lock(ahd, &flags); | ||
2398 | ahd_set_syncrate(ahd, &devinfo, period, offset, ppr_options, | ||
2399 | AHD_TRANS_GOAL, FALSE); | ||
2400 | ahd_unlock(ahd, &flags); | ||
4441 | } | 2401 | } |
4442 | 2402 | ||
2403 | static void ahd_linux_set_dt(struct scsi_target *starget, int dt) | ||
2404 | { | ||
2405 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | ||
2406 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2407 | struct ahd_tmode_tstate *tstate; | ||
2408 | struct ahd_initiator_tinfo *tinfo | ||
2409 | = ahd_fetch_transinfo(ahd, | ||
2410 | starget->channel + 'A', | ||
2411 | shost->this_id, starget->id, &tstate); | ||
2412 | struct ahd_devinfo devinfo; | ||
2413 | unsigned int ppr_options = tinfo->goal.ppr_options | ||
2414 | & ~MSG_EXT_PPR_DT_REQ; | ||
2415 | unsigned int period = tinfo->goal.period; | ||
2416 | unsigned long flags; | ||
2417 | |||
2418 | if (dt) { | ||
2419 | ppr_options |= MSG_EXT_PPR_DT_REQ; | ||
2420 | if (period > 9) | ||
2421 | period = 9; /* at least 12.5ns for DT */ | ||
2422 | } else if (period <= 9) | ||
2423 | period = 10; /* If resetting DT, period must be >= 25ns */ | ||
2424 | |||
2425 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2426 | starget->channel + 'A', ROLE_INITIATOR); | ||
2427 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2428 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
2429 | ahd_lock(ahd, &flags); | ||
2430 | ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset, | ||
2431 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2432 | ahd_unlock(ahd, &flags); | ||
2433 | } | ||
2434 | |||
2435 | static void ahd_linux_set_qas(struct scsi_target *starget, int qas) | ||
2436 | { | ||
2437 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | ||
2438 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2439 | struct ahd_tmode_tstate *tstate; | ||
2440 | struct ahd_initiator_tinfo *tinfo | ||
2441 | = ahd_fetch_transinfo(ahd, | ||
2442 | starget->channel + 'A', | ||
2443 | shost->this_id, starget->id, &tstate); | ||
2444 | struct ahd_devinfo devinfo; | ||
2445 | unsigned int ppr_options = tinfo->goal.ppr_options | ||
2446 | & ~MSG_EXT_PPR_QAS_REQ; | ||
2447 | unsigned int period = tinfo->goal.period; | ||
2448 | unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ; | ||
2449 | unsigned long flags; | ||
2450 | |||
2451 | if (qas) | ||
2452 | ppr_options |= MSG_EXT_PPR_QAS_REQ; | ||
2453 | |||
2454 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2455 | starget->channel + 'A', ROLE_INITIATOR); | ||
2456 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2457 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
2458 | ahd_lock(ahd, &flags); | ||
2459 | ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset, | ||
2460 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2461 | ahd_unlock(ahd, &flags); | ||
2462 | } | ||
2463 | |||
2464 | static void ahd_linux_set_iu(struct scsi_target *starget, int iu) | ||
2465 | { | ||
2466 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | ||
2467 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2468 | struct ahd_tmode_tstate *tstate; | ||
2469 | struct ahd_initiator_tinfo *tinfo | ||
2470 | = ahd_fetch_transinfo(ahd, | ||
2471 | starget->channel + 'A', | ||
2472 | shost->this_id, starget->id, &tstate); | ||
2473 | struct ahd_devinfo devinfo; | ||
2474 | unsigned int ppr_options = tinfo->goal.ppr_options | ||
2475 | & ~MSG_EXT_PPR_IU_REQ; | ||
2476 | unsigned int period = tinfo->goal.period; | ||
2477 | unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ; | ||
2478 | unsigned long flags; | ||
2479 | |||
2480 | if (iu) | ||
2481 | ppr_options |= MSG_EXT_PPR_IU_REQ; | ||
2482 | |||
2483 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2484 | starget->channel + 'A', ROLE_INITIATOR); | ||
2485 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2486 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
2487 | ahd_lock(ahd, &flags); | ||
2488 | ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset, | ||
2489 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2490 | ahd_unlock(ahd, &flags); | ||
2491 | } | ||
2492 | |||
2493 | static void ahd_linux_set_rd_strm(struct scsi_target *starget, int rdstrm) | ||
2494 | { | ||
2495 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | ||
2496 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2497 | struct ahd_tmode_tstate *tstate; | ||
2498 | struct ahd_initiator_tinfo *tinfo | ||
2499 | = ahd_fetch_transinfo(ahd, | ||
2500 | starget->channel + 'A', | ||
2501 | shost->this_id, starget->id, &tstate); | ||
2502 | struct ahd_devinfo devinfo; | ||
2503 | unsigned int ppr_options = tinfo->goal.ppr_options | ||
2504 | & ~MSG_EXT_PPR_RD_STRM; | ||
2505 | unsigned int period = tinfo->goal.period; | ||
2506 | unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ; | ||
2507 | unsigned long flags; | ||
2508 | |||
2509 | if (rdstrm) | ||
2510 | ppr_options |= MSG_EXT_PPR_RD_STRM; | ||
2511 | |||
2512 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2513 | starget->channel + 'A', ROLE_INITIATOR); | ||
2514 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2515 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
2516 | ahd_lock(ahd, &flags); | ||
2517 | ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset, | ||
2518 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2519 | ahd_unlock(ahd, &flags); | ||
2520 | } | ||
2521 | |||
2522 | static struct spi_function_template ahd_linux_transport_functions = { | ||
2523 | .set_offset = ahd_linux_set_offset, | ||
2524 | .show_offset = 1, | ||
2525 | .set_period = ahd_linux_set_period, | ||
2526 | .show_period = 1, | ||
2527 | .set_width = ahd_linux_set_width, | ||
2528 | .show_width = 1, | ||
2529 | .set_dt = ahd_linux_set_dt, | ||
2530 | .show_dt = 1, | ||
2531 | .set_iu = ahd_linux_set_iu, | ||
2532 | .show_iu = 1, | ||
2533 | .set_qas = ahd_linux_set_qas, | ||
2534 | .show_qas = 1, | ||
2535 | .set_rd_strm = ahd_linux_set_rd_strm, | ||
2536 | .show_rd_strm = 1, | ||
2537 | }; | ||
2538 | |||
2539 | |||
2540 | |||
4443 | static int __init | 2541 | static int __init |
4444 | ahd_linux_init(void) | 2542 | ahd_linux_init(void) |
4445 | { | 2543 | { |
4446 | return ahd_linux_detect(&aic79xx_driver_template); | 2544 | ahd_linux_transport_template = spi_attach_transport(&ahd_linux_transport_functions); |
2545 | if (!ahd_linux_transport_template) | ||
2546 | return -ENODEV; | ||
2547 | scsi_transport_reserve_target(ahd_linux_transport_template, | ||
2548 | sizeof(struct ahd_linux_target)); | ||
2549 | scsi_transport_reserve_device(ahd_linux_transport_template, | ||
2550 | sizeof(struct ahd_linux_device)); | ||
2551 | if (ahd_linux_detect(&aic79xx_driver_template) > 0) | ||
2552 | return 0; | ||
2553 | spi_release_transport(ahd_linux_transport_template); | ||
2554 | ahd_linux_exit(); | ||
2555 | return -ENODEV; | ||
4447 | } | 2556 | } |
4448 | 2557 | ||
4449 | static void __exit | 2558 | static void __exit |
4450 | ahd_linux_exit(void) | 2559 | ahd_linux_exit(void) |
4451 | { | 2560 | { |
4452 | struct ahd_softc *ahd; | ||
4453 | |||
4454 | /* | ||
4455 | * Shutdown DV threads before going into the SCSI mid-layer. | ||
4456 | * This avoids situations where the mid-layer locks the entire | ||
4457 | * kernel so that waiting for our DV threads to exit leads | ||
4458 | * to deadlock. | ||
4459 | */ | ||
4460 | TAILQ_FOREACH(ahd, &ahd_tailq, links) { | ||
4461 | |||
4462 | ahd_linux_kill_dv_thread(ahd); | ||
4463 | } | ||
4464 | |||
4465 | ahd_linux_pci_exit(); | 2561 | ahd_linux_pci_exit(); |
2562 | spi_release_transport(ahd_linux_transport_template); | ||
4466 | } | 2563 | } |
4467 | 2564 | ||
4468 | module_init(ahd_linux_init); | 2565 | module_init(ahd_linux_init); |