linux/drivers/scsi/aic7xxx/aic79xx.h

/*
 * Core definitions and data structures shareable across OS platforms.
 *
 * Copyright (c) 1994-2002 Justin T. Gibbs.
 * Copyright (c) 2000-2002 Adaptec Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * $Id: //depot/aic7xxx/aic7xxx/aic79xx.h#109 $
 *
 * $FreeBSD$
 */

#ifndef _AIC79XX_H_
#define _AIC79XX_H_

/* Register Definitions */
#include "aic79xx_reg.h"

/************************* Forward Declarations *******************************/
struct ahd_platform_data;
struct scb_platform_data;

/****************************** Useful Macros *********************************/
#ifndef TRUE
#define TRUE
#endif
#ifndef FALSE
#define FALSE
#endif

#define ALL_CHANNELS
#define ALL_TARGETS_MASK
#define INITIATOR_WILDCARD
#define SCB_LIST_NULL
#define SCB_LIST_NULL_LE
#define QOUTFIFO_ENTRY_VALID
#define SCBID_IS_NULL(scbid)

#define SCSIID_TARGET(ahd, scsiid)
#define SCSIID_OUR_ID(scsiid)
#define SCSIID_CHANNEL(ahd, scsiid)
#define SCB_IS_SCSIBUS_B(ahd, scb)
#define SCB_GET_OUR_ID(scb)
#define SCB_GET_TARGET(ahd, scb)
#define SCB_GET_CHANNEL(ahd, scb)
#define SCB_GET_LUN(scb)
#define SCB_GET_TARGET_OFFSET(ahd, scb)
#define SCB_GET_TARGET_MASK(ahd, scb)
#ifdef AHD_DEBUG
#define SCB_IS_SILENT(scb)
#else
#define SCB_IS_SILENT
#endif
/*
 * TCLs have the following format: TTTTLLLLLLLL
 */
#define TCL_TARGET_OFFSET(tcl)
#define TCL_LUN(tcl)
#define BUILD_TCL(scsiid, lun)
#define BUILD_TCL_RAW(target, channel, lun)

#define SCB_GET_TAG(scb)

#ifndef	AHD_TARGET_MODE
#undef	AHD_TMODE_ENABLE
#define AHD_TMODE_ENABLE
#endif

#define AHD_BUILD_COL_IDX(target, lun)

#define AHD_GET_SCB_COL_IDX(ahd, scb)

#define AHD_SET_SCB_COL_IDX(scb, col_idx)

#define AHD_COPY_SCB_COL_IDX(dst, src)

#define AHD_NEVER_COL_IDX

/**************************** Driver Constants ********************************/
/*
 * The maximum number of supported targets.
 */
#define AHD_NUM_TARGETS

/*
 * The maximum number of supported luns.
 * The identify message only supports 64 luns in non-packetized transfers.
 * You can have 2^64 luns when information unit transfers are enabled,
 * but until we see a need to support that many, we support 256.
 */
#define AHD_NUM_LUNS_NONPKT
#define AHD_NUM_LUNS

/*
 * The maximum transfer per S/G segment.
 */
#define AHD_MAXTRANSFER_SIZE

/*
 * The maximum amount of SCB storage in hardware on a controller.
 * This value represents an upper bound.  Due to software design,
 * we may not be able to use this number.
 */
#define AHD_SCB_MAX

/*
 * The maximum number of concurrent transactions supported per driver instance.
 * Sequencer Control Blocks (SCBs) store per-transaction information.
 */
#define AHD_MAX_QUEUE

/*
 * Define the size of our QIN and QOUT FIFOs.  They must be a power of 2
 * in size and accommodate as many transactions as can be queued concurrently.
 */
#define AHD_QIN_SIZE
#define AHD_QOUT_SIZE

#define AHD_QIN_WRAP(x)
/*
 * The maximum amount of SCB storage we allocate in host memory.
 */
#define AHD_SCB_MAX_ALLOC

