1 /* $OpenBSD: mpivar.h,v 1.41 2020/07/22 13:16:04 krw Exp $ */ 2 3 /* 4 * Copyright (c) 2005 David Gwynne <dlg@openbsd.org> 5 * Copyright (c) 2005 Marco Peereboom <marco@openbsd.org> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #include <sys/task.h> 21 22 /* #define MPI_DEBUG */ 23 #ifdef MPI_DEBUG 24 extern uint32_t mpi_debug; 25 #define DPRINTF(x...) do { if (mpi_debug) printf(x); } while(0) 26 #define DNPRINTF(n,x...) do { if (mpi_debug & (n)) printf(x); } while(0) 27 #define MPI_D_CMD 0x0001 28 #define MPI_D_INTR 0x0002 29 #define MPI_D_MISC 0x0004 30 #define MPI_D_DMA 0x0008 31 #define MPI_D_IOCTL 0x0010 32 #define MPI_D_RW 0x0020 33 #define MPI_D_MEM 0x0040 34 #define MPI_D_CCB 0x0080 35 #define MPI_D_PPR 0x0100 36 #define MPI_D_RAID 0x0200 37 #define MPI_D_EVT 0x0400 38 #else 39 #define DPRINTF(x...) 40 #define DNPRINTF(n,x...) 41 #endif 42 43 #define MPI_REQUEST_SIZE 512 44 #define MPI_REPLY_SIZE 80 45 #define MPI_REPLYQ_DEPTH 128 46 #define MPI_REPLY_COUNT (PAGE_SIZE / MPI_REPLY_SIZE) 47 48 /* 49 * this is the max number of sge's we can stuff in a request frame: 50 * sizeof(scsi_io) + sizeof(sense) + sizeof(sge) * 32 = MPI_REQUEST_SIZE 51 */ 52 #define MPI_MAX_SGL 36 53 54 struct mpi_dmamem { 55 bus_dmamap_t mdm_map; 56 bus_dma_segment_t mdm_seg; 57 size_t mdm_size; 58 caddr_t mdm_kva; 59 }; 60 #define MPI_DMA_MAP(_mdm) ((_mdm)->mdm_map) 61 #define MPI_DMA_DVA(_mdm) ((u_int64_t)(_mdm)->mdm_map->dm_segs[0].ds_addr) 62 #define MPI_DMA_KVA(_mdm) ((void *)(_mdm)->mdm_kva) 63 64 struct mpi_ccb_bundle { 65 struct mpi_msg_scsi_io mcb_io; /* sgl must follow */ 66 struct mpi_sge mcb_sgl[MPI_MAX_SGL]; 67 struct scsi_sense_data mcb_sense; 68 } __packed; 69 70 struct mpi_softc; 71 72 struct mpi_rcb { 73 SIMPLEQ_ENTRY(mpi_rcb) rcb_link; 74 void *rcb_reply; 75 bus_addr_t rcb_offset; 76 u_int32_t rcb_reply_dva; 77 }; 78 SIMPLEQ_HEAD(mpi_rcb_list, mpi_rcb); 79 80 struct mpi_ccb { 81 struct mpi_softc *ccb_sc; 82 int ccb_id; 83 84 void *ccb_cookie; 85 bus_dmamap_t ccb_dmamap; 86 87 bus_addr_t ccb_offset; 88 void *ccb_cmd; 89 u_int64_t ccb_cmd_dva; 90 91 volatile enum { 92 MPI_CCB_FREE, 93 MPI_CCB_READY, 94 MPI_CCB_QUEUED 95 } ccb_state; 96 void (*ccb_done)(struct mpi_ccb *); 97 struct mpi_rcb *ccb_rcb; 98 99 SLIST_ENTRY(mpi_ccb) ccb_link; 100 }; 101 102 SLIST_HEAD(mpi_ccb_list, mpi_ccb); 103 104 struct mpi_softc { 105 struct device sc_dev; 106 107 u_int64_t sc_port_wwn; 108 u_int64_t sc_node_wwn; 109 110 int sc_flags; 111 #define MPI_F_SPI (1<<0) 112 #define MPI_F_RAID (1<<1) 113 114 struct scsibus_softc *sc_scsibus; 115 116 bus_space_tag_t sc_iot; 117 bus_space_handle_t sc_ioh; 118 bus_size_t sc_ios; 119 bus_dma_tag_t sc_dmat; 120 121 u_int8_t sc_fw_maj; 122 u_int8_t sc_fw_min; 123 u_int8_t sc_fw_unit; 124 u_int8_t sc_fw_dev; 125 126 u_int8_t sc_porttype; 127 int sc_maxcmds; 128 int sc_maxchdepth; 129 int sc_first_sgl_len; 130 int sc_chain_len; 131 int sc_max_sgl_len; 132 133 int sc_buswidth; 134 int sc_target; 135 int sc_ioc_number; 136 137 struct mpi_dmamem *sc_requests; 138 struct mpi_ccb *sc_ccbs; 139 struct mpi_ccb_list sc_ccb_free; 140 struct mutex sc_ccb_mtx; 141 struct scsi_iopool sc_iopool; 142 143 struct mpi_dmamem *sc_replies; 144 struct mpi_rcb *sc_rcbs; 145 int sc_repq; 146 147 struct mpi_ccb *sc_evt_ccb; 148 struct mpi_rcb_list sc_evt_ack_queue; 149 struct mutex sc_evt_ack_mtx; 150 struct scsi_iohandler sc_evt_ack_handler; 151 152 struct mpi_rcb_list sc_evt_scan_queue; 153 struct mutex sc_evt_scan_mtx; 154 struct scsi_iohandler sc_evt_scan_handler; 155 156 struct task sc_evt_rescan; 157 158 size_t sc_fw_len; 159 struct mpi_dmamem *sc_fw; 160 161 /* scsi ioctl from sd device */ 162 int (*sc_ioctl)(struct device *, u_long, caddr_t); 163 164 struct rwlock sc_lock; 165 struct mpi_cfg_hdr sc_cfg_hdr; 166 struct mpi_cfg_ioc_pg2 *sc_vol_page; 167 struct mpi_cfg_raid_vol *sc_vol_list; 168 struct mpi_cfg_raid_vol_pg0 *sc_rpg0; 169 170 struct ksensor *sc_sensors; 171 struct ksensordev sc_sensordev; 172 }; 173 174 int mpi_attach(struct mpi_softc *); 175 void mpi_detach(struct mpi_softc *); 176 177 int mpi_intr(void *); 178