1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * Copyright 2016 Nexenta Systems, Inc. 14 */ 15 16 #ifndef _PVSCSI_VAR_H_ 17 #define _PVSCSI_VAR_H_ 18 19 typedef struct pvscsi_dma_buf { 20 ddi_dma_handle_t dma_handle; 21 caddr_t addr; 22 uint64_t pa; 23 size_t real_length; 24 ddi_acc_handle_t acc_handle; 25 } pvscsi_dma_buf_t; 26 27 #define PVSCSI_TGT_PRIV_SIZE 2 28 29 #define PVSCSI_FLAG_CDB_EXT 0x0001 30 #define PVSCSI_FLAG_SCB_EXT 0x0002 31 #define PVSCSI_FLAG_PRIV_EXT 0x0004 32 #define PVSCSI_FLAG_TAG 0x0008 33 #define PVSCSI_FLAG_IO_READ 0x0010 34 #define PVSCSI_FLAG_IO_IOPB 0x0040 35 #define PVSCSI_FLAG_DONE 0x0080 36 #define PVSCSI_FLAG_DMA_VALID 0x0100 37 #define PVSCSI_FLAG_XARQ 0x0200 38 #define PVSCSI_FLAG_HW_STATUS 0x0400 39 #define PVSCSI_FLAG_TIMED_OUT 0x0800 40 #define PVSCSI_FLAG_ABORTED 0x1000 41 #define PVSCSI_FLAG_RESET_BUS 0x2000 42 #define PVSCSI_FLAG_RESET_DEV 0x4000 43 #define PVSCSI_FLAG_TRANSPORT 0x8000 44 45 /* Flags that must remain during SCSI packet retransmission */ 46 #define PVSCSI_FLAGS_PERSISTENT \ 47 (PVSCSI_FLAG_CDB_EXT |\ 48 PVSCSI_FLAG_SCB_EXT |\ 49 PVSCSI_FLAG_PRIV_EXT |\ 50 PVSCSI_FLAG_TAG |\ 51 PVSCSI_FLAG_IO_READ |\ 52 PVSCSI_FLAG_IO_IOPB |\ 53 PVSCSI_FLAG_DMA_VALID |\ 54 PVSCSI_FLAG_XARQ) 55 56 #define PVSCSI_FLAGS_RESET \ 57 (PVSCSI_FLAG_RESET_BUS |\ 58 PVSCSI_FLAG_RESET_DEV) 59 60 #define PVSCSI_FLAGS_NON_HW_COMPLETION \ 61 (PVSCSI_FLAG_TIMED_OUT |\ 62 PVSCSI_FLAG_ABORTED |\ 63 PVSCSI_FLAGS_RESET) 64 65 #define PVSCSI_FLAGS_COMPLETION \ 66 (PVSCSI_FLAG_HW_STATUS |\ 67 PVSCSI_FLAGS_NON_HW_COMPLETION) 68 69 #define PVSCSI_FLAGS_EXT \ 70 (PVSCSI_FLAG_CDB_EXT |\ 71 PVSCSI_FLAG_SCB_EXT |\ 72 PVSCSI_FLAG_PRIV_EXT) 73 74 typedef struct pvscsi_cmd_ctx { 75 pvscsi_dma_buf_t dma_buf; 76 struct pvscsi_cmd *cmd; 77 list_node_t list; 78 } pvscsi_cmd_ctx_t; 79 80 typedef struct pvscsi_cmp_desc_stat { 81 uchar_t scsi_status; 82 uint32_t host_status; 83 uint64_t data_len; 84 } pvscsi_cmp_desc_stat_t; 85 86 #define PVSCSI_MAX_IO_PAGES 256 87 #define PVSCSI_MAX_IO_SIZE (PVSCSI_MAX_IO_PAGES * PAGE_SIZE) 88 #define PVSCSI_MAX_SG_SIZE (PVSCSI_MAX_IO_PAGES + 1) 89 90 typedef struct pvscsi_cmd { 91 struct scsi_pkt *pkt; 92 uint8_t cmd_cdb[SCSI_CDB_SIZE]; 93 struct scsi_arq_status cmd_scb; 94 uint64_t tgt_priv[PVSCSI_TGT_PRIV_SIZE]; 95 size_t tgtlen; 96 size_t cmdlen; 97 size_t statuslen; 98 uint8_t tag; 99 int flags; 100 ulong_t dma_count; 101 pvscsi_cmp_desc_stat_t cmp_stat; 102 pvscsi_cmd_ctx_t *ctx; 103 ddi_dma_handle_t cmd_dmahdl; 104 ddi_dma_cookie_t cmd_dmac; 105 uint_t cmd_dmaccount; 106 uint_t cmd_winindex; 107 uint_t cmd_nwin; 108 off_t cmd_dma_offset; 109 size_t cmd_dma_len; 110 uint_t cmd_dma_count; 111 uint_t cmd_total_dma_count; 112 int cmd_target; 113 list_node_t cmd_queue_node; 114 clock_t timeout_lbolt; 115 struct pvscsi_softc *cmd_pvs; 116 struct pvscsi_cmd *next_cmd; 117 struct pvscsi_cmd *tail_cmd; 118 struct buf *arqbuf; 119 ddi_dma_cookie_t arqc; 120 ddi_dma_handle_t arqhdl; 121 int cmd_rqslen; 122 struct scsi_pkt cached_pkt; 123 ddi_dma_cookie_t cached_cookies[PVSCSI_MAX_SG_SIZE]; 124 } pvscsi_cmd_t; 125 126 #define AP2PRIV(ap) ((ap)->a_hba_tran->tran_hba_private) 127 #define CMD2PKT(cmd) ((struct scsi_pkt *)((cmd)->pkt)) 128 #define PKT2CMD(pkt) ((pvscsi_cmd_t *)((pkt)->pkt_ha_private)) 129 #define SDEV2PRIV(sd) ((sd)->sd_address.a_hba_tran->tran_hba_private) 130 #define TRAN2PRIV(tran) ((pvscsi_softc_t *)(tran)->tran_hba_private) 131 132 #define CMD_CTX_SGLIST_VA(cmd_ctx) \ 133 ((struct PVSCSISGElement *) \ 134 (((pvscsi_cmd_ctx_t *)(cmd_ctx))->dma_buf.addr)) 135 136 #define CMD_CTX_SGLIST_PA(cmd_ctx) \ 137 ((((pvscsi_cmd_ctx_t *)(cmd_ctx))->dma_buf.pa)) 138 139 typedef struct pvscsi_msg { 140 struct pvscsi_softc *msg_pvs; 141 int type; 142 int target; 143 } pvscsi_msg_t; 144 145 /* Driver-wide flags */ 146 #define PVSCSI_DRIVER_SHUTDOWN 0x01 147 #define PVSCSI_HBA_QUIESCED 0x02 148 #define PVSCSI_HBA_QUIESCE_PENDING 0x04 149 #define PVSCSI_HBA_AUTO_REQUEST_SENSE 0x08 150 151 #define HBA_IS_QUIESCED(pvs) (((pvs)->flags & PVSCSI_HBA_QUIESCED) != 0) 152 #define HBA_QUIESCE_PENDING(pvs) \ 153 (((pvs)->flags & PVSCSI_HBA_QUIESCE_PENDING) != 0 && \ 154 ((pvs)->cmd_queue_len == 0)) 155 156 typedef struct pvscsi_softc { 157 dev_info_t *dip; 158 int instance; 159 scsi_hba_tran_t *tran; 160 ddi_dma_attr_t hba_dma_attr; 161 ddi_dma_attr_t io_dma_attr; 162 ddi_dma_attr_t ring_dma_attr; 163 pvscsi_dma_buf_t rings_state_buf; 164 pvscsi_dma_buf_t req_ring_buf; 165 uint_t req_pages; 166 uint_t req_depth; 167 pvscsi_dma_buf_t cmp_ring_buf; 168 uint_t cmp_pages; 169 pvscsi_dma_buf_t msg_ring_buf; 170 uint_t msg_pages; 171 ddi_acc_handle_t pci_config_handle; 172 ddi_acc_handle_t mmio_handle; 173 caddr_t mmio_base; 174 int intr_type; 175 int intr_size; 176 int intr_cnt; 177 int intr_pri; 178 int flags; 179 ddi_intr_handle_t *intr_htable; 180 pvscsi_cmd_ctx_t *cmd_ctx; 181 list_t cmd_ctx_pool; 182 list_t cmd_queue; 183 int cmd_queue_len; 184 kcondvar_t wd_condvar; 185 kmutex_t mutex; 186 kmutex_t rx_mutex; 187 kmutex_t tx_mutex; 188 kmutex_t intr_mutex; 189 struct kmem_cache *cmd_cache; 190 list_t devnodes; 191 kcondvar_t syncvar; 192 kcondvar_t quiescevar; 193 kthread_t *wd_thread; 194 int intr_lock_counter; 195 int num_pollers; 196 ddi_taskq_t *comp_tq; 197 ddi_taskq_t *msg_tq; 198 } pvscsi_softc_t; 199 200 typedef struct pvscsi_device { 201 list_node_t list; 202 int target; 203 dev_info_t *pdip; 204 dev_info_t *parent; 205 } pvscsi_device_t; 206 207 #define REQ_RING(pvs) \ 208 ((struct PVSCSIRingReqDesc *) \ 209 (((pvscsi_softc_t *)(pvs))->req_ring_buf.addr)) 210 211 #define CMP_RING(pvs) \ 212 ((struct PVSCSIRingCmpDesc *) \ 213 (((pvscsi_softc_t *)(pvs))->cmp_ring_buf.addr)) 214 215 #define MSG_RING(pvs) \ 216 ((struct PVSCSIRingMsgDesc *) \ 217 (((pvscsi_softc_t *)(pvs))->msg_ring_buf.addr)) 218 219 #define RINGS_STATE(pvs) \ 220 ((struct PVSCSIRingsState *)(((pvscsi_softc_t *)\ 221 (pvs))->rings_state_buf.addr)) 222 223 #define PVSCSI_INITIAL_SSTATE_ITEMS 16 224 225 #define SENSE_BUFFER_SIZE SENSE_LENGTH 226 #define USECS_TO_WAIT 1000 227 228 #define PVSCSI_MAXTGTS 16 229 230 #define PAGE_SIZE 4096 231 #define PAGE_SHIFT 12 232 233 #define PVSCSI_DEFAULT_NUM_PAGES_PER_RING 8 234 #define PVSCSI_DEFAULT_NUM_PAGES_MSG_RING 1 235 236 #endif /* _PVSCSI_VAR_H_ */ 237