162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
262306a36Sopenharmony_ci// Copyright 2017 IBM Corp.
362306a36Sopenharmony_ci#ifndef _MISC_OCXL_H_
462306a36Sopenharmony_ci#define _MISC_OCXL_H_
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#include <linux/pci.h>
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci/*
962306a36Sopenharmony_ci * Opencapi drivers all need some common facilities, like parsing the
1062306a36Sopenharmony_ci * device configuration space, adding a Process Element to the Shared
1162306a36Sopenharmony_ci * Process Area, etc...
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci * The ocxl module provides a kernel API, to allow other drivers to
1462306a36Sopenharmony_ci * reuse common code. A bit like a in-kernel library.
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#define OCXL_AFU_NAME_SZ      (24+1)  /* add 1 for NULL termination */
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cistruct ocxl_afu_config {
2162306a36Sopenharmony_ci	u8 idx;
2262306a36Sopenharmony_ci	int dvsec_afu_control_pos; /* offset of AFU control DVSEC */
2362306a36Sopenharmony_ci	char name[OCXL_AFU_NAME_SZ];
2462306a36Sopenharmony_ci	u8 version_major;
2562306a36Sopenharmony_ci	u8 version_minor;
2662306a36Sopenharmony_ci	u8 afuc_type;
2762306a36Sopenharmony_ci	u8 afum_type;
2862306a36Sopenharmony_ci	u8 profile;
2962306a36Sopenharmony_ci	u8 global_mmio_bar;     /* global MMIO area */
3062306a36Sopenharmony_ci	u64 global_mmio_offset;
3162306a36Sopenharmony_ci	u32 global_mmio_size;
3262306a36Sopenharmony_ci	u8 pp_mmio_bar;         /* per-process MMIO area */
3362306a36Sopenharmony_ci	u64 pp_mmio_offset;
3462306a36Sopenharmony_ci	u32 pp_mmio_stride;
3562306a36Sopenharmony_ci	u64 lpc_mem_offset;
3662306a36Sopenharmony_ci	u64 lpc_mem_size;
3762306a36Sopenharmony_ci	u64 special_purpose_mem_offset;
3862306a36Sopenharmony_ci	u64 special_purpose_mem_size;
3962306a36Sopenharmony_ci	u8 pasid_supported_log;
4062306a36Sopenharmony_ci	u16 actag_supported;
4162306a36Sopenharmony_ci};
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_cistruct ocxl_fn_config {
4462306a36Sopenharmony_ci	int dvsec_tl_pos;       /* offset of the Transaction Layer DVSEC */
4562306a36Sopenharmony_ci	int dvsec_function_pos; /* offset of the Function DVSEC */
4662306a36Sopenharmony_ci	int dvsec_afu_info_pos; /* offset of the AFU information DVSEC */
4762306a36Sopenharmony_ci	s8 max_pasid_log;
4862306a36Sopenharmony_ci	s8 max_afu_index;
4962306a36Sopenharmony_ci};
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_cienum ocxl_endian {
5262306a36Sopenharmony_ci	OCXL_BIG_ENDIAN = 0,    /**< AFU data is big-endian */
5362306a36Sopenharmony_ci	OCXL_LITTLE_ENDIAN = 1, /**< AFU data is little-endian */
5462306a36Sopenharmony_ci	OCXL_HOST_ENDIAN = 2,   /**< AFU data is the same endianness as the host */
5562306a36Sopenharmony_ci};
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci// These are opaque outside the ocxl driver
5862306a36Sopenharmony_cistruct ocxl_afu;
5962306a36Sopenharmony_cistruct ocxl_fn;
6062306a36Sopenharmony_cistruct ocxl_context;
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci// Device detection & initialisation
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci/**
6562306a36Sopenharmony_ci * ocxl_function_open() - Open an OpenCAPI function on an OpenCAPI device
6662306a36Sopenharmony_ci * @dev: The PCI device that contains the function
6762306a36Sopenharmony_ci *
6862306a36Sopenharmony_ci * Returns an opaque pointer to the function, or an error pointer (check with IS_ERR)
6962306a36Sopenharmony_ci */
7062306a36Sopenharmony_cistruct ocxl_fn *ocxl_function_open(struct pci_dev *dev);
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/**
7362306a36Sopenharmony_ci * ocxl_function_afu_list() - Get the list of AFUs associated with a PCI function device
7462306a36Sopenharmony_ci * Returns a list of struct ocxl_afu *
7562306a36Sopenharmony_ci *
7662306a36Sopenharmony_ci * @fn: The OpenCAPI function containing the AFUs
7762306a36Sopenharmony_ci */
7862306a36Sopenharmony_cistruct list_head *ocxl_function_afu_list(struct ocxl_fn *fn);
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci/**
8162306a36Sopenharmony_ci * ocxl_function_fetch_afu() - Fetch an AFU instance from an OpenCAPI function
8262306a36Sopenharmony_ci * @fn: The OpenCAPI function to get the AFU from
8362306a36Sopenharmony_ci * @afu_idx: The index of the AFU to get
8462306a36Sopenharmony_ci *
8562306a36Sopenharmony_ci * If successful, the AFU should be released with ocxl_afu_put()
8662306a36Sopenharmony_ci *
8762306a36Sopenharmony_ci * Returns a pointer to the AFU, or NULL on error
8862306a36Sopenharmony_ci */
8962306a36Sopenharmony_cistruct ocxl_afu *ocxl_function_fetch_afu(struct ocxl_fn *fn, u8 afu_idx);
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci/**
9262306a36Sopenharmony_ci * ocxl_afu_get() - Take a reference to an AFU
9362306a36Sopenharmony_ci * @afu: The AFU to increment the reference count on
9462306a36Sopenharmony_ci */
9562306a36Sopenharmony_civoid ocxl_afu_get(struct ocxl_afu *afu);
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci/**
9862306a36Sopenharmony_ci * ocxl_afu_put() - Release a reference to an AFU
9962306a36Sopenharmony_ci * @afu: The AFU to decrement the reference count on
10062306a36Sopenharmony_ci */
10162306a36Sopenharmony_civoid ocxl_afu_put(struct ocxl_afu *afu);
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci/**
10562306a36Sopenharmony_ci * ocxl_function_config() - Get the configuration information for an OpenCAPI function
10662306a36Sopenharmony_ci * @fn: The OpenCAPI function to get the config for
10762306a36Sopenharmony_ci *
10862306a36Sopenharmony_ci * Returns the function config, or NULL on error
10962306a36Sopenharmony_ci */
11062306a36Sopenharmony_ciconst struct ocxl_fn_config *ocxl_function_config(struct ocxl_fn *fn);
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci/**
11362306a36Sopenharmony_ci * ocxl_function_close() - Close an OpenCAPI function
11462306a36Sopenharmony_ci * This will free any AFUs previously retrieved from the function, and
11562306a36Sopenharmony_ci * detach and associated contexts. The contexts must by freed by the caller.
11662306a36Sopenharmony_ci *
11762306a36Sopenharmony_ci * @fn: The OpenCAPI function to close
11862306a36Sopenharmony_ci *
11962306a36Sopenharmony_ci */
12062306a36Sopenharmony_civoid ocxl_function_close(struct ocxl_fn *fn);
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci// Context allocation
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci/**
12562306a36Sopenharmony_ci * ocxl_context_alloc() - Allocate an OpenCAPI context
12662306a36Sopenharmony_ci * @context: The OpenCAPI context to allocate, must be freed with ocxl_context_free
12762306a36Sopenharmony_ci * @afu: The AFU the context belongs to
12862306a36Sopenharmony_ci * @mapping: The mapping to unmap when the context is closed (may be NULL)
12962306a36Sopenharmony_ci */
13062306a36Sopenharmony_ciint ocxl_context_alloc(struct ocxl_context **context, struct ocxl_afu *afu,
13162306a36Sopenharmony_ci			struct address_space *mapping);
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci/**
13462306a36Sopenharmony_ci * ocxl_context_free() - Free an OpenCAPI context
13562306a36Sopenharmony_ci * @ctx: The OpenCAPI context to free
13662306a36Sopenharmony_ci */
13762306a36Sopenharmony_civoid ocxl_context_free(struct ocxl_context *ctx);
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci/**
14062306a36Sopenharmony_ci * ocxl_context_attach() - Grant access to an MM to an OpenCAPI context
14162306a36Sopenharmony_ci * @ctx: The OpenCAPI context to attach
14262306a36Sopenharmony_ci * @amr: The value of the AMR register to restrict access
14362306a36Sopenharmony_ci * @mm: The mm to attach to the context
14462306a36Sopenharmony_ci *
14562306a36Sopenharmony_ci * Returns 0 on success, negative on failure
14662306a36Sopenharmony_ci */
14762306a36Sopenharmony_ciint ocxl_context_attach(struct ocxl_context *ctx, u64 amr,
14862306a36Sopenharmony_ci				struct mm_struct *mm);
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci/**
15162306a36Sopenharmony_ci * ocxl_context_detach() - Detach an MM from an OpenCAPI context
15262306a36Sopenharmony_ci * @ctx: The OpenCAPI context to attach
15362306a36Sopenharmony_ci *
15462306a36Sopenharmony_ci * Returns 0 on success, negative on failure
15562306a36Sopenharmony_ci */
15662306a36Sopenharmony_ciint ocxl_context_detach(struct ocxl_context *ctx);
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci// AFU IRQs
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci/**
16162306a36Sopenharmony_ci * ocxl_afu_irq_alloc() - Allocate an IRQ associated with an AFU context
16262306a36Sopenharmony_ci * @ctx: the AFU context
16362306a36Sopenharmony_ci * @irq_id: out, the IRQ ID
16462306a36Sopenharmony_ci *
16562306a36Sopenharmony_ci * Returns 0 on success, negative on failure
16662306a36Sopenharmony_ci */
16762306a36Sopenharmony_ciint ocxl_afu_irq_alloc(struct ocxl_context *ctx, int *irq_id);
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci/**
17062306a36Sopenharmony_ci * ocxl_afu_irq_free() - Frees an IRQ associated with an AFU context
17162306a36Sopenharmony_ci * @ctx: the AFU context
17262306a36Sopenharmony_ci * @irq_id: the IRQ ID
17362306a36Sopenharmony_ci *
17462306a36Sopenharmony_ci * Returns 0 on success, negative on failure
17562306a36Sopenharmony_ci */
17662306a36Sopenharmony_ciint ocxl_afu_irq_free(struct ocxl_context *ctx, int irq_id);
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci/**
17962306a36Sopenharmony_ci * ocxl_afu_irq_get_addr() - Gets the address of the trigger page for an IRQ
18062306a36Sopenharmony_ci * This can then be provided to an AFU which will write to that
18162306a36Sopenharmony_ci * page to trigger the IRQ.
18262306a36Sopenharmony_ci * @ctx: The AFU context that the IRQ is associated with
18362306a36Sopenharmony_ci * @irq_id: The IRQ ID
18462306a36Sopenharmony_ci *
18562306a36Sopenharmony_ci * returns the trigger page address, or 0 if the IRQ is not valid
18662306a36Sopenharmony_ci */
18762306a36Sopenharmony_ciu64 ocxl_afu_irq_get_addr(struct ocxl_context *ctx, int irq_id);
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci/**
19062306a36Sopenharmony_ci * ocxl_irq_set_handler() - Provide a callback to be called when an IRQ is triggered
19162306a36Sopenharmony_ci * @ctx: The AFU context that the IRQ is associated with
19262306a36Sopenharmony_ci * @irq_id: The IRQ ID
19362306a36Sopenharmony_ci * @handler: the callback to be called when the IRQ is triggered
19462306a36Sopenharmony_ci * @free_private: the callback to be called when the IRQ is freed (may be NULL)
19562306a36Sopenharmony_ci * @private: Private data to be passed to the callbacks
19662306a36Sopenharmony_ci *
19762306a36Sopenharmony_ci * Returns 0 on success, negative on failure
19862306a36Sopenharmony_ci */
19962306a36Sopenharmony_ciint ocxl_irq_set_handler(struct ocxl_context *ctx, int irq_id,
20062306a36Sopenharmony_ci		irqreturn_t (*handler)(void *private),
20162306a36Sopenharmony_ci		void (*free_private)(void *private),
20262306a36Sopenharmony_ci		void *private);
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci// AFU Metadata
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_ci/**
20762306a36Sopenharmony_ci * ocxl_afu_config() - Get a pointer to the config for an AFU
20862306a36Sopenharmony_ci * @afu: a pointer to the AFU to get the config for
20962306a36Sopenharmony_ci *
21062306a36Sopenharmony_ci * Returns a pointer to the AFU config
21162306a36Sopenharmony_ci */
21262306a36Sopenharmony_cistruct ocxl_afu_config *ocxl_afu_config(struct ocxl_afu *afu);
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ci/**
21562306a36Sopenharmony_ci * ocxl_afu_set_private() - Assign opaque hardware specific information to an OpenCAPI AFU.
21662306a36Sopenharmony_ci * @afu: The OpenCAPI AFU
21762306a36Sopenharmony_ci * @private: the opaque hardware specific information to assign to the driver
21862306a36Sopenharmony_ci */
21962306a36Sopenharmony_civoid ocxl_afu_set_private(struct ocxl_afu *afu, void *private);
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci/**
22262306a36Sopenharmony_ci * ocxl_afu_get_private() - Fetch the hardware specific information associated with
22362306a36Sopenharmony_ci * an external OpenCAPI AFU. This may be consumed by an external OpenCAPI driver.
22462306a36Sopenharmony_ci * @afu: The OpenCAPI AFU
22562306a36Sopenharmony_ci *
22662306a36Sopenharmony_ci * Returns the opaque pointer associated with the device, or NULL if not set
22762306a36Sopenharmony_ci */
22862306a36Sopenharmony_civoid *ocxl_afu_get_private(struct ocxl_afu *afu);
22962306a36Sopenharmony_ci
23062306a36Sopenharmony_ci// Global MMIO
23162306a36Sopenharmony_ci/**
23262306a36Sopenharmony_ci * ocxl_global_mmio_read32() - Read a 32 bit value from global MMIO
23362306a36Sopenharmony_ci * @afu: The AFU
23462306a36Sopenharmony_ci * @offset: The Offset from the start of MMIO
23562306a36Sopenharmony_ci * @endian: the endianness that the MMIO data is in
23662306a36Sopenharmony_ci * @val: returns the value
23762306a36Sopenharmony_ci *
23862306a36Sopenharmony_ci * Returns 0 for success, negative on error
23962306a36Sopenharmony_ci */
24062306a36Sopenharmony_ciint ocxl_global_mmio_read32(struct ocxl_afu *afu, size_t offset,
24162306a36Sopenharmony_ci			    enum ocxl_endian endian, u32 *val);
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ci/**
24462306a36Sopenharmony_ci * ocxl_global_mmio_read64() - Read a 64 bit value from global MMIO
24562306a36Sopenharmony_ci * @afu: The AFU
24662306a36Sopenharmony_ci * @offset: The Offset from the start of MMIO
24762306a36Sopenharmony_ci * @endian: the endianness that the MMIO data is in
24862306a36Sopenharmony_ci * @val: returns the value
24962306a36Sopenharmony_ci *
25062306a36Sopenharmony_ci * Returns 0 for success, negative on error
25162306a36Sopenharmony_ci */
25262306a36Sopenharmony_ciint ocxl_global_mmio_read64(struct ocxl_afu *afu, size_t offset,
25362306a36Sopenharmony_ci			    enum ocxl_endian endian, u64 *val);
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci/**
25662306a36Sopenharmony_ci * ocxl_global_mmio_write32() - Write a 32 bit value to global MMIO
25762306a36Sopenharmony_ci * @afu: The AFU
25862306a36Sopenharmony_ci * @offset: The Offset from the start of MMIO
25962306a36Sopenharmony_ci * @endian: the endianness that the MMIO data is in
26062306a36Sopenharmony_ci * @val: The value to write
26162306a36Sopenharmony_ci *
26262306a36Sopenharmony_ci * Returns 0 for success, negative on error
26362306a36Sopenharmony_ci */
26462306a36Sopenharmony_ciint ocxl_global_mmio_write32(struct ocxl_afu *afu, size_t offset,
26562306a36Sopenharmony_ci			     enum ocxl_endian endian, u32 val);
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci/**
26862306a36Sopenharmony_ci * ocxl_global_mmio_write64() - Write a 64 bit value to global MMIO
26962306a36Sopenharmony_ci * @afu: The AFU
27062306a36Sopenharmony_ci * @offset: The Offset from the start of MMIO
27162306a36Sopenharmony_ci * @endian: the endianness that the MMIO data is in
27262306a36Sopenharmony_ci * @val: The value to write
27362306a36Sopenharmony_ci *
27462306a36Sopenharmony_ci * Returns 0 for success, negative on error
27562306a36Sopenharmony_ci */
27662306a36Sopenharmony_ciint ocxl_global_mmio_write64(struct ocxl_afu *afu, size_t offset,
27762306a36Sopenharmony_ci			     enum ocxl_endian endian, u64 val);
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_ci/**
28062306a36Sopenharmony_ci * ocxl_global_mmio_set32() - Set bits in a 32 bit global MMIO register
28162306a36Sopenharmony_ci * @afu: The AFU
28262306a36Sopenharmony_ci * @offset: The Offset from the start of MMIO
28362306a36Sopenharmony_ci * @endian: the endianness that the MMIO data is in
28462306a36Sopenharmony_ci * @mask: a mask of the bits to set
28562306a36Sopenharmony_ci *
28662306a36Sopenharmony_ci * Returns 0 for success, negative on error
28762306a36Sopenharmony_ci */
28862306a36Sopenharmony_ciint ocxl_global_mmio_set32(struct ocxl_afu *afu, size_t offset,
28962306a36Sopenharmony_ci			   enum ocxl_endian endian, u32 mask);
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ci/**
29262306a36Sopenharmony_ci * ocxl_global_mmio_set64() - Set bits in a 64 bit global MMIO register
29362306a36Sopenharmony_ci * @afu: The AFU
29462306a36Sopenharmony_ci * @offset: The Offset from the start of MMIO
29562306a36Sopenharmony_ci * @endian: the endianness that the MMIO data is in
29662306a36Sopenharmony_ci * @mask: a mask of the bits to set
29762306a36Sopenharmony_ci *
29862306a36Sopenharmony_ci * Returns 0 for success, negative on error
29962306a36Sopenharmony_ci */
30062306a36Sopenharmony_ciint ocxl_global_mmio_set64(struct ocxl_afu *afu, size_t offset,
30162306a36Sopenharmony_ci			   enum ocxl_endian endian, u64 mask);
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_ci/**
30462306a36Sopenharmony_ci * ocxl_global_mmio_clear32() - Set bits in a 32 bit global MMIO register
30562306a36Sopenharmony_ci * @afu: The AFU
30662306a36Sopenharmony_ci * @offset: The Offset from the start of MMIO
30762306a36Sopenharmony_ci * @endian: the endianness that the MMIO data is in
30862306a36Sopenharmony_ci * @mask: a mask of the bits to set
30962306a36Sopenharmony_ci *
31062306a36Sopenharmony_ci * Returns 0 for success, negative on error
31162306a36Sopenharmony_ci */
31262306a36Sopenharmony_ciint ocxl_global_mmio_clear32(struct ocxl_afu *afu, size_t offset,
31362306a36Sopenharmony_ci			     enum ocxl_endian endian, u32 mask);
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_ci/**
31662306a36Sopenharmony_ci * ocxl_global_mmio_clear64() - Set bits in a 64 bit global MMIO register
31762306a36Sopenharmony_ci * @afu: The AFU
31862306a36Sopenharmony_ci * @offset: The Offset from the start of MMIO
31962306a36Sopenharmony_ci * @endian: the endianness that the MMIO data is in
32062306a36Sopenharmony_ci * @mask: a mask of the bits to set
32162306a36Sopenharmony_ci *
32262306a36Sopenharmony_ci * Returns 0 for success, negative on error
32362306a36Sopenharmony_ci */
32462306a36Sopenharmony_ciint ocxl_global_mmio_clear64(struct ocxl_afu *afu, size_t offset,
32562306a36Sopenharmony_ci			     enum ocxl_endian endian, u64 mask);
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci// Functions left here are for compatibility with the cxlflash driver
32862306a36Sopenharmony_ci
32962306a36Sopenharmony_ci/*
33062306a36Sopenharmony_ci * Read the configuration space of a function for the AFU specified by
33162306a36Sopenharmony_ci * the index 'afu_idx'. Fills in a ocxl_afu_config structure
33262306a36Sopenharmony_ci */
33362306a36Sopenharmony_ciint ocxl_config_read_afu(struct pci_dev *dev,
33462306a36Sopenharmony_ci				struct ocxl_fn_config *fn,
33562306a36Sopenharmony_ci				struct ocxl_afu_config *afu,
33662306a36Sopenharmony_ci				u8 afu_idx);
33762306a36Sopenharmony_ci
33862306a36Sopenharmony_ci/*
33962306a36Sopenharmony_ci * Tell an AFU, by writing in the configuration space, the PASIDs that
34062306a36Sopenharmony_ci * it can use. Range starts at 'pasid_base' and its size is a multiple
34162306a36Sopenharmony_ci * of 2
34262306a36Sopenharmony_ci *
34362306a36Sopenharmony_ci * 'afu_control_offset' is the offset of the AFU control DVSEC which
34462306a36Sopenharmony_ci * can be found in the function configuration
34562306a36Sopenharmony_ci */
34662306a36Sopenharmony_civoid ocxl_config_set_afu_pasid(struct pci_dev *dev,
34762306a36Sopenharmony_ci				int afu_control_offset,
34862306a36Sopenharmony_ci				int pasid_base, u32 pasid_count_log);
34962306a36Sopenharmony_ci
35062306a36Sopenharmony_ci/*
35162306a36Sopenharmony_ci * Get the actag configuration for the function:
35262306a36Sopenharmony_ci * 'base' is the first actag value that can be used.
35362306a36Sopenharmony_ci * 'enabled' it the number of actags available, starting from base.
35462306a36Sopenharmony_ci * 'supported' is the total number of actags desired by all the AFUs
35562306a36Sopenharmony_ci *             of the function.
35662306a36Sopenharmony_ci */
35762306a36Sopenharmony_ciint ocxl_config_get_actag_info(struct pci_dev *dev,
35862306a36Sopenharmony_ci				u16 *base, u16 *enabled, u16 *supported);
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_ci/*
36162306a36Sopenharmony_ci * Tell a function, by writing in the configuration space, the actags
36262306a36Sopenharmony_ci * it can use.
36362306a36Sopenharmony_ci *
36462306a36Sopenharmony_ci * 'func_offset' is the offset of the Function DVSEC that can found in
36562306a36Sopenharmony_ci * the function configuration
36662306a36Sopenharmony_ci */
36762306a36Sopenharmony_civoid ocxl_config_set_actag(struct pci_dev *dev, int func_offset,
36862306a36Sopenharmony_ci				u32 actag_base, u32 actag_count);
36962306a36Sopenharmony_ci
37062306a36Sopenharmony_ci/*
37162306a36Sopenharmony_ci * Tell an AFU, by writing in the configuration space, the actags it
37262306a36Sopenharmony_ci * can use.
37362306a36Sopenharmony_ci *
37462306a36Sopenharmony_ci * 'afu_control_offset' is the offset of the AFU control DVSEC for the
37562306a36Sopenharmony_ci * desired AFU. It can be found in the AFU configuration
37662306a36Sopenharmony_ci */
37762306a36Sopenharmony_civoid ocxl_config_set_afu_actag(struct pci_dev *dev,
37862306a36Sopenharmony_ci				int afu_control_offset,
37962306a36Sopenharmony_ci				int actag_base, int actag_count);
38062306a36Sopenharmony_ci
38162306a36Sopenharmony_ci/*
38262306a36Sopenharmony_ci * Enable/disable an AFU, by writing in the configuration space.
38362306a36Sopenharmony_ci *
38462306a36Sopenharmony_ci * 'afu_control_offset' is the offset of the AFU control DVSEC for the
38562306a36Sopenharmony_ci * desired AFU. It can be found in the AFU configuration
38662306a36Sopenharmony_ci */
38762306a36Sopenharmony_civoid ocxl_config_set_afu_state(struct pci_dev *dev,
38862306a36Sopenharmony_ci				int afu_control_offset, int enable);
38962306a36Sopenharmony_ci
39062306a36Sopenharmony_ci/*
39162306a36Sopenharmony_ci * Set the Transaction Layer configuration in the configuration space.
39262306a36Sopenharmony_ci * Only needed for function 0.
39362306a36Sopenharmony_ci *
39462306a36Sopenharmony_ci * It queries the host TL capabilities, find some common ground
39562306a36Sopenharmony_ci * between the host and device, and set the Transaction Layer on both
39662306a36Sopenharmony_ci * accordingly.
39762306a36Sopenharmony_ci */
39862306a36Sopenharmony_ciint ocxl_config_set_TL(struct pci_dev *dev, int tl_dvsec);
39962306a36Sopenharmony_ci
40062306a36Sopenharmony_ci/*
40162306a36Sopenharmony_ci * Request an AFU to terminate a PASID.
40262306a36Sopenharmony_ci * Will return once the AFU has acked the request, or an error in case
40362306a36Sopenharmony_ci * of timeout.
40462306a36Sopenharmony_ci *
40562306a36Sopenharmony_ci * The hardware can only terminate one PASID at a time, so caller must
40662306a36Sopenharmony_ci * guarantee some kind of serialization.
40762306a36Sopenharmony_ci *
40862306a36Sopenharmony_ci * 'afu_control_offset' is the offset of the AFU control DVSEC for the
40962306a36Sopenharmony_ci * desired AFU. It can be found in the AFU configuration
41062306a36Sopenharmony_ci */
41162306a36Sopenharmony_ciint ocxl_config_terminate_pasid(struct pci_dev *dev,
41262306a36Sopenharmony_ci				int afu_control_offset, int pasid);
41362306a36Sopenharmony_ci
41462306a36Sopenharmony_ci/*
41562306a36Sopenharmony_ci * Read the configuration space of a function and fill in a
41662306a36Sopenharmony_ci * ocxl_fn_config structure with all the function details
41762306a36Sopenharmony_ci */
41862306a36Sopenharmony_ciint ocxl_config_read_function(struct pci_dev *dev,
41962306a36Sopenharmony_ci				struct ocxl_fn_config *fn);
42062306a36Sopenharmony_ci
42162306a36Sopenharmony_ci/*
42262306a36Sopenharmony_ci * Set up the opencapi link for the function.
42362306a36Sopenharmony_ci *
42462306a36Sopenharmony_ci * When called for the first time for a link, it sets up the Shared
42562306a36Sopenharmony_ci * Process Area for the link and the interrupt handler to process
42662306a36Sopenharmony_ci * translation faults.
42762306a36Sopenharmony_ci *
42862306a36Sopenharmony_ci * Returns a 'link handle' that should be used for further calls for
42962306a36Sopenharmony_ci * the link
43062306a36Sopenharmony_ci */
43162306a36Sopenharmony_ciint ocxl_link_setup(struct pci_dev *dev, int PE_mask,
43262306a36Sopenharmony_ci			void **link_handle);
43362306a36Sopenharmony_ci
43462306a36Sopenharmony_ci/*
43562306a36Sopenharmony_ci * Remove the association between the function and its link.
43662306a36Sopenharmony_ci */
43762306a36Sopenharmony_civoid ocxl_link_release(struct pci_dev *dev, void *link_handle);
43862306a36Sopenharmony_ci
43962306a36Sopenharmony_ci/*
44062306a36Sopenharmony_ci * Add a Process Element to the Shared Process Area for a link.
44162306a36Sopenharmony_ci * The process is defined by its PASID, pid, tid and its mm_struct.
44262306a36Sopenharmony_ci *
44362306a36Sopenharmony_ci * 'xsl_err_cb' is an optional callback if the driver wants to be
44462306a36Sopenharmony_ci * notified when the translation fault interrupt handler detects an
44562306a36Sopenharmony_ci * address error.
44662306a36Sopenharmony_ci * 'xsl_err_data' is an argument passed to the above callback, if
44762306a36Sopenharmony_ci * defined
44862306a36Sopenharmony_ci */
44962306a36Sopenharmony_ciint ocxl_link_add_pe(void *link_handle, int pasid, u32 pidr, u32 tidr,
45062306a36Sopenharmony_ci		u64 amr, u16 bdf, struct mm_struct *mm,
45162306a36Sopenharmony_ci		void (*xsl_err_cb)(void *data, u64 addr, u64 dsisr),
45262306a36Sopenharmony_ci		void *xsl_err_data);
45362306a36Sopenharmony_ci
45462306a36Sopenharmony_ci/*
45562306a36Sopenharmony_ci * Remove a Process Element from the Shared Process Area for a link
45662306a36Sopenharmony_ci */
45762306a36Sopenharmony_ciint ocxl_link_remove_pe(void *link_handle, int pasid);
45862306a36Sopenharmony_ci
45962306a36Sopenharmony_ci/*
46062306a36Sopenharmony_ci * Allocate an AFU interrupt associated to the link.
46162306a36Sopenharmony_ci *
46262306a36Sopenharmony_ci * 'hw_irq' is the hardware interrupt number
46362306a36Sopenharmony_ci */
46462306a36Sopenharmony_ciint ocxl_link_irq_alloc(void *link_handle, int *hw_irq);
46562306a36Sopenharmony_ci
46662306a36Sopenharmony_ci/*
46762306a36Sopenharmony_ci * Free a previously allocated AFU interrupt
46862306a36Sopenharmony_ci */
46962306a36Sopenharmony_civoid ocxl_link_free_irq(void *link_handle, int hw_irq);
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_ci#endif /* _MISC_OCXL_H_ */
472