Blame opae-libs/plugins/xfpga/fpga-dfl.h

Packit 534379
// Copyright(c) 2017-2020, Intel Corporation
Packit 534379
//
Packit 534379
// Redistribution  and  use  in source  and  binary  forms,  with  or  without
Packit 534379
// modification, are permitted provided that the following conditions are met:
Packit 534379
//
Packit 534379
// * Redistributions of  source code  must retain the  above copyright notice,
Packit 534379
//   this list of conditions and the following disclaimer.
Packit 534379
// * Redistributions in binary form must reproduce the above copyright notice,
Packit 534379
//   this list of conditions and the following disclaimer in the documentation
Packit 534379
//   and/or other materials provided with the distribution.
Packit 534379
// * Neither the name  of Intel Corporation  nor the names of its contributors
Packit 534379
//   may be used to  endorse or promote  products derived  from this  software
Packit 534379
//   without specific prior written permission.
Packit 534379
//
Packit 534379
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit 534379
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,  BUT NOT LIMITED TO,  THE
Packit 534379
// IMPLIED WARRANTIES OF  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 534379
// ARE DISCLAIMED.  IN NO EVENT  SHALL THE COPYRIGHT OWNER  OR CONTRIBUTORS BE
Packit 534379
// LIABLE  FOR  ANY  DIRECT,  INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR
Packit 534379
// CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT  NOT LIMITED  TO,  PROCUREMENT  OF
Packit 534379
// SUBSTITUTE GOODS OR SERVICES;  LOSS OF USE,  DATA, OR PROFITS;  OR BUSINESS
Packit 534379
// INTERRUPTION)  HOWEVER CAUSED  AND ON ANY THEORY  OF LIABILITY,  WHETHER IN
Packit 534379
// CONTRACT,  STRICT LIABILITY,  OR TORT  (INCLUDING NEGLIGENCE  OR OTHERWISE)
Packit 534379
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  EVEN IF ADVISED OF THE
Packit 534379
// POSSIBILITY OF SUCH DAMAGE.
Packit 534379
Packit 534379
#ifndef _UAPI_LINUX_FPGA_DFL_H
Packit 534379
#define _UAPI_LINUX_FPGA_DFL_H
Packit 534379
Packit 534379
#include <linux/types.h>
Packit 534379
#include <linux/ioctl.h>
Packit 534379
Packit 534379
#define DFL_FPGA_API_VERSION 0
Packit 534379
Packit 534379
/*
Packit 534379
 * The IOCTL interface for DFL based FPGA is designed for extensibility by
Packit 534379
 * embedding the structure length (argsz) and flags into structures passed
Packit 534379
 * between kernel and userspace. This design referenced the VFIO IOCTL
Packit 534379
 * interface (include/uapi/linux/vfio.h).
Packit 534379
 */
Packit 534379
Packit 534379
#define DFL_FPGA_MAGIC 0xB6
Packit 534379
Packit 534379
#define DFL_FPGA_BASE 0
Packit 534379
#define DFL_PORT_BASE 0x40
Packit 534379
#define DFL_FME_BASE 0x80
Packit 534379
Packit 534379
/* Common IOCTLs for both FME and AFU file descriptor */
Packit 534379
Packit 534379
/**
Packit 534379
 * DFL_FPGA_GET_API_VERSION - _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 0)
Packit 534379
 *
Packit 534379
 * Report the version of the driver API.
Packit 534379
 * Return: Driver API Version.
Packit 534379
 */
Packit 534379
Packit 534379
#define DFL_FPGA_GET_API_VERSION	_IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 0)
Packit 534379
Packit 534379
/**
Packit 534379
 * DFL_FPGA_CHECK_EXTENSION - _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 1)
Packit 534379
 *
Packit 534379
 * Check whether an extension is supported.
Packit 534379
 * Return: 0 if not supported, otherwise the extension is supported.
Packit 534379
 */
Packit 534379
Packit 534379
#define DFL_FPGA_CHECK_EXTENSION	_IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 1)
Packit 534379
Packit 534379
/* IOCTLs for AFU file descriptor */
Packit 534379
Packit 534379
/**
Packit 534379
 * DFL_FPGA_PORT_RESET - _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 0)
Packit 534379
 *
Packit 534379
 * Reset the FPGA Port and its AFU. No parameters are supported.
Packit 534379
 * Userspace can do Port reset at any time, e.g. during DMA or PR. But
Packit 534379
 * it should never cause any system level issue, only functional failure
Packit 534379
 * (e.g. DMA or PR operation failure) and be recoverable from the failure.
Packit 534379
 * Return: 0 on success, -errno of failure
Packit 534379
 */
Packit 534379
Packit 534379
#define DFL_FPGA_PORT_RESET		_IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 0)
Packit 534379
Packit 534379
/**
Packit 534379
 * DFL_FPGA_PORT_GET_INFO - _IOR(DFL_FPGA_MAGIC, DFL_PORT_BASE + 1,
Packit 534379
 *						struct dfl_fpga_port_info)
Packit 534379
 *
Packit 534379
 * Retrieve information about the fpga port.
Packit 534379
 * Driver fills the info in provided struct dfl_fpga_port_info.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct dfl_fpga_port_info {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	/* Output */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__u32 num_regions;	/* The number of supported regions */
Packit 534379
	__u32 num_umsgs;	/* The number of allocated umsgs */
Packit 534379
};
Packit 534379
Packit 534379
#define DFL_FPGA_PORT_GET_INFO		_IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 1)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_PORT_GET_REGION_INFO - _IOWR(FPGA_MAGIC, PORT_BASE + 2,
Packit 534379
 *					struct dfl_fpga_port_region_info)
Packit 534379
 *
Packit 534379
 * Retrieve information about a device memory region.
Packit 534379
 * Caller provides struct dfl_fpga_port_region_info with index value set.
Packit 534379
 * Driver returns the region info in other fields.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct dfl_fpga_port_region_info {
Packit 534379
	/* input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	/* Output */
Packit 534379
	__u32 flags;		/* Access permission */
Packit 534379
#define DFL_PORT_REGION_READ	(1 << 0)	/* Region is readable */
Packit 534379
#define DFL_PORT_REGION_WRITE	(1 << 1)	/* Region is writable */
Packit 534379
#define DFL_PORT_REGION_MMAP	(1 << 2)	/* Can be mmaped to userspace */
Packit 534379
	/* Input */
Packit 534379
	__u32 index;		/* Region index */
Packit 534379
#define DFL_PORT_REGION_INDEX_AFU	0	/* AFU */
Packit 534379
#define DFL_PORT_REGION_INDEX_STP	1	/* Signal Tap */
Packit 534379
	__u32 padding;
Packit 534379
	/* Output */
Packit 534379
	__u64 size;		/* Region size (bytes) */
Packit 534379
	__u64 offset;		/* Region offset from start of device fd */
Packit 534379
};
Packit 534379
Packit 534379
#define DFL_FPGA_PORT_GET_REGION_INFO	_IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 2)
Packit 534379
Packit 534379
/**
Packit 534379
 * DFL_FPGA_PORT_DMA_MAP - _IOWR(DFL_FPGA_MAGIC, DFL_PORT_BASE + 3,
Packit 534379
 *						struct dfl_fpga_port_dma_map)
Packit 534379
 *
Packit 534379
 * Map the dma memory per user_addr and length which are provided by caller.
Packit 534379
 * Driver fills the iova in provided struct afu_port_dma_map.
Packit 534379
 * This interface only accepts page-size aligned user memory for dma mapping.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct dfl_fpga_port_dma_map {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__u64 user_addr;        /* Process virtual address */
Packit 534379
	__u64 length;           /* Length of mapping (bytes)*/
Packit 534379
	/* Output */
Packit 534379
	__u64 iova;             /* IO virtual address */
Packit 534379
};
Packit 534379
Packit 534379
#define DFL_FPGA_PORT_DMA_MAP		_IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 3)
Packit 534379
Packit 534379
/**
Packit 534379
 * DFL_FPGA_PORT_DMA_UNMAP - _IOW(FPGA_MAGIC, PORT_BASE + 4,
Packit 534379
 *						struct dfl_fpga_port_dma_unmap)
Packit 534379
 *
Packit 534379
 * Unmap the dma memory per iova provided by caller.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct dfl_fpga_port_dma_unmap {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__u64 iova;		/* IO virtual address */
Packit 534379
};
Packit 534379
Packit 534379
#define DFL_FPGA_PORT_DMA_UNMAP		_IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 4)
Packit 534379
Packit 534379
/* IOCTLs for FME file descriptor */
Packit 534379
Packit 534379
/**
Packit 534379
 * DFL_FPGA_FME_PORT_PR - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 0,
Packit 534379
 *						struct dfl_fpga_fme_port_pr)
Packit 534379
 *
Packit 534379
 * Driver does Partial Reconfiguration based on Port ID and Buffer (Image)
Packit 534379
 * provided by caller.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 * If DFL_FPGA_FME_PORT_PR returns -EIO, that indicates the HW has detected
Packit 534379
 * some errors during PR, under this case, the user can fetch HW error info
Packit 534379
 * from the status of FME's fpga manager.
Packit 534379
 */
Packit 534379
Packit 534379
struct dfl_fpga_fme_port_pr {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__u32 port_id;
Packit 534379
	__u32 buffer_size;
Packit 534379
	__u64 buffer_address;	/* Userspace address to the buffer for PR */
Packit 534379
};
Packit 534379
Packit 534379
#define DFL_FPGA_FME_PORT_PR	_IO(DFL_FPGA_MAGIC, DFL_FME_BASE + 0)
Packit 534379
Packit 534379
/**
Packit 534379
 * DFL_FPGA_FME_PORT_RELEASE - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 1,
Packit 534379
 *						int port_id)
Packit 534379
 *
Packit 534379
 * Driver releases the port per Port ID provided by caller.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
#define DFL_FPGA_FME_PORT_RELEASE   _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 1, int)
Packit 534379
Packit 534379
/**
Packit 534379
 * DFL_FPGA_FME_PORT_ASSIGN - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 2,
Packit 534379
 *						int port_id)
Packit 534379
 *
Packit 534379
 * Driver assigns the port back per Port ID provided by caller.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
#define DFL_FPGA_FME_PORT_ASSIGN     _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 2, int)
Packit 534379
Packit 534379
#endif /* _UAPI_LINUX_FPGA_DFL_H */