/*
 * atari_scsi.h -- Header file for the Atari native SCSI driver
 *
 * Copyright 1994 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
 *
 * (Loosely based on the work of Robert De Vries' team)
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file README.legal in the main directory of this archive
 * for more details.
 *
 */


#ifndef ATARI_SCSI_H
#define ATARI_SCSI_H

/* (I_HAVE_OVERRUNS stuff removed) */

#ifndef ASM
int atari_scsi_abort (Scsi_Cmnd *);
int atari_scsi_detect (Scsi_Host_Template *);
const char *atari_scsi_info (struct Scsi_Host *);
int atari_scsi_queue_command (Scsi_Cmnd *, void (*done) (Scsi_Cmnd *));
int atari_scsi_reset (Scsi_Cmnd *);

/* The values for CMD_PER_LUN and CAN_QUEUE are somehow arbitrary. Higher
 * values should work, too; try it! (but cmd_per_lun costs memory!) */

/* But there seems to be a bug somewhere that requires CAN_QUEUE to be
 * 2*CMD_OER_LUN. At least on a TT, no suprious timeouts seen since
 * changed CMD_PER_LUN... */

/* Note: The Falcon currently uses 8/1 setting due to unsolved problems with
 * cmd_per_lun != 1 */

#define ATARI_TT_CAN_QUEUE			16
#define ATARI_TT_CMD_PER_LUN		8
#define ATARI_TT_SG_TABLESIZE		SG_ALL

#define ATARI_FALCON_CAN_QUEUE		8
#define ATARI_FALCON_CMD_PER_LUN	1
#define ATARI_FALCON_SG_TABLESIZE	SG_NONE

#define	DEFAULT_USE_TAGGED_QUEUING	0


#ifdef HOSTS_C

#define ATARI_SCSI { NULL, NULL,								\
  "Atari native SCSI",											\
  atari_scsi_detect,											\
  /* release */ NULL,											\
  atari_scsi_info,												\
  /* command */ NULL,											\
  atari_scsi_queue_command,										\
  atari_scsi_abort,												\
  atari_scsi_reset,												\
  /* slave_attach */ NULL,										\
  /* bios_param */ NULL,										\
  /* can queue */ 			0, /* initialized at run-time */	\
  /* host_id */				0, /* initialized at run-time */	\
  /* scatter gather */ 		0, /* initialized at run-time */	\
  /* cmd per lun */ 		0, /* initialized at run-time */	\
  /* present */ 			0,									\
  /* unchecked ISA DMA */	0,									\
  /* use_clustering */		DISABLE_CLUSTERING }

#else

#define NCR5380_implementation_fields     /* none */

#define NCR5380_read(reg)		  atari_scsi_reg_read( reg )
#define NCR5380_write(reg, value) atari_scsi_reg_write( reg, value )

#define NCR5380_intr atari_scsi_intr
#define NCR5380_queue_command atari_scsi_queue_command
#define NCR5380_abort atari_scsi_abort
#define NCR5380_dma_read_setup(inst,d,c) atari_scsi_dma_setup (inst, d, c, 0)
#define NCR5380_dma_write_setup(inst,d,c) atari_scsi_dma_setup (inst, d, c, 1)
#define NCR5380_dma_residual(inst) atari_scsi_dma_residual( inst )
#define	NCR5380_dma_xfer_len(i,cmd,phase) \
	atari_dma_xfer_len(cmd->SCp.this_residual,cmd,((phase) & SR_IO) ? 0 : 1)

/* Debugging printk definitions:
 * DPRINTK() is the generic one, takes an NDEBUG_* mask as argument;
 * all others are hardcoded to one NDEBUG_* code:
 *
 *  ARB  -> arbitration
 *  ASEN -> auto-sense
 *  DMA  -> DMA
 *  HSH  -> PIO handshake
 *  INF  -> information transfer
 *  INI  -> initialization
 *  INT  -> interrupt
 *  LNK  -> linked commands
 *  MAIN -> NCR5380_main() control flow
 *  NDAT -> no data-out phase
 *  NWR  -> no write commands
 *  PIO  -> PIO tansfers
 *  PDMA -> pseudo DMA (unused on Atari)
 *  QU   -> queues
 *  RSL  -> reselections
 *  SEL  -> selections
 *  USL  -> usleep cpde (unused on Atari)
 *  LBS  -> last byte sent (unused on Atari)
 *  RSS  -> restarting of selections
 *  EXT  -> extended messages
 *  ABRT -> aborting and resetting
 *  TAG  -> queue tag handling
 *  MER  -> merging of consec. buffers
 *
 */

#define DPRINTK( mask, format, args... )			\
	do {											\
		if (NDEBUG & (mask))						\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define ARB_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_ARBITRATION)			\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define ASEN_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_AUTOSENSE)				\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define DMA_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_DMA)					\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define HSH_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_HANDSHAKE)				\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define INF_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_INFORMATION)			\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define INI_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_INIT)					\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define INT_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_INTR)					\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define LNK_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_LINKED)					\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define MAIN_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_MAIN)					\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define NDAT_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_NO_DATAOUT)				\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define NWR_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_NO_WRITE)				\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define PIO_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_PIO)					\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define PDMA_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_PSEUDO_DMA)				\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define QU_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_QUEUES)					\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define RSL_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_RESELECTION)			\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define SEL_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_SELECTION)				\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define USL_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_USLEEP)					\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define LBS_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_LAST_BYTE_SENT)			\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define RSS_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_RESTART_SELECT)			\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define EXT_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_EXTENDED)				\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define ABRT_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_ABORT)					\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define TAG_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_TAGS)					\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

#define MER_PRINTK( format, args... )				\
	do {											\
		if (NDEBUG & NDEBUG_MERGING)				\
			printk( KERN_DEBUG format , ## args );	\
	} while(0)

/* conditional macros for NCR5380_print_{,phase,status} */

#define NCR_PRINT(mask)							\
	do {										\
		if (NDEBUG & (mask))					\
			NCR5380_print( instance );			\
	} while(0)

#define NCR_PRINT_PHASE(mask)					\
	do {										\
		if (NDEBUG & (mask))					\
			NCR5380_print_phase( instance );	\
	} while(0)

#define NCR_PRINT_STATUS(mask)					\
	do {										\
		if (NDEBUG & (mask))					\
			NCR5380_print_status( instance );	\
	} while(0)

#define NDEBUG_ANY	0xffffffff


#endif /* else def HOSTS_C */
#endif /* ndef ASM */
#endif /* ATARI_SCSI_H */


