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.
44 #define SBU_QP_QUEUE_SIZE 8
45 #define MLX5_FPGA_CMD_TIMEOUT_MSEC (60 * 1000)
47 enum mlx5_fpga_access_type {
48 MLX5_FPGA_ACCESS_TYPE_I2C = 0x0,
49 MLX5_FPGA_ACCESS_TYPE_DONTCARE = 0x0,
52 struct mlx5_fpga_conn;
53 struct mlx5_fpga_device;
56 * struct mlx5_fpga_dma_entry - A scatter-gather DMA entry
58 struct mlx5_fpga_dma_entry {
59 /** @data: Virtual address pointer to the data */
61 /** @size: Size in bytes of the data */
63 /** @dma_addr: Private member. Physical DMA-mapped address of the data */
68 * struct mlx5_fpga_dma_buf - A packet buffer
69 * May contain up to 2 scatter-gather data entries
71 struct mlx5_fpga_dma_buf {
72 /** @dma_dir: DMA direction */
73 enum dma_data_direction dma_dir;
74 /** @sg: Scatter-gather entries pointing to the data in memory */
75 struct mlx5_fpga_dma_entry sg[2];
76 /** @list: Item in SQ backlog, for TX packets */
77 struct list_head list;
79 * @complete: Completion routine, for TX packets
80 * @conn: FPGA Connection this packet was sent to
81 * @fdev: FPGA device this packet was sent to
82 * @buf: The packet buffer
83 * @status: 0 if successful, or an error code otherwise
85 void (*complete)(struct mlx5_fpga_conn *conn,
86 struct mlx5_fpga_device *fdev,
87 struct mlx5_fpga_dma_buf *buf, u8 status);
91 * struct mlx5_fpga_conn_attr - FPGA connection attributes
92 * Describes the attributes of a connection
94 struct mlx5_fpga_conn_attr {
95 /** @tx_size: Size of connection TX queue, in packets */
97 /** @rx_size: Size of connection RX queue, in packets */
100 * @recv_cb: Callback function which is called for received packets
101 * @cb_arg: The value provided in mlx5_fpga_conn_attr.cb_arg
102 * @buf: A buffer containing a received packet
104 * buf is guaranteed to only contain a single scatter-gather entry.
105 * The size of the actual packet received is specified in buf.sg[0].size
106 * When this callback returns, the packet buffer may be re-used for
107 * subsequent receives.
109 void (*recv_cb)(void *cb_arg, struct mlx5_fpga_dma_buf *buf);
114 * mlx5_fpga_sbu_conn_create() - Initialize a new FPGA SBU connection
115 * @fdev: The FPGA device
116 * @attr: Attributes of the new connection
118 * Sets up a new FPGA SBU connection with the specified attributes.
119 * The receive callback function may be called for incoming messages even
120 * before this function returns.
122 * The caller must eventually destroy the connection by calling
123 * mlx5_fpga_sbu_conn_destroy.
125 * Return: A new connection, or ERR_PTR() error value otherwise.
127 struct mlx5_fpga_conn *
128 mlx5_fpga_sbu_conn_create(struct mlx5_fpga_device *fdev,
129 struct mlx5_fpga_conn_attr *attr);
132 * mlx5_fpga_sbu_conn_destroy() - Destroy an FPGA SBU connection
133 * @conn: The FPGA SBU connection to destroy
135 * Cleans up an FPGA SBU connection which was previously created with
136 * mlx5_fpga_sbu_conn_create.
138 void mlx5_fpga_sbu_conn_destroy(struct mlx5_fpga_conn *conn);
141 * mlx5_fpga_sbu_conn_sendmsg() - Queue the transmission of a packet
142 * @fdev: An FPGA SBU connection
143 * @buf: The packet buffer
145 * Queues a packet for transmission over an FPGA SBU connection.
146 * The buffer should not be modified or freed until completion.
147 * Upon completion, the buf's complete() callback is invoked, indicating the
148 * success or error status of the transmission.
150 * Return: 0 if successful, or an error value otherwise.
152 int mlx5_fpga_sbu_conn_sendmsg(struct mlx5_fpga_conn *conn,
153 struct mlx5_fpga_dma_buf *buf);
156 * mlx5_fpga_mem_read() - Read from FPGA memory address space
157 * @fdev: The FPGA device
158 * @size: Size of chunk to read, in bytes
159 * @addr: Starting address to read from, in FPGA address space
160 * @buf: Buffer to read into
161 * @access_type: Method for reading
163 * Reads from the specified address into the specified buffer.
164 * The address may point to configuration space or to DDR.
165 * Large reads may be performed internally as several non-atomic operations.
166 * This function may sleep, so should not be called from atomic contexts.
168 * Return: 0 if successful, or an error value otherwise.
170 int mlx5_fpga_mem_read(struct mlx5_fpga_device *fdev, size_t size, u64 addr,
171 void *buf, enum mlx5_fpga_access_type access_type);
174 * mlx5_fpga_mem_write() - Write to FPGA memory address space
175 * @fdev: The FPGA device
176 * @size: Size of chunk to write, in bytes
177 * @addr: Starting address to write to, in FPGA address space
178 * @buf: Buffer which contains data to write
179 * @access_type: Method for writing
181 * Writes the specified buffer data to FPGA memory at the specified address.
182 * The address may point to configuration space or to DDR.
183 * Large writes may be performed internally as several non-atomic operations.
184 * This function may sleep, so should not be called from atomic contexts.
186 * Return: 0 if successful, or an error value otherwise.
188 int mlx5_fpga_mem_write(struct mlx5_fpga_device *fdev, size_t size, u64 addr,
189 void *buf, enum mlx5_fpga_access_type access_type);
192 * mlx5_fpga_get_sbu_caps() - Read the SBU capabilities
193 * @fdev: The FPGA device
194 * @size: Size of the buffer to read into
195 * @buf: Buffer to read the capabilities into
197 * Reads the FPGA SBU capabilities into the specified buffer.
198 * The format of the capabilities buffer is SBU-dependent.
200 * Return: 0 if successful
201 * -EINVAL if the buffer is not large enough to contain SBU caps
202 * or any other error value otherwise.
204 int mlx5_fpga_get_sbu_caps(struct mlx5_fpga_device *fdev, int size, void *buf);
206 #endif /* MLX5_FPGA_SDK_H */