| 1 | /* $NetBSD: esiopvar.h,v 1.21 2012/08/24 09:01:22 msaitoh 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 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | /* structure and definitions for the siop driver */ |
| 29 | |
| 30 | /* Number of tag */ |
| 31 | #define ESIOP_NTAG 256 |
| 32 | |
| 33 | /* |
| 34 | * description of a command scheduler slot. The script uses a ring of |
| 35 | * A_ncmd_slots of this. |
| 36 | */ |
| 37 | struct esiop_slot { |
| 38 | uint32_t dsa; /* DSA of the xfer. The first 2 bits holds flags */ |
| 39 | } __packed; |
| 40 | |
| 41 | #define CMD_SLOTSIZE (sizeof(struct esiop_slot) / sizeof(uint32_t)) |
| 42 | |
| 43 | /* |
| 44 | * xfer description of the script: tables and reselect script |
| 45 | * In struct siop_common_cmd siop_xfer will point to this. |
| 46 | * If you change this don't forget to update o_cmd_* and cmd_slot_size in script |
| 47 | */ |
| 48 | struct esiop_xfer { |
| 49 | struct siop_common_xfer siop_tables; |
| 50 | uint32_t tlq; /* target/lun/tag loaded in scratchC by script */ |
| 51 | uint32_t saved_offset;/* contains scratchA if script saved an offset */ |
| 52 | } __packed; |
| 53 | |
| 54 | #define ESIOP_XFER(cmd, m) (((struct esiop_xfer *)((cmd)->cmd_tables))->m) |
| 55 | |
| 56 | /* |
| 57 | * This describes a command handled by the SCSI controller |
| 58 | * These are chained in either a free list or an 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 | uint32_t *tbl; /* the table itself */ |
| 84 | uint32_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(uint32_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 | struct esiop_dsatbl *lun_tagtbl; /* the tag DSA table */ |
| 107 | }; |
| 108 | |
| 109 | /* |
| 110 | * per target struct; siop_common_cmd->target and siop_common_softc->targets[] |
| 111 | * will point to this |
| 112 | */ |
| 113 | struct esiop_target { |
| 114 | struct siop_common_target target_c; |
| 115 | struct esiop_lun *esiop_lun[8]; /* per-lun state */ |
| 116 | uint32_t lun_table_offset; /* pointer to our DSA table */ |
| 117 | }; |
| 118 | |
| 119 | static __inline void esiop_table_sync(struct esiop_cmd *, int); |
| 120 | static __inline void |
| 121 | esiop_table_sync(struct esiop_cmd *esiop_cmd, int ops) |
| 122 | { |
| 123 | struct siop_common_softc *sc = esiop_cmd->cmd_c.siop_sc; |
| 124 | bus_addr_t offset; |
| 125 | |
| 126 | offset = esiop_cmd->cmd_c.dsa - |
| 127 | esiop_cmd->esiop_cbdp->xferdma->dm_segs[0].ds_addr; |
| 128 | bus_dmamap_sync(sc->sc_dmat, esiop_cmd->esiop_cbdp->xferdma, offset, |
| 129 | sizeof(struct esiop_xfer), ops); |
| 130 | } |
| 131 | |
| 132 | |
| 133 | |
| 134 | /* Driver internal state */ |
| 135 | struct esiop_softc { |
| 136 | struct siop_common_softc sc_c; |
| 137 | uint32_t sc_semoffset; /* semaphore */ |
| 138 | uint32_t sc_shedoffset; /* base of scheduler ring */ |
| 139 | int sc_currschedslot; /* current scheduler slot */ |
| 140 | struct cbd_list cmds; /* list of command block descriptors */ |
| 141 | struct cmd_list free_list; /* cmd descr free list */ |
| 142 | struct tbl_list free_tagtbl; /* list of free tag DSA tables */ |
| 143 | struct tblblk_list tag_tblblk; /* tag DSA table blocks */ |
| 144 | uint32_t sc_flags; |
| 145 | uint32_t sc_free_offset; /* pointer to free RAM */ |
| 146 | uint32_t sc_target_table_offset;/* pointer to target DSA table */ |
| 147 | int sc_currdoneslot; /* current done slot */ |
| 148 | bus_dmamap_t sc_done_map; /* dma map for done ring (shared) */ |
| 149 | bus_addr_t sc_done_offset; /* offset of ring in sc_done_map */ |
| 150 | uint32_t *sc_done_slot; /* The done ring itself */ |
| 151 | }; |
| 152 | |
| 153 | /* defs for sc_flags */ |
| 154 | #define SCF_CHAN_NOSLOT 0x0001 /* channel out of scheduler slot */ |
| 155 | #define SCF_CHAN_ADAPTREQ 0x0002 /* esiop_scsipi_request() is running */ |
| 156 | |
| 157 | void esiop_attach(struct esiop_softc *); |
| 158 | int esiop_intr(void *); |
| 159 | void esiop_add_dev(struct esiop_softc *, int, int); |
| 160 | void esiop_del_dev(struct esiop_softc *, int, int); |
| 161 | |