Home | History | Annotate | Line # | Download | only in ic
esiopvar.h revision 1.7.8.2
      1  1.7.8.2  jdolecek /*	$NetBSD: esiopvar.h,v 1.7.8.2 2002/06/23 17:46:22 jdolecek Exp $	*/
      2  1.7.8.2  jdolecek 
      3  1.7.8.2  jdolecek /*
      4  1.7.8.2  jdolecek  * Copyright (c) 2002 Manuel Bouyer.
      5  1.7.8.2  jdolecek  *
      6  1.7.8.2  jdolecek  * Redistribution and use in source and binary forms, with or without
      7  1.7.8.2  jdolecek  * modification, are permitted provided that the following conditions
      8  1.7.8.2  jdolecek  * are met:
      9  1.7.8.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     10  1.7.8.2  jdolecek  *    notice, this list of conditions and the following disclaimer.
     11  1.7.8.2  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.7.8.2  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     13  1.7.8.2  jdolecek  *    documentation and/or other materials provided with the distribution.
     14  1.7.8.2  jdolecek  * 3. All advertising materials mentioning features or use of this software
     15  1.7.8.2  jdolecek  *    must display the following acknowledgement:
     16  1.7.8.2  jdolecek  *	This product includes software developed by Manuel Bouyer.
     17  1.7.8.2  jdolecek  * 4. The name of the author may not be used to endorse or promote products
     18  1.7.8.2  jdolecek  *    derived from this software without specific prior written permission.
     19  1.7.8.2  jdolecek  *
     20  1.7.8.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.7.8.2  jdolecek  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.7.8.2  jdolecek  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.7.8.2  jdolecek  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.7.8.2  jdolecek  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.7.8.2  jdolecek  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.7.8.2  jdolecek  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.7.8.2  jdolecek  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.7.8.2  jdolecek  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.7.8.2  jdolecek  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.7.8.2  jdolecek  *
     31  1.7.8.2  jdolecek  */
     32  1.7.8.2  jdolecek 
     33  1.7.8.2  jdolecek /* structure and definitions for the siop driver */
     34  1.7.8.2  jdolecek 
     35  1.7.8.2  jdolecek /* Number of tag */
     36  1.7.8.2  jdolecek #define ESIOP_NTAG 256
     37  1.7.8.2  jdolecek 
     38  1.7.8.2  jdolecek /*
     39  1.7.8.2  jdolecek  * description of a command scheduler slot. The script uses a ring of
     40  1.7.8.2  jdolecek  * A_ncmd_slots of this.
     41  1.7.8.2  jdolecek  */
     42  1.7.8.2  jdolecek struct esiop_slot {
     43  1.7.8.2  jdolecek 	u_int32_t dsa; /* DSA of the xfer. The first 2 bits holds flags */
     44  1.7.8.2  jdolecek } __attribute__((__packed__));
     45  1.7.8.2  jdolecek 
     46  1.7.8.2  jdolecek #define CMD_SLOTSIZE (sizeof(struct esiop_slot) / sizeof(u_int32_t))
     47  1.7.8.2  jdolecek 
     48  1.7.8.2  jdolecek /*
     49  1.7.8.2  jdolecek  * xfer description of the script: tables and reselect script
     50  1.7.8.2  jdolecek  * In struct siop_common_cmd siop_xfer will point to this.
     51  1.7.8.2  jdolecek  * If you change this don't forget to update o_cmd_* and cmd_slot_size in script
     52  1.7.8.2  jdolecek  */
     53  1.7.8.2  jdolecek struct esiop_xfer {
     54  1.7.8.2  jdolecek 	struct siop_common_xfer siop_tables;
     55  1.7.8.2  jdolecek 	u_int32_t tlq; /* target/lun/tag loaded in scratchC by script */
     56  1.7.8.2  jdolecek } __attribute__((__packed__));
     57  1.7.8.2  jdolecek 
     58  1.7.8.2  jdolecek /*
     59  1.7.8.2  jdolecek  * This decribes a command handled by the SCSI controller
     60  1.7.8.2  jdolecek  * These are chained in either a free list or a active list
     61  1.7.8.2  jdolecek  * We have one queue per target
     62  1.7.8.2  jdolecek  */
     63  1.7.8.2  jdolecek 
     64  1.7.8.2  jdolecek struct esiop_cmd {
     65  1.7.8.2  jdolecek 	TAILQ_ENTRY (esiop_cmd) next;
     66  1.7.8.2  jdolecek 	struct siop_common_cmd cmd_c;
     67  1.7.8.2  jdolecek 	struct esiop_cbd *esiop_cbdp; /* pointer to our siop_cbd */
     68  1.7.8.2  jdolecek };
     69  1.7.8.2  jdolecek #define cmd_tables cmd_c.siop_tables
     70  1.7.8.2  jdolecek 
     71  1.7.8.2  jdolecek /* command block descriptors: an array of siop_cmd + an array of siop_xfer */
     72  1.7.8.2  jdolecek struct esiop_cbd {
     73  1.7.8.2  jdolecek 	TAILQ_ENTRY (esiop_cbd) next;
     74  1.7.8.2  jdolecek 	struct esiop_cmd *cmds;
     75  1.7.8.2  jdolecek 	struct esiop_xfer *xfers;
     76  1.7.8.2  jdolecek 	bus_dmamap_t xferdma; /* DMA map for this block of xfers */
     77  1.7.8.2  jdolecek };
     78  1.7.8.2  jdolecek 
     79  1.7.8.2  jdolecek TAILQ_HEAD(cmd_list, esiop_cmd);
     80  1.7.8.2  jdolecek TAILQ_HEAD(cbd_list, esiop_cbd);
     81  1.7.8.2  jdolecek 
     82  1.7.8.2  jdolecek /* DSA table descriptor for tags. Free tables are in a list */
     83  1.7.8.2  jdolecek struct esiop_dsatbl {
     84  1.7.8.2  jdolecek 	TAILQ_ENTRY (esiop_dsatbl) next;
     85  1.7.8.2  jdolecek 	u_int32_t *tbl; /* the table itself */
     86  1.7.8.2  jdolecek 	u_int32_t tbl_dsa; /* DSA of base of this table */
     87  1.7.8.2  jdolecek 	bus_addr_t tbl_offset; /* offset of this table in the map */
     88  1.7.8.2  jdolecek 	struct esiop_dsatblblk *tblblk; /* pointer back to our block */
     89  1.7.8.2  jdolecek };
     90  1.7.8.2  jdolecek 
     91  1.7.8.2  jdolecek /* DSA table block descriptor. */
     92  1.7.8.2  jdolecek struct esiop_dsatblblk {
     93  1.7.8.2  jdolecek 	TAILQ_ENTRY (esiop_dsatblblk) next;
     94  1.7.8.2  jdolecek 	bus_dmamap_t blkmap; /* DMA map of this block */
     95  1.7.8.2  jdolecek };
     96  1.7.8.2  jdolecek 
     97  1.7.8.2  jdolecek TAILQ_HEAD(tbl_list, esiop_dsatbl);
     98  1.7.8.2  jdolecek TAILQ_HEAD(tblblk_list, esiop_dsatblblk);
     99  1.7.8.2  jdolecek 
    100  1.7.8.2  jdolecek /* Number of table per block */
    101  1.7.8.2  jdolecek #define ESIOP_NTPB ((PAGE_SIZE) / (sizeof(u_int32_t) * ESIOP_NTAG))
    102  1.7.8.2  jdolecek 
    103  1.7.8.2  jdolecek /* per lun struct */
    104  1.7.8.2  jdolecek struct esiop_lun {
    105  1.7.8.2  jdolecek 	struct esiop_cmd *active; /* active non-tagged command */
    106  1.7.8.2  jdolecek 	struct esiop_cmd *tactive[ESIOP_NTAG]; /* active tagged commands */
    107  1.7.8.2  jdolecek 	int lun_flags; /* per-lun flags */
    108  1.7.8.2  jdolecek 	struct esiop_dsatbl *lun_tagtbl; /* the tag DSA table */
    109  1.7.8.2  jdolecek };
    110  1.7.8.2  jdolecek 
    111  1.7.8.2  jdolecek /*
    112  1.7.8.2  jdolecek  * per target struct; siop_common_cmd->target and siop_common_softc->targets[]
    113  1.7.8.2  jdolecek  * will point to this
    114  1.7.8.2  jdolecek  */
    115  1.7.8.2  jdolecek struct esiop_target {
    116  1.7.8.2  jdolecek 	struct siop_common_target target_c;
    117  1.7.8.2  jdolecek 	struct esiop_lun *esiop_lun[8]; /* per-lun state */
    118  1.7.8.2  jdolecek 	u_int32_t lun_table_offset; /* pointer to our DSA table */
    119  1.7.8.2  jdolecek };
    120  1.7.8.2  jdolecek 
    121  1.7.8.2  jdolecek static __inline__ void esiop_table_sync __P((struct esiop_cmd *, int));
    122  1.7.8.2  jdolecek static __inline__ void
    123  1.7.8.2  jdolecek esiop_table_sync(esiop_cmd, ops)
    124  1.7.8.2  jdolecek 	struct esiop_cmd *esiop_cmd;
    125  1.7.8.2  jdolecek 	int ops;
    126  1.7.8.2  jdolecek {
    127  1.7.8.2  jdolecek 	struct siop_common_softc *sc  = esiop_cmd->cmd_c.siop_sc;
    128  1.7.8.2  jdolecek 	bus_addr_t offset;
    129  1.7.8.2  jdolecek 
    130  1.7.8.2  jdolecek 	offset = esiop_cmd->cmd_c.dsa -
    131  1.7.8.2  jdolecek 	    esiop_cmd->esiop_cbdp->xferdma->dm_segs[0].ds_addr;
    132  1.7.8.2  jdolecek 	bus_dmamap_sync(sc->sc_dmat, esiop_cmd->esiop_cbdp->xferdma, offset,
    133  1.7.8.2  jdolecek 	    sizeof(struct esiop_xfer), ops);
    134  1.7.8.2  jdolecek }
    135  1.7.8.2  jdolecek 
    136  1.7.8.2  jdolecek 
    137  1.7.8.2  jdolecek 
    138  1.7.8.2  jdolecek /* Driver internal state */
    139  1.7.8.2  jdolecek struct esiop_softc {
    140  1.7.8.2  jdolecek 	struct siop_common_softc sc_c;
    141  1.7.8.2  jdolecek 	u_int32_t sc_semoffset;		/* semaphore */
    142  1.7.8.2  jdolecek 	u_int32_t sc_shedoffset;	/* base of scheduler ring */
    143  1.7.8.2  jdolecek 	int sc_currschedslot;		/* current scheduler slot */
    144  1.7.8.2  jdolecek 	struct cbd_list cmds;		/* list of command block descriptors */
    145  1.7.8.2  jdolecek 	struct cmd_list free_list;	/* cmd descr free list */
    146  1.7.8.2  jdolecek 	struct tbl_list free_tagtbl;	/* list of free tag DSA tables */
    147  1.7.8.2  jdolecek 	struct tblblk_list tag_tblblk;	/* tag DSA table blocks */
    148  1.7.8.2  jdolecek 	u_int32_t sc_flags;
    149  1.7.8.2  jdolecek 	u_int32_t sc_free_offset;	/* pointer to free RAM */
    150  1.7.8.2  jdolecek 	u_int32_t sc_target_table_offset;/* pointer to target DSA table */
    151  1.7.8.2  jdolecek 	int sc_currdoneslot;		/* current done slot */
    152  1.7.8.2  jdolecek 	bus_dmamap_t sc_done_map;	/* dma map for done ring (shared) */
    153  1.7.8.2  jdolecek 	bus_addr_t sc_done_offset; 	/* offset of ring in sc_done_map */
    154  1.7.8.2  jdolecek 	u_int32_t *sc_done_slot;	/* The done ring itself */
    155  1.7.8.2  jdolecek };
    156  1.7.8.2  jdolecek 
    157  1.7.8.2  jdolecek /* defs for sc_flags */
    158  1.7.8.2  jdolecek #define SCF_CHAN_NOSLOT	0x0001		/* channel out of sheduler slot */
    159  1.7.8.2  jdolecek #define SCF_CHAN_ADAPTREQ 0x0002	/* esiop_scsipi_request() is running */
    160  1.7.8.2  jdolecek 
    161  1.7.8.2  jdolecek void    esiop_attach __P((struct esiop_softc *));
    162  1.7.8.2  jdolecek int	esiop_intr __P((void *));
    163  1.7.8.2  jdolecek void	esiop_add_dev __P((struct esiop_softc *, int, int));
    164  1.7.8.2  jdolecek void	esiop_del_dev __P((struct esiop_softc *, int, int));
    165