aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/aic7xxx/aic7xxx_osm.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/aic7xxx/aic7xxx_osm.c')
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.c1863
1 files changed, 479 insertions, 1384 deletions
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index d978e4a3e973..b89094db14c1 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -122,8 +122,6 @@
122#include "aic7xxx_osm.h" 122#include "aic7xxx_osm.h"
123#include "aic7xxx_inline.h" 123#include "aic7xxx_inline.h"
124#include <scsi/scsicam.h> 124#include <scsi/scsicam.h>
125#include <scsi/scsi_transport.h>
126#include <scsi/scsi_transport_spi.h>
127 125
128static struct scsi_transport_template *ahc_linux_transport_template = NULL; 126static struct scsi_transport_template *ahc_linux_transport_template = NULL;
129 127
@@ -134,11 +132,6 @@ static struct scsi_transport_template *ahc_linux_transport_template = NULL;
134#include "aiclib.c" 132#include "aiclib.c"
135 133
136#include <linux/init.h> /* __setup */ 134#include <linux/init.h> /* __setup */
137
138#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
139#include "sd.h" /* For geometry detection */
140#endif
141
142#include <linux/mm.h> /* For fetching system memory size */ 135#include <linux/mm.h> /* For fetching system memory size */
143#include <linux/blkdev.h> /* For block_size() */ 136#include <linux/blkdev.h> /* For block_size() */
144#include <linux/delay.h> /* For ssleep/msleep */ 137#include <linux/delay.h> /* For ssleep/msleep */
@@ -148,11 +141,6 @@ static struct scsi_transport_template *ahc_linux_transport_template = NULL;
148 */ 141 */
149spinlock_t ahc_list_spinlock; 142spinlock_t ahc_list_spinlock;
150 143
151#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
152/* For dynamic sglist size calculation. */
153u_int ahc_linux_nseg;
154#endif
155
156/* 144/*
157 * Set this to the delay in seconds after SCSI bus reset. 145 * Set this to the delay in seconds after SCSI bus reset.
158 * Note, we honor this only for the initial bus reset. 146 * Note, we honor this only for the initial bus reset.
@@ -342,22 +330,6 @@ static uint32_t aic7xxx_extended;
342static uint32_t aic7xxx_pci_parity = ~0; 330static uint32_t aic7xxx_pci_parity = ~0;
343 331
344/* 332/*
345 * Certain newer motherboards have put new PCI based devices into the
346 * IO spaces that used to typically be occupied by VLB or EISA cards.
347 * This overlap can cause these newer motherboards to lock up when scanned
348 * for older EISA and VLB devices. Setting this option to non-0 will
349 * cause the driver to skip scanning for any VLB or EISA controllers and
350 * only support the PCI controllers. NOTE: this means that if the kernel
351 * os compiled with PCI support disabled, then setting this to non-0
352 * would result in never finding any devices :)
353 */
354#ifndef CONFIG_AIC7XXX_PROBE_EISA_VL
355uint32_t aic7xxx_probe_eisa_vl;
356#else
357uint32_t aic7xxx_probe_eisa_vl = ~0;
358#endif
359
360/*
361 * There are lots of broken chipsets in the world. Some of them will 333 * There are lots of broken chipsets in the world. Some of them will
362 * violate the PCI spec when we issue byte sized memory writes to our 334 * violate the PCI spec when we issue byte sized memory writes to our
363 * controller. I/O mapped register access, if allowed by the given 335 * controller. I/O mapped register access, if allowed by the given
@@ -433,51 +405,27 @@ MODULE_PARM_DESC(aic7xxx,
433); 405);
434 406
435static void ahc_linux_handle_scsi_status(struct ahc_softc *, 407static void ahc_linux_handle_scsi_status(struct ahc_softc *,
436 struct ahc_linux_device *, 408 struct scsi_device *,
437 struct scb *); 409 struct scb *);
438static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, 410static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc,
439 Scsi_Cmnd *cmd); 411 struct scsi_cmnd *cmd);
440static void ahc_linux_sem_timeout(u_long arg); 412static void ahc_linux_sem_timeout(u_long arg);
441static void ahc_linux_freeze_simq(struct ahc_softc *ahc); 413static void ahc_linux_freeze_simq(struct ahc_softc *ahc);
442static void ahc_linux_release_simq(u_long arg); 414static void ahc_linux_release_simq(u_long arg);
443static void ahc_linux_dev_timed_unfreeze(u_long arg); 415static int ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag);
444static int ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag);
445static void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc); 416static void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc);
446static void ahc_linux_size_nseg(void);
447static void ahc_linux_thread_run_complete_queue(struct ahc_softc *ahc);
448static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc, 417static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc,
449 struct ahc_devinfo *devinfo); 418 struct ahc_devinfo *devinfo);
450static void ahc_linux_device_queue_depth(struct ahc_softc *ahc, 419static void ahc_linux_device_queue_depth(struct scsi_device *);
451 struct ahc_linux_device *dev); 420static int ahc_linux_run_command(struct ahc_softc*,
452static struct ahc_linux_target* ahc_linux_alloc_target(struct ahc_softc*, 421 struct ahc_linux_device *,
453 u_int, u_int); 422 struct scsi_cmnd *);
454static void ahc_linux_free_target(struct ahc_softc*,
455 struct ahc_linux_target*);
456static struct ahc_linux_device* ahc_linux_alloc_device(struct ahc_softc*,
457 struct ahc_linux_target*,
458 u_int);
459static void ahc_linux_free_device(struct ahc_softc*,
460 struct ahc_linux_device*);
461static void ahc_linux_run_device_queue(struct ahc_softc*,
462 struct ahc_linux_device*);
463static void ahc_linux_setup_tag_info_global(char *p); 423static void ahc_linux_setup_tag_info_global(char *p);
464static aic_option_callback_t ahc_linux_setup_tag_info; 424static aic_option_callback_t ahc_linux_setup_tag_info;
465static int aic7xxx_setup(char *s); 425static int aic7xxx_setup(char *s);
466static int ahc_linux_next_unit(void); 426static int ahc_linux_next_unit(void);
467static void ahc_runq_tasklet(unsigned long data);
468static struct ahc_cmd *ahc_linux_run_complete_queue(struct ahc_softc *ahc);
469 427
470/********************************* Inlines ************************************/ 428/********************************* Inlines ************************************/
471static __inline void ahc_schedule_runq(struct ahc_softc *ahc);
472static __inline struct ahc_linux_device*
473 ahc_linux_get_device(struct ahc_softc *ahc, u_int channel,
474 u_int target, u_int lun, int alloc);
475static __inline void ahc_schedule_completeq(struct ahc_softc *ahc);
476static __inline void ahc_linux_check_device_queue(struct ahc_softc *ahc,
477 struct ahc_linux_device *dev);
478static __inline struct ahc_linux_device *
479 ahc_linux_next_device_to_run(struct ahc_softc *ahc);
480static __inline void ahc_linux_run_device_queues(struct ahc_softc *ahc);
481static __inline void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*); 429static __inline void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*);
482 430
483static __inline int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb, 431static __inline int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
@@ -485,132 +433,9 @@ static __inline int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
485 dma_addr_t addr, bus_size_t len); 433 dma_addr_t addr, bus_size_t len);
486 434
487static __inline void 435static __inline void
488ahc_schedule_completeq(struct ahc_softc *ahc)
489{
490 if ((ahc->platform_data->flags & AHC_RUN_CMPLT_Q_TIMER) == 0) {
491 ahc->platform_data->flags |= AHC_RUN_CMPLT_Q_TIMER;
492 ahc->platform_data->completeq_timer.expires = jiffies;
493 add_timer(&ahc->platform_data->completeq_timer);
494 }
495}
496
497/*
498 * Must be called with our lock held.
499 */
500static __inline void
501ahc_schedule_runq(struct ahc_softc *ahc)
502{
503 tasklet_schedule(&ahc->platform_data->runq_tasklet);
504}
505
506static __inline struct ahc_linux_device*
507ahc_linux_get_device(struct ahc_softc *ahc, u_int channel, u_int target,
508 u_int lun, int alloc)
509{
510 struct ahc_linux_target *targ;
511 struct ahc_linux_device *dev;
512 u_int target_offset;
513
514 target_offset = target;
515 if (channel != 0)
516 target_offset += 8;
517 targ = ahc->platform_data->targets[target_offset];
518 if (targ == NULL) {
519 if (alloc != 0) {
520 targ = ahc_linux_alloc_target(ahc, channel, target);
521 if (targ == NULL)
522 return (NULL);
523 } else
524 return (NULL);
525 }
526 dev = targ->devices[lun];
527 if (dev == NULL && alloc != 0)
528 dev = ahc_linux_alloc_device(ahc, targ, lun);
529 return (dev);
530}
531
532#define AHC_LINUX_MAX_RETURNED_ERRORS 4
533static struct ahc_cmd *
534ahc_linux_run_complete_queue(struct ahc_softc *ahc)
535{
536 struct ahc_cmd *acmd;
537 u_long done_flags;
538 int with_errors;
539
540 with_errors = 0;
541 ahc_done_lock(ahc, &done_flags);
542 while ((acmd = TAILQ_FIRST(&ahc->platform_data->completeq)) != NULL) {
543 Scsi_Cmnd *cmd;
544
545 if (with_errors > AHC_LINUX_MAX_RETURNED_ERRORS) {
546 /*
547 * Linux uses stack recursion to requeue
548 * commands that need to be retried. Avoid
549 * blowing out the stack by "spoon feeding"
550 * commands that completed with error back
551 * the operating system in case they are going
552 * to be retried. "ick"
553 */
554 ahc_schedule_completeq(ahc);
555 break;
556 }
557 TAILQ_REMOVE(&ahc->platform_data->completeq,
558 acmd, acmd_links.tqe);
559 cmd = &acmd_scsi_cmd(acmd);
560 cmd->host_scribble = NULL;
561 if (ahc_cmd_get_transaction_status(cmd) != DID_OK
562 || (cmd->result & 0xFF) != SCSI_STATUS_OK)
563 with_errors++;
564
565 cmd->scsi_done(cmd);
566 }
567 ahc_done_unlock(ahc, &done_flags);
568 return (acmd);
569}
570
571static __inline void
572ahc_linux_check_device_queue(struct ahc_softc *ahc,
573 struct ahc_linux_device *dev)
574{
575 if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) != 0
576 && dev->active == 0) {
577 dev->flags &= ~AHC_DEV_FREEZE_TIL_EMPTY;
578 dev->qfrozen--;
579 }
580
581 if (TAILQ_FIRST(&dev->busyq) == NULL
582 || dev->openings == 0 || dev->qfrozen != 0)
583 return;
584
585 ahc_linux_run_device_queue(ahc, dev);
586}
587
588static __inline struct ahc_linux_device *
589ahc_linux_next_device_to_run(struct ahc_softc *ahc)
590{
591
592 if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0
593 || (ahc->platform_data->qfrozen != 0))
594 return (NULL);
595 return (TAILQ_FIRST(&ahc->platform_data->device_runq));
596}
597
598static __inline void
599ahc_linux_run_device_queues(struct ahc_softc *ahc)
600{
601 struct ahc_linux_device *dev;
602
603 while ((dev = ahc_linux_next_device_to_run(ahc)) != NULL) {
604 TAILQ_REMOVE(&ahc->platform_data->device_runq, dev, links);
605 dev->flags &= ~AHC_DEV_ON_RUN_LIST;
606 ahc_linux_check_device_queue(ahc, dev);
607 }
608}
609
610static __inline void
611ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb) 436ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb)
612{ 437{
613 Scsi_Cmnd *cmd; 438 struct scsi_cmnd *cmd;
614 439
615 cmd = scb->io_ctx; 440 cmd = scb->io_ctx;
616 ahc_sync_sglist(ahc, scb, BUS_DMASYNC_POSTWRITE); 441 ahc_sync_sglist(ahc, scb, BUS_DMASYNC_POSTWRITE);
@@ -650,121 +475,15 @@ ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
650 return (consumed); 475 return (consumed);
651} 476}
652 477
653/************************ Host template entry points *************************/
654static int ahc_linux_detect(Scsi_Host_Template *);
655static int ahc_linux_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
656static const char *ahc_linux_info(struct Scsi_Host *);
657#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
658static int ahc_linux_slave_alloc(Scsi_Device *);
659static int ahc_linux_slave_configure(Scsi_Device *);
660static void ahc_linux_slave_destroy(Scsi_Device *);
661#if defined(__i386__)
662static int ahc_linux_biosparam(struct scsi_device*,
663 struct block_device*,
664 sector_t, int[]);
665#endif
666#else
667static int ahc_linux_release(struct Scsi_Host *);
668static void ahc_linux_select_queue_depth(struct Scsi_Host *host,
669 Scsi_Device *scsi_devs);
670#if defined(__i386__)
671static int ahc_linux_biosparam(Disk *, kdev_t, int[]);
672#endif
673#endif
674static int ahc_linux_bus_reset(Scsi_Cmnd *);
675static int ahc_linux_dev_reset(Scsi_Cmnd *);
676static int ahc_linux_abort(Scsi_Cmnd *);
677
678/*
679 * Calculate a safe value for AHC_NSEG (as expressed through ahc_linux_nseg).
680 *
681 * In pre-2.5.X...
682 * The midlayer allocates an S/G array dynamically when a command is issued
683 * using SCSI malloc. This array, which is in an OS dependent format that
684 * must later be copied to our private S/G list, is sized to house just the
685 * number of segments needed for the current transfer. Since the code that
686 * sizes the SCSI malloc pool does not take into consideration fragmentation
687 * of the pool, executing transactions numbering just a fraction of our
688 * concurrent transaction limit with list lengths aproaching AHC_NSEG will
689 * quickly depleat the SCSI malloc pool of usable space. Unfortunately, the
690 * mid-layer does not properly handle this scsi malloc failures for the S/G
691 * array and the result can be a lockup of the I/O subsystem. We try to size
692 * our S/G list so that it satisfies our drivers allocation requirements in
693 * addition to avoiding fragmentation of the SCSI malloc pool.
694 */
695static void
696ahc_linux_size_nseg(void)
697{
698#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
699 u_int cur_size;
700 u_int best_size;
701
702 /*
703 * The SCSI allocator rounds to the nearest 512 bytes
704 * an cannot allocate across a page boundary. Our algorithm
705 * is to start at 1K of scsi malloc space per-command and
706 * loop through all factors of the PAGE_SIZE and pick the best.
707 */
708 best_size = 0;
709 for (cur_size = 1024; cur_size <= PAGE_SIZE; cur_size *= 2) {
710 u_int nseg;
711
712 nseg = cur_size / sizeof(struct scatterlist);
713 if (nseg < AHC_LINUX_MIN_NSEG)
714 continue;
715
716 if (best_size == 0) {
717 best_size = cur_size;
718 ahc_linux_nseg = nseg;
719 } else {
720 u_int best_rem;
721 u_int cur_rem;
722
723 /*
724 * Compare the traits of the current "best_size"
725 * with the current size to determine if the
726 * current size is a better size.
727 */
728 best_rem = best_size % sizeof(struct scatterlist);
729 cur_rem = cur_size % sizeof(struct scatterlist);
730 if (cur_rem < best_rem) {
731 best_size = cur_size;
732 ahc_linux_nseg = nseg;
733 }
734 }
735 }
736#endif
737}
738
739/* 478/*
740 * Try to detect an Adaptec 7XXX controller. 479 * Try to detect an Adaptec 7XXX controller.
741 */ 480 */
742static int 481static int
743ahc_linux_detect(Scsi_Host_Template *template) 482ahc_linux_detect(struct scsi_host_template *template)
744{ 483{
745 struct ahc_softc *ahc; 484 struct ahc_softc *ahc;
746 int found = 0; 485 int found = 0;
747 486
748#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
749 /*
750 * It is a bug that the upper layer takes
751 * this lock just prior to calling us.
752 */
753 spin_unlock_irq(&io_request_lock);
754#endif
755
756 /*
757 * Sanity checking of Linux SCSI data structures so
758 * that some of our hacks^H^H^H^H^Hassumptions aren't
759 * violated.
760 */
761 if (offsetof(struct ahc_cmd_internal, end)
762 > offsetof(struct scsi_cmnd, host_scribble)) {
763 printf("ahc_linux_detect: SCSI data structures changed.\n");
764 printf("ahc_linux_detect: Unable to attach\n");
765 return (0);
766 }
767 ahc_linux_size_nseg();
768 /* 487 /*
769 * If we've been passed any parameters, process them now. 488 * If we've been passed any parameters, process them now.
770 */ 489 */
@@ -793,48 +512,11 @@ ahc_linux_detect(Scsi_Host_Template *template)
793 found++; 512 found++;
794 } 513 }
795 514
796#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
797 spin_lock_irq(&io_request_lock);
798#endif
799 aic7xxx_detect_complete++; 515 aic7xxx_detect_complete++;
800 516
801 return (found); 517 return (found);
802} 518}
803 519
804#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
805/*
806 * Free the passed in Scsi_Host memory structures prior to unloading the
807 * module.
808 */
809int
810ahc_linux_release(struct Scsi_Host * host)
811{
812 struct ahc_softc *ahc;
813 u_long l;
814
815 ahc_list_lock(&l);
816 if (host != NULL) {
817
818 /*
819 * We should be able to just perform
820 * the free directly, but check our
821 * list for extra sanity.
822 */
823 ahc = ahc_find_softc(*(struct ahc_softc **)host->hostdata);
824 if (ahc != NULL) {
825 u_long s;
826
827 ahc_lock(ahc, &s);
828 ahc_intr_enable(ahc, FALSE);
829 ahc_unlock(ahc, &s);
830 ahc_free(ahc);
831 }
832 }
833 ahc_list_unlock(&l);
834 return (0);
835}
836#endif
837
838/* 520/*
839 * Return a string describing the driver. 521 * Return a string describing the driver.
840 */ 522 */
@@ -867,11 +549,10 @@ ahc_linux_info(struct Scsi_Host *host)
867 * Queue an SCB to the controller. 549 * Queue an SCB to the controller.
868 */ 550 */
869static int 551static int
870ahc_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *)) 552ahc_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
871{ 553{
872 struct ahc_softc *ahc; 554 struct ahc_softc *ahc;
873 struct ahc_linux_device *dev; 555 struct ahc_linux_device *dev = scsi_transport_device_data(cmd->device);
874 u_long flags;
875 556
876 ahc = *(struct ahc_softc **)cmd->device->host->hostdata; 557 ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
877 558
@@ -880,205 +561,197 @@ ahc_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
880 */ 561 */
881 cmd->scsi_done = scsi_done; 562 cmd->scsi_done = scsi_done;
882 563
883 ahc_midlayer_entrypoint_lock(ahc, &flags);
884
885 /* 564 /*
886 * Close the race of a command that was in the process of 565 * Close the race of a command that was in the process of
887 * being queued to us just as our simq was frozen. Let 566 * being queued to us just as our simq was frozen. Let
888 * DV commands through so long as we are only frozen to 567 * DV commands through so long as we are only frozen to
889 * perform DV. 568 * perform DV.
890 */ 569 */
891 if (ahc->platform_data->qfrozen != 0) { 570 if (ahc->platform_data->qfrozen != 0)
571 return SCSI_MLQUEUE_HOST_BUSY;
892 572
893 ahc_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ);
894 ahc_linux_queue_cmd_complete(ahc, cmd);
895 ahc_schedule_completeq(ahc);
896 ahc_midlayer_entrypoint_unlock(ahc, &flags);
897 return (0);
898 }
899 dev = ahc_linux_get_device(ahc, cmd->device->channel, cmd->device->id,
900 cmd->device->lun, /*alloc*/TRUE);
901 if (dev == NULL) {
902 ahc_cmd_set_transaction_status(cmd, CAM_RESRC_UNAVAIL);
903 ahc_linux_queue_cmd_complete(ahc, cmd);
904 ahc_schedule_completeq(ahc);
905 ahc_midlayer_entrypoint_unlock(ahc, &flags);
906 printf("%s: aic7xxx_linux_queue - Unable to allocate device!\n",
907 ahc_name(ahc));
908 return (0);
909 }
910 cmd->result = CAM_REQ_INPROG << 16; 573 cmd->result = CAM_REQ_INPROG << 16;
911 TAILQ_INSERT_TAIL(&dev->busyq, (struct ahc_cmd *)cmd, acmd_links.tqe); 574
912 if ((dev->flags & AHC_DEV_ON_RUN_LIST) == 0) { 575 return ahc_linux_run_command(ahc, dev, cmd);
913 TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, dev, links); 576}
914 dev->flags |= AHC_DEV_ON_RUN_LIST; 577
915 ahc_linux_run_device_queues(ahc); 578static inline struct scsi_target **
916 } 579ahc_linux_target_in_softc(struct scsi_target *starget)
917 ahc_midlayer_entrypoint_unlock(ahc, &flags); 580{
918 return (0); 581 struct ahc_softc *ahc =
582 *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata);
583 unsigned int target_offset;
584
585 target_offset = starget->id;
586 if (starget->channel != 0)
587 target_offset += 8;
588
589 return &ahc->platform_data->starget[target_offset];
919} 590}
920 591
921#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
922static int 592static int
923ahc_linux_slave_alloc(Scsi_Device *device) 593ahc_linux_target_alloc(struct scsi_target *starget)
924{ 594{
925 struct ahc_softc *ahc; 595 struct ahc_softc *ahc =
596 *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata);
597 struct seeprom_config *sc = ahc->seep_config;
598 unsigned long flags;
599 struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget);
600 struct ahc_linux_target *targ = scsi_transport_target_data(starget);
601 unsigned short scsirate;
602 struct ahc_devinfo devinfo;
603 struct ahc_initiator_tinfo *tinfo;
604 struct ahc_tmode_tstate *tstate;
605 char channel = starget->channel + 'A';
606 unsigned int our_id = ahc->our_id;
607 unsigned int target_offset;
926 608
927 ahc = *((struct ahc_softc **)device->host->hostdata); 609 target_offset = starget->id;
928 if (bootverbose) 610 if (starget->channel != 0)
929 printf("%s: Slave Alloc %d\n", ahc_name(ahc), device->id); 611 target_offset += 8;
930 return (0); 612
613 if (starget->channel)
614 our_id = ahc->our_id_b;
615
616 ahc_lock(ahc, &flags);
617
618 BUG_ON(*ahc_targp != NULL);
619
620 *ahc_targp = starget;
621 memset(targ, 0, sizeof(*targ));
622
623 if (sc) {
624 int maxsync = AHC_SYNCRATE_DT;
625 int ultra = 0;
626 int flags = sc->device_flags[target_offset];
627
628 if (ahc->flags & AHC_NEWEEPROM_FMT) {
629 if (flags & CFSYNCHISULTRA)
630 ultra = 1;
631 } else if (flags & CFULTRAEN)
632 ultra = 1;
633 /* AIC nutcase; 10MHz appears as ultra = 1, CFXFER = 0x04
634 * change it to ultra=0, CFXFER = 0 */
635 if(ultra && (flags & CFXFER) == 0x04) {
636 ultra = 0;
637 flags &= ~CFXFER;
638 }
639
640 if ((ahc->features & AHC_ULTRA2) != 0) {
641 scsirate = (flags & CFXFER) | (ultra ? 0x8 : 0);
642 } else {
643 scsirate = (flags & CFXFER) << 4;
644 maxsync = ultra ? AHC_SYNCRATE_ULTRA :
645 AHC_SYNCRATE_FAST;
646 }
647 spi_max_width(starget) = (flags & CFWIDEB) ? 1 : 0;
648 if (!(flags & CFSYNCH))
649 spi_max_offset(starget) = 0;
650 spi_min_period(starget) =
651 ahc_find_period(ahc, scsirate, maxsync);
652
653 tinfo = ahc_fetch_transinfo(ahc, channel, ahc->our_id,
654 starget->id, &tstate);
655 }
656 ahc_compile_devinfo(&devinfo, our_id, starget->id,
657 CAM_LUN_WILDCARD, channel,
658 ROLE_INITIATOR);
659 ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0,
660 AHC_TRANS_GOAL, /*paused*/FALSE);
661 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
662 AHC_TRANS_GOAL, /*paused*/FALSE);
663 ahc_unlock(ahc, &flags);
664
665 return 0;
666}
667
668static void
669ahc_linux_target_destroy(struct scsi_target *starget)
670{
671 struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget);
672
673 *ahc_targp = NULL;
931} 674}
932 675
933static int 676static int
934ahc_linux_slave_configure(Scsi_Device *device) 677ahc_linux_slave_alloc(struct scsi_device *sdev)
935{ 678{
936 struct ahc_softc *ahc; 679 struct ahc_softc *ahc =
937 struct ahc_linux_device *dev; 680 *((struct ahc_softc **)sdev->host->hostdata);
938 u_long flags; 681 struct scsi_target *starget = sdev->sdev_target;
682 struct ahc_linux_target *targ = scsi_transport_target_data(starget);
683 struct ahc_linux_device *dev;
939 684
940 ahc = *((struct ahc_softc **)device->host->hostdata);
941 if (bootverbose) 685 if (bootverbose)
942 printf("%s: Slave Configure %d\n", ahc_name(ahc), device->id); 686 printf("%s: Slave Alloc %d\n", ahc_name(ahc), sdev->id);
943 ahc_midlayer_entrypoint_lock(ahc, &flags); 687
688 BUG_ON(targ->sdev[sdev->lun] != NULL);
689
690 dev = scsi_transport_device_data(sdev);
691 memset(dev, 0, sizeof(*dev));
692
944 /* 693 /*
945 * Since Linux has attached to the device, configure 694 * We start out life using untagged
946 * it so we don't free and allocate the device 695 * transactions of which we allow one.
947 * structure on every command.
948 */ 696 */
949 dev = ahc_linux_get_device(ahc, device->channel, 697 dev->openings = 1;
950 device->id, device->lun,
951 /*alloc*/TRUE);
952 if (dev != NULL) {
953 dev->flags &= ~AHC_DEV_UNCONFIGURED;
954 dev->scsi_device = device;
955 ahc_linux_device_queue_depth(ahc, dev);
956 }
957 ahc_midlayer_entrypoint_unlock(ahc, &flags);
958 698
959 /* Initial Domain Validation */ 699 /*
960 if (!spi_initial_dv(device->sdev_target)) 700 * Set maxtags to 0. This will be changed if we
961 spi_dv_device(device); 701 * later determine that we are dealing with
702 * a tagged queuing capable device.
703 */
704 dev->maxtags = 0;
705
706 targ->sdev[sdev->lun] = sdev;
962 707
963 return (0); 708 return 0;
964} 709}
965 710
966static void 711static int
967ahc_linux_slave_destroy(Scsi_Device *device) 712ahc_linux_slave_configure(struct scsi_device *sdev)
968{ 713{
969 struct ahc_softc *ahc; 714 struct ahc_softc *ahc;
970 struct ahc_linux_device *dev;
971 u_long flags;
972 715
973 ahc = *((struct ahc_softc **)device->host->hostdata); 716 ahc = *((struct ahc_softc **)sdev->host->hostdata);
717
974 if (bootverbose) 718 if (bootverbose)
975 printf("%s: Slave Destroy %d\n", ahc_name(ahc), device->id); 719 printf("%s: Slave Configure %d\n", ahc_name(ahc), sdev->id);
976 ahc_midlayer_entrypoint_lock(ahc, &flags); 720
977 dev = ahc_linux_get_device(ahc, device->channel, 721 ahc_linux_device_queue_depth(sdev);
978 device->id, device->lun, 722
979 /*alloc*/FALSE); 723 /* Initial Domain Validation */
980 /* 724 if (!spi_initial_dv(sdev->sdev_target))
981 * Filter out "silly" deletions of real devices by only 725 spi_dv_device(sdev);
982 * deleting devices that have had slave_configure() 726
983 * called on them. All other devices that have not 727 return 0;
984 * been configured will automatically be deleted by
985 * the refcounting process.
986 */
987 if (dev != NULL
988 && (dev->flags & AHC_DEV_SLAVE_CONFIGURED) != 0) {
989 dev->flags |= AHC_DEV_UNCONFIGURED;
990 if (TAILQ_EMPTY(&dev->busyq)
991 && dev->active == 0
992 && (dev->flags & AHC_DEV_TIMER_ACTIVE) == 0)
993 ahc_linux_free_device(ahc, dev);
994 }
995 ahc_midlayer_entrypoint_unlock(ahc, &flags);
996} 728}
997#else 729
998/*
999 * Sets the queue depth for each SCSI device hanging
1000 * off the input host adapter.
1001 */
1002static void 730static void
1003ahc_linux_select_queue_depth(struct Scsi_Host *host, Scsi_Device *scsi_devs) 731ahc_linux_slave_destroy(struct scsi_device *sdev)
1004{ 732{
1005 Scsi_Device *device;
1006 Scsi_Device *ldev;
1007 struct ahc_softc *ahc; 733 struct ahc_softc *ahc;
1008 u_long flags; 734 struct ahc_linux_device *dev = scsi_transport_device_data(sdev);
1009 735 struct ahc_linux_target *targ = scsi_transport_target_data(sdev->sdev_target);
1010 ahc = *((struct ahc_softc **)host->hostdata);
1011 ahc_lock(ahc, &flags);
1012 for (device = scsi_devs; device != NULL; device = device->next) {
1013 736
1014 /* 737 ahc = *((struct ahc_softc **)sdev->host->hostdata);
1015 * Watch out for duplicate devices. This works around 738 if (bootverbose)
1016 * some quirks in how the SCSI scanning code does its 739 printf("%s: Slave Destroy %d\n", ahc_name(ahc), sdev->id);
1017 * device management.
1018 */
1019 for (ldev = scsi_devs; ldev != device; ldev = ldev->next) {
1020 if (ldev->host == device->host
1021 && ldev->channel == device->channel
1022 && ldev->id == device->id
1023 && ldev->lun == device->lun)
1024 break;
1025 }
1026 /* Skip duplicate. */
1027 if (ldev != device)
1028 continue;
1029 740
1030 if (device->host == host) { 741 BUG_ON(dev->active);
1031 struct ahc_linux_device *dev;
1032 742
1033 /* 743 targ->sdev[sdev->lun] = NULL;
1034 * Since Linux has attached to the device, configure
1035 * it so we don't free and allocate the device
1036 * structure on every command.
1037 */
1038 dev = ahc_linux_get_device(ahc, device->channel,
1039 device->id, device->lun,
1040 /*alloc*/TRUE);
1041 if (dev != NULL) {
1042 dev->flags &= ~AHC_DEV_UNCONFIGURED;
1043 dev->scsi_device = device;
1044 ahc_linux_device_queue_depth(ahc, dev);
1045 device->queue_depth = dev->openings
1046 + dev->active;
1047 if ((dev->flags & (AHC_DEV_Q_BASIC
1048 | AHC_DEV_Q_TAGGED)) == 0) {
1049 /*
1050 * We allow the OS to queue 2 untagged
1051 * transactions to us at any time even
1052 * though we can only execute them
1053 * serially on the controller/device.
1054 * This should remove some latency.
1055 */
1056 device->queue_depth = 2;
1057 }
1058 }
1059 }
1060 }
1061 ahc_unlock(ahc, &flags);
1062} 744}
1063#endif
1064 745
1065#if defined(__i386__) 746#if defined(__i386__)
1066/* 747/*
1067 * Return the disk geometry for the given SCSI device. 748 * Return the disk geometry for the given SCSI device.
1068 */ 749 */
1069static int 750static int
1070#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1071ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev, 751ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1072 sector_t capacity, int geom[]) 752 sector_t capacity, int geom[])
1073{ 753{
1074 uint8_t *bh; 754 uint8_t *bh;
1075#else
1076ahc_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
1077{
1078 struct scsi_device *sdev = disk->device;
1079 u_long capacity = disk->capacity;
1080 struct buffer_head *bh;
1081#endif
1082 int heads; 755 int heads;
1083 int sectors; 756 int sectors;
1084 int cylinders; 757 int cylinders;
@@ -1090,22 +763,11 @@ ahc_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
1090 ahc = *((struct ahc_softc **)sdev->host->hostdata); 763 ahc = *((struct ahc_softc **)sdev->host->hostdata);
1091 channel = sdev->channel; 764 channel = sdev->channel;
1092 765
1093#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1094 bh = scsi_bios_ptable(bdev); 766 bh = scsi_bios_ptable(bdev);
1095#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,17)
1096 bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, block_size(dev));
1097#else
1098 bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, 1024);
1099#endif
1100
1101 if (bh) { 767 if (bh) {
1102 ret = scsi_partsize(bh, capacity, 768 ret = scsi_partsize(bh, capacity,
1103 &geom[2], &geom[0], &geom[1]); 769 &geom[2], &geom[0], &geom[1]);
1104#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1105 kfree(bh); 770 kfree(bh);
1106#else
1107 brelse(bh);
1108#endif
1109 if (ret != -1) 771 if (ret != -1)
1110 return (ret); 772 return (ret);
1111 } 773 }
@@ -1135,7 +797,7 @@ ahc_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
1135 * Abort the current SCSI command(s). 797 * Abort the current SCSI command(s).
1136 */ 798 */
1137static int 799static int
1138ahc_linux_abort(Scsi_Cmnd *cmd) 800ahc_linux_abort(struct scsi_cmnd *cmd)
1139{ 801{
1140 int error; 802 int error;
1141 803
@@ -1149,7 +811,7 @@ ahc_linux_abort(Scsi_Cmnd *cmd)
1149 * Attempt to send a target reset message to the device that timed out. 811 * Attempt to send a target reset message to the device that timed out.
1150 */ 812 */
1151static int 813static int
1152ahc_linux_dev_reset(Scsi_Cmnd *cmd) 814ahc_linux_dev_reset(struct scsi_cmnd *cmd)
1153{ 815{
1154 int error; 816 int error;
1155 817
@@ -1163,18 +825,18 @@ ahc_linux_dev_reset(Scsi_Cmnd *cmd)
1163 * Reset the SCSI bus. 825 * Reset the SCSI bus.
1164 */ 826 */
1165static int 827static int
1166ahc_linux_bus_reset(Scsi_Cmnd *cmd) 828ahc_linux_bus_reset(struct scsi_cmnd *cmd)
1167{ 829{
1168 struct ahc_softc *ahc; 830 struct ahc_softc *ahc;
1169 u_long s;
1170 int found; 831 int found;
832 unsigned long flags;
1171 833
1172 ahc = *(struct ahc_softc **)cmd->device->host->hostdata; 834 ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
1173 ahc_midlayer_entrypoint_lock(ahc, &s); 835
836 ahc_lock(ahc, &flags);
1174 found = ahc_reset_channel(ahc, cmd->device->channel + 'A', 837 found = ahc_reset_channel(ahc, cmd->device->channel + 'A',
1175 /*initiate reset*/TRUE); 838 /*initiate reset*/TRUE);
1176 ahc_linux_run_complete_queue(ahc); 839 ahc_unlock(ahc, &flags);
1177 ahc_midlayer_entrypoint_unlock(ahc, &s);
1178 840
1179 if (bootverbose) 841 if (bootverbose)
1180 printf("%s: SCSI bus reset delivered. " 842 printf("%s: SCSI bus reset delivered. "
@@ -1183,7 +845,7 @@ ahc_linux_bus_reset(Scsi_Cmnd *cmd)
1183 return SUCCESS; 845 return SUCCESS;
1184} 846}
1185 847
1186Scsi_Host_Template aic7xxx_driver_template = { 848struct scsi_host_template aic7xxx_driver_template = {
1187 .module = THIS_MODULE, 849 .module = THIS_MODULE,
1188 .name = "aic7xxx", 850 .name = "aic7xxx",
1189 .proc_info = ahc_linux_proc_info, 851 .proc_info = ahc_linux_proc_info,
@@ -1202,37 +864,12 @@ Scsi_Host_Template aic7xxx_driver_template = {
1202 .slave_alloc = ahc_linux_slave_alloc, 864 .slave_alloc = ahc_linux_slave_alloc,
1203 .slave_configure = ahc_linux_slave_configure, 865 .slave_configure = ahc_linux_slave_configure,
1204 .slave_destroy = ahc_linux_slave_destroy, 866 .slave_destroy = ahc_linux_slave_destroy,
867 .target_alloc = ahc_linux_target_alloc,
868 .target_destroy = ahc_linux_target_destroy,
1205}; 869};
1206 870
1207/**************************** Tasklet Handler *********************************/ 871/**************************** Tasklet Handler *********************************/
1208 872
1209/*
1210 * In 2.4.X and above, this routine is called from a tasklet,
1211 * so we must re-acquire our lock prior to executing this code.
1212 * In all prior kernels, ahc_schedule_runq() calls this routine
1213 * directly and ahc_schedule_runq() is called with our lock held.
1214 */
1215static void
1216ahc_runq_tasklet(unsigned long data)
1217{
1218 struct ahc_softc* ahc;
1219 struct ahc_linux_device *dev;
1220 u_long flags;
1221
1222 ahc = (struct ahc_softc *)data;
1223 ahc_lock(ahc, &flags);
1224 while ((dev = ahc_linux_next_device_to_run(ahc)) != NULL) {
1225
1226 TAILQ_REMOVE(&ahc->platform_data->device_runq, dev, links);
1227 dev->flags &= ~AHC_DEV_ON_RUN_LIST;
1228 ahc_linux_check_device_queue(ahc, dev);
1229 /* Yeild to our interrupt handler */
1230 ahc_unlock(ahc, &flags);
1231 ahc_lock(ahc, &flags);
1232 }
1233 ahc_unlock(ahc, &flags);
1234}
1235
1236/******************************** Macros **************************************/ 873/******************************** Macros **************************************/
1237#define BUILD_SCSIID(ahc, cmd) \ 874#define BUILD_SCSIID(ahc, cmd) \
1238 ((((cmd)->device->id << TID_SHIFT) & TID) \ 875 ((((cmd)->device->id << TID_SHIFT) & TID) \
@@ -1278,37 +915,11 @@ int
1278ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr, 915ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr,
1279 int flags, bus_dmamap_t *mapp) 916 int flags, bus_dmamap_t *mapp)
1280{ 917{
1281 bus_dmamap_t map;
1282
1283 map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT);
1284 if (map == NULL)
1285 return (ENOMEM);
1286 /*
1287 * Although we can dma data above 4GB, our
1288 * "consistent" memory is below 4GB for
1289 * space efficiency reasons (only need a 4byte
1290 * address). For this reason, we have to reset
1291 * our dma mask when doing allocations.
1292 */
1293 if (ahc->dev_softc != NULL)
1294 if (pci_set_dma_mask(ahc->dev_softc, 0xFFFFFFFF)) {
1295 printk(KERN_WARNING "aic7xxx: No suitable DMA available.\n");
1296 kfree(map);
1297 return (ENODEV);
1298 }
1299 *vaddr = pci_alloc_consistent(ahc->dev_softc, 918 *vaddr = pci_alloc_consistent(ahc->dev_softc,
1300 dmat->maxsize, &map->bus_addr); 919 dmat->maxsize, mapp);
1301 if (ahc->dev_softc != NULL)
1302 if (pci_set_dma_mask(ahc->dev_softc,
1303 ahc->platform_data->hw_dma_mask)) {
1304 printk(KERN_WARNING "aic7xxx: No suitable DMA available.\n");
1305 kfree(map);
1306 return (ENODEV);
1307 }
1308 if (*vaddr == NULL) 920 if (*vaddr == NULL)
1309 return (ENOMEM); 921 return ENOMEM;
1310 *mapp = map; 922 return 0;
1311 return(0);
1312} 923}
1313 924
1314void 925void
@@ -1316,7 +927,7 @@ ahc_dmamem_free(struct ahc_softc *ahc, bus_dma_tag_t dmat,
1316 void* vaddr, bus_dmamap_t map) 927 void* vaddr, bus_dmamap_t map)
1317{ 928{
1318 pci_free_consistent(ahc->dev_softc, dmat->maxsize, 929 pci_free_consistent(ahc->dev_softc, dmat->maxsize,
1319 vaddr, map->bus_addr); 930 vaddr, map);
1320} 931}
1321 932
1322int 933int
@@ -1330,7 +941,7 @@ ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map,
1330 */ 941 */
1331 bus_dma_segment_t stack_sg; 942 bus_dma_segment_t stack_sg;
1332 943
1333 stack_sg.ds_addr = map->bus_addr; 944 stack_sg.ds_addr = map;
1334 stack_sg.ds_len = dmat->maxsize; 945 stack_sg.ds_len = dmat->maxsize;
1335 cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0); 946 cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
1336 return (0); 947 return (0);
@@ -1339,12 +950,6 @@ ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map,
1339void 950void
1340ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map) 951ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
1341{ 952{
1342 /*
1343 * The map may is NULL in our < 2.3.X implementation.
1344 * Now it's 2.6.5, but just in case...
1345 */
1346 BUG_ON(map == NULL);
1347 free(map, M_DEVBUF);
1348} 953}
1349 954
1350int 955int
@@ -1499,8 +1104,6 @@ aic7xxx_setup(char *s)
1499 { "debug", &ahc_debug }, 1104 { "debug", &ahc_debug },
1500#endif 1105#endif
1501 { "reverse_scan", &aic7xxx_reverse_scan }, 1106 { "reverse_scan", &aic7xxx_reverse_scan },
1502 { "no_probe", &aic7xxx_probe_eisa_vl },
1503 { "probe_eisa_vl", &aic7xxx_probe_eisa_vl },
1504 { "periodic_otag", &aic7xxx_periodic_otag }, 1107 { "periodic_otag", &aic7xxx_periodic_otag },
1505 { "pci_parity", &aic7xxx_pci_parity }, 1108 { "pci_parity", &aic7xxx_pci_parity },
1506 { "seltime", &aic7xxx_seltime }, 1109 { "seltime", &aic7xxx_seltime },
@@ -1550,7 +1153,7 @@ __setup("aic7xxx=", aic7xxx_setup);
1550uint32_t aic7xxx_verbose; 1153uint32_t aic7xxx_verbose;
1551 1154
1552int 1155int
1553ahc_linux_register_host(struct ahc_softc *ahc, Scsi_Host_Template *template) 1156ahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *template)
1554{ 1157{
1555 char buf[80]; 1158 char buf[80];
1556 struct Scsi_Host *host; 1159 struct Scsi_Host *host;
@@ -1564,11 +1167,7 @@ ahc_linux_register_host(struct ahc_softc *ahc, Scsi_Host_Template *template)
1564 1167
1565 *((struct ahc_softc **)host->hostdata) = ahc; 1168 *((struct ahc_softc **)host->hostdata) = ahc;
1566 ahc_lock(ahc, &s); 1169 ahc_lock(ahc, &s);
1567#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1568 scsi_assign_lock(host, &ahc->platform_data->spin_lock); 1170 scsi_assign_lock(host, &ahc->platform_data->spin_lock);
1569#elif AHC_SCSI_HAS_HOST_LOCK != 0
1570 host->lock = &ahc->platform_data->spin_lock;
1571#endif
1572 ahc->platform_data->host = host; 1171 ahc->platform_data->host = host;
1573 host->can_queue = AHC_MAX_QUEUE; 1172 host->can_queue = AHC_MAX_QUEUE;
1574 host->cmd_per_lun = 2; 1173 host->cmd_per_lun = 2;
@@ -1587,19 +1186,14 @@ ahc_linux_register_host(struct ahc_softc *ahc, Scsi_Host_Template *template)
1587 ahc_set_name(ahc, new_name); 1186 ahc_set_name(ahc, new_name);
1588 } 1187 }
1589 host->unique_id = ahc->unit; 1188 host->unique_id = ahc->unit;
1590#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1591 scsi_set_pci_device(host, ahc->dev_softc);
1592#endif
1593 ahc_linux_initialize_scsi_bus(ahc); 1189 ahc_linux_initialize_scsi_bus(ahc);
1594 ahc_intr_enable(ahc, TRUE); 1190 ahc_intr_enable(ahc, TRUE);
1595 ahc_unlock(ahc, &s); 1191 ahc_unlock(ahc, &s);
1596 1192
1597 host->transportt = ahc_linux_transport_template; 1193 host->transportt = ahc_linux_transport_template;
1598 1194
1599#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1600 scsi_add_host(host, (ahc->dev_softc ? &ahc->dev_softc->dev : NULL)); /* XXX handle failure */ 1195 scsi_add_host(host, (ahc->dev_softc ? &ahc->dev_softc->dev : NULL)); /* XXX handle failure */
1601 scsi_scan_host(host); 1196 scsi_scan_host(host);
1602#endif
1603 return (0); 1197 return (0);
1604} 1198}
1605 1199
@@ -1717,19 +1311,9 @@ ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
1717 if (ahc->platform_data == NULL) 1311 if (ahc->platform_data == NULL)
1718 return (ENOMEM); 1312 return (ENOMEM);
1719 memset(ahc->platform_data, 0, sizeof(struct ahc_platform_data)); 1313 memset(ahc->platform_data, 0, sizeof(struct ahc_platform_data));
1720 TAILQ_INIT(&ahc->platform_data->completeq);
1721 TAILQ_INIT(&ahc->platform_data->device_runq);
1722 ahc->platform_data->irq = AHC_LINUX_NOIRQ; 1314 ahc->platform_data->irq = AHC_LINUX_NOIRQ;
1723 ahc->platform_data->hw_dma_mask = 0xFFFFFFFF;
1724 ahc_lockinit(ahc); 1315 ahc_lockinit(ahc);
1725 ahc_done_lockinit(ahc);
1726 init_timer(&ahc->platform_data->completeq_timer);
1727 ahc->platform_data->completeq_timer.data = (u_long)ahc;
1728 ahc->platform_data->completeq_timer.function =
1729 (ahc_linux_callback_t *)ahc_linux_thread_run_complete_queue;
1730 init_MUTEX_LOCKED(&ahc->platform_data->eh_sem); 1316 init_MUTEX_LOCKED(&ahc->platform_data->eh_sem);
1731 tasklet_init(&ahc->platform_data->runq_tasklet, ahc_runq_tasklet,
1732 (unsigned long)ahc);
1733 ahc->seltime = (aic7xxx_seltime & 0x3) << 4; 1317 ahc->seltime = (aic7xxx_seltime & 0x3) << 4;
1734 ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4; 1318 ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4;
1735 if (aic7xxx_pci_parity == 0) 1319 if (aic7xxx_pci_parity == 0)
@@ -1741,38 +1325,28 @@ ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
1741void 1325void
1742ahc_platform_free(struct ahc_softc *ahc) 1326ahc_platform_free(struct ahc_softc *ahc)
1743{ 1327{
1744 struct ahc_linux_target *targ; 1328 struct scsi_target *starget;
1745 struct ahc_linux_device *dev;
1746 int i, j; 1329 int i, j;
1747 1330
1748 if (ahc->platform_data != NULL) { 1331 if (ahc->platform_data != NULL) {
1749 del_timer_sync(&ahc->platform_data->completeq_timer);
1750 tasklet_kill(&ahc->platform_data->runq_tasklet);
1751 if (ahc->platform_data->host != NULL) { 1332 if (ahc->platform_data->host != NULL) {
1752#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1753 scsi_remove_host(ahc->platform_data->host); 1333 scsi_remove_host(ahc->platform_data->host);
1754#endif
1755 scsi_host_put(ahc->platform_data->host); 1334 scsi_host_put(ahc->platform_data->host);
1756 } 1335 }
1757 1336
1758 /* destroy all of the device and target objects */ 1337 /* destroy all of the device and target objects */
1759 for (i = 0; i < AHC_NUM_TARGETS; i++) { 1338 for (i = 0; i < AHC_NUM_TARGETS; i++) {
1760 targ = ahc->platform_data->targets[i]; 1339 starget = ahc->platform_data->starget[i];
1761 if (targ != NULL) { 1340 if (starget != NULL) {
1762 /* Keep target around through the loop. */
1763 targ->refcount++;
1764 for (j = 0; j < AHC_NUM_LUNS; j++) { 1341 for (j = 0; j < AHC_NUM_LUNS; j++) {
1342 struct ahc_linux_target *targ =
1343 scsi_transport_target_data(starget);
1765 1344
1766 if (targ->devices[j] == NULL) 1345 if (targ->sdev[j] == NULL)
1767 continue; 1346 continue;
1768 dev = targ->devices[j]; 1347 targ->sdev[j] = NULL;
1769 ahc_linux_free_device(ahc, dev);
1770 } 1348 }
1771 /* 1349 ahc->platform_data->starget[i] = NULL;
1772 * Forcibly free the target now that
1773 * all devices are gone.
1774 */
1775 ahc_linux_free_target(ahc, targ);
1776 } 1350 }
1777 } 1351 }
1778 1352
@@ -1787,16 +1361,7 @@ ahc_platform_free(struct ahc_softc *ahc)
1787 release_mem_region(ahc->platform_data->mem_busaddr, 1361 release_mem_region(ahc->platform_data->mem_busaddr,
1788 0x1000); 1362 0x1000);
1789 } 1363 }
1790#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 1364
1791 /*
1792 * In 2.4 we detach from the scsi midlayer before the PCI
1793 * layer invokes our remove callback. No per-instance
1794 * detach is provided, so we must reach inside the PCI
1795 * subsystem's internals and detach our driver manually.
1796 */
1797 if (ahc->dev_softc != NULL)
1798 ahc->dev_softc->driver = NULL;
1799#endif
1800 free(ahc->platform_data, M_DEVBUF); 1365 free(ahc->platform_data, M_DEVBUF);
1801 } 1366 }
1802} 1367}
@@ -1814,15 +1379,25 @@ void
1814ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, 1379ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1815 ahc_queue_alg alg) 1380 ahc_queue_alg alg)
1816{ 1381{
1382 struct scsi_target *starget;
1383 struct ahc_linux_target *targ;
1817 struct ahc_linux_device *dev; 1384 struct ahc_linux_device *dev;
1385 struct scsi_device *sdev;
1386 u_int target_offset;
1818 int was_queuing; 1387 int was_queuing;
1819 int now_queuing; 1388 int now_queuing;
1820 1389
1821 dev = ahc_linux_get_device(ahc, devinfo->channel - 'A', 1390 target_offset = devinfo->target;
1822 devinfo->target, 1391 if (devinfo->channel != 'A')
1823 devinfo->lun, /*alloc*/FALSE); 1392 target_offset += 8;
1824 if (dev == NULL) 1393 starget = ahc->platform_data->starget[target_offset];
1394 targ = scsi_transport_target_data(starget);
1395 BUG_ON(targ == NULL);
1396 sdev = targ->sdev[devinfo->lun];
1397 if (sdev == NULL)
1825 return; 1398 return;
1399 dev = scsi_transport_device_data(sdev);
1400
1826 was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED); 1401 was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED);
1827 switch (alg) { 1402 switch (alg) {
1828 default: 1403 default:
@@ -1873,116 +1448,36 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1873 dev->maxtags = 0; 1448 dev->maxtags = 0;
1874 dev->openings = 1 - dev->active; 1449 dev->openings = 1 - dev->active;
1875 } 1450 }
1876#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 1451 switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) {
1877 if (dev->scsi_device != NULL) { 1452 case AHC_DEV_Q_BASIC:
1878 switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) { 1453 scsi_adjust_queue_depth(sdev,
1879 case AHC_DEV_Q_BASIC: 1454 MSG_SIMPLE_TASK,
1880 scsi_adjust_queue_depth(dev->scsi_device, 1455 dev->openings + dev->active);
1881 MSG_SIMPLE_TASK, 1456 break;
1882 dev->openings + dev->active); 1457 case AHC_DEV_Q_TAGGED:
1883 break; 1458 scsi_adjust_queue_depth(sdev,
1884 case AHC_DEV_Q_TAGGED: 1459 MSG_ORDERED_TASK,
1885 scsi_adjust_queue_depth(dev->scsi_device, 1460 dev->openings + dev->active);
1886 MSG_ORDERED_TASK, 1461 break;
1887 dev->openings + dev->active); 1462 default:
1888 break; 1463 /*
1889 default: 1464 * We allow the OS to queue 2 untagged transactions to
1890 /* 1465 * us at any time even though we can only execute them
1891 * We allow the OS to queue 2 untagged transactions to 1466 * serially on the controller/device. This should
1892 * us at any time even though we can only execute them 1467 * remove some latency.
1893 * serially on the controller/device. This should 1468 */
1894 * remove some latency. 1469 scsi_adjust_queue_depth(sdev,
1895 */ 1470 /*NON-TAGGED*/0,
1896 scsi_adjust_queue_depth(dev->scsi_device, 1471 /*queue depth*/2);
1897 /*NON-TAGGED*/0, 1472 break;
1898 /*queue depth*/2);
1899 break;
1900 }
1901 } 1473 }
1902#endif
1903} 1474}
1904 1475
1905int 1476int
1906ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, char channel, 1477ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, char channel,
1907 int lun, u_int tag, role_t role, uint32_t status) 1478 int lun, u_int tag, role_t role, uint32_t status)
1908{ 1479{
1909 int chan; 1480 return 0;
1910 int maxchan;
1911 int targ;
1912 int maxtarg;
1913 int clun;
1914 int maxlun;
1915 int count;
1916
1917 if (tag != SCB_LIST_NULL)
1918 return (0);
1919
1920 chan = 0;
1921 if (channel != ALL_CHANNELS) {
1922 chan = channel - 'A';
1923 maxchan = chan + 1;
1924 } else {
1925 maxchan = (ahc->features & AHC_TWIN) ? 2 : 1;
1926 }
1927 targ = 0;
1928 if (target != CAM_TARGET_WILDCARD) {
1929 targ = target;
1930 maxtarg = targ + 1;
1931 } else {
1932 maxtarg = (ahc->features & AHC_WIDE) ? 16 : 8;
1933 }
1934 clun = 0;
1935 if (lun != CAM_LUN_WILDCARD) {
1936 clun = lun;
1937 maxlun = clun + 1;
1938 } else {
1939 maxlun = AHC_NUM_LUNS;
1940 }
1941
1942 count = 0;
1943 for (; chan < maxchan; chan++) {
1944
1945 for (; targ < maxtarg; targ++) {
1946
1947 for (; clun < maxlun; clun++) {
1948 struct ahc_linux_device *dev;
1949 struct ahc_busyq *busyq;
1950 struct ahc_cmd *acmd;
1951
1952 dev = ahc_linux_get_device(ahc, chan,
1953 targ, clun,
1954 /*alloc*/FALSE);
1955 if (dev == NULL)
1956 continue;
1957
1958 busyq = &dev->busyq;
1959 while ((acmd = TAILQ_FIRST(busyq)) != NULL) {
1960 Scsi_Cmnd *cmd;
1961
1962 cmd = &acmd_scsi_cmd(acmd);
1963 TAILQ_REMOVE(busyq, acmd,
1964 acmd_links.tqe);
1965 count++;
1966 cmd->result = status << 16;
1967 ahc_linux_queue_cmd_complete(ahc, cmd);
1968 }
1969 }
1970 }
1971 }
1972
1973 return (count);
1974}
1975
1976static void
1977ahc_linux_thread_run_complete_queue(struct ahc_softc *ahc)
1978{
1979 u_long flags;
1980
1981 ahc_lock(ahc, &flags);
1982 del_timer(&ahc->platform_data->completeq_timer);
1983 ahc->platform_data->flags &= ~AHC_RUN_CMPLT_Q_TIMER;
1984 ahc_linux_run_complete_queue(ahc);
1985 ahc_unlock(ahc, &flags);
1986} 1481}
1987 1482
1988static u_int 1483static u_int
@@ -2020,22 +1515,20 @@ ahc_linux_user_tagdepth(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2020 * Determines the queue depth for a given device. 1515 * Determines the queue depth for a given device.
2021 */ 1516 */
2022static void 1517static void
2023ahc_linux_device_queue_depth(struct ahc_softc *ahc, 1518ahc_linux_device_queue_depth(struct scsi_device *sdev)
2024 struct ahc_linux_device *dev)
2025{ 1519{
2026 struct ahc_devinfo devinfo; 1520 struct ahc_devinfo devinfo;
2027 u_int tags; 1521 u_int tags;
1522 struct ahc_softc *ahc = *((struct ahc_softc **)sdev->host->hostdata);
2028 1523
2029 ahc_compile_devinfo(&devinfo, 1524 ahc_compile_devinfo(&devinfo,
2030 dev->target->channel == 0 1525 sdev->sdev_target->channel == 0
2031 ? ahc->our_id : ahc->our_id_b, 1526 ? ahc->our_id : ahc->our_id_b,
2032 dev->target->target, dev->lun, 1527 sdev->sdev_target->id, sdev->lun,
2033 dev->target->channel == 0 ? 'A' : 'B', 1528 sdev->sdev_target->channel == 0 ? 'A' : 'B',
2034 ROLE_INITIATOR); 1529 ROLE_INITIATOR);
2035 tags = ahc_linux_user_tagdepth(ahc, &devinfo); 1530 tags = ahc_linux_user_tagdepth(ahc, &devinfo);
2036 if (tags != 0 1531 if (tags != 0 && sdev->tagged_supported != 0) {
2037 && dev->scsi_device != NULL
2038 && dev->scsi_device->tagged_supported != 0) {
2039 1532
2040 ahc_set_tags(ahc, &devinfo, AHC_QUEUE_TAGGED); 1533 ahc_set_tags(ahc, &devinfo, AHC_QUEUE_TAGGED);
2041 ahc_print_devinfo(ahc, &devinfo); 1534 ahc_print_devinfo(ahc, &devinfo);
@@ -2045,213 +1538,199 @@ ahc_linux_device_queue_depth(struct ahc_softc *ahc,
2045 } 1538 }
2046} 1539}
2047 1540
2048static void 1541static int
2049ahc_linux_run_device_queue(struct ahc_softc *ahc, struct ahc_linux_device *dev) 1542ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev,
1543 struct scsi_cmnd *cmd)
2050{ 1544{
2051 struct ahc_cmd *acmd;
2052 struct scsi_cmnd *cmd;
2053 struct scb *scb; 1545 struct scb *scb;
2054 struct hardware_scb *hscb; 1546 struct hardware_scb *hscb;
2055 struct ahc_initiator_tinfo *tinfo; 1547 struct ahc_initiator_tinfo *tinfo;
2056 struct ahc_tmode_tstate *tstate; 1548 struct ahc_tmode_tstate *tstate;
2057 uint16_t mask; 1549 uint16_t mask;
1550 struct scb_tailq *untagged_q = NULL;
2058 1551
2059 if ((dev->flags & AHC_DEV_ON_RUN_LIST) != 0) 1552 /*
2060 panic("running device on run list"); 1553 * Schedule us to run later. The only reason we are not
1554 * running is because the whole controller Q is frozen.
1555 */
1556 if (ahc->platform_data->qfrozen != 0)
1557 return SCSI_MLQUEUE_HOST_BUSY;
2061 1558
2062 while ((acmd = TAILQ_FIRST(&dev->busyq)) != NULL 1559 /*
2063 && dev->openings > 0 && dev->qfrozen == 0) { 1560 * We only allow one untagged transaction
1561 * per target in the initiator role unless
1562 * we are storing a full busy target *lun*
1563 * table in SCB space.
1564 */
1565 if (!blk_rq_tagged(cmd->request)
1566 && (ahc->features & AHC_SCB_BTT) == 0) {
1567 int target_offset;
2064 1568
2065 /* 1569 target_offset = cmd->device->id + cmd->device->channel * 8;
2066 * Schedule us to run later. The only reason we are not 1570 untagged_q = &(ahc->untagged_queues[target_offset]);
2067 * running is because the whole controller Q is frozen. 1571 if (!TAILQ_EMPTY(untagged_q))
2068 */ 1572 /* if we're already executing an untagged command
2069 if (ahc->platform_data->qfrozen != 0) { 1573 * we're busy to another */
2070 TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, 1574 return SCSI_MLQUEUE_DEVICE_BUSY;
2071 dev, links); 1575 }
2072 dev->flags |= AHC_DEV_ON_RUN_LIST;
2073 return;
2074 }
2075 /*
2076 * Get an scb to use.
2077 */
2078 if ((scb = ahc_get_scb(ahc)) == NULL) {
2079 TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq,
2080 dev, links);
2081 dev->flags |= AHC_DEV_ON_RUN_LIST;
2082 ahc->flags |= AHC_RESOURCE_SHORTAGE;
2083 return;
2084 }
2085 TAILQ_REMOVE(&dev->busyq, acmd, acmd_links.tqe);
2086 cmd = &acmd_scsi_cmd(acmd);
2087 scb->io_ctx = cmd;
2088 scb->platform_data->dev = dev;
2089 hscb = scb->hscb;
2090 cmd->host_scribble = (char *)scb;
2091 1576
2092 /* 1577 /*
2093 * Fill out basics of the HSCB. 1578 * Get an scb to use.
2094 */ 1579 */
2095 hscb->control = 0; 1580 scb = ahc_get_scb(ahc);
2096 hscb->scsiid = BUILD_SCSIID(ahc, cmd); 1581 if (!scb)
2097 hscb->lun = cmd->device->lun; 1582 return SCSI_MLQUEUE_HOST_BUSY;
2098 mask = SCB_GET_TARGET_MASK(ahc, scb);
2099 tinfo = ahc_fetch_transinfo(ahc, SCB_GET_CHANNEL(ahc, scb),
2100 SCB_GET_OUR_ID(scb),
2101 SCB_GET_TARGET(ahc, scb), &tstate);
2102 hscb->scsirate = tinfo->scsirate;
2103 hscb->scsioffset = tinfo->curr.offset;
2104 if ((tstate->ultraenb & mask) != 0)
2105 hscb->control |= ULTRAENB;
2106
2107 if ((ahc->user_discenable & mask) != 0)
2108 hscb->control |= DISCENB;
2109
2110 if ((tstate->auto_negotiate & mask) != 0) {
2111 scb->flags |= SCB_AUTO_NEGOTIATE;
2112 scb->hscb->control |= MK_MESSAGE;
2113 }
2114 1583
2115 if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) { 1584 scb->io_ctx = cmd;
2116#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 1585 scb->platform_data->dev = dev;
2117 int msg_bytes; 1586 hscb = scb->hscb;
2118 uint8_t tag_msgs[2]; 1587 cmd->host_scribble = (char *)scb;
2119
2120 msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
2121 if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
2122 hscb->control |= tag_msgs[0];
2123 if (tag_msgs[0] == MSG_ORDERED_TASK)
2124 dev->commands_since_idle_or_otag = 0;
2125 } else
2126#endif
2127 if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH
2128 && (dev->flags & AHC_DEV_Q_TAGGED) != 0) {
2129 hscb->control |= MSG_ORDERED_TASK;
2130 dev->commands_since_idle_or_otag = 0;
2131 } else {
2132 hscb->control |= MSG_SIMPLE_TASK;
2133 }
2134 }
2135 1588
2136 hscb->cdb_len = cmd->cmd_len; 1589 /*
2137 if (hscb->cdb_len <= 12) { 1590 * Fill out basics of the HSCB.
2138 memcpy(hscb->shared_data.cdb, cmd->cmnd, hscb->cdb_len); 1591 */
1592 hscb->control = 0;
1593 hscb->scsiid = BUILD_SCSIID(ahc, cmd);
1594 hscb->lun = cmd->device->lun;
1595 mask = SCB_GET_TARGET_MASK(ahc, scb);
1596 tinfo = ahc_fetch_transinfo(ahc, SCB_GET_CHANNEL(ahc, scb),
1597 SCB_GET_OUR_ID(scb),
1598 SCB_GET_TARGET(ahc, scb), &tstate);
1599 hscb->scsirate = tinfo->scsirate;
1600 hscb->scsioffset = tinfo->curr.offset;
1601 if ((tstate->ultraenb & mask) != 0)
1602 hscb->control |= ULTRAENB;
1603
1604 if ((ahc->user_discenable & mask) != 0)
1605 hscb->control |= DISCENB;
1606
1607 if ((tstate->auto_negotiate & mask) != 0) {
1608 scb->flags |= SCB_AUTO_NEGOTIATE;
1609 scb->hscb->control |= MK_MESSAGE;
1610 }
1611
1612 if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) {
1613 int msg_bytes;
1614 uint8_t tag_msgs[2];
1615
1616 msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
1617 if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
1618 hscb->control |= tag_msgs[0];
1619 if (tag_msgs[0] == MSG_ORDERED_TASK)
1620 dev->commands_since_idle_or_otag = 0;
1621 } else if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH
1622 && (dev->flags & AHC_DEV_Q_TAGGED) != 0) {
1623 hscb->control |= MSG_ORDERED_TASK;
1624 dev->commands_since_idle_or_otag = 0;
2139 } else { 1625 } else {
2140 memcpy(hscb->cdb32, cmd->cmnd, hscb->cdb_len); 1626 hscb->control |= MSG_SIMPLE_TASK;
2141 scb->flags |= SCB_CDB32_PTR;
2142 } 1627 }
1628 }
2143 1629
2144 scb->platform_data->xfer_len = 0; 1630 hscb->cdb_len = cmd->cmd_len;
2145 ahc_set_residual(scb, 0); 1631 if (hscb->cdb_len <= 12) {
2146 ahc_set_sense_residual(scb, 0); 1632 memcpy(hscb->shared_data.cdb, cmd->cmnd, hscb->cdb_len);
2147 scb->sg_count = 0; 1633 } else {
2148 if (cmd->use_sg != 0) { 1634 memcpy(hscb->cdb32, cmd->cmnd, hscb->cdb_len);
2149 struct ahc_dma_seg *sg; 1635 scb->flags |= SCB_CDB32_PTR;
2150 struct scatterlist *cur_seg; 1636 }
2151 struct scatterlist *end_seg;
2152 int nseg;
2153
2154 cur_seg = (struct scatterlist *)cmd->request_buffer;
2155 nseg = pci_map_sg(ahc->dev_softc, cur_seg, cmd->use_sg,
2156 cmd->sc_data_direction);
2157 end_seg = cur_seg + nseg;
2158 /* Copy the segments into the SG list. */
2159 sg = scb->sg_list;
2160 /*
2161 * The sg_count may be larger than nseg if
2162 * a transfer crosses a 32bit page.
2163 */
2164 while (cur_seg < end_seg) {
2165 dma_addr_t addr;
2166 bus_size_t len;
2167 int consumed;
2168
2169 addr = sg_dma_address(cur_seg);
2170 len = sg_dma_len(cur_seg);
2171 consumed = ahc_linux_map_seg(ahc, scb,
2172 sg, addr, len);
2173 sg += consumed;
2174 scb->sg_count += consumed;
2175 cur_seg++;
2176 }
2177 sg--;
2178 sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
2179
2180 /*
2181 * Reset the sg list pointer.
2182 */
2183 scb->hscb->sgptr =
2184 ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
2185 1637
2186 /* 1638 scb->platform_data->xfer_len = 0;
2187 * Copy the first SG into the "current" 1639 ahc_set_residual(scb, 0);
2188 * data pointer area. 1640 ahc_set_sense_residual(scb, 0);
2189 */ 1641 scb->sg_count = 0;
2190 scb->hscb->dataptr = scb->sg_list->addr; 1642 if (cmd->use_sg != 0) {
2191 scb->hscb->datacnt = scb->sg_list->len; 1643 struct ahc_dma_seg *sg;
2192 } else if (cmd->request_bufflen != 0) { 1644 struct scatterlist *cur_seg;
2193 struct ahc_dma_seg *sg; 1645 struct scatterlist *end_seg;
1646 int nseg;
1647
1648 cur_seg = (struct scatterlist *)cmd->request_buffer;
1649 nseg = pci_map_sg(ahc->dev_softc, cur_seg, cmd->use_sg,
1650 cmd->sc_data_direction);
1651 end_seg = cur_seg + nseg;
1652 /* Copy the segments into the SG list. */
1653 sg = scb->sg_list;
1654 /*
1655 * The sg_count may be larger than nseg if
1656 * a transfer crosses a 32bit page.
1657 */
1658 while (cur_seg < end_seg) {
2194 dma_addr_t addr; 1659 dma_addr_t addr;
2195 1660 bus_size_t len;
2196 sg = scb->sg_list; 1661 int consumed;
2197 addr = pci_map_single(ahc->dev_softc, 1662
2198 cmd->request_buffer, 1663 addr = sg_dma_address(cur_seg);
2199 cmd->request_bufflen, 1664 len = sg_dma_len(cur_seg);
2200 cmd->sc_data_direction); 1665 consumed = ahc_linux_map_seg(ahc, scb,
2201 scb->platform_data->buf_busaddr = addr; 1666 sg, addr, len);
2202 scb->sg_count = ahc_linux_map_seg(ahc, scb, 1667 sg += consumed;
2203 sg, addr, 1668 scb->sg_count += consumed;
2204 cmd->request_bufflen); 1669 cur_seg++;
2205 sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
2206
2207 /*
2208 * Reset the sg list pointer.
2209 */
2210 scb->hscb->sgptr =
2211 ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
2212
2213 /*
2214 * Copy the first SG into the "current"
2215 * data pointer area.
2216 */
2217 scb->hscb->dataptr = sg->addr;
2218 scb->hscb->datacnt = sg->len;
2219 } else {
2220 scb->hscb->sgptr = ahc_htole32(SG_LIST_NULL);
2221 scb->hscb->dataptr = 0;
2222 scb->hscb->datacnt = 0;
2223 scb->sg_count = 0;
2224 } 1670 }
1671 sg--;
1672 sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
1673
1674 /*
1675 * Reset the sg list pointer.
1676 */
1677 scb->hscb->sgptr =
1678 ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
1679
1680 /*
1681 * Copy the first SG into the "current"
1682 * data pointer area.
1683 */
1684 scb->hscb->dataptr = scb->sg_list->addr;
1685 scb->hscb->datacnt = scb->sg_list->len;
1686 } else if (cmd->request_bufflen != 0) {
1687 struct ahc_dma_seg *sg;
1688 dma_addr_t addr;
1689
1690 sg = scb->sg_list;
1691 addr = pci_map_single(ahc->dev_softc,
1692 cmd->request_buffer,
1693 cmd->request_bufflen,
1694 cmd->sc_data_direction);
1695 scb->platform_data->buf_busaddr = addr;
1696 scb->sg_count = ahc_linux_map_seg(ahc, scb,
1697 sg, addr,
1698 cmd->request_bufflen);
1699 sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
2225 1700
2226 ahc_sync_sglist(ahc, scb, BUS_DMASYNC_PREWRITE); 1701 /*
2227 LIST_INSERT_HEAD(&ahc->pending_scbs, scb, pending_links); 1702 * Reset the sg list pointer.
2228 dev->openings--; 1703 */
2229 dev->active++; 1704 scb->hscb->sgptr =
2230 dev->commands_issued++; 1705 ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
2231 if ((dev->flags & AHC_DEV_PERIODIC_OTAG) != 0)
2232 dev->commands_since_idle_or_otag++;
2233 1706
2234 /* 1707 /*
2235 * We only allow one untagged transaction 1708 * Copy the first SG into the "current"
2236 * per target in the initiator role unless 1709 * data pointer area.
2237 * we are storing a full busy target *lun*
2238 * table in SCB space.
2239 */ 1710 */
2240 if ((scb->hscb->control & (TARGET_SCB|TAG_ENB)) == 0 1711 scb->hscb->dataptr = sg->addr;
2241 && (ahc->features & AHC_SCB_BTT) == 0) { 1712 scb->hscb->datacnt = sg->len;
2242 struct scb_tailq *untagged_q; 1713 } else {
2243 int target_offset; 1714 scb->hscb->sgptr = ahc_htole32(SG_LIST_NULL);
2244 1715 scb->hscb->dataptr = 0;
2245 target_offset = SCB_GET_TARGET_OFFSET(ahc, scb); 1716 scb->hscb->datacnt = 0;
2246 untagged_q = &(ahc->untagged_queues[target_offset]); 1717 scb->sg_count = 0;
2247 TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe);
2248 scb->flags |= SCB_UNTAGGEDQ;
2249 if (TAILQ_FIRST(untagged_q) != scb)
2250 continue;
2251 }
2252 scb->flags |= SCB_ACTIVE;
2253 ahc_queue_scb(ahc, scb);
2254 } 1718 }
1719
1720 LIST_INSERT_HEAD(&ahc->pending_scbs, scb, pending_links);
1721 dev->openings--;
1722 dev->active++;
1723 dev->commands_issued++;
1724 if ((dev->flags & AHC_DEV_PERIODIC_OTAG) != 0)
1725 dev->commands_since_idle_or_otag++;
1726
1727 scb->flags |= SCB_ACTIVE;
1728 if (untagged_q) {
1729 TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe);
1730 scb->flags |= SCB_UNTAGGEDQ;
1731 }
1732 ahc_queue_scb(ahc, scb);
1733 return 0;
2255} 1734}
2256 1735
2257/* 1736/*
@@ -2267,9 +1746,6 @@ ahc_linux_isr(int irq, void *dev_id, struct pt_regs * regs)
2267 ahc = (struct ahc_softc *) dev_id; 1746 ahc = (struct ahc_softc *) dev_id;
2268 ahc_lock(ahc, &flags); 1747 ahc_lock(ahc, &flags);
2269 ours = ahc_intr(ahc); 1748 ours = ahc_intr(ahc);
2270 if (ahc_linux_next_device_to_run(ahc) != NULL)
2271 ahc_schedule_runq(ahc);
2272 ahc_linux_run_complete_queue(ahc);
2273 ahc_unlock(ahc, &flags); 1749 ahc_unlock(ahc, &flags);
2274 return IRQ_RETVAL(ours); 1750 return IRQ_RETVAL(ours);
2275} 1751}
@@ -2278,118 +1754,6 @@ void
2278ahc_platform_flushwork(struct ahc_softc *ahc) 1754ahc_platform_flushwork(struct ahc_softc *ahc)
2279{ 1755{
2280 1756
2281 while (ahc_linux_run_complete_queue(ahc) != NULL)
2282 ;
2283}
2284
2285static struct ahc_linux_target*
2286ahc_linux_alloc_target(struct ahc_softc *ahc, u_int channel, u_int target)
2287{
2288 struct ahc_linux_target *targ;
2289 u_int target_offset;
2290
2291 target_offset = target;
2292 if (channel != 0)
2293 target_offset += 8;
2294
2295 targ = malloc(sizeof(*targ), M_DEVBUG, M_NOWAIT);
2296 if (targ == NULL)
2297 return (NULL);
2298 memset(targ, 0, sizeof(*targ));
2299 targ->channel = channel;
2300 targ->target = target;
2301 targ->ahc = ahc;
2302 ahc->platform_data->targets[target_offset] = targ;
2303 return (targ);
2304}
2305
2306static void
2307ahc_linux_free_target(struct ahc_softc *ahc, struct ahc_linux_target *targ)
2308{
2309 struct ahc_devinfo devinfo;
2310 struct ahc_initiator_tinfo *tinfo;
2311 struct ahc_tmode_tstate *tstate;
2312 u_int our_id;
2313 u_int target_offset;
2314 char channel;
2315
2316 /*
2317 * Force a negotiation to async/narrow on any
2318 * future command to this device unless a bus
2319 * reset occurs between now and that command.
2320 */
2321 channel = 'A' + targ->channel;
2322 our_id = ahc->our_id;
2323 target_offset = targ->target;
2324 if (targ->channel != 0) {
2325 target_offset += 8;
2326 our_id = ahc->our_id_b;
2327 }
2328 tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
2329 targ->target, &tstate);
2330 ahc_compile_devinfo(&devinfo, our_id, targ->target, CAM_LUN_WILDCARD,
2331 channel, ROLE_INITIATOR);
2332 ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0,
2333 AHC_TRANS_GOAL, /*paused*/FALSE);
2334 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
2335 AHC_TRANS_GOAL, /*paused*/FALSE);
2336 ahc_update_neg_request(ahc, &devinfo, tstate, tinfo, AHC_NEG_ALWAYS);
2337 ahc->platform_data->targets[target_offset] = NULL;
2338 free(targ, M_DEVBUF);
2339}
2340
2341static struct ahc_linux_device*
2342ahc_linux_alloc_device(struct ahc_softc *ahc,
2343 struct ahc_linux_target *targ, u_int lun)
2344{
2345 struct ahc_linux_device *dev;
2346
2347 dev = malloc(sizeof(*dev), M_DEVBUG, M_NOWAIT);
2348 if (dev == NULL)
2349 return (NULL);
2350 memset(dev, 0, sizeof(*dev));
2351 init_timer(&dev->timer);
2352 TAILQ_INIT(&dev->busyq);
2353 dev->flags = AHC_DEV_UNCONFIGURED;
2354 dev->lun = lun;
2355 dev->target = targ;
2356
2357 /*
2358 * We start out life using untagged
2359 * transactions of which we allow one.
2360 */
2361 dev->openings = 1;
2362
2363 /*
2364 * Set maxtags to 0. This will be changed if we
2365 * later determine that we are dealing with
2366 * a tagged queuing capable device.
2367 */
2368 dev->maxtags = 0;
2369
2370 targ->refcount++;
2371 targ->devices[lun] = dev;
2372 return (dev);
2373}
2374
2375static void
2376__ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev)
2377{
2378 struct ahc_linux_target *targ;
2379
2380 targ = dev->target;
2381 targ->devices[dev->lun] = NULL;
2382 free(dev, M_DEVBUF);
2383 targ->refcount--;
2384 if (targ->refcount == 0)
2385 ahc_linux_free_target(ahc, targ);
2386}
2387
2388static void
2389ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev)
2390{
2391 del_timer_sync(&dev->timer);
2392 __ahc_linux_free_device(ahc, dev);
2393} 1757}
2394 1758
2395void 1759void
@@ -2400,11 +1764,15 @@ ahc_send_async(struct ahc_softc *ahc, char channel,
2400 case AC_TRANSFER_NEG: 1764 case AC_TRANSFER_NEG:
2401 { 1765 {
2402 char buf[80]; 1766 char buf[80];
1767 struct scsi_target *starget;
2403 struct ahc_linux_target *targ; 1768 struct ahc_linux_target *targ;
2404 struct info_str info; 1769 struct info_str info;
2405 struct ahc_initiator_tinfo *tinfo; 1770 struct ahc_initiator_tinfo *tinfo;
2406 struct ahc_tmode_tstate *tstate; 1771 struct ahc_tmode_tstate *tstate;
2407 int target_offset; 1772 int target_offset;
1773 unsigned int target_ppr_options;
1774
1775 BUG_ON(target == CAM_TARGET_WILDCARD);
2408 1776
2409 info.buffer = buf; 1777 info.buffer = buf;
2410 info.length = sizeof(buf); 1778 info.length = sizeof(buf);
@@ -2433,58 +1801,37 @@ ahc_send_async(struct ahc_softc *ahc, char channel,
2433 target_offset = target; 1801 target_offset = target;
2434 if (channel == 'B') 1802 if (channel == 'B')
2435 target_offset += 8; 1803 target_offset += 8;
2436 targ = ahc->platform_data->targets[target_offset]; 1804 starget = ahc->platform_data->starget[target_offset];
1805 targ = scsi_transport_target_data(starget);
2437 if (targ == NULL) 1806 if (targ == NULL)
2438 break; 1807 break;
2439 if (tinfo->curr.period == targ->last_tinfo.period 1808
2440 && tinfo->curr.width == targ->last_tinfo.width 1809 target_ppr_options =
2441 && tinfo->curr.offset == targ->last_tinfo.offset 1810 (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0)
2442 && tinfo->curr.ppr_options == targ->last_tinfo.ppr_options) 1811 + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0)
1812 + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0);
1813
1814 if (tinfo->curr.period == spi_period(starget)
1815 && tinfo->curr.width == spi_width(starget)
1816 && tinfo->curr.offset == spi_offset(starget)
1817 && tinfo->curr.ppr_options == target_ppr_options)
2443 if (bootverbose == 0) 1818 if (bootverbose == 0)
2444 break; 1819 break;
2445 1820
2446 targ->last_tinfo.period = tinfo->curr.period; 1821 spi_period(starget) = tinfo->curr.period;
2447 targ->last_tinfo.width = tinfo->curr.width; 1822 spi_width(starget) = tinfo->curr.width;
2448 targ->last_tinfo.offset = tinfo->curr.offset; 1823 spi_offset(starget) = tinfo->curr.offset;
2449 targ->last_tinfo.ppr_options = tinfo->curr.ppr_options; 1824 spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ;
2450 1825 spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ;
2451 printf("(%s:%c:", ahc_name(ahc), channel); 1826 spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ;
2452 if (target == CAM_TARGET_WILDCARD) 1827 spi_display_xfer_agreement(starget);
2453 printf("*): ");
2454 else
2455 printf("%d): ", target);
2456 ahc_format_transinfo(&info, &tinfo->curr);
2457 if (info.pos < info.length)
2458 *info.buffer = '\0';
2459 else
2460 buf[info.length - 1] = '\0';
2461 printf("%s", buf);
2462 break; 1828 break;
2463 } 1829 }
2464 case AC_SENT_BDR: 1830 case AC_SENT_BDR:
2465 { 1831 {
2466#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
2467 WARN_ON(lun != CAM_LUN_WILDCARD); 1832 WARN_ON(lun != CAM_LUN_WILDCARD);
2468 scsi_report_device_reset(ahc->platform_data->host, 1833 scsi_report_device_reset(ahc->platform_data->host,
2469 channel - 'A', target); 1834 channel - 'A', target);
2470#else
2471 Scsi_Device *scsi_dev;
2472
2473 /*
2474 * Find the SCSI device associated with this
2475 * request and indicate that a UA is expected.
2476 */
2477 for (scsi_dev = ahc->platform_data->host->host_queue;
2478 scsi_dev != NULL; scsi_dev = scsi_dev->next) {
2479 if (channel - 'A' == scsi_dev->channel
2480 && target == scsi_dev->id
2481 && (lun == CAM_LUN_WILDCARD
2482 || lun == scsi_dev->lun)) {
2483 scsi_dev->was_reset = 1;
2484 scsi_dev->expecting_cc_ua = 1;
2485 }
2486 }
2487#endif
2488 break; 1835 break;
2489 } 1836 }
2490 case AC_BUS_RESET: 1837 case AC_BUS_RESET:
@@ -2504,7 +1851,7 @@ ahc_send_async(struct ahc_softc *ahc, char channel,
2504void 1851void
2505ahc_done(struct ahc_softc *ahc, struct scb *scb) 1852ahc_done(struct ahc_softc *ahc, struct scb *scb)
2506{ 1853{
2507 Scsi_Cmnd *cmd; 1854 struct scsi_cmnd *cmd;
2508 struct ahc_linux_device *dev; 1855 struct ahc_linux_device *dev;
2509 1856
2510 LIST_REMOVE(scb, pending_links); 1857 LIST_REMOVE(scb, pending_links);
@@ -2515,7 +1862,7 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
2515 target_offset = SCB_GET_TARGET_OFFSET(ahc, scb); 1862 target_offset = SCB_GET_TARGET_OFFSET(ahc, scb);
2516 untagged_q = &(ahc->untagged_queues[target_offset]); 1863 untagged_q = &(ahc->untagged_queues[target_offset]);
2517 TAILQ_REMOVE(untagged_q, scb, links.tqe); 1864 TAILQ_REMOVE(untagged_q, scb, links.tqe);
2518 ahc_run_untagged_queue(ahc, untagged_q); 1865 BUG_ON(!TAILQ_EMPTY(untagged_q));
2519 } 1866 }
2520 1867
2521 if ((scb->flags & SCB_ACTIVE) == 0) { 1868 if ((scb->flags & SCB_ACTIVE) == 0) {
@@ -2582,9 +1929,7 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
2582 ahc_set_transaction_status(scb, CAM_REQ_CMP); 1929 ahc_set_transaction_status(scb, CAM_REQ_CMP);
2583 } 1930 }
2584 } else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) { 1931 } else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
2585 ahc_linux_handle_scsi_status(ahc, dev, scb); 1932 ahc_linux_handle_scsi_status(ahc, cmd->device, scb);
2586 } else if (ahc_get_transaction_status(scb) == CAM_SEL_TIMEOUT) {
2587 dev->flags |= AHC_DEV_UNCONFIGURED;
2588 } 1933 }
2589 1934
2590 if (dev->openings == 1 1935 if (dev->openings == 1
@@ -2606,16 +1951,6 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
2606 if (dev->active == 0) 1951 if (dev->active == 0)
2607 dev->commands_since_idle_or_otag = 0; 1952 dev->commands_since_idle_or_otag = 0;
2608 1953
2609 if (TAILQ_EMPTY(&dev->busyq)) {
2610 if ((dev->flags & AHC_DEV_UNCONFIGURED) != 0
2611 && dev->active == 0
2612 && (dev->flags & AHC_DEV_TIMER_ACTIVE) == 0)
2613 ahc_linux_free_device(ahc, dev);
2614 } else if ((dev->flags & AHC_DEV_ON_RUN_LIST) == 0) {
2615 TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, dev, links);
2616 dev->flags |= AHC_DEV_ON_RUN_LIST;
2617 }
2618
2619 if ((scb->flags & SCB_RECOVERY_SCB) != 0) { 1954 if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
2620 printf("Recovery SCB completes\n"); 1955 printf("Recovery SCB completes\n");
2621 if (ahc_get_transaction_status(scb) == CAM_BDR_SENT 1956 if (ahc_get_transaction_status(scb) == CAM_BDR_SENT
@@ -2633,14 +1968,15 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
2633 1968
2634static void 1969static void
2635ahc_linux_handle_scsi_status(struct ahc_softc *ahc, 1970ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
2636 struct ahc_linux_device *dev, struct scb *scb) 1971 struct scsi_device *sdev, struct scb *scb)
2637{ 1972{
2638 struct ahc_devinfo devinfo; 1973 struct ahc_devinfo devinfo;
1974 struct ahc_linux_device *dev = scsi_transport_device_data(sdev);
2639 1975
2640 ahc_compile_devinfo(&devinfo, 1976 ahc_compile_devinfo(&devinfo,
2641 ahc->our_id, 1977 ahc->our_id,
2642 dev->target->target, dev->lun, 1978 sdev->sdev_target->id, sdev->lun,
2643 dev->target->channel == 0 ? 'A' : 'B', 1979 sdev->sdev_target->channel == 0 ? 'A' : 'B',
2644 ROLE_INITIATOR); 1980 ROLE_INITIATOR);
2645 1981
2646 /* 1982 /*
@@ -2659,7 +1995,7 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
2659 case SCSI_STATUS_CHECK_COND: 1995 case SCSI_STATUS_CHECK_COND:
2660 case SCSI_STATUS_CMD_TERMINATED: 1996 case SCSI_STATUS_CMD_TERMINATED:
2661 { 1997 {
2662 Scsi_Cmnd *cmd; 1998 struct scsi_cmnd *cmd;
2663 1999
2664 /* 2000 /*
2665 * Copy sense information to the OS's cmd 2001 * Copy sense information to the OS's cmd
@@ -2754,52 +2090,15 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
2754 ahc_platform_set_tags(ahc, &devinfo, 2090 ahc_platform_set_tags(ahc, &devinfo,
2755 (dev->flags & AHC_DEV_Q_BASIC) 2091 (dev->flags & AHC_DEV_Q_BASIC)
2756 ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED); 2092 ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
2757 /* FALLTHROUGH */
2758 }
2759 case SCSI_STATUS_BUSY:
2760 {
2761 /*
2762 * Set a short timer to defer sending commands for
2763 * a bit since Linux will not delay in this case.
2764 */
2765 if ((dev->flags & AHC_DEV_TIMER_ACTIVE) != 0) {
2766 printf("%s:%c:%d: Device Timer still active during "
2767 "busy processing\n", ahc_name(ahc),
2768 dev->target->channel, dev->target->target);
2769 break;
2770 }
2771 dev->flags |= AHC_DEV_TIMER_ACTIVE;
2772 dev->qfrozen++;
2773 init_timer(&dev->timer);
2774 dev->timer.data = (u_long)dev;
2775 dev->timer.expires = jiffies + (HZ/2);
2776 dev->timer.function = ahc_linux_dev_timed_unfreeze;
2777 add_timer(&dev->timer);
2778 break; 2093 break;
2779 } 2094 }
2780 } 2095 }
2781} 2096}
2782 2097
2783static void 2098static void
2784ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, Scsi_Cmnd *cmd) 2099ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, struct scsi_cmnd *cmd)
2785{ 2100{
2786 /* 2101 /*
2787 * Typically, the complete queue has very few entries
2788 * queued to it before the queue is emptied by
2789 * ahc_linux_run_complete_queue, so sorting the entries
2790 * by generation number should be inexpensive.
2791 * We perform the sort so that commands that complete
2792 * with an error are retuned in the order origionally
2793 * queued to the controller so that any subsequent retries
2794 * are performed in order. The underlying ahc routines do
2795 * not guarantee the order that aborted commands will be
2796 * returned to us.
2797 */
2798 struct ahc_completeq *completeq;
2799 struct ahc_cmd *list_cmd;
2800 struct ahc_cmd *acmd;
2801
2802 /*
2803 * Map CAM error codes into Linux Error codes. We 2102 * Map CAM error codes into Linux Error codes. We
2804 * avoid the conversion so that the DV code has the 2103 * avoid the conversion so that the DV code has the
2805 * full error information available when making 2104 * full error information available when making
@@ -2852,26 +2151,7 @@ ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, Scsi_Cmnd *cmd)
2852 new_status = DID_ERROR; 2151 new_status = DID_ERROR;
2853 break; 2152 break;
2854 case CAM_REQUEUE_REQ: 2153 case CAM_REQUEUE_REQ:
2855 /* 2154 new_status = DID_REQUEUE;
2856 * If we want the request requeued, make sure there
2857 * are sufficent retries. In the old scsi error code,
2858 * we used to be able to specify a result code that
2859 * bypassed the retry count. Now we must use this
2860 * hack. We also "fake" a check condition with
2861 * a sense code of ABORTED COMMAND. This seems to
2862 * evoke a retry even if this command is being sent
2863 * via the eh thread. Ick! Ick! Ick!
2864 */
2865 if (cmd->retries > 0)
2866 cmd->retries--;
2867 new_status = DID_OK;
2868 ahc_cmd_set_scsi_status(cmd, SCSI_STATUS_CHECK_COND);
2869 cmd->result |= (DRIVER_SENSE << 24);
2870 memset(cmd->sense_buffer, 0,
2871 sizeof(cmd->sense_buffer));
2872 cmd->sense_buffer[0] = SSD_ERRCODE_VALID
2873 | SSD_CURRENT_ERROR;
2874 cmd->sense_buffer[2] = SSD_KEY_ABORTED_COMMAND;
2875 break; 2155 break;
2876 default: 2156 default:
2877 /* We should never get here */ 2157 /* We should never get here */
@@ -2882,17 +2162,7 @@ ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, Scsi_Cmnd *cmd)
2882 ahc_cmd_set_transaction_status(cmd, new_status); 2162 ahc_cmd_set_transaction_status(cmd, new_status);
2883 } 2163 }
2884 2164
2885 completeq = &ahc->platform_data->completeq; 2165 cmd->scsi_done(cmd);
2886 list_cmd = TAILQ_FIRST(completeq);
2887 acmd = (struct ahc_cmd *)cmd;
2888 while (list_cmd != NULL
2889 && acmd_scsi_cmd(list_cmd).serial_number
2890 < acmd_scsi_cmd(acmd).serial_number)
2891 list_cmd = TAILQ_NEXT(list_cmd, acmd_links.tqe);
2892 if (list_cmd != NULL)
2893 TAILQ_INSERT_BEFORE(list_cmd, acmd, acmd_links.tqe);
2894 else
2895 TAILQ_INSERT_TAIL(completeq, acmd, acmd_links.tqe);
2896} 2166}
2897 2167
2898static void 2168static void
@@ -2940,7 +2210,6 @@ ahc_linux_release_simq(u_long arg)
2940 ahc->platform_data->qfrozen--; 2210 ahc->platform_data->qfrozen--;
2941 if (ahc->platform_data->qfrozen == 0) 2211 if (ahc->platform_data->qfrozen == 0)
2942 unblock_reqs = 1; 2212 unblock_reqs = 1;
2943 ahc_schedule_runq(ahc);
2944 ahc_unlock(ahc, &s); 2213 ahc_unlock(ahc, &s);
2945 /* 2214 /*
2946 * There is still a race here. The mid-layer 2215 * There is still a race here. The mid-layer
@@ -2952,37 +2221,12 @@ ahc_linux_release_simq(u_long arg)
2952 scsi_unblock_requests(ahc->platform_data->host); 2221 scsi_unblock_requests(ahc->platform_data->host);
2953} 2222}
2954 2223
2955static void
2956ahc_linux_dev_timed_unfreeze(u_long arg)
2957{
2958 struct ahc_linux_device *dev;
2959 struct ahc_softc *ahc;
2960 u_long s;
2961
2962 dev = (struct ahc_linux_device *)arg;
2963 ahc = dev->target->ahc;
2964 ahc_lock(ahc, &s);
2965 dev->flags &= ~AHC_DEV_TIMER_ACTIVE;
2966 if (dev->qfrozen > 0)
2967 dev->qfrozen--;
2968 if (dev->qfrozen == 0
2969 && (dev->flags & AHC_DEV_ON_RUN_LIST) == 0)
2970 ahc_linux_run_device_queue(ahc, dev);
2971 if (TAILQ_EMPTY(&dev->busyq)
2972 && dev->active == 0)
2973 __ahc_linux_free_device(ahc, dev);
2974 ahc_unlock(ahc, &s);
2975}
2976
2977static int 2224static int
2978ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag) 2225ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag)
2979{ 2226{
2980 struct ahc_softc *ahc; 2227 struct ahc_softc *ahc;
2981 struct ahc_cmd *acmd;
2982 struct ahc_cmd *list_acmd;
2983 struct ahc_linux_device *dev; 2228 struct ahc_linux_device *dev;
2984 struct scb *pending_scb; 2229 struct scb *pending_scb;
2985 u_long s;
2986 u_int saved_scbptr; 2230 u_int saved_scbptr;
2987 u_int active_scb_index; 2231 u_int active_scb_index;
2988 u_int last_phase; 2232 u_int last_phase;
@@ -2998,7 +2242,6 @@ ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
2998 paused = FALSE; 2242 paused = FALSE;
2999 wait = FALSE; 2243 wait = FALSE;
3000 ahc = *(struct ahc_softc **)cmd->device->host->hostdata; 2244 ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
3001 acmd = (struct ahc_cmd *)cmd;
3002 2245
3003 printf("%s:%d:%d:%d: Attempting to queue a%s message\n", 2246 printf("%s:%d:%d:%d: Attempting to queue a%s message\n",
3004 ahc_name(ahc), cmd->device->channel, 2247 ahc_name(ahc), cmd->device->channel,
@@ -3010,21 +2253,7 @@ ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
3010 printf(" 0x%x", cmd->cmnd[cdb_byte]); 2253 printf(" 0x%x", cmd->cmnd[cdb_byte]);
3011 printf("\n"); 2254 printf("\n");
3012 2255
3013 /* 2256 spin_lock_irq(&ahc->platform_data->spin_lock);
3014 * In all versions of Linux, we have to work around
3015 * a major flaw in how the mid-layer is locked down
3016 * if we are to sleep successfully in our error handler
3017 * while allowing our interrupt handler to run. Since
3018 * the midlayer acquires either the io_request_lock or
3019 * our lock prior to calling us, we must use the
3020 * spin_unlock_irq() method for unlocking our lock.
3021 * This will force interrupts to be enabled on the
3022 * current CPU. Since the EH thread should not have
3023 * been running with CPU interrupts disabled other than
3024 * by acquiring either the io_request_lock or our own
3025 * lock, this *should* be safe.
3026 */
3027 ahc_midlayer_entrypoint_lock(ahc, &s);
3028 2257
3029 /* 2258 /*
3030 * First determine if we currently own this command. 2259 * First determine if we currently own this command.
@@ -3033,8 +2262,7 @@ ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
3033 * at all, and the system wanted us to just abort the 2262 * at all, and the system wanted us to just abort the
3034 * command, return success. 2263 * command, return success.
3035 */ 2264 */
3036 dev = ahc_linux_get_device(ahc, cmd->device->channel, cmd->device->id, 2265 dev = scsi_transport_device_data(cmd->device);
3037 cmd->device->lun, /*alloc*/FALSE);
3038 2266
3039 if (dev == NULL) { 2267 if (dev == NULL) {
3040 /* 2268 /*
@@ -3048,24 +2276,6 @@ ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
3048 goto no_cmd; 2276 goto no_cmd;
3049 } 2277 }
3050 2278
3051 TAILQ_FOREACH(list_acmd, &dev->busyq, acmd_links.tqe) {
3052 if (list_acmd == acmd)
3053 break;
3054 }
3055
3056 if (list_acmd != NULL) {
3057 printf("%s:%d:%d:%d: Command found on device queue\n",
3058 ahc_name(ahc), cmd->device->channel, cmd->device->id,
3059 cmd->device->lun);
3060 if (flag == SCB_ABORT) {
3061 TAILQ_REMOVE(&dev->busyq, list_acmd, acmd_links.tqe);
3062 cmd->result = DID_ABORT << 16;
3063 ahc_linux_queue_cmd_complete(ahc, cmd);
3064 retval = SUCCESS;
3065 goto done;
3066 }
3067 }
3068
3069 if ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED)) == 0 2279 if ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED)) == 0
3070 && ahc_search_untagged_queues(ahc, cmd, cmd->device->id, 2280 && ahc_search_untagged_queues(ahc, cmd, cmd->device->id,
3071 cmd->device->channel + 'A', 2281 cmd->device->channel + 'A',
@@ -3299,63 +2509,30 @@ done:
3299 } 2509 }
3300 spin_lock_irq(&ahc->platform_data->spin_lock); 2510 spin_lock_irq(&ahc->platform_data->spin_lock);
3301 } 2511 }
3302 ahc_schedule_runq(ahc); 2512
3303 ahc_linux_run_complete_queue(ahc); 2513 spin_unlock_irq(&ahc->platform_data->spin_lock);
3304 ahc_midlayer_entrypoint_unlock(ahc, &s);
3305 return (retval); 2514 return (retval);
3306} 2515}
3307 2516
3308void 2517void
3309ahc_platform_dump_card_state(struct ahc_softc *ahc) 2518ahc_platform_dump_card_state(struct ahc_softc *ahc)
3310{ 2519{
3311 struct ahc_linux_device *dev;
3312 int channel;
3313 int maxchannel;
3314 int target;
3315 int maxtarget;
3316 int lun;
3317 int i;
3318
3319 maxchannel = (ahc->features & AHC_TWIN) ? 1 : 0;
3320 maxtarget = (ahc->features & AHC_WIDE) ? 15 : 7;
3321 for (channel = 0; channel <= maxchannel; channel++) {
3322
3323 for (target = 0; target <=maxtarget; target++) {
3324
3325 for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
3326 struct ahc_cmd *acmd;
3327
3328 dev = ahc_linux_get_device(ahc, channel, target,
3329 lun, /*alloc*/FALSE);
3330 if (dev == NULL)
3331 continue;
3332
3333 printf("DevQ(%d:%d:%d): ",
3334 channel, target, lun);
3335 i = 0;
3336 TAILQ_FOREACH(acmd, &dev->busyq,
3337 acmd_links.tqe) {
3338 if (i++ > AHC_SCB_MAX)
3339 break;
3340 }
3341 printf("%d waiting\n", i);
3342 }
3343 }
3344 }
3345} 2520}
3346 2521
3347static void ahc_linux_exit(void); 2522static void ahc_linux_exit(void);
3348 2523
3349static void ahc_linux_get_period(struct scsi_target *starget) 2524static void ahc_linux_set_width(struct scsi_target *starget, int width)
3350{ 2525{
3351 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2526 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3352 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); 2527 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
3353 struct ahc_tmode_tstate *tstate; 2528 struct ahc_devinfo devinfo;
3354 struct ahc_initiator_tinfo *tinfo 2529 unsigned long flags;
3355 = ahc_fetch_transinfo(ahc, 2530
3356 starget->channel + 'A', 2531 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
3357 shost->this_id, starget->id, &tstate); 2532 starget->channel + 'A', ROLE_INITIATOR);
3358 spi_period(starget) = tinfo->curr.period; 2533 ahc_lock(ahc, &flags);
2534 ahc_set_width(ahc, &devinfo, width, AHC_TRANS_GOAL, FALSE);
2535 ahc_unlock(ahc, &flags);
3359} 2536}
3360 2537
3361static void ahc_linux_set_period(struct scsi_target *starget, int period) 2538static void ahc_linux_set_period(struct scsi_target *starget, int period)
@@ -3368,16 +2545,28 @@ static void ahc_linux_set_period(struct scsi_target *starget, int period)
3368 starget->channel + 'A', 2545 starget->channel + 'A',
3369 shost->this_id, starget->id, &tstate); 2546 shost->this_id, starget->id, &tstate);
3370 struct ahc_devinfo devinfo; 2547 struct ahc_devinfo devinfo;
3371 unsigned int ppr_options = tinfo->curr.ppr_options; 2548 unsigned int ppr_options = tinfo->goal.ppr_options;
3372 unsigned long flags; 2549 unsigned long flags;
3373 unsigned long offset = tinfo->curr.offset; 2550 unsigned long offset = tinfo->goal.offset;
3374 struct ahc_syncrate *syncrate; 2551 struct ahc_syncrate *syncrate;
3375 2552
3376 if (offset == 0) 2553 if (offset == 0)
3377 offset = MAX_OFFSET; 2554 offset = MAX_OFFSET;
3378 2555
2556 if (period < 9)
2557 period = 9; /* 12.5ns is our minimum */
2558 if (period == 9)
2559 ppr_options |= MSG_EXT_PPR_DT_REQ;
2560
3379 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 2561 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
3380 starget->channel + 'A', ROLE_INITIATOR); 2562 starget->channel + 'A', ROLE_INITIATOR);
2563
2564 /* all PPR requests apart from QAS require wide transfers */
2565 if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) {
2566 if (spi_width(starget) == 0)
2567 ppr_options &= MSG_EXT_PPR_QAS_REQ;
2568 }
2569
3381 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); 2570 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
3382 ahc_lock(ahc, &flags); 2571 ahc_lock(ahc, &flags);
3383 ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset, 2572 ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset,
@@ -3385,18 +2574,6 @@ static void ahc_linux_set_period(struct scsi_target *starget, int period)
3385 ahc_unlock(ahc, &flags); 2574 ahc_unlock(ahc, &flags);
3386} 2575}
3387 2576
3388static void ahc_linux_get_offset(struct scsi_target *starget)
3389{
3390 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3391 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
3392 struct ahc_tmode_tstate *tstate;
3393 struct ahc_initiator_tinfo *tinfo
3394 = ahc_fetch_transinfo(ahc,
3395 starget->channel + 'A',
3396 shost->this_id, starget->id, &tstate);
3397 spi_offset(starget) = tinfo->curr.offset;
3398}
3399
3400static void ahc_linux_set_offset(struct scsi_target *starget, int offset) 2577static void ahc_linux_set_offset(struct scsi_target *starget, int offset)
3401{ 2578{
3402 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2579 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
@@ -3416,8 +2593,8 @@ static void ahc_linux_set_offset(struct scsi_target *starget, int offset)
3416 starget->channel + 'A', ROLE_INITIATOR); 2593 starget->channel + 'A', ROLE_INITIATOR);
3417 if (offset != 0) { 2594 if (offset != 0) {
3418 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); 2595 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
3419 period = tinfo->curr.period; 2596 period = tinfo->goal.period;
3420 ppr_options = tinfo->curr.ppr_options; 2597 ppr_options = tinfo->goal.ppr_options;
3421 } 2598 }
3422 ahc_lock(ahc, &flags); 2599 ahc_lock(ahc, &flags);
3423 ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset, 2600 ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset,
@@ -3425,44 +2602,6 @@ static void ahc_linux_set_offset(struct scsi_target *starget, int offset)
3425 ahc_unlock(ahc, &flags); 2602 ahc_unlock(ahc, &flags);
3426} 2603}
3427 2604
3428static void ahc_linux_get_width(struct scsi_target *starget)
3429{
3430 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3431 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
3432 struct ahc_tmode_tstate *tstate;
3433 struct ahc_initiator_tinfo *tinfo
3434 = ahc_fetch_transinfo(ahc,
3435 starget->channel + 'A',
3436 shost->this_id, starget->id, &tstate);
3437 spi_width(starget) = tinfo->curr.width;
3438}
3439
3440static void ahc_linux_set_width(struct scsi_target *starget, int width)
3441{
3442 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3443 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
3444 struct ahc_devinfo devinfo;
3445 unsigned long flags;
3446
3447 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
3448 starget->channel + 'A', ROLE_INITIATOR);
3449 ahc_lock(ahc, &flags);
3450 ahc_set_width(ahc, &devinfo, width, AHC_TRANS_GOAL, FALSE);
3451 ahc_unlock(ahc, &flags);
3452}
3453
3454static void ahc_linux_get_dt(struct scsi_target *starget)
3455{
3456 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3457 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
3458 struct ahc_tmode_tstate *tstate;
3459 struct ahc_initiator_tinfo *tinfo
3460 = ahc_fetch_transinfo(ahc,
3461 starget->channel + 'A',
3462 shost->this_id, starget->id, &tstate);
3463 spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ;
3464}
3465
3466static void ahc_linux_set_dt(struct scsi_target *starget, int dt) 2605static void ahc_linux_set_dt(struct scsi_target *starget, int dt)
3467{ 2606{
3468 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2607 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
@@ -3473,34 +2612,27 @@ static void ahc_linux_set_dt(struct scsi_target *starget, int dt)
3473 starget->channel + 'A', 2612 starget->channel + 'A',
3474 shost->this_id, starget->id, &tstate); 2613 shost->this_id, starget->id, &tstate);
3475 struct ahc_devinfo devinfo; 2614 struct ahc_devinfo devinfo;
3476 unsigned int ppr_options = tinfo->curr.ppr_options 2615 unsigned int ppr_options = tinfo->goal.ppr_options
3477 & ~MSG_EXT_PPR_DT_REQ; 2616 & ~MSG_EXT_PPR_DT_REQ;
3478 unsigned int period = tinfo->curr.period; 2617 unsigned int period = tinfo->goal.period;
3479 unsigned long flags; 2618 unsigned long flags;
3480 struct ahc_syncrate *syncrate; 2619 struct ahc_syncrate *syncrate;
3481 2620
2621 if (dt) {
2622 period = 9; /* 12.5ns is the only period valid for DT */
2623 ppr_options |= MSG_EXT_PPR_DT_REQ;
2624 } else if (period == 9)
2625 period = 10; /* if resetting DT, period must be >= 25ns */
2626
3482 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 2627 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
3483 starget->channel + 'A', ROLE_INITIATOR); 2628 starget->channel + 'A', ROLE_INITIATOR);
3484 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, 2629 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options,AHC_SYNCRATE_DT);
3485 dt ? AHC_SYNCRATE_DT : AHC_SYNCRATE_ULTRA2);
3486 ahc_lock(ahc, &flags); 2630 ahc_lock(ahc, &flags);
3487 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->curr.offset, 2631 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset,
3488 ppr_options, AHC_TRANS_GOAL, FALSE); 2632 ppr_options, AHC_TRANS_GOAL, FALSE);
3489 ahc_unlock(ahc, &flags); 2633 ahc_unlock(ahc, &flags);
3490} 2634}
3491 2635
3492static void ahc_linux_get_qas(struct scsi_target *starget)
3493{
3494 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3495 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
3496 struct ahc_tmode_tstate *tstate;
3497 struct ahc_initiator_tinfo *tinfo
3498 = ahc_fetch_transinfo(ahc,
3499 starget->channel + 'A',
3500 shost->this_id, starget->id, &tstate);
3501 spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ;
3502}
3503
3504static void ahc_linux_set_qas(struct scsi_target *starget, int qas) 2636static void ahc_linux_set_qas(struct scsi_target *starget, int qas)
3505{ 2637{
3506 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2638 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
@@ -3511,10 +2643,9 @@ static void ahc_linux_set_qas(struct scsi_target *starget, int qas)
3511 starget->channel + 'A', 2643 starget->channel + 'A',
3512 shost->this_id, starget->id, &tstate); 2644 shost->this_id, starget->id, &tstate);
3513 struct ahc_devinfo devinfo; 2645 struct ahc_devinfo devinfo;
3514 unsigned int ppr_options = tinfo->curr.ppr_options 2646 unsigned int ppr_options = tinfo->goal.ppr_options
3515 & ~MSG_EXT_PPR_QAS_REQ; 2647 & ~MSG_EXT_PPR_QAS_REQ;
3516 unsigned int period = tinfo->curr.period; 2648 unsigned int period = tinfo->goal.period;
3517 unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
3518 unsigned long flags; 2649 unsigned long flags;
3519 struct ahc_syncrate *syncrate; 2650 struct ahc_syncrate *syncrate;
3520 2651
@@ -3523,26 +2654,13 @@ static void ahc_linux_set_qas(struct scsi_target *starget, int qas)
3523 2654
3524 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 2655 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
3525 starget->channel + 'A', ROLE_INITIATOR); 2656 starget->channel + 'A', ROLE_INITIATOR);
3526 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, 2657 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
3527 dt ? AHC_SYNCRATE_DT : AHC_SYNCRATE_ULTRA2);
3528 ahc_lock(ahc, &flags); 2658 ahc_lock(ahc, &flags);
3529 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->curr.offset, 2659 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset,
3530 ppr_options, AHC_TRANS_GOAL, FALSE); 2660 ppr_options, AHC_TRANS_GOAL, FALSE);
3531 ahc_unlock(ahc, &flags); 2661 ahc_unlock(ahc, &flags);
3532} 2662}
3533 2663
3534static void ahc_linux_get_iu(struct scsi_target *starget)
3535{
3536 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3537 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
3538 struct ahc_tmode_tstate *tstate;
3539 struct ahc_initiator_tinfo *tinfo
3540 = ahc_fetch_transinfo(ahc,
3541 starget->channel + 'A',
3542 shost->this_id, starget->id, &tstate);
3543 spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ;
3544}
3545
3546static void ahc_linux_set_iu(struct scsi_target *starget, int iu) 2664static void ahc_linux_set_iu(struct scsi_target *starget, int iu)
3547{ 2665{
3548 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2666 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
@@ -3553,10 +2671,9 @@ static void ahc_linux_set_iu(struct scsi_target *starget, int iu)
3553 starget->channel + 'A', 2671 starget->channel + 'A',
3554 shost->this_id, starget->id, &tstate); 2672 shost->this_id, starget->id, &tstate);
3555 struct ahc_devinfo devinfo; 2673 struct ahc_devinfo devinfo;
3556 unsigned int ppr_options = tinfo->curr.ppr_options 2674 unsigned int ppr_options = tinfo->goal.ppr_options
3557 & ~MSG_EXT_PPR_IU_REQ; 2675 & ~MSG_EXT_PPR_IU_REQ;
3558 unsigned int period = tinfo->curr.period; 2676 unsigned int period = tinfo->goal.period;
3559 unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
3560 unsigned long flags; 2677 unsigned long flags;
3561 struct ahc_syncrate *syncrate; 2678 struct ahc_syncrate *syncrate;
3562 2679
@@ -3565,31 +2682,24 @@ static void ahc_linux_set_iu(struct scsi_target *starget, int iu)
3565 2682
3566 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 2683 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
3567 starget->channel + 'A', ROLE_INITIATOR); 2684 starget->channel + 'A', ROLE_INITIATOR);
3568 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, 2685 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
3569 dt ? AHC_SYNCRATE_DT : AHC_SYNCRATE_ULTRA2);
3570 ahc_lock(ahc, &flags); 2686 ahc_lock(ahc, &flags);
3571 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->curr.offset, 2687 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset,
3572 ppr_options, AHC_TRANS_GOAL, FALSE); 2688 ppr_options, AHC_TRANS_GOAL, FALSE);
3573 ahc_unlock(ahc, &flags); 2689 ahc_unlock(ahc, &flags);
3574} 2690}
3575 2691
3576static struct spi_function_template ahc_linux_transport_functions = { 2692static struct spi_function_template ahc_linux_transport_functions = {
3577 .get_offset = ahc_linux_get_offset,
3578 .set_offset = ahc_linux_set_offset, 2693 .set_offset = ahc_linux_set_offset,
3579 .show_offset = 1, 2694 .show_offset = 1,
3580 .get_period = ahc_linux_get_period,
3581 .set_period = ahc_linux_set_period, 2695 .set_period = ahc_linux_set_period,
3582 .show_period = 1, 2696 .show_period = 1,
3583 .get_width = ahc_linux_get_width,
3584 .set_width = ahc_linux_set_width, 2697 .set_width = ahc_linux_set_width,
3585 .show_width = 1, 2698 .show_width = 1,
3586 .get_dt = ahc_linux_get_dt,
3587 .set_dt = ahc_linux_set_dt, 2699 .set_dt = ahc_linux_set_dt,
3588 .show_dt = 1, 2700 .show_dt = 1,
3589 .get_iu = ahc_linux_get_iu,
3590 .set_iu = ahc_linux_set_iu, 2701 .set_iu = ahc_linux_set_iu,
3591 .show_iu = 1, 2702 .show_iu = 1,
3592 .get_qas = ahc_linux_get_qas,
3593 .set_qas = ahc_linux_set_qas, 2703 .set_qas = ahc_linux_set_qas,
3594 .show_qas = 1, 2704 .show_qas = 1,
3595}; 2705};
@@ -3599,38 +2709,23 @@ static struct spi_function_template ahc_linux_transport_functions = {
3599static int __init 2709static int __init
3600ahc_linux_init(void) 2710ahc_linux_init(void)
3601{ 2711{
3602#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
3603 ahc_linux_transport_template = spi_attach_transport(&ahc_linux_transport_functions); 2712 ahc_linux_transport_template = spi_attach_transport(&ahc_linux_transport_functions);
3604 if (!ahc_linux_transport_template) 2713 if (!ahc_linux_transport_template)
3605 return -ENODEV; 2714 return -ENODEV;
2715 scsi_transport_reserve_target(ahc_linux_transport_template,
2716 sizeof(struct ahc_linux_target));
2717 scsi_transport_reserve_device(ahc_linux_transport_template,
2718 sizeof(struct ahc_linux_device));
3606 if (ahc_linux_detect(&aic7xxx_driver_template)) 2719 if (ahc_linux_detect(&aic7xxx_driver_template))
3607 return 0; 2720 return 0;
3608 spi_release_transport(ahc_linux_transport_template); 2721 spi_release_transport(ahc_linux_transport_template);
3609 ahc_linux_exit(); 2722 ahc_linux_exit();
3610 return -ENODEV; 2723 return -ENODEV;
3611#else
3612 scsi_register_module(MODULE_SCSI_HA, &aic7xxx_driver_template);
3613 if (aic7xxx_driver_template.present == 0) {
3614 scsi_unregister_module(MODULE_SCSI_HA,
3615 &aic7xxx_driver_template);
3616 return (-ENODEV);
3617 }
3618
3619 return (0);
3620#endif
3621} 2724}
3622 2725
3623static void 2726static void
3624ahc_linux_exit(void) 2727ahc_linux_exit(void)
3625{ 2728{
3626#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
3627 /*
3628 * In 2.4 we have to unregister from the PCI core _after_
3629 * unregistering from the scsi midlayer to avoid dangling
3630 * references.
3631 */
3632 scsi_unregister_module(MODULE_SCSI_HA, &aic7xxx_driver_template);
3633#endif
3634 ahc_linux_pci_exit(); 2729 ahc_linux_pci_exit();
3635 ahc_linux_eisa_exit(); 2730 ahc_linux_eisa_exit();
3636 spi_release_transport(ahc_linux_transport_template); 2731 spi_release_transport(ahc_linux_transport_template);