diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-07-31 00:01:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-07-31 00:01:36 -0400 |
commit | bad60e6f259a01cf9f29a1ef8d435ab6c60b2de9 (patch) | |
tree | c9aaa8166735659761239c117af2b11b022bc6cb /drivers/misc/cxl/api.c | |
parent | dd0f0cf58af70dc9267409f113bea772d57f675c (diff) | |
parent | 719dbb2df78fc9a40e28392b07cd715bfc5a665c (diff) |
Merge tag 'powerpc-4.8-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux
Pull powerpc updates from Michael Ellerman:
"Highlights:
- PowerNV PCI hotplug support.
- Lots more Power9 support.
- eBPF JIT support on ppc64le.
- Lots of cxl updates.
- Boot code consolidation.
Bug fixes:
- Fix spin_unlock_wait() from Boqun Feng
- Fix stack pointer corruption in __tm_recheckpoint() from Michael
Neuling
- Fix multiple bugs in memory_hotplug_max() from Bharata B Rao
- mm: Ensure "special" zones are empty from Oliver O'Halloran
- ftrace: Separate the heuristics for checking call sites from
Michael Ellerman
- modules: Never restore r2 for a mprofile-kernel style mcount() call
from Michael Ellerman
- Fix endianness when reading TCEs from Alexey Kardashevskiy
- start rtasd before PCI probing from Greg Kurz
- PCI: rpaphp: Fix slot registration for multiple slots under a PHB
from Tyrel Datwyler
- powerpc/mm: Add memory barrier in __hugepte_alloc() from Sukadev
Bhattiprolu
Cleanups & fixes:
- Drop support for MPIC in pseries from Rashmica Gupta
- Define and use PPC64_ELF_ABI_v2/v1 from Michael Ellerman
- Remove unused symbols in asm-offsets.c from Rashmica Gupta
- Fix SRIOV not building without EEH enabled from Russell Currey
- Remove kretprobe_trampoline_holder from Thiago Jung Bauermann
- Reduce log level of PCI I/O space warning from Benjamin
Herrenschmidt
- Add array bounds checking to crash_shutdown_handlers from Suraj
Jitindar Singh
- Avoid -maltivec when using clang integrated assembler from Anton
Blanchard
- Fix array overrun in ppc_rtas() syscall from Andrew Donnellan
- Fix error return value in cmm_mem_going_offline() from Rasmus
Villemoes
- export cpu_to_core_id() from Mauricio Faria de Oliveira
- Remove old symbols from defconfigs from Andrew Donnellan
- Update obsolete comments in setup_32.c about entry conditions from
Benjamin Herrenschmidt
- Add comment explaining the purpose of setup_kdump_trampoline() from
Benjamin Herrenschmidt
- Merge the RELOCATABLE config entries for ppc32 and ppc64 from Kevin
Hao
- Remove RELOCATABLE_PPC32 from Kevin Hao
- Fix .long's in tlb-radix.c to more meaningful from Balbir Singh
Minor cleanups & fixes:
- Andrew Donnellan, Anna-Maria Gleixner, Anton Blanchard, Benjamin
Herrenschmidt, Bharata B Rao, Christophe Leroy, Colin Ian King,
Geliang Tang, Greg Kurz, Madhavan Srinivasan, Michael Ellerman,
Michael Ellerman, Stephen Rothwell, Stewart Smith.
Freescale updates from Scott:
- "Highlights include more 8xx optimizations, device tree updates,
and MVME7100 support."
PowerNV PCI hotplug from Gavin Shan:
- PCI: Add pcibios_setup_bridge()
- Override pcibios_setup_bridge()
- Remove PCI_RESET_DELAY_US
- Move pnv_pci_ioda_setup_opal_tce_kill() around
- Increase PE# capacity
- Allocate PE# in reverse order
- Create PEs in pcibios_setup_bridge()
- Setup PE for root bus
- Extend PCI bridge resources
- Make pnv_ioda_deconfigure_pe() visible
- Dynamically release PE
- Update bridge windows on PCI plug
- Delay populating pdn
- Support PCI slot ID
- Use PCI slot reset infrastructure
- Introduce pnv_pci_get_slot_id()
- Functions to get/set PCI slot state
- PCI/hotplug: PowerPC PowerNV PCI hotplug driver
- Print correct PHB type names
Power9 idle support from Shreyas B. Prabhu:
- set power_save func after the idle states are initialized
- Use PNV_THREAD_WINKLE macro while requesting for winkle
- make hypervisor state restore a function
- Rename idle_power7.S to idle_book3s.S
- Rename reusable idle functions to hardware agnostic names
- Make pnv_powersave_common more generic
- abstraction for saving SPRs before entering deep idle states
- Add platform support for stop instruction
- cpuidle/powernv: Use CPUIDLE_STATE_MAX instead of MAX_POWERNV_IDLE_STATES
- cpuidle/powernv: cleanup cpuidle-powernv.c
- cpuidle/powernv: Add support for POWER ISA v3 idle states
- Use deepest stop state when cpu is offlined
Power9 PMU from Madhavan Srinivasan:
- factor out power8 pmu macros and defines
- factor out power8 pmu functions
- factor out power8 __init_pmu code
- Add power9 event list macros for generic and cache events
- Power9 PMU support
- Export Power9 generic and cache events to sysfs
Power9 preliminary interrupt & PCI support from Benjamin Herrenschmidt:
- Add XICS emulation APIs
- Move a few exception common handlers to make room
- Add support for HV virtualization interrupts
- Add mechanism to force a replay of interrupts
- Add ICP OPAL backend
- Discover IODA3 PHBs
- pci: Remove obsolete SW invalidate
- opal: Add real mode call wrappers
- Rename TCE invalidation calls
- Remove SWINV constants and obsolete TCE code
- Rework accessing the TCE invalidate register
- Fallback to OPAL for TCE invalidations
- Use the device-tree to get available range of M64's
- Check status of a PHB before using it
- pci: Don't try to allocate resources that will be reassigned
Other Power9:
- Send SIGBUS on unaligned copy and paste from Chris Smart
- Large Decrementer support from Oliver O'Halloran
- Load Monitor Register Support from Jack Miller
Performance improvements from Anton Blanchard:
- Avoid load hit store in __giveup_fpu() and __giveup_altivec()
- Avoid load hit store in setup_sigcontext()
- Remove assembly versions of strcpy, strcat, strlen and strcmp
- Align hot loops of some string functions
eBPF JIT from Naveen N. Rao:
- Fix/enhance 32-bit Load Immediate implementation
- Optimize 64-bit Immediate loads
- Introduce rotate immediate instructions
- A few cleanups
- Isolate classic BPF JIT specifics into a separate header
- Implement JIT compiler for extended BPF
Operator Panel driver from Suraj Jitindar Singh:
- devicetree/bindings: Add binding for operator panel on FSP machines
- Add inline function to get rc from an ASYNC_COMP opal_msg
- Add driver for operator panel on FSP machines
Sparse fixes from Daniel Axtens:
- make some things static
- Introduce asm-prototypes.h
- Include headers containing prototypes
- Use #ifdef __BIG_ENDIAN__ #else for REG_BYTE
- kvm: Clarify __user annotations
- Pass endianness to sparse
- Make ppc_md.{halt, restart} __noreturn
MM fixes & cleanups from Aneesh Kumar K.V:
- radix: Update LPCR HR bit as per ISA
- use _raw variant of page table accessors
- Compile out radix related functions if RADIX_MMU is disabled
- Clear top 16 bits of va only on older cpus
- Print formation regarding the the MMU mode
- hash: Update SDR1 size encoding as documented in ISA 3.0
- radix: Update PID switch sequence
- radix: Update machine call back to support new HCALL.
- radix: Add LPID based tlb flush helpers
- radix: Add a kernel command line to disable radix
- Cleanup LPCR defines
Boot code consolidation from Benjamin Herrenschmidt:
- Move epapr_paravirt_early_init() to early_init_devtree()
- cell: Don't use flat device-tree after boot
- ge_imp3a: Don't use the flat device-tree after boot
- mpc85xx_ds: Don't use the flat device-tree after boot
- mpc85xx_rdb: Don't use the flat device-tree after boot
- Don't test for machine type in rtas_initialize()
- Don't test for machine type in smp_setup_cpu_maps()
- dt: Add of_device_compatible_match()
- Factor do_feature_fixup calls
- Move 64-bit feature fixup earlier
- Move 64-bit memory reserves to setup_arch()
- Use a cachable DART
- Move FW feature probing out of pseries probe()
- Put exception configuration in a common place
- Remove early allocation of the SMU command buffer
- Move MMU backend selection out of platform code
- pasemi: Remove IOBMAP allocation from platform probe()
- mm/hash: Don't use machine_is() early during boot
- Don't test for machine type to detect HEA special case
- pmac: Remove spurrious machine type test
- Move hash table ops to a separate structure
- Ensure that ppc_md is empty before probing for machine type
- Move 64-bit probe_machine() to later in the boot process
- Move 32-bit probe() machine to later in the boot process
- Get rid of ppc_md.init_early()
- Move the boot time info banner to a separate function
- Move setting of {i,d}cache_bsize to initialize_cache_info()
- Move the content of setup_system() to setup_arch()
- Move cache info inits to a separate function
- Re-order the call to smp_setup_cpu_maps()
- Re-order setup_panic()
- Make a few boot functions __init
- Merge 32-bit and 64-bit setup_arch()
Other new features:
- tty/hvc: Use IRQF_SHARED for OPAL hvc consoles from Sam Mendoza-Jonas
- tty/hvc: Use opal irqchip interface if available from Sam Mendoza-Jonas
- powerpc: Add module autoloading based on CPU features from Alastair D'Silva
- crypto: vmx - Convert to CPU feature based module autoloading from Alastair D'Silva
- Wake up kopald polling thread before waiting for events from Benjamin Herrenschmidt
- xmon: Dump ISA 2.06 SPRs from Michael Ellerman
- xmon: Dump ISA 2.07 SPRs from Michael Ellerman
- Add a parameter to disable 1TB segs from Oliver O'Halloran
- powerpc/boot: Add OPAL console to epapr wrappers from Oliver O'Halloran
- Assign fixed PHB number based on device-tree properties from Guilherme G. Piccoli
- pseries: Add pseries hotplug workqueue from John Allen
- pseries: Add support for hotplug interrupt source from John Allen
- pseries: Use kernel hotplug queue for PowerVM hotplug events from John Allen
- pseries: Move property cloning into its own routine from Nathan Fontenot
- pseries: Dynamic add entires to associativity lookup array from Nathan Fontenot
- pseries: Auto-online hotplugged memory from Nathan Fontenot
- pseries: Remove call to memblock_add() from Nathan Fontenot
cxl:
- Add set and get private data to context struct from Michael Neuling
- make base more explicitly non-modular from Paul Gortmaker
- Use for_each_compatible_node() macro from Wei Yongjun
- Frederic Barrat
- Abstract the differences between the PSL and XSL
- Make vPHB device node match adapter's
- Philippe Bergheaud
- Add mechanism for delivering AFU driver specific events
- Ignore CAPI adapters misplaced in switched slots
- Refine slice error debug messages
- Andrew Donnellan
- static-ify variables to fix sparse warnings
- PCI/hotplug: pnv_php: export symbols and move struct types needed by cxl
- PCI/hotplug: pnv_php: handle OPAL_PCI_SLOT_OFFLINE power state
- Add cxl_check_and_switch_mode() API to switch bi-modal cards
- remove dead Kconfig options
- fix potential NULL dereference in free_adapter()
- Ian Munsie
- Update process element after allocating interrupts
- Add support for CAPP DMA mode
- Fix allowing bogus AFU descriptors with 0 maximum processes
- Fix allocating a minimum of 2 pages for the SPA
- Fix bug where AFU disable operation had no effect
- Workaround XSL bug that does not clear the RA bit after a reset
- Fix NULL pointer dereference on kernel contexts with no AFU interrupts
- powerpc/powernv: Split cxl code out into a separate file
- Add cxl_slot_is_supported API
- Enable bus mastering for devices using CAPP DMA mode
- Move cxl_afu_get / cxl_afu_put to base
- Allow a default context to be associated with an external pci_dev
- Do not create vPHB if there are no AFU configuration records
- powerpc/powernv: Add support for the cxl kernel api on the real phb
- Add support for using the kernel API with a real PHB
- Add kernel APIs to get & set the max irqs per context
- Add preliminary workaround for CX4 interrupt limitation
- Add support for interrupts on the Mellanox CX4
- Workaround PE=0 hardware limitation in Mellanox CX4
- powerpc/powernv: Fix pci-cxl.c build when CONFIG_MODULES=n
selftests:
- Test unaligned copy and paste from Chris Smart
- Load Monitor Register Tests from Jack Miller
- Cyril Bur
- exec() with suspended transaction
- Use signed long to read perf_event_paranoid
- Fix usage message in context_switch
- Fix generation of vector instructions/types in context_switch
- Michael Ellerman
- Use "Delta" rather than "Error" in normal output
- Import Anton's mmap & futex micro benchmarks
- Add a test for PROT_SAO"
* tag 'powerpc-4.8-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: (263 commits)
powerpc/mm: Parenthesise IS_ENABLED() in if condition
tty/hvc: Use opal irqchip interface if available
tty/hvc: Use IRQF_SHARED for OPAL hvc consoles
selftests/powerpc: exec() with suspended transaction
powerpc: Improve comment explaining why we modify VRSAVE
powerpc/mm: Drop unused externs for hpte_init_beat[_v3]()
powerpc/mm: Rename hpte_init_lpar() and move the fallback to a header
powerpc/mm: Fix build break when PPC_NATIVE=n
crypto: vmx - Convert to CPU feature based module autoloading
powerpc: Add module autoloading based on CPU features
powerpc/powernv/ioda: Fix endianness when reading TCEs
powerpc/mm: Add memory barrier in __hugepte_alloc()
powerpc/modules: Never restore r2 for a mprofile-kernel style mcount() call
powerpc/ftrace: Separate the heuristics for checking call sites
powerpc: Merge 32-bit and 64-bit setup_arch()
powerpc/64: Make a few boot functions __init
powerpc: Re-order setup_panic()
powerpc: Re-order the call to smp_setup_cpu_maps()
powerpc/32: Move cache info inits to a separate function
powerpc/64: Move the content of setup_system() to setup_arch()
...
Diffstat (limited to 'drivers/misc/cxl/api.c')
-rw-r--r-- | drivers/misc/cxl/api.c | 168 |
1 files changed, 167 insertions, 1 deletions
diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c index 6d228ccd884d..f3d34b941f85 100644 --- a/drivers/misc/cxl/api.c +++ b/drivers/misc/cxl/api.c | |||
@@ -13,6 +13,8 @@ | |||
13 | #include <linux/file.h> | 13 | #include <linux/file.h> |
14 | #include <misc/cxl.h> | 14 | #include <misc/cxl.h> |
15 | #include <linux/fs.h> | 15 | #include <linux/fs.h> |
16 | #include <asm/pnv-pci.h> | ||
17 | #include <linux/msi.h> | ||
16 | 18 | ||
17 | #include "cxl.h" | 19 | #include "cxl.h" |
18 | 20 | ||
@@ -24,6 +26,8 @@ struct cxl_context *cxl_dev_context_init(struct pci_dev *dev) | |||
24 | int rc; | 26 | int rc; |
25 | 27 | ||
26 | afu = cxl_pci_to_afu(dev); | 28 | afu = cxl_pci_to_afu(dev); |
29 | if (IS_ERR(afu)) | ||
30 | return ERR_CAST(afu); | ||
27 | 31 | ||
28 | ctx = cxl_context_alloc(); | 32 | ctx = cxl_context_alloc(); |
29 | if (IS_ERR(ctx)) { | 33 | if (IS_ERR(ctx)) { |
@@ -94,6 +98,42 @@ static irq_hw_number_t cxl_find_afu_irq(struct cxl_context *ctx, int num) | |||
94 | return 0; | 98 | return 0; |
95 | } | 99 | } |
96 | 100 | ||
101 | int _cxl_next_msi_hwirq(struct pci_dev *pdev, struct cxl_context **ctx, int *afu_irq) | ||
102 | { | ||
103 | if (*ctx == NULL || *afu_irq == 0) { | ||
104 | *afu_irq = 1; | ||
105 | *ctx = cxl_get_context(pdev); | ||
106 | } else { | ||
107 | (*afu_irq)++; | ||
108 | if (*afu_irq > cxl_get_max_irqs_per_process(pdev)) { | ||
109 | *ctx = list_next_entry(*ctx, extra_irq_contexts); | ||
110 | *afu_irq = 1; | ||
111 | } | ||
112 | } | ||
113 | return cxl_find_afu_irq(*ctx, *afu_irq); | ||
114 | } | ||
115 | /* Exported via cxl_base */ | ||
116 | |||
117 | int cxl_set_priv(struct cxl_context *ctx, void *priv) | ||
118 | { | ||
119 | if (!ctx) | ||
120 | return -EINVAL; | ||
121 | |||
122 | ctx->priv = priv; | ||
123 | |||
124 | return 0; | ||
125 | } | ||
126 | EXPORT_SYMBOL_GPL(cxl_set_priv); | ||
127 | |||
128 | void *cxl_get_priv(struct cxl_context *ctx) | ||
129 | { | ||
130 | if (!ctx) | ||
131 | return ERR_PTR(-EINVAL); | ||
132 | |||
133 | return ctx->priv; | ||
134 | } | ||
135 | EXPORT_SYMBOL_GPL(cxl_get_priv); | ||
136 | |||
97 | int cxl_allocate_afu_irqs(struct cxl_context *ctx, int num) | 137 | int cxl_allocate_afu_irqs(struct cxl_context *ctx, int num) |
98 | { | 138 | { |
99 | int res; | 139 | int res; |
@@ -102,7 +142,10 @@ int cxl_allocate_afu_irqs(struct cxl_context *ctx, int num) | |||
102 | if (num == 0) | 142 | if (num == 0) |
103 | num = ctx->afu->pp_irqs; | 143 | num = ctx->afu->pp_irqs; |
104 | res = afu_allocate_irqs(ctx, num); | 144 | res = afu_allocate_irqs(ctx, num); |
105 | if (!res && !cpu_has_feature(CPU_FTR_HVMODE)) { | 145 | if (res) |
146 | return res; | ||
147 | |||
148 | if (!cpu_has_feature(CPU_FTR_HVMODE)) { | ||
106 | /* In a guest, the PSL interrupt is not multiplexed. It was | 149 | /* In a guest, the PSL interrupt is not multiplexed. It was |
107 | * allocated above, and we need to set its handler | 150 | * allocated above, and we need to set its handler |
108 | */ | 151 | */ |
@@ -110,6 +153,13 @@ int cxl_allocate_afu_irqs(struct cxl_context *ctx, int num) | |||
110 | if (hwirq) | 153 | if (hwirq) |
111 | cxl_map_irq(ctx->afu->adapter, hwirq, cxl_ops->psl_interrupt, ctx, "psl"); | 154 | cxl_map_irq(ctx->afu->adapter, hwirq, cxl_ops->psl_interrupt, ctx, "psl"); |
112 | } | 155 | } |
156 | |||
157 | if (ctx->status == STARTED) { | ||
158 | if (cxl_ops->update_ivtes) | ||
159 | cxl_ops->update_ivtes(ctx); | ||
160 | else WARN(1, "BUG: cxl_allocate_afu_irqs must be called prior to starting the context on this platform\n"); | ||
161 | } | ||
162 | |||
113 | return res; | 163 | return res; |
114 | } | 164 | } |
115 | EXPORT_SYMBOL_GPL(cxl_allocate_afu_irqs); | 165 | EXPORT_SYMBOL_GPL(cxl_allocate_afu_irqs); |
@@ -323,6 +373,23 @@ struct cxl_context *cxl_fops_get_context(struct file *file) | |||
323 | } | 373 | } |
324 | EXPORT_SYMBOL_GPL(cxl_fops_get_context); | 374 | EXPORT_SYMBOL_GPL(cxl_fops_get_context); |
325 | 375 | ||
376 | void cxl_set_driver_ops(struct cxl_context *ctx, | ||
377 | struct cxl_afu_driver_ops *ops) | ||
378 | { | ||
379 | WARN_ON(!ops->fetch_event || !ops->event_delivered); | ||
380 | atomic_set(&ctx->afu_driver_events, 0); | ||
381 | ctx->afu_driver_ops = ops; | ||
382 | } | ||
383 | EXPORT_SYMBOL_GPL(cxl_set_driver_ops); | ||
384 | |||
385 | void cxl_context_events_pending(struct cxl_context *ctx, | ||
386 | unsigned int new_events) | ||
387 | { | ||
388 | atomic_add(new_events, &ctx->afu_driver_events); | ||
389 | wake_up_all(&ctx->wq); | ||
390 | } | ||
391 | EXPORT_SYMBOL_GPL(cxl_context_events_pending); | ||
392 | |||
326 | int cxl_start_work(struct cxl_context *ctx, | 393 | int cxl_start_work(struct cxl_context *ctx, |
327 | struct cxl_ioctl_start_work *work) | 394 | struct cxl_ioctl_start_work *work) |
328 | { | 395 | { |
@@ -390,7 +457,106 @@ EXPORT_SYMBOL_GPL(cxl_perst_reloads_same_image); | |||
390 | ssize_t cxl_read_adapter_vpd(struct pci_dev *dev, void *buf, size_t count) | 457 | ssize_t cxl_read_adapter_vpd(struct pci_dev *dev, void *buf, size_t count) |
391 | { | 458 | { |
392 | struct cxl_afu *afu = cxl_pci_to_afu(dev); | 459 | struct cxl_afu *afu = cxl_pci_to_afu(dev); |
460 | if (IS_ERR(afu)) | ||
461 | return -ENODEV; | ||
393 | 462 | ||
394 | return cxl_ops->read_adapter_vpd(afu->adapter, buf, count); | 463 | return cxl_ops->read_adapter_vpd(afu->adapter, buf, count); |
395 | } | 464 | } |
396 | EXPORT_SYMBOL_GPL(cxl_read_adapter_vpd); | 465 | EXPORT_SYMBOL_GPL(cxl_read_adapter_vpd); |
466 | |||
467 | int cxl_set_max_irqs_per_process(struct pci_dev *dev, int irqs) | ||
468 | { | ||
469 | struct cxl_afu *afu = cxl_pci_to_afu(dev); | ||
470 | if (IS_ERR(afu)) | ||
471 | return -ENODEV; | ||
472 | |||
473 | if (irqs > afu->adapter->user_irqs) | ||
474 | return -EINVAL; | ||
475 | |||
476 | /* Limit user_irqs to prevent the user increasing this via sysfs */ | ||
477 | afu->adapter->user_irqs = irqs; | ||
478 | afu->irqs_max = irqs; | ||
479 | |||
480 | return 0; | ||
481 | } | ||
482 | EXPORT_SYMBOL_GPL(cxl_set_max_irqs_per_process); | ||
483 | |||
484 | int cxl_get_max_irqs_per_process(struct pci_dev *dev) | ||
485 | { | ||
486 | struct cxl_afu *afu = cxl_pci_to_afu(dev); | ||
487 | if (IS_ERR(afu)) | ||
488 | return -ENODEV; | ||
489 | |||
490 | return afu->irqs_max; | ||
491 | } | ||
492 | EXPORT_SYMBOL_GPL(cxl_get_max_irqs_per_process); | ||
493 | |||
494 | /* | ||
495 | * This is a special interrupt allocation routine called from the PHB's MSI | ||
496 | * setup function. When capi interrupts are allocated in this manner they must | ||
497 | * still be associated with a running context, but since the MSI APIs have no | ||
498 | * way to specify this we use the default context associated with the device. | ||
499 | * | ||
500 | * The Mellanox CX4 has a hardware limitation that restricts the maximum AFU | ||
501 | * interrupt number, so in order to overcome this their driver informs us of | ||
502 | * the restriction by setting the maximum interrupts per context, and we | ||
503 | * allocate additional contexts as necessary so that we can keep the AFU | ||
504 | * interrupt number within the supported range. | ||
505 | */ | ||
506 | int _cxl_cx4_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type) | ||
507 | { | ||
508 | struct cxl_context *ctx, *new_ctx, *default_ctx; | ||
509 | int remaining; | ||
510 | int rc; | ||
511 | |||
512 | ctx = default_ctx = cxl_get_context(pdev); | ||
513 | if (WARN_ON(!default_ctx)) | ||
514 | return -ENODEV; | ||
515 | |||
516 | remaining = nvec; | ||
517 | while (remaining > 0) { | ||
518 | rc = cxl_allocate_afu_irqs(ctx, min(remaining, ctx->afu->irqs_max)); | ||
519 | if (rc) { | ||
520 | pr_warn("%s: Failed to find enough free MSIs\n", pci_name(pdev)); | ||
521 | return rc; | ||
522 | } | ||
523 | remaining -= ctx->afu->irqs_max; | ||
524 | |||
525 | if (ctx != default_ctx && default_ctx->status == STARTED) { | ||
526 | WARN_ON(cxl_start_context(ctx, | ||
527 | be64_to_cpu(default_ctx->elem->common.wed), | ||
528 | NULL)); | ||
529 | } | ||
530 | |||
531 | if (remaining > 0) { | ||
532 | new_ctx = cxl_dev_context_init(pdev); | ||
533 | if (!new_ctx) { | ||
534 | pr_warn("%s: Failed to allocate enough contexts for MSIs\n", pci_name(pdev)); | ||
535 | return -ENOSPC; | ||
536 | } | ||
537 | list_add(&new_ctx->extra_irq_contexts, &ctx->extra_irq_contexts); | ||
538 | ctx = new_ctx; | ||
539 | } | ||
540 | } | ||
541 | |||
542 | return 0; | ||
543 | } | ||
544 | /* Exported via cxl_base */ | ||
545 | |||
546 | void _cxl_cx4_teardown_msi_irqs(struct pci_dev *pdev) | ||
547 | { | ||
548 | struct cxl_context *ctx, *pos, *tmp; | ||
549 | |||
550 | ctx = cxl_get_context(pdev); | ||
551 | if (WARN_ON(!ctx)) | ||
552 | return; | ||
553 | |||
554 | cxl_free_afu_irqs(ctx); | ||
555 | list_for_each_entry_safe(pos, tmp, &ctx->extra_irq_contexts, extra_irq_contexts) { | ||
556 | cxl_stop_context(pos); | ||
557 | cxl_free_afu_irqs(pos); | ||
558 | list_del(&pos->extra_irq_contexts); | ||
559 | cxl_release_context(pos); | ||
560 | } | ||
561 | } | ||
562 | /* Exported via cxl_base */ | ||