565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Copyright (C) 2008-2014, VMware, Inc. All Rights Reserved.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Redistribution and use in source and binary forms, with or without
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * modification, are permitted provided that the following conditions are met:
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * 1. Redistributions of source code must retain the above copyright notice,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * this list of conditions and the following disclaimer.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * 2. Redistributions in binary form must reproduce the above copyright notice,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * this list of conditions and the following disclaimer in the documentation
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * and/or other materials provided with the distribution.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov#define PVSCSI_MAX_NUM_SG_ENTRIES_PER_SEGMENT 128
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov#define MASK(n) ((1 << (n)) - 1) /* make an n-bit mask */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * host adapter status/error codes
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_SUCCESS = 0x00, /* CCB complete normally with */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov /* no errors */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_LINKED_COMMAND_COMPLETED_WITH_FLAG = 0x0b,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_SELTIMEO = 0x11, /* SCSI selection timeout */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_DATARUN = 0x12, /* data overrun/underrun */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_BUSFREE = 0x13, /* unexpected bus free */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_INVPHASE = 0x14, /* invalid bus phase or sequence */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov /* requested by target */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_LUNMISMATCH = 0x17, /* linked CCB has different LUN from */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov /* first CCB */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_INVPARAM = 0x1a, /* invalid parameter in CCB */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov /* or segment list */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_SENSFAILED = 0x1b, /* auto request sense failed */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_TAGREJECT = 0x1c, /* SCSI II tagged queueing message */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov /* rejected by target */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_BADMSG = 0x1d, /* unsupported message received by */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov /* the host adapter */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_HAHARDWARE = 0x20, /* host adapter hardware failed */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_NORESPONSE = 0x21, /* target did not respond to */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov /* SCSI ATN, sent a SCSI RST */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_SENTRST = 0x22, /* host adapter asserted a SCSI RST */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_RECVRST = 0x23, /* other SCSI devices asserted */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov /* a SCSI RST */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_DISCONNECT = 0x24, /* target device reconnected */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov /* improperly (w/o tag) */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_BUSRESET = 0x25, /* host adapter issued */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov /* BUS device reset */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_ABORTQUEUE = 0x26, /* abort queue generated */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_HASOFTWARE = 0x27, /* host adapter software error */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_HATIMEOUT = 0x30, /* host adapter hardware */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov /* timeout error */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov BTSTAT_SCSIPARITY = 0x34, /* SCSI parity error detected */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * SCSI device status values.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Register offsets.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * These registers are accessible both via i/o space and mm i/o.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Virtual h/w commands.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Command descriptor for PVSCSI_CMD_RESET_DEVICE --
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Command descriptor for PVSCSI_CMD_CONFIG --
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Command descriptor for PVSCSI_CMD_SETUP_REQCALLTHRESHOLD --
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Command descriptor for PVSCSI_CMD_ABORT_CMD --
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - currently does not support specifying the LUN.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - _pad should be 0.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Command descriptor for PVSCSI_CMD_SETUP_RINGS --
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - reqRingNumPages and cmpRingNumPages need to be power of two.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - reqRingNumPages and cmpRingNumPages need to be different from 0,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - reqRingNumPages and cmpRingNumPages need to be inferior to
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * PVSCSI_SETUP_RINGS_MAX_NUM_PAGES.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov uint64_t reqRingPPNs[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES];
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov uint64_t cmpRingPPNs[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES];
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Command descriptor for PVSCSI_CMD_SETUP_MSG_RING --
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - this command was not supported in the initial revision of the h/w
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * interface. Before using it, you need to check that it is supported by
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * writing PVSCSI_CMD_SETUP_MSG_RING to the 'command' register, then
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * immediately after read the 'command status' register:
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * * a value of -1 means that the cmd is NOT supported,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * * a value != -1 means that the cmd IS supported.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * If it's supported the 'command status' register should return:
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * sizeof(PVSCSICmdDescSetupMsgRing) / sizeof(uint32_t).
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - this command should be issued _after_ the usual SETUP_RINGS so that the
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * RingsState page is already setup. If not, the command is a nop.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - numPages needs to be a power of two,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - numPages needs to be different from 0,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - _pad should be zero.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov uint64_t ringPPNs[PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES];
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Msg descriptor.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * sizeof(struct PVSCSIRingMsgDesc) == 128.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - type is of type enum PVSCSIMsgType.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - the content of args depend on the type of event being delivered.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov uint32_t type; /* PVSCSI_MSG_DEV _ADDED / _REMOVED */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Rings state.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - the fields:
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * . msgProdIdx,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * . msgConsIdx,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * . msgNumEntriesLog2,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * .. are only used once the SETUP_MSG_RING cmd has been issued.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - '_pad' helps to ensure that the msg related fields are on their own
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * cache-line.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Request descriptor.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * sizeof(RingReqDesc) = 128
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - context: is a unique identifier of a command. It could normally be any
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * 64bit value, however we currently store it in the serialNumber variable
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * of struct SCSI_Command, so we have the following restrictions due to the
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * way this field is handled in the vmkernel storage stack:
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * * this value can't be 0,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * * the upper 32bit need to be 0 since serialNumber is as a uint32_t.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Currently tracked as PR 292060.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - dataLen: contains the total number of bytes that need to be transferred.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - dataAddr:
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * * if PVSCSI_FLAG_CMD_WITH_SG_LIST is set: dataAddr is the PA of the first
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * s/g table segment, each s/g segment is entirely contained on a single
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * page of physical memory,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * * if PVSCSI_FLAG_CMD_WITH_SG_LIST is NOT set, then dataAddr is the PA of
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * the buffer used for the DMA transfer,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * * PVSCSI_FLAG_CMD_WITH_SG_LIST: see dataAddr above,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * * PVSCSI_FLAG_CMD_DIR_NONE: no DMA involved,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * * PVSCSI_FLAG_CMD_DIR_TOHOST: transfer from device to main memory,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * * PVSCSI_FLAG_CMD_DIR_TODEVICE: transfer from main memory to device,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * * PVSCSI_FLAG_CMD_OUT_OF_BAND_CDB: reserved to handle CDBs larger than
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * 16bytes. To be specified.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - vcpuHint: vcpuId of the processor that will be most likely waiting for the
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * completion of the i/o. For guest OSes that use lowest priority message
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * delivery mode (such as windows), we use this "hint" to deliver the
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * completion action to the proper vcpu. For now, we can use the vcpuId of
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * the processor that initiated the i/o as a likely candidate for the vcpu
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * that will be waiting for the completion..
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - bus should be 0: we currently only support bus 0 for now.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - unused should be zero'd.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Scatter-gather list management.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * As described above, when PVSCSI_FLAG_CMD_WITH_SG_LIST is set in the
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * RingReqDesc.flags, then RingReqDesc.dataAddr is the PA of the first s/g
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * table segment.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - each segment of the s/g table contain a succession of struct
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * PVSCSISGElement.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - each segment is entirely contained on a single physical page of memory.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - a "chain" s/g element has the flag PVSCSI_SGE_FLAG_CHAIN_ELEMENT set in
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * PVSCSISGElement.flags and in this case:
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * * addr is the PA of the next s/g segment,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * * length is undefined, assumed to be 0.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Completion descriptor.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * sizeof(RingCmpDesc) = 32
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - context: identifier of the command. The same thing that was specified
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * under "context" as part of struct RingReqDesc at initiation time,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - dataLen: number of bytes transferred for the actual i/o operation,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - senseLen: number of bytes written into the sense buffer,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - hostStatus: adapter status,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - scsiStatus: device status,
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * - _pad should be zero.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov uint64_t nodeWWN; /* Device name as defined in the SAS spec. */
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Interrupt status / IRQ bits.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Number of MSI-X vectors supported.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Enumeration of supported MSI-X vectors
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov * Misc constants for the rings.
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov#define PVSCSI_MAX_NUM_PAGES_REQ_RING PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov#define PVSCSI_MAX_NUM_PAGES_CMP_RING PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov#define PVSCSI_MAX_NUM_PAGES_MSG_RING PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov (PVSCSI_MAX_NUM_PAGES_REQ_RING * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE)
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov#define PVSCSI_MEM_SPACE_SIZE (PVSCSI_MEM_SPACE_NUM_PAGES * PAGE_SIZE)
565657ca18725b8f8dbe5b93704cc1d173be9d65Yuri Pankov#endif /* _PVSCSI_H_ */