1 /* $NetBSD: amrvar.h,v 1.10 2015/03/02 15:26:57 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 2002, 2003 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 #ifndef _PCI_AMRVAR_H_ 33 #define _PCI_AMRVAR_H_ 34 35 #define AMR_MAX_UNITS 16 36 #define AMR_WDOG_TICKS (hz * 5) 37 #define AMR_NCCB_RESV 2 38 #define AMR_ENQUIRY_BUFSIZE 2048 39 #define AMR_SGL_SIZE (sizeof(struct amr_sgentry) * AMR_MAX_SEGS) 40 #define AMR_TIMEOUT 30 41 42 /* 43 * Logical drive information. 44 */ 45 struct amr_logdrive { 46 u_int al_size; 47 u_short al_state; 48 u_short al_properties; 49 device_t al_dv; 50 }; 51 52 /* 53 * Per-controller state. 54 */ 55 struct amr_softc { 56 device_t amr_dv; 57 bus_space_tag_t amr_iot; 58 bus_space_handle_t amr_ioh; 59 bus_size_t amr_ios; 60 bus_dma_tag_t amr_dmat; 61 pci_chipset_tag_t amr_pc; 62 void *amr_ih; 63 struct lwp *amr_thread; 64 int amr_flags; 65 66 struct amr_mailbox *amr_mbox; 67 bus_addr_t amr_mbox_paddr; 68 bus_dmamap_t amr_dmamap; 69 bus_dma_segment_t amr_dmaseg; 70 int amr_dmasize; 71 void *amr_enqbuf; 72 73 struct amr_sgentry *amr_sgls; 74 bus_addr_t amr_sgls_paddr; 75 76 struct amr_ccb *amr_ccbs; 77 SLIST_HEAD(, amr_ccb) amr_ccb_freelist; 78 SIMPLEQ_HEAD(, amr_ccb) amr_ccb_queue; 79 TAILQ_HEAD(, amr_ccb) amr_ccb_active; 80 int amr_maxqueuecnt; 81 82 int (*amr_get_work)(struct amr_softc *, struct amr_mailbox_resp *); 83 int (*amr_submit)(struct amr_softc *sc, struct amr_ccb *); 84 85 kmutex_t amr_mutex; 86 87 int amr_numdrives; 88 struct amr_logdrive amr_drive[AMR_MAX_UNITS]; 89 }; 90 91 /* What resources are allocated? */ 92 #define AMRF_INTR 0x00000001 93 #define AMRF_DMA_LOAD 0x00000002 94 #define AMRF_DMA_MAP 0x00000004 95 #define AMRF_DMA_ALLOC 0x00000008 96 #define AMRF_DMA_CREATE 0x00000010 97 #define AMRF_PCI_INTR 0x00000020 98 #define AMRF_PCI_REGS 0x00000040 99 #define AMRF_CCBS 0x00000080 100 #define AMRF_ENQBUF 0x00000100 101 #define AMRF_THREAD 0x00000200 102 103 /* General flags. */ 104 #define AMRF_THREAD_EXIT 0x00010000 105 #define AMRF_OPEN 0x00020000 106 107 /* 108 * Command control block. 109 */ 110 struct amr_ccb { 111 union { 112 SIMPLEQ_ENTRY(amr_ccb) simpleq; 113 SLIST_ENTRY(amr_ccb) slist; 114 TAILQ_ENTRY(amr_ccb) tailq; 115 } ac_chain; 116 117 u_int ac_flags; 118 u_int ac_status; 119 u_int ac_ident; 120 u_int ac_xfer_size; 121 time_t ac_start_time; 122 bus_dmamap_t ac_xfer_map; 123 void (*ac_handler)(struct amr_ccb *); 124 void *ac_context; 125 device_t ac_dv; 126 struct amr_mailbox_cmd ac_cmd; 127 kmutex_t ac_mutex; 128 kcondvar_t ac_cv; 129 }; 130 #define AC_XFER_IN 0x01 /* Map describes inbound xfer */ 131 #define AC_XFER_OUT 0x02 /* Map describes outbound xfer */ 132 #define AC_COMPLETE 0x04 /* Command completed */ 133 #define AC_ACTIVE 0x08 /* Command active */ 134 #define AC_NOSGL 0x10 /* No scatter/gather list */ 135 #define AC_MOAN 0x20 /* We have already moaned */ 136 137 struct amr_attach_args { 138 int amra_unit; 139 }; 140 141 int amr_ccb_alloc(struct amr_softc *, struct amr_ccb **); 142 void amr_ccb_enqueue(struct amr_softc *, struct amr_ccb *); 143 void amr_ccb_free(struct amr_softc *, struct amr_ccb *); 144 int amr_ccb_map(struct amr_softc *, struct amr_ccb *, void *, int, int); 145 int amr_ccb_poll(struct amr_softc *, struct amr_ccb *, int); 146 void amr_ccb_unmap(struct amr_softc *, struct amr_ccb *); 147 int amr_ccb_wait(struct amr_softc *, struct amr_ccb *); 148 const char *amr_drive_state(int, int *); 149 150 extern int amr_max_xfer; 151 152 #endif /* !_PCI_AMRVAR_H_ */ 153