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
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.
13 * Copyright 2016 Nexenta Systems, Inc.
16 #ifndef _PVSCSI_VAR_H_
17 #define _PVSCSI_VAR_H_
19 typedef struct pvscsi_dma_buf
{
20 ddi_dma_handle_t dma_handle
;
24 ddi_acc_handle_t acc_handle
;
27 #define PVSCSI_TGT_PRIV_SIZE 2
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
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 |\
51 PVSCSI_FLAG_IO_READ |\
52 PVSCSI_FLAG_IO_IOPB |\
53 PVSCSI_FLAG_DMA_VALID |\
56 #define PVSCSI_FLAGS_RESET \
57 (PVSCSI_FLAG_RESET_BUS |\
58 PVSCSI_FLAG_RESET_DEV)
60 #define PVSCSI_FLAGS_NON_HW_COMPLETION \
61 (PVSCSI_FLAG_TIMED_OUT |\
62 PVSCSI_FLAG_ABORTED |\
65 #define PVSCSI_FLAGS_COMPLETION \
66 (PVSCSI_FLAG_HW_STATUS |\
67 PVSCSI_FLAGS_NON_HW_COMPLETION)
69 #define PVSCSI_FLAGS_EXT \
70 (PVSCSI_FLAG_CDB_EXT |\
71 PVSCSI_FLAG_SCB_EXT |\
74 typedef struct pvscsi_cmd_ctx
{
75 pvscsi_dma_buf_t dma_buf
;
76 struct pvscsi_cmd
*cmd
;
80 typedef struct pvscsi_cmp_desc_stat
{
84 } pvscsi_cmp_desc_stat_t
;
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)
90 typedef struct pvscsi_cmd
{
92 uint8_t cmd_cdb
[SCSI_CDB_SIZE
];
93 struct scsi_arq_status cmd_scb
;
94 uint64_t tgt_priv
[PVSCSI_TGT_PRIV_SIZE
];
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
;
108 off_t cmd_dma_offset
;
110 uint_t cmd_dma_count
;
111 uint_t cmd_total_dma_count
;
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
;
119 ddi_dma_cookie_t arqc
;
120 ddi_dma_handle_t arqhdl
;
122 struct scsi_pkt cached_pkt
;
123 ddi_dma_cookie_t cached_cookies
[PVSCSI_MAX_SG_SIZE
];
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)
132 #define CMD_CTX_SGLIST_VA(cmd_ctx) \
133 ((struct PVSCSISGElement *) \
134 (((pvscsi_cmd_ctx_t *)(cmd_ctx))->dma_buf.addr))
136 #define CMD_CTX_SGLIST_PA(cmd_ctx) \
137 ((((pvscsi_cmd_ctx_t *)(cmd_ctx))->dma_buf.pa))
139 typedef struct pvscsi_msg
{
140 struct pvscsi_softc
*msg_pvs
;
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
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))
156 typedef struct pvscsi_softc
{
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
;
167 pvscsi_dma_buf_t cmp_ring_buf
;
169 pvscsi_dma_buf_t msg_ring_buf
;
171 ddi_acc_handle_t pci_config_handle
;
172 ddi_acc_handle_t mmio_handle
;
179 ddi_intr_handle_t
*intr_htable
;
180 pvscsi_cmd_ctx_t
*cmd_ctx
;
184 kcondvar_t wd_condvar
;
189 struct kmem_cache
*cmd_cache
;
192 kcondvar_t quiescevar
;
193 kthread_t
*wd_thread
;
194 int intr_lock_counter
;
196 ddi_taskq_t
*comp_tq
;
200 typedef struct pvscsi_device
{
207 #define REQ_RING(pvs) \
208 ((struct PVSCSIRingReqDesc *) \
209 (((pvscsi_softc_t *)(pvs))->req_ring_buf.addr))
211 #define CMP_RING(pvs) \
212 ((struct PVSCSIRingCmpDesc *) \
213 (((pvscsi_softc_t *)(pvs))->cmp_ring_buf.addr))
215 #define MSG_RING(pvs) \
216 ((struct PVSCSIRingMsgDesc *) \
217 (((pvscsi_softc_t *)(pvs))->msg_ring_buf.addr))
219 #define RINGS_STATE(pvs) \
220 ((struct PVSCSIRingsState *)(((pvscsi_softc_t *)\
221 (pvs))->rings_state_buf.addr))
223 #define PVSCSI_INITIAL_SSTATE_ITEMS 16
225 #define SENSE_BUFFER_SIZE SENSE_LENGTH
226 #define USECS_TO_WAIT 1000
228 #define PVSCSI_MAXTGTS 16
230 #define PAGE_SIZE 4096
231 #define PAGE_SHIFT 12
233 #define PVSCSI_DEFAULT_NUM_PAGES_PER_RING 8
234 #define PVSCSI_DEFAULT_NUM_PAGES_MSG_RING 1
236 #endif /* _PVSCSI_VAR_H_ */