1 1.35 andvar /* $NetBSD: ncr5380var.h,v 1.35 2025/09/14 14:24:12 andvar Exp $ */ 2 1.1 pk 3 1.1 pk /* 4 1.4 thorpej * Copyright (c) 1995 David Jones, Gordon W. Ross 5 1.4 thorpej * Copyright (c) 1994 Jarle Greipsland 6 1.1 pk * All rights reserved. 7 1.1 pk * 8 1.1 pk * Redistribution and use in source and binary forms, with or without 9 1.1 pk * modification, are permitted provided that the following conditions 10 1.1 pk * are met: 11 1.1 pk * 1. Redistributions of source code must retain the above copyright 12 1.1 pk * notice, this list of conditions and the following disclaimer. 13 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright 14 1.1 pk * notice, this list of conditions and the following disclaimer in the 15 1.1 pk * documentation and/or other materials provided with the distribution. 16 1.4 thorpej * 3. The name of the authors may not be used to endorse or promote products 17 1.4 thorpej * derived from this software without specific prior written permission. 18 1.4 thorpej * 4. All advertising materials mentioning features or use of this software 19 1.1 pk * must display the following acknowledgement: 20 1.4 thorpej * This product includes software developed by 21 1.4 thorpej * David Jones and Gordon Ross 22 1.1 pk * 23 1.4 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 24 1.1 pk * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 1.1 pk * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 1.4 thorpej * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 1.1 pk * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 1.1 pk * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 1.1 pk * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 1.1 pk * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 1.4 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 1.4 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 1.1 pk */ 34 1.1 pk 35 1.4 thorpej /* 36 1.4 thorpej * This file defines the interface between the machine-dependent 37 1.24 wiz * module and the machine-independent ncr5380sbc.c module. 38 1.4 thorpej */ 39 1.4 thorpej 40 1.9 christos /* 41 1.34 skrll * Currently amd64, alpha, i386, mips, news68k, sparc, sun2, and vax 42 1.27 tsutsui * use real bus space: 43 1.27 tsutsui * acorn32: csa driver; easy to convert 44 1.9 christos * mac68k: sbc driver; easy to convert 45 1.9 christos * pc532: ncr driver; need bus.h first 46 1.9 christos * sun3: si driver; need bus.h first 47 1.9 christos */ 48 1.34 skrll #if \ 49 1.27 tsutsui defined(__alpha__) || \ 50 1.27 tsutsui defined(__amd64__) || \ 51 1.27 tsutsui defined(__i386__) || \ 52 1.27 tsutsui defined(__mips__) || \ 53 1.27 tsutsui defined(news68k) || \ 54 1.27 tsutsui defined(__sparc__) || \ 55 1.27 tsutsui defined(sun2) || \ 56 1.27 tsutsui defined(__vax__) 57 1.9 christos # define NCR5380_USE_BUS_SPACE 58 1.9 christos #endif 59 1.9 christos 60 1.9 christos /* 61 1.9 christos * Handy read/write macros 62 1.9 christos */ 63 1.10 christos #ifdef NCR5380_USE_BUS_SPACE 64 1.31 ad # include <sys/bus.h> 65 1.9 christos /* bus_space() variety */ 66 1.12 scottr # define NCR5380_READ(sc, reg) bus_space_read_1(sc->sc_regt, \ 67 1.11 scottr sc->sc_regh, sc->reg) 68 1.12 scottr # define NCR5380_WRITE(sc, reg, val) bus_space_write_1(sc->sc_regt, \ 69 1.11 scottr sc->sc_regh, sc->reg, val) 70 1.9 christos #else 71 1.9 christos /* legacy memory-mapped variety */ 72 1.12 scottr # define NCR5380_READ(sc, reg) (*sc->reg) 73 1.12 scottr # define NCR5380_WRITE(sc, reg, val) do { *(sc->reg) = val; } while (0) 74 1.9 christos #endif 75 1.9 christos 76 1.12 scottr #define SCI_CLR_INTR(sc) NCR5380_READ(sc, sci_iack) 77 1.12 scottr #define SCI_BUSY(sc) (NCR5380_READ(sc, sci_bus_csr) & SCI_BUS_BSY) 78 1.4 thorpej 79 1.4 thorpej /* These are NOT artibtrary, but map to bits in sci_tcmd */ 80 1.4 thorpej #define PHASE_DATA_OUT 0x0 81 1.4 thorpej #define PHASE_DATA_IN 0x1 82 1.4 thorpej #define PHASE_COMMAND 0x2 83 1.4 thorpej #define PHASE_STATUS 0x3 84 1.4 thorpej #define PHASE_UNSPEC1 0x4 85 1.4 thorpej #define PHASE_UNSPEC2 0x5 86 1.4 thorpej #define PHASE_MSG_OUT 0x6 87 1.4 thorpej #define PHASE_MSG_IN 0x7 88 1.4 thorpej 89 1.4 thorpej /* 90 1.4 thorpej * This illegal phase is used to prevent the 5380 from having 91 1.4 thorpej * a phase-match condition when we don't want one, such as 92 1.4 thorpej * when setting up the DMA engine or whatever... 93 1.4 thorpej */ 94 1.4 thorpej #define PHASE_INVALID PHASE_UNSPEC1 95 1.4 thorpej 96 1.4 thorpej 97 1.4 thorpej /* Per-request state. This is required in order to support reselection. */ 98 1.4 thorpej struct sci_req { 99 1.8 bouyer struct scsipi_xfer *sr_xs; /* Pointer to xfer struct, NULL=unused */ 100 1.4 thorpej int sr_target, sr_lun; /* For fast access */ 101 1.35 andvar void *sr_dma_hand; /* Current DMA handle */ 102 1.32 tsutsui uint8_t *sr_dataptr; /* Saved data pointer */ 103 1.4 thorpej int sr_datalen; 104 1.4 thorpej int sr_flags; /* Internal error code */ 105 1.4 thorpej #define SR_IMMED 1 /* Immediate command */ 106 1.4 thorpej #define SR_SENSE 2 /* We are getting sense */ 107 1.4 thorpej #define SR_OVERDUE 4 /* Timeout while not current */ 108 1.4 thorpej #define SR_ERROR 8 /* Error occurred */ 109 1.4 thorpej int sr_status; /* Status code from last cmd */ 110 1.4 thorpej }; 111 1.4 thorpej #define SCI_OPENINGS 16 /* How many commands we can enqueue. */ 112 1.4 thorpej 113 1.1 pk 114 1.1 pk struct ncr5380_softc { 115 1.32 tsutsui device_t sc_dev; 116 1.13 thorpej struct scsipi_adapter sc_adapter; 117 1.20 bouyer struct scsipi_channel sc_channel; 118 1.1 pk 119 1.9 christos #ifdef NCR5380_USE_BUS_SPACE 120 1.9 christos /* Pointers to bus_space */ 121 1.11 scottr bus_space_tag_t sc_regt; 122 1.11 scottr bus_space_handle_t sc_regh; 123 1.9 christos 124 1.9 christos /* Pointers to 5380 registers. */ 125 1.9 christos bus_size_t sci_r0; 126 1.9 christos bus_size_t sci_r1; 127 1.9 christos bus_size_t sci_r2; 128 1.9 christos bus_size_t sci_r3; 129 1.9 christos bus_size_t sci_r4; 130 1.9 christos bus_size_t sci_r5; 131 1.9 christos bus_size_t sci_r6; 132 1.9 christos bus_size_t sci_r7; 133 1.9 christos #else 134 1.4 thorpej /* Pointers to 5380 registers. See ncr5380reg.h */ 135 1.32 tsutsui volatile uint8_t *sci_r0; 136 1.32 tsutsui volatile uint8_t *sci_r1; 137 1.32 tsutsui volatile uint8_t *sci_r2; 138 1.32 tsutsui volatile uint8_t *sci_r3; 139 1.32 tsutsui volatile uint8_t *sci_r4; 140 1.32 tsutsui volatile uint8_t *sci_r5; 141 1.32 tsutsui volatile uint8_t *sci_r6; 142 1.32 tsutsui volatile uint8_t *sci_r7; 143 1.9 christos #endif 144 1.4 thorpej 145 1.4 thorpej /* Functions set from MD code */ 146 1.28 perry int (*sc_pio_out)(struct ncr5380_softc *, 147 1.32 tsutsui int, int, uint8_t *); 148 1.28 perry int (*sc_pio_in)(struct ncr5380_softc *, 149 1.32 tsutsui int, int, uint8_t *); 150 1.28 perry void (*sc_dma_alloc)(struct ncr5380_softc *); 151 1.28 perry void (*sc_dma_free)(struct ncr5380_softc *); 152 1.28 perry 153 1.28 perry void (*sc_dma_setup)(struct ncr5380_softc *); 154 1.28 perry void (*sc_dma_start)(struct ncr5380_softc *); 155 1.28 perry void (*sc_dma_poll)(struct ncr5380_softc *); 156 1.28 perry void (*sc_dma_eop)(struct ncr5380_softc *); 157 1.28 perry void (*sc_dma_stop)(struct ncr5380_softc *); 158 1.4 thorpej 159 1.28 perry void (*sc_intr_on)(struct ncr5380_softc *); 160 1.28 perry void (*sc_intr_off)(struct ncr5380_softc *); 161 1.4 thorpej 162 1.4 thorpej int sc_flags; /* Misc. flags and capabilities */ 163 1.7 gwr #define NCR5380_FORCE_POLLING 1 /* Do not use interrupts. */ 164 1.7 gwr 165 1.7 gwr /* Set bits in this to disable disconnect per-target. */ 166 1.7 gwr int sc_no_disconnect; 167 1.6 gwr 168 1.6 gwr /* Set bits in this to disable parity for some target. */ 169 1.6 gwr int sc_parity_disable; 170 1.4 thorpej 171 1.4 thorpej int sc_min_dma_len; /* Smaller than this is done with PIO */ 172 1.4 thorpej 173 1.4 thorpej /* Begin MI shared data */ 174 1.4 thorpej 175 1.4 thorpej int sc_state; 176 1.4 thorpej #define NCR_IDLE 0 /* Ready for new work. */ 177 1.4 thorpej #define NCR_WORKING 0x01 /* Some command is in progress. */ 178 1.4 thorpej #define NCR_ABORTING 0x02 /* Bailing out */ 179 1.4 thorpej #define NCR_DOINGDMA 0x04 /* The FIFO data path is active! */ 180 1.4 thorpej #define NCR_DROP_MSGIN 0x10 /* Discard all msgs (parity err detected) */ 181 1.4 thorpej 182 1.4 thorpej /* The request that has the bus now. */ 183 1.4 thorpej struct sci_req *sc_current; 184 1.4 thorpej 185 1.4 thorpej /* Active data pointer for current SCSI command. */ 186 1.32 tsutsui uint8_t *sc_dataptr; 187 1.4 thorpej int sc_datalen; 188 1.4 thorpej 189 1.4 thorpej /* Begin MI private data */ 190 1.4 thorpej 191 1.4 thorpej /* The number of operations in progress on the bus */ 192 1.4 thorpej volatile int sc_ncmds; 193 1.4 thorpej 194 1.4 thorpej /* Ring buffer of pending/active requests */ 195 1.4 thorpej struct sci_req sc_ring[SCI_OPENINGS]; 196 1.4 thorpej int sc_rr; /* Round-robin scan pointer */ 197 1.4 thorpej 198 1.4 thorpej /* Active requests, by target/LUN */ 199 1.4 thorpej struct sci_req *sc_matrix[8][8]; 200 1.4 thorpej 201 1.4 thorpej /* Message stuff */ 202 1.4 thorpej int sc_prevphase; 203 1.4 thorpej 204 1.4 thorpej u_int sc_msgpriq; /* Messages we want to send */ 205 1.4 thorpej u_int sc_msgoutq; /* Messages sent during last MESSAGE OUT */ 206 1.4 thorpej u_int sc_msgout; /* Message last transmitted */ 207 1.4 thorpej #define SEND_DEV_RESET 0x01 208 1.4 thorpej #define SEND_PARITY_ERROR 0x02 209 1.4 thorpej #define SEND_ABORT 0x04 210 1.4 thorpej #define SEND_REJECT 0x08 211 1.4 thorpej #define SEND_INIT_DET_ERR 0x10 212 1.4 thorpej #define SEND_IDENTIFY 0x20 213 1.4 thorpej #define SEND_SDTR 0x40 214 1.4 thorpej #define SEND_WDTR 0x80 215 1.4 thorpej #define NCR_MAX_MSG_LEN 8 216 1.32 tsutsui uint8_t sc_omess[NCR_MAX_MSG_LEN]; 217 1.32 tsutsui uint8_t *sc_omp; /* Outgoing message pointer */ 218 1.32 tsutsui uint8_t sc_imess[NCR_MAX_MSG_LEN]; 219 1.32 tsutsui uint8_t *sc_imp; /* Incoming message pointer */ 220 1.18 tsutsui int sc_rev; /* Chip revision */ 221 1.18 tsutsui #define NCR_VARIANT_NCR5380 0 222 1.18 tsutsui #define NCR_VARIANT_DP8490 1 223 1.18 tsutsui #define NCR_VARIANT_NCR53C400 2 224 1.18 tsutsui #define NCR_VARIANT_PAS16 3 225 1.18 tsutsui #define NCR_VARIANT_CXD1180 4 226 1.1 pk 227 1.4 thorpej }; 228 1.1 pk 229 1.28 perry void ncr5380_attach(struct ncr5380_softc *); 230 1.28 perry int ncr5380_detach(struct ncr5380_softc *, int); 231 1.28 perry int ncr5380_intr(void *); 232 1.28 perry void ncr5380_scsipi_request(struct scsipi_channel *, 233 1.28 perry scsipi_adapter_req_t, void *); 234 1.32 tsutsui int ncr5380_pio_in(struct ncr5380_softc *, int, int, uint8_t *); 235 1.32 tsutsui int ncr5380_pio_out(struct ncr5380_softc *, int, int, uint8_t *); 236 1.28 perry void ncr5380_init(struct ncr5380_softc *); 237 1.4 thorpej 238 1.5 gwr #ifdef NCR5380_DEBUG 239 1.33 matt extern struct ncr5380_softc *ncr5380_debug_sc; 240 1.30 christos void ncr5380_trace(const char *msg, long val); 241 1.4 thorpej #define NCR_TRACE(msg, val) ncr5380_trace(msg, val) 242 1.5 gwr #else /* NCR5380_DEBUG */ 243 1.4 thorpej #define NCR_TRACE(msg, val) /* nada */ 244 1.5 gwr #endif /* NCR5380_DEBUG */ 245