diff options
| author | Frederic Barrat <fbarrat@linux.vnet.ibm.com> | 2018-01-23 06:31:43 -0500 |
|---|---|---|
| committer | Michael Ellerman <mpe@ellerman.id.au> | 2018-01-23 19:42:59 -0500 |
| commit | 280b983ce2b8759722d911ea4b5af66e95d84e09 (patch) | |
| tree | d3f3ffe5ee5acd780749b690921e97c09aa76845 | |
| parent | aeddad1760aeb206d912b27b230269407efd5b06 (diff) | |
ocxl: Add a kernel API for other opencapi drivers
Some of the functions done by the generic driver should also be needed
by other opencapi drivers: attaching a context to an adapter,
translation fault handling, AFU interrupt allocation...
So to avoid code duplication, the driver provides a kernel API that
other drivers can use, similar to calling a in-kernel library.
It is still a bit theoretical, for lack of real hardware, and will
likely need adjustements down the road. But we used the cxlflash
driver as a guinea pig.
Signed-off-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
| -rw-r--r-- | drivers/misc/ocxl/config.c | 13 | ||||
| -rw-r--r-- | drivers/misc/ocxl/link.c | 7 | ||||
| -rw-r--r-- | drivers/misc/ocxl/ocxl_internal.h | 71 | ||||
| -rw-r--r-- | include/misc/ocxl.h | 214 |
4 files changed, 234 insertions, 71 deletions
diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c index ea8cca50ea06..2e30de9c694a 100644 --- a/drivers/misc/ocxl/config.c +++ b/drivers/misc/ocxl/config.c | |||
| @@ -2,8 +2,8 @@ | |||
| 2 | // Copyright 2017 IBM Corp. | 2 | // Copyright 2017 IBM Corp. |
| 3 | #include <linux/pci.h> | 3 | #include <linux/pci.h> |
| 4 | #include <asm/pnv-ocxl.h> | 4 | #include <asm/pnv-ocxl.h> |
| 5 | #include <misc/ocxl.h> | ||
| 5 | #include <misc/ocxl-config.h> | 6 | #include <misc/ocxl-config.h> |
| 6 | #include "ocxl_internal.h" | ||
| 7 | 7 | ||
| 8 | #define EXTRACT_BIT(val, bit) (!!(val & BIT(bit))) | 8 | #define EXTRACT_BIT(val, bit) (!!(val & BIT(bit))) |
| 9 | #define EXTRACT_BITS(val, s, e) ((val & GENMASK(e, s)) >> s) | 9 | #define EXTRACT_BITS(val, s, e) ((val & GENMASK(e, s)) >> s) |
| @@ -243,6 +243,7 @@ int ocxl_config_read_function(struct pci_dev *dev, struct ocxl_fn_config *fn) | |||
| 243 | rc = validate_function(dev, fn); | 243 | rc = validate_function(dev, fn); |
| 244 | return rc; | 244 | return rc; |
| 245 | } | 245 | } |
| 246 | EXPORT_SYMBOL_GPL(ocxl_config_read_function); | ||
| 246 | 247 | ||
| 247 | static int read_afu_info(struct pci_dev *dev, struct ocxl_fn_config *fn, | 248 | static int read_afu_info(struct pci_dev *dev, struct ocxl_fn_config *fn, |
| 248 | int offset, u32 *data) | 249 | int offset, u32 *data) |
| @@ -301,6 +302,7 @@ int ocxl_config_check_afu_index(struct pci_dev *dev, | |||
| 301 | } | 302 | } |
| 302 | return 1; | 303 | return 1; |
| 303 | } | 304 | } |
| 305 | EXPORT_SYMBOL_GPL(ocxl_config_check_afu_index); | ||
| 304 | 306 | ||
| 305 | static int read_afu_name(struct pci_dev *dev, struct ocxl_fn_config *fn, | 307 | static int read_afu_name(struct pci_dev *dev, struct ocxl_fn_config *fn, |
| 306 | struct ocxl_afu_config *afu) | 308 | struct ocxl_afu_config *afu) |
| @@ -498,6 +500,7 @@ int ocxl_config_read_afu(struct pci_dev *dev, struct ocxl_fn_config *fn, | |||
| 498 | rc = validate_afu(dev, afu); | 500 | rc = validate_afu(dev, afu); |
| 499 | return rc; | 501 | return rc; |
| 500 | } | 502 | } |
| 503 | EXPORT_SYMBOL_GPL(ocxl_config_read_afu); | ||
| 501 | 504 | ||
| 502 | int ocxl_config_get_actag_info(struct pci_dev *dev, u16 *base, u16 *enabled, | 505 | int ocxl_config_get_actag_info(struct pci_dev *dev, u16 *base, u16 *enabled, |
| 503 | u16 *supported) | 506 | u16 *supported) |
| @@ -516,6 +519,7 @@ int ocxl_config_get_actag_info(struct pci_dev *dev, u16 *base, u16 *enabled, | |||
| 516 | } | 519 | } |
| 517 | return 0; | 520 | return 0; |
| 518 | } | 521 | } |
| 522 | EXPORT_SYMBOL_GPL(ocxl_config_get_actag_info); | ||
| 519 | 523 | ||
| 520 | void ocxl_config_set_afu_actag(struct pci_dev *dev, int pos, int actag_base, | 524 | void ocxl_config_set_afu_actag(struct pci_dev *dev, int pos, int actag_base, |
| 521 | int actag_count) | 525 | int actag_count) |
| @@ -528,11 +532,13 @@ void ocxl_config_set_afu_actag(struct pci_dev *dev, int pos, int actag_base, | |||
| 528 | val = actag_base & OCXL_DVSEC_ACTAG_MASK; | 532 | val = actag_base & OCXL_DVSEC_ACTAG_MASK; |
| 529 | pci_write_config_dword(dev, pos + OCXL_DVSEC_AFU_CTRL_ACTAG_BASE, val); | 533 | pci_write_config_dword(dev, pos + OCXL_DVSEC_AFU_CTRL_ACTAG_BASE, val); |
| 530 | } | 534 | } |
| 535 | EXPORT_SYMBOL_GPL(ocxl_config_set_afu_actag); | ||
| 531 | 536 | ||
| 532 | int ocxl_config_get_pasid_info(struct pci_dev *dev, int *count) | 537 | int ocxl_config_get_pasid_info(struct pci_dev *dev, int *count) |
| 533 | { | 538 | { |
| 534 | return pnv_ocxl_get_pasid_count(dev, count); | 539 | return pnv_ocxl_get_pasid_count(dev, count); |
| 535 | } | 540 | } |
| 541 | EXPORT_SYMBOL_GPL(ocxl_config_get_pasid_info); | ||
| 536 | 542 | ||
| 537 | void ocxl_config_set_afu_pasid(struct pci_dev *dev, int pos, int pasid_base, | 543 | void ocxl_config_set_afu_pasid(struct pci_dev *dev, int pos, int pasid_base, |
| 538 | u32 pasid_count_log) | 544 | u32 pasid_count_log) |
| @@ -550,6 +556,7 @@ void ocxl_config_set_afu_pasid(struct pci_dev *dev, int pos, int pasid_base, | |||
| 550 | pci_write_config_dword(dev, pos + OCXL_DVSEC_AFU_CTRL_PASID_BASE, | 556 | pci_write_config_dword(dev, pos + OCXL_DVSEC_AFU_CTRL_PASID_BASE, |
| 551 | val32); | 557 | val32); |
| 552 | } | 558 | } |
| 559 | EXPORT_SYMBOL_GPL(ocxl_config_set_afu_pasid); | ||
| 553 | 560 | ||
| 554 | void ocxl_config_set_afu_state(struct pci_dev *dev, int pos, int enable) | 561 | void ocxl_config_set_afu_state(struct pci_dev *dev, int pos, int enable) |
| 555 | { | 562 | { |
| @@ -562,6 +569,7 @@ void ocxl_config_set_afu_state(struct pci_dev *dev, int pos, int enable) | |||
| 562 | val &= 0xFE; | 569 | val &= 0xFE; |
| 563 | pci_write_config_byte(dev, pos + OCXL_DVSEC_AFU_CTRL_ENABLE, val); | 570 | pci_write_config_byte(dev, pos + OCXL_DVSEC_AFU_CTRL_ENABLE, val); |
| 564 | } | 571 | } |
| 572 | EXPORT_SYMBOL_GPL(ocxl_config_set_afu_state); | ||
| 565 | 573 | ||
| 566 | int ocxl_config_set_TL(struct pci_dev *dev, int tl_dvsec) | 574 | int ocxl_config_set_TL(struct pci_dev *dev, int tl_dvsec) |
| 567 | { | 575 | { |
| @@ -660,6 +668,7 @@ out: | |||
| 660 | kfree(recv_rate); | 668 | kfree(recv_rate); |
| 661 | return rc; | 669 | return rc; |
| 662 | } | 670 | } |
| 671 | EXPORT_SYMBOL_GPL(ocxl_config_set_TL); | ||
| 663 | 672 | ||
| 664 | int ocxl_config_terminate_pasid(struct pci_dev *dev, int afu_control, int pasid) | 673 | int ocxl_config_terminate_pasid(struct pci_dev *dev, int afu_control, int pasid) |
| 665 | { | 674 | { |
| @@ -699,6 +708,7 @@ int ocxl_config_terminate_pasid(struct pci_dev *dev, int afu_control, int pasid) | |||
| 699 | } | 708 | } |
| 700 | return 0; | 709 | return 0; |
| 701 | } | 710 | } |
| 711 | EXPORT_SYMBOL_GPL(ocxl_config_terminate_pasid); | ||
| 702 | 712 | ||
| 703 | void ocxl_config_set_actag(struct pci_dev *dev, int func_dvsec, u32 tag_first, | 713 | void ocxl_config_set_actag(struct pci_dev *dev, int func_dvsec, u32 tag_first, |
| 704 | u32 tag_count) | 714 | u32 tag_count) |
| @@ -710,3 +720,4 @@ void ocxl_config_set_actag(struct pci_dev *dev, int func_dvsec, u32 tag_first, | |||
| 710 | pci_write_config_dword(dev, func_dvsec + OCXL_DVSEC_FUNC_OFF_ACTAG, | 720 | pci_write_config_dword(dev, func_dvsec + OCXL_DVSEC_FUNC_OFF_ACTAG, |
| 711 | val); | 721 | val); |
| 712 | } | 722 | } |
| 723 | EXPORT_SYMBOL_GPL(ocxl_config_set_actag); | ||
diff --git a/drivers/misc/ocxl/link.c b/drivers/misc/ocxl/link.c index 8bdcef9c3cba..fbca3feec592 100644 --- a/drivers/misc/ocxl/link.c +++ b/drivers/misc/ocxl/link.c | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <linux/mmu_context.h> | 5 | #include <linux/mmu_context.h> |
| 6 | #include <asm/copro.h> | 6 | #include <asm/copro.h> |
| 7 | #include <asm/pnv-ocxl.h> | 7 | #include <asm/pnv-ocxl.h> |
| 8 | #include <misc/ocxl.h> | ||
| 8 | #include "ocxl_internal.h" | 9 | #include "ocxl_internal.h" |
| 9 | 10 | ||
| 10 | 11 | ||
| @@ -420,6 +421,7 @@ unlock: | |||
| 420 | mutex_unlock(&links_list_lock); | 421 | mutex_unlock(&links_list_lock); |
| 421 | return rc; | 422 | return rc; |
| 422 | } | 423 | } |
| 424 | EXPORT_SYMBOL_GPL(ocxl_link_setup); | ||
| 423 | 425 | ||
| 424 | static void release_xsl(struct kref *ref) | 426 | static void release_xsl(struct kref *ref) |
| 425 | { | 427 | { |
| @@ -439,6 +441,7 @@ void ocxl_link_release(struct pci_dev *dev, void *link_handle) | |||
| 439 | kref_put(&link->ref, release_xsl); | 441 | kref_put(&link->ref, release_xsl); |
| 440 | mutex_unlock(&links_list_lock); | 442 | mutex_unlock(&links_list_lock); |
| 441 | } | 443 | } |
| 444 | EXPORT_SYMBOL_GPL(ocxl_link_release); | ||
| 442 | 445 | ||
| 443 | static u64 calculate_cfg_state(bool kernel) | 446 | static u64 calculate_cfg_state(bool kernel) |
| 444 | { | 447 | { |
| @@ -533,6 +536,7 @@ unlock: | |||
| 533 | mutex_unlock(&spa->spa_lock); | 536 | mutex_unlock(&spa->spa_lock); |
| 534 | return rc; | 537 | return rc; |
| 535 | } | 538 | } |
| 539 | EXPORT_SYMBOL_GPL(ocxl_link_add_pe); | ||
| 536 | 540 | ||
| 537 | int ocxl_link_remove_pe(void *link_handle, int pasid) | 541 | int ocxl_link_remove_pe(void *link_handle, int pasid) |
| 538 | { | 542 | { |
| @@ -601,6 +605,7 @@ unlock: | |||
| 601 | mutex_unlock(&spa->spa_lock); | 605 | mutex_unlock(&spa->spa_lock); |
| 602 | return rc; | 606 | return rc; |
| 603 | } | 607 | } |
| 608 | EXPORT_SYMBOL_GPL(ocxl_link_remove_pe); | ||
| 604 | 609 | ||
| 605 | int ocxl_link_irq_alloc(void *link_handle, int *hw_irq, u64 *trigger_addr) | 610 | int ocxl_link_irq_alloc(void *link_handle, int *hw_irq, u64 *trigger_addr) |
| 606 | { | 611 | { |
| @@ -621,6 +626,7 @@ int ocxl_link_irq_alloc(void *link_handle, int *hw_irq, u64 *trigger_addr) | |||
| 621 | *trigger_addr = addr; | 626 | *trigger_addr = addr; |
| 622 | return 0; | 627 | return 0; |
| 623 | } | 628 | } |
| 629 | EXPORT_SYMBOL_GPL(ocxl_link_irq_alloc); | ||
| 624 | 630 | ||
| 625 | void ocxl_link_free_irq(void *link_handle, int hw_irq) | 631 | void ocxl_link_free_irq(void *link_handle, int hw_irq) |
| 626 | { | 632 | { |
| @@ -629,3 +635,4 @@ void ocxl_link_free_irq(void *link_handle, int hw_irq) | |||
| 629 | pnv_ocxl_free_xive_irq(hw_irq); | 635 | pnv_ocxl_free_xive_irq(hw_irq); |
| 630 | atomic_inc(&link->irq_available); | 636 | atomic_inc(&link->irq_available); |
| 631 | } | 637 | } |
| 638 | EXPORT_SYMBOL_GPL(ocxl_link_free_irq); | ||
diff --git a/drivers/misc/ocxl/ocxl_internal.h b/drivers/misc/ocxl/ocxl_internal.h index a89b88ac67eb..5d421824afd9 100644 --- a/drivers/misc/ocxl/ocxl_internal.h +++ b/drivers/misc/ocxl/ocxl_internal.h | |||
| @@ -6,8 +6,8 @@ | |||
| 6 | #include <linux/pci.h> | 6 | #include <linux/pci.h> |
| 7 | #include <linux/cdev.h> | 7 | #include <linux/cdev.h> |
| 8 | #include <linux/list.h> | 8 | #include <linux/list.h> |
| 9 | #include <misc/ocxl.h> | ||
| 9 | 10 | ||
| 10 | #define OCXL_AFU_NAME_SZ (24+1) /* add 1 for NULL termination */ | ||
| 11 | #define MAX_IRQ_PER_LINK 2000 | 11 | #define MAX_IRQ_PER_LINK 2000 |
| 12 | #define MAX_IRQ_PER_CONTEXT MAX_IRQ_PER_LINK | 12 | #define MAX_IRQ_PER_CONTEXT MAX_IRQ_PER_LINK |
| 13 | 13 | ||
| @@ -16,38 +16,6 @@ | |||
| 16 | 16 | ||
| 17 | extern struct pci_driver ocxl_pci_driver; | 17 | extern struct pci_driver ocxl_pci_driver; |
| 18 | 18 | ||
| 19 | /* | ||
| 20 | * The following 2 structures are a fairly generic way of representing | ||
| 21 | * the configuration data for a function and AFU, as read from the | ||
| 22 | * configuration space. | ||
| 23 | */ | ||
| 24 | struct ocxl_afu_config { | ||
| 25 | u8 idx; | ||
| 26 | int dvsec_afu_control_pos; | ||
| 27 | char name[OCXL_AFU_NAME_SZ]; | ||
| 28 | u8 version_major; | ||
| 29 | u8 version_minor; | ||
| 30 | u8 afuc_type; | ||
| 31 | u8 afum_type; | ||
| 32 | u8 profile; | ||
| 33 | u8 global_mmio_bar; | ||
| 34 | u64 global_mmio_offset; | ||
| 35 | u32 global_mmio_size; | ||
| 36 | u8 pp_mmio_bar; | ||
| 37 | u64 pp_mmio_offset; | ||
| 38 | u32 pp_mmio_stride; | ||
| 39 | u8 log_mem_size; | ||
| 40 | u8 pasid_supported_log; | ||
| 41 | u16 actag_supported; | ||
| 42 | }; | ||
| 43 | |||
| 44 | struct ocxl_fn_config { | ||
| 45 | int dvsec_tl_pos; | ||
| 46 | int dvsec_function_pos; | ||
| 47 | int dvsec_afu_info_pos; | ||
| 48 | s8 max_pasid_log; | ||
| 49 | s8 max_afu_index; | ||
| 50 | }; | ||
| 51 | 19 | ||
| 52 | struct ocxl_fn { | 20 | struct ocxl_fn { |
| 53 | struct device dev; | 21 | struct device dev; |
| @@ -135,43 +103,6 @@ extern void ocxl_unregister_afu(struct ocxl_afu *afu); | |||
| 135 | extern int ocxl_file_init(void); | 103 | extern int ocxl_file_init(void); |
| 136 | extern void ocxl_file_exit(void); | 104 | extern void ocxl_file_exit(void); |
| 137 | 105 | ||
| 138 | extern int ocxl_config_read_function(struct pci_dev *dev, | ||
| 139 | struct ocxl_fn_config *fn); | ||
| 140 | |||
| 141 | extern int ocxl_config_check_afu_index(struct pci_dev *dev, | ||
| 142 | struct ocxl_fn_config *fn, int afu_idx); | ||
| 143 | extern int ocxl_config_read_afu(struct pci_dev *dev, | ||
| 144 | struct ocxl_fn_config *fn, | ||
| 145 | struct ocxl_afu_config *afu, | ||
| 146 | u8 afu_idx); | ||
| 147 | extern int ocxl_config_get_pasid_info(struct pci_dev *dev, int *count); | ||
| 148 | extern void ocxl_config_set_afu_pasid(struct pci_dev *dev, | ||
| 149 | int afu_control, | ||
| 150 | int pasid_base, u32 pasid_count_log); | ||
| 151 | extern int ocxl_config_get_actag_info(struct pci_dev *dev, | ||
| 152 | u16 *base, u16 *enabled, u16 *supported); | ||
| 153 | extern void ocxl_config_set_actag(struct pci_dev *dev, int func_dvsec, | ||
| 154 | u32 tag_first, u32 tag_count); | ||
| 155 | extern void ocxl_config_set_afu_actag(struct pci_dev *dev, int afu_control, | ||
| 156 | int actag_base, int actag_count); | ||
| 157 | extern void ocxl_config_set_afu_state(struct pci_dev *dev, int afu_control, | ||
| 158 | int enable); | ||
| 159 | extern int ocxl_config_set_TL(struct pci_dev *dev, int tl_dvsec); | ||
| 160 | extern int ocxl_config_terminate_pasid(struct pci_dev *dev, int afu_control, | ||
| 161 | int pasid); | ||
| 162 | |||
| 163 | extern int ocxl_link_setup(struct pci_dev *dev, int PE_mask, | ||
| 164 | void **link_handle); | ||
| 165 | extern void ocxl_link_release(struct pci_dev *dev, void *link_handle); | ||
| 166 | extern int ocxl_link_add_pe(void *link_handle, int pasid, u32 pidr, u32 tidr, | ||
| 167 | u64 amr, struct mm_struct *mm, | ||
| 168 | void (*xsl_err_cb)(void *data, u64 addr, u64 dsisr), | ||
| 169 | void *xsl_err_data); | ||
| 170 | extern int ocxl_link_remove_pe(void *link_handle, int pasid); | ||
| 171 | extern int ocxl_link_irq_alloc(void *link_handle, int *hw_irq, | ||
| 172 | u64 *addr); | ||
| 173 | extern void ocxl_link_free_irq(void *link_handle, int hw_irq); | ||
| 174 | |||
| 175 | extern int ocxl_pasid_afu_alloc(struct ocxl_fn *fn, u32 size); | 106 | extern int ocxl_pasid_afu_alloc(struct ocxl_fn *fn, u32 size); |
| 176 | extern void ocxl_pasid_afu_free(struct ocxl_fn *fn, u32 start, u32 size); | 107 | extern void ocxl_pasid_afu_free(struct ocxl_fn *fn, u32 start, u32 size); |
| 177 | extern int ocxl_actag_afu_alloc(struct ocxl_fn *fn, u32 size); | 108 | extern int ocxl_actag_afu_alloc(struct ocxl_fn *fn, u32 size); |
diff --git a/include/misc/ocxl.h b/include/misc/ocxl.h new file mode 100644 index 000000000000..51ccf76db293 --- /dev/null +++ b/include/misc/ocxl.h | |||
| @@ -0,0 +1,214 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0+ | ||
| 2 | // Copyright 2017 IBM Corp. | ||
| 3 | #ifndef _MISC_OCXL_H_ | ||
| 4 | #define _MISC_OCXL_H_ | ||
| 5 | |||
| 6 | #include <linux/pci.h> | ||
| 7 | |||
| 8 | /* | ||
| 9 | * Opencapi drivers all need some common facilities, like parsing the | ||
| 10 | * device configuration space, adding a Process Element to the Shared | ||
| 11 | * Process Area, etc... | ||
| 12 | * | ||
| 13 | * The ocxl module provides a kernel API, to allow other drivers to | ||
| 14 | * reuse common code. A bit like a in-kernel library. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #define OCXL_AFU_NAME_SZ (24+1) /* add 1 for NULL termination */ | ||
| 18 | |||
| 19 | /* | ||
| 20 | * The following 2 structures are a fairly generic way of representing | ||
| 21 | * the configuration data for a function and AFU, as read from the | ||
| 22 | * configuration space. | ||
| 23 | */ | ||
| 24 | struct ocxl_afu_config { | ||
| 25 | u8 idx; | ||
| 26 | int dvsec_afu_control_pos; /* offset of AFU control DVSEC */ | ||
| 27 | char name[OCXL_AFU_NAME_SZ]; | ||
| 28 | u8 version_major; | ||
| 29 | u8 version_minor; | ||
| 30 | u8 afuc_type; | ||
| 31 | u8 afum_type; | ||
| 32 | u8 profile; | ||
| 33 | u8 global_mmio_bar; /* global MMIO area */ | ||
| 34 | u64 global_mmio_offset; | ||
| 35 | u32 global_mmio_size; | ||
| 36 | u8 pp_mmio_bar; /* per-process MMIO area */ | ||
| 37 | u64 pp_mmio_offset; | ||
| 38 | u32 pp_mmio_stride; | ||
| 39 | u8 log_mem_size; | ||
| 40 | u8 pasid_supported_log; | ||
| 41 | u16 actag_supported; | ||
| 42 | }; | ||
| 43 | |||
| 44 | struct ocxl_fn_config { | ||
| 45 | int dvsec_tl_pos; /* offset of the Transaction Layer DVSEC */ | ||
| 46 | int dvsec_function_pos; /* offset of the Function DVSEC */ | ||
| 47 | int dvsec_afu_info_pos; /* offset of the AFU information DVSEC */ | ||
| 48 | s8 max_pasid_log; | ||
| 49 | s8 max_afu_index; | ||
| 50 | }; | ||
| 51 | |||
| 52 | /* | ||
| 53 | * Read the configuration space of a function and fill in a | ||
| 54 | * ocxl_fn_config structure with all the function details | ||
| 55 | */ | ||
| 56 | extern int ocxl_config_read_function(struct pci_dev *dev, | ||
| 57 | struct ocxl_fn_config *fn); | ||
| 58 | |||
| 59 | /* | ||
| 60 | * Check if an AFU index is valid for the given function. | ||
| 61 | * | ||
| 62 | * AFU indexes can be sparse, so a driver should check all indexes up | ||
| 63 | * to the maximum found in the function description | ||
| 64 | */ | ||
| 65 | extern int ocxl_config_check_afu_index(struct pci_dev *dev, | ||
| 66 | struct ocxl_fn_config *fn, int afu_idx); | ||
| 67 | |||
| 68 | /* | ||
| 69 | * Read the configuration space of a function for the AFU specified by | ||
| 70 | * the index 'afu_idx'. Fills in a ocxl_afu_config structure | ||
| 71 | */ | ||
| 72 | extern int ocxl_config_read_afu(struct pci_dev *dev, | ||
| 73 | struct ocxl_fn_config *fn, | ||
| 74 | struct ocxl_afu_config *afu, | ||
| 75 | u8 afu_idx); | ||
| 76 | |||
| 77 | /* | ||
| 78 | * Get the max PASID value that can be used by the function | ||
| 79 | */ | ||
| 80 | extern int ocxl_config_get_pasid_info(struct pci_dev *dev, int *count); | ||
| 81 | |||
| 82 | /* | ||
| 83 | * Tell an AFU, by writing in the configuration space, the PASIDs that | ||
| 84 | * it can use. Range starts at 'pasid_base' and its size is a multiple | ||
| 85 | * of 2 | ||
| 86 | * | ||
| 87 | * 'afu_control_offset' is the offset of the AFU control DVSEC which | ||
| 88 | * can be found in the function configuration | ||
| 89 | */ | ||
| 90 | extern void ocxl_config_set_afu_pasid(struct pci_dev *dev, | ||
| 91 | int afu_control_offset, | ||
| 92 | int pasid_base, u32 pasid_count_log); | ||
| 93 | |||
| 94 | /* | ||
| 95 | * Get the actag configuration for the function: | ||
| 96 | * 'base' is the first actag value that can be used. | ||
| 97 | * 'enabled' it the number of actags available, starting from base. | ||
| 98 | * 'supported' is the total number of actags desired by all the AFUs | ||
| 99 | * of the function. | ||
| 100 | */ | ||
| 101 | extern int ocxl_config_get_actag_info(struct pci_dev *dev, | ||
| 102 | u16 *base, u16 *enabled, u16 *supported); | ||
| 103 | |||
| 104 | /* | ||
| 105 | * Tell a function, by writing in the configuration space, the actags | ||
| 106 | * it can use. | ||
| 107 | * | ||
| 108 | * 'func_offset' is the offset of the Function DVSEC that can found in | ||
| 109 | * the function configuration | ||
| 110 | */ | ||
| 111 | extern void ocxl_config_set_actag(struct pci_dev *dev, int func_offset, | ||
| 112 | u32 actag_base, u32 actag_count); | ||
| 113 | |||
| 114 | /* | ||
| 115 | * Tell an AFU, by writing in the configuration space, the actags it | ||
| 116 | * can use. | ||
| 117 | * | ||
| 118 | * 'afu_control_offset' is the offset of the AFU control DVSEC for the | ||
| 119 | * desired AFU. It can be found in the AFU configuration | ||
| 120 | */ | ||
| 121 | extern void ocxl_config_set_afu_actag(struct pci_dev *dev, | ||
| 122 | int afu_control_offset, | ||
| 123 | int actag_base, int actag_count); | ||
| 124 | |||
| 125 | /* | ||
| 126 | * Enable/disable an AFU, by writing in the configuration space. | ||
| 127 | * | ||
| 128 | * 'afu_control_offset' is the offset of the AFU control DVSEC for the | ||
| 129 | * desired AFU. It can be found in the AFU configuration | ||
| 130 | */ | ||
| 131 | extern void ocxl_config_set_afu_state(struct pci_dev *dev, | ||
| 132 | int afu_control_offset, int enable); | ||
| 133 | |||
| 134 | /* | ||
| 135 | * Set the Transaction Layer configuration in the configuration space. | ||
| 136 | * Only needed for function 0. | ||
| 137 | * | ||
| 138 | * It queries the host TL capabilities, find some common ground | ||
| 139 | * between the host and device, and set the Transaction Layer on both | ||
| 140 | * accordingly. | ||
| 141 | */ | ||
| 142 | extern int ocxl_config_set_TL(struct pci_dev *dev, int tl_dvsec); | ||
| 143 | |||
| 144 | /* | ||
| 145 | * Request an AFU to terminate a PASID. | ||
| 146 | * Will return once the AFU has acked the request, or an error in case | ||
| 147 | * of timeout. | ||
| 148 | * | ||
| 149 | * The hardware can only terminate one PASID at a time, so caller must | ||
| 150 | * guarantee some kind of serialization. | ||
| 151 | * | ||
| 152 | * 'afu_control_offset' is the offset of the AFU control DVSEC for the | ||
| 153 | * desired AFU. It can be found in the AFU configuration | ||
| 154 | */ | ||
| 155 | extern int ocxl_config_terminate_pasid(struct pci_dev *dev, | ||
| 156 | int afu_control_offset, int pasid); | ||
| 157 | |||
| 158 | /* | ||
| 159 | * Set up the opencapi link for the function. | ||
| 160 | * | ||
| 161 | * When called for the first time for a link, it sets up the Shared | ||
| 162 | * Process Area for the link and the interrupt handler to process | ||
| 163 | * translation faults. | ||
| 164 | * | ||
| 165 | * Returns a 'link handle' that should be used for further calls for | ||
| 166 | * the link | ||
| 167 | */ | ||
| 168 | extern int ocxl_link_setup(struct pci_dev *dev, int PE_mask, | ||
| 169 | void **link_handle); | ||
| 170 | |||
| 171 | /* | ||
| 172 | * Remove the association between the function and its link. | ||
| 173 | */ | ||
| 174 | extern void ocxl_link_release(struct pci_dev *dev, void *link_handle); | ||
| 175 | |||
| 176 | /* | ||
| 177 | * Add a Process Element to the Shared Process Area for a link. | ||
| 178 | * The process is defined by its PASID, pid, tid and its mm_struct. | ||
| 179 | * | ||
| 180 | * 'xsl_err_cb' is an optional callback if the driver wants to be | ||
| 181 | * notified when the translation fault interrupt handler detects an | ||
| 182 | * address error. | ||
| 183 | * 'xsl_err_data' is an argument passed to the above callback, if | ||
| 184 | * defined | ||
| 185 | */ | ||
| 186 | extern int ocxl_link_add_pe(void *link_handle, int pasid, u32 pidr, u32 tidr, | ||
| 187 | u64 amr, struct mm_struct *mm, | ||
| 188 | void (*xsl_err_cb)(void *data, u64 addr, u64 dsisr), | ||
| 189 | void *xsl_err_data); | ||
| 190 | |||
| 191 | /* | ||
| 192 | * Remove a Process Element from the Shared Process Area for a link | ||
| 193 | */ | ||
| 194 | extern int ocxl_link_remove_pe(void *link_handle, int pasid); | ||
| 195 | |||
| 196 | /* | ||
| 197 | * Allocate an AFU interrupt associated to the link. | ||
| 198 | * | ||
| 199 | * 'hw_irq' is the hardware interrupt number | ||
| 200 | * 'obj_handle' is the 64-bit object handle to be passed to the AFU to | ||
| 201 | * trigger the interrupt. | ||
| 202 | * On P9, 'obj_handle' is an address, which, if written, triggers the | ||
| 203 | * interrupt. It is an MMIO address which needs to be remapped (one | ||
| 204 | * page). | ||
| 205 | */ | ||
| 206 | extern int ocxl_link_irq_alloc(void *link_handle, int *hw_irq, | ||
| 207 | u64 *obj_handle); | ||
| 208 | |||
| 209 | /* | ||
| 210 | * Free a previously allocated AFU interrupt | ||
| 211 | */ | ||
| 212 | extern void ocxl_link_free_irq(void *link_handle, int hw_irq); | ||
| 213 | |||
| 214 | #endif /* _MISC_OCXL_H_ */ | ||
