1 /*- 2 * Copyright (c) 1999,2000 Jonathan Lemon 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: src/sys/dev/ida/idavar.h,v 1.3.2.4 2001/07/30 20:29:58 jlemon Exp $ 27 * $DragonFly: src/sys/dev/raid/ida/idavar.h,v 1.4 2007/05/15 22:44:10 dillon Exp $ 28 */ 29 30 /* 31 * software structures for the Compaq RAID controller 32 */ 33 34 #ifndef _IDAVAR_H 35 #define _IDAVAR_H 36 37 #define ida_inb(ida, port) \ 38 bus_space_read_1((ida)->tag, (ida)->bsh, port) 39 #define ida_inw(ida, port) \ 40 bus_space_read_2((ida)->tag, (ida)->bsh, port) 41 #define ida_inl(ida, port) \ 42 bus_space_read_4((ida)->tag, (ida)->bsh, port) 43 44 #define ida_outb(ida, port, val) \ 45 bus_space_write_1((ida)->tag, (ida)->bsh, port, val) 46 #define ida_outw(ida, port, val) \ 47 bus_space_write_2((ida)->tag, (ida)->bsh, port, val) 48 #define ida_outl(ida, port, val) \ 49 bus_space_write_4((ida)->tag, (ida)->bsh, port, val) 50 51 struct ida_hdr { 52 u_int8_t drive; /* logical drive */ 53 u_int8_t priority; /* block priority */ 54 u_int16_t size; /* size of request, in words */ 55 }; 56 57 struct ida_req { 58 u_int16_t next; /* offset of next request */ 59 u_int8_t command; /* command */ 60 u_int8_t error; /* return error code */ 61 u_int32_t blkno; /* block number */ 62 u_int16_t bcount; /* block count */ 63 u_int8_t sgcount; /* number of scatter/gather entries */ 64 u_int8_t spare; /* reserved */ 65 }; 66 67 struct ida_sgb { 68 u_int32_t length; /* length of S/G segment */ 69 u_int32_t addr; /* physical address of block */ 70 }; 71 72 #define IDA_NSEG 32 /* maximum number of segments */ 73 74 /* 75 * right now, this structure totals 276 bytes. 76 */ 77 struct ida_hardware_qcb { 78 struct ida_hdr hdr; /* 4 */ 79 struct ida_req req; /* 12 */ 80 struct ida_sgb seg[IDA_NSEG]; /* 256 */ 81 struct ida_qcb *qcb; /* 4 - qcb backpointer */ 82 }; 83 84 typedef enum { 85 QCB_FREE = 0x0000, 86 QCB_ACTIVE = 0x0001, /* waiting for completion */ 87 } qcb_state; 88 89 #define DMA_DATA_IN 0x0001 90 #define DMA_DATA_OUT 0x0002 91 #define IDA_COMMAND 0x0004 92 #define DMA_DATA_TRANSFER (DMA_DATA_IN | DMA_DATA_OUT) 93 94 #define IDA_QCB_MAX 256 95 #define IDA_CONTROLLER 0 /* drive "number" for controller */ 96 97 struct ida_qcb { 98 struct ida_hardware_qcb *hwqcb; 99 qcb_state state; 100 short flags; 101 union { 102 STAILQ_ENTRY(ida_qcb) stqe; 103 SLIST_ENTRY(ida_qcb) sle; 104 } link; 105 bus_dmamap_t dmamap; 106 bus_addr_t hwqcb_busaddr; 107 struct bio *bio; /* bio associated with qcb */ 108 }; 109 110 struct ida_softc; 111 112 struct ida_access { 113 int (*fifo_full)(struct ida_softc *); 114 void (*submit)(struct ida_softc *, struct ida_qcb *); 115 bus_addr_t (*done)(struct ida_softc *); 116 int (*int_pending)(struct ida_softc *); 117 void (*int_enable)(struct ida_softc *, int); 118 }; 119 120 /* 121 * flags for the controller 122 */ 123 #define IDA_ATTACHED 0x01 /* attached */ 124 #define IDA_FIRMWARE 0x02 /* firmware must be started */ 125 #define IDA_INTERRUPTS 0x04 /* interrupts enabled */ 126 127 struct ida_softc { 128 device_t dev; 129 int unit; 130 131 int regs_res_type; 132 int regs_res_id; 133 struct resource *regs; 134 135 int irq_res_type; 136 struct resource *irq; 137 void *ih; 138 139 bus_space_tag_t tag; 140 bus_space_handle_t bsh; 141 142 /* various DMA tags */ 143 bus_dma_tag_t parent_dmat; 144 bus_dma_tag_t buffer_dmat; 145 146 bus_dma_tag_t hwqcb_dmat; 147 bus_dmamap_t hwqcb_dmamap; 148 bus_addr_t hwqcb_busaddr; 149 150 bus_dma_tag_t sg_dmat; 151 152 int num_drives; 153 int num_qcbs; 154 int flags; 155 156 struct ida_hardware_qcb *hwqcbs; /* HW QCB array */ 157 struct ida_qcb *qcbs; /* kernel QCB array */ 158 SLIST_HEAD(, ida_qcb) free_qcbs; 159 STAILQ_HEAD(, ida_qcb) qcb_queue; 160 struct bio_queue_head bio_queue; 161 162 struct ida_access cmd; 163 }; 164 165 /* 166 * drive flags 167 */ 168 #define DRV_WRITEPROT 0x0001 169 170 struct idad_softc { 171 device_t dev; 172 struct ida_softc *controller; 173 struct disk disk; 174 struct devstat stats; 175 int drive; /* per controller */ 176 int unit; /* global */ 177 int cylinders; 178 int heads; 179 int sectors; 180 int secsize; 181 int secperunit; 182 int flags; 183 }; 184 185 struct ida_board { 186 u_int32_t board; 187 char *desc; 188 struct ida_access *accessor; 189 int flags; 190 }; 191 192 extern int ida_detach(device_t dev); 193 extern struct ida_softc *ida_alloc(device_t dev, struct resource *regs, 194 int regs_type, int regs_id, bus_dma_tag_t parent_dmat); 195 extern void ida_free(struct ida_softc *ida); 196 extern int ida_init(struct ida_softc *ida); 197 extern void ida_attach(struct ida_softc *ida); 198 extern int ida_command(struct ida_softc *ida, int command, void *data, 199 int datasize, int drive, u_int64_t pblkno, int flags); 200 extern void ida_submit_buf(struct ida_softc *ida, struct bio *bio); 201 extern void ida_intr(void *data); 202 203 extern void idad_intr(struct bio *bio); 204 205 #endif /* _IDAVAR_H */ 206