1 /* $OpenBSD: cacvar.h,v 1.9 2020/07/22 13:16:04 krw Exp $ */ 2 /* $NetBSD: cacvar.h,v 1.7 2000/10/19 14:28:47 ad Exp $ */ 3 4 /*- 5 * Copyright (c) 2000 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Andrew Doran. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #ifndef _IC_CACVAR_H_ 34 #define _IC_CACVAR_H_ 35 36 #define CAC_MAX_CCBS 128 37 #define CAC_MAX_XFER (0xffff * 512) 38 #define CAC_SG_SIZE 32 39 #define CAC_SECTOR_SIZE 512 40 41 #define cac_inb(sc, port) \ 42 bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh, port) 43 #define cac_inw(sc, port) \ 44 bus_space_read_2((sc)->sc_iot, (sc)->sc_ioh, port) 45 #define cac_inl(sc, port) \ 46 bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, port) 47 #define cac_outb(sc, port, val) \ 48 bus_space_write_1((sc)->sc_iot, (sc)->sc_ioh, port, val) 49 #define cac_outw(sc, port, val) \ 50 bus_space_write_2((sc)->sc_iot, (sc)->sc_ioh, port, val) 51 #define cac_outl(sc, port, val) \ 52 bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, port, val) 53 54 /* 55 * Stupid macros to deal with alignment/endianness issues. 56 */ 57 58 #define CAC_GET1(x) \ 59 (((u_char *)&(x))[0]) 60 #define CAC_GET2(x) \ 61 (((u_char *)&(x))[0] | (((u_char *)&(x))[1] << 8)) 62 #define CAC_GET4(x) \ 63 ((((u_char *)&(x))[0] | (((u_char *)&(x))[1] << 8)) | \ 64 (((u_char *)&(x))[2] << 16 | (((u_char *)&(x))[3] << 24))) 65 66 struct cac_ccb { 67 /* Data the controller will touch - 276 bytes */ 68 struct cac_hdr ccb_hdr; 69 struct cac_req ccb_req; 70 struct cac_sgb ccb_seg[CAC_SG_SIZE]; 71 72 /* Data the controller won't touch */ 73 int ccb_flags; 74 int ccb_datasize; 75 paddr_t ccb_paddr; 76 bus_dmamap_t ccb_dmamap_xfer; 77 SIMPLEQ_ENTRY(cac_ccb) ccb_chain; 78 struct scsi_xfer *ccb_xs; 79 }; 80 81 #define CAC_CCB_DATA_IN 0x0001 /* Map describes inbound xfer */ 82 #define CAC_CCB_DATA_OUT 0x0002 /* Map describes outbound xfer */ 83 #define CAC_CCB_ACTIVE 0x0004 /* Command submitted to controller */ 84 85 struct cac_softc; 86 87 struct cac_linkage { 88 struct cac_ccb *(*cl_completed)(struct cac_softc *); 89 int (*cl_fifo_full)(struct cac_softc *); 90 void (*cl_intr_enable)(struct cac_softc *, int); 91 int (*cl_intr_pending)(struct cac_softc *); 92 void (*cl_submit)(struct cac_softc *, struct cac_ccb *); 93 }; 94 95 struct cac_softc { 96 struct device sc_dv; 97 bus_space_tag_t sc_iot; 98 bus_space_handle_t sc_ioh; 99 bus_dma_tag_t sc_dmat; 100 bus_dmamap_t sc_dmamap; 101 int sc_nunits; 102 void *sc_ih; 103 struct scsibus_softc *sc_scsibus; 104 const struct cac_linkage *sc_cl; 105 caddr_t sc_ccbs; 106 paddr_t sc_ccbs_paddr; 107 SIMPLEQ_HEAD(, cac_ccb) sc_ccb_free; 108 SIMPLEQ_HEAD(, cac_ccb) sc_ccb_queue; 109 struct cac_drive_info *sc_dinfos; 110 int (*sc_ioctl)(struct device *, u_long, caddr_t); 111 struct ksensor *sc_sensors; 112 struct ksensordev sc_sensordev; 113 114 struct mutex sc_ccb_mtx; /* ccb queue protection */ 115 struct scsi_iopool sc_iopool; 116 }; 117 118 /* XXX These have to become spinlocks in case of fine SMP */ 119 #define CAC_LOCK(sc) splbio() 120 #define CAC_UNLOCK(sc, lock) splx(lock) 121 typedef int cac_lock_t; 122 123 int cac_init(struct cac_softc *, int); 124 int cac_intr(void *); 125 int cac_flush(struct cac_softc *); 126 127 extern const struct cac_linkage cac_l0; 128 129 #endif /* !_IC_CACVAR_H_ */ 130