Add the pvscsi driver to the tree.

This driver allows to usage of the paravirt SCSI controller
in VMware products like ESXi.  The pvscsi driver provides a
substantial performance improvement in block devices versus
the emulated mpt and mps SCSI/SAS controllers.

Error handling in this driver has not been extensively tested
yet.

Submitted by:	vbhakta@vmware.com
Relnotes:	yes
Sponsored by:	VMware, Panzura
Differential Revision:	D18613
This commit is contained in:
Josh Paetzel 2019-11-14 23:31:20 +00:00
parent 4694d573b4
commit 052e12a508
10 changed files with 2159 additions and 1 deletions

74
share/man/man4/pvscsi.4 Normal file
View File

@ -0,0 +1,74 @@
.\" Copyright (c) 2018 VMware, Inc.
.\"
.\" SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0)
.\"
.\" $FreeBSD$
.Dd December 5, 2018
.Dt PVSCSI 4
.Os
.Sh NAME
.Nm pvscsi
.Nd VMware Paravirtual SCSI Controller
.Sh SYNOPSIS
To compile this driver into the kernel,
place the following line in your
kernel configuration file:
.Bd -ragged -offset indent
.Cd "device pci"
.Cd "device scbus"
.Cd "device pvscsi"
.Ed
.Pp
Alternatively, to load the driver as a
module at boot time, place the following line in
.Xr loader.conf 5 :
.Bd -literal -offset indent
pvscsi_load="YES"
.Ed
.Pp
The following tunables are settable from the
.Xr loader 8 :
.Bl -ohang
.It Va hw.pvscsi.request_ring_pages
controls how many pages are allocated for the device request ring.
A non-positive value will cause the driver to choose the value based on device
capabilities.
A non-zero value will use that many number of pages up to a maximum of 32.
The default setting is 0.
.It Va hw.pvscsi.max_queue_depth
controls the queue size for the adapter.
A non-positive value will cause the driver to choose the value based on number
of request ring pages.
A non-zero value will set the queue size up to a maximum allowed by the number
of request ring pages.
Default is 0.
.It Va hw.pvscsi.use_msg
setting to nonzero value enables the use of the PVSCSI message queue allowing
for disk hot-add and remove without manual rescan needed.
Default is 1.
.It Va hw.pvscsi.use_msi
setting to nonzero value enables the use of MSI interrupts.
Default is 1.
.It Va hw.pvscsi.use_msix
setting to nonzero value enables the use of MSI-X interrupts.
Default is 1.
.It Va hw.pvscsi.use_req_call_threshold
setting to nonzero value enables the request call threshold functionality.
TODO.
Default is 1.
.El
.Sh DESCRIPTION
The
.Nm
driver provides support for the VMware Paravirtual SCSI Controller (PVSCSI) in
virtual machines by VMware.
.Sh SEE ALSO
.Xr cam 4 ,
.Xr da 4
.Sh HISTORY
The
.Nm
driver first appeared in
.Fx 13.0 .
.Sh AUTHORS
.An Vishal Bhakta Aq Mt vbhakta@vmware.com .

View File

@ -152,6 +152,7 @@ device sym # NCR/Symbios Logic
device trm # Tekram DC395U/UW/F DC315U adapters
device isci # Intel C600 SAS controller
device ocs_fc # Emulex FC adapters
device pvscsi # VMware PVSCSI
# ATA/SCSI peripherals
device scbus # SCSI bus (required for ATA/SCSI)

View File

@ -345,6 +345,7 @@ dev/vmware/vmci/vmci_kernel_if.c optional vmci
dev/vmware/vmci/vmci_qpair.c optional vmci
dev/vmware/vmci/vmci_queue_pair.c optional vmci
dev/vmware/vmci/vmci_resource.c optional vmci
dev/vmware/pvscsi/pvscsi.c optional pvscsi
dev/vmd/vmd.c optional vmd
dev/vmd/vmd_bus.c optional vmd_bus
dev/wbwd/wbwd.c optional wbwd

View File

@ -162,6 +162,7 @@ dev/vmware/vmci/vmci_kernel_if.c optional vmci
dev/vmware/vmci/vmci_qpair.c optional vmci
dev/vmware/vmci/vmci_queue_pair.c optional vmci
dev/vmware/vmci/vmci_resource.c optional vmci
dev/vmware/pvscsi/pvscsi.c optional pvscsi
dev/acpi_support/acpi_wmi_if.m standard
dev/wbwd/wbwd.c optional wbwd
i386/acpica/acpi_machdep.c optional acpi

View File

