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