18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/**************************************************************************** 38c2ecf20Sopenharmony_ci * Driver for Solarflare network controllers and boards 48c2ecf20Sopenharmony_ci * Copyright 2010-2012 Solarflare Communications Inc. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci#ifndef _VFDI_H 78c2ecf20Sopenharmony_ci#define _VFDI_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci/** 108c2ecf20Sopenharmony_ci * DOC: Virtual Function Driver Interface 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * This file contains software structures used to form a two way 138c2ecf20Sopenharmony_ci * communication channel between the VF driver and the PF driver, 148c2ecf20Sopenharmony_ci * named Virtual Function Driver Interface (VFDI). 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * For the purposes of VFDI, a page is a memory region with size and 178c2ecf20Sopenharmony_ci * alignment of 4K. All addresses are DMA addresses to be used within 188c2ecf20Sopenharmony_ci * the domain of the relevant VF. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * The only hardware-defined channels for a VF driver to communicate 218c2ecf20Sopenharmony_ci * with the PF driver are the event mailboxes (%FR_CZ_USR_EV 228c2ecf20Sopenharmony_ci * registers). Writing to these registers generates an event with 238c2ecf20Sopenharmony_ci * EV_CODE = EV_CODE_USR_EV, USER_QID set to the index of the mailbox 248c2ecf20Sopenharmony_ci * and USER_EV_REG_VALUE set to the value written. The PF driver may 258c2ecf20Sopenharmony_ci * direct or disable delivery of these events by setting 268c2ecf20Sopenharmony_ci * %FR_CZ_USR_EV_CFG. 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * The PF driver can send arbitrary events to arbitrary event queues. 298c2ecf20Sopenharmony_ci * However, for consistency, VFDI events from the PF are defined to 308c2ecf20Sopenharmony_ci * follow the same form and be sent to the first event queue assigned 318c2ecf20Sopenharmony_ci * to the VF while that queue is enabled by the VF driver. 328c2ecf20Sopenharmony_ci * 338c2ecf20Sopenharmony_ci * The general form of the variable bits of VFDI events is: 348c2ecf20Sopenharmony_ci * 358c2ecf20Sopenharmony_ci * 0 16 24 31 368c2ecf20Sopenharmony_ci * | DATA | TYPE | SEQ | 378c2ecf20Sopenharmony_ci * 388c2ecf20Sopenharmony_ci * SEQ is a sequence number which should be incremented by 1 (modulo 398c2ecf20Sopenharmony_ci * 256) for each event. The sequence numbers used in each direction 408c2ecf20Sopenharmony_ci * are independent. 418c2ecf20Sopenharmony_ci * 428c2ecf20Sopenharmony_ci * The VF submits requests of type &struct vfdi_req by sending the 438c2ecf20Sopenharmony_ci * address of the request (ADDR) in a series of 4 events: 448c2ecf20Sopenharmony_ci * 458c2ecf20Sopenharmony_ci * 0 16 24 31 468c2ecf20Sopenharmony_ci * | ADDR[0:15] | VFDI_EV_TYPE_REQ_WORD0 | SEQ | 478c2ecf20Sopenharmony_ci * | ADDR[16:31] | VFDI_EV_TYPE_REQ_WORD1 | SEQ+1 | 488c2ecf20Sopenharmony_ci * | ADDR[32:47] | VFDI_EV_TYPE_REQ_WORD2 | SEQ+2 | 498c2ecf20Sopenharmony_ci * | ADDR[48:63] | VFDI_EV_TYPE_REQ_WORD3 | SEQ+3 | 508c2ecf20Sopenharmony_ci * 518c2ecf20Sopenharmony_ci * The address must be page-aligned. After receiving such a valid 528c2ecf20Sopenharmony_ci * series of events, the PF driver will attempt to read the request 538c2ecf20Sopenharmony_ci * and write a response to the same address. In case of an invalid 548c2ecf20Sopenharmony_ci * sequence of events or a DMA error, there will be no response. 558c2ecf20Sopenharmony_ci * 568c2ecf20Sopenharmony_ci * The VF driver may request that the PF driver writes status 578c2ecf20Sopenharmony_ci * information into its domain asynchronously. After writing the 588c2ecf20Sopenharmony_ci * status, the PF driver will send an event of the form: 598c2ecf20Sopenharmony_ci * 608c2ecf20Sopenharmony_ci * 0 16 24 31 618c2ecf20Sopenharmony_ci * | reserved | VFDI_EV_TYPE_STATUS | SEQ | 628c2ecf20Sopenharmony_ci * 638c2ecf20Sopenharmony_ci * In case the VF must be reset for any reason, the PF driver will 648c2ecf20Sopenharmony_ci * send an event of the form: 658c2ecf20Sopenharmony_ci * 668c2ecf20Sopenharmony_ci * 0 16 24 31 678c2ecf20Sopenharmony_ci * | reserved | VFDI_EV_TYPE_RESET | SEQ | 688c2ecf20Sopenharmony_ci * 698c2ecf20Sopenharmony_ci * It is then the responsibility of the VF driver to request 708c2ecf20Sopenharmony_ci * reinitialisation of its queues. 718c2ecf20Sopenharmony_ci */ 728c2ecf20Sopenharmony_ci#define VFDI_EV_SEQ_LBN 24 738c2ecf20Sopenharmony_ci#define VFDI_EV_SEQ_WIDTH 8 748c2ecf20Sopenharmony_ci#define VFDI_EV_TYPE_LBN 16 758c2ecf20Sopenharmony_ci#define VFDI_EV_TYPE_WIDTH 8 768c2ecf20Sopenharmony_ci#define VFDI_EV_TYPE_REQ_WORD0 0 778c2ecf20Sopenharmony_ci#define VFDI_EV_TYPE_REQ_WORD1 1 788c2ecf20Sopenharmony_ci#define VFDI_EV_TYPE_REQ_WORD2 2 798c2ecf20Sopenharmony_ci#define VFDI_EV_TYPE_REQ_WORD3 3 808c2ecf20Sopenharmony_ci#define VFDI_EV_TYPE_STATUS 4 818c2ecf20Sopenharmony_ci#define VFDI_EV_TYPE_RESET 5 828c2ecf20Sopenharmony_ci#define VFDI_EV_DATA_LBN 0 838c2ecf20Sopenharmony_ci#define VFDI_EV_DATA_WIDTH 16 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_cistruct vfdi_endpoint { 868c2ecf20Sopenharmony_ci u8 mac_addr[ETH_ALEN]; 878c2ecf20Sopenharmony_ci __be16 tci; 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci/** 918c2ecf20Sopenharmony_ci * enum vfdi_op - VFDI operation enumeration 928c2ecf20Sopenharmony_ci * @VFDI_OP_RESPONSE: Indicates a response to the request. 938c2ecf20Sopenharmony_ci * @VFDI_OP_INIT_EVQ: Initialize SRAM entries and initialize an EVQ. 948c2ecf20Sopenharmony_ci * @VFDI_OP_INIT_RXQ: Initialize SRAM entries and initialize an RXQ. 958c2ecf20Sopenharmony_ci * @VFDI_OP_INIT_TXQ: Initialize SRAM entries and initialize a TXQ. 968c2ecf20Sopenharmony_ci * @VFDI_OP_FINI_ALL_QUEUES: Flush all queues, finalize all queues, then 978c2ecf20Sopenharmony_ci * finalize the SRAM entries. 988c2ecf20Sopenharmony_ci * @VFDI_OP_INSERT_FILTER: Insert a MAC filter targeting the given RXQ. 998c2ecf20Sopenharmony_ci * @VFDI_OP_REMOVE_ALL_FILTERS: Remove all filters. 1008c2ecf20Sopenharmony_ci * @VFDI_OP_SET_STATUS_PAGE: Set the DMA page(s) used for status updates 1018c2ecf20Sopenharmony_ci * from PF and write the initial status. 1028c2ecf20Sopenharmony_ci * @VFDI_OP_CLEAR_STATUS_PAGE: Clear the DMA page(s) used for status 1038c2ecf20Sopenharmony_ci * updates from PF. 1048c2ecf20Sopenharmony_ci */ 1058c2ecf20Sopenharmony_cienum vfdi_op { 1068c2ecf20Sopenharmony_ci VFDI_OP_RESPONSE = 0, 1078c2ecf20Sopenharmony_ci VFDI_OP_INIT_EVQ = 1, 1088c2ecf20Sopenharmony_ci VFDI_OP_INIT_RXQ = 2, 1098c2ecf20Sopenharmony_ci VFDI_OP_INIT_TXQ = 3, 1108c2ecf20Sopenharmony_ci VFDI_OP_FINI_ALL_QUEUES = 4, 1118c2ecf20Sopenharmony_ci VFDI_OP_INSERT_FILTER = 5, 1128c2ecf20Sopenharmony_ci VFDI_OP_REMOVE_ALL_FILTERS = 6, 1138c2ecf20Sopenharmony_ci VFDI_OP_SET_STATUS_PAGE = 7, 1148c2ecf20Sopenharmony_ci VFDI_OP_CLEAR_STATUS_PAGE = 8, 1158c2ecf20Sopenharmony_ci VFDI_OP_LIMIT, 1168c2ecf20Sopenharmony_ci}; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci/* Response codes for VFDI operations. Other values may be used in future. */ 1198c2ecf20Sopenharmony_ci#define VFDI_RC_SUCCESS 0 1208c2ecf20Sopenharmony_ci#define VFDI_RC_ENOMEM (-12) 1218c2ecf20Sopenharmony_ci#define VFDI_RC_EINVAL (-22) 1228c2ecf20Sopenharmony_ci#define VFDI_RC_EOPNOTSUPP (-95) 1238c2ecf20Sopenharmony_ci#define VFDI_RC_ETIMEDOUT (-110) 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/** 1268c2ecf20Sopenharmony_ci * struct vfdi_req - Request from VF driver to PF driver 1278c2ecf20Sopenharmony_ci * @op: Operation code or response indicator, taken from &enum vfdi_op. 1288c2ecf20Sopenharmony_ci * @rc: Response code. Set to 0 on success or a negative error code on failure. 1298c2ecf20Sopenharmony_ci * @u.init_evq.index: Index of event queue to create. 1308c2ecf20Sopenharmony_ci * @u.init_evq.buf_count: Number of 4k buffers backing event queue. 1318c2ecf20Sopenharmony_ci * @u.init_evq.addr: Array of length %u.init_evq.buf_count containing DMA 1328c2ecf20Sopenharmony_ci * address of each page backing the event queue. 1338c2ecf20Sopenharmony_ci * @u.init_rxq.index: Index of receive queue to create. 1348c2ecf20Sopenharmony_ci * @u.init_rxq.buf_count: Number of 4k buffers backing receive queue. 1358c2ecf20Sopenharmony_ci * @u.init_rxq.evq: Instance of event queue to target receive events at. 1368c2ecf20Sopenharmony_ci * @u.init_rxq.label: Label used in receive events. 1378c2ecf20Sopenharmony_ci * @u.init_rxq.flags: Unused. 1388c2ecf20Sopenharmony_ci * @u.init_rxq.addr: Array of length %u.init_rxq.buf_count containing DMA 1398c2ecf20Sopenharmony_ci * address of each page backing the receive queue. 1408c2ecf20Sopenharmony_ci * @u.init_txq.index: Index of transmit queue to create. 1418c2ecf20Sopenharmony_ci * @u.init_txq.buf_count: Number of 4k buffers backing transmit queue. 1428c2ecf20Sopenharmony_ci * @u.init_txq.evq: Instance of event queue to target transmit completion 1438c2ecf20Sopenharmony_ci * events at. 1448c2ecf20Sopenharmony_ci * @u.init_txq.label: Label used in transmit completion events. 1458c2ecf20Sopenharmony_ci * @u.init_txq.flags: Checksum offload flags. 1468c2ecf20Sopenharmony_ci * @u.init_txq.addr: Array of length %u.init_txq.buf_count containing DMA 1478c2ecf20Sopenharmony_ci * address of each page backing the transmit queue. 1488c2ecf20Sopenharmony_ci * @u.mac_filter.rxq: Insert MAC filter at VF local address/VLAN targeting 1498c2ecf20Sopenharmony_ci * all traffic at this receive queue. 1508c2ecf20Sopenharmony_ci * @u.mac_filter.flags: MAC filter flags. 1518c2ecf20Sopenharmony_ci * @u.set_status_page.dma_addr: Base address for the &struct vfdi_status. 1528c2ecf20Sopenharmony_ci * This address must be page-aligned and the PF may write up to a 1538c2ecf20Sopenharmony_ci * whole page (allowing for extension of the structure). 1548c2ecf20Sopenharmony_ci * @u.set_status_page.peer_page_count: Number of additional pages the VF 1558c2ecf20Sopenharmony_ci * has provided into which peer addresses may be DMAd. 1568c2ecf20Sopenharmony_ci * @u.set_status_page.peer_page_addr: Array of DMA addresses of pages. 1578c2ecf20Sopenharmony_ci * If the number of peers exceeds 256, then the VF must provide 1588c2ecf20Sopenharmony_ci * additional pages in this array. The PF will then DMA up to 1598c2ecf20Sopenharmony_ci * 512 vfdi_endpoint structures into each page. These addresses 1608c2ecf20Sopenharmony_ci * must be page-aligned. 1618c2ecf20Sopenharmony_ci */ 1628c2ecf20Sopenharmony_cistruct vfdi_req { 1638c2ecf20Sopenharmony_ci u32 op; 1648c2ecf20Sopenharmony_ci u32 reserved1; 1658c2ecf20Sopenharmony_ci s32 rc; 1668c2ecf20Sopenharmony_ci u32 reserved2; 1678c2ecf20Sopenharmony_ci union { 1688c2ecf20Sopenharmony_ci struct { 1698c2ecf20Sopenharmony_ci u32 index; 1708c2ecf20Sopenharmony_ci u32 buf_count; 1718c2ecf20Sopenharmony_ci u64 addr[]; 1728c2ecf20Sopenharmony_ci } init_evq; 1738c2ecf20Sopenharmony_ci struct { 1748c2ecf20Sopenharmony_ci u32 index; 1758c2ecf20Sopenharmony_ci u32 buf_count; 1768c2ecf20Sopenharmony_ci u32 evq; 1778c2ecf20Sopenharmony_ci u32 label; 1788c2ecf20Sopenharmony_ci u32 flags; 1798c2ecf20Sopenharmony_ci#define VFDI_RXQ_FLAG_SCATTER_EN 1 1808c2ecf20Sopenharmony_ci u32 reserved; 1818c2ecf20Sopenharmony_ci u64 addr[]; 1828c2ecf20Sopenharmony_ci } init_rxq; 1838c2ecf20Sopenharmony_ci struct { 1848c2ecf20Sopenharmony_ci u32 index; 1858c2ecf20Sopenharmony_ci u32 buf_count; 1868c2ecf20Sopenharmony_ci u32 evq; 1878c2ecf20Sopenharmony_ci u32 label; 1888c2ecf20Sopenharmony_ci u32 flags; 1898c2ecf20Sopenharmony_ci#define VFDI_TXQ_FLAG_IP_CSUM_DIS 1 1908c2ecf20Sopenharmony_ci#define VFDI_TXQ_FLAG_TCPUDP_CSUM_DIS 2 1918c2ecf20Sopenharmony_ci u32 reserved; 1928c2ecf20Sopenharmony_ci u64 addr[]; 1938c2ecf20Sopenharmony_ci } init_txq; 1948c2ecf20Sopenharmony_ci struct { 1958c2ecf20Sopenharmony_ci u32 rxq; 1968c2ecf20Sopenharmony_ci u32 flags; 1978c2ecf20Sopenharmony_ci#define VFDI_MAC_FILTER_FLAG_RSS 1 1988c2ecf20Sopenharmony_ci#define VFDI_MAC_FILTER_FLAG_SCATTER 2 1998c2ecf20Sopenharmony_ci } mac_filter; 2008c2ecf20Sopenharmony_ci struct { 2018c2ecf20Sopenharmony_ci u64 dma_addr; 2028c2ecf20Sopenharmony_ci u64 peer_page_count; 2038c2ecf20Sopenharmony_ci u64 peer_page_addr[]; 2048c2ecf20Sopenharmony_ci } set_status_page; 2058c2ecf20Sopenharmony_ci } u; 2068c2ecf20Sopenharmony_ci}; 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci/** 2098c2ecf20Sopenharmony_ci * struct vfdi_status - Status provided by PF driver to VF driver 2108c2ecf20Sopenharmony_ci * @generation_start: A generation count DMA'd to VF *before* the 2118c2ecf20Sopenharmony_ci * rest of the structure. 2128c2ecf20Sopenharmony_ci * @generation_end: A generation count DMA'd to VF *after* the 2138c2ecf20Sopenharmony_ci * rest of the structure. 2148c2ecf20Sopenharmony_ci * @version: Version of this structure; currently set to 1. Later 2158c2ecf20Sopenharmony_ci * versions must either be layout-compatible or only be sent to VFs 2168c2ecf20Sopenharmony_ci * that specifically request them. 2178c2ecf20Sopenharmony_ci * @length: Total length of this structure including embedded tables 2188c2ecf20Sopenharmony_ci * @vi_scale: log2 the number of VIs available on this VF. This quantity 2198c2ecf20Sopenharmony_ci * is used by the hardware for register decoding. 2208c2ecf20Sopenharmony_ci * @max_tx_channels: The maximum number of transmit queues the VF can use. 2218c2ecf20Sopenharmony_ci * @rss_rxq_count: The number of receive queues present in the shared RSS 2228c2ecf20Sopenharmony_ci * indirection table. 2238c2ecf20Sopenharmony_ci * @peer_count: Total number of peers in the complete peer list. If larger 2248c2ecf20Sopenharmony_ci * than ARRAY_SIZE(%peers), then the VF must provide sufficient 2258c2ecf20Sopenharmony_ci * additional pages each of which is filled with vfdi_endpoint structures. 2268c2ecf20Sopenharmony_ci * @local: The MAC address and outer VLAN tag of *this* VF 2278c2ecf20Sopenharmony_ci * @peers: Table of peer addresses. The @tci fields in these structures 2288c2ecf20Sopenharmony_ci * are currently unused and must be ignored. Additional peers are 2298c2ecf20Sopenharmony_ci * written into any additional pages provided by the VF. 2308c2ecf20Sopenharmony_ci * @timer_quantum_ns: Timer quantum (nominal period between timer ticks) 2318c2ecf20Sopenharmony_ci * for interrupt moderation timers, in nanoseconds. This member is only 2328c2ecf20Sopenharmony_ci * present if @length is sufficiently large. 2338c2ecf20Sopenharmony_ci */ 2348c2ecf20Sopenharmony_cistruct vfdi_status { 2358c2ecf20Sopenharmony_ci u32 generation_start; 2368c2ecf20Sopenharmony_ci u32 generation_end; 2378c2ecf20Sopenharmony_ci u32 version; 2388c2ecf20Sopenharmony_ci u32 length; 2398c2ecf20Sopenharmony_ci u8 vi_scale; 2408c2ecf20Sopenharmony_ci u8 max_tx_channels; 2418c2ecf20Sopenharmony_ci u8 rss_rxq_count; 2428c2ecf20Sopenharmony_ci u8 reserved1; 2438c2ecf20Sopenharmony_ci u16 peer_count; 2448c2ecf20Sopenharmony_ci u16 reserved2; 2458c2ecf20Sopenharmony_ci struct vfdi_endpoint local; 2468c2ecf20Sopenharmony_ci struct vfdi_endpoint peers[256]; 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci /* Members below here extend version 1 of this structure */ 2498c2ecf20Sopenharmony_ci u32 timer_quantum_ns; 2508c2ecf20Sopenharmony_ci}; 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci#endif 253