/*
 * Ring Buffer of incoming target commands.
 * We allocate 256 to simplify the logic in the sequencer
 * by using the natural wrap point of an 8bit counter.
 */
#define AHD_TMODE_CMDS

/* Reset line assertion time in us */
#define AHD_BUSRESET_DELAY

/******************* Chip Characteristics/Operating Settings  *****************/
/*
 * Chip Type
 * The chip order is from least sophisticated to most sophisticated.
 */
ahd_chip;

/*
 * Features available in each chip type.
 */
ahd_feature;

/*
 * Bugs in the silicon that we work around in software.
 */
ahd_bug;

/*
 * Configuration specific settings.
 * The driver determines these settings by probing the
 * chip/controller's configuration.
 */
ahd_flag;

/************************* Hardware  SCB Definition ***************************/

/*
 * The driver keeps up to MAX_SCB scb structures per card in memory.  The SCB
 * consists of a "hardware SCB" mirroring the fields available on the card
 * and additional information the kernel stores for each transaction.
 *
 * To minimize space utilization, a portion of the hardware scb stores
 * different data during different portions of a SCSI transaction.
 * As initialized by the host driver for the initiator role, this area
 * contains the SCSI cdb (or a pointer to the  cdb) to be executed.  After
 * the cdb has been presented to the target, this area serves to store
 * residual transfer information and the SCSI status byte.
 * For the target role, the contents of this area do not change, but
 * still serve a different purpose than for the initiator role.  See
 * struct target_data for details.
 */

/*
 * Status information embedded in the shared poriton of
 * an SCB after passing the cdb to the target.  The kernel
 * driver will only read this data for transactions that
 * complete abnormally.
 */
struct initiator_status {};

struct target_status {};

/*
 * Initiator mode SCB shared data area.
 * If the embedded CDB is 12 bytes or less, we embed
 * the sense buffer address in the SCB.  This allows
 * us to retrieve sense information without interrupting
 * the host in packetized mode.
 */
sense_addr_t;
#define MAX_CDB_LEN
#define MAX_CDB_LEN_WITH_SENSE_ADDR
initiator_data;

/*
 * Target mode version of the shared data SCB segment.
 */
struct target_data {};

struct hardware_scb {};

/************************ Kernel SCB Definitions ******************************/
/*
 * Some fields of the SCB are OS dependent.  Here we collect the
 * definitions for elements that all OS platforms need to include
 * in there SCB definition.
 */

/*
 * Definition of a scatter/gather element as transferred to the controller.
 * The aic7xxx chips only support a 24bit length.  We use the top byte of
 * the length to store additional address bits and a flag to indicate
 * that a given segment terminates the transfer.  This gives us an
 * addressable range of 512GB on machines with 64bit PCI or with chips
 * that can support dual address cycles on 32bit PCI busses.
 */
struct ahd_dma_seg {};

struct ahd_dma64_seg {};

struct map_node {};

/*
 * The current state of this SCB.
 */
scb_flag;

struct scb {};

TAILQ_HEAD(scb_tailq, scb);
BSD_LIST_HEAD(scb_list, scb);

struct scb_data {};

/************************ Target Mode Definitions *****************************/

/*
 * Connection descriptor for select-in requests in target mode.
 */
struct target_cmd {};

/*
 * Number of events we can buffer up if we run out
 * of immediate notify ccbs.
 */
#define AHD_TMODE_EVENT_BUFFER_SIZE
struct ahd_tmode_event {};

/*
 * Per enabled lun target mode state.
 * As this state is directly influenced by the host OS'es target mode
 * environment, we let the OS module define it.  Forward declare the
 * structure here so we can store arrays of them, etc. in OS neutral
 * data structures.
 */
#ifdef AHD_TARGET_MODE
struct ahd_tmode_lstate {
	struct cam_path *path;
	struct ccb_hdr_slist accept_tios;
	struct ccb_hdr_slist immed_notifies;
	struct ahd_tmode_event event_buffer[AHD_TMODE_EVENT_BUFFER_SIZE];
	uint8_t event_r_idx;
	uint8_t event_w_idx;
};
#else
struct ahd_tmode_lstate;
#endif

