1 /* $NetBSD: sbicvar.h,v 1.9 2002/05/14 02:03:01 matt 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. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)scsivar.h 7.1 (Berkeley) 5/8/90 39 */ 40 #ifndef _SBICVAR_H_ 41 #define _SBICVAR_H_ 42 #include <sys/callout.h> 43 #include <sys/malloc.h> 44 45 46 /* 47 * DMA chains are used for Scatter-Gather DMA. 48 */ 49 struct dma_chain { 50 int dc_count; 51 char *dc_addr; 52 }; 53 54 /* 55 * ACB. Holds additional information for each SCSI command Comments: We 56 * need a separate scsi command block because we may need to overwrite it 57 * with a request sense command. Basicly, we refrain from fiddling with 58 * the scsi_xfer struct (except do the expected updating of return values). 59 * We'll generally update: xs->{flags,resid,error,sense,status} and 60 * occasionally xs->retries. 61 */ 62 struct sbic_acb { 63 TAILQ_ENTRY(sbic_acb) chain; 64 struct scsipi_xfer *xs; /* SCSI xfer ctrl block from above */ 65 int flags; /* Status */ 66 #define ACB_FREE 0x00 67 #define ACB_ACTIVE 0x01 68 #define ACB_DONE 0x04 69 #define ACB_BBUF 0x10 /* DMA input needs to be copied from bounce */ 70 #define ACB_DATAIN 0x20 /* DMA direction flag */ 71 72 struct scsi_generic cmd; /* SCSI command block */ 73 int clen; 74 struct dma_chain sc_kv; /* Virtual address of whole DMA */ 75 struct dma_chain sc_pa; /* Physical address of DMA segment */ 76 u_long sc_tcnt; /* number of bytes for this DMA */ 77 u_short sc_dmacmd; /* Internal data for this DMA */ 78 char *pa_addr; /* XXXX initial phys addr */ 79 }; 80 81 /* 82 * Some info about each (possible) target on the SCSI bus. This should 83 * probably have been a "per target+lunit" structure, but we'll leave it at 84 * this for now. Is there a way to reliably hook it up to sc->fordriver?? 85 */ 86 struct sbic_tinfo { 87 int cmds; /* #commands processed */ 88 int dconns; /* #disconnects */ 89 int lubusy; /* What local units/subr. are busy? */ 90 }; 91 92 struct sbic_softc { 93 struct device sc_dev; 94 struct target_sync { 95 u_char state; 96 u_char period; 97 u_char offset; 98 } sc_sync[8]; 99 u_char target; /* Currently active target */ 100 u_char lun; 101 struct scsipi_channel sc_channel; /* proto for sub devices */ 102 struct scsipi_adapter sc_adapter; 103 sbic_regmap_p sc_sbicp; /* the SBIC */ 104 void *sc_driver; /* driver specific field */ 105 int sc_ipl; 106 107 struct callout sc_timo_ch; 108 109 /* Lists of command blocks */ 110 TAILQ_HEAD(acb_list, sbic_acb) free_list, 111 ready_list, 112 nexus_list; 113 114 struct sbic_acb *sc_nexus; /* current command */ 115 struct sbic_acb sc_acb[8]; /* the real command blocks */ 116 struct sbic_tinfo sc_tinfo[8]; 117 118 struct scsipi_xfer *sc_xs; /* transfer from high level code */ 119 u_char sc_flags; 120 u_char sc_stat[2]; 121 u_char sc_msg[7]; 122 u_long sc_clkfreq; 123 u_long sc_tcnt; /* number of bytes transfered */ 124 u_short sc_dmacmd; /* used by dma drivers */ 125 u_long sc_dmamask; /* dma valid mem mask */ 126 #ifdef DEBUG 127 u_short sc_dmatimo; /* dma timeout */ 128 #endif 129 struct dma_chain *sc_cur; 130 struct dma_chain *sc_last; 131 int (*sc_dmago) __P((struct sbic_softc *, char *, int, int)); 132 int (*sc_dmanext) __P((struct sbic_softc *)); 133 void (*sc_enintr) __P((struct sbic_softc *)); 134 void (*sc_dmastop) __P((struct sbic_softc *)); 135 }; 136 137 /* 138 * sc_flags 139 */ 140 #define SBICF_ALIVE 0x01 /* controller initialized */ 141 #define SBICF_DCFLUSH 0x02 /* need flush for overlap after dma finishes */ 142 #define SBICF_SELECTED 0x04 /* bus is in selected state. */ 143 #define SBICF_ICMD 0x08 /* Immediate command in execution */ 144 #define SBICF_BADDMA 0x10 /* controller can only DMA to ztwobus space */ 145 #define SBICF_INTR 0x40 /* SBICF interrupt expected */ 146 #define SBICF_INDMA 0x80 /* not used yet, DMA I/O in progress */ 147 148 /* 149 * sync states 150 */ 151 #define SYNC_START 0 /* no sync handshake started */ 152 #define SYNC_SENT 1 /* we sent sync request, no answer yet */ 153 #define SYNC_DONE 2 /* target accepted our (or inferior) settings, 154 or it rejected the request and we stay async */ 155 156 #define PHASE 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 183 184 #define STS_CHECKCOND 0x02 /* Check Condition (ie., read sense) */ 185 #define STS_CONDMET 0x04 /* Condition Met (ie., search worked) */ 186 #define STS_BUSY 0x08 187 #define STS_INTERMED 0x10 /* Intermediate status sent */ 188 #define STS_EXT 0x80 /* Extended status valid */ 189 190 191 /* 192 * States returned by our state machine 193 */ 194 195 #define SBIC_STATE_ERROR -1 196 #define SBIC_STATE_DONE 0 197 #define SBIC_STATE_RUNNING 1 198 #define SBIC_STATE_DISCONNECT 2 199 200 201 struct buf; 202 struct scsipi_xfer; 203 204 void sbic_minphys __P((struct buf *bp)); 205 void sbic_scsi_request __P((struct scsipi_channel *, 206 scsipi_adapter_req_t, void *)); 207 void sbicinit __P((struct sbic_softc *)); 208 int sbicintr __P((struct sbic_softc *)); 209 210 #endif /* _SBICVAR_H_ */ 211