Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vmw_pvscsi.h
Go to the documentation of this file.
1 /*
2  * VMware PVSCSI header file
3  *
4  * Copyright (C) 2008-2009, 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 <[email protected]>
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.2.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  */
42  BTSTAT_SUCCESS = 0x00, /* CCB complete normally with no errors */
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  */
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 
102 };
103 
104 /*
105  * Virtual h/w commands.
106  */
107 
109  PVSCSI_CMD_FIRST = 0, /* has to be first */
110 
120 
121  PVSCSI_CMD_LAST = 10 /* has to be last */
122 };
123 
124 /*
125  * Command descriptor for PVSCSI_CMD_RESET_DEVICE --
126  */
127 
130  u8 lun[8];
131 } __packed;
132 
133 /*
134  * Command descriptor for PVSCSI_CMD_CONFIG --
135  */
136 
142 } __packed;
143 
148 };
149 
154 };
155 
156 /*
157  * Command descriptor for PVSCSI_CMD_ABORT_CMD --
158  *
159  * - currently does not support specifying the LUN.
160  * - _pad should be 0.
161  */
162 
167 } __packed;
168 
169 /*
170  * Command descriptor for PVSCSI_CMD_SETUP_RINGS --
171  *
172  * Notes:
173  * - reqRingNumPages and cmpRingNumPages need to be power of two.
174  * - reqRingNumPages and cmpRingNumPages need to be different from 0,
175  * - reqRingNumPages and cmpRingNumPages need to be inferior to
176  * PVSCSI_SETUP_RINGS_MAX_NUM_PAGES.
177  */
178 
179 #define PVSCSI_SETUP_RINGS_MAX_NUM_PAGES 32
186 } __packed;
187 
188 /*
189  * Command descriptor for PVSCSI_CMD_SETUP_MSG_RING --
190  *
191  * Notes:
192  * - this command was not supported in the initial revision of the h/w
193  * interface. Before using it, you need to check that it is supported by
194  * writing PVSCSI_CMD_SETUP_MSG_RING to the 'command' register, then
195  * immediately after read the 'command status' register:
196  * * a value of -1 means that the cmd is NOT supported,
197  * * a value != -1 means that the cmd IS supported.
198  * If it's supported the 'command status' register should return:
199  * sizeof(PVSCSICmdDescSetupMsgRing) / sizeof(u32).
200  * - this command should be issued _after_ the usual SETUP_RINGS so that the
201  * RingsState page is already setup. If not, the command is a nop.
202  * - numPages needs to be a power of two,
203  * - numPages needs to be different from 0,
204  * - _pad should be zero.
205  */
206 
207 #define PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES 16
208 
213 } __packed;
214 
219 };
220 
221 /*
222  * Msg descriptor.
223  *
224  * sizeof(struct PVSCSIRingMsgDesc) == 128.
225  *
226  * - type is of type enum PVSCSIMsgType.
227  * - the content of args depend on the type of event being delivered.
228  */
229 
232  u32 args[31];
233 } __packed;
234 
236  u32 type; /* PVSCSI_MSG_DEV _ADDED / _REMOVED */
239  u8 lun[8];
240  u32 pad[27];
241 } __packed;
242 
243 /*
244  * Rings state.
245  *
246  * - the fields:
247  * . msgProdIdx,
248  * . msgConsIdx,
249  * . msgNumEntriesLog2,
250  * .. are only used once the SETUP_MSG_RING cmd has been issued.
251  * - '_pad' helps to ensure that the msg related fields are on their own
252  * cache-line.
253  */
254 
259 
263 
264  u8 _pad[104];
265 
269 } __packed;
270 
271 /*
272  * Request descriptor.
273  *
274  * sizeof(RingReqDesc) = 128
275  *
276  * - context: is a unique identifier of a command. It could normally be any
277  * 64bit value, however we currently store it in the serialNumber variable
278  * of struct SCSI_Command, so we have the following restrictions due to the
279  * way this field is handled in the vmkernel storage stack:
280  * * this value can't be 0,
281  * * the upper 32bit need to be 0 since serialNumber is as a u32.
282  * Currently tracked as PR 292060.
283  * - dataLen: contains the total number of bytes that need to be transferred.
284  * - dataAddr:
285  * * if PVSCSI_FLAG_CMD_WITH_SG_LIST is set: dataAddr is the PA of the first
286  * s/g table segment, each s/g segment is entirely contained on a single
287  * page of physical memory,
288  * * if PVSCSI_FLAG_CMD_WITH_SG_LIST is NOT set, then dataAddr is the PA of
289  * the buffer used for the DMA transfer,
290  * - flags:
291  * * PVSCSI_FLAG_CMD_WITH_SG_LIST: see dataAddr above,
292  * * PVSCSI_FLAG_CMD_DIR_NONE: no DMA involved,
293  * * PVSCSI_FLAG_CMD_DIR_TOHOST: transfer from device to main memory,
294  * * PVSCSI_FLAG_CMD_DIR_TODEVICE: transfer from main memory to device,
295  * * PVSCSI_FLAG_CMD_OUT_OF_BAND_CDB: reserved to handle CDBs larger than
296  * 16bytes. To be specified.
297  * - vcpuHint: vcpuId of the processor that will be most likely waiting for the
298  * completion of the i/o. For guest OSes that use lowest priority message
299  * delivery mode (such as windows), we use this "hint" to deliver the
300  * completion action to the proper vcpu. For now, we can use the vcpuId of
301  * the processor that initiated the i/o as a likely candidate for the vcpu
302  * that will be waiting for the completion..
303  * - bus should be 0: we currently only support bus 0 for now.
304  * - unused should be zero'd.
305  */
306 
307 #define PVSCSI_FLAG_CMD_WITH_SG_LIST (1 << 0)
308 #define PVSCSI_FLAG_CMD_OUT_OF_BAND_CDB (1 << 1)
309 #define PVSCSI_FLAG_CMD_DIR_NONE (1 << 2)
310 #define PVSCSI_FLAG_CMD_DIR_TOHOST (1 << 3)
311 #define PVSCSI_FLAG_CMD_DIR_TODEVICE (1 << 4)
312 
320  u8 cdb[16];
322  u8 lun[8];
327  u8 unused[59];
328 } __packed;
329 
330 /*
331  * Scatter-gather list management.
332  *
333  * As described above, when PVSCSI_FLAG_CMD_WITH_SG_LIST is set in the
334  * RingReqDesc.flags, then RingReqDesc.dataAddr is the PA of the first s/g
335  * table segment.
336  *
337  * - each segment of the s/g table contain a succession of struct
338  * PVSCSISGElement.
339  * - each segment is entirely contained on a single physical page of memory.
340  * - a "chain" s/g element has the flag PVSCSI_SGE_FLAG_CHAIN_ELEMENT set in
341  * PVSCSISGElement.flags and in this case:
342  * * addr is the PA of the next s/g segment,
343  * * length is undefined, assumed to be 0.
344  */
345 
350 } __packed;
351 
352 /*
353  * Completion descriptor.
354  *
355  * sizeof(RingCmpDesc) = 32
356  *
357  * - context: identifier of the command. The same thing that was specified
358  * under "context" as part of struct RingReqDesc at initiation time,
359  * - dataLen: number of bytes transferred for the actual i/o operation,
360  * - senseLen: number of bytes written into the sense buffer,
361  * - hostStatus: adapter status,
362  * - scsiStatus: device status,
363  * - _pad should be zero.
364  */
365 
372  u32 _pad[2];
373 } __packed;
374 
381 } __packed;
382 
385  u64 nodeWWN; /* Device name as defined in the SAS spec. */
394 } __packed;
395 
396 /*
397  * Interrupt status / IRQ bits.
398  */
399 
400 #define PVSCSI_INTR_CMPL_0 (1 << 0)
401 #define PVSCSI_INTR_CMPL_1 (1 << 1)
402 #define PVSCSI_INTR_CMPL_MASK MASK(2)
403 
404 #define PVSCSI_INTR_MSG_0 (1 << 2)
405 #define PVSCSI_INTR_MSG_1 (1 << 3)
406 #define PVSCSI_INTR_MSG_MASK (MASK(2) << 2)
407 
408 #define PVSCSI_INTR_ALL_SUPPORTED MASK(4)
409 
410 /*
411  * Number of MSI-X vectors supported.
412  */
413 #define PVSCSI_MAX_INTRS 24
414 
415 /*
416  * Enumeration of supported MSI-X vectors
417  */
418 #define PVSCSI_VECTOR_COMPLETION 0
419 
420 /*
421  * Misc constants for the rings.
422  */
423 
424 #define PVSCSI_MAX_NUM_PAGES_REQ_RING PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
425 #define PVSCSI_MAX_NUM_PAGES_CMP_RING PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
426 #define PVSCSI_MAX_NUM_PAGES_MSG_RING PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES
427 
428 #define PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE \
429  (PAGE_SIZE / sizeof(struct PVSCSIRingReqDesc))
430 
431 #define PVSCSI_MAX_REQ_QUEUE_DEPTH \
432  (PVSCSI_MAX_NUM_PAGES_REQ_RING * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE)
433 
434 #define PVSCSI_MEM_SPACE_COMMAND_NUM_PAGES 1
435 #define PVSCSI_MEM_SPACE_INTR_STATUS_NUM_PAGES 1
436 #define PVSCSI_MEM_SPACE_MISC_NUM_PAGES 2
437 #define PVSCSI_MEM_SPACE_KICK_IO_NUM_PAGES 2
438 #define PVSCSI_MEM_SPACE_MSIX_NUM_PAGES 2
439 
447 };
448 
449 #define PVSCSI_MEM_SPACE_NUM_PAGES \
450  (PVSCSI_MEM_SPACE_COMMAND_NUM_PAGES + \
451  PVSCSI_MEM_SPACE_INTR_STATUS_NUM_PAGES + \
452  PVSCSI_MEM_SPACE_MISC_NUM_PAGES + \
453  PVSCSI_MEM_SPACE_KICK_IO_NUM_PAGES + \
454  PVSCSI_MEM_SPACE_MSIX_NUM_PAGES)
455 
456 #define PVSCSI_MEM_SPACE_SIZE (PVSCSI_MEM_SPACE_NUM_PAGES * PAGE_SIZE)
457 
458 #endif /* _VMW_PVSCSI_H_ */