253 lines · c
1/* SPDX-License-Identifier: GPL-2.0-only */2/****************************************************************************3 * Driver for Solarflare network controllers and boards4 * Copyright 2010-2012 Solarflare Communications Inc.5 */6#ifndef _VFDI_H7#define _VFDI_H8 9/**10 * DOC: Virtual Function Driver Interface11 *12 * This file contains software structures used to form a two way13 * communication channel between the VF driver and the PF driver,14 * named Virtual Function Driver Interface (VFDI).15 *16 * For the purposes of VFDI, a page is a memory region with size and17 * alignment of 4K. All addresses are DMA addresses to be used within18 * the domain of the relevant VF.19 *20 * The only hardware-defined channels for a VF driver to communicate21 * with the PF driver are the event mailboxes (%FR_CZ_USR_EV22 * registers). Writing to these registers generates an event with23 * EV_CODE = EV_CODE_USR_EV, USER_QID set to the index of the mailbox24 * and USER_EV_REG_VALUE set to the value written. The PF driver may25 * direct or disable delivery of these events by setting26 * %FR_CZ_USR_EV_CFG.27 *28 * The PF driver can send arbitrary events to arbitrary event queues.29 * However, for consistency, VFDI events from the PF are defined to30 * follow the same form and be sent to the first event queue assigned31 * to the VF while that queue is enabled by the VF driver.32 *33 * The general form of the variable bits of VFDI events is:34 *35 * 0 16 24 3136 * | DATA | TYPE | SEQ |37 *38 * SEQ is a sequence number which should be incremented by 1 (modulo39 * 256) for each event. The sequence numbers used in each direction40 * are independent.41 *42 * The VF submits requests of type &struct vfdi_req by sending the43 * address of the request (ADDR) in a series of 4 events:44 *45 * 0 16 24 3146 * | ADDR[0:15] | VFDI_EV_TYPE_REQ_WORD0 | SEQ |47 * | ADDR[16:31] | VFDI_EV_TYPE_REQ_WORD1 | SEQ+1 |48 * | ADDR[32:47] | VFDI_EV_TYPE_REQ_WORD2 | SEQ+2 |49 * | ADDR[48:63] | VFDI_EV_TYPE_REQ_WORD3 | SEQ+3 |50 *51 * The address must be page-aligned. After receiving such a valid52 * series of events, the PF driver will attempt to read the request53 * and write a response to the same address. In case of an invalid54 * sequence of events or a DMA error, there will be no response.55 *56 * The VF driver may request that the PF driver writes status57 * information into its domain asynchronously. After writing the58 * status, the PF driver will send an event of the form:59 *60 * 0 16 24 3161 * | reserved | VFDI_EV_TYPE_STATUS | SEQ |62 *63 * In case the VF must be reset for any reason, the PF driver will64 * send an event of the form:65 *66 * 0 16 24 3167 * | reserved | VFDI_EV_TYPE_RESET | SEQ |68 *69 * It is then the responsibility of the VF driver to request70 * reinitialisation of its queues.71 */72#define VFDI_EV_SEQ_LBN 2473#define VFDI_EV_SEQ_WIDTH 874#define VFDI_EV_TYPE_LBN 1675#define VFDI_EV_TYPE_WIDTH 876#define VFDI_EV_TYPE_REQ_WORD0 077#define VFDI_EV_TYPE_REQ_WORD1 178#define VFDI_EV_TYPE_REQ_WORD2 279#define VFDI_EV_TYPE_REQ_WORD3 380#define VFDI_EV_TYPE_STATUS 481#define VFDI_EV_TYPE_RESET 582#define VFDI_EV_DATA_LBN 083#define VFDI_EV_DATA_WIDTH 1684 85struct vfdi_endpoint {86 u8 mac_addr[ETH_ALEN];87 __be16 tci;88};89 90/**91 * enum vfdi_op - VFDI operation enumeration92 * @VFDI_OP_RESPONSE: Indicates a response to the request.93 * @VFDI_OP_INIT_EVQ: Initialize SRAM entries and initialize an EVQ.94 * @VFDI_OP_INIT_RXQ: Initialize SRAM entries and initialize an RXQ.95 * @VFDI_OP_INIT_TXQ: Initialize SRAM entries and initialize a TXQ.96 * @VFDI_OP_FINI_ALL_QUEUES: Flush all queues, finalize all queues, then97 * finalize the SRAM entries.98 * @VFDI_OP_INSERT_FILTER: Insert a MAC filter targeting the given RXQ.99 * @VFDI_OP_REMOVE_ALL_FILTERS: Remove all filters.100 * @VFDI_OP_SET_STATUS_PAGE: Set the DMA page(s) used for status updates101 * from PF and write the initial status.102 * @VFDI_OP_CLEAR_STATUS_PAGE: Clear the DMA page(s) used for status103 * updates from PF.104 */105enum vfdi_op {106 VFDI_OP_RESPONSE = 0,107 VFDI_OP_INIT_EVQ = 1,108 VFDI_OP_INIT_RXQ = 2,109 VFDI_OP_INIT_TXQ = 3,110 VFDI_OP_FINI_ALL_QUEUES = 4,111 VFDI_OP_INSERT_FILTER = 5,112 VFDI_OP_REMOVE_ALL_FILTERS = 6,113 VFDI_OP_SET_STATUS_PAGE = 7,114 VFDI_OP_CLEAR_STATUS_PAGE = 8,115 VFDI_OP_LIMIT,116};117 118/* Response codes for VFDI operations. Other values may be used in future. */119#define VFDI_RC_SUCCESS 0120#define VFDI_RC_ENOMEM (-12)121#define VFDI_RC_EINVAL (-22)122#define VFDI_RC_EOPNOTSUPP (-95)123#define VFDI_RC_ETIMEDOUT (-110)124 125/**126 * struct vfdi_req - Request from VF driver to PF driver127 * @op: Operation code or response indicator, taken from &enum vfdi_op.128 * @rc: Response code. Set to 0 on success or a negative error code on failure.129 * @u.init_evq.index: Index of event queue to create.130 * @u.init_evq.buf_count: Number of 4k buffers backing event queue.131 * @u.init_evq.addr: Array of length %u.init_evq.buf_count containing DMA132 * address of each page backing the event queue.133 * @u.init_rxq.index: Index of receive queue to create.134 * @u.init_rxq.buf_count: Number of 4k buffers backing receive queue.135 * @u.init_rxq.evq: Instance of event queue to target receive events at.136 * @u.init_rxq.label: Label used in receive events.137 * @u.init_rxq.flags: Unused.138 * @u.init_rxq.addr: Array of length %u.init_rxq.buf_count containing DMA139 * address of each page backing the receive queue.140 * @u.init_txq.index: Index of transmit queue to create.141 * @u.init_txq.buf_count: Number of 4k buffers backing transmit queue.142 * @u.init_txq.evq: Instance of event queue to target transmit completion143 * events at.144 * @u.init_txq.label: Label used in transmit completion events.145 * @u.init_txq.flags: Checksum offload flags.146 * @u.init_txq.addr: Array of length %u.init_txq.buf_count containing DMA147 * address of each page backing the transmit queue.148 * @u.mac_filter.rxq: Insert MAC filter at VF local address/VLAN targeting149 * all traffic at this receive queue.150 * @u.mac_filter.flags: MAC filter flags.151 * @u.set_status_page.dma_addr: Base address for the &struct vfdi_status.152 * This address must be page-aligned and the PF may write up to a153 * whole page (allowing for extension of the structure).154 * @u.set_status_page.peer_page_count: Number of additional pages the VF155 * has provided into which peer addresses may be DMAd.156 * @u.set_status_page.peer_page_addr: Array of DMA addresses of pages.157 * If the number of peers exceeds 256, then the VF must provide158 * additional pages in this array. The PF will then DMA up to159 * 512 vfdi_endpoint structures into each page. These addresses160 * must be page-aligned.161 */162struct vfdi_req {163 u32 op;164 u32 reserved1;165 s32 rc;166 u32 reserved2;167 union {168 struct {169 u32 index;170 u32 buf_count;171 u64 addr[];172 } init_evq;173 struct {174 u32 index;175 u32 buf_count;176 u32 evq;177 u32 label;178 u32 flags;179#define VFDI_RXQ_FLAG_SCATTER_EN 1180 u32 reserved;181 u64 addr[];182 } init_rxq;183 struct {184 u32 index;185 u32 buf_count;186 u32 evq;187 u32 label;188 u32 flags;189#define VFDI_TXQ_FLAG_IP_CSUM_DIS 1190#define VFDI_TXQ_FLAG_TCPUDP_CSUM_DIS 2191 u32 reserved;192 u64 addr[];193 } init_txq;194 struct {195 u32 rxq;196 u32 flags;197#define VFDI_MAC_FILTER_FLAG_RSS 1198#define VFDI_MAC_FILTER_FLAG_SCATTER 2199 } mac_filter;200 struct {201 u64 dma_addr;202 u64 peer_page_count;203 u64 peer_page_addr[];204 } set_status_page;205 } u;206};207 208/**209 * struct vfdi_status - Status provided by PF driver to VF driver210 * @generation_start: A generation count DMA'd to VF *before* the211 * rest of the structure.212 * @generation_end: A generation count DMA'd to VF *after* the213 * rest of the structure.214 * @version: Version of this structure; currently set to 1. Later215 * versions must either be layout-compatible or only be sent to VFs216 * that specifically request them.217 * @length: Total length of this structure including embedded tables218 * @vi_scale: log2 the number of VIs available on this VF. This quantity219 * is used by the hardware for register decoding.220 * @max_tx_channels: The maximum number of transmit queues the VF can use.221 * @rss_rxq_count: The number of receive queues present in the shared RSS222 * indirection table.223 * @peer_count: Total number of peers in the complete peer list. If larger224 * than ARRAY_SIZE(%peers), then the VF must provide sufficient225 * additional pages each of which is filled with vfdi_endpoint structures.226 * @local: The MAC address and outer VLAN tag of *this* VF227 * @peers: Table of peer addresses. The @tci fields in these structures228 * are currently unused and must be ignored. Additional peers are229 * written into any additional pages provided by the VF.230 * @timer_quantum_ns: Timer quantum (nominal period between timer ticks)231 * for interrupt moderation timers, in nanoseconds. This member is only232 * present if @length is sufficiently large.233 */234struct vfdi_status {235 u32 generation_start;236 u32 generation_end;237 u32 version;238 u32 length;239 u8 vi_scale;240 u8 max_tx_channels;241 u8 rss_rxq_count;242 u8 reserved1;243 u16 peer_count;244 u16 reserved2;245 struct vfdi_endpoint local;246 struct vfdi_endpoint peers[256];247 248 /* Members below here extend version 1 of this structure */249 u32 timer_quantum_ns;250};251 252#endif253