18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Adaptec AIC79xx device driver for Linux.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (c) 2000-2001 Adaptec Inc.
58c2ecf20Sopenharmony_ci * All rights reserved.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
88c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
98c2ecf20Sopenharmony_ci * are met:
108c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
118c2ecf20Sopenharmony_ci *    notice, this list of conditions, and the following disclaimer,
128c2ecf20Sopenharmony_ci *    without modification.
138c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer
148c2ecf20Sopenharmony_ci *    substantially similar to the "NO WARRANTY" disclaimer below
158c2ecf20Sopenharmony_ci *    ("Disclaimer") and any redistribution must be conditioned upon
168c2ecf20Sopenharmony_ci *    including a substantially similar Disclaimer requirement for further
178c2ecf20Sopenharmony_ci *    binary redistribution.
188c2ecf20Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names
198c2ecf20Sopenharmony_ci *    of any contributors may be used to endorse or promote products derived
208c2ecf20Sopenharmony_ci *    from this software without specific prior written permission.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
238c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
248c2ecf20Sopenharmony_ci * Software Foundation.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci * NO WARRANTY
278c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
288c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
298c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
308c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
318c2ecf20Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
328c2ecf20Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
338c2ecf20Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
348c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
358c2ecf20Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
368c2ecf20Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
378c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES.
388c2ecf20Sopenharmony_ci *
398c2ecf20Sopenharmony_ci * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm.h#166 $
408c2ecf20Sopenharmony_ci *
418c2ecf20Sopenharmony_ci */
428c2ecf20Sopenharmony_ci#ifndef _AIC79XX_LINUX_H_
438c2ecf20Sopenharmony_ci#define _AIC79XX_LINUX_H_
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#include <linux/types.h>
468c2ecf20Sopenharmony_ci#include <linux/blkdev.h>
478c2ecf20Sopenharmony_ci#include <linux/delay.h>
488c2ecf20Sopenharmony_ci#include <linux/ioport.h>
498c2ecf20Sopenharmony_ci#include <linux/pci.h>
508c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
518c2ecf20Sopenharmony_ci#include <linux/module.h>
528c2ecf20Sopenharmony_ci#include <linux/slab.h>
538c2ecf20Sopenharmony_ci#include <asm/byteorder.h>
548c2ecf20Sopenharmony_ci#include <asm/io.h>
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#include <scsi/scsi.h>
578c2ecf20Sopenharmony_ci#include <scsi/scsi_cmnd.h>
588c2ecf20Sopenharmony_ci#include <scsi/scsi_eh.h>
598c2ecf20Sopenharmony_ci#include <scsi/scsi_device.h>
608c2ecf20Sopenharmony_ci#include <scsi/scsi_host.h>
618c2ecf20Sopenharmony_ci#include <scsi/scsi_tcq.h>
628c2ecf20Sopenharmony_ci#include <scsi/scsi_transport.h>
638c2ecf20Sopenharmony_ci#include <scsi/scsi_transport_spi.h>
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* Core SCSI definitions */
668c2ecf20Sopenharmony_ci#define AIC_LIB_PREFIX ahd
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#include "cam.h"
698c2ecf20Sopenharmony_ci#include "queue.h"
708c2ecf20Sopenharmony_ci#include "scsi_message.h"
718c2ecf20Sopenharmony_ci#include "scsi_iu.h"
728c2ecf20Sopenharmony_ci#include "aiclib.h"
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/*********************************** Debugging ********************************/
758c2ecf20Sopenharmony_ci#ifdef CONFIG_AIC79XX_DEBUG_ENABLE
768c2ecf20Sopenharmony_ci#ifdef CONFIG_AIC79XX_DEBUG_MASK
778c2ecf20Sopenharmony_ci#define AHD_DEBUG 1
788c2ecf20Sopenharmony_ci#define AHD_DEBUG_OPTS CONFIG_AIC79XX_DEBUG_MASK
798c2ecf20Sopenharmony_ci#else
808c2ecf20Sopenharmony_ci/*
818c2ecf20Sopenharmony_ci * Compile in debugging code, but do not enable any printfs.
828c2ecf20Sopenharmony_ci */
838c2ecf20Sopenharmony_ci#define AHD_DEBUG 1
848c2ecf20Sopenharmony_ci#define AHD_DEBUG_OPTS 0
858c2ecf20Sopenharmony_ci#endif
868c2ecf20Sopenharmony_ci/* No debugging code. */
878c2ecf20Sopenharmony_ci#endif
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/********************************** Misc Macros *******************************/
908c2ecf20Sopenharmony_ci#define	powerof2(x)	((((x)-1)&(x))==0)
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/************************* Forward Declarations *******************************/
938c2ecf20Sopenharmony_cistruct ahd_softc;
948c2ecf20Sopenharmony_citypedef struct pci_dev *ahd_dev_softc_t;
958c2ecf20Sopenharmony_citypedef struct scsi_cmnd      *ahd_io_ctx_t;
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/******************************* Byte Order ***********************************/
988c2ecf20Sopenharmony_ci#define ahd_htobe16(x)	cpu_to_be16(x)
998c2ecf20Sopenharmony_ci#define ahd_htobe32(x)	cpu_to_be32(x)
1008c2ecf20Sopenharmony_ci#define ahd_htobe64(x)	cpu_to_be64(x)
1018c2ecf20Sopenharmony_ci#define ahd_htole16(x)	cpu_to_le16(x)
1028c2ecf20Sopenharmony_ci#define ahd_htole32(x)	cpu_to_le32(x)
1038c2ecf20Sopenharmony_ci#define ahd_htole64(x)	cpu_to_le64(x)
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#define ahd_be16toh(x)	be16_to_cpu(x)
1068c2ecf20Sopenharmony_ci#define ahd_be32toh(x)	be32_to_cpu(x)
1078c2ecf20Sopenharmony_ci#define ahd_be64toh(x)	be64_to_cpu(x)
1088c2ecf20Sopenharmony_ci#define ahd_le16toh(x)	le16_to_cpu(x)
1098c2ecf20Sopenharmony_ci#define ahd_le32toh(x)	le32_to_cpu(x)
1108c2ecf20Sopenharmony_ci#define ahd_le64toh(x)	le64_to_cpu(x)
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/************************* Configuration Data *********************************/
1138c2ecf20Sopenharmony_ciextern uint32_t aic79xx_allow_memio;
1148c2ecf20Sopenharmony_ciextern struct scsi_host_template aic79xx_driver_template;
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/***************************** Bus Space/DMA **********************************/
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_citypedef uint32_t bus_size_t;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_citypedef enum {
1218c2ecf20Sopenharmony_ci	BUS_SPACE_MEMIO,
1228c2ecf20Sopenharmony_ci	BUS_SPACE_PIO
1238c2ecf20Sopenharmony_ci} bus_space_tag_t;
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_citypedef union {
1268c2ecf20Sopenharmony_ci	u_long		  ioport;
1278c2ecf20Sopenharmony_ci	volatile uint8_t __iomem *maddr;
1288c2ecf20Sopenharmony_ci} bus_space_handle_t;
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_citypedef struct bus_dma_segment
1318c2ecf20Sopenharmony_ci{
1328c2ecf20Sopenharmony_ci	dma_addr_t	ds_addr;
1338c2ecf20Sopenharmony_ci	bus_size_t	ds_len;
1348c2ecf20Sopenharmony_ci} bus_dma_segment_t;
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_cistruct ahd_linux_dma_tag
1378c2ecf20Sopenharmony_ci{
1388c2ecf20Sopenharmony_ci	bus_size_t	alignment;
1398c2ecf20Sopenharmony_ci	bus_size_t	boundary;
1408c2ecf20Sopenharmony_ci	bus_size_t	maxsize;
1418c2ecf20Sopenharmony_ci};
1428c2ecf20Sopenharmony_citypedef struct ahd_linux_dma_tag* bus_dma_tag_t;
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_citypedef dma_addr_t bus_dmamap_t;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_citypedef int bus_dma_filter_t(void*, dma_addr_t);
1478c2ecf20Sopenharmony_citypedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci#define BUS_DMA_WAITOK		0x0
1508c2ecf20Sopenharmony_ci#define BUS_DMA_NOWAIT		0x1
1518c2ecf20Sopenharmony_ci#define BUS_DMA_ALLOCNOW	0x2
1528c2ecf20Sopenharmony_ci#define BUS_DMA_LOAD_SEGS	0x4	/*
1538c2ecf20Sopenharmony_ci					 * Argument is an S/G list not
1548c2ecf20Sopenharmony_ci					 * a single buffer.
1558c2ecf20Sopenharmony_ci					 */
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci#define BUS_SPACE_MAXADDR	0xFFFFFFFF
1588c2ecf20Sopenharmony_ci#define BUS_SPACE_MAXADDR_32BIT	0xFFFFFFFF
1598c2ecf20Sopenharmony_ci#define BUS_SPACE_MAXSIZE_32BIT	0xFFFFFFFF
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ciint	ahd_dma_tag_create(struct ahd_softc *, bus_dma_tag_t /*parent*/,
1628c2ecf20Sopenharmony_ci			   bus_size_t /*alignment*/, bus_size_t /*boundary*/,
1638c2ecf20Sopenharmony_ci			   dma_addr_t /*lowaddr*/, dma_addr_t /*highaddr*/,
1648c2ecf20Sopenharmony_ci			   bus_dma_filter_t*/*filter*/, void */*filterarg*/,
1658c2ecf20Sopenharmony_ci			   bus_size_t /*maxsize*/, int /*nsegments*/,
1668c2ecf20Sopenharmony_ci			   bus_size_t /*maxsegsz*/, int /*flags*/,
1678c2ecf20Sopenharmony_ci			   bus_dma_tag_t */*dma_tagp*/);
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_civoid	ahd_dma_tag_destroy(struct ahd_softc *, bus_dma_tag_t /*tag*/);
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ciint	ahd_dmamem_alloc(struct ahd_softc *, bus_dma_tag_t /*dmat*/,
1728c2ecf20Sopenharmony_ci			 void** /*vaddr*/, int /*flags*/,
1738c2ecf20Sopenharmony_ci			 bus_dmamap_t* /*mapp*/);
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_civoid	ahd_dmamem_free(struct ahd_softc *, bus_dma_tag_t /*dmat*/,
1768c2ecf20Sopenharmony_ci			void* /*vaddr*/, bus_dmamap_t /*map*/);
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_civoid	ahd_dmamap_destroy(struct ahd_softc *, bus_dma_tag_t /*tag*/,
1798c2ecf20Sopenharmony_ci			   bus_dmamap_t /*map*/);
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ciint	ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t /*dmat*/,
1828c2ecf20Sopenharmony_ci			bus_dmamap_t /*map*/, void * /*buf*/,
1838c2ecf20Sopenharmony_ci			bus_size_t /*buflen*/, bus_dmamap_callback_t *,
1848c2ecf20Sopenharmony_ci			void */*callback_arg*/, int /*flags*/);
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ciint	ahd_dmamap_unload(struct ahd_softc *, bus_dma_tag_t, bus_dmamap_t);
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/*
1898c2ecf20Sopenharmony_ci * Operations performed by ahd_dmamap_sync().
1908c2ecf20Sopenharmony_ci */
1918c2ecf20Sopenharmony_ci#define BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
1928c2ecf20Sopenharmony_ci#define BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
1938c2ecf20Sopenharmony_ci#define BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
1948c2ecf20Sopenharmony_ci#define BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci/*
1978c2ecf20Sopenharmony_ci * XXX
1988c2ecf20Sopenharmony_ci * ahd_dmamap_sync is only used on buffers allocated with
1998c2ecf20Sopenharmony_ci * the pci_alloc_consistent() API.  Although I'm not sure how
2008c2ecf20Sopenharmony_ci * this works on architectures with a write buffer, Linux does
2018c2ecf20Sopenharmony_ci * not have an API to sync "coherent" memory.  Perhaps we need
2028c2ecf20Sopenharmony_ci * to do an mb()?
2038c2ecf20Sopenharmony_ci */
2048c2ecf20Sopenharmony_ci#define ahd_dmamap_sync(ahd, dma_tag, dmamap, offset, len, op)
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci/********************************** Includes **********************************/
2078c2ecf20Sopenharmony_ci#ifdef CONFIG_AIC79XX_REG_PRETTY_PRINT
2088c2ecf20Sopenharmony_ci#define AIC_DEBUG_REGISTERS 1
2098c2ecf20Sopenharmony_ci#else
2108c2ecf20Sopenharmony_ci#define AIC_DEBUG_REGISTERS 0
2118c2ecf20Sopenharmony_ci#endif
2128c2ecf20Sopenharmony_ci#include "aic79xx.h"
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci/***************************** SMP support ************************************/
2158c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci#define AIC79XX_DRIVER_VERSION "3.0"
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci/*************************** Device Data Structures ***************************/
2208c2ecf20Sopenharmony_ci/*
2218c2ecf20Sopenharmony_ci * A per probed device structure used to deal with some error recovery
2228c2ecf20Sopenharmony_ci * scenarios that the Linux mid-layer code just doesn't know how to
2238c2ecf20Sopenharmony_ci * handle.  The structure allocated for a device only becomes persistent
2248c2ecf20Sopenharmony_ci * after a successfully completed inquiry command to the target when
2258c2ecf20Sopenharmony_ci * that inquiry data indicates a lun is present.
2268c2ecf20Sopenharmony_ci */
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_citypedef enum {
2298c2ecf20Sopenharmony_ci	AHD_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
2308c2ecf20Sopenharmony_ci	AHD_DEV_Q_BASIC		 = 0x10, /* Allow basic device queuing */
2318c2ecf20Sopenharmony_ci	AHD_DEV_Q_TAGGED	 = 0x20, /* Allow full SCSI2 command queueing */
2328c2ecf20Sopenharmony_ci	AHD_DEV_PERIODIC_OTAG	 = 0x40, /* Send OTAG to prevent starvation */
2338c2ecf20Sopenharmony_ci} ahd_linux_dev_flags;
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_cistruct ahd_linux_device {
2368c2ecf20Sopenharmony_ci	TAILQ_ENTRY(ahd_linux_device) links;
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	/*
2398c2ecf20Sopenharmony_ci	 * The number of transactions currently
2408c2ecf20Sopenharmony_ci	 * queued to the device.
2418c2ecf20Sopenharmony_ci	 */
2428c2ecf20Sopenharmony_ci	int			active;
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci	/*
2458c2ecf20Sopenharmony_ci	 * The currently allowed number of
2468c2ecf20Sopenharmony_ci	 * transactions that can be queued to
2478c2ecf20Sopenharmony_ci	 * the device.  Must be signed for
2488c2ecf20Sopenharmony_ci	 * conversion from tagged to untagged
2498c2ecf20Sopenharmony_ci	 * mode where the device may have more
2508c2ecf20Sopenharmony_ci	 * than one outstanding active transaction.
2518c2ecf20Sopenharmony_ci	 */
2528c2ecf20Sopenharmony_ci	int			openings;
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci	/*
2558c2ecf20Sopenharmony_ci	 * A positive count indicates that this
2568c2ecf20Sopenharmony_ci	 * device's queue is halted.
2578c2ecf20Sopenharmony_ci	 */
2588c2ecf20Sopenharmony_ci	u_int			qfrozen;
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	/*
2618c2ecf20Sopenharmony_ci	 * Cumulative command counter.
2628c2ecf20Sopenharmony_ci	 */
2638c2ecf20Sopenharmony_ci	u_long			commands_issued;
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	/*
2668c2ecf20Sopenharmony_ci	 * The number of tagged transactions when
2678c2ecf20Sopenharmony_ci	 * running at our current opening level
2688c2ecf20Sopenharmony_ci	 * that have been successfully received by
2698c2ecf20Sopenharmony_ci	 * this device since the last QUEUE FULL.
2708c2ecf20Sopenharmony_ci	 */
2718c2ecf20Sopenharmony_ci	u_int			tag_success_count;
2728c2ecf20Sopenharmony_ci#define AHD_TAG_SUCCESS_INTERVAL 50
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	ahd_linux_dev_flags	flags;
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	/*
2778c2ecf20Sopenharmony_ci	 * Per device timer.
2788c2ecf20Sopenharmony_ci	 */
2798c2ecf20Sopenharmony_ci	struct timer_list	timer;
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	/*
2828c2ecf20Sopenharmony_ci	 * The high limit for the tags variable.
2838c2ecf20Sopenharmony_ci	 */
2848c2ecf20Sopenharmony_ci	u_int			maxtags;
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci	/*
2878c2ecf20Sopenharmony_ci	 * The computed number of tags outstanding
2888c2ecf20Sopenharmony_ci	 * at the time of the last QUEUE FULL event.
2898c2ecf20Sopenharmony_ci	 */
2908c2ecf20Sopenharmony_ci	u_int			tags_on_last_queuefull;
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci	/*
2938c2ecf20Sopenharmony_ci	 * How many times we have seen a queue full
2948c2ecf20Sopenharmony_ci	 * with the same number of tags.  This is used
2958c2ecf20Sopenharmony_ci	 * to stop our adaptive queue depth algorithm
2968c2ecf20Sopenharmony_ci	 * on devices with a fixed number of tags.
2978c2ecf20Sopenharmony_ci	 */
2988c2ecf20Sopenharmony_ci	u_int			last_queuefull_same_count;
2998c2ecf20Sopenharmony_ci#define AHD_LOCK_TAGS_COUNT 50
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci	/*
3028c2ecf20Sopenharmony_ci	 * How many transactions have been queued
3038c2ecf20Sopenharmony_ci	 * without the device going idle.  We use
3048c2ecf20Sopenharmony_ci	 * this statistic to determine when to issue
3058c2ecf20Sopenharmony_ci	 * an ordered tag to prevent transaction
3068c2ecf20Sopenharmony_ci	 * starvation.  This statistic is only updated
3078c2ecf20Sopenharmony_ci	 * if the AHD_DEV_PERIODIC_OTAG flag is set
3088c2ecf20Sopenharmony_ci	 * on this device.
3098c2ecf20Sopenharmony_ci	 */
3108c2ecf20Sopenharmony_ci	u_int			commands_since_idle_or_otag;
3118c2ecf20Sopenharmony_ci#define AHD_OTAG_THRESH	500
3128c2ecf20Sopenharmony_ci};
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_ci/********************* Definitions Required by the Core ***********************/
3158c2ecf20Sopenharmony_ci/*
3168c2ecf20Sopenharmony_ci * Number of SG segments we require.  So long as the S/G segments for
3178c2ecf20Sopenharmony_ci * a particular transaction are allocated in a physically contiguous
3188c2ecf20Sopenharmony_ci * manner and are allocated below 4GB, the number of S/G segments is
3198c2ecf20Sopenharmony_ci * unrestricted.
3208c2ecf20Sopenharmony_ci */
3218c2ecf20Sopenharmony_ci#define	AHD_NSEG 128
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci/*
3248c2ecf20Sopenharmony_ci * Per-SCB OSM storage.
3258c2ecf20Sopenharmony_ci */
3268c2ecf20Sopenharmony_cistruct scb_platform_data {
3278c2ecf20Sopenharmony_ci	struct ahd_linux_device	*dev;
3288c2ecf20Sopenharmony_ci	dma_addr_t		 buf_busaddr;
3298c2ecf20Sopenharmony_ci	uint32_t		 xfer_len;
3308c2ecf20Sopenharmony_ci	uint32_t		 sense_resid;	/* Auto-Sense residual */
3318c2ecf20Sopenharmony_ci};
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci/*
3348c2ecf20Sopenharmony_ci * Define a structure used for each host adapter.  All members are
3358c2ecf20Sopenharmony_ci * aligned on a boundary >= the size of the member to honor the
3368c2ecf20Sopenharmony_ci * alignment restrictions of the various platforms supported by
3378c2ecf20Sopenharmony_ci * this driver.
3388c2ecf20Sopenharmony_ci */
3398c2ecf20Sopenharmony_cistruct ahd_platform_data {
3408c2ecf20Sopenharmony_ci	/*
3418c2ecf20Sopenharmony_ci	 * Fields accessed from interrupt context.
3428c2ecf20Sopenharmony_ci	 */
3438c2ecf20Sopenharmony_ci	struct scsi_target *starget[AHD_NUM_TARGETS];
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	spinlock_t		 spin_lock;
3468c2ecf20Sopenharmony_ci	struct completion	*eh_done;
3478c2ecf20Sopenharmony_ci	struct Scsi_Host        *host;		/* pointer to scsi host */
3488c2ecf20Sopenharmony_ci#define AHD_LINUX_NOIRQ	((uint32_t)~0)
3498c2ecf20Sopenharmony_ci	uint32_t		 irq;		/* IRQ for this adapter */
3508c2ecf20Sopenharmony_ci	uint32_t		 bios_address;
3518c2ecf20Sopenharmony_ci	resource_size_t		 mem_busaddr;	/* Mem Base Addr */
3528c2ecf20Sopenharmony_ci};
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_civoid ahd_delay(long);
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci/***************************** Low Level I/O **********************************/
3578c2ecf20Sopenharmony_ciuint8_t ahd_inb(struct ahd_softc * ahd, long port);
3588c2ecf20Sopenharmony_civoid ahd_outb(struct ahd_softc * ahd, long port, uint8_t val);
3598c2ecf20Sopenharmony_civoid ahd_outw_atomic(struct ahd_softc * ahd,
3608c2ecf20Sopenharmony_ci				     long port, uint16_t val);
3618c2ecf20Sopenharmony_civoid ahd_outsb(struct ahd_softc * ahd, long port,
3628c2ecf20Sopenharmony_ci			       uint8_t *, int count);
3638c2ecf20Sopenharmony_civoid ahd_insb(struct ahd_softc * ahd, long port,
3648c2ecf20Sopenharmony_ci			       uint8_t *, int count);
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ci/**************************** Initialization **********************************/
3678c2ecf20Sopenharmony_ciint		ahd_linux_register_host(struct ahd_softc *,
3688c2ecf20Sopenharmony_ci					struct scsi_host_template *);
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci/******************************** Locking *************************************/
3718c2ecf20Sopenharmony_cistatic inline void
3728c2ecf20Sopenharmony_ciahd_lockinit(struct ahd_softc *ahd)
3738c2ecf20Sopenharmony_ci{
3748c2ecf20Sopenharmony_ci	spin_lock_init(&ahd->platform_data->spin_lock);
3758c2ecf20Sopenharmony_ci}
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_cistatic inline void
3788c2ecf20Sopenharmony_ciahd_lock(struct ahd_softc *ahd, unsigned long *flags)
3798c2ecf20Sopenharmony_ci{
3808c2ecf20Sopenharmony_ci	spin_lock_irqsave(&ahd->platform_data->spin_lock, *flags);
3818c2ecf20Sopenharmony_ci}
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_cistatic inline void
3848c2ecf20Sopenharmony_ciahd_unlock(struct ahd_softc *ahd, unsigned long *flags)
3858c2ecf20Sopenharmony_ci{
3868c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&ahd->platform_data->spin_lock, *flags);
3878c2ecf20Sopenharmony_ci}
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci/******************************* PCI Definitions ******************************/
3908c2ecf20Sopenharmony_ci/*
3918c2ecf20Sopenharmony_ci * PCIM_xxx: mask to locate subfield in register
3928c2ecf20Sopenharmony_ci * PCIR_xxx: config register offset
3938c2ecf20Sopenharmony_ci * PCIC_xxx: device class
3948c2ecf20Sopenharmony_ci * PCIS_xxx: device subclass
3958c2ecf20Sopenharmony_ci * PCIP_xxx: device programming interface
3968c2ecf20Sopenharmony_ci * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
3978c2ecf20Sopenharmony_ci * PCID_xxx: device ID
3988c2ecf20Sopenharmony_ci */
3998c2ecf20Sopenharmony_ci#define PCIR_DEVVENDOR		0x00
4008c2ecf20Sopenharmony_ci#define PCIR_VENDOR		0x00
4018c2ecf20Sopenharmony_ci#define PCIR_DEVICE		0x02
4028c2ecf20Sopenharmony_ci#define PCIR_COMMAND		0x04
4038c2ecf20Sopenharmony_ci#define PCIM_CMD_PORTEN		0x0001
4048c2ecf20Sopenharmony_ci#define PCIM_CMD_MEMEN		0x0002
4058c2ecf20Sopenharmony_ci#define PCIM_CMD_BUSMASTEREN	0x0004
4068c2ecf20Sopenharmony_ci#define PCIM_CMD_MWRICEN	0x0010
4078c2ecf20Sopenharmony_ci#define PCIM_CMD_PERRESPEN	0x0040
4088c2ecf20Sopenharmony_ci#define	PCIM_CMD_SERRESPEN	0x0100
4098c2ecf20Sopenharmony_ci#define PCIR_STATUS		0x06
4108c2ecf20Sopenharmony_ci#define PCIR_REVID		0x08
4118c2ecf20Sopenharmony_ci#define PCIR_PROGIF		0x09
4128c2ecf20Sopenharmony_ci#define PCIR_SUBCLASS		0x0a
4138c2ecf20Sopenharmony_ci#define PCIR_CLASS		0x0b
4148c2ecf20Sopenharmony_ci#define PCIR_CACHELNSZ		0x0c
4158c2ecf20Sopenharmony_ci#define PCIR_LATTIMER		0x0d
4168c2ecf20Sopenharmony_ci#define PCIR_HEADERTYPE		0x0e
4178c2ecf20Sopenharmony_ci#define PCIM_MFDEV		0x80
4188c2ecf20Sopenharmony_ci#define PCIR_BIST		0x0f
4198c2ecf20Sopenharmony_ci#define PCIR_CAP_PTR		0x34
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci/* config registers for header type 0 devices */
4228c2ecf20Sopenharmony_ci#define PCIR_MAPS	0x10
4238c2ecf20Sopenharmony_ci#define PCIR_SUBVEND_0	0x2c
4248c2ecf20Sopenharmony_ci#define PCIR_SUBDEV_0	0x2e
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci/****************************** PCI-X definitions *****************************/
4278c2ecf20Sopenharmony_ci#define PCIXR_COMMAND	0x96
4288c2ecf20Sopenharmony_ci#define PCIXR_DEVADDR	0x98
4298c2ecf20Sopenharmony_ci#define PCIXM_DEVADDR_FNUM	0x0003	/* Function Number */
4308c2ecf20Sopenharmony_ci#define PCIXM_DEVADDR_DNUM	0x00F8	/* Device Number */
4318c2ecf20Sopenharmony_ci#define PCIXM_DEVADDR_BNUM	0xFF00	/* Bus Number */
4328c2ecf20Sopenharmony_ci#define PCIXR_STATUS	0x9A
4338c2ecf20Sopenharmony_ci#define PCIXM_STATUS_64BIT	0x0001	/* Active 64bit connection to device. */
4348c2ecf20Sopenharmony_ci#define PCIXM_STATUS_133CAP	0x0002	/* Device is 133MHz capable */
4358c2ecf20Sopenharmony_ci#define PCIXM_STATUS_SCDISC	0x0004	/* Split Completion Discarded */
4368c2ecf20Sopenharmony_ci#define PCIXM_STATUS_UNEXPSC	0x0008	/* Unexpected Split Completion */
4378c2ecf20Sopenharmony_ci#define PCIXM_STATUS_CMPLEXDEV	0x0010	/* Device Complexity (set == bridge) */
4388c2ecf20Sopenharmony_ci#define PCIXM_STATUS_MAXMRDBC	0x0060	/* Maximum Burst Read Count */
4398c2ecf20Sopenharmony_ci#define PCIXM_STATUS_MAXSPLITS	0x0380	/* Maximum Split Transactions */
4408c2ecf20Sopenharmony_ci#define PCIXM_STATUS_MAXCRDS	0x1C00	/* Maximum Cumulative Read Size */
4418c2ecf20Sopenharmony_ci#define PCIXM_STATUS_RCVDSCEM	0x2000	/* Received a Split Comp w/Error msg */
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_citypedef enum
4448c2ecf20Sopenharmony_ci{
4458c2ecf20Sopenharmony_ci	AHD_POWER_STATE_D0,
4468c2ecf20Sopenharmony_ci	AHD_POWER_STATE_D1,
4478c2ecf20Sopenharmony_ci	AHD_POWER_STATE_D2,
4488c2ecf20Sopenharmony_ci	AHD_POWER_STATE_D3
4498c2ecf20Sopenharmony_ci} ahd_power_state;
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_civoid ahd_power_state_change(struct ahd_softc *ahd,
4528c2ecf20Sopenharmony_ci			    ahd_power_state new_state);
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci/******************************* PCI Routines *********************************/
4558c2ecf20Sopenharmony_ciint			 ahd_linux_pci_init(void);
4568c2ecf20Sopenharmony_civoid			 ahd_linux_pci_exit(void);
4578c2ecf20Sopenharmony_ciint			 ahd_pci_map_registers(struct ahd_softc *ahd);
4588c2ecf20Sopenharmony_ciint			 ahd_pci_map_int(struct ahd_softc *ahd);
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ciuint32_t		 ahd_pci_read_config(ahd_dev_softc_t pci,
4618c2ecf20Sopenharmony_ci					     int reg, int width);
4628c2ecf20Sopenharmony_civoid			 ahd_pci_write_config(ahd_dev_softc_t pci,
4638c2ecf20Sopenharmony_ci					  int reg, uint32_t value,
4648c2ecf20Sopenharmony_ci					  int width);
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_cistatic inline int ahd_get_pci_function(ahd_dev_softc_t);
4678c2ecf20Sopenharmony_cistatic inline int
4688c2ecf20Sopenharmony_ciahd_get_pci_function(ahd_dev_softc_t pci)
4698c2ecf20Sopenharmony_ci{
4708c2ecf20Sopenharmony_ci	return (PCI_FUNC(pci->devfn));
4718c2ecf20Sopenharmony_ci}
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_cistatic inline int ahd_get_pci_slot(ahd_dev_softc_t);
4748c2ecf20Sopenharmony_cistatic inline int
4758c2ecf20Sopenharmony_ciahd_get_pci_slot(ahd_dev_softc_t pci)
4768c2ecf20Sopenharmony_ci{
4778c2ecf20Sopenharmony_ci	return (PCI_SLOT(pci->devfn));
4788c2ecf20Sopenharmony_ci}
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_cistatic inline int ahd_get_pci_bus(ahd_dev_softc_t);
4818c2ecf20Sopenharmony_cistatic inline int
4828c2ecf20Sopenharmony_ciahd_get_pci_bus(ahd_dev_softc_t pci)
4838c2ecf20Sopenharmony_ci{
4848c2ecf20Sopenharmony_ci	return (pci->bus->number);
4858c2ecf20Sopenharmony_ci}
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_cistatic inline void ahd_flush_device_writes(struct ahd_softc *);
4888c2ecf20Sopenharmony_cistatic inline void
4898c2ecf20Sopenharmony_ciahd_flush_device_writes(struct ahd_softc *ahd)
4908c2ecf20Sopenharmony_ci{
4918c2ecf20Sopenharmony_ci	/* XXX Is this sufficient for all architectures??? */
4928c2ecf20Sopenharmony_ci	ahd_inb(ahd, INTSTAT);
4938c2ecf20Sopenharmony_ci}
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_ci/**************************** Proc FS Support *********************************/
4968c2ecf20Sopenharmony_ciint	ahd_proc_write_seeprom(struct Scsi_Host *, char *, int);
4978c2ecf20Sopenharmony_ciint	ahd_linux_show_info(struct seq_file *,struct Scsi_Host *);
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci/*********************** Transaction Access Wrappers **************************/
5008c2ecf20Sopenharmony_cistatic inline void ahd_cmd_set_transaction_status(struct scsi_cmnd *, uint32_t);
5018c2ecf20Sopenharmony_cistatic inline void ahd_set_transaction_status(struct scb *, uint32_t);
5028c2ecf20Sopenharmony_cistatic inline void ahd_cmd_set_scsi_status(struct scsi_cmnd *, uint32_t);
5038c2ecf20Sopenharmony_cistatic inline void ahd_set_scsi_status(struct scb *, uint32_t);
5048c2ecf20Sopenharmony_cistatic inline uint32_t ahd_cmd_get_transaction_status(struct scsi_cmnd *cmd);
5058c2ecf20Sopenharmony_cistatic inline uint32_t ahd_get_transaction_status(struct scb *);
5068c2ecf20Sopenharmony_cistatic inline uint32_t ahd_cmd_get_scsi_status(struct scsi_cmnd *cmd);
5078c2ecf20Sopenharmony_cistatic inline uint32_t ahd_get_scsi_status(struct scb *);
5088c2ecf20Sopenharmony_cistatic inline void ahd_set_transaction_tag(struct scb *, int, u_int);
5098c2ecf20Sopenharmony_cistatic inline u_long ahd_get_transfer_length(struct scb *);
5108c2ecf20Sopenharmony_cistatic inline int ahd_get_transfer_dir(struct scb *);
5118c2ecf20Sopenharmony_cistatic inline void ahd_set_residual(struct scb *, u_long);
5128c2ecf20Sopenharmony_cistatic inline void ahd_set_sense_residual(struct scb *scb, u_long resid);
5138c2ecf20Sopenharmony_cistatic inline u_long ahd_get_residual(struct scb *);
5148c2ecf20Sopenharmony_cistatic inline u_long ahd_get_sense_residual(struct scb *);
5158c2ecf20Sopenharmony_cistatic inline int ahd_perform_autosense(struct scb *);
5168c2ecf20Sopenharmony_cistatic inline uint32_t ahd_get_sense_bufsize(struct ahd_softc *,
5178c2ecf20Sopenharmony_ci					       struct scb *);
5188c2ecf20Sopenharmony_cistatic inline void ahd_notify_xfer_settings_change(struct ahd_softc *,
5198c2ecf20Sopenharmony_ci						     struct ahd_devinfo *);
5208c2ecf20Sopenharmony_cistatic inline void ahd_platform_scb_free(struct ahd_softc *ahd,
5218c2ecf20Sopenharmony_ci					   struct scb *scb);
5228c2ecf20Sopenharmony_cistatic inline void ahd_freeze_scb(struct scb *scb);
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_cistatic inline
5258c2ecf20Sopenharmony_civoid ahd_cmd_set_transaction_status(struct scsi_cmnd *cmd, uint32_t status)
5268c2ecf20Sopenharmony_ci{
5278c2ecf20Sopenharmony_ci	cmd->result &= ~(CAM_STATUS_MASK << 16);
5288c2ecf20Sopenharmony_ci	cmd->result |= status << 16;
5298c2ecf20Sopenharmony_ci}
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_cistatic inline
5328c2ecf20Sopenharmony_civoid ahd_set_transaction_status(struct scb *scb, uint32_t status)
5338c2ecf20Sopenharmony_ci{
5348c2ecf20Sopenharmony_ci	ahd_cmd_set_transaction_status(scb->io_ctx,status);
5358c2ecf20Sopenharmony_ci}
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_cistatic inline
5388c2ecf20Sopenharmony_civoid ahd_cmd_set_scsi_status(struct scsi_cmnd *cmd, uint32_t status)
5398c2ecf20Sopenharmony_ci{
5408c2ecf20Sopenharmony_ci	cmd->result &= ~0xFFFF;
5418c2ecf20Sopenharmony_ci	cmd->result |= status;
5428c2ecf20Sopenharmony_ci}
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_cistatic inline
5458c2ecf20Sopenharmony_civoid ahd_set_scsi_status(struct scb *scb, uint32_t status)
5468c2ecf20Sopenharmony_ci{
5478c2ecf20Sopenharmony_ci	ahd_cmd_set_scsi_status(scb->io_ctx, status);
5488c2ecf20Sopenharmony_ci}
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_cistatic inline
5518c2ecf20Sopenharmony_ciuint32_t ahd_cmd_get_transaction_status(struct scsi_cmnd *cmd)
5528c2ecf20Sopenharmony_ci{
5538c2ecf20Sopenharmony_ci	return ((cmd->result >> 16) & CAM_STATUS_MASK);
5548c2ecf20Sopenharmony_ci}
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_cistatic inline
5578c2ecf20Sopenharmony_ciuint32_t ahd_get_transaction_status(struct scb *scb)
5588c2ecf20Sopenharmony_ci{
5598c2ecf20Sopenharmony_ci	return (ahd_cmd_get_transaction_status(scb->io_ctx));
5608c2ecf20Sopenharmony_ci}
5618c2ecf20Sopenharmony_ci
5628c2ecf20Sopenharmony_cistatic inline
5638c2ecf20Sopenharmony_ciuint32_t ahd_cmd_get_scsi_status(struct scsi_cmnd *cmd)
5648c2ecf20Sopenharmony_ci{
5658c2ecf20Sopenharmony_ci	return (cmd->result & 0xFFFF);
5668c2ecf20Sopenharmony_ci}
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_cistatic inline
5698c2ecf20Sopenharmony_ciuint32_t ahd_get_scsi_status(struct scb *scb)
5708c2ecf20Sopenharmony_ci{
5718c2ecf20Sopenharmony_ci	return (ahd_cmd_get_scsi_status(scb->io_ctx));
5728c2ecf20Sopenharmony_ci}
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_cistatic inline
5758c2ecf20Sopenharmony_civoid ahd_set_transaction_tag(struct scb *scb, int enabled, u_int type)
5768c2ecf20Sopenharmony_ci{
5778c2ecf20Sopenharmony_ci	/*
5788c2ecf20Sopenharmony_ci	 * Nothing to do for linux as the incoming transaction
5798c2ecf20Sopenharmony_ci	 * has no concept of tag/non tagged, etc.
5808c2ecf20Sopenharmony_ci	 */
5818c2ecf20Sopenharmony_ci}
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_cistatic inline
5848c2ecf20Sopenharmony_ciu_long ahd_get_transfer_length(struct scb *scb)
5858c2ecf20Sopenharmony_ci{
5868c2ecf20Sopenharmony_ci	return (scb->platform_data->xfer_len);
5878c2ecf20Sopenharmony_ci}
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_cistatic inline
5908c2ecf20Sopenharmony_ciint ahd_get_transfer_dir(struct scb *scb)
5918c2ecf20Sopenharmony_ci{
5928c2ecf20Sopenharmony_ci	return (scb->io_ctx->sc_data_direction);
5938c2ecf20Sopenharmony_ci}
5948c2ecf20Sopenharmony_ci
5958c2ecf20Sopenharmony_cistatic inline
5968c2ecf20Sopenharmony_civoid ahd_set_residual(struct scb *scb, u_long resid)
5978c2ecf20Sopenharmony_ci{
5988c2ecf20Sopenharmony_ci	scsi_set_resid(scb->io_ctx, resid);
5998c2ecf20Sopenharmony_ci}
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_cistatic inline
6028c2ecf20Sopenharmony_civoid ahd_set_sense_residual(struct scb *scb, u_long resid)
6038c2ecf20Sopenharmony_ci{
6048c2ecf20Sopenharmony_ci	scb->platform_data->sense_resid = resid;
6058c2ecf20Sopenharmony_ci}
6068c2ecf20Sopenharmony_ci
6078c2ecf20Sopenharmony_cistatic inline
6088c2ecf20Sopenharmony_ciu_long ahd_get_residual(struct scb *scb)
6098c2ecf20Sopenharmony_ci{
6108c2ecf20Sopenharmony_ci	return scsi_get_resid(scb->io_ctx);
6118c2ecf20Sopenharmony_ci}
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_cistatic inline
6148c2ecf20Sopenharmony_ciu_long ahd_get_sense_residual(struct scb *scb)
6158c2ecf20Sopenharmony_ci{
6168c2ecf20Sopenharmony_ci	return (scb->platform_data->sense_resid);
6178c2ecf20Sopenharmony_ci}
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_cistatic inline
6208c2ecf20Sopenharmony_ciint ahd_perform_autosense(struct scb *scb)
6218c2ecf20Sopenharmony_ci{
6228c2ecf20Sopenharmony_ci	/*
6238c2ecf20Sopenharmony_ci	 * We always perform autosense in Linux.
6248c2ecf20Sopenharmony_ci	 * On other platforms this is set on a
6258c2ecf20Sopenharmony_ci	 * per-transaction basis.
6268c2ecf20Sopenharmony_ci	 */
6278c2ecf20Sopenharmony_ci	return (1);
6288c2ecf20Sopenharmony_ci}
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_cistatic inline uint32_t
6318c2ecf20Sopenharmony_ciahd_get_sense_bufsize(struct ahd_softc *ahd, struct scb *scb)
6328c2ecf20Sopenharmony_ci{
6338c2ecf20Sopenharmony_ci	return (sizeof(struct scsi_sense_data));
6348c2ecf20Sopenharmony_ci}
6358c2ecf20Sopenharmony_ci
6368c2ecf20Sopenharmony_cistatic inline void
6378c2ecf20Sopenharmony_ciahd_notify_xfer_settings_change(struct ahd_softc *ahd,
6388c2ecf20Sopenharmony_ci				struct ahd_devinfo *devinfo)
6398c2ecf20Sopenharmony_ci{
6408c2ecf20Sopenharmony_ci	/* Nothing to do here for linux */
6418c2ecf20Sopenharmony_ci}
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_cistatic inline void
6448c2ecf20Sopenharmony_ciahd_platform_scb_free(struct ahd_softc *ahd, struct scb *scb)
6458c2ecf20Sopenharmony_ci{
6468c2ecf20Sopenharmony_ci	ahd->flags &= ~AHD_RESOURCE_SHORTAGE;
6478c2ecf20Sopenharmony_ci}
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ciint	ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
6508c2ecf20Sopenharmony_civoid	ahd_platform_free(struct ahd_softc *ahd);
6518c2ecf20Sopenharmony_civoid	ahd_platform_init(struct ahd_softc *ahd);
6528c2ecf20Sopenharmony_civoid	ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb);
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_cistatic inline void
6558c2ecf20Sopenharmony_ciahd_freeze_scb(struct scb *scb)
6568c2ecf20Sopenharmony_ci{
6578c2ecf20Sopenharmony_ci	if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
6588c2ecf20Sopenharmony_ci                scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
6598c2ecf20Sopenharmony_ci                scb->platform_data->dev->qfrozen++;
6608c2ecf20Sopenharmony_ci        }
6618c2ecf20Sopenharmony_ci}
6628c2ecf20Sopenharmony_ci
6638c2ecf20Sopenharmony_civoid	ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
6648c2ecf20Sopenharmony_ci			      struct ahd_devinfo *devinfo, ahd_queue_alg);
6658c2ecf20Sopenharmony_ciint	ahd_platform_abort_scbs(struct ahd_softc *ahd, int target,
6668c2ecf20Sopenharmony_ci				char channel, int lun, u_int tag,
6678c2ecf20Sopenharmony_ci				role_t role, uint32_t status);
6688c2ecf20Sopenharmony_ciirqreturn_t
6698c2ecf20Sopenharmony_ci	ahd_linux_isr(int irq, void *dev_id);
6708c2ecf20Sopenharmony_civoid	ahd_done(struct ahd_softc*, struct scb*);
6718c2ecf20Sopenharmony_civoid	ahd_send_async(struct ahd_softc *, char channel,
6728c2ecf20Sopenharmony_ci		       u_int target, u_int lun, ac_code);
6738c2ecf20Sopenharmony_civoid	ahd_print_path(struct ahd_softc *, struct scb *);
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI
6768c2ecf20Sopenharmony_ci#define AHD_PCI_CONFIG 1
6778c2ecf20Sopenharmony_ci#else
6788c2ecf20Sopenharmony_ci#define AHD_PCI_CONFIG 0
6798c2ecf20Sopenharmony_ci#endif
6808c2ecf20Sopenharmony_ci#define bootverbose aic79xx_verbose
6818c2ecf20Sopenharmony_ciextern uint32_t aic79xx_verbose;
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci#endif /* _AIC79XX_LINUX_H_ */
684