1 /* $NetBSD: sbicvar.h,v 1.8 2023/12/20 06:13:59 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1990 The Regents of the University of California. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Van Jacobson of Lawrence Berkeley Laboratory. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)scsivar.h 7.1 (Berkeley) 5/8/90 35 */ 36 37 #ifndef _SBICVAR_H_ 38 #define _SBICVAR_H_ 39 40 #include <sys/callout.h> 41 42 /* 43 * ACB. Holds additional information for each SCSI command Comments: We 44 * need a separate scsi command block because we may need to overwrite it 45 * with a request sense command. Basically, we refrain from fiddling with 46 * the scsi_xfer struct (except do the expected updating of return values). 47 * We'll generally update: xs->{flags,resid,error,sense,status} and 48 * occasionally xs->retries. 49 */ 50 struct sbic_acb { 51 TAILQ_ENTRY(sbic_acb) chain; 52 struct scsipi_xfer *xs; /* SCSI xfer ctrl block from above */ 53 int flags; /* Status */ 54 #define ACB_FREE 0x00 55 #define ACB_ACTIVE 0x01 56 #define ACB_DONE 0x02 57 #define ACB_DATAIN 0x04 /* DMA direction flag */ 58 #define ACB_DMA 0x08 /* ACB using DMA this time */ 59 struct scsipi_generic cmd; /* SCSI command block */ 60 int clen; 61 bus_dmamap_t dmamap_xfer; /* Handle for dma */ 62 u_char *data; /* Data buffer... */ 63 int datalen; /* ... and its length. */ 64 int offset; 65 u_long sc_tcnt; /* number of bytes for this DMA */ 66 }; 67 68 /* 69 * Some info about each (possible) target on the SCSI bus. This should 70 * probably have been a "per target+lunit" structure, but we'll leave it at 71 * this for now. Is there a way to reliably hook it up to sc->fordriver?? 72 */ 73 struct sbic_tinfo { 74 int cmds; /* #commands processed */ 75 int dconns; /* #disconnects */ 76 int touts; /* #timeouts */ 77 int perrs; /* #parity errors */ 78 u_char* bounce; /* Bounce buffer for this device */ 79 ushort lubusy; /* What local units/subr. are busy? */ 80 u_char flags; 81 u_char period; /* Period suggestion */ 82 u_char offset; /* Offset suggestion */ 83 }; 84 85 struct sbic_softc { 86 device_t sc_dev; 87 /* struct isr sc_isr;*/ 88 struct callout sc_timo_ch; 89 struct target_sync { 90 u_char state; 91 u_char period; 92 u_char offset; 93 } sc_sync[8]; 94 u_char target; /* Currently active target */ 95 u_char lun; 96 struct scsipi_channel sc_channel; 97 struct scsipi_adapter sc_adapter; 98 sbic_regmap sc_sbicp; /* Handle for the SBIC */ 99 100 volatile void *sc_cregs; /* driver specific regs */ 101 102 /* Lists of command blocks */ 103 TAILQ_HEAD(acb_list, sbic_acb) free_list, 104 ready_list, 105 nexus_list; 106 107 struct sbic_acb *sc_nexus; /* current command */ 108 struct sbic_acb sc_acb[8]; /* the real command blocks */ 109 struct sbic_tinfo sc_tinfo[8]; 110 111 u_char sc_flags; 112 u_char sc_scsiaddr; 113 u_char sc_stat[2]; 114 u_char sc_msg[7]; 115 u_long sc_clkfreq; 116 117 int sc_dmaflags; /* Target-specific busdma flags */ 118 void *sc_dmah; /* Interface specific dma handle */ 119 bus_dma_tag_t sc_dmat; /* Tag for dma accesses */ 120 int sc_max_dmalen; /* Maximum DMA segment length */ 121 int sc_dmamode; /* Machine-specific DMA mode for 122 the SBIC chip */ 123 124 u_short sc_dmatimo; /* dma timeout */ 125 int (*sc_dmaok) (void *, bus_dma_tag_t, struct sbic_acb *); 126 int (*sc_dmasetup) (void *, bus_dma_tag_t, struct sbic_acb *, int); 127 int (*sc_dmanext) (void *, bus_dma_tag_t, struct sbic_acb *, int); 128 void (*sc_dmastop) (void *, bus_dma_tag_t, struct sbic_acb *); 129 void (*sc_dmafinish) (void *, bus_dma_tag_t, struct sbic_acb *); 130 void (*sc_enintr) (struct sbic_softc *); 131 }; 132 133 /* sc_flags */ 134 #define SBICF_ALIVE 0x01 /* controller initialized */ 135 #define SBICF_SELECTED 0x02 /* bus is in selected state. */ 136 #define SBICF_ICMD 0x04 /* Immediate command in execution */ 137 #define SBICF_BADDMA 0x08 /* controller can only DMA to ztwobus space */ 138 #define SBICF_NODMA 0x10 /* Don't use DMA */ 139 #define SBICF_INTR 0x20 /* SBICF interrupt expected */ 140 #define SBICF_INDMA 0x40 /* not used yet, DMA I/O in progress */ 141 142 /* sync states */ 143 #define SYNC_START 0 /* no sync handshake started */ 144 #define SYNC_SENT 1 /* we sent sync request, no answer yet */ 145 #define SYNC_DONE 2 /* target accepted our (or inferior) settings, 146 or it rejected the request and we stay 147 async */ 148 #ifdef DEBUG 149 #define DDB_FOLLOW 0x04 150 #define DDB_IO 0x08 151 #endif 152 extern u_char sbic_inhibit_sync[8]; 153 extern int sbic_no_dma; 154 extern int sbic_clock_override; 155 156 #define PHASE_MASK 0x07 /* mask for psns/pctl phase */ 157 #define DATA_OUT_PHASE 0x00 158 #define DATA_IN_PHASE 0x01 159 #define CMD_PHASE 0x02 160 #define STATUS_PHASE 0x03 161 #define BUS_FREE_PHASE 0x04 162 #define ARB_SEL_PHASE 0x05 /* Fuji chip combines arbitration with sel. */ 163 #define MESG_OUT_PHASE 0x06 164 #define MESG_IN_PHASE 0x07 165 166 #define MSG_CMD_COMPLETE 0x00 167 #define MSG_EXT_MESSAGE 0x01 168 #define MSG_SAVE_DATA_PTR 0x02 169 #define MSG_RESTORE_PTR 0x03 170 #define MSG_DISCONNECT 0x04 171 #define MSG_INIT_DETECT_ERROR 0x05 172 #define MSG_ABORT 0x06 173 #define MSG_REJECT 0x07 174 #define MSG_NOOP 0x08 175 #define MSG_PARITY_ERROR 0x09 176 #define MSG_BUS_DEVICE_RESET 0x0C 177 #define MSG_IDENTIFY 0x80 178 #define MSG_IDENTIFY_DR 0xc0 /* (disconnect/reconnect allowed) */ 179 #define MSG_SYNC_REQ 0x01 180 181 #define MSG_ISIDENTIFY(x) (x&MSG_IDENTIFY) 182 #define IFY_TRN 0x20 183 #define IFY_LUNTRN(x) (x&0x07) 184 #define IFY_LUN(x) (!(x&0x20)) 185 186 /* Check if high bit set */ 187 188 #define STS_CHECKCOND 0x02 /* Check Condition (ie., read sense) */ 189 #define STS_CONDMET 0x04 /* Condition Met (ie., search worked) */ 190 #define STS_BUSY 0x08 191 #define STS_INTERMED 0x10 /* Intermediate status sent */ 192 #define STS_EXT 0x80 /* Extended status valid */ 193 194 195 /* States returned by our state machine */ 196 197 #define SBIC_STATE_ERROR -1 198 #define SBIC_STATE_DONE 0 199 #define SBIC_STATE_RUNNING 1 200 #define SBIC_STATE_DISCONNECT 2 201 202 /* 203 * XXXX 204 */ 205 struct scsi_fmt_cdb { 206 int len; /* cdb length (in bytes) */ 207 u_char cdb[28]; /* cdb to use on next read/write */ 208 }; 209 210 struct buf; 211 struct scsipi_xfer; 212 213 void sbic_minphys (struct buf *bp); 214 void sbic_scsi_request (struct scsipi_channel *, 215 scsipi_adapter_req_t, void *); 216 int sbicinit (struct sbic_softc *dev); 217 int sbicintr (struct sbic_softc *); 218 void sbic_dump (struct sbic_softc *dev); 219 220 #endif /* _SBICVAR_H_ */ 221