1 /* $NetBSD: aacvar.h,v 1.15 2016/09/27 03:33:32 pgoyette 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /*- 33 * Copyright (c) 2000 Michael Smith 34 * Copyright (c) 2000 BSDi 35 * Copyright (c) 2000 Niklas Hallqvist 36 * All rights reserved. 37 * 38 * Redistribution and use in source and binary forms, with or without 39 * modification, are permitted provided that the following conditions 40 * are met: 41 * 1. Redistributions of source code must retain the above copyright 42 * notice, this list of conditions and the following disclaimer. 43 * 2. Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in the 45 * documentation and/or other materials provided with the distribution. 46 * 47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * SUCH DAMAGE. 58 * 59 * from FreeBSD: aacvar.h,v 1.1 2000/09/13 03:20:34 msmith Exp 60 * via OpenBSD: aacvar.h,v 1.2 2002/03/14 01:26:53 millert Exp 61 */ 62 63 #ifndef _PCI_AACVAR_H_ 64 #define _PCI_AACVAR_H_ 65 66 /* Debugging */ 67 #ifdef AAC_DEBUG 68 #define AAC_DPRINTF(mask, args) if ((aac_debug & (mask)) != 0) printf args 69 #define AAC_D_INTR 0x01 70 #define AAC_D_MISC 0x02 71 #define AAC_D_CMD 0x04 72 #define AAC_D_QUEUE 0x08 73 #define AAC_D_IO 0x10 74 extern int aac_debug; 75 76 #define AAC_PRINT_FIB(sc, fib) aac_print_fib((sc), (fib), __func__) 77 #else 78 #define AAC_DPRINTF(mask, args) 79 #define AAC_PRINT_FIB(sc, fib) 80 #endif 81 82 struct aac_code_lookup { 83 const char *string; 84 u_int32_t code; 85 }; 86 87 extern const struct aac_code_lookup aac_command_status_table[]; 88 extern const struct aac_code_lookup aac_container_types[]; 89 90 struct aac_softc; 91 92 /* 93 * We allocate a small set of FIBs for the adapter to use to send us messages. 94 */ 95 #define AAC_ADAPTER_FIBS 8 96 97 /* 98 * FIBs are allocated in page-size chunks and can grow up to the 512 99 * limit imposed by the hardware. 100 * XXX -- There should be some way to allocate these as-needed without 101 * allocating them at interrupt time. For now, though, allocate 102 * all that we'll ever need up-front. 103 */ 104 #define AAC_PREALLOCATE_FIBS(sc) ((sc)->sc_max_fibs) 105 106 /* 107 * Firmware messages are passed in the printf buffer. 108 */ 109 #define AAC_PRINTF_BUFSIZE 256 110 111 /* 112 * We wait this many seconds for the adapter to come ready if it is still 113 * booting. 114 */ 115 #define AAC_BOOT_TIMEOUT (3 * 60) 116 117 /* 118 * Wait this long for a lost interrupt to get detected. 119 */ 120 #define AAC_WATCH_TIMEOUT 10000 /* 10000 * 1ms = 10s */ 121 122 /* 123 * Timeout for immediate commands. 124 */ 125 #define AAC_IMMEDIATE_TIMEOUT 30 126 127 /* 128 * Delay 20ms after the qnotify in sync operations. Experimentally deduced. 129 */ 130 #define AAC_SYNC_DELAY 20000 131 132 /* 133 * sc->sc_max_sgs is the number of scatter-gather elements we can fit 134 * in one block I/O request (64-bit or 32-bit, depending) FIB, or the 135 * maximum number that the firmware will accept. We subtract one to 136 * deal with requests that do not start on an even page boundary. 137 */ 138 #define AAC_MAX_XFER(sc) (((sc)->sc_max_sgs - 1) * PAGE_SIZE) 139 140 /* 141 * Fixed sector size. 142 */ 143 #define AAC_SECTOR_SIZE 512 144 145 /* 146 * Number of CCBs to reserve for control operations. 147 */ 148 #define AAC_NCCBS_RESERVE 8 149 150 /* 151 * Quirk listings. 152 */ 153 #define AAC_QUIRK_PERC2QC (1 << 0) /* Dell PERC 2QC */ 154 #define AAC_QUIRK_SG_64BIT (1 << 4) /* Use 64-bit S/G addresses */ 155 #define AAC_QUIRK_4GB_WINDOW (1 << 5) /* Device can access host mem 156 * in 2GB-4GB range */ 157 #define AAC_QUIRK_NO4GB (1 << 6) /* Can't access host mem >2GB */ 158 #define AAC_QUIRK_256FIBS (1 << 7) /* Can only handle 256 cmds */ 159 #define AAC_QUIRK_BROKEN_MMAP (1 << 8) /* Broken HostPhysMemPages */ 160 #define AAC_QUIRK_NEW_COMM (1 << 11) /* New comm. i/f supported */ 161 #define AAC_QUIRK_RAW_IO (1 << 12) /* Raw I/O interface */ 162 #define AAC_QUIRK_ARRAY_64BIT (1 << 13) /* 64-bit array size */ 163 #define AAC_QUIRK_LBA_64BIT (1 << 14) /* 64-bit LBA support */ 164 165 166 /* 167 * We gather a number of adapter-visible items into a single structure. 168 * 169 * The ordering of this structure may be important; we copy the Linux driver: 170 * 171 * Adapter FIBs 172 * Init struct 173 * Queue headers (Comm Area) 174 * Printf buffer 175 * 176 * In addition, we add: 177 * Sync Fib 178 */ 179 struct aac_common { 180 /* fibs for the controller to send us messages */ 181 struct aac_fib ac_fibs[AAC_ADAPTER_FIBS]; 182 183 /* the init structure */ 184 struct aac_adapter_init ac_init; 185 186 /* arena within which the queue structures are kept */ 187 u_int8_t ac_qbuf[sizeof(struct aac_queue_table) + AAC_QUEUE_ALIGN]; 188 189 /* buffer for text messages from the controller */ 190 char ac_printf[AAC_PRINTF_BUFSIZE]; 191 192 /* fib for synchronous commands */ 193 struct aac_fib ac_sync_fib; 194 }; 195 196 struct aac_ccb; 197 198 /* 199 * Interface operations 200 */ 201 struct aac_interface { 202 int (*aif_get_fwstatus)(struct aac_softc *); 203 void (*aif_qnotify)(struct aac_softc *, int); 204 int (*aif_get_istatus)(struct aac_softc *); 205 void (*aif_set_istatus)(struct aac_softc *, int); 206 void (*aif_set_mailbox)(struct aac_softc *, u_int32_t, 207 u_int32_t, u_int32_t, u_int32_t, u_int32_t); 208 uint32_t (*aif_get_mailbox)(struct aac_softc *, int); 209 void (*aif_set_interrupts)(struct aac_softc *, int); 210 int (*aif_send_command)(struct aac_softc *, struct aac_ccb *); 211 int (*aif_get_outb_queue)(struct aac_softc *); 212 void (*aif_set_outb_queue)(struct aac_softc *, int); 213 }; 214 215 #define AAC_GET_FWSTATUS(sc) ((sc)->sc_if.aif_get_fwstatus(sc)) 216 #define AAC_QNOTIFY(sc, qbit) \ 217 ((sc)->sc_if.aif_qnotify((sc), (qbit))) 218 #define AAC_GET_ISTATUS(sc) ((sc)->sc_if.aif_get_istatus(sc)) 219 #define AAC_CLEAR_ISTATUS(sc, mask) \ 220 ((sc)->sc_if.aif_set_istatus((sc), (mask))) 221 #define AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3) \ 222 do { \ 223 ((sc)->sc_if.aif_set_mailbox((sc), (command), (arg0), \ 224 (arg1), (arg2), (arg3))); \ 225 } while(0) 226 #define AAC_GET_MAILBOX(sc, mb) ((sc)->sc_if.aif_get_mailbox(sc, mb)) 227 #define AAC_GET_MAILBOXSTATUS(sc) (AAC_GET_MAILBOX(sc, 0)) 228 #define AAC_MASK_INTERRUPTS(sc) \ 229 ((sc)->sc_if.aif_set_interrupts((sc), 0)) 230 #define AAC_UNMASK_INTERRUPTS(sc) \ 231 ((sc)->sc_if.aif_set_interrupts((sc), 1)) 232 #define AAC_SEND_COMMAND(sc, cm) \ 233 ((sc)->sc_if.aif_send_command((sc), cm)) 234 #define AAC_GET_OUTB_QUEUE(sc) \ 235 ((sc)->sc_if.aif_get_outb_queue((sc))) 236 #define AAC_SET_OUTB_QUEUE(sc, idx) \ 237 ((sc)->sc_if.aif_set_outb_queue((sc), (idx))) 238 239 #define AAC_SETREG4(sc, reg, val) \ 240 bus_space_write_4((sc)->sc_memt, (sc)->sc_memh, (reg), (val)) 241 #define AAC_GETREG4(sc, reg) \ 242 bus_space_read_4((sc)->sc_memt, (sc)->sc_memh, (reg)) 243 #define AAC_SETREG2(sc, reg, val) \ 244 bus_space_write_2((sc)->sc_memt, (sc)->sc_memh, (reg), (val)) 245 #define AAC_GETREG2(sc, reg) \ 246 bus_space_read_2((sc)->sc_memt, (sc)->sc_memh, (reg)) 247 #define AAC_SETREG1(sc, reg, val) \ 248 bus_space_write_1((sc)->sc_memt, (sc)->sc_memh, (reg), (val)) 249 #define AAC_GETREG1(sc, reg) \ 250 bus_space_read_1((sc)->sc_memt, (sc)->sc_memh, (reg)) 251 252 struct aac_fibmap { 253 TAILQ_ENTRY(aac_fibmap) fm_link; 254 struct aac_fib *fm_fibs; 255 bus_dma_segment_t fm_fibseg; 256 bus_dmamap_t fm_fibmap; 257 struct aac_ccb *fm_ccbs; 258 }; 259 260 /* 261 * A command control block, one for each corresponding command index 262 * of the controller. 263 */ 264 struct aac_ccb { 265 SIMPLEQ_ENTRY(aac_ccb) ac_chain; 266 267 struct aac_fib *ac_fib; 268 struct aac_fibmap *ac_fibmap; 269 bus_addr_t ac_fibphys; 270 bus_dmamap_t ac_dmamap_xfer; 271 272 void *ac_data; 273 size_t ac_datalen; 274 u_int ac_flags; 275 276 void (*ac_intr)(struct aac_ccb *); 277 device_t ac_device; 278 void *ac_context; 279 }; 280 #define AAC_CCB_MAPPED 0x01 281 #define AAC_CCB_COMPLETED 0x02 282 #define AAC_CCB_DATA_IN 0x04 283 #define AAC_CCB_DATA_OUT 0x08 284 285 struct aac_drive { 286 u_int hd_present; 287 u_int hd_devtype; 288 u_int64_t hd_size; 289 }; 290 291 /* 292 * Per-controller structure. 293 */ 294 struct aac_softc { 295 device_t sc_dv; 296 void *sc_ih; 297 bus_space_tag_t sc_memt; 298 bus_space_handle_t sc_memh; 299 bus_dma_tag_t sc_dmat; 300 bus_size_t sc_regsize; 301 302 struct FsaRevision sc_revision; 303 int sc_hwif; 304 int sc_quirks; 305 struct aac_interface sc_if; 306 307 u_int32_t sc_max_fibs; 308 u_int32_t sc_max_fibs_alloc; 309 u_int32_t sc_max_sectors; 310 u_int32_t sc_max_fib_size; 311 u_int32_t sc_max_sgs; 312 313 u_int32_t sc_total_fibs; 314 TAILQ_HEAD(,aac_fibmap) sc_fibmap_tqh; 315 316 struct aac_common *sc_common; 317 bus_dma_segment_t sc_common_seg; 318 bus_dmamap_t sc_common_dmamap; 319 struct aac_fib *sc_aif_fib; 320 321 struct aac_ccb *sc_ccbs; 322 SIMPLEQ_HEAD(, aac_ccb) sc_ccb_free; 323 SIMPLEQ_HEAD(, aac_ccb) sc_ccb_queue; 324 SIMPLEQ_HEAD(, aac_ccb) sc_ccb_complete; 325 326 struct aac_queue_table *sc_queues; 327 struct aac_queue_entry *sc_qentries[AAC_QUEUE_COUNT]; 328 struct aac_drive sc_hdr[AAC_MAX_CONTAINERS]; 329 int sc_nunits; 330 int sc_flags; 331 uint32_t sc_supported_options; 332 333 /* Set by parent */ 334 int (*sc_intr_set)(struct aac_softc *, 335 int (*)(void *), void *); 336 }; 337 #define AAC_HWIF_I960RX 0 338 #define AAC_HWIF_STRONGARM 1 339 #define AAC_HWIF_FALCON 2 340 #define AAC_HWIF_RKT 3 341 #define AAC_HWIF_UNKNOWN -1 342 343 #define AAC_ONLINE 2 344 345 struct aac_attach_args { 346 int aaca_unit; 347 }; 348 349 int aac_attach(struct aac_softc *); 350 int aac_devscan(struct aac_softc *); 351 void aac_ccb_enqueue(struct aac_softc *, struct aac_ccb *); 352 void aac_ccb_free(struct aac_softc *, struct aac_ccb *); 353 struct aac_ccb *aac_ccb_alloc(struct aac_softc *, int); 354 int aac_ccb_map(struct aac_softc *, struct aac_ccb *); 355 int aac_ccb_poll(struct aac_softc *, struct aac_ccb *, int); 356 int aac_ccb_submit(struct aac_softc *, struct aac_ccb *); 357 void aac_ccb_unmap(struct aac_softc *, struct aac_ccb *); 358 const char *aac_describe_code(const struct aac_code_lookup *, u_int32_t); 359 int aac_intr(void *); 360 361 #endif /* !_PCI_AACVAR_H_ */ 362