1341572Sslavash/*- 2341572Sslavash * Copyright (c) 2017 Mellanox Technologies. All rights reserved. 3341572Sslavash * 4341572Sslavash * This software is available to you under a choice of one of two 5341572Sslavash * licenses. You may choose to be licensed under the terms of the GNU 6341572Sslavash * General Public License (GPL) Version 2, available from the file 7341572Sslavash * COPYING in the main directory of this source tree, or the 8341572Sslavash * OpenIB.org BSD license below: 9341572Sslavash * 10341572Sslavash * Redistribution and use in source and binary forms, with or 11341572Sslavash * without modification, are permitted provided that the following 12341572Sslavash * conditions are met: 13341572Sslavash * 14341572Sslavash * - Redistributions of source code must retain the above 15341572Sslavash * copyright notice, this list of conditions and the following 16341572Sslavash * disclaimer. 17341572Sslavash * 18341572Sslavash * - Redistributions in binary form must reproduce the above 19341572Sslavash * copyright notice, this list of conditions and the following 20341572Sslavash * disclaimer in the documentation and/or other materials 21341572Sslavash * provided with the distribution. 22341572Sslavash * 23341572Sslavash * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24341572Sslavash * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25341572Sslavash * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26341572Sslavash * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27341572Sslavash * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28341572Sslavash * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29341572Sslavash * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30341572Sslavash * SOFTWARE. 31341572Sslavash * 32341572Sslavash * $FreeBSD: stable/11/sys/dev/mlx5/mlx5_fpga/sdk.h 341966 2018-12-12 12:54:43Z hselasky $ 33341572Sslavash */ 34341572Sslavash 35341572Sslavash#ifndef MLX5_FPGA_SDK_H 36341572Sslavash#define MLX5_FPGA_SDK_H 37341572Sslavash 38341572Sslavash#include <dev/mlx5/driver.h> 39341572Sslavash#include <linux/types.h> 40341572Sslavash#include <linux/list.h> 41341572Sslavash/* #include <linux/dma-direction.h> */ 42341572Sslavash 43341572Sslavash#include <dev/mlx5/mlx5_fpga/cmd.h> 44341572Sslavash#include <dev/mlx5/mlx5io.h> 45341572Sslavash 46341572Sslavash/** 47341572Sslavash * DOC: Innova SDK 48341572Sslavash * This header defines the in-kernel API for Innova FPGA client drivers. 49341572Sslavash */ 50341572Sslavash 51341572Sslavash#define MLX5_FPGA_CLIENT_NAME_MAX 64 52341572Sslavash 53341572Sslavashstruct mlx5_fpga_conn; 54341572Sslavashstruct mlx5_fpga_device; 55341572Sslavash 56341572Sslavash/** 57341572Sslavash * struct mlx5_fpga_client - Describes an Innova client driver 58341572Sslavash */ 59341572Sslavashstruct mlx5_fpga_client { 60341572Sslavash /** 61341572Sslavash * @create: Informs the client that an Innova device was created. 62341572Sslavash * The device is not yet operational at this stage 63341572Sslavash * This callback is optional 64341572Sslavash * @fdev: The FPGA device 65341572Sslavash */ 66341572Sslavash void (*create)(struct mlx5_fpga_device *fdev); 67341572Sslavash /** 68341572Sslavash * @add: Informs the client that a core device is ready and operational. 69341572Sslavash * @fdev: The FPGA device 70341572Sslavash * @param vid SBU Vendor ID 71341572Sslavash * @param pid SBU Product ID 72341572Sslavash * Any SBU-specific initialization should happen at this stage 73341572Sslavash * Return: 0 on success, nonzero error value otherwise 74341572Sslavash */ 75341572Sslavash int (*add)(struct mlx5_fpga_device *fdev, u32 vid, u16 pid); 76341572Sslavash /** 77341572Sslavash * @remove: Informs the client that a core device is not operational 78341572Sslavash * anymore. 79341572Sslavash * @fdev: The FPGA device 80341572Sslavash * SBU-specific cleanup should happen at this stage 81341572Sslavash * This callback is called once for every successful call to add() 82341572Sslavash */ 83341572Sslavash void (*remove)(struct mlx5_fpga_device *fdev); 84341572Sslavash /** 85341572Sslavash * @destroy: Informs the client that a core device is being destroyed. 86341572Sslavash * @fdev: The FPGA device 87341572Sslavash * The device is not operational at this stage 88341572Sslavash */ 89341572Sslavash void (*destroy)(struct mlx5_fpga_device *fdev); 90341572Sslavash /** The name of this client driver */ 91341572Sslavash char name[MLX5_FPGA_CLIENT_NAME_MAX]; 92341572Sslavash /** For use by core. A link in the list of client drivers */ 93341572Sslavash struct list_head list; 94341572Sslavash}; 95341572Sslavash 96341572Sslavash/** 97341572Sslavash * struct mlx5_fpga_dma_entry - A scatter-gather DMA entry 98341572Sslavash */ 99341572Sslavashstruct mlx5_fpga_dma_entry { 100341572Sslavash /** @data: Virtual address pointer to the data */ 101341572Sslavash void *data; 102341572Sslavash /** @size: Size in bytes of the data */ 103341572Sslavash unsigned int size; 104341572Sslavash /** @dma_addr: Private member. Physical DMA-mapped address of the data */ 105341572Sslavash dma_addr_t dma_addr; 106341572Sslavash}; 107341572Sslavash 108341572Sslavash/** 109341572Sslavash * struct mlx5_fpga_dma_buf - A packet buffer 110341572Sslavash * May contain up to 2 scatter-gather data entries 111341572Sslavash */ 112341572Sslavashstruct mlx5_fpga_dma_buf { 113341572Sslavash /** @dma_dir: DMA direction */ 114341572Sslavash enum dma_data_direction dma_dir; 115341572Sslavash /** @sg: Scatter-gather entries pointing to the data in memory */ 116341572Sslavash struct mlx5_fpga_dma_entry sg[2]; 117341572Sslavash /** @list: Item in SQ backlog, for TX packets */ 118341572Sslavash struct list_head list; 119341572Sslavash /** 120341572Sslavash * @complete: Completion routine, for TX packets 121341572Sslavash * @conn: FPGA Connection this packet was sent to 122341572Sslavash * @fdev: FPGA device this packet was sent to 123341572Sslavash * @buf: The packet buffer 124341572Sslavash * @status: 0 if successful, or an error code otherwise 125341572Sslavash */ 126341572Sslavash void (*complete)(struct mlx5_fpga_conn *conn, 127341572Sslavash struct mlx5_fpga_device *fdev, 128341572Sslavash struct mlx5_fpga_dma_buf *buf, u8 status); 129341572Sslavash}; 130341572Sslavash 131341572Sslavash/** 132341572Sslavash * struct mlx5_fpga_conn_attr - FPGA connection attributes 133341572Sslavash * Describes the attributes of a connection 134341572Sslavash */ 135341572Sslavashstruct mlx5_fpga_conn_attr { 136341572Sslavash /** @tx_size: Size of connection TX queue, in packets */ 137341572Sslavash unsigned int tx_size; 138341572Sslavash /** @rx_size: Size of connection RX queue, in packets */ 139341572Sslavash unsigned int rx_size; 140341572Sslavash /** 141341572Sslavash * @recv_cb: Callback function which is called for received packets 142341572Sslavash * @cb_arg: The value provided in mlx5_fpga_conn_attr.cb_arg 143341572Sslavash * @buf: A buffer containing a received packet 144341572Sslavash * 145341572Sslavash * buf is guaranteed to only contain a single scatter-gather entry. 146341572Sslavash * The size of the actual packet received is specified in buf.sg[0].size 147341572Sslavash * When this callback returns, the packet buffer may be re-used for 148341572Sslavash * subsequent receives. 149341572Sslavash */ 150341572Sslavash void (*recv_cb)(void *cb_arg, struct mlx5_fpga_dma_buf *buf); 151341572Sslavash void *cb_arg; 152341572Sslavash}; 153341572Sslavash 154341572Sslavash/** 155341572Sslavash * mlx5_fpga_client_register() - Register a client driver 156341572Sslavash * @client: The properties of the client driver 157341572Sslavash * 158341572Sslavash * Should be called from a client driver's module init routine. 159341572Sslavash * Note: The core will immediately callback create() and add() for any existing 160341572Sslavash * devices in the system, as well as new ones added later on. 161341572Sslavash */ 162341572Sslavashvoid mlx5_fpga_client_register(struct mlx5_fpga_client *client); 163341572Sslavash/** 164341572Sslavash * mlx5_fpga_client_unregister() - Unregister a client driver 165341572Sslavash * @client: The client driver to unregister 166341572Sslavash * 167341572Sslavash * Should be called from a client driver's module exit routine. 168341572Sslavash * Note: The core will immediately callback delete() and destroy() for any 169341572Sslavash * created/added devices in the system, to clean up their state. 170341572Sslavash */ 171341572Sslavashvoid mlx5_fpga_client_unregister(struct mlx5_fpga_client *client); 172341572Sslavash 173341572Sslavash/** 174341572Sslavash * mlx5_fpga_device_reload() - Force the FPGA to reload its synthesis from flash 175341572Sslavash * @fdev: The FPGA device 176341572Sslavash * @image: Which flash image to load 177341572Sslavash * 178341572Sslavash * This routine attempts graceful teardown of all device resources before 179341572Sslavash * loading. This includes a callback to client driver delete(). 180341572Sslavash * Calls client driver add() once device is operational again. 181341572Sslavash * Blocks until the new synthesis is loaded, and the device is fully 182341572Sslavash * initialized. 183341572Sslavash * 184341572Sslavash * Return: 0 if successful, or a negative error value otherwise 185341572Sslavash */ 186341572Sslavashint mlx5_fpga_device_reload(struct mlx5_fpga_device *fdev, 187341572Sslavash enum mlx5_fpga_image image); 188341572Sslavash 189341572Sslavash/** 190341572Sslavash * mlx5_fpga_flash_select() - Select the current active flash 191341572Sslavash * @fdev: The FPGA device 192341572Sslavash * @image: Which flash image will be active 193341572Sslavash * 194341572Sslavash * This routine selects the active flash by programming the relevant MUX. 195341572Sslavash * Useful prior to burning a new image on flash. 196341572Sslavash * This setting is volatile and is reset upon reboot or power-cycle 197341572Sslavash * 198341572Sslavash * Return: 0 if successful, or a negative error value otherwise 199341572Sslavash */ 200341572Sslavashint mlx5_fpga_flash_select(struct mlx5_fpga_device *fdev, 201341572Sslavash enum mlx5_fpga_image image); 202341572Sslavash 203341572Sslavash/** 204341572Sslavash * mlx5_fpga_sbu_conn_create() - Initialize a new FPGA SBU connection 205341572Sslavash * @fdev: The FPGA device 206341572Sslavash * @attr: Attributes of the new connection 207341572Sslavash * 208341572Sslavash * Sets up a new FPGA SBU connection with the specified attributes. 209341572Sslavash * The receive callback function may be called for incoming messages even 210341572Sslavash * before this function returns. 211341572Sslavash * 212341572Sslavash * The caller must eventually destroy the connection by calling 213341572Sslavash * mlx5_fpga_sbu_conn_destroy. 214341572Sslavash * 215341572Sslavash * Return: A new connection, or ERR_PTR() error value otherwise. 216341572Sslavash */ 217341572Sslavashstruct mlx5_fpga_conn * 218341572Sslavashmlx5_fpga_sbu_conn_create(struct mlx5_fpga_device *fdev, 219341572Sslavash struct mlx5_fpga_conn_attr *attr); 220341572Sslavash 221341572Sslavash/** 222341572Sslavash * mlx5_fpga_sbu_conn_destroy() - Destroy an FPGA SBU connection 223341572Sslavash * @conn: The FPGA SBU connection to destroy 224341572Sslavash * 225341572Sslavash * Cleans up an FPGA SBU connection which was previously created with 226341572Sslavash * mlx5_fpga_sbu_conn_create. 227341572Sslavash */ 228341572Sslavashvoid mlx5_fpga_sbu_conn_destroy(struct mlx5_fpga_conn *conn); 229341572Sslavash 230341572Sslavash/** 231341572Sslavash * mlx5_fpga_sbu_conn_sendmsg() - Queue the transmission of a packet 232341572Sslavash * @fdev: An FPGA SBU connection 233341572Sslavash * @buf: The packet buffer 234341572Sslavash * 235341572Sslavash * Queues a packet for transmission over an FPGA SBU connection. 236341572Sslavash * The buffer should not be modified or freed until completion. 237341572Sslavash * Upon completion, the buf's complete() callback is invoked, indicating the 238341572Sslavash * success or error status of the transmission. 239341572Sslavash * 240341572Sslavash * Return: 0 if successful, or an error value otherwise. 241341572Sslavash */ 242341572Sslavashint mlx5_fpga_sbu_conn_sendmsg(struct mlx5_fpga_conn *conn, 243341572Sslavash struct mlx5_fpga_dma_buf *buf); 244341572Sslavash 245341572Sslavash/** 246341572Sslavash * mlx5_fpga_mem_read() - Read from FPGA memory address space 247341572Sslavash * @fdev: The FPGA device 248341572Sslavash * @size: Size of chunk to read, in bytes 249341572Sslavash * @addr: Starting address to read from, in FPGA address space 250341572Sslavash * @buf: Buffer to read into 251341572Sslavash * @access_type: Method for reading 252341572Sslavash * 253341572Sslavash * Reads from the specified address into the specified buffer. 254341572Sslavash * The address may point to configuration space or to DDR. 255341572Sslavash * Large reads may be performed internally as several non-atomic operations. 256341572Sslavash * This function may sleep, so should not be called from atomic contexts. 257341572Sslavash * 258341572Sslavash * Return: 0 if successful, or an error value otherwise. 259341572Sslavash */ 260341572Sslavashint mlx5_fpga_mem_read(struct mlx5_fpga_device *fdev, size_t size, u64 addr, 261341572Sslavash void *buf, enum mlx5_fpga_access_type access_type); 262341572Sslavash 263341572Sslavash/** 264341572Sslavash * mlx5_fpga_mem_write() - Write to FPGA memory address space 265341572Sslavash * @fdev: The FPGA device 266341572Sslavash * @size: Size of chunk to write, in bytes 267341572Sslavash * @addr: Starting address to write to, in FPGA address space 268341572Sslavash * @buf: Buffer which contains data to write 269341572Sslavash * @access_type: Method for writing 270341572Sslavash * 271341572Sslavash * Writes the specified buffer data to FPGA memory at the specified address. 272341572Sslavash * The address may point to configuration space or to DDR. 273341572Sslavash * Large writes may be performed internally as several non-atomic operations. 274341572Sslavash * This function may sleep, so should not be called from atomic contexts. 275341572Sslavash * 276341572Sslavash * Return: 0 if successful, or an error value otherwise. 277341572Sslavash */ 278341572Sslavashint mlx5_fpga_mem_write(struct mlx5_fpga_device *fdev, size_t size, u64 addr, 279341572Sslavash void *buf, enum mlx5_fpga_access_type access_type); 280341572Sslavash 281341572Sslavash/** 282341572Sslavash * mlx5_fpga_get_sbu_caps() - Read the SBU capabilities 283341572Sslavash * @fdev: The FPGA device 284341572Sslavash * @size: Size of the buffer to read into 285341572Sslavash * @buf: Buffer to read the capabilities into 286341572Sslavash * 287341572Sslavash * Reads the FPGA SBU capabilities into the specified buffer. 288341572Sslavash * The format of the capabilities buffer is SBU-dependent. 289341572Sslavash * 290341572Sslavash * Return: 0 if successful 291341572Sslavash * -EINVAL if the buffer is not large enough to contain SBU caps 292341572Sslavash * or any other error value otherwise. 293341572Sslavash */ 294341572Sslavashint mlx5_fpga_get_sbu_caps(struct mlx5_fpga_device *fdev, int size, void *buf); 295341572Sslavash 296341572Sslavash/** 297341572Sslavash * mlx5_fpga_ddr_size_get() - Retrieve the size of FPGA DDR 298341572Sslavash * @fdev: The FPGA device 299341572Sslavash * 300341572Sslavash * Return: Size of DDR avaailable for FPGA, in bytes 301341572Sslavash */ 302341572Sslavashu64 mlx5_fpga_ddr_size_get(struct mlx5_fpga_device *fdev); 303341572Sslavash 304341572Sslavash/** 305341572Sslavash * mlx5_fpga_ddr_base_get() - Retrieve the base address of FPGA DDR 306341572Sslavash * @fdev: The FPGA device 307341572Sslavash * 308341572Sslavash * Return: Base address of DDR in FPGA address space 309341572Sslavash */ 310341572Sslavashu64 mlx5_fpga_ddr_base_get(struct mlx5_fpga_device *fdev); 311341572Sslavash 312341572Sslavash/** 313341572Sslavash * mlx5_fpga_client_data_set() - Attach client-defined private value to a device 314341572Sslavash * @fdev: The FPGA device 315341572Sslavash * @client: The client driver 316341572Sslavash * @data: Opaque private value 317341572Sslavash * 318341572Sslavash * Client driver may use the private value for storing device-specific 319341572Sslavash * state and configuration information, and may retrieve it with a call to 320341572Sslavash * mlx5_fpga_client_data_get(). 321341572Sslavash */ 322341572Sslavashvoid mlx5_fpga_client_data_set(struct mlx5_fpga_device *fdev, 323341572Sslavash struct mlx5_fpga_client *client, 324341572Sslavash void *data); 325341572Sslavash 326341572Sslavash/** 327341572Sslavash * mlx5_fpga_client_data_get() - Retrieve client-defined private value 328341572Sslavash * @fdev: The FPGA device 329341572Sslavash * @client: The client driver 330341572Sslavash * 331341572Sslavash * Client driver may use the private value for storing device-specific 332341572Sslavash * state and configuration information by calling mlx5_fpga_client_data_set() 333341572Sslavash * 334341572Sslavash * Return: The private value 335341572Sslavash */ 336341572Sslavashvoid *mlx5_fpga_client_data_get(struct mlx5_fpga_device *fdev, 337341572Sslavash struct mlx5_fpga_client *client); 338341572Sslavash 339341572Sslavash/** 340341572Sslavash * mlx5_fpga_device_query() - Query FPGA device state information 341341572Sslavash * @fdev: The FPGA device 342341572Sslavash * @query: Returns the device state 343341572Sslavash * 344341572Sslavash * Queries the device state and returns it in *query 345341572Sslavash */ 346341572Sslavashvoid mlx5_fpga_device_query(struct mlx5_fpga_device *fdev, 347341572Sslavash struct mlx5_fpga_query *query); 348341572Sslavash 349341572Sslavash/** 350341572Sslavash * mlx5_fpga_dev() - Retrieve FPGA device structure 351341572Sslavash * @fdev: The FPGA device 352341572Sslavash 353341572Sslavash * Return: A pointer to a struct device, which may be used with dev_* logging, 354341572Sslavash * sysfs extensions, etc. 355341572Sslavash */ 356341572Sslavashstruct device *mlx5_fpga_dev(struct mlx5_fpga_device *fdev); 357341572Sslavash 358341572Sslavash/** 359341964Shselasky * mlx5_fpga_temperature() - Retrieve FPGA sensor of temperature 360341964Shselasky * @fdev: The FPGA device 361341964Shselasky 362341964Shselasky * Return: 0 if successful 363341964Shselasky * or any other error value otherwise. 364341964Shselasky */ 365341964Shselaskyint mlx5_fpga_temperature(struct mlx5_fpga_device *fdev, 366341964Shselasky struct mlx5_fpga_temperature *temp); 367341964Shselasky 368341964Shselasky/** 369341966Shselasky * mlx5_fpga_connectdisconnect() - Connect/disconnect ConnectX to FPGA 370341966Shselasky * @fdev: The FPGA device 371341966Shselasky 372341966Shselasky * Return: 0 if successful 373341966Shselasky * or any other error value otherwise. 374341966Shselasky */ 375341966Shselaskyint mlx5_fpga_connectdisconnect(struct mlx5_fpga_device *fdev, 376341966Shselasky enum mlx5_fpga_connect *connect); 377341966Shselasky 378341966Shselasky/** 379341572Sslavash * mlx5_fpga_get_cap() - Returns the FPGA cap mailbox from FW without parsing. 380341572Sslavash * @fdev: The FPGA device 381341572Sslavash * @fpga_caps: Is an array with a length of according to the size of 382341572Sslavash * mlx5_ifc_fpga_cap_bits/32 383341572Sslavash * 384341572Sslavash * Returns a copy of the FPGA caps mailbox and returns it in fpga_caps 385341572Sslavash */ 386341572Sslavashvoid mlx5_fpga_get_cap(struct mlx5_fpga_device *fdev, u32 *fpga_caps); 387341572Sslavash 388341572Sslavash#endif /* MLX5_FPGA_SDK_H */ 389