cxl: Add AFU virtual PHB and in kernel API
Subsystems (3)
v3 cover cxl: Add AFU virtual PHB and in kernel API
This patch series adds the ability to present AFUs as PCI devices on a virtual PHB.
It also adds an in kernel API (to the existing userspace API) so AFU drivers can be written as kernel drivers.
This series is dependant on Daniel DMA set mask and MSI PCI controller ops patch series.
v3:
Cleans up device disable and adds a new API call. Details:
- Added pci_disable_device() hook to powerpc.
- Added cxl pci_disable_device() to PCI controller ops.
- Added cxl_fops_get_context() API call for cxlflash team.
- Fixed error path on probe().
- Removed a verbose print from cxl_remove().
v2:
- Address comments from Ian
o Rename some functions now they are global
o Rework context lifetime
o Merge and fix SR calculation
o Added ACKs from Ian
o correct from Ian on one patch
- Fixed powernv pci shutdown hook
Mikey
PATCH v3 1/24 powerpc/copro: Fix faulting kernel segments
This fixes calculating the key bits (KP and KS) in the SLB VSID for kernel mappings.
I'm not CCing this to stable as there are no uses of this currently.
--- arch/powerpc/mm/copro_fault.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/powerpc/mm/copro_fault.c +5 -2
@@ -100,7 +100,7 @@ EXPORT_SYMBOL_GPL(copro_handle_mm_fault);int copro_calculate_slb (struct mm_struct *mm,u64 ea,struct copro_slb *slb) { -u64 vsid; +u64 vsid, vsidkey;int psize, ssize;switch (REGION_ID (ea)) {
@@ -109,6 +109,7 @@ int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb) psize =get_slice_psize (mm, ea); ssize =user_segment_size (ea); vsid =get_vsid (mm->context.id, ea, ssize); + vsidkey =SLB_VSID_USER ;break ;case VMALLOC_REGION_ID :pr_devel ("%s: 0x%llx -- VMALLOC_REGION_ID\n" , __func__, ea);
@@ -118,19 +119,21 @@ int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb) psize = mmu_io_psize; ssize = mmu_kernel_ssize; vsid =get_kernel_vsid (ea, mmu_kernel_ssize); + vsidkey =SLB_VSID_KERNEL ;break ;case KERNEL_REGION_ID :pr_devel ("%s: 0x%llx -- KERNEL_REGION_ID\n" , __func__, ea); psize = mmu_linear_psize; ssize = mmu_kernel_ssize; vsid =get_kernel_vsid (ea, mmu_kernel_ssize); + vsidkey =SLB_VSID_KERNEL ;break ;default :pr_debug ("%s: invalid region access at %016llx\n" , __func__, ea);return 1 ; } - vsid = (vsid <<slb_vsid_shift (ssize)) |SLB_VSID_USER ; + vsid = (vsid <<slb_vsid_shift (ssize)) | vsidkey; vsid |= mmu_psize_defs[psize].sllp | ((ssize ==MMU_SEGSIZE_1T ) ?SLB_VSID_B_1T :0 );
Signature · 1 line
2.1.0
PATCH v3 2/24 powerpc/pci: Export symbols for CXL
In reply to Michael NeulingFrom: Daniel Axtens <[email protected]>
Export pcibios_claim_one_bus, pcibios_scan_phb and pcibios_alloc_controller.
These will be used by the CXL driver.
--- arch/powerpc/kernel/pci-common.c | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/kernel/pci-common.c +3 -0
@@ -89,6 +89,7 @@ struct pci_controller *pcibios_alloc_controller(struct device_node *dev)#endif return phb; } +EXPORT_SYMBOL_GPL (pcibios_alloc_controller);void pcibios_free_controller (struct pci_controller *phb) {
@@ -1447,6 +1448,7 @@ void pcibios_claim_one_bus(struct pci_bus *bus)list_for_each_entry (child_bus, &bus->children, node)pcibios_claim_one_bus (child_bus); } +EXPORT_SYMBOL_GPL (pcibios_claim_one_bus);/* pcibios_finish_adding_to_bus
@@ -1680,6 +1682,7 @@ void pcibios_scan_phb(struct pci_controller *hose)pcie_bus_configure_settings (child); } } +EXPORT_SYMBOL_GPL (pcibios_scan_phb);static void fixup_hide_host_resource_fsl (struct pci_dev *dev) {
Signature · 1 line
2.1.0
PATCH v3 3/24 powerpc/pci: Add release_device() hook to phb ops
In reply to Michael NeulingAdd release_device() hook to phb ops so we can clean up for specific phbs.
--- arch/powerpc/include/asm/pci-bridge.h | 2 ++ arch/powerpc/kernel/pci-hotplug.c | 5 +++++ 2 files changed, 7 insertions(+)
arch/powerpc/include/asm/pci-bridge.h +2 -0
@@ -27,6 +27,8 @@ struct pci_controller_ops {* allow assignment/enabling of the device. */ bool (*enable_device_hook)(struct pci_dev *); +void (*release_device)(struct pci_dev *); +/* Called during PCI resource reassignment */ resource_size_t (*window_alignment)(struct pci_bus *,unsigned long type);void (*reset_secondary_bus)(struct pci_dev *dev);
arch/powerpc/kernel/pci-hotplug.c +5 -0
@@ -29,7 +29,12 @@*/ void pcibios_release_device (struct pci_dev *dev) { +struct pci_controller *phb =pci_bus_to_host (dev->bus); +eeh_remove_device (dev); + +if (phb->controller_ops.release_device) + phb->controller_ops.release_device (dev); }/**
Signature · 1 line
2.1.0
PATCH v3 4/24 powerpc: Add cxl context to device archdata
In reply to Michael NeulingAdd cxl context pointer to archdata. We'll want to create one of these for cxl PCI devices. Put them here until we can get a pci_dev specific private data.
This location was suggested by benh.
--- arch/powerpc/include/asm/device.h | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/include/asm/device.h +3 -0
@@ -46,6 +46,9 @@ struct dev_archdata {#ifdef CONFIG_FAIL_IOMMU int fail_iommu;#endif +#ifdef CONFIG_CXL_BASE +struct cxl_context *cxl_ctx; +#endif };struct pdev_archdata {
Signature · 1 line
2.1.0
PATCH v3 5/24 powerpc/pci: Add shutdown hook to pci_controller_ops
In reply to Michael NeulingCurrently pnv_pci_shutdown() calls the PHB shutdown code for all PHBs in the system. It dereferences the private_data assuming it's a powernv PHB, which won't be the case when we have different PHB in the systems (like when we add vPHBs for CXL).
This moves the shutdown hook to the pci_controller_ops and fixes the call site to use that instead.
--- arch/powerpc/include/asm/pci-bridge.h | 2 ++ arch/powerpc/platforms/powernv/pci-ioda.c | 8 ++++---- arch/powerpc/platforms/powernv/pci.c | 9 +++------ arch/powerpc/platforms/powernv/pci.h | 1 - 4 files changed, 9 insertions(+), 11 deletions(-)
arch/powerpc/include/asm/pci-bridge.h +2 -0
@@ -40,6 +40,8 @@ struct pci_controller_ops {#endif int (*dma_set_mask)(struct pci_dev *dev,u64 dma_mask); + +void (*shutdown)(struct pci_controller *); };/*
arch/powerpc/platforms/powernv/pci-ioda.c +4 -4
@@ -2645,8 +2645,10 @@ static u32 pnv_ioda_bdfn_to_pe(struct pnv_phb *phb, struct pci_bus *bus,return phb->ioda.pe_rmap[(bus->number <<8 ) | devfn]; } -static void pnv_pci_ioda_shutdown (struct pnv_phb *phb) +static void pnv_pci_ioda_shutdown (struct pci_controller *hose) { +struct pnv_phb *phb = hose->private_data; +opal_pci_reset (phb->opal_id,OPAL_RESET_PCI_IODA_TABLE ,OPAL_ASSERT_RESET ); }
@@ -2796,9 +2798,6 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np, phb->dma_dev_setup = pnv_pci_ioda_dma_dev_setup; phb->dma_get_required_mask = pnv_pci_ioda_dma_get_required_mask; -/* Setup shutdown function for kexec */ - phb->shutdown = pnv_pci_ioda_shutdown; -/* Setup MSI support */ pnv_pci_init_ioda_msis (phb);
@@ -2879,4 +2878,5 @@ static const struct pci_controller_ops pnv_pci_ioda_controller_ops = { .window_alignment = pnv_pci_window_alignment, .reset_secondary_bus = pnv_pci_reset_secondary_bus, .dma_set_mask = pnv_pci_ioda_dma_set_mask, + .shutdown = pnv_pci_ioda_shutdown, };
arch/powerpc/platforms/powernv/pci.c +3 -6
@@ -704,12 +704,9 @@ void pnv_pci_shutdown(void) {struct pci_controller *hose; -list_for_each_entry (hose, &hose_list, list_node) { -struct pnv_phb *phb = hose->private_data; - -if (phb && phb->shutdown) - phb->shutdown (phb); - } +list_for_each_entry (hose, &hose_list, list_node) +if (hose->controller_ops.shutdown) + hose->controller_ops.shutdown (hose); }/* Fixup wrong class code in p7ioc and p8 root complex */
arch/powerpc/platforms/powernv/pci.h +0 -1
@@ -110,7 +110,6 @@ struct pnv_phb { struct pci_dev *pdev);void (*fixup_phb)(struct pci_controller *hose);u32 (*bdfn_to_pe)(struct pnv_phb *phb,struct pci_bus *bus,u32 devfn); -void (*shutdown)(struct pnv_phb *phb);int (*init_m64)(struct pnv_phb *phb);void (*reserve_m64_pe)(struct pnv_phb *phb);int (*pick_m64_pe)(struct pnv_phb *phb,struct pci_bus *bus,int all);
Signature · 1 line
2.1.0
PATCH v3 6/24 powerpc/pci: Add pcibios_disable_device() hook
In reply to Michael NeulingThis adds a hook into the powerpc pci code for pci_disable_device() calls. The generic code already provides a weak pcibios_disable_device() symbol, so we just need to provide our own in powerpc and it'll get picked up.
This is passed directly to the phb controller ops, provided one exists.
--- arch/powerpc/include/asm/pci-bridge.h | 2 ++ arch/powerpc/kernel/pci-common.c | 8 ++++++++ 2 files changed, 10 insertions(+)
arch/powerpc/include/asm/pci-bridge.h +2 -0
@@ -27,6 +27,8 @@ struct pci_controller_ops {* allow assignment/enabling of the device. */ bool (*enable_device_hook)(struct pci_dev *); +void (*disable_device)(struct pci_dev *); +void (*release_device)(struct pci_dev *);/* Called during PCI resource reassignment */
arch/powerpc/kernel/pci-common.c +8 -0
@@ -1490,6 +1490,14 @@ int pcibios_enable_device(struct pci_dev *dev, int mask)return pci_enable_resources (dev, mask); } +void pcibios_disable_device (struct pci_dev *dev) +{ +struct pci_controller *phb =pci_bus_to_host (dev->bus); + +if (phb->controller_ops.disable_device) + phb->controller_ops.disable_device (dev); +} +resource_size_t pcibios_io_space_offset (struct pci_controller *hose) {return (unsigned long ) hose->io_base_virt - _IO_BASE;
Signature · 1 line
2.1.0
PATCH v3 7/24 cxl: Document external user of existing API
In reply to Michael NeulingNow that libcxl is public, let's document it.
--- Documentation/ABI/testing/sysfs-class-cxl | 22 ++++++++++++++++++++++ Documentation/powerpc/cxl.txt | 4 ++++ 2 files changed, 26 insertions(+)
Documentation/ABI/testing/sysfs-class-cxl +22 -0
@@ -15,6 +15,7 @@ Description: read/write that hardware can support (eg. 2037). Write values will limit userspace applications to that many userspace interrupts. Must be >= irqs_min. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<afu>/irqs_min Date: September 2014
@@ -24,6 +25,7 @@ Description: read only userspace must request on a CXL_START_WORK ioctl. Userspace may omit the num_interrupts field in the START_WORK IOCTL to get this minimum automatically. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<afu>/mmio_size Date: September 2014
@@ -31,6 +33,7 @@ Contact: [email protected] Description: read only Decimal value of the size of the MMIO space that may be mmaped by userspace. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<afu>/modes_supported Date: September 2014
@@ -38,6 +41,7 @@ Contact: [email protected] Description: read only List of the modes this AFU supports. One per line. Valid entries are: "dedicated_process" and "afu_directed" +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<afu>/mode Date: September 2014
@@ -46,6 +50,7 @@ Description: read/write The current mode the AFU is using. Will be one of the modes given in modes_supported. Writing will change the mode provided that no user contexts are attached. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<afu>/prefault_mode
@@ -59,6 +64,7 @@ Description: read/write descriptor as an effective address and prefault what it points to. all: all segments process calling START_WORK maps. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<afu>/reset Date: September 2014
@@ -66,12 +72,14 @@ Contact: [email protected] Description: write only Writing 1 here will reset the AFU provided there are not contexts active on the AFU. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<afu>/api_version Date: September 2014 Contact: [email protected] Description: read only Decimal value of the current version of the kernel/user API. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<afu>/api_version_compatible Date: September 2014
@@ -79,6 +87,7 @@ Contact: [email protected] Description: read only Decimal value of the the lowest version of the userspace API this this kernel supports. +Users: https://github.com/ibm-capi/libcxl AFU configuration records (eg. /sys/class/cxl/afu0.0/cr0):
@@ -92,6 +101,7 @@ Contact: [email protected] Description: read only Hexadecimal value of the vendor ID found in this AFU configuration record. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<afu>/cr<config num>/device Date: February 2015
@@ -99,6 +109,7 @@ Contact: [email protected] Description: read only Hexadecimal value of the device ID found in this AFU configuration record. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<afu>/cr<config num>/class Date: February 2015
@@ -106,6 +117,7 @@ Contact: [email protected] Description: read only Hexadecimal value of the class code found in this AFU configuration record. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<afu>/cr<config num>/config Date: February 2015
@@ -115,6 +127,7 @@ Description: read only record. The format is expected to match the either the standard or extended configuration space defined by the PCIe specification. +Users: https://github.com/ibm-capi/libcxl
@@ -126,18 +139,21 @@ Contact: [email protected] Description: read only Decimal value of the size of the MMIO space that may be mmaped by userspace. This includes all slave contexts space also. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<afu>m/pp_mmio_len Date: September 2014 Contact: [email protected] Description: read only Decimal value of the Per Process MMIO space length. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<afu>m/pp_mmio_off Date: September 2014 Contact: [email protected] Description: read only Decimal value of the Per Process MMIO space offset. +Users: https://github.com/ibm-capi/libcxl Card info (eg. /sys/class/cxl/card0)
@@ -147,12 +163,14 @@ Date: September 2014 Contact: [email protected] Description: read only Identifies the CAIA Version the card implements. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<card>/psl_revision Date: September 2014 Contact: [email protected] Description: read only Identifies the revision level of the PSL. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<card>/base_image Date: September 2014
@@ -162,6 +180,7 @@ Description: read only that support loadable PSLs. For FPGAs this field identifies the image contained in the on-adapter flash which is loaded during the initial program load. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<card>/image_loaded Date: September 2014
@@ -169,6 +188,7 @@ Contact: [email protected] Description: read only Will return "user" or "factory" depending on the image loaded onto the card. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<card>/load_image_on_perst Date: December 2014
@@ -183,6 +203,7 @@ Description: read/write user or factory image to be loaded. Default is to reload on PERST whichever image the card has loaded. +Users: https://github.com/ibm-capi/libcxl What: /sys/class/cxl/<card>/reset Date: October 2014
@@ -190,3 +211,4 @@ Contact: [email protected] Description: write only Writing 1 will issue a PERST to card which may cause the card to reload the FPGA depending on load_image_on_perst. +Users: https://github.com/ibm-capi/libcxl
Documentation/powerpc/cxl.txt +4 -0
@@ -133,6 +133,9 @@ User API The following file operations are supported on both slave and master devices. + A userspace library libcxl is avaliable here: + https://github.com/ibm-capi/libcxl + This provides a C interface to this kernel API. open ----
@@ -366,6 +369,7 @@ Sysfs Class enumeration and tuning of the accelerators. Its layout is described in Documentation/ABI/testing/sysfs-class-cxl + Udev rules ==========
Signature · 1 line
2.1.0
PATCH v3 8/24 cxl: Add shutdown hook
In reply to Michael Neuling--- drivers/misc/cxl/pci.c | 1 + 1 file changed, 1 insertion(+)
drivers/misc/cxl/pci.c +1 -0
@@ -1135,4 +1135,5 @@ struct pci_driver cxl_pci_driver = { .id_table = cxl_pci_tbl, .probe = cxl_probe, .remove = cxl_remove, + .shutdown = cxl_remove, };
Signature · 1 line
2.1.0
PATCH v3 9/24 cxl: Remove unnecessarily verbose print in cxl_remove()
In reply to Michael Neuling--- drivers/misc/cxl/pci.c | 2 -- 1 file changed, 2 deletions(-)
drivers/misc/cxl/pci.c +0 -2
@@ -1119,8 +1119,6 @@ static void cxl_remove(struct pci_dev *dev)struct cxl *adapter =pci_get_drvdata (dev);int afu; -dev_warn (&dev->dev,"pci remove\n" ); -/* * Lock to prevent someone grabbing a ref through the adapter list as * we are removing it
Signature · 1 line
2.1.0
PATCH v3 10/24 cxl: Re-order card init to check the VSEC earlier
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
When we expose AFUs as virtual PCI devices, they may look like the physical CAPI PCI card. ie they may have the same vendor/device IDs.
We want to avoid these AFUs binding to this driver and any init this driver may do.
Re-order card init to check the VSEC earlier before assigning BARs or activating CXL. Also change the dev used in early prints as the adapter struct may not be inited at this earlier stage.
--- drivers/misc/cxl/pci.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/misc/cxl/pci.c +15 -15
@@ -884,13 +884,13 @@ static int cxl_read_vsec(struct cxl *adapter, struct pci_dev *dev)u16 vseclen;if (!(vsec =find_cxl_vsec (dev))) { -dev_err (&adapter->dev,"ABORTING: CXL VSEC not found!\n" ); +dev_err (&dev->dev,"ABORTING: CXL VSEC not found!\n" );return -ENODEV ; }CXL_READ_VSEC_LENGTH (dev, vsec, &vseclen);if (vseclen <CXL_VSEC_MIN_SIZE ) { -pr_err ("ABORTING: CXL VSEC too short\n" ); +dev_err (&dev->dev,"ABORTING: CXL VSEC too short\n" );return -EINVAL ; }
@@ -927,24 +927,24 @@ static int cxl_vsec_looks_ok(struct cxl *adapter, struct pci_dev *dev)return -EBUSY ;if (adapter->vsec_status &CXL_UNSUPPORTED_FEATURES ) { -dev_err (&adapter->dev,"ABORTING: CXL requires unsupported features\n" ); +dev_err (&dev->dev,"ABORTING: CXL requires unsupported features\n" );return -EINVAL ; }if (!adapter->slices) {/* Once we support dynamic reprogramming we can use the card if * it supports loadable AFUs */ -dev_err (&adapter->dev,"ABORTING: Device has no AFUs\n" ); +dev_err (&dev->dev,"ABORTING: Device has no AFUs\n" );return -EINVAL ; }if (!adapter->afu_desc_off || !adapter->afu_desc_size) { -dev_err (&adapter->dev,"ABORTING: VSEC shows no AFU descriptors\n" ); +dev_err (&dev->dev,"ABORTING: VSEC shows no AFU descriptors\n" );return -EINVAL ; }if (adapter->ps_size >p2_size (dev) - adapter->ps_off) { -dev_err (&adapter->dev,"ABORTING: Problem state size larger than " +dev_err (&dev->dev,"ABORTING: Problem state size larger than " "available in BAR2: 0x%llx > 0x%llx\n" , adapter->ps_size,p2_size (dev) - adapter->ps_off);return -EINVAL ;
@@ -993,6 +993,15 @@ static struct cxl *cxl_init_adapter(struct pci_dev *dev)if (!(adapter =cxl_alloc_adapter (dev)))return ERR_PTR (-ENOMEM ); +if ((rc =cxl_read_vsec (adapter, dev))) + goto err1; + +if ((rc =cxl_vsec_looks_ok (adapter, dev))) + goto err1; + +if ((rc =setup_cxl_bars (dev))) + goto err1; +if ((rc =switch_card_to_cxl (dev))) goto err1;
@@ -1002,12 +1011,6 @@ static struct cxl *cxl_init_adapter(struct pci_dev *dev)if ((rc =dev_set_name (&adapter->dev,"card%i" , adapter->adapter_num))) goto err2; -if ((rc =cxl_read_vsec (adapter, dev))) - goto err2; - -if ((rc =cxl_vsec_looks_ok (adapter, dev))) - goto err2; -if ((rc =cxl_update_image_control (adapter))) goto err2;
@@ -1092,9 +1095,6 @@ static int cxl_probe(struct pci_dev *dev, const struct pci_device_id *id)if (cxl_verbose)dump_cxl_config_space (dev); -if ((rc =setup_cxl_bars (dev))) -return rc; -if ((rc =pci_enable_device (dev))) {dev_err (&dev->dev,"pci_enable_device failed: %i\n" , rc);return rc;
Signature · 1 line
2.1.0
PATCH v3 11/24 cxl: Fix error path on probe
In reply to Michael NeulingWhen probing we call pci_enable_device() but don't call pci_disable_device() on fail. This causes refcounting issues in the PCI subsystem if a second driver tries to bind to the same device.
This patch adds the pci_disable_device() to the probe error path. This error path is hit when this cxl driver tries to bind to AFUs (on the vPHB) rather than the physical device.
--- drivers/misc/cxl/pci.c | 1 + 1 file changed, 1 insertion(+)
drivers/misc/cxl/pci.c +1 -0
@@ -1103,6 +1103,7 @@ static int cxl_probe(struct pci_dev *dev, const struct pci_device_id *id) adapter =cxl_init_adapter (dev);if (IS_ERR (adapter)) {dev_err (&dev->dev,"cxl_init_adapter failed: %li\n" ,PTR_ERR (adapter)); +pci_disable_device (dev);return PTR_ERR (adapter); }
Signature · 1 line
2.1.0
PATCH v3 12/24 cxl: Dump debug info on the AFU configuration record
In reply to Michael NeulingNow that we parse the AFU Configuration record, dump some info on it when in debug mode.
--- drivers/misc/cxl/pci.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/misc/cxl/pci.c +11 -1
@@ -90,6 +90,7 @@/* This works a little different than the p1/p2 register accesses to make it * easier to pull out individual fields */ #define AFUD_READ (afu, off) in_be64(afu->afu_desc_mmio + off) +#define AFUD_READ_LE (afu, off) in_le64(afu->afu_desc_mmio + off)#define EXTRACT_PPC_BIT (val, bit) (!!(val & PPC_BIT(bit)))#define EXTRACT_PPC_BITS (val, bs, be) ((val & PPC_BITMASK(bs, be)) >> PPC_BITLSHIFT(be))
@@ -286,7 +287,8 @@ static void dump_cxl_config_space(struct pci_dev *dev)static void dump_afu_descriptor (struct cxl_afu *afu) { -u64 val; +u64 val, afu_cr_num, afu_cr_off, afu_cr_len; +int i;#define show_reg (name, what) \ dev_info(&afu->dev, "afu desc: %30s: %#llx\n", name, what)
@@ -296,6 +298,7 @@ static void dump_afu_descriptor(struct cxl_afu *afu)show_reg ("num_of_processes" ,AFUD_NUM_PROCS (val));show_reg ("num_of_afu_CRs" ,AFUD_NUM_CRS (val));show_reg ("req_prog_mode" , val &0xffffULL ); + afu_cr_num =AFUD_NUM_CRS (val); val =AFUD_READ (afu,0x8 );show_reg ("Reserved" , val);
@@ -307,8 +310,10 @@ static void dump_afu_descriptor(struct cxl_afu *afu) val =AFUD_READ_CR (afu);show_reg ("Reserved" , (val >> (63 -7 )) &0xff );show_reg ("AFU_CR_len" ,AFUD_CR_LEN (val)); + afu_cr_len =AFUD_CR_LEN (val) *256 ; val =AFUD_READ_CR_OFF (afu); + afu_cr_off = val;show_reg ("AFU_CR_offset" , val); val =AFUD_READ_PPPSA (afu);
@@ -325,6 +330,11 @@ static void dump_afu_descriptor(struct cxl_afu *afu) val =AFUD_READ_EB_OFF (afu);show_reg ("AFU_EB_offset" , val); +for (i =0 ; i < afu_cr_num; i++) { + val =AFUD_READ_LE (afu, afu_cr_off + i * afu_cr_len); +show_reg ("CR Vendor" , val &0xffff ); +show_reg ("CR Device" , (val >>16 ) &0xffff ); + }#undef show_reg }
Signature · 1 line
2.1.0
PATCH v3 13/24 cxl: Add cookie parameter to afu_release_irqs()
In reply to Michael NeulingAdd cookie parameter to afu_release_irqs() so that we can pass in a different cookie than the context structure. This will be useful for other kernel drivers that want to call this but get their own cookie back in the interrupt handler.
Update all existing call sites.
--- drivers/misc/cxl/context.c | 2 +- drivers/misc/cxl/cxl.h | 2 +- drivers/misc/cxl/file.c | 2 +- drivers/misc/cxl/irq.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-)
drivers/misc/cxl/context.c +1 -1
@@ -186,7 +186,7 @@ static void __detach_context(struct cxl_context *ctx)return ;WARN_ON (cxl_detach_process (ctx)); -afu_release_irqs (ctx); +afu_release_irqs (ctx, ctx);flush_work (&ctx->fault_work);/* Only needed for dedicated process */ wake_up_all (&ctx->wq); }
drivers/misc/cxl/cxl.h +1 -1
@@ -609,7 +609,7 @@ void cxl_release_psl_err_irq(struct cxl *adapter);int cxl_register_serr_irq (struct cxl_afu *afu);void cxl_release_serr_irq (struct cxl_afu *afu);int afu_register_irqs (struct cxl_context *ctx,u32 count); -void afu_release_irqs (struct cxl_context *ctx); +void afu_release_irqs (struct cxl_context *ctx,void *cookie);irqreturn_t cxl_slice_irq_err (int irq,void *data);int cxl_debugfs_init (void );
drivers/misc/cxl/file.c +1 -1
@@ -191,7 +191,7 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,if ((rc =cxl_attach_process (ctx, false, work.work_element_descriptor, amr))) { -afu_release_irqs (ctx); +afu_release_irqs (ctx, ctx); goto out; }
drivers/misc/cxl/irq.c +2 -2
@@ -477,7 +477,7 @@ out:return -ENOMEM ; } -void afu_release_irqs (struct cxl_context *ctx) +void afu_release_irqs (struct cxl_context *ctx,void *cookie) {irq_hw_number_t hwirq;unsigned int virq;
@@ -488,7 +488,7 @@ void afu_release_irqs(struct cxl_context *ctx)for (i =0 ; i < ctx->irqs.range[r]; hwirq++, i++) { virq =irq_find_mapping (NULL , hwirq);if (virq) -cxl_unmap_irq (virq, ctx); +cxl_unmap_irq (virq, cookie); } }
Signature · 1 line
2.1.0
PATCH v3 14/24 cxl: Rework detach context functions
In reply to Michael NeulingRework __detach_context() and cxl_context_detach() so we can reuse them in the kernel API.
--- drivers/misc/cxl/context.c | 20 +++++++++++++------- drivers/misc/cxl/cxl.h | 1 + 2 files changed, 14 insertions(+), 7 deletions(-)
drivers/misc/cxl/context.c +13 -7
@@ -174,7 +174,7 @@ int cxl_context_iomap(struct cxl_context *ctx, struct vm_area_struct *vma)* return until all outstanding interrupts for this context have completed. The * hardware should no longer access *ctx after this has returned. */ -static void __detach_context (struct cxl_context *ctx) +int __detach_context (struct cxl_context *ctx) {enum cxl_context_status status;
@@ -183,12 +183,10 @@ static void __detach_context(struct cxl_context *ctx) ctx->status =CLOSED ;mutex_unlock (&ctx->status_mutex);if (status !=STARTED ) -return ; +return -EBUSY ;WARN_ON (cxl_detach_process (ctx)); -afu_release_irqs (ctx, ctx); -flush_work (&ctx->fault_work);/* Only needed for dedicated process */ -wake_up_all (&ctx->wq); +return 0 ; }/*
@@ -199,7 +197,15 @@ static void __detach_context(struct cxl_context *ctx)*/ void cxl_context_detach (struct cxl_context *ctx) { -__detach_context (ctx); +int rc; + + rc =__detach_context (ctx); +if (rc) +return ; + +afu_release_irqs (ctx, ctx); +flush_work (&ctx->fault_work);/* Only needed for dedicated process */ +wake_up_all (&ctx->wq); }/*
@@ -216,7 +222,7 @@ void cxl_context_detach_all(struct cxl_afu *afu)* Anything done in here needs to be setup before the IDR is * created and torn down after the IDR removed */ -__detach_context (ctx); +cxl_context_detach (ctx);/* * We are force detaching - remove any active PSA mappings so
drivers/misc/cxl/cxl.h +1 -0
@@ -632,6 +632,7 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master, struct address_space *mapping);void cxl_context_free (struct cxl_context *ctx);int cxl_context_iomap (struct cxl_context *ctx,struct vm_area_struct *vma); +int __detach_context (struct cxl_context *ctx);/* This matches the layout of the H_COLLECT_CA_INT_INFO retbuf */ struct cxl_irq_info {
Signature · 1 line
2.1.0
PATCH v3 15/24 cxl: cxl_afu_reset() -> __cxl_afu_reset()
In reply to Michael NeulingRename cxl_afu_reset() to __cxl_afu_reset() to we can reuse this function name in the API.
--- drivers/misc/cxl/cxl.h | 2 +- drivers/misc/cxl/native.c | 8 ++++---- drivers/misc/cxl/pci.c | 4 ++-- drivers/misc/cxl/sysfs.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-)
drivers/misc/cxl/cxl.h +1 -1
@@ -657,7 +657,7 @@ int cxl_check_error(struct cxl_afu *afu);int cxl_afu_slbia (struct cxl_afu *afu);int cxl_tlb_slb_invalidate (struct cxl *adapter);int cxl_afu_disable (struct cxl_afu *afu); -int cxl_afu_reset (struct cxl_afu *afu); +int __cxl_afu_reset (struct cxl_afu *afu);int cxl_psl_purge (struct cxl_afu *afu);void cxl_stop_trace (struct cxl *cxl);
drivers/misc/cxl/native.c +4 -4
@@ -73,7 +73,7 @@ int cxl_afu_disable(struct cxl_afu *afu) }/* This will disable as well as reset */ -int cxl_afu_reset (struct cxl_afu *afu) +int __cxl_afu_reset (struct cxl_afu *afu) {pr_devel ("AFU reset request\n" );
@@ -495,7 +495,7 @@ static int deactivate_afu_directed(struct cxl_afu *afu)cxl_sysfs_afu_m_remove (afu);cxl_chardev_afu_remove (afu); -cxl_afu_reset (afu); +__cxl_afu_reset (afu);cxl_afu_disable (afu);cxl_psl_purge (afu);
@@ -566,7 +566,7 @@ static int attach_dedicated(struct cxl_context *ctx, u64 wed, u64 amr)/* master only context for dedicated */ assign_psn_space (ctx); -if ((rc =cxl_afu_reset (afu))) +if ((rc =__cxl_afu_reset (afu)))return rc;cxl_p2n_write (afu, CXL_PSL_WED_An, wed);
@@ -629,7 +629,7 @@ int cxl_attach_process(struct cxl_context *ctx, bool kernel, u64 wed, u64 amr)static inline int detach_process_native_dedicated (struct cxl_context *ctx) { -cxl_afu_reset (ctx->afu); +__cxl_afu_reset (ctx->afu);cxl_afu_disable (ctx->afu);cxl_psl_purge (ctx->afu);return 0 ;
drivers/misc/cxl/pci.c +2 -2
@@ -641,7 +641,7 @@ static int sanitise_afu_regs(struct cxl_afu *afu) reg =cxl_p2n_read (afu, CXL_AFU_Cntl_An);if ((reg & CXL_AFU_Cntl_An_ES_MASK) != CXL_AFU_Cntl_An_ES_Disabled) {dev_warn (&afu->dev,"WARNING: AFU was not disabled: %#.16llx\n" , reg); -if (cxl_afu_reset (afu)) +if (__cxl_afu_reset (afu))return -EIO ;if (cxl_afu_disable (afu))return -EIO ;
@@ -701,7 +701,7 @@ static int cxl_init_afu(struct cxl *adapter, int slice, struct pci_dev *dev) goto err2;/* We need to reset the AFU before we can read the AFU descriptor */ -if ((rc =cxl_afu_reset (afu))) +if ((rc =__cxl_afu_reset (afu))) goto err2;if (cxl_verbose)
drivers/misc/cxl/sysfs.c +1 -1
@@ -185,7 +185,7 @@ static ssize_t reset_store_afu(struct device *device, goto err; } -if ((rc =cxl_afu_reset (afu))) +if ((rc =__cxl_afu_reset (afu))) goto err; rc = count;
Signature · 1 line
2.1.0
PATCH v3 16/24 cxl: Export some symbols
In reply to Michael NeulingExport some symbols which will soon be used elsewhere in this driver.
Now they are global we rename them so to avoid collisions.
--- drivers/misc/cxl/cxl.h | 5 +++++ drivers/misc/cxl/native.c | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-)
drivers/misc/cxl/cxl.h +5 -0
@@ -632,6 +632,9 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master, struct address_space *mapping);void cxl_context_free (struct cxl_context *ctx);int cxl_context_iomap (struct cxl_context *ctx,struct vm_area_struct *vma); +unsigned int cxl_map_irq (struct cxl *adapter,irq_hw_number_t hwirq, +irq_handler_t handler,void *cookie,const char *name); +void cxl_unmap_irq (unsigned int virq,void *cookie);int __detach_context (struct cxl_context *ctx);/* This matches the layout of the H_COLLECT_CA_INT_INFO retbuf */
@@ -646,6 +649,7 @@ struct cxl_irq_info {u64 padding[3 ];/* to match the expected retbuf size for plpar_hcall9 */ }; +void cxl_assign_psn_space (struct cxl_context *ctx);int cxl_attach_process (struct cxl_context *ctx,bool kernel,u64 wed,u64 amr);int cxl_detach_process (struct cxl_context *ctx);
@@ -658,6 +662,7 @@ int cxl_afu_slbia(struct cxl_afu *afu);int cxl_tlb_slb_invalidate (struct cxl *adapter);int cxl_afu_disable (struct cxl_afu *afu);int __cxl_afu_reset (struct cxl_afu *afu); +int cxl_afu_check_and_enable (struct cxl_afu *afu);int cxl_psl_purge (struct cxl_afu *afu);void cxl_stop_trace (struct cxl *cxl);
drivers/misc/cxl/native.c +5 -5
@@ -83,7 +83,7 @@ int __cxl_afu_reset(struct cxl_afu *afu) false); } -static int afu_check_and_enable (struct cxl_afu *afu) +int cxl_afu_check_and_enable (struct cxl_afu *afu) {if (afu->enabled)return 0 ;
@@ -379,7 +379,7 @@ static int remove_process_element(struct cxl_context *ctx) } -static void assign_psn_space (struct cxl_context *ctx) +void cxl_assign_psn_space (struct cxl_context *ctx) {if (!ctx->afu->pp_size || ctx->master) { ctx->psn_phys = ctx->afu->psn_phys;
@@ -435,7 +435,7 @@ static int attach_afu_directed(struct cxl_context *ctx, u64 wed, u64 amr)u64 sr;int r, result; -assign_psn_space (ctx); +cxl_assign_psn_space (ctx); ctx->elem->ctxtime =0 ;/* disable */ ctx->elem->lpid =cpu_to_be32 (mfspr (SPRN_LPID ));
@@ -477,7 +477,7 @@ static int attach_afu_directed(struct cxl_context *ctx, u64 wed, u64 amr) ctx->elem->common.wed =cpu_to_be64 (wed);/* first guy needs to enable */ -if ((result =afu_check_and_enable (ctx->afu))) +if ((result =cxl_afu_check_and_enable (ctx->afu)))return result;add_process_element (ctx);
@@ -564,7 +564,7 @@ static int attach_dedicated(struct cxl_context *ctx, u64 wed, u64 amr)cxl_p2n_write (afu, CXL_PSL_AMR_An, amr);/* master only context for dedicated */ -assign_psn_space (ctx); +cxl_assign_psn_space (ctx);if ((rc =__cxl_afu_reset (afu)))return rc;
Signature · 1 line
2.1.0
PATCH v3 17/24 cxl: Only check pid for userspace contexts
In reply to Michael NeulingWe only need to check the pid attached to this context for userspace contexts. Kernel contexts can skip this check.
--- drivers/misc/cxl/fault.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
drivers/misc/cxl/fault.c +19 -15
@@ -172,8 +172,8 @@ void cxl_handle_fault(struct work_struct *fault_work) container_of(fault_work, struct cxl_context, fault_work);u64 dsisr = ctx->dsisr;u64 dar = ctx->dar; -struct task_struct *task; -struct mm_struct *mm; +struct task_struct *task =NULL ; +struct mm_struct *mm =NULL ; if (cxl_p2n_read(ctx->afu, CXL_PSL_DSISR_An) != dsisr || cxl_p2n_read(ctx->afu, CXL_PSL_DAR_An) != dar ||
@@ -194,17 +194,19 @@ void cxl_handle_fault(struct work_struct *fault_work)pr_devel ("CXL BOTTOM HALF handling fault for afu pe: %i. " "DSISR: %#llx DAR: %#llx\n" , ctx->pe, dsisr, dar); -if (!(task =get_pid_task (ctx->pid,PIDTYPE_PID ))) { -pr_devel ("cxl_handle_fault unable to get task %i\n" , -pid_nr (ctx->pid)); -cxl_ack_ae (ctx); -return ; - } -if (!(mm =get_task_mm (task))) { -pr_devel ("cxl_handle_fault unable to get mm %i\n" , -pid_nr (ctx->pid)); -cxl_ack_ae (ctx); - goto out; +if (!ctx->kernel) { +if (!(task =get_pid_task (ctx->pid,PIDTYPE_PID ))) { +pr_devel ("cxl_handle_fault unable to get task %i\n" , +pid_nr (ctx->pid)); +cxl_ack_ae (ctx); +return ; + } +if (!(mm =get_task_mm (task))) { +pr_devel ("cxl_handle_fault unable to get mm %i\n" , +pid_nr (ctx->pid)); +cxl_ack_ae (ctx); + goto out; + } }if (dsisr & CXL_PSL_DSISR_An_DS)
@@ -214,9 +216,11 @@ void cxl_handle_fault(struct work_struct *fault_work)else WARN (1 ,"cxl_handle_fault has nothing to handle\n" ); -mmput (mm); +if (mm) +mmput (mm); out: -put_task_struct (task); +if (task) +put_task_struct (task); }static void cxl_prefault_one (struct cxl_context *ctx,u64 ea)
Signature · 1 line
2.1.0
PATCH v3 18/24 cxl: Split afu_register_irqs() function
In reply to Michael NeulingSplit the afu_register_irqs() function so that different parts can be useful elsewhere.
--- drivers/misc/cxl/cxl.h | 1 + drivers/misc/cxl/irq.c | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-)
drivers/misc/cxl/cxl.h +1 -0
@@ -668,5 +668,6 @@ int cxl_psl_purge(struct cxl_afu *afu);void cxl_stop_trace (struct cxl *cxl);extern struct pci_driver cxl_pci_driver; +int afu_allocate_irqs (struct cxl_context *ctx,u32 count);#endif
drivers/misc/cxl/irq.c +24 -7
@@ -416,9 +416,8 @@ void afu_irq_name_free(struct cxl_context *ctx) } } -int afu_register_irqs (struct cxl_context *ctx,u32 count) +int afu_allocate_irqs (struct cxl_context *ctx,u32 count) { -irq_hw_number_t hwirq;int rc, r, i, j =1 ;struct cxl_irq_name *irq_name;
@@ -458,6 +457,18 @@ int afu_register_irqs(struct cxl_context *ctx, u32 count) j++; } } +return 0 ; + +out: +afu_irq_name_free (ctx); +return -ENOMEM ; +} + +void afu_register_hwirqs (struct cxl_context *ctx) +{ +irq_hw_number_t hwirq; +struct cxl_irq_name *irq_name; +int r,i;/* We've allocated all memory now, so let's do the irq allocations */ irq_name = list_first_entry(&ctx->irq_names, struct cxl_irq_name, list);
@@ -469,13 +480,19 @@ int afu_register_irqs(struct cxl_context *ctx, u32 count) irq_name =list_next_entry (irq_name, list); } } +} -return 0 ; +int afu_register_irqs (struct cxl_context *ctx,u32 count) +{ +int rc; -out: -afu_irq_name_free (ctx); -return -ENOMEM ; -} + rc =afu_allocate_irqs (ctx, count); +if (rc) +return rc; + +afu_register_hwirqs (ctx); +return 0 ; + }void afu_release_irqs (struct cxl_context *ctx,void *cookie) {
Signature · 1 line
2.1.0
PATCH v3 19/24 cxl: Configure PSL for kernel contexts and merge code
In reply to Michael NeulingThis updates AFU directed and dedicated modes for contexts attached to the kernel.
The SR (similar to the MSR in the core) calculation is getting quite complex and is duplicated in AFU directed and dedicated modes. This patch also merges this SR calculation for these modes.
--- drivers/misc/cxl/native.c | 63 ++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 28 deletions(-)
drivers/misc/cxl/native.c +35 -28
@@ -430,9 +430,30 @@ err:#define set_endian (sr) ((sr) &= ~(CXL_PSL_SR_An_LE))#endif +static u64 calculate_sr (struct cxl_context *ctx) +{ +u64 sr =0 ; + +if (ctx->master) + sr |= CXL_PSL_SR_An_MP; +if (mfspr (SPRN_LPCR ) &LPCR_TC ) + sr |= CXL_PSL_SR_An_TC; +if (ctx->kernel) { + sr |= CXL_PSL_SR_An_R | (mfmsr () &MSR_SF ); + sr |= CXL_PSL_SR_An_HV; + }else { + sr |= CXL_PSL_SR_An_PR | CXL_PSL_SR_An_R; +set_endian (sr); + sr &= ~(CXL_PSL_SR_An_HV); +if (!test_tsk_thread_flag (current,TIF_32BIT )) + sr |= CXL_PSL_SR_An_SF; + } +return sr; +} +static int attach_afu_directed (struct cxl_context *ctx,u64 wed,u64 amr) { -u64 sr; +u32 pid;int r, result;cxl_assign_psn_space (ctx);
@@ -442,22 +463,13 @@ static int attach_afu_directed(struct cxl_context *ctx, u64 wed, u64 amr) ctx->elem->haurp =0 ;/* disable */ ctx->elem->sdr =cpu_to_be64 (mfspr (SPRN_SDR1 )); - sr =0 ; -if (ctx->master) - sr |= CXL_PSL_SR_An_MP; -if (mfspr (SPRN_LPCR ) &LPCR_TC ) - sr |= CXL_PSL_SR_An_TC; -/* HV=0, PR=1, R=1 for userspace -* For kernel contexts: this would need to change -*/ - sr |= CXL_PSL_SR_An_PR | CXL_PSL_SR_An_R; -set_endian (sr); - sr &= ~(CXL_PSL_SR_An_HV); -if (!test_tsk_thread_flag (current,TIF_32BIT )) - sr |= CXL_PSL_SR_An_SF; - ctx->elem->common.pid =cpu_to_be32 (current->pid); + pid = current->pid; +if (ctx->kernel) + pid =0 ; ctx->elem->common.tid =0 ; - ctx->elem->sr =cpu_to_be64 (sr); + ctx->elem->common.pid =cpu_to_be32 (pid); + + ctx->elem->sr =cpu_to_be64 (calculate_sr (ctx)); ctx->elem->common.csrp =0 ;/* disable */ ctx->elem->common.aurp0 =0 ;/* disable */
@@ -530,20 +542,15 @@ static int activate_dedicated_process(struct cxl_afu *afu)static int attach_dedicated (struct cxl_context *ctx,u64 wed,u64 amr) {struct cxl_afu *afu = ctx->afu; -u64 sr; +u64 pid;int rc; - sr =0 ; -set_endian (sr); -if (ctx->master) - sr |= CXL_PSL_SR_An_MP; -if (mfspr (SPRN_LPCR ) &LPCR_TC ) - sr |= CXL_PSL_SR_An_TC; - sr |= CXL_PSL_SR_An_PR | CXL_PSL_SR_An_R; -if (!test_tsk_thread_flag (current,TIF_32BIT )) - sr |= CXL_PSL_SR_An_SF; -cxl_p2n_write (afu, CXL_PSL_PID_TID_An, (u64 )current->pid <<32 ); -cxl_p1n_write (afu, CXL_PSL_SR_An, sr); + pid = (u64 )current->pid <<32 ; +if (ctx->kernel) + pid =0 ; +cxl_p2n_write (afu, CXL_PSL_PID_TID_An, pid); + +cxl_p1n_write (afu, CXL_PSL_SR_An,calculate_sr (ctx));if ((rc =cxl_write_sstp (afu, ctx->sstp0, ctx->sstp1)))return rc;
Signature · 1 line
2.1.0
PATCH v3 20/24 cxl: Rework context lifetimes
In reply to Michael NeulingThis reworks contexts lifetimes a bit to enable the kernel API where we may want to reuse contexts. Here we will want to start and stop contexts without freeing them.
Start context does the get pid & ctx so stop context will need to do the puts. Here we move put pid & ctx to the detach context path which will become part of the stop context path.
--- drivers/misc/cxl/context.c | 5 +++-- drivers/misc/cxl/file.c | 1 - 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/misc/cxl/context.c +3 -2
@@ -186,6 +186,9 @@ int __detach_context(struct cxl_context *ctx)return -EBUSY ;WARN_ON (cxl_detach_process (ctx)); +flush_work (&ctx->fault_work);/* Only needed for dedicated process */ +put_pid (ctx->pid); +cxl_ctx_put ();return 0 ; }
@@ -204,7 +207,6 @@ void cxl_context_detach(struct cxl_context *ctx)return ;afu_release_irqs (ctx, ctx); -flush_work (&ctx->fault_work);/* Only needed for dedicated process */ wake_up_all (&ctx->wq); }
@@ -245,7 +247,6 @@ static void reclaim_ctx(struct rcu_head *rcu)free_page ((u64 )ctx->sstp); ctx->sstp =NULL ; -put_pid (ctx->pid);kfree (ctx); }
drivers/misc/cxl/file.c +0 -1
@@ -128,7 +128,6 @@ static int afu_release(struct inode *inode, struct file *file)*/ cxl_context_free (ctx); -cxl_ctx_put ();return 0 ; }
Signature · 1 line
2.1.0
PATCH v3 21/24 cxl: Cleanup Makefile
In reply to Michael NeulingCleanup Makefile by fixing line wrapping.
--- drivers/misc/cxl/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/misc/cxl/Makefile +2 -1
@@ -1,4 +1,5 @@ -cxl-y += main.o file.o irq.o fault.o native.o context.o sysfs.o debugfs.o pci.o trace.o +cxl-y += main.o file.o irq.o fault.o native.o +cxl-y += context.o sysfs.o debugfs.o pci.o trace.o obj-$(CONFIG_CXL) += cxl.o obj-$(CONFIG_CXL_BASE) += base.o
Signature · 1 line
2.1.0
PATCH v3 22/24 cxl: Move include file cxl.h -> cxl-base.h
In reply to Michael NeulingThis moves the current include file from cxl.h -> cxl-base.h. This current include file is used only to pass information between the base driver that needs to be built into the kernel and the cxl module.
This is to make way for a new include/misc/cxl.h which will contain just the kernel API for other driver to use
---
MAINTAINERS | 2 +-
arch/powerpc/include/asm/pnv-pci.h | 2 +-
arch/powerpc/mm/copro_fault.c | 2 +-
arch/powerpc/mm/hash_native_64.c | 2 +-
arch/powerpc/platforms/powernv/pci-ioda.c | 2 +-
drivers/misc/cxl/base.c | 2 +-
drivers/misc/cxl/cxl.h | 2 +-
drivers/misc/cxl/irq.c | 2 +-
drivers/misc/cxl/main.c | 2 +-
drivers/misc/cxl/native.c | 2 +-
include/misc/{cxl.h => cxl-base.h} | 4 ++--
11 files changed, 12 insertions(+), 12 deletions(-)
rename include/misc/{cxl.h => cxl-base.h} (95%)MAINTAINERS +1 -1
@@ -2956,7 +2956,7 @@ M: Michael Neuling <[email protected]> L: [email protected] S: Supported F: drivers/misc/cxl/ -F: include/misc/cxl.h +F: include/misc/cxl* F: include/uapi/misc/cxl.h F: Documentation/powerpc/cxl.txt F: Documentation/powerpc/cxl.txt
arch/powerpc/include/asm/pnv-pci.h +1 -1
@@ -11,7 +11,7 @@#define _ASM_PNV_PCI_H#include <linux/pci.h> -#include <misc/cxl.h> +#include <misc/cxl-base.h> int pnv_phb_to_cxl_mode (struct pci_dev *dev,uint64_t mode); int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq,
arch/powerpc/mm/copro_fault.c +1 -1
@@ -26,7 +26,7 @@#include <asm/reg.h> #include <asm/copro.h> #include <asm/spu.h> -#include <misc/cxl.h> +#include <misc/cxl-base.h> /* * This ought to be kept in sync with the powerpc specific do_page_fault
arch/powerpc/mm/hash_native_64.c +1 -1
@@ -29,7 +29,7 @@#include <asm/kexec.h> #include <asm/ppc-opcode.h> -#include <misc/cxl.h> +#include <misc/cxl-base.h> #ifdef DEBUG_LOW #define DBG_LOW(fmt...) udbg_printf(fmt)
arch/powerpc/platforms/powernv/pci-ioda.c +1 -1
@@ -39,7 +39,7 @@#include <asm/firmware.h> #include <asm/pnv-pci.h> -#include <misc/cxl.h> +#include <misc/cxl-base.h> #include "powernv.h" #include "pci.h"
drivers/misc/cxl/base.c +1 -1
@@ -10,7 +10,7 @@#include <linux/module.h> #include <linux/rcupdate.h> #include <asm/errno.h> -#include <misc/cxl.h> +#include <misc/cxl-base.h> #include "cxl.h" /* protected by rcu */
drivers/misc/cxl/cxl.h +1 -1
@@ -21,7 +21,7 @@#include <asm/cputable.h> #include <asm/mmu.h> #include <asm/reg.h> -#include <misc/cxl.h> +#include <misc/cxl-base.h> #include <uapi/misc/cxl.h>
drivers/misc/cxl/irq.c +1 -1
@@ -14,7 +14,7 @@#include <linux/slab.h> #include <linux/pid.h> #include <asm/cputable.h> -#include <misc/cxl.h> +#include <misc/cxl-base.h> #include "cxl.h" #include "trace.h"
drivers/misc/cxl/main.c +1 -1
@@ -20,7 +20,7 @@#include <linux/idr.h> #include <linux/pci.h> #include <asm/cputable.h> -#include <misc/cxl.h> +#include <misc/cxl-base.h> #include "cxl.h" #include "trace.h"
drivers/misc/cxl/native.c +1 -1
@@ -15,7 +15,7 @@#include <linux/mm.h> #include <linux/uaccess.h> #include <asm/synch.h> -#include <misc/cxl.h> +#include <misc/cxl-base.h> #include "cxl.h" #include "trace.h"
include/misc/cxl-base.h renamed from include/misc/cxl.h +2 -2
@@ -7,8 +7,8 @@* 2 of the License, or (at your option) any later version. */ -#ifndef _MISC_CXL_H -#define _MISC_CXL_H +#ifndef _MISC_CXL_BASE_H +#define _MISC_CXL_BASE_H#ifdef CONFIG_CXL_BASE
Signature · 1 line
2.1.0
PATCH v3 23/24 cxl: Export file ops for use by API
In reply to Michael NeulingThe cxl kernel API will allow drivers other than cxl to export a file descriptor which has the same userspace API. These file descriptors will be able to be used against libcxl.
This exports those file ops for use by other drivers.
--- drivers/misc/cxl/cxl.h | 9 +++++++++ drivers/misc/cxl/file.c | 23 ++++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-)
drivers/misc/cxl/cxl.h +9 -0
@@ -18,6 +18,7 @@#include <linux/pid.h> #include <linux/io.h> #include <linux/pci.h> +#include <linux/fs.h> #include <asm/cputable.h> #include <asm/mmu.h> #include <asm/reg.h>
@@ -670,4 +671,12 @@ void cxl_stop_trace(struct cxl *cxl);extern struct pci_driver cxl_pci_driver;int afu_allocate_irqs (struct cxl_context *ctx,u32 count); +int afu_open (struct inode *inode,struct file *file); +int afu_release (struct inode *inode,struct file *file); +long afu_ioctl (struct file *file,unsigned int cmd,unsigned long arg); +int afu_mmap (struct file *file,struct vm_area_struct *vm); +unsigned int afu_poll (struct file *file,struct poll_table_struct *poll); +ssize_t afu_read (struct file *file,char __user *buf,size_t count,loff_t *off); +extern const struct file_operations afu_fops; +#endif
drivers/misc/cxl/file.c +14 -9
@@ -96,7 +96,8 @@ err_put_adapter:put_device (&adapter->dev);return rc; } -static int afu_open (struct inode *inode,struct file *file) + +int afu_open (struct inode *inode,struct file *file) {return __afu_open (inode, file, false); }
@@ -106,7 +107,7 @@ static int afu_master_open(struct inode *inode, struct file *file)return __afu_open (inode, file, true); } -static int afu_release (struct inode *inode,struct file *file) +int afu_release (struct inode *inode,struct file *file) {struct cxl_context *ctx = file->private_data;
@@ -211,7 +212,7 @@ static long afu_ioctl_process_element(struct cxl_context *ctx,return 0 ; } -static long afu_ioctl (struct file *file,unsigned int cmd,unsigned long arg) +long afu_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {struct cxl_context *ctx = file->private_data;
@@ -228,13 +229,13 @@ static long afu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)return -EINVAL ; } -static long afu_compat_ioctl (struct file *file,unsigned int cmd, +long afu_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {return afu_ioctl (file, cmd, arg); } -static int afu_mmap (struct file *file,struct vm_area_struct *vm) +int afu_mmap (struct file *file,struct vm_area_struct *vm) {struct cxl_context *ctx = file->private_data;
@@ -245,7 +246,7 @@ static int afu_mmap(struct file *file, struct vm_area_struct *vm)return cxl_context_iomap (ctx, vm); } -static unsigned int afu_poll (struct file *file,struct poll_table_struct *poll) +unsigned int afu_poll (struct file *file,struct poll_table_struct *poll) {struct cxl_context *ctx = file->private_data;int mask =0 ;
@@ -277,7 +278,7 @@ static inline int ctx_event_pending(struct cxl_context *ctx) ctx->pending_afu_err || (ctx->status == CLOSED)); } -static ssize_t afu_read (struct file *file,char __user *buf,size_t count, +ssize_t afu_read (struct file *file,char __user *buf,size_t count,loff_t *off) {struct cxl_context *ctx = file->private_data;
@@ -358,7 +359,11 @@ out:return rc; } -static const struct file_operations afu_fops = { +/* +* Note: if this is updated, we need to update api.c to patch the new ones in +* too +*/ +const struct file_operations afu_fops = { .owner =THIS_MODULE , .open = afu_open, .poll = afu_poll,
@@ -369,7 +374,7 @@ static const struct file_operations afu_fops = { .mmap = afu_mmap, }; -static const struct file_operations afu_master_fops = { +const struct file_operations afu_master_fops = { .owner =THIS_MODULE , .open = afu_master_open, .poll = afu_poll,
Signature · 1 line
2.1.0
PATCH v3 24/24 cxl: Add AFU virtual PHB and kernel API
In reply to Michael NeulingThis patch does two things.
Firstly it presents the Accelerator Function Unit (AFUs) behind the POWER Service Layer (PSL) as PCI devices on a virtual PCI Host Bridge (vPHB). This in in addition to the PSL being a PCI device itself.
As part of the Coherent Accelerator Interface Architecture (CAIA) AFUs can provide an AFU configuration. This AFU configuration recored is architected to be the same as a PCI config space.
This patch sets discovers the AFU configuration records, provides AFU config space read/write functions to these configuration records. It then enumerates the PCI bus. It also hooks in PCI ops where appropriate. It also destroys the vPHB when the physical card is removed.
Secondly, it add an in kernel API for AFU to use CXL. AFUs must present a driver that firstly binds as a PCI device. This PCI device can then be using to do CXL specific operations (that can't sit in the PCI ops) using this API.
--- drivers/misc/cxl/Makefile | 1 + drivers/misc/cxl/api.c | 331 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/misc/cxl/cxl.h | 5 + drivers/misc/cxl/pci.c | 17 ++- drivers/misc/cxl/vphb.c | 269 +++++++++++++++++++++++++++++++++++++ include/misc/cxl.h | 203 ++++++++++++++++++++++++++++ 6 files changed, 822 insertions(+), 4 deletions(-) create mode 100644 drivers/misc/cxl/api.c create mode 100644 drivers/misc/cxl/vphb.c create mode 100644 include/misc/cxl.h
drivers/misc/cxl/Makefile +1 -0
@@ -1,5 +1,6 @@ cxl-y += main.o file.o irq.o fault.o native.o cxl-y += context.o sysfs.o debugfs.o pci.o trace.o +cxl-y += vphb.o api.o obj-$(CONFIG_CXL) += cxl.o obj-$(CONFIG_CXL_BASE) += base.o
drivers/misc/cxl/api.c new file +331 -0
331 lines not on this page · raw message
drivers/misc/cxl/cxl.h +5 -0
@@ -377,6 +377,9 @@ struct cxl_afu {int spa_max_procs;unsigned int psl_virq; +/* pointer to the vphb */ +struct pci_controller *phb; +int pp_irqs;int irqs_max;int num_procs;
@@ -667,6 +670,8 @@ int cxl_afu_check_and_enable(struct cxl_afu *afu);int cxl_psl_purge (struct cxl_afu *afu);void cxl_stop_trace (struct cxl *cxl); +int cxl_pci_vphb_add (struct cxl_afu *afu); +void cxl_pci_vphb_remove (struct cxl_afu *afu);extern struct pci_driver cxl_pci_driver;int afu_allocate_irqs (struct cxl_context *ctx,u32 count);
drivers/misc/cxl/pci.c +13 -4
@@ -741,6 +741,9 @@ static int cxl_init_afu(struct cxl *adapter, int slice, struct pci_dev *dev) adapter->afu[afu->slice] = afu; +if ((rc =cxl_pci_vphb_add (afu))) +dev_info (&afu->dev,"Can't register vPHB\n" ); +return 0 ; err_put2:
@@ -793,8 +796,10 @@ int cxl_reset(struct cxl *adapter)dev_info (&dev->dev,"CXL reset\n" ); -for (i =0 ; i < adapter->slices; i++) +for (i =0 ; i < adapter->slices; i++) { +cxl_pci_vphb_remove (adapter->afu[i]);cxl_remove_afu (adapter->afu[i]); + }/* pcie_warm_reset requests a fundamental pci reset which includes a * PERST assert/deassert. PERST triggers a loading of the image
@@ -1128,14 +1133,18 @@ static int cxl_probe(struct pci_dev *dev, const struct pci_device_id *id)static void cxl_remove (struct pci_dev *dev) {struct cxl *adapter =pci_get_drvdata (dev); -int afu; +struct cxl_afu *afu; +int i;/* * Lock to prevent someone grabbing a ref through the adapter list as * we are removing it */ -for (afu =0 ; afu < adapter->slices; afu++) -cxl_remove_afu (adapter->afu[afu]); +for (i =0 ; i < adapter->slices; i++) { + afu = adapter->afu[i]; +cxl_pci_vphb_remove (afu); +cxl_remove_afu (afu); + }cxl_remove_adapter (adapter); }
drivers/misc/cxl/vphb.c new file +269 -0
269 lines not on this page · raw message
include/misc/cxl.h new file +203 -0
203 lines not on this page · raw message
Signature · 1 line
2.1.0