amrvar.h revision 52543
1121330Sharti/*- 2121330Sharti * Copyright (c) 1999 Michael Smith 3121330Sharti * All rights reserved. 4121330Sharti * 5121330Sharti * Redistribution and use in source and binary forms, with or without 6121330Sharti * modification, are permitted provided that the following conditions 7121330Sharti * are met: 8121330Sharti * 1. Redistributions of source code must retain the above copyright 9121330Sharti * notice, this list of conditions and the following disclaimer. 10121330Sharti * 2. Redistributions in binary form must reproduce the above copyright 11121330Sharti * notice, this list of conditions and the following disclaimer in the 12121330Sharti * documentation and/or other materials provided with the distribution. 13121330Sharti * 14121330Sharti * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15121330Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16121330Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17121330Sharti * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18121330Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19121330Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20121330Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21121330Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22121330Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23121330Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24121330Sharti * SUCH DAMAGE. 25121330Sharti * 26121330Sharti * $FreeBSD: head/sys/dev/amr/amrvar.h 52543 1999-10-26 23:18:57Z msmith $ 27121330Sharti */ 28121330Sharti 29131823Sharti/* 30121330Sharti * We could actually use all 17 segments, but using only 16 means that 31121330Sharti * each scatter/gather map is 128 bytes in size, and thus we don't have to worry about 32121330Sharti * maps crossing page boundaries. 33121330Sharti */ 34121330Sharti#define AMR_NSEG 16 35121330Sharti 36121330Sharti#define AMR_CFG_BASE 0x10 37121330Sharti#define AMR_CFG_SIG 0xa0 38121330Sharti#define AMR_SIGNATURE 0x3344 39121330Sharti 40121330Sharti#define AMR_MAXCMD 255 /* ident = 0 not allowed */ 41121330Sharti#define AMR_MAXLD 40 42121330Sharti 43121330Sharti#define AMR_BLKSIZE 512 44121330Sharti 45121330Shartistruct amr_softc; 46121330Sharti 47121330Sharti/* 48121330Sharti * Per-logical-drive datastructure 49121330Sharti */ 50121330Shartistruct amr_logdrive 51121330Sharti{ 52121330Sharti u_int32_t al_size; 53121330Sharti int al_state; 54121330Sharti int al_properties; 55121330Sharti 56121330Sharti /* synthetic geometry */ 57121330Sharti int al_cylinders; 58121330Sharti int al_heads; 59121330Sharti int al_sectors; 60121330Sharti 61121330Sharti /* driver */ 62121330Sharti device_t al_disk; 63121330Sharti}; 64121330Sharti 65121330Sharti 66121330Sharti/* 67121330Sharti * Per-command control structure. 68121330Sharti */ 69121330Shartistruct amr_command 70121330Sharti{ 71121330Sharti TAILQ_ENTRY(amr_command) ac_link; 72121330Sharti 73121330Sharti struct amr_softc *ac_sc; 74121330Sharti u_int8_t ac_slot; 75121330Sharti int ac_status; 76121330Sharti#define AMR_STATUS_BUSY 0xffff 77121330Sharti#define AMR_STATUS_WEDGED 0xdead 78121330Sharti struct amr_mailbox ac_mailbox; 79121330Sharti u_int32_t ac_sgphys; 80121330Sharti int ac_nsgent; 81121330Sharti int ac_flags; 82121330Sharti#define AMR_CMD_DATAIN (1<<0) 83121330Sharti#define AMR_CMD_DATAOUT (1<<1) 84121330Sharti#define AMR_CMD_PRIORITY (1<<2) 85121330Sharti time_t ac_stamp; 86121330Sharti 87121330Sharti void *ac_data; 88121330Sharti size_t ac_length; 89121330Sharti bus_dmamap_t ac_dmamap; 90121330Sharti u_int32_t ac_dataphys; 91121330Sharti 92121330Sharti void (* ac_complete)(struct amr_command *ac); 93121330Sharti void *ac_private; 94121330Sharti}; 95121330Sharti 96121330Shartistruct amr_softc 97121330Sharti{ 98121330Sharti /* bus attachments */ 99121330Sharti device_t amr_dev; 100121330Sharti struct resource *amr_reg; /* control registers */ 101121330Sharti bus_space_handle_t amr_bhandle; 102121330Sharti bus_space_tag_t amr_btag; 103121330Sharti bus_dma_tag_t amr_parent_dmat; /* parent DMA tag */ 104121330Sharti bus_dma_tag_t amr_buffer_dmat; /* data buffer DMA tag */ 105121330Sharti struct resource *amr_irq; /* interrupt */ 106121330Sharti void *amr_intr; 107121330Sharti 108121330Sharti /* mailbox */ 109121330Sharti struct amr_mailbox *amr_mailbox; 110121330Sharti struct amr_mailbox64 *amr_mailbox64; 111121330Sharti u_int32_t amr_mailboxphys; 112121330Sharti bus_dma_tag_t amr_mailbox_dmat; 113121330Sharti bus_dmamap_t amr_mailbox_dmamap; 114121330Sharti 115121330Sharti /* scatter/gather lists and their controller-visible mappings */ 116121330Sharti struct amr_sgentry *amr_sgtable; /* s/g lists */ 117121330Sharti u_int32_t amr_sgbusaddr; /* s/g table base address in bus space */ 118121330Sharti bus_dma_tag_t amr_sg_dmat; /* s/g buffer DMA tag */ 119121330Sharti bus_dmamap_t amr_sg_dmamap; /* map for s/g buffers */ 120121330Sharti 121121330Sharti /* controller limits and features */ 122121330Sharti int amr_maxio; /* maximum number of I/O transactions */ 123121330Sharti int amr_maxdrives; /* max number of logical drives */ 124121330Sharti 125121330Sharti /* connected logical drives */ 126121330Sharti struct amr_logdrive amr_drive[AMR_MAXLD]; 127121330Sharti 128121330Sharti /* controller status */ 129121330Sharti int amr_state; 130121330Sharti#define AMR_STATE_OPEN (1<<0) 131121330Sharti#define AMR_STATE_SUSPEND (1<<1) 132121330Sharti#define AMR_STATE_INTEN (1<<2) 133121330Sharti#define AMR_STATE_SHUTDOWN (1<<3) 134121330Sharti 135121330Sharti /* per-controller queues */ 136121330Sharti struct buf_queue_head amr_bufq; /* pending I/O */ 137121330Sharti int amr_waitbufs; 138121330Sharti struct amr_command *amr_busycmd[AMR_MAXCMD]; 139121330Sharti int amr_busycmdcount; 140121330Sharti TAILQ_HEAD(,amr_command) amr_work; 141121330Sharti int amr_workcount; 142121330Sharti TAILQ_HEAD(,amr_command) amr_freecmds; 143121330Sharti 144121330Sharti /* controller type-specific support */ 145121330Sharti int amr_type; 146121330Sharti#define AMR_TYPE_STD 0 147121330Sharti#define AMR_TYPE_QUARTZ 1 148121330Sharti void (* amr_submit_command)(struct amr_softc *sc); 149121330Sharti int (* amr_get_work)(struct amr_softc *sc, struct amr_mailbox *mbsave); 150121330Sharti void (* amr_attach_mailbox)(struct amr_softc *sc); 151121330Sharti}; 152121330Sharti 153121330Sharti/* 154121330Sharti * I/O primitives 155121330Sharti */ 156121330Sharti/* Quartz */ 157121330Sharti#define AMR_QPUT_IDB(sc, val) bus_space_write_4(sc->amr_btag, sc->amr_bhandle, AMR_QIDB, val) 158121330Sharti#define AMR_QGET_IDB(sc) bus_space_read_4 (sc->amr_btag, sc->amr_bhandle, AMR_QIDB) 159121330Sharti#define AMR_QPUT_ODB(sc, val) bus_space_write_4(sc->amr_btag, sc->amr_bhandle, AMR_QODB, val) 160121330Sharti#define AMR_QGET_ODB(sc) bus_space_read_4 (sc->amr_btag, sc->amr_bhandle, AMR_QODB) 161121330Sharti 162121330Sharti/* Standard */ 163121330Sharti#define AMR_SPUT_ISTAT(sc, val) bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_SINTR, val) 164121330Sharti#define AMR_SGET_ISTAT(sc) bus_space_read_1 (sc->amr_btag, sc->amr_bhandle, AMR_SINTR) 165121330Sharti#define AMR_SACK_INTERRUPT(sc) bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_SCMD, AMR_SCMD_ACKINTR) 166121330Sharti#define AMR_SPOST_COMMAND(sc) bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_SCMD, AMR_SCMD_POST) 167121330Sharti#define AMR_SGET_MBSTAT(sc) bus_space_read_1 (sc->amr_btag, sc->amr_bhandle, AMR_SMBOX_BUSY) 168121330Sharti#define AMR_SENABLE_INTR(sc) \ 169121330Sharti bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_STOGGLE, \ 170121330Sharti bus_space_read_1(sc->amr_btag, sc->amr_bhandle, AMR_STOGGLE) | AMR_STOGL_IENABLE) 171121330Sharti#define AMR_SDISABLE_INTR(sc) \ 172121330Sharti bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_STOGGLE, \ 173121330Sharti bus_space_read_1(sc->amr_btag, sc->amr_bhandle, AMR_STOGGLE) & ~AMR_STOGL_IENABLE) 174121330Sharti#define AMR_SBYTE_SET(sc, reg, val) bus_space_write_1(sc->amr_btag, sc->amr_bhandle, reg, val) 175121330Sharti 176121330Sharti/* 177121330Sharti * Interface between bus connections and driver core. 178121330Sharti */ 179121330Shartiextern void amr_free(struct amr_softc *sc); 180121330Shartiextern int amr_attach(struct amr_softc *sc); 181121330Shartiextern void amr_startup(struct amr_softc *sc); 182121330Shartiextern void amr_intr(void *data); 183121330Shartiextern int amr_detach(device_t dev); 184121330Shartiextern int amr_shutdown(device_t dev); 185121330Shartiextern int amr_suspend(device_t dev); 186121330Shartiextern int amr_resume(device_t dev); 187121330Shartiextern d_open_t amr_open; 188121330Shartiextern d_close_t amr_close; 189121330Shartiextern d_ioctl_t amr_ioctl; 190121330Sharti 191121330Shartiextern devclass_t amr_devclass; 192121330Sharti 193121330Sharti/* 194121330Sharti * MegaRAID logical disk driver 195121330Sharti */ 196121330Shartistruct amrd_softc 197121330Sharti{ 198121330Sharti device_t amrd_dev; 199121330Sharti struct amr_softc *amrd_controller; 200121330Sharti struct amr_logdrive *amrd_drive; 201121330Sharti struct disk amrd_disk; 202121330Sharti struct devstat amrd_stats; 203121330Sharti struct disklabel amrd_label; 204121330Sharti int amrd_unit; 205121330Sharti int amrd_flags; 206121330Sharti#define AMRD_OPEN (1<<0) /* drive is open (can't shut down) */ 207121330Sharti}; 208121330Sharti 209121330Sharti/* 210121330Sharti * Interface between driver core and disk driver (should be using a bus?) 211121330Sharti */ 212121330Shartiextern int amr_submit_buf(struct amr_softc *sc, struct buf *bp); 213121330Shartiextern int amr_submit_ioctl(struct amr_softc *sc, struct amr_logdrive *drive, u_long cmd, 214121330Sharti caddr_t addr, int32_t flag, struct proc *p); 215121330Shartiextern void amrd_intr(void *data); 216121330Sharti 217121330Sharti