aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/Kconfig14
-rw-r--r--drivers/scsi/NCR53C9x.c5
-rw-r--r--drivers/scsi/aacraid/linit.c2
-rw-r--r--drivers/scsi/ahci.c3
-rw-r--r--drivers/scsi/aic7xxx/aic7770_osm.c52
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c2
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.c1405
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.h175
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm_pci.c11
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_proc.c13
-rw-r--r--drivers/scsi/aic7xxx/aiclib.c1
-rw-r--r--drivers/scsi/ata_piix.c18
-rw-r--r--drivers/scsi/ide-scsi.c86
-rw-r--r--drivers/scsi/libata-core.c512
-rw-r--r--drivers/scsi/libata-scsi.c7
-rw-r--r--drivers/scsi/libata.h2
-rw-r--r--drivers/scsi/qla2xxx/qla_attr.c8
-rw-r--r--drivers/scsi/qla2xxx/qla_gbl.h4
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c27
-rw-r--r--drivers/scsi/sata_nv.c2
-rw-r--r--drivers/scsi/sata_promise.c3
-rw-r--r--drivers/scsi/sata_qstor.c2
-rw-r--r--drivers/scsi/sata_sil.c10
-rw-r--r--drivers/scsi/sata_sis.c1
-rw-r--r--drivers/scsi/sata_svw.c3
-rw-r--r--drivers/scsi/sata_sx4.c2
-rw-r--r--drivers/scsi/sata_uli.c1
-rw-r--r--drivers/scsi/sata_via.c1
-rw-r--r--drivers/scsi/sata_vsc.c2
-rw-r--r--drivers/scsi/scsi.c2
-rw-r--r--drivers/scsi/scsi_scan.c1
-rw-r--r--drivers/scsi/scsi_transport_spi.c237
-rw-r--r--drivers/scsi/sr_ioctl.c3
-rw-r--r--drivers/scsi/sym53c416.c2
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_glue.c5
35 files changed, 1139 insertions, 1485 deletions
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 750b11cefd93..27fec8a5eb5b 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -260,7 +260,7 @@ config SCSI_3W_9XXX
260 260
261config SCSI_7000FASST 261config SCSI_7000FASST
262 tristate "7000FASST SCSI support" 262 tristate "7000FASST SCSI support"
263 depends on ISA && SCSI 263 depends on ISA && SCSI && ISA_DMA_API
264 help 264 help
265 This driver supports the Western Digital 7000 SCSI host adapter 265 This driver supports the Western Digital 7000 SCSI host adapter
266 family. Some information is in the source: 266 family. Some information is in the source:
@@ -295,7 +295,7 @@ config SCSI_AHA152X
295 295
296config SCSI_AHA1542 296config SCSI_AHA1542
297 tristate "Adaptec AHA1542 support" 297 tristate "Adaptec AHA1542 support"
298 depends on ISA && SCSI 298 depends on ISA && SCSI && ISA_DMA_API
299 ---help--- 299 ---help---
300 This is support for a SCSI host adapter. It is explained in section 300 This is support for a SCSI host adapter. It is explained in section
301 3.4 of the SCSI-HOWTO, available from 301 3.4 of the SCSI-HOWTO, available from
@@ -515,7 +515,7 @@ config SCSI_SATA_VITESSE
515 515
516config SCSI_BUSLOGIC 516config SCSI_BUSLOGIC
517 tristate "BusLogic SCSI support" 517 tristate "BusLogic SCSI support"
518 depends on (PCI || ISA || MCA) && SCSI && (BROKEN || !SPARC64) 518 depends on (PCI || ISA || MCA) && SCSI && ISA_DMA_API
519 ---help--- 519 ---help---
520 This is support for BusLogic MultiMaster and FlashPoint SCSI Host 520 This is support for BusLogic MultiMaster and FlashPoint SCSI Host
521 Adapters. Consult the SCSI-HOWTO, available from 521 Adapters. Consult the SCSI-HOWTO, available from
@@ -571,7 +571,7 @@ config SCSI_DTC3280
571 571
572config SCSI_EATA 572config SCSI_EATA
573 tristate "EATA ISA/EISA/PCI (DPT and generic EATA/DMA-compliant boards) support" 573 tristate "EATA ISA/EISA/PCI (DPT and generic EATA/DMA-compliant boards) support"
574 depends on (ISA || EISA || PCI) && SCSI && (BROKEN || !SPARC64) 574 depends on (ISA || EISA || PCI) && SCSI && ISA_DMA_API
575 ---help--- 575 ---help---
576 This driver supports all EATA/DMA-compliant SCSI host adapters. DPT 576 This driver supports all EATA/DMA-compliant SCSI host adapters. DPT
577 ISA and all EISA I/O addresses are probed looking for the "EATA" 577 ISA and all EISA I/O addresses are probed looking for the "EATA"
@@ -665,7 +665,7 @@ config SCSI_FD_MCS
665 665
666config SCSI_GDTH 666config SCSI_GDTH
667 tristate "Intel/ICP (former GDT SCSI Disk Array) RAID Controller support" 667 tristate "Intel/ICP (former GDT SCSI Disk Array) RAID Controller support"
668 depends on (ISA || EISA || PCI) && SCSI && (BROKEN || !SPARC64) 668 depends on (ISA || EISA || PCI) && SCSI && ISA_DMA_API
669 ---help--- 669 ---help---
670 Formerly called GDT SCSI Disk Array Controller Support. 670 Formerly called GDT SCSI Disk Array Controller Support.
671 671
@@ -1416,7 +1416,7 @@ config SCSI_T128
1416 1416
1417config SCSI_U14_34F 1417config SCSI_U14_34F
1418 tristate "UltraStor 14F/34F support" 1418 tristate "UltraStor 14F/34F support"
1419 depends on ISA && SCSI 1419 depends on ISA && SCSI && ISA_DMA_API
1420 ---help--- 1420 ---help---
1421 This is support for the UltraStor 14F and 34F SCSI-2 host adapters. 1421 This is support for the UltraStor 14F and 34F SCSI-2 host adapters.
1422 The source at <file:drivers/scsi/u14-34f.c> contains some 1422 The source at <file:drivers/scsi/u14-34f.c> contains some
@@ -1752,7 +1752,7 @@ config SCSI_NCR53C7xx_FAST
1752 1752
1753config SUN3_SCSI 1753config SUN3_SCSI
1754 tristate "Sun3 NCR5380 SCSI" 1754 tristate "Sun3 NCR5380 SCSI"
1755 depends on SUN3 && SCSI 1755 depends on SUN3 && SCSI && BROKEN
1756 help 1756 help
1757 This option will enable support for the OBIO (onboard io) NCR5380 1757 This option will enable support for the OBIO (onboard io) NCR5380
1758 SCSI controller found in the Sun 3/50 and 3/60, as well as for 1758 SCSI controller found in the Sun 3/50 and 3/60, as well as for
diff --git a/drivers/scsi/NCR53C9x.c b/drivers/scsi/NCR53C9x.c
index 3c86655a5f33..74b93564a258 100644
--- a/drivers/scsi/NCR53C9x.c
+++ b/drivers/scsi/NCR53C9x.c
@@ -1824,7 +1824,10 @@ static int esp_do_data(struct NCR_ESP *esp, struct ESP_regs *eregs)
1824 /* loop */ 1824 /* loop */
1825 while (hmuch) { 1825 while (hmuch) {
1826 int j, fifo_stuck = 0, newphase; 1826 int j, fifo_stuck = 0, newphase;
1827 unsigned long flags, timeout; 1827 unsigned long timeout;
1828#if 0
1829 unsigned long flags;
1830#endif
1828#if 0 1831#if 0
1829 if ( i % 10 ) 1832 if ( i % 10 )
1830 ESPDATA(("\r")); 1833 ESPDATA(("\r"));
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index c9b82687ba1a..242fa77513f5 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -450,7 +450,7 @@ static int aac_cfg_open(struct inode *inode, struct file *file)
450 } 450 }
451 } 451 }
452 452
453 return 0; 453 return err;
454} 454}
455 455
456/** 456/**
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index da5bd33d982d..fc5263c6b102 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -32,6 +32,7 @@
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/interrupt.h> 33#include <linux/interrupt.h>
34#include <linux/sched.h> 34#include <linux/sched.h>
35#include <linux/dma-mapping.h>
35#include "scsi.h" 36#include "scsi.h"
36#include <scsi/scsi_host.h> 37#include <scsi/scsi_host.h>
37#include <linux/libata.h> 38#include <linux/libata.h>
@@ -289,6 +290,8 @@ static void ahci_host_stop(struct ata_host_set *host_set)
289{ 290{
290 struct ahci_host_priv *hpriv = host_set->private_data; 291 struct ahci_host_priv *hpriv = host_set->private_data;
291 kfree(hpriv); 292 kfree(hpriv);
293
294 ata_host_stop(host_set);
292} 295}
293 296
294static int ahci_port_start(struct ata_port *ap) 297static int ahci_port_start(struct ata_port *ap)
diff --git a/drivers/scsi/aic7xxx/aic7770_osm.c b/drivers/scsi/aic7xxx/aic7770_osm.c
index c2b47f2bdffd..682ca0b32b44 100644
--- a/drivers/scsi/aic7xxx/aic7770_osm.c
+++ b/drivers/scsi/aic7xxx/aic7770_osm.c
@@ -41,7 +41,6 @@
41 41
42#include "aic7xxx_osm.h" 42#include "aic7xxx_osm.h"
43 43
44#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
45#include <linux/device.h> 44#include <linux/device.h>
46#include <linux/eisa.h> 45#include <linux/eisa.h>
47 46
@@ -62,13 +61,6 @@ static struct eisa_driver aic7770_driver = {
62}; 61};
63 62
64typedef struct device *aic7770_dev_t; 63typedef struct device *aic7770_dev_t;
65#else
66#define MINSLOT 1
67#define NUMSLOTS 16
68#define IDOFFSET 0x80
69
70typedef void *aic7770_dev_t;
71#endif
72 64
73static int aic7770_linux_config(struct aic7770_identity *entry, 65static int aic7770_linux_config(struct aic7770_identity *entry,
74 aic7770_dev_t dev, u_int eisaBase); 66 aic7770_dev_t dev, u_int eisaBase);
@@ -76,7 +68,6 @@ static int aic7770_linux_config(struct aic7770_identity *entry,
76int 68int
77ahc_linux_eisa_init(void) 69ahc_linux_eisa_init(void)
78{ 70{
79#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
80 struct eisa_device_id *eid; 71 struct eisa_device_id *eid;
81 struct aic7770_identity *id; 72 struct aic7770_identity *id;
82 int i; 73 int i;
@@ -110,44 +101,6 @@ ahc_linux_eisa_init(void)
110 eid->sig[0] = 0; 101 eid->sig[0] = 0;
111 102
112 return eisa_driver_register(&aic7770_driver); 103 return eisa_driver_register(&aic7770_driver);
113#else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
114 struct aic7770_identity *entry;
115 u_int slot;
116 u_int eisaBase;
117 u_int i;
118 int ret = -ENODEV;
119
120 if (aic7xxx_probe_eisa_vl == 0)
121 return ret;
122
123 eisaBase = 0x1000 + AHC_EISA_SLOT_OFFSET;
124 for (slot = 1; slot < NUMSLOTS; eisaBase+=0x1000, slot++) {
125 uint32_t eisa_id;
126 size_t id_size;
127
128 if (request_region(eisaBase, AHC_EISA_IOSIZE, "aic7xxx") == 0)
129 continue;
130
131 eisa_id = 0;
132 id_size = sizeof(eisa_id);
133 for (i = 0; i < 4; i++) {
134 /* VLcards require priming*/
135 outb(0x80 + i, eisaBase + IDOFFSET);
136 eisa_id |= inb(eisaBase + IDOFFSET + i)
137 << ((id_size-i-1) * 8);
138 }
139 release_region(eisaBase, AHC_EISA_IOSIZE);
140 if (eisa_id & 0x80000000)
141 continue; /* no EISA card in slot */
142
143 entry = aic7770_find_device(eisa_id);
144 if (entry != NULL) {
145 aic7770_linux_config(entry, NULL, eisaBase);
146 ret = 0;
147 }
148 }
149 return ret;
150#endif
151} 104}
152 105
153void 106void
@@ -187,11 +140,10 @@ aic7770_linux_config(struct aic7770_identity *entry, aic7770_dev_t dev,
187 ahc_free(ahc); 140 ahc_free(ahc);
188 return (error); 141 return (error);
189 } 142 }
190#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 143
191 dev->driver_data = (void *)ahc; 144 dev->driver_data = (void *)ahc;
192 if (aic7xxx_detect_complete) 145 if (aic7xxx_detect_complete)
193 error = ahc_linux_register_host(ahc, &aic7xxx_driver_template); 146 error = ahc_linux_register_host(ahc, &aic7xxx_driver_template);
194#endif
195 return (error); 147 return (error);
196} 148}
197 149
@@ -225,7 +177,6 @@ aic7770_map_int(struct ahc_softc *ahc, u_int irq)
225 return (-error); 177 return (-error);
226} 178}
227 179
228#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
229static int 180static int
230aic7770_eisa_dev_probe(struct device *dev) 181aic7770_eisa_dev_probe(struct device *dev)
231{ 182{
@@ -261,4 +212,3 @@ aic7770_eisa_dev_remove(struct device *dev)
261 212
262 return (0); 213 return (0);
263} 214}
264#endif
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index 550c9921691a..7c02b7dc7098 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -2488,7 +2488,7 @@ ahd_linux_dv_thread(void *data)
2488 sprintf(current->comm, "ahd_dv_%d", ahd->unit); 2488 sprintf(current->comm, "ahd_dv_%d", ahd->unit);
2489#else 2489#else
2490 daemonize("ahd_dv_%d", ahd->unit); 2490 daemonize("ahd_dv_%d", ahd->unit);
2491 current->flags |= PF_FREEZE; 2491 current->flags |= PF_NOFREEZE;
2492#endif 2492#endif
2493 unlock_kernel(); 2493 unlock_kernel();
2494 2494
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index e60f9338e44a..c13e56320010 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -134,11 +134,6 @@ static struct scsi_transport_template *ahc_linux_transport_template = NULL;
134#include "aiclib.c" 134#include "aiclib.c"
135 135
136#include <linux/init.h> /* __setup */ 136#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 */ 137#include <linux/mm.h> /* For fetching system memory size */
143#include <linux/blkdev.h> /* For block_size() */ 138#include <linux/blkdev.h> /* For block_size() */
144#include <linux/delay.h> /* For ssleep/msleep */ 139#include <linux/delay.h> /* For ssleep/msleep */
@@ -148,11 +143,6 @@ static struct scsi_transport_template *ahc_linux_transport_template = NULL;
148 */ 143 */
149spinlock_t ahc_list_spinlock; 144spinlock_t ahc_list_spinlock;
150 145
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/* 146/*
157 * Set this to the delay in seconds after SCSI bus reset. 147 * Set this to the delay in seconds after SCSI bus reset.
158 * Note, we honor this only for the initial bus reset. 148 * Note, we honor this only for the initial bus reset.
@@ -436,15 +426,12 @@ static void ahc_linux_handle_scsi_status(struct ahc_softc *,
436 struct ahc_linux_device *, 426 struct ahc_linux_device *,
437 struct scb *); 427 struct scb *);
438static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, 428static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc,
439 Scsi_Cmnd *cmd); 429 struct scsi_cmnd *cmd);
440static void ahc_linux_sem_timeout(u_long arg); 430static void ahc_linux_sem_timeout(u_long arg);
441static void ahc_linux_freeze_simq(struct ahc_softc *ahc); 431static void ahc_linux_freeze_simq(struct ahc_softc *ahc);
442static void ahc_linux_release_simq(u_long arg); 432static void ahc_linux_release_simq(u_long arg);
443static void ahc_linux_dev_timed_unfreeze(u_long arg); 433static 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); 434static 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, 435static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc,
449 struct ahc_devinfo *devinfo); 436 struct ahc_devinfo *devinfo);
450static void ahc_linux_device_queue_depth(struct ahc_softc *ahc, 437static void ahc_linux_device_queue_depth(struct ahc_softc *ahc,
@@ -458,54 +445,27 @@ static struct ahc_linux_device* ahc_linux_alloc_device(struct ahc_softc*,
458 u_int); 445 u_int);
459static void ahc_linux_free_device(struct ahc_softc*, 446static void ahc_linux_free_device(struct ahc_softc*,
460 struct ahc_linux_device*); 447 struct ahc_linux_device*);
461static void ahc_linux_run_device_queue(struct ahc_softc*, 448static int ahc_linux_run_command(struct ahc_softc*,
462 struct ahc_linux_device*); 449 struct ahc_linux_device *,
450 struct scsi_cmnd *);
463static void ahc_linux_setup_tag_info_global(char *p); 451static void ahc_linux_setup_tag_info_global(char *p);
464static aic_option_callback_t ahc_linux_setup_tag_info; 452static aic_option_callback_t ahc_linux_setup_tag_info;
465static int aic7xxx_setup(char *s); 453static int aic7xxx_setup(char *s);
466static int ahc_linux_next_unit(void); 454static 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 455
470/********************************* Inlines ************************************/ 456/********************************* Inlines ************************************/
471static __inline void ahc_schedule_runq(struct ahc_softc *ahc);
472static __inline struct ahc_linux_device* 457static __inline struct ahc_linux_device*
473 ahc_linux_get_device(struct ahc_softc *ahc, u_int channel, 458 ahc_linux_get_device(struct ahc_softc *ahc, u_int channel,
474 u_int target, u_int lun, int alloc); 459 u_int target, u_int lun);
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*); 460static __inline void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*);
482 461
483static __inline int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb, 462static __inline int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
484 struct ahc_dma_seg *sg, 463 struct ahc_dma_seg *sg,
485 dma_addr_t addr, bus_size_t len); 464 dma_addr_t addr, bus_size_t len);
486 465
487static __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* 466static __inline struct ahc_linux_device*
507ahc_linux_get_device(struct ahc_softc *ahc, u_int channel, u_int target, 467ahc_linux_get_device(struct ahc_softc *ahc, u_int channel, u_int target,
508 u_int lun, int alloc) 468 u_int lun)
509{ 469{
510 struct ahc_linux_target *targ; 470 struct ahc_linux_target *targ;
511 struct ahc_linux_device *dev; 471 struct ahc_linux_device *dev;
@@ -515,102 +475,15 @@ ahc_linux_get_device(struct ahc_softc *ahc, u_int channel, u_int target,
515 if (channel != 0) 475 if (channel != 0)
516 target_offset += 8; 476 target_offset += 8;
517 targ = ahc->platform_data->targets[target_offset]; 477 targ = ahc->platform_data->targets[target_offset];
518 if (targ == NULL) { 478 BUG_ON(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]; 479 dev = targ->devices[lun];
527 if (dev == NULL && alloc != 0) 480 return dev;
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} 481}
609 482
610static __inline void 483static __inline void
611ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb) 484ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb)
612{ 485{
613 Scsi_Cmnd *cmd; 486 struct scsi_cmnd *cmd;
614 487
615 cmd = scb->io_ctx; 488 cmd = scb->io_ctx;
616 ahc_sync_sglist(ahc, scb, BUS_DMASYNC_POSTWRITE); 489 ahc_sync_sglist(ahc, scb, BUS_DMASYNC_POSTWRITE);
@@ -650,109 +523,15 @@ ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
650 return (consumed); 523 return (consumed);
651} 524}
652 525
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/* 526/*
740 * Try to detect an Adaptec 7XXX controller. 527 * Try to detect an Adaptec 7XXX controller.
741 */ 528 */
742static int 529static int
743ahc_linux_detect(Scsi_Host_Template *template) 530ahc_linux_detect(struct scsi_host_template *template)
744{ 531{
745 struct ahc_softc *ahc; 532 struct ahc_softc *ahc;
746 int found = 0; 533 int found = 0;
747 534
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 /* 535 /*
757 * Sanity checking of Linux SCSI data structures so 536 * Sanity checking of Linux SCSI data structures so
758 * that some of our hacks^H^H^H^H^Hassumptions aren't 537 * that some of our hacks^H^H^H^H^Hassumptions aren't
@@ -764,7 +543,6 @@ ahc_linux_detect(Scsi_Host_Template *template)
764 printf("ahc_linux_detect: Unable to attach\n"); 543 printf("ahc_linux_detect: Unable to attach\n");
765 return (0); 544 return (0);
766 } 545 }
767 ahc_linux_size_nseg();
768 /* 546 /*
769 * If we've been passed any parameters, process them now. 547 * If we've been passed any parameters, process them now.
770 */ 548 */
@@ -793,48 +571,11 @@ ahc_linux_detect(Scsi_Host_Template *template)
793 found++; 571 found++;
794 } 572 }
795 573
796#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
797 spin_lock_irq(&io_request_lock);
798#endif
799 aic7xxx_detect_complete++; 574 aic7xxx_detect_complete++;
800 575
801 return (found); 576 return (found);
802} 577}
803 578
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/* 579/*
839 * Return a string describing the driver. 580 * Return a string describing the driver.
840 */ 581 */
@@ -867,11 +608,10 @@ ahc_linux_info(struct Scsi_Host *host)
867 * Queue an SCB to the controller. 608 * Queue an SCB to the controller.
868 */ 609 */
869static int 610static int
870ahc_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *)) 611ahc_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
871{ 612{
872 struct ahc_softc *ahc; 613 struct ahc_softc *ahc;
873 struct ahc_linux_device *dev; 614 struct ahc_linux_device *dev;
874 u_long flags;
875 615
876 ahc = *(struct ahc_softc **)cmd->device->host->hostdata; 616 ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
877 617
@@ -880,205 +620,152 @@ ahc_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
880 */ 620 */
881 cmd->scsi_done = scsi_done; 621 cmd->scsi_done = scsi_done;
882 622
883 ahc_midlayer_entrypoint_lock(ahc, &flags);
884
885 /* 623 /*
886 * Close the race of a command that was in the process of 624 * Close the race of a command that was in the process of
887 * being queued to us just as our simq was frozen. Let 625 * being queued to us just as our simq was frozen. Let
888 * DV commands through so long as we are only frozen to 626 * DV commands through so long as we are only frozen to
889 * perform DV. 627 * perform DV.
890 */ 628 */
891 if (ahc->platform_data->qfrozen != 0) { 629 if (ahc->platform_data->qfrozen != 0)
630 return SCSI_MLQUEUE_HOST_BUSY;
892 631
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, 632 dev = ahc_linux_get_device(ahc, cmd->device->channel, cmd->device->id,
900 cmd->device->lun, /*alloc*/TRUE); 633 cmd->device->lun);
901 if (dev == NULL) { 634 BUG_ON(dev == NULL);
902 ahc_cmd_set_transaction_status(cmd, CAM_RESRC_UNAVAIL); 635
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; 636 cmd->result = CAM_REQ_INPROG << 16;
911 TAILQ_INSERT_TAIL(&dev->busyq, (struct ahc_cmd *)cmd, acmd_links.tqe); 637
912 if ((dev->flags & AHC_DEV_ON_RUN_LIST) == 0) { 638 return ahc_linux_run_command(ahc, dev, cmd);
913 TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, dev, links);
914 dev->flags |= AHC_DEV_ON_RUN_LIST;
915 ahc_linux_run_device_queues(ahc);
916 }
917 ahc_midlayer_entrypoint_unlock(ahc, &flags);
918 return (0);
919} 639}
920 640
921#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
922static int 641static int
923ahc_linux_slave_alloc(Scsi_Device *device) 642ahc_linux_slave_alloc(struct scsi_device *device)
924{ 643{
925 struct ahc_softc *ahc; 644 struct ahc_softc *ahc;
645 struct ahc_linux_target *targ;
646 struct scsi_target *starget = device->sdev_target;
647 struct ahc_linux_device *dev;
648 unsigned int target_offset;
649 unsigned long flags;
650 int retval = -ENOMEM;
651
652 target_offset = starget->id;
653 if (starget->channel != 0)
654 target_offset += 8;
926 655
927 ahc = *((struct ahc_softc **)device->host->hostdata); 656 ahc = *((struct ahc_softc **)device->host->hostdata);
928 if (bootverbose) 657 if (bootverbose)
929 printf("%s: Slave Alloc %d\n", ahc_name(ahc), device->id); 658 printf("%s: Slave Alloc %d\n", ahc_name(ahc), device->id);
930 return (0); 659 ahc_lock(ahc, &flags);
660 targ = ahc->platform_data->targets[target_offset];
661 if (targ == NULL) {
662 struct seeprom_config *sc;
663
664 targ = ahc_linux_alloc_target(ahc, starget->channel,
665 starget->id);
666 sc = ahc->seep_config;
667 if (targ == NULL)
668 goto out;
669
670 if (sc) {
671 unsigned short scsirate;
672 struct ahc_devinfo devinfo;
673 struct ahc_initiator_tinfo *tinfo;
674 struct ahc_tmode_tstate *tstate;
675 char channel = starget->channel + 'A';
676 unsigned int our_id = ahc->our_id;
677
678 if (starget->channel)
679 our_id = ahc->our_id_b;
680
681 if ((ahc->features & AHC_ULTRA2) != 0) {
682 scsirate = sc->device_flags[target_offset] & CFXFER;
683 } else {
684 scsirate = (sc->device_flags[target_offset] & CFXFER) << 4;
685 if (sc->device_flags[target_offset] & CFSYNCH)
686 scsirate |= SOFS;
687 }
688 if (sc->device_flags[target_offset] & CFWIDEB) {
689 scsirate |= WIDEXFER;
690 spi_max_width(starget) = 1;
691 } else
692 spi_max_width(starget) = 0;
693 spi_min_period(starget) =
694 ahc_find_period(ahc, scsirate, AHC_SYNCRATE_DT);
695 tinfo = ahc_fetch_transinfo(ahc, channel, ahc->our_id,
696 targ->target, &tstate);
697 ahc_compile_devinfo(&devinfo, our_id, targ->target,
698 CAM_LUN_WILDCARD, channel,
699 ROLE_INITIATOR);
700 ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0,
701 AHC_TRANS_GOAL, /*paused*/FALSE);
702 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
703 AHC_TRANS_GOAL, /*paused*/FALSE);
704 }
705
706 }
707 dev = targ->devices[device->lun];
708 if (dev == NULL) {
709 dev = ahc_linux_alloc_device(ahc, targ, device->lun);
710 if (dev == NULL)
711 goto out;
712 }
713 retval = 0;
714
715 out:
716 ahc_unlock(ahc, &flags);
717 return retval;
931} 718}
932 719
933static int 720static int
934ahc_linux_slave_configure(Scsi_Device *device) 721ahc_linux_slave_configure(struct scsi_device *device)
935{ 722{
936 struct ahc_softc *ahc; 723 struct ahc_softc *ahc;
937 struct ahc_linux_device *dev; 724 struct ahc_linux_device *dev;
938 u_long flags;
939 725
940 ahc = *((struct ahc_softc **)device->host->hostdata); 726 ahc = *((struct ahc_softc **)device->host->hostdata);
727
941 if (bootverbose) 728 if (bootverbose)
942 printf("%s: Slave Configure %d\n", ahc_name(ahc), device->id); 729 printf("%s: Slave Configure %d\n", ahc_name(ahc), device->id);
943 ahc_midlayer_entrypoint_lock(ahc, &flags); 730
944 /* 731 dev = ahc_linux_get_device(ahc, device->channel, device->id,
945 * Since Linux has attached to the device, configure 732 device->lun);
946 * it so we don't free and allocate the device 733 dev->scsi_device = device;
947 * structure on every command. 734 ahc_linux_device_queue_depth(ahc, dev);
948 */
949 dev = ahc_linux_get_device(ahc, device->channel,
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 735
959 /* Initial Domain Validation */ 736 /* Initial Domain Validation */
960 if (!spi_initial_dv(device->sdev_target)) 737 if (!spi_initial_dv(device->sdev_target))
961 spi_dv_device(device); 738 spi_dv_device(device);
962 739
963 return (0); 740 return 0;
964} 741}
965 742
966static void 743static void
967ahc_linux_slave_destroy(Scsi_Device *device) 744ahc_linux_slave_destroy(struct scsi_device *device)
968{ 745{
969 struct ahc_softc *ahc; 746 struct ahc_softc *ahc;
970 struct ahc_linux_device *dev; 747 struct ahc_linux_device *dev;
971 u_long flags;
972 748
973 ahc = *((struct ahc_softc **)device->host->hostdata); 749 ahc = *((struct ahc_softc **)device->host->hostdata);
974 if (bootverbose) 750 if (bootverbose)
975 printf("%s: Slave Destroy %d\n", ahc_name(ahc), device->id); 751 printf("%s: Slave Destroy %d\n", ahc_name(ahc), device->id);
976 ahc_midlayer_entrypoint_lock(ahc, &flags);
977 dev = ahc_linux_get_device(ahc, device->channel, 752 dev = ahc_linux_get_device(ahc, device->channel,
978 device->id, device->lun, 753 device->id, device->lun);
979 /*alloc*/FALSE);
980 /*
981 * Filter out "silly" deletions of real devices by only
982 * deleting devices that have had slave_configure()
983 * called on them. All other devices that have not
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}
997#else
998/*
999 * Sets the queue depth for each SCSI device hanging
1000 * off the input host adapter.
1001 */
1002static void
1003ahc_linux_select_queue_depth(struct Scsi_Host *host, Scsi_Device *scsi_devs)
1004{
1005 Scsi_Device *device;
1006 Scsi_Device *ldev;
1007 struct ahc_softc *ahc;
1008 u_long flags;
1009 754
1010 ahc = *((struct ahc_softc **)host->hostdata); 755 BUG_ON(dev->active);
1011 ahc_lock(ahc, &flags);
1012 for (device = scsi_devs; device != NULL; device = device->next) {
1013 756
1014 /* 757 ahc_linux_free_device(ahc, dev);
1015 * Watch out for duplicate devices. This works around
1016 * some quirks in how the SCSI scanning code does its
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
1030 if (device->host == host) {
1031 struct ahc_linux_device *dev;
1032
1033 /*
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} 758}
1063#endif
1064 759
1065#if defined(__i386__) 760#if defined(__i386__)
1066/* 761/*
1067 * Return the disk geometry for the given SCSI device. 762 * Return the disk geometry for the given SCSI device.
1068 */ 763 */
1069static int 764static int
1070#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1071ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev, 765ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1072 sector_t capacity, int geom[]) 766 sector_t capacity, int geom[])
1073{ 767{
1074 uint8_t *bh; 768 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; 769 int heads;
1083 int sectors; 770 int sectors;
1084 int cylinders; 771 int cylinders;
@@ -1090,22 +777,11 @@ ahc_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
1090 ahc = *((struct ahc_softc **)sdev->host->hostdata); 777 ahc = *((struct ahc_softc **)sdev->host->hostdata);
1091 channel = sdev->channel; 778 channel = sdev->channel;
1092 779
1093#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1094 bh = scsi_bios_ptable(bdev); 780 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) { 781 if (bh) {
1102 ret = scsi_partsize(bh, capacity, 782 ret = scsi_partsize(bh, capacity,
1103 &geom[2], &geom[0], &geom[1]); 783 &geom[2], &geom[0], &geom[1]);
1104#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1105 kfree(bh); 784 kfree(bh);
1106#else
1107 brelse(bh);
1108#endif
1109 if (ret != -1) 785 if (ret != -1)
1110 return (ret); 786 return (ret);
1111 } 787 }
@@ -1135,7 +811,7 @@ ahc_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
1135 * Abort the current SCSI command(s). 811 * Abort the current SCSI command(s).
1136 */ 812 */
1137static int 813static int
1138ahc_linux_abort(Scsi_Cmnd *cmd) 814ahc_linux_abort(struct scsi_cmnd *cmd)
1139{ 815{
1140 int error; 816 int error;
1141 817
@@ -1149,7 +825,7 @@ ahc_linux_abort(Scsi_Cmnd *cmd)
1149 * Attempt to send a target reset message to the device that timed out. 825 * Attempt to send a target reset message to the device that timed out.
1150 */ 826 */
1151static int 827static int
1152ahc_linux_dev_reset(Scsi_Cmnd *cmd) 828ahc_linux_dev_reset(struct scsi_cmnd *cmd)
1153{ 829{
1154 int error; 830 int error;
1155 831
@@ -1163,18 +839,14 @@ ahc_linux_dev_reset(Scsi_Cmnd *cmd)
1163 * Reset the SCSI bus. 839 * Reset the SCSI bus.
1164 */ 840 */
1165static int 841static int
1166ahc_linux_bus_reset(Scsi_Cmnd *cmd) 842ahc_linux_bus_reset(struct scsi_cmnd *cmd)
1167{ 843{
1168 struct ahc_softc *ahc; 844 struct ahc_softc *ahc;
1169 u_long s;
1170 int found; 845 int found;
1171 846
1172 ahc = *(struct ahc_softc **)cmd->device->host->hostdata; 847 ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
1173 ahc_midlayer_entrypoint_lock(ahc, &s);
1174 found = ahc_reset_channel(ahc, cmd->device->channel + 'A', 848 found = ahc_reset_channel(ahc, cmd->device->channel + 'A',
1175 /*initiate reset*/TRUE); 849 /*initiate reset*/TRUE);
1176 ahc_linux_run_complete_queue(ahc);
1177 ahc_midlayer_entrypoint_unlock(ahc, &s);
1178 850
1179 if (bootverbose) 851 if (bootverbose)
1180 printf("%s: SCSI bus reset delivered. " 852 printf("%s: SCSI bus reset delivered. "
@@ -1183,7 +855,7 @@ ahc_linux_bus_reset(Scsi_Cmnd *cmd)
1183 return SUCCESS; 855 return SUCCESS;
1184} 856}
1185 857
1186Scsi_Host_Template aic7xxx_driver_template = { 858struct scsi_host_template aic7xxx_driver_template = {
1187 .module = THIS_MODULE, 859 .module = THIS_MODULE,
1188 .name = "aic7xxx", 860 .name = "aic7xxx",
1189 .proc_info = ahc_linux_proc_info, 861 .proc_info = ahc_linux_proc_info,
@@ -1206,33 +878,6 @@ Scsi_Host_Template aic7xxx_driver_template = {
1206 878
1207/**************************** Tasklet Handler *********************************/ 879/**************************** Tasklet Handler *********************************/
1208 880
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 **************************************/ 881/******************************** Macros **************************************/
1237#define BUILD_SCSIID(ahc, cmd) \ 882#define BUILD_SCSIID(ahc, cmd) \
1238 ((((cmd)->device->id << TID_SHIFT) & TID) \ 883 ((((cmd)->device->id << TID_SHIFT) & TID) \
@@ -1278,37 +923,11 @@ int
1278ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr, 923ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr,
1279 int flags, bus_dmamap_t *mapp) 924 int flags, bus_dmamap_t *mapp)
1280{ 925{
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, 926 *vaddr = pci_alloc_consistent(ahc->dev_softc,
1300 dmat->maxsize, &map->bus_addr); 927 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) 928 if (*vaddr == NULL)
1309 return (ENOMEM); 929 return ENOMEM;
1310 *mapp = map; 930 return 0;
1311 return(0);
1312} 931}
1313 932
1314void 933void
@@ -1316,7 +935,7 @@ ahc_dmamem_free(struct ahc_softc *ahc, bus_dma_tag_t dmat,
1316 void* vaddr, bus_dmamap_t map) 935 void* vaddr, bus_dmamap_t map)
1317{ 936{
1318 pci_free_consistent(ahc->dev_softc, dmat->maxsize, 937 pci_free_consistent(ahc->dev_softc, dmat->maxsize,
1319 vaddr, map->bus_addr); 938 vaddr, map);
1320} 939}
1321 940
1322int 941int
@@ -1330,7 +949,7 @@ ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map,
1330 */ 949 */
1331 bus_dma_segment_t stack_sg; 950 bus_dma_segment_t stack_sg;
1332 951
1333 stack_sg.ds_addr = map->bus_addr; 952 stack_sg.ds_addr = map;
1334 stack_sg.ds_len = dmat->maxsize; 953 stack_sg.ds_len = dmat->maxsize;
1335 cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0); 954 cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
1336 return (0); 955 return (0);
@@ -1339,12 +958,6 @@ ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map,
1339void 958void
1340ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map) 959ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
1341{ 960{
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} 961}
1349 962
1350int 963int
@@ -1550,7 +1163,7 @@ __setup("aic7xxx=", aic7xxx_setup);
1550uint32_t aic7xxx_verbose; 1163uint32_t aic7xxx_verbose;
1551 1164
1552int 1165int
1553ahc_linux_register_host(struct ahc_softc *ahc, Scsi_Host_Template *template) 1166ahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *template)
1554{ 1167{
1555 char buf[80]; 1168 char buf[80];
1556 struct Scsi_Host *host; 1169 struct Scsi_Host *host;
@@ -1564,11 +1177,7 @@ ahc_linux_register_host(struct ahc_softc *ahc, Scsi_Host_Template *template)
1564 1177
1565 *((struct ahc_softc **)host->hostdata) = ahc; 1178 *((struct ahc_softc **)host->hostdata) = ahc;
1566 ahc_lock(ahc, &s); 1179 ahc_lock(ahc, &s);
1567#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1568 scsi_assign_lock(host, &ahc->platform_data->spin_lock); 1180 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; 1181 ahc->platform_data->host = host;
1573 host->can_queue = AHC_MAX_QUEUE; 1182 host->can_queue = AHC_MAX_QUEUE;
1574 host->cmd_per_lun = 2; 1183 host->cmd_per_lun = 2;
@@ -1587,19 +1196,14 @@ ahc_linux_register_host(struct ahc_softc *ahc, Scsi_Host_Template *template)
1587 ahc_set_name(ahc, new_name); 1196 ahc_set_name(ahc, new_name);
1588 } 1197 }
1589 host->unique_id = ahc->unit; 1198 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); 1199 ahc_linux_initialize_scsi_bus(ahc);
1594 ahc_intr_enable(ahc, TRUE); 1200 ahc_intr_enable(ahc, TRUE);
1595 ahc_unlock(ahc, &s); 1201 ahc_unlock(ahc, &s);
1596 1202
1597 host->transportt = ahc_linux_transport_template; 1203 host->transportt = ahc_linux_transport_template;
1598 1204
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 */ 1205 scsi_add_host(host, (ahc->dev_softc ? &ahc->dev_softc->dev : NULL)); /* XXX handle failure */
1601 scsi_scan_host(host); 1206 scsi_scan_host(host);
1602#endif
1603 return (0); 1207 return (0);
1604} 1208}
1605 1209
@@ -1717,19 +1321,9 @@ ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
1717 if (ahc->platform_data == NULL) 1321 if (ahc->platform_data == NULL)
1718 return (ENOMEM); 1322 return (ENOMEM);
1719 memset(ahc->platform_data, 0, sizeof(struct ahc_platform_data)); 1323 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; 1324 ahc->platform_data->irq = AHC_LINUX_NOIRQ;
1723 ahc->platform_data->hw_dma_mask = 0xFFFFFFFF;
1724 ahc_lockinit(ahc); 1325 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); 1326 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; 1327 ahc->seltime = (aic7xxx_seltime & 0x3) << 4;
1734 ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4; 1328 ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4;
1735 if (aic7xxx_pci_parity == 0) 1329 if (aic7xxx_pci_parity == 0)
@@ -1746,12 +1340,8 @@ ahc_platform_free(struct ahc_softc *ahc)
1746 int i, j; 1340 int i, j;
1747 1341
1748 if (ahc->platform_data != NULL) { 1342 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) { 1343 if (ahc->platform_data->host != NULL) {
1752#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1753 scsi_remove_host(ahc->platform_data->host); 1344 scsi_remove_host(ahc->platform_data->host);
1754#endif
1755 scsi_host_put(ahc->platform_data->host); 1345 scsi_host_put(ahc->platform_data->host);
1756 } 1346 }
1757 1347
@@ -1787,16 +1377,7 @@ ahc_platform_free(struct ahc_softc *ahc)
1787 release_mem_region(ahc->platform_data->mem_busaddr, 1377 release_mem_region(ahc->platform_data->mem_busaddr,
1788 0x1000); 1378 0x1000);
1789 } 1379 }
1790#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 1380
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); 1381 free(ahc->platform_data, M_DEVBUF);
1801 } 1382 }
1802} 1383}
@@ -1820,7 +1401,7 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1820 1401
1821 dev = ahc_linux_get_device(ahc, devinfo->channel - 'A', 1402 dev = ahc_linux_get_device(ahc, devinfo->channel - 'A',
1822 devinfo->target, 1403 devinfo->target,
1823 devinfo->lun, /*alloc*/FALSE); 1404 devinfo->lun);
1824 if (dev == NULL) 1405 if (dev == NULL)
1825 return; 1406 return;
1826 was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED); 1407 was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED);
@@ -1873,7 +1454,6 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1873 dev->maxtags = 0; 1454 dev->maxtags = 0;
1874 dev->openings = 1 - dev->active; 1455 dev->openings = 1 - dev->active;
1875 } 1456 }
1876#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1877 if (dev->scsi_device != NULL) { 1457 if (dev->scsi_device != NULL) {
1878 switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) { 1458 switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) {
1879 case AHC_DEV_Q_BASIC: 1459 case AHC_DEV_Q_BASIC:
@@ -1899,90 +1479,13 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1899 break; 1479 break;
1900 } 1480 }
1901 } 1481 }
1902#endif
1903} 1482}
1904 1483
1905int 1484int
1906ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, char channel, 1485ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, char channel,
1907 int lun, u_int tag, role_t role, uint32_t status) 1486 int lun, u_int tag, role_t role, uint32_t status)
1908{ 1487{
1909 int chan; 1488 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} 1489}
1987 1490
1988static u_int 1491static u_int
@@ -2045,213 +1548,200 @@ ahc_linux_device_queue_depth(struct ahc_softc *ahc,
2045 } 1548 }
2046} 1549}
2047 1550
2048static void 1551static int
2049ahc_linux_run_device_queue(struct ahc_softc *ahc, struct ahc_linux_device *dev) 1552ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev,
1553 struct scsi_cmnd *cmd)
2050{ 1554{
2051 struct ahc_cmd *acmd;
2052 struct scsi_cmnd *cmd;
2053 struct scb *scb; 1555 struct scb *scb;
2054 struct hardware_scb *hscb; 1556 struct hardware_scb *hscb;
2055 struct ahc_initiator_tinfo *tinfo; 1557 struct ahc_initiator_tinfo *tinfo;
2056 struct ahc_tmode_tstate *tstate; 1558 struct ahc_tmode_tstate *tstate;
2057 uint16_t mask; 1559 uint16_t mask;
1560 struct scb_tailq *untagged_q = NULL;
2058 1561
2059 if ((dev->flags & AHC_DEV_ON_RUN_LIST) != 0) 1562 /*
2060 panic("running device on run list"); 1563 * Schedule us to run later. The only reason we are not
1564 * running is because the whole controller Q is frozen.
1565 */
1566 if (ahc->platform_data->qfrozen != 0)
1567 return SCSI_MLQUEUE_HOST_BUSY;
2061 1568
2062 while ((acmd = TAILQ_FIRST(&dev->busyq)) != NULL 1569 /*
2063 && dev->openings > 0 && dev->qfrozen == 0) { 1570 * We only allow one untagged transaction
1571 * per target in the initiator role unless
1572 * we are storing a full busy target *lun*
1573 * table in SCB space.
1574 */
1575 if (!blk_rq_tagged(cmd->request)
1576 && (ahc->features & AHC_SCB_BTT) == 0) {
1577 int target_offset;
2064 1578
2065 /* 1579 target_offset = cmd->device->id + cmd->device->channel * 8;
2066 * Schedule us to run later. The only reason we are not 1580 untagged_q = &(ahc->untagged_queues[target_offset]);
2067 * running is because the whole controller Q is frozen. 1581 if (!TAILQ_EMPTY(untagged_q))
2068 */ 1582 /* if we're already executing an untagged command
2069 if (ahc->platform_data->qfrozen != 0) { 1583 * we're busy to another */
2070 TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, 1584 return SCSI_MLQUEUE_DEVICE_BUSY;
2071 dev, links); 1585 }
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 1586
2092 /* 1587 /*
2093 * Fill out basics of the HSCB. 1588 * Get an scb to use.
2094 */ 1589 */
2095 hscb->control = 0; 1590 if ((scb = ahc_get_scb(ahc)) == NULL) {
2096 hscb->scsiid = BUILD_SCSIID(ahc, cmd); 1591 ahc->flags |= AHC_RESOURCE_SHORTAGE;
2097 hscb->lun = cmd->device->lun; 1592 return SCSI_MLQUEUE_HOST_BUSY;
2098 mask = SCB_GET_TARGET_MASK(ahc, scb); 1593 }
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 1594
2115 if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) { 1595 scb->io_ctx = cmd;
2116#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 1596 scb->platform_data->dev = dev;
2117 int msg_bytes; 1597 hscb = scb->hscb;
2118 uint8_t tag_msgs[2]; 1598 cmd->host_scribble = (char *)scb;
2119 1599
2120 msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs); 1600 /*
2121 if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) { 1601 * Fill out basics of the HSCB.
2122 hscb->control |= tag_msgs[0]; 1602 */
2123 if (tag_msgs[0] == MSG_ORDERED_TASK) 1603 hscb->control = 0;
2124 dev->commands_since_idle_or_otag = 0; 1604 hscb->scsiid = BUILD_SCSIID(ahc, cmd);
2125 } else 1605 hscb->lun = cmd->device->lun;
2126#endif 1606 mask = SCB_GET_TARGET_MASK(ahc, scb);
2127 if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH 1607 tinfo = ahc_fetch_transinfo(ahc, SCB_GET_CHANNEL(ahc, scb),
2128 && (dev->flags & AHC_DEV_Q_TAGGED) != 0) { 1608 SCB_GET_OUR_ID(scb),
2129 hscb->control |= MSG_ORDERED_TASK; 1609 SCB_GET_TARGET(ahc, scb), &tstate);
1610 hscb->scsirate = tinfo->scsirate;
1611 hscb->scsioffset = tinfo->curr.offset;
1612 if ((tstate->ultraenb & mask) != 0)
1613 hscb->control |= ULTRAENB;
1614
1615 if ((ahc->user_discenable & mask) != 0)
1616 hscb->control |= DISCENB;
1617
1618 if ((tstate->auto_negotiate & mask) != 0) {
1619 scb->flags |= SCB_AUTO_NEGOTIATE;
1620 scb->hscb->control |= MK_MESSAGE;
1621 }
1622
1623 if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) {
1624 int msg_bytes;
1625 uint8_t tag_msgs[2];
1626
1627 msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
1628 if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
1629 hscb->control |= tag_msgs[0];
1630 if (tag_msgs[0] == MSG_ORDERED_TASK)
2130 dev->commands_since_idle_or_otag = 0; 1631 dev->commands_since_idle_or_otag = 0;
2131 } else { 1632 } else if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH
2132 hscb->control |= MSG_SIMPLE_TASK; 1633 && (dev->flags & AHC_DEV_Q_TAGGED) != 0) {
2133 } 1634 hscb->control |= MSG_ORDERED_TASK;
2134 } 1635 dev->commands_since_idle_or_otag = 0;
2135
2136 hscb->cdb_len = cmd->cmd_len;
2137 if (hscb->cdb_len <= 12) {
2138 memcpy(hscb->shared_data.cdb, cmd->cmnd, hscb->cdb_len);
2139 } else { 1636 } else {
2140 memcpy(hscb->cdb32, cmd->cmnd, hscb->cdb_len); 1637 hscb->control |= MSG_SIMPLE_TASK;
2141 scb->flags |= SCB_CDB32_PTR;
2142 } 1638 }
1639 }
2143 1640
2144 scb->platform_data->xfer_len = 0; 1641 hscb->cdb_len = cmd->cmd_len;
2145 ahc_set_residual(scb, 0); 1642 if (hscb->cdb_len <= 12) {
2146 ahc_set_sense_residual(scb, 0); 1643 memcpy(hscb->shared_data.cdb, cmd->cmnd, hscb->cdb_len);
2147 scb->sg_count = 0; 1644 } else {
2148 if (cmd->use_sg != 0) { 1645 memcpy(hscb->cdb32, cmd->cmnd, hscb->cdb_len);
2149 struct ahc_dma_seg *sg; 1646 scb->flags |= SCB_CDB32_PTR;
2150 struct scatterlist *cur_seg; 1647 }
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 1648
2186 /* 1649 scb->platform_data->xfer_len = 0;
2187 * Copy the first SG into the "current" 1650 ahc_set_residual(scb, 0);
2188 * data pointer area. 1651 ahc_set_sense_residual(scb, 0);
2189 */ 1652 scb->sg_count = 0;
2190 scb->hscb->dataptr = scb->sg_list->addr; 1653 if (cmd->use_sg != 0) {
2191 scb->hscb->datacnt = scb->sg_list->len; 1654 struct ahc_dma_seg *sg;
2192 } else if (cmd->request_bufflen != 0) { 1655 struct scatterlist *cur_seg;
2193 struct ahc_dma_seg *sg; 1656 struct scatterlist *end_seg;
1657 int nseg;
1658
1659 cur_seg = (struct scatterlist *)cmd->request_buffer;
1660 nseg = pci_map_sg(ahc->dev_softc, cur_seg, cmd->use_sg,
1661 cmd->sc_data_direction);
1662 end_seg = cur_seg + nseg;
1663 /* Copy the segments into the SG list. */
1664 sg = scb->sg_list;
1665 /*
1666 * The sg_count may be larger than nseg if
1667 * a transfer crosses a 32bit page.
1668 */
1669 while (cur_seg < end_seg) {
2194 dma_addr_t addr; 1670 dma_addr_t addr;
2195 1671 bus_size_t len;
2196 sg = scb->sg_list; 1672 int consumed;
2197 addr = pci_map_single(ahc->dev_softc, 1673
2198 cmd->request_buffer, 1674 addr = sg_dma_address(cur_seg);
2199 cmd->request_bufflen, 1675 len = sg_dma_len(cur_seg);
2200 cmd->sc_data_direction); 1676 consumed = ahc_linux_map_seg(ahc, scb,
2201 scb->platform_data->buf_busaddr = addr; 1677 sg, addr, len);
2202 scb->sg_count = ahc_linux_map_seg(ahc, scb, 1678 sg += consumed;
2203 sg, addr, 1679 scb->sg_count += consumed;
2204 cmd->request_bufflen); 1680 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 } 1681 }
1682 sg--;
1683 sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
2225 1684
2226 ahc_sync_sglist(ahc, scb, BUS_DMASYNC_PREWRITE); 1685 /*
2227 LIST_INSERT_HEAD(&ahc->pending_scbs, scb, pending_links); 1686 * Reset the sg list pointer.
2228 dev->openings--; 1687 */
2229 dev->active++; 1688 scb->hscb->sgptr =
2230 dev->commands_issued++; 1689 ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
2231 if ((dev->flags & AHC_DEV_PERIODIC_OTAG) != 0) 1690
2232 dev->commands_since_idle_or_otag++; 1691 /*
1692 * Copy the first SG into the "current"
1693 * data pointer area.
1694 */
1695 scb->hscb->dataptr = scb->sg_list->addr;
1696 scb->hscb->datacnt = scb->sg_list->len;
1697 } else if (cmd->request_bufflen != 0) {
1698 struct ahc_dma_seg *sg;
1699 dma_addr_t addr;
1700
1701 sg = scb->sg_list;
1702 addr = pci_map_single(ahc->dev_softc,
1703 cmd->request_buffer,
1704 cmd->request_bufflen,
1705 cmd->sc_data_direction);
1706 scb->platform_data->buf_busaddr = addr;
1707 scb->sg_count = ahc_linux_map_seg(ahc, scb,
1708 sg, addr,
1709 cmd->request_bufflen);
1710 sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
2233 1711
2234 /* 1712 /*
2235 * We only allow one untagged transaction 1713 * Reset the sg list pointer.
2236 * per target in the initiator role unless
2237 * we are storing a full busy target *lun*
2238 * table in SCB space.
2239 */ 1714 */
2240 if ((scb->hscb->control & (TARGET_SCB|TAG_ENB)) == 0 1715 scb->hscb->sgptr =
2241 && (ahc->features & AHC_SCB_BTT) == 0) { 1716 ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
2242 struct scb_tailq *untagged_q; 1717
2243 int target_offset; 1718 /*
2244 1719 * Copy the first SG into the "current"
2245 target_offset = SCB_GET_TARGET_OFFSET(ahc, scb); 1720 * data pointer area.
2246 untagged_q = &(ahc->untagged_queues[target_offset]); 1721 */
2247 TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe); 1722 scb->hscb->dataptr = sg->addr;
2248 scb->flags |= SCB_UNTAGGEDQ; 1723 scb->hscb->datacnt = sg->len;
2249 if (TAILQ_FIRST(untagged_q) != scb) 1724 } else {
2250 continue; 1725 scb->hscb->sgptr = ahc_htole32(SG_LIST_NULL);
2251 } 1726 scb->hscb->dataptr = 0;
2252 scb->flags |= SCB_ACTIVE; 1727 scb->hscb->datacnt = 0;
2253 ahc_queue_scb(ahc, scb); 1728 scb->sg_count = 0;
2254 } 1729 }
1730
1731 LIST_INSERT_HEAD(&ahc->pending_scbs, scb, pending_links);
1732 dev->openings--;
1733 dev->active++;
1734 dev->commands_issued++;
1735 if ((dev->flags & AHC_DEV_PERIODIC_OTAG) != 0)
1736 dev->commands_since_idle_or_otag++;
1737
1738 scb->flags |= SCB_ACTIVE;
1739 if (untagged_q) {
1740 TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe);
1741 scb->flags |= SCB_UNTAGGEDQ;
1742 }
1743 ahc_queue_scb(ahc, scb);
1744 return 0;
2255} 1745}
2256 1746
2257/* 1747/*
@@ -2267,9 +1757,6 @@ ahc_linux_isr(int irq, void *dev_id, struct pt_regs * regs)
2267 ahc = (struct ahc_softc *) dev_id; 1757 ahc = (struct ahc_softc *) dev_id;
2268 ahc_lock(ahc, &flags); 1758 ahc_lock(ahc, &flags);
2269 ours = ahc_intr(ahc); 1759 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); 1760 ahc_unlock(ahc, &flags);
2274 return IRQ_RETVAL(ours); 1761 return IRQ_RETVAL(ours);
2275} 1762}
@@ -2278,8 +1765,6 @@ void
2278ahc_platform_flushwork(struct ahc_softc *ahc) 1765ahc_platform_flushwork(struct ahc_softc *ahc)
2279{ 1766{
2280 1767
2281 while (ahc_linux_run_complete_queue(ahc) != NULL)
2282 ;
2283} 1768}
2284 1769
2285static struct ahc_linux_target* 1770static struct ahc_linux_target*
@@ -2335,8 +1820,6 @@ ahc_linux_free_target(struct ahc_softc *ahc, struct ahc_linux_target *targ)
2335 AHC_TRANS_GOAL, /*paused*/FALSE); 1820 AHC_TRANS_GOAL, /*paused*/FALSE);
2336 ahc_update_neg_request(ahc, &devinfo, tstate, tinfo, AHC_NEG_ALWAYS); 1821 ahc_update_neg_request(ahc, &devinfo, tstate, tinfo, AHC_NEG_ALWAYS);
2337 ahc->platform_data->targets[target_offset] = NULL; 1822 ahc->platform_data->targets[target_offset] = NULL;
2338 if (targ->inq_data != NULL)
2339 free(targ->inq_data, M_DEVBUF);
2340 free(targ, M_DEVBUF); 1823 free(targ, M_DEVBUF);
2341} 1824}
2342 1825
@@ -2350,9 +1833,6 @@ ahc_linux_alloc_device(struct ahc_softc *ahc,
2350 if (dev == NULL) 1833 if (dev == NULL)
2351 return (NULL); 1834 return (NULL);
2352 memset(dev, 0, sizeof(*dev)); 1835 memset(dev, 0, sizeof(*dev));
2353 init_timer(&dev->timer);
2354 TAILQ_INIT(&dev->busyq);
2355 dev->flags = AHC_DEV_UNCONFIGURED;
2356 dev->lun = lun; 1836 dev->lun = lun;
2357 dev->target = targ; 1837 dev->target = targ;
2358 1838
@@ -2375,7 +1855,7 @@ ahc_linux_alloc_device(struct ahc_softc *ahc,
2375} 1855}
2376 1856
2377static void 1857static void
2378__ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev) 1858ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev)
2379{ 1859{
2380 struct ahc_linux_target *targ; 1860 struct ahc_linux_target *targ;
2381 1861
@@ -2387,13 +1867,6 @@ __ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev)
2387 ahc_linux_free_target(ahc, targ); 1867 ahc_linux_free_target(ahc, targ);
2388} 1868}
2389 1869
2390static void
2391ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev)
2392{
2393 del_timer_sync(&dev->timer);
2394 __ahc_linux_free_device(ahc, dev);
2395}
2396
2397void 1870void
2398ahc_send_async(struct ahc_softc *ahc, char channel, 1871ahc_send_async(struct ahc_softc *ahc, char channel,
2399 u_int target, u_int lun, ac_code code, void *arg) 1872 u_int target, u_int lun, ac_code code, void *arg)
@@ -2465,28 +1938,9 @@ ahc_send_async(struct ahc_softc *ahc, char channel,
2465 } 1938 }
2466 case AC_SENT_BDR: 1939 case AC_SENT_BDR:
2467 { 1940 {
2468#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
2469 WARN_ON(lun != CAM_LUN_WILDCARD); 1941 WARN_ON(lun != CAM_LUN_WILDCARD);
2470 scsi_report_device_reset(ahc->platform_data->host, 1942 scsi_report_device_reset(ahc->platform_data->host,
2471 channel - 'A', target); 1943 channel - 'A', target);
2472#else
2473 Scsi_Device *scsi_dev;
2474
2475 /*
2476 * Find the SCSI device associated with this
2477 * request and indicate that a UA is expected.
2478 */
2479 for (scsi_dev = ahc->platform_data->host->host_queue;
2480 scsi_dev != NULL; scsi_dev = scsi_dev->next) {
2481 if (channel - 'A' == scsi_dev->channel
2482 && target == scsi_dev->id
2483 && (lun == CAM_LUN_WILDCARD
2484 || lun == scsi_dev->lun)) {
2485 scsi_dev->was_reset = 1;
2486 scsi_dev->expecting_cc_ua = 1;
2487 }
2488 }
2489#endif
2490 break; 1944 break;
2491 } 1945 }
2492 case AC_BUS_RESET: 1946 case AC_BUS_RESET:
@@ -2506,7 +1960,7 @@ ahc_send_async(struct ahc_softc *ahc, char channel,
2506void 1960void
2507ahc_done(struct ahc_softc *ahc, struct scb *scb) 1961ahc_done(struct ahc_softc *ahc, struct scb *scb)
2508{ 1962{
2509 Scsi_Cmnd *cmd; 1963 struct scsi_cmnd *cmd;
2510 struct ahc_linux_device *dev; 1964 struct ahc_linux_device *dev;
2511 1965
2512 LIST_REMOVE(scb, pending_links); 1966 LIST_REMOVE(scb, pending_links);
@@ -2517,7 +1971,7 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
2517 target_offset = SCB_GET_TARGET_OFFSET(ahc, scb); 1971 target_offset = SCB_GET_TARGET_OFFSET(ahc, scb);
2518 untagged_q = &(ahc->untagged_queues[target_offset]); 1972 untagged_q = &(ahc->untagged_queues[target_offset]);
2519 TAILQ_REMOVE(untagged_q, scb, links.tqe); 1973 TAILQ_REMOVE(untagged_q, scb, links.tqe);
2520 ahc_run_untagged_queue(ahc, untagged_q); 1974 BUG_ON(!TAILQ_EMPTY(untagged_q));
2521 } 1975 }
2522 1976
2523 if ((scb->flags & SCB_ACTIVE) == 0) { 1977 if ((scb->flags & SCB_ACTIVE) == 0) {
@@ -2585,8 +2039,6 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
2585 } 2039 }
2586 } else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) { 2040 } else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
2587 ahc_linux_handle_scsi_status(ahc, dev, scb); 2041 ahc_linux_handle_scsi_status(ahc, dev, scb);
2588 } else if (ahc_get_transaction_status(scb) == CAM_SEL_TIMEOUT) {
2589 dev->flags |= AHC_DEV_UNCONFIGURED;
2590 } 2042 }
2591 2043
2592 if (dev->openings == 1 2044 if (dev->openings == 1
@@ -2608,16 +2060,6 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
2608 if (dev->active == 0) 2060 if (dev->active == 0)
2609 dev->commands_since_idle_or_otag = 0; 2061 dev->commands_since_idle_or_otag = 0;
2610 2062
2611 if (TAILQ_EMPTY(&dev->busyq)) {
2612 if ((dev->flags & AHC_DEV_UNCONFIGURED) != 0
2613 && dev->active == 0
2614 && (dev->flags & AHC_DEV_TIMER_ACTIVE) == 0)
2615 ahc_linux_free_device(ahc, dev);
2616 } else if ((dev->flags & AHC_DEV_ON_RUN_LIST) == 0) {
2617 TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, dev, links);
2618 dev->flags |= AHC_DEV_ON_RUN_LIST;
2619 }
2620
2621 if ((scb->flags & SCB_RECOVERY_SCB) != 0) { 2063 if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
2622 printf("Recovery SCB completes\n"); 2064 printf("Recovery SCB completes\n");
2623 if (ahc_get_transaction_status(scb) == CAM_BDR_SENT 2065 if (ahc_get_transaction_status(scb) == CAM_BDR_SENT
@@ -2661,7 +2103,7 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
2661 case SCSI_STATUS_CHECK_COND: 2103 case SCSI_STATUS_CHECK_COND:
2662 case SCSI_STATUS_CMD_TERMINATED: 2104 case SCSI_STATUS_CMD_TERMINATED:
2663 { 2105 {
2664 Scsi_Cmnd *cmd; 2106 struct scsi_cmnd *cmd;
2665 2107
2666 /* 2108 /*
2667 * Copy sense information to the OS's cmd 2109 * Copy sense information to the OS's cmd
@@ -2756,52 +2198,15 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
2756 ahc_platform_set_tags(ahc, &devinfo, 2198 ahc_platform_set_tags(ahc, &devinfo,
2757 (dev->flags & AHC_DEV_Q_BASIC) 2199 (dev->flags & AHC_DEV_Q_BASIC)
2758 ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED); 2200 ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
2759 /* FALLTHROUGH */
2760 }
2761 case SCSI_STATUS_BUSY:
2762 {
2763 /*
2764 * Set a short timer to defer sending commands for
2765 * a bit since Linux will not delay in this case.
2766 */
2767 if ((dev->flags & AHC_DEV_TIMER_ACTIVE) != 0) {
2768 printf("%s:%c:%d: Device Timer still active during "
2769 "busy processing\n", ahc_name(ahc),
2770 dev->target->channel, dev->target->target);
2771 break;
2772 }
2773 dev->flags |= AHC_DEV_TIMER_ACTIVE;
2774 dev->qfrozen++;
2775 init_timer(&dev->timer);
2776 dev->timer.data = (u_long)dev;
2777 dev->timer.expires = jiffies + (HZ/2);
2778 dev->timer.function = ahc_linux_dev_timed_unfreeze;
2779 add_timer(&dev->timer);
2780 break; 2201 break;
2781 } 2202 }
2782 } 2203 }
2783} 2204}
2784 2205
2785static void 2206static void
2786ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, Scsi_Cmnd *cmd) 2207ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, struct scsi_cmnd *cmd)
2787{ 2208{
2788 /* 2209 /*
2789 * Typically, the complete queue has very few entries
2790 * queued to it before the queue is emptied by
2791 * ahc_linux_run_complete_queue, so sorting the entries
2792 * by generation number should be inexpensive.
2793 * We perform the sort so that commands that complete
2794 * with an error are retuned in the order origionally
2795 * queued to the controller so that any subsequent retries
2796 * are performed in order. The underlying ahc routines do
2797 * not guarantee the order that aborted commands will be
2798 * returned to us.
2799 */
2800 struct ahc_completeq *completeq;
2801 struct ahc_cmd *list_cmd;
2802 struct ahc_cmd *acmd;
2803
2804 /*
2805 * Map CAM error codes into Linux Error codes. We 2210 * Map CAM error codes into Linux Error codes. We
2806 * avoid the conversion so that the DV code has the 2211 * avoid the conversion so that the DV code has the
2807 * full error information available when making 2212 * full error information available when making
@@ -2854,26 +2259,7 @@ ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, Scsi_Cmnd *cmd)
2854 new_status = DID_ERROR; 2259 new_status = DID_ERROR;
2855 break; 2260 break;
2856 case CAM_REQUEUE_REQ: 2261 case CAM_REQUEUE_REQ:
2857 /* 2262 new_status = DID_REQUEUE;
2858 * If we want the request requeued, make sure there
2859 * are sufficent retries. In the old scsi error code,
2860 * we used to be able to specify a result code that
2861 * bypassed the retry count. Now we must use this
2862 * hack. We also "fake" a check condition with
2863 * a sense code of ABORTED COMMAND. This seems to
2864 * evoke a retry even if this command is being sent
2865 * via the eh thread. Ick! Ick! Ick!
2866 */
2867 if (cmd->retries > 0)
2868 cmd->retries--;
2869 new_status = DID_OK;
2870 ahc_cmd_set_scsi_status(cmd, SCSI_STATUS_CHECK_COND);
2871 cmd->result |= (DRIVER_SENSE << 24);
2872 memset(cmd->sense_buffer, 0,
2873 sizeof(cmd->sense_buffer));
2874 cmd->sense_buffer[0] = SSD_ERRCODE_VALID
2875 | SSD_CURRENT_ERROR;
2876 cmd->sense_buffer[2] = SSD_KEY_ABORTED_COMMAND;
2877 break; 2263 break;
2878 default: 2264 default:
2879 /* We should never get here */ 2265 /* We should never get here */
@@ -2884,17 +2270,7 @@ ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, Scsi_Cmnd *cmd)
2884 ahc_cmd_set_transaction_status(cmd, new_status); 2270 ahc_cmd_set_transaction_status(cmd, new_status);
2885 } 2271 }
2886 2272
2887 completeq = &ahc->platform_data->completeq; 2273 cmd->scsi_done(cmd);
2888 list_cmd = TAILQ_FIRST(completeq);
2889 acmd = (struct ahc_cmd *)cmd;
2890 while (list_cmd != NULL
2891 && acmd_scsi_cmd(list_cmd).serial_number
2892 < acmd_scsi_cmd(acmd).serial_number)
2893 list_cmd = TAILQ_NEXT(list_cmd, acmd_links.tqe);
2894 if (list_cmd != NULL)
2895 TAILQ_INSERT_BEFORE(list_cmd, acmd, acmd_links.tqe);
2896 else
2897 TAILQ_INSERT_TAIL(completeq, acmd, acmd_links.tqe);
2898} 2274}
2899 2275
2900static void 2276static void
@@ -2942,7 +2318,6 @@ ahc_linux_release_simq(u_long arg)
2942 ahc->platform_data->qfrozen--; 2318 ahc->platform_data->qfrozen--;
2943 if (ahc->platform_data->qfrozen == 0) 2319 if (ahc->platform_data->qfrozen == 0)
2944 unblock_reqs = 1; 2320 unblock_reqs = 1;
2945 ahc_schedule_runq(ahc);
2946 ahc_unlock(ahc, &s); 2321 ahc_unlock(ahc, &s);
2947 /* 2322 /*
2948 * There is still a race here. The mid-layer 2323 * There is still a race here. The mid-layer
@@ -2954,37 +2329,12 @@ ahc_linux_release_simq(u_long arg)
2954 scsi_unblock_requests(ahc->platform_data->host); 2329 scsi_unblock_requests(ahc->platform_data->host);
2955} 2330}
2956 2331
2957static void
2958ahc_linux_dev_timed_unfreeze(u_long arg)
2959{
2960 struct ahc_linux_device *dev;
2961 struct ahc_softc *ahc;
2962 u_long s;
2963
2964 dev = (struct ahc_linux_device *)arg;
2965 ahc = dev->target->ahc;
2966 ahc_lock(ahc, &s);
2967 dev->flags &= ~AHC_DEV_TIMER_ACTIVE;
2968 if (dev->qfrozen > 0)
2969 dev->qfrozen--;
2970 if (dev->qfrozen == 0
2971 && (dev->flags & AHC_DEV_ON_RUN_LIST) == 0)
2972 ahc_linux_run_device_queue(ahc, dev);
2973 if (TAILQ_EMPTY(&dev->busyq)
2974 && dev->active == 0)
2975 __ahc_linux_free_device(ahc, dev);
2976 ahc_unlock(ahc, &s);
2977}
2978
2979static int 2332static int
2980ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag) 2333ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag)
2981{ 2334{
2982 struct ahc_softc *ahc; 2335 struct ahc_softc *ahc;
2983 struct ahc_cmd *acmd;
2984 struct ahc_cmd *list_acmd;
2985 struct ahc_linux_device *dev; 2336 struct ahc_linux_device *dev;
2986 struct scb *pending_scb; 2337 struct scb *pending_scb;
2987 u_long s;
2988 u_int saved_scbptr; 2338 u_int saved_scbptr;
2989 u_int active_scb_index; 2339 u_int active_scb_index;
2990 u_int last_phase; 2340 u_int last_phase;
@@ -3000,7 +2350,6 @@ ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
3000 paused = FALSE; 2350 paused = FALSE;
3001 wait = FALSE; 2351 wait = FALSE;
3002 ahc = *(struct ahc_softc **)cmd->device->host->hostdata; 2352 ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
3003 acmd = (struct ahc_cmd *)cmd;
3004 2353
3005 printf("%s:%d:%d:%d: Attempting to queue a%s message\n", 2354 printf("%s:%d:%d:%d: Attempting to queue a%s message\n",
3006 ahc_name(ahc), cmd->device->channel, 2355 ahc_name(ahc), cmd->device->channel,
@@ -3013,22 +2362,6 @@ ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
3013 printf("\n"); 2362 printf("\n");
3014 2363
3015 /* 2364 /*
3016 * In all versions of Linux, we have to work around
3017 * a major flaw in how the mid-layer is locked down
3018 * if we are to sleep successfully in our error handler
3019 * while allowing our interrupt handler to run. Since
3020 * the midlayer acquires either the io_request_lock or
3021 * our lock prior to calling us, we must use the
3022 * spin_unlock_irq() method for unlocking our lock.
3023 * This will force interrupts to be enabled on the
3024 * current CPU. Since the EH thread should not have
3025 * been running with CPU interrupts disabled other than
3026 * by acquiring either the io_request_lock or our own
3027 * lock, this *should* be safe.
3028 */
3029 ahc_midlayer_entrypoint_lock(ahc, &s);
3030
3031 /*
3032 * First determine if we currently own this command. 2365 * First determine if we currently own this command.
3033 * Start by searching the device queue. If not found 2366 * Start by searching the device queue. If not found
3034 * there, check the pending_scb list. If not found 2367 * there, check the pending_scb list. If not found
@@ -3036,7 +2369,7 @@ ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
3036 * command, return success. 2369 * command, return success.
3037 */ 2370 */
3038 dev = ahc_linux_get_device(ahc, cmd->device->channel, cmd->device->id, 2371 dev = ahc_linux_get_device(ahc, cmd->device->channel, cmd->device->id,
3039 cmd->device->lun, /*alloc*/FALSE); 2372 cmd->device->lun);
3040 2373
3041 if (dev == NULL) { 2374 if (dev == NULL) {
3042 /* 2375 /*
@@ -3050,24 +2383,6 @@ ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
3050 goto no_cmd; 2383 goto no_cmd;
3051 } 2384 }
3052 2385
3053 TAILQ_FOREACH(list_acmd, &dev->busyq, acmd_links.tqe) {
3054 if (list_acmd == acmd)
3055 break;
3056 }
3057
3058 if (list_acmd != NULL) {
3059 printf("%s:%d:%d:%d: Command found on device queue\n",
3060 ahc_name(ahc), cmd->device->channel, cmd->device->id,
3061 cmd->device->lun);
3062 if (flag == SCB_ABORT) {
3063 TAILQ_REMOVE(&dev->busyq, list_acmd, acmd_links.tqe);
3064 cmd->result = DID_ABORT << 16;
3065 ahc_linux_queue_cmd_complete(ahc, cmd);
3066 retval = SUCCESS;
3067 goto done;
3068 }
3069 }
3070
3071 if ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED)) == 0 2386 if ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED)) == 0
3072 && ahc_search_untagged_queues(ahc, cmd, cmd->device->id, 2387 && ahc_search_untagged_queues(ahc, cmd, cmd->device->id,
3073 cmd->device->channel + 'A', 2388 cmd->device->channel + 'A',
@@ -3301,53 +2616,42 @@ done:
3301 } 2616 }
3302 spin_lock_irq(&ahc->platform_data->spin_lock); 2617 spin_lock_irq(&ahc->platform_data->spin_lock);
3303 } 2618 }
3304 ahc_schedule_runq(ahc);
3305 ahc_linux_run_complete_queue(ahc);
3306 ahc_midlayer_entrypoint_unlock(ahc, &s);
3307 return (retval); 2619 return (retval);
3308} 2620}
3309 2621
3310void 2622void
3311ahc_platform_dump_card_state(struct ahc_softc *ahc) 2623ahc_platform_dump_card_state(struct ahc_softc *ahc)
3312{ 2624{
3313 struct ahc_linux_device *dev; 2625}
3314 int channel;
3315 int maxchannel;
3316 int target;
3317 int maxtarget;
3318 int lun;
3319 int i;
3320
3321 maxchannel = (ahc->features & AHC_TWIN) ? 1 : 0;
3322 maxtarget = (ahc->features & AHC_WIDE) ? 15 : 7;
3323 for (channel = 0; channel <= maxchannel; channel++) {
3324 2626
3325 for (target = 0; target <=maxtarget; target++) { 2627static void ahc_linux_exit(void);
3326 2628
3327 for (lun = 0; lun < AHC_NUM_LUNS; lun++) { 2629static void ahc_linux_get_width(struct scsi_target *starget)
3328 struct ahc_cmd *acmd; 2630{
2631 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2632 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
2633 struct ahc_tmode_tstate *tstate;
2634 struct ahc_initiator_tinfo *tinfo
2635 = ahc_fetch_transinfo(ahc,
2636 starget->channel + 'A',
2637 shost->this_id, starget->id, &tstate);
2638 spi_width(starget) = tinfo->curr.width;
2639}
3329 2640
3330 dev = ahc_linux_get_device(ahc, channel, target, 2641static void ahc_linux_set_width(struct scsi_target *starget, int width)
3331 lun, /*alloc*/FALSE); 2642{
3332 if (dev == NULL) 2643 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3333 continue; 2644 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
2645 struct ahc_devinfo devinfo;
2646 unsigned long flags;
3334 2647
3335 printf("DevQ(%d:%d:%d): ", 2648 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
3336 channel, target, lun); 2649 starget->channel + 'A', ROLE_INITIATOR);
3337 i = 0; 2650 ahc_lock(ahc, &flags);
3338 TAILQ_FOREACH(acmd, &dev->busyq, 2651 ahc_set_width(ahc, &devinfo, width, AHC_TRANS_GOAL, FALSE);
3339 acmd_links.tqe) { 2652 ahc_unlock(ahc, &flags);
3340 if (i++ > AHC_SCB_MAX)
3341 break;
3342 }
3343 printf("%d waiting\n", i);
3344 }
3345 }
3346 }
3347} 2653}
3348 2654
3349static void ahc_linux_exit(void);
3350
3351static void ahc_linux_get_period(struct scsi_target *starget) 2655static void ahc_linux_get_period(struct scsi_target *starget)
3352{ 2656{
3353 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2657 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
@@ -3378,8 +2682,21 @@ static void ahc_linux_set_period(struct scsi_target *starget, int period)
3378 if (offset == 0) 2682 if (offset == 0)
3379 offset = MAX_OFFSET; 2683 offset = MAX_OFFSET;
3380 2684
2685 if (period < 9)
2686 period = 9; /* 12.5ns is our minimum */
2687 if (period == 9)
2688 ppr_options |= MSG_EXT_PPR_DT_REQ;
2689
3381 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 2690 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
3382 starget->channel + 'A', ROLE_INITIATOR); 2691 starget->channel + 'A', ROLE_INITIATOR);
2692
2693 /* all PPR requests apart from QAS require wide transfers */
2694 if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) {
2695 ahc_linux_get_width(starget);
2696 if (spi_width(starget) == 0)
2697 ppr_options &= MSG_EXT_PPR_QAS_REQ;
2698 }
2699
3383 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); 2700 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
3384 ahc_lock(ahc, &flags); 2701 ahc_lock(ahc, &flags);
3385 ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset, 2702 ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset,
@@ -3427,32 +2744,6 @@ static void ahc_linux_set_offset(struct scsi_target *starget, int offset)
3427 ahc_unlock(ahc, &flags); 2744 ahc_unlock(ahc, &flags);
3428} 2745}
3429 2746
3430static void ahc_linux_get_width(struct scsi_target *starget)
3431{
3432 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3433 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
3434 struct ahc_tmode_tstate *tstate;
3435 struct ahc_initiator_tinfo *tinfo
3436 = ahc_fetch_transinfo(ahc,
3437 starget->channel + 'A',
3438 shost->this_id, starget->id, &tstate);
3439 spi_width(starget) = tinfo->curr.width;
3440}
3441
3442static void ahc_linux_set_width(struct scsi_target *starget, int width)
3443{
3444 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3445 struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
3446 struct ahc_devinfo devinfo;
3447 unsigned long flags;
3448
3449 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
3450 starget->channel + 'A', ROLE_INITIATOR);
3451 ahc_lock(ahc, &flags);
3452 ahc_set_width(ahc, &devinfo, width, AHC_TRANS_GOAL, FALSE);
3453 ahc_unlock(ahc, &flags);
3454}
3455
3456static void ahc_linux_get_dt(struct scsi_target *starget) 2747static void ahc_linux_get_dt(struct scsi_target *starget)
3457{ 2748{
3458 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2749 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
@@ -3481,10 +2772,15 @@ static void ahc_linux_set_dt(struct scsi_target *starget, int dt)
3481 unsigned long flags; 2772 unsigned long flags;
3482 struct ahc_syncrate *syncrate; 2773 struct ahc_syncrate *syncrate;
3483 2774
2775 if (dt) {
2776 period = 9; /* 12.5ns is the only period valid for DT */
2777 ppr_options |= MSG_EXT_PPR_DT_REQ;
2778 } else if (period == 9)
2779 period = 10; /* if resetting DT, period must be >= 25ns */
2780
3484 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 2781 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
3485 starget->channel + 'A', ROLE_INITIATOR); 2782 starget->channel + 'A', ROLE_INITIATOR);
3486 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, 2783 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options,AHC_SYNCRATE_DT);
3487 dt ? AHC_SYNCRATE_DT : AHC_SYNCRATE_ULTRA2);
3488 ahc_lock(ahc, &flags); 2784 ahc_lock(ahc, &flags);
3489 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->curr.offset, 2785 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->curr.offset,
3490 ppr_options, AHC_TRANS_GOAL, FALSE); 2786 ppr_options, AHC_TRANS_GOAL, FALSE);
@@ -3516,7 +2812,6 @@ static void ahc_linux_set_qas(struct scsi_target *starget, int qas)
3516 unsigned int ppr_options = tinfo->curr.ppr_options 2812 unsigned int ppr_options = tinfo->curr.ppr_options
3517 & ~MSG_EXT_PPR_QAS_REQ; 2813 & ~MSG_EXT_PPR_QAS_REQ;
3518 unsigned int period = tinfo->curr.period; 2814 unsigned int period = tinfo->curr.period;
3519 unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
3520 unsigned long flags; 2815 unsigned long flags;
3521 struct ahc_syncrate *syncrate; 2816 struct ahc_syncrate *syncrate;
3522 2817
@@ -3525,8 +2820,7 @@ static void ahc_linux_set_qas(struct scsi_target *starget, int qas)
3525 2820
3526 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 2821 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
3527 starget->channel + 'A', ROLE_INITIATOR); 2822 starget->channel + 'A', ROLE_INITIATOR);
3528 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, 2823 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
3529 dt ? AHC_SYNCRATE_DT : AHC_SYNCRATE_ULTRA2);
3530 ahc_lock(ahc, &flags); 2824 ahc_lock(ahc, &flags);
3531 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->curr.offset, 2825 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->curr.offset,
3532 ppr_options, AHC_TRANS_GOAL, FALSE); 2826 ppr_options, AHC_TRANS_GOAL, FALSE);
@@ -3558,7 +2852,6 @@ static void ahc_linux_set_iu(struct scsi_target *starget, int iu)
3558 unsigned int ppr_options = tinfo->curr.ppr_options 2852 unsigned int ppr_options = tinfo->curr.ppr_options
3559 & ~MSG_EXT_PPR_IU_REQ; 2853 & ~MSG_EXT_PPR_IU_REQ;
3560 unsigned int period = tinfo->curr.period; 2854 unsigned int period = tinfo->curr.period;
3561 unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
3562 unsigned long flags; 2855 unsigned long flags;
3563 struct ahc_syncrate *syncrate; 2856 struct ahc_syncrate *syncrate;
3564 2857
@@ -3567,8 +2860,7 @@ static void ahc_linux_set_iu(struct scsi_target *starget, int iu)
3567 2860
3568 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 2861 ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
3569 starget->channel + 'A', ROLE_INITIATOR); 2862 starget->channel + 'A', ROLE_INITIATOR);
3570 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, 2863 syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
3571 dt ? AHC_SYNCRATE_DT : AHC_SYNCRATE_ULTRA2);
3572 ahc_lock(ahc, &flags); 2864 ahc_lock(ahc, &flags);
3573 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->curr.offset, 2865 ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->curr.offset,
3574 ppr_options, AHC_TRANS_GOAL, FALSE); 2866 ppr_options, AHC_TRANS_GOAL, FALSE);
@@ -3601,7 +2893,6 @@ static struct spi_function_template ahc_linux_transport_functions = {
3601static int __init 2893static int __init
3602ahc_linux_init(void) 2894ahc_linux_init(void)
3603{ 2895{
3604#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
3605 ahc_linux_transport_template = spi_attach_transport(&ahc_linux_transport_functions); 2896 ahc_linux_transport_template = spi_attach_transport(&ahc_linux_transport_functions);
3606 if (!ahc_linux_transport_template) 2897 if (!ahc_linux_transport_template)
3607 return -ENODEV; 2898 return -ENODEV;
@@ -3610,29 +2901,11 @@ ahc_linux_init(void)
3610 spi_release_transport(ahc_linux_transport_template); 2901 spi_release_transport(ahc_linux_transport_template);
3611 ahc_linux_exit(); 2902 ahc_linux_exit();
3612 return -ENODEV; 2903 return -ENODEV;
3613#else
3614 scsi_register_module(MODULE_SCSI_HA, &aic7xxx_driver_template);
3615 if (aic7xxx_driver_template.present == 0) {
3616 scsi_unregister_module(MODULE_SCSI_HA,
3617 &aic7xxx_driver_template);
3618 return (-ENODEV);
3619 }
3620
3621 return (0);
3622#endif
3623} 2904}
3624 2905
3625static void 2906static void
3626ahc_linux_exit(void) 2907ahc_linux_exit(void)
3627{ 2908{
3628#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
3629 /*
3630 * In 2.4 we have to unregister from the PCI core _after_
3631 * unregistering from the scsi midlayer to avoid dangling
3632 * references.
3633 */
3634 scsi_unregister_module(MODULE_SCSI_HA, &aic7xxx_driver_template);
3635#endif
3636 ahc_linux_pci_exit(); 2909 ahc_linux_pci_exit();
3637 ahc_linux_eisa_exit(); 2910 ahc_linux_eisa_exit();
3638 spi_release_transport(ahc_linux_transport_template); 2911 spi_release_transport(ahc_linux_transport_template);
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.h b/drivers/scsi/aic7xxx/aic7xxx_osm.h
index c401537067b6..30c200d5bcd5 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.h
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.h
@@ -59,6 +59,7 @@
59#ifndef _AIC7XXX_LINUX_H_ 59#ifndef _AIC7XXX_LINUX_H_
60#define _AIC7XXX_LINUX_H_ 60#define _AIC7XXX_LINUX_H_
61 61
62#include <linux/config.h>
62#include <linux/types.h> 63#include <linux/types.h>
63#include <linux/blkdev.h> 64#include <linux/blkdev.h>
64#include <linux/delay.h> 65#include <linux/delay.h>
@@ -66,18 +67,21 @@
66#include <linux/pci.h> 67#include <linux/pci.h>
67#include <linux/smp_lock.h> 68#include <linux/smp_lock.h>
68#include <linux/version.h> 69#include <linux/version.h>
70#include <linux/interrupt.h>
69#include <linux/module.h> 71#include <linux/module.h>
72#include <linux/slab.h>
70#include <asm/byteorder.h> 73#include <asm/byteorder.h>
71#include <asm/io.h> 74#include <asm/io.h>
72 75
73#include <linux/interrupt.h> /* For tasklet support. */ 76#include <scsi/scsi.h>
74#include <linux/config.h> 77#include <scsi/scsi_cmnd.h>
75#include <linux/slab.h> 78#include <scsi/scsi_eh.h>
79#include <scsi/scsi_device.h>
80#include <scsi/scsi_host.h>
81#include <scsi/scsi_tcq.h>
76 82
77/* Core SCSI definitions */ 83/* Core SCSI definitions */
78#define AIC_LIB_PREFIX ahc 84#define AIC_LIB_PREFIX ahc
79#include "scsi.h"
80#include <scsi/scsi_host.h>
81 85
82/* Name space conflict with BSD queue macros */ 86/* Name space conflict with BSD queue macros */
83#ifdef LIST_HEAD 87#ifdef LIST_HEAD
@@ -106,7 +110,7 @@
106/************************* Forward Declarations *******************************/ 110/************************* Forward Declarations *******************************/
107struct ahc_softc; 111struct ahc_softc;
108typedef struct pci_dev *ahc_dev_softc_t; 112typedef struct pci_dev *ahc_dev_softc_t;
109typedef Scsi_Cmnd *ahc_io_ctx_t; 113typedef struct scsi_cmnd *ahc_io_ctx_t;
110 114
111/******************************* Byte Order ***********************************/ 115/******************************* Byte Order ***********************************/
112#define ahc_htobe16(x) cpu_to_be16(x) 116#define ahc_htobe16(x) cpu_to_be16(x)
@@ -144,7 +148,7 @@ typedef Scsi_Cmnd *ahc_io_ctx_t;
144extern u_int aic7xxx_no_probe; 148extern u_int aic7xxx_no_probe;
145extern u_int aic7xxx_allow_memio; 149extern u_int aic7xxx_allow_memio;
146extern int aic7xxx_detect_complete; 150extern int aic7xxx_detect_complete;
147extern Scsi_Host_Template aic7xxx_driver_template; 151extern struct scsi_host_template aic7xxx_driver_template;
148 152
149/***************************** Bus Space/DMA **********************************/ 153/***************************** Bus Space/DMA **********************************/
150 154
@@ -174,11 +178,7 @@ struct ahc_linux_dma_tag
174}; 178};
175typedef struct ahc_linux_dma_tag* bus_dma_tag_t; 179typedef struct ahc_linux_dma_tag* bus_dma_tag_t;
176 180
177struct ahc_linux_dmamap 181typedef dma_addr_t bus_dmamap_t;
178{
179 dma_addr_t bus_addr;
180};
181typedef struct ahc_linux_dmamap* bus_dmamap_t;
182 182
183typedef int bus_dma_filter_t(void*, dma_addr_t); 183typedef int bus_dma_filter_t(void*, dma_addr_t);
184typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); 184typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
@@ -281,12 +281,6 @@ ahc_scb_timer_reset(struct scb *scb, u_int usec)
281/***************************** SMP support ************************************/ 281/***************************** SMP support ************************************/
282#include <linux/spinlock.h> 282#include <linux/spinlock.h>
283 283
284#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) || defined(SCSI_HAS_HOST_LOCK))
285#define AHC_SCSI_HAS_HOST_LOCK 1
286#else
287#define AHC_SCSI_HAS_HOST_LOCK 0
288#endif
289
290#define AIC7XXX_DRIVER_VERSION "6.2.36" 284#define AIC7XXX_DRIVER_VERSION "6.2.36"
291 285
292/**************************** Front End Queues ********************************/ 286/**************************** Front End Queues ********************************/
@@ -328,20 +322,15 @@ struct ahc_cmd {
328 */ 322 */
329TAILQ_HEAD(ahc_busyq, ahc_cmd); 323TAILQ_HEAD(ahc_busyq, ahc_cmd);
330typedef enum { 324typedef enum {
331 AHC_DEV_UNCONFIGURED = 0x01,
332 AHC_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */ 325 AHC_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
333 AHC_DEV_TIMER_ACTIVE = 0x04, /* Our timer is active */
334 AHC_DEV_ON_RUN_LIST = 0x08, /* Queued to be run later */
335 AHC_DEV_Q_BASIC = 0x10, /* Allow basic device queuing */ 326 AHC_DEV_Q_BASIC = 0x10, /* Allow basic device queuing */
336 AHC_DEV_Q_TAGGED = 0x20, /* Allow full SCSI2 command queueing */ 327 AHC_DEV_Q_TAGGED = 0x20, /* Allow full SCSI2 command queueing */
337 AHC_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */ 328 AHC_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */
338 AHC_DEV_SLAVE_CONFIGURED = 0x80 /* slave_configure() has been called */
339} ahc_linux_dev_flags; 329} ahc_linux_dev_flags;
340 330
341struct ahc_linux_target; 331struct ahc_linux_target;
342struct ahc_linux_device { 332struct ahc_linux_device {
343 TAILQ_ENTRY(ahc_linux_device) links; 333 TAILQ_ENTRY(ahc_linux_device) links;
344 struct ahc_busyq busyq;
345 334
346 /* 335 /*
347 * The number of transactions currently 336 * The number of transactions currently
@@ -382,11 +371,6 @@ struct ahc_linux_device {
382 ahc_linux_dev_flags flags; 371 ahc_linux_dev_flags flags;
383 372
384 /* 373 /*
385 * Per device timer.
386 */
387 struct timer_list timer;
388
389 /*
390 * The high limit for the tags variable. 374 * The high limit for the tags variable.
391 */ 375 */
392 u_int maxtags; 376 u_int maxtags;
@@ -419,14 +403,10 @@ struct ahc_linux_device {
419#define AHC_OTAG_THRESH 500 403#define AHC_OTAG_THRESH 500
420 404
421 int lun; 405 int lun;
422 Scsi_Device *scsi_device; 406 struct scsi_device *scsi_device;
423 struct ahc_linux_target *target; 407 struct ahc_linux_target *target;
424}; 408};
425 409
426typedef enum {
427 AHC_INQ_VALID = 0x02,
428} ahc_linux_targ_flags;
429
430struct ahc_linux_target { 410struct ahc_linux_target {
431 struct ahc_linux_device *devices[AHC_NUM_LUNS]; 411 struct ahc_linux_device *devices[AHC_NUM_LUNS];
432 int channel; 412 int channel;
@@ -434,8 +414,6 @@ struct ahc_linux_target {
434 int refcount; 414 int refcount;
435 struct ahc_transinfo last_tinfo; 415 struct ahc_transinfo last_tinfo;
436 struct ahc_softc *ahc; 416 struct ahc_softc *ahc;
437 ahc_linux_targ_flags flags;
438 struct scsi_inquiry_data *inq_data;
439}; 417};
440 418
441/********************* Definitions Required by the Core ***********************/ 419/********************* Definitions Required by the Core ***********************/
@@ -445,32 +423,16 @@ struct ahc_linux_target {
445 * manner and are allocated below 4GB, the number of S/G segments is 423 * manner and are allocated below 4GB, the number of S/G segments is
446 * unrestricted. 424 * unrestricted.
447 */ 425 */
448#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
449/*
450 * We dynamically adjust the number of segments in pre-2.5 kernels to
451 * avoid fragmentation issues in the SCSI mid-layer's private memory
452 * allocator. See aic7xxx_osm.c ahc_linux_size_nseg() for details.
453 */
454extern u_int ahc_linux_nseg;
455#define AHC_NSEG ahc_linux_nseg
456#define AHC_LINUX_MIN_NSEG 64
457#else
458#define AHC_NSEG 128 426#define AHC_NSEG 128
459#endif
460 427
461/* 428/*
462 * Per-SCB OSM storage. 429 * Per-SCB OSM storage.
463 */ 430 */
464typedef enum {
465 AHC_UP_EH_SEMAPHORE = 0x1
466} ahc_linux_scb_flags;
467
468struct scb_platform_data { 431struct scb_platform_data {
469 struct ahc_linux_device *dev; 432 struct ahc_linux_device *dev;
470 dma_addr_t buf_busaddr; 433 dma_addr_t buf_busaddr;
471 uint32_t xfer_len; 434 uint32_t xfer_len;
472 uint32_t sense_resid; /* Auto-Sense residual */ 435 uint32_t sense_resid; /* Auto-Sense residual */
473 ahc_linux_scb_flags flags;
474}; 436};
475 437
476/* 438/*
@@ -479,39 +441,24 @@ struct scb_platform_data {
479 * alignment restrictions of the various platforms supported by 441 * alignment restrictions of the various platforms supported by
480 * this driver. 442 * this driver.
481 */ 443 */
482typedef enum {
483 AHC_RUN_CMPLT_Q_TIMER = 0x10
484} ahc_linux_softc_flags;
485
486TAILQ_HEAD(ahc_completeq, ahc_cmd);
487
488struct ahc_platform_data { 444struct ahc_platform_data {
489 /* 445 /*
490 * Fields accessed from interrupt context. 446 * Fields accessed from interrupt context.
491 */ 447 */
492 struct ahc_linux_target *targets[AHC_NUM_TARGETS]; 448 struct ahc_linux_target *targets[AHC_NUM_TARGETS];
493 TAILQ_HEAD(, ahc_linux_device) device_runq;
494 struct ahc_completeq completeq;
495 449
496 spinlock_t spin_lock; 450 spinlock_t spin_lock;
497 struct tasklet_struct runq_tasklet;
498 u_int qfrozen; 451 u_int qfrozen;
499 pid_t dv_pid;
500 struct timer_list completeq_timer;
501 struct timer_list reset_timer; 452 struct timer_list reset_timer;
502 struct semaphore eh_sem; 453 struct semaphore eh_sem;
503 struct semaphore dv_sem;
504 struct semaphore dv_cmd_sem; /* XXX This needs to be in
505 * the target struct
506 */
507 struct scsi_device *dv_scsi_dev;
508 struct Scsi_Host *host; /* pointer to scsi host */ 454 struct Scsi_Host *host; /* pointer to scsi host */
509#define AHC_LINUX_NOIRQ ((uint32_t)~0) 455#define AHC_LINUX_NOIRQ ((uint32_t)~0)
510 uint32_t irq; /* IRQ for this adapter */ 456 uint32_t irq; /* IRQ for this adapter */
511 uint32_t bios_address; 457 uint32_t bios_address;
512 uint32_t mem_busaddr; /* Mem Base Addr */ 458 uint32_t mem_busaddr; /* Mem Base Addr */
513 uint64_t hw_dma_mask; 459
514 ahc_linux_softc_flags flags; 460#define AHC_UP_EH_SEMAPHORE 0x1
461 uint32_t flags;
515}; 462};
516 463
517/************************** OS Utility Wrappers *******************************/ 464/************************** OS Utility Wrappers *******************************/
@@ -600,7 +547,7 @@ ahc_insb(struct ahc_softc * ahc, long port, uint8_t *array, int count)
600 547
601/**************************** Initialization **********************************/ 548/**************************** Initialization **********************************/
602int ahc_linux_register_host(struct ahc_softc *, 549int ahc_linux_register_host(struct ahc_softc *,
603 Scsi_Host_Template *); 550 struct scsi_host_template *);
604 551
605uint64_t ahc_linux_get_memsize(void); 552uint64_t ahc_linux_get_memsize(void);
606 553
@@ -621,17 +568,6 @@ static __inline void ahc_lockinit(struct ahc_softc *);
621static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags); 568static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags);
622static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags); 569static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags);
623 570
624/* Lock acquisition and release of the above lock in midlayer entry points. */
625static __inline void ahc_midlayer_entrypoint_lock(struct ahc_softc *,
626 unsigned long *flags);
627static __inline void ahc_midlayer_entrypoint_unlock(struct ahc_softc *,
628 unsigned long *flags);
629
630/* Lock held during command compeletion to the upper layer */
631static __inline void ahc_done_lockinit(struct ahc_softc *);
632static __inline void ahc_done_lock(struct ahc_softc *, unsigned long *flags);
633static __inline void ahc_done_unlock(struct ahc_softc *, unsigned long *flags);
634
635/* Lock held during ahc_list manipulation and ahc softc frees */ 571/* Lock held during ahc_list manipulation and ahc softc frees */
636extern spinlock_t ahc_list_spinlock; 572extern spinlock_t ahc_list_spinlock;
637static __inline void ahc_list_lockinit(void); 573static __inline void ahc_list_lockinit(void);
@@ -657,57 +593,6 @@ ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
657} 593}
658 594
659static __inline void 595static __inline void
660ahc_midlayer_entrypoint_lock(struct ahc_softc *ahc, unsigned long *flags)
661{
662 /*
663 * In 2.5.X and some 2.4.X versions, the midlayer takes our
664 * lock just before calling us, so we avoid locking again.
665 * For other kernel versions, the io_request_lock is taken
666 * just before our entry point is called. In this case, we
667 * trade the io_request_lock for our per-softc lock.
668 */
669#if AHC_SCSI_HAS_HOST_LOCK == 0
670 spin_unlock(&io_request_lock);
671 spin_lock(&ahc->platform_data->spin_lock);
672#endif
673}
674
675static __inline void
676ahc_midlayer_entrypoint_unlock(struct ahc_softc *ahc, unsigned long *flags)
677{
678#if AHC_SCSI_HAS_HOST_LOCK == 0
679 spin_unlock(&ahc->platform_data->spin_lock);
680 spin_lock(&io_request_lock);
681#endif
682}
683
684static __inline void
685ahc_done_lockinit(struct ahc_softc *ahc)
686{
687 /*
688 * In 2.5.X, our own lock is held during completions.
689 * In previous versions, the io_request_lock is used.
690 * In either case, we can't initialize this lock again.
691 */
692}
693
694static __inline void
695ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags)
696{
697#if AHC_SCSI_HAS_HOST_LOCK == 0
698 spin_lock_irqsave(&io_request_lock, *flags);
699#endif
700}
701
702static __inline void
703ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags)
704{
705#if AHC_SCSI_HAS_HOST_LOCK == 0
706 spin_unlock_irqrestore(&io_request_lock, *flags);
707#endif
708}
709
710static __inline void
711ahc_list_lockinit(void) 596ahc_list_lockinit(void)
712{ 597{
713 spin_lock_init(&ahc_list_spinlock); 598 spin_lock_init(&ahc_list_spinlock);
@@ -773,12 +658,6 @@ typedef enum
773} ahc_power_state; 658} ahc_power_state;
774 659
775/**************************** VL/EISA Routines ********************************/ 660/**************************** VL/EISA Routines ********************************/
776#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) \
777 && (defined(__i386__) || defined(__alpha__)) \
778 && (!defined(CONFIG_EISA)))
779#define CONFIG_EISA
780#endif
781
782#ifdef CONFIG_EISA 661#ifdef CONFIG_EISA
783extern uint32_t aic7xxx_probe_eisa_vl; 662extern uint32_t aic7xxx_probe_eisa_vl;
784int ahc_linux_eisa_init(void); 663int ahc_linux_eisa_init(void);
@@ -894,22 +773,18 @@ ahc_flush_device_writes(struct ahc_softc *ahc)
894} 773}
895 774
896/**************************** Proc FS Support *********************************/ 775/**************************** Proc FS Support *********************************/
897#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
898int ahc_linux_proc_info(char *, char **, off_t, int, int, int);
899#else
900int ahc_linux_proc_info(struct Scsi_Host *, char *, char **, 776int ahc_linux_proc_info(struct Scsi_Host *, char *, char **,
901 off_t, int, int); 777 off_t, int, int);
902#endif
903 778
904/*************************** Domain Validation ********************************/ 779/*************************** Domain Validation ********************************/
905/*********************** Transaction Access Wrappers *************************/ 780/*********************** Transaction Access Wrappers *************************/
906static __inline void ahc_cmd_set_transaction_status(Scsi_Cmnd *, uint32_t); 781static __inline void ahc_cmd_set_transaction_status(struct scsi_cmnd *, uint32_t);
907static __inline void ahc_set_transaction_status(struct scb *, uint32_t); 782static __inline void ahc_set_transaction_status(struct scb *, uint32_t);
908static __inline void ahc_cmd_set_scsi_status(Scsi_Cmnd *, uint32_t); 783static __inline void ahc_cmd_set_scsi_status(struct scsi_cmnd *, uint32_t);
909static __inline void ahc_set_scsi_status(struct scb *, uint32_t); 784static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
910static __inline uint32_t ahc_cmd_get_transaction_status(Scsi_Cmnd *cmd); 785static __inline uint32_t ahc_cmd_get_transaction_status(struct scsi_cmnd *cmd);
911static __inline uint32_t ahc_get_transaction_status(struct scb *); 786static __inline uint32_t ahc_get_transaction_status(struct scb *);
912static __inline uint32_t ahc_cmd_get_scsi_status(Scsi_Cmnd *cmd); 787static __inline uint32_t ahc_cmd_get_scsi_status(struct scsi_cmnd *cmd);
913static __inline uint32_t ahc_get_scsi_status(struct scb *); 788static __inline uint32_t ahc_get_scsi_status(struct scb *);
914static __inline void ahc_set_transaction_tag(struct scb *, int, u_int); 789static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
915static __inline u_long ahc_get_transfer_length(struct scb *); 790static __inline u_long ahc_get_transfer_length(struct scb *);
@@ -928,7 +803,7 @@ static __inline void ahc_platform_scb_free(struct ahc_softc *ahc,
928static __inline void ahc_freeze_scb(struct scb *scb); 803static __inline void ahc_freeze_scb(struct scb *scb);
929 804
930static __inline 805static __inline
931void ahc_cmd_set_transaction_status(Scsi_Cmnd *cmd, uint32_t status) 806void ahc_cmd_set_transaction_status(struct scsi_cmnd *cmd, uint32_t status)
932{ 807{
933 cmd->result &= ~(CAM_STATUS_MASK << 16); 808 cmd->result &= ~(CAM_STATUS_MASK << 16);
934 cmd->result |= status << 16; 809 cmd->result |= status << 16;
@@ -941,7 +816,7 @@ void ahc_set_transaction_status(struct scb *scb, uint32_t status)
941} 816}
942 817
943static __inline 818static __inline
944void ahc_cmd_set_scsi_status(Scsi_Cmnd *cmd, uint32_t status) 819void ahc_cmd_set_scsi_status(struct scsi_cmnd *cmd, uint32_t status)
945{ 820{
946 cmd->result &= ~0xFFFF; 821 cmd->result &= ~0xFFFF;
947 cmd->result |= status; 822 cmd->result |= status;
@@ -954,7 +829,7 @@ void ahc_set_scsi_status(struct scb *scb, uint32_t status)
954} 829}
955 830
956static __inline 831static __inline
957uint32_t ahc_cmd_get_transaction_status(Scsi_Cmnd *cmd) 832uint32_t ahc_cmd_get_transaction_status(struct scsi_cmnd *cmd)
958{ 833{
959 return ((cmd->result >> 16) & CAM_STATUS_MASK); 834 return ((cmd->result >> 16) & CAM_STATUS_MASK);
960} 835}
@@ -966,7 +841,7 @@ uint32_t ahc_get_transaction_status(struct scb *scb)
966} 841}
967 842
968static __inline 843static __inline
969uint32_t ahc_cmd_get_scsi_status(Scsi_Cmnd *cmd) 844uint32_t ahc_cmd_get_scsi_status(struct scsi_cmnd *cmd)
970{ 845{
971 return (cmd->result & 0xFFFF); 846 return (cmd->result & 0xFFFF);
972} 847}
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
index 6f6674aa31ef..2a0ebce83e7a 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
@@ -221,13 +221,11 @@ ahc_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
221 && ahc_linux_get_memsize() > 0x80000000 221 && ahc_linux_get_memsize() > 0x80000000
222 && pci_set_dma_mask(pdev, mask_39bit) == 0) { 222 && pci_set_dma_mask(pdev, mask_39bit) == 0) {
223 ahc->flags |= AHC_39BIT_ADDRESSING; 223 ahc->flags |= AHC_39BIT_ADDRESSING;
224 ahc->platform_data->hw_dma_mask = mask_39bit;
225 } else { 224 } else {
226 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) { 225 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
227 printk(KERN_WARNING "aic7xxx: No suitable DMA available.\n"); 226 printk(KERN_WARNING "aic7xxx: No suitable DMA available.\n");
228 return (-ENODEV); 227 return (-ENODEV);
229 } 228 }
230 ahc->platform_data->hw_dma_mask = DMA_32BIT_MASK;
231 } 229 }
232 ahc->dev_softc = pci; 230 ahc->dev_softc = pci;
233 error = ahc_pci_config(ahc, entry); 231 error = ahc_pci_config(ahc, entry);
@@ -236,15 +234,8 @@ ahc_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
236 return (-error); 234 return (-error);
237 } 235 }
238 pci_set_drvdata(pdev, ahc); 236 pci_set_drvdata(pdev, ahc);
239 if (aic7xxx_detect_complete) { 237 if (aic7xxx_detect_complete)
240#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
241 ahc_linux_register_host(ahc, &aic7xxx_driver_template); 238 ahc_linux_register_host(ahc, &aic7xxx_driver_template);
242#else
243 printf("aic7xxx: ignoring PCI device found after "
244 "initialization\n");
245 return (-ENODEV);
246#endif
247 }
248 return (0); 239 return (0);
249} 240}
250 241
diff --git a/drivers/scsi/aic7xxx/aic7xxx_proc.c b/drivers/scsi/aic7xxx/aic7xxx_proc.c
index 85e80eecc9d0..5fece859fbd9 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_proc.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_proc.c
@@ -289,13 +289,8 @@ done:
289 * Return information to handle /proc support for the driver. 289 * Return information to handle /proc support for the driver.
290 */ 290 */
291int 291int
292#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
293ahc_linux_proc_info(char *buffer, char **start, off_t offset,
294 int length, int hostno, int inout)
295#else
296ahc_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start, 292ahc_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
297 off_t offset, int length, int inout) 293 off_t offset, int length, int inout)
298#endif
299{ 294{
300 struct ahc_softc *ahc; 295 struct ahc_softc *ahc;
301 struct info_str info; 296 struct info_str info;
@@ -307,15 +302,7 @@ ahc_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
307 302
308 retval = -EINVAL; 303 retval = -EINVAL;
309 ahc_list_lock(&s); 304 ahc_list_lock(&s);
310#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
311 TAILQ_FOREACH(ahc, &ahc_tailq, links) {
312 if (ahc->platform_data->host->host_no == hostno)
313 break;
314 }
315#else
316 ahc = ahc_find_softc(*(struct ahc_softc **)shost->hostdata); 305 ahc = ahc_find_softc(*(struct ahc_softc **)shost->hostdata);
317#endif
318
319 if (ahc == NULL) 306 if (ahc == NULL)
320 goto done; 307 goto done;
321 308
diff --git a/drivers/scsi/aic7xxx/aiclib.c b/drivers/scsi/aic7xxx/aiclib.c
index 79bfd9efd8ed..7c5a6db0e672 100644
--- a/drivers/scsi/aic7xxx/aiclib.c
+++ b/drivers/scsi/aic7xxx/aiclib.c
@@ -35,7 +35,6 @@
35#include <linux/version.h> 35#include <linux/version.h>
36 36
37/* Core SCSI definitions */ 37/* Core SCSI definitions */
38#include "scsi.h"
39#include <scsi/scsi_host.h> 38#include <scsi/scsi_host.h>
40#include "aiclib.h" 39#include "aiclib.h"
41#include "cam.h" 40#include "cam.h"
diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c
index 3867f91ef8c7..3be546439252 100644
--- a/drivers/scsi/ata_piix.c
+++ b/drivers/scsi/ata_piix.c
@@ -153,6 +153,7 @@ static struct ata_port_operations piix_pata_ops = {
153 153
154 .port_start = ata_port_start, 154 .port_start = ata_port_start,
155 .port_stop = ata_port_stop, 155 .port_stop = ata_port_stop,
156 .host_stop = ata_host_stop,
156}; 157};
157 158
158static struct ata_port_operations piix_sata_ops = { 159static struct ata_port_operations piix_sata_ops = {
@@ -180,6 +181,7 @@ static struct ata_port_operations piix_sata_ops = {
180 181
181 .port_start = ata_port_start, 182 .port_start = ata_port_start,
182 .port_stop = ata_port_stop, 183 .port_stop = ata_port_stop,
184 .host_stop = ata_host_stop,
183}; 185};
184 186
185static struct ata_port_info piix_port_info[] = { 187static struct ata_port_info piix_port_info[] = {
@@ -663,15 +665,6 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
663 return ata_pci_init_one(pdev, port_info, n_ports); 665 return ata_pci_init_one(pdev, port_info, n_ports);
664} 666}
665 667
666/**
667 * piix_init -
668 *
669 * LOCKING:
670 *
671 * RETURNS:
672 *
673 */
674
675static int __init piix_init(void) 668static int __init piix_init(void)
676{ 669{
677 int rc; 670 int rc;
@@ -687,13 +680,6 @@ static int __init piix_init(void)
687 return 0; 680 return 0;
688} 681}
689 682
690/**
691 * piix_exit -
692 *
693 * LOCKING:
694 *
695 */
696
697static void __exit piix_exit(void) 683static void __exit piix_exit(void)
698{ 684{
699 pci_unregister_driver(&piix_pci_driver); 685 pci_unregister_driver(&piix_pci_driver);
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 2e2486b035dd..83f062ed9082 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -179,8 +179,18 @@ static void idescsi_input_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigne
179 return; 179 return;
180 } 180 }
181 count = min(pc->sg->length - pc->b_count, bcount); 181 count = min(pc->sg->length - pc->b_count, bcount);
182 buf = page_address(pc->sg->page) + pc->sg->offset; 182 if (PageHighMem(pc->sg->page)) {
183 drive->hwif->atapi_input_bytes(drive, buf + pc->b_count, count); 183 unsigned long flags;
184
185 local_irq_save(flags);
186 buf = kmap_atomic(pc->sg->page, KM_IRQ0) + pc->sg->offset;
187 drive->hwif->atapi_input_bytes(drive, buf + pc->b_count, count);
188 kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
189 local_irq_restore(flags);
190 } else {
191 buf = page_address(pc->sg->page) + pc->sg->offset;
192 drive->hwif->atapi_input_bytes(drive, buf + pc->b_count, count);
193 }
184 bcount -= count; pc->b_count += count; 194 bcount -= count; pc->b_count += count;
185 if (pc->b_count == pc->sg->length) { 195 if (pc->b_count == pc->sg->length) {
186 pc->sg++; 196 pc->sg++;
@@ -201,8 +211,18 @@ static void idescsi_output_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsign
201 return; 211 return;
202 } 212 }
203 count = min(pc->sg->length - pc->b_count, bcount); 213 count = min(pc->sg->length - pc->b_count, bcount);
204 buf = page_address(pc->sg->page) + pc->sg->offset; 214 if (PageHighMem(pc->sg->page)) {
205 drive->hwif->atapi_output_bytes(drive, buf + pc->b_count, count); 215 unsigned long flags;
216
217 local_irq_save(flags);
218 buf = kmap_atomic(pc->sg->page, KM_IRQ0) + pc->sg->offset;
219 drive->hwif->atapi_output_bytes(drive, buf + pc->b_count, count);
220 kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
221 local_irq_restore(flags);
222 } else {
223 buf = page_address(pc->sg->page) + pc->sg->offset;
224 drive->hwif->atapi_output_bytes(drive, buf + pc->b_count, count);
225 }
206 bcount -= count; pc->b_count += count; 226 bcount -= count; pc->b_count += count;
207 if (pc->b_count == pc->sg->length) { 227 if (pc->b_count == pc->sg->length) {
208 pc->sg++; 228 pc->sg++;
@@ -713,7 +733,6 @@ static void idescsi_add_settings(ide_drive_t *drive)
713 */ 733 */
714static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi) 734static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi)
715{ 735{
716 DRIVER(drive)->busy++;
717 if (drive->id && (drive->id->config & 0x0060) == 0x20) 736 if (drive->id && (drive->id->config & 0x0060) == 0x20)
718 set_bit (IDESCSI_DRQ_INTERRUPT, &scsi->flags); 737 set_bit (IDESCSI_DRQ_INTERRUPT, &scsi->flags);
719 set_bit(IDESCSI_TRANSFORM, &scsi->transform); 738 set_bit(IDESCSI_TRANSFORM, &scsi->transform);
@@ -722,17 +741,16 @@ static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi)
722 set_bit(IDESCSI_LOG_CMD, &scsi->log); 741 set_bit(IDESCSI_LOG_CMD, &scsi->log);
723#endif /* IDESCSI_DEBUG_LOG */ 742#endif /* IDESCSI_DEBUG_LOG */
724 idescsi_add_settings(drive); 743 idescsi_add_settings(drive);
725 DRIVER(drive)->busy--;
726} 744}
727 745
728static int idescsi_cleanup (ide_drive_t *drive) 746static int ide_scsi_remove(struct device *dev)
729{ 747{
748 ide_drive_t *drive = to_ide_device(dev);
730 struct Scsi_Host *scsihost = drive->driver_data; 749 struct Scsi_Host *scsihost = drive->driver_data;
731 struct ide_scsi_obj *scsi = scsihost_to_idescsi(scsihost); 750 struct ide_scsi_obj *scsi = scsihost_to_idescsi(scsihost);
732 struct gendisk *g = scsi->disk; 751 struct gendisk *g = scsi->disk;
733 752
734 if (ide_unregister_subdriver(drive)) 753 ide_unregister_subdriver(drive, scsi->driver);
735 return 1;
736 754
737 ide_unregister_region(g); 755 ide_unregister_region(g);
738 756
@@ -746,7 +764,7 @@ static int idescsi_cleanup (ide_drive_t *drive)
746 return 0; 764 return 0;
747} 765}
748 766
749static int idescsi_attach(ide_drive_t *drive); 767static int ide_scsi_probe(struct device *);
750 768
751#ifdef CONFIG_PROC_FS 769#ifdef CONFIG_PROC_FS
752static ide_proc_entry_t idescsi_proc[] = { 770static ide_proc_entry_t idescsi_proc[] = {
@@ -757,24 +775,22 @@ static ide_proc_entry_t idescsi_proc[] = {
757# define idescsi_proc NULL 775# define idescsi_proc NULL
758#endif 776#endif
759 777
760/*
761 * IDE subdriver functions, registered with ide.c
762 */
763static ide_driver_t idescsi_driver = { 778static ide_driver_t idescsi_driver = {
764 .owner = THIS_MODULE, 779 .owner = THIS_MODULE,
765 .name = "ide-scsi", 780 .gen_driver = {
781 .name = "ide-scsi",
782 .bus = &ide_bus_type,
783 .probe = ide_scsi_probe,
784 .remove = ide_scsi_remove,
785 },
766 .version = IDESCSI_VERSION, 786 .version = IDESCSI_VERSION,
767 .media = ide_scsi, 787 .media = ide_scsi,
768 .busy = 0,
769 .supports_dsc_overlap = 0, 788 .supports_dsc_overlap = 0,
770 .proc = idescsi_proc, 789 .proc = idescsi_proc,
771 .attach = idescsi_attach,
772 .cleanup = idescsi_cleanup,
773 .do_request = idescsi_do_request, 790 .do_request = idescsi_do_request,
774 .end_request = idescsi_end_request, 791 .end_request = idescsi_end_request,
775 .error = idescsi_atapi_error, 792 .error = idescsi_atapi_error,
776 .abort = idescsi_atapi_abort, 793 .abort = idescsi_atapi_abort,
777 .drives = LIST_HEAD_INIT(idescsi_driver.drives),
778}; 794};
779 795
780static int idescsi_ide_open(struct inode *inode, struct file *filp) 796static int idescsi_ide_open(struct inode *inode, struct file *filp)
@@ -821,8 +837,6 @@ static struct block_device_operations idescsi_ops = {
821 .ioctl = idescsi_ide_ioctl, 837 .ioctl = idescsi_ide_ioctl,
822}; 838};
823 839
824static int idescsi_attach(ide_drive_t *drive);
825
826static int idescsi_slave_configure(struct scsi_device * sdp) 840static int idescsi_slave_configure(struct scsi_device * sdp)
827{ 841{
828 /* Configure detected device */ 842 /* Configure detected device */
@@ -1095,8 +1109,9 @@ static struct scsi_host_template idescsi_template = {
1095 .proc_name = "ide-scsi", 1109 .proc_name = "ide-scsi",
1096}; 1110};
1097 1111
1098static int idescsi_attach(ide_drive_t *drive) 1112static int ide_scsi_probe(struct device *dev)
1099{ 1113{
1114 ide_drive_t *drive = to_ide_device(dev);
1100 idescsi_scsi_t *idescsi; 1115 idescsi_scsi_t *idescsi;
1101 struct Scsi_Host *host; 1116 struct Scsi_Host *host;
1102 struct gendisk *g; 1117 struct gendisk *g;
@@ -1112,7 +1127,7 @@ static int idescsi_attach(ide_drive_t *drive)
1112 !drive->present || 1127 !drive->present ||
1113 drive->media == ide_disk || 1128 drive->media == ide_disk ||
1114 !(host = scsi_host_alloc(&idescsi_template,sizeof(idescsi_scsi_t)))) 1129 !(host = scsi_host_alloc(&idescsi_template,sizeof(idescsi_scsi_t))))
1115 return 1; 1130 return -ENODEV;
1116 1131
1117 g = alloc_disk(1 << PARTN_BITS); 1132 g = alloc_disk(1 << PARTN_BITS);
1118 if (!g) 1133 if (!g)
@@ -1138,20 +1153,19 @@ static int idescsi_attach(ide_drive_t *drive)
1138 idescsi->host = host; 1153 idescsi->host = host;
1139 idescsi->disk = g; 1154 idescsi->disk = g;
1140 g->private_data = &idescsi->driver; 1155 g->private_data = &idescsi->driver;
1141 err = ide_register_subdriver(drive, &idescsi_driver); 1156 ide_register_subdriver(drive, &idescsi_driver);
1157 err = 0;
1158 idescsi_setup(drive, idescsi);
1159 g->fops = &idescsi_ops;
1160 ide_register_region(g);
1161 err = scsi_add_host(host, &drive->gendev);
1142 if (!err) { 1162 if (!err) {
1143 idescsi_setup (drive, idescsi); 1163 scsi_scan_host(host);
1144 g->fops = &idescsi_ops; 1164 return 0;
1145 ide_register_region(g);
1146 err = scsi_add_host(host, &drive->gendev);
1147 if (!err) {
1148 scsi_scan_host(host);
1149 return 0;
1150 }
1151 /* fall through on error */
1152 ide_unregister_region(g);
1153 ide_unregister_subdriver(drive);
1154 } 1165 }
1166 /* fall through on error */
1167 ide_unregister_region(g);
1168 ide_unregister_subdriver(drive, &idescsi_driver);
1155 1169
1156 put_disk(g); 1170 put_disk(g);
1157out_host_put: 1171out_host_put:
@@ -1161,12 +1175,12 @@ out_host_put:
1161 1175
1162static int __init init_idescsi_module(void) 1176static int __init init_idescsi_module(void)
1163{ 1177{
1164 return ide_register_driver(&idescsi_driver); 1178 return driver_register(&idescsi_driver.gen_driver);
1165} 1179}
1166 1180
1167static void __exit exit_idescsi_module(void) 1181static void __exit exit_idescsi_module(void)
1168{ 1182{
1169 ide_unregister_driver(&idescsi_driver); 1183 driver_unregister(&idescsi_driver.gen_driver);
1170} 1184}
1171 1185
1172module_init(init_idescsi_module); 1186module_init(init_idescsi_module);
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 0b5d3a5b7eda..9e58f134f68b 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -186,6 +186,28 @@ static void ata_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf)
186 ata_wait_idle(ap); 186 ata_wait_idle(ap);
187} 187}
188 188
189
190/**
191 * ata_tf_load - send taskfile registers to host controller
192 * @ap: Port to which output is sent
193 * @tf: ATA taskfile register set
194 *
195 * Outputs ATA taskfile to standard ATA host controller using MMIO
196 * or PIO as indicated by the ATA_FLAG_MMIO flag.
197 * Writes the control, feature, nsect, lbal, lbam, and lbah registers.
198 * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,
199 * hob_lbal, hob_lbam, and hob_lbah.
200 *
201 * This function waits for idle (!BUSY and !DRQ) after writing
202 * registers. If the control register has a new value, this
203 * function also waits for idle after writing control and before
204 * writing the remaining registers.
205 *
206 * May be used as the tf_load() entry in ata_port_operations.
207 *
208 * LOCKING:
209 * Inherited from caller.
210 */
189void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf) 211void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf)
190{ 212{
191 if (ap->flags & ATA_FLAG_MMIO) 213 if (ap->flags & ATA_FLAG_MMIO)
@@ -195,11 +217,11 @@ void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf)
195} 217}
196 218
197/** 219/**
198 * ata_exec_command - issue ATA command to host controller 220 * ata_exec_command_pio - issue ATA command to host controller
199 * @ap: port to which command is being issued 221 * @ap: port to which command is being issued
200 * @tf: ATA taskfile register set 222 * @tf: ATA taskfile register set
201 * 223 *
202 * Issues PIO/MMIO write to ATA command register, with proper 224 * Issues PIO write to ATA command register, with proper
203 * synchronization with interrupt handler / other threads. 225 * synchronization with interrupt handler / other threads.
204 * 226 *
205 * LOCKING: 227 * LOCKING:
@@ -235,6 +257,18 @@ static void ata_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf)
235 ata_pause(ap); 257 ata_pause(ap);
236} 258}
237 259
260
261/**
262 * ata_exec_command - issue ATA command to host controller
263 * @ap: port to which command is being issued
264 * @tf: ATA taskfile register set
265 *
266 * Issues PIO/MMIO write to ATA command register, with proper
267 * synchronization with interrupt handler / other threads.
268 *
269 * LOCKING:
270 * spin_lock_irqsave(host_set lock)
271 */
238void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf) 272void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf)
239{ 273{
240 if (ap->flags & ATA_FLAG_MMIO) 274 if (ap->flags & ATA_FLAG_MMIO)
@@ -305,7 +339,7 @@ void ata_tf_to_host_nolock(struct ata_port *ap, struct ata_taskfile *tf)
305} 339}
306 340
307/** 341/**
308 * ata_tf_read - input device's ATA taskfile shadow registers 342 * ata_tf_read_pio - input device's ATA taskfile shadow registers
309 * @ap: Port from which input is read 343 * @ap: Port from which input is read
310 * @tf: ATA taskfile register set for storing input 344 * @tf: ATA taskfile register set for storing input
311 * 345 *
@@ -368,6 +402,23 @@ static void ata_tf_read_mmio(struct ata_port *ap, struct ata_taskfile *tf)
368 } 402 }
369} 403}
370 404
405
406/**
407 * ata_tf_read - input device's ATA taskfile shadow registers
408 * @ap: Port from which input is read
409 * @tf: ATA taskfile register set for storing input
410 *
411 * Reads ATA taskfile registers for currently-selected device
412 * into @tf.
413 *
414 * Reads nsect, lbal, lbam, lbah, and device. If ATA_TFLAG_LBA48
415 * is set, also reads the hob registers.
416 *
417 * May be used as the tf_read() entry in ata_port_operations.
418 *
419 * LOCKING:
420 * Inherited from caller.
421 */
371void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf) 422void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
372{ 423{
373 if (ap->flags & ATA_FLAG_MMIO) 424 if (ap->flags & ATA_FLAG_MMIO)
@@ -381,7 +432,7 @@ void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
381 * @ap: port where the device is 432 * @ap: port where the device is
382 * 433 *
383 * Reads ATA taskfile status register for currently-selected device 434 * Reads ATA taskfile status register for currently-selected device
384 * and return it's value. This also clears pending interrupts 435 * and return its value. This also clears pending interrupts
385 * from this device 436 * from this device
386 * 437 *
387 * LOCKING: 438 * LOCKING:
@@ -397,7 +448,7 @@ static u8 ata_check_status_pio(struct ata_port *ap)
397 * @ap: port where the device is 448 * @ap: port where the device is
398 * 449 *
399 * Reads ATA taskfile status register for currently-selected device 450 * Reads ATA taskfile status register for currently-selected device
400 * via MMIO and return it's value. This also clears pending interrupts 451 * via MMIO and return its value. This also clears pending interrupts
401 * from this device 452 * from this device
402 * 453 *
403 * LOCKING: 454 * LOCKING:
@@ -408,6 +459,20 @@ static u8 ata_check_status_mmio(struct ata_port *ap)
408 return readb((void __iomem *) ap->ioaddr.status_addr); 459 return readb((void __iomem *) ap->ioaddr.status_addr);
409} 460}
410 461
462
463/**
464 * ata_check_status - Read device status reg & clear interrupt
465 * @ap: port where the device is
466 *
467 * Reads ATA taskfile status register for currently-selected device
468 * and return its value. This also clears pending interrupts
469 * from this device
470 *
471 * May be used as the check_status() entry in ata_port_operations.
472 *
473 * LOCKING:
474 * Inherited from caller.
475 */
411u8 ata_check_status(struct ata_port *ap) 476u8 ata_check_status(struct ata_port *ap)
412{ 477{
413 if (ap->flags & ATA_FLAG_MMIO) 478 if (ap->flags & ATA_FLAG_MMIO)
@@ -415,6 +480,20 @@ u8 ata_check_status(struct ata_port *ap)
415 return ata_check_status_pio(ap); 480 return ata_check_status_pio(ap);
416} 481}
417 482
483
484/**
485 * ata_altstatus - Read device alternate status reg
486 * @ap: port where the device is
487 *
488 * Reads ATA taskfile alternate status register for
489 * currently-selected device and return its value.
490 *
491 * Note: may NOT be used as the check_altstatus() entry in
492 * ata_port_operations.
493 *
494 * LOCKING:
495 * Inherited from caller.
496 */
418u8 ata_altstatus(struct ata_port *ap) 497u8 ata_altstatus(struct ata_port *ap)
419{ 498{
420 if (ap->ops->check_altstatus) 499 if (ap->ops->check_altstatus)
@@ -425,6 +504,20 @@ u8 ata_altstatus(struct ata_port *ap)
425 return inb(ap->ioaddr.altstatus_addr); 504 return inb(ap->ioaddr.altstatus_addr);
426} 505}
427 506
507
508/**
509 * ata_chk_err - Read device error reg
510 * @ap: port where the device is
511 *
512 * Reads ATA taskfile error register for
513 * currently-selected device and return its value.
514 *
515 * Note: may NOT be used as the check_err() entry in
516 * ata_port_operations.
517 *
518 * LOCKING:
519 * Inherited from caller.
520 */
428u8 ata_chk_err(struct ata_port *ap) 521u8 ata_chk_err(struct ata_port *ap)
429{ 522{
430 if (ap->ops->check_err) 523 if (ap->ops->check_err)
@@ -873,10 +966,24 @@ void ata_dev_id_string(u16 *id, unsigned char *s,
873 } 966 }
874} 967}
875 968
969
970/**
971 * ata_noop_dev_select - Select device 0/1 on ATA bus
972 * @ap: ATA channel to manipulate
973 * @device: ATA device (numbered from zero) to select
974 *
975 * This function performs no actual function.
976 *
977 * May be used as the dev_select() entry in ata_port_operations.
978 *
979 * LOCKING:
980 * caller.
981 */
876void ata_noop_dev_select (struct ata_port *ap, unsigned int device) 982void ata_noop_dev_select (struct ata_port *ap, unsigned int device)
877{ 983{
878} 984}
879 985
986
880/** 987/**
881 * ata_std_dev_select - Select device 0/1 on ATA bus 988 * ata_std_dev_select - Select device 0/1 on ATA bus
882 * @ap: ATA channel to manipulate 989 * @ap: ATA channel to manipulate
@@ -884,7 +991,9 @@ void ata_noop_dev_select (struct ata_port *ap, unsigned int device)
884 * 991 *
885 * Use the method defined in the ATA specification to 992 * Use the method defined in the ATA specification to
886 * make either device 0, or device 1, active on the 993 * make either device 0, or device 1, active on the
887 * ATA channel. 994 * ATA channel. Works with both PIO and MMIO.
995 *
996 * May be used as the dev_select() entry in ata_port_operations.
888 * 997 *
889 * LOCKING: 998 * LOCKING:
890 * caller. 999 * caller.
@@ -1190,7 +1299,12 @@ err_out:
1190 * ata_bus_probe - Reset and probe ATA bus 1299 * ata_bus_probe - Reset and probe ATA bus
1191 * @ap: Bus to probe 1300 * @ap: Bus to probe
1192 * 1301 *
1302 * Master ATA bus probing function. Initiates a hardware-dependent
1303 * bus reset, then attempts to identify any devices found on
1304 * the bus.
1305 *
1193 * LOCKING: 1306 * LOCKING:
1307 * PCI/etc. bus probe sem.
1194 * 1308 *
1195 * RETURNS: 1309 * RETURNS:
1196 * Zero on success, non-zero on error. 1310 * Zero on success, non-zero on error.
@@ -1229,10 +1343,14 @@ err_out:
1229} 1343}
1230 1344
1231/** 1345/**
1232 * ata_port_probe - 1346 * ata_port_probe - Mark port as enabled
1233 * @ap: 1347 * @ap: Port for which we indicate enablement
1234 * 1348 *
1235 * LOCKING: 1349 * Modify @ap data structure such that the system
1350 * thinks that the entire port is enabled.
1351 *
1352 * LOCKING: host_set lock, or some other form of
1353 * serialization.
1236 */ 1354 */
1237 1355
1238void ata_port_probe(struct ata_port *ap) 1356void ata_port_probe(struct ata_port *ap)
@@ -1241,10 +1359,15 @@ void ata_port_probe(struct ata_port *ap)
1241} 1359}
1242 1360
1243/** 1361/**
1244 * __sata_phy_reset - 1362 * __sata_phy_reset - Wake/reset a low-level SATA PHY
1245 * @ap: 1363 * @ap: SATA port associated with target SATA PHY.
1364 *
1365 * This function issues commands to standard SATA Sxxx
1366 * PHY registers, to wake up the phy (and device), and
1367 * clear any reset condition.
1246 * 1368 *
1247 * LOCKING: 1369 * LOCKING:
1370 * PCI/etc. bus probe sem.
1248 * 1371 *
1249 */ 1372 */
1250void __sata_phy_reset(struct ata_port *ap) 1373void __sata_phy_reset(struct ata_port *ap)
@@ -1253,11 +1376,11 @@ void __sata_phy_reset(struct ata_port *ap)
1253 unsigned long timeout = jiffies + (HZ * 5); 1376 unsigned long timeout = jiffies + (HZ * 5);
1254 1377
1255 if (ap->flags & ATA_FLAG_SATA_RESET) { 1378 if (ap->flags & ATA_FLAG_SATA_RESET) {
1256 scr_write(ap, SCR_CONTROL, 0x301); /* issue phy wake/reset */ 1379 /* issue phy wake/reset */
1257 scr_read(ap, SCR_STATUS); /* dummy read; flush */ 1380 scr_write_flush(ap, SCR_CONTROL, 0x301);
1258 udelay(400); /* FIXME: a guess */ 1381 udelay(400); /* FIXME: a guess */
1259 } 1382 }
1260 scr_write(ap, SCR_CONTROL, 0x300); /* issue phy wake/clear reset */ 1383 scr_write_flush(ap, SCR_CONTROL, 0x300); /* phy wake/clear reset */
1261 1384
1262 /* wait for phy to become ready, if necessary */ 1385 /* wait for phy to become ready, if necessary */
1263 do { 1386 do {
@@ -1289,10 +1412,14 @@ void __sata_phy_reset(struct ata_port *ap)
1289} 1412}
1290 1413
1291/** 1414/**
1292 * __sata_phy_reset - 1415 * sata_phy_reset - Reset SATA bus.
1293 * @ap: 1416 * @ap: SATA port associated with target SATA PHY.
1417 *
1418 * This function resets the SATA bus, and then probes
1419 * the bus for devices.
1294 * 1420 *
1295 * LOCKING: 1421 * LOCKING:
1422 * PCI/etc. bus probe sem.
1296 * 1423 *
1297 */ 1424 */
1298void sata_phy_reset(struct ata_port *ap) 1425void sata_phy_reset(struct ata_port *ap)
@@ -1304,10 +1431,16 @@ void sata_phy_reset(struct ata_port *ap)
1304} 1431}
1305 1432
1306/** 1433/**
1307 * ata_port_disable - 1434 * ata_port_disable - Disable port.
1308 * @ap: 1435 * @ap: Port to be disabled.
1309 * 1436 *
1310 * LOCKING: 1437 * Modify @ap data structure such that the system
1438 * thinks that the entire port is disabled, and should
1439 * never attempt to probe or communicate with devices
1440 * on this port.
1441 *
1442 * LOCKING: host_set lock, or some other form of
1443 * serialization.
1311 */ 1444 */
1312 1445
1313void ata_port_disable(struct ata_port *ap) 1446void ata_port_disable(struct ata_port *ap)
@@ -1416,7 +1549,10 @@ static void ata_host_set_dma(struct ata_port *ap, u8 xfer_mode,
1416 * ata_set_mode - Program timings and issue SET FEATURES - XFER 1549 * ata_set_mode - Program timings and issue SET FEATURES - XFER
1417 * @ap: port on which timings will be programmed 1550 * @ap: port on which timings will be programmed
1418 * 1551 *
1552 * Set ATA device disk transfer mode (PIO3, UDMA6, etc.).
1553 *
1419 * LOCKING: 1554 * LOCKING:
1555 * PCI/etc. bus probe sem.
1420 * 1556 *
1421 */ 1557 */
1422static void ata_set_mode(struct ata_port *ap) 1558static void ata_set_mode(struct ata_port *ap)
@@ -1467,7 +1603,10 @@ err_out:
1467 * @tmout_pat: impatience timeout 1603 * @tmout_pat: impatience timeout
1468 * @tmout: overall timeout 1604 * @tmout: overall timeout
1469 * 1605 *
1470 * LOCKING: 1606 * Sleep until ATA Status register bit BSY clears,
1607 * or a timeout occurs.
1608 *
1609 * LOCKING: None.
1471 * 1610 *
1472 */ 1611 */
1473 1612
@@ -1553,10 +1692,14 @@ static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask)
1553} 1692}
1554 1693
1555/** 1694/**
1556 * ata_bus_edd - 1695 * ata_bus_edd - Issue EXECUTE DEVICE DIAGNOSTIC command.
1557 * @ap: 1696 * @ap: Port to reset and probe
1697 *
1698 * Use the EXECUTE DEVICE DIAGNOSTIC command to reset and
1699 * probe the bus. Not often used these days.
1558 * 1700 *
1559 * LOCKING: 1701 * LOCKING:
1702 * PCI/etc. bus probe sem.
1560 * 1703 *
1561 */ 1704 */
1562 1705
@@ -1633,8 +1776,8 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
1633 * the device is ATA or ATAPI. 1776 * the device is ATA or ATAPI.
1634 * 1777 *
1635 * LOCKING: 1778 * LOCKING:
1636 * Inherited from caller. Some functions called by this function 1779 * PCI/etc. bus probe sem.
1637 * obtain the host_set lock. 1780 * Obtains host_set lock.
1638 * 1781 *
1639 * SIDE EFFECTS: 1782 * SIDE EFFECTS:
1640 * Sets ATA_FLAG_PORT_DISABLED if bus reset fails. 1783 * Sets ATA_FLAG_PORT_DISABLED if bus reset fails.
@@ -1876,7 +2019,11 @@ static int fgb(u32 bitmap)
1876 * @xfer_mode_out: (output) SET FEATURES - XFER MODE code 2019 * @xfer_mode_out: (output) SET FEATURES - XFER MODE code
1877 * @xfer_shift_out: (output) bit shift that selects this mode 2020 * @xfer_shift_out: (output) bit shift that selects this mode
1878 * 2021 *
2022 * Based on host and device capabilities, determine the
2023 * maximum transfer mode that is amenable to all.
2024 *
1879 * LOCKING: 2025 * LOCKING:
2026 * PCI/etc. bus probe sem.
1880 * 2027 *
1881 * RETURNS: 2028 * RETURNS:
1882 * Zero on success, negative on error. 2029 * Zero on success, negative on error.
@@ -1909,7 +2056,11 @@ static int ata_choose_xfer_mode(struct ata_port *ap,
1909 * @ap: Port associated with device @dev 2056 * @ap: Port associated with device @dev
1910 * @dev: Device to which command will be sent 2057 * @dev: Device to which command will be sent
1911 * 2058 *
2059 * Issue SET FEATURES - XFER MODE command to device @dev
2060 * on port @ap.
2061 *
1912 * LOCKING: 2062 * LOCKING:
2063 * PCI/etc. bus probe sem.
1913 */ 2064 */
1914 2065
1915static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev) 2066static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev)
@@ -1947,10 +2098,13 @@ static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev)
1947} 2098}
1948 2099
1949/** 2100/**
1950 * ata_sg_clean - 2101 * ata_sg_clean - Unmap DMA memory associated with command
1951 * @qc: 2102 * @qc: Command containing DMA memory to be released
2103 *
2104 * Unmap all mapped DMA memory associated with this command.
1952 * 2105 *
1953 * LOCKING: 2106 * LOCKING:
2107 * spin_lock_irqsave(host_set lock)
1954 */ 2108 */
1955 2109
1956static void ata_sg_clean(struct ata_queued_cmd *qc) 2110static void ata_sg_clean(struct ata_queued_cmd *qc)
@@ -1981,7 +2135,11 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
1981 * ata_fill_sg - Fill PCI IDE PRD table 2135 * ata_fill_sg - Fill PCI IDE PRD table
1982 * @qc: Metadata associated with taskfile to be transferred 2136 * @qc: Metadata associated with taskfile to be transferred
1983 * 2137 *
2138 * Fill PCI IDE PRD (scatter-gather) table with segments
2139 * associated with the current disk command.
2140 *
1984 * LOCKING: 2141 * LOCKING:
2142 * spin_lock_irqsave(host_set lock)
1985 * 2143 *
1986 */ 2144 */
1987static void ata_fill_sg(struct ata_queued_cmd *qc) 2145static void ata_fill_sg(struct ata_queued_cmd *qc)
@@ -2028,7 +2186,13 @@ static void ata_fill_sg(struct ata_queued_cmd *qc)
2028 * ata_check_atapi_dma - Check whether ATAPI DMA can be supported 2186 * ata_check_atapi_dma - Check whether ATAPI DMA can be supported
2029 * @qc: Metadata associated with taskfile to check 2187 * @qc: Metadata associated with taskfile to check
2030 * 2188 *
2189 * Allow low-level driver to filter ATA PACKET commands, returning
2190 * a status indicating whether or not it is OK to use DMA for the
2191 * supplied PACKET command.
2192 *
2031 * LOCKING: 2193 * LOCKING:
2194 * spin_lock_irqsave(host_set lock)
2195 *
2032 * RETURNS: 0 when ATAPI DMA can be used 2196 * RETURNS: 0 when ATAPI DMA can be used
2033 * nonzero otherwise 2197 * nonzero otherwise
2034 */ 2198 */
@@ -2046,6 +2210,8 @@ int ata_check_atapi_dma(struct ata_queued_cmd *qc)
2046 * ata_qc_prep - Prepare taskfile for submission 2210 * ata_qc_prep - Prepare taskfile for submission
2047 * @qc: Metadata associated with taskfile to be prepared 2211 * @qc: Metadata associated with taskfile to be prepared
2048 * 2212 *
2213 * Prepare ATA taskfile for submission.
2214 *
2049 * LOCKING: 2215 * LOCKING:
2050 * spin_lock_irqsave(host_set lock) 2216 * spin_lock_irqsave(host_set lock)
2051 */ 2217 */
@@ -2057,6 +2223,32 @@ void ata_qc_prep(struct ata_queued_cmd *qc)
2057 ata_fill_sg(qc); 2223 ata_fill_sg(qc);
2058} 2224}
2059 2225
2226/**
2227 * ata_sg_init_one - Associate command with memory buffer
2228 * @qc: Command to be associated
2229 * @buf: Memory buffer
2230 * @buflen: Length of memory buffer, in bytes.
2231 *
2232 * Initialize the data-related elements of queued_cmd @qc
2233 * to point to a single memory buffer, @buf of byte length @buflen.
2234 *
2235 * LOCKING:
2236 * spin_lock_irqsave(host_set lock)
2237 */
2238
2239
2240
2241/**
2242 * ata_sg_init_one - Prepare a one-entry scatter-gather list.
2243 * @qc: Queued command
2244 * @buf: transfer buffer
2245 * @buflen: length of buf
2246 *
2247 * Builds a single-entry scatter-gather list to initiate a
2248 * transfer utilizing the specified buffer.
2249 *
2250 * LOCKING:
2251 */
2060void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) 2252void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen)
2061{ 2253{
2062 struct scatterlist *sg; 2254 struct scatterlist *sg;
@@ -2071,9 +2263,35 @@ void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen)
2071 sg = qc->sg; 2263 sg = qc->sg;
2072 sg->page = virt_to_page(buf); 2264 sg->page = virt_to_page(buf);
2073 sg->offset = (unsigned long) buf & ~PAGE_MASK; 2265 sg->offset = (unsigned long) buf & ~PAGE_MASK;
2074 sg_dma_len(sg) = buflen; 2266 sg->length = buflen;
2075} 2267}
2076 2268
2269/**
2270 * ata_sg_init - Associate command with scatter-gather table.
2271 * @qc: Command to be associated
2272 * @sg: Scatter-gather table.
2273 * @n_elem: Number of elements in s/g table.
2274 *
2275 * Initialize the data-related elements of queued_cmd @qc
2276 * to point to a scatter-gather table @sg, containing @n_elem
2277 * elements.
2278 *
2279 * LOCKING:
2280 * spin_lock_irqsave(host_set lock)
2281 */
2282
2283
2284/**
2285 * ata_sg_init - Assign a scatter gather list to a queued command
2286 * @qc: Queued command
2287 * @sg: Scatter-gather list
2288 * @n_elem: length of sg list
2289 *
2290 * Attaches a scatter-gather list to a queued command.
2291 *
2292 * LOCKING:
2293 */
2294
2077void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, 2295void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
2078 unsigned int n_elem) 2296 unsigned int n_elem)
2079{ 2297{
@@ -2083,14 +2301,16 @@ void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
2083} 2301}
2084 2302
2085/** 2303/**
2086 * ata_sg_setup_one - 2304 * ata_sg_setup_one - DMA-map the memory buffer associated with a command.
2087 * @qc: 2305 * @qc: Command with memory buffer to be mapped.
2306 *
2307 * DMA-map the memory buffer associated with queued_cmd @qc.
2088 * 2308 *
2089 * LOCKING: 2309 * LOCKING:
2090 * spin_lock_irqsave(host_set lock) 2310 * spin_lock_irqsave(host_set lock)
2091 * 2311 *
2092 * RETURNS: 2312 * RETURNS:
2093 * 2313 * Zero on success, negative on error.
2094 */ 2314 */
2095 2315
2096static int ata_sg_setup_one(struct ata_queued_cmd *qc) 2316static int ata_sg_setup_one(struct ata_queued_cmd *qc)
@@ -2101,11 +2321,12 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
2101 dma_addr_t dma_address; 2321 dma_addr_t dma_address;
2102 2322
2103 dma_address = dma_map_single(ap->host_set->dev, qc->buf_virt, 2323 dma_address = dma_map_single(ap->host_set->dev, qc->buf_virt,
2104 sg_dma_len(sg), dir); 2324 sg->length, dir);
2105 if (dma_mapping_error(dma_address)) 2325 if (dma_mapping_error(dma_address))
2106 return -1; 2326 return -1;
2107 2327
2108 sg_dma_address(sg) = dma_address; 2328 sg_dma_address(sg) = dma_address;
2329 sg_dma_len(sg) = sg->length;
2109 2330
2110 DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg), 2331 DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg),
2111 qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); 2332 qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
@@ -2114,13 +2335,16 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
2114} 2335}
2115 2336
2116/** 2337/**
2117 * ata_sg_setup - 2338 * ata_sg_setup - DMA-map the scatter-gather table associated with a command.
2118 * @qc: 2339 * @qc: Command with scatter-gather table to be mapped.
2340 *
2341 * DMA-map the scatter-gather table associated with queued_cmd @qc.
2119 * 2342 *
2120 * LOCKING: 2343 * LOCKING:
2121 * spin_lock_irqsave(host_set lock) 2344 * spin_lock_irqsave(host_set lock)
2122 * 2345 *
2123 * RETURNS: 2346 * RETURNS:
2347 * Zero on success, negative on error.
2124 * 2348 *
2125 */ 2349 */
2126 2350
@@ -2150,6 +2374,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
2150 * @ap: 2374 * @ap:
2151 * 2375 *
2152 * LOCKING: 2376 * LOCKING:
2377 * None. (executing in kernel thread context)
2153 * 2378 *
2154 * RETURNS: 2379 * RETURNS:
2155 * 2380 *
@@ -2197,6 +2422,7 @@ static unsigned long ata_pio_poll(struct ata_port *ap)
2197 * @ap: 2422 * @ap:
2198 * 2423 *
2199 * LOCKING: 2424 * LOCKING:
2425 * None. (executing in kernel thread context)
2200 */ 2426 */
2201 2427
2202static void ata_pio_complete (struct ata_port *ap) 2428static void ata_pio_complete (struct ata_port *ap)
@@ -2239,6 +2465,18 @@ static void ata_pio_complete (struct ata_port *ap)
2239 ata_qc_complete(qc, drv_stat); 2465 ata_qc_complete(qc, drv_stat);
2240} 2466}
2241 2467
2468
2469/**
2470 * swap_buf_le16 -
2471 * @buf: Buffer to swap
2472 * @buf_words: Number of 16-bit words in buffer.
2473 *
2474 * Swap halves of 16-bit words if needed to convert from
2475 * little-endian byte order to native cpu byte order, or
2476 * vice-versa.
2477 *
2478 * LOCKING:
2479 */
2242void swap_buf_le16(u16 *buf, unsigned int buf_words) 2480void swap_buf_le16(u16 *buf, unsigned int buf_words)
2243{ 2481{
2244#ifdef __BIG_ENDIAN 2482#ifdef __BIG_ENDIAN
@@ -2310,7 +2548,7 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
2310 qc->cursect++; 2548 qc->cursect++;
2311 qc->cursg_ofs++; 2549 qc->cursg_ofs++;
2312 2550
2313 if ((qc->cursg_ofs * ATA_SECT_SIZE) == sg_dma_len(&sg[qc->cursg])) { 2551 if ((qc->cursg_ofs * ATA_SECT_SIZE) == (&sg[qc->cursg])->length) {
2314 qc->cursg++; 2552 qc->cursg++;
2315 qc->cursg_ofs = 0; 2553 qc->cursg_ofs = 0;
2316 } 2554 }
@@ -2339,7 +2577,6 @@ static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes)
2339next_sg: 2577next_sg:
2340 sg = &qc->sg[qc->cursg]; 2578 sg = &qc->sg[qc->cursg];
2341 2579
2342next_page:
2343 page = sg->page; 2580 page = sg->page;
2344 offset = sg->offset + qc->cursg_ofs; 2581 offset = sg->offset + qc->cursg_ofs;
2345 2582
@@ -2347,7 +2584,8 @@ next_page:
2347 page = nth_page(page, (offset >> PAGE_SHIFT)); 2584 page = nth_page(page, (offset >> PAGE_SHIFT));
2348 offset %= PAGE_SIZE; 2585 offset %= PAGE_SIZE;
2349 2586
2350 count = min(sg_dma_len(sg) - qc->cursg_ofs, bytes); 2587 /* don't overrun current sg */
2588 count = min(sg->length - qc->cursg_ofs, bytes);
2351 2589
2352 /* don't cross page boundaries */ 2590 /* don't cross page boundaries */
2353 count = min(count, (unsigned int)PAGE_SIZE - offset); 2591 count = min(count, (unsigned int)PAGE_SIZE - offset);
@@ -2358,7 +2596,7 @@ next_page:
2358 qc->curbytes += count; 2596 qc->curbytes += count;
2359 qc->cursg_ofs += count; 2597 qc->cursg_ofs += count;
2360 2598
2361 if (qc->cursg_ofs == sg_dma_len(sg)) { 2599 if (qc->cursg_ofs == sg->length) {
2362 qc->cursg++; 2600 qc->cursg++;
2363 qc->cursg_ofs = 0; 2601 qc->cursg_ofs = 0;
2364 } 2602 }
@@ -2371,8 +2609,6 @@ next_page:
2371 kunmap(page); 2609 kunmap(page);
2372 2610
2373 if (bytes) { 2611 if (bytes) {
2374 if (qc->cursg_ofs < sg_dma_len(sg))
2375 goto next_page;
2376 goto next_sg; 2612 goto next_sg;
2377 } 2613 }
2378} 2614}
@@ -2414,6 +2650,7 @@ err_out:
2414 * @ap: 2650 * @ap:
2415 * 2651 *
2416 * LOCKING: 2652 * LOCKING:
2653 * None. (executing in kernel thread context)
2417 */ 2654 */
2418 2655
2419static void ata_pio_block(struct ata_port *ap) 2656static void ata_pio_block(struct ata_port *ap)
@@ -2539,7 +2776,7 @@ static void atapi_request_sense(struct ata_port *ap, struct ata_device *dev,
2539 ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer)); 2776 ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer));
2540 qc->dma_dir = DMA_FROM_DEVICE; 2777 qc->dma_dir = DMA_FROM_DEVICE;
2541 2778
2542 memset(&qc->cdb, 0, sizeof(ap->cdb_len)); 2779 memset(&qc->cdb, 0, ap->cdb_len);
2543 qc->cdb[0] = REQUEST_SENSE; 2780 qc->cdb[0] = REQUEST_SENSE;
2544 qc->cdb[4] = SCSI_SENSE_BUFFERSIZE; 2781 qc->cdb[4] = SCSI_SENSE_BUFFERSIZE;
2545 2782
@@ -2582,6 +2819,7 @@ static void atapi_request_sense(struct ata_port *ap, struct ata_device *dev,
2582 * transaction completed successfully. 2819 * transaction completed successfully.
2583 * 2820 *
2584 * LOCKING: 2821 * LOCKING:
2822 * Inherited from SCSI layer (none, can sleep)
2585 */ 2823 */
2586 2824
2587static void ata_qc_timeout(struct ata_queued_cmd *qc) 2825static void ata_qc_timeout(struct ata_queued_cmd *qc)
@@ -2691,6 +2929,7 @@ out:
2691 * @dev: Device from whom we request an available command structure 2929 * @dev: Device from whom we request an available command structure
2692 * 2930 *
2693 * LOCKING: 2931 * LOCKING:
2932 * None.
2694 */ 2933 */
2695 2934
2696static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) 2935static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
@@ -2716,6 +2955,7 @@ static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
2716 * @dev: Device from whom we request an available command structure 2955 * @dev: Device from whom we request an available command structure
2717 * 2956 *
2718 * LOCKING: 2957 * LOCKING:
2958 * None.
2719 */ 2959 */
2720 2960
2721struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, 2961struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
@@ -2780,6 +3020,7 @@ static void __ata_qc_complete(struct ata_queued_cmd *qc)
2780 * in case something prevents using it. 3020 * in case something prevents using it.
2781 * 3021 *
2782 * LOCKING: 3022 * LOCKING:
3023 * spin_lock_irqsave(host_set lock)
2783 * 3024 *
2784 */ 3025 */
2785void ata_qc_free(struct ata_queued_cmd *qc) 3026void ata_qc_free(struct ata_queued_cmd *qc)
@@ -2793,9 +3034,13 @@ void ata_qc_free(struct ata_queued_cmd *qc)
2793/** 3034/**
2794 * ata_qc_complete - Complete an active ATA command 3035 * ata_qc_complete - Complete an active ATA command
2795 * @qc: Command to complete 3036 * @qc: Command to complete
2796 * @drv_stat: ATA status register contents 3037 * @drv_stat: ATA Status register contents
3038 *
3039 * Indicate to the mid and upper layers that an ATA
3040 * command has completed, with either an ok or not-ok status.
2797 * 3041 *
2798 * LOCKING: 3042 * LOCKING:
3043 * spin_lock_irqsave(host_set lock)
2799 * 3044 *
2800 */ 3045 */
2801 3046
@@ -2811,6 +3056,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
2811 3056
2812 /* call completion callback */ 3057 /* call completion callback */
2813 rc = qc->complete_fn(qc, drv_stat); 3058 rc = qc->complete_fn(qc, drv_stat);
3059 qc->flags &= ~ATA_QCFLAG_ACTIVE;
2814 3060
2815 /* if callback indicates not to complete command (non-zero), 3061 /* if callback indicates not to complete command (non-zero),
2816 * return immediately 3062 * return immediately
@@ -2890,6 +3136,7 @@ err_out:
2890 return -1; 3136 return -1;
2891} 3137}
2892 3138
3139
2893/** 3140/**
2894 * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner 3141 * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner
2895 * @qc: command to issue to device 3142 * @qc: command to issue to device
@@ -2899,6 +3146,8 @@ err_out:
2899 * classes called "protocols", and issuing each type of protocol 3146 * classes called "protocols", and issuing each type of protocol
2900 * is slightly different. 3147 * is slightly different.
2901 * 3148 *
3149 * May be used as the qc_issue() entry in ata_port_operations.
3150 *
2902 * LOCKING: 3151 * LOCKING:
2903 * spin_lock_irqsave(host_set lock) 3152 * spin_lock_irqsave(host_set lock)
2904 * 3153 *
@@ -2956,7 +3205,7 @@ int ata_qc_issue_prot(struct ata_queued_cmd *qc)
2956} 3205}
2957 3206
2958/** 3207/**
2959 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction 3208 * ata_bmdma_setup_mmio - Set up PCI IDE BMDMA transaction
2960 * @qc: Info associated with this ATA transaction. 3209 * @qc: Info associated with this ATA transaction.
2961 * 3210 *
2962 * LOCKING: 3211 * LOCKING:
@@ -3063,6 +3312,18 @@ static void ata_bmdma_start_pio (struct ata_queued_cmd *qc)
3063 ap->ioaddr.bmdma_addr + ATA_DMA_CMD); 3312 ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
3064} 3313}
3065 3314
3315
3316/**
3317 * ata_bmdma_start - Start a PCI IDE BMDMA transaction
3318 * @qc: Info associated with this ATA transaction.
3319 *
3320 * Writes the ATA_DMA_START flag to the DMA command register.
3321 *
3322 * May be used as the bmdma_start() entry in ata_port_operations.
3323 *
3324 * LOCKING:
3325 * spin_lock_irqsave(host_set lock)
3326 */
3066void ata_bmdma_start(struct ata_queued_cmd *qc) 3327void ata_bmdma_start(struct ata_queued_cmd *qc)
3067{ 3328{
3068 if (qc->ap->flags & ATA_FLAG_MMIO) 3329 if (qc->ap->flags & ATA_FLAG_MMIO)
@@ -3071,6 +3332,20 @@ void ata_bmdma_start(struct ata_queued_cmd *qc)
3071 ata_bmdma_start_pio(qc); 3332 ata_bmdma_start_pio(qc);
3072} 3333}
3073 3334
3335
3336/**
3337 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction
3338 * @qc: Info associated with this ATA transaction.
3339 *
3340 * Writes address of PRD table to device's PRD Table Address
3341 * register, sets the DMA control register, and calls
3342 * ops->exec_command() to start the transfer.
3343 *
3344 * May be used as the bmdma_setup() entry in ata_port_operations.
3345 *
3346 * LOCKING:
3347 * spin_lock_irqsave(host_set lock)
3348 */
3074void ata_bmdma_setup(struct ata_queued_cmd *qc) 3349void ata_bmdma_setup(struct ata_queued_cmd *qc)
3075{ 3350{
3076 if (qc->ap->flags & ATA_FLAG_MMIO) 3351 if (qc->ap->flags & ATA_FLAG_MMIO)
@@ -3079,6 +3354,19 @@ void ata_bmdma_setup(struct ata_queued_cmd *qc)
3079 ata_bmdma_setup_pio(qc); 3354 ata_bmdma_setup_pio(qc);
3080} 3355}
3081 3356
3357
3358/**
3359 * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
3360 * @ap: Port associated with this ATA transaction.
3361 *
3362 * Clear interrupt and error flags in DMA status register.
3363 *
3364 * May be used as the irq_clear() entry in ata_port_operations.
3365 *
3366 * LOCKING:
3367 * spin_lock_irqsave(host_set lock)
3368 */
3369
3082void ata_bmdma_irq_clear(struct ata_port *ap) 3370void ata_bmdma_irq_clear(struct ata_port *ap)
3083{ 3371{
3084 if (ap->flags & ATA_FLAG_MMIO) { 3372 if (ap->flags & ATA_FLAG_MMIO) {
@@ -3091,6 +3379,19 @@ void ata_bmdma_irq_clear(struct ata_port *ap)
3091 3379
3092} 3380}
3093 3381
3382
3383/**
3384 * ata_bmdma_status - Read PCI IDE BMDMA status
3385 * @ap: Port associated with this ATA transaction.
3386 *
3387 * Read and return BMDMA status register.
3388 *
3389 * May be used as the bmdma_status() entry in ata_port_operations.
3390 *
3391 * LOCKING:
3392 * spin_lock_irqsave(host_set lock)
3393 */
3394
3094u8 ata_bmdma_status(struct ata_port *ap) 3395u8 ata_bmdma_status(struct ata_port *ap)
3095{ 3396{
3096 u8 host_stat; 3397 u8 host_stat;
@@ -3102,6 +3403,19 @@ u8 ata_bmdma_status(struct ata_port *ap)
3102 return host_stat; 3403 return host_stat;
3103} 3404}
3104 3405
3406
3407/**
3408 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer
3409 * @ap: Port associated with this ATA transaction.
3410 *
3411 * Clears the ATA_DMA_START flag in the dma control register
3412 *
3413 * May be used as the bmdma_stop() entry in ata_port_operations.
3414 *
3415 * LOCKING:
3416 * spin_lock_irqsave(host_set lock)
3417 */
3418
3105void ata_bmdma_stop(struct ata_port *ap) 3419void ata_bmdma_stop(struct ata_port *ap)
3106{ 3420{
3107 if (ap->flags & ATA_FLAG_MMIO) { 3421 if (ap->flags & ATA_FLAG_MMIO) {
@@ -3201,13 +3515,18 @@ idle_irq:
3201 3515
3202/** 3516/**
3203 * ata_interrupt - Default ATA host interrupt handler 3517 * ata_interrupt - Default ATA host interrupt handler
3204 * @irq: irq line 3518 * @irq: irq line (unused)
3205 * @dev_instance: pointer to our host information structure 3519 * @dev_instance: pointer to our ata_host_set information structure
3206 * @regs: unused 3520 * @regs: unused
3207 * 3521 *
3522 * Default interrupt handler for PCI IDE devices. Calls
3523 * ata_host_intr() for each port that is not disabled.
3524 *
3208 * LOCKING: 3525 * LOCKING:
3526 * Obtains host_set lock during operation.
3209 * 3527 *
3210 * RETURNS: 3528 * RETURNS:
3529 * IRQ_NONE or IRQ_HANDLED.
3211 * 3530 *
3212 */ 3531 */
3213 3532
@@ -3229,7 +3548,8 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
3229 struct ata_queued_cmd *qc; 3548 struct ata_queued_cmd *qc;
3230 3549
3231 qc = ata_qc_from_tag(ap, ap->active_tag); 3550 qc = ata_qc_from_tag(ap, ap->active_tag);
3232 if (qc && (!(qc->tf.ctl & ATA_NIEN))) 3551 if (qc && (!(qc->tf.ctl & ATA_NIEN)) &&
3552 (qc->flags & ATA_QCFLAG_ACTIVE))
3233 handled |= ata_host_intr(ap, qc); 3553 handled |= ata_host_intr(ap, qc);
3234 } 3554 }
3235 } 3555 }
@@ -3299,6 +3619,19 @@ err_out:
3299 ata_qc_complete(qc, ATA_ERR); 3619 ata_qc_complete(qc, ATA_ERR);
3300} 3620}
3301 3621
3622
3623/**
3624 * ata_port_start - Set port up for dma.
3625 * @ap: Port to initialize
3626 *
3627 * Called just after data structures for each port are
3628 * initialized. Allocates space for PRD table.
3629 *
3630 * May be used as the port_start() entry in ata_port_operations.
3631 *
3632 * LOCKING:
3633 */
3634
3302int ata_port_start (struct ata_port *ap) 3635int ata_port_start (struct ata_port *ap)
3303{ 3636{
3304 struct device *dev = ap->host_set->dev; 3637 struct device *dev = ap->host_set->dev;
@@ -3312,6 +3645,18 @@ int ata_port_start (struct ata_port *ap)
3312 return 0; 3645 return 0;
3313} 3646}
3314 3647
3648
3649/**
3650 * ata_port_stop - Undo ata_port_start()
3651 * @ap: Port to shut down
3652 *
3653 * Frees the PRD table.
3654 *
3655 * May be used as the port_stop() entry in ata_port_operations.
3656 *
3657 * LOCKING:
3658 */
3659
3315void ata_port_stop (struct ata_port *ap) 3660void ata_port_stop (struct ata_port *ap)
3316{ 3661{
3317 struct device *dev = ap->host_set->dev; 3662 struct device *dev = ap->host_set->dev;
@@ -3319,6 +3664,13 @@ void ata_port_stop (struct ata_port *ap)
3319 dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma); 3664 dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma);
3320} 3665}
3321 3666
3667void ata_host_stop (struct ata_host_set *host_set)
3668{
3669 if (host_set->mmio_base)
3670 iounmap(host_set->mmio_base);
3671}
3672
3673
3322/** 3674/**
3323 * ata_host_remove - Unregister SCSI host structure with upper layers 3675 * ata_host_remove - Unregister SCSI host structure with upper layers
3324 * @ap: Port to unregister 3676 * @ap: Port to unregister
@@ -3347,7 +3699,11 @@ static void ata_host_remove(struct ata_port *ap, unsigned int do_unregister)
3347 * @ent: Probe information provided by low-level driver 3699 * @ent: Probe information provided by low-level driver
3348 * @port_no: Port number associated with this ata_port 3700 * @port_no: Port number associated with this ata_port
3349 * 3701 *
3702 * Initialize a new ata_port structure, and its associated
3703 * scsi_host.
3704 *
3350 * LOCKING: 3705 * LOCKING:
3706 * Inherited from caller.
3351 * 3707 *
3352 */ 3708 */
3353 3709
@@ -3402,9 +3758,13 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
3402 * @host_set: Collections of ports to which we add 3758 * @host_set: Collections of ports to which we add
3403 * @port_no: Port number associated with this host 3759 * @port_no: Port number associated with this host
3404 * 3760 *
3761 * Attach low-level ATA driver to system.
3762 *
3405 * LOCKING: 3763 * LOCKING:
3764 * PCI/etc. bus probe sem.
3406 * 3765 *
3407 * RETURNS: 3766 * RETURNS:
3767 * New ata_port on success, for NULL on error.
3408 * 3768 *
3409 */ 3769 */
3410 3770
@@ -3437,12 +3797,22 @@ err_out:
3437} 3797}
3438 3798
3439/** 3799/**
3440 * ata_device_add - 3800 * ata_device_add - Register hardware device with ATA and SCSI layers
3441 * @ent: 3801 * @ent: Probe information describing hardware device to be registered
3802 *
3803 * This function processes the information provided in the probe
3804 * information struct @ent, allocates the necessary ATA and SCSI
3805 * host information structures, initializes them, and registers
3806 * everything with requisite kernel subsystems.
3807 *
3808 * This function requests irqs, probes the ATA bus, and probes
3809 * the SCSI bus.
3442 * 3810 *
3443 * LOCKING: 3811 * LOCKING:
3812 * PCI/etc. bus probe sem.
3444 * 3813 *
3445 * RETURNS: 3814 * RETURNS:
3815 * Number of ports registered. Zero on error (no ports registered).
3446 * 3816 *
3447 */ 3817 */
3448 3818
@@ -3594,7 +3964,15 @@ int ata_scsi_release(struct Scsi_Host *host)
3594/** 3964/**
3595 * ata_std_ports - initialize ioaddr with standard port offsets. 3965 * ata_std_ports - initialize ioaddr with standard port offsets.
3596 * @ioaddr: IO address structure to be initialized 3966 * @ioaddr: IO address structure to be initialized
3967 *
3968 * Utility function which initializes data_addr, error_addr,
3969 * feature_addr, nsect_addr, lbal_addr, lbam_addr, lbah_addr,
3970 * device_addr, status_addr, and command_addr to standard offsets
3971 * relative to cmd_addr.
3972 *
3973 * Does not set ctl_addr, altstatus_addr, bmdma_addr, or scr_addr.
3597 */ 3974 */
3975
3598void ata_std_ports(struct ata_ioports *ioaddr) 3976void ata_std_ports(struct ata_ioports *ioaddr)
3599{ 3977{
3600 ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA; 3978 ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA;
@@ -3636,6 +4014,20 @@ ata_probe_ent_alloc(struct device *dev, struct ata_port_info *port)
3636 return probe_ent; 4014 return probe_ent;
3637} 4015}
3638 4016
4017
4018
4019/**
4020 * ata_pci_init_native_mode - Initialize native-mode driver
4021 * @pdev: pci device to be initialized
4022 * @port: array[2] of pointers to port info structures.
4023 *
4024 * Utility function which allocates and initializes an
4025 * ata_probe_ent structure for a standard dual-port
4026 * PIO-based IDE controller. The returned ata_probe_ent
4027 * structure can be passed to ata_device_add(). The returned
4028 * ata_probe_ent structure should then be freed with kfree().
4029 */
4030
3639#ifdef CONFIG_PCI 4031#ifdef CONFIG_PCI
3640struct ata_probe_ent * 4032struct ata_probe_ent *
3641ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port) 4033ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port)
@@ -3717,10 +4109,19 @@ ata_pci_init_legacy_mode(struct pci_dev *pdev, struct ata_port_info **port,
3717 * @port_info: Information from low-level host driver 4109 * @port_info: Information from low-level host driver
3718 * @n_ports: Number of ports attached to host controller 4110 * @n_ports: Number of ports attached to host controller
3719 * 4111 *
4112 * This is a helper function which can be called from a driver's
4113 * xxx_init_one() probe function if the hardware uses traditional
4114 * IDE taskfile registers.
4115 *
4116 * This function calls pci_enable_device(), reserves its register
4117 * regions, sets the dma mask, enables bus master mode, and calls
4118 * ata_device_add()
4119 *
3720 * LOCKING: 4120 * LOCKING:
3721 * Inherited from PCI layer (may sleep). 4121 * Inherited from PCI layer (may sleep).
3722 * 4122 *
3723 * RETURNS: 4123 * RETURNS:
4124 * Zero on success, negative on errno-based value on error.
3724 * 4125 *
3725 */ 4126 */
3726 4127
@@ -3875,10 +4276,6 @@ void ata_pci_remove_one (struct pci_dev *pdev)
3875 } 4276 }
3876 4277
3877 free_irq(host_set->irq, host_set); 4278 free_irq(host_set->irq, host_set);
3878 if (host_set->ops->host_stop)
3879 host_set->ops->host_stop(host_set);
3880 if (host_set->mmio_base)
3881 iounmap(host_set->mmio_base);
3882 4279
3883 for (i = 0; i < host_set->n_ports; i++) { 4280 for (i = 0; i < host_set->n_ports; i++) {
3884 ap = host_set->ports[i]; 4281 ap = host_set->ports[i];
@@ -3897,6 +4294,9 @@ void ata_pci_remove_one (struct pci_dev *pdev)
3897 scsi_host_put(ap->host); 4294 scsi_host_put(ap->host);
3898 } 4295 }
3899 4296
4297 if (host_set->ops->host_stop)
4298 host_set->ops->host_stop(host_set);
4299
3900 kfree(host_set); 4300 kfree(host_set);
3901 4301
3902 pci_release_regions(pdev); 4302 pci_release_regions(pdev);
@@ -3940,15 +4340,6 @@ int pci_test_config_bits(struct pci_dev *pdev, struct pci_bits *bits)
3940#endif /* CONFIG_PCI */ 4340#endif /* CONFIG_PCI */
3941 4341
3942 4342
3943/**
3944 * ata_init -
3945 *
3946 * LOCKING:
3947 *
3948 * RETURNS:
3949 *
3950 */
3951
3952static int __init ata_init(void) 4343static int __init ata_init(void)
3953{ 4344{
3954 ata_wq = create_workqueue("ata"); 4345 ata_wq = create_workqueue("ata");
@@ -3994,6 +4385,7 @@ EXPORT_SYMBOL_GPL(ata_chk_err);
3994EXPORT_SYMBOL_GPL(ata_exec_command); 4385EXPORT_SYMBOL_GPL(ata_exec_command);
3995EXPORT_SYMBOL_GPL(ata_port_start); 4386EXPORT_SYMBOL_GPL(ata_port_start);
3996EXPORT_SYMBOL_GPL(ata_port_stop); 4387EXPORT_SYMBOL_GPL(ata_port_stop);
4388EXPORT_SYMBOL_GPL(ata_host_stop);
3997EXPORT_SYMBOL_GPL(ata_interrupt); 4389EXPORT_SYMBOL_GPL(ata_interrupt);
3998EXPORT_SYMBOL_GPL(ata_qc_prep); 4390EXPORT_SYMBOL_GPL(ata_qc_prep);
3999EXPORT_SYMBOL_GPL(ata_bmdma_setup); 4391EXPORT_SYMBOL_GPL(ata_bmdma_setup);
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 4c96df060c3b..7a4adc4c8f09 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -347,7 +347,10 @@ int ata_scsi_slave_config(struct scsi_device *sdev)
347 */ 347 */
348 if ((dev->flags & ATA_DFLAG_LBA48) && 348 if ((dev->flags & ATA_DFLAG_LBA48) &&
349 ((dev->flags & ATA_DFLAG_LOCK_SECTORS) == 0)) { 349 ((dev->flags & ATA_DFLAG_LOCK_SECTORS) == 0)) {
350 sdev->host->max_sectors = 2048; 350 /*
351 * do not overwrite sdev->host->max_sectors, since
352 * other drives on this host may not support LBA48
353 */
351 blk_queue_max_sectors(sdev->request_queue, 2048); 354 blk_queue_max_sectors(sdev->request_queue, 2048);
352 } 355 }
353 } 356 }
@@ -944,7 +947,7 @@ unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf,
944} 947}
945 948
946/** 949/**
947 * ata_scsiop_noop - 950 * ata_scsiop_noop - Command handler that simply returns success.
948 * @args: device IDENTIFY data / SCSI command of interest. 951 * @args: device IDENTIFY data / SCSI command of interest.
949 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. 952 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent.
950 * @buflen: Response buffer length. 953 * @buflen: Response buffer length.
diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h
index 6518226b8f87..d90430bbb0de 100644
--- a/drivers/scsi/libata.h
+++ b/drivers/scsi/libata.h
@@ -26,7 +26,7 @@
26#define __LIBATA_H__ 26#define __LIBATA_H__
27 27
28#define DRV_NAME "libata" 28#define DRV_NAME "libata"
29#define DRV_VERSION "1.10" /* must be exactly four chars */ 29#define DRV_VERSION "1.11" /* must be exactly four chars */
30 30
31struct ata_scsi_args { 31struct ata_scsi_args {
32 u16 *id; 32 u16 *id;
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 2240a0cde583..9bc1f153f7ea 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -300,7 +300,7 @@ qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
300 rport->dev_loss_tmo = ha->port_down_retry_count + 5; 300 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
301} 301}
302 302
303static struct fc_function_template qla2xxx_transport_functions = { 303struct fc_function_template qla2xxx_transport_functions = {
304 304
305 .show_host_node_name = 1, 305 .show_host_node_name = 1,
306 .show_host_port_name = 1, 306 .show_host_port_name = 1,
@@ -322,12 +322,6 @@ static struct fc_function_template qla2xxx_transport_functions = {
322 322
323}; 323};
324 324
325struct scsi_transport_template *
326qla2x00_alloc_transport_tmpl(void)
327{
328 return (fc_attach_transport(&qla2xxx_transport_functions));
329}
330
331void 325void
332qla2x00_init_host_attr(scsi_qla_host_t *ha) 326qla2x00_init_host_attr(scsi_qla_host_t *ha)
333{ 327{
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index e4bfe4d5bbe4..2efec6c24d60 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -24,7 +24,6 @@
24#define __QLA_GBL_H 24#define __QLA_GBL_H
25 25
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <scsi/scsi_transport.h>
28 27
29extern void qla2x00_remove_one(struct pci_dev *); 28extern void qla2x00_remove_one(struct pci_dev *);
30extern int qla2x00_probe_one(struct pci_dev *, struct qla_board_info *); 29extern int qla2x00_probe_one(struct pci_dev *, struct qla_board_info *);
@@ -248,9 +247,10 @@ extern void qla2x00_cancel_io_descriptors(scsi_qla_host_t *);
248/* 247/*
249 * Global Function Prototypes in qla_attr.c source file. 248 * Global Function Prototypes in qla_attr.c source file.
250 */ 249 */
250struct fc_function_template;
251extern struct fc_function_template qla2xxx_transport_functions;
251extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *); 252extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
252extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *); 253extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
253extern struct scsi_transport_template *qla2x00_alloc_transport_tmpl(void);
254extern void qla2x00_init_host_attr(scsi_qla_host_t *); 254extern void qla2x00_init_host_attr(scsi_qla_host_t *);
255extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *); 255extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
256extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *); 256extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 84db911318c6..3c97aa45772d 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -507,6 +507,7 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
507 int ret, i; 507 int ret, i;
508 unsigned int id, lun; 508 unsigned int id, lun;
509 unsigned long serial; 509 unsigned long serial;
510 unsigned long flags;
510 511
511 if (!CMD_SP(cmd)) 512 if (!CMD_SP(cmd))
512 return FAILED; 513 return FAILED;
@@ -519,7 +520,7 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
519 520
520 /* Check active list for command command. */ 521 /* Check active list for command command. */
521 spin_unlock_irq(ha->host->host_lock); 522 spin_unlock_irq(ha->host->host_lock);
522 spin_lock(&ha->hardware_lock); 523 spin_lock_irqsave(&ha->hardware_lock, flags);
523 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) { 524 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
524 sp = ha->outstanding_cmds[i]; 525 sp = ha->outstanding_cmds[i];
525 526
@@ -534,7 +535,7 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
534 sp->state)); 535 sp->state));
535 DEBUG3(qla2x00_print_scsi_cmd(cmd);) 536 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
536 537
537 spin_unlock(&ha->hardware_lock); 538 spin_unlock_irqrestore(&ha->hardware_lock, flags);
538 if (qla2x00_abort_command(ha, sp)) { 539 if (qla2x00_abort_command(ha, sp)) {
539 DEBUG2(printk("%s(%ld): abort_command " 540 DEBUG2(printk("%s(%ld): abort_command "
540 "mbx failed.\n", __func__, ha->host_no)); 541 "mbx failed.\n", __func__, ha->host_no));
@@ -543,20 +544,19 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
543 "mbx success.\n", __func__, ha->host_no)); 544 "mbx success.\n", __func__, ha->host_no));
544 ret = SUCCESS; 545 ret = SUCCESS;
545 } 546 }
546 spin_lock(&ha->hardware_lock); 547 spin_lock_irqsave(&ha->hardware_lock, flags);
547 548
548 break; 549 break;
549 } 550 }
551 spin_unlock_irqrestore(&ha->hardware_lock, flags);
550 552
551 /* Wait for the command to be returned. */ 553 /* Wait for the command to be returned. */
552 if (ret == SUCCESS) { 554 if (ret == SUCCESS) {
553 spin_unlock(&ha->hardware_lock);
554 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) { 555 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
555 qla_printk(KERN_ERR, ha, 556 qla_printk(KERN_ERR, ha,
556 "scsi(%ld:%d:%d): Abort handler timed out -- %lx " 557 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
557 "%x.\n", ha->host_no, id, lun, serial, ret); 558 "%x.\n", ha->host_no, id, lun, serial, ret);
558 } 559 }
559 spin_lock(&ha->hardware_lock);
560 } 560 }
561 spin_lock_irq(ha->host->host_lock); 561 spin_lock_irq(ha->host->host_lock);
562 562
@@ -588,6 +588,7 @@ qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
588 int status; 588 int status;
589 srb_t *sp; 589 srb_t *sp;
590 struct scsi_cmnd *cmd; 590 struct scsi_cmnd *cmd;
591 unsigned long flags;
591 592
592 status = 0; 593 status = 0;
593 594
@@ -596,11 +597,11 @@ qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
596 * array 597 * array
597 */ 598 */
598 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { 599 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
599 spin_lock(&ha->hardware_lock); 600 spin_lock_irqsave(&ha->hardware_lock, flags);
600 sp = ha->outstanding_cmds[cnt]; 601 sp = ha->outstanding_cmds[cnt];
601 if (sp) { 602 if (sp) {
602 cmd = sp->cmd; 603 cmd = sp->cmd;
603 spin_unlock(&ha->hardware_lock); 604 spin_unlock_irqrestore(&ha->hardware_lock, flags);
604 if (cmd->device->id == t) { 605 if (cmd->device->id == t) {
605 if (!qla2x00_eh_wait_on_command(ha, cmd)) { 606 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
606 status = 1; 607 status = 1;
@@ -608,7 +609,7 @@ qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
608 } 609 }
609 } 610 }
610 } else { 611 } else {
611 spin_unlock(&ha->hardware_lock); 612 spin_unlock_irqrestore(&ha->hardware_lock, flags);
612 } 613 }
613 } 614 }
614 return (status); 615 return (status);
@@ -740,6 +741,7 @@ qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
740 int status; 741 int status;
741 srb_t *sp; 742 srb_t *sp;
742 struct scsi_cmnd *cmd; 743 struct scsi_cmnd *cmd;
744 unsigned long flags;
743 745
744 status = 1; 746 status = 1;
745 747
@@ -748,17 +750,17 @@ qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
748 * array 750 * array
749 */ 751 */
750 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { 752 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
751 spin_lock(&ha->hardware_lock); 753 spin_lock_irqsave(&ha->hardware_lock, flags);
752 sp = ha->outstanding_cmds[cnt]; 754 sp = ha->outstanding_cmds[cnt];
753 if (sp) { 755 if (sp) {
754 cmd = sp->cmd; 756 cmd = sp->cmd;
755 spin_unlock(&ha->hardware_lock); 757 spin_unlock_irqrestore(&ha->hardware_lock, flags);
756 status = qla2x00_eh_wait_on_command(ha, cmd); 758 status = qla2x00_eh_wait_on_command(ha, cmd);
757 if (status == 0) 759 if (status == 0)
758 break; 760 break;
759 } 761 }
760 else { 762 else {
761 spin_unlock(&ha->hardware_lock); 763 spin_unlock_irqrestore(&ha->hardware_lock, flags);
762 } 764 }
763 } 765 }
764 return (status); 766 return (status);
@@ -2350,7 +2352,8 @@ qla2x00_module_init(void)
2350#if DEBUG_QLA2100 2352#if DEBUG_QLA2100
2351 strcat(qla2x00_version_str, "-debug"); 2353 strcat(qla2x00_version_str, "-debug");
2352#endif 2354#endif
2353 qla2xxx_transport_template = qla2x00_alloc_transport_tmpl(); 2355 qla2xxx_transport_template =
2356 fc_attach_transport(&qla2xxx_transport_functions);
2354 if (!qla2xxx_transport_template) 2357 if (!qla2xxx_transport_template)
2355 return -ENODEV; 2358 return -ENODEV;
2356 2359
diff --git a/drivers/scsi/sata_nv.c b/drivers/scsi/sata_nv.c
index 69009f853a49..b0403ccd8a25 100644
--- a/drivers/scsi/sata_nv.c
+++ b/drivers/scsi/sata_nv.c
@@ -329,6 +329,8 @@ static void nv_host_stop (struct ata_host_set *host_set)
329 host->host_desc->disable_hotplug(host_set); 329 host->host_desc->disable_hotplug(host_set);
330 330
331 kfree(host); 331 kfree(host);
332
333 ata_host_stop(host_set);
332} 334}
333 335
334static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 336static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
diff --git a/drivers/scsi/sata_promise.c b/drivers/scsi/sata_promise.c
index 19a13e3590f4..b18c90582e67 100644
--- a/drivers/scsi/sata_promise.c
+++ b/drivers/scsi/sata_promise.c
@@ -122,6 +122,7 @@ static struct ata_port_operations pdc_ata_ops = {
122 .scr_write = pdc_sata_scr_write, 122 .scr_write = pdc_sata_scr_write,
123 .port_start = pdc_port_start, 123 .port_start = pdc_port_start,
124 .port_stop = pdc_port_stop, 124 .port_stop = pdc_port_stop,
125 .host_stop = ata_host_stop,
125}; 126};
126 127
127static struct ata_port_info pdc_port_info[] = { 128static struct ata_port_info pdc_port_info[] = {
@@ -151,6 +152,8 @@ static struct ata_port_info pdc_port_info[] = {
151static struct pci_device_id pdc_ata_pci_tbl[] = { 152static struct pci_device_id pdc_ata_pci_tbl[] = {
152 { PCI_VENDOR_ID_PROMISE, 0x3371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 153 { PCI_VENDOR_ID_PROMISE, 0x3371, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
153 board_2037x }, 154 board_2037x },
155 { PCI_VENDOR_ID_PROMISE, 0x3571, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
156 board_2037x },
154 { PCI_VENDOR_ID_PROMISE, 0x3373, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 157 { PCI_VENDOR_ID_PROMISE, 0x3373, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
155 board_2037x }, 158 board_2037x },
156 { PCI_VENDOR_ID_PROMISE, 0x3375, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 159 { PCI_VENDOR_ID_PROMISE, 0x3375, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
diff --git a/drivers/scsi/sata_qstor.c b/drivers/scsi/sata_qstor.c
index dfd362104717..1383e8a28d72 100644
--- a/drivers/scsi/sata_qstor.c
+++ b/drivers/scsi/sata_qstor.c
@@ -536,6 +536,8 @@ static void qs_host_stop(struct ata_host_set *host_set)
536 536
537 writeb(0, mmio_base + QS_HCT_CTRL); /* disable host interrupts */ 537 writeb(0, mmio_base + QS_HCT_CTRL); /* disable host interrupts */
538 writeb(QS_CNFG3_GSRST, mmio_base + QS_HCF_CNFG3); /* global reset */ 538 writeb(QS_CNFG3_GSRST, mmio_base + QS_HCF_CNFG3); /* global reset */
539
540 ata_host_stop(host_set);
539} 541}
540 542
541static void qs_host_init(unsigned int chip_id, struct ata_probe_ent *pe) 543static void qs_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c
index f0489dc302a0..49ed557a4b66 100644
--- a/drivers/scsi/sata_sil.c
+++ b/drivers/scsi/sata_sil.c
@@ -82,6 +82,7 @@ static struct pci_device_id sil_pci_tbl[] = {
82 { 0x1095, 0x3114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3114 }, 82 { 0x1095, 0x3114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3114 },
83 { 0x1002, 0x436e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112 }, 83 { 0x1002, 0x436e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112 },
84 { 0x1002, 0x4379, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112 }, 84 { 0x1002, 0x4379, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112 },
85 { 0x1002, 0x437a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112 },
85 { } /* terminate list */ 86 { } /* terminate list */
86}; 87};
87 88
@@ -160,6 +161,7 @@ static struct ata_port_operations sil_ops = {
160 .scr_write = sil_scr_write, 161 .scr_write = sil_scr_write,
161 .port_start = ata_port_start, 162 .port_start = ata_port_start,
162 .port_stop = ata_port_stop, 163 .port_stop = ata_port_stop,
164 .host_stop = ata_host_stop,
163}; 165};
164 166
165static struct ata_port_info sil_port_info[] = { 167static struct ata_port_info sil_port_info[] = {
@@ -430,7 +432,13 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
430 writeb(cls, mmio_base + SIL_FIFO_R0); 432 writeb(cls, mmio_base + SIL_FIFO_R0);
431 writeb(cls, mmio_base + SIL_FIFO_W0); 433 writeb(cls, mmio_base + SIL_FIFO_W0);
432 writeb(cls, mmio_base + SIL_FIFO_R1); 434 writeb(cls, mmio_base + SIL_FIFO_R1);
433 writeb(cls, mmio_base + SIL_FIFO_W2); 435 writeb(cls, mmio_base + SIL_FIFO_W1);
436 if (ent->driver_data == sil_3114) {
437 writeb(cls, mmio_base + SIL_FIFO_R2);
438 writeb(cls, mmio_base + SIL_FIFO_W2);
439 writeb(cls, mmio_base + SIL_FIFO_R3);
440 writeb(cls, mmio_base + SIL_FIFO_W3);
441 }
434 } else 442 } else
435 printk(KERN_WARNING DRV_NAME "(%s): cache line size not set. Driver may not function\n", 443 printk(KERN_WARNING DRV_NAME "(%s): cache line size not set. Driver may not function\n",
436 pci_name(pdev)); 444 pci_name(pdev));
diff --git a/drivers/scsi/sata_sis.c b/drivers/scsi/sata_sis.c
index 5105ddd08447..e418b89c6b9d 100644
--- a/drivers/scsi/sata_sis.c
+++ b/drivers/scsi/sata_sis.c
@@ -114,6 +114,7 @@ static struct ata_port_operations sis_ops = {
114 .scr_write = sis_scr_write, 114 .scr_write = sis_scr_write,
115 .port_start = ata_port_start, 115 .port_start = ata_port_start,
116 .port_stop = ata_port_stop, 116 .port_stop = ata_port_stop,
117 .host_stop = ata_host_stop,
117}; 118};
118 119
119static struct ata_port_info sis_port_info = { 120static struct ata_port_info sis_port_info = {
diff --git a/drivers/scsi/sata_svw.c b/drivers/scsi/sata_svw.c
index 8d1a5d25c053..edef1fa969fc 100644
--- a/drivers/scsi/sata_svw.c
+++ b/drivers/scsi/sata_svw.c
@@ -313,6 +313,7 @@ static struct ata_port_operations k2_sata_ops = {
313 .scr_write = k2_sata_scr_write, 313 .scr_write = k2_sata_scr_write,
314 .port_start = ata_port_start, 314 .port_start = ata_port_start,
315 .port_stop = ata_port_stop, 315 .port_stop = ata_port_stop,
316 .host_stop = ata_host_stop,
316}; 317};
317 318
318static void k2_sata_setup_port(struct ata_ioports *port, unsigned long base) 319static void k2_sata_setup_port(struct ata_ioports *port, unsigned long base)
@@ -395,7 +396,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
395 396
396 /* Clear a magic bit in SCR1 according to Darwin, those help 397 /* Clear a magic bit in SCR1 according to Darwin, those help
397 * some funky seagate drives (though so far, those were already 398 * some funky seagate drives (though so far, those were already
398 * set by the firmware on the machines I had access to 399 * set by the firmware on the machines I had access to)
399 */ 400 */
400 writel(readl(mmio_base + K2_SATA_SICR1_OFFSET) & ~0x00040000, 401 writel(readl(mmio_base + K2_SATA_SICR1_OFFSET) & ~0x00040000,
401 mmio_base + K2_SATA_SICR1_OFFSET); 402 mmio_base + K2_SATA_SICR1_OFFSET);
diff --git a/drivers/scsi/sata_sx4.c b/drivers/scsi/sata_sx4.c
index 70118650c461..140cea05de3f 100644
--- a/drivers/scsi/sata_sx4.c
+++ b/drivers/scsi/sata_sx4.c
@@ -245,6 +245,8 @@ static void pdc20621_host_stop(struct ata_host_set *host_set)
245 245
246 iounmap(dimm_mmio); 246 iounmap(dimm_mmio);
247 kfree(hpriv); 247 kfree(hpriv);
248
249 ata_host_stop(host_set);
248} 250}
249 251
250static int pdc_port_start(struct ata_port *ap) 252static int pdc_port_start(struct ata_port *ap)
diff --git a/drivers/scsi/sata_uli.c b/drivers/scsi/sata_uli.c
index 0bff4f475f26..a71fb54eebd3 100644
--- a/drivers/scsi/sata_uli.c
+++ b/drivers/scsi/sata_uli.c
@@ -113,6 +113,7 @@ static struct ata_port_operations uli_ops = {
113 113
114 .port_start = ata_port_start, 114 .port_start = ata_port_start,
115 .port_stop = ata_port_stop, 115 .port_stop = ata_port_stop,
116 .host_stop = ata_host_stop,
116}; 117};
117 118
118static struct ata_port_info uli_port_info = { 119static struct ata_port_info uli_port_info = {
diff --git a/drivers/scsi/sata_via.c b/drivers/scsi/sata_via.c
index 3a7830667277..f43183c19a12 100644
--- a/drivers/scsi/sata_via.c
+++ b/drivers/scsi/sata_via.c
@@ -134,6 +134,7 @@ static struct ata_port_operations svia_sata_ops = {
134 134
135 .port_start = ata_port_start, 135 .port_start = ata_port_start,
136 .port_stop = ata_port_stop, 136 .port_stop = ata_port_stop,
137 .host_stop = ata_host_stop,
137}; 138};
138 139
139static struct ata_port_info svia_port_info = { 140static struct ata_port_info svia_port_info = {
diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c
index 2c28f0ad73c2..c5e09dc6f3de 100644
--- a/drivers/scsi/sata_vsc.c
+++ b/drivers/scsi/sata_vsc.c
@@ -21,6 +21,7 @@
21#include <linux/blkdev.h> 21#include <linux/blkdev.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/dma-mapping.h>
24#include "scsi.h" 25#include "scsi.h"
25#include <scsi/scsi_host.h> 26#include <scsi/scsi_host.h>
26#include <linux/libata.h> 27#include <linux/libata.h>
@@ -230,6 +231,7 @@ static struct ata_port_operations vsc_sata_ops = {
230 .scr_write = vsc_sata_scr_write, 231 .scr_write = vsc_sata_scr_write,
231 .port_start = ata_port_start, 232 .port_start = ata_port_start,
232 .port_stop = ata_port_stop, 233 .port_stop = ata_port_stop,
234 .host_stop = ata_host_stop,
233}; 235};
234 236
235static void __devinit vsc_sata_setup_port(struct ata_ioports *port, unsigned long base) 237static void __devinit vsc_sata_setup_port(struct ata_ioports *port, unsigned long base)
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 05d2bd075fd4..184bcaeaf812 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -542,7 +542,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
542 * that the device is no longer present */ 542 * that the device is no longer present */
543 cmd->result = DID_NO_CONNECT << 16; 543 cmd->result = DID_NO_CONNECT << 16;
544 atomic_inc(&cmd->device->iorequest_cnt); 544 atomic_inc(&cmd->device->iorequest_cnt);
545 scsi_done(cmd); 545 __scsi_done(cmd);
546 /* return 0 (because the command has been processed) */ 546 /* return 0 (because the command has been processed) */
547 goto out; 547 goto out;
548 } 548 }
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index cca772624ae7..8d0d302844a1 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1197,6 +1197,7 @@ struct scsi_device *__scsi_add_device(struct Scsi_Host *shost, uint channel,
1197 if (!starget) 1197 if (!starget)
1198 return ERR_PTR(-ENOMEM); 1198 return ERR_PTR(-ENOMEM);
1199 1199
1200 get_device(&starget->dev);
1200 down(&shost->scan_mutex); 1201 down(&shost->scan_mutex);
1201 res = scsi_probe_and_add_lun(starget, lun, NULL, &sdev, 1, hostdata); 1202 res = scsi_probe_and_add_lun(starget, lun, NULL, &sdev, 1, hostdata);
1202 if (res != SCSI_SCAN_LUN_PRESENT) 1203 if (res != SCSI_SCAN_LUN_PRESENT)
diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c
index 303d7656f710..67c6cc40ce16 100644
--- a/drivers/scsi/scsi_transport_spi.c
+++ b/drivers/scsi/scsi_transport_spi.c
@@ -22,6 +22,7 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/workqueue.h> 24#include <linux/workqueue.h>
25#include <linux/blkdev.h>
25#include <asm/semaphore.h> 26#include <asm/semaphore.h>
26#include <scsi/scsi.h> 27#include <scsi/scsi.h>
27#include "scsi_priv.h" 28#include "scsi_priv.h"
@@ -34,13 +35,18 @@
34 35
35#define SPI_PRINTK(x, l, f, a...) dev_printk(l, &(x)->dev, f , ##a) 36#define SPI_PRINTK(x, l, f, a...) dev_printk(l, &(x)->dev, f , ##a)
36 37
37#define SPI_NUM_ATTRS 10 /* increase this if you add attributes */ 38#define SPI_NUM_ATTRS 13 /* increase this if you add attributes */
38#define SPI_OTHER_ATTRS 1 /* Increase this if you add "always 39#define SPI_OTHER_ATTRS 1 /* Increase this if you add "always
39 * on" attributes */ 40 * on" attributes */
40#define SPI_HOST_ATTRS 1 41#define SPI_HOST_ATTRS 1
41 42
42#define SPI_MAX_ECHO_BUFFER_SIZE 4096 43#define SPI_MAX_ECHO_BUFFER_SIZE 4096
43 44
45#define DV_LOOPS 3
46#define DV_TIMEOUT (10*HZ)
47#define DV_RETRIES 3 /* should only need at most
48 * two cc/ua clears */
49
44/* Private data accessors (keep these out of the header file) */ 50/* Private data accessors (keep these out of the header file) */
45#define spi_dv_pending(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_pending) 51#define spi_dv_pending(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_pending)
46#define spi_dv_sem(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_sem) 52#define spi_dv_sem(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_sem)
@@ -100,6 +106,29 @@ static int sprint_frac(char *dest, int value, int denom)
100 return result; 106 return result;
101} 107}
102 108
109/* Modification of scsi_wait_req that will clear UNIT ATTENTION conditions
110 * resulting from (likely) bus and device resets */
111static void spi_wait_req(struct scsi_request *sreq, const void *cmd,
112 void *buffer, unsigned bufflen)
113{
114 int i;
115
116 for(i = 0; i < DV_RETRIES; i++) {
117 sreq->sr_request->flags |= REQ_FAILFAST;
118
119 scsi_wait_req(sreq, cmd, buffer, bufflen,
120 DV_TIMEOUT, /* retries */ 1);
121 if (sreq->sr_result & DRIVER_SENSE) {
122 struct scsi_sense_hdr sshdr;
123
124 if (scsi_request_normalize_sense(sreq, &sshdr)
125 && sshdr.sense_key == UNIT_ATTENTION)
126 continue;
127 }
128 break;
129 }
130}
131
103static struct { 132static struct {
104 enum spi_signal_type value; 133 enum spi_signal_type value;
105 char *name; 134 char *name;
@@ -190,8 +219,11 @@ static int spi_setup_transport_attrs(struct device *dev)
190 struct scsi_target *starget = to_scsi_target(dev); 219 struct scsi_target *starget = to_scsi_target(dev);
191 220
192 spi_period(starget) = -1; /* illegal value */ 221 spi_period(starget) = -1; /* illegal value */
222 spi_min_period(starget) = 0;
193 spi_offset(starget) = 0; /* async */ 223 spi_offset(starget) = 0; /* async */
224 spi_max_offset(starget) = 255;
194 spi_width(starget) = 0; /* narrow */ 225 spi_width(starget) = 0; /* narrow */
226 spi_max_width(starget) = 1;
195 spi_iu(starget) = 0; /* no IU */ 227 spi_iu(starget) = 0; /* no IU */
196 spi_dt(starget) = 0; /* ST */ 228 spi_dt(starget) = 0; /* ST */
197 spi_qas(starget) = 0; 229 spi_qas(starget) = 0;
@@ -206,6 +238,34 @@ static int spi_setup_transport_attrs(struct device *dev)
206 return 0; 238 return 0;
207} 239}
208 240
241#define spi_transport_show_simple(field, format_string) \
242 \
243static ssize_t \
244show_spi_transport_##field(struct class_device *cdev, char *buf) \
245{ \
246 struct scsi_target *starget = transport_class_to_starget(cdev); \
247 struct spi_transport_attrs *tp; \
248 \
249 tp = (struct spi_transport_attrs *)&starget->starget_data; \
250 return snprintf(buf, 20, format_string, tp->field); \
251}
252
253#define spi_transport_store_simple(field, format_string) \
254 \
255static ssize_t \
256store_spi_transport_##field(struct class_device *cdev, const char *buf, \
257 size_t count) \
258{ \
259 int val; \
260 struct scsi_target *starget = transport_class_to_starget(cdev); \
261 struct spi_transport_attrs *tp; \
262 \
263 tp = (struct spi_transport_attrs *)&starget->starget_data; \
264 val = simple_strtoul(buf, NULL, 0); \
265 tp->field = val; \
266 return count; \
267}
268
209#define spi_transport_show_function(field, format_string) \ 269#define spi_transport_show_function(field, format_string) \
210 \ 270 \
211static ssize_t \ 271static ssize_t \
@@ -232,6 +292,25 @@ store_spi_transport_##field(struct class_device *cdev, const char *buf, \
232 struct spi_internal *i = to_spi_internal(shost->transportt); \ 292 struct spi_internal *i = to_spi_internal(shost->transportt); \
233 \ 293 \
234 val = simple_strtoul(buf, NULL, 0); \ 294 val = simple_strtoul(buf, NULL, 0); \
295 i->f->set_##field(starget, val); \
296 return count; \
297}
298
299#define spi_transport_store_max(field, format_string) \
300static ssize_t \
301store_spi_transport_##field(struct class_device *cdev, const char *buf, \
302 size_t count) \
303{ \
304 int val; \
305 struct scsi_target *starget = transport_class_to_starget(cdev); \
306 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \
307 struct spi_internal *i = to_spi_internal(shost->transportt); \
308 struct spi_transport_attrs *tp \
309 = (struct spi_transport_attrs *)&starget->starget_data; \
310 \
311 val = simple_strtoul(buf, NULL, 0); \
312 if (val > tp->max_##field) \
313 val = tp->max_##field; \
235 i->f->set_##field(starget, val); \ 314 i->f->set_##field(starget, val); \
236 return count; \ 315 return count; \
237} 316}
@@ -243,9 +322,24 @@ static CLASS_DEVICE_ATTR(field, S_IRUGO | S_IWUSR, \
243 show_spi_transport_##field, \ 322 show_spi_transport_##field, \
244 store_spi_transport_##field); 323 store_spi_transport_##field);
245 324
325#define spi_transport_simple_attr(field, format_string) \
326 spi_transport_show_simple(field, format_string) \
327 spi_transport_store_simple(field, format_string) \
328static CLASS_DEVICE_ATTR(field, S_IRUGO | S_IWUSR, \
329 show_spi_transport_##field, \
330 store_spi_transport_##field);
331
332#define spi_transport_max_attr(field, format_string) \
333 spi_transport_show_function(field, format_string) \
334 spi_transport_store_max(field, format_string) \
335 spi_transport_simple_attr(max_##field, format_string) \
336static CLASS_DEVICE_ATTR(field, S_IRUGO | S_IWUSR, \
337 show_spi_transport_##field, \
338 store_spi_transport_##field);
339
246/* The Parallel SCSI Tranport Attributes: */ 340/* The Parallel SCSI Tranport Attributes: */
247spi_transport_rd_attr(offset, "%d\n"); 341spi_transport_max_attr(offset, "%d\n");
248spi_transport_rd_attr(width, "%d\n"); 342spi_transport_max_attr(width, "%d\n");
249spi_transport_rd_attr(iu, "%d\n"); 343spi_transport_rd_attr(iu, "%d\n");
250spi_transport_rd_attr(dt, "%d\n"); 344spi_transport_rd_attr(dt, "%d\n");
251spi_transport_rd_attr(qas, "%d\n"); 345spi_transport_rd_attr(qas, "%d\n");
@@ -271,26 +365,18 @@ static CLASS_DEVICE_ATTR(revalidate, S_IWUSR, NULL, store_spi_revalidate);
271 365
272/* Translate the period into ns according to the current spec 366/* Translate the period into ns according to the current spec
273 * for SDTR/PPR messages */ 367 * for SDTR/PPR messages */
274static ssize_t show_spi_transport_period(struct class_device *cdev, char *buf) 368static ssize_t
275 369show_spi_transport_period_helper(struct class_device *cdev, char *buf,
370 int period)
276{ 371{
277 struct scsi_target *starget = transport_class_to_starget(cdev);
278 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
279 struct spi_transport_attrs *tp;
280 int len, picosec; 372 int len, picosec;
281 struct spi_internal *i = to_spi_internal(shost->transportt);
282
283 tp = (struct spi_transport_attrs *)&starget->starget_data;
284 373
285 if (i->f->get_period) 374 if (period < 0 || period > 0xff) {
286 i->f->get_period(starget);
287
288 if (tp->period < 0 || tp->period > 0xff) {
289 picosec = -1; 375 picosec = -1;
290 } else if (tp->period <= SPI_STATIC_PPR) { 376 } else if (period <= SPI_STATIC_PPR) {
291 picosec = ppr_to_ps[tp->period]; 377 picosec = ppr_to_ps[period];
292 } else { 378 } else {
293 picosec = tp->period * 4000; 379 picosec = period * 4000;
294 } 380 }
295 381
296 if (picosec == -1) { 382 if (picosec == -1) {
@@ -305,12 +391,9 @@ static ssize_t show_spi_transport_period(struct class_device *cdev, char *buf)
305} 391}
306 392
307static ssize_t 393static ssize_t
308store_spi_transport_period(struct class_device *cdev, const char *buf, 394store_spi_transport_period_helper(struct class_device *cdev, const char *buf,
309 size_t count) 395 size_t count, int *periodp)
310{ 396{
311 struct scsi_target *starget = transport_class_to_starget(cdev);
312 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
313 struct spi_internal *i = to_spi_internal(shost->transportt);
314 int j, picosec, period = -1; 397 int j, picosec, period = -1;
315 char *endp; 398 char *endp;
316 399
@@ -339,15 +422,79 @@ store_spi_transport_period(struct class_device *cdev, const char *buf,
339 if (period > 0xff) 422 if (period > 0xff)
340 period = 0xff; 423 period = 0xff;
341 424
342 i->f->set_period(starget, period); 425 *periodp = period;
343 426
344 return count; 427 return count;
345} 428}
346 429
430static ssize_t
431show_spi_transport_period(struct class_device *cdev, char *buf)
432{
433 struct scsi_target *starget = transport_class_to_starget(cdev);
434 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
435 struct spi_internal *i = to_spi_internal(shost->transportt);
436 struct spi_transport_attrs *tp =
437 (struct spi_transport_attrs *)&starget->starget_data;
438
439 if (i->f->get_period)
440 i->f->get_period(starget);
441
442 return show_spi_transport_period_helper(cdev, buf, tp->period);
443}
444
445static ssize_t
446store_spi_transport_period(struct class_device *cdev, const char *buf,
447 size_t count)
448{
449 struct scsi_target *starget = transport_class_to_starget(cdev);
450 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
451 struct spi_internal *i = to_spi_internal(shost->transportt);
452 struct spi_transport_attrs *tp =
453 (struct spi_transport_attrs *)&starget->starget_data;
454 int period, retval;
455
456 retval = store_spi_transport_period_helper(cdev, buf, count, &period);
457
458 if (period < tp->min_period)
459 period = tp->min_period;
460
461 i->f->set_period(starget, period);
462
463 return retval;
464}
465
347static CLASS_DEVICE_ATTR(period, S_IRUGO | S_IWUSR, 466static CLASS_DEVICE_ATTR(period, S_IRUGO | S_IWUSR,
348 show_spi_transport_period, 467 show_spi_transport_period,
349 store_spi_transport_period); 468 store_spi_transport_period);
350 469
470static ssize_t
471show_spi_transport_min_period(struct class_device *cdev, char *buf)
472{
473 struct scsi_target *starget = transport_class_to_starget(cdev);
474 struct spi_transport_attrs *tp =
475 (struct spi_transport_attrs *)&starget->starget_data;
476
477 return show_spi_transport_period_helper(cdev, buf, tp->min_period);
478}
479
480static ssize_t
481store_spi_transport_min_period(struct class_device *cdev, const char *buf,
482 size_t count)
483{
484 struct scsi_target *starget = transport_class_to_starget(cdev);
485 struct spi_transport_attrs *tp =
486 (struct spi_transport_attrs *)&starget->starget_data;
487
488 return store_spi_transport_period_helper(cdev, buf, count,
489 &tp->min_period);
490}
491
492
493static CLASS_DEVICE_ATTR(min_period, S_IRUGO | S_IWUSR,
494 show_spi_transport_min_period,
495 store_spi_transport_min_period);
496
497
351static ssize_t show_spi_host_signalling(struct class_device *cdev, char *buf) 498static ssize_t show_spi_host_signalling(struct class_device *cdev, char *buf)
352{ 499{
353 struct Scsi_Host *shost = transport_class_to_shost(cdev); 500 struct Scsi_Host *shost = transport_class_to_shost(cdev);
@@ -378,11 +525,6 @@ static CLASS_DEVICE_ATTR(signalling, S_IRUGO | S_IWUSR,
378 if(i->f->set_##x) \ 525 if(i->f->set_##x) \
379 i->f->set_##x(sdev->sdev_target, y) 526 i->f->set_##x(sdev->sdev_target, y)
380 527
381#define DV_LOOPS 3
382#define DV_TIMEOUT (10*HZ)
383#define DV_RETRIES 3 /* should only need at most
384 * two cc/ua clears */
385
386enum spi_compare_returns { 528enum spi_compare_returns {
387 SPI_COMPARE_SUCCESS, 529 SPI_COMPARE_SUCCESS,
388 SPI_COMPARE_FAILURE, 530 SPI_COMPARE_FAILURE,
@@ -446,8 +588,7 @@ spi_dv_device_echo_buffer(struct scsi_request *sreq, u8 *buffer,
446 for (r = 0; r < retries; r++) { 588 for (r = 0; r < retries; r++) {
447 sreq->sr_cmd_len = 0; /* wait_req to fill in */ 589 sreq->sr_cmd_len = 0; /* wait_req to fill in */
448 sreq->sr_data_direction = DMA_TO_DEVICE; 590 sreq->sr_data_direction = DMA_TO_DEVICE;
449 scsi_wait_req(sreq, spi_write_buffer, buffer, len, 591 spi_wait_req(sreq, spi_write_buffer, buffer, len);
450 DV_TIMEOUT, DV_RETRIES);
451 if(sreq->sr_result || !scsi_device_online(sdev)) { 592 if(sreq->sr_result || !scsi_device_online(sdev)) {
452 struct scsi_sense_hdr sshdr; 593 struct scsi_sense_hdr sshdr;
453 594
@@ -471,8 +612,7 @@ spi_dv_device_echo_buffer(struct scsi_request *sreq, u8 *buffer,
471 memset(ptr, 0, len); 612 memset(ptr, 0, len);
472 sreq->sr_cmd_len = 0; /* wait_req to fill in */ 613 sreq->sr_cmd_len = 0; /* wait_req to fill in */
473 sreq->sr_data_direction = DMA_FROM_DEVICE; 614 sreq->sr_data_direction = DMA_FROM_DEVICE;
474 scsi_wait_req(sreq, spi_read_buffer, ptr, len, 615 spi_wait_req(sreq, spi_read_buffer, ptr, len);
475 DV_TIMEOUT, DV_RETRIES);
476 scsi_device_set_state(sdev, SDEV_QUIESCE); 616 scsi_device_set_state(sdev, SDEV_QUIESCE);
477 617
478 if (memcmp(buffer, ptr, len) != 0) 618 if (memcmp(buffer, ptr, len) != 0)
@@ -500,8 +640,7 @@ spi_dv_device_compare_inquiry(struct scsi_request *sreq, u8 *buffer,
500 640
501 memset(ptr, 0, len); 641 memset(ptr, 0, len);
502 642
503 scsi_wait_req(sreq, spi_inquiry, ptr, len, 643 spi_wait_req(sreq, spi_inquiry, ptr, len);
504 DV_TIMEOUT, DV_RETRIES);
505 644
506 if(sreq->sr_result || !scsi_device_online(sdev)) { 645 if(sreq->sr_result || !scsi_device_online(sdev)) {
507 scsi_device_set_state(sdev, SDEV_QUIESCE); 646 scsi_device_set_state(sdev, SDEV_QUIESCE);
@@ -593,8 +732,7 @@ spi_dv_device_get_echo_buffer(struct scsi_request *sreq, u8 *buffer)
593 * (reservation conflict, device not ready, etc) just 732 * (reservation conflict, device not ready, etc) just
594 * skip the write tests */ 733 * skip the write tests */
595 for (l = 0; ; l++) { 734 for (l = 0; ; l++) {
596 scsi_wait_req(sreq, spi_test_unit_ready, NULL, 0, 735 spi_wait_req(sreq, spi_test_unit_ready, NULL, 0);
597 DV_TIMEOUT, DV_RETRIES);
598 736
599 if(sreq->sr_result) { 737 if(sreq->sr_result) {
600 if(l >= 3) 738 if(l >= 3)
@@ -608,8 +746,7 @@ spi_dv_device_get_echo_buffer(struct scsi_request *sreq, u8 *buffer)
608 sreq->sr_cmd_len = 0; 746 sreq->sr_cmd_len = 0;
609 sreq->sr_data_direction = DMA_FROM_DEVICE; 747 sreq->sr_data_direction = DMA_FROM_DEVICE;
610 748
611 scsi_wait_req(sreq, spi_read_buffer_descriptor, buffer, 4, 749 spi_wait_req(sreq, spi_read_buffer_descriptor, buffer, 4);
612 DV_TIMEOUT, DV_RETRIES);
613 750
614 if (sreq->sr_result) 751 if (sreq->sr_result)
615 /* Device has no echo buffer */ 752 /* Device has no echo buffer */
@@ -623,6 +760,7 @@ spi_dv_device_internal(struct scsi_request *sreq, u8 *buffer)
623{ 760{
624 struct spi_internal *i = to_spi_internal(sreq->sr_host->transportt); 761 struct spi_internal *i = to_spi_internal(sreq->sr_host->transportt);
625 struct scsi_device *sdev = sreq->sr_device; 762 struct scsi_device *sdev = sreq->sr_device;
763 struct scsi_target *starget = sdev->sdev_target;
626 int len = sdev->inquiry_len; 764 int len = sdev->inquiry_len;
627 /* first set us up for narrow async */ 765 /* first set us up for narrow async */
628 DV_SET(offset, 0); 766 DV_SET(offset, 0);
@@ -636,9 +774,11 @@ spi_dv_device_internal(struct scsi_request *sreq, u8 *buffer)
636 } 774 }
637 775
638 /* test width */ 776 /* test width */
639 if (i->f->set_width && sdev->wdtr) { 777 if (i->f->set_width && spi_max_width(starget) && sdev->wdtr) {
640 i->f->set_width(sdev->sdev_target, 1); 778 i->f->set_width(sdev->sdev_target, 1);
641 779
780 printk("WIDTH IS %d\n", spi_max_width(starget));
781
642 if (spi_dv_device_compare_inquiry(sreq, buffer, 782 if (spi_dv_device_compare_inquiry(sreq, buffer,
643 buffer + len, 783 buffer + len,
644 DV_LOOPS) 784 DV_LOOPS)
@@ -665,8 +805,8 @@ spi_dv_device_internal(struct scsi_request *sreq, u8 *buffer)
665 retry: 805 retry:
666 806
667 /* now set up to the maximum */ 807 /* now set up to the maximum */
668 DV_SET(offset, 255); 808 DV_SET(offset, spi_max_offset(starget));
669 DV_SET(period, 1); 809 DV_SET(period, spi_min_period(starget));
670 810
671 if (len == 0) { 811 if (len == 0) {
672 SPI_PRINTK(sdev->sdev_target, KERN_INFO, "Domain Validation skipping write tests\n"); 812 SPI_PRINTK(sdev->sdev_target, KERN_INFO, "Domain Validation skipping write tests\n");
@@ -873,6 +1013,16 @@ EXPORT_SYMBOL(spi_display_xfer_agreement);
873 if (i->f->show_##field) \ 1013 if (i->f->show_##field) \
874 count++ 1014 count++
875 1015
1016#define SETUP_RELATED_ATTRIBUTE(field, rel_field) \
1017 i->private_attrs[count] = class_device_attr_##field; \
1018 if (!i->f->set_##rel_field) { \
1019 i->private_attrs[count].attr.mode = S_IRUGO; \
1020 i->private_attrs[count].store = NULL; \
1021 } \
1022 i->attrs[count] = &i->private_attrs[count]; \
1023 if (i->f->show_##rel_field) \
1024 count++
1025
876#define SETUP_HOST_ATTRIBUTE(field) \ 1026#define SETUP_HOST_ATTRIBUTE(field) \
877 i->private_host_attrs[count] = class_device_attr_##field; \ 1027 i->private_host_attrs[count] = class_device_attr_##field; \
878 if (!i->f->set_##field) { \ 1028 if (!i->f->set_##field) { \
@@ -956,8 +1106,11 @@ spi_attach_transport(struct spi_function_template *ft)
956 i->f = ft; 1106 i->f = ft;
957 1107
958 SETUP_ATTRIBUTE(period); 1108 SETUP_ATTRIBUTE(period);
1109 SETUP_RELATED_ATTRIBUTE(min_period, period);
959 SETUP_ATTRIBUTE(offset); 1110 SETUP_ATTRIBUTE(offset);
1111 SETUP_RELATED_ATTRIBUTE(max_offset, offset);
960 SETUP_ATTRIBUTE(width); 1112 SETUP_ATTRIBUTE(width);
1113 SETUP_RELATED_ATTRIBUTE(max_width, width);
961 SETUP_ATTRIBUTE(iu); 1114 SETUP_ATTRIBUTE(iu);
962 SETUP_ATTRIBUTE(dt); 1115 SETUP_ATTRIBUTE(dt);
963 SETUP_ATTRIBUTE(qas); 1116 SETUP_ATTRIBUTE(qas);
diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
index 3471be05779a..82d68fdb1548 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -281,6 +281,9 @@ int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
281 char *buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd)); 281 char *buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
282 int result; 282 int result;
283 283
284 if (!buffer)
285 return -ENOMEM;
286
284 memset(&cgc, 0, sizeof(struct packet_command)); 287 memset(&cgc, 0, sizeof(struct packet_command));
285 cgc.cmd[0] = GPCMD_READ_SUBCHANNEL; 288 cgc.cmd[0] = GPCMD_READ_SUBCHANNEL;
286 cgc.cmd[2] = 0x40; /* I do want the subchannel info */ 289 cgc.cmd[2] = 0x40; /* I do want the subchannel info */
diff --git a/drivers/scsi/sym53c416.c b/drivers/scsi/sym53c416.c
index f26c3a29e631..ebfddd40ce67 100644
--- a/drivers/scsi/sym53c416.c
+++ b/drivers/scsi/sym53c416.c
@@ -809,7 +809,7 @@ static int sym53c416_host_reset(Scsi_Cmnd *SCpnt)
809 /* printk("sym53c416_reset\n"); */ 809 /* printk("sym53c416_reset\n"); */
810 base = SCpnt->device->host->io_port; 810 base = SCpnt->device->host->io_port;
811 /* search scsi_id - fixme, we shouldnt need to iterate for this! */ 811 /* search scsi_id - fixme, we shouldnt need to iterate for this! */
812 for(i = 0; i < host_index && scsi_id != -1; i++) 812 for(i = 0; i < host_index && scsi_id == -1; i++)
813 if(hosts[i].base == base) 813 if(hosts[i].base == base)
814 scsi_id = hosts[i].scsi_id; 814 scsi_id = hosts[i].scsi_id;
815 outb(RESET_CHIP, base + COMMAND_REG); 815 outb(RESET_CHIP, base + COMMAND_REG);
diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
index 5ff83d214f12..5b07c6ec3ecc 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
@@ -2038,8 +2038,9 @@ static void sym2_set_period(struct scsi_target *starget, int period)
2038 struct sym_hcb *np = sym_get_hcb(shost); 2038 struct sym_hcb *np = sym_get_hcb(shost);
2039 struct sym_tcb *tp = &np->target[starget->id]; 2039 struct sym_tcb *tp = &np->target[starget->id];
2040 2040
2041 /* have to have DT for these transfers */ 2041 /* have to have DT for these transfers, but DT will also
2042 if (period <= np->minsync) 2042 * set width, so check that this is allowed */
2043 if (period <= np->minsync && spi_width(starget))
2043 tp->tgoal.dt = 1; 2044 tp->tgoal.dt = 1;
2044 2045
2045 tp->tgoal.period = period; 2046 tp->tgoal.period = period;