1 /* $OpenBSD: mfivar.h,v 1.54 2014/08/15 02:27:02 yasuoka Exp $ */ 2 /* 3 * Copyright (c) 2006 Marco Peereboom <marco@peereboom.us> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 struct mfi_softc; 19 #define DEVNAME(_s) ((_s)->sc_dev.dv_xname) 20 21 /* #define MFI_DEBUG */ 22 #ifdef MFI_DEBUG 23 extern uint32_t mfi_debug; 24 #define DPRINTF(x...) do { if (mfi_debug) printf(x); } while(0) 25 #define DNPRINTF(n,x...) do { if (mfi_debug & n) printf(x); } while(0) 26 #define MFI_D_CMD 0x0001 27 #define MFI_D_INTR 0x0002 28 #define MFI_D_MISC 0x0004 29 #define MFI_D_DMA 0x0008 30 #define MFI_D_IOCTL 0x0010 31 #define MFI_D_RW 0x0020 32 #define MFI_D_MEM 0x0040 33 #define MFI_D_CCB 0x0080 34 #else 35 #define DPRINTF(x...) 36 #define DNPRINTF(n,x...) 37 #endif 38 39 struct mfi_mem { 40 bus_dmamap_t am_map; 41 bus_dma_segment_t am_seg; 42 size_t am_size; 43 caddr_t am_kva; 44 }; 45 46 #define MFIMEM_MAP(_am) ((_am)->am_map) 47 #define MFIMEM_LEN(_am) ((_am)->am_map->dm_mapsize) 48 #define MFIMEM_DVA(_am) ((_am)->am_map->dm_segs[0].ds_addr) 49 #define MFIMEM_KVA(_am) ((void *)(_am)->am_kva) 50 51 struct mfi_prod_cons { 52 uint32_t mpc_producer; 53 uint32_t mpc_consumer; 54 uint32_t mpc_reply_q[1]; /* compensate for 1 extra reply per spec */ 55 }; 56 57 struct mfi_ccb { 58 union mfi_frame *ccb_frame; 59 paddr_t ccb_pframe; 60 bus_addr_t ccb_pframe_offset; 61 uint32_t ccb_frame_size; 62 uint32_t ccb_extra_frames; 63 64 struct mfi_sense *ccb_sense; 65 paddr_t ccb_psense; 66 67 bus_dmamap_t ccb_dmamap; 68 69 union mfi_sgl *ccb_sgl; 70 71 /* data for sgl */ 72 void *ccb_data; 73 uint32_t ccb_len; 74 75 uint32_t ccb_direction; 76 #define MFI_DATA_NONE 0 77 #define MFI_DATA_IN 1 78 #define MFI_DATA_OUT 2 79 80 void *ccb_cookie; 81 void (*ccb_done)(struct mfi_softc *, 82 struct mfi_ccb *); 83 84 volatile enum { 85 MFI_CCB_FREE, 86 MFI_CCB_READY, 87 MFI_CCB_DONE 88 } ccb_state; 89 uint32_t ccb_flags; 90 #define MFI_CCB_F_ERR (1<<0) 91 SLIST_ENTRY(mfi_ccb) ccb_link; 92 }; 93 94 SLIST_HEAD(mfi_ccb_list, mfi_ccb); 95 96 enum mfi_iop { 97 MFI_IOP_XSCALE, 98 MFI_IOP_PPC, 99 MFI_IOP_GEN2, 100 MFI_IOP_SKINNY 101 }; 102 103 struct mfi_iop_ops { 104 u_int32_t (*mio_fw_state)(struct mfi_softc *); 105 void (*mio_intr_ena)(struct mfi_softc *); 106 int (*mio_intr)(struct mfi_softc *); 107 void (*mio_post)(struct mfi_softc *, struct mfi_ccb *); 108 u_int (*mio_sgd_load)(struct mfi_softc *, struct mfi_ccb *); 109 u_int32_t mio_idb; 110 u_int32_t mio_flags; 111 #define MFI_IOP_F_SYSPD (1 << 0) 112 }; 113 114 struct mfi_pd_link { 115 u_int16_t pd_id; 116 struct mfi_pd_details pd_info; 117 }; 118 119 struct mfi_pd_softc { 120 struct scsi_link pd_link; 121 struct scsibus_softc *pd_scsibus; 122 struct mfi_pd_link *pd_links[MFI_MAX_PD]; 123 }; 124 125 struct mfi_softc { 126 struct device sc_dev; 127 void *sc_ih; 128 struct scsi_link sc_link; 129 struct scsi_iopool sc_iopool; 130 131 const struct mfi_iop_ops *sc_iop; 132 133 int sc_64bit_dma; 134 135 bus_space_tag_t sc_iot; 136 bus_space_handle_t sc_ioh; 137 bus_dma_tag_t sc_dmat; 138 139 /* save some useful information for logical drives that is missing 140 * in sc_ld_list 141 */ 142 struct { 143 uint32_t ld_present; 144 char ld_dev[16]; /* device name sd? */ 145 } sc_ld[MFI_MAX_LD]; 146 147 /* scsi ioctl from sd device */ 148 int (*sc_ioctl)(struct device *, u_long, caddr_t); 149 150 /* firmware determined max, totals and other information*/ 151 uint32_t sc_max_cmds; 152 uint32_t sc_max_sgl; 153 uint32_t sc_sgl_size; 154 uint32_t sc_ld_cnt; 155 156 uint16_t sc_sgl_flags; 157 uint16_t sc_reserved; 158 159 /* bio */ 160 struct mfi_conf *sc_cfg; 161 struct mfi_ctrl_info sc_info; 162 struct mfi_ld_list sc_ld_list; 163 struct mfi_ld_details *sc_ld_details; /* array to all logical disks */ 164 int sc_no_pd; /* used physical disks */ 165 int sc_ld_sz; /* sizeof sc_ld_details */ 166 167 /* all commands */ 168 struct mfi_ccb *sc_ccb; 169 170 /* producer/consumer pointers and reply queue */ 171 struct mfi_mem *sc_pcq; 172 173 /* frame memory */ 174 struct mfi_mem *sc_frames; 175 uint32_t sc_frames_size; 176 177 /* sense memory */ 178 struct mfi_mem *sc_sense; 179 180 struct mfi_ccb_list sc_ccb_freeq; 181 struct mutex sc_ccb_mtx; 182 183 struct scsibus_softc *sc_scsibus; 184 struct mfi_pd_softc *sc_pd; 185 186 /* mgmt lock */ 187 struct rwlock sc_lock; 188 189 /* sensors */ 190 struct ksensordev sc_sensordev; 191 struct ksensor *sc_bbu; 192 struct ksensor *sc_bbu_status; 193 struct ksensor *sc_sensors; 194 }; 195 196 int mfi_attach(struct mfi_softc *sc, enum mfi_iop); 197 int mfi_intr(void *); 198