| 1 | /* $NetBSD: siopvar.h,v 1.29 2012/08/24 09:01:23 msaitoh Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2000 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 SIOP_NTAG 16 |
| 32 | |
| 33 | /* |
| 34 | * xfer description of the script: tables and reselect script |
| 35 | * In struct siop_common_cmd siop_xfer will point to this. |
| 36 | */ |
| 37 | struct siop_xfer { |
| 38 | struct siop_common_xfer siop_tables; |
| 39 | /* uint32_t resel[sizeof(load_dsa) / sizeof(load_dsa[0])]; */ |
| 40 | uint32_t resel[25]; |
| 41 | } __packed; |
| 42 | |
| 43 | /* |
| 44 | * This describes a command handled by the SCSI controller |
| 45 | * These are chained in either a free list or an active list |
| 46 | * We have one queue per target |
| 47 | */ |
| 48 | |
| 49 | struct siop_cmd { |
| 50 | TAILQ_ENTRY (siop_cmd) next; |
| 51 | struct siop_common_cmd cmd_c; |
| 52 | struct siop_cbd *siop_cbdp; /* pointer to our siop_cbd */ |
| 53 | int reselslot; |
| 54 | uint32_t saved_offset; /* offset in table after disc without sdp */ |
| 55 | }; |
| 56 | #define cmd_tables cmd_c.siop_tables |
| 57 | |
| 58 | /* command block descriptors: an array of siop_cmd + an array of siop_xfer */ |
| 59 | struct siop_cbd { |
| 60 | TAILQ_ENTRY (siop_cbd) next; |
| 61 | struct siop_cmd *cmds; |
| 62 | struct siop_xfer *xfers; |
| 63 | bus_dmamap_t xferdma; /* DMA map for this block of xfers */ |
| 64 | }; |
| 65 | |
| 66 | /* per-tag struct */ |
| 67 | struct siop_tag { |
| 68 | struct siop_cmd *active; /* active command */ |
| 69 | u_int reseloff; |
| 70 | }; |
| 71 | |
| 72 | /* per lun struct */ |
| 73 | struct siop_lun { |
| 74 | struct siop_tag siop_tag[SIOP_NTAG]; /* tag array */ |
| 75 | int lun_flags; /* per-lun flags, none currently */ |
| 76 | u_int reseloff; |
| 77 | }; |
| 78 | |
| 79 | /* |
| 80 | * per target struct; siop_common_cmd->target and siop_common_softc->targets[] |
| 81 | * will point to this |
| 82 | */ |
| 83 | struct siop_target { |
| 84 | struct siop_common_target target_c; |
| 85 | struct siop_lun *siop_lun[8]; /* per-lun state */ |
| 86 | u_int reseloff; |
| 87 | struct siop_lunsw *lunsw; |
| 88 | }; |
| 89 | |
| 90 | struct siop_lunsw { |
| 91 | TAILQ_ENTRY (siop_lunsw) next; |
| 92 | uint32_t lunsw_off; /* offset of this lun sw, from sc_scriptaddr*/ |
| 93 | uint32_t lunsw_size; /* size of this lun sw */ |
| 94 | }; |
| 95 | |
| 96 | static __inline void siop_table_sync(struct siop_cmd *, int); |
| 97 | static __inline void |
| 98 | siop_table_sync(struct siop_cmd *siop_cmd, int ops) |
| 99 | { |
| 100 | struct siop_common_softc *sc = siop_cmd->cmd_c.siop_sc; |
| 101 | bus_addr_t offset; |
| 102 | |
| 103 | offset = siop_cmd->cmd_c.dsa - |
| 104 | siop_cmd->siop_cbdp->xferdma->dm_segs[0].ds_addr; |
| 105 | bus_dmamap_sync(sc->sc_dmat, siop_cmd->siop_cbdp->xferdma, offset, |
| 106 | sizeof(struct siop_xfer), ops); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | TAILQ_HEAD(cmd_list, siop_cmd); |
| 111 | TAILQ_HEAD(cbd_list, siop_cbd); |
| 112 | TAILQ_HEAD(lunsw_list, siop_lunsw); |
| 113 | |
| 114 | |
| 115 | /* Driver internal state */ |
| 116 | struct siop_softc { |
| 117 | struct siop_common_softc sc_c; |
| 118 | int sc_currschedslot; /* current scheduler slot */ |
| 119 | struct cbd_list cmds; /* list of command block descriptors */ |
| 120 | struct cmd_list free_list; /* cmd descr free list */ |
| 121 | struct lunsw_list lunsw_list; /* lunsw free list */ |
| 122 | uint32_t script_free_lo; /* free ram offset from sc_scriptaddr */ |
| 123 | uint32_t script_free_hi; /* free ram offset from sc_scriptaddr */ |
| 124 | int sc_ntargets; /* number of known targets */ |
| 125 | uint32_t sc_flags; |
| 126 | }; |
| 127 | |
| 128 | /* defs for sc_flags */ |
| 129 | #define SCF_CHAN_NOSLOT 0x0001 /* channel out of scheduler slot */ |
| 130 | |
| 131 | void siop_attach(struct siop_softc *); |
| 132 | int siop_intr(void *); |
| 133 | void siop_add_dev(struct siop_softc *, int, int); |
| 134 | void siop_del_dev(struct siop_softc *, int, int); |
| 135 | |