siopvar.h revision 1.25.10.2       1  1.25.10.2    yamt /*	$NetBSD: siopvar.h,v 1.25.10.2 2009/09/16 13:37:48 yamt Exp $	*/
      2        1.1  bouyer 
      3        1.1  bouyer /*
      4        1.1  bouyer  * Copyright (c) 2000 Manuel Bouyer.
      5        1.1  bouyer  *
      6        1.1  bouyer  * Redistribution and use in source and binary forms, with or without
      7        1.1  bouyer  * modification, are permitted provided that the following conditions
      8        1.1  bouyer  * are met:
      9        1.1  bouyer  * 1. Redistributions of source code must retain the above copyright
     10        1.1  bouyer  *    notice, this list of conditions and the following disclaimer.
     11        1.1  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12        1.1  bouyer  *    notice, this list of conditions and the following disclaimer in the
     13        1.1  bouyer  *    documentation and/or other materials provided with the distribution.
     14        1.1  bouyer  * 3. All advertising materials mentioning features or use of this software
     15        1.1  bouyer  *    must display the following acknowledgement:
     16       1.18  bouyer  *	This product includes software developed by Manuel Bouyer.
     17        1.3  bouyer  * 4. The name of the author may not be used to endorse or promote products
     18        1.3  bouyer  *    derived from this software without specific prior written permission.
     19        1.1  bouyer  *
     20        1.5  bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21        1.5  bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22        1.5  bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23       1.21   perry  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24        1.5  bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25        1.5  bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26        1.5  bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27        1.5  bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28        1.5  bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29        1.5  bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30        1.1  bouyer  *
     31        1.1  bouyer  */
     32        1.1  bouyer 
     33        1.1  bouyer /* structure and definitions for the siop driver */
     34        1.1  bouyer 
     35       1.17  bouyer /* Number of tag */
     36       1.17  bouyer #define SIOP_NTAG 16
     37       1.17  bouyer 
     38       1.17  bouyer /*
     39       1.17  bouyer  * xfer description of the script: tables and reselect script
     40       1.17  bouyer  * In struct siop_common_cmd siop_xfer will point to this.
     41       1.17  bouyer  */
     42       1.17  bouyer struct siop_xfer {
     43       1.17  bouyer 	struct siop_common_xfer siop_tables;
     44  1.25.10.2    yamt 	/* uint32_t resel[sizeof(load_dsa) / sizeof(load_dsa[0])]; */
     45  1.25.10.2    yamt 	uint32_t resel[25];
     46       1.25   perry } __packed;
     47       1.17  bouyer 
     48       1.17  bouyer /*
     49       1.19     wiz  * This describes a command handled by the SCSI controller
     50       1.17  bouyer  * These are chained in either a free list or a active list
     51       1.17  bouyer  * We have one queue per target
     52       1.17  bouyer  */
     53       1.17  bouyer 
     54       1.17  bouyer struct siop_cmd {
     55       1.17  bouyer 	TAILQ_ENTRY (siop_cmd) next;
     56       1.17  bouyer 	struct siop_common_cmd cmd_c;
     57       1.17  bouyer 	struct siop_cbd *siop_cbdp; /* pointer to our siop_cbd */
     58       1.17  bouyer 	int reselslot;
     59  1.25.10.2    yamt 	uint32_t saved_offset; /* offset in table after disc without sdp */
     60       1.17  bouyer };
     61       1.17  bouyer #define cmd_tables cmd_c.siop_tables
     62       1.17  bouyer 
     63       1.17  bouyer /* command block descriptors: an array of siop_cmd + an array of siop_xfer */
     64       1.17  bouyer struct siop_cbd {
     65       1.17  bouyer 	TAILQ_ENTRY (siop_cbd) next;
     66       1.17  bouyer 	struct siop_cmd *cmds;
     67       1.17  bouyer 	struct siop_xfer *xfers;
     68       1.17  bouyer 	bus_dmamap_t xferdma; /* DMA map for this block of xfers */
     69       1.17  bouyer };
     70       1.17  bouyer 
     71       1.17  bouyer /* per-tag struct */
     72       1.17  bouyer struct siop_tag {
     73       1.17  bouyer 	struct siop_cmd *active; /* active command */
     74       1.17  bouyer 	u_int reseloff;
     75       1.17  bouyer };
     76       1.17  bouyer 
     77       1.17  bouyer /* per lun struct */
     78       1.17  bouyer struct siop_lun {
     79       1.17  bouyer 	struct siop_tag siop_tag[SIOP_NTAG]; /* tag array */
     80       1.17  bouyer 	int lun_flags; /* per-lun flags, none currently */
     81       1.17  bouyer 	u_int reseloff;
     82       1.17  bouyer };
     83       1.17  bouyer 
     84       1.17  bouyer /*
     85       1.17  bouyer  * per target struct; siop_common_cmd->target and siop_common_softc->targets[]
     86       1.17  bouyer  * will point to this
     87       1.17  bouyer  */
     88       1.17  bouyer struct siop_target {
     89       1.17  bouyer 	struct siop_common_target target_c;
     90       1.17  bouyer 	struct siop_lun *siop_lun[8]; /* per-lun state */
     91       1.17  bouyer 	u_int reseloff;
     92       1.17  bouyer 	struct siop_lunsw *lunsw;
     93       1.17  bouyer };
     94       1.17  bouyer 
     95       1.17  bouyer struct siop_lunsw {
     96       1.17  bouyer 	TAILQ_ENTRY (siop_lunsw) next;
     97  1.25.10.2    yamt 	uint32_t lunsw_off; /* offset of this lun sw, from sc_scriptaddr*/
     98  1.25.10.2    yamt 	uint32_t lunsw_size; /* size of this lun sw */
     99       1.17  bouyer };
    100       1.17  bouyer 
    101       1.24   perry static __inline void siop_table_sync(struct siop_cmd *, int);
    102       1.24   perry static __inline void
    103  1.25.10.1    yamt siop_table_sync(struct siop_cmd *siop_cmd, int ops)
    104       1.17  bouyer {
    105       1.17  bouyer 	struct siop_common_softc *sc  = siop_cmd->cmd_c.siop_sc;
    106       1.17  bouyer 	bus_addr_t offset;
    107       1.17  bouyer 
    108       1.17  bouyer 	offset = siop_cmd->cmd_c.dsa -
    109       1.17  bouyer 	    siop_cmd->siop_cbdp->xferdma->dm_segs[0].ds_addr;
    110       1.17  bouyer 	bus_dmamap_sync(sc->sc_dmat, siop_cmd->siop_cbdp->xferdma, offset,
    111       1.17  bouyer 	    sizeof(struct siop_xfer), ops);
    112       1.17  bouyer }
    113       1.17  bouyer 
    114       1.17  bouyer 
    115        1.1  bouyer TAILQ_HEAD(cmd_list, siop_cmd);
    116        1.6  bouyer TAILQ_HEAD(cbd_list, siop_cbd);
    117       1.11  bouyer TAILQ_HEAD(lunsw_list, siop_lunsw);
    118        1.1  bouyer 
    119       1.17  bouyer 
    120        1.1  bouyer /* Driver internal state */
    121        1.1  bouyer struct siop_softc {
    122       1.17  bouyer 	struct siop_common_softc sc_c;
    123       1.10  bouyer 	int sc_currschedslot;		/* current scheduler slot */
    124        1.6  bouyer 	struct cbd_list cmds;		/* list of command block descriptors */
    125        1.1  bouyer 	struct cmd_list free_list;	/* cmd descr free list */
    126       1.11  bouyer 	struct lunsw_list lunsw_list;	/* lunsw free list */
    127  1.25.10.2    yamt 	uint32_t script_free_lo;	/* free ram offset from sc_scriptaddr */
    128  1.25.10.2    yamt 	uint32_t script_free_hi;	/* free ram offset from sc_scriptaddr */
    129       1.12  bouyer 	int sc_ntargets;		/* number of known targets */
    130  1.25.10.2    yamt 	uint32_t sc_flags;
    131        1.1  bouyer };
    132       1.17  bouyer 
    133        1.1  bouyer /* defs for sc_flags */
    134       1.19     wiz #define SCF_CHAN_NOSLOT	0x0001		/* channel out of scheduler slot */
    135        1.1  bouyer 
    136       1.20   perry void    siop_attach(struct siop_softc *);
    137       1.20   perry int	siop_intr(void *);
    138       1.20   perry void	siop_add_dev(struct siop_softc *, int, int);
    139       1.20   perry void	siop_del_dev(struct siop_softc *, int, int);
    140