Home | History | Annotate | Line # | Download | only in ic
oosiopvar.h revision 1.4.56.1
      1  1.4.56.1       ad /* $NetBSD: oosiopvar.h,v 1.4.56.1 2007/12/26 19:46:20 ad Exp $ */
      2       1.1  tsutsui 
      3       1.1  tsutsui /*
      4       1.1  tsutsui  * Copyright (c) 2001 Shuichiro URATA.  All rights reserved.
      5       1.1  tsutsui  *
      6       1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
      7       1.1  tsutsui  * modification, are permitted provided that the following conditions
      8       1.1  tsutsui  * are met:
      9       1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     10       1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     11       1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     13       1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     14       1.1  tsutsui  * 3. The name of the author may not be used to endorse or promote products
     15       1.1  tsutsui  *    derived from this software without specific prior written permission.
     16       1.1  tsutsui  *
     17       1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18       1.1  tsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19       1.1  tsutsui  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20       1.1  tsutsui  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21       1.1  tsutsui  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22       1.1  tsutsui  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23       1.1  tsutsui  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24       1.1  tsutsui  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25       1.1  tsutsui  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26       1.1  tsutsui  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27       1.1  tsutsui  */
     28       1.1  tsutsui 
     29       1.1  tsutsui #define	OOSIOP_NTGT	8		/* Max targets */
     30       1.1  tsutsui #define	OOSIOP_NCB	32		/* Initial command buffers */
     31       1.1  tsutsui #define	OOSIOP_NSG	(MIN(btoc(MAXPHYS) + 1, 32)) /* Max S/G operation */
     32       1.1  tsutsui #define	OOSIOP_MAX_XFER	ctob(OOSIOP_NSG - 1)
     33       1.1  tsutsui 
     34       1.1  tsutsui struct oosiop_xfer {
     35       1.1  tsutsui 	/* script for scatter/gather DMA (move*nsg+jump) */
     36       1.3  tsutsui 	uint32_t datain_scr[(OOSIOP_NSG + 1) * 2];
     37       1.3  tsutsui 	uint32_t dataout_scr[(OOSIOP_NSG + 1) * 2];
     38       1.1  tsutsui 
     39       1.3  tsutsui 	uint8_t msgin[8];
     40       1.3  tsutsui 	uint8_t msgout[8];
     41       1.3  tsutsui 	uint8_t status;
     42       1.3  tsutsui 	uint8_t pad[7];
     43  1.4.56.1       ad } __packed;
     44       1.1  tsutsui 
     45       1.1  tsutsui #define	SCSI_OOSIOP_NOSTATUS	0xff	/* device didn't report status */
     46       1.1  tsutsui 
     47       1.1  tsutsui #define	OOSIOP_XFEROFF(x)	offsetof(struct oosiop_xfer, x)
     48       1.1  tsutsui #define	OOSIOP_DINSCROFF	OOSIOP_XFEROFF(datain_scr[0])
     49       1.1  tsutsui #define	OOSIOP_DOUTSCROFF	OOSIOP_XFEROFF(dataout_scr[0])
     50       1.1  tsutsui #define	OOSIOP_MSGINOFF		OOSIOP_XFEROFF(msgin[0])
     51       1.1  tsutsui #define	OOSIOP_MSGOUTOFF	OOSIOP_XFEROFF(msgout[0])
     52       1.1  tsutsui 
     53       1.1  tsutsui #define	OOSIOP_XFERSCR_SYNC(sc, cb, ops)				\
     54       1.1  tsutsui 	bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_DINSCROFF,	\
     55       1.1  tsutsui 	    OOSIOP_MSGINOFF - OOSIOP_DINSCROFF, (ops))
     56       1.1  tsutsui #define	OOSIOP_DINSCR_SYNC(sc, cb, ops)					\
     57       1.1  tsutsui 	bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_DINSCROFF,	\
     58       1.1  tsutsui 	    OOSIOP_DOUTSCROFF - OOSIOP_DINSCROFF, (ops))
     59       1.1  tsutsui #define	OOSIOP_DOUTSCR_SYNC(sc, cb, ops)				\
     60       1.1  tsutsui 	bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_DOUTSCROFF,\
     61       1.1  tsutsui 	    OOSIOP_MSGINOFF - OOSIOP_DOUTSCROFF, (ops))
     62       1.1  tsutsui #define	OOSIOP_XFERMSG_SYNC(sc, cb, ops)				\
     63       1.1  tsutsui 	bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_MSGINOFF,	\
     64       1.1  tsutsui 	    sizeof(struct oosiop_xfer) - OOSIOP_MSGINOFF, (ops))
     65       1.1  tsutsui 
     66       1.1  tsutsui #define	OOSIOP_SCRIPT_SYNC(sc, ops)					\
     67       1.1  tsutsui 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_scrdma,			\
     68       1.1  tsutsui 	    0, sizeof(oosiop_script), (ops))
     69       1.1  tsutsui 
     70       1.1  tsutsui struct oosiop_cb {
     71       1.1  tsutsui 	TAILQ_ENTRY(oosiop_cb) chain;
     72       1.1  tsutsui 
     73       1.1  tsutsui 	struct scsipi_xfer *xs;		/* SCSI xfer ctrl block from above */
     74       1.1  tsutsui 	int flags;
     75       1.1  tsutsui 	int id;				/* target scsi id */
     76       1.1  tsutsui 	int lun;			/* target lun */
     77       1.1  tsutsui 
     78       1.1  tsutsui 	bus_dmamap_t cmddma;		/* DMA map for command out */
     79       1.1  tsutsui 	bus_dmamap_t datadma;		/* DMA map for data I/O */
     80       1.1  tsutsui 	bus_dmamap_t xferdma;		/* DMA map for xfer block */
     81       1.1  tsutsui 
     82       1.1  tsutsui 	int curdp;			/* current data pointer */
     83       1.1  tsutsui 	int savedp;			/* saved data pointer */
     84       1.1  tsutsui 	int msgoutlen;
     85       1.1  tsutsui 
     86       1.1  tsutsui 	struct oosiop_xfer *xfer;	/* DMA xfer block */
     87       1.1  tsutsui };
     88       1.1  tsutsui 
     89       1.1  tsutsui /* oosiop_cb flags */
     90       1.1  tsutsui #define	CBF_SELTOUT	0x01	/* Selection timeout */
     91       1.1  tsutsui #define	CBF_TIMEOUT	0x02	/* Command timeout */
     92       1.1  tsutsui 
     93       1.1  tsutsui TAILQ_HEAD(oosiop_cb_queue, oosiop_cb);
     94       1.1  tsutsui 
     95       1.1  tsutsui struct oosiop_target {
     96       1.1  tsutsui 	struct oosiop_cb *nexus;
     97       1.1  tsutsui 	int flags;
     98       1.3  tsutsui 	uint8_t scf;		/* synchronous clock divisor */
     99       1.3  tsutsui 	uint8_t sxfer;		/* synchronous period and offset */
    100       1.1  tsutsui };
    101       1.1  tsutsui 
    102       1.1  tsutsui /* target flags */
    103       1.1  tsutsui #define	TGTF_SYNCNEG	0x01	/* Trigger synchronous negotiation */
    104       1.1  tsutsui #define	TGTF_WAITSDTR	0x02	/* Waiting SDTR from target */
    105       1.1  tsutsui 
    106       1.1  tsutsui struct oosiop_softc {
    107       1.1  tsutsui 	struct device sc_dev;
    108       1.1  tsutsui 
    109       1.1  tsutsui 	bus_space_tag_t	sc_bst;		/* bus space tag */
    110       1.1  tsutsui 	bus_space_handle_t sc_bsh;	/* bus space handle */
    111       1.1  tsutsui 
    112       1.2      wiz 	bus_dma_tag_t sc_dmat;		/* bus DMA tag */
    113       1.2      wiz 	bus_dmamap_t sc_scrdma;		/* script DMA map */
    114       1.1  tsutsui 
    115       1.2      wiz 	bus_addr_t sc_scrbase;		/* script DMA base address */
    116       1.3  tsutsui 	uint32_t *sc_scr;		/* ptr to script memory */
    117       1.1  tsutsui 
    118       1.1  tsutsui 	int sc_chip;			/* 700 or 700-66 */
    119       1.1  tsutsui #define	OOSIOP_700	0
    120       1.1  tsutsui #define	OOSIOP_700_66	1
    121       1.1  tsutsui 
    122       1.1  tsutsui 	int		sc_id;		/* SCSI ID of this interface */
    123       1.1  tsutsui 	int		sc_freq;	/* SCLK frequency */
    124       1.1  tsutsui 	int		sc_ccf;		/* asynchronous divisor (*10) */
    125       1.3  tsutsui 	uint8_t		sc_dcntl;
    126       1.3  tsutsui 	uint8_t		sc_minperiod;
    127       1.1  tsutsui 
    128       1.1  tsutsui 	struct oosiop_target sc_tgt[OOSIOP_NTGT];
    129       1.1  tsutsui 
    130       1.1  tsutsui 	struct scsipi_adapter sc_adapter;
    131       1.1  tsutsui 	struct scsipi_channel sc_channel;
    132       1.1  tsutsui 
    133       1.1  tsutsui 	/* Lists of command blocks */
    134       1.1  tsutsui 	struct oosiop_cb_queue sc_free_cb;
    135       1.1  tsutsui 	struct oosiop_cb_queue sc_cbq;	/* command issue queue */
    136       1.1  tsutsui 	struct oosiop_cb *sc_curcb;	/* current command */
    137       1.1  tsutsui 	struct oosiop_cb *sc_lastcb;	/* last activated command */
    138       1.1  tsutsui 
    139       1.1  tsutsui 	bus_addr_t sc_reselbuf;		/* msgin buffer for reselection */
    140       1.1  tsutsui 	int sc_resid;			/* reselected target id */
    141       1.1  tsutsui 
    142       1.1  tsutsui 	int sc_active;
    143       1.1  tsutsui 	int sc_nextdsp;
    144       1.1  tsutsui };
    145       1.1  tsutsui 
    146       1.1  tsutsui #define	oosiop_read_1(sc, addr)						\
    147       1.1  tsutsui     bus_space_read_1((sc)->sc_bst, (sc)->sc_bsh, (addr))
    148       1.1  tsutsui #define	oosiop_write_1(sc, addr, data)					\
    149       1.1  tsutsui     bus_space_write_1((sc)->sc_bst, (sc)->sc_bsh, (addr), (data))
    150       1.1  tsutsui /* XXX byte swapping should be handled by MD bus_space(9)? */
    151       1.1  tsutsui #define	oosiop_read_4(sc, addr)						\
    152       1.1  tsutsui     le32toh(bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (addr)))
    153       1.1  tsutsui #define	oosiop_write_4(sc, addr, data)					\
    154       1.1  tsutsui     bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (addr), htole32(data))
    155       1.1  tsutsui 
    156       1.1  tsutsui void oosiop_attach(struct oosiop_softc *);
    157       1.1  tsutsui int oosiop_intr(struct oosiop_softc *);
    158