@ -0,0 +1,51 @@
$FreeBSD$
These files are provided under a dual BSD-2 Clause/GPLv2 license. When
using or redistributing this file, you may do so under either license.
BSD-2 Clause License
Copyright (c) 2018 VMware, Inc.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
GPL License Summary
Copyright (c) 2018 VMware, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution
in the file called LICENSE.GPL.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,215 @@
/*-
* Copyright (c) 2018 VMware, Inc.
*
* SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0)
*
* $FreeBSD$
*/
#ifndef _PVSCSI_H_
#define _PVSCSI_H_
#define MASK(v) ((1 << (v)) - 1)
#define PCI_VENDOR_ID_VMWARE 0x15ad
#define PCI_DEVICE_ID_VMWARE_PVSCSI 0x07c0
enum pvscsi_reg_offset {
PVSCSI_REG_OFFSET_COMMAND = 0x0000,
PVSCSI_REG_OFFSET_COMMAND_DATA = 0x0004,
PVSCSI_REG_OFFSET_COMMAND_STATUS = 0x0008,
PVSCSI_REG_OFFSET_LAST_STS_0 = 0x0100,
PVSCSI_REG_OFFSET_LAST_STS_1 = 0x0104,
PVSCSI_REG_OFFSET_LAST_STS_2 = 0x0108,
PVSCSI_REG_OFFSET_LAST_STS_3 = 0x010c,
PVSCSI_REG_OFFSET_INTR_STATUS = 0x100c,
PVSCSI_REG_OFFSET_INTR_MASK = 0x2010,
PVSCSI_REG_OFFSET_KICK_NON_RW_IO = 0x3014,
PVSCSI_REG_OFFSET_DEBUG = 0x3018,
PVSCSI_REG_OFFSET_KICK_RW_IO = 0x4018,
};
enum pvscsi_commands {
PVSCSI_CMD_FIRST = 0,
PVSCSI_CMD_ADAPTER_RESET = 1,
PVSCSI_CMD_ISSUE_SCSI = 2,
PVSCSI_CMD_SETUP_RINGS = 3,
PVSCSI_CMD_RESET_BUS = 4,
PVSCSI_CMD_RESET_DEVICE = 5,
PVSCSI_CMD_ABORT_CMD = 6,
PVSCSI_CMD_CONFIG = 7,
PVSCSI_CMD_SETUP_MSG_RING = 8,
PVSCSI_CMD_DEVICE_UNPLUG = 9,
PVSCSI_CMD_SETUP_REQCALLTHRESHOLD = 10,
PVSCSI_CMD_GET_MAX_TARGETS = 11,
PVSCSI_CMD_LAST = 12,
};
struct pvscsi_cmd_desc_reset_device {
uint32_t target;
uint8_t lun[8];
};
struct pvscsi_cmd_desc_abort_cmd {
uint64_t context;
uint32_t target;
uint32_t pad;
};
#define PVSCSI_SETUP_RINGS_MAX_NUM_PAGES 32
#define PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES 16
struct pvscsi_cmd_desc_setup_rings {
uint32_t req_ring_num_pages;
uint32_t cmp_ring_num_pages;
uint64_t rings_state_ppn;
uint64_t req_ring_ppns[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES];
uint64_t cmp_ring_ppns[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES];
};
struct pvscsi_cmd_desc_setup_msg_ring {
uint32_t num_pages;
uint32_t pad_;
uint64_t ring_ppns[PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES];
};
struct pvscsi_rings_state {
uint32_t req_prod_idx;
uint32_t req_cons_idx;
uint32_t req_num_entries_log2;
uint32_t cmp_prod_idx;
uint32_t cmp_cons_idx;
uint32_t cmp_num_entries_log2;
uint32_t req_call_threshold;
uint8_t _pad[100];
uint32_t msg_prod_idx;
uint32_t msg_cons_idx;
uint32_t msg_num_entries_log2;
};
#define PVSCSI_FLAG_CMD_WITH_SG_LIST (1 << 0)
#define PVSCSI_FLAG_CMD_OUT_OF_BAND_CDB (1 << 1)
#define PVSCSI_FLAG_CMD_DIR_NONE (1 << 2)
#define PVSCSI_FLAG_CMD_DIR_TOHOST (1 << 3)
#define PVSCSI_FLAG_CMD_DIR_TODEVICE (1 << 4)
#define PVSCSI_FLAG_RESERVED_MASK (~MASK(5))
#define PVSCSI_INTR_CMPL_0 (1 << 0)
#define PVSCSI_INTR_CMPL_1 (1 << 1)
#define PVSCSI_INTR_CMPL_MASK MASK(2)
#define PVSCSI_INTR_MSG_0 (1 << 2)
#define PVSCSI_INTR_MSG_1 (1 << 3)
#define PVSCSI_INTR_MSG_MASK (MASK(2) << 2)
#define PVSCSI_INTR_ALL_SUPPORTED MASK(4)
struct pvscsi_ring_req_desc {
uint64_t context;
uint64_t data_addr;
uint64_t data_len;
uint64_t sense_addr;
uint32_t sense_len;
uint32_t flags;
uint8_t cdb[16];
uint8_t cdb_len;
uint8_t lun[8];
uint8_t tag;
uint8_t bus;
uint8_t target;
uint8_t vcpu_hint;
uint8_t unused[59];
};
struct pvscsi_ring_cmp_desc {
uint64_t context;
uint64_t data_len;
uint32_t sense_len;
uint16_t host_status;
uint16_t scsi_status;
uint32_t _pad[2];
};
#define PVSCSI_MAX_SG_ENTRIES_PER_SEGMENT 128
#define PVSCSI_MAX_NUM_SG_SEGMENTS 128
#define PVSCSI_SGE_FLAG_CHAIN_ELEMENT (1 << 0)
struct pvscsi_sg_element {
uint64_t addr;
uint32_t length;
uint32_t flags;
};
enum pvscsi_msg_type {
PVSCSI_MSG_DEV_ADDED = 0,
PVSCSI_MSG_DEV_REMOVED = 1,
PVSCSI_MSG_LAST = 2,
};
struct pvscsi_ring_msg_desc {
uint32_t type;
uint32_t args[31];
};
struct pvscsi_ring_msg_dev_status_changed {
uint32_t type;
uint32_t bus;
uint32_t target;
uint8_t lun[8];
uint32_t pad[27];
};
struct pvscsi_cmd_desc_setup_req_call {
uint32_t enable;
};
#define PVSCSI_MAX_NUM_PAGES_REQ_RING PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
#define PVSCSI_MAX_NUM_PAGES_CMP_RING PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
#define PVSCSI_MAX_NUM_PAGES_MSG_RING PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES
#define PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE \
(PAGE_SIZE / sizeof(struct pvscsi_ring_req_desc))
#define PVSCSI_MAX_NUM_CMP_ENTRIES_PER_PAGE \
(PAGE_SIZE / sizeof(struct pvscs_ring_cmp_desc))
#define PVSCSI_MAX_NUM_MSG_ENTRIES_PER_PAGE \
(PAGE_SIZE / sizeof(struct pvscsi_ring_msg_desc))
#define PVSCSI_MAX_REQ_QUEUE_DEPTH \
(PVSCSI_MAX_NUM_PAGES_REQ_RING * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE)
#define PVSCSI_MAX_CMP_QUEUE_DEPTH \
(PVSCSI_MAX_NUM_PAGES_CMP_RING * PVSCSI_MAX_NUM_CMP_ENTRIES_PER_PAGE)
#define PVSCSI_MAX_QUEUE_DEPTH \
MAX(PVSCSI_MAX_REQ_QUEUE_DEPTH, PVSCSI_MAX_CMP_QUEUE_DEPTH)
enum pvscsi_host_status {
BTSTAT_SUCCESS = 0x00,
BTSTAT_LINKED_COMMAND_COMPLETED = 0x0a,
BTSTAT_LINKED_COMMAND_COMPLETED_WITH_FLAG = 0x0b,
BTSTAT_DATA_UNDERRUN = 0x0c,
BTSTAT_SELTIMEO = 0x11,
BTSTAT_DATARUN = 0x12,
BTSTAT_BUSFREE = 0x13,
BTSTAT_INVPHASE = 0x14,
BTSTAT_INVCODE = 0x15,
BTSTAT_INVOPCODE = 0x16,
BTSTAT_LUNMISMATCH = 0x17,
BTSTAT_INVPARAM = 0x1a,
BTSTAT_SENSFAILED = 0x1b,
BTSTAT_TAGREJECT = 0x1c,
BTSTAT_BADMSG = 0x1d,
BTSTAT_HAHARDWARE = 0x20,
BTSTAT_NORESPONSE = 0x21,
BTSTAT_SENTRST = 0x22,
BTSTAT_RECVRST = 0x23,
BTSTAT_DISCONNECT = 0x24,
BTSTAT_BUSRESET = 0x25,
BTSTAT_ABORTQUEUE = 0x26,
BTSTAT_HASOFTWARE = 0x27,
BTSTAT_HATIMEOUT = 0x30,
BTSTAT_SCSIPARITY = 0x34,
};
#endif /* !_PVSCSI_H_ */

View File

@ -138,6 +138,7 @@ device mpr # LSI-Logic MPT-Fusion 3
device sym # NCR/Symbios Logic
device trm # Tekram DC395U/UW/F DC315U adapters
device isci # Intel C600 SAS controller
device pvscsi # VMware PVSCSI
# ATA/SCSI peripherals
device scbus # SCSI bus (required for ATA/SCSI)

View File

@ -23,6 +23,6 @@
# SUCH DAMAGE.
#
SUBDIR= vmci vmxnet3
SUBDIR= pvscsi vmci vmxnet3
.include <bsd.subdir.mk>

View File

@ -0,0 +1,10 @@
# $FreeBSD$
.PATH: ${SRCTOP}/sys/dev/vmware/pvscsi
KMOD= pvscsi
SRCS= pvscsi.c
SRCS+= device_if.h bus_if.h pci_if.h
SRCS+= opt_cam.h
.include <bsd.kmod.mk>