1 1.20 bouyer /* $NetBSD: mfivar.h,v 1.20 2012/09/19 21:24:29 bouyer Exp $ */ 2 1.1 bouyer /* $OpenBSD: mfivar.h,v 1.28 2006/08/31 18:18:46 marco Exp $ */ 3 1.1 bouyer /* 4 1.1 bouyer * Copyright (c) 2006 Marco Peereboom <marco (at) peereboom.us> 5 1.1 bouyer * 6 1.1 bouyer * Permission to use, copy, modify, and distribute this software for any 7 1.1 bouyer * purpose with or without fee is hereby granted, provided that the above 8 1.1 bouyer * copyright notice and this permission notice appear in all copies. 9 1.1 bouyer * 10 1.1 bouyer * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 1.1 bouyer * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 1.1 bouyer * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 1.1 bouyer * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 1.1 bouyer * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 1.1 bouyer * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 1.1 bouyer * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 1.1 bouyer */ 18 1.1 bouyer 19 1.4 bouyer #include <dev/sysmon/sysmonvar.h> 20 1.4 bouyer #include <sys/envsys.h> 21 1.18 bouyer #include <sys/workqueue.h> 22 1.4 bouyer 23 1.12 dyoung #define DEVNAME(_s) (device_xname((_s)->sc_dev)) 24 1.1 bouyer 25 1.7 xtraeme /* #define MFI_DEBUG */ 26 1.1 bouyer #ifdef MFI_DEBUG 27 1.1 bouyer extern uint32_t mfi_debug; 28 1.1 bouyer #define DPRINTF(x...) do { if (mfi_debug) printf(x); } while(0) 29 1.1 bouyer #define DNPRINTF(n,x...) do { if (mfi_debug & n) printf(x); } while(0) 30 1.1 bouyer #define MFI_D_CMD 0x0001 31 1.1 bouyer #define MFI_D_INTR 0x0002 32 1.1 bouyer #define MFI_D_MISC 0x0004 33 1.1 bouyer #define MFI_D_DMA 0x0008 34 1.1 bouyer #define MFI_D_IOCTL 0x0010 35 1.1 bouyer #define MFI_D_RW 0x0020 36 1.1 bouyer #define MFI_D_MEM 0x0040 37 1.1 bouyer #define MFI_D_CCB 0x0080 38 1.18 bouyer #define MFI_D_SYNC 0x0100 39 1.1 bouyer #else 40 1.10 gmcgarry #define DPRINTF(x, ...) 41 1.10 gmcgarry #define DNPRINTF(n, x, ...) 42 1.1 bouyer #endif 43 1.1 bouyer 44 1.1 bouyer struct mfi_mem { 45 1.1 bouyer bus_dmamap_t am_map; 46 1.1 bouyer bus_dma_segment_t am_seg; 47 1.1 bouyer size_t am_size; 48 1.3 christos void * am_kva; 49 1.1 bouyer }; 50 1.1 bouyer 51 1.1 bouyer #define MFIMEM_MAP(_am) ((_am)->am_map) 52 1.1 bouyer #define MFIMEM_DVA(_am) ((_am)->am_map->dm_segs[0].ds_addr) 53 1.1 bouyer #define MFIMEM_KVA(_am) ((void *)(_am)->am_kva) 54 1.1 bouyer 55 1.1 bouyer struct mfi_prod_cons { 56 1.1 bouyer uint32_t mpc_producer; 57 1.1 bouyer uint32_t mpc_consumer; 58 1.1 bouyer uint32_t mpc_reply_q[1]; /* compensate for 1 extra reply per spec */ 59 1.1 bouyer }; 60 1.1 bouyer 61 1.1 bouyer struct mfi_ccb { 62 1.1 bouyer struct mfi_softc *ccb_sc; 63 1.1 bouyer 64 1.1 bouyer union mfi_frame *ccb_frame; 65 1.1 bouyer paddr_t ccb_pframe; 66 1.1 bouyer uint32_t ccb_frame_size; 67 1.1 bouyer uint32_t ccb_extra_frames; 68 1.1 bouyer 69 1.1 bouyer struct mfi_sense *ccb_sense; 70 1.1 bouyer paddr_t ccb_psense; 71 1.1 bouyer 72 1.1 bouyer bus_dmamap_t ccb_dmamap; 73 1.1 bouyer 74 1.1 bouyer union mfi_sgl *ccb_sgl; 75 1.1 bouyer 76 1.1 bouyer /* data for sgl */ 77 1.1 bouyer void *ccb_data; 78 1.1 bouyer uint32_t ccb_len; 79 1.1 bouyer 80 1.1 bouyer uint32_t ccb_direction; 81 1.1 bouyer #define MFI_DATA_NONE 0 82 1.1 bouyer #define MFI_DATA_IN 1 83 1.1 bouyer #define MFI_DATA_OUT 2 84 1.1 bouyer 85 1.18 bouyer /* 86 1.18 bouyer * memory structure used by ThunderBolt controller. 87 1.18 bouyer * The legacy structures above are used too, depending on 88 1.18 bouyer * the command type. 89 1.18 bouyer */ 90 1.18 bouyer union mfi_mpi2_request_descriptor ccb_tb_request_desc; 91 1.18 bouyer struct mfi_mpi2_request_raid_scsi_io *ccb_tb_io_request; 92 1.18 bouyer bus_addr_t ccb_tb_pio_request; 93 1.18 bouyer mpi2_sge_io_union *ccb_tb_sg_frame; 94 1.18 bouyer bus_addr_t ccb_tb_psg_frame; 95 1.18 bouyer 96 1.1 bouyer struct scsipi_xfer *ccb_xs; 97 1.1 bouyer 98 1.1 bouyer void (*ccb_done)(struct mfi_ccb *); 99 1.1 bouyer 100 1.1 bouyer volatile enum { 101 1.1 bouyer MFI_CCB_FREE, 102 1.1 bouyer MFI_CCB_READY, 103 1.18 bouyer MFI_CCB_RUNNING, 104 1.1 bouyer MFI_CCB_DONE 105 1.1 bouyer } ccb_state; 106 1.1 bouyer uint32_t ccb_flags; 107 1.1 bouyer #define MFI_CCB_F_ERR (1<<0) 108 1.18 bouyer #define MFI_CCB_F_TBOLT (1<<1) /* Thunderbolt descriptor */ 109 1.18 bouyer #define MFI_CCB_F_TBOLT_IO (1<<2) /* Thunderbolt I/O descriptor */ 110 1.1 bouyer TAILQ_ENTRY(mfi_ccb) ccb_link; 111 1.1 bouyer }; 112 1.1 bouyer 113 1.1 bouyer TAILQ_HEAD(mfi_ccb_list, mfi_ccb); 114 1.1 bouyer 115 1.7 xtraeme enum mfi_iop { 116 1.7 xtraeme MFI_IOP_XSCALE, 117 1.14 msaitoh MFI_IOP_PPC, 118 1.15 sborrill MFI_IOP_GEN2, 119 1.18 bouyer MFI_IOP_SKINNY, 120 1.18 bouyer MFI_IOP_TBOLT 121 1.7 xtraeme }; 122 1.7 xtraeme 123 1.7 xtraeme struct mfi_iop_ops { 124 1.7 xtraeme uint32_t (*mio_fw_state)(struct mfi_softc *); 125 1.11 dyoung void (*mio_intr_dis)(struct mfi_softc *); 126 1.7 xtraeme void (*mio_intr_ena)(struct mfi_softc *); 127 1.7 xtraeme int (*mio_intr)(struct mfi_softc *); 128 1.18 bouyer void (*mio_post)(struct mfi_softc *, 129 1.18 bouyer struct mfi_ccb *); 130 1.18 bouyer int (*mio_ld_io)(struct mfi_ccb *, 131 1.18 bouyer struct scsipi_xfer *, uint64_t, uint32_t); 132 1.7 xtraeme }; 133 1.7 xtraeme 134 1.1 bouyer struct mfi_softc { 135 1.12 dyoung device_t sc_dev; 136 1.1 bouyer struct scsipi_channel sc_chan; 137 1.1 bouyer struct scsipi_adapter sc_adapt; 138 1.1 bouyer 139 1.7 xtraeme const struct mfi_iop_ops *sc_iop; 140 1.17 bouyer enum mfi_iop sc_ioptype; 141 1.7 xtraeme 142 1.1 bouyer void *sc_ih; 143 1.1 bouyer 144 1.16 bouyer bool sc_64bit_dma; 145 1.1 bouyer 146 1.1 bouyer bus_space_tag_t sc_iot; 147 1.1 bouyer bus_space_handle_t sc_ioh; 148 1.18 bouyer bus_size_t sc_size; 149 1.1 bouyer bus_dma_tag_t sc_dmat; 150 1.18 bouyer bus_dma_tag_t sc_datadmat; 151 1.1 bouyer 152 1.1 bouyer /* save some useful information for logical drives that is missing 153 1.1 bouyer * in sc_ld_list 154 1.1 bouyer */ 155 1.1 bouyer struct { 156 1.1 bouyer uint32_t ld_present; 157 1.1 bouyer char ld_dev[16]; /* device name sd? */ 158 1.1 bouyer } sc_ld[MFI_MAX_LD]; 159 1.1 bouyer 160 1.1 bouyer /* firmware determined max, totals and other information*/ 161 1.1 bouyer uint32_t sc_max_cmds; 162 1.1 bouyer uint32_t sc_max_sgl; 163 1.16 bouyer uint32_t sc_sgl_size; 164 1.1 bouyer uint32_t sc_max_ld; 165 1.1 bouyer uint32_t sc_ld_cnt; 166 1.1 bouyer /* XXX these struct should be local to mgmt function */ 167 1.1 bouyer struct mfi_ctrl_info sc_info; 168 1.1 bouyer struct mfi_ld_list sc_ld_list; 169 1.1 bouyer struct mfi_ld_details sc_ld_details; 170 1.1 bouyer 171 1.1 bouyer /* all commands */ 172 1.1 bouyer struct mfi_ccb *sc_ccb; 173 1.1 bouyer 174 1.1 bouyer /* producer/consumer pointers and reply queue */ 175 1.1 bouyer struct mfi_mem *sc_pcq; 176 1.1 bouyer 177 1.1 bouyer /* frame memory */ 178 1.1 bouyer struct mfi_mem *sc_frames; 179 1.1 bouyer uint32_t sc_frames_size; 180 1.1 bouyer 181 1.18 bouyer /* thunderbolt memory */ 182 1.18 bouyer struct mfi_mem *sc_tbolt_reqmsgpool; 183 1.18 bouyer 184 1.18 bouyer struct mfi_mem *sc_tbolt_ioc_init; 185 1.18 bouyer /* Virtual address of reply Frame Pool, part of sc_tbolt_reqmsgpool */ 186 1.18 bouyer int sc_reply_pool_size; 187 1.18 bouyer struct mfi_mpi2_reply_header* sc_reply_frame_pool; 188 1.18 bouyer bus_addr_t sc_reply_frame_busaddr; 189 1.18 bouyer uint8_t *sc_reply_pool_limit; 190 1.18 bouyer bus_addr_t sc_sg_frame_busaddr; 191 1.18 bouyer int sc_last_reply_idx; 192 1.18 bouyer 193 1.18 bouyer struct mfi_mem *sc_tbolt_verbuf; 194 1.18 bouyer 195 1.18 bouyer bool sc_MFA_enabled; 196 1.18 bouyer 197 1.18 bouyer /* workqueue for the ld sync command */ 198 1.18 bouyer struct workqueue *sc_ldsync_wq; 199 1.18 bouyer struct work sc_ldsync_wk; 200 1.18 bouyer struct mfi_ccb *sc_ldsync_ccb; 201 1.18 bouyer 202 1.1 bouyer /* sense memory */ 203 1.1 bouyer struct mfi_mem *sc_sense; 204 1.1 bouyer 205 1.1 bouyer struct mfi_ccb_list sc_ccb_freeq; 206 1.1 bouyer 207 1.6 xtraeme struct sysmon_envsys *sc_sme; 208 1.6 xtraeme envsys_data_t *sc_sensor; 209 1.19 bouyer bool sc_bbuok; 210 1.19 bouyer bool sc_running; 211 1.4 bouyer 212 1.13 dyoung device_t sc_child; 213 1.20 bouyer 214 1.20 bouyer /* for ioctl interface */ 215 1.20 bouyer bool sc_opened; 216 1.1 bouyer }; 217 1.1 bouyer 218 1.13 dyoung int mfi_rescan(device_t, const char *, const int *); 219 1.13 dyoung void mfi_childdetached(device_t, device_t); 220 1.11 dyoung int mfi_attach(struct mfi_softc *, enum mfi_iop); 221 1.11 dyoung int mfi_detach(struct mfi_softc *, int); 222 1.1 bouyer int mfi_intr(void *); 223 1.18 bouyer int mfi_tbolt_intrh(void *); 224