#include <uvm/uvm_extern.h>
#define OOSIOP_NTGT 8
#define OOSIOP_NCB 32
#define OOSIOP_NSG (MIN(atop(MAXPHYS) + 1, 32))
#define OOSIOP_MAX_XFER ptoa(OOSIOP_NSG - 1)
struct oosiop_xfer {
u_int32_t datain_scr[(OOSIOP_NSG + 1) * 2];
u_int32_t dataout_scr[(OOSIOP_NSG + 1) * 2];
u_int8_t msgin[8];
u_int8_t msgout[8];
u_int8_t status;
u_int8_t pad[7];
} __packed;
#define SCSI_OOSIOP_NOSTATUS 0xff
#define OOSIOP_XFEROFF(x) offsetof(struct oosiop_xfer, x)
#define OOSIOP_DINSCROFF OOSIOP_XFEROFF(datain_scr[0])
#define OOSIOP_DOUTSCROFF OOSIOP_XFEROFF(dataout_scr[0])
#define OOSIOP_MSGINOFF OOSIOP_XFEROFF(msgin[0])
#define OOSIOP_MSGOUTOFF OOSIOP_XFEROFF(msgout[0])
#define OOSIOP_XFERSCR_SYNC(sc, cb, ops) \
bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_DINSCROFF, \
OOSIOP_MSGINOFF - OOSIOP_DINSCROFF, (ops))
#define OOSIOP_DINSCR_SYNC(sc, cb, ops) \
bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_DINSCROFF, \
OOSIOP_DOUTSCROFF - OOSIOP_DINSCROFF, (ops))
#define OOSIOP_DOUTSCR_SYNC(sc, cb, ops) \
bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_DOUTSCROFF,\
OOSIOP_MSGINOFF - OOSIOP_DOUTSCROFF, (ops))
#define OOSIOP_XFERMSG_SYNC(sc, cb, ops) \
bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_MSGINOFF, \
sizeof(struct oosiop_xfer) - OOSIOP_MSGINOFF, (ops))
#define OOSIOP_SCRIPT_SYNC(sc, ops) \
bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_scrdma, \
0, sizeof(oosiop_script), (ops))
struct oosiop_cb {
TAILQ_ENTRY(oosiop_cb) chain;
struct scsi_xfer *xs;
int flags;
int id;
int lun;
bus_dmamap_t cmddma;
bus_dmamap_t datadma;
bus_dmamap_t xferdma;
int curdp;
int savedp;
int msgoutlen;
int xsflags;
int datalen;
int cmdlen;
struct oosiop_xfer *xfer;
};
#define CBF_SELTOUT 0x01
#define CBF_TIMEOUT 0x02
#define CBF_AUTOSENSE 0x04
struct oosiop_target {
struct oosiop_cb *nexus;
int flags;
u_int8_t scf;
u_int8_t sxfer;
};
#define TGTF_SYNCNEG 0x01
#define TGTF_WAITSDTR 0x02
struct oosiop_softc {
struct device sc_dev;
bus_space_tag_t sc_bst;
bus_space_handle_t sc_bsh;
bus_dma_tag_t sc_dmat;
bus_dmamap_t sc_scrdma;
bus_addr_t sc_scrbase;
u_int32_t *sc_scr;
int sc_chip;
#define OOSIOP_700 0
#define OOSIOP_700_66 1
int sc_id;
int sc_freq;
int sc_ccf;
u_int8_t sc_dcntl;
u_int8_t sc_minperiod;
struct oosiop_target sc_tgt[OOSIOP_NTGT];
TAILQ_HEAD(oosiop_cb_queue, oosiop_cb) sc_free_cb,
sc_cbq;
struct mutex sc_cb_mtx;
struct scsi_iopool sc_iopool;
struct oosiop_cb *sc_curcb;
struct oosiop_cb *sc_lastcb;
bus_addr_t sc_reselbuf;
int sc_resid;
int sc_active;
int sc_nextdsp;
uint8_t sc_scntl0;
uint8_t sc_dmode;
uint8_t sc_dwt;
uint8_t sc_ctest7;
};
#define oosiop_read_1(sc, addr) \
bus_space_read_1((sc)->sc_bst, (sc)->sc_bsh, (addr))
#define oosiop_write_1(sc, addr, data) \
bus_space_write_1((sc)->sc_bst, (sc)->sc_bsh, (addr), (data))
#define oosiop_read_4(sc, addr) \
letoh32(bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (addr)))
#define oosiop_write_4(sc, addr, data) \
bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (addr), htole32(data))
void oosiop_attach(struct oosiop_softc *);
int oosiop_intr(struct oosiop_softc *);