xref: /linux/drivers/scsi/aic7xxx/aic79xx_osm.h (revision 7d12e780e003f93433d49ce78cfedf4b4c52adc5)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Adaptec AIC79xx device driver for Linux.
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Copyright (c) 2000-2001 Adaptec Inc.
51da177e4SLinus Torvalds  * All rights reserved.
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  * Redistribution and use in source and binary forms, with or without
81da177e4SLinus Torvalds  * modification, are permitted provided that the following conditions
91da177e4SLinus Torvalds  * are met:
101da177e4SLinus Torvalds  * 1. Redistributions of source code must retain the above copyright
111da177e4SLinus Torvalds  *    notice, this list of conditions, and the following disclaimer,
121da177e4SLinus Torvalds  *    without modification.
131da177e4SLinus Torvalds  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
141da177e4SLinus Torvalds  *    substantially similar to the "NO WARRANTY" disclaimer below
151da177e4SLinus Torvalds  *    ("Disclaimer") and any redistribution must be conditioned upon
161da177e4SLinus Torvalds  *    including a substantially similar Disclaimer requirement for further
171da177e4SLinus Torvalds  *    binary redistribution.
181da177e4SLinus Torvalds  * 3. Neither the names of the above-listed copyright holders nor the names
191da177e4SLinus Torvalds  *    of any contributors may be used to endorse or promote products derived
201da177e4SLinus Torvalds  *    from this software without specific prior written permission.
211da177e4SLinus Torvalds  *
221da177e4SLinus Torvalds  * Alternatively, this software may be distributed under the terms of the
231da177e4SLinus Torvalds  * GNU General Public License ("GPL") version 2 as published by the Free
241da177e4SLinus Torvalds  * Software Foundation.
251da177e4SLinus Torvalds  *
261da177e4SLinus Torvalds  * NO WARRANTY
271da177e4SLinus Torvalds  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
281da177e4SLinus Torvalds  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
291da177e4SLinus Torvalds  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
301da177e4SLinus Torvalds  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
311da177e4SLinus Torvalds  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
321da177e4SLinus Torvalds  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
331da177e4SLinus Torvalds  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
341da177e4SLinus Torvalds  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
351da177e4SLinus Torvalds  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
361da177e4SLinus Torvalds  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
371da177e4SLinus Torvalds  * POSSIBILITY OF SUCH DAMAGES.
381da177e4SLinus Torvalds  *
3953467e63SHannes Reinecke  * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm.h#166 $
401da177e4SLinus Torvalds  *
411da177e4SLinus Torvalds  */
421da177e4SLinus Torvalds #ifndef _AIC79XX_LINUX_H_
431da177e4SLinus Torvalds #define _AIC79XX_LINUX_H_
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds #include <linux/types.h>
461da177e4SLinus Torvalds #include <linux/blkdev.h>
471da177e4SLinus Torvalds #include <linux/delay.h>
481da177e4SLinus Torvalds #include <linux/ioport.h>
491da177e4SLinus Torvalds #include <linux/pci.h>
501da177e4SLinus Torvalds #include <linux/smp_lock.h>
5173a25462SHannes Reinecke #include <linux/interrupt.h>
521da177e4SLinus Torvalds #include <linux/module.h>
5373a25462SHannes Reinecke #include <linux/slab.h>
541da177e4SLinus Torvalds #include <asm/byteorder.h>
551da177e4SLinus Torvalds #include <asm/io.h>
561da177e4SLinus Torvalds 
5773a25462SHannes Reinecke #include <scsi/scsi.h>
5873a25462SHannes Reinecke #include <scsi/scsi_cmnd.h>
5973a25462SHannes Reinecke #include <scsi/scsi_eh.h>
6073a25462SHannes Reinecke #include <scsi/scsi_device.h>
6173a25462SHannes Reinecke #include <scsi/scsi_host.h>
6273a25462SHannes Reinecke #include <scsi/scsi_tcq.h>
6373a25462SHannes Reinecke #include <scsi/scsi_transport.h>
6473a25462SHannes Reinecke #include <scsi/scsi_transport_spi.h>
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds /* Core SCSI definitions */
671da177e4SLinus Torvalds #define AIC_LIB_PREFIX ahd
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds /* Name space conflict with BSD queue macros */
701da177e4SLinus Torvalds #ifdef LIST_HEAD
711da177e4SLinus Torvalds #undef LIST_HEAD
721da177e4SLinus Torvalds #endif
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds #include "cam.h"
751da177e4SLinus Torvalds #include "queue.h"
761da177e4SLinus Torvalds #include "scsi_message.h"
771da177e4SLinus Torvalds #include "scsi_iu.h"
781da177e4SLinus Torvalds #include "aiclib.h"
791da177e4SLinus Torvalds 
801da177e4SLinus Torvalds /*********************************** Debugging ********************************/
811da177e4SLinus Torvalds #ifdef CONFIG_AIC79XX_DEBUG_ENABLE
821da177e4SLinus Torvalds #ifdef CONFIG_AIC79XX_DEBUG_MASK
831da177e4SLinus Torvalds #define AHD_DEBUG 1
841da177e4SLinus Torvalds #define AHD_DEBUG_OPTS CONFIG_AIC79XX_DEBUG_MASK
851da177e4SLinus Torvalds #else
861da177e4SLinus Torvalds /*
871da177e4SLinus Torvalds  * Compile in debugging code, but do not enable any printfs.
881da177e4SLinus Torvalds  */
891da177e4SLinus Torvalds #define AHD_DEBUG 1
901da177e4SLinus Torvalds #define AHD_DEBUG_OPTS 0
911da177e4SLinus Torvalds #endif
921da177e4SLinus Torvalds /* No debugging code. */
931da177e4SLinus Torvalds #endif
941da177e4SLinus Torvalds 
951da177e4SLinus Torvalds /********************************** Misc Macros *******************************/
961da177e4SLinus Torvalds #define	powerof2(x)	((((x)-1)&(x))==0)
971da177e4SLinus Torvalds 
981da177e4SLinus Torvalds /************************* Forward Declarations *******************************/
991da177e4SLinus Torvalds struct ahd_softc;
1001da177e4SLinus Torvalds typedef struct pci_dev *ahd_dev_softc_t;
10173a25462SHannes Reinecke typedef struct scsi_cmnd      *ahd_io_ctx_t;
1021da177e4SLinus Torvalds 
1031da177e4SLinus Torvalds /******************************* Byte Order ***********************************/
1041da177e4SLinus Torvalds #define ahd_htobe16(x)	cpu_to_be16(x)
1051da177e4SLinus Torvalds #define ahd_htobe32(x)	cpu_to_be32(x)
1061da177e4SLinus Torvalds #define ahd_htobe64(x)	cpu_to_be64(x)
1071da177e4SLinus Torvalds #define ahd_htole16(x)	cpu_to_le16(x)
1081da177e4SLinus Torvalds #define ahd_htole32(x)	cpu_to_le32(x)
1091da177e4SLinus Torvalds #define ahd_htole64(x)	cpu_to_le64(x)
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds #define ahd_be16toh(x)	be16_to_cpu(x)
1121da177e4SLinus Torvalds #define ahd_be32toh(x)	be32_to_cpu(x)
1131da177e4SLinus Torvalds #define ahd_be64toh(x)	be64_to_cpu(x)
1141da177e4SLinus Torvalds #define ahd_le16toh(x)	le16_to_cpu(x)
1151da177e4SLinus Torvalds #define ahd_le32toh(x)	le32_to_cpu(x)
1161da177e4SLinus Torvalds #define ahd_le64toh(x)	le64_to_cpu(x)
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds /************************* Configuration Data *********************************/
1191da177e4SLinus Torvalds extern uint32_t aic79xx_allow_memio;
12073a25462SHannes Reinecke extern struct scsi_host_template aic79xx_driver_template;
1211da177e4SLinus Torvalds 
1221da177e4SLinus Torvalds /***************************** Bus Space/DMA **********************************/
1231da177e4SLinus Torvalds 
1241da177e4SLinus Torvalds typedef uint32_t bus_size_t;
1251da177e4SLinus Torvalds 
1261da177e4SLinus Torvalds typedef enum {
1271da177e4SLinus Torvalds 	BUS_SPACE_MEMIO,
1281da177e4SLinus Torvalds 	BUS_SPACE_PIO
1291da177e4SLinus Torvalds } bus_space_tag_t;
1301da177e4SLinus Torvalds 
1311da177e4SLinus Torvalds typedef union {
1321da177e4SLinus Torvalds 	u_long		  ioport;
1331da177e4SLinus Torvalds 	volatile uint8_t __iomem *maddr;
1341da177e4SLinus Torvalds } bus_space_handle_t;
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds typedef struct bus_dma_segment
1371da177e4SLinus Torvalds {
1381da177e4SLinus Torvalds 	dma_addr_t	ds_addr;
1391da177e4SLinus Torvalds 	bus_size_t	ds_len;
1401da177e4SLinus Torvalds } bus_dma_segment_t;
1411da177e4SLinus Torvalds 
1421da177e4SLinus Torvalds struct ahd_linux_dma_tag
1431da177e4SLinus Torvalds {
1441da177e4SLinus Torvalds 	bus_size_t	alignment;
1451da177e4SLinus Torvalds 	bus_size_t	boundary;
1461da177e4SLinus Torvalds 	bus_size_t	maxsize;
1471da177e4SLinus Torvalds };
1481da177e4SLinus Torvalds typedef struct ahd_linux_dma_tag* bus_dma_tag_t;
1491da177e4SLinus Torvalds 
15073a25462SHannes Reinecke typedef dma_addr_t bus_dmamap_t;
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds typedef int bus_dma_filter_t(void*, dma_addr_t);
1531da177e4SLinus Torvalds typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
1541da177e4SLinus Torvalds 
1551da177e4SLinus Torvalds #define BUS_DMA_WAITOK		0x0
1561da177e4SLinus Torvalds #define BUS_DMA_NOWAIT		0x1
1571da177e4SLinus Torvalds #define BUS_DMA_ALLOCNOW	0x2
1581da177e4SLinus Torvalds #define BUS_DMA_LOAD_SEGS	0x4	/*
1591da177e4SLinus Torvalds 					 * Argument is an S/G list not
1601da177e4SLinus Torvalds 					 * a single buffer.
1611da177e4SLinus Torvalds 					 */
1621da177e4SLinus Torvalds 
1631da177e4SLinus Torvalds #define BUS_SPACE_MAXADDR	0xFFFFFFFF
1641da177e4SLinus Torvalds #define BUS_SPACE_MAXADDR_32BIT	0xFFFFFFFF
1651da177e4SLinus Torvalds #define BUS_SPACE_MAXSIZE_32BIT	0xFFFFFFFF
1661da177e4SLinus Torvalds 
1671da177e4SLinus Torvalds int	ahd_dma_tag_create(struct ahd_softc *, bus_dma_tag_t /*parent*/,
1681da177e4SLinus Torvalds 			   bus_size_t /*alignment*/, bus_size_t /*boundary*/,
1691da177e4SLinus Torvalds 			   dma_addr_t /*lowaddr*/, dma_addr_t /*highaddr*/,
1701da177e4SLinus Torvalds 			   bus_dma_filter_t*/*filter*/, void */*filterarg*/,
1711da177e4SLinus Torvalds 			   bus_size_t /*maxsize*/, int /*nsegments*/,
1721da177e4SLinus Torvalds 			   bus_size_t /*maxsegsz*/, int /*flags*/,
1731da177e4SLinus Torvalds 			   bus_dma_tag_t */*dma_tagp*/);
1741da177e4SLinus Torvalds 
1751da177e4SLinus Torvalds void	ahd_dma_tag_destroy(struct ahd_softc *, bus_dma_tag_t /*tag*/);
1761da177e4SLinus Torvalds 
1771da177e4SLinus Torvalds int	ahd_dmamem_alloc(struct ahd_softc *, bus_dma_tag_t /*dmat*/,
1781da177e4SLinus Torvalds 			 void** /*vaddr*/, int /*flags*/,
1791da177e4SLinus Torvalds 			 bus_dmamap_t* /*mapp*/);
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds void	ahd_dmamem_free(struct ahd_softc *, bus_dma_tag_t /*dmat*/,
1821da177e4SLinus Torvalds 			void* /*vaddr*/, bus_dmamap_t /*map*/);
1831da177e4SLinus Torvalds 
1841da177e4SLinus Torvalds void	ahd_dmamap_destroy(struct ahd_softc *, bus_dma_tag_t /*tag*/,
1851da177e4SLinus Torvalds 			   bus_dmamap_t /*map*/);
1861da177e4SLinus Torvalds 
1871da177e4SLinus Torvalds int	ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t /*dmat*/,
1881da177e4SLinus Torvalds 			bus_dmamap_t /*map*/, void * /*buf*/,
1891da177e4SLinus Torvalds 			bus_size_t /*buflen*/, bus_dmamap_callback_t *,
1901da177e4SLinus Torvalds 			void */*callback_arg*/, int /*flags*/);
1911da177e4SLinus Torvalds 
1921da177e4SLinus Torvalds int	ahd_dmamap_unload(struct ahd_softc *, bus_dma_tag_t, bus_dmamap_t);
1931da177e4SLinus Torvalds 
1941da177e4SLinus Torvalds /*
1951da177e4SLinus Torvalds  * Operations performed by ahd_dmamap_sync().
1961da177e4SLinus Torvalds  */
1971da177e4SLinus Torvalds #define BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
1981da177e4SLinus Torvalds #define BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
1991da177e4SLinus Torvalds #define BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
2001da177e4SLinus Torvalds #define BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds /*
2031da177e4SLinus Torvalds  * XXX
2041da177e4SLinus Torvalds  * ahd_dmamap_sync is only used on buffers allocated with
2051da177e4SLinus Torvalds  * the pci_alloc_consistent() API.  Although I'm not sure how
2061da177e4SLinus Torvalds  * this works on architectures with a write buffer, Linux does
2071da177e4SLinus Torvalds  * not have an API to sync "coherent" memory.  Perhaps we need
2081da177e4SLinus Torvalds  * to do an mb()?
2091da177e4SLinus Torvalds  */
2101da177e4SLinus Torvalds #define ahd_dmamap_sync(ahd, dma_tag, dmamap, offset, len, op)
2111da177e4SLinus Torvalds 
2121da177e4SLinus Torvalds /************************** Timer DataStructures ******************************/
2131da177e4SLinus Torvalds typedef struct timer_list ahd_timer_t;
2141da177e4SLinus Torvalds 
2151da177e4SLinus Torvalds /********************************** Includes **********************************/
2161da177e4SLinus Torvalds #ifdef CONFIG_AIC79XX_REG_PRETTY_PRINT
2171da177e4SLinus Torvalds #define AIC_DEBUG_REGISTERS 1
2181da177e4SLinus Torvalds #else
2191da177e4SLinus Torvalds #define AIC_DEBUG_REGISTERS 0
2201da177e4SLinus Torvalds #endif
2211da177e4SLinus Torvalds #include "aic79xx.h"
2221da177e4SLinus Torvalds 
2231da177e4SLinus Torvalds /***************************** Timer Facilities *******************************/
2241da177e4SLinus Torvalds #define ahd_timer_init init_timer
2251da177e4SLinus Torvalds #define ahd_timer_stop del_timer_sync
2261da177e4SLinus Torvalds typedef void ahd_linux_callback_t (u_long);
22773a25462SHannes Reinecke static __inline void ahd_timer_reset(ahd_timer_t *timer, int usec,
2281da177e4SLinus Torvalds 				     ahd_callback_t *func, void *arg);
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds static __inline void
23173a25462SHannes Reinecke ahd_timer_reset(ahd_timer_t *timer, int usec, ahd_callback_t *func, void *arg)
2321da177e4SLinus Torvalds {
2331da177e4SLinus Torvalds 	struct ahd_softc *ahd;
2341da177e4SLinus Torvalds 
2351da177e4SLinus Torvalds 	ahd = (struct ahd_softc *)arg;
2361da177e4SLinus Torvalds 	del_timer(timer);
2371da177e4SLinus Torvalds 	timer->data = (u_long)arg;
2381da177e4SLinus Torvalds 	timer->expires = jiffies + (usec * HZ)/1000000;
2391da177e4SLinus Torvalds 	timer->function = (ahd_linux_callback_t*)func;
2401da177e4SLinus Torvalds 	add_timer(timer);
2411da177e4SLinus Torvalds }
2421da177e4SLinus Torvalds 
2431da177e4SLinus Torvalds /***************************** SMP support ************************************/
2441da177e4SLinus Torvalds #include <linux/spinlock.h>
2451da177e4SLinus Torvalds 
246cd2f1e69SJames Bottomley #define AIC79XX_DRIVER_VERSION "3.0"
2471da177e4SLinus Torvalds 
2481da177e4SLinus Torvalds /*************************** Device Data Structures ***************************/
2491da177e4SLinus Torvalds /*
2501da177e4SLinus Torvalds  * A per probed device structure used to deal with some error recovery
2511da177e4SLinus Torvalds  * scenarios that the Linux mid-layer code just doesn't know how to
2521da177e4SLinus Torvalds  * handle.  The structure allocated for a device only becomes persistent
2531da177e4SLinus Torvalds  * after a successfully completed inquiry command to the target when
2541da177e4SLinus Torvalds  * that inquiry data indicates a lun is present.
2551da177e4SLinus Torvalds  */
25660a13213SHannes Reinecke 
2571da177e4SLinus Torvalds typedef enum {
2581da177e4SLinus Torvalds 	AHD_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
2591da177e4SLinus Torvalds 	AHD_DEV_Q_BASIC		 = 0x10, /* Allow basic device queuing */
2601da177e4SLinus Torvalds 	AHD_DEV_Q_TAGGED	 = 0x20, /* Allow full SCSI2 command queueing */
2611da177e4SLinus Torvalds 	AHD_DEV_PERIODIC_OTAG	 = 0x40, /* Send OTAG to prevent starvation */
2621da177e4SLinus Torvalds } ahd_linux_dev_flags;
2631da177e4SLinus Torvalds 
2641da177e4SLinus Torvalds struct ahd_linux_device {
2651da177e4SLinus Torvalds 	TAILQ_ENTRY(ahd_linux_device) links;
2661da177e4SLinus Torvalds 
2671da177e4SLinus Torvalds 	/*
2681da177e4SLinus Torvalds 	 * The number of transactions currently
2691da177e4SLinus Torvalds 	 * queued to the device.
2701da177e4SLinus Torvalds 	 */
2711da177e4SLinus Torvalds 	int			active;
2721da177e4SLinus Torvalds 
2731da177e4SLinus Torvalds 	/*
2741da177e4SLinus Torvalds 	 * The currently allowed number of
2751da177e4SLinus Torvalds 	 * transactions that can be queued to
2761da177e4SLinus Torvalds 	 * the device.  Must be signed for
2771da177e4SLinus Torvalds 	 * conversion from tagged to untagged
2781da177e4SLinus Torvalds 	 * mode where the device may have more
2791da177e4SLinus Torvalds 	 * than one outstanding active transaction.
2801da177e4SLinus Torvalds 	 */
2811da177e4SLinus Torvalds 	int			openings;
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds 	/*
2841da177e4SLinus Torvalds 	 * A positive count indicates that this
2851da177e4SLinus Torvalds 	 * device's queue is halted.
2861da177e4SLinus Torvalds 	 */
2871da177e4SLinus Torvalds 	u_int			qfrozen;
2881da177e4SLinus Torvalds 
2891da177e4SLinus Torvalds 	/*
2901da177e4SLinus Torvalds 	 * Cumulative command counter.
2911da177e4SLinus Torvalds 	 */
2921da177e4SLinus Torvalds 	u_long			commands_issued;
2931da177e4SLinus Torvalds 
2941da177e4SLinus Torvalds 	/*
2951da177e4SLinus Torvalds 	 * The number of tagged transactions when
2961da177e4SLinus Torvalds 	 * running at our current opening level
2971da177e4SLinus Torvalds 	 * that have been successfully received by
2981da177e4SLinus Torvalds 	 * this device since the last QUEUE FULL.
2991da177e4SLinus Torvalds 	 */
3001da177e4SLinus Torvalds 	u_int			tag_success_count;
3011da177e4SLinus Torvalds #define AHD_TAG_SUCCESS_INTERVAL 50
3021da177e4SLinus Torvalds 
3031da177e4SLinus Torvalds 	ahd_linux_dev_flags	flags;
3041da177e4SLinus Torvalds 
3051da177e4SLinus Torvalds 	/*
3061da177e4SLinus Torvalds 	 * Per device timer.
3071da177e4SLinus Torvalds 	 */
3081da177e4SLinus Torvalds 	struct timer_list	timer;
3091da177e4SLinus Torvalds 
3101da177e4SLinus Torvalds 	/*
3111da177e4SLinus Torvalds 	 * The high limit for the tags variable.
3121da177e4SLinus Torvalds 	 */
3131da177e4SLinus Torvalds 	u_int			maxtags;
3141da177e4SLinus Torvalds 
3151da177e4SLinus Torvalds 	/*
3161da177e4SLinus Torvalds 	 * The computed number of tags outstanding
3171da177e4SLinus Torvalds 	 * at the time of the last QUEUE FULL event.
3181da177e4SLinus Torvalds 	 */
3191da177e4SLinus Torvalds 	u_int			tags_on_last_queuefull;
3201da177e4SLinus Torvalds 
3211da177e4SLinus Torvalds 	/*
3221da177e4SLinus Torvalds 	 * How many times we have seen a queue full
3231da177e4SLinus Torvalds 	 * with the same number of tags.  This is used
3241da177e4SLinus Torvalds 	 * to stop our adaptive queue depth algorithm
3251da177e4SLinus Torvalds 	 * on devices with a fixed number of tags.
3261da177e4SLinus Torvalds 	 */
3271da177e4SLinus Torvalds 	u_int			last_queuefull_same_count;
3281da177e4SLinus Torvalds #define AHD_LOCK_TAGS_COUNT 50
3291da177e4SLinus Torvalds 
3301da177e4SLinus Torvalds 	/*
3311da177e4SLinus Torvalds 	 * How many transactions have been queued
3321da177e4SLinus Torvalds 	 * without the device going idle.  We use
3331da177e4SLinus Torvalds 	 * this statistic to determine when to issue
3341da177e4SLinus Torvalds 	 * an ordered tag to prevent transaction
3351da177e4SLinus Torvalds 	 * starvation.  This statistic is only updated
3361da177e4SLinus Torvalds 	 * if the AHD_DEV_PERIODIC_OTAG flag is set
3371da177e4SLinus Torvalds 	 * on this device.
3381da177e4SLinus Torvalds 	 */
3391da177e4SLinus Torvalds 	u_int			commands_since_idle_or_otag;
3401da177e4SLinus Torvalds #define AHD_OTAG_THRESH	500
3411da177e4SLinus Torvalds };
3421da177e4SLinus Torvalds 
3431da177e4SLinus Torvalds /********************* Definitions Required by the Core ***********************/
3441da177e4SLinus Torvalds /*
3451da177e4SLinus Torvalds  * Number of SG segments we require.  So long as the S/G segments for
3461da177e4SLinus Torvalds  * a particular transaction are allocated in a physically contiguous
3471da177e4SLinus Torvalds  * manner and are allocated below 4GB, the number of S/G segments is
3481da177e4SLinus Torvalds  * unrestricted.
3491da177e4SLinus Torvalds  */
3501da177e4SLinus Torvalds #define	AHD_NSEG 128
3511da177e4SLinus Torvalds 
3521da177e4SLinus Torvalds /*
3531da177e4SLinus Torvalds  * Per-SCB OSM storage.
3541da177e4SLinus Torvalds  */
3551da177e4SLinus Torvalds struct scb_platform_data {
3561da177e4SLinus Torvalds 	struct ahd_linux_device	*dev;
3571da177e4SLinus Torvalds 	dma_addr_t		 buf_busaddr;
3581da177e4SLinus Torvalds 	uint32_t		 xfer_len;
3591da177e4SLinus Torvalds 	uint32_t		 sense_resid;	/* Auto-Sense residual */
3601da177e4SLinus Torvalds };
3611da177e4SLinus Torvalds 
3621da177e4SLinus Torvalds /*
3631da177e4SLinus Torvalds  * Define a structure used for each host adapter.  All members are
3641da177e4SLinus Torvalds  * aligned on a boundary >= the size of the member to honor the
3651da177e4SLinus Torvalds  * alignment restrictions of the various platforms supported by
3661da177e4SLinus Torvalds  * this driver.
3671da177e4SLinus Torvalds  */
3681da177e4SLinus Torvalds struct ahd_platform_data {
3691da177e4SLinus Torvalds 	/*
3701da177e4SLinus Torvalds 	 * Fields accessed from interrupt context.
3711da177e4SLinus Torvalds 	 */
37273a25462SHannes Reinecke 	struct scsi_target *starget[AHD_NUM_TARGETS];
3731da177e4SLinus Torvalds 
3741da177e4SLinus Torvalds 	spinlock_t		 spin_lock;
3757b22da38SHannes Reinecke 	struct completion	*eh_done;
3761da177e4SLinus Torvalds 	struct Scsi_Host        *host;		/* pointer to scsi host */
3771da177e4SLinus Torvalds #define AHD_LINUX_NOIRQ	((uint32_t)~0)
3781da177e4SLinus Torvalds 	uint32_t		 irq;		/* IRQ for this adapter */
3791da177e4SLinus Torvalds 	uint32_t		 bios_address;
3801da177e4SLinus Torvalds 	uint32_t		 mem_busaddr;	/* Mem Base Addr */
3811da177e4SLinus Torvalds };
3821da177e4SLinus Torvalds 
3831da177e4SLinus Torvalds /************************** OS Utility Wrappers *******************************/
3841da177e4SLinus Torvalds #define printf printk
3851da177e4SLinus Torvalds #define M_NOWAIT GFP_ATOMIC
3861da177e4SLinus Torvalds #define M_WAITOK 0
3871da177e4SLinus Torvalds #define malloc(size, type, flags) kmalloc(size, flags)
3881da177e4SLinus Torvalds #define free(ptr, type) kfree(ptr)
3891da177e4SLinus Torvalds 
3901da177e4SLinus Torvalds static __inline void ahd_delay(long);
3911da177e4SLinus Torvalds static __inline void
3921da177e4SLinus Torvalds ahd_delay(long usec)
3931da177e4SLinus Torvalds {
3941da177e4SLinus Torvalds 	/*
3951da177e4SLinus Torvalds 	 * udelay on Linux can have problems for
3961da177e4SLinus Torvalds 	 * multi-millisecond waits.  Wait at most
3971da177e4SLinus Torvalds 	 * 1024us per call.
3981da177e4SLinus Torvalds 	 */
3991da177e4SLinus Torvalds 	while (usec > 0) {
4001da177e4SLinus Torvalds 		udelay(usec % 1024);
4011da177e4SLinus Torvalds 		usec -= 1024;
4021da177e4SLinus Torvalds 	}
4031da177e4SLinus Torvalds }
4041da177e4SLinus Torvalds 
4051da177e4SLinus Torvalds 
4061da177e4SLinus Torvalds /***************************** Low Level I/O **********************************/
4071da177e4SLinus Torvalds static __inline uint8_t ahd_inb(struct ahd_softc * ahd, long port);
4081da177e4SLinus Torvalds static __inline uint16_t ahd_inw_atomic(struct ahd_softc * ahd, long port);
4091da177e4SLinus Torvalds static __inline void ahd_outb(struct ahd_softc * ahd, long port, uint8_t val);
4101da177e4SLinus Torvalds static __inline void ahd_outw_atomic(struct ahd_softc * ahd,
4111da177e4SLinus Torvalds 				     long port, uint16_t val);
4121da177e4SLinus Torvalds static __inline void ahd_outsb(struct ahd_softc * ahd, long port,
4131da177e4SLinus Torvalds 			       uint8_t *, int count);
4141da177e4SLinus Torvalds static __inline void ahd_insb(struct ahd_softc * ahd, long port,
4151da177e4SLinus Torvalds 			       uint8_t *, int count);
4161da177e4SLinus Torvalds 
4171da177e4SLinus Torvalds static __inline uint8_t
4181da177e4SLinus Torvalds ahd_inb(struct ahd_softc * ahd, long port)
4191da177e4SLinus Torvalds {
4201da177e4SLinus Torvalds 	uint8_t x;
4211da177e4SLinus Torvalds 
4221da177e4SLinus Torvalds 	if (ahd->tags[0] == BUS_SPACE_MEMIO) {
4231da177e4SLinus Torvalds 		x = readb(ahd->bshs[0].maddr + port);
4241da177e4SLinus Torvalds 	} else {
4251da177e4SLinus Torvalds 		x = inb(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
4261da177e4SLinus Torvalds 	}
4271da177e4SLinus Torvalds 	mb();
4281da177e4SLinus Torvalds 	return (x);
4291da177e4SLinus Torvalds }
4301da177e4SLinus Torvalds 
4311da177e4SLinus Torvalds static __inline uint16_t
4321da177e4SLinus Torvalds ahd_inw_atomic(struct ahd_softc * ahd, long port)
4331da177e4SLinus Torvalds {
4341da177e4SLinus Torvalds 	uint8_t x;
4351da177e4SLinus Torvalds 
4361da177e4SLinus Torvalds 	if (ahd->tags[0] == BUS_SPACE_MEMIO) {
4371da177e4SLinus Torvalds 		x = readw(ahd->bshs[0].maddr + port);
4381da177e4SLinus Torvalds 	} else {
4391da177e4SLinus Torvalds 		x = inw(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
4401da177e4SLinus Torvalds 	}
4411da177e4SLinus Torvalds 	mb();
4421da177e4SLinus Torvalds 	return (x);
4431da177e4SLinus Torvalds }
4441da177e4SLinus Torvalds 
4451da177e4SLinus Torvalds static __inline void
4461da177e4SLinus Torvalds ahd_outb(struct ahd_softc * ahd, long port, uint8_t val)
4471da177e4SLinus Torvalds {
4481da177e4SLinus Torvalds 	if (ahd->tags[0] == BUS_SPACE_MEMIO) {
4491da177e4SLinus Torvalds 		writeb(val, ahd->bshs[0].maddr + port);
4501da177e4SLinus Torvalds 	} else {
4511da177e4SLinus Torvalds 		outb(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
4521da177e4SLinus Torvalds 	}
4531da177e4SLinus Torvalds 	mb();
4541da177e4SLinus Torvalds }
4551da177e4SLinus Torvalds 
4561da177e4SLinus Torvalds static __inline void
4571da177e4SLinus Torvalds ahd_outw_atomic(struct ahd_softc * ahd, long port, uint16_t val)
4581da177e4SLinus Torvalds {
4591da177e4SLinus Torvalds 	if (ahd->tags[0] == BUS_SPACE_MEMIO) {
4601da177e4SLinus Torvalds 		writew(val, ahd->bshs[0].maddr + port);
4611da177e4SLinus Torvalds 	} else {
4621da177e4SLinus Torvalds 		outw(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
4631da177e4SLinus Torvalds 	}
4641da177e4SLinus Torvalds 	mb();
4651da177e4SLinus Torvalds }
4661da177e4SLinus Torvalds 
4671da177e4SLinus Torvalds static __inline void
4681da177e4SLinus Torvalds ahd_outsb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
4691da177e4SLinus Torvalds {
4701da177e4SLinus Torvalds 	int i;
4711da177e4SLinus Torvalds 
4721da177e4SLinus Torvalds 	/*
4731da177e4SLinus Torvalds 	 * There is probably a more efficient way to do this on Linux
4741da177e4SLinus Torvalds 	 * but we don't use this for anything speed critical and this
4751da177e4SLinus Torvalds 	 * should work.
4761da177e4SLinus Torvalds 	 */
4771da177e4SLinus Torvalds 	for (i = 0; i < count; i++)
4781da177e4SLinus Torvalds 		ahd_outb(ahd, port, *array++);
4791da177e4SLinus Torvalds }
4801da177e4SLinus Torvalds 
4811da177e4SLinus Torvalds static __inline void
4821da177e4SLinus Torvalds ahd_insb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
4831da177e4SLinus Torvalds {
4841da177e4SLinus Torvalds 	int i;
4851da177e4SLinus Torvalds 
4861da177e4SLinus Torvalds 	/*
4871da177e4SLinus Torvalds 	 * There is probably a more efficient way to do this on Linux
4881da177e4SLinus Torvalds 	 * but we don't use this for anything speed critical and this
4891da177e4SLinus Torvalds 	 * should work.
4901da177e4SLinus Torvalds 	 */
4911da177e4SLinus Torvalds 	for (i = 0; i < count; i++)
4921da177e4SLinus Torvalds 		*array++ = ahd_inb(ahd, port);
4931da177e4SLinus Torvalds }
4941da177e4SLinus Torvalds 
4951da177e4SLinus Torvalds /**************************** Initialization **********************************/
4961da177e4SLinus Torvalds int		ahd_linux_register_host(struct ahd_softc *,
49773a25462SHannes Reinecke 					struct scsi_host_template *);
4981da177e4SLinus Torvalds 
4991da177e4SLinus Torvalds uint64_t	ahd_linux_get_memsize(void);
5001da177e4SLinus Torvalds 
5011da177e4SLinus Torvalds /*************************** Pretty Printing **********************************/
5021da177e4SLinus Torvalds struct info_str {
5031da177e4SLinus Torvalds 	char *buffer;
5041da177e4SLinus Torvalds 	int length;
5051da177e4SLinus Torvalds 	off_t offset;
5061da177e4SLinus Torvalds 	int pos;
5071da177e4SLinus Torvalds };
5081da177e4SLinus Torvalds 
5091da177e4SLinus Torvalds void	ahd_format_transinfo(struct info_str *info,
5101da177e4SLinus Torvalds 			     struct ahd_transinfo *tinfo);
5111da177e4SLinus Torvalds 
5121da177e4SLinus Torvalds /******************************** Locking *************************************/
5131da177e4SLinus Torvalds static __inline void
5141da177e4SLinus Torvalds ahd_lockinit(struct ahd_softc *ahd)
5151da177e4SLinus Torvalds {
5161da177e4SLinus Torvalds 	spin_lock_init(&ahd->platform_data->spin_lock);
5171da177e4SLinus Torvalds }
5181da177e4SLinus Torvalds 
5191da177e4SLinus Torvalds static __inline void
5201da177e4SLinus Torvalds ahd_lock(struct ahd_softc *ahd, unsigned long *flags)
5211da177e4SLinus Torvalds {
5221da177e4SLinus Torvalds 	spin_lock_irqsave(&ahd->platform_data->spin_lock, *flags);
5231da177e4SLinus Torvalds }
5241da177e4SLinus Torvalds 
5251da177e4SLinus Torvalds static __inline void
5261da177e4SLinus Torvalds ahd_unlock(struct ahd_softc *ahd, unsigned long *flags)
5271da177e4SLinus Torvalds {
5281da177e4SLinus Torvalds 	spin_unlock_irqrestore(&ahd->platform_data->spin_lock, *flags);
5291da177e4SLinus Torvalds }
5301da177e4SLinus Torvalds 
5311da177e4SLinus Torvalds /******************************* PCI Definitions ******************************/
5321da177e4SLinus Torvalds /*
5331da177e4SLinus Torvalds  * PCIM_xxx: mask to locate subfield in register
5341da177e4SLinus Torvalds  * PCIR_xxx: config register offset
5351da177e4SLinus Torvalds  * PCIC_xxx: device class
5361da177e4SLinus Torvalds  * PCIS_xxx: device subclass
5371da177e4SLinus Torvalds  * PCIP_xxx: device programming interface
5381da177e4SLinus Torvalds  * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
5391da177e4SLinus Torvalds  * PCID_xxx: device ID
5401da177e4SLinus Torvalds  */
5411da177e4SLinus Torvalds #define PCIR_DEVVENDOR		0x00
5421da177e4SLinus Torvalds #define PCIR_VENDOR		0x00
5431da177e4SLinus Torvalds #define PCIR_DEVICE		0x02
5441da177e4SLinus Torvalds #define PCIR_COMMAND		0x04
5451da177e4SLinus Torvalds #define PCIM_CMD_PORTEN		0x0001
5461da177e4SLinus Torvalds #define PCIM_CMD_MEMEN		0x0002
5471da177e4SLinus Torvalds #define PCIM_CMD_BUSMASTEREN	0x0004
5481da177e4SLinus Torvalds #define PCIM_CMD_MWRICEN	0x0010
5491da177e4SLinus Torvalds #define PCIM_CMD_PERRESPEN	0x0040
5501da177e4SLinus Torvalds #define	PCIM_CMD_SERRESPEN	0x0100
5511da177e4SLinus Torvalds #define PCIR_STATUS		0x06
5521da177e4SLinus Torvalds #define PCIR_REVID		0x08
5531da177e4SLinus Torvalds #define PCIR_PROGIF		0x09
5541da177e4SLinus Torvalds #define PCIR_SUBCLASS		0x0a
5551da177e4SLinus Torvalds #define PCIR_CLASS		0x0b
5561da177e4SLinus Torvalds #define PCIR_CACHELNSZ		0x0c
5571da177e4SLinus Torvalds #define PCIR_LATTIMER		0x0d
5581da177e4SLinus Torvalds #define PCIR_HEADERTYPE		0x0e
5591da177e4SLinus Torvalds #define PCIM_MFDEV		0x80
5601da177e4SLinus Torvalds #define PCIR_BIST		0x0f
5611da177e4SLinus Torvalds #define PCIR_CAP_PTR		0x34
5621da177e4SLinus Torvalds 
5631da177e4SLinus Torvalds /* config registers for header type 0 devices */
5641da177e4SLinus Torvalds #define PCIR_MAPS	0x10
5651da177e4SLinus Torvalds #define PCIR_SUBVEND_0	0x2c
5661da177e4SLinus Torvalds #define PCIR_SUBDEV_0	0x2e
5671da177e4SLinus Torvalds 
5681da177e4SLinus Torvalds /****************************** PCI-X definitions *****************************/
5691da177e4SLinus Torvalds #define PCIXR_COMMAND	0x96
5701da177e4SLinus Torvalds #define PCIXR_DEVADDR	0x98
5711da177e4SLinus Torvalds #define PCIXM_DEVADDR_FNUM	0x0003	/* Function Number */
5721da177e4SLinus Torvalds #define PCIXM_DEVADDR_DNUM	0x00F8	/* Device Number */
5731da177e4SLinus Torvalds #define PCIXM_DEVADDR_BNUM	0xFF00	/* Bus Number */
5741da177e4SLinus Torvalds #define PCIXR_STATUS	0x9A
5751da177e4SLinus Torvalds #define PCIXM_STATUS_64BIT	0x0001	/* Active 64bit connection to device. */
5761da177e4SLinus Torvalds #define PCIXM_STATUS_133CAP	0x0002	/* Device is 133MHz capable */
5771da177e4SLinus Torvalds #define PCIXM_STATUS_SCDISC	0x0004	/* Split Completion Discarded */
5781da177e4SLinus Torvalds #define PCIXM_STATUS_UNEXPSC	0x0008	/* Unexpected Split Completion */
5791da177e4SLinus Torvalds #define PCIXM_STATUS_CMPLEXDEV	0x0010	/* Device Complexity (set == bridge) */
5801da177e4SLinus Torvalds #define PCIXM_STATUS_MAXMRDBC	0x0060	/* Maximum Burst Read Count */
5811da177e4SLinus Torvalds #define PCIXM_STATUS_MAXSPLITS	0x0380	/* Maximum Split Transactions */
5821da177e4SLinus Torvalds #define PCIXM_STATUS_MAXCRDS	0x1C00	/* Maximum Cumulative Read Size */
5831da177e4SLinus Torvalds #define PCIXM_STATUS_RCVDSCEM	0x2000	/* Received a Split Comp w/Error msg */
5841da177e4SLinus Torvalds 
5851da177e4SLinus Torvalds extern struct pci_driver aic79xx_pci_driver;
5861da177e4SLinus Torvalds 
5871da177e4SLinus Torvalds typedef enum
5881da177e4SLinus Torvalds {
5891da177e4SLinus Torvalds 	AHD_POWER_STATE_D0,
5901da177e4SLinus Torvalds 	AHD_POWER_STATE_D1,
5911da177e4SLinus Torvalds 	AHD_POWER_STATE_D2,
5921da177e4SLinus Torvalds 	AHD_POWER_STATE_D3
5931da177e4SLinus Torvalds } ahd_power_state;
5941da177e4SLinus Torvalds 
5951da177e4SLinus Torvalds void ahd_power_state_change(struct ahd_softc *ahd,
5961da177e4SLinus Torvalds 			    ahd_power_state new_state);
5971da177e4SLinus Torvalds 
5981da177e4SLinus Torvalds /******************************* PCI Routines *********************************/
5991da177e4SLinus Torvalds int			 ahd_linux_pci_init(void);
6001da177e4SLinus Torvalds void			 ahd_linux_pci_exit(void);
6011da177e4SLinus Torvalds int			 ahd_pci_map_registers(struct ahd_softc *ahd);
6021da177e4SLinus Torvalds int			 ahd_pci_map_int(struct ahd_softc *ahd);
6031da177e4SLinus Torvalds 
6041da177e4SLinus Torvalds static __inline uint32_t ahd_pci_read_config(ahd_dev_softc_t pci,
6051da177e4SLinus Torvalds 					     int reg, int width);
6061da177e4SLinus Torvalds 
6071da177e4SLinus Torvalds static __inline uint32_t
6081da177e4SLinus Torvalds ahd_pci_read_config(ahd_dev_softc_t pci, int reg, int width)
6091da177e4SLinus Torvalds {
6101da177e4SLinus Torvalds 	switch (width) {
6111da177e4SLinus Torvalds 	case 1:
6121da177e4SLinus Torvalds 	{
6131da177e4SLinus Torvalds 		uint8_t retval;
6141da177e4SLinus Torvalds 
6151da177e4SLinus Torvalds 		pci_read_config_byte(pci, reg, &retval);
6161da177e4SLinus Torvalds 		return (retval);
6171da177e4SLinus Torvalds 	}
6181da177e4SLinus Torvalds 	case 2:
6191da177e4SLinus Torvalds 	{
6201da177e4SLinus Torvalds 		uint16_t retval;
6211da177e4SLinus Torvalds 		pci_read_config_word(pci, reg, &retval);
6221da177e4SLinus Torvalds 		return (retval);
6231da177e4SLinus Torvalds 	}
6241da177e4SLinus Torvalds 	case 4:
6251da177e4SLinus Torvalds 	{
6261da177e4SLinus Torvalds 		uint32_t retval;
6271da177e4SLinus Torvalds 		pci_read_config_dword(pci, reg, &retval);
6281da177e4SLinus Torvalds 		return (retval);
6291da177e4SLinus Torvalds 	}
6301da177e4SLinus Torvalds 	default:
6311da177e4SLinus Torvalds 		panic("ahd_pci_read_config: Read size too big");
6321da177e4SLinus Torvalds 		/* NOTREACHED */
6331da177e4SLinus Torvalds 		return (0);
6341da177e4SLinus Torvalds 	}
6351da177e4SLinus Torvalds }
6361da177e4SLinus Torvalds 
6371da177e4SLinus Torvalds static __inline void ahd_pci_write_config(ahd_dev_softc_t pci,
6381da177e4SLinus Torvalds 					  int reg, uint32_t value,
6391da177e4SLinus Torvalds 					  int width);
6401da177e4SLinus Torvalds 
6411da177e4SLinus Torvalds static __inline void
6421da177e4SLinus Torvalds ahd_pci_write_config(ahd_dev_softc_t pci, int reg, uint32_t value, int width)
6431da177e4SLinus Torvalds {
6441da177e4SLinus Torvalds 	switch (width) {
6451da177e4SLinus Torvalds 	case 1:
6461da177e4SLinus Torvalds 		pci_write_config_byte(pci, reg, value);
6471da177e4SLinus Torvalds 		break;
6481da177e4SLinus Torvalds 	case 2:
6491da177e4SLinus Torvalds 		pci_write_config_word(pci, reg, value);
6501da177e4SLinus Torvalds 		break;
6511da177e4SLinus Torvalds 	case 4:
6521da177e4SLinus Torvalds 		pci_write_config_dword(pci, reg, value);
6531da177e4SLinus Torvalds 		break;
6541da177e4SLinus Torvalds 	default:
6551da177e4SLinus Torvalds 		panic("ahd_pci_write_config: Write size too big");
6561da177e4SLinus Torvalds 		/* NOTREACHED */
6571da177e4SLinus Torvalds 	}
6581da177e4SLinus Torvalds }
6591da177e4SLinus Torvalds 
6601da177e4SLinus Torvalds static __inline int ahd_get_pci_function(ahd_dev_softc_t);
6611da177e4SLinus Torvalds static __inline int
6621da177e4SLinus Torvalds ahd_get_pci_function(ahd_dev_softc_t pci)
6631da177e4SLinus Torvalds {
6641da177e4SLinus Torvalds 	return (PCI_FUNC(pci->devfn));
6651da177e4SLinus Torvalds }
6661da177e4SLinus Torvalds 
6671da177e4SLinus Torvalds static __inline int ahd_get_pci_slot(ahd_dev_softc_t);
6681da177e4SLinus Torvalds static __inline int
6691da177e4SLinus Torvalds ahd_get_pci_slot(ahd_dev_softc_t pci)
6701da177e4SLinus Torvalds {
6711da177e4SLinus Torvalds 	return (PCI_SLOT(pci->devfn));
6721da177e4SLinus Torvalds }
6731da177e4SLinus Torvalds 
6741da177e4SLinus Torvalds static __inline int ahd_get_pci_bus(ahd_dev_softc_t);
6751da177e4SLinus Torvalds static __inline int
6761da177e4SLinus Torvalds ahd_get_pci_bus(ahd_dev_softc_t pci)
6771da177e4SLinus Torvalds {
6781da177e4SLinus Torvalds 	return (pci->bus->number);
6791da177e4SLinus Torvalds }
6801da177e4SLinus Torvalds 
6811da177e4SLinus Torvalds static __inline void ahd_flush_device_writes(struct ahd_softc *);
6821da177e4SLinus Torvalds static __inline void
6831da177e4SLinus Torvalds ahd_flush_device_writes(struct ahd_softc *ahd)
6841da177e4SLinus Torvalds {
6851da177e4SLinus Torvalds 	/* XXX Is this sufficient for all architectures??? */
6861da177e4SLinus Torvalds 	ahd_inb(ahd, INTSTAT);
6871da177e4SLinus Torvalds }
6881da177e4SLinus Torvalds 
6891da177e4SLinus Torvalds /**************************** Proc FS Support *********************************/
6901da177e4SLinus Torvalds int	ahd_linux_proc_info(struct Scsi_Host *, char *, char **,
6911da177e4SLinus Torvalds 			    off_t, int, int);
6921da177e4SLinus Torvalds 
6931da177e4SLinus Torvalds /*********************** Transaction Access Wrappers **************************/
69473a25462SHannes Reinecke static __inline void ahd_cmd_set_transaction_status(struct scsi_cmnd *, uint32_t);
6951da177e4SLinus Torvalds static __inline void ahd_set_transaction_status(struct scb *, uint32_t);
69673a25462SHannes Reinecke static __inline void ahd_cmd_set_scsi_status(struct scsi_cmnd *, uint32_t);
6971da177e4SLinus Torvalds static __inline void ahd_set_scsi_status(struct scb *, uint32_t);
69873a25462SHannes Reinecke static __inline uint32_t ahd_cmd_get_transaction_status(struct scsi_cmnd *cmd);
6991da177e4SLinus Torvalds static __inline uint32_t ahd_get_transaction_status(struct scb *);
70073a25462SHannes Reinecke static __inline uint32_t ahd_cmd_get_scsi_status(struct scsi_cmnd *cmd);
7011da177e4SLinus Torvalds static __inline uint32_t ahd_get_scsi_status(struct scb *);
7021da177e4SLinus Torvalds static __inline void ahd_set_transaction_tag(struct scb *, int, u_int);
7031da177e4SLinus Torvalds static __inline u_long ahd_get_transfer_length(struct scb *);
7041da177e4SLinus Torvalds static __inline int ahd_get_transfer_dir(struct scb *);
7051da177e4SLinus Torvalds static __inline void ahd_set_residual(struct scb *, u_long);
7061da177e4SLinus Torvalds static __inline void ahd_set_sense_residual(struct scb *scb, u_long resid);
7071da177e4SLinus Torvalds static __inline u_long ahd_get_residual(struct scb *);
7081da177e4SLinus Torvalds static __inline u_long ahd_get_sense_residual(struct scb *);
7091da177e4SLinus Torvalds static __inline int ahd_perform_autosense(struct scb *);
7101da177e4SLinus Torvalds static __inline uint32_t ahd_get_sense_bufsize(struct ahd_softc *,
7111da177e4SLinus Torvalds 					       struct scb *);
7121da177e4SLinus Torvalds static __inline void ahd_notify_xfer_settings_change(struct ahd_softc *,
7131da177e4SLinus Torvalds 						     struct ahd_devinfo *);
7141da177e4SLinus Torvalds static __inline void ahd_platform_scb_free(struct ahd_softc *ahd,
7151da177e4SLinus Torvalds 					   struct scb *scb);
7161da177e4SLinus Torvalds static __inline void ahd_freeze_scb(struct scb *scb);
7171da177e4SLinus Torvalds 
7181da177e4SLinus Torvalds static __inline
71973a25462SHannes Reinecke void ahd_cmd_set_transaction_status(struct scsi_cmnd *cmd, uint32_t status)
7201da177e4SLinus Torvalds {
7211da177e4SLinus Torvalds 	cmd->result &= ~(CAM_STATUS_MASK << 16);
7221da177e4SLinus Torvalds 	cmd->result |= status << 16;
7231da177e4SLinus Torvalds }
7241da177e4SLinus Torvalds 
7251da177e4SLinus Torvalds static __inline
7261da177e4SLinus Torvalds void ahd_set_transaction_status(struct scb *scb, uint32_t status)
7271da177e4SLinus Torvalds {
7281da177e4SLinus Torvalds 	ahd_cmd_set_transaction_status(scb->io_ctx,status);
7291da177e4SLinus Torvalds }
7301da177e4SLinus Torvalds 
7311da177e4SLinus Torvalds static __inline
73273a25462SHannes Reinecke void ahd_cmd_set_scsi_status(struct scsi_cmnd *cmd, uint32_t status)
7331da177e4SLinus Torvalds {
7341da177e4SLinus Torvalds 	cmd->result &= ~0xFFFF;
7351da177e4SLinus Torvalds 	cmd->result |= status;
7361da177e4SLinus Torvalds }
7371da177e4SLinus Torvalds 
7381da177e4SLinus Torvalds static __inline
7391da177e4SLinus Torvalds void ahd_set_scsi_status(struct scb *scb, uint32_t status)
7401da177e4SLinus Torvalds {
7411da177e4SLinus Torvalds 	ahd_cmd_set_scsi_status(scb->io_ctx, status);
7421da177e4SLinus Torvalds }
7431da177e4SLinus Torvalds 
7441da177e4SLinus Torvalds static __inline
74573a25462SHannes Reinecke uint32_t ahd_cmd_get_transaction_status(struct scsi_cmnd *cmd)
7461da177e4SLinus Torvalds {
7471da177e4SLinus Torvalds 	return ((cmd->result >> 16) & CAM_STATUS_MASK);
7481da177e4SLinus Torvalds }
7491da177e4SLinus Torvalds 
7501da177e4SLinus Torvalds static __inline
7511da177e4SLinus Torvalds uint32_t ahd_get_transaction_status(struct scb *scb)
7521da177e4SLinus Torvalds {
7531da177e4SLinus Torvalds 	return (ahd_cmd_get_transaction_status(scb->io_ctx));
7541da177e4SLinus Torvalds }
7551da177e4SLinus Torvalds 
7561da177e4SLinus Torvalds static __inline
75773a25462SHannes Reinecke uint32_t ahd_cmd_get_scsi_status(struct scsi_cmnd *cmd)
7581da177e4SLinus Torvalds {
7591da177e4SLinus Torvalds 	return (cmd->result & 0xFFFF);
7601da177e4SLinus Torvalds }
7611da177e4SLinus Torvalds 
7621da177e4SLinus Torvalds static __inline
7631da177e4SLinus Torvalds uint32_t ahd_get_scsi_status(struct scb *scb)
7641da177e4SLinus Torvalds {
7651da177e4SLinus Torvalds 	return (ahd_cmd_get_scsi_status(scb->io_ctx));
7661da177e4SLinus Torvalds }
7671da177e4SLinus Torvalds 
7681da177e4SLinus Torvalds static __inline
7691da177e4SLinus Torvalds void ahd_set_transaction_tag(struct scb *scb, int enabled, u_int type)
7701da177e4SLinus Torvalds {
7711da177e4SLinus Torvalds 	/*
7721da177e4SLinus Torvalds 	 * Nothing to do for linux as the incoming transaction
7731da177e4SLinus Torvalds 	 * has no concept of tag/non tagged, etc.
7741da177e4SLinus Torvalds 	 */
7751da177e4SLinus Torvalds }
7761da177e4SLinus Torvalds 
7771da177e4SLinus Torvalds static __inline
7781da177e4SLinus Torvalds u_long ahd_get_transfer_length(struct scb *scb)
7791da177e4SLinus Torvalds {
7801da177e4SLinus Torvalds 	return (scb->platform_data->xfer_len);
7811da177e4SLinus Torvalds }
7821da177e4SLinus Torvalds 
7831da177e4SLinus Torvalds static __inline
7841da177e4SLinus Torvalds int ahd_get_transfer_dir(struct scb *scb)
7851da177e4SLinus Torvalds {
7861da177e4SLinus Torvalds 	return (scb->io_ctx->sc_data_direction);
7871da177e4SLinus Torvalds }
7881da177e4SLinus Torvalds 
7891da177e4SLinus Torvalds static __inline
7901da177e4SLinus Torvalds void ahd_set_residual(struct scb *scb, u_long resid)
7911da177e4SLinus Torvalds {
7921da177e4SLinus Torvalds 	scb->io_ctx->resid = resid;
7931da177e4SLinus Torvalds }
7941da177e4SLinus Torvalds 
7951da177e4SLinus Torvalds static __inline
7961da177e4SLinus Torvalds void ahd_set_sense_residual(struct scb *scb, u_long resid)
7971da177e4SLinus Torvalds {
7981da177e4SLinus Torvalds 	scb->platform_data->sense_resid = resid;
7991da177e4SLinus Torvalds }
8001da177e4SLinus Torvalds 
8011da177e4SLinus Torvalds static __inline
8021da177e4SLinus Torvalds u_long ahd_get_residual(struct scb *scb)
8031da177e4SLinus Torvalds {
8041da177e4SLinus Torvalds 	return (scb->io_ctx->resid);
8051da177e4SLinus Torvalds }
8061da177e4SLinus Torvalds 
8071da177e4SLinus Torvalds static __inline
8081da177e4SLinus Torvalds u_long ahd_get_sense_residual(struct scb *scb)
8091da177e4SLinus Torvalds {
8101da177e4SLinus Torvalds 	return (scb->platform_data->sense_resid);
8111da177e4SLinus Torvalds }
8121da177e4SLinus Torvalds 
8131da177e4SLinus Torvalds static __inline
8141da177e4SLinus Torvalds int ahd_perform_autosense(struct scb *scb)
8151da177e4SLinus Torvalds {
8161da177e4SLinus Torvalds 	/*
8171da177e4SLinus Torvalds 	 * We always perform autosense in Linux.
8181da177e4SLinus Torvalds 	 * On other platforms this is set on a
8191da177e4SLinus Torvalds 	 * per-transaction basis.
8201da177e4SLinus Torvalds 	 */
8211da177e4SLinus Torvalds 	return (1);
8221da177e4SLinus Torvalds }
8231da177e4SLinus Torvalds 
8241da177e4SLinus Torvalds static __inline uint32_t
8251da177e4SLinus Torvalds ahd_get_sense_bufsize(struct ahd_softc *ahd, struct scb *scb)
8261da177e4SLinus Torvalds {
8271da177e4SLinus Torvalds 	return (sizeof(struct scsi_sense_data));
8281da177e4SLinus Torvalds }
8291da177e4SLinus Torvalds 
8301da177e4SLinus Torvalds static __inline void
8311da177e4SLinus Torvalds ahd_notify_xfer_settings_change(struct ahd_softc *ahd,
8321da177e4SLinus Torvalds 				struct ahd_devinfo *devinfo)
8331da177e4SLinus Torvalds {
8341da177e4SLinus Torvalds 	/* Nothing to do here for linux */
8351da177e4SLinus Torvalds }
8361da177e4SLinus Torvalds 
8371da177e4SLinus Torvalds static __inline void
8381da177e4SLinus Torvalds ahd_platform_scb_free(struct ahd_softc *ahd, struct scb *scb)
8391da177e4SLinus Torvalds {
8401da177e4SLinus Torvalds 	ahd->flags &= ~AHD_RESOURCE_SHORTAGE;
8411da177e4SLinus Torvalds }
8421da177e4SLinus Torvalds 
8431da177e4SLinus Torvalds int	ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
8441da177e4SLinus Torvalds void	ahd_platform_free(struct ahd_softc *ahd);
8451da177e4SLinus Torvalds void	ahd_platform_init(struct ahd_softc *ahd);
8461da177e4SLinus Torvalds void	ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb);
8471da177e4SLinus Torvalds void	ahd_freeze_simq(struct ahd_softc *ahd);
8481da177e4SLinus Torvalds void	ahd_release_simq(struct ahd_softc *ahd);
8491da177e4SLinus Torvalds 
8501da177e4SLinus Torvalds static __inline void
8511da177e4SLinus Torvalds ahd_freeze_scb(struct scb *scb)
8521da177e4SLinus Torvalds {
8531da177e4SLinus Torvalds 	if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
8541da177e4SLinus Torvalds                 scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
8551da177e4SLinus Torvalds                 scb->platform_data->dev->qfrozen++;
8561da177e4SLinus Torvalds         }
8571da177e4SLinus Torvalds }
8581da177e4SLinus Torvalds 
859f89d0a4eSHannes Reinecke void	ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
8601da177e4SLinus Torvalds 			      struct ahd_devinfo *devinfo, ahd_queue_alg);
8611da177e4SLinus Torvalds int	ahd_platform_abort_scbs(struct ahd_softc *ahd, int target,
8621da177e4SLinus Torvalds 				char channel, int lun, u_int tag,
8631da177e4SLinus Torvalds 				role_t role, uint32_t status);
8641da177e4SLinus Torvalds irqreturn_t
865*7d12e780SDavid Howells 	ahd_linux_isr(int irq, void *dev_id);
8661da177e4SLinus Torvalds void	ahd_done(struct ahd_softc*, struct scb*);
8671da177e4SLinus Torvalds void	ahd_send_async(struct ahd_softc *, char channel,
868f89d0a4eSHannes Reinecke 		       u_int target, u_int lun, ac_code);
8691da177e4SLinus Torvalds void	ahd_print_path(struct ahd_softc *, struct scb *);
8701da177e4SLinus Torvalds 
8711da177e4SLinus Torvalds #ifdef CONFIG_PCI
8721da177e4SLinus Torvalds #define AHD_PCI_CONFIG 1
8731da177e4SLinus Torvalds #else
8741da177e4SLinus Torvalds #define AHD_PCI_CONFIG 0
8751da177e4SLinus Torvalds #endif
8761da177e4SLinus Torvalds #define bootverbose aic79xx_verbose
8771da177e4SLinus Torvalds extern uint32_t aic79xx_verbose;
8781da177e4SLinus Torvalds 
8791da177e4SLinus Torvalds #endif /* _AIC79XX_LINUX_H_ */
880