^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Header file for FPGA Accelerated Function Unit (AFU) Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2017-2018 Intel Corporation, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Wu Hao <hao.wu@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Xiao Guangrong <guangrong.xiao@linux.intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Joseph Grecco <joe.grecco@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Enno Luebbers <enno.luebbers@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Tim Whisonant <tim.whisonant@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Ananda Ravuri <ananda.ravuri@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Henry Mitchel <henry.mitchel@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #ifndef __DFL_AFU_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define __DFL_AFU_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "dfl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * struct dfl_afu_mmio_region - afu mmio region data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * @index: region index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * @flags: region flags (access permission).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * @size: region size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * @offset: region offset from start of the device fd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * @phys: region's physical address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * @node: node to add to afu feature dev's region list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct dfl_afu_mmio_region {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) u32 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) u64 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) u64 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) u64 phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct list_head node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * struct fpga_afu_dma_region - afu DMA region data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * @user_addr: region userspace virtual address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * @length: region length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * @iova: region IO virtual address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * @pages: ptr to pages of this region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @node: rb tree node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * @in_use: flag to indicate if this region is in_use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct dfl_afu_dma_region {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u64 user_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u64 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u64 iova;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct page **pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct rb_node node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) bool in_use;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * struct dfl_afu - afu device data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * @region_cur_offset: current region offset from start to the device fd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * @num_regions: num of mmio regions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * @regions: the mmio region linked list of this afu feature device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * @dma_regions: root of dma regions rb tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * @num_umsgs: num of umsgs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * @pdata: afu platform device's pdata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct dfl_afu {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) u64 region_cur_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int num_regions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) u8 num_umsgs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct list_head regions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct rb_root dma_regions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct dfl_feature_platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* hold pdata->lock when call __afu_port_enable/disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) void __afu_port_enable(struct platform_device *pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int __afu_port_disable(struct platform_device *pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) void afu_mmio_region_init(struct dfl_feature_platform_data *pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int afu_mmio_region_add(struct dfl_feature_platform_data *pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u32 region_index, u64 region_size, u64 phys, u32 flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) void afu_mmio_region_destroy(struct dfl_feature_platform_data *pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int afu_mmio_region_get_by_index(struct dfl_feature_platform_data *pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) u32 region_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct dfl_afu_mmio_region *pregion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int afu_mmio_region_get_by_offset(struct dfl_feature_platform_data *pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) u64 offset, u64 size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct dfl_afu_mmio_region *pregion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) void afu_dma_region_init(struct dfl_feature_platform_data *pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) void afu_dma_region_destroy(struct dfl_feature_platform_data *pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) int afu_dma_map_region(struct dfl_feature_platform_data *pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) u64 user_addr, u64 length, u64 *iova);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int afu_dma_unmap_region(struct dfl_feature_platform_data *pdata, u64 iova);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct dfl_afu_dma_region *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) afu_dma_region_find(struct dfl_feature_platform_data *pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) u64 iova, u64 size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) extern const struct dfl_feature_ops port_err_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) extern const struct dfl_feature_id port_err_id_table[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) extern const struct attribute_group port_err_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #endif /* __DFL_AFU_H */