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