1 /* $NetBSD: aacvar.h,v 1.4 2004/09/13 12:55:47 drochner Exp $ */ 2 3 /*- 4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Andrew Doran. 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 NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /*- 40 * Copyright (c) 2000 Michael Smith 41 * Copyright (c) 2000 BSDi 42 * Copyright (c) 2000 Niklas Hallqvist 43 * All rights reserved. 44 * 45 * Redistribution and use in source and binary forms, with or without 46 * modification, are permitted provided that the following conditions 47 * are met: 48 * 1. Redistributions of source code must retain the above copyright 49 * notice, this list of conditions and the following disclaimer. 50 * 2. Redistributions in binary form must reproduce the above copyright 51 * notice, this list of conditions and the following disclaimer in the 52 * documentation and/or other materials provided with the distribution. 53 * 54 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 57 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 64 * SUCH DAMAGE. 65 * 66 * from FreeBSD: aacvar.h,v 1.1 2000/09/13 03:20:34 msmith Exp 67 * via OpenBSD: aacvar.h,v 1.2 2002/03/14 01:26:53 millert Exp 68 */ 69 70 #ifndef _PCI_AACVAR_H_ 71 #define _PCI_AACVAR_H_ 72 73 /* Debugging */ 74 #ifdef AAC_DEBUG 75 #define AAC_DPRINTF(mask, args) if ((aac_debug & (mask)) != 0) printf args 76 #define AAC_D_INTR 0x01 77 #define AAC_D_MISC 0x02 78 #define AAC_D_CMD 0x04 79 #define AAC_D_QUEUE 0x08 80 #define AAC_D_IO 0x10 81 extern int aac_debug; 82 83 #define AAC_PRINT_FIB(sc, fib) aac_print_fib((sc), (fib), __FUNCTION__) 84 #else 85 #define AAC_DPRINTF(mask, args) 86 #define AAC_PRINT_FIB(sc, fib) 87 #endif 88 89 struct aac_code_lookup { 90 char *string; 91 u_int32_t code; 92 }; 93 94 extern const struct aac_code_lookup aac_command_status_table[]; 95 extern const struct aac_code_lookup aac_container_types[]; 96 97 struct aac_softc; 98 99 /* 100 * We allocate a small set of FIBs for the adapter to use to send us messages. 101 */ 102 #define AAC_ADAPTER_FIBS 8 103 104 /* 105 * Firmware messages are passed in the printf buffer. 106 */ 107 #define AAC_PRINTF_BUFSIZE 256 108 109 /* 110 * We wait this many seconds for the adapter to come ready if it is still 111 * booting. 112 */ 113 #define AAC_BOOT_TIMEOUT (3 * 60) 114 115 /* 116 * Wait this long for a lost interrupt to get detected. 117 */ 118 #define AAC_WATCH_TIMEOUT 10000 /* 10000 * 1ms = 10s */ 119 120 /* 121 * Timeout for immediate commands. 122 */ 123 #define AAC_IMMEDIATE_TIMEOUT 30 124 125 /* 126 * Delay 20ms after the qnotify in sync operations. Experimentally deduced. 127 */ 128 #define AAC_SYNC_DELAY 20000 129 130 /* 131 * The firmware interface allows for a 16-bit s/g list length. We limit 132 * ourselves to a reasonable maximum and ensure alignment. 133 */ 134 #define AAC_MAX_SGENTRIES 17 /* max S/G entries, limit 65535 */ 135 #define AAC_MAX_XFER ((AAC_MAX_SGENTRIES - 1) * PAGE_SIZE) 136 137 /* 138 * Fixed sector size. 139 */ 140 #define AAC_SECTOR_SIZE 512 141 142 /* 143 * Number of CCBs to allocate, and to reserve for control operations. 144 */ 145 #define AAC_NCCBS 256 146 #define AAC_NCCBS_RESERVE 4 147 148 /* 149 * Quirk listings. 150 */ 151 #define AAC_QUIRK_PERC2QC 0x0001 152 153 /* 154 * We gather a number of adapter-visible items into a single structure. 155 * 156 * The ordering of this structure may be important; we copy the Linux driver: 157 * 158 * Adapter FIBs 159 * Init struct 160 * Queue headers (Comm Area) 161 * Printf buffer 162 * 163 * In addition, we add: 164 * Sync Fib 165 */ 166 struct aac_common { 167 /* fibs for the controller to send us messages */ 168 struct aac_fib ac_fibs[AAC_ADAPTER_FIBS]; 169 170 /* the init structure */ 171 struct aac_adapter_init ac_init; 172 173 /* arena within which the queue structures are kept */ 174 u_int8_t ac_qbuf[sizeof(struct aac_queue_table) + AAC_QUEUE_ALIGN]; 175 176 /* buffer for text messages from the controller */ 177 char ac_printf[AAC_PRINTF_BUFSIZE]; 178 179 /* fib for synchronous commands */ 180 struct aac_fib ac_sync_fib; 181 }; 182 183 /* 184 * Interface operations 185 */ 186 struct aac_interface { 187 int (*aif_get_fwstatus)(struct aac_softc *); 188 void (*aif_qnotify)(struct aac_softc *, int); 189 int (*aif_get_istatus)(struct aac_softc *); 190 void (*aif_set_istatus)(struct aac_softc *, int); 191 void (*aif_set_mailbox)(struct aac_softc *, u_int32_t, 192 u_int32_t, u_int32_t, u_int32_t, u_int32_t); 193 int (*aif_get_mailboxstatus)(struct aac_softc *); 194 void (*aif_set_interrupts)(struct aac_softc *, int); 195 }; 196 197 #define AAC_GET_FWSTATUS(sc) ((sc)->sc_if.aif_get_fwstatus(sc)) 198 #define AAC_QNOTIFY(sc, qbit) \ 199 ((sc)->sc_if.aif_qnotify((sc), (qbit))) 200 #define AAC_GET_ISTATUS(sc) ((sc)->sc_if.aif_get_istatus(sc)) 201 #define AAC_CLEAR_ISTATUS(sc, mask) \ 202 ((sc)->sc_if.aif_set_istatus((sc), (mask))) 203 #define AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3) \ 204 do { \ 205 ((sc)->sc_if.aif_set_mailbox((sc), (command), (arg0), \ 206 (arg1), (arg2), (arg3))); \ 207 } while(0) 208 #define AAC_GET_MAILBOXSTATUS(sc) \ 209 ((sc)->sc_if.aif_get_mailboxstatus(sc)) 210 #define AAC_MASK_INTERRUPTS(sc) \ 211 ((sc)->sc_if.aif_set_interrupts((sc), 0)) 212 #define AAC_UNMASK_INTERRUPTS(sc) \ 213 ((sc)->sc_if.aif_set_interrupts((sc), 1)) 214 215 #define AAC_SETREG4(sc, reg, val) \ 216 bus_space_write_4((sc)->sc_memt, (sc)->sc_memh, (reg), (val)) 217 #define AAC_GETREG4(sc, reg) \ 218 bus_space_read_4((sc)->sc_memt, (sc)->sc_memh, (reg)) 219 #define AAC_SETREG2(sc, reg, val) \ 220 bus_space_write_2((sc)->sc_memt, (sc)->sc_memh, (reg), (val)) 221 #define AAC_GETREG2(sc, reg) \ 222 bus_space_read_2((sc)->sc_memt, (sc)->sc_memh, (reg)) 223 #define AAC_SETREG1(sc, reg, val) \ 224 bus_space_write_1((sc)->sc_memt, (sc)->sc_memh, (reg), (val)) 225 #define AAC_GETREG1(sc, reg) \ 226 bus_space_read_1((sc)->sc_memt, (sc)->sc_memh, (reg)) 227 228 229 /* 230 * A command contol block, one for each corresponding command index of the 231 * controller. 232 */ 233 struct aac_ccb { 234 SIMPLEQ_ENTRY(aac_ccb) ac_chain; 235 236 struct aac_fib *ac_fib; 237 bus_addr_t ac_fibphys; 238 bus_dmamap_t ac_dmamap_xfer; 239 240 void *ac_data; 241 size_t ac_datalen; 242 u_int ac_flags; 243 244 void (*ac_intr)(struct aac_ccb *); 245 struct device *ac_device; 246 void *ac_context; 247 }; 248 #define AAC_CCB_MAPPED 0x01 249 #define AAC_CCB_COMPLETED 0x02 250 #define AAC_CCB_DATA_IN 0x04 251 #define AAC_CCB_DATA_OUT 0x08 252 253 struct aac_drive { 254 u_int hd_present; 255 u_int hd_devtype; 256 u_int hd_size; 257 }; 258 259 /* 260 * Per-controller structure. 261 */ 262 struct aac_softc { 263 struct device sc_dv; 264 void *sc_ih; 265 bus_space_tag_t sc_memt; 266 bus_space_handle_t sc_memh; 267 bus_dma_tag_t sc_dmat; 268 269 struct FsaRevision sc_revision; 270 int sc_hwif; 271 int sc_quirks; 272 struct aac_interface sc_if; 273 274 struct aac_common *sc_common; 275 bus_dma_segment_t sc_common_seg; 276 bus_dmamap_t sc_common_dmamap; 277 struct aac_fib *sc_fibs; 278 bus_dma_segment_t sc_fibs_seg; 279 bus_dmamap_t sc_fibs_dmamap; 280 281 struct aac_ccb *sc_ccbs; 282 SIMPLEQ_HEAD(, aac_ccb) sc_ccb_free; 283 SIMPLEQ_HEAD(, aac_ccb) sc_ccb_queue; 284 SIMPLEQ_HEAD(, aac_ccb) sc_ccb_complete; 285 286 struct aac_queue_table *sc_queues; 287 struct aac_queue_entry *sc_qentries[AAC_QUEUE_COUNT]; 288 struct aac_drive sc_hdr[AAC_MAX_CONTAINERS]; 289 int sc_nunits; 290 int sc_flags; 291 }; 292 #define AAC_HWIF_I960RX 0 293 #define AAC_HWIF_STRONGARM 1 294 295 #define AAC_ONLINE 2 296 297 struct aac_attach_args { 298 int aaca_unit; 299 }; 300 301 int aac_attach(struct aac_softc *); 302 void aac_ccb_enqueue(struct aac_softc *, struct aac_ccb *); 303 void aac_ccb_free(struct aac_softc *, struct aac_ccb *); 304 struct aac_ccb *aac_ccb_alloc(struct aac_softc *, int); 305 int aac_ccb_map(struct aac_softc *, struct aac_ccb *); 306 int aac_ccb_poll(struct aac_softc *, struct aac_ccb *, int); 307 int aac_ccb_submit(struct aac_softc *, struct aac_ccb *); 308 void aac_ccb_unmap(struct aac_softc *, struct aac_ccb *); 309 const char *aac_describe_code(const struct aac_code_lookup *, u_int32_t); 310 int aac_intr(void *); 311 312 #endif /* !_PCI_AACVAR_H_ */ 313