1 /* $NetBSD: mscpvar.h,v 1.14 2005/12/11 12:22:47 christos Exp $ */ 2 /* 3 * Copyright (c) 1988 Regents of the University of California. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Chris Torek. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)mscpvar.h 7.3 (Berkeley) 6/28/90 34 */ 35 36 /* 37 * Copyright (c) 1996 Ludd, University of Lule}, Sweden. 38 * 39 * This code is derived from software contributed to Berkeley by 40 * Chris Torek. 41 * 42 * Redistribution and use in source and binary forms, with or without 43 * modification, are permitted provided that the following conditions 44 * are met: 45 * 1. Redistributions of source code must retain the above copyright 46 * notice, this list of conditions and the following disclaimer. 47 * 2. Redistributions in binary form must reproduce the above copyright 48 * notice, this list of conditions and the following disclaimer in the 49 * documentation and/or other materials provided with the distribution. 50 * 3. All advertising materials mentioning features or use of this software 51 * must display the following acknowledgement: 52 * This product includes software developed by the University of 53 * California, Berkeley and its contributors. 54 * 4. Neither the name of the University nor the names of its contributors 55 * may be used to endorse or promote products derived from this software 56 * without specific prior written permission. 57 * 58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 68 * SUCH DAMAGE. 69 * 70 * @(#)mscpvar.h 7.3 (Berkeley) 6/28/90 71 */ 72 73 /* 74 * MSCP generic driver configuration 75 */ 76 77 /* 78 * Enabling MSCP_PARANOIA makes the response code perform various checks 79 * on the hardware. (Right now it verifies only the buffer pointer in 80 * mscp_cmdref.) 81 * 82 * Enabling AVOID_EMULEX_BUG selects an alternative method of identifying 83 * transfers in progress, which gets around a rather peculiar bug in the 84 * SC41/MS. Enabling MSCP_PARANOIA instead should work, but will cause 85 * `extra' Unibus resets. 86 * 87 * Either of these flags can simply be included as an `options' line in 88 * your configuration file. 89 */ 90 91 /* #define MSCP_PARANOIA */ 92 /* #define AVOID_EMULEX_BUG */ 93 94 /* 95 * Ring information, per ring (one each for commands and responses). 96 */ 97 struct mscp_ri { 98 int mri_size; /* ring size */ 99 int mri_next; /* next (expected|free) */ 100 long *mri_desc; /* base address of descriptors */ 101 struct mscp *mri_ring; /* base address of packets */ 102 }; 103 104 /* 105 * Transfer info, one per command packet. 106 */ 107 struct mscp_xi { 108 bus_dmamap_t mxi_dmam; /* Allocated DMA map for this entry */ 109 struct buf * mxi_bp; /* Buffer used in this command */ 110 struct mscp * mxi_mp; /* Packet used in this command */ 111 int mxi_inuse; 112 }; 113 114 struct mscp_ctlr { 115 void (*mc_ctlrdone) /* controller operation complete */ 116 (struct device *); 117 void (*mc_go) /* device-specific start routine */ 118 (struct device *, struct mscp_xi *); 119 void (*mc_saerror) /* ctlr error handling */ 120 (struct device *, int); 121 }; 122 123 struct mscp_softc; 124 125 struct mscp_device { 126 void (*me_dgram) /* error datagram */ 127 (struct device *, struct mscp *, struct mscp_softc *); 128 void (*me_iodone) /* normal I/O is done */ 129 (struct device *, struct buf *); 130 int (*me_online) /* drive on line */ 131 (struct device *, struct mscp *); 132 int (*me_gotstatus) /* got unit status */ 133 (struct device *, struct mscp *); 134 void (*me_replace) /* replace done */ 135 (struct device *, struct mscp *); 136 int (*me_ioerr) /* read or write failed */ 137 (struct device *, struct mscp *, struct buf *); 138 void (*me_bb) /* B_BAD io done */ 139 (struct device *, struct mscp *, struct buf *); 140 void (*me_fillin) /* Fill in mscp info for this drive */ 141 (struct buf *,struct mscp *); 142 void (*me_cmddone) /* Non-data transfer operation is done */ 143 (struct device *, struct mscp *); 144 }; 145 146 /* 147 * This struct is used when attaching a mscpbus. 148 */ 149 struct mscp_attach_args { 150 struct mscp_ctlr *ma_mc; /* Pointer to ctlr's mscp_ctlr */ 151 int ma_type; /* disk/tape bus type */ 152 struct mscp_pack *ma_uda; /* comm area virtual */ 153 struct mscp_softc **ma_softc; /* backpointer to bus softc */ 154 bus_dmamap_t ma_dmam; /* This comm area dma info */ 155 bus_dma_tag_t ma_dmat; 156 bus_space_tag_t ma_iot; 157 bus_space_handle_t ma_iph; /* initialisation and polling */ 158 bus_space_handle_t ma_sah; /* status & address (read part) */ 159 bus_space_handle_t ma_swh; /* status & address (write part) */ 160 short ma_ivec; /* Interrupt vector to use */ 161 char ma_ctlrnr; /* Phys ctlr nr */ 162 char ma_adapnr; /* Phys adapter nr */ 163 }; 164 #define MSCPBUS_DISK 001 /* Bus is used for disk mounts */ 165 #define MSCPBUS_TAPE 002 /* Bus is used for tape mounts */ 166 #define MSCPBUS_UDA 004 /* ctlr is disk on unibus/qbus */ 167 #define MSCPBUS_KDB 010 /* ctlr is disk on BI */ 168 #define MSCPBUS_KLE 020 /* ctlr is tape on unibus/qbus */ 169 170 /* 171 * Used when going for child devices. 172 */ 173 struct drive_attach_args { 174 struct mscp *da_mp; /* this devices response struct */ 175 int da_typ; /* Parent of type */ 176 }; 177 178 /* 179 * Return values from functions. 180 * MSCP_RESTARTED is peculiar to I/O errors. 181 */ 182 #define MSCP_DONE 0 /* all ok */ 183 #define MSCP_FAILED 1 /* no go */ 184 #define MSCP_RESTARTED 2 /* transfer restarted */ 185 186 /* 187 * Per device information. 188 * 189 * mi_ip is a pointer to the inverting pointers (things that get `ui's 190 * given unit numbers) FOR THIS CONTROLLER (NOT the whole set!). 191 * 192 * b_actf holds a queue of those transfers that were started but have 193 * not yet finished. Other Unibus drivers do not need this as they hand 194 * out requests one at a time. MSCP devices, however, take a slew of 195 * requests and pick their own order to execute them. This means that 196 * we have to have a place to move transfers that were given to the 197 * controller, so we can tell those apart from those that have not yet 198 * been handed out; b_actf is that place. 199 */ 200 struct mscp_softc { 201 struct device mi_dev; /* Autoconf stuff */ 202 struct mscp_ri mi_cmd; /* MSCP command ring info */ 203 struct mscp_ri mi_rsp; /* MSCP response ring info */ 204 bus_dma_tag_t mi_dmat; 205 bus_dmamap_t mi_dmam; 206 struct mscp_xi mi_xi[NCMD]; 207 int mi_mxiuse; /* Bitfield of inuse mxi packets */ 208 short mi_credits; /* transfer credits */ 209 char mi_wantcmd; /* waiting for command packet */ 210 char mi_wantcredits; /* waiting for transfer credits */ 211 struct mscp_ctlr *mi_mc; /* Pointer to parent's mscp_ctlr */ 212 struct mscp_device *mi_me; /* Pointer to child's mscp_device */ 213 struct device **mi_dp; /* array of backpointers */ 214 int mi_driveno; /* Max physical drive number found */ 215 char mi_ctlrnr; /* Phys ctlr nr */ 216 char mi_adapnr; /* Phys adapter nr */ 217 int mi_flags; 218 struct mscp_pack *mi_uda; /* virtual address */ 219 int mi_type; 220 short mi_ivec; /* Interrupt vector to use */ 221 short mi_ierr; /* Init err counter */ 222 bus_space_tag_t mi_iot; 223 bus_space_handle_t mi_iph; /* initialisation and polling */ 224 bus_space_handle_t mi_sah; /* status & address (read part) */ 225 bus_space_handle_t mi_swh; /* status & address (write part) */ 226 struct bufq_state *mi_resq; /* While waiting for packets */ 227 }; 228 229 /* mi_flags */ 230 #define MSC_STARTPOLL 1 231 #define MSC_INSTART 2 232 #define MSC_IGNOREINTR 4 233 #define MSC_READY 8 234 235 /* 236 * We have run out of credits when mi_credits is <= MSCP_MINCREDITS. 237 * It is still possible to issue one command in this case, but it must 238 * not be a data transfer. E.g., `get command status' or `abort command' 239 * is legal, while `read' is not. 240 */ 241 #define MSCP_MINCREDITS 1 242 243 /* 244 * Flags for mscp_getcp(). 245 */ 246 #define MSCP_WAIT 1 247 #define MSCP_DONTWAIT 0 248 249 /* get a command packet */ 250 251 /* 252 * Unit flags 253 */ 254 #define UNIT_ONLINE 0x01 /* drive is on line */ 255 #define UNIT_HAVESTATUS 0x02 /* got unit status */ 256 #define UNIT_REQUEUE 0x04 /* requeue after response */ 257 258 /* 259 * Handle a command ring transition: wake up sleepers for command packets. 260 * This is too simple to bother with a function call. 261 */ 262 #define MSCP_DOCMD(mi) { \ 263 if ((mi)->mi_wantcmd) { \ 264 (mi)->mi_wantcmd = 0; \ 265 wakeup((caddr_t) &(mi)->mi_wantcmd); \ 266 } \ 267 } 268 269 /* Prototypes */ 270 struct mscp *mscp_getcp(struct mscp_softc *, int); 271 void mscp_printevent(struct mscp *); 272 void mscp_go(struct mscp_softc *, struct mscp *, int); 273 void mscp_requeue(struct mscp_softc *); 274 void mscp_dorsp(struct mscp_softc *); 275 int mscp_decodeerror(const char *, struct mscp *, struct mscp_softc *); 276 int mscp_print(void *, const char *); 277 void mscp_hexdump(struct mscp *); 278 void mscp_strategy(struct buf *, struct device *); 279 void mscp_printtype(int, int); 280 int mscp_waitstep(struct mscp_softc *, int, int); 281 void mscp_dgo(struct mscp_softc *, struct mscp_xi *); 282 void mscp_intr(struct mscp_softc *); 283