#ifndef _NJSC32VAR_H_
#define _NJSC32VAR_H_
typedef unsigned njsc32_model_t;
#define NJSC32_MODEL_MASK 0xff
#define NJSC32_MODEL_INVALID 0
#define NJSC32_MODEL_32BI 1
#define NJSC32_MODEL_32UDE 2
#define NJSC32_FLAG_DUALEDGE 0x100
#define NJSC32_SEL_TIMEOUT_TIME 20000
#define NJSC32_ARBITRATION_RETRY_TIME 4
#define NJSC32_REQ_TIMEOUT 10000
#define NJSC32_RESET_HOLD_TIME 26
#ifdef NJSC32_AUTOPARAM
#define NJSC32_NUM_CMD 14
#else
#define NJSC32_NUM_CMD 15
#endif
#define NJSC32_NUM_SG 17
struct njsc32_dma_page {
struct njsc32_sgtable dp_sg[NJSC32_NUM_CMD][NJSC32_NUM_SG];
#define NJSC32_SIZE_SGT \
(sizeof(struct njsc32_sgtable) * NJSC32_NUM_SG)
#ifdef NJSC32_AUTOPARAM
struct njsc32_autoparam dp_ap;
#endif
};
struct njsc32_cmd {
TAILQ_ENTRY(njsc32_cmd) c_q;
struct njsc32_softc *c_sc;
struct scsipi_xfer *c_xs;
struct njsc32_target *c_target;
struct njsc32_lu *c_lu;
u_int32_t c_datacnt;
int c_flags;
#define NJSC32_CMD_DMA_MAPPED 0x01
#define NJSC32_CMD_TAGGED 0x02
#define NJSC32_CMD_TAGGED_HEAD 0x04
u_int32_t c_dp_cur;
u_int32_t c_dp_saved;
u_int32_t c_dp_max;
unsigned c_sgoffset;
u_int32_t c_sgfixcnt;
u_int8_t c_msg_identify;
u_int16_t c_xferctl;
u_int32_t c_sgtdmaaddr;
struct njsc32_sgtable *c_sgt;
bus_addr_t c_sgt_dma;
#define NJSC32_CMD_DMAADDR_SGT(cmd, n) \
((cmd)->c_sgt_dma + sizeof(struct njsc32_sgtable) * (n))
bus_dmamap_t c_dmamap_xfer;
};
#define NJSC32_MAX_XFER ((NJSC32_NUM_SG - 1) << PGSHIFT)
struct njsc32_softc {
device_t sc_dev;
njsc32_model_t sc_model;
int sc_clk;
#define NJSC32_CLK_40M NJSC32_CLOCK_DIV_4
#define NJSC32_CLK_20M NJSC32_CLOCK_DIV_2
#define NJSC32_CLK_PCI_33M NJSC32_CLOCK_PCICLK
bus_space_tag_t sc_regt;
bus_space_handle_t sc_regh;
unsigned sc_flags;
#define NJSC32_IO_MAPPED 0x00000001
#define NJSC32_MEM_MAPPED 0x00000002
#define NJSC32_CMDPG_MAPPED 0x00000004
#define NJSC32_CANNOT_SUPPLY_TERMPWR 0x00000100
enum njsc32_stat {
NJSC32_STAT_IDLE,
NJSC32_STAT_ARBIT,
NJSC32_STAT_CONNECT,
NJSC32_STAT_RESEL,
NJSC32_STAT_RESEL_LUN,
NJSC32_STAT_RECONNECT,
NJSC32_STAT_RESET,
NJSC32_STAT_RESET1,
NJSC32_STAT_RESET2,
NJSC32_STAT_DETACH
} sc_stat;
void *sc_ih;
bus_dma_tag_t sc_dmat;
struct njsc32_dma_page *sc_cmdpg;
#if 0
bus_addr_t sc_cmdpg_dma;
#endif
bus_dma_segment_t sc_cmdpg_seg;
bus_dmamap_t sc_dmamap_cmdpg;
int sc_cmdpg_nsegs;
#ifdef NJSC32_AUTOPARAM
u_int32_t sc_ap_dma;
#endif
struct callout sc_callout;
struct njsc32_cmd sc_cmds[NJSC32_NUM_CMD];
TAILQ_HEAD(njsc32_cmd_head, njsc32_cmd)
sc_freecmd,
sc_reqcmd;
struct njsc32_cmd *sc_curcmd;
int sc_ncmd;
int sc_nusedcmds;
int sc_reselid, sc_resellun;
#define NJSC32_MSGIN_LEN 20
u_int8_t sc_msginbuf[NJSC32_MSGIN_LEN];
int sc_msgincnt;
#define NJSC32_MSGOUT_LEN 16
u_int8_t sc_msgout[NJSC32_MSGOUT_LEN];
size_t sc_msgoutlen;
size_t sc_msgoutidx;
const struct njsc32_sync_param {
u_int8_t sp_period;
u_int8_t sp_ackw;
u_int8_t sp_sample;
} *sc_synct;
int sc_sync_max;
device_t sc_scsi;
struct scsipi_adapter sc_adapter;
struct scsipi_channel sc_channel;
struct njsc32_target {
enum njsc32_tarst {
NJSC32_TARST_DONE,
NJSC32_TARST_INIT,
NJSC32_TARST_DE,
NJSC32_TARST_WDTR,
NJSC32_TARST_SDTR,
NJSC32_TARST_ASYNC
} t_state;
int t_flags;
#define NJSC32_TARF_TAG 0x0001
#define NJSC32_TARF_SYNC 0x0002
#define NJSC32_TARF_DE 0x0004
int t_syncperiod;
int t_syncoffset;
u_int8_t t_sync;
u_int8_t t_ackwidth;
u_int8_t t_targetid;
u_int8_t t_sample;
u_int16_t t_xferctl;
struct njsc32_lu {
struct njsc32_cmd *lu_cmd;
struct njsc32_cmd_head lu_q;
} t_lus[NJSC32_NLU];
} sc_targets[NJSC32_MAX_TARGET_ID + 1];
};
#ifdef _KERNEL
void njsc32_attach(struct njsc32_softc *);
int njsc32_detach(struct njsc32_softc *, int);
int njsc32_intr(void *);
#endif
#endif