2 * VMware PVSCSI header file
4 * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 of the License and no later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 * Maintained by: Alok N Kataria <akataria@vmware.com>
24 #ifndef _VMW_PVSCSI_H_
25 #define _VMW_PVSCSI_H_
27 #include <linux/types.h>
29 #define PVSCSI_DRIVER_VERSION_STRING "1.0.1.0-k"
31 #define PVSCSI_MAX_NUM_SG_ENTRIES_PER_SEGMENT 128
33 #define MASK(n) ((1 << (n)) - 1) /* make an n-bit mask */
35 #define PCI_VENDOR_ID_VMWARE 0x15AD
36 #define PCI_DEVICE_ID_VMWARE_PVSCSI 0x07C0
39 * host adapter status/error codes
41 enum HostBusAdapterStatus
{
42 BTSTAT_SUCCESS
= 0x00, /* CCB complete normally with no errors */
43 BTSTAT_LINKED_COMMAND_COMPLETED
= 0x0a,
44 BTSTAT_LINKED_COMMAND_COMPLETED_WITH_FLAG
= 0x0b,
45 BTSTAT_DATA_UNDERRUN
= 0x0c,
46 BTSTAT_SELTIMEO
= 0x11, /* SCSI selection timeout */
47 BTSTAT_DATARUN
= 0x12, /* data overrun/underrun */
48 BTSTAT_BUSFREE
= 0x13, /* unexpected bus free */
49 BTSTAT_INVPHASE
= 0x14, /* invalid bus phase or sequence requested by target */
50 BTSTAT_LUNMISMATCH
= 0x17, /* linked CCB has different LUN from first CCB */
51 BTSTAT_SENSFAILED
= 0x1b, /* auto request sense failed */
52 BTSTAT_TAGREJECT
= 0x1c, /* SCSI II tagged queueing message rejected by target */
53 BTSTAT_BADMSG
= 0x1d, /* unsupported message received by the host adapter */
54 BTSTAT_HAHARDWARE
= 0x20, /* host adapter hardware failed */
55 BTSTAT_NORESPONSE
= 0x21, /* target did not respond to SCSI ATN, sent a SCSI RST */
56 BTSTAT_SENTRST
= 0x22, /* host adapter asserted a SCSI RST */
57 BTSTAT_RECVRST
= 0x23, /* other SCSI devices asserted a SCSI RST */
58 BTSTAT_DISCONNECT
= 0x24, /* target device reconnected improperly (w/o tag) */
59 BTSTAT_BUSRESET
= 0x25, /* host adapter issued BUS device reset */
60 BTSTAT_ABORTQUEUE
= 0x26, /* abort queue generated */
61 BTSTAT_HASOFTWARE
= 0x27, /* host adapter software error */
62 BTSTAT_HATIMEOUT
= 0x30, /* host adapter hardware timeout error */
63 BTSTAT_SCSIPARITY
= 0x34, /* SCSI parity error detected */
69 * These registers are accessible both via i/o space and mm i/o.
72 enum PVSCSIRegOffset
{
73 PVSCSI_REG_OFFSET_COMMAND
= 0x0,
74 PVSCSI_REG_OFFSET_COMMAND_DATA
= 0x4,
75 PVSCSI_REG_OFFSET_COMMAND_STATUS
= 0x8,
76 PVSCSI_REG_OFFSET_LAST_STS_0
= 0x100,
77 PVSCSI_REG_OFFSET_LAST_STS_1
= 0x104,
78 PVSCSI_REG_OFFSET_LAST_STS_2
= 0x108,
79 PVSCSI_REG_OFFSET_LAST_STS_3
= 0x10c,
80 PVSCSI_REG_OFFSET_INTR_STATUS
= 0x100c,
81 PVSCSI_REG_OFFSET_INTR_MASK
= 0x2010,
82 PVSCSI_REG_OFFSET_KICK_NON_RW_IO
= 0x3014,
83 PVSCSI_REG_OFFSET_DEBUG
= 0x3018,
84 PVSCSI_REG_OFFSET_KICK_RW_IO
= 0x4018,
88 * Virtual h/w commands.
92 PVSCSI_CMD_FIRST
= 0, /* has to be first */
94 PVSCSI_CMD_ADAPTER_RESET
= 1,
95 PVSCSI_CMD_ISSUE_SCSI
= 2,
96 PVSCSI_CMD_SETUP_RINGS
= 3,
97 PVSCSI_CMD_RESET_BUS
= 4,
98 PVSCSI_CMD_RESET_DEVICE
= 5,
99 PVSCSI_CMD_ABORT_CMD
= 6,
100 PVSCSI_CMD_CONFIG
= 7,
101 PVSCSI_CMD_SETUP_MSG_RING
= 8,
102 PVSCSI_CMD_DEVICE_UNPLUG
= 9,
104 PVSCSI_CMD_LAST
= 10 /* has to be last */
108 * Command descriptor for PVSCSI_CMD_RESET_DEVICE --
111 struct PVSCSICmdDescResetDevice
{
117 * Command descriptor for PVSCSI_CMD_ABORT_CMD --
119 * - currently does not support specifying the LUN.
120 * - _pad should be 0.
123 struct PVSCSICmdDescAbortCmd
{
130 * Command descriptor for PVSCSI_CMD_SETUP_RINGS --
133 * - reqRingNumPages and cmpRingNumPages need to be power of two.
134 * - reqRingNumPages and cmpRingNumPages need to be different from 0,
135 * - reqRingNumPages and cmpRingNumPages need to be inferior to
136 * PVSCSI_SETUP_RINGS_MAX_NUM_PAGES.
139 #define PVSCSI_SETUP_RINGS_MAX_NUM_PAGES 32
140 struct PVSCSICmdDescSetupRings
{
144 u64 reqRingPPNs
[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
];
145 u64 cmpRingPPNs
[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
];
149 * Command descriptor for PVSCSI_CMD_SETUP_MSG_RING --
152 * - this command was not supported in the initial revision of the h/w
153 * interface. Before using it, you need to check that it is supported by
154 * writing PVSCSI_CMD_SETUP_MSG_RING to the 'command' register, then
155 * immediately after read the 'command status' register:
156 * * a value of -1 means that the cmd is NOT supported,
157 * * a value != -1 means that the cmd IS supported.
158 * If it's supported the 'command status' register should return:
159 * sizeof(PVSCSICmdDescSetupMsgRing) / sizeof(u32).
160 * - this command should be issued _after_ the usual SETUP_RINGS so that the
161 * RingsState page is already setup. If not, the command is a nop.
162 * - numPages needs to be a power of two,
163 * - numPages needs to be different from 0,
164 * - _pad should be zero.
167 #define PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES 16
169 struct PVSCSICmdDescSetupMsgRing
{
172 u64 ringPPNs
[PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES
];
176 PVSCSI_MSG_DEV_ADDED
= 0,
177 PVSCSI_MSG_DEV_REMOVED
= 1,
184 * sizeof(struct PVSCSIRingMsgDesc) == 128.
186 * - type is of type enum PVSCSIMsgType.
187 * - the content of args depend on the type of event being delivered.
190 struct PVSCSIRingMsgDesc
{
195 struct PVSCSIMsgDescDevStatusChanged
{
196 u32 type
; /* PVSCSI_MSG_DEV _ADDED / _REMOVED */
209 * . msgNumEntriesLog2,
210 * .. are only used once the SETUP_MSG_RING cmd has been issued.
211 * - '_pad' helps to ensure that the msg related fields are on their own
215 struct PVSCSIRingsState
{
218 u32 reqNumEntriesLog2
;
222 u32 cmpNumEntriesLog2
;
228 u32 msgNumEntriesLog2
;
232 #define PVSCSI_FLAG_CMD_WITH_SG_LIST (1 << 0)
233 #define PVSCSI_FLAG_CMD_OUT_OF_BAND_CDB (1 << 1)
234 #define PVSCSI_FLAG_CMD_DIR_NONE (1 << 2)
235 #define PVSCSI_FLAG_CMD_DIR_TOHOST (1 << 3)
236 #define PVSCSI_FLAG_CMD_DIR_TODEVICE (1 << 4)
238 struct PVSCSIRingReqDesc
{
256 * Scatter-gather list management.
258 * As described above, when PVSCSI_FLAG_CMD_WITH_SG_LIST is set in the
259 * RingReqDesc.flags, then RingReqDesc.dataAddr is the PA of the first s/g
262 * - each segment of the s/g table contain a succession of struct
264 * - each segment is entirely contained on a single physical page of memory.
265 * - a "chain" s/g element has the flag PVSCSI_SGE_FLAG_CHAIN_ELEMENT set in
266 * PVSCSISGElement.flags and in this case:
267 * * addr is the PA of the next s/g segment,
268 * * length is undefined, assumed to be 0.
271 struct PVSCSISGElement
{
278 * Completion descriptor.
280 * sizeof(RingCmpDesc) = 32
282 * - context: identifier of the command. The same thing that was specified
283 * under "context" as part of struct RingReqDesc at initiation time,
284 * - dataLen: number of bytes transferred for the actual i/o operation,
285 * - senseLen: number of bytes written into the sense buffer,
286 * - hostStatus: adapter status,
287 * - scsiStatus: device status,
288 * - _pad should be zero.
291 struct PVSCSIRingCmpDesc
{
301 * Interrupt status / IRQ bits.
304 #define PVSCSI_INTR_CMPL_0 (1 << 0)
305 #define PVSCSI_INTR_CMPL_1 (1 << 1)
306 #define PVSCSI_INTR_CMPL_MASK MASK(2)
308 #define PVSCSI_INTR_MSG_0 (1 << 2)
309 #define PVSCSI_INTR_MSG_1 (1 << 3)
310 #define PVSCSI_INTR_MSG_MASK (MASK(2) << 2)
312 #define PVSCSI_INTR_ALL_SUPPORTED MASK(4)
315 * Number of MSI-X vectors supported.
317 #define PVSCSI_MAX_INTRS 24
320 * Enumeration of supported MSI-X vectors
322 #define PVSCSI_VECTOR_COMPLETION 0
325 * Misc constants for the rings.
328 #define PVSCSI_MAX_NUM_PAGES_REQ_RING PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
329 #define PVSCSI_MAX_NUM_PAGES_CMP_RING PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
330 #define PVSCSI_MAX_NUM_PAGES_MSG_RING PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES
332 #define PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE \
333 (PAGE_SIZE / sizeof(struct PVSCSIRingReqDesc))
335 #define PVSCSI_MAX_REQ_QUEUE_DEPTH \
336 (PVSCSI_MAX_NUM_PAGES_REQ_RING * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE)
338 #define PVSCSI_MEM_SPACE_COMMAND_NUM_PAGES 1
339 #define PVSCSI_MEM_SPACE_INTR_STATUS_NUM_PAGES 1
340 #define PVSCSI_MEM_SPACE_MISC_NUM_PAGES 2
341 #define PVSCSI_MEM_SPACE_KICK_IO_NUM_PAGES 2
342 #define PVSCSI_MEM_SPACE_MSIX_NUM_PAGES 2
344 enum PVSCSIMemSpace
{
345 PVSCSI_MEM_SPACE_COMMAND_PAGE
= 0,
346 PVSCSI_MEM_SPACE_INTR_STATUS_PAGE
= 1,
347 PVSCSI_MEM_SPACE_MISC_PAGE
= 2,
348 PVSCSI_MEM_SPACE_KICK_IO_PAGE
= 4,
349 PVSCSI_MEM_SPACE_MSIX_TABLE_PAGE
= 6,
350 PVSCSI_MEM_SPACE_MSIX_PBA_PAGE
= 7,
353 #define PVSCSI_MEM_SPACE_NUM_PAGES \
354 (PVSCSI_MEM_SPACE_COMMAND_NUM_PAGES + \
355 PVSCSI_MEM_SPACE_INTR_STATUS_NUM_PAGES + \
356 PVSCSI_MEM_SPACE_MISC_NUM_PAGES + \
357 PVSCSI_MEM_SPACE_KICK_IO_NUM_PAGES + \
358 PVSCSI_MEM_SPACE_MSIX_NUM_PAGES)
360 #define PVSCSI_MEM_SPACE_SIZE (PVSCSI_MEM_SPACE_NUM_PAGES * PAGE_SIZE)
362 #endif /* _VMW_PVSCSI_H_ */