Linux Audio

Check our new training course

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