1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * VMware PVSCSI header file 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * Copyright (C) 2008-2014, VMware, Inc. All Rights Reserved. 5*4882a593Smuzhiyun * 6*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify it 7*4882a593Smuzhiyun * under the terms of the GNU General Public License as published by the 8*4882a593Smuzhiyun * Free Software Foundation; version 2 of the License and no later version. 9*4882a593Smuzhiyun * 10*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, but 11*4882a593Smuzhiyun * WITHOUT ANY WARRANTY; without even the implied warranty of 12*4882a593Smuzhiyun * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or 13*4882a593Smuzhiyun * NON INFRINGEMENT. See the GNU General Public License for more 14*4882a593Smuzhiyun * details. 15*4882a593Smuzhiyun * 16*4882a593Smuzhiyun * You should have received a copy of the GNU General Public License 17*4882a593Smuzhiyun * along with this program; if not, write to the Free Software 18*4882a593Smuzhiyun * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19*4882a593Smuzhiyun * 20*4882a593Smuzhiyun * Maintained by: Jim Gill <jgill@vmware.com> 21*4882a593Smuzhiyun * 22*4882a593Smuzhiyun */ 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun #ifndef _VMW_PVSCSI_H_ 25*4882a593Smuzhiyun #define _VMW_PVSCSI_H_ 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun #include <linux/types.h> 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun #define PVSCSI_DRIVER_VERSION_STRING "1.0.7.0-k" 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun #define PVSCSI_MAX_NUM_SG_ENTRIES_PER_SEGMENT 128 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun #define MASK(n) ((1 << (n)) - 1) /* make an n-bit mask */ 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun #define PCI_DEVICE_ID_VMWARE_PVSCSI 0x07C0 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun /* 38*4882a593Smuzhiyun * host adapter status/error codes 39*4882a593Smuzhiyun */ 40*4882a593Smuzhiyun enum HostBusAdapterStatus { 41*4882a593Smuzhiyun BTSTAT_SUCCESS = 0x00, /* CCB complete normally with no errors */ 42*4882a593Smuzhiyun BTSTAT_LINKED_COMMAND_COMPLETED = 0x0a, 43*4882a593Smuzhiyun BTSTAT_LINKED_COMMAND_COMPLETED_WITH_FLAG = 0x0b, 44*4882a593Smuzhiyun BTSTAT_DATA_UNDERRUN = 0x0c, 45*4882a593Smuzhiyun BTSTAT_SELTIMEO = 0x11, /* SCSI selection timeout */ 46*4882a593Smuzhiyun BTSTAT_DATARUN = 0x12, /* data overrun/underrun */ 47*4882a593Smuzhiyun BTSTAT_BUSFREE = 0x13, /* unexpected bus free */ 48*4882a593Smuzhiyun BTSTAT_INVPHASE = 0x14, /* invalid bus phase or sequence 49*4882a593Smuzhiyun * requested by target */ 50*4882a593Smuzhiyun BTSTAT_LUNMISMATCH = 0x17, /* linked CCB has different LUN from 51*4882a593Smuzhiyun * first CCB */ 52*4882a593Smuzhiyun BTSTAT_INVPARAM = 0x1a, /* invalid parameter in CCB or segment 53*4882a593Smuzhiyun * list */ 54*4882a593Smuzhiyun BTSTAT_SENSFAILED = 0x1b, /* auto request sense failed */ 55*4882a593Smuzhiyun BTSTAT_TAGREJECT = 0x1c, /* SCSI II tagged queueing message 56*4882a593Smuzhiyun * rejected by target */ 57*4882a593Smuzhiyun BTSTAT_BADMSG = 0x1d, /* unsupported message received by the 58*4882a593Smuzhiyun * host adapter */ 59*4882a593Smuzhiyun BTSTAT_HAHARDWARE = 0x20, /* host adapter hardware failed */ 60*4882a593Smuzhiyun BTSTAT_NORESPONSE = 0x21, /* target did not respond to SCSI ATN, 61*4882a593Smuzhiyun * sent a SCSI RST */ 62*4882a593Smuzhiyun BTSTAT_SENTRST = 0x22, /* host adapter asserted a SCSI RST */ 63*4882a593Smuzhiyun BTSTAT_RECVRST = 0x23, /* other SCSI devices asserted a SCSI 64*4882a593Smuzhiyun * RST */ 65*4882a593Smuzhiyun BTSTAT_DISCONNECT = 0x24, /* target device reconnected improperly 66*4882a593Smuzhiyun * (w/o tag) */ 67*4882a593Smuzhiyun BTSTAT_BUSRESET = 0x25, /* host adapter issued BUS device reset */ 68*4882a593Smuzhiyun BTSTAT_ABORTQUEUE = 0x26, /* abort queue generated */ 69*4882a593Smuzhiyun BTSTAT_HASOFTWARE = 0x27, /* host adapter software error */ 70*4882a593Smuzhiyun BTSTAT_HATIMEOUT = 0x30, /* host adapter hardware timeout error */ 71*4882a593Smuzhiyun BTSTAT_SCSIPARITY = 0x34, /* SCSI parity error detected */ 72*4882a593Smuzhiyun }; 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun /* 75*4882a593Smuzhiyun * SCSI device status values. 76*4882a593Smuzhiyun */ 77*4882a593Smuzhiyun enum ScsiDeviceStatus { 78*4882a593Smuzhiyun SDSTAT_GOOD = 0x00, /* No errors. */ 79*4882a593Smuzhiyun SDSTAT_CHECK = 0x02, /* Check condition. */ 80*4882a593Smuzhiyun }; 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun /* 83*4882a593Smuzhiyun * Register offsets. 84*4882a593Smuzhiyun * 85*4882a593Smuzhiyun * These registers are accessible both via i/o space and mm i/o. 86*4882a593Smuzhiyun */ 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun enum PVSCSIRegOffset { 89*4882a593Smuzhiyun PVSCSI_REG_OFFSET_COMMAND = 0x0, 90*4882a593Smuzhiyun PVSCSI_REG_OFFSET_COMMAND_DATA = 0x4, 91*4882a593Smuzhiyun PVSCSI_REG_OFFSET_COMMAND_STATUS = 0x8, 92*4882a593Smuzhiyun PVSCSI_REG_OFFSET_LAST_STS_0 = 0x100, 93*4882a593Smuzhiyun PVSCSI_REG_OFFSET_LAST_STS_1 = 0x104, 94*4882a593Smuzhiyun PVSCSI_REG_OFFSET_LAST_STS_2 = 0x108, 95*4882a593Smuzhiyun PVSCSI_REG_OFFSET_LAST_STS_3 = 0x10c, 96*4882a593Smuzhiyun PVSCSI_REG_OFFSET_INTR_STATUS = 0x100c, 97*4882a593Smuzhiyun PVSCSI_REG_OFFSET_INTR_MASK = 0x2010, 98*4882a593Smuzhiyun PVSCSI_REG_OFFSET_KICK_NON_RW_IO = 0x3014, 99*4882a593Smuzhiyun PVSCSI_REG_OFFSET_DEBUG = 0x3018, 100*4882a593Smuzhiyun PVSCSI_REG_OFFSET_KICK_RW_IO = 0x4018, 101*4882a593Smuzhiyun }; 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun /* 104*4882a593Smuzhiyun * Virtual h/w commands. 105*4882a593Smuzhiyun */ 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun enum PVSCSICommands { 108*4882a593Smuzhiyun PVSCSI_CMD_FIRST = 0, /* has to be first */ 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun PVSCSI_CMD_ADAPTER_RESET = 1, 111*4882a593Smuzhiyun PVSCSI_CMD_ISSUE_SCSI = 2, 112*4882a593Smuzhiyun PVSCSI_CMD_SETUP_RINGS = 3, 113*4882a593Smuzhiyun PVSCSI_CMD_RESET_BUS = 4, 114*4882a593Smuzhiyun PVSCSI_CMD_RESET_DEVICE = 5, 115*4882a593Smuzhiyun PVSCSI_CMD_ABORT_CMD = 6, 116*4882a593Smuzhiyun PVSCSI_CMD_CONFIG = 7, 117*4882a593Smuzhiyun PVSCSI_CMD_SETUP_MSG_RING = 8, 118*4882a593Smuzhiyun PVSCSI_CMD_DEVICE_UNPLUG = 9, 119*4882a593Smuzhiyun PVSCSI_CMD_SETUP_REQCALLTHRESHOLD = 10, 120*4882a593Smuzhiyun 121*4882a593Smuzhiyun PVSCSI_CMD_LAST = 11 /* has to be last */ 122*4882a593Smuzhiyun }; 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun /* 125*4882a593Smuzhiyun * Command descriptor for PVSCSI_CMD_RESET_DEVICE -- 126*4882a593Smuzhiyun */ 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun struct PVSCSICmdDescResetDevice { 129*4882a593Smuzhiyun u32 target; 130*4882a593Smuzhiyun u8 lun[8]; 131*4882a593Smuzhiyun } __packed; 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun /* 134*4882a593Smuzhiyun * Command descriptor for PVSCSI_CMD_CONFIG -- 135*4882a593Smuzhiyun */ 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun struct PVSCSICmdDescConfigCmd { 138*4882a593Smuzhiyun u64 cmpAddr; 139*4882a593Smuzhiyun u64 configPageAddress; 140*4882a593Smuzhiyun u32 configPageNum; 141*4882a593Smuzhiyun u32 _pad; 142*4882a593Smuzhiyun } __packed; 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun /* 145*4882a593Smuzhiyun * Command descriptor for PVSCSI_CMD_SETUP_REQCALLTHRESHOLD -- 146*4882a593Smuzhiyun */ 147*4882a593Smuzhiyun 148*4882a593Smuzhiyun struct PVSCSICmdDescSetupReqCall { 149*4882a593Smuzhiyun u32 enable; 150*4882a593Smuzhiyun } __packed; 151*4882a593Smuzhiyun 152*4882a593Smuzhiyun enum PVSCSIConfigPageType { 153*4882a593Smuzhiyun PVSCSI_CONFIG_PAGE_CONTROLLER = 0x1958, 154*4882a593Smuzhiyun PVSCSI_CONFIG_PAGE_PHY = 0x1959, 155*4882a593Smuzhiyun PVSCSI_CONFIG_PAGE_DEVICE = 0x195a, 156*4882a593Smuzhiyun }; 157*4882a593Smuzhiyun 158*4882a593Smuzhiyun enum PVSCSIConfigPageAddressType { 159*4882a593Smuzhiyun PVSCSI_CONFIG_CONTROLLER_ADDRESS = 0x2120, 160*4882a593Smuzhiyun PVSCSI_CONFIG_BUSTARGET_ADDRESS = 0x2121, 161*4882a593Smuzhiyun PVSCSI_CONFIG_PHY_ADDRESS = 0x2122, 162*4882a593Smuzhiyun }; 163*4882a593Smuzhiyun 164*4882a593Smuzhiyun /* 165*4882a593Smuzhiyun * Command descriptor for PVSCSI_CMD_ABORT_CMD -- 166*4882a593Smuzhiyun * 167*4882a593Smuzhiyun * - currently does not support specifying the LUN. 168*4882a593Smuzhiyun * - _pad should be 0. 169*4882a593Smuzhiyun */ 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun struct PVSCSICmdDescAbortCmd { 172*4882a593Smuzhiyun u64 context; 173*4882a593Smuzhiyun u32 target; 174*4882a593Smuzhiyun u32 _pad; 175*4882a593Smuzhiyun } __packed; 176*4882a593Smuzhiyun 177*4882a593Smuzhiyun /* 178*4882a593Smuzhiyun * Command descriptor for PVSCSI_CMD_SETUP_RINGS -- 179*4882a593Smuzhiyun * 180*4882a593Smuzhiyun * Notes: 181*4882a593Smuzhiyun * - reqRingNumPages and cmpRingNumPages need to be power of two. 182*4882a593Smuzhiyun * - reqRingNumPages and cmpRingNumPages need to be different from 0, 183*4882a593Smuzhiyun * - reqRingNumPages and cmpRingNumPages need to be inferior to 184*4882a593Smuzhiyun * PVSCSI_SETUP_RINGS_MAX_NUM_PAGES. 185*4882a593Smuzhiyun */ 186*4882a593Smuzhiyun 187*4882a593Smuzhiyun #define PVSCSI_SETUP_RINGS_MAX_NUM_PAGES 32 188*4882a593Smuzhiyun struct PVSCSICmdDescSetupRings { 189*4882a593Smuzhiyun u32 reqRingNumPages; 190*4882a593Smuzhiyun u32 cmpRingNumPages; 191*4882a593Smuzhiyun u64 ringsStatePPN; 192*4882a593Smuzhiyun u64 reqRingPPNs[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES]; 193*4882a593Smuzhiyun u64 cmpRingPPNs[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES]; 194*4882a593Smuzhiyun } __packed; 195*4882a593Smuzhiyun 196*4882a593Smuzhiyun /* 197*4882a593Smuzhiyun * Command descriptor for PVSCSI_CMD_SETUP_MSG_RING -- 198*4882a593Smuzhiyun * 199*4882a593Smuzhiyun * Notes: 200*4882a593Smuzhiyun * - this command was not supported in the initial revision of the h/w 201*4882a593Smuzhiyun * interface. Before using it, you need to check that it is supported by 202*4882a593Smuzhiyun * writing PVSCSI_CMD_SETUP_MSG_RING to the 'command' register, then 203*4882a593Smuzhiyun * immediately after read the 'command status' register: 204*4882a593Smuzhiyun * * a value of -1 means that the cmd is NOT supported, 205*4882a593Smuzhiyun * * a value != -1 means that the cmd IS supported. 206*4882a593Smuzhiyun * If it's supported the 'command status' register should return: 207*4882a593Smuzhiyun * sizeof(PVSCSICmdDescSetupMsgRing) / sizeof(u32). 208*4882a593Smuzhiyun * - this command should be issued _after_ the usual SETUP_RINGS so that the 209*4882a593Smuzhiyun * RingsState page is already setup. If not, the command is a nop. 210*4882a593Smuzhiyun * - numPages needs to be a power of two, 211*4882a593Smuzhiyun * - numPages needs to be different from 0, 212*4882a593Smuzhiyun * - _pad should be zero. 213*4882a593Smuzhiyun */ 214*4882a593Smuzhiyun 215*4882a593Smuzhiyun #define PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES 16 216*4882a593Smuzhiyun 217*4882a593Smuzhiyun struct PVSCSICmdDescSetupMsgRing { 218*4882a593Smuzhiyun u32 numPages; 219*4882a593Smuzhiyun u32 _pad; 220*4882a593Smuzhiyun u64 ringPPNs[PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES]; 221*4882a593Smuzhiyun } __packed; 222*4882a593Smuzhiyun 223*4882a593Smuzhiyun enum PVSCSIMsgType { 224*4882a593Smuzhiyun PVSCSI_MSG_DEV_ADDED = 0, 225*4882a593Smuzhiyun PVSCSI_MSG_DEV_REMOVED = 1, 226*4882a593Smuzhiyun PVSCSI_MSG_LAST = 2, 227*4882a593Smuzhiyun }; 228*4882a593Smuzhiyun 229*4882a593Smuzhiyun /* 230*4882a593Smuzhiyun * Msg descriptor. 231*4882a593Smuzhiyun * 232*4882a593Smuzhiyun * sizeof(struct PVSCSIRingMsgDesc) == 128. 233*4882a593Smuzhiyun * 234*4882a593Smuzhiyun * - type is of type enum PVSCSIMsgType. 235*4882a593Smuzhiyun * - the content of args depend on the type of event being delivered. 236*4882a593Smuzhiyun */ 237*4882a593Smuzhiyun 238*4882a593Smuzhiyun struct PVSCSIRingMsgDesc { 239*4882a593Smuzhiyun u32 type; 240*4882a593Smuzhiyun u32 args[31]; 241*4882a593Smuzhiyun } __packed; 242*4882a593Smuzhiyun 243*4882a593Smuzhiyun struct PVSCSIMsgDescDevStatusChanged { 244*4882a593Smuzhiyun u32 type; /* PVSCSI_MSG_DEV _ADDED / _REMOVED */ 245*4882a593Smuzhiyun u32 bus; 246*4882a593Smuzhiyun u32 target; 247*4882a593Smuzhiyun u8 lun[8]; 248*4882a593Smuzhiyun u32 pad[27]; 249*4882a593Smuzhiyun } __packed; 250*4882a593Smuzhiyun 251*4882a593Smuzhiyun /* 252*4882a593Smuzhiyun * Rings state. 253*4882a593Smuzhiyun * 254*4882a593Smuzhiyun * - the fields: 255*4882a593Smuzhiyun * . msgProdIdx, 256*4882a593Smuzhiyun * . msgConsIdx, 257*4882a593Smuzhiyun * . msgNumEntriesLog2, 258*4882a593Smuzhiyun * .. are only used once the SETUP_MSG_RING cmd has been issued. 259*4882a593Smuzhiyun * - '_pad' helps to ensure that the msg related fields are on their own 260*4882a593Smuzhiyun * cache-line. 261*4882a593Smuzhiyun */ 262*4882a593Smuzhiyun 263*4882a593Smuzhiyun struct PVSCSIRingsState { 264*4882a593Smuzhiyun u32 reqProdIdx; 265*4882a593Smuzhiyun u32 reqConsIdx; 266*4882a593Smuzhiyun u32 reqNumEntriesLog2; 267*4882a593Smuzhiyun 268*4882a593Smuzhiyun u32 cmpProdIdx; 269*4882a593Smuzhiyun u32 cmpConsIdx; 270*4882a593Smuzhiyun u32 cmpNumEntriesLog2; 271*4882a593Smuzhiyun 272*4882a593Smuzhiyun u32 reqCallThreshold; 273*4882a593Smuzhiyun 274*4882a593Smuzhiyun u8 _pad[100]; 275*4882a593Smuzhiyun 276*4882a593Smuzhiyun u32 msgProdIdx; 277*4882a593Smuzhiyun u32 msgConsIdx; 278*4882a593Smuzhiyun u32 msgNumEntriesLog2; 279*4882a593Smuzhiyun } __packed; 280*4882a593Smuzhiyun 281*4882a593Smuzhiyun /* 282*4882a593Smuzhiyun * Request descriptor. 283*4882a593Smuzhiyun * 284*4882a593Smuzhiyun * sizeof(RingReqDesc) = 128 285*4882a593Smuzhiyun * 286*4882a593Smuzhiyun * - context: is a unique identifier of a command. It could normally be any 287*4882a593Smuzhiyun * 64bit value, however we currently store it in the serialNumber variable 288*4882a593Smuzhiyun * of struct SCSI_Command, so we have the following restrictions due to the 289*4882a593Smuzhiyun * way this field is handled in the vmkernel storage stack: 290*4882a593Smuzhiyun * * this value can't be 0, 291*4882a593Smuzhiyun * * the upper 32bit need to be 0 since serialNumber is as a u32. 292*4882a593Smuzhiyun * Currently tracked as PR 292060. 293*4882a593Smuzhiyun * - dataLen: contains the total number of bytes that need to be transferred. 294*4882a593Smuzhiyun * - dataAddr: 295*4882a593Smuzhiyun * * if PVSCSI_FLAG_CMD_WITH_SG_LIST is set: dataAddr is the PA of the first 296*4882a593Smuzhiyun * s/g table segment, each s/g segment is entirely contained on a single 297*4882a593Smuzhiyun * page of physical memory, 298*4882a593Smuzhiyun * * if PVSCSI_FLAG_CMD_WITH_SG_LIST is NOT set, then dataAddr is the PA of 299*4882a593Smuzhiyun * the buffer used for the DMA transfer, 300*4882a593Smuzhiyun * - flags: 301*4882a593Smuzhiyun * * PVSCSI_FLAG_CMD_WITH_SG_LIST: see dataAddr above, 302*4882a593Smuzhiyun * * PVSCSI_FLAG_CMD_DIR_NONE: no DMA involved, 303*4882a593Smuzhiyun * * PVSCSI_FLAG_CMD_DIR_TOHOST: transfer from device to main memory, 304*4882a593Smuzhiyun * * PVSCSI_FLAG_CMD_DIR_TODEVICE: transfer from main memory to device, 305*4882a593Smuzhiyun * * PVSCSI_FLAG_CMD_OUT_OF_BAND_CDB: reserved to handle CDBs larger than 306*4882a593Smuzhiyun * 16bytes. To be specified. 307*4882a593Smuzhiyun * - vcpuHint: vcpuId of the processor that will be most likely waiting for the 308*4882a593Smuzhiyun * completion of the i/o. For guest OSes that use lowest priority message 309*4882a593Smuzhiyun * delivery mode (such as windows), we use this "hint" to deliver the 310*4882a593Smuzhiyun * completion action to the proper vcpu. For now, we can use the vcpuId of 311*4882a593Smuzhiyun * the processor that initiated the i/o as a likely candidate for the vcpu 312*4882a593Smuzhiyun * that will be waiting for the completion.. 313*4882a593Smuzhiyun * - bus should be 0: we currently only support bus 0 for now. 314*4882a593Smuzhiyun * - unused should be zero'd. 315*4882a593Smuzhiyun */ 316*4882a593Smuzhiyun 317*4882a593Smuzhiyun #define PVSCSI_FLAG_CMD_WITH_SG_LIST (1 << 0) 318*4882a593Smuzhiyun #define PVSCSI_FLAG_CMD_OUT_OF_BAND_CDB (1 << 1) 319*4882a593Smuzhiyun #define PVSCSI_FLAG_CMD_DIR_NONE (1 << 2) 320*4882a593Smuzhiyun #define PVSCSI_FLAG_CMD_DIR_TOHOST (1 << 3) 321*4882a593Smuzhiyun #define PVSCSI_FLAG_CMD_DIR_TODEVICE (1 << 4) 322*4882a593Smuzhiyun 323*4882a593Smuzhiyun struct PVSCSIRingReqDesc { 324*4882a593Smuzhiyun u64 context; 325*4882a593Smuzhiyun u64 dataAddr; 326*4882a593Smuzhiyun u64 dataLen; 327*4882a593Smuzhiyun u64 senseAddr; 328*4882a593Smuzhiyun u32 senseLen; 329*4882a593Smuzhiyun u32 flags; 330*4882a593Smuzhiyun u8 cdb[16]; 331*4882a593Smuzhiyun u8 cdbLen; 332*4882a593Smuzhiyun u8 lun[8]; 333*4882a593Smuzhiyun u8 tag; 334*4882a593Smuzhiyun u8 bus; 335*4882a593Smuzhiyun u8 target; 336*4882a593Smuzhiyun u16 vcpuHint; 337*4882a593Smuzhiyun u8 unused[58]; 338*4882a593Smuzhiyun } __packed; 339*4882a593Smuzhiyun 340*4882a593Smuzhiyun /* 341*4882a593Smuzhiyun * Scatter-gather list management. 342*4882a593Smuzhiyun * 343*4882a593Smuzhiyun * As described above, when PVSCSI_FLAG_CMD_WITH_SG_LIST is set in the 344*4882a593Smuzhiyun * RingReqDesc.flags, then RingReqDesc.dataAddr is the PA of the first s/g 345*4882a593Smuzhiyun * table segment. 346*4882a593Smuzhiyun * 347*4882a593Smuzhiyun * - each segment of the s/g table contain a succession of struct 348*4882a593Smuzhiyun * PVSCSISGElement. 349*4882a593Smuzhiyun * - each segment is entirely contained on a single physical page of memory. 350*4882a593Smuzhiyun * - a "chain" s/g element has the flag PVSCSI_SGE_FLAG_CHAIN_ELEMENT set in 351*4882a593Smuzhiyun * PVSCSISGElement.flags and in this case: 352*4882a593Smuzhiyun * * addr is the PA of the next s/g segment, 353*4882a593Smuzhiyun * * length is undefined, assumed to be 0. 354*4882a593Smuzhiyun */ 355*4882a593Smuzhiyun 356*4882a593Smuzhiyun struct PVSCSISGElement { 357*4882a593Smuzhiyun u64 addr; 358*4882a593Smuzhiyun u32 length; 359*4882a593Smuzhiyun u32 flags; 360*4882a593Smuzhiyun } __packed; 361*4882a593Smuzhiyun 362*4882a593Smuzhiyun /* 363*4882a593Smuzhiyun * Completion descriptor. 364*4882a593Smuzhiyun * 365*4882a593Smuzhiyun * sizeof(RingCmpDesc) = 32 366*4882a593Smuzhiyun * 367*4882a593Smuzhiyun * - context: identifier of the command. The same thing that was specified 368*4882a593Smuzhiyun * under "context" as part of struct RingReqDesc at initiation time, 369*4882a593Smuzhiyun * - dataLen: number of bytes transferred for the actual i/o operation, 370*4882a593Smuzhiyun * - senseLen: number of bytes written into the sense buffer, 371*4882a593Smuzhiyun * - hostStatus: adapter status, 372*4882a593Smuzhiyun * - scsiStatus: device status, 373*4882a593Smuzhiyun * - _pad should be zero. 374*4882a593Smuzhiyun */ 375*4882a593Smuzhiyun 376*4882a593Smuzhiyun struct PVSCSIRingCmpDesc { 377*4882a593Smuzhiyun u64 context; 378*4882a593Smuzhiyun u64 dataLen; 379*4882a593Smuzhiyun u32 senseLen; 380*4882a593Smuzhiyun u16 hostStatus; 381*4882a593Smuzhiyun u16 scsiStatus; 382*4882a593Smuzhiyun u32 _pad[2]; 383*4882a593Smuzhiyun } __packed; 384*4882a593Smuzhiyun 385*4882a593Smuzhiyun struct PVSCSIConfigPageHeader { 386*4882a593Smuzhiyun u32 pageNum; 387*4882a593Smuzhiyun u16 numDwords; 388*4882a593Smuzhiyun u16 hostStatus; 389*4882a593Smuzhiyun u16 scsiStatus; 390*4882a593Smuzhiyun u16 reserved[3]; 391*4882a593Smuzhiyun } __packed; 392*4882a593Smuzhiyun 393*4882a593Smuzhiyun struct PVSCSIConfigPageController { 394*4882a593Smuzhiyun struct PVSCSIConfigPageHeader header; 395*4882a593Smuzhiyun u64 nodeWWN; /* Device name as defined in the SAS spec. */ 396*4882a593Smuzhiyun u16 manufacturer[64]; 397*4882a593Smuzhiyun u16 serialNumber[64]; 398*4882a593Smuzhiyun u16 opromVersion[32]; 399*4882a593Smuzhiyun u16 hwVersion[32]; 400*4882a593Smuzhiyun u16 firmwareVersion[32]; 401*4882a593Smuzhiyun u32 numPhys; 402*4882a593Smuzhiyun u8 useConsecutivePhyWWNs; 403*4882a593Smuzhiyun u8 reserved[3]; 404*4882a593Smuzhiyun } __packed; 405*4882a593Smuzhiyun 406*4882a593Smuzhiyun /* 407*4882a593Smuzhiyun * Interrupt status / IRQ bits. 408*4882a593Smuzhiyun */ 409*4882a593Smuzhiyun 410*4882a593Smuzhiyun #define PVSCSI_INTR_CMPL_0 (1 << 0) 411*4882a593Smuzhiyun #define PVSCSI_INTR_CMPL_1 (1 << 1) 412*4882a593Smuzhiyun #define PVSCSI_INTR_CMPL_MASK MASK(2) 413*4882a593Smuzhiyun 414*4882a593Smuzhiyun #define PVSCSI_INTR_MSG_0 (1 << 2) 415*4882a593Smuzhiyun #define PVSCSI_INTR_MSG_1 (1 << 3) 416*4882a593Smuzhiyun #define PVSCSI_INTR_MSG_MASK (MASK(2) << 2) 417*4882a593Smuzhiyun 418*4882a593Smuzhiyun #define PVSCSI_INTR_ALL_SUPPORTED MASK(4) 419*4882a593Smuzhiyun 420*4882a593Smuzhiyun /* 421*4882a593Smuzhiyun * Number of MSI-X vectors supported. 422*4882a593Smuzhiyun */ 423*4882a593Smuzhiyun #define PVSCSI_MAX_INTRS 24 424*4882a593Smuzhiyun 425*4882a593Smuzhiyun /* 426*4882a593Smuzhiyun * Misc constants for the rings. 427*4882a593Smuzhiyun */ 428*4882a593Smuzhiyun 429*4882a593Smuzhiyun #define PVSCSI_MAX_NUM_PAGES_REQ_RING PVSCSI_SETUP_RINGS_MAX_NUM_PAGES 430*4882a593Smuzhiyun #define PVSCSI_MAX_NUM_PAGES_CMP_RING PVSCSI_SETUP_RINGS_MAX_NUM_PAGES 431*4882a593Smuzhiyun #define PVSCSI_MAX_NUM_PAGES_MSG_RING PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES 432*4882a593Smuzhiyun 433*4882a593Smuzhiyun #define PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE \ 434*4882a593Smuzhiyun (PAGE_SIZE / sizeof(struct PVSCSIRingReqDesc)) 435*4882a593Smuzhiyun 436*4882a593Smuzhiyun #define PVSCSI_MAX_REQ_QUEUE_DEPTH \ 437*4882a593Smuzhiyun (PVSCSI_MAX_NUM_PAGES_REQ_RING * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE) 438*4882a593Smuzhiyun 439*4882a593Smuzhiyun #define PVSCSI_MEM_SPACE_COMMAND_NUM_PAGES 1 440*4882a593Smuzhiyun #define PVSCSI_MEM_SPACE_INTR_STATUS_NUM_PAGES 1 441*4882a593Smuzhiyun #define PVSCSI_MEM_SPACE_MISC_NUM_PAGES 2 442*4882a593Smuzhiyun #define PVSCSI_MEM_SPACE_KICK_IO_NUM_PAGES 2 443*4882a593Smuzhiyun #define PVSCSI_MEM_SPACE_MSIX_NUM_PAGES 2 444*4882a593Smuzhiyun 445*4882a593Smuzhiyun enum PVSCSIMemSpace { 446*4882a593Smuzhiyun PVSCSI_MEM_SPACE_COMMAND_PAGE = 0, 447*4882a593Smuzhiyun PVSCSI_MEM_SPACE_INTR_STATUS_PAGE = 1, 448*4882a593Smuzhiyun PVSCSI_MEM_SPACE_MISC_PAGE = 2, 449*4882a593Smuzhiyun PVSCSI_MEM_SPACE_KICK_IO_PAGE = 4, 450*4882a593Smuzhiyun PVSCSI_MEM_SPACE_MSIX_TABLE_PAGE = 6, 451*4882a593Smuzhiyun PVSCSI_MEM_SPACE_MSIX_PBA_PAGE = 7, 452*4882a593Smuzhiyun }; 453*4882a593Smuzhiyun 454*4882a593Smuzhiyun #define PVSCSI_MEM_SPACE_NUM_PAGES \ 455*4882a593Smuzhiyun (PVSCSI_MEM_SPACE_COMMAND_NUM_PAGES + \ 456*4882a593Smuzhiyun PVSCSI_MEM_SPACE_INTR_STATUS_NUM_PAGES + \ 457*4882a593Smuzhiyun PVSCSI_MEM_SPACE_MISC_NUM_PAGES + \ 458*4882a593Smuzhiyun PVSCSI_MEM_SPACE_KICK_IO_NUM_PAGES + \ 459*4882a593Smuzhiyun PVSCSI_MEM_SPACE_MSIX_NUM_PAGES) 460*4882a593Smuzhiyun 461*4882a593Smuzhiyun #define PVSCSI_MEM_SPACE_SIZE (PVSCSI_MEM_SPACE_NUM_PAGES * PAGE_SIZE) 462*4882a593Smuzhiyun 463*4882a593Smuzhiyun #endif /* _VMW_PVSCSI_H_ */ 464