diff options
author | Frederic Barrat <fbarrat@linux.vnet.ibm.com> | 2016-03-04 06:26:40 -0500 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2016-03-09 07:40:00 -0500 |
commit | d601ea918b878582e60b773f2f943d8d292b2abf (patch) | |
tree | d2bba34d1bc92b685d21c668c3abbde2c292a464 /drivers/misc/cxl/native.c | |
parent | b40844aa55bb325de7509003c7529c75b0532412 (diff) |
cxl: Support the cxl kernel API from a guest
Like on bare-metal, the cxl driver creates a virtual PHB and a pci
device for the AFU. The configuration space of the device is mapped to
the configuration record of the AFU.
Reuse the code defined in afu_cr_read8|16|32() when reading the
configuration space of the AFU device.
Even though the (virtual) AFU device is a pci device, the adapter is
not. So a driver using the cxl kernel API cannot read the VPD of the
adapter through the usual PCI interface. Therefore, we add a call to
the cxl kernel API:
ssize_t cxl_read_adapter_vpd(struct pci_dev *dev, void *buf, size_t count);
Co-authored-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
Signed-off-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
Reviewed-by: Manoj Kumar <manoj@linux.vnet.ibm.com>
Acked-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'drivers/misc/cxl/native.c')
-rw-r--r-- | drivers/misc/cxl/native.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/drivers/misc/cxl/native.c b/drivers/misc/cxl/native.c index 0e289c22cdec..e564ae657584 100644 --- a/drivers/misc/cxl/native.c +++ b/drivers/misc/cxl/native.c | |||
@@ -1019,6 +1019,52 @@ static int native_afu_cr_read8(struct cxl_afu *afu, int cr, u64 off, u8 *out) | |||
1019 | return rc; | 1019 | return rc; |
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | static int native_afu_cr_write32(struct cxl_afu *afu, int cr, u64 off, u32 in) | ||
1023 | { | ||
1024 | if (unlikely(!cxl_ops->link_ok(afu->adapter))) | ||
1025 | return -EIO; | ||
1026 | if (unlikely(off >= afu->crs_len)) | ||
1027 | return -ERANGE; | ||
1028 | out_le32(afu->native->afu_desc_mmio + afu->crs_offset + | ||
1029 | (cr * afu->crs_len) + off, in); | ||
1030 | return 0; | ||
1031 | } | ||
1032 | |||
1033 | static int native_afu_cr_write16(struct cxl_afu *afu, int cr, u64 off, u16 in) | ||
1034 | { | ||
1035 | u64 aligned_off = off & ~0x3L; | ||
1036 | u32 val32, mask, shift; | ||
1037 | int rc; | ||
1038 | |||
1039 | rc = native_afu_cr_read32(afu, cr, aligned_off, &val32); | ||
1040 | if (rc) | ||
1041 | return rc; | ||
1042 | shift = (off & 0x3) * 8; | ||
1043 | WARN_ON(shift == 24); | ||
1044 | mask = 0xffff << shift; | ||
1045 | val32 = (val32 & ~mask) | (in << shift); | ||
1046 | |||
1047 | rc = native_afu_cr_write32(afu, cr, aligned_off, val32); | ||
1048 | return rc; | ||
1049 | } | ||
1050 | |||
1051 | static int native_afu_cr_write8(struct cxl_afu *afu, int cr, u64 off, u8 in) | ||
1052 | { | ||
1053 | u64 aligned_off = off & ~0x3L; | ||
1054 | u32 val32, mask, shift; | ||
1055 | int rc; | ||
1056 | |||
1057 | rc = native_afu_cr_read32(afu, cr, aligned_off, &val32); | ||
1058 | if (rc) | ||
1059 | return rc; | ||
1060 | shift = (off & 0x3) * 8; | ||
1061 | mask = 0xff << shift; | ||
1062 | val32 = (val32 & ~mask) | (in << shift); | ||
1063 | |||
1064 | rc = native_afu_cr_write32(afu, cr, aligned_off, val32); | ||
1065 | return rc; | ||
1066 | } | ||
1067 | |||
1022 | const struct cxl_backend_ops cxl_native_ops = { | 1068 | const struct cxl_backend_ops cxl_native_ops = { |
1023 | .module = THIS_MODULE, | 1069 | .module = THIS_MODULE, |
1024 | .adapter_reset = cxl_pci_reset, | 1070 | .adapter_reset = cxl_pci_reset, |
@@ -1044,4 +1090,8 @@ const struct cxl_backend_ops cxl_native_ops = { | |||
1044 | .afu_cr_read16 = native_afu_cr_read16, | 1090 | .afu_cr_read16 = native_afu_cr_read16, |
1045 | .afu_cr_read32 = native_afu_cr_read32, | 1091 | .afu_cr_read32 = native_afu_cr_read32, |
1046 | .afu_cr_read64 = native_afu_cr_read64, | 1092 | .afu_cr_read64 = native_afu_cr_read64, |
1093 | .afu_cr_write8 = native_afu_cr_write8, | ||
1094 | .afu_cr_write16 = native_afu_cr_write16, | ||
1095 | .afu_cr_write32 = native_afu_cr_write32, | ||
1096 | .read_adapter_vpd = cxl_pci_read_adapter_vpd, | ||
1047 | }; | 1097 | }; |