Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * VMware PVSCSI header file
0003  *
0004  * Copyright (C) 2008-2014, VMware, Inc. All Rights Reserved.
0005  *
0006  * This program is free software; you can redistribute it and/or modify it
0007  * under the terms of the GNU General Public License as published by the
0008  * Free Software Foundation; version 2 of the License and no later version.
0009  *
0010  * This program is distributed in the hope that it will be useful, but
0011  * WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
0013  * NON INFRINGEMENT.  See the GNU General Public License for more
0014  * details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program; if not, write to the Free Software
0018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0019  *
0020  */
0021 
0022 #ifndef _VMW_PVSCSI_H_
0023 #define _VMW_PVSCSI_H_
0024 
0025 #include <linux/types.h>
0026 
0027 #define PVSCSI_DRIVER_VERSION_STRING   "1.0.7.0-k"
0028 
0029 #define PVSCSI_MAX_NUM_SG_ENTRIES_PER_SEGMENT 128
0030 
0031 #define MASK(n)        ((1 << (n)) - 1)        /* make an n-bit mask */
0032 
0033 #define PCI_DEVICE_ID_VMWARE_PVSCSI 0x07C0
0034 
0035 /*
0036  * host adapter status/error codes
0037  */
0038 enum HostBusAdapterStatus {
0039     BTSTAT_SUCCESS       = 0x00,  /* CCB complete normally with no errors */
0040     BTSTAT_LINKED_COMMAND_COMPLETED           = 0x0a,
0041     BTSTAT_LINKED_COMMAND_COMPLETED_WITH_FLAG = 0x0b,
0042     BTSTAT_DATA_UNDERRUN = 0x0c,
0043     BTSTAT_SELTIMEO      = 0x11,  /* SCSI selection timeout */
0044     BTSTAT_DATARUN       = 0x12,  /* data overrun/underrun */
0045     BTSTAT_BUSFREE       = 0x13,  /* unexpected bus free */
0046     BTSTAT_INVPHASE      = 0x14,  /* invalid bus phase or sequence
0047                        * requested by target */
0048     BTSTAT_LUNMISMATCH   = 0x17,  /* linked CCB has different LUN from
0049                        * first CCB */
0050     BTSTAT_INVPARAM      = 0x1a,  /* invalid parameter in CCB or segment
0051                        * list */
0052     BTSTAT_SENSFAILED    = 0x1b,  /* auto request sense failed */
0053     BTSTAT_TAGREJECT     = 0x1c,  /* SCSI II tagged queueing message
0054                        * rejected by target */
0055     BTSTAT_BADMSG        = 0x1d,  /* unsupported message received by the
0056                        * host adapter */
0057     BTSTAT_HAHARDWARE    = 0x20,  /* host adapter hardware failed */
0058     BTSTAT_NORESPONSE    = 0x21,  /* target did not respond to SCSI ATN,
0059                        * sent a SCSI RST */
0060     BTSTAT_SENTRST       = 0x22,  /* host adapter asserted a SCSI RST */
0061     BTSTAT_RECVRST       = 0x23,  /* other SCSI devices asserted a SCSI
0062                        * RST */
0063     BTSTAT_DISCONNECT    = 0x24,  /* target device reconnected improperly
0064                        * (w/o tag) */
0065     BTSTAT_BUSRESET      = 0x25,  /* host adapter issued BUS device reset */
0066     BTSTAT_ABORTQUEUE    = 0x26,  /* abort queue generated */
0067     BTSTAT_HASOFTWARE    = 0x27,  /* host adapter software error */
0068     BTSTAT_HATIMEOUT     = 0x30,  /* host adapter hardware timeout error */
0069     BTSTAT_SCSIPARITY    = 0x34,  /* SCSI parity error detected */
0070 };
0071 
0072 /*
0073  * SCSI device status values.
0074  */
0075 enum ScsiDeviceStatus {
0076     SDSTAT_GOOD  = 0x00, /* No errors. */
0077     SDSTAT_CHECK = 0x02, /* Check condition. */
0078 };
0079 
0080 /*
0081  * Register offsets.
0082  *
0083  * These registers are accessible both via i/o space and mm i/o.
0084  */
0085 
0086 enum PVSCSIRegOffset {
0087     PVSCSI_REG_OFFSET_COMMAND        =    0x0,
0088     PVSCSI_REG_OFFSET_COMMAND_DATA   =    0x4,
0089     PVSCSI_REG_OFFSET_COMMAND_STATUS =    0x8,
0090     PVSCSI_REG_OFFSET_LAST_STS_0     =  0x100,
0091     PVSCSI_REG_OFFSET_LAST_STS_1     =  0x104,
0092     PVSCSI_REG_OFFSET_LAST_STS_2     =  0x108,
0093     PVSCSI_REG_OFFSET_LAST_STS_3     =  0x10c,
0094     PVSCSI_REG_OFFSET_INTR_STATUS    = 0x100c,
0095     PVSCSI_REG_OFFSET_INTR_MASK      = 0x2010,
0096     PVSCSI_REG_OFFSET_KICK_NON_RW_IO = 0x3014,
0097     PVSCSI_REG_OFFSET_DEBUG          = 0x3018,
0098     PVSCSI_REG_OFFSET_KICK_RW_IO     = 0x4018,
0099 };
0100 
0101 /*
0102  * Virtual h/w commands.
0103  */
0104 
0105 enum PVSCSICommands {
0106     PVSCSI_CMD_FIRST             = 0, /* has to be first */
0107 
0108     PVSCSI_CMD_ADAPTER_RESET     = 1,
0109     PVSCSI_CMD_ISSUE_SCSI        = 2,
0110     PVSCSI_CMD_SETUP_RINGS       = 3,
0111     PVSCSI_CMD_RESET_BUS         = 4,
0112     PVSCSI_CMD_RESET_DEVICE      = 5,
0113     PVSCSI_CMD_ABORT_CMD         = 6,
0114     PVSCSI_CMD_CONFIG            = 7,
0115     PVSCSI_CMD_SETUP_MSG_RING    = 8,
0116     PVSCSI_CMD_DEVICE_UNPLUG     = 9,
0117     PVSCSI_CMD_SETUP_REQCALLTHRESHOLD     = 10,
0118 
0119     PVSCSI_CMD_LAST              = 11  /* has to be last */
0120 };
0121 
0122 /*
0123  * Command descriptor for PVSCSI_CMD_RESET_DEVICE --
0124  */
0125 
0126 struct PVSCSICmdDescResetDevice {
0127     u32 target;
0128     u8  lun[8];
0129 } __packed;
0130 
0131 /*
0132  * Command descriptor for PVSCSI_CMD_CONFIG --
0133  */
0134 
0135 struct PVSCSICmdDescConfigCmd {
0136     u64 cmpAddr;
0137     u64 configPageAddress;
0138     u32 configPageNum;
0139     u32 _pad;
0140 } __packed;
0141 
0142 /*
0143  * Command descriptor for PVSCSI_CMD_SETUP_REQCALLTHRESHOLD --
0144  */
0145 
0146 struct PVSCSICmdDescSetupReqCall {
0147     u32 enable;
0148 } __packed;
0149 
0150 enum PVSCSIConfigPageType {
0151     PVSCSI_CONFIG_PAGE_CONTROLLER = 0x1958,
0152     PVSCSI_CONFIG_PAGE_PHY        = 0x1959,
0153     PVSCSI_CONFIG_PAGE_DEVICE     = 0x195a,
0154 };
0155 
0156 enum PVSCSIConfigPageAddressType {
0157     PVSCSI_CONFIG_CONTROLLER_ADDRESS = 0x2120,
0158     PVSCSI_CONFIG_BUSTARGET_ADDRESS  = 0x2121,
0159     PVSCSI_CONFIG_PHY_ADDRESS        = 0x2122,
0160 };
0161 
0162 /*
0163  * Command descriptor for PVSCSI_CMD_ABORT_CMD --
0164  *
0165  * - currently does not support specifying the LUN.
0166  * - _pad should be 0.
0167  */
0168 
0169 struct PVSCSICmdDescAbortCmd {
0170     u64 context;
0171     u32 target;
0172     u32 _pad;
0173 } __packed;
0174 
0175 /*
0176  * Command descriptor for PVSCSI_CMD_SETUP_RINGS --
0177  *
0178  * Notes:
0179  * - reqRingNumPages and cmpRingNumPages need to be power of two.
0180  * - reqRingNumPages and cmpRingNumPages need to be different from 0,
0181  * - reqRingNumPages and cmpRingNumPages need to be inferior to
0182  *   PVSCSI_SETUP_RINGS_MAX_NUM_PAGES.
0183  */
0184 
0185 #define PVSCSI_SETUP_RINGS_MAX_NUM_PAGES        32
0186 struct PVSCSICmdDescSetupRings {
0187     u32 reqRingNumPages;
0188     u32 cmpRingNumPages;
0189     u64 ringsStatePPN;
0190     u64 reqRingPPNs[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES];
0191     u64 cmpRingPPNs[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES];
0192 } __packed;
0193 
0194 /*
0195  * Command descriptor for PVSCSI_CMD_SETUP_MSG_RING --
0196  *
0197  * Notes:
0198  * - this command was not supported in the initial revision of the h/w
0199  *   interface. Before using it, you need to check that it is supported by
0200  *   writing PVSCSI_CMD_SETUP_MSG_RING to the 'command' register, then
0201  *   immediately after read the 'command status' register:
0202  *       * a value of -1 means that the cmd is NOT supported,
0203  *       * a value != -1 means that the cmd IS supported.
0204  *   If it's supported the 'command status' register should return:
0205  *      sizeof(PVSCSICmdDescSetupMsgRing) / sizeof(u32).
0206  * - this command should be issued _after_ the usual SETUP_RINGS so that the
0207  *   RingsState page is already setup. If not, the command is a nop.
0208  * - numPages needs to be a power of two,
0209  * - numPages needs to be different from 0,
0210  * - _pad should be zero.
0211  */
0212 
0213 #define PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES  16
0214 
0215 struct PVSCSICmdDescSetupMsgRing {
0216     u32 numPages;
0217     u32 _pad;
0218     u64 ringPPNs[PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES];
0219 } __packed;
0220 
0221 enum PVSCSIMsgType {
0222     PVSCSI_MSG_DEV_ADDED          = 0,
0223     PVSCSI_MSG_DEV_REMOVED        = 1,
0224     PVSCSI_MSG_LAST               = 2,
0225 };
0226 
0227 /*
0228  * Msg descriptor.
0229  *
0230  * sizeof(struct PVSCSIRingMsgDesc) == 128.
0231  *
0232  * - type is of type enum PVSCSIMsgType.
0233  * - the content of args depend on the type of event being delivered.
0234  */
0235 
0236 struct PVSCSIRingMsgDesc {
0237     u32 type;
0238     u32 args[31];
0239 } __packed;
0240 
0241 struct PVSCSIMsgDescDevStatusChanged {
0242     u32 type;  /* PVSCSI_MSG_DEV _ADDED / _REMOVED */
0243     u32 bus;
0244     u32 target;
0245     u8  lun[8];
0246     u32 pad[27];
0247 } __packed;
0248 
0249 /*
0250  * Rings state.
0251  *
0252  * - the fields:
0253  *    . msgProdIdx,
0254  *    . msgConsIdx,
0255  *    . msgNumEntriesLog2,
0256  *   .. are only used once the SETUP_MSG_RING cmd has been issued.
0257  * - '_pad' helps to ensure that the msg related fields are on their own
0258  *   cache-line.
0259  */
0260 
0261 struct PVSCSIRingsState {
0262     u32 reqProdIdx;
0263     u32 reqConsIdx;
0264     u32 reqNumEntriesLog2;
0265 
0266     u32 cmpProdIdx;
0267     u32 cmpConsIdx;
0268     u32 cmpNumEntriesLog2;
0269 
0270     u32 reqCallThreshold;
0271 
0272     u8  _pad[100];
0273 
0274     u32 msgProdIdx;
0275     u32 msgConsIdx;
0276     u32 msgNumEntriesLog2;
0277 } __packed;
0278 
0279 /*
0280  * Request descriptor.
0281  *
0282  * sizeof(RingReqDesc) = 128
0283  *
0284  * - context: is a unique identifier of a command. It could normally be any
0285  *   64bit value, however we currently store it in the serialNumber variable
0286  *   of struct SCSI_Command, so we have the following restrictions due to the
0287  *   way this field is handled in the vmkernel storage stack:
0288  *    * this value can't be 0,
0289  *    * the upper 32bit need to be 0 since serialNumber is as a u32.
0290  *   Currently tracked as PR 292060.
0291  * - dataLen: contains the total number of bytes that need to be transferred.
0292  * - dataAddr:
0293  *   * if PVSCSI_FLAG_CMD_WITH_SG_LIST is set: dataAddr is the PA of the first
0294  *     s/g table segment, each s/g segment is entirely contained on a single
0295  *     page of physical memory,
0296  *   * if PVSCSI_FLAG_CMD_WITH_SG_LIST is NOT set, then dataAddr is the PA of
0297  *     the buffer used for the DMA transfer,
0298  * - flags:
0299  *   * PVSCSI_FLAG_CMD_WITH_SG_LIST: see dataAddr above,
0300  *   * PVSCSI_FLAG_CMD_DIR_NONE: no DMA involved,
0301  *   * PVSCSI_FLAG_CMD_DIR_TOHOST: transfer from device to main memory,
0302  *   * PVSCSI_FLAG_CMD_DIR_TODEVICE: transfer from main memory to device,
0303  *   * PVSCSI_FLAG_CMD_OUT_OF_BAND_CDB: reserved to handle CDBs larger than
0304  *     16bytes. To be specified.
0305  * - vcpuHint: vcpuId of the processor that will be most likely waiting for the
0306  *   completion of the i/o. For guest OSes that use lowest priority message
0307  *   delivery mode (such as windows), we use this "hint" to deliver the
0308  *   completion action to the proper vcpu. For now, we can use the vcpuId of
0309  *   the processor that initiated the i/o as a likely candidate for the vcpu
0310  *   that will be waiting for the completion..
0311  * - bus should be 0: we currently only support bus 0 for now.
0312  * - unused should be zero'd.
0313  */
0314 
0315 #define PVSCSI_FLAG_CMD_WITH_SG_LIST        (1 << 0)
0316 #define PVSCSI_FLAG_CMD_OUT_OF_BAND_CDB     (1 << 1)
0317 #define PVSCSI_FLAG_CMD_DIR_NONE            (1 << 2)
0318 #define PVSCSI_FLAG_CMD_DIR_TOHOST          (1 << 3)
0319 #define PVSCSI_FLAG_CMD_DIR_TODEVICE        (1 << 4)
0320 
0321 struct PVSCSIRingReqDesc {
0322     u64 context;
0323     u64 dataAddr;
0324     u64 dataLen;
0325     u64 senseAddr;
0326     u32 senseLen;
0327     u32 flags;
0328     u8  cdb[16];
0329     u8  cdbLen;
0330     u8  lun[8];
0331     u8  tag;
0332     u8  bus;
0333     u8  target;
0334     u16 vcpuHint;
0335     u8  unused[58];
0336 } __packed;
0337 
0338 /*
0339  * Scatter-gather list management.
0340  *
0341  * As described above, when PVSCSI_FLAG_CMD_WITH_SG_LIST is set in the
0342  * RingReqDesc.flags, then RingReqDesc.dataAddr is the PA of the first s/g
0343  * table segment.
0344  *
0345  * - each segment of the s/g table contain a succession of struct
0346  *   PVSCSISGElement.
0347  * - each segment is entirely contained on a single physical page of memory.
0348  * - a "chain" s/g element has the flag PVSCSI_SGE_FLAG_CHAIN_ELEMENT set in
0349  *   PVSCSISGElement.flags and in this case:
0350  *     * addr is the PA of the next s/g segment,
0351  *     * length is undefined, assumed to be 0.
0352  */
0353 
0354 struct PVSCSISGElement {
0355     u64 addr;
0356     u32 length;
0357     u32 flags;
0358 } __packed;
0359 
0360 /*
0361  * Completion descriptor.
0362  *
0363  * sizeof(RingCmpDesc) = 32
0364  *
0365  * - context: identifier of the command. The same thing that was specified
0366  *   under "context" as part of struct RingReqDesc at initiation time,
0367  * - dataLen: number of bytes transferred for the actual i/o operation,
0368  * - senseLen: number of bytes written into the sense buffer,
0369  * - hostStatus: adapter status,
0370  * - scsiStatus: device status,
0371  * - _pad should be zero.
0372  */
0373 
0374 struct PVSCSIRingCmpDesc {
0375     u64 context;
0376     u64 dataLen;
0377     u32 senseLen;
0378     u16 hostStatus;
0379     u16 scsiStatus;
0380     u32 _pad[2];
0381 } __packed;
0382 
0383 struct PVSCSIConfigPageHeader {
0384     u32 pageNum;
0385     u16 numDwords;
0386     u16 hostStatus;
0387     u16 scsiStatus;
0388     u16 reserved[3];
0389 } __packed;
0390 
0391 struct PVSCSIConfigPageController {
0392     struct PVSCSIConfigPageHeader header;
0393     u64 nodeWWN; /* Device name as defined in the SAS spec. */
0394     u16 manufacturer[64];
0395     u16 serialNumber[64];
0396     u16 opromVersion[32];
0397     u16 hwVersion[32];
0398     u16 firmwareVersion[32];
0399     u32 numPhys;
0400     u8  useConsecutivePhyWWNs;
0401     u8  reserved[3];
0402 } __packed;
0403 
0404 /*
0405  * Interrupt status / IRQ bits.
0406  */
0407 
0408 #define PVSCSI_INTR_CMPL_0                 (1 << 0)
0409 #define PVSCSI_INTR_CMPL_1                 (1 << 1)
0410 #define PVSCSI_INTR_CMPL_MASK              MASK(2)
0411 
0412 #define PVSCSI_INTR_MSG_0                  (1 << 2)
0413 #define PVSCSI_INTR_MSG_1                  (1 << 3)
0414 #define PVSCSI_INTR_MSG_MASK               (MASK(2) << 2)
0415 
0416 #define PVSCSI_INTR_ALL_SUPPORTED          MASK(4)
0417 
0418 /*
0419  * Number of MSI-X vectors supported.
0420  */
0421 #define PVSCSI_MAX_INTRS        24
0422 
0423 /*
0424  * Misc constants for the rings.
0425  */
0426 
0427 #define PVSCSI_MAX_NUM_PAGES_REQ_RING   PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
0428 #define PVSCSI_MAX_NUM_PAGES_CMP_RING   PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
0429 #define PVSCSI_MAX_NUM_PAGES_MSG_RING   PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES
0430 
0431 #define PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE \
0432                 (PAGE_SIZE / sizeof(struct PVSCSIRingReqDesc))
0433 
0434 #define PVSCSI_MAX_REQ_QUEUE_DEPTH \
0435     (PVSCSI_MAX_NUM_PAGES_REQ_RING * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE)
0436 
0437 #define PVSCSI_MEM_SPACE_COMMAND_NUM_PAGES     1
0438 #define PVSCSI_MEM_SPACE_INTR_STATUS_NUM_PAGES 1
0439 #define PVSCSI_MEM_SPACE_MISC_NUM_PAGES        2
0440 #define PVSCSI_MEM_SPACE_KICK_IO_NUM_PAGES     2
0441 #define PVSCSI_MEM_SPACE_MSIX_NUM_PAGES        2
0442 
0443 enum PVSCSIMemSpace {
0444     PVSCSI_MEM_SPACE_COMMAND_PAGE       = 0,
0445     PVSCSI_MEM_SPACE_INTR_STATUS_PAGE   = 1,
0446     PVSCSI_MEM_SPACE_MISC_PAGE      = 2,
0447     PVSCSI_MEM_SPACE_KICK_IO_PAGE       = 4,
0448     PVSCSI_MEM_SPACE_MSIX_TABLE_PAGE    = 6,
0449     PVSCSI_MEM_SPACE_MSIX_PBA_PAGE      = 7,
0450 };
0451 
0452 #define PVSCSI_MEM_SPACE_NUM_PAGES \
0453     (PVSCSI_MEM_SPACE_COMMAND_NUM_PAGES +       \
0454      PVSCSI_MEM_SPACE_INTR_STATUS_NUM_PAGES +   \
0455      PVSCSI_MEM_SPACE_MISC_NUM_PAGES +          \
0456      PVSCSI_MEM_SPACE_KICK_IO_NUM_PAGES +       \
0457      PVSCSI_MEM_SPACE_MSIX_NUM_PAGES)
0458 
0459 #define PVSCSI_MEM_SPACE_SIZE        (PVSCSI_MEM_SPACE_NUM_PAGES * PAGE_SIZE)
0460 
0461 #endif /* _VMW_PVSCSI_H_ */