/******************** Transfer Negotiation Datastructures *********************/
#define AHD_TRANS_CUR
#define AHD_TRANS_ACTIVE
#define AHD_TRANS_GOAL
#define AHD_TRANS_USER
#define AHD_PERIOD_10MHz

#define AHD_WIDTH_UNKNOWN
#define AHD_PERIOD_UNKNOWN
#define AHD_OFFSET_UNKNOWN
#define AHD_PPR_OPTS_UNKNOWN

/*
 * Transfer Negotiation Information.
 */
struct ahd_transinfo {};

/*
 * Per-initiator current, goal and user transfer negotiation information. */
struct ahd_initiator_tinfo {};

/*
 * Per enabled target ID state.
 * Pointers to lun target state as well as sync/wide negotiation information
 * for each initiator<->target mapping.  For the initiator role we pretend
 * that we are the target and the targets are the initiators since the
 * negotiation is the same regardless of role.
 */
struct ahd_tmode_tstate {};

/*
 * Points of interest along the negotiated transfer scale.
 */
#define AHD_SYNCRATE_160
#define AHD_SYNCRATE_PACED
#define AHD_SYNCRATE_DT
#define AHD_SYNCRATE_ULTRA2
#define AHD_SYNCRATE_ULTRA
#define AHD_SYNCRATE_FAST
#define AHD_SYNCRATE_MIN_DT
#define AHD_SYNCRATE_SYNC
#define AHD_SYNCRATE_MIN
#define AHD_SYNCRATE_ASYNC
#define AHD_SYNCRATE_MAX

/* Safe and valid period for async negotiations. */
#define AHD_ASYNC_XFER_PERIOD

/*
 * In RevA, the synctable uses a 120MHz rate for the period
 * factor 8 and 160MHz for the period factor 7.  The 120MHz
 * rate never made it into the official SCSI spec, so we must
 * compensate when setting the negotiation table for Rev A
 * parts.
 */
#define AHD_SYNCRATE_REVA_120
#define AHD_SYNCRATE_REVA_160

/***************************** Lookup Tables **********************************/
/*
 * Phase -> name and message out response
 * to parity errors in each phase table.
 */
struct ahd_phase_table_entry {};

/************************** Serial EEPROM Format ******************************/

struct seeprom_config {};

/*
 * Vital Product Data used during POST and by the BIOS.
 */
struct vpd_config {};

/****************************** Flexport Logic ********************************/
#define FLXADDR_TERMCTL
#define FLX_TERMCTL_ENSECHIGH
#define FLX_TERMCTL_ENSECLOW
#define FLX_TERMCTL_ENPRIHIGH
#define FLX_TERMCTL_ENPRILOW
#define FLXADDR_ROMSTAT_CURSENSECTL
#define FLX_ROMSTAT_SEECFG
#define FLX_ROMSTAT_EECFG
#define FLX_ROMSTAT_SEE_93C66
#define FLX_ROMSTAT_SEE_NONE
#define FLX_ROMSTAT_EE_512x8
#define FLX_ROMSTAT_EE_1MBx8
#define FLX_ROMSTAT_EE_2MBx8
#define FLX_ROMSTAT_EE_4MBx8
#define FLX_ROMSTAT_EE_16MBx8
#define CURSENSE_ENB
#define FLXADDR_FLEXSTAT
#define FLX_FSTAT_BUSY
#define FLXADDR_CURRENT_STAT
#define FLX_CSTAT_SEC_HIGH
#define FLX_CSTAT_SEC_LOW
#define FLX_CSTAT_PRI_HIGH
#define FLX_CSTAT_PRI_LOW
#define FLX_CSTAT_MASK
#define FLX_CSTAT_SHIFT
#define FLX_CSTAT_OKAY
#define FLX_CSTAT_OVER
#define FLX_CSTAT_UNDER
#define FLX_CSTAT_INVALID

