Commit 348dd93e authored by Haiyang Zhang's avatar Haiyang Zhang Committed by David S. Miller

PCI: hv: Add a Hyper-V PCI interface driver for software backchannel interface

This interface driver is a helper driver allows other drivers to
have a common interface with the Hyper-V PCI frontend driver.
Signed-off-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e5d2f910
...@@ -7469,6 +7469,7 @@ F: drivers/hid/hid-hyperv.c ...@@ -7469,6 +7469,7 @@ F: drivers/hid/hid-hyperv.c
F: drivers/hv/ F: drivers/hv/
F: drivers/input/serio/hyperv-keyboard.c F: drivers/input/serio/hyperv-keyboard.c
F: drivers/pci/controller/pci-hyperv.c F: drivers/pci/controller/pci-hyperv.c
F: drivers/pci/controller/pci-hyperv-intf.c
F: drivers/net/hyperv/ F: drivers/net/hyperv/
F: drivers/scsi/storvsc_drv.c F: drivers/scsi/storvsc_drv.c
F: drivers/uio/uio_hv_generic.c F: drivers/uio/uio_hv_generic.c
......
...@@ -182,6 +182,7 @@ config PCI_LABEL ...@@ -182,6 +182,7 @@ config PCI_LABEL
config PCI_HYPERV config PCI_HYPERV
tristate "Hyper-V PCI Frontend" tristate "Hyper-V PCI Frontend"
depends on X86 && HYPERV && PCI_MSI && PCI_MSI_IRQ_DOMAIN && X86_64 depends on X86 && HYPERV && PCI_MSI && PCI_MSI_IRQ_DOMAIN && X86_64
select PCI_HYPERV_INTERFACE
help help
The PCI device frontend driver allows the kernel to import arbitrary The PCI device frontend driver allows the kernel to import arbitrary
PCI devices from a PCI backend to support PCI driver domains. PCI devices from a PCI backend to support PCI driver domains.
......
...@@ -281,5 +281,12 @@ config VMD ...@@ -281,5 +281,12 @@ config VMD
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called vmd. module will be called vmd.
config PCI_HYPERV_INTERFACE
tristate "Hyper-V PCI Interface"
depends on X86 && HYPERV && PCI_MSI && PCI_MSI_IRQ_DOMAIN && X86_64
help
The Hyper-V PCI Interface is a helper driver allows other drivers to
have a common interface with the Hyper-V PCI frontend driver.
source "drivers/pci/controller/dwc/Kconfig" source "drivers/pci/controller/dwc/Kconfig"
endmenu endmenu
...@@ -4,6 +4,7 @@ obj-$(CONFIG_PCIE_CADENCE_HOST) += pcie-cadence-host.o ...@@ -4,6 +4,7 @@ obj-$(CONFIG_PCIE_CADENCE_HOST) += pcie-cadence-host.o
obj-$(CONFIG_PCIE_CADENCE_EP) += pcie-cadence-ep.o obj-$(CONFIG_PCIE_CADENCE_EP) += pcie-cadence-ep.o
obj-$(CONFIG_PCI_FTPCI100) += pci-ftpci100.o obj-$(CONFIG_PCI_FTPCI100) += pci-ftpci100.o
obj-$(CONFIG_PCI_HYPERV) += pci-hyperv.o obj-$(CONFIG_PCI_HYPERV) += pci-hyperv.o
obj-$(CONFIG_PCI_HYPERV_INTERFACE) += pci-hyperv-intf.o
obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o
obj-$(CONFIG_PCI_AARDVARK) += pci-aardvark.o obj-$(CONFIG_PCI_AARDVARK) += pci-aardvark.o
obj-$(CONFIG_PCI_TEGRA) += pci-tegra.o obj-$(CONFIG_PCI_TEGRA) += pci-tegra.o
......
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) Microsoft Corporation.
*
* Author:
* Haiyang Zhang <haiyangz@microsoft.com>
*
* This small module is a helper driver allows other drivers to
* have a common interface with the Hyper-V PCI frontend driver.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/hyperv.h>
struct hyperv_pci_block_ops hvpci_block_ops;
EXPORT_SYMBOL_GPL(hvpci_block_ops);
int hyperv_read_cfg_blk(struct pci_dev *dev, void *buf, unsigned int buf_len,
unsigned int block_id, unsigned int *bytes_returned)
{
if (!hvpci_block_ops.read_block)
return -EOPNOTSUPP;
return hvpci_block_ops.read_block(dev, buf, buf_len, block_id,
bytes_returned);
}
EXPORT_SYMBOL_GPL(hyperv_read_cfg_blk);
int hyperv_write_cfg_blk(struct pci_dev *dev, void *buf, unsigned int len,
unsigned int block_id)
{
if (!hvpci_block_ops.write_block)
return -EOPNOTSUPP;
return hvpci_block_ops.write_block(dev, buf, len, block_id);
}
EXPORT_SYMBOL_GPL(hyperv_write_cfg_blk);
int hyperv_reg_block_invalidate(struct pci_dev *dev, void *context,
void (*block_invalidate)(void *context,
u64 block_mask))
{
if (!hvpci_block_ops.reg_blk_invalidate)
return -EOPNOTSUPP;
return hvpci_block_ops.reg_blk_invalidate(dev, context,
block_invalidate);
}
EXPORT_SYMBOL_GPL(hyperv_reg_block_invalidate);
static void __exit exit_hv_pci_intf(void)
{
}
static int __init init_hv_pci_intf(void)
{
return 0;
}
module_init(init_hv_pci_intf);
module_exit(exit_hv_pci_intf);
MODULE_DESCRIPTION("Hyper-V PCI Interface");
MODULE_LICENSE("GPL v2");
...@@ -983,7 +983,6 @@ int hv_read_config_block(struct pci_dev *pdev, void *buf, unsigned int len, ...@@ -983,7 +983,6 @@ int hv_read_config_block(struct pci_dev *pdev, void *buf, unsigned int len,
*bytes_returned = comp_pkt.bytes_returned; *bytes_returned = comp_pkt.bytes_returned;
return 0; return 0;
} }
EXPORT_SYMBOL(hv_read_config_block);
/** /**
* hv_pci_write_config_compl() - Invoked when a response packet for a write * hv_pci_write_config_compl() - Invoked when a response packet for a write
...@@ -1070,7 +1069,6 @@ int hv_write_config_block(struct pci_dev *pdev, void *buf, unsigned int len, ...@@ -1070,7 +1069,6 @@ int hv_write_config_block(struct pci_dev *pdev, void *buf, unsigned int len,
return 0; return 0;
} }
EXPORT_SYMBOL(hv_write_config_block);
/** /**
* hv_register_block_invalidate() - Invoked when a config block invalidation * hv_register_block_invalidate() - Invoked when a config block invalidation
...@@ -1101,7 +1099,6 @@ int hv_register_block_invalidate(struct pci_dev *pdev, void *context, ...@@ -1101,7 +1099,6 @@ int hv_register_block_invalidate(struct pci_dev *pdev, void *context,
return 0; return 0;
} }
EXPORT_SYMBOL(hv_register_block_invalidate);
/* Interrupt management hooks */ /* Interrupt management hooks */
static void hv_int_desc_free(struct hv_pci_dev *hpdev, static void hv_int_desc_free(struct hv_pci_dev *hpdev,
...@@ -3045,10 +3042,19 @@ static struct hv_driver hv_pci_drv = { ...@@ -3045,10 +3042,19 @@ static struct hv_driver hv_pci_drv = {
static void __exit exit_hv_pci_drv(void) static void __exit exit_hv_pci_drv(void)
{ {
vmbus_driver_unregister(&hv_pci_drv); vmbus_driver_unregister(&hv_pci_drv);
hvpci_block_ops.read_block = NULL;
hvpci_block_ops.write_block = NULL;
hvpci_block_ops.reg_blk_invalidate = NULL;
} }
static int __init init_hv_pci_drv(void) static int __init init_hv_pci_drv(void)
{ {
/* Initialize PCI block r/w interface */
hvpci_block_ops.read_block = hv_read_config_block;
hvpci_block_ops.write_block = hv_write_config_block;
hvpci_block_ops.reg_blk_invalidate = hv_register_block_invalidate;
return vmbus_driver_register(&hv_pci_drv); return vmbus_driver_register(&hv_pci_drv);
} }
......
...@@ -1579,18 +1579,32 @@ hv_pkt_iter_next(struct vmbus_channel *channel, ...@@ -1579,18 +1579,32 @@ hv_pkt_iter_next(struct vmbus_channel *channel,
pkt = hv_pkt_iter_next(channel, pkt)) pkt = hv_pkt_iter_next(channel, pkt))
/* /*
* Functions for passing data between SR-IOV PF and VF drivers. The VF driver * Interface for passing data between SR-IOV PF and VF drivers. The VF driver
* sends requests to read and write blocks. Each block must be 128 bytes or * sends requests to read and write blocks. Each block must be 128 bytes or
* smaller. Optionally, the VF driver can register a callback function which * smaller. Optionally, the VF driver can register a callback function which
* will be invoked when the host says that one or more of the first 64 block * will be invoked when the host says that one or more of the first 64 block
* IDs is "invalid" which means that the VF driver should reread them. * IDs is "invalid" which means that the VF driver should reread them.
*/ */
#define HV_CONFIG_BLOCK_SIZE_MAX 128 #define HV_CONFIG_BLOCK_SIZE_MAX 128
int hv_read_config_block(struct pci_dev *dev, void *buf, unsigned int buf_len,
unsigned int block_id, unsigned int *bytes_returned); int hyperv_read_cfg_blk(struct pci_dev *dev, void *buf, unsigned int buf_len,
int hv_write_config_block(struct pci_dev *dev, void *buf, unsigned int len, unsigned int block_id, unsigned int *bytes_returned);
unsigned int block_id); int hyperv_write_cfg_blk(struct pci_dev *dev, void *buf, unsigned int len,
int hv_register_block_invalidate(struct pci_dev *dev, void *context, unsigned int block_id);
void (*block_invalidate)(void *context, int hyperv_reg_block_invalidate(struct pci_dev *dev, void *context,
u64 block_mask)); void (*block_invalidate)(void *context,
u64 block_mask));
struct hyperv_pci_block_ops {
int (*read_block)(struct pci_dev *dev, void *buf, unsigned int buf_len,
unsigned int block_id, unsigned int *bytes_returned);
int (*write_block)(struct pci_dev *dev, void *buf, unsigned int len,
unsigned int block_id);
int (*reg_blk_invalidate)(struct pci_dev *dev, void *context,
void (*block_invalidate)(void *context,
u64 block_mask));
};
extern struct hyperv_pci_block_ops hvpci_block_ops;
#endif /* _HYPERV_H */ #endif /* _HYPERV_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment