2 * Copyright (c) 2017 Mellanox Technologies. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #ifndef MLX5_FPGA_SDK_H
35 #define MLX5_FPGA_SDK_H
37 #include <linux/types.h>
38 #include <linux/dma-direction.h>
42 * This header defines the in-kernel API for Innova FPGA client drivers.
45 enum mlx5_fpga_access_type {
46 MLX5_FPGA_ACCESS_TYPE_I2C = 0x0,
47 MLX5_FPGA_ACCESS_TYPE_DONTCARE = 0x0,
50 struct mlx5_fpga_conn;
51 struct mlx5_fpga_device;
54 * struct mlx5_fpga_dma_entry - A scatter-gather DMA entry
56 struct mlx5_fpga_dma_entry {
57 /** @data: Virtual address pointer to the data */
59 /** @size: Size in bytes of the data */
61 /** @dma_addr: Private member. Physical DMA-mapped address of the data */
66 * struct mlx5_fpga_dma_buf - A packet buffer
67 * May contain up to 2 scatter-gather data entries
69 struct mlx5_fpga_dma_buf {
70 /** @dma_dir: DMA direction */
71 enum dma_data_direction dma_dir;
72 /** @sg: Scatter-gather entries pointing to the data in memory */
73 struct mlx5_fpga_dma_entry sg[2];
74 /** @list: Item in SQ backlog, for TX packets */
75 struct list_head list;
77 * @complete: Completion routine, for TX packets
78 * @conn: FPGA Connection this packet was sent to
79 * @fdev: FPGA device this packet was sent to
80 * @buf: The packet buffer
81 * @status: 0 if successful, or an error code otherwise
83 void (*complete)(struct mlx5_fpga_conn *conn,
84 struct mlx5_fpga_device *fdev,
85 struct mlx5_fpga_dma_buf *buf, u8 status);
89 * struct mlx5_fpga_conn_attr - FPGA connection attributes
90 * Describes the attributes of a connection
92 struct mlx5_fpga_conn_attr {
93 /** @tx_size: Size of connection TX queue, in packets */
95 /** @rx_size: Size of connection RX queue, in packets */
98 * @recv_cb: Callback function which is called for received packets
99 * @cb_arg: The value provided in mlx5_fpga_conn_attr.cb_arg
100 * @buf: A buffer containing a received packet
102 * buf is guaranteed to only contain a single scatter-gather entry.
103 * The size of the actual packet received is specified in buf.sg[0].size
104 * When this callback returns, the packet buffer may be re-used for
105 * subsequent receives.
107 void (*recv_cb)(void *cb_arg, struct mlx5_fpga_dma_buf *buf);
112 * mlx5_fpga_sbu_conn_create() - Initialize a new FPGA SBU connection
113 * @fdev: The FPGA device
114 * @attr: Attributes of the new connection
116 * Sets up a new FPGA SBU connection with the specified attributes.
117 * The receive callback function may be called for incoming messages even
118 * before this function returns.
120 * The caller must eventually destroy the connection by calling
121 * mlx5_fpga_sbu_conn_destroy.
123 * Return: A new connection, or ERR_PTR() error value otherwise.
125 struct mlx5_fpga_conn *
126 mlx5_fpga_sbu_conn_create(struct mlx5_fpga_device *fdev,
127 struct mlx5_fpga_conn_attr *attr);
130 * mlx5_fpga_sbu_conn_destroy() - Destroy an FPGA SBU connection
131 * @conn: The FPGA SBU connection to destroy
133 * Cleans up an FPGA SBU connection which was previously created with
134 * mlx5_fpga_sbu_conn_create.
136 void mlx5_fpga_sbu_conn_destroy(struct mlx5_fpga_conn *conn);
139 * mlx5_fpga_sbu_conn_sendmsg() - Queue the transmission of a packet
140 * @fdev: An FPGA SBU connection
141 * @buf: The packet buffer
143 * Queues a packet for transmission over an FPGA SBU connection.
144 * The buffer should not be modified or freed until completion.
145 * Upon completion, the buf's complete() callback is invoked, indicating the
146 * success or error status of the transmission.
148 * Return: 0 if successful, or an error value otherwise.
150 int mlx5_fpga_sbu_conn_sendmsg(struct mlx5_fpga_conn *conn,
151 struct mlx5_fpga_dma_buf *buf);
154 * mlx5_fpga_mem_read() - Read from FPGA memory address space
155 * @fdev: The FPGA device
156 * @size: Size of chunk to read, in bytes
157 * @addr: Starting address to read from, in FPGA address space
158 * @buf: Buffer to read into
159 * @access_type: Method for reading
161 * Reads from the specified address into the specified buffer.
162 * The address may point to configuration space or to DDR.
163 * Large reads may be performed internally as several non-atomic operations.
164 * This function may sleep, so should not be called from atomic contexts.
166 * Return: 0 if successful, or an error value otherwise.
168 int mlx5_fpga_mem_read(struct mlx5_fpga_device *fdev, size_t size, u64 addr,
169 void *buf, enum mlx5_fpga_access_type access_type);
172 * mlx5_fpga_mem_write() - Write to FPGA memory address space
173 * @fdev: The FPGA device
174 * @size: Size of chunk to write, in bytes
175 * @addr: Starting address to write to, in FPGA address space
176 * @buf: Buffer which contains data to write
177 * @access_type: Method for writing
179 * Writes the specified buffer data to FPGA memory at the specified address.
180 * The address may point to configuration space or to DDR.
181 * Large writes may be performed internally as several non-atomic operations.
182 * This function may sleep, so should not be called from atomic contexts.
184 * Return: 0 if successful, or an error value otherwise.
186 int mlx5_fpga_mem_write(struct mlx5_fpga_device *fdev, size_t size, u64 addr,
187 void *buf, enum mlx5_fpga_access_type access_type);
190 * mlx5_fpga_get_sbu_caps() - Read the SBU capabilities
191 * @fdev: The FPGA device
192 * @size: Size of the buffer to read into
193 * @buf: Buffer to read the capabilities into
195 * Reads the FPGA SBU capabilities into the specified buffer.
196 * The format of the capabilities buffer is SBU-dependent.
198 * Return: 0 if successful
199 * -EINVAL if the buffer is not large enough to contain SBU caps
200 * or any other error value otherwise.
202 int mlx5_fpga_get_sbu_caps(struct mlx5_fpga_device *fdev, int size, void *buf);
204 #endif /* MLX5_FPGA_SDK_H */