int		ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *buf,
				 u_int start_addr, u_int count, int bstream);

int		ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,
				  u_int start_addr, u_int count);
int		ahd_verify_cksum(struct seeprom_config *sc);
int		ahd_acquire_seeprom(struct ahd_softc *ahd);
void		ahd_release_seeprom(struct ahd_softc *ahd);

/****************************  Message Buffer *********************************/
ahd_msg_flags;

ahd_msg_type;

msg_loop_stat;

/*********************** Software Configuration Structure *********************/
struct ahd_suspend_channel_state {};

struct ahd_suspend_pci_state {};

struct ahd_suspend_state {};

ahd_bus_intr_t;

ahd_mode;

#define AHD_MK_MSK(x)
#define AHD_MODE_DFF0_MSK
#define AHD_MODE_DFF1_MSK
#define AHD_MODE_CCHAN_MSK
#define AHD_MODE_SCSI_MSK
#define AHD_MODE_CFG_MSK
#define AHD_MODE_UNKNOWN_MSK
#define AHD_MODE_ANY_MSK

ahd_mode_state;

struct ahd_completion
{};

struct ahd_softc {};

/*************************** IO Cell Configuration ****************************/
#define AHD_PRECOMP_SLEW_INDEX

#define AHD_AMPLITUDE_INDEX

#define AHD_SET_SLEWRATE(ahd, new_slew)

#define AHD_SET_PRECOMP(ahd, new_pcomp)

#define AHD_SET_AMPLITUDE(ahd, new_amp)

/************************ Active Device Information ***************************/
role_t;

struct ahd_devinfo {};

/****************************** PCI Structures ********************************/
#define AHD_PCI_IOADDR0
#define AHD_PCI_MEMADDR
#define AHD_PCI_IOADDR1

ahd_device_setup_t;

struct ahd_pci_identity {};

/***************************** VL/EISA Declarations ***************************/
struct aic7770_identity {};
extern struct aic7770_identity aic7770_ident_table [];
extern const int ahd_num_aic7770_devs;

#define AHD_EISA_SLOT_OFFSET
#define AHD_EISA_IOSIZE

/*************************** Function Declarations ****************************/
/******************************************************************************/

/***************************** PCI Front End *********************************/
const struct	ahd_pci_identity *ahd_find_pci_device(ahd_dev_softc_t);
int			  ahd_pci_config(struct ahd_softc *,
					 const struct ahd_pci_identity *);
int	ahd_pci_test_register_access(struct ahd_softc *);
void __maybe_unused	ahd_pci_suspend(struct ahd_softc *);
void __maybe_unused	ahd_pci_resume(struct ahd_softc *);

/************************** SCB and SCB queue management **********************/
void		ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,
					 struct scb *scb);

/****************************** Initialization ********************************/
struct ahd_softc	*ahd_alloc(void *platform_arg, char *name);
int			 ahd_softc_init(struct ahd_softc *);
void			 ahd_controller_info(struct ahd_softc *ahd, char *buf);
int			 ahd_init(struct ahd_softc *ahd);
int __maybe_unused	 ahd_suspend(struct ahd_softc *ahd);
void __maybe_unused	 ahd_resume(struct ahd_softc *ahd);
int			 ahd_default_config(struct ahd_softc *ahd);
int			 ahd_parse_vpddata(struct ahd_softc *ahd,
					   struct vpd_config *vpd);
int			 ahd_parse_cfgdata(struct ahd_softc *ahd,
					   struct seeprom_config *sc);
void			 ahd_intr_enable(struct ahd_softc *ahd, int enable);
void			 ahd_pause_and_flushwork(struct ahd_softc *ahd);
void			 ahd_set_unit(struct ahd_softc *, int);
void			 ahd_set_name(struct ahd_softc *, char *);
struct scb		*ahd_get_scb(struct ahd_softc *ahd, u_int col_idx);
void			 ahd_free_scb(struct ahd_softc *ahd, struct scb *scb);
void			 ahd_free(struct ahd_softc *ahd);
int			 ahd_reset(struct ahd_softc *ahd, int reinit);
int			 ahd_write_flexport(struct ahd_softc *ahd,
					    u_int addr, u_int value);
int			 ahd_read_flexport(struct ahd_softc *ahd, u_int addr,
					   uint8_t *value);

/***************************** Error Recovery *********************************/
ahd_search_action;
int			ahd_search_qinfifo(struct ahd_softc *ahd, int target,
					   char channel, int lun, u_int tag,
					   role_t role, uint32_t status,
					   ahd_search_action action);
int			ahd_search_disc_list(struct ahd_softc *ahd, int target,
					     char channel, int lun, u_int tag,
					     int stop_on_first, int remove,
					     int save_state);
int			ahd_reset_channel(struct ahd_softc *ahd, char channel,
					  int initiate_reset);
/*************************** Utility Functions ********************************/
void			ahd_compile_devinfo(struct ahd_devinfo *devinfo,
					    u_int our_id, u_int target,
					    u_int lun, char channel,
					    role_t role);
/************************** Transfer Negotiation ******************************/
void			ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
					  u_int *ppr_options, u_int maxsync);
/*
 * Negotiation types.  These are used to qualify if we should renegotiate
 * even if our goal and current transport parameters are identical.
 */
ahd_neg_type;
int			ahd_update_neg_request(struct ahd_softc*,
					       struct ahd_devinfo*,
					       struct ahd_tmode_tstate*,
					       struct ahd_initiator_tinfo*,
					       ahd_neg_type);
void			ahd_set_width(struct ahd_softc *ahd,
				      struct ahd_devinfo *devinfo,
				      u_int width, u_int type, int paused);
void			ahd_set_syncrate(struct ahd_softc *ahd,
					 struct ahd_devinfo *devinfo,
					 u_int period, u_int offset,
					 u_int ppr_options,
					 u_int type, int paused);
ahd_queue_alg;

/**************************** Target Mode *************************************/
#ifdef AHD_TARGET_MODE
void		ahd_send_lstate_events(struct ahd_softc *,
				       struct ahd_tmode_lstate *);
void		ahd_handle_en_lun(struct ahd_softc *ahd,
				  struct cam_sim *sim, union ccb *ccb);
cam_status	ahd_find_tmode_devs(struct ahd_softc *ahd,
				    struct cam_sim *sim, union ccb *ccb,
				    struct ahd_tmode_tstate **tstate,
				    struct ahd_tmode_lstate **lstate,
				    int notfound_failure);
#ifndef AHD_TMODE_ENABLE
#define AHD_TMODE_ENABLE
#endif
#endif
/******************************* Debug ***************************************/
#ifdef AHD_DEBUG
extern uint32_t ahd_debug;
#define AHD_SHOW_MISC
#define AHD_SHOW_SENSE
#define AHD_SHOW_RECOVERY
#define AHD_DUMP_SEEPROM
#define AHD_SHOW_TERMCTL
#define AHD_SHOW_MEMORY
#define AHD_SHOW_MESSAGES
#define AHD_SHOW_MODEPTR
#define AHD_SHOW_SELTO
#define AHD_SHOW_FIFOS
#define AHD_SHOW_QFULL
#define AHD_SHOW_DV
#define AHD_SHOW_MASKED_ERRORS
#define AHD_SHOW_QUEUE
#define AHD_SHOW_TQIN
#define AHD_SHOW_SG
#define AHD_SHOW_INT_COALESCING
#define AHD_DEBUG_SEQUENCER
#endif
void			ahd_print_devinfo(struct ahd_softc *ahd,
					  struct ahd_devinfo *devinfo);
void			ahd_dump_card_state(struct ahd_softc *ahd);
int			ahd_print_register(const ahd_reg_parse_entry_t *table,
					   u_int num_entries,
					   const char *name,
					   u_int address,
					   u_int value,
					   u_int *cur_column,
					   u_int wrap_point);
#endif /* _AIC79XX_H_ */