diff options
Diffstat (limited to 'drivers/scsi/aic7xxx/aic79xx_osm.c')
-rw-r--r-- | drivers/scsi/aic7xxx/aic79xx_osm.c | 4570 |
1 files changed, 1171 insertions, 3399 deletions
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c index 329cb233133..6b6d4e28779 100644 --- a/drivers/scsi/aic7xxx/aic79xx_osm.c +++ b/drivers/scsi/aic7xxx/aic79xx_osm.c | |||
@@ -46,32 +46,14 @@ | |||
46 | #include "aic79xx_inline.h" | 46 | #include "aic79xx_inline.h" |
47 | #include <scsi/scsicam.h> | 47 | #include <scsi/scsicam.h> |
48 | 48 | ||
49 | /* | 49 | static struct scsi_transport_template *ahd_linux_transport_template = NULL; |
50 | * Include aiclib.c as part of our | ||
51 | * "module dependencies are hard" work around. | ||
52 | */ | ||
53 | #include "aiclib.c" | ||
54 | 50 | ||
55 | #include <linux/init.h> /* __setup */ | 51 | #include <linux/init.h> /* __setup */ |
56 | |||
57 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) | ||
58 | #include "sd.h" /* For geometry detection */ | ||
59 | #endif | ||
60 | |||
61 | #include <linux/mm.h> /* For fetching system memory size */ | 52 | #include <linux/mm.h> /* For fetching system memory size */ |
53 | #include <linux/blkdev.h> /* For block_size() */ | ||
62 | #include <linux/delay.h> /* For ssleep/msleep */ | 54 | #include <linux/delay.h> /* For ssleep/msleep */ |
63 | 55 | ||
64 | /* | 56 | /* |
65 | * Lock protecting manipulation of the ahd softc list. | ||
66 | */ | ||
67 | spinlock_t ahd_list_spinlock; | ||
68 | |||
69 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) | ||
70 | /* For dynamic sglist size calculation. */ | ||
71 | u_int ahd_linux_nseg; | ||
72 | #endif | ||
73 | |||
74 | /* | ||
75 | * Bucket size for counting good commands in between bad ones. | 57 | * Bucket size for counting good commands in between bad ones. |
76 | */ | 58 | */ |
77 | #define AHD_LINUX_ERR_THRESH 1000 | 59 | #define AHD_LINUX_ERR_THRESH 1000 |
@@ -188,71 +170,6 @@ static adapter_tag_info_t aic79xx_tag_info[] = | |||
188 | }; | 170 | }; |
189 | 171 | ||
190 | /* | 172 | /* |
191 | * By default, read streaming is disabled. In theory, | ||
192 | * read streaming should enhance performance, but early | ||
193 | * U320 drive firmware actually performs slower with | ||
194 | * read streaming enabled. | ||
195 | */ | ||
196 | #ifdef CONFIG_AIC79XX_ENABLE_RD_STRM | ||
197 | #define AIC79XX_CONFIGED_RD_STRM 0xFFFF | ||
198 | #else | ||
199 | #define AIC79XX_CONFIGED_RD_STRM 0 | ||
200 | #endif | ||
201 | |||
202 | static uint16_t aic79xx_rd_strm_info[] = | ||
203 | { | ||
204 | AIC79XX_CONFIGED_RD_STRM, | ||
205 | AIC79XX_CONFIGED_RD_STRM, | ||
206 | AIC79XX_CONFIGED_RD_STRM, | ||
207 | AIC79XX_CONFIGED_RD_STRM, | ||
208 | AIC79XX_CONFIGED_RD_STRM, | ||
209 | AIC79XX_CONFIGED_RD_STRM, | ||
210 | AIC79XX_CONFIGED_RD_STRM, | ||
211 | AIC79XX_CONFIGED_RD_STRM, | ||
212 | AIC79XX_CONFIGED_RD_STRM, | ||
213 | AIC79XX_CONFIGED_RD_STRM, | ||
214 | AIC79XX_CONFIGED_RD_STRM, | ||
215 | AIC79XX_CONFIGED_RD_STRM, | ||
216 | AIC79XX_CONFIGED_RD_STRM, | ||
217 | AIC79XX_CONFIGED_RD_STRM, | ||
218 | AIC79XX_CONFIGED_RD_STRM, | ||
219 | AIC79XX_CONFIGED_RD_STRM | ||
220 | }; | ||
221 | |||
222 | /* | ||
223 | * DV option: | ||
224 | * | ||
225 | * positive value = DV Enabled | ||
226 | * zero = DV Disabled | ||
227 | * negative value = DV Default for adapter type/seeprom | ||
228 | */ | ||
229 | #ifdef CONFIG_AIC79XX_DV_SETTING | ||
230 | #define AIC79XX_CONFIGED_DV CONFIG_AIC79XX_DV_SETTING | ||
231 | #else | ||
232 | #define AIC79XX_CONFIGED_DV -1 | ||
233 | #endif | ||
234 | |||
235 | static int8_t aic79xx_dv_settings[] = | ||
236 | { | ||
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 | AIC79XX_CONFIGED_DV, | ||
244 | AIC79XX_CONFIGED_DV, | ||
245 | AIC79XX_CONFIGED_DV, | ||
246 | AIC79XX_CONFIGED_DV, | ||
247 | AIC79XX_CONFIGED_DV, | ||
248 | AIC79XX_CONFIGED_DV, | ||
249 | AIC79XX_CONFIGED_DV, | ||
250 | AIC79XX_CONFIGED_DV, | ||
251 | AIC79XX_CONFIGED_DV, | ||
252 | AIC79XX_CONFIGED_DV | ||
253 | }; | ||
254 | |||
255 | /* | ||
256 | * The I/O cell on the chip is very configurable in respect to its analog | 173 | * The I/O cell on the chip is very configurable in respect to its analog |
257 | * characteristics. Set the defaults here; they can be overriden with | 174 | * characteristics. Set the defaults here; they can be overriden with |
258 | * the proper insmod parameters. | 175 | * the proper insmod parameters. |
@@ -375,13 +292,6 @@ static uint32_t aic79xx_pci_parity = ~0; | |||
375 | uint32_t aic79xx_allow_memio = ~0; | 292 | uint32_t aic79xx_allow_memio = ~0; |
376 | 293 | ||
377 | /* | 294 | /* |
378 | * aic79xx_detect() has been run, so register all device arrivals | ||
379 | * immediately with the system rather than deferring to the sorted | ||
380 | * attachment performed by aic79xx_detect(). | ||
381 | */ | ||
382 | int aic79xx_detect_complete; | ||
383 | |||
384 | /* | ||
385 | * So that we can set how long each device is given as a selection timeout. | 295 | * So that we can set how long each device is given as a selection timeout. |
386 | * The table of values goes like this: | 296 | * The table of values goes like this: |
387 | * 0 - 256ms | 297 | * 0 - 256ms |
@@ -412,7 +322,7 @@ MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>"); | |||
412 | MODULE_DESCRIPTION("Adaptec Aic790X U320 SCSI Host Bus Adapter driver"); | 322 | MODULE_DESCRIPTION("Adaptec Aic790X U320 SCSI Host Bus Adapter driver"); |
413 | MODULE_LICENSE("Dual BSD/GPL"); | 323 | MODULE_LICENSE("Dual BSD/GPL"); |
414 | MODULE_VERSION(AIC79XX_DRIVER_VERSION); | 324 | MODULE_VERSION(AIC79XX_DRIVER_VERSION); |
415 | module_param(aic79xx, charp, 0); | 325 | module_param(aic79xx, charp, 0444); |
416 | MODULE_PARM_DESC(aic79xx, | 326 | MODULE_PARM_DESC(aic79xx, |
417 | "period delimited, options string.\n" | 327 | "period delimited, options string.\n" |
418 | " verbose Enable verbose/diagnostic logging\n" | 328 | " verbose Enable verbose/diagnostic logging\n" |
@@ -427,8 +337,6 @@ MODULE_PARM_DESC(aic79xx, | |||
427 | " reverse_scan Sort PCI devices highest Bus/Slot to lowest\n" | 337 | " reverse_scan Sort PCI devices highest Bus/Slot to lowest\n" |
428 | " tag_info:<tag_str> Set per-target tag depth\n" | 338 | " tag_info:<tag_str> Set per-target tag depth\n" |
429 | " global_tag_depth:<int> Global tag depth for all targets on all buses\n" | 339 | " global_tag_depth:<int> Global tag depth for all targets on all buses\n" |
430 | " rd_strm:<rd_strm_masks> Set per-target read streaming setting.\n" | ||
431 | " dv:<dv_settings> Set per-controller Domain Validation Setting.\n" | ||
432 | " slewrate:<slewrate_list>Set the signal slew rate (0-15).\n" | 340 | " slewrate:<slewrate_list>Set the signal slew rate (0-15).\n" |
433 | " precomp:<pcomp_list> Set the signal precompensation (0-7).\n" | 341 | " precomp:<pcomp_list> Set the signal precompensation (0-7).\n" |
434 | " amplitude:<int> Set the signal amplitude (0-7).\n" | 342 | " amplitude:<int> Set the signal amplitude (0-7).\n" |
@@ -441,249 +349,35 @@ MODULE_PARM_DESC(aic79xx, | |||
441 | " Shorten the selection timeout to 128ms\n" | 349 | " Shorten the selection timeout to 128ms\n" |
442 | "\n" | 350 | "\n" |
443 | " options aic79xx 'aic79xx=verbose.tag_info:{{}.{}.{..10}}.seltime:1'\n" | 351 | " options aic79xx 'aic79xx=verbose.tag_info:{{}.{}.{..10}}.seltime:1'\n" |
444 | "\n" | 352 | "\n"); |
445 | " Sample /etc/modprobe.conf line:\n" | ||
446 | " Change Read Streaming for Controller's 2 and 3\n" | ||
447 | "\n" | ||
448 | " options aic79xx 'aic79xx=rd_strm:{..0xFFF0.0xC0F0}'"); | ||
449 | 353 | ||
450 | static void ahd_linux_handle_scsi_status(struct ahd_softc *, | 354 | static void ahd_linux_handle_scsi_status(struct ahd_softc *, |
451 | struct ahd_linux_device *, | 355 | struct scsi_device *, |
452 | struct scb *); | 356 | struct scb *); |
453 | static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, | 357 | static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, |
454 | Scsi_Cmnd *cmd); | 358 | struct scsi_cmnd *cmd); |
455 | static void ahd_linux_filter_inquiry(struct ahd_softc *ahd, | ||
456 | struct ahd_devinfo *devinfo); | ||
457 | static void ahd_linux_dev_timed_unfreeze(u_long arg); | ||
458 | static void ahd_linux_sem_timeout(u_long arg); | 359 | static void ahd_linux_sem_timeout(u_long arg); |
360 | static int ahd_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag); | ||
459 | static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd); | 361 | static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd); |
460 | static void ahd_linux_size_nseg(void); | ||
461 | static void ahd_linux_thread_run_complete_queue(struct ahd_softc *ahd); | ||
462 | static void ahd_linux_start_dv(struct ahd_softc *ahd); | ||
463 | static void ahd_linux_dv_timeout(struct scsi_cmnd *cmd); | ||
464 | static int ahd_linux_dv_thread(void *data); | ||
465 | static void ahd_linux_kill_dv_thread(struct ahd_softc *ahd); | ||
466 | static void ahd_linux_dv_target(struct ahd_softc *ahd, u_int target); | ||
467 | static void ahd_linux_dv_transition(struct ahd_softc *ahd, | ||
468 | struct scsi_cmnd *cmd, | ||
469 | struct ahd_devinfo *devinfo, | ||
470 | struct ahd_linux_target *targ); | ||
471 | static void ahd_linux_dv_fill_cmd(struct ahd_softc *ahd, | ||
472 | struct scsi_cmnd *cmd, | ||
473 | struct ahd_devinfo *devinfo); | ||
474 | static void ahd_linux_dv_inq(struct ahd_softc *ahd, | ||
475 | struct scsi_cmnd *cmd, | ||
476 | struct ahd_devinfo *devinfo, | ||
477 | struct ahd_linux_target *targ, | ||
478 | u_int request_length); | ||
479 | static void ahd_linux_dv_tur(struct ahd_softc *ahd, | ||
480 | struct scsi_cmnd *cmd, | ||
481 | struct ahd_devinfo *devinfo); | ||
482 | static void ahd_linux_dv_rebd(struct ahd_softc *ahd, | ||
483 | struct scsi_cmnd *cmd, | ||
484 | struct ahd_devinfo *devinfo, | ||
485 | struct ahd_linux_target *targ); | ||
486 | static void ahd_linux_dv_web(struct ahd_softc *ahd, | ||
487 | struct scsi_cmnd *cmd, | ||
488 | struct ahd_devinfo *devinfo, | ||
489 | struct ahd_linux_target *targ); | ||
490 | static void ahd_linux_dv_reb(struct ahd_softc *ahd, | ||
491 | struct scsi_cmnd *cmd, | ||
492 | struct ahd_devinfo *devinfo, | ||
493 | struct ahd_linux_target *targ); | ||
494 | static void ahd_linux_dv_su(struct ahd_softc *ahd, | ||
495 | struct scsi_cmnd *cmd, | ||
496 | struct ahd_devinfo *devinfo, | ||
497 | struct ahd_linux_target *targ); | ||
498 | static int ahd_linux_fallback(struct ahd_softc *ahd, | ||
499 | struct ahd_devinfo *devinfo); | ||
500 | static __inline int ahd_linux_dv_fallback(struct ahd_softc *ahd, | ||
501 | struct ahd_devinfo *devinfo); | ||
502 | static void ahd_linux_dv_complete(Scsi_Cmnd *cmd); | ||
503 | static void ahd_linux_generate_dv_pattern(struct ahd_linux_target *targ); | ||
504 | static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd, | 362 | static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd, |
505 | struct ahd_devinfo *devinfo); | 363 | struct ahd_devinfo *devinfo); |
506 | static u_int ahd_linux_user_dv_setting(struct ahd_softc *ahd); | 364 | static void ahd_linux_device_queue_depth(struct scsi_device *); |
507 | static void ahd_linux_setup_user_rd_strm_settings(struct ahd_softc *ahd); | 365 | static int ahd_linux_run_command(struct ahd_softc*, |
508 | static void ahd_linux_device_queue_depth(struct ahd_softc *ahd, | 366 | struct ahd_linux_device *, |
509 | struct ahd_linux_device *dev); | 367 | struct scsi_cmnd *); |
510 | static struct ahd_linux_target* ahd_linux_alloc_target(struct ahd_softc*, | ||
511 | u_int, u_int); | ||
512 | static void ahd_linux_free_target(struct ahd_softc*, | ||
513 | struct ahd_linux_target*); | ||
514 | static struct ahd_linux_device* ahd_linux_alloc_device(struct ahd_softc*, | ||
515 | struct ahd_linux_target*, | ||
516 | u_int); | ||
517 | static void ahd_linux_free_device(struct ahd_softc*, | ||
518 | struct ahd_linux_device*); | ||
519 | static void ahd_linux_run_device_queue(struct ahd_softc*, | ||
520 | struct ahd_linux_device*); | ||
521 | static void ahd_linux_setup_tag_info_global(char *p); | 368 | static void ahd_linux_setup_tag_info_global(char *p); |
522 | static aic_option_callback_t ahd_linux_setup_tag_info; | 369 | static int aic79xx_setup(char *c); |
523 | static aic_option_callback_t ahd_linux_setup_rd_strm_info; | ||
524 | static aic_option_callback_t ahd_linux_setup_dv; | ||
525 | static aic_option_callback_t ahd_linux_setup_iocell_info; | ||
526 | static int ahd_linux_next_unit(void); | ||
527 | static void ahd_runq_tasklet(unsigned long data); | ||
528 | static int aic79xx_setup(char *c); | ||
529 | |||
530 | /****************************** Inlines ***************************************/ | ||
531 | static __inline void ahd_schedule_completeq(struct ahd_softc *ahd); | ||
532 | static __inline void ahd_schedule_runq(struct ahd_softc *ahd); | ||
533 | static __inline void ahd_setup_runq_tasklet(struct ahd_softc *ahd); | ||
534 | static __inline void ahd_teardown_runq_tasklet(struct ahd_softc *ahd); | ||
535 | static __inline struct ahd_linux_device* | ||
536 | ahd_linux_get_device(struct ahd_softc *ahd, u_int channel, | ||
537 | u_int target, u_int lun, int alloc); | ||
538 | static struct ahd_cmd *ahd_linux_run_complete_queue(struct ahd_softc *ahd); | ||
539 | static __inline void ahd_linux_check_device_queue(struct ahd_softc *ahd, | ||
540 | struct ahd_linux_device *dev); | ||
541 | static __inline struct ahd_linux_device * | ||
542 | ahd_linux_next_device_to_run(struct ahd_softc *ahd); | ||
543 | static __inline void ahd_linux_run_device_queues(struct ahd_softc *ahd); | ||
544 | static __inline void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*); | ||
545 | |||
546 | static __inline void | ||
547 | ahd_schedule_completeq(struct ahd_softc *ahd) | ||
548 | { | ||
549 | if ((ahd->platform_data->flags & AHD_RUN_CMPLT_Q_TIMER) == 0) { | ||
550 | ahd->platform_data->flags |= AHD_RUN_CMPLT_Q_TIMER; | ||
551 | ahd->platform_data->completeq_timer.expires = jiffies; | ||
552 | add_timer(&ahd->platform_data->completeq_timer); | ||
553 | } | ||
554 | } | ||
555 | |||
556 | /* | ||
557 | * Must be called with our lock held. | ||
558 | */ | ||
559 | static __inline void | ||
560 | ahd_schedule_runq(struct ahd_softc *ahd) | ||
561 | { | ||
562 | tasklet_schedule(&ahd->platform_data->runq_tasklet); | ||
563 | } | ||
564 | |||
565 | static __inline | ||
566 | void ahd_setup_runq_tasklet(struct ahd_softc *ahd) | ||
567 | { | ||
568 | tasklet_init(&ahd->platform_data->runq_tasklet, ahd_runq_tasklet, | ||
569 | (unsigned long)ahd); | ||
570 | } | ||
571 | 370 | ||
572 | static __inline void | 371 | static int ahd_linux_unit; |
573 | ahd_teardown_runq_tasklet(struct ahd_softc *ahd) | ||
574 | { | ||
575 | tasklet_kill(&ahd->platform_data->runq_tasklet); | ||
576 | } | ||
577 | 372 | ||
578 | static __inline struct ahd_linux_device* | ||
579 | ahd_linux_get_device(struct ahd_softc *ahd, u_int channel, u_int target, | ||
580 | u_int lun, int alloc) | ||
581 | { | ||
582 | struct ahd_linux_target *targ; | ||
583 | struct ahd_linux_device *dev; | ||
584 | u_int target_offset; | ||
585 | 373 | ||
586 | target_offset = target; | 374 | /****************************** Inlines ***************************************/ |
587 | if (channel != 0) | 375 | static __inline void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*); |
588 | target_offset += 8; | ||
589 | targ = ahd->platform_data->targets[target_offset]; | ||
590 | if (targ == NULL) { | ||
591 | if (alloc != 0) { | ||
592 | targ = ahd_linux_alloc_target(ahd, channel, target); | ||
593 | if (targ == NULL) | ||
594 | return (NULL); | ||
595 | } else | ||
596 | return (NULL); | ||
597 | } | ||
598 | dev = targ->devices[lun]; | ||
599 | if (dev == NULL && alloc != 0) | ||
600 | dev = ahd_linux_alloc_device(ahd, targ, lun); | ||
601 | return (dev); | ||
602 | } | ||
603 | |||
604 | #define AHD_LINUX_MAX_RETURNED_ERRORS 4 | ||
605 | static struct ahd_cmd * | ||
606 | ahd_linux_run_complete_queue(struct ahd_softc *ahd) | ||
607 | { | ||
608 | struct ahd_cmd *acmd; | ||
609 | u_long done_flags; | ||
610 | int with_errors; | ||
611 | |||
612 | with_errors = 0; | ||
613 | ahd_done_lock(ahd, &done_flags); | ||
614 | while ((acmd = TAILQ_FIRST(&ahd->platform_data->completeq)) != NULL) { | ||
615 | Scsi_Cmnd *cmd; | ||
616 | |||
617 | if (with_errors > AHD_LINUX_MAX_RETURNED_ERRORS) { | ||
618 | /* | ||
619 | * Linux uses stack recursion to requeue | ||
620 | * commands that need to be retried. Avoid | ||
621 | * blowing out the stack by "spoon feeding" | ||
622 | * commands that completed with error back | ||
623 | * the operating system in case they are going | ||
624 | * to be retried. "ick" | ||
625 | */ | ||
626 | ahd_schedule_completeq(ahd); | ||
627 | break; | ||
628 | } | ||
629 | TAILQ_REMOVE(&ahd->platform_data->completeq, | ||
630 | acmd, acmd_links.tqe); | ||
631 | cmd = &acmd_scsi_cmd(acmd); | ||
632 | cmd->host_scribble = NULL; | ||
633 | if (ahd_cmd_get_transaction_status(cmd) != DID_OK | ||
634 | || (cmd->result & 0xFF) != SCSI_STATUS_OK) | ||
635 | with_errors++; | ||
636 | |||
637 | cmd->scsi_done(cmd); | ||
638 | } | ||
639 | ahd_done_unlock(ahd, &done_flags); | ||
640 | return (acmd); | ||
641 | } | ||
642 | |||
643 | static __inline void | ||
644 | ahd_linux_check_device_queue(struct ahd_softc *ahd, | ||
645 | struct ahd_linux_device *dev) | ||
646 | { | ||
647 | if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) != 0 | ||
648 | && dev->active == 0) { | ||
649 | dev->flags &= ~AHD_DEV_FREEZE_TIL_EMPTY; | ||
650 | dev->qfrozen--; | ||
651 | } | ||
652 | |||
653 | if (TAILQ_FIRST(&dev->busyq) == NULL | ||
654 | || dev->openings == 0 || dev->qfrozen != 0) | ||
655 | return; | ||
656 | |||
657 | ahd_linux_run_device_queue(ahd, dev); | ||
658 | } | ||
659 | |||
660 | static __inline struct ahd_linux_device * | ||
661 | ahd_linux_next_device_to_run(struct ahd_softc *ahd) | ||
662 | { | ||
663 | |||
664 | if ((ahd->flags & AHD_RESOURCE_SHORTAGE) != 0 | ||
665 | || (ahd->platform_data->qfrozen != 0 | ||
666 | && AHD_DV_SIMQ_FROZEN(ahd) == 0)) | ||
667 | return (NULL); | ||
668 | return (TAILQ_FIRST(&ahd->platform_data->device_runq)); | ||
669 | } | ||
670 | |||
671 | static __inline void | ||
672 | ahd_linux_run_device_queues(struct ahd_softc *ahd) | ||
673 | { | ||
674 | struct ahd_linux_device *dev; | ||
675 | |||
676 | while ((dev = ahd_linux_next_device_to_run(ahd)) != NULL) { | ||
677 | TAILQ_REMOVE(&ahd->platform_data->device_runq, dev, links); | ||
678 | dev->flags &= ~AHD_DEV_ON_RUN_LIST; | ||
679 | ahd_linux_check_device_queue(ahd, dev); | ||
680 | } | ||
681 | } | ||
682 | 376 | ||
683 | static __inline void | 377 | static __inline void |
684 | ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb) | 378 | ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb) |
685 | { | 379 | { |
686 | Scsi_Cmnd *cmd; | 380 | struct scsi_cmnd *cmd; |
687 | int direction; | 381 | int direction; |
688 | 382 | ||
689 | cmd = scb->io_ctx; | 383 | cmd = scb->io_ctx; |
@@ -705,197 +399,6 @@ ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb) | |||
705 | #define BUILD_SCSIID(ahd, cmd) \ | 399 | #define BUILD_SCSIID(ahd, cmd) \ |
706 | ((((cmd)->device->id << TID_SHIFT) & TID) | (ahd)->our_id) | 400 | ((((cmd)->device->id << TID_SHIFT) & TID) | (ahd)->our_id) |
707 | 401 | ||
708 | /************************ Host template entry points *************************/ | ||
709 | static int ahd_linux_detect(Scsi_Host_Template *); | ||
710 | static const char *ahd_linux_info(struct Scsi_Host *); | ||
711 | static int ahd_linux_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *)); | ||
712 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | ||
713 | static int ahd_linux_slave_alloc(Scsi_Device *); | ||
714 | static int ahd_linux_slave_configure(Scsi_Device *); | ||
715 | static void ahd_linux_slave_destroy(Scsi_Device *); | ||
716 | #if defined(__i386__) | ||
717 | static int ahd_linux_biosparam(struct scsi_device*, | ||
718 | struct block_device*, sector_t, int[]); | ||
719 | #endif | ||
720 | #else | ||
721 | static int ahd_linux_release(struct Scsi_Host *); | ||
722 | static void ahd_linux_select_queue_depth(struct Scsi_Host *host, | ||
723 | Scsi_Device *scsi_devs); | ||
724 | #if defined(__i386__) | ||
725 | static int ahd_linux_biosparam(Disk *, kdev_t, int[]); | ||
726 | #endif | ||
727 | #endif | ||
728 | static int ahd_linux_bus_reset(Scsi_Cmnd *); | ||
729 | static int ahd_linux_dev_reset(Scsi_Cmnd *); | ||
730 | static int ahd_linux_abort(Scsi_Cmnd *); | ||
731 | |||
732 | /* | ||
733 | * Calculate a safe value for AHD_NSEG (as expressed through ahd_linux_nseg). | ||
734 | * | ||
735 | * In pre-2.5.X... | ||
736 | * The midlayer allocates an S/G array dynamically when a command is issued | ||
737 | * using SCSI malloc. This array, which is in an OS dependent format that | ||
738 | * must later be copied to our private S/G list, is sized to house just the | ||
739 | * number of segments needed for the current transfer. Since the code that | ||
740 | * sizes the SCSI malloc pool does not take into consideration fragmentation | ||
741 | * of the pool, executing transactions numbering just a fraction of our | ||
742 | * concurrent transaction limit with SG list lengths aproaching AHC_NSEG will | ||
743 | * quickly depleat the SCSI malloc pool of usable space. Unfortunately, the | ||
744 | * mid-layer does not properly handle this scsi malloc failures for the S/G | ||
745 | * array and the result can be a lockup of the I/O subsystem. We try to size | ||
746 | * our S/G list so that it satisfies our drivers allocation requirements in | ||
747 | * addition to avoiding fragmentation of the SCSI malloc pool. | ||
748 | */ | ||
749 | static void | ||
750 | ahd_linux_size_nseg(void) | ||
751 | { | ||
752 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) | ||
753 | u_int cur_size; | ||
754 | u_int best_size; | ||
755 | |||
756 | /* | ||
757 | * The SCSI allocator rounds to the nearest 512 bytes | ||
758 | * an cannot allocate across a page boundary. Our algorithm | ||
759 | * is to start at 1K of scsi malloc space per-command and | ||
760 | * loop through all factors of the PAGE_SIZE and pick the best. | ||
761 | */ | ||
762 | best_size = 0; | ||
763 | for (cur_size = 1024; cur_size <= PAGE_SIZE; cur_size *= 2) { | ||
764 | u_int nseg; | ||
765 | |||
766 | nseg = cur_size / sizeof(struct scatterlist); | ||
767 | if (nseg < AHD_LINUX_MIN_NSEG) | ||
768 | continue; | ||
769 | |||
770 | if (best_size == 0) { | ||
771 | best_size = cur_size; | ||
772 | ahd_linux_nseg = nseg; | ||
773 | } else { | ||
774 | u_int best_rem; | ||
775 | u_int cur_rem; | ||
776 | |||
777 | /* | ||
778 | * Compare the traits of the current "best_size" | ||
779 | * with the current size to determine if the | ||
780 | * current size is a better size. | ||
781 | */ | ||
782 | best_rem = best_size % sizeof(struct scatterlist); | ||
783 | cur_rem = cur_size % sizeof(struct scatterlist); | ||
784 | if (cur_rem < best_rem) { | ||
785 | best_size = cur_size; | ||
786 | ahd_linux_nseg = nseg; | ||
787 | } | ||
788 | } | ||
789 | } | ||
790 | #endif | ||
791 | } | ||
792 | |||
793 | /* | ||
794 | * Try to detect an Adaptec 79XX controller. | ||
795 | */ | ||
796 | static int | ||
797 | ahd_linux_detect(Scsi_Host_Template *template) | ||
798 | { | ||
799 | struct ahd_softc *ahd; | ||
800 | int found; | ||
801 | int error = 0; | ||
802 | |||
803 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) | ||
804 | /* | ||
805 | * It is a bug that the upper layer takes | ||
806 | * this lock just prior to calling us. | ||
807 | */ | ||
808 | spin_unlock_irq(&io_request_lock); | ||
809 | #endif | ||
810 | |||
811 | /* | ||
812 | * Sanity checking of Linux SCSI data structures so | ||
813 | * that some of our hacks^H^H^H^H^Hassumptions aren't | ||
814 | * violated. | ||
815 | */ | ||
816 | if (offsetof(struct ahd_cmd_internal, end) | ||
817 | > offsetof(struct scsi_cmnd, host_scribble)) { | ||
818 | printf("ahd_linux_detect: SCSI data structures changed.\n"); | ||
819 | printf("ahd_linux_detect: Unable to attach\n"); | ||
820 | return (0); | ||
821 | } | ||
822 | /* | ||
823 | * Determine an appropriate size for our Scatter Gatther lists. | ||
824 | */ | ||
825 | ahd_linux_size_nseg(); | ||
826 | #ifdef MODULE | ||
827 | /* | ||
828 | * If we've been passed any parameters, process them now. | ||
829 | */ | ||
830 | if (aic79xx) | ||
831 | aic79xx_setup(aic79xx); | ||
832 | #endif | ||
833 | |||
834 | template->proc_name = "aic79xx"; | ||
835 | |||
836 | /* | ||
837 | * Initialize our softc list lock prior to | ||
838 | * probing for any adapters. | ||
839 | */ | ||
840 | ahd_list_lockinit(); | ||
841 | |||
842 | #ifdef CONFIG_PCI | ||
843 | error = ahd_linux_pci_init(); | ||
844 | if (error) | ||
845 | return error; | ||
846 | #endif | ||
847 | |||
848 | /* | ||
849 | * Register with the SCSI layer all | ||
850 | * controllers we've found. | ||
851 | */ | ||
852 | found = 0; | ||
853 | TAILQ_FOREACH(ahd, &ahd_tailq, links) { | ||
854 | |||
855 | if (ahd_linux_register_host(ahd, template) == 0) | ||
856 | found++; | ||
857 | } | ||
858 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) | ||
859 | spin_lock_irq(&io_request_lock); | ||
860 | #endif | ||
861 | aic79xx_detect_complete++; | ||
862 | return 0; | ||
863 | } | ||
864 | |||
865 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) | ||
866 | /* | ||
867 | * Free the passed in Scsi_Host memory structures prior to unloading the | ||
868 | * module. | ||
869 | */ | ||
870 | static int | ||
871 | ahd_linux_release(struct Scsi_Host * host) | ||
872 | { | ||
873 | struct ahd_softc *ahd; | ||
874 | u_long l; | ||
875 | |||
876 | ahd_list_lock(&l); | ||
877 | if (host != NULL) { | ||
878 | |||
879 | /* | ||
880 | * We should be able to just perform | ||
881 | * the free directly, but check our | ||
882 | * list for extra sanity. | ||
883 | */ | ||
884 | ahd = ahd_find_softc(*(struct ahd_softc **)host->hostdata); | ||
885 | if (ahd != NULL) { | ||
886 | u_long s; | ||
887 | |||
888 | ahd_lock(ahd, &s); | ||
889 | ahd_intr_enable(ahd, FALSE); | ||
890 | ahd_unlock(ahd, &s); | ||
891 | ahd_free(ahd); | ||
892 | } | ||
893 | } | ||
894 | ahd_list_unlock(&l); | ||
895 | return (0); | ||
896 | } | ||
897 | #endif | ||
898 | |||
899 | /* | 402 | /* |
900 | * Return a string describing the driver. | 403 | * Return a string describing the driver. |
901 | */ | 404 | */ |
@@ -928,220 +431,177 @@ ahd_linux_info(struct Scsi_Host *host) | |||
928 | * Queue an SCB to the controller. | 431 | * Queue an SCB to the controller. |
929 | */ | 432 | */ |
930 | static int | 433 | static int |
931 | ahd_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *)) | 434 | ahd_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *)) |
932 | { | 435 | { |
933 | struct ahd_softc *ahd; | 436 | struct ahd_softc *ahd; |
934 | struct ahd_linux_device *dev; | 437 | struct ahd_linux_device *dev = scsi_transport_device_data(cmd->device); |
935 | u_long flags; | ||
936 | 438 | ||
937 | ahd = *(struct ahd_softc **)cmd->device->host->hostdata; | 439 | ahd = *(struct ahd_softc **)cmd->device->host->hostdata; |
938 | 440 | ||
939 | /* | 441 | /* |
940 | * Save the callback on completion function. | ||
941 | */ | ||
942 | cmd->scsi_done = scsi_done; | ||
943 | |||
944 | ahd_midlayer_entrypoint_lock(ahd, &flags); | ||
945 | |||
946 | /* | ||
947 | * Close the race of a command that was in the process of | 442 | * Close the race of a command that was in the process of |
948 | * being queued to us just as our simq was frozen. Let | 443 | * being queued to us just as our simq was frozen. Let |
949 | * DV commands through so long as we are only frozen to | 444 | * DV commands through so long as we are only frozen to |
950 | * perform DV. | 445 | * perform DV. |
951 | */ | 446 | */ |
952 | if (ahd->platform_data->qfrozen != 0 | 447 | if (ahd->platform_data->qfrozen != 0) { |
953 | && AHD_DV_CMD(cmd) == 0) { | 448 | printf("%s: queue frozen\n", ahd_name(ahd)); |
954 | 449 | ||
955 | ahd_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ); | 450 | return SCSI_MLQUEUE_HOST_BUSY; |
956 | ahd_linux_queue_cmd_complete(ahd, cmd); | ||
957 | ahd_schedule_completeq(ahd); | ||
958 | ahd_midlayer_entrypoint_unlock(ahd, &flags); | ||
959 | return (0); | ||
960 | } | ||
961 | dev = ahd_linux_get_device(ahd, cmd->device->channel, | ||
962 | cmd->device->id, cmd->device->lun, | ||
963 | /*alloc*/TRUE); | ||
964 | if (dev == NULL) { | ||
965 | ahd_cmd_set_transaction_status(cmd, CAM_RESRC_UNAVAIL); | ||
966 | ahd_linux_queue_cmd_complete(ahd, cmd); | ||
967 | ahd_schedule_completeq(ahd); | ||
968 | ahd_midlayer_entrypoint_unlock(ahd, &flags); | ||
969 | printf("%s: aic79xx_linux_queue - Unable to allocate device!\n", | ||
970 | ahd_name(ahd)); | ||
971 | return (0); | ||
972 | } | 451 | } |
973 | if (cmd->cmd_len > MAX_CDB_LEN) | 452 | |
974 | return (-EINVAL); | 453 | /* |
454 | * Save the callback on completion function. | ||
455 | */ | ||
456 | cmd->scsi_done = scsi_done; | ||
457 | |||
975 | cmd->result = CAM_REQ_INPROG << 16; | 458 | cmd->result = CAM_REQ_INPROG << 16; |
976 | TAILQ_INSERT_TAIL(&dev->busyq, (struct ahd_cmd *)cmd, acmd_links.tqe); | 459 | |
977 | if ((dev->flags & AHD_DEV_ON_RUN_LIST) == 0) { | 460 | return ahd_linux_run_command(ahd, dev, cmd); |
978 | TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, dev, links); | 461 | } |
979 | dev->flags |= AHD_DEV_ON_RUN_LIST; | 462 | |
980 | ahd_linux_run_device_queues(ahd); | 463 | static inline struct scsi_target ** |
981 | } | 464 | ahd_linux_target_in_softc(struct scsi_target *starget) |
982 | ahd_midlayer_entrypoint_unlock(ahd, &flags); | 465 | { |
983 | return (0); | 466 | struct ahd_softc *ahd = |
467 | *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata); | ||
468 | unsigned int target_offset; | ||
469 | |||
470 | target_offset = starget->id; | ||
471 | if (starget->channel != 0) | ||
472 | target_offset += 8; | ||
473 | |||
474 | return &ahd->platform_data->starget[target_offset]; | ||
984 | } | 475 | } |
985 | 476 | ||
986 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | ||
987 | static int | 477 | static int |
988 | ahd_linux_slave_alloc(Scsi_Device *device) | 478 | ahd_linux_target_alloc(struct scsi_target *starget) |
989 | { | 479 | { |
990 | struct ahd_softc *ahd; | 480 | struct ahd_softc *ahd = |
481 | *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata); | ||
482 | unsigned long flags; | ||
483 | struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget); | ||
484 | struct ahd_linux_target *targ = scsi_transport_target_data(starget); | ||
485 | struct ahd_devinfo devinfo; | ||
486 | struct ahd_initiator_tinfo *tinfo; | ||
487 | struct ahd_tmode_tstate *tstate; | ||
488 | char channel = starget->channel + 'A'; | ||
991 | 489 | ||
992 | ahd = *((struct ahd_softc **)device->host->hostdata); | 490 | ahd_lock(ahd, &flags); |
993 | if (bootverbose) | 491 | |
994 | printf("%s: Slave Alloc %d\n", ahd_name(ahd), device->id); | 492 | BUG_ON(*ahd_targp != NULL); |
995 | return (0); | 493 | |
494 | *ahd_targp = starget; | ||
495 | memset(targ, 0, sizeof(*targ)); | ||
496 | |||
497 | tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id, | ||
498 | starget->id, &tstate); | ||
499 | ahd_compile_devinfo(&devinfo, ahd->our_id, starget->id, | ||
500 | CAM_LUN_WILDCARD, channel, | ||
501 | ROLE_INITIATOR); | ||
502 | spi_min_period(starget) = AHD_SYNCRATE_MAX; /* We can do U320 */ | ||
503 | if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) | ||
504 | spi_max_offset(starget) = MAX_OFFSET_PACED_BUG; | ||
505 | else | ||
506 | spi_max_offset(starget) = MAX_OFFSET_PACED; | ||
507 | spi_max_width(starget) = ahd->features & AHD_WIDE; | ||
508 | |||
509 | ahd_set_syncrate(ahd, &devinfo, 0, 0, 0, | ||
510 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
511 | ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT, | ||
512 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
513 | ahd_unlock(ahd, &flags); | ||
514 | |||
515 | return 0; | ||
516 | } | ||
517 | |||
518 | static void | ||
519 | ahd_linux_target_destroy(struct scsi_target *starget) | ||
520 | { | ||
521 | struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget); | ||
522 | |||
523 | *ahd_targp = NULL; | ||
996 | } | 524 | } |
997 | 525 | ||
998 | static int | 526 | static int |
999 | ahd_linux_slave_configure(Scsi_Device *device) | 527 | ahd_linux_slave_alloc(struct scsi_device *sdev) |
1000 | { | 528 | { |
1001 | struct ahd_softc *ahd; | 529 | struct ahd_softc *ahd = |
1002 | struct ahd_linux_device *dev; | 530 | *((struct ahd_softc **)sdev->host->hostdata); |
1003 | u_long flags; | 531 | struct scsi_target *starget = sdev->sdev_target; |
532 | struct ahd_linux_target *targ = scsi_transport_target_data(starget); | ||
533 | struct ahd_linux_device *dev; | ||
1004 | 534 | ||
1005 | ahd = *((struct ahd_softc **)device->host->hostdata); | ||
1006 | if (bootverbose) | 535 | if (bootverbose) |
1007 | printf("%s: Slave Configure %d\n", ahd_name(ahd), device->id); | 536 | printf("%s: Slave Alloc %d\n", ahd_name(ahd), sdev->id); |
1008 | ahd_midlayer_entrypoint_lock(ahd, &flags); | 537 | |
538 | BUG_ON(targ->sdev[sdev->lun] != NULL); | ||
539 | |||
540 | dev = scsi_transport_device_data(sdev); | ||
541 | memset(dev, 0, sizeof(*dev)); | ||
542 | |||
1009 | /* | 543 | /* |
1010 | * Since Linux has attached to the device, configure | 544 | * We start out life using untagged |
1011 | * it so we don't free and allocate the device | 545 | * transactions of which we allow one. |
1012 | * structure on every command. | ||
1013 | */ | 546 | */ |
1014 | dev = ahd_linux_get_device(ahd, device->channel, | 547 | dev->openings = 1; |
1015 | device->id, device->lun, | 548 | |
1016 | /*alloc*/TRUE); | 549 | /* |
1017 | if (dev != NULL) { | 550 | * Set maxtags to 0. This will be changed if we |
1018 | dev->flags &= ~AHD_DEV_UNCONFIGURED; | 551 | * later determine that we are dealing with |
1019 | dev->flags |= AHD_DEV_SLAVE_CONFIGURED; | 552 | * a tagged queuing capable device. |
1020 | dev->scsi_device = device; | 553 | */ |
1021 | ahd_linux_device_queue_depth(ahd, dev); | 554 | dev->maxtags = 0; |
1022 | } | 555 | |
1023 | ahd_midlayer_entrypoint_unlock(ahd, &flags); | 556 | targ->sdev[sdev->lun] = sdev; |
557 | |||
1024 | return (0); | 558 | return (0); |
1025 | } | 559 | } |
1026 | 560 | ||
1027 | static void | 561 | static int |
1028 | ahd_linux_slave_destroy(Scsi_Device *device) | 562 | ahd_linux_slave_configure(struct scsi_device *sdev) |
1029 | { | 563 | { |
1030 | struct ahd_softc *ahd; | 564 | struct ahd_softc *ahd; |
1031 | struct ahd_linux_device *dev; | ||
1032 | u_long flags; | ||
1033 | 565 | ||
1034 | ahd = *((struct ahd_softc **)device->host->hostdata); | 566 | ahd = *((struct ahd_softc **)sdev->host->hostdata); |
1035 | if (bootverbose) | 567 | if (bootverbose) |
1036 | printf("%s: Slave Destroy %d\n", ahd_name(ahd), device->id); | 568 | printf("%s: Slave Configure %d\n", ahd_name(ahd), sdev->id); |
1037 | ahd_midlayer_entrypoint_lock(ahd, &flags); | ||
1038 | dev = ahd_linux_get_device(ahd, device->channel, | ||
1039 | device->id, device->lun, | ||
1040 | /*alloc*/FALSE); | ||
1041 | 569 | ||
1042 | /* | 570 | ahd_linux_device_queue_depth(sdev); |
1043 | * Filter out "silly" deletions of real devices by only | 571 | |
1044 | * deleting devices that have had slave_configure() | 572 | /* Initial Domain Validation */ |
1045 | * called on them. All other devices that have not | 573 | if (!spi_initial_dv(sdev->sdev_target)) |
1046 | * been configured will automatically be deleted by | 574 | spi_dv_device(sdev); |
1047 | * the refcounting process. | 575 | |
1048 | */ | 576 | return 0; |
1049 | if (dev != NULL | ||
1050 | && (dev->flags & AHD_DEV_SLAVE_CONFIGURED) != 0) { | ||
1051 | dev->flags |= AHD_DEV_UNCONFIGURED; | ||
1052 | if (TAILQ_EMPTY(&dev->busyq) | ||
1053 | && dev->active == 0 | ||
1054 | && (dev->flags & AHD_DEV_TIMER_ACTIVE) == 0) | ||
1055 | ahd_linux_free_device(ahd, dev); | ||
1056 | } | ||
1057 | ahd_midlayer_entrypoint_unlock(ahd, &flags); | ||
1058 | } | 577 | } |
1059 | #else | 578 | |
1060 | /* | ||
1061 | * Sets the queue depth for each SCSI device hanging | ||
1062 | * off the input host adapter. | ||
1063 | */ | ||
1064 | static void | 579 | static void |
1065 | ahd_linux_select_queue_depth(struct Scsi_Host * host, | 580 | ahd_linux_slave_destroy(struct scsi_device *sdev) |
1066 | Scsi_Device * scsi_devs) | ||
1067 | { | 581 | { |
1068 | Scsi_Device *device; | ||
1069 | Scsi_Device *ldev; | ||
1070 | struct ahd_softc *ahd; | 582 | struct ahd_softc *ahd; |
1071 | u_long flags; | 583 | struct ahd_linux_device *dev = scsi_transport_device_data(sdev); |
584 | struct ahd_linux_target *targ = scsi_transport_target_data(sdev->sdev_target); | ||
1072 | 585 | ||
1073 | ahd = *((struct ahd_softc **)host->hostdata); | 586 | ahd = *((struct ahd_softc **)sdev->host->hostdata); |
1074 | ahd_lock(ahd, &flags); | 587 | if (bootverbose) |
1075 | for (device = scsi_devs; device != NULL; device = device->next) { | 588 | printf("%s: Slave Destroy %d\n", ahd_name(ahd), sdev->id); |
1076 | 589 | ||
1077 | /* | 590 | BUG_ON(dev->active); |
1078 | * Watch out for duplicate devices. This works around | ||
1079 | * some quirks in how the SCSI scanning code does its | ||
1080 | * device management. | ||
1081 | */ | ||
1082 | for (ldev = scsi_devs; ldev != device; ldev = ldev->next) { | ||
1083 | if (ldev->host == device->host | ||
1084 | && ldev->channel == device->channel | ||
1085 | && ldev->id == device->id | ||
1086 | && ldev->lun == device->lun) | ||
1087 | break; | ||
1088 | } | ||
1089 | /* Skip duplicate. */ | ||
1090 | if (ldev != device) | ||
1091 | continue; | ||
1092 | 591 | ||
1093 | if (device->host == host) { | 592 | targ->sdev[sdev->lun] = NULL; |
1094 | struct ahd_linux_device *dev; | ||
1095 | 593 | ||
1096 | /* | ||
1097 | * Since Linux has attached to the device, configure | ||
1098 | * it so we don't free and allocate the device | ||
1099 | * structure on every command. | ||
1100 | */ | ||
1101 | dev = ahd_linux_get_device(ahd, device->channel, | ||
1102 | device->id, device->lun, | ||
1103 | /*alloc*/TRUE); | ||
1104 | if (dev != NULL) { | ||
1105 | dev->flags &= ~AHD_DEV_UNCONFIGURED; | ||
1106 | dev->scsi_device = device; | ||
1107 | ahd_linux_device_queue_depth(ahd, dev); | ||
1108 | device->queue_depth = dev->openings | ||
1109 | + dev->active; | ||
1110 | if ((dev->flags & (AHD_DEV_Q_BASIC | ||
1111 | | AHD_DEV_Q_TAGGED)) == 0) { | ||
1112 | /* | ||
1113 | * We allow the OS to queue 2 untagged | ||
1114 | * transactions to us at any time even | ||
1115 | * though we can only execute them | ||
1116 | * serially on the controller/device. | ||
1117 | * This should remove some latency. | ||
1118 | */ | ||
1119 | device->queue_depth = 2; | ||
1120 | } | ||
1121 | } | ||
1122 | } | ||
1123 | } | ||
1124 | ahd_unlock(ahd, &flags); | ||
1125 | } | 594 | } |
1126 | #endif | ||
1127 | 595 | ||
1128 | #if defined(__i386__) | 596 | #if defined(__i386__) |
1129 | /* | 597 | /* |
1130 | * Return the disk geometry for the given SCSI device. | 598 | * Return the disk geometry for the given SCSI device. |
1131 | */ | 599 | */ |
1132 | static int | 600 | static int |
1133 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | ||
1134 | ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev, | 601 | ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev, |
1135 | sector_t capacity, int geom[]) | 602 | sector_t capacity, int geom[]) |
1136 | { | 603 | { |
1137 | uint8_t *bh; | 604 | uint8_t *bh; |
1138 | #else | ||
1139 | ahd_linux_biosparam(Disk *disk, kdev_t dev, int geom[]) | ||
1140 | { | ||
1141 | struct scsi_device *sdev = disk->device; | ||
1142 | u_long capacity = disk->capacity; | ||
1143 | struct buffer_head *bh; | ||
1144 | #endif | ||
1145 | int heads; | 605 | int heads; |
1146 | int sectors; | 606 | int sectors; |
1147 | int cylinders; | 607 | int cylinders; |
@@ -1151,22 +611,11 @@ ahd_linux_biosparam(Disk *disk, kdev_t dev, int geom[]) | |||
1151 | 611 | ||
1152 | ahd = *((struct ahd_softc **)sdev->host->hostdata); | 612 | ahd = *((struct ahd_softc **)sdev->host->hostdata); |
1153 | 613 | ||
1154 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | ||
1155 | bh = scsi_bios_ptable(bdev); | 614 | bh = scsi_bios_ptable(bdev); |
1156 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,17) | ||
1157 | bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, block_size(dev)); | ||
1158 | #else | ||
1159 | bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, 1024); | ||
1160 | #endif | ||
1161 | |||
1162 | if (bh) { | 615 | if (bh) { |
1163 | ret = scsi_partsize(bh, capacity, | 616 | ret = scsi_partsize(bh, capacity, |
1164 | &geom[2], &geom[0], &geom[1]); | 617 | &geom[2], &geom[0], &geom[1]); |
1165 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | ||
1166 | kfree(bh); | 618 | kfree(bh); |
1167 | #else | ||
1168 | brelse(bh); | ||
1169 | #endif | ||
1170 | if (ret != -1) | 619 | if (ret != -1) |
1171 | return (ret); | 620 | return (ret); |
1172 | } | 621 | } |
@@ -1194,392 +643,35 @@ ahd_linux_biosparam(Disk *disk, kdev_t dev, int geom[]) | |||
1194 | * Abort the current SCSI command(s). | 643 | * Abort the current SCSI command(s). |
1195 | */ | 644 | */ |
1196 | static int | 645 | static int |
1197 | ahd_linux_abort(Scsi_Cmnd *cmd) | 646 | ahd_linux_abort(struct scsi_cmnd *cmd) |
1198 | { | 647 | { |
1199 | struct ahd_softc *ahd; | 648 | int error; |
1200 | struct ahd_cmd *acmd; | ||
1201 | struct ahd_cmd *list_acmd; | ||
1202 | struct ahd_linux_device *dev; | ||
1203 | struct scb *pending_scb; | ||
1204 | u_long s; | ||
1205 | u_int saved_scbptr; | ||
1206 | u_int active_scbptr; | ||
1207 | u_int last_phase; | ||
1208 | u_int cdb_byte; | ||
1209 | int retval; | ||
1210 | int was_paused; | ||
1211 | int paused; | ||
1212 | int wait; | ||
1213 | int disconnected; | ||
1214 | ahd_mode_state saved_modes; | ||
1215 | |||
1216 | pending_scb = NULL; | ||
1217 | paused = FALSE; | ||
1218 | wait = FALSE; | ||
1219 | ahd = *(struct ahd_softc **)cmd->device->host->hostdata; | ||
1220 | acmd = (struct ahd_cmd *)cmd; | ||
1221 | |||
1222 | printf("%s:%d:%d:%d: Attempting to abort cmd %p:", | ||
1223 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
1224 | cmd->device->lun, cmd); | ||
1225 | for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++) | ||
1226 | printf(" 0x%x", cmd->cmnd[cdb_byte]); | ||
1227 | printf("\n"); | ||
1228 | |||
1229 | /* | ||
1230 | * In all versions of Linux, we have to work around | ||
1231 | * a major flaw in how the mid-layer is locked down | ||
1232 | * if we are to sleep successfully in our error handler | ||
1233 | * while allowing our interrupt handler to run. Since | ||
1234 | * the midlayer acquires either the io_request_lock or | ||
1235 | * our lock prior to calling us, we must use the | ||
1236 | * spin_unlock_irq() method for unlocking our lock. | ||
1237 | * This will force interrupts to be enabled on the | ||
1238 | * current CPU. Since the EH thread should not have | ||
1239 | * been running with CPU interrupts disabled other than | ||
1240 | * by acquiring either the io_request_lock or our own | ||
1241 | * lock, this *should* be safe. | ||
1242 | */ | ||
1243 | ahd_midlayer_entrypoint_lock(ahd, &s); | ||
1244 | |||
1245 | /* | ||
1246 | * First determine if we currently own this command. | ||
1247 | * Start by searching the device queue. If not found | ||
1248 | * there, check the pending_scb list. If not found | ||
1249 | * at all, and the system wanted us to just abort the | ||
1250 | * command, return success. | ||
1251 | */ | ||
1252 | dev = ahd_linux_get_device(ahd, cmd->device->channel, | ||
1253 | cmd->device->id, cmd->device->lun, | ||
1254 | /*alloc*/FALSE); | ||
1255 | |||
1256 | if (dev == NULL) { | ||
1257 | /* | ||
1258 | * No target device for this command exists, | ||
1259 | * so we must not still own the command. | ||
1260 | */ | ||
1261 | printf("%s:%d:%d:%d: Is not an active device\n", | ||
1262 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
1263 | cmd->device->lun); | ||
1264 | retval = SUCCESS; | ||
1265 | goto no_cmd; | ||
1266 | } | ||
1267 | |||
1268 | TAILQ_FOREACH(list_acmd, &dev->busyq, acmd_links.tqe) { | ||
1269 | if (list_acmd == acmd) | ||
1270 | break; | ||
1271 | } | ||
1272 | |||
1273 | if (list_acmd != NULL) { | ||
1274 | printf("%s:%d:%d:%d: Command found on device queue\n", | ||
1275 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
1276 | cmd->device->lun); | ||
1277 | TAILQ_REMOVE(&dev->busyq, list_acmd, acmd_links.tqe); | ||
1278 | cmd->result = DID_ABORT << 16; | ||
1279 | ahd_linux_queue_cmd_complete(ahd, cmd); | ||
1280 | retval = SUCCESS; | ||
1281 | goto done; | ||
1282 | } | ||
1283 | 649 | ||
1284 | /* | 650 | error = ahd_linux_queue_recovery_cmd(cmd, SCB_ABORT); |
1285 | * See if we can find a matching cmd in the pending list. | 651 | if (error != 0) |
1286 | */ | 652 | printf("aic79xx_abort returns 0x%x\n", error); |
1287 | LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) { | 653 | return error; |
1288 | if (pending_scb->io_ctx == cmd) | ||
1289 | break; | ||
1290 | } | ||
1291 | |||
1292 | if (pending_scb == NULL) { | ||
1293 | printf("%s:%d:%d:%d: Command not found\n", | ||
1294 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
1295 | cmd->device->lun); | ||
1296 | goto no_cmd; | ||
1297 | } | ||
1298 | |||
1299 | if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) { | ||
1300 | /* | ||
1301 | * We can't queue two recovery actions using the same SCB | ||
1302 | */ | ||
1303 | retval = FAILED; | ||
1304 | goto done; | ||
1305 | } | ||
1306 | |||
1307 | /* | ||
1308 | * Ensure that the card doesn't do anything | ||
1309 | * behind our back. Also make sure that we | ||
1310 | * didn't "just" miss an interrupt that would | ||
1311 | * affect this cmd. | ||
1312 | */ | ||
1313 | was_paused = ahd_is_paused(ahd); | ||
1314 | ahd_pause_and_flushwork(ahd); | ||
1315 | paused = TRUE; | ||
1316 | |||
1317 | if ((pending_scb->flags & SCB_ACTIVE) == 0) { | ||
1318 | printf("%s:%d:%d:%d: Command already completed\n", | ||
1319 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
1320 | cmd->device->lun); | ||
1321 | goto no_cmd; | ||
1322 | } | ||
1323 | |||
1324 | printf("%s: At time of recovery, card was %spaused\n", | ||
1325 | ahd_name(ahd), was_paused ? "" : "not "); | ||
1326 | ahd_dump_card_state(ahd); | ||
1327 | |||
1328 | disconnected = TRUE; | ||
1329 | if (ahd_search_qinfifo(ahd, cmd->device->id, cmd->device->channel + 'A', | ||
1330 | cmd->device->lun, SCB_GET_TAG(pending_scb), | ||
1331 | ROLE_INITIATOR, CAM_REQ_ABORTED, | ||
1332 | SEARCH_COMPLETE) > 0) { | ||
1333 | printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n", | ||
1334 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
1335 | cmd->device->lun); | ||
1336 | retval = SUCCESS; | ||
1337 | goto done; | ||
1338 | } | ||
1339 | |||
1340 | saved_modes = ahd_save_modes(ahd); | ||
1341 | ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI); | ||
1342 | last_phase = ahd_inb(ahd, LASTPHASE); | ||
1343 | saved_scbptr = ahd_get_scbptr(ahd); | ||
1344 | active_scbptr = saved_scbptr; | ||
1345 | if (disconnected && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) { | ||
1346 | struct scb *bus_scb; | ||
1347 | |||
1348 | bus_scb = ahd_lookup_scb(ahd, active_scbptr); | ||
1349 | if (bus_scb == pending_scb) | ||
1350 | disconnected = FALSE; | ||
1351 | } | ||
1352 | |||
1353 | /* | ||
1354 | * At this point, pending_scb is the scb associated with the | ||
1355 | * passed in command. That command is currently active on the | ||
1356 | * bus or is in the disconnected state. | ||
1357 | */ | ||
1358 | if (last_phase != P_BUSFREE | ||
1359 | && SCB_GET_TAG(pending_scb) == active_scbptr) { | ||
1360 | |||
1361 | /* | ||
1362 | * We're active on the bus, so assert ATN | ||
1363 | * and hope that the target responds. | ||
1364 | */ | ||
1365 | pending_scb = ahd_lookup_scb(ahd, active_scbptr); | ||
1366 | pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT; | ||
1367 | ahd_outb(ahd, MSG_OUT, HOST_MSG); | ||
1368 | ahd_outb(ahd, SCSISIGO, last_phase|ATNO); | ||
1369 | printf("%s:%d:%d:%d: Device is active, asserting ATN\n", | ||
1370 | ahd_name(ahd), cmd->device->channel, | ||
1371 | cmd->device->id, cmd->device->lun); | ||
1372 | wait = TRUE; | ||
1373 | } else if (disconnected) { | ||
1374 | |||
1375 | /* | ||
1376 | * Actually re-queue this SCB in an attempt | ||
1377 | * to select the device before it reconnects. | ||
1378 | */ | ||
1379 | pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT; | ||
1380 | ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb)); | ||
1381 | pending_scb->hscb->cdb_len = 0; | ||
1382 | pending_scb->hscb->task_attribute = 0; | ||
1383 | pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK; | ||
1384 | |||
1385 | if ((pending_scb->flags & SCB_PACKETIZED) != 0) { | ||
1386 | /* | ||
1387 | * Mark the SCB has having an outstanding | ||
1388 | * task management function. Should the command | ||
1389 | * complete normally before the task management | ||
1390 | * function can be sent, the host will be notified | ||
1391 | * to abort our requeued SCB. | ||
1392 | */ | ||
1393 | ahd_outb(ahd, SCB_TASK_MANAGEMENT, | ||
1394 | pending_scb->hscb->task_management); | ||
1395 | } else { | ||
1396 | /* | ||
1397 | * If non-packetized, set the MK_MESSAGE control | ||
1398 | * bit indicating that we desire to send a message. | ||
1399 | * We also set the disconnected flag since there is | ||
1400 | * no guarantee that our SCB control byte matches | ||
1401 | * the version on the card. We don't want the | ||
1402 | * sequencer to abort the command thinking an | ||
1403 | * unsolicited reselection occurred. | ||
1404 | */ | ||
1405 | pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED; | ||
1406 | |||
1407 | /* | ||
1408 | * The sequencer will never re-reference the | ||
1409 | * in-core SCB. To make sure we are notified | ||
1410 | * during reslection, set the MK_MESSAGE flag in | ||
1411 | * the card's copy of the SCB. | ||
1412 | */ | ||
1413 | ahd_outb(ahd, SCB_CONTROL, | ||
1414 | ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE); | ||
1415 | } | ||
1416 | |||
1417 | /* | ||
1418 | * Clear out any entries in the QINFIFO first | ||
1419 | * so we are the next SCB for this target | ||
1420 | * to run. | ||
1421 | */ | ||
1422 | ahd_search_qinfifo(ahd, cmd->device->id, | ||
1423 | cmd->device->channel + 'A', cmd->device->lun, | ||
1424 | SCB_LIST_NULL, ROLE_INITIATOR, | ||
1425 | CAM_REQUEUE_REQ, SEARCH_COMPLETE); | ||
1426 | ahd_qinfifo_requeue_tail(ahd, pending_scb); | ||
1427 | ahd_set_scbptr(ahd, saved_scbptr); | ||
1428 | ahd_print_path(ahd, pending_scb); | ||
1429 | printf("Device is disconnected, re-queuing SCB\n"); | ||
1430 | wait = TRUE; | ||
1431 | } else { | ||
1432 | printf("%s:%d:%d:%d: Unable to deliver message\n", | ||
1433 | ahd_name(ahd), cmd->device->channel, | ||
1434 | cmd->device->id, cmd->device->lun); | ||
1435 | retval = FAILED; | ||
1436 | goto done; | ||
1437 | } | ||
1438 | |||
1439 | no_cmd: | ||
1440 | /* | ||
1441 | * Our assumption is that if we don't have the command, no | ||
1442 | * recovery action was required, so we return success. Again, | ||
1443 | * the semantics of the mid-layer recovery engine are not | ||
1444 | * well defined, so this may change in time. | ||
1445 | */ | ||
1446 | retval = SUCCESS; | ||
1447 | done: | ||
1448 | if (paused) | ||
1449 | ahd_unpause(ahd); | ||
1450 | if (wait) { | ||
1451 | struct timer_list timer; | ||
1452 | int ret; | ||
1453 | |||
1454 | pending_scb->platform_data->flags |= AHD_SCB_UP_EH_SEM; | ||
1455 | spin_unlock_irq(&ahd->platform_data->spin_lock); | ||
1456 | init_timer(&timer); | ||
1457 | timer.data = (u_long)pending_scb; | ||
1458 | timer.expires = jiffies + (5 * HZ); | ||
1459 | timer.function = ahd_linux_sem_timeout; | ||
1460 | add_timer(&timer); | ||
1461 | printf("Recovery code sleeping\n"); | ||
1462 | down(&ahd->platform_data->eh_sem); | ||
1463 | printf("Recovery code awake\n"); | ||
1464 | ret = del_timer_sync(&timer); | ||
1465 | if (ret == 0) { | ||
1466 | printf("Timer Expired\n"); | ||
1467 | retval = FAILED; | ||
1468 | } | ||
1469 | spin_lock_irq(&ahd->platform_data->spin_lock); | ||
1470 | } | ||
1471 | ahd_schedule_runq(ahd); | ||
1472 | ahd_linux_run_complete_queue(ahd); | ||
1473 | ahd_midlayer_entrypoint_unlock(ahd, &s); | ||
1474 | return (retval); | ||
1475 | } | ||
1476 | |||
1477 | |||
1478 | static void | ||
1479 | ahd_linux_dev_reset_complete(Scsi_Cmnd *cmd) | ||
1480 | { | ||
1481 | free(cmd, M_DEVBUF); | ||
1482 | } | 654 | } |
1483 | 655 | ||
1484 | /* | 656 | /* |
1485 | * Attempt to send a target reset message to the device that timed out. | 657 | * Attempt to send a target reset message to the device that timed out. |
1486 | */ | 658 | */ |
1487 | static int | 659 | static int |
1488 | ahd_linux_dev_reset(Scsi_Cmnd *cmd) | 660 | ahd_linux_dev_reset(struct scsi_cmnd *cmd) |
1489 | { | 661 | { |
1490 | struct ahd_softc *ahd; | 662 | int error; |
1491 | struct scsi_cmnd *recovery_cmd; | ||
1492 | struct ahd_linux_device *dev; | ||
1493 | struct ahd_initiator_tinfo *tinfo; | ||
1494 | struct ahd_tmode_tstate *tstate; | ||
1495 | struct scb *scb; | ||
1496 | struct hardware_scb *hscb; | ||
1497 | u_long s; | ||
1498 | struct timer_list timer; | ||
1499 | int retval; | ||
1500 | |||
1501 | ahd = *(struct ahd_softc **)cmd->device->host->hostdata; | ||
1502 | recovery_cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK); | ||
1503 | if (!recovery_cmd) | ||
1504 | return (FAILED); | ||
1505 | memset(recovery_cmd, 0, sizeof(struct scsi_cmnd)); | ||
1506 | recovery_cmd->device = cmd->device; | ||
1507 | recovery_cmd->scsi_done = ahd_linux_dev_reset_complete; | ||
1508 | #ifdef AHD_DEBUG | ||
1509 | if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) | ||
1510 | printf("%s:%d:%d:%d: Device reset called for cmd %p\n", | ||
1511 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
1512 | cmd->device->lun, cmd); | ||
1513 | #endif | ||
1514 | ahd_lock(ahd, &s); | ||
1515 | |||
1516 | dev = ahd_linux_get_device(ahd, cmd->device->channel, cmd->device->id, | ||
1517 | cmd->device->lun, /*alloc*/FALSE); | ||
1518 | if (dev == NULL) { | ||
1519 | ahd_unlock(ahd, &s); | ||
1520 | kfree(recovery_cmd); | ||
1521 | return (FAILED); | ||
1522 | } | ||
1523 | if ((scb = ahd_get_scb(ahd, AHD_NEVER_COL_IDX)) == NULL) { | ||
1524 | ahd_unlock(ahd, &s); | ||
1525 | kfree(recovery_cmd); | ||
1526 | return (FAILED); | ||
1527 | } | ||
1528 | tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id, | ||
1529 | cmd->device->id, &tstate); | ||
1530 | recovery_cmd->result = CAM_REQ_INPROG << 16; | ||
1531 | recovery_cmd->host_scribble = (char *)scb; | ||
1532 | scb->io_ctx = recovery_cmd; | ||
1533 | scb->platform_data->dev = dev; | ||
1534 | scb->sg_count = 0; | ||
1535 | ahd_set_residual(scb, 0); | ||
1536 | ahd_set_sense_residual(scb, 0); | ||
1537 | hscb = scb->hscb; | ||
1538 | hscb->control = 0; | ||
1539 | hscb->scsiid = BUILD_SCSIID(ahd, cmd); | ||
1540 | hscb->lun = cmd->device->lun; | ||
1541 | hscb->cdb_len = 0; | ||
1542 | hscb->task_management = SIU_TASKMGMT_LUN_RESET; | ||
1543 | scb->flags |= SCB_DEVICE_RESET|SCB_RECOVERY_SCB|SCB_ACTIVE; | ||
1544 | if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) { | ||
1545 | scb->flags |= SCB_PACKETIZED; | ||
1546 | } else { | ||
1547 | hscb->control |= MK_MESSAGE; | ||
1548 | } | ||
1549 | dev->openings--; | ||
1550 | dev->active++; | ||
1551 | dev->commands_issued++; | ||
1552 | LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links); | ||
1553 | ahd_queue_scb(ahd, scb); | ||
1554 | 663 | ||
1555 | scb->platform_data->flags |= AHD_SCB_UP_EH_SEM; | 664 | error = ahd_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET); |
1556 | ahd_unlock(ahd, &s); | 665 | if (error != 0) |
1557 | init_timer(&timer); | 666 | printf("aic79xx_dev_reset returns 0x%x\n", error); |
1558 | timer.data = (u_long)scb; | 667 | return error; |
1559 | timer.expires = jiffies + (5 * HZ); | ||
1560 | timer.function = ahd_linux_sem_timeout; | ||
1561 | add_timer(&timer); | ||
1562 | printf("Recovery code sleeping\n"); | ||
1563 | down(&ahd->platform_data->eh_sem); | ||
1564 | printf("Recovery code awake\n"); | ||
1565 | retval = SUCCESS; | ||
1566 | if (del_timer_sync(&timer) == 0) { | ||
1567 | printf("Timer Expired\n"); | ||
1568 | retval = FAILED; | ||
1569 | } | ||
1570 | ahd_lock(ahd, &s); | ||
1571 | ahd_schedule_runq(ahd); | ||
1572 | ahd_linux_run_complete_queue(ahd); | ||
1573 | ahd_unlock(ahd, &s); | ||
1574 | printf("%s: Device reset returning 0x%x\n", ahd_name(ahd), retval); | ||
1575 | return (retval); | ||
1576 | } | 668 | } |
1577 | 669 | ||
1578 | /* | 670 | /* |
1579 | * Reset the SCSI bus. | 671 | * Reset the SCSI bus. |
1580 | */ | 672 | */ |
1581 | static int | 673 | static int |
1582 | ahd_linux_bus_reset(Scsi_Cmnd *cmd) | 674 | ahd_linux_bus_reset(struct scsi_cmnd *cmd) |
1583 | { | 675 | { |
1584 | struct ahd_softc *ahd; | 676 | struct ahd_softc *ahd; |
1585 | u_long s; | 677 | u_long s; |
@@ -1594,7 +686,6 @@ ahd_linux_bus_reset(Scsi_Cmnd *cmd) | |||
1594 | ahd_lock(ahd, &s); | 686 | ahd_lock(ahd, &s); |
1595 | found = ahd_reset_channel(ahd, cmd->device->channel + 'A', | 687 | found = ahd_reset_channel(ahd, cmd->device->channel + 'A', |
1596 | /*initiate reset*/TRUE); | 688 | /*initiate reset*/TRUE); |
1597 | ahd_linux_run_complete_queue(ahd); | ||
1598 | ahd_unlock(ahd, &s); | 689 | ahd_unlock(ahd, &s); |
1599 | 690 | ||
1600 | if (bootverbose) | 691 | if (bootverbose) |
@@ -1604,9 +695,10 @@ ahd_linux_bus_reset(Scsi_Cmnd *cmd) | |||
1604 | return (SUCCESS); | 695 | return (SUCCESS); |
1605 | } | 696 | } |
1606 | 697 | ||
1607 | Scsi_Host_Template aic79xx_driver_template = { | 698 | struct scsi_host_template aic79xx_driver_template = { |
1608 | .module = THIS_MODULE, | 699 | .module = THIS_MODULE, |
1609 | .name = "aic79xx", | 700 | .name = "aic79xx", |
701 | .proc_name = "aic79xx", | ||
1610 | .proc_info = ahd_linux_proc_info, | 702 | .proc_info = ahd_linux_proc_info, |
1611 | .info = ahd_linux_info, | 703 | .info = ahd_linux_info, |
1612 | .queuecommand = ahd_linux_queue, | 704 | .queuecommand = ahd_linux_queue, |
@@ -1623,37 +715,10 @@ Scsi_Host_Template aic79xx_driver_template = { | |||
1623 | .slave_alloc = ahd_linux_slave_alloc, | 715 | .slave_alloc = ahd_linux_slave_alloc, |
1624 | .slave_configure = ahd_linux_slave_configure, | 716 | .slave_configure = ahd_linux_slave_configure, |
1625 | .slave_destroy = ahd_linux_slave_destroy, | 717 | .slave_destroy = ahd_linux_slave_destroy, |
718 | .target_alloc = ahd_linux_target_alloc, | ||
719 | .target_destroy = ahd_linux_target_destroy, | ||
1626 | }; | 720 | }; |
1627 | 721 | ||
1628 | /**************************** Tasklet Handler *********************************/ | ||
1629 | |||
1630 | /* | ||
1631 | * In 2.4.X and above, this routine is called from a tasklet, | ||
1632 | * so we must re-acquire our lock prior to executing this code. | ||
1633 | * In all prior kernels, ahd_schedule_runq() calls this routine | ||
1634 | * directly and ahd_schedule_runq() is called with our lock held. | ||
1635 | */ | ||
1636 | static void | ||
1637 | ahd_runq_tasklet(unsigned long data) | ||
1638 | { | ||
1639 | struct ahd_softc* ahd; | ||
1640 | struct ahd_linux_device *dev; | ||
1641 | u_long flags; | ||
1642 | |||
1643 | ahd = (struct ahd_softc *)data; | ||
1644 | ahd_lock(ahd, &flags); | ||
1645 | while ((dev = ahd_linux_next_device_to_run(ahd)) != NULL) { | ||
1646 | |||
1647 | TAILQ_REMOVE(&ahd->platform_data->device_runq, dev, links); | ||
1648 | dev->flags &= ~AHD_DEV_ON_RUN_LIST; | ||
1649 | ahd_linux_check_device_queue(ahd, dev); | ||
1650 | /* Yeild to our interrupt handler */ | ||
1651 | ahd_unlock(ahd, &flags); | ||
1652 | ahd_lock(ahd, &flags); | ||
1653 | } | ||
1654 | ahd_unlock(ahd, &flags); | ||
1655 | } | ||
1656 | |||
1657 | /******************************** Bus DMA *************************************/ | 722 | /******************************** Bus DMA *************************************/ |
1658 | int | 723 | int |
1659 | ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent, | 724 | ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent, |
@@ -1693,36 +758,10 @@ int | |||
1693 | ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr, | 758 | ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr, |
1694 | int flags, bus_dmamap_t *mapp) | 759 | int flags, bus_dmamap_t *mapp) |
1695 | { | 760 | { |
1696 | bus_dmamap_t map; | ||
1697 | |||
1698 | map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT); | ||
1699 | if (map == NULL) | ||
1700 | return (ENOMEM); | ||
1701 | /* | ||
1702 | * Although we can dma data above 4GB, our | ||
1703 | * "consistent" memory is below 4GB for | ||
1704 | * space efficiency reasons (only need a 4byte | ||
1705 | * address). For this reason, we have to reset | ||
1706 | * our dma mask when doing allocations. | ||
1707 | */ | ||
1708 | if (ahd->dev_softc != NULL) | ||
1709 | if (pci_set_dma_mask(ahd->dev_softc, 0xFFFFFFFF)) { | ||
1710 | printk(KERN_WARNING "aic79xx: No suitable DMA available.\n"); | ||
1711 | kfree(map); | ||
1712 | return (ENODEV); | ||
1713 | } | ||
1714 | *vaddr = pci_alloc_consistent(ahd->dev_softc, | 761 | *vaddr = pci_alloc_consistent(ahd->dev_softc, |
1715 | dmat->maxsize, &map->bus_addr); | 762 | dmat->maxsize, mapp); |
1716 | if (ahd->dev_softc != NULL) | ||
1717 | if (pci_set_dma_mask(ahd->dev_softc, | ||
1718 | ahd->platform_data->hw_dma_mask)) { | ||
1719 | printk(KERN_WARNING "aic79xx: No suitable DMA available.\n"); | ||
1720 | kfree(map); | ||
1721 | return (ENODEV); | ||
1722 | } | ||
1723 | if (*vaddr == NULL) | 763 | if (*vaddr == NULL) |
1724 | return (ENOMEM); | 764 | return (ENOMEM); |
1725 | *mapp = map; | ||
1726 | return(0); | 765 | return(0); |
1727 | } | 766 | } |
1728 | 767 | ||
@@ -1731,7 +770,7 @@ ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat, | |||
1731 | void* vaddr, bus_dmamap_t map) | 770 | void* vaddr, bus_dmamap_t map) |
1732 | { | 771 | { |
1733 | pci_free_consistent(ahd->dev_softc, dmat->maxsize, | 772 | pci_free_consistent(ahd->dev_softc, dmat->maxsize, |
1734 | vaddr, map->bus_addr); | 773 | vaddr, map); |
1735 | } | 774 | } |
1736 | 775 | ||
1737 | int | 776 | int |
@@ -1745,7 +784,7 @@ ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map, | |||
1745 | */ | 784 | */ |
1746 | bus_dma_segment_t stack_sg; | 785 | bus_dma_segment_t stack_sg; |
1747 | 786 | ||
1748 | stack_sg.ds_addr = map->bus_addr; | 787 | stack_sg.ds_addr = map; |
1749 | stack_sg.ds_len = dmat->maxsize; | 788 | stack_sg.ds_len = dmat->maxsize; |
1750 | cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0); | 789 | cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0); |
1751 | return (0); | 790 | return (0); |
@@ -1754,11 +793,6 @@ ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map, | |||
1754 | void | 793 | void |
1755 | ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map) | 794 | ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map) |
1756 | { | 795 | { |
1757 | /* | ||
1758 | * The map may is NULL in our < 2.3.X implementation. | ||
1759 | */ | ||
1760 | if (map != NULL) | ||
1761 | free(map, M_DEVBUF); | ||
1762 | } | 796 | } |
1763 | 797 | ||
1764 | int | 798 | int |
@@ -1823,41 +857,6 @@ ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd) | |||
1823 | } | 857 | } |
1824 | 858 | ||
1825 | static void | 859 | static void |
1826 | ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value) | ||
1827 | { | ||
1828 | |||
1829 | if ((instance >= 0) && (targ >= 0) | ||
1830 | && (instance < NUM_ELEMENTS(aic79xx_tag_info)) | ||
1831 | && (targ < AHD_NUM_TARGETS)) { | ||
1832 | aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF; | ||
1833 | if (bootverbose) | ||
1834 | printf("tag_info[%d:%d] = %d\n", instance, targ, value); | ||
1835 | } | ||
1836 | } | ||
1837 | |||
1838 | static void | ||
1839 | ahd_linux_setup_rd_strm_info(u_long arg, int instance, int targ, int32_t value) | ||
1840 | { | ||
1841 | if ((instance >= 0) | ||
1842 | && (instance < NUM_ELEMENTS(aic79xx_rd_strm_info))) { | ||
1843 | aic79xx_rd_strm_info[instance] = value & 0xFFFF; | ||
1844 | if (bootverbose) | ||
1845 | printf("rd_strm[%d] = 0x%x\n", instance, value); | ||
1846 | } | ||
1847 | } | ||
1848 | |||
1849 | static void | ||
1850 | ahd_linux_setup_dv(u_long arg, int instance, int targ, int32_t value) | ||
1851 | { | ||
1852 | if ((instance >= 0) | ||
1853 | && (instance < NUM_ELEMENTS(aic79xx_dv_settings))) { | ||
1854 | aic79xx_dv_settings[instance] = value; | ||
1855 | if (bootverbose) | ||
1856 | printf("dv[%d] = %d\n", instance, value); | ||
1857 | } | ||
1858 | } | ||
1859 | |||
1860 | static void | ||
1861 | ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value) | 860 | ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value) |
1862 | { | 861 | { |
1863 | 862 | ||
@@ -1887,6 +886,99 @@ ahd_linux_setup_tag_info_global(char *p) | |||
1887 | } | 886 | } |
1888 | } | 887 | } |
1889 | 888 | ||
889 | static void | ||
890 | ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value) | ||
891 | { | ||
892 | |||
893 | if ((instance >= 0) && (targ >= 0) | ||
894 | && (instance < NUM_ELEMENTS(aic79xx_tag_info)) | ||
895 | && (targ < AHD_NUM_TARGETS)) { | ||
896 | aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF; | ||
897 | if (bootverbose) | ||
898 | printf("tag_info[%d:%d] = %d\n", instance, targ, value); | ||
899 | } | ||
900 | } | ||
901 | |||
902 | static char * | ||
903 | ahd_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth, | ||
904 | void (*callback)(u_long, int, int, int32_t), | ||
905 | u_long callback_arg) | ||
906 | { | ||
907 | char *tok_end; | ||
908 | char *tok_end2; | ||
909 | int i; | ||
910 | int instance; | ||
911 | int targ; | ||
912 | int done; | ||
913 | char tok_list[] = {'.', ',', '{', '}', '\0'}; | ||
914 | |||
915 | /* All options use a ':' name/arg separator */ | ||
916 | if (*opt_arg != ':') | ||
917 | return (opt_arg); | ||
918 | opt_arg++; | ||
919 | instance = -1; | ||
920 | targ = -1; | ||
921 | done = FALSE; | ||
922 | /* | ||
923 | * Restore separator that may be in | ||
924 | * the middle of our option argument. | ||
925 | */ | ||
926 | tok_end = strchr(opt_arg, '\0'); | ||
927 | if (tok_end < end) | ||
928 | *tok_end = ','; | ||
929 | while (!done) { | ||
930 | switch (*opt_arg) { | ||
931 | case '{': | ||
932 | if (instance == -1) { | ||
933 | instance = 0; | ||
934 | } else { | ||
935 | if (depth > 1) { | ||
936 | if (targ == -1) | ||
937 | targ = 0; | ||
938 | } else { | ||
939 | printf("Malformed Option %s\n", | ||
940 | opt_name); | ||
941 | done = TRUE; | ||
942 | } | ||
943 | } | ||
944 | opt_arg++; | ||
945 | break; | ||
946 | case '}': | ||
947 | if (targ != -1) | ||
948 | targ = -1; | ||
949 | else if (instance != -1) | ||
950 | instance = -1; | ||
951 | opt_arg++; | ||
952 | break; | ||
953 | case ',': | ||
954 | case '.': | ||
955 | if (instance == -1) | ||
956 | done = TRUE; | ||
957 | else if (targ >= 0) | ||
958 | targ++; | ||
959 | else if (instance >= 0) | ||
960 | instance++; | ||
961 | opt_arg++; | ||
962 | break; | ||
963 | case '\0': | ||
964 | done = TRUE; | ||
965 | break; | ||
966 | default: | ||
967 | tok_end = end; | ||
968 | for (i = 0; tok_list[i]; i++) { | ||
969 | tok_end2 = strchr(opt_arg, tok_list[i]); | ||
970 | if ((tok_end2) && (tok_end2 < tok_end)) | ||
971 | tok_end = tok_end2; | ||
972 | } | ||
973 | callback(callback_arg, instance, targ, | ||
974 | simple_strtol(opt_arg, NULL, 0)); | ||
975 | opt_arg = tok_end; | ||
976 | break; | ||
977 | } | ||
978 | } | ||
979 | return (opt_arg); | ||
980 | } | ||
981 | |||
1890 | /* | 982 | /* |
1891 | * Handle Linux boot parameters. This routine allows for assigning a value | 983 | * Handle Linux boot parameters. This routine allows for assigning a value |
1892 | * to a parameter with a ':' between the parameter and the value. | 984 | * to a parameter with a ':' between the parameter and the value. |
@@ -1916,8 +1008,6 @@ aic79xx_setup(char *s) | |||
1916 | { "seltime", &aic79xx_seltime }, | 1008 | { "seltime", &aic79xx_seltime }, |
1917 | { "tag_info", NULL }, | 1009 | { "tag_info", NULL }, |
1918 | { "global_tag_depth", NULL}, | 1010 | { "global_tag_depth", NULL}, |
1919 | { "rd_strm", NULL }, | ||
1920 | { "dv", NULL }, | ||
1921 | { "slewrate", NULL }, | 1011 | { "slewrate", NULL }, |
1922 | { "precomp", NULL }, | 1012 | { "precomp", NULL }, |
1923 | { "amplitude", NULL }, | 1013 | { "amplitude", NULL }, |
@@ -1946,24 +1036,18 @@ aic79xx_setup(char *s) | |||
1946 | if (strncmp(p, "global_tag_depth", n) == 0) { | 1036 | if (strncmp(p, "global_tag_depth", n) == 0) { |
1947 | ahd_linux_setup_tag_info_global(p + n); | 1037 | ahd_linux_setup_tag_info_global(p + n); |
1948 | } else if (strncmp(p, "tag_info", n) == 0) { | 1038 | } else if (strncmp(p, "tag_info", n) == 0) { |
1949 | s = aic_parse_brace_option("tag_info", p + n, end, | 1039 | s = ahd_parse_brace_option("tag_info", p + n, end, |
1950 | 2, ahd_linux_setup_tag_info, 0); | 1040 | 2, ahd_linux_setup_tag_info, 0); |
1951 | } else if (strncmp(p, "rd_strm", n) == 0) { | ||
1952 | s = aic_parse_brace_option("rd_strm", p + n, end, | ||
1953 | 1, ahd_linux_setup_rd_strm_info, 0); | ||
1954 | } else if (strncmp(p, "dv", n) == 0) { | ||
1955 | s = aic_parse_brace_option("dv", p + n, end, 1, | ||
1956 | ahd_linux_setup_dv, 0); | ||
1957 | } else if (strncmp(p, "slewrate", n) == 0) { | 1041 | } else if (strncmp(p, "slewrate", n) == 0) { |
1958 | s = aic_parse_brace_option("slewrate", | 1042 | s = ahd_parse_brace_option("slewrate", |
1959 | p + n, end, 1, ahd_linux_setup_iocell_info, | 1043 | p + n, end, 1, ahd_linux_setup_iocell_info, |
1960 | AIC79XX_SLEWRATE_INDEX); | 1044 | AIC79XX_SLEWRATE_INDEX); |
1961 | } else if (strncmp(p, "precomp", n) == 0) { | 1045 | } else if (strncmp(p, "precomp", n) == 0) { |
1962 | s = aic_parse_brace_option("precomp", | 1046 | s = ahd_parse_brace_option("precomp", |
1963 | p + n, end, 1, ahd_linux_setup_iocell_info, | 1047 | p + n, end, 1, ahd_linux_setup_iocell_info, |
1964 | AIC79XX_PRECOMP_INDEX); | 1048 | AIC79XX_PRECOMP_INDEX); |
1965 | } else if (strncmp(p, "amplitude", n) == 0) { | 1049 | } else if (strncmp(p, "amplitude", n) == 0) { |
1966 | s = aic_parse_brace_option("amplitude", | 1050 | s = ahd_parse_brace_option("amplitude", |
1967 | p + n, end, 1, ahd_linux_setup_iocell_info, | 1051 | p + n, end, 1, ahd_linux_setup_iocell_info, |
1968 | AIC79XX_AMPLITUDE_INDEX); | 1052 | AIC79XX_AMPLITUDE_INDEX); |
1969 | } else if (p[n] == ':') { | 1053 | } else if (p[n] == ':') { |
@@ -1982,13 +1066,12 @@ __setup("aic79xx=", aic79xx_setup); | |||
1982 | uint32_t aic79xx_verbose; | 1066 | uint32_t aic79xx_verbose; |
1983 | 1067 | ||
1984 | int | 1068 | int |
1985 | ahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template) | 1069 | ahd_linux_register_host(struct ahd_softc *ahd, struct scsi_host_template *template) |
1986 | { | 1070 | { |
1987 | char buf[80]; | 1071 | char buf[80]; |
1988 | struct Scsi_Host *host; | 1072 | struct Scsi_Host *host; |
1989 | char *new_name; | 1073 | char *new_name; |
1990 | u_long s; | 1074 | u_long s; |
1991 | u_long target; | ||
1992 | 1075 | ||
1993 | template->name = ahd->description; | 1076 | template->name = ahd->description; |
1994 | host = scsi_host_alloc(template, sizeof(struct ahd_softc *)); | 1077 | host = scsi_host_alloc(template, sizeof(struct ahd_softc *)); |
@@ -1997,11 +1080,7 @@ ahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template) | |||
1997 | 1080 | ||
1998 | *((struct ahd_softc **)host->hostdata) = ahd; | 1081 | *((struct ahd_softc **)host->hostdata) = ahd; |
1999 | ahd_lock(ahd, &s); | 1082 | ahd_lock(ahd, &s); |
2000 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | ||
2001 | scsi_assign_lock(host, &ahd->platform_data->spin_lock); | 1083 | scsi_assign_lock(host, &ahd->platform_data->spin_lock); |
2002 | #elif AHD_SCSI_HAS_HOST_LOCK != 0 | ||
2003 | host->lock = &ahd->platform_data->spin_lock; | ||
2004 | #endif | ||
2005 | ahd->platform_data->host = host; | 1084 | ahd->platform_data->host = host; |
2006 | host->can_queue = AHD_MAX_QUEUE; | 1085 | host->can_queue = AHD_MAX_QUEUE; |
2007 | host->cmd_per_lun = 2; | 1086 | host->cmd_per_lun = 2; |
@@ -2012,7 +1091,7 @@ ahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template) | |||
2012 | host->max_lun = AHD_NUM_LUNS; | 1091 | host->max_lun = AHD_NUM_LUNS; |
2013 | host->max_channel = 0; | 1092 | host->max_channel = 0; |
2014 | host->sg_tablesize = AHD_NSEG; | 1093 | host->sg_tablesize = AHD_NSEG; |
2015 | ahd_set_unit(ahd, ahd_linux_next_unit()); | 1094 | ahd_set_unit(ahd, ahd_linux_unit++); |
2016 | sprintf(buf, "scsi%d", host->host_no); | 1095 | sprintf(buf, "scsi%d", host->host_no); |
2017 | new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT); | 1096 | new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT); |
2018 | if (new_name != NULL) { | 1097 | if (new_name != NULL) { |
@@ -2020,54 +1099,14 @@ ahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template) | |||
2020 | ahd_set_name(ahd, new_name); | 1099 | ahd_set_name(ahd, new_name); |
2021 | } | 1100 | } |
2022 | host->unique_id = ahd->unit; | 1101 | host->unique_id = ahd->unit; |
2023 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) | ||
2024 | scsi_set_pci_device(host, ahd->dev_softc); | ||
2025 | #endif | ||
2026 | ahd_linux_setup_user_rd_strm_settings(ahd); | ||
2027 | ahd_linux_initialize_scsi_bus(ahd); | 1102 | ahd_linux_initialize_scsi_bus(ahd); |
2028 | ahd_unlock(ahd, &s); | ||
2029 | ahd->platform_data->dv_pid = kernel_thread(ahd_linux_dv_thread, ahd, 0); | ||
2030 | ahd_lock(ahd, &s); | ||
2031 | if (ahd->platform_data->dv_pid < 0) { | ||
2032 | printf("%s: Failed to create DV thread, error= %d\n", | ||
2033 | ahd_name(ahd), ahd->platform_data->dv_pid); | ||
2034 | return (-ahd->platform_data->dv_pid); | ||
2035 | } | ||
2036 | /* | ||
2037 | * Initially allocate *all* of our linux target objects | ||
2038 | * so that the DV thread will scan them all in parallel | ||
2039 | * just after driver initialization. Any device that | ||
2040 | * does not exist will have its target object destroyed | ||
2041 | * by the selection timeout handler. In the case of a | ||
2042 | * device that appears after the initial DV scan, async | ||
2043 | * negotiation will occur for the first command, and DV | ||
2044 | * will comence should that first command be successful. | ||
2045 | */ | ||
2046 | for (target = 0; target < host->max_id; target++) { | ||
2047 | |||
2048 | /* | ||
2049 | * Skip our own ID. Some Compaq/HP storage devices | ||
2050 | * have enclosure management devices that respond to | ||
2051 | * single bit selection (i.e. selecting ourselves). | ||
2052 | * It is expected that either an external application | ||
2053 | * or a modified kernel will be used to probe this | ||
2054 | * ID if it is appropriate. To accommodate these | ||
2055 | * installations, ahc_linux_alloc_target() will allocate | ||
2056 | * for our ID if asked to do so. | ||
2057 | */ | ||
2058 | if (target == ahd->our_id) | ||
2059 | continue; | ||
2060 | |||
2061 | ahd_linux_alloc_target(ahd, 0, target); | ||
2062 | } | ||
2063 | ahd_intr_enable(ahd, TRUE); | 1103 | ahd_intr_enable(ahd, TRUE); |
2064 | ahd_linux_start_dv(ahd); | ||
2065 | ahd_unlock(ahd, &s); | 1104 | ahd_unlock(ahd, &s); |
2066 | 1105 | ||
2067 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | 1106 | host->transportt = ahd_linux_transport_template; |
1107 | |||
2068 | scsi_add_host(host, &ahd->dev_softc->dev); /* XXX handle failure */ | 1108 | scsi_add_host(host, &ahd->dev_softc->dev); /* XXX handle failure */ |
2069 | scsi_scan_host(host); | 1109 | scsi_scan_host(host); |
2070 | #endif | ||
2071 | return (0); | 1110 | return (0); |
2072 | } | 1111 | } |
2073 | 1112 | ||
@@ -2081,29 +1120,6 @@ ahd_linux_get_memsize(void) | |||
2081 | } | 1120 | } |
2082 | 1121 | ||
2083 | /* | 1122 | /* |
2084 | * Find the smallest available unit number to use | ||
2085 | * for a new device. We don't just use a static | ||
2086 | * count to handle the "repeated hot-(un)plug" | ||
2087 | * scenario. | ||
2088 | */ | ||
2089 | static int | ||
2090 | ahd_linux_next_unit(void) | ||
2091 | { | ||
2092 | struct ahd_softc *ahd; | ||
2093 | int unit; | ||
2094 | |||
2095 | unit = 0; | ||
2096 | retry: | ||
2097 | TAILQ_FOREACH(ahd, &ahd_tailq, links) { | ||
2098 | if (ahd->unit == unit) { | ||
2099 | unit++; | ||
2100 | goto retry; | ||
2101 | } | ||
2102 | } | ||
2103 | return (unit); | ||
2104 | } | ||
2105 | |||
2106 | /* | ||
2107 | * Place the SCSI bus into a known state by either resetting it, | 1123 | * Place the SCSI bus into a known state by either resetting it, |
2108 | * or forcing transfer negotiations on the next command to any | 1124 | * or forcing transfer negotiations on the next command to any |
2109 | * target. | 1125 | * target. |
@@ -2162,20 +1178,9 @@ ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg) | |||
2162 | if (ahd->platform_data == NULL) | 1178 | if (ahd->platform_data == NULL) |
2163 | return (ENOMEM); | 1179 | return (ENOMEM); |
2164 | memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data)); | 1180 | memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data)); |
2165 | TAILQ_INIT(&ahd->platform_data->completeq); | ||
2166 | TAILQ_INIT(&ahd->platform_data->device_runq); | ||
2167 | ahd->platform_data->irq = AHD_LINUX_NOIRQ; | 1181 | ahd->platform_data->irq = AHD_LINUX_NOIRQ; |
2168 | ahd->platform_data->hw_dma_mask = 0xFFFFFFFF; | ||
2169 | ahd_lockinit(ahd); | 1182 | ahd_lockinit(ahd); |
2170 | ahd_done_lockinit(ahd); | ||
2171 | init_timer(&ahd->platform_data->completeq_timer); | ||
2172 | ahd->platform_data->completeq_timer.data = (u_long)ahd; | ||
2173 | ahd->platform_data->completeq_timer.function = | ||
2174 | (ahd_linux_callback_t *)ahd_linux_thread_run_complete_queue; | ||
2175 | init_MUTEX_LOCKED(&ahd->platform_data->eh_sem); | 1183 | init_MUTEX_LOCKED(&ahd->platform_data->eh_sem); |
2176 | init_MUTEX_LOCKED(&ahd->platform_data->dv_sem); | ||
2177 | init_MUTEX_LOCKED(&ahd->platform_data->dv_cmd_sem); | ||
2178 | ahd_setup_runq_tasklet(ahd); | ||
2179 | ahd->seltime = (aic79xx_seltime & 0x3) << 4; | 1184 | ahd->seltime = (aic79xx_seltime & 0x3) << 4; |
2180 | return (0); | 1185 | return (0); |
2181 | } | 1186 | } |
@@ -2183,39 +1188,27 @@ ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg) | |||
2183 | void | 1188 | void |
2184 | ahd_platform_free(struct ahd_softc *ahd) | 1189 | ahd_platform_free(struct ahd_softc *ahd) |
2185 | { | 1190 | { |
2186 | struct ahd_linux_target *targ; | 1191 | struct scsi_target *starget; |
2187 | struct ahd_linux_device *dev; | ||
2188 | int i, j; | 1192 | int i, j; |
2189 | 1193 | ||
2190 | if (ahd->platform_data != NULL) { | 1194 | if (ahd->platform_data != NULL) { |
2191 | del_timer_sync(&ahd->platform_data->completeq_timer); | ||
2192 | ahd_linux_kill_dv_thread(ahd); | ||
2193 | ahd_teardown_runq_tasklet(ahd); | ||
2194 | if (ahd->platform_data->host != NULL) { | 1195 | if (ahd->platform_data->host != NULL) { |
2195 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | ||
2196 | scsi_remove_host(ahd->platform_data->host); | 1196 | scsi_remove_host(ahd->platform_data->host); |
2197 | #endif | ||
2198 | scsi_host_put(ahd->platform_data->host); | 1197 | scsi_host_put(ahd->platform_data->host); |
2199 | } | 1198 | } |
2200 | 1199 | ||
2201 | /* destroy all of the device and target objects */ | 1200 | /* destroy all of the device and target objects */ |
2202 | for (i = 0; i < AHD_NUM_TARGETS; i++) { | 1201 | for (i = 0; i < AHD_NUM_TARGETS; i++) { |
2203 | targ = ahd->platform_data->targets[i]; | 1202 | starget = ahd->platform_data->starget[i]; |
2204 | if (targ != NULL) { | 1203 | if (starget != NULL) { |
2205 | /* Keep target around through the loop. */ | ||
2206 | targ->refcount++; | ||
2207 | for (j = 0; j < AHD_NUM_LUNS; j++) { | 1204 | for (j = 0; j < AHD_NUM_LUNS; j++) { |
2208 | 1205 | struct ahd_linux_target *targ = | |
2209 | if (targ->devices[j] == NULL) | 1206 | scsi_transport_target_data(starget); |
1207 | if (targ->sdev[j] == NULL) | ||
2210 | continue; | 1208 | continue; |
2211 | dev = targ->devices[j]; | 1209 | targ->sdev[j] = NULL; |
2212 | ahd_linux_free_device(ahd, dev); | ||
2213 | } | 1210 | } |
2214 | /* | 1211 | ahd->platform_data->starget[i] = NULL; |
2215 | * Forcibly free the target now that | ||
2216 | * all devices are gone. | ||
2217 | */ | ||
2218 | ahd_linux_free_target(ahd, targ); | ||
2219 | } | 1212 | } |
2220 | } | 1213 | } |
2221 | 1214 | ||
@@ -2233,16 +1226,6 @@ ahd_platform_free(struct ahd_softc *ahd) | |||
2233 | release_mem_region(ahd->platform_data->mem_busaddr, | 1226 | release_mem_region(ahd->platform_data->mem_busaddr, |
2234 | 0x1000); | 1227 | 0x1000); |
2235 | } | 1228 | } |
2236 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) | ||
2237 | /* | ||
2238 | * In 2.4 we detach from the scsi midlayer before the PCI | ||
2239 | * layer invokes our remove callback. No per-instance | ||
2240 | * detach is provided, so we must reach inside the PCI | ||
2241 | * subsystem's internals and detach our driver manually. | ||
2242 | */ | ||
2243 | if (ahd->dev_softc != NULL) | ||
2244 | ahd->dev_softc->driver = NULL; | ||
2245 | #endif | ||
2246 | free(ahd->platform_data, M_DEVBUF); | 1229 | free(ahd->platform_data, M_DEVBUF); |
2247 | } | 1230 | } |
2248 | } | 1231 | } |
@@ -2280,13 +1263,22 @@ void | |||
2280 | ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo, | 1263 | ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo, |
2281 | ahd_queue_alg alg) | 1264 | ahd_queue_alg alg) |
2282 | { | 1265 | { |
1266 | struct scsi_target *starget; | ||
1267 | struct ahd_linux_target *targ; | ||
2283 | struct ahd_linux_device *dev; | 1268 | struct ahd_linux_device *dev; |
1269 | struct scsi_device *sdev; | ||
2284 | int was_queuing; | 1270 | int was_queuing; |
2285 | int now_queuing; | 1271 | int now_queuing; |
2286 | 1272 | ||
2287 | dev = ahd_linux_get_device(ahd, devinfo->channel - 'A', | 1273 | starget = ahd->platform_data->starget[devinfo->target]; |
2288 | devinfo->target, | 1274 | targ = scsi_transport_target_data(starget); |
2289 | devinfo->lun, /*alloc*/FALSE); | 1275 | BUG_ON(targ == NULL); |
1276 | sdev = targ->sdev[devinfo->lun]; | ||
1277 | if (sdev == NULL) | ||
1278 | return; | ||
1279 | |||
1280 | dev = scsi_transport_device_data(sdev); | ||
1281 | |||
2290 | if (dev == NULL) | 1282 | if (dev == NULL) |
2291 | return; | 1283 | return; |
2292 | was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED); | 1284 | was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED); |
@@ -2339,1434 +1331,37 @@ ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo, | |||
2339 | dev->maxtags = 0; | 1331 | dev->maxtags = 0; |
2340 | dev->openings = 1 - dev->active; | 1332 | dev->openings = 1 - dev->active; |
2341 | } | 1333 | } |
2342 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | ||
2343 | if (dev->scsi_device != NULL) { | ||
2344 | switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) { | ||
2345 | case AHD_DEV_Q_BASIC: | ||
2346 | scsi_adjust_queue_depth(dev->scsi_device, | ||
2347 | MSG_SIMPLE_TASK, | ||
2348 | dev->openings + dev->active); | ||
2349 | break; | ||
2350 | case AHD_DEV_Q_TAGGED: | ||
2351 | scsi_adjust_queue_depth(dev->scsi_device, | ||
2352 | MSG_ORDERED_TASK, | ||
2353 | dev->openings + dev->active); | ||
2354 | break; | ||
2355 | default: | ||
2356 | /* | ||
2357 | * We allow the OS to queue 2 untagged transactions to | ||
2358 | * us at any time even though we can only execute them | ||
2359 | * serially on the controller/device. This should | ||
2360 | * remove some latency. | ||
2361 | */ | ||
2362 | scsi_adjust_queue_depth(dev->scsi_device, | ||
2363 | /*NON-TAGGED*/0, | ||
2364 | /*queue depth*/2); | ||
2365 | break; | ||
2366 | } | ||
2367 | } | ||
2368 | #endif | ||
2369 | } | ||
2370 | |||
2371 | int | ||
2372 | ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel, | ||
2373 | int lun, u_int tag, role_t role, uint32_t status) | ||
2374 | { | ||
2375 | int targ; | ||
2376 | int maxtarg; | ||
2377 | int maxlun; | ||
2378 | int clun; | ||
2379 | int count; | ||
2380 | |||
2381 | if (tag != SCB_LIST_NULL) | ||
2382 | return (0); | ||
2383 | |||
2384 | targ = 0; | ||
2385 | if (target != CAM_TARGET_WILDCARD) { | ||
2386 | targ = target; | ||
2387 | maxtarg = targ + 1; | ||
2388 | } else { | ||
2389 | maxtarg = (ahd->features & AHD_WIDE) ? 16 : 8; | ||
2390 | } | ||
2391 | clun = 0; | ||
2392 | if (lun != CAM_LUN_WILDCARD) { | ||
2393 | clun = lun; | ||
2394 | maxlun = clun + 1; | ||
2395 | } else { | ||
2396 | maxlun = AHD_NUM_LUNS; | ||
2397 | } | ||
2398 | |||
2399 | count = 0; | ||
2400 | for (; targ < maxtarg; targ++) { | ||
2401 | |||
2402 | for (; clun < maxlun; clun++) { | ||
2403 | struct ahd_linux_device *dev; | ||
2404 | struct ahd_busyq *busyq; | ||
2405 | struct ahd_cmd *acmd; | ||
2406 | |||
2407 | dev = ahd_linux_get_device(ahd, /*chan*/0, targ, | ||
2408 | clun, /*alloc*/FALSE); | ||
2409 | if (dev == NULL) | ||
2410 | continue; | ||
2411 | |||
2412 | busyq = &dev->busyq; | ||
2413 | while ((acmd = TAILQ_FIRST(busyq)) != NULL) { | ||
2414 | Scsi_Cmnd *cmd; | ||
2415 | |||
2416 | cmd = &acmd_scsi_cmd(acmd); | ||
2417 | TAILQ_REMOVE(busyq, acmd, | ||
2418 | acmd_links.tqe); | ||
2419 | count++; | ||
2420 | cmd->result = status << 16; | ||
2421 | ahd_linux_queue_cmd_complete(ahd, cmd); | ||
2422 | } | ||
2423 | } | ||
2424 | } | ||
2425 | |||
2426 | return (count); | ||
2427 | } | ||
2428 | |||
2429 | static void | ||
2430 | ahd_linux_thread_run_complete_queue(struct ahd_softc *ahd) | ||
2431 | { | ||
2432 | u_long flags; | ||
2433 | |||
2434 | ahd_lock(ahd, &flags); | ||
2435 | del_timer(&ahd->platform_data->completeq_timer); | ||
2436 | ahd->platform_data->flags &= ~AHD_RUN_CMPLT_Q_TIMER; | ||
2437 | ahd_linux_run_complete_queue(ahd); | ||
2438 | ahd_unlock(ahd, &flags); | ||
2439 | } | ||
2440 | |||
2441 | static void | ||
2442 | ahd_linux_start_dv(struct ahd_softc *ahd) | ||
2443 | { | ||
2444 | |||
2445 | /* | ||
2446 | * Freeze the simq and signal ahd_linux_queue to not let any | ||
2447 | * more commands through | ||
2448 | */ | ||
2449 | if ((ahd->platform_data->flags & AHD_DV_ACTIVE) == 0) { | ||
2450 | #ifdef AHD_DEBUG | ||
2451 | if (ahd_debug & AHD_SHOW_DV) | ||
2452 | printf("%s: Starting DV\n", ahd_name(ahd)); | ||
2453 | #endif | ||
2454 | |||
2455 | ahd->platform_data->flags |= AHD_DV_ACTIVE; | ||
2456 | ahd_freeze_simq(ahd); | ||
2457 | |||
2458 | /* Wake up the DV kthread */ | ||
2459 | up(&ahd->platform_data->dv_sem); | ||
2460 | } | ||
2461 | } | ||
2462 | |||
2463 | static int | ||
2464 | ahd_linux_dv_thread(void *data) | ||
2465 | { | ||
2466 | struct ahd_softc *ahd; | ||
2467 | int target; | ||
2468 | u_long s; | ||
2469 | |||
2470 | ahd = (struct ahd_softc *)data; | ||
2471 | |||
2472 | #ifdef AHD_DEBUG | ||
2473 | if (ahd_debug & AHD_SHOW_DV) | ||
2474 | printf("In DV Thread\n"); | ||
2475 | #endif | ||
2476 | |||
2477 | /* | ||
2478 | * Complete thread creation. | ||
2479 | */ | ||
2480 | lock_kernel(); | ||
2481 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,60) | ||
2482 | /* | ||
2483 | * Don't care about any signals. | ||
2484 | */ | ||
2485 | siginitsetinv(¤t->blocked, 0); | ||
2486 | |||
2487 | daemonize(); | ||
2488 | sprintf(current->comm, "ahd_dv_%d", ahd->unit); | ||
2489 | #else | ||
2490 | daemonize("ahd_dv_%d", ahd->unit); | ||
2491 | current->flags |= PF_NOFREEZE; | ||
2492 | #endif | ||
2493 | unlock_kernel(); | ||
2494 | |||
2495 | while (1) { | ||
2496 | /* | ||
2497 | * Use down_interruptible() rather than down() to | ||
2498 | * avoid inclusion in the load average. | ||
2499 | */ | ||
2500 | down_interruptible(&ahd->platform_data->dv_sem); | ||
2501 | |||
2502 | /* Check to see if we've been signaled to exit */ | ||
2503 | ahd_lock(ahd, &s); | ||
2504 | if ((ahd->platform_data->flags & AHD_DV_SHUTDOWN) != 0) { | ||
2505 | ahd_unlock(ahd, &s); | ||
2506 | break; | ||
2507 | } | ||
2508 | ahd_unlock(ahd, &s); | ||
2509 | |||
2510 | #ifdef AHD_DEBUG | ||
2511 | if (ahd_debug & AHD_SHOW_DV) | ||
2512 | printf("%s: Beginning Domain Validation\n", | ||
2513 | ahd_name(ahd)); | ||
2514 | #endif | ||
2515 | |||
2516 | /* | ||
2517 | * Wait for any pending commands to drain before proceeding. | ||
2518 | */ | ||
2519 | ahd_lock(ahd, &s); | ||
2520 | while (LIST_FIRST(&ahd->pending_scbs) != NULL) { | ||
2521 | ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_EMPTY; | ||
2522 | ahd_unlock(ahd, &s); | ||
2523 | down_interruptible(&ahd->platform_data->dv_sem); | ||
2524 | ahd_lock(ahd, &s); | ||
2525 | } | ||
2526 | |||
2527 | /* | ||
2528 | * Wait for the SIMQ to be released so that DV is the | ||
2529 | * only reason the queue is frozen. | ||
2530 | */ | ||
2531 | while (AHD_DV_SIMQ_FROZEN(ahd) == 0) { | ||
2532 | ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE; | ||
2533 | ahd_unlock(ahd, &s); | ||
2534 | down_interruptible(&ahd->platform_data->dv_sem); | ||
2535 | ahd_lock(ahd, &s); | ||
2536 | } | ||
2537 | ahd_unlock(ahd, &s); | ||
2538 | |||
2539 | for (target = 0; target < AHD_NUM_TARGETS; target++) | ||
2540 | ahd_linux_dv_target(ahd, target); | ||
2541 | |||
2542 | ahd_lock(ahd, &s); | ||
2543 | ahd->platform_data->flags &= ~AHD_DV_ACTIVE; | ||
2544 | ahd_unlock(ahd, &s); | ||
2545 | |||
2546 | /* | ||
2547 | * Release the SIMQ so that normal commands are | ||
2548 | * allowed to continue on the bus. | ||
2549 | */ | ||
2550 | ahd_release_simq(ahd); | ||
2551 | } | ||
2552 | up(&ahd->platform_data->eh_sem); | ||
2553 | return (0); | ||
2554 | } | ||
2555 | |||
2556 | static void | ||
2557 | ahd_linux_kill_dv_thread(struct ahd_softc *ahd) | ||
2558 | { | ||
2559 | u_long s; | ||
2560 | |||
2561 | ahd_lock(ahd, &s); | ||
2562 | if (ahd->platform_data->dv_pid != 0) { | ||
2563 | ahd->platform_data->flags |= AHD_DV_SHUTDOWN; | ||
2564 | ahd_unlock(ahd, &s); | ||
2565 | up(&ahd->platform_data->dv_sem); | ||
2566 | |||
2567 | /* | ||
2568 | * Use the eh_sem as an indicator that the | ||
2569 | * dv thread is exiting. Note that the dv | ||
2570 | * thread must still return after performing | ||
2571 | * the up on our semaphore before it has | ||
2572 | * completely exited this module. Unfortunately, | ||
2573 | * there seems to be no easy way to wait for the | ||
2574 | * exit of a thread for which you are not the | ||
2575 | * parent (dv threads are parented by init). | ||
2576 | * Cross your fingers... | ||
2577 | */ | ||
2578 | down(&ahd->platform_data->eh_sem); | ||
2579 | |||
2580 | /* | ||
2581 | * Mark the dv thread as already dead. This | ||
2582 | * avoids attempting to kill it a second time. | ||
2583 | * This is necessary because we must kill the | ||
2584 | * DV thread before calling ahd_free() in the | ||
2585 | * module shutdown case to avoid bogus locking | ||
2586 | * in the SCSI mid-layer, but we ahd_free() is | ||
2587 | * called without killing the DV thread in the | ||
2588 | * instance detach case, so ahd_platform_free() | ||
2589 | * calls us again to verify that the DV thread | ||
2590 | * is dead. | ||
2591 | */ | ||
2592 | ahd->platform_data->dv_pid = 0; | ||
2593 | } else { | ||
2594 | ahd_unlock(ahd, &s); | ||
2595 | } | ||
2596 | } | ||
2597 | |||
2598 | #define AHD_LINUX_DV_INQ_SHORT_LEN 36 | ||
2599 | #define AHD_LINUX_DV_INQ_LEN 256 | ||
2600 | #define AHD_LINUX_DV_TIMEOUT (HZ / 4) | ||
2601 | |||
2602 | #define AHD_SET_DV_STATE(ahd, targ, newstate) \ | ||
2603 | ahd_set_dv_state(ahd, targ, newstate, __LINE__) | ||
2604 | |||
2605 | static __inline void | ||
2606 | ahd_set_dv_state(struct ahd_softc *ahd, struct ahd_linux_target *targ, | ||
2607 | ahd_dv_state newstate, u_int line) | ||
2608 | { | ||
2609 | ahd_dv_state oldstate; | ||
2610 | |||
2611 | oldstate = targ->dv_state; | ||
2612 | #ifdef AHD_DEBUG | ||
2613 | if (ahd_debug & AHD_SHOW_DV) | ||
2614 | printf("%s:%d: Going from state %d to state %d\n", | ||
2615 | ahd_name(ahd), line, oldstate, newstate); | ||
2616 | #endif | ||
2617 | |||
2618 | if (oldstate == newstate) | ||
2619 | targ->dv_state_retry++; | ||
2620 | else | ||
2621 | targ->dv_state_retry = 0; | ||
2622 | targ->dv_state = newstate; | ||
2623 | } | ||
2624 | |||
2625 | static void | ||
2626 | ahd_linux_dv_target(struct ahd_softc *ahd, u_int target_offset) | ||
2627 | { | ||
2628 | struct ahd_devinfo devinfo; | ||
2629 | struct ahd_linux_target *targ; | ||
2630 | struct scsi_cmnd *cmd; | ||
2631 | struct scsi_device *scsi_dev; | ||
2632 | struct scsi_sense_data *sense; | ||
2633 | uint8_t *buffer; | ||
2634 | u_long s; | ||
2635 | u_int timeout; | ||
2636 | int echo_size; | ||
2637 | |||
2638 | sense = NULL; | ||
2639 | buffer = NULL; | ||
2640 | echo_size = 0; | ||
2641 | ahd_lock(ahd, &s); | ||
2642 | targ = ahd->platform_data->targets[target_offset]; | ||
2643 | if (targ == NULL || (targ->flags & AHD_DV_REQUIRED) == 0) { | ||
2644 | ahd_unlock(ahd, &s); | ||
2645 | return; | ||
2646 | } | ||
2647 | ahd_compile_devinfo(&devinfo, ahd->our_id, targ->target, /*lun*/0, | ||
2648 | targ->channel + 'A', ROLE_INITIATOR); | ||
2649 | #ifdef AHD_DEBUG | ||
2650 | if (ahd_debug & AHD_SHOW_DV) { | ||
2651 | ahd_print_devinfo(ahd, &devinfo); | ||
2652 | printf("Performing DV\n"); | ||
2653 | } | ||
2654 | #endif | ||
2655 | |||
2656 | ahd_unlock(ahd, &s); | ||
2657 | |||
2658 | cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK); | ||
2659 | scsi_dev = malloc(sizeof(struct scsi_device), M_DEVBUF, M_WAITOK); | ||
2660 | scsi_dev->host = ahd->platform_data->host; | ||
2661 | scsi_dev->id = devinfo.target; | ||
2662 | scsi_dev->lun = devinfo.lun; | ||
2663 | scsi_dev->channel = devinfo.channel - 'A'; | ||
2664 | ahd->platform_data->dv_scsi_dev = scsi_dev; | ||
2665 | |||
2666 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2667 | |||
2668 | while (targ->dv_state != AHD_DV_STATE_EXIT) { | ||
2669 | timeout = AHD_LINUX_DV_TIMEOUT; | ||
2670 | switch (targ->dv_state) { | ||
2671 | case AHD_DV_STATE_INQ_SHORT_ASYNC: | ||
2672 | case AHD_DV_STATE_INQ_ASYNC: | ||
2673 | case AHD_DV_STATE_INQ_ASYNC_VERIFY: | ||
2674 | /* | ||
2675 | * Set things to async narrow to reduce the | ||
2676 | * chance that the INQ will fail. | ||
2677 | */ | ||
2678 | ahd_lock(ahd, &s); | ||
2679 | ahd_set_syncrate(ahd, &devinfo, 0, 0, 0, | ||
2680 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
2681 | ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT, | ||
2682 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
2683 | ahd_unlock(ahd, &s); | ||
2684 | timeout = 10 * HZ; | ||
2685 | targ->flags &= ~AHD_INQ_VALID; | ||
2686 | /* FALLTHROUGH */ | ||
2687 | case AHD_DV_STATE_INQ_VERIFY: | ||
2688 | { | ||
2689 | u_int inq_len; | ||
2690 | |||
2691 | if (targ->dv_state == AHD_DV_STATE_INQ_SHORT_ASYNC) | ||
2692 | inq_len = AHD_LINUX_DV_INQ_SHORT_LEN; | ||
2693 | else | ||
2694 | inq_len = targ->inq_data->additional_length + 5; | ||
2695 | ahd_linux_dv_inq(ahd, cmd, &devinfo, targ, inq_len); | ||
2696 | break; | ||
2697 | } | ||
2698 | case AHD_DV_STATE_TUR: | ||
2699 | case AHD_DV_STATE_BUSY: | ||
2700 | timeout = 5 * HZ; | ||
2701 | ahd_linux_dv_tur(ahd, cmd, &devinfo); | ||
2702 | break; | ||
2703 | case AHD_DV_STATE_REBD: | ||
2704 | ahd_linux_dv_rebd(ahd, cmd, &devinfo, targ); | ||
2705 | break; | ||
2706 | case AHD_DV_STATE_WEB: | ||
2707 | ahd_linux_dv_web(ahd, cmd, &devinfo, targ); | ||
2708 | break; | ||
2709 | |||
2710 | case AHD_DV_STATE_REB: | ||
2711 | ahd_linux_dv_reb(ahd, cmd, &devinfo, targ); | ||
2712 | break; | ||
2713 | |||
2714 | case AHD_DV_STATE_SU: | ||
2715 | ahd_linux_dv_su(ahd, cmd, &devinfo, targ); | ||
2716 | timeout = 50 * HZ; | ||
2717 | break; | ||
2718 | |||
2719 | default: | ||
2720 | ahd_print_devinfo(ahd, &devinfo); | ||
2721 | printf("Unknown DV state %d\n", targ->dv_state); | ||
2722 | goto out; | ||
2723 | } | ||
2724 | |||
2725 | /* Queue the command and wait for it to complete */ | ||
2726 | /* Abuse eh_timeout in the scsi_cmnd struct for our purposes */ | ||
2727 | init_timer(&cmd->eh_timeout); | ||
2728 | #ifdef AHD_DEBUG | ||
2729 | if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) | ||
2730 | /* | ||
2731 | * All of the printfs during negotiation | ||
2732 | * really slow down the negotiation. | ||
2733 | * Add a bit of time just to be safe. | ||
2734 | */ | ||
2735 | timeout += HZ; | ||
2736 | #endif | ||
2737 | scsi_add_timer(cmd, timeout, ahd_linux_dv_timeout); | ||
2738 | /* | ||
2739 | * In 2.5.X, it is assumed that all calls from the | ||
2740 | * "midlayer" (which we are emulating) will have the | ||
2741 | * ahd host lock held. For other kernels, the | ||
2742 | * io_request_lock must be held. | ||
2743 | */ | ||
2744 | #if AHD_SCSI_HAS_HOST_LOCK != 0 | ||
2745 | ahd_lock(ahd, &s); | ||
2746 | #else | ||
2747 | spin_lock_irqsave(&io_request_lock, s); | ||
2748 | #endif | ||
2749 | ahd_linux_queue(cmd, ahd_linux_dv_complete); | ||
2750 | #if AHD_SCSI_HAS_HOST_LOCK != 0 | ||
2751 | ahd_unlock(ahd, &s); | ||
2752 | #else | ||
2753 | spin_unlock_irqrestore(&io_request_lock, s); | ||
2754 | #endif | ||
2755 | down_interruptible(&ahd->platform_data->dv_cmd_sem); | ||
2756 | /* | ||
2757 | * Wait for the SIMQ to be released so that DV is the | ||
2758 | * only reason the queue is frozen. | ||
2759 | */ | ||
2760 | ahd_lock(ahd, &s); | ||
2761 | while (AHD_DV_SIMQ_FROZEN(ahd) == 0) { | ||
2762 | ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE; | ||
2763 | ahd_unlock(ahd, &s); | ||
2764 | down_interruptible(&ahd->platform_data->dv_sem); | ||
2765 | ahd_lock(ahd, &s); | ||
2766 | } | ||
2767 | ahd_unlock(ahd, &s); | ||
2768 | |||
2769 | ahd_linux_dv_transition(ahd, cmd, &devinfo, targ); | ||
2770 | } | ||
2771 | |||
2772 | out: | ||
2773 | if ((targ->flags & AHD_INQ_VALID) != 0 | ||
2774 | && ahd_linux_get_device(ahd, devinfo.channel - 'A', | ||
2775 | devinfo.target, devinfo.lun, | ||
2776 | /*alloc*/FALSE) == NULL) { | ||
2777 | /* | ||
2778 | * The DV state machine failed to configure this device. | ||
2779 | * This is normal if DV is disabled. Since we have inquiry | ||
2780 | * data, filter it and use the "optimistic" negotiation | ||
2781 | * parameters found in the inquiry string. | ||
2782 | */ | ||
2783 | ahd_linux_filter_inquiry(ahd, &devinfo); | ||
2784 | if ((targ->flags & (AHD_BASIC_DV|AHD_ENHANCED_DV)) != 0) { | ||
2785 | ahd_print_devinfo(ahd, &devinfo); | ||
2786 | printf("DV failed to configure device. " | ||
2787 | "Please file a bug report against " | ||
2788 | "this driver.\n"); | ||
2789 | } | ||
2790 | } | ||
2791 | |||
2792 | if (cmd != NULL) | ||
2793 | free(cmd, M_DEVBUF); | ||
2794 | |||
2795 | if (ahd->platform_data->dv_scsi_dev != NULL) { | ||
2796 | free(ahd->platform_data->dv_scsi_dev, M_DEVBUF); | ||
2797 | ahd->platform_data->dv_scsi_dev = NULL; | ||
2798 | } | ||
2799 | |||
2800 | ahd_lock(ahd, &s); | ||
2801 | if (targ->dv_buffer != NULL) { | ||
2802 | free(targ->dv_buffer, M_DEVBUF); | ||
2803 | targ->dv_buffer = NULL; | ||
2804 | } | ||
2805 | if (targ->dv_buffer1 != NULL) { | ||
2806 | free(targ->dv_buffer1, M_DEVBUF); | ||
2807 | targ->dv_buffer1 = NULL; | ||
2808 | } | ||
2809 | targ->flags &= ~AHD_DV_REQUIRED; | ||
2810 | if (targ->refcount == 0) | ||
2811 | ahd_linux_free_target(ahd, targ); | ||
2812 | ahd_unlock(ahd, &s); | ||
2813 | } | ||
2814 | |||
2815 | static __inline int | ||
2816 | ahd_linux_dv_fallback(struct ahd_softc *ahd, struct ahd_devinfo *devinfo) | ||
2817 | { | ||
2818 | u_long s; | ||
2819 | int retval; | ||
2820 | |||
2821 | ahd_lock(ahd, &s); | ||
2822 | retval = ahd_linux_fallback(ahd, devinfo); | ||
2823 | ahd_unlock(ahd, &s); | ||
2824 | |||
2825 | return (retval); | ||
2826 | } | ||
2827 | |||
2828 | static void | ||
2829 | ahd_linux_dv_transition(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
2830 | struct ahd_devinfo *devinfo, | ||
2831 | struct ahd_linux_target *targ) | ||
2832 | { | ||
2833 | u_int32_t status; | ||
2834 | |||
2835 | status = aic_error_action(cmd, targ->inq_data, | ||
2836 | ahd_cmd_get_transaction_status(cmd), | ||
2837 | ahd_cmd_get_scsi_status(cmd)); | ||
2838 | |||
2839 | |||
2840 | #ifdef AHD_DEBUG | ||
2841 | if (ahd_debug & AHD_SHOW_DV) { | ||
2842 | ahd_print_devinfo(ahd, devinfo); | ||
2843 | printf("Entering ahd_linux_dv_transition, state= %d, " | ||
2844 | "status= 0x%x, cmd->result= 0x%x\n", targ->dv_state, | ||
2845 | status, cmd->result); | ||
2846 | } | ||
2847 | #endif | ||
2848 | 1334 | ||
2849 | switch (targ->dv_state) { | 1335 | switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) { |
2850 | case AHD_DV_STATE_INQ_SHORT_ASYNC: | 1336 | case AHD_DEV_Q_BASIC: |
2851 | case AHD_DV_STATE_INQ_ASYNC: | 1337 | scsi_adjust_queue_depth(sdev, |
2852 | switch (status & SS_MASK) { | 1338 | MSG_SIMPLE_TASK, |
2853 | case SS_NOP: | 1339 | dev->openings + dev->active); |
2854 | { | ||
2855 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state+1); | ||
2856 | break; | ||
2857 | } | ||
2858 | case SS_INQ_REFRESH: | ||
2859 | AHD_SET_DV_STATE(ahd, targ, | ||
2860 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2861 | break; | ||
2862 | case SS_TUR: | ||
2863 | case SS_RETRY: | ||
2864 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
2865 | if (ahd_cmd_get_transaction_status(cmd) | ||
2866 | == CAM_REQUEUE_REQ) | ||
2867 | targ->dv_state_retry--; | ||
2868 | if ((status & SS_ERRMASK) == EBUSY) | ||
2869 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY); | ||
2870 | if (targ->dv_state_retry < 10) | ||
2871 | break; | ||
2872 | /* FALLTHROUGH */ | ||
2873 | default: | ||
2874 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2875 | #ifdef AHD_DEBUG | ||
2876 | if (ahd_debug & AHD_SHOW_DV) { | ||
2877 | ahd_print_devinfo(ahd, devinfo); | ||
2878 | printf("Failed DV inquiry, skipping\n"); | ||
2879 | } | ||
2880 | #endif | ||
2881 | break; | ||
2882 | } | ||
2883 | break; | 1340 | break; |
2884 | case AHD_DV_STATE_INQ_ASYNC_VERIFY: | 1341 | case AHD_DEV_Q_TAGGED: |
2885 | switch (status & SS_MASK) { | 1342 | scsi_adjust_queue_depth(sdev, |
2886 | case SS_NOP: | 1343 | MSG_ORDERED_TASK, |
2887 | { | 1344 | dev->openings + dev->active); |
2888 | u_int xportflags; | ||
2889 | u_int spi3data; | ||
2890 | |||
2891 | if (memcmp(targ->inq_data, targ->dv_buffer, | ||
2892 | AHD_LINUX_DV_INQ_LEN) != 0) { | ||
2893 | /* | ||
2894 | * Inquiry data must have changed. | ||
2895 | * Try from the top again. | ||
2896 | */ | ||
2897 | AHD_SET_DV_STATE(ahd, targ, | ||
2898 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2899 | break; | ||
2900 | } | ||
2901 | |||
2902 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state+1); | ||
2903 | targ->flags |= AHD_INQ_VALID; | ||
2904 | if (ahd_linux_user_dv_setting(ahd) == 0) | ||
2905 | break; | ||
2906 | |||
2907 | xportflags = targ->inq_data->flags; | ||
2908 | if ((xportflags & (SID_Sync|SID_WBus16)) == 0) | ||
2909 | break; | ||
2910 | |||
2911 | spi3data = targ->inq_data->spi3data; | ||
2912 | switch (spi3data & SID_SPI_CLOCK_DT_ST) { | ||
2913 | default: | ||
2914 | case SID_SPI_CLOCK_ST: | ||
2915 | /* Assume only basic DV is supported. */ | ||
2916 | targ->flags |= AHD_BASIC_DV; | ||
2917 | break; | ||
2918 | case SID_SPI_CLOCK_DT: | ||
2919 | case SID_SPI_CLOCK_DT_ST: | ||
2920 | targ->flags |= AHD_ENHANCED_DV; | ||
2921 | break; | ||
2922 | } | ||
2923 | break; | ||
2924 | } | ||
2925 | case SS_INQ_REFRESH: | ||
2926 | AHD_SET_DV_STATE(ahd, targ, | ||
2927 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2928 | break; | ||
2929 | case SS_TUR: | ||
2930 | case SS_RETRY: | ||
2931 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
2932 | if (ahd_cmd_get_transaction_status(cmd) | ||
2933 | == CAM_REQUEUE_REQ) | ||
2934 | targ->dv_state_retry--; | ||
2935 | |||
2936 | if ((status & SS_ERRMASK) == EBUSY) | ||
2937 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY); | ||
2938 | if (targ->dv_state_retry < 10) | ||
2939 | break; | ||
2940 | /* FALLTHROUGH */ | ||
2941 | default: | ||
2942 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2943 | #ifdef AHD_DEBUG | ||
2944 | if (ahd_debug & AHD_SHOW_DV) { | ||
2945 | ahd_print_devinfo(ahd, devinfo); | ||
2946 | printf("Failed DV inquiry, skipping\n"); | ||
2947 | } | ||
2948 | #endif | ||
2949 | break; | ||
2950 | } | ||
2951 | break; | 1345 | break; |
2952 | case AHD_DV_STATE_INQ_VERIFY: | ||
2953 | switch (status & SS_MASK) { | ||
2954 | case SS_NOP: | ||
2955 | { | ||
2956 | |||
2957 | if (memcmp(targ->inq_data, targ->dv_buffer, | ||
2958 | AHD_LINUX_DV_INQ_LEN) == 0) { | ||
2959 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2960 | break; | ||
2961 | } | ||
2962 | |||
2963 | #ifdef AHD_DEBUG | ||
2964 | if (ahd_debug & AHD_SHOW_DV) { | ||
2965 | int i; | ||
2966 | |||
2967 | ahd_print_devinfo(ahd, devinfo); | ||
2968 | printf("Inquiry buffer mismatch:"); | ||
2969 | for (i = 0; i < AHD_LINUX_DV_INQ_LEN; i++) { | ||
2970 | if ((i & 0xF) == 0) | ||
2971 | printf("\n "); | ||
2972 | printf("0x%x:0x0%x ", | ||
2973 | ((uint8_t *)targ->inq_data)[i], | ||
2974 | targ->dv_buffer[i]); | ||
2975 | } | ||
2976 | printf("\n"); | ||
2977 | } | ||
2978 | #endif | ||
2979 | |||
2980 | if (ahd_linux_dv_fallback(ahd, devinfo) != 0) { | ||
2981 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
2982 | break; | ||
2983 | } | ||
2984 | /* | ||
2985 | * Do not count "falling back" | ||
2986 | * against our retries. | ||
2987 | */ | ||
2988 | targ->dv_state_retry = 0; | ||
2989 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
2990 | break; | ||
2991 | } | ||
2992 | case SS_INQ_REFRESH: | ||
2993 | AHD_SET_DV_STATE(ahd, targ, | ||
2994 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
2995 | break; | ||
2996 | case SS_TUR: | ||
2997 | case SS_RETRY: | ||
2998 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
2999 | if (ahd_cmd_get_transaction_status(cmd) | ||
3000 | == CAM_REQUEUE_REQ) { | ||
3001 | targ->dv_state_retry--; | ||
3002 | } else if ((status & SSQ_FALLBACK) != 0) { | ||
3003 | if (ahd_linux_dv_fallback(ahd, devinfo) != 0) { | ||
3004 | AHD_SET_DV_STATE(ahd, targ, | ||
3005 | AHD_DV_STATE_EXIT); | ||
3006 | break; | ||
3007 | } | ||
3008 | /* | ||
3009 | * Do not count "falling back" | ||
3010 | * against our retries. | ||
3011 | */ | ||
3012 | targ->dv_state_retry = 0; | ||
3013 | } else if ((status & SS_ERRMASK) == EBUSY) | ||
3014 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY); | ||
3015 | if (targ->dv_state_retry < 10) | ||
3016 | break; | ||
3017 | /* FALLTHROUGH */ | ||
3018 | default: | ||
3019 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
3020 | #ifdef AHD_DEBUG | ||
3021 | if (ahd_debug & AHD_SHOW_DV) { | ||
3022 | ahd_print_devinfo(ahd, devinfo); | ||
3023 | printf("Failed DV inquiry, skipping\n"); | ||
3024 | } | ||
3025 | #endif | ||
3026 | break; | ||
3027 | } | ||
3028 | break; | ||
3029 | |||
3030 | case AHD_DV_STATE_TUR: | ||
3031 | switch (status & SS_MASK) { | ||
3032 | case SS_NOP: | ||
3033 | if ((targ->flags & AHD_BASIC_DV) != 0) { | ||
3034 | ahd_linux_filter_inquiry(ahd, devinfo); | ||
3035 | AHD_SET_DV_STATE(ahd, targ, | ||
3036 | AHD_DV_STATE_INQ_VERIFY); | ||
3037 | } else if ((targ->flags & AHD_ENHANCED_DV) != 0) { | ||
3038 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_REBD); | ||
3039 | } else { | ||
3040 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
3041 | } | ||
3042 | break; | ||
3043 | case SS_RETRY: | ||
3044 | case SS_TUR: | ||
3045 | if ((status & SS_ERRMASK) == EBUSY) { | ||
3046 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY); | ||
3047 | break; | ||
3048 | } | ||
3049 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
3050 | if (ahd_cmd_get_transaction_status(cmd) | ||
3051 | == CAM_REQUEUE_REQ) { | ||
3052 | targ->dv_state_retry--; | ||
3053 | } else if ((status & SSQ_FALLBACK) != 0) { | ||
3054 | if (ahd_linux_dv_fallback(ahd, devinfo) != 0) { | ||
3055 | AHD_SET_DV_STATE(ahd, targ, | ||
3056 | AHD_DV_STATE_EXIT); | ||
3057 | break; | ||
3058 | } | ||
3059 | /* | ||
3060 | * Do not count "falling back" | ||
3061 | * against our retries. | ||
3062 | */ | ||
3063 | targ->dv_state_retry = 0; | ||
3064 | } | ||
3065 | if (targ->dv_state_retry >= 10) { | ||
3066 | #ifdef AHD_DEBUG | ||
3067 | if (ahd_debug & AHD_SHOW_DV) { | ||
3068 | ahd_print_devinfo(ahd, devinfo); | ||
3069 | printf("DV TUR reties exhausted\n"); | ||
3070 | } | ||
3071 | #endif | ||
3072 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
3073 | break; | ||
3074 | } | ||
3075 | if (status & SSQ_DELAY) | ||
3076 | ssleep(1); | ||
3077 | |||
3078 | break; | ||
3079 | case SS_START: | ||
3080 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_SU); | ||
3081 | break; | ||
3082 | case SS_INQ_REFRESH: | ||
3083 | AHD_SET_DV_STATE(ahd, targ, | ||
3084 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
3085 | break; | ||
3086 | default: | ||
3087 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
3088 | break; | ||
3089 | } | ||
3090 | break; | ||
3091 | |||
3092 | case AHD_DV_STATE_REBD: | ||
3093 | switch (status & SS_MASK) { | ||
3094 | case SS_NOP: | ||
3095 | { | ||
3096 | uint32_t echo_size; | ||
3097 | |||
3098 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_WEB); | ||
3099 | echo_size = scsi_3btoul(&targ->dv_buffer[1]); | ||
3100 | echo_size &= 0x1FFF; | ||
3101 | #ifdef AHD_DEBUG | ||
3102 | if (ahd_debug & AHD_SHOW_DV) { | ||
3103 | ahd_print_devinfo(ahd, devinfo); | ||
3104 | printf("Echo buffer size= %d\n", echo_size); | ||
3105 | } | ||
3106 | #endif | ||
3107 | if (echo_size == 0) { | ||
3108 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
3109 | break; | ||
3110 | } | ||
3111 | |||
3112 | /* Generate the buffer pattern */ | ||
3113 | targ->dv_echo_size = echo_size; | ||
3114 | ahd_linux_generate_dv_pattern(targ); | ||
3115 | /* | ||
3116 | * Setup initial negotiation values. | ||
3117 | */ | ||
3118 | ahd_linux_filter_inquiry(ahd, devinfo); | ||
3119 | break; | ||
3120 | } | ||
3121 | case SS_INQ_REFRESH: | ||
3122 | AHD_SET_DV_STATE(ahd, targ, | ||
3123 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
3124 | break; | ||
3125 | case SS_RETRY: | ||
3126 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
3127 | if (ahd_cmd_get_transaction_status(cmd) | ||
3128 | == CAM_REQUEUE_REQ) | ||
3129 | targ->dv_state_retry--; | ||
3130 | if (targ->dv_state_retry <= 10) | ||
3131 | break; | ||
3132 | #ifdef AHD_DEBUG | ||
3133 | if (ahd_debug & AHD_SHOW_DV) { | ||
3134 | ahd_print_devinfo(ahd, devinfo); | ||
3135 | printf("DV REBD reties exhausted\n"); | ||
3136 | } | ||
3137 | #endif | ||
3138 | /* FALLTHROUGH */ | ||
3139 | case SS_FATAL: | ||
3140 | default: | ||
3141 | /* | ||
3142 | * Setup initial negotiation values | ||
3143 | * and try level 1 DV. | ||
3144 | */ | ||
3145 | ahd_linux_filter_inquiry(ahd, devinfo); | ||
3146 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_INQ_VERIFY); | ||
3147 | targ->dv_echo_size = 0; | ||
3148 | break; | ||
3149 | } | ||
3150 | break; | ||
3151 | |||
3152 | case AHD_DV_STATE_WEB: | ||
3153 | switch (status & SS_MASK) { | ||
3154 | case SS_NOP: | ||
3155 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_REB); | ||
3156 | break; | ||
3157 | case SS_INQ_REFRESH: | ||
3158 | AHD_SET_DV_STATE(ahd, targ, | ||
3159 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
3160 | break; | ||
3161 | case SS_RETRY: | ||
3162 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
3163 | if (ahd_cmd_get_transaction_status(cmd) | ||
3164 | == CAM_REQUEUE_REQ) { | ||
3165 | targ->dv_state_retry--; | ||
3166 | } else if ((status & SSQ_FALLBACK) != 0) { | ||
3167 | if (ahd_linux_dv_fallback(ahd, devinfo) != 0) { | ||
3168 | AHD_SET_DV_STATE(ahd, targ, | ||
3169 | AHD_DV_STATE_EXIT); | ||
3170 | break; | ||
3171 | } | ||
3172 | /* | ||
3173 | * Do not count "falling back" | ||
3174 | * against our retries. | ||
3175 | */ | ||
3176 | targ->dv_state_retry = 0; | ||
3177 | } | ||
3178 | if (targ->dv_state_retry <= 10) | ||
3179 | break; | ||
3180 | /* FALLTHROUGH */ | ||
3181 | #ifdef AHD_DEBUG | ||
3182 | if (ahd_debug & AHD_SHOW_DV) { | ||
3183 | ahd_print_devinfo(ahd, devinfo); | ||
3184 | printf("DV WEB reties exhausted\n"); | ||
3185 | } | ||
3186 | #endif | ||
3187 | default: | ||
3188 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
3189 | break; | ||
3190 | } | ||
3191 | break; | ||
3192 | |||
3193 | case AHD_DV_STATE_REB: | ||
3194 | switch (status & SS_MASK) { | ||
3195 | case SS_NOP: | ||
3196 | if (memcmp(targ->dv_buffer, targ->dv_buffer1, | ||
3197 | targ->dv_echo_size) != 0) { | ||
3198 | if (ahd_linux_dv_fallback(ahd, devinfo) != 0) | ||
3199 | AHD_SET_DV_STATE(ahd, targ, | ||
3200 | AHD_DV_STATE_EXIT); | ||
3201 | else | ||
3202 | AHD_SET_DV_STATE(ahd, targ, | ||
3203 | AHD_DV_STATE_WEB); | ||
3204 | break; | ||
3205 | } | ||
3206 | |||
3207 | if (targ->dv_buffer != NULL) { | ||
3208 | free(targ->dv_buffer, M_DEVBUF); | ||
3209 | targ->dv_buffer = NULL; | ||
3210 | } | ||
3211 | if (targ->dv_buffer1 != NULL) { | ||
3212 | free(targ->dv_buffer1, M_DEVBUF); | ||
3213 | targ->dv_buffer1 = NULL; | ||
3214 | } | ||
3215 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
3216 | break; | ||
3217 | case SS_INQ_REFRESH: | ||
3218 | AHD_SET_DV_STATE(ahd, targ, | ||
3219 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
3220 | break; | ||
3221 | case SS_RETRY: | ||
3222 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
3223 | if (ahd_cmd_get_transaction_status(cmd) | ||
3224 | == CAM_REQUEUE_REQ) { | ||
3225 | targ->dv_state_retry--; | ||
3226 | } else if ((status & SSQ_FALLBACK) != 0) { | ||
3227 | if (ahd_linux_dv_fallback(ahd, devinfo) != 0) { | ||
3228 | AHD_SET_DV_STATE(ahd, targ, | ||
3229 | AHD_DV_STATE_EXIT); | ||
3230 | break; | ||
3231 | } | ||
3232 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_WEB); | ||
3233 | } | ||
3234 | if (targ->dv_state_retry <= 10) { | ||
3235 | if ((status & (SSQ_DELAY_RANDOM|SSQ_DELAY))!= 0) | ||
3236 | msleep(ahd->our_id*1000/10); | ||
3237 | break; | ||
3238 | } | ||
3239 | #ifdef AHD_DEBUG | ||
3240 | if (ahd_debug & AHD_SHOW_DV) { | ||
3241 | ahd_print_devinfo(ahd, devinfo); | ||
3242 | printf("DV REB reties exhausted\n"); | ||
3243 | } | ||
3244 | #endif | ||
3245 | /* FALLTHROUGH */ | ||
3246 | default: | ||
3247 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
3248 | break; | ||
3249 | } | ||
3250 | break; | ||
3251 | |||
3252 | case AHD_DV_STATE_SU: | ||
3253 | switch (status & SS_MASK) { | ||
3254 | case SS_NOP: | ||
3255 | case SS_INQ_REFRESH: | ||
3256 | AHD_SET_DV_STATE(ahd, targ, | ||
3257 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
3258 | break; | ||
3259 | default: | ||
3260 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
3261 | break; | ||
3262 | } | ||
3263 | break; | ||
3264 | |||
3265 | case AHD_DV_STATE_BUSY: | ||
3266 | switch (status & SS_MASK) { | ||
3267 | case SS_NOP: | ||
3268 | case SS_INQ_REFRESH: | ||
3269 | AHD_SET_DV_STATE(ahd, targ, | ||
3270 | AHD_DV_STATE_INQ_SHORT_ASYNC); | ||
3271 | break; | ||
3272 | case SS_TUR: | ||
3273 | case SS_RETRY: | ||
3274 | AHD_SET_DV_STATE(ahd, targ, targ->dv_state); | ||
3275 | if (ahd_cmd_get_transaction_status(cmd) | ||
3276 | == CAM_REQUEUE_REQ) { | ||
3277 | targ->dv_state_retry--; | ||
3278 | } else if (targ->dv_state_retry < 60) { | ||
3279 | if ((status & SSQ_DELAY) != 0) | ||
3280 | ssleep(1); | ||
3281 | } else { | ||
3282 | #ifdef AHD_DEBUG | ||
3283 | if (ahd_debug & AHD_SHOW_DV) { | ||
3284 | ahd_print_devinfo(ahd, devinfo); | ||
3285 | printf("DV BUSY reties exhausted\n"); | ||
3286 | } | ||
3287 | #endif | ||
3288 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
3289 | } | ||
3290 | break; | ||
3291 | default: | ||
3292 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
3293 | break; | ||
3294 | } | ||
3295 | break; | ||
3296 | |||
3297 | default: | 1346 | default: |
3298 | printf("%s: Invalid DV completion state %d\n", ahd_name(ahd), | ||
3299 | targ->dv_state); | ||
3300 | AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT); | ||
3301 | break; | ||
3302 | } | ||
3303 | } | ||
3304 | |||
3305 | static void | ||
3306 | ahd_linux_dv_fill_cmd(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
3307 | struct ahd_devinfo *devinfo) | ||
3308 | { | ||
3309 | memset(cmd, 0, sizeof(struct scsi_cmnd)); | ||
3310 | cmd->device = ahd->platform_data->dv_scsi_dev; | ||
3311 | cmd->scsi_done = ahd_linux_dv_complete; | ||
3312 | } | ||
3313 | |||
3314 | /* | ||
3315 | * Synthesize an inquiry command. On the return trip, it'll be | ||
3316 | * sniffed and the device transfer settings set for us. | ||
3317 | */ | ||
3318 | static void | ||
3319 | ahd_linux_dv_inq(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
3320 | struct ahd_devinfo *devinfo, struct ahd_linux_target *targ, | ||
3321 | u_int request_length) | ||
3322 | { | ||
3323 | |||
3324 | #ifdef AHD_DEBUG | ||
3325 | if (ahd_debug & AHD_SHOW_DV) { | ||
3326 | ahd_print_devinfo(ahd, devinfo); | ||
3327 | printf("Sending INQ\n"); | ||
3328 | } | ||
3329 | #endif | ||
3330 | if (targ->inq_data == NULL) | ||
3331 | targ->inq_data = malloc(AHD_LINUX_DV_INQ_LEN, | ||
3332 | M_DEVBUF, M_WAITOK); | ||
3333 | if (targ->dv_state > AHD_DV_STATE_INQ_ASYNC) { | ||
3334 | if (targ->dv_buffer != NULL) | ||
3335 | free(targ->dv_buffer, M_DEVBUF); | ||
3336 | targ->dv_buffer = malloc(AHD_LINUX_DV_INQ_LEN, | ||
3337 | M_DEVBUF, M_WAITOK); | ||
3338 | } | ||
3339 | |||
3340 | ahd_linux_dv_fill_cmd(ahd, cmd, devinfo); | ||
3341 | cmd->sc_data_direction = DMA_FROM_DEVICE; | ||
3342 | cmd->cmd_len = 6; | ||
3343 | cmd->cmnd[0] = INQUIRY; | ||
3344 | cmd->cmnd[4] = request_length; | ||
3345 | cmd->request_bufflen = request_length; | ||
3346 | if (targ->dv_state > AHD_DV_STATE_INQ_ASYNC) | ||
3347 | cmd->request_buffer = targ->dv_buffer; | ||
3348 | else | ||
3349 | cmd->request_buffer = targ->inq_data; | ||
3350 | memset(cmd->request_buffer, 0, AHD_LINUX_DV_INQ_LEN); | ||
3351 | } | ||
3352 | |||
3353 | static void | ||
3354 | ahd_linux_dv_tur(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
3355 | struct ahd_devinfo *devinfo) | ||
3356 | { | ||
3357 | |||
3358 | #ifdef AHD_DEBUG | ||
3359 | if (ahd_debug & AHD_SHOW_DV) { | ||
3360 | ahd_print_devinfo(ahd, devinfo); | ||
3361 | printf("Sending TUR\n"); | ||
3362 | } | ||
3363 | #endif | ||
3364 | /* Do a TUR to clear out any non-fatal transitional state */ | ||
3365 | ahd_linux_dv_fill_cmd(ahd, cmd, devinfo); | ||
3366 | cmd->sc_data_direction = DMA_NONE; | ||
3367 | cmd->cmd_len = 6; | ||
3368 | cmd->cmnd[0] = TEST_UNIT_READY; | ||
3369 | } | ||
3370 | |||
3371 | #define AHD_REBD_LEN 4 | ||
3372 | |||
3373 | static void | ||
3374 | ahd_linux_dv_rebd(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
3375 | struct ahd_devinfo *devinfo, struct ahd_linux_target *targ) | ||
3376 | { | ||
3377 | |||
3378 | #ifdef AHD_DEBUG | ||
3379 | if (ahd_debug & AHD_SHOW_DV) { | ||
3380 | ahd_print_devinfo(ahd, devinfo); | ||
3381 | printf("Sending REBD\n"); | ||
3382 | } | ||
3383 | #endif | ||
3384 | if (targ->dv_buffer != NULL) | ||
3385 | free(targ->dv_buffer, M_DEVBUF); | ||
3386 | targ->dv_buffer = malloc(AHD_REBD_LEN, M_DEVBUF, M_WAITOK); | ||
3387 | ahd_linux_dv_fill_cmd(ahd, cmd, devinfo); | ||
3388 | cmd->sc_data_direction = DMA_FROM_DEVICE; | ||
3389 | cmd->cmd_len = 10; | ||
3390 | cmd->cmnd[0] = READ_BUFFER; | ||
3391 | cmd->cmnd[1] = 0x0b; | ||
3392 | scsi_ulto3b(AHD_REBD_LEN, &cmd->cmnd[6]); | ||
3393 | cmd->request_bufflen = AHD_REBD_LEN; | ||
3394 | cmd->underflow = cmd->request_bufflen; | ||
3395 | cmd->request_buffer = targ->dv_buffer; | ||
3396 | } | ||
3397 | |||
3398 | static void | ||
3399 | ahd_linux_dv_web(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
3400 | struct ahd_devinfo *devinfo, struct ahd_linux_target *targ) | ||
3401 | { | ||
3402 | |||
3403 | #ifdef AHD_DEBUG | ||
3404 | if (ahd_debug & AHD_SHOW_DV) { | ||
3405 | ahd_print_devinfo(ahd, devinfo); | ||
3406 | printf("Sending WEB\n"); | ||
3407 | } | ||
3408 | #endif | ||
3409 | ahd_linux_dv_fill_cmd(ahd, cmd, devinfo); | ||
3410 | cmd->sc_data_direction = DMA_TO_DEVICE; | ||
3411 | cmd->cmd_len = 10; | ||
3412 | cmd->cmnd[0] = WRITE_BUFFER; | ||
3413 | cmd->cmnd[1] = 0x0a; | ||
3414 | scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]); | ||
3415 | cmd->request_bufflen = targ->dv_echo_size; | ||
3416 | cmd->underflow = cmd->request_bufflen; | ||
3417 | cmd->request_buffer = targ->dv_buffer; | ||
3418 | } | ||
3419 | |||
3420 | static void | ||
3421 | ahd_linux_dv_reb(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
3422 | struct ahd_devinfo *devinfo, struct ahd_linux_target *targ) | ||
3423 | { | ||
3424 | |||
3425 | #ifdef AHD_DEBUG | ||
3426 | if (ahd_debug & AHD_SHOW_DV) { | ||
3427 | ahd_print_devinfo(ahd, devinfo); | ||
3428 | printf("Sending REB\n"); | ||
3429 | } | ||
3430 | #endif | ||
3431 | ahd_linux_dv_fill_cmd(ahd, cmd, devinfo); | ||
3432 | cmd->sc_data_direction = DMA_FROM_DEVICE; | ||
3433 | cmd->cmd_len = 10; | ||
3434 | cmd->cmnd[0] = READ_BUFFER; | ||
3435 | cmd->cmnd[1] = 0x0a; | ||
3436 | scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]); | ||
3437 | cmd->request_bufflen = targ->dv_echo_size; | ||
3438 | cmd->underflow = cmd->request_bufflen; | ||
3439 | cmd->request_buffer = targ->dv_buffer1; | ||
3440 | } | ||
3441 | |||
3442 | static void | ||
3443 | ahd_linux_dv_su(struct ahd_softc *ahd, struct scsi_cmnd *cmd, | ||
3444 | struct ahd_devinfo *devinfo, | ||
3445 | struct ahd_linux_target *targ) | ||
3446 | { | ||
3447 | u_int le; | ||
3448 | |||
3449 | le = SID_IS_REMOVABLE(targ->inq_data) ? SSS_LOEJ : 0; | ||
3450 | |||
3451 | #ifdef AHD_DEBUG | ||
3452 | if (ahd_debug & AHD_SHOW_DV) { | ||
3453 | ahd_print_devinfo(ahd, devinfo); | ||
3454 | printf("Sending SU\n"); | ||
3455 | } | ||
3456 | #endif | ||
3457 | ahd_linux_dv_fill_cmd(ahd, cmd, devinfo); | ||
3458 | cmd->sc_data_direction = DMA_NONE; | ||
3459 | cmd->cmd_len = 6; | ||
3460 | cmd->cmnd[0] = START_STOP_UNIT; | ||
3461 | cmd->cmnd[4] = le | SSS_START; | ||
3462 | } | ||
3463 | |||
3464 | static int | ||
3465 | ahd_linux_fallback(struct ahd_softc *ahd, struct ahd_devinfo *devinfo) | ||
3466 | { | ||
3467 | struct ahd_linux_target *targ; | ||
3468 | struct ahd_initiator_tinfo *tinfo; | ||
3469 | struct ahd_transinfo *goal; | ||
3470 | struct ahd_tmode_tstate *tstate; | ||
3471 | u_int width; | ||
3472 | u_int period; | ||
3473 | u_int offset; | ||
3474 | u_int ppr_options; | ||
3475 | u_int cur_speed; | ||
3476 | u_int wide_speed; | ||
3477 | u_int narrow_speed; | ||
3478 | u_int fallback_speed; | ||
3479 | |||
3480 | #ifdef AHD_DEBUG | ||
3481 | if (ahd_debug & AHD_SHOW_DV) { | ||
3482 | ahd_print_devinfo(ahd, devinfo); | ||
3483 | printf("Trying to fallback\n"); | ||
3484 | } | ||
3485 | #endif | ||
3486 | targ = ahd->platform_data->targets[devinfo->target_offset]; | ||
3487 | tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, | ||
3488 | devinfo->our_scsiid, | ||
3489 | devinfo->target, &tstate); | ||
3490 | goal = &tinfo->goal; | ||
3491 | width = goal->width; | ||
3492 | period = goal->period; | ||
3493 | offset = goal->offset; | ||
3494 | ppr_options = goal->ppr_options; | ||
3495 | if (offset == 0) | ||
3496 | period = AHD_ASYNC_XFER_PERIOD; | ||
3497 | if (targ->dv_next_narrow_period == 0) | ||
3498 | targ->dv_next_narrow_period = MAX(period, AHD_SYNCRATE_ULTRA2); | ||
3499 | if (targ->dv_next_wide_period == 0) | ||
3500 | targ->dv_next_wide_period = period; | ||
3501 | if (targ->dv_max_width == 0) | ||
3502 | targ->dv_max_width = width; | ||
3503 | if (targ->dv_max_ppr_options == 0) | ||
3504 | targ->dv_max_ppr_options = ppr_options; | ||
3505 | if (targ->dv_last_ppr_options == 0) | ||
3506 | targ->dv_last_ppr_options = ppr_options; | ||
3507 | |||
3508 | cur_speed = aic_calc_speed(width, period, offset, AHD_SYNCRATE_MIN); | ||
3509 | wide_speed = aic_calc_speed(MSG_EXT_WDTR_BUS_16_BIT, | ||
3510 | targ->dv_next_wide_period, | ||
3511 | MAX_OFFSET, AHD_SYNCRATE_MIN); | ||
3512 | narrow_speed = aic_calc_speed(MSG_EXT_WDTR_BUS_8_BIT, | ||
3513 | targ->dv_next_narrow_period, | ||
3514 | MAX_OFFSET, AHD_SYNCRATE_MIN); | ||
3515 | fallback_speed = aic_calc_speed(width, period+1, offset, | ||
3516 | AHD_SYNCRATE_MIN); | ||
3517 | #ifdef AHD_DEBUG | ||
3518 | if (ahd_debug & AHD_SHOW_DV) { | ||
3519 | printf("cur_speed= %d, wide_speed= %d, narrow_speed= %d, " | ||
3520 | "fallback_speed= %d\n", cur_speed, wide_speed, | ||
3521 | narrow_speed, fallback_speed); | ||
3522 | } | ||
3523 | #endif | ||
3524 | |||
3525 | if (cur_speed > 160000) { | ||
3526 | /* | ||
3527 | * Paced/DT/IU_REQ only transfer speeds. All we | ||
3528 | * can do is fallback in terms of syncrate. | ||
3529 | */ | ||
3530 | period++; | ||
3531 | } else if (cur_speed > 80000) { | ||
3532 | if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) { | ||
3533 | /* | ||
3534 | * Try without IU_REQ as it may be confusing | ||
3535 | * an expander. | ||
3536 | */ | ||
3537 | ppr_options &= ~MSG_EXT_PPR_IU_REQ; | ||
3538 | } else { | ||
3539 | /* | ||
3540 | * Paced/DT only transfer speeds. All we | ||
3541 | * can do is fallback in terms of syncrate. | ||
3542 | */ | ||
3543 | period++; | ||
3544 | ppr_options = targ->dv_max_ppr_options; | ||
3545 | } | ||
3546 | } else if (cur_speed > 3300) { | ||
3547 | |||
3548 | /* | 1347 | /* |
3549 | * In this range we the following | 1348 | * We allow the OS to queue 2 untagged transactions to |
3550 | * options ordered from highest to | 1349 | * us at any time even though we can only execute them |
3551 | * lowest desireability: | 1350 | * serially on the controller/device. This should |
3552 | * | 1351 | * remove some latency. |
3553 | * o Wide/DT | ||
3554 | * o Wide/non-DT | ||
3555 | * o Narrow at a potentally higher sync rate. | ||
3556 | * | ||
3557 | * All modes are tested with and without IU_REQ | ||
3558 | * set since using IUs may confuse an expander. | ||
3559 | */ | 1352 | */ |
3560 | if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) { | 1353 | scsi_adjust_queue_depth(sdev, |
3561 | 1354 | /*NON-TAGGED*/0, | |
3562 | ppr_options &= ~MSG_EXT_PPR_IU_REQ; | 1355 | /*queue depth*/2); |
3563 | } else if ((ppr_options & MSG_EXT_PPR_DT_REQ) != 0) { | 1356 | break; |
3564 | /* | ||
3565 | * Try going non-DT. | ||
3566 | */ | ||
3567 | ppr_options = targ->dv_max_ppr_options; | ||
3568 | ppr_options &= ~MSG_EXT_PPR_DT_REQ; | ||
3569 | } else if (targ->dv_last_ppr_options != 0) { | ||
3570 | /* | ||
3571 | * Try without QAS or any other PPR options. | ||
3572 | * We may need a non-PPR message to work with | ||
3573 | * an expander. We look at the "last PPR options" | ||
3574 | * so we will perform this fallback even if the | ||
3575 | * target responded to our PPR negotiation with | ||
3576 | * no option bits set. | ||
3577 | */ | ||
3578 | ppr_options = 0; | ||
3579 | } else if (width == MSG_EXT_WDTR_BUS_16_BIT) { | ||
3580 | /* | ||
3581 | * If the next narrow speed is greater than | ||
3582 | * the next wide speed, fallback to narrow. | ||
3583 | * Otherwise fallback to the next DT/Wide setting. | ||
3584 | * The narrow async speed will always be smaller | ||
3585 | * than the wide async speed, so handle this case | ||
3586 | * specifically. | ||
3587 | */ | ||
3588 | ppr_options = targ->dv_max_ppr_options; | ||
3589 | if (narrow_speed > fallback_speed | ||
3590 | || period >= AHD_ASYNC_XFER_PERIOD) { | ||
3591 | targ->dv_next_wide_period = period+1; | ||
3592 | width = MSG_EXT_WDTR_BUS_8_BIT; | ||
3593 | period = targ->dv_next_narrow_period; | ||
3594 | } else { | ||
3595 | period++; | ||
3596 | } | ||
3597 | } else if ((ahd->features & AHD_WIDE) != 0 | ||
3598 | && targ->dv_max_width != 0 | ||
3599 | && wide_speed >= fallback_speed | ||
3600 | && (targ->dv_next_wide_period <= AHD_ASYNC_XFER_PERIOD | ||
3601 | || period >= AHD_ASYNC_XFER_PERIOD)) { | ||
3602 | |||
3603 | /* | ||
3604 | * We are narrow. Try falling back | ||
3605 | * to the next wide speed with | ||
3606 | * all supported ppr options set. | ||
3607 | */ | ||
3608 | targ->dv_next_narrow_period = period+1; | ||
3609 | width = MSG_EXT_WDTR_BUS_16_BIT; | ||
3610 | period = targ->dv_next_wide_period; | ||
3611 | ppr_options = targ->dv_max_ppr_options; | ||
3612 | } else { | ||
3613 | /* Only narrow fallback is allowed. */ | ||
3614 | period++; | ||
3615 | ppr_options = targ->dv_max_ppr_options; | ||
3616 | } | ||
3617 | } else { | ||
3618 | return (-1); | ||
3619 | } | ||
3620 | offset = MAX_OFFSET; | ||
3621 | ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_PACED); | ||
3622 | ahd_set_width(ahd, devinfo, width, AHD_TRANS_GOAL, FALSE); | ||
3623 | if (period == 0) { | ||
3624 | period = 0; | ||
3625 | offset = 0; | ||
3626 | ppr_options = 0; | ||
3627 | if (width == MSG_EXT_WDTR_BUS_8_BIT) | ||
3628 | targ->dv_next_narrow_period = AHD_ASYNC_XFER_PERIOD; | ||
3629 | else | ||
3630 | targ->dv_next_wide_period = AHD_ASYNC_XFER_PERIOD; | ||
3631 | } | ||
3632 | ahd_set_syncrate(ahd, devinfo, period, offset, | ||
3633 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
3634 | targ->dv_last_ppr_options = ppr_options; | ||
3635 | return (0); | ||
3636 | } | ||
3637 | |||
3638 | static void | ||
3639 | ahd_linux_dv_timeout(struct scsi_cmnd *cmd) | ||
3640 | { | ||
3641 | struct ahd_softc *ahd; | ||
3642 | struct scb *scb; | ||
3643 | u_long flags; | ||
3644 | |||
3645 | ahd = *((struct ahd_softc **)cmd->device->host->hostdata); | ||
3646 | ahd_lock(ahd, &flags); | ||
3647 | |||
3648 | #ifdef AHD_DEBUG | ||
3649 | if (ahd_debug & AHD_SHOW_DV) { | ||
3650 | printf("%s: Timeout while doing DV command %x.\n", | ||
3651 | ahd_name(ahd), cmd->cmnd[0]); | ||
3652 | ahd_dump_card_state(ahd); | ||
3653 | } | ||
3654 | #endif | ||
3655 | |||
3656 | /* | ||
3657 | * Guard against "done race". No action is | ||
3658 | * required if we just completed. | ||
3659 | */ | ||
3660 | if ((scb = (struct scb *)cmd->host_scribble) == NULL) { | ||
3661 | ahd_unlock(ahd, &flags); | ||
3662 | return; | ||
3663 | } | 1357 | } |
3664 | |||
3665 | /* | ||
3666 | * Command has not completed. Mark this | ||
3667 | * SCB as having failing status prior to | ||
3668 | * resetting the bus, so we get the correct | ||
3669 | * error code. | ||
3670 | */ | ||
3671 | if ((scb->flags & SCB_SENSE) != 0) | ||
3672 | ahd_set_transaction_status(scb, CAM_AUTOSENSE_FAIL); | ||
3673 | else | ||
3674 | ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT); | ||
3675 | ahd_reset_channel(ahd, cmd->device->channel + 'A', /*initiate*/TRUE); | ||
3676 | |||
3677 | /* | ||
3678 | * Add a minimal bus settle delay for devices that are slow to | ||
3679 | * respond after bus resets. | ||
3680 | */ | ||
3681 | ahd_freeze_simq(ahd); | ||
3682 | init_timer(&ahd->platform_data->reset_timer); | ||
3683 | ahd->platform_data->reset_timer.data = (u_long)ahd; | ||
3684 | ahd->platform_data->reset_timer.expires = jiffies + HZ / 2; | ||
3685 | ahd->platform_data->reset_timer.function = | ||
3686 | (ahd_linux_callback_t *)ahd_release_simq; | ||
3687 | add_timer(&ahd->platform_data->reset_timer); | ||
3688 | if (ahd_linux_next_device_to_run(ahd) != NULL) | ||
3689 | ahd_schedule_runq(ahd); | ||
3690 | ahd_linux_run_complete_queue(ahd); | ||
3691 | ahd_unlock(ahd, &flags); | ||
3692 | } | ||
3693 | |||
3694 | static void | ||
3695 | ahd_linux_dv_complete(struct scsi_cmnd *cmd) | ||
3696 | { | ||
3697 | struct ahd_softc *ahd; | ||
3698 | |||
3699 | ahd = *((struct ahd_softc **)cmd->device->host->hostdata); | ||
3700 | |||
3701 | /* Delete the DV timer before it goes off! */ | ||
3702 | scsi_delete_timer(cmd); | ||
3703 | |||
3704 | #ifdef AHD_DEBUG | ||
3705 | if (ahd_debug & AHD_SHOW_DV) | ||
3706 | printf("%s:%c:%d: Command completed, status= 0x%x\n", | ||
3707 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
3708 | cmd->result); | ||
3709 | #endif | ||
3710 | |||
3711 | /* Wake up the state machine */ | ||
3712 | up(&ahd->platform_data->dv_cmd_sem); | ||
3713 | } | 1358 | } |
3714 | 1359 | ||
3715 | static void | 1360 | int |
3716 | ahd_linux_generate_dv_pattern(struct ahd_linux_target *targ) | 1361 | ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel, |
1362 | int lun, u_int tag, role_t role, uint32_t status) | ||
3717 | { | 1363 | { |
3718 | uint16_t b; | 1364 | return 0; |
3719 | u_int i; | ||
3720 | u_int j; | ||
3721 | |||
3722 | if (targ->dv_buffer != NULL) | ||
3723 | free(targ->dv_buffer, M_DEVBUF); | ||
3724 | targ->dv_buffer = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK); | ||
3725 | if (targ->dv_buffer1 != NULL) | ||
3726 | free(targ->dv_buffer1, M_DEVBUF); | ||
3727 | targ->dv_buffer1 = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK); | ||
3728 | |||
3729 | i = 0; | ||
3730 | |||
3731 | b = 0x0001; | ||
3732 | for (j = 0 ; i < targ->dv_echo_size; j++) { | ||
3733 | if (j < 32) { | ||
3734 | /* | ||
3735 | * 32bytes of sequential numbers. | ||
3736 | */ | ||
3737 | targ->dv_buffer[i++] = j & 0xff; | ||
3738 | } else if (j < 48) { | ||
3739 | /* | ||
3740 | * 32bytes of repeating 0x0000, 0xffff. | ||
3741 | */ | ||
3742 | targ->dv_buffer[i++] = (j & 0x02) ? 0xff : 0x00; | ||
3743 | } else if (j < 64) { | ||
3744 | /* | ||
3745 | * 32bytes of repeating 0x5555, 0xaaaa. | ||
3746 | */ | ||
3747 | targ->dv_buffer[i++] = (j & 0x02) ? 0xaa : 0x55; | ||
3748 | } else { | ||
3749 | /* | ||
3750 | * Remaining buffer is filled with a repeating | ||
3751 | * patter of: | ||
3752 | * | ||
3753 | * 0xffff | ||
3754 | * ~0x0001 << shifted once in each loop. | ||
3755 | */ | ||
3756 | if (j & 0x02) { | ||
3757 | if (j & 0x01) { | ||
3758 | targ->dv_buffer[i++] = ~(b >> 8) & 0xff; | ||
3759 | b <<= 1; | ||
3760 | if (b == 0x0000) | ||
3761 | b = 0x0001; | ||
3762 | } else { | ||
3763 | targ->dv_buffer[i++] = (~b & 0xff); | ||
3764 | } | ||
3765 | } else { | ||
3766 | targ->dv_buffer[i++] = 0xff; | ||
3767 | } | ||
3768 | } | ||
3769 | } | ||
3770 | } | 1365 | } |
3771 | 1366 | ||
3772 | static u_int | 1367 | static u_int |
@@ -3800,100 +1395,23 @@ ahd_linux_user_tagdepth(struct ahd_softc *ahd, struct ahd_devinfo *devinfo) | |||
3800 | return (tags); | 1395 | return (tags); |
3801 | } | 1396 | } |
3802 | 1397 | ||
3803 | static u_int | ||
3804 | ahd_linux_user_dv_setting(struct ahd_softc *ahd) | ||
3805 | { | ||
3806 | static int warned_user; | ||
3807 | int dv; | ||
3808 | |||
3809 | if (ahd->unit >= NUM_ELEMENTS(aic79xx_dv_settings)) { | ||
3810 | |||
3811 | if (warned_user == 0) { | ||
3812 | printf(KERN_WARNING | ||
3813 | "aic79xx: WARNING: Insufficient dv settings instances\n" | ||
3814 | "aic79xx: for installed controllers. Using defaults\n" | ||
3815 | "aic79xx: Please update the aic79xx_dv_settings array in" | ||
3816 | "aic79xx: the aic79xx_osm.c source file.\n"); | ||
3817 | warned_user++; | ||
3818 | } | ||
3819 | dv = -1; | ||
3820 | } else { | ||
3821 | |||
3822 | dv = aic79xx_dv_settings[ahd->unit]; | ||
3823 | } | ||
3824 | |||
3825 | if (dv < 0) { | ||
3826 | /* | ||
3827 | * Apply the default. | ||
3828 | */ | ||
3829 | dv = 1; | ||
3830 | if (ahd->seep_config != 0) | ||
3831 | dv = (ahd->seep_config->bios_control & CFENABLEDV); | ||
3832 | } | ||
3833 | return (dv); | ||
3834 | } | ||
3835 | |||
3836 | static void | ||
3837 | ahd_linux_setup_user_rd_strm_settings(struct ahd_softc *ahd) | ||
3838 | { | ||
3839 | static int warned_user; | ||
3840 | u_int rd_strm_mask; | ||
3841 | u_int target_id; | ||
3842 | |||
3843 | /* | ||
3844 | * If we have specific read streaming info for this controller, | ||
3845 | * apply it. Otherwise use the defaults. | ||
3846 | */ | ||
3847 | if (ahd->unit >= NUM_ELEMENTS(aic79xx_rd_strm_info)) { | ||
3848 | |||
3849 | if (warned_user == 0) { | ||
3850 | |||
3851 | printf(KERN_WARNING | ||
3852 | "aic79xx: WARNING: Insufficient rd_strm instances\n" | ||
3853 | "aic79xx: for installed controllers. Using defaults\n" | ||
3854 | "aic79xx: Please update the aic79xx_rd_strm_info array\n" | ||
3855 | "aic79xx: in the aic79xx_osm.c source file.\n"); | ||
3856 | warned_user++; | ||
3857 | } | ||
3858 | rd_strm_mask = AIC79XX_CONFIGED_RD_STRM; | ||
3859 | } else { | ||
3860 | |||
3861 | rd_strm_mask = aic79xx_rd_strm_info[ahd->unit]; | ||
3862 | } | ||
3863 | for (target_id = 0; target_id < 16; target_id++) { | ||
3864 | struct ahd_devinfo devinfo; | ||
3865 | struct ahd_initiator_tinfo *tinfo; | ||
3866 | struct ahd_tmode_tstate *tstate; | ||
3867 | |||
3868 | tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id, | ||
3869 | target_id, &tstate); | ||
3870 | ahd_compile_devinfo(&devinfo, ahd->our_id, target_id, | ||
3871 | CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR); | ||
3872 | tinfo->user.ppr_options &= ~MSG_EXT_PPR_RD_STRM; | ||
3873 | if ((rd_strm_mask & devinfo.target_mask) != 0) | ||
3874 | tinfo->user.ppr_options |= MSG_EXT_PPR_RD_STRM; | ||
3875 | } | ||
3876 | } | ||
3877 | |||
3878 | /* | 1398 | /* |
3879 | * Determines the queue depth for a given device. | 1399 | * Determines the queue depth for a given device. |
3880 | */ | 1400 | */ |
3881 | static void | 1401 | static void |
3882 | ahd_linux_device_queue_depth(struct ahd_softc *ahd, | 1402 | ahd_linux_device_queue_depth(struct scsi_device *sdev) |
3883 | struct ahd_linux_device *dev) | ||
3884 | { | 1403 | { |
3885 | struct ahd_devinfo devinfo; | 1404 | struct ahd_devinfo devinfo; |
3886 | u_int tags; | 1405 | u_int tags; |
1406 | struct ahd_softc *ahd = *((struct ahd_softc **)sdev->host->hostdata); | ||
3887 | 1407 | ||
3888 | ahd_compile_devinfo(&devinfo, | 1408 | ahd_compile_devinfo(&devinfo, |
3889 | ahd->our_id, | 1409 | ahd->our_id, |
3890 | dev->target->target, dev->lun, | 1410 | sdev->sdev_target->id, sdev->lun, |
3891 | dev->target->channel == 0 ? 'A' : 'B', | 1411 | sdev->sdev_target->channel == 0 ? 'A' : 'B', |
3892 | ROLE_INITIATOR); | 1412 | ROLE_INITIATOR); |
3893 | tags = ahd_linux_user_tagdepth(ahd, &devinfo); | 1413 | tags = ahd_linux_user_tagdepth(ahd, &devinfo); |
3894 | if (tags != 0 | 1414 | if (tags != 0 && sdev->tagged_supported != 0) { |
3895 | && dev->scsi_device != NULL | ||
3896 | && dev->scsi_device->tagged_supported != 0) { | ||
3897 | 1415 | ||
3898 | ahd_set_tags(ahd, &devinfo, AHD_QUEUE_TAGGED); | 1416 | ahd_set_tags(ahd, &devinfo, AHD_QUEUE_TAGGED); |
3899 | ahd_print_devinfo(ahd, &devinfo); | 1417 | ahd_print_devinfo(ahd, &devinfo); |
@@ -3903,11 +1421,10 @@ ahd_linux_device_queue_depth(struct ahd_softc *ahd, | |||
3903 | } | 1421 | } |
3904 | } | 1422 | } |
3905 | 1423 | ||
3906 | static void | 1424 | static int |
3907 | ahd_linux_run_device_queue(struct ahd_softc *ahd, struct ahd_linux_device *dev) | 1425 | ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev, |
1426 | struct scsi_cmnd *cmd) | ||
3908 | { | 1427 | { |
3909 | struct ahd_cmd *acmd; | ||
3910 | struct scsi_cmnd *cmd; | ||
3911 | struct scb *scb; | 1428 | struct scb *scb; |
3912 | struct hardware_scb *hscb; | 1429 | struct hardware_scb *hscb; |
3913 | struct ahd_initiator_tinfo *tinfo; | 1430 | struct ahd_initiator_tinfo *tinfo; |
@@ -3915,157 +1432,122 @@ ahd_linux_run_device_queue(struct ahd_softc *ahd, struct ahd_linux_device *dev) | |||
3915 | u_int col_idx; | 1432 | u_int col_idx; |
3916 | uint16_t mask; | 1433 | uint16_t mask; |
3917 | 1434 | ||
3918 | if ((dev->flags & AHD_DEV_ON_RUN_LIST) != 0) | 1435 | /* |
3919 | panic("running device on run list"); | 1436 | * Get an scb to use. |
3920 | 1437 | */ | |
3921 | while ((acmd = TAILQ_FIRST(&dev->busyq)) != NULL | 1438 | tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id, |
3922 | && dev->openings > 0 && dev->qfrozen == 0) { | 1439 | cmd->device->id, &tstate); |
3923 | 1440 | if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0 | |
3924 | /* | 1441 | || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) { |
3925 | * Schedule us to run later. The only reason we are not | 1442 | col_idx = AHD_NEVER_COL_IDX; |
3926 | * running is because the whole controller Q is frozen. | 1443 | } else { |
3927 | */ | 1444 | col_idx = AHD_BUILD_COL_IDX(cmd->device->id, |
3928 | if (ahd->platform_data->qfrozen != 0 | 1445 | cmd->device->lun); |
3929 | && AHD_DV_SIMQ_FROZEN(ahd) == 0) { | 1446 | } |
3930 | 1447 | if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) { | |
3931 | TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, | 1448 | ahd->flags |= AHD_RESOURCE_SHORTAGE; |
3932 | dev, links); | 1449 | return SCSI_MLQUEUE_HOST_BUSY; |
3933 | dev->flags |= AHD_DEV_ON_RUN_LIST; | 1450 | } |
3934 | return; | ||
3935 | } | ||
3936 | |||
3937 | cmd = &acmd_scsi_cmd(acmd); | ||
3938 | 1451 | ||
3939 | /* | 1452 | scb->io_ctx = cmd; |
3940 | * Get an scb to use. | 1453 | scb->platform_data->dev = dev; |
3941 | */ | 1454 | hscb = scb->hscb; |
3942 | tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id, | 1455 | cmd->host_scribble = (char *)scb; |
3943 | cmd->device->id, &tstate); | ||
3944 | if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0 | ||
3945 | || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) { | ||
3946 | col_idx = AHD_NEVER_COL_IDX; | ||
3947 | } else { | ||
3948 | col_idx = AHD_BUILD_COL_IDX(cmd->device->id, | ||
3949 | cmd->device->lun); | ||
3950 | } | ||
3951 | if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) { | ||
3952 | TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, | ||
3953 | dev, links); | ||
3954 | dev->flags |= AHD_DEV_ON_RUN_LIST; | ||
3955 | ahd->flags |= AHD_RESOURCE_SHORTAGE; | ||
3956 | return; | ||
3957 | } | ||
3958 | TAILQ_REMOVE(&dev->busyq, acmd, acmd_links.tqe); | ||
3959 | scb->io_ctx = cmd; | ||
3960 | scb->platform_data->dev = dev; | ||
3961 | hscb = scb->hscb; | ||
3962 | cmd->host_scribble = (char *)scb; | ||
3963 | 1456 | ||
3964 | /* | 1457 | /* |
3965 | * Fill out basics of the HSCB. | 1458 | * Fill out basics of the HSCB. |
3966 | */ | 1459 | */ |
3967 | hscb->control = 0; | 1460 | hscb->control = 0; |
3968 | hscb->scsiid = BUILD_SCSIID(ahd, cmd); | 1461 | hscb->scsiid = BUILD_SCSIID(ahd, cmd); |
3969 | hscb->lun = cmd->device->lun; | 1462 | hscb->lun = cmd->device->lun; |
3970 | scb->hscb->task_management = 0; | 1463 | scb->hscb->task_management = 0; |
3971 | mask = SCB_GET_TARGET_MASK(ahd, scb); | 1464 | mask = SCB_GET_TARGET_MASK(ahd, scb); |
3972 | 1465 | ||
3973 | if ((ahd->user_discenable & mask) != 0) | 1466 | if ((ahd->user_discenable & mask) != 0) |
3974 | hscb->control |= DISCENB; | 1467 | hscb->control |= DISCENB; |
3975 | 1468 | ||
3976 | if (AHD_DV_CMD(cmd) != 0) | 1469 | if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) |
3977 | scb->flags |= SCB_SILENT; | 1470 | scb->flags |= SCB_PACKETIZED; |
3978 | 1471 | ||
3979 | if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) | 1472 | if ((tstate->auto_negotiate & mask) != 0) { |
3980 | scb->flags |= SCB_PACKETIZED; | 1473 | scb->flags |= SCB_AUTO_NEGOTIATE; |
1474 | scb->hscb->control |= MK_MESSAGE; | ||
1475 | } | ||
3981 | 1476 | ||
3982 | if ((tstate->auto_negotiate & mask) != 0) { | 1477 | if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) { |
3983 | scb->flags |= SCB_AUTO_NEGOTIATE; | 1478 | int msg_bytes; |
3984 | scb->hscb->control |= MK_MESSAGE; | 1479 | uint8_t tag_msgs[2]; |
3985 | } | ||
3986 | 1480 | ||
3987 | if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) { | 1481 | msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs); |
3988 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | 1482 | if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) { |
3989 | int msg_bytes; | 1483 | hscb->control |= tag_msgs[0]; |
3990 | uint8_t tag_msgs[2]; | 1484 | if (tag_msgs[0] == MSG_ORDERED_TASK) |
3991 | |||
3992 | msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs); | ||
3993 | if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) { | ||
3994 | hscb->control |= tag_msgs[0]; | ||
3995 | if (tag_msgs[0] == MSG_ORDERED_TASK) | ||
3996 | dev->commands_since_idle_or_otag = 0; | ||
3997 | } else | ||
3998 | #endif | ||
3999 | if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH | ||
4000 | && (dev->flags & AHD_DEV_Q_TAGGED) != 0) { | ||
4001 | hscb->control |= MSG_ORDERED_TASK; | ||
4002 | dev->commands_since_idle_or_otag = 0; | 1485 | dev->commands_since_idle_or_otag = 0; |
4003 | } else { | 1486 | } else |
4004 | hscb->control |= MSG_SIMPLE_TASK; | 1487 | if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH |
4005 | } | 1488 | && (dev->flags & AHD_DEV_Q_TAGGED) != 0) { |
1489 | hscb->control |= MSG_ORDERED_TASK; | ||
1490 | dev->commands_since_idle_or_otag = 0; | ||
1491 | } else { | ||
1492 | hscb->control |= MSG_SIMPLE_TASK; | ||
4006 | } | 1493 | } |
1494 | } | ||
4007 | 1495 | ||
4008 | hscb->cdb_len = cmd->cmd_len; | 1496 | hscb->cdb_len = cmd->cmd_len; |
4009 | memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len); | 1497 | memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len); |
4010 | 1498 | ||
4011 | scb->sg_count = 0; | 1499 | scb->platform_data->xfer_len = 0; |
4012 | ahd_set_residual(scb, 0); | 1500 | ahd_set_residual(scb, 0); |
4013 | ahd_set_sense_residual(scb, 0); | 1501 | ahd_set_sense_residual(scb, 0); |
4014 | if (cmd->use_sg != 0) { | 1502 | scb->sg_count = 0; |
4015 | void *sg; | 1503 | if (cmd->use_sg != 0) { |
4016 | struct scatterlist *cur_seg; | 1504 | void *sg; |
4017 | u_int nseg; | 1505 | struct scatterlist *cur_seg; |
4018 | int dir; | 1506 | u_int nseg; |
4019 | 1507 | int dir; | |
4020 | cur_seg = (struct scatterlist *)cmd->request_buffer; | 1508 | |
4021 | dir = cmd->sc_data_direction; | 1509 | cur_seg = (struct scatterlist *)cmd->request_buffer; |
4022 | nseg = pci_map_sg(ahd->dev_softc, cur_seg, | 1510 | dir = cmd->sc_data_direction; |
4023 | cmd->use_sg, dir); | 1511 | nseg = pci_map_sg(ahd->dev_softc, cur_seg, |
4024 | scb->platform_data->xfer_len = 0; | 1512 | cmd->use_sg, dir); |
4025 | for (sg = scb->sg_list; nseg > 0; nseg--, cur_seg++) { | 1513 | scb->platform_data->xfer_len = 0; |
4026 | dma_addr_t addr; | 1514 | for (sg = scb->sg_list; nseg > 0; nseg--, cur_seg++) { |
4027 | bus_size_t len; | ||
4028 | |||
4029 | addr = sg_dma_address(cur_seg); | ||
4030 | len = sg_dma_len(cur_seg); | ||
4031 | scb->platform_data->xfer_len += len; | ||
4032 | sg = ahd_sg_setup(ahd, scb, sg, addr, len, | ||
4033 | /*last*/nseg == 1); | ||
4034 | } | ||
4035 | } else if (cmd->request_bufflen != 0) { | ||
4036 | void *sg; | ||
4037 | dma_addr_t addr; | 1515 | dma_addr_t addr; |
4038 | int dir; | 1516 | bus_size_t len; |
4039 | |||
4040 | sg = scb->sg_list; | ||
4041 | dir = cmd->sc_data_direction; | ||
4042 | addr = pci_map_single(ahd->dev_softc, | ||
4043 | cmd->request_buffer, | ||
4044 | cmd->request_bufflen, dir); | ||
4045 | scb->platform_data->xfer_len = cmd->request_bufflen; | ||
4046 | scb->platform_data->buf_busaddr = addr; | ||
4047 | sg = ahd_sg_setup(ahd, scb, sg, addr, | ||
4048 | cmd->request_bufflen, /*last*/TRUE); | ||
4049 | } | ||
4050 | 1517 | ||
4051 | LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links); | 1518 | addr = sg_dma_address(cur_seg); |
4052 | dev->openings--; | 1519 | len = sg_dma_len(cur_seg); |
4053 | dev->active++; | 1520 | scb->platform_data->xfer_len += len; |
4054 | dev->commands_issued++; | 1521 | sg = ahd_sg_setup(ahd, scb, sg, addr, len, |
4055 | 1522 | /*last*/nseg == 1); | |
4056 | /* Update the error counting bucket and dump if needed */ | ||
4057 | if (dev->target->cmds_since_error) { | ||
4058 | dev->target->cmds_since_error++; | ||
4059 | if (dev->target->cmds_since_error > | ||
4060 | AHD_LINUX_ERR_THRESH) | ||
4061 | dev->target->cmds_since_error = 0; | ||
4062 | } | 1523 | } |
1524 | } else if (cmd->request_bufflen != 0) { | ||
1525 | void *sg; | ||
1526 | dma_addr_t addr; | ||
1527 | int dir; | ||
4063 | 1528 | ||
4064 | if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0) | 1529 | sg = scb->sg_list; |
4065 | dev->commands_since_idle_or_otag++; | 1530 | dir = cmd->sc_data_direction; |
4066 | scb->flags |= SCB_ACTIVE; | 1531 | addr = pci_map_single(ahd->dev_softc, |
4067 | ahd_queue_scb(ahd, scb); | 1532 | cmd->request_buffer, |
1533 | cmd->request_bufflen, dir); | ||
1534 | scb->platform_data->xfer_len = cmd->request_bufflen; | ||
1535 | scb->platform_data->buf_busaddr = addr; | ||
1536 | sg = ahd_sg_setup(ahd, scb, sg, addr, | ||
1537 | cmd->request_bufflen, /*last*/TRUE); | ||
4068 | } | 1538 | } |
1539 | |||
1540 | LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links); | ||
1541 | dev->openings--; | ||
1542 | dev->active++; | ||
1543 | dev->commands_issued++; | ||
1544 | |||
1545 | if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0) | ||
1546 | dev->commands_since_idle_or_otag++; | ||
1547 | scb->flags |= SCB_ACTIVE; | ||
1548 | ahd_queue_scb(ahd, scb); | ||
1549 | |||
1550 | return 0; | ||
4069 | } | 1551 | } |
4070 | 1552 | ||
4071 | /* | 1553 | /* |
@@ -4081,9 +1563,6 @@ ahd_linux_isr(int irq, void *dev_id, struct pt_regs * regs) | |||
4081 | ahd = (struct ahd_softc *) dev_id; | 1563 | ahd = (struct ahd_softc *) dev_id; |
4082 | ahd_lock(ahd, &flags); | 1564 | ahd_lock(ahd, &flags); |
4083 | ours = ahd_intr(ahd); | 1565 | ours = ahd_intr(ahd); |
4084 | if (ahd_linux_next_device_to_run(ahd) != NULL) | ||
4085 | ahd_schedule_runq(ahd); | ||
4086 | ahd_linux_run_complete_queue(ahd); | ||
4087 | ahd_unlock(ahd, &flags); | 1566 | ahd_unlock(ahd, &flags); |
4088 | return IRQ_RETVAL(ours); | 1567 | return IRQ_RETVAL(ours); |
4089 | } | 1568 | } |
@@ -4092,111 +1571,6 @@ void | |||
4092 | ahd_platform_flushwork(struct ahd_softc *ahd) | 1571 | ahd_platform_flushwork(struct ahd_softc *ahd) |
4093 | { | 1572 | { |
4094 | 1573 | ||
4095 | while (ahd_linux_run_complete_queue(ahd) != NULL) | ||
4096 | ; | ||
4097 | } | ||
4098 | |||
4099 | static struct ahd_linux_target* | ||
4100 | ahd_linux_alloc_target(struct ahd_softc *ahd, u_int channel, u_int target) | ||
4101 | { | ||
4102 | struct ahd_linux_target *targ; | ||
4103 | |||
4104 | targ = malloc(sizeof(*targ), M_DEVBUF, M_NOWAIT); | ||
4105 | if (targ == NULL) | ||
4106 | return (NULL); | ||
4107 | memset(targ, 0, sizeof(*targ)); | ||
4108 | targ->channel = channel; | ||
4109 | targ->target = target; | ||
4110 | targ->ahd = ahd; | ||
4111 | targ->flags = AHD_DV_REQUIRED; | ||
4112 | ahd->platform_data->targets[target] = targ; | ||
4113 | return (targ); | ||
4114 | } | ||
4115 | |||
4116 | static void | ||
4117 | ahd_linux_free_target(struct ahd_softc *ahd, struct ahd_linux_target *targ) | ||
4118 | { | ||
4119 | struct ahd_devinfo devinfo; | ||
4120 | struct ahd_initiator_tinfo *tinfo; | ||
4121 | struct ahd_tmode_tstate *tstate; | ||
4122 | u_int our_id; | ||
4123 | u_int target_offset; | ||
4124 | char channel; | ||
4125 | |||
4126 | /* | ||
4127 | * Force a negotiation to async/narrow on any | ||
4128 | * future command to this device unless a bus | ||
4129 | * reset occurs between now and that command. | ||
4130 | */ | ||
4131 | channel = 'A' + targ->channel; | ||
4132 | our_id = ahd->our_id; | ||
4133 | target_offset = targ->target; | ||
4134 | tinfo = ahd_fetch_transinfo(ahd, channel, our_id, | ||
4135 | targ->target, &tstate); | ||
4136 | ahd_compile_devinfo(&devinfo, our_id, targ->target, CAM_LUN_WILDCARD, | ||
4137 | channel, ROLE_INITIATOR); | ||
4138 | ahd_set_syncrate(ahd, &devinfo, 0, 0, 0, | ||
4139 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
4140 | ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT, | ||
4141 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
4142 | ahd_update_neg_request(ahd, &devinfo, tstate, tinfo, AHD_NEG_ALWAYS); | ||
4143 | ahd->platform_data->targets[target_offset] = NULL; | ||
4144 | if (targ->inq_data != NULL) | ||
4145 | free(targ->inq_data, M_DEVBUF); | ||
4146 | if (targ->dv_buffer != NULL) | ||
4147 | free(targ->dv_buffer, M_DEVBUF); | ||
4148 | if (targ->dv_buffer1 != NULL) | ||
4149 | free(targ->dv_buffer1, M_DEVBUF); | ||
4150 | free(targ, M_DEVBUF); | ||
4151 | } | ||
4152 | |||
4153 | static struct ahd_linux_device* | ||
4154 | ahd_linux_alloc_device(struct ahd_softc *ahd, | ||
4155 | struct ahd_linux_target *targ, u_int lun) | ||
4156 | { | ||
4157 | struct ahd_linux_device *dev; | ||
4158 | |||
4159 | dev = malloc(sizeof(*dev), M_DEVBUG, M_NOWAIT); | ||
4160 | if (dev == NULL) | ||
4161 | return (NULL); | ||
4162 | memset(dev, 0, sizeof(*dev)); | ||
4163 | init_timer(&dev->timer); | ||
4164 | TAILQ_INIT(&dev->busyq); | ||
4165 | dev->flags = AHD_DEV_UNCONFIGURED; | ||
4166 | dev->lun = lun; | ||
4167 | dev->target = targ; | ||
4168 | |||
4169 | /* | ||
4170 | * We start out life using untagged | ||
4171 | * transactions of which we allow one. | ||
4172 | */ | ||
4173 | dev->openings = 1; | ||
4174 | |||
4175 | /* | ||
4176 | * Set maxtags to 0. This will be changed if we | ||
4177 | * later determine that we are dealing with | ||
4178 | * a tagged queuing capable device. | ||
4179 | */ | ||
4180 | dev->maxtags = 0; | ||
4181 | |||
4182 | targ->refcount++; | ||
4183 | targ->devices[lun] = dev; | ||
4184 | return (dev); | ||
4185 | } | ||
4186 | |||
4187 | static void | ||
4188 | ahd_linux_free_device(struct ahd_softc *ahd, struct ahd_linux_device *dev) | ||
4189 | { | ||
4190 | struct ahd_linux_target *targ; | ||
4191 | |||
4192 | del_timer(&dev->timer); | ||
4193 | targ = dev->target; | ||
4194 | targ->devices[dev->lun] = NULL; | ||
4195 | free(dev, M_DEVBUF); | ||
4196 | targ->refcount--; | ||
4197 | if (targ->refcount == 0 | ||
4198 | && (targ->flags & AHD_DV_REQUIRED) == 0) | ||
4199 | ahd_linux_free_target(ahd, targ); | ||
4200 | } | 1574 | } |
4201 | 1575 | ||
4202 | void | 1576 | void |
@@ -4207,10 +1581,14 @@ ahd_send_async(struct ahd_softc *ahd, char channel, | |||
4207 | case AC_TRANSFER_NEG: | 1581 | case AC_TRANSFER_NEG: |
4208 | { | 1582 | { |
4209 | char buf[80]; | 1583 | char buf[80]; |
1584 | struct scsi_target *starget; | ||
4210 | struct ahd_linux_target *targ; | 1585 | struct ahd_linux_target *targ; |
4211 | struct info_str info; | 1586 | struct info_str info; |
4212 | struct ahd_initiator_tinfo *tinfo; | 1587 | struct ahd_initiator_tinfo *tinfo; |
4213 | struct ahd_tmode_tstate *tstate; | 1588 | struct ahd_tmode_tstate *tstate; |
1589 | unsigned int target_ppr_options; | ||
1590 | |||
1591 | BUG_ON(target == CAM_TARGET_WILDCARD); | ||
4214 | 1592 | ||
4215 | info.buffer = buf; | 1593 | info.buffer = buf; |
4216 | info.length = sizeof(buf); | 1594 | info.length = sizeof(buf); |
@@ -4234,58 +1612,47 @@ ahd_send_async(struct ahd_softc *ahd, char channel, | |||
4234 | * Don't bother reporting results that | 1612 | * Don't bother reporting results that |
4235 | * are identical to those last reported. | 1613 | * are identical to those last reported. |
4236 | */ | 1614 | */ |
4237 | targ = ahd->platform_data->targets[target]; | 1615 | starget = ahd->platform_data->starget[target]; |
4238 | if (targ == NULL) | 1616 | if (starget == NULL) |
4239 | break; | 1617 | break; |
4240 | if (tinfo->curr.period == targ->last_tinfo.period | 1618 | targ = scsi_transport_target_data(starget); |
4241 | && tinfo->curr.width == targ->last_tinfo.width | 1619 | |
4242 | && tinfo->curr.offset == targ->last_tinfo.offset | 1620 | target_ppr_options = |
4243 | && tinfo->curr.ppr_options == targ->last_tinfo.ppr_options) | 1621 | (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0) |
1622 | + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0) | ||
1623 | + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0) | ||
1624 | + (spi_rd_strm(starget) ? MSG_EXT_PPR_RD_STRM : 0) | ||
1625 | + (spi_pcomp_en(starget) ? MSG_EXT_PPR_PCOMP_EN : 0) | ||
1626 | + (spi_rti(starget) ? MSG_EXT_PPR_RTI : 0) | ||
1627 | + (spi_wr_flow(starget) ? MSG_EXT_PPR_WR_FLOW : 0) | ||
1628 | + (spi_hold_mcs(starget) ? MSG_EXT_PPR_HOLD_MCS : 0); | ||
1629 | |||
1630 | if (tinfo->curr.period == spi_period(starget) | ||
1631 | && tinfo->curr.width == spi_width(starget) | ||
1632 | && tinfo->curr.offset == spi_offset(starget) | ||
1633 | && tinfo->curr.ppr_options == target_ppr_options) | ||
4244 | if (bootverbose == 0) | 1634 | if (bootverbose == 0) |
4245 | break; | 1635 | break; |
4246 | 1636 | ||
4247 | targ->last_tinfo.period = tinfo->curr.period; | 1637 | spi_period(starget) = tinfo->curr.period; |
4248 | targ->last_tinfo.width = tinfo->curr.width; | 1638 | spi_width(starget) = tinfo->curr.width; |
4249 | targ->last_tinfo.offset = tinfo->curr.offset; | 1639 | spi_offset(starget) = tinfo->curr.offset; |
4250 | targ->last_tinfo.ppr_options = tinfo->curr.ppr_options; | 1640 | spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0; |
4251 | 1641 | spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0; | |
4252 | printf("(%s:%c:", ahd_name(ahd), channel); | 1642 | spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0; |
4253 | if (target == CAM_TARGET_WILDCARD) | 1643 | spi_rd_strm(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RD_STRM ? 1 : 0; |
4254 | printf("*): "); | 1644 | spi_pcomp_en(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_PCOMP_EN ? 1 : 0; |
4255 | else | 1645 | spi_rti(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RTI ? 1 : 0; |
4256 | printf("%d): ", target); | 1646 | spi_wr_flow(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_WR_FLOW ? 1 : 0; |
4257 | ahd_format_transinfo(&info, &tinfo->curr); | 1647 | spi_hold_mcs(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_HOLD_MCS ? 1 : 0; |
4258 | if (info.pos < info.length) | 1648 | spi_display_xfer_agreement(starget); |
4259 | *info.buffer = '\0'; | ||
4260 | else | ||
4261 | buf[info.length - 1] = '\0'; | ||
4262 | printf("%s", buf); | ||
4263 | break; | 1649 | break; |
4264 | } | 1650 | } |
4265 | case AC_SENT_BDR: | 1651 | case AC_SENT_BDR: |
4266 | { | 1652 | { |
4267 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | ||
4268 | WARN_ON(lun != CAM_LUN_WILDCARD); | 1653 | WARN_ON(lun != CAM_LUN_WILDCARD); |
4269 | scsi_report_device_reset(ahd->platform_data->host, | 1654 | scsi_report_device_reset(ahd->platform_data->host, |
4270 | channel - 'A', target); | 1655 | channel - 'A', target); |
4271 | #else | ||
4272 | Scsi_Device *scsi_dev; | ||
4273 | |||
4274 | /* | ||
4275 | * Find the SCSI device associated with this | ||
4276 | * request and indicate that a UA is expected. | ||
4277 | */ | ||
4278 | for (scsi_dev = ahd->platform_data->host->host_queue; | ||
4279 | scsi_dev != NULL; scsi_dev = scsi_dev->next) { | ||
4280 | if (channel - 'A' == scsi_dev->channel | ||
4281 | && target == scsi_dev->id | ||
4282 | && (lun == CAM_LUN_WILDCARD | ||
4283 | || lun == scsi_dev->lun)) { | ||
4284 | scsi_dev->was_reset = 1; | ||
4285 | scsi_dev->expecting_cc_ua = 1; | ||
4286 | } | ||
4287 | } | ||
4288 | #endif | ||
4289 | break; | 1656 | break; |
4290 | } | 1657 | } |
4291 | case AC_BUS_RESET: | 1658 | case AC_BUS_RESET: |
@@ -4305,7 +1672,7 @@ ahd_send_async(struct ahd_softc *ahd, char channel, | |||
4305 | void | 1672 | void |
4306 | ahd_done(struct ahd_softc *ahd, struct scb *scb) | 1673 | ahd_done(struct ahd_softc *ahd, struct scb *scb) |
4307 | { | 1674 | { |
4308 | Scsi_Cmnd *cmd; | 1675 | struct scsi_cmnd *cmd; |
4309 | struct ahd_linux_device *dev; | 1676 | struct ahd_linux_device *dev; |
4310 | 1677 | ||
4311 | if ((scb->flags & SCB_ACTIVE) == 0) { | 1678 | if ((scb->flags & SCB_ACTIVE) == 0) { |
@@ -4373,19 +1740,8 @@ ahd_done(struct ahd_softc *ahd, struct scb *scb) | |||
4373 | ahd_set_transaction_status(scb, CAM_REQ_CMP); | 1740 | ahd_set_transaction_status(scb, CAM_REQ_CMP); |
4374 | } | 1741 | } |
4375 | } else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) { | 1742 | } else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) { |
4376 | ahd_linux_handle_scsi_status(ahd, dev, scb); | 1743 | ahd_linux_handle_scsi_status(ahd, cmd->device, scb); |
4377 | } else if (ahd_get_transaction_status(scb) == CAM_SEL_TIMEOUT) { | ||
4378 | dev->flags |= AHD_DEV_UNCONFIGURED; | ||
4379 | if (AHD_DV_CMD(cmd) == FALSE) | ||
4380 | dev->target->flags &= ~AHD_DV_REQUIRED; | ||
4381 | } | 1744 | } |
4382 | /* | ||
4383 | * Start DV for devices that require it assuming the first command | ||
4384 | * sent does not result in a selection timeout. | ||
4385 | */ | ||
4386 | if (ahd_get_transaction_status(scb) != CAM_SEL_TIMEOUT | ||
4387 | && (dev->target->flags & AHD_DV_REQUIRED) != 0) | ||
4388 | ahd_linux_start_dv(ahd); | ||
4389 | 1745 | ||
4390 | if (dev->openings == 1 | 1746 | if (dev->openings == 1 |
4391 | && ahd_get_transaction_status(scb) == CAM_REQ_CMP | 1747 | && ahd_get_transaction_status(scb) == CAM_REQ_CMP |
@@ -4406,47 +1762,32 @@ ahd_done(struct ahd_softc *ahd, struct scb *scb) | |||
4406 | if (dev->active == 0) | 1762 | if (dev->active == 0) |
4407 | dev->commands_since_idle_or_otag = 0; | 1763 | dev->commands_since_idle_or_otag = 0; |
4408 | 1764 | ||
4409 | if (TAILQ_EMPTY(&dev->busyq)) { | ||
4410 | if ((dev->flags & AHD_DEV_UNCONFIGURED) != 0 | ||
4411 | && dev->active == 0 | ||
4412 | && (dev->flags & AHD_DEV_TIMER_ACTIVE) == 0) | ||
4413 | ahd_linux_free_device(ahd, dev); | ||
4414 | } else if ((dev->flags & AHD_DEV_ON_RUN_LIST) == 0) { | ||
4415 | TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, dev, links); | ||
4416 | dev->flags |= AHD_DEV_ON_RUN_LIST; | ||
4417 | } | ||
4418 | |||
4419 | if ((scb->flags & SCB_RECOVERY_SCB) != 0) { | 1765 | if ((scb->flags & SCB_RECOVERY_SCB) != 0) { |
4420 | printf("Recovery SCB completes\n"); | 1766 | printf("Recovery SCB completes\n"); |
4421 | if (ahd_get_transaction_status(scb) == CAM_BDR_SENT | 1767 | if (ahd_get_transaction_status(scb) == CAM_BDR_SENT |
4422 | || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED) | 1768 | || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED) |
4423 | ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT); | 1769 | ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT); |
4424 | if ((scb->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) { | 1770 | if ((ahd->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) { |
4425 | scb->platform_data->flags &= ~AHD_SCB_UP_EH_SEM; | 1771 | ahd->platform_data->flags &= ~AHD_SCB_UP_EH_SEM; |
4426 | up(&ahd->platform_data->eh_sem); | 1772 | up(&ahd->platform_data->eh_sem); |
4427 | } | 1773 | } |
4428 | } | 1774 | } |
4429 | 1775 | ||
4430 | ahd_free_scb(ahd, scb); | 1776 | ahd_free_scb(ahd, scb); |
4431 | ahd_linux_queue_cmd_complete(ahd, cmd); | 1777 | ahd_linux_queue_cmd_complete(ahd, cmd); |
4432 | |||
4433 | if ((ahd->platform_data->flags & AHD_DV_WAIT_SIMQ_EMPTY) != 0 | ||
4434 | && LIST_FIRST(&ahd->pending_scbs) == NULL) { | ||
4435 | ahd->platform_data->flags &= ~AHD_DV_WAIT_SIMQ_EMPTY; | ||
4436 | up(&ahd->platform_data->dv_sem); | ||
4437 | } | ||
4438 | } | 1778 | } |
4439 | 1779 | ||
4440 | static void | 1780 | static void |
4441 | ahd_linux_handle_scsi_status(struct ahd_softc *ahd, | 1781 | ahd_linux_handle_scsi_status(struct ahd_softc *ahd, |
4442 | struct ahd_linux_device *dev, struct scb *scb) | 1782 | struct scsi_device *sdev, struct scb *scb) |
4443 | { | 1783 | { |
4444 | struct ahd_devinfo devinfo; | 1784 | struct ahd_devinfo devinfo; |
1785 | struct ahd_linux_device *dev = scsi_transport_device_data(sdev); | ||
4445 | 1786 | ||
4446 | ahd_compile_devinfo(&devinfo, | 1787 | ahd_compile_devinfo(&devinfo, |
4447 | ahd->our_id, | 1788 | ahd->our_id, |
4448 | dev->target->target, dev->lun, | 1789 | sdev->sdev_target->id, sdev->lun, |
4449 | dev->target->channel == 0 ? 'A' : 'B', | 1790 | sdev->sdev_target->channel == 0 ? 'A' : 'B', |
4450 | ROLE_INITIATOR); | 1791 | ROLE_INITIATOR); |
4451 | 1792 | ||
4452 | /* | 1793 | /* |
@@ -4465,7 +1806,7 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd, | |||
4465 | case SCSI_STATUS_CHECK_COND: | 1806 | case SCSI_STATUS_CHECK_COND: |
4466 | case SCSI_STATUS_CMD_TERMINATED: | 1807 | case SCSI_STATUS_CMD_TERMINATED: |
4467 | { | 1808 | { |
4468 | Scsi_Cmnd *cmd; | 1809 | struct scsi_cmnd *cmd; |
4469 | 1810 | ||
4470 | /* | 1811 | /* |
4471 | * Copy sense information to the OS's cmd | 1812 | * Copy sense information to the OS's cmd |
@@ -4518,7 +1859,6 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd, | |||
4518 | break; | 1859 | break; |
4519 | } | 1860 | } |
4520 | case SCSI_STATUS_QUEUE_FULL: | 1861 | case SCSI_STATUS_QUEUE_FULL: |
4521 | { | ||
4522 | /* | 1862 | /* |
4523 | * By the time the core driver has returned this | 1863 | * By the time the core driver has returned this |
4524 | * command, all other commands that were queued | 1864 | * command, all other commands that were queued |
@@ -4579,98 +1919,23 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd, | |||
4579 | (dev->flags & AHD_DEV_Q_BASIC) | 1919 | (dev->flags & AHD_DEV_Q_BASIC) |
4580 | ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED); | 1920 | ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED); |
4581 | ahd_set_scsi_status(scb, SCSI_STATUS_BUSY); | 1921 | ahd_set_scsi_status(scb, SCSI_STATUS_BUSY); |
4582 | /* FALLTHROUGH */ | ||
4583 | } | ||
4584 | case SCSI_STATUS_BUSY: | ||
4585 | /* | ||
4586 | * Set a short timer to defer sending commands for | ||
4587 | * a bit since Linux will not delay in this case. | ||
4588 | */ | ||
4589 | if ((dev->flags & AHD_DEV_TIMER_ACTIVE) != 0) { | ||
4590 | printf("%s:%c:%d: Device Timer still active during " | ||
4591 | "busy processing\n", ahd_name(ahd), | ||
4592 | dev->target->channel, dev->target->target); | ||
4593 | break; | ||
4594 | } | ||
4595 | dev->flags |= AHD_DEV_TIMER_ACTIVE; | ||
4596 | dev->qfrozen++; | ||
4597 | init_timer(&dev->timer); | ||
4598 | dev->timer.data = (u_long)dev; | ||
4599 | dev->timer.expires = jiffies + (HZ/2); | ||
4600 | dev->timer.function = ahd_linux_dev_timed_unfreeze; | ||
4601 | add_timer(&dev->timer); | ||
4602 | break; | ||
4603 | } | 1922 | } |
4604 | } | 1923 | } |
4605 | 1924 | ||
4606 | static void | 1925 | static void |
4607 | ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, Scsi_Cmnd *cmd) | 1926 | ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd) |
4608 | { | 1927 | { |
4609 | /* | 1928 | /* |
4610 | * Typically, the complete queue has very few entries | ||
4611 | * queued to it before the queue is emptied by | ||
4612 | * ahd_linux_run_complete_queue, so sorting the entries | ||
4613 | * by generation number should be inexpensive. | ||
4614 | * We perform the sort so that commands that complete | ||
4615 | * with an error are retuned in the order origionally | ||
4616 | * queued to the controller so that any subsequent retries | ||
4617 | * are performed in order. The underlying ahd routines do | ||
4618 | * not guarantee the order that aborted commands will be | ||
4619 | * returned to us. | ||
4620 | */ | ||
4621 | struct ahd_completeq *completeq; | ||
4622 | struct ahd_cmd *list_cmd; | ||
4623 | struct ahd_cmd *acmd; | ||
4624 | |||
4625 | /* | ||
4626 | * Map CAM error codes into Linux Error codes. We | 1929 | * Map CAM error codes into Linux Error codes. We |
4627 | * avoid the conversion so that the DV code has the | 1930 | * avoid the conversion so that the DV code has the |
4628 | * full error information available when making | 1931 | * full error information available when making |
4629 | * state change decisions. | 1932 | * state change decisions. |
4630 | */ | 1933 | */ |
4631 | if (AHD_DV_CMD(cmd) == FALSE) { | 1934 | { |
4632 | uint32_t status; | 1935 | uint32_t status; |
4633 | u_int new_status; | 1936 | u_int new_status; |
4634 | 1937 | ||
4635 | status = ahd_cmd_get_transaction_status(cmd); | 1938 | status = ahd_cmd_get_transaction_status(cmd); |
4636 | if (status != CAM_REQ_CMP) { | ||
4637 | struct ahd_linux_device *dev; | ||
4638 | struct ahd_devinfo devinfo; | ||
4639 | cam_status cam_status; | ||
4640 | uint32_t action; | ||
4641 | u_int scsi_status; | ||
4642 | |||
4643 | dev = ahd_linux_get_device(ahd, cmd->device->channel, | ||
4644 | cmd->device->id, | ||
4645 | cmd->device->lun, | ||
4646 | /*alloc*/FALSE); | ||
4647 | |||
4648 | if (dev == NULL) | ||
4649 | goto no_fallback; | ||
4650 | |||
4651 | ahd_compile_devinfo(&devinfo, | ||
4652 | ahd->our_id, | ||
4653 | dev->target->target, dev->lun, | ||
4654 | dev->target->channel == 0 ? 'A':'B', | ||
4655 | ROLE_INITIATOR); | ||
4656 | |||
4657 | scsi_status = ahd_cmd_get_scsi_status(cmd); | ||
4658 | cam_status = ahd_cmd_get_transaction_status(cmd); | ||
4659 | action = aic_error_action(cmd, dev->target->inq_data, | ||
4660 | cam_status, scsi_status); | ||
4661 | if ((action & SSQ_FALLBACK) != 0) { | ||
4662 | |||
4663 | /* Update stats */ | ||
4664 | dev->target->errors_detected++; | ||
4665 | if (dev->target->cmds_since_error == 0) | ||
4666 | dev->target->cmds_since_error++; | ||
4667 | else { | ||
4668 | dev->target->cmds_since_error = 0; | ||
4669 | ahd_linux_fallback(ahd, &devinfo); | ||
4670 | } | ||
4671 | } | ||
4672 | } | ||
4673 | no_fallback: | ||
4674 | switch (status) { | 1939 | switch (status) { |
4675 | case CAM_REQ_INPROG: | 1940 | case CAM_REQ_INPROG: |
4676 | case CAM_REQ_CMP: | 1941 | case CAM_REQ_CMP: |
@@ -4715,26 +1980,7 @@ no_fallback: | |||
4715 | new_status = DID_ERROR; | 1980 | new_status = DID_ERROR; |
4716 | break; | 1981 | break; |
4717 | case CAM_REQUEUE_REQ: | 1982 | case CAM_REQUEUE_REQ: |
4718 | /* | 1983 | new_status = DID_REQUEUE; |
4719 | * If we want the request requeued, make sure there | ||
4720 | * are sufficent retries. In the old scsi error code, | ||
4721 | * we used to be able to specify a result code that | ||
4722 | * bypassed the retry count. Now we must use this | ||
4723 | * hack. We also "fake" a check condition with | ||
4724 | * a sense code of ABORTED COMMAND. This seems to | ||
4725 | * evoke a retry even if this command is being sent | ||
4726 | * via the eh thread. Ick! Ick! Ick! | ||
4727 | */ | ||
4728 | if (cmd->retries > 0) | ||
4729 | cmd->retries--; | ||
4730 | new_status = DID_OK; | ||
4731 | ahd_cmd_set_scsi_status(cmd, SCSI_STATUS_CHECK_COND); | ||
4732 | cmd->result |= (DRIVER_SENSE << 24); | ||
4733 | memset(cmd->sense_buffer, 0, | ||
4734 | sizeof(cmd->sense_buffer)); | ||
4735 | cmd->sense_buffer[0] = SSD_ERRCODE_VALID | ||
4736 | | SSD_CURRENT_ERROR; | ||
4737 | cmd->sense_buffer[2] = SSD_KEY_ABORTED_COMMAND; | ||
4738 | break; | 1984 | break; |
4739 | default: | 1985 | default: |
4740 | /* We should never get here */ | 1986 | /* We should never get here */ |
@@ -4745,116 +1991,23 @@ no_fallback: | |||
4745 | ahd_cmd_set_transaction_status(cmd, new_status); | 1991 | ahd_cmd_set_transaction_status(cmd, new_status); |
4746 | } | 1992 | } |
4747 | 1993 | ||
4748 | completeq = &ahd->platform_data->completeq; | 1994 | cmd->scsi_done(cmd); |
4749 | list_cmd = TAILQ_FIRST(completeq); | ||
4750 | acmd = (struct ahd_cmd *)cmd; | ||
4751 | while (list_cmd != NULL | ||
4752 | && acmd_scsi_cmd(list_cmd).serial_number | ||
4753 | < acmd_scsi_cmd(acmd).serial_number) | ||
4754 | list_cmd = TAILQ_NEXT(list_cmd, acmd_links.tqe); | ||
4755 | if (list_cmd != NULL) | ||
4756 | TAILQ_INSERT_BEFORE(list_cmd, acmd, acmd_links.tqe); | ||
4757 | else | ||
4758 | TAILQ_INSERT_TAIL(completeq, acmd, acmd_links.tqe); | ||
4759 | } | 1995 | } |
4760 | 1996 | ||
4761 | static void | 1997 | static void |
4762 | ahd_linux_filter_inquiry(struct ahd_softc *ahd, struct ahd_devinfo *devinfo) | 1998 | ahd_linux_sem_timeout(u_long arg) |
4763 | { | 1999 | { |
4764 | struct scsi_inquiry_data *sid; | 2000 | struct ahd_softc *ahd; |
4765 | struct ahd_initiator_tinfo *tinfo; | 2001 | u_long s; |
4766 | struct ahd_transinfo *user; | ||
4767 | struct ahd_transinfo *goal; | ||
4768 | struct ahd_transinfo *curr; | ||
4769 | struct ahd_tmode_tstate *tstate; | ||
4770 | struct ahd_linux_device *dev; | ||
4771 | u_int width; | ||
4772 | u_int period; | ||
4773 | u_int offset; | ||
4774 | u_int ppr_options; | ||
4775 | u_int trans_version; | ||
4776 | u_int prot_version; | ||
4777 | |||
4778 | /* | ||
4779 | * Determine if this lun actually exists. If so, | ||
4780 | * hold on to its corresponding device structure. | ||
4781 | * If not, make sure we release the device and | ||
4782 | * don't bother processing the rest of this inquiry | ||
4783 | * command. | ||
4784 | */ | ||
4785 | dev = ahd_linux_get_device(ahd, devinfo->channel - 'A', | ||
4786 | devinfo->target, devinfo->lun, | ||
4787 | /*alloc*/TRUE); | ||
4788 | |||
4789 | sid = (struct scsi_inquiry_data *)dev->target->inq_data; | ||
4790 | if (SID_QUAL(sid) == SID_QUAL_LU_CONNECTED) { | ||
4791 | |||
4792 | dev->flags &= ~AHD_DEV_UNCONFIGURED; | ||
4793 | } else { | ||
4794 | dev->flags |= AHD_DEV_UNCONFIGURED; | ||
4795 | return; | ||
4796 | } | ||
4797 | 2002 | ||
4798 | /* | 2003 | ahd = (struct ahd_softc *)arg; |
4799 | * Update our notion of this device's transfer | ||
4800 | * negotiation capabilities. | ||
4801 | */ | ||
4802 | tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, | ||
4803 | devinfo->our_scsiid, | ||
4804 | devinfo->target, &tstate); | ||
4805 | user = &tinfo->user; | ||
4806 | goal = &tinfo->goal; | ||
4807 | curr = &tinfo->curr; | ||
4808 | width = user->width; | ||
4809 | period = user->period; | ||
4810 | offset = user->offset; | ||
4811 | ppr_options = user->ppr_options; | ||
4812 | trans_version = user->transport_version; | ||
4813 | prot_version = MIN(user->protocol_version, SID_ANSI_REV(sid)); | ||
4814 | 2004 | ||
4815 | /* | 2005 | ahd_lock(ahd, &s); |
4816 | * Only attempt SPI3/4 once we've verified that | 2006 | if ((ahd->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) { |
4817 | * the device claims to support SPI3/4 features. | 2007 | ahd->platform_data->flags &= ~AHD_SCB_UP_EH_SEM; |
4818 | */ | 2008 | up(&ahd->platform_data->eh_sem); |
4819 | if (prot_version < SCSI_REV_2) | ||
4820 | trans_version = SID_ANSI_REV(sid); | ||
4821 | else | ||
4822 | trans_version = SCSI_REV_2; | ||
4823 | |||
4824 | if ((sid->flags & SID_WBus16) == 0) | ||
4825 | width = MSG_EXT_WDTR_BUS_8_BIT; | ||
4826 | if ((sid->flags & SID_Sync) == 0) { | ||
4827 | period = 0; | ||
4828 | offset = 0; | ||
4829 | ppr_options = 0; | ||
4830 | } | ||
4831 | if ((sid->spi3data & SID_SPI_QAS) == 0) | ||
4832 | ppr_options &= ~MSG_EXT_PPR_QAS_REQ; | ||
4833 | if ((sid->spi3data & SID_SPI_CLOCK_DT) == 0) | ||
4834 | ppr_options &= MSG_EXT_PPR_QAS_REQ; | ||
4835 | if ((sid->spi3data & SID_SPI_IUS) == 0) | ||
4836 | ppr_options &= (MSG_EXT_PPR_DT_REQ | ||
4837 | | MSG_EXT_PPR_QAS_REQ); | ||
4838 | |||
4839 | if (prot_version > SCSI_REV_2 | ||
4840 | && ppr_options != 0) | ||
4841 | trans_version = user->transport_version; | ||
4842 | |||
4843 | ahd_validate_width(ahd, /*tinfo limit*/NULL, &width, ROLE_UNKNOWN); | ||
4844 | ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_MAX); | ||
4845 | ahd_validate_offset(ahd, /*tinfo limit*/NULL, period, | ||
4846 | &offset, width, ROLE_UNKNOWN); | ||
4847 | if (offset == 0 || period == 0) { | ||
4848 | period = 0; | ||
4849 | offset = 0; | ||
4850 | ppr_options = 0; | ||
4851 | } | 2009 | } |
4852 | /* Apply our filtered user settings. */ | 2010 | ahd_unlock(ahd, &s); |
4853 | curr->transport_version = trans_version; | ||
4854 | curr->protocol_version = prot_version; | ||
4855 | ahd_set_width(ahd, devinfo, width, AHD_TRANS_GOAL, /*paused*/FALSE); | ||
4856 | ahd_set_syncrate(ahd, devinfo, period, offset, ppr_options, | ||
4857 | AHD_TRANS_GOAL, /*paused*/FALSE); | ||
4858 | } | 2011 | } |
4859 | 2012 | ||
4860 | void | 2013 | void |
@@ -4882,12 +2035,6 @@ ahd_release_simq(struct ahd_softc *ahd) | |||
4882 | if (ahd->platform_data->qfrozen == 0) { | 2035 | if (ahd->platform_data->qfrozen == 0) { |
4883 | unblock_reqs = 1; | 2036 | unblock_reqs = 1; |
4884 | } | 2037 | } |
4885 | if (AHD_DV_SIMQ_FROZEN(ahd) | ||
4886 | && ((ahd->platform_data->flags & AHD_DV_WAIT_SIMQ_RELEASE) != 0)) { | ||
4887 | ahd->platform_data->flags &= ~AHD_DV_WAIT_SIMQ_RELEASE; | ||
4888 | up(&ahd->platform_data->dv_sem); | ||
4889 | } | ||
4890 | ahd_schedule_runq(ahd); | ||
4891 | ahd_unlock(ahd, &s); | 2038 | ahd_unlock(ahd, &s); |
4892 | /* | 2039 | /* |
4893 | * There is still a race here. The mid-layer | 2040 | * There is still a race here. The mid-layer |
@@ -4899,118 +2046,743 @@ ahd_release_simq(struct ahd_softc *ahd) | |||
4899 | scsi_unblock_requests(ahd->platform_data->host); | 2046 | scsi_unblock_requests(ahd->platform_data->host); |
4900 | } | 2047 | } |
4901 | 2048 | ||
4902 | static void | 2049 | static int |
4903 | ahd_linux_sem_timeout(u_long arg) | 2050 | ahd_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag) |
4904 | { | 2051 | { |
4905 | struct scb *scb; | 2052 | struct ahd_softc *ahd; |
4906 | struct ahd_softc *ahd; | 2053 | struct ahd_linux_device *dev; |
4907 | u_long s; | 2054 | struct scb *pending_scb; |
2055 | u_int saved_scbptr; | ||
2056 | u_int active_scbptr; | ||
2057 | u_int last_phase; | ||
2058 | u_int saved_scsiid; | ||
2059 | u_int cdb_byte; | ||
2060 | int retval; | ||
2061 | int was_paused; | ||
2062 | int paused; | ||
2063 | int wait; | ||
2064 | int disconnected; | ||
2065 | ahd_mode_state saved_modes; | ||
4908 | 2066 | ||
4909 | scb = (struct scb *)arg; | 2067 | pending_scb = NULL; |
4910 | ahd = scb->ahd_softc; | 2068 | paused = FALSE; |
4911 | ahd_lock(ahd, &s); | 2069 | wait = FALSE; |
4912 | if ((scb->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) { | 2070 | ahd = *(struct ahd_softc **)cmd->device->host->hostdata; |
4913 | scb->platform_data->flags &= ~AHD_SCB_UP_EH_SEM; | 2071 | |
4914 | up(&ahd->platform_data->eh_sem); | 2072 | printf("%s:%d:%d:%d: Attempting to queue a%s message:", |
2073 | ahd_name(ahd), cmd->device->channel, | ||
2074 | cmd->device->id, cmd->device->lun, | ||
2075 | flag == SCB_ABORT ? "n ABORT" : " TARGET RESET"); | ||
2076 | |||
2077 | printf("CDB:"); | ||
2078 | for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++) | ||
2079 | printf(" 0x%x", cmd->cmnd[cdb_byte]); | ||
2080 | printf("\n"); | ||
2081 | |||
2082 | spin_lock_irq(&ahd->platform_data->spin_lock); | ||
2083 | |||
2084 | /* | ||
2085 | * First determine if we currently own this command. | ||
2086 | * Start by searching the device queue. If not found | ||
2087 | * there, check the pending_scb list. If not found | ||
2088 | * at all, and the system wanted us to just abort the | ||
2089 | * command, return success. | ||
2090 | */ | ||
2091 | dev = scsi_transport_device_data(cmd->device); | ||
2092 | |||
2093 | if (dev == NULL) { | ||
2094 | /* | ||
2095 | * No target device for this command exists, | ||
2096 | * so we must not still own the command. | ||
2097 | */ | ||
2098 | printf("%s:%d:%d:%d: Is not an active device\n", | ||
2099 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
2100 | cmd->device->lun); | ||
2101 | retval = SUCCESS; | ||
2102 | goto no_cmd; | ||
4915 | } | 2103 | } |
4916 | ahd_unlock(ahd, &s); | 2104 | |
2105 | /* | ||
2106 | * See if we can find a matching cmd in the pending list. | ||
2107 | */ | ||
2108 | LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) { | ||
2109 | if (pending_scb->io_ctx == cmd) | ||
2110 | break; | ||
2111 | } | ||
2112 | |||
2113 | if (pending_scb == NULL && flag == SCB_DEVICE_RESET) { | ||
2114 | |||
2115 | /* Any SCB for this device will do for a target reset */ | ||
2116 | LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) { | ||
2117 | if (ahd_match_scb(ahd, pending_scb, cmd->device->id, | ||
2118 | cmd->device->channel + 'A', | ||
2119 | CAM_LUN_WILDCARD, | ||
2120 | SCB_LIST_NULL, ROLE_INITIATOR) == 0) | ||
2121 | break; | ||
2122 | } | ||
2123 | } | ||
2124 | |||
2125 | if (pending_scb == NULL) { | ||
2126 | printf("%s:%d:%d:%d: Command not found\n", | ||
2127 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
2128 | cmd->device->lun); | ||
2129 | goto no_cmd; | ||
2130 | } | ||
2131 | |||
2132 | if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) { | ||
2133 | /* | ||
2134 | * We can't queue two recovery actions using the same SCB | ||
2135 | */ | ||
2136 | retval = FAILED; | ||
2137 | goto done; | ||
2138 | } | ||
2139 | |||
2140 | /* | ||
2141 | * Ensure that the card doesn't do anything | ||
2142 | * behind our back. Also make sure that we | ||
2143 | * didn't "just" miss an interrupt that would | ||
2144 | * affect this cmd. | ||
2145 | */ | ||
2146 | was_paused = ahd_is_paused(ahd); | ||
2147 | ahd_pause_and_flushwork(ahd); | ||
2148 | paused = TRUE; | ||
2149 | |||
2150 | if ((pending_scb->flags & SCB_ACTIVE) == 0) { | ||
2151 | printf("%s:%d:%d:%d: Command already completed\n", | ||
2152 | ahd_name(ahd), cmd->device->channel, cmd->device->id, | ||
2153 | cmd->device->lun); | ||
2154 | goto no_cmd; | ||
2155 | } | ||
2156 | |||
2157 | printf("%s: At time of recovery, card was %spaused\n", | ||
2158 | ahd_name(ahd), was_paused ? "" : "not "); | ||
2159 | ahd_dump_card_state(ahd); | ||
2160 | |||
2161 | disconnected = TRUE; | ||
2162 | if (flag == SCB_ABORT) { | ||
2163 | if (ahd_search_qinfifo(ahd, cmd->device->id, | ||
2164 | cmd->device->channel + 'A', | ||
2165 | cmd->device->lun, | ||
2166 | pending_scb->hscb->tag, | ||
2167 | ROLE_INITIATOR, CAM_REQ_ABORTED, | ||
2168 | SEARCH_COMPLETE) > 0) { | ||
2169 | printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n", | ||
2170 | ahd_name(ahd), cmd->device->channel, | ||
2171 | cmd->device->id, cmd->device->lun); | ||
2172 | retval = SUCCESS; | ||
2173 | goto done; | ||
2174 | } | ||
2175 | } else if (ahd_search_qinfifo(ahd, cmd->device->id, | ||
2176 | cmd->device->channel + 'A', | ||
2177 | cmd->device->lun, pending_scb->hscb->tag, | ||
2178 | ROLE_INITIATOR, /*status*/0, | ||
2179 | SEARCH_COUNT) > 0) { | ||
2180 | disconnected = FALSE; | ||
2181 | } | ||
2182 | |||
2183 | saved_modes = ahd_save_modes(ahd); | ||
2184 | ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI); | ||
2185 | last_phase = ahd_inb(ahd, LASTPHASE); | ||
2186 | saved_scbptr = ahd_get_scbptr(ahd); | ||
2187 | active_scbptr = saved_scbptr; | ||
2188 | if (disconnected && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) { | ||
2189 | struct scb *bus_scb; | ||
2190 | |||
2191 | bus_scb = ahd_lookup_scb(ahd, active_scbptr); | ||
2192 | if (bus_scb == pending_scb) | ||
2193 | disconnected = FALSE; | ||
2194 | else if (flag != SCB_ABORT | ||
2195 | && ahd_inb(ahd, SAVED_SCSIID) == pending_scb->hscb->scsiid | ||
2196 | && ahd_inb(ahd, SAVED_LUN) == SCB_GET_LUN(pending_scb)) | ||
2197 | disconnected = FALSE; | ||
2198 | } | ||
2199 | |||
2200 | /* | ||
2201 | * At this point, pending_scb is the scb associated with the | ||
2202 | * passed in command. That command is currently active on the | ||
2203 | * bus or is in the disconnected state. | ||
2204 | */ | ||
2205 | saved_scsiid = ahd_inb(ahd, SAVED_SCSIID); | ||
2206 | if (last_phase != P_BUSFREE | ||
2207 | && (SCB_GET_TAG(pending_scb) == active_scbptr | ||
2208 | || (flag == SCB_DEVICE_RESET | ||
2209 | && SCSIID_TARGET(ahd, saved_scsiid) == cmd->device->id))) { | ||
2210 | |||
2211 | /* | ||
2212 | * We're active on the bus, so assert ATN | ||
2213 | * and hope that the target responds. | ||
2214 | */ | ||
2215 | pending_scb = ahd_lookup_scb(ahd, active_scbptr); | ||
2216 | pending_scb->flags |= SCB_RECOVERY_SCB|flag; | ||
2217 | ahd_outb(ahd, MSG_OUT, HOST_MSG); | ||
2218 | ahd_outb(ahd, SCSISIGO, last_phase|ATNO); | ||
2219 | printf("%s:%d:%d:%d: Device is active, asserting ATN\n", | ||
2220 | ahd_name(ahd), cmd->device->channel, | ||
2221 | cmd->device->id, cmd->device->lun); | ||
2222 | wait = TRUE; | ||
2223 | } else if (disconnected) { | ||
2224 | |||
2225 | /* | ||
2226 | * Actually re-queue this SCB in an attempt | ||
2227 | * to select the device before it reconnects. | ||
2228 | */ | ||
2229 | pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT; | ||
2230 | ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb)); | ||
2231 | pending_scb->hscb->cdb_len = 0; | ||
2232 | pending_scb->hscb->task_attribute = 0; | ||
2233 | pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK; | ||
2234 | |||
2235 | if ((pending_scb->flags & SCB_PACKETIZED) != 0) { | ||
2236 | /* | ||
2237 | * Mark the SCB has having an outstanding | ||
2238 | * task management function. Should the command | ||
2239 | * complete normally before the task management | ||
2240 | * function can be sent, the host will be notified | ||
2241 | * to abort our requeued SCB. | ||
2242 | */ | ||
2243 | ahd_outb(ahd, SCB_TASK_MANAGEMENT, | ||
2244 | pending_scb->hscb->task_management); | ||
2245 | } else { | ||
2246 | /* | ||
2247 | * If non-packetized, set the MK_MESSAGE control | ||
2248 | * bit indicating that we desire to send a message. | ||
2249 | * We also set the disconnected flag since there is | ||
2250 | * no guarantee that our SCB control byte matches | ||
2251 | * the version on the card. We don't want the | ||
2252 | * sequencer to abort the command thinking an | ||
2253 | * unsolicited reselection occurred. | ||
2254 | */ | ||
2255 | pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED; | ||
2256 | |||
2257 | /* | ||
2258 | * The sequencer will never re-reference the | ||
2259 | * in-core SCB. To make sure we are notified | ||
2260 | * during reslection, set the MK_MESSAGE flag in | ||
2261 | * the card's copy of the SCB. | ||
2262 | */ | ||
2263 | ahd_outb(ahd, SCB_CONTROL, | ||
2264 | ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE); | ||
2265 | } | ||
2266 | |||
2267 | /* | ||
2268 | * Clear out any entries in the QINFIFO first | ||
2269 | * so we are the next SCB for this target | ||
2270 | * to run. | ||
2271 | */ | ||
2272 | ahd_search_qinfifo(ahd, cmd->device->id, | ||
2273 | cmd->device->channel + 'A', cmd->device->lun, | ||
2274 | SCB_LIST_NULL, ROLE_INITIATOR, | ||
2275 | CAM_REQUEUE_REQ, SEARCH_COMPLETE); | ||
2276 | ahd_qinfifo_requeue_tail(ahd, pending_scb); | ||
2277 | ahd_set_scbptr(ahd, saved_scbptr); | ||
2278 | ahd_print_path(ahd, pending_scb); | ||
2279 | printf("Device is disconnected, re-queuing SCB\n"); | ||
2280 | wait = TRUE; | ||
2281 | } else { | ||
2282 | printf("%s:%d:%d:%d: Unable to deliver message\n", | ||
2283 | ahd_name(ahd), cmd->device->channel, | ||
2284 | cmd->device->id, cmd->device->lun); | ||
2285 | retval = FAILED; | ||
2286 | goto done; | ||
2287 | } | ||
2288 | |||
2289 | no_cmd: | ||
2290 | /* | ||
2291 | * Our assumption is that if we don't have the command, no | ||
2292 | * recovery action was required, so we return success. Again, | ||
2293 | * the semantics of the mid-layer recovery engine are not | ||
2294 | * well defined, so this may change in time. | ||
2295 | */ | ||
2296 | retval = SUCCESS; | ||
2297 | done: | ||
2298 | if (paused) | ||
2299 | ahd_unpause(ahd); | ||
2300 | if (wait) { | ||
2301 | struct timer_list timer; | ||
2302 | int ret; | ||
2303 | |||
2304 | ahd->platform_data->flags |= AHD_SCB_UP_EH_SEM; | ||
2305 | spin_unlock_irq(&ahd->platform_data->spin_lock); | ||
2306 | init_timer(&timer); | ||
2307 | timer.data = (u_long)ahd; | ||
2308 | timer.expires = jiffies + (5 * HZ); | ||
2309 | timer.function = ahd_linux_sem_timeout; | ||
2310 | add_timer(&timer); | ||
2311 | printf("Recovery code sleeping\n"); | ||
2312 | down(&ahd->platform_data->eh_sem); | ||
2313 | printf("Recovery code awake\n"); | ||
2314 | ret = del_timer_sync(&timer); | ||
2315 | if (ret == 0) { | ||
2316 | printf("Timer Expired\n"); | ||
2317 | retval = FAILED; | ||
2318 | } | ||
2319 | spin_lock_irq(&ahd->platform_data->spin_lock); | ||
2320 | } | ||
2321 | spin_unlock_irq(&ahd->platform_data->spin_lock); | ||
2322 | return (retval); | ||
4917 | } | 2323 | } |
4918 | 2324 | ||
4919 | static void | 2325 | static void ahd_linux_set_width(struct scsi_target *starget, int width) |
4920 | ahd_linux_dev_timed_unfreeze(u_long arg) | ||
4921 | { | 2326 | { |
4922 | struct ahd_linux_device *dev; | 2327 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
4923 | struct ahd_softc *ahd; | 2328 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); |
4924 | u_long s; | 2329 | struct ahd_devinfo devinfo; |
2330 | unsigned long flags; | ||
4925 | 2331 | ||
4926 | dev = (struct ahd_linux_device *)arg; | 2332 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, |
4927 | ahd = dev->target->ahd; | 2333 | starget->channel + 'A', ROLE_INITIATOR); |
4928 | ahd_lock(ahd, &s); | 2334 | ahd_lock(ahd, &flags); |
4929 | dev->flags &= ~AHD_DEV_TIMER_ACTIVE; | 2335 | ahd_set_width(ahd, &devinfo, width, AHD_TRANS_GOAL, FALSE); |
4930 | if (dev->qfrozen > 0) | 2336 | ahd_unlock(ahd, &flags); |
4931 | dev->qfrozen--; | ||
4932 | if (dev->qfrozen == 0 | ||
4933 | && (dev->flags & AHD_DEV_ON_RUN_LIST) == 0) | ||
4934 | ahd_linux_run_device_queue(ahd, dev); | ||
4935 | if ((dev->flags & AHD_DEV_UNCONFIGURED) != 0 | ||
4936 | && dev->active == 0) | ||
4937 | ahd_linux_free_device(ahd, dev); | ||
4938 | ahd_unlock(ahd, &s); | ||
4939 | } | 2337 | } |
4940 | 2338 | ||
4941 | void | 2339 | static void ahd_linux_set_period(struct scsi_target *starget, int period) |
4942 | ahd_platform_dump_card_state(struct ahd_softc *ahd) | ||
4943 | { | 2340 | { |
4944 | struct ahd_linux_device *dev; | 2341 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
4945 | int target; | 2342 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); |
4946 | int maxtarget; | 2343 | struct ahd_tmode_tstate *tstate; |
4947 | int lun; | 2344 | struct ahd_initiator_tinfo *tinfo |
4948 | int i; | 2345 | = ahd_fetch_transinfo(ahd, |
4949 | 2346 | starget->channel + 'A', | |
4950 | maxtarget = (ahd->features & AHD_WIDE) ? 15 : 7; | 2347 | shost->this_id, starget->id, &tstate); |
4951 | for (target = 0; target <=maxtarget; target++) { | 2348 | struct ahd_devinfo devinfo; |
4952 | 2349 | unsigned int ppr_options = tinfo->goal.ppr_options; | |
4953 | for (lun = 0; lun < AHD_NUM_LUNS; lun++) { | 2350 | unsigned int dt; |
4954 | struct ahd_cmd *acmd; | 2351 | unsigned long flags; |
4955 | 2352 | unsigned long offset = tinfo->goal.offset; | |
4956 | dev = ahd_linux_get_device(ahd, 0, target, | 2353 | |
4957 | lun, /*alloc*/FALSE); | 2354 | #ifdef AHD_DEBUG |
4958 | if (dev == NULL) | 2355 | if ((ahd_debug & AHD_SHOW_DV) != 0) |
4959 | continue; | 2356 | printf("%s: set period to %d\n", ahd_name(ahd), period); |
4960 | 2357 | #endif | |
4961 | printf("DevQ(%d:%d:%d): ", 0, target, lun); | 2358 | if (offset == 0) |
4962 | i = 0; | 2359 | offset = MAX_OFFSET; |
4963 | TAILQ_FOREACH(acmd, &dev->busyq, acmd_links.tqe) { | 2360 | |
4964 | if (i++ > AHD_SCB_MAX) | 2361 | if (period < 8) |
4965 | break; | 2362 | period = 8; |
4966 | } | 2363 | if (period < 10) { |
4967 | printf("%d waiting\n", i); | 2364 | ppr_options |= MSG_EXT_PPR_DT_REQ; |
4968 | } | 2365 | if (period == 8) |
2366 | ppr_options |= MSG_EXT_PPR_IU_REQ; | ||
4969 | } | 2367 | } |
2368 | |||
2369 | dt = ppr_options & MSG_EXT_PPR_DT_REQ; | ||
2370 | |||
2371 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2372 | starget->channel + 'A', ROLE_INITIATOR); | ||
2373 | |||
2374 | /* all PPR requests apart from QAS require wide transfers */ | ||
2375 | if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) { | ||
2376 | if (spi_width(starget) == 0) | ||
2377 | ppr_options &= MSG_EXT_PPR_QAS_REQ; | ||
2378 | } | ||
2379 | |||
2380 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2381 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
2382 | |||
2383 | ahd_lock(ahd, &flags); | ||
2384 | ahd_set_syncrate(ahd, &devinfo, period, offset, | ||
2385 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2386 | ahd_unlock(ahd, &flags); | ||
4970 | } | 2387 | } |
4971 | 2388 | ||
4972 | static int __init | 2389 | static void ahd_linux_set_offset(struct scsi_target *starget, int offset) |
4973 | ahd_linux_init(void) | ||
4974 | { | 2390 | { |
4975 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | 2391 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
4976 | return ahd_linux_detect(&aic79xx_driver_template); | 2392 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); |
4977 | #else | 2393 | struct ahd_tmode_tstate *tstate; |
4978 | scsi_register_module(MODULE_SCSI_HA, &aic79xx_driver_template); | 2394 | struct ahd_initiator_tinfo *tinfo |
4979 | if (aic79xx_driver_template.present == 0) { | 2395 | = ahd_fetch_transinfo(ahd, |
4980 | scsi_unregister_module(MODULE_SCSI_HA, | 2396 | starget->channel + 'A', |
4981 | &aic79xx_driver_template); | 2397 | shost->this_id, starget->id, &tstate); |
4982 | return (-ENODEV); | 2398 | struct ahd_devinfo devinfo; |
2399 | unsigned int ppr_options = 0; | ||
2400 | unsigned int period = 0; | ||
2401 | unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ; | ||
2402 | unsigned long flags; | ||
2403 | |||
2404 | #ifdef AHD_DEBUG | ||
2405 | if ((ahd_debug & AHD_SHOW_DV) != 0) | ||
2406 | printf("%s: set offset to %d\n", ahd_name(ahd), offset); | ||
2407 | #endif | ||
2408 | |||
2409 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2410 | starget->channel + 'A', ROLE_INITIATOR); | ||
2411 | if (offset != 0) { | ||
2412 | period = tinfo->goal.period; | ||
2413 | ppr_options = tinfo->goal.ppr_options; | ||
2414 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2415 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
4983 | } | 2416 | } |
4984 | 2417 | ||
4985 | return (0); | 2418 | ahd_lock(ahd, &flags); |
2419 | ahd_set_syncrate(ahd, &devinfo, period, offset, ppr_options, | ||
2420 | AHD_TRANS_GOAL, FALSE); | ||
2421 | ahd_unlock(ahd, &flags); | ||
2422 | } | ||
2423 | |||
2424 | static void ahd_linux_set_dt(struct scsi_target *starget, int dt) | ||
2425 | { | ||
2426 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | ||
2427 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2428 | struct ahd_tmode_tstate *tstate; | ||
2429 | struct ahd_initiator_tinfo *tinfo | ||
2430 | = ahd_fetch_transinfo(ahd, | ||
2431 | starget->channel + 'A', | ||
2432 | shost->this_id, starget->id, &tstate); | ||
2433 | struct ahd_devinfo devinfo; | ||
2434 | unsigned int ppr_options = tinfo->goal.ppr_options | ||
2435 | & ~MSG_EXT_PPR_DT_REQ; | ||
2436 | unsigned int period = tinfo->goal.period; | ||
2437 | unsigned int width = tinfo->goal.width; | ||
2438 | unsigned long flags; | ||
2439 | |||
2440 | #ifdef AHD_DEBUG | ||
2441 | if ((ahd_debug & AHD_SHOW_DV) != 0) | ||
2442 | printf("%s: %s DT\n", ahd_name(ahd), | ||
2443 | dt ? "enabling" : "disabling"); | ||
2444 | #endif | ||
2445 | if (dt) { | ||
2446 | ppr_options |= MSG_EXT_PPR_DT_REQ; | ||
2447 | if (!width) | ||
2448 | ahd_linux_set_width(starget, 1); | ||
2449 | } else { | ||
2450 | if (period <= 9) | ||
2451 | period = 10; /* If resetting DT, period must be >= 25ns */ | ||
2452 | /* IU is invalid without DT set */ | ||
2453 | ppr_options &= ~MSG_EXT_PPR_IU_REQ; | ||
2454 | } | ||
2455 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2456 | starget->channel + 'A', ROLE_INITIATOR); | ||
2457 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2458 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
2459 | |||
2460 | ahd_lock(ahd, &flags); | ||
2461 | ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset, | ||
2462 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2463 | ahd_unlock(ahd, &flags); | ||
2464 | } | ||
2465 | |||
2466 | static void ahd_linux_set_qas(struct scsi_target *starget, int qas) | ||
2467 | { | ||
2468 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | ||
2469 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2470 | struct ahd_tmode_tstate *tstate; | ||
2471 | struct ahd_initiator_tinfo *tinfo | ||
2472 | = ahd_fetch_transinfo(ahd, | ||
2473 | starget->channel + 'A', | ||
2474 | shost->this_id, starget->id, &tstate); | ||
2475 | struct ahd_devinfo devinfo; | ||
2476 | unsigned int ppr_options = tinfo->goal.ppr_options | ||
2477 | & ~MSG_EXT_PPR_QAS_REQ; | ||
2478 | unsigned int period = tinfo->goal.period; | ||
2479 | unsigned int dt; | ||
2480 | unsigned long flags; | ||
2481 | |||
2482 | #ifdef AHD_DEBUG | ||
2483 | if ((ahd_debug & AHD_SHOW_DV) != 0) | ||
2484 | printf("%s: %s QAS\n", ahd_name(ahd), | ||
2485 | qas ? "enabling" : "disabling"); | ||
2486 | #endif | ||
2487 | |||
2488 | if (qas) { | ||
2489 | ppr_options |= MSG_EXT_PPR_QAS_REQ; | ||
2490 | } | ||
2491 | |||
2492 | dt = ppr_options & MSG_EXT_PPR_DT_REQ; | ||
2493 | |||
2494 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2495 | starget->channel + 'A', ROLE_INITIATOR); | ||
2496 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2497 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
2498 | |||
2499 | ahd_lock(ahd, &flags); | ||
2500 | ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset, | ||
2501 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2502 | ahd_unlock(ahd, &flags); | ||
2503 | } | ||
2504 | |||
2505 | static void ahd_linux_set_iu(struct scsi_target *starget, int iu) | ||
2506 | { | ||
2507 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | ||
2508 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2509 | struct ahd_tmode_tstate *tstate; | ||
2510 | struct ahd_initiator_tinfo *tinfo | ||
2511 | = ahd_fetch_transinfo(ahd, | ||
2512 | starget->channel + 'A', | ||
2513 | shost->this_id, starget->id, &tstate); | ||
2514 | struct ahd_devinfo devinfo; | ||
2515 | unsigned int ppr_options = tinfo->goal.ppr_options | ||
2516 | & ~MSG_EXT_PPR_IU_REQ; | ||
2517 | unsigned int period = tinfo->goal.period; | ||
2518 | unsigned int dt; | ||
2519 | unsigned long flags; | ||
2520 | |||
2521 | #ifdef AHD_DEBUG | ||
2522 | if ((ahd_debug & AHD_SHOW_DV) != 0) | ||
2523 | printf("%s: %s IU\n", ahd_name(ahd), | ||
2524 | iu ? "enabling" : "disabling"); | ||
4986 | #endif | 2525 | #endif |
2526 | |||
2527 | if (iu) { | ||
2528 | ppr_options |= MSG_EXT_PPR_IU_REQ; | ||
2529 | ppr_options |= MSG_EXT_PPR_DT_REQ; /* IU requires DT */ | ||
2530 | } | ||
2531 | |||
2532 | dt = ppr_options & MSG_EXT_PPR_DT_REQ; | ||
2533 | |||
2534 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2535 | starget->channel + 'A', ROLE_INITIATOR); | ||
2536 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2537 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
2538 | |||
2539 | ahd_lock(ahd, &flags); | ||
2540 | ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset, | ||
2541 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2542 | ahd_unlock(ahd, &flags); | ||
4987 | } | 2543 | } |
4988 | 2544 | ||
4989 | static void __exit | 2545 | static void ahd_linux_set_rd_strm(struct scsi_target *starget, int rdstrm) |
4990 | ahd_linux_exit(void) | ||
4991 | { | 2546 | { |
4992 | struct ahd_softc *ahd; | 2547 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
2548 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2549 | struct ahd_tmode_tstate *tstate; | ||
2550 | struct ahd_initiator_tinfo *tinfo | ||
2551 | = ahd_fetch_transinfo(ahd, | ||
2552 | starget->channel + 'A', | ||
2553 | shost->this_id, starget->id, &tstate); | ||
2554 | struct ahd_devinfo devinfo; | ||
2555 | unsigned int ppr_options = tinfo->goal.ppr_options | ||
2556 | & ~MSG_EXT_PPR_RD_STRM; | ||
2557 | unsigned int period = tinfo->goal.period; | ||
2558 | unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ; | ||
2559 | unsigned long flags; | ||
4993 | 2560 | ||
4994 | /* | 2561 | #ifdef AHD_DEBUG |
4995 | * Shutdown DV threads before going into the SCSI mid-layer. | 2562 | if ((ahd_debug & AHD_SHOW_DV) != 0) |
4996 | * This avoids situations where the mid-layer locks the entire | 2563 | printf("%s: %s Read Streaming\n", ahd_name(ahd), |
4997 | * kernel so that waiting for our DV threads to exit leads | 2564 | rdstrm ? "enabling" : "disabling"); |
4998 | * to deadlock. | 2565 | #endif |
4999 | */ | 2566 | |
5000 | TAILQ_FOREACH(ahd, &ahd_tailq, links) { | 2567 | if (rdstrm) |
2568 | ppr_options |= MSG_EXT_PPR_RD_STRM; | ||
2569 | |||
2570 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2571 | starget->channel + 'A', ROLE_INITIATOR); | ||
2572 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2573 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
5001 | 2574 | ||
5002 | ahd_linux_kill_dv_thread(ahd); | 2575 | ahd_lock(ahd, &flags); |
2576 | ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset, | ||
2577 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2578 | ahd_unlock(ahd, &flags); | ||
2579 | } | ||
2580 | |||
2581 | static void ahd_linux_set_wr_flow(struct scsi_target *starget, int wrflow) | ||
2582 | { | ||
2583 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | ||
2584 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2585 | struct ahd_tmode_tstate *tstate; | ||
2586 | struct ahd_initiator_tinfo *tinfo | ||
2587 | = ahd_fetch_transinfo(ahd, | ||
2588 | starget->channel + 'A', | ||
2589 | shost->this_id, starget->id, &tstate); | ||
2590 | struct ahd_devinfo devinfo; | ||
2591 | unsigned int ppr_options = tinfo->goal.ppr_options | ||
2592 | & ~MSG_EXT_PPR_WR_FLOW; | ||
2593 | unsigned int period = tinfo->goal.period; | ||
2594 | unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ; | ||
2595 | unsigned long flags; | ||
2596 | |||
2597 | #ifdef AHD_DEBUG | ||
2598 | if ((ahd_debug & AHD_SHOW_DV) != 0) | ||
2599 | printf("%s: %s Write Flow Control\n", ahd_name(ahd), | ||
2600 | wrflow ? "enabling" : "disabling"); | ||
2601 | #endif | ||
2602 | |||
2603 | if (wrflow) | ||
2604 | ppr_options |= MSG_EXT_PPR_WR_FLOW; | ||
2605 | |||
2606 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2607 | starget->channel + 'A', ROLE_INITIATOR); | ||
2608 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2609 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
2610 | |||
2611 | ahd_lock(ahd, &flags); | ||
2612 | ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset, | ||
2613 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2614 | ahd_unlock(ahd, &flags); | ||
2615 | } | ||
2616 | |||
2617 | static void ahd_linux_set_rti(struct scsi_target *starget, int rti) | ||
2618 | { | ||
2619 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | ||
2620 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2621 | struct ahd_tmode_tstate *tstate; | ||
2622 | struct ahd_initiator_tinfo *tinfo | ||
2623 | = ahd_fetch_transinfo(ahd, | ||
2624 | starget->channel + 'A', | ||
2625 | shost->this_id, starget->id, &tstate); | ||
2626 | struct ahd_devinfo devinfo; | ||
2627 | unsigned int ppr_options = tinfo->goal.ppr_options | ||
2628 | & ~MSG_EXT_PPR_RTI; | ||
2629 | unsigned int period = tinfo->goal.period; | ||
2630 | unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ; | ||
2631 | unsigned long flags; | ||
2632 | |||
2633 | if ((ahd->features & AHD_RTI) == 0) { | ||
2634 | #ifdef AHD_DEBUG | ||
2635 | if ((ahd_debug & AHD_SHOW_DV) != 0) | ||
2636 | printf("%s: RTI not available\n", ahd_name(ahd)); | ||
2637 | #endif | ||
2638 | return; | ||
5003 | } | 2639 | } |
5004 | 2640 | ||
5005 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) | 2641 | #ifdef AHD_DEBUG |
2642 | if ((ahd_debug & AHD_SHOW_DV) != 0) | ||
2643 | printf("%s: %s RTI\n", ahd_name(ahd), | ||
2644 | rti ? "enabling" : "disabling"); | ||
2645 | #endif | ||
2646 | |||
2647 | if (rti) | ||
2648 | ppr_options |= MSG_EXT_PPR_RTI; | ||
2649 | |||
2650 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2651 | starget->channel + 'A', ROLE_INITIATOR); | ||
2652 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2653 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
2654 | |||
2655 | ahd_lock(ahd, &flags); | ||
2656 | ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset, | ||
2657 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2658 | ahd_unlock(ahd, &flags); | ||
2659 | } | ||
2660 | |||
2661 | static void ahd_linux_set_pcomp_en(struct scsi_target *starget, int pcomp) | ||
2662 | { | ||
2663 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | ||
2664 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2665 | struct ahd_tmode_tstate *tstate; | ||
2666 | struct ahd_initiator_tinfo *tinfo | ||
2667 | = ahd_fetch_transinfo(ahd, | ||
2668 | starget->channel + 'A', | ||
2669 | shost->this_id, starget->id, &tstate); | ||
2670 | struct ahd_devinfo devinfo; | ||
2671 | unsigned int ppr_options = tinfo->goal.ppr_options | ||
2672 | & ~MSG_EXT_PPR_PCOMP_EN; | ||
2673 | unsigned int period = tinfo->goal.period; | ||
2674 | unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ; | ||
2675 | unsigned long flags; | ||
2676 | |||
2677 | #ifdef AHD_DEBUG | ||
2678 | if ((ahd_debug & AHD_SHOW_DV) != 0) | ||
2679 | printf("%s: %s Precompensation\n", ahd_name(ahd), | ||
2680 | pcomp ? "Enable" : "Disable"); | ||
2681 | #endif | ||
2682 | |||
2683 | if (pcomp) | ||
2684 | ppr_options |= MSG_EXT_PPR_PCOMP_EN; | ||
2685 | |||
2686 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2687 | starget->channel + 'A', ROLE_INITIATOR); | ||
2688 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2689 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
2690 | |||
2691 | ahd_lock(ahd, &flags); | ||
2692 | ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset, | ||
2693 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2694 | ahd_unlock(ahd, &flags); | ||
2695 | } | ||
2696 | |||
2697 | static void ahd_linux_set_hold_mcs(struct scsi_target *starget, int hold) | ||
2698 | { | ||
2699 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | ||
2700 | struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata); | ||
2701 | struct ahd_tmode_tstate *tstate; | ||
2702 | struct ahd_initiator_tinfo *tinfo | ||
2703 | = ahd_fetch_transinfo(ahd, | ||
2704 | starget->channel + 'A', | ||
2705 | shost->this_id, starget->id, &tstate); | ||
2706 | struct ahd_devinfo devinfo; | ||
2707 | unsigned int ppr_options = tinfo->goal.ppr_options | ||
2708 | & ~MSG_EXT_PPR_HOLD_MCS; | ||
2709 | unsigned int period = tinfo->goal.period; | ||
2710 | unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ; | ||
2711 | unsigned long flags; | ||
2712 | |||
2713 | if (hold) | ||
2714 | ppr_options |= MSG_EXT_PPR_HOLD_MCS; | ||
2715 | |||
2716 | ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, | ||
2717 | starget->channel + 'A', ROLE_INITIATOR); | ||
2718 | ahd_find_syncrate(ahd, &period, &ppr_options, | ||
2719 | dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2); | ||
2720 | |||
2721 | ahd_lock(ahd, &flags); | ||
2722 | ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset, | ||
2723 | ppr_options, AHD_TRANS_GOAL, FALSE); | ||
2724 | ahd_unlock(ahd, &flags); | ||
2725 | } | ||
2726 | |||
2727 | |||
2728 | |||
2729 | static struct spi_function_template ahd_linux_transport_functions = { | ||
2730 | .set_offset = ahd_linux_set_offset, | ||
2731 | .show_offset = 1, | ||
2732 | .set_period = ahd_linux_set_period, | ||
2733 | .show_period = 1, | ||
2734 | .set_width = ahd_linux_set_width, | ||
2735 | .show_width = 1, | ||
2736 | .set_dt = ahd_linux_set_dt, | ||
2737 | .show_dt = 1, | ||
2738 | .set_iu = ahd_linux_set_iu, | ||
2739 | .show_iu = 1, | ||
2740 | .set_qas = ahd_linux_set_qas, | ||
2741 | .show_qas = 1, | ||
2742 | .set_rd_strm = ahd_linux_set_rd_strm, | ||
2743 | .show_rd_strm = 1, | ||
2744 | .set_wr_flow = ahd_linux_set_wr_flow, | ||
2745 | .show_wr_flow = 1, | ||
2746 | .set_rti = ahd_linux_set_rti, | ||
2747 | .show_rti = 1, | ||
2748 | .set_pcomp_en = ahd_linux_set_pcomp_en, | ||
2749 | .show_pcomp_en = 1, | ||
2750 | .set_hold_mcs = ahd_linux_set_hold_mcs, | ||
2751 | .show_hold_mcs = 1, | ||
2752 | }; | ||
2753 | |||
2754 | static int __init | ||
2755 | ahd_linux_init(void) | ||
2756 | { | ||
2757 | int error = 0; | ||
2758 | |||
5006 | /* | 2759 | /* |
5007 | * In 2.4 we have to unregister from the PCI core _after_ | 2760 | * If we've been passed any parameters, process them now. |
5008 | * unregistering from the scsi midlayer to avoid dangling | ||
5009 | * references. | ||
5010 | */ | 2761 | */ |
5011 | scsi_unregister_module(MODULE_SCSI_HA, &aic79xx_driver_template); | 2762 | if (aic79xx) |
5012 | #endif | 2763 | aic79xx_setup(aic79xx); |
2764 | |||
2765 | ahd_linux_transport_template = | ||
2766 | spi_attach_transport(&ahd_linux_transport_functions); | ||
2767 | if (!ahd_linux_transport_template) | ||
2768 | return -ENODEV; | ||
2769 | |||
2770 | scsi_transport_reserve_target(ahd_linux_transport_template, | ||
2771 | sizeof(struct ahd_linux_target)); | ||
2772 | scsi_transport_reserve_device(ahd_linux_transport_template, | ||
2773 | sizeof(struct ahd_linux_device)); | ||
2774 | |||
2775 | error = ahd_linux_pci_init(); | ||
2776 | if (error) | ||
2777 | spi_release_transport(ahd_linux_transport_template); | ||
2778 | return error; | ||
2779 | } | ||
2780 | |||
2781 | static void __exit | ||
2782 | ahd_linux_exit(void) | ||
2783 | { | ||
5013 | ahd_linux_pci_exit(); | 2784 | ahd_linux_pci_exit(); |
2785 | spi_release_transport(ahd_linux_transport_template); | ||
5014 | } | 2786 | } |
5015 | 2787 | ||
5016 | module_init(ahd_linux_init); | 2788 | module_init(ahd_linux_init); |