#if defined(sun2) || defined(__sparc__)
# define SUNSCPAL_USE_BUS_SPACE
#endif
#if defined(sun2) || defined(__sparc__)
#define SUNSCPAL_USE_BUS_DMA
#endif
#ifdef SUNSCPAL_USE_BUS_SPACE
# include <sys/bus.h>
#define SUNSCPAL_READ_1(sc, reg) bus_space_read_1(sc->sunscpal_regt, \
sc->sunscpal_regh, sc->reg)
#define SUNSCPAL_WRITE_1(sc, reg, val) bus_space_write_1(sc->sunscpal_regt, \
sc->sunscpal_regh, sc->reg, val)
#define SUNSCPAL_READ_2(sc, reg) bus_space_read_2(sc->sunscpal_regt, \
sc->sunscpal_regh, sc->reg)
#define SUNSCPAL_WRITE_2(sc, reg, val) bus_space_write_2(sc->sunscpal_regt, \
sc->sunscpal_regh, sc->reg, val)
#else
# define SUNSCPAL_READ_1(sc, reg) (*sc->reg)
# define SUNSCPAL_WRITE_1(sc, reg, val) do { *(sc->reg) = val; } while(0)
# define SUNSCPAL_READ_2 SUNSCPAL_READ_1
# define SUNSCPAL_WRITE_2 SUNSCPAL_WRITE_1
#endif
#define SUNSCPAL_CLR_INTR(sc) do { SUNSCPAL_READ_2(sc, sunscpal_dma_count); SUNSCPAL_READ_2(sc, sunscpal_icr); } while(0)
#define SUNSCPAL_BUSY(sc) (SUNSCPAL_READ_2(sc, sunscpal_icr) & SUNSCPAL_ICR_BUSY)
#define SUNSCPAL_PHASE_DATA_IN (SUNSCPAL_ICR_INPUT_OUTPUT)
#define SUNSCPAL_PHASE_DATA_OUT (0)
#define SUNSCPAL_PHASE_COMMAND (SUNSCPAL_ICR_COMMAND_DATA)
#define SUNSCPAL_PHASE_STATUS (SUNSCPAL_ICR_COMMAND_DATA | \
SUNSCPAL_ICR_INPUT_OUTPUT)
#define SUNSCPAL_PHASE_MSG_IN (SUNSCPAL_ICR_MESSAGE | \
SUNSCPAL_ICR_COMMAND_DATA | \
SUNSCPAL_ICR_INPUT_OUTPUT)
#define SUNSCPAL_PHASE_MSG_OUT (SUNSCPAL_ICR_MESSAGE | \
SUNSCPAL_ICR_COMMAND_DATA)
#define SUNSCPAL_PHASE_UNSPEC1 (SUNSCPAL_ICR_MESSAGE | \
SUNSCPAL_ICR_INPUT_OUTPUT)
#define SUNSCPAL_PHASE_UNSPEC2 (SUNSCPAL_ICR_MESSAGE)
#define SUNSCPAL_BYTE_READ(sc, phase) (((phase) & SUNSCPAL_ICR_COMMAND_DATA) ? \
SUNSCPAL_READ_1(sc, sunscpal_cmd_stat) : \
SUNSCPAL_READ_1(sc, sunscpal_data))
#define SUNSCPAL_BYTE_WRITE(sc, phase, b) do { \
if ((phase) & SUNSCPAL_ICR_COMMAND_DATA) { \
SUNSCPAL_WRITE_1(sc, sunscpal_cmd_stat, b); \
} else { \
SUNSCPAL_WRITE_1(sc, sunscpal_data, b); \
} \
} while(0)
#define SUNSCPAL_ICR_PHASE_MASK (SUNSCPAL_ICR_MESSAGE | \
SUNSCPAL_ICR_COMMAND_DATA | \
SUNSCPAL_ICR_INPUT_OUTPUT)
#define SUNSCPAL_BUS_PHASE(icr) ((icr) & SUNSCPAL_ICR_PHASE_MASK)
#define SUNSCPAL_PHASE_INVALID SUNSCPAL_PHASE_UNSPEC1
#define SUNSCPAL_MAX_DMA_LEN 0xE000
#ifdef SUNSCPAL_USE_BUS_DMA
struct sunscpal_dma_handle {
int dh_flags;
#define SUNSCDH_BUSY 0x01
uint8_t * dh_mapaddr;
int dh_maplen;
bus_dmamap_t dh_dmamap;
#define dh_dvma dh_dmamap->dm_segs[0].ds_addr
};
typedef struct sunscpal_dma_handle *sunscpal_dma_handle_t;
#else
typedef void *sunscpal_dma_handle_t;
#endif
struct sunscpal_req {
struct scsipi_xfer *sr_xs;
int sr_target, sr_lun;
sunscpal_dma_handle_t sr_dma_hand;
uint8_t *sr_dataptr;
int sr_datalen;
int sr_flags;
#define SR_IMMED 1
#define SR_OVERDUE 2
#define SR_ERROR 4
int sr_status;
};
#define SUNSCPAL_OPENINGS 16
struct sunscpal_softc {
device_t sc_dev;
struct scsipi_adapter sc_adapter;
struct scsipi_channel sc_channel;
#ifdef SUNSCPAL_USE_BUS_SPACE
bus_space_tag_t sunscpal_regt;
bus_space_handle_t sunscpal_regh;
bus_size_t sunscpal_data;
bus_size_t sunscpal_cmd_stat;
bus_size_t sunscpal_icr;
bus_size_t sunscpal_dma_addr_h;
bus_size_t sunscpal_dma_addr_l;
bus_size_t sunscpal_dma_count;
bus_size_t sunscpal_intvec;
#else
volatile uint8_t *sunscpal_data;
volatile uint8_t *sunscpal_cmd_stat;
volatile uint16_t *sunscpal_icr;
volatile uint16_t *sunscpal_dma_addr_h;
volatile uint16_t *sunscpal_dma_addr_l;
volatile uint16_t *sunscpal_dma_count;
volatile uint8_t *sunscpal_intvec;
#endif
#ifdef SUNSCPAL_USE_BUS_DMA
bus_dma_tag_t sunscpal_dmat;
#endif
sunscpal_dma_handle_t sc_dma_handles;
#ifndef SUNSCPAL_USE_BUS_DMA
void (*sc_dma_alloc)(struct sunscpal_softc *);
void (*sc_dma_free)(struct sunscpal_softc *);
void (*sc_dma_setup)(struct sunscpal_softc *);
#endif
void (*sc_intr_on)(struct sunscpal_softc *);
void (*sc_intr_off)(struct sunscpal_softc *);
int sc_flags;
#define SUNSCPAL_DISABLE_DMA 1
int sc_parity_disable;
int sc_min_dma_len;
int sc_state;
#define SUNSCPAL_IDLE 0
#define SUNSCPAL_WORKING 0x01
#define SUNSCPAL_ABORTING 0x02
#define SUNSCPAL_DOINGDMA 0x04
#define SUNSCPAL_DROP_MSGIN 0x10
struct sunscpal_req *sc_current;
uint8_t *sc_dataptr;
int sc_datalen;
int sc_reqlen;
volatile int sc_ncmds;
struct sunscpal_req sc_ring[SUNSCPAL_OPENINGS];
int sc_rr;
struct sunscpal_req *sc_matrix[8][8];
int sc_prevphase;
u_int sc_msgpriq;
u_int sc_msgoutq;
u_int sc_msgout;
#define SEND_DEV_RESET 0x01
#define SEND_PARITY_ERROR 0x02
#define SEND_ABORT 0x04
#define SEND_REJECT 0x08
#define SEND_INIT_DET_ERR 0x10
#define SEND_IDENTIFY 0x20
#define SEND_SDTR 0x40
#define SEND_WDTR 0x80
#define SUNSCPAL_MAX_MSG_LEN 8
uint8_t sc_omess[SUNSCPAL_MAX_MSG_LEN];
uint8_t *sc_omp;
uint8_t sc_imess[SUNSCPAL_MAX_MSG_LEN];
uint8_t *sc_imp;
int sc_rev;
#define SUNSCPAL_VARIANT_501_1006 0
#define SUNSCPAL_VARIANT_501_1045 1
};
void sunscpal_attach(struct sunscpal_softc *, int);
int sunscpal_detach(struct sunscpal_softc *, int);
int sunscpal_intr(void *);
void sunscpal_scsipi_request(struct scsipi_channel *,
scsipi_adapter_req_t, void *);
int sunscpal_pio_in(struct sunscpal_softc *, int, int, uint8_t *);
int sunscpal_pio_out(struct sunscpal_softc *, int, int, uint8_t *);
void sunscpal_init(struct sunscpal_softc *);
#define SUNSCPAL_OPT_NO_PARITY_CHK 0xff
#define SUNSCPAL_OPT_FORCE_POLLING 0x100
#define SUNSCPAL_OPT_DISABLE_DMA 0x200
#ifdef SUNSCPAL_DEBUG
struct sunscpal_softc *sunscpal_debug_sc;
void sunscpal_trace(char *msg, long val);
#define SUNSCPAL_TRACE(msg, val) sunscpal_trace(msg, val)
#else
#define SUNSCPAL_TRACE(msg, val)
#endif