Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /****************************************************************************
0003  * Driver for Solarflare network controllers and boards
0004  * Copyright 2010-2012 Solarflare Communications Inc.
0005  */
0006 #ifndef _VFDI_H
0007 #define _VFDI_H
0008 
0009 /**
0010  * DOC: Virtual Function Driver Interface
0011  *
0012  * This file contains software structures used to form a two way
0013  * communication channel between the VF driver and the PF driver,
0014  * named Virtual Function Driver Interface (VFDI).
0015  *
0016  * For the purposes of VFDI, a page is a memory region with size and
0017  * alignment of 4K.  All addresses are DMA addresses to be used within
0018  * the domain of the relevant VF.
0019  *
0020  * The only hardware-defined channels for a VF driver to communicate
0021  * with the PF driver are the event mailboxes (%FR_CZ_USR_EV
0022  * registers).  Writing to these registers generates an event with
0023  * EV_CODE = EV_CODE_USR_EV, USER_QID set to the index of the mailbox
0024  * and USER_EV_REG_VALUE set to the value written.  The PF driver may
0025  * direct or disable delivery of these events by setting
0026  * %FR_CZ_USR_EV_CFG.
0027  *
0028  * The PF driver can send arbitrary events to arbitrary event queues.
0029  * However, for consistency, VFDI events from the PF are defined to
0030  * follow the same form and be sent to the first event queue assigned
0031  * to the VF while that queue is enabled by the VF driver.
0032  *
0033  * The general form of the variable bits of VFDI events is:
0034  *
0035  *       0             16                       24   31
0036  *      | DATA        | TYPE                   | SEQ   |
0037  *
0038  * SEQ is a sequence number which should be incremented by 1 (modulo
0039  * 256) for each event.  The sequence numbers used in each direction
0040  * are independent.
0041  *
0042  * The VF submits requests of type &struct vfdi_req by sending the
0043  * address of the request (ADDR) in a series of 4 events:
0044  *
0045  *       0             16                       24   31
0046  *      | ADDR[0:15]  | VFDI_EV_TYPE_REQ_WORD0 | SEQ   |
0047  *      | ADDR[16:31] | VFDI_EV_TYPE_REQ_WORD1 | SEQ+1 |
0048  *      | ADDR[32:47] | VFDI_EV_TYPE_REQ_WORD2 | SEQ+2 |
0049  *      | ADDR[48:63] | VFDI_EV_TYPE_REQ_WORD3 | SEQ+3 |
0050  *
0051  * The address must be page-aligned.  After receiving such a valid
0052  * series of events, the PF driver will attempt to read the request
0053  * and write a response to the same address.  In case of an invalid
0054  * sequence of events or a DMA error, there will be no response.
0055  *
0056  * The VF driver may request that the PF driver writes status
0057  * information into its domain asynchronously.  After writing the
0058  * status, the PF driver will send an event of the form:
0059  *
0060  *       0             16                       24   31
0061  *      | reserved    | VFDI_EV_TYPE_STATUS    | SEQ   |
0062  *
0063  * In case the VF must be reset for any reason, the PF driver will
0064  * send an event of the form:
0065  *
0066  *       0             16                       24   31
0067  *      | reserved    | VFDI_EV_TYPE_RESET     | SEQ   |
0068  *
0069  * It is then the responsibility of the VF driver to request
0070  * reinitialisation of its queues.
0071  */
0072 #define VFDI_EV_SEQ_LBN 24
0073 #define VFDI_EV_SEQ_WIDTH 8
0074 #define VFDI_EV_TYPE_LBN 16
0075 #define VFDI_EV_TYPE_WIDTH 8
0076 #define VFDI_EV_TYPE_REQ_WORD0 0
0077 #define VFDI_EV_TYPE_REQ_WORD1 1
0078 #define VFDI_EV_TYPE_REQ_WORD2 2
0079 #define VFDI_EV_TYPE_REQ_WORD3 3
0080 #define VFDI_EV_TYPE_STATUS 4
0081 #define VFDI_EV_TYPE_RESET 5
0082 #define VFDI_EV_DATA_LBN 0
0083 #define VFDI_EV_DATA_WIDTH 16
0084 
0085 struct vfdi_endpoint {
0086     u8 mac_addr[ETH_ALEN];
0087     __be16 tci;
0088 };
0089 
0090 /**
0091  * enum vfdi_op - VFDI operation enumeration
0092  * @VFDI_OP_RESPONSE: Indicates a response to the request.
0093  * @VFDI_OP_INIT_EVQ: Initialize SRAM entries and initialize an EVQ.
0094  * @VFDI_OP_INIT_RXQ: Initialize SRAM entries and initialize an RXQ.
0095  * @VFDI_OP_INIT_TXQ: Initialize SRAM entries and initialize a TXQ.
0096  * @VFDI_OP_FINI_ALL_QUEUES: Flush all queues, finalize all queues, then
0097  *  finalize the SRAM entries.
0098  * @VFDI_OP_INSERT_FILTER: Insert a MAC filter targeting the given RXQ.
0099  * @VFDI_OP_REMOVE_ALL_FILTERS: Remove all filters.
0100  * @VFDI_OP_SET_STATUS_PAGE: Set the DMA page(s) used for status updates
0101  *  from PF and write the initial status.
0102  * @VFDI_OP_CLEAR_STATUS_PAGE: Clear the DMA page(s) used for status
0103  *  updates from PF.
0104  */
0105 enum vfdi_op {
0106     VFDI_OP_RESPONSE = 0,
0107     VFDI_OP_INIT_EVQ = 1,
0108     VFDI_OP_INIT_RXQ = 2,
0109     VFDI_OP_INIT_TXQ = 3,
0110     VFDI_OP_FINI_ALL_QUEUES = 4,
0111     VFDI_OP_INSERT_FILTER = 5,
0112     VFDI_OP_REMOVE_ALL_FILTERS = 6,
0113     VFDI_OP_SET_STATUS_PAGE = 7,
0114     VFDI_OP_CLEAR_STATUS_PAGE = 8,
0115     VFDI_OP_LIMIT,
0116 };
0117 
0118 /* Response codes for VFDI operations. Other values may be used in future. */
0119 #define VFDI_RC_SUCCESS     0
0120 #define VFDI_RC_ENOMEM      (-12)
0121 #define VFDI_RC_EINVAL      (-22)
0122 #define VFDI_RC_EOPNOTSUPP  (-95)
0123 #define VFDI_RC_ETIMEDOUT   (-110)
0124 
0125 /**
0126  * struct vfdi_req - Request from VF driver to PF driver
0127  * @op: Operation code or response indicator, taken from &enum vfdi_op.
0128  * @rc: Response code.  Set to 0 on success or a negative error code on failure.
0129  * @u.init_evq.index: Index of event queue to create.
0130  * @u.init_evq.buf_count: Number of 4k buffers backing event queue.
0131  * @u.init_evq.addr: Array of length %u.init_evq.buf_count containing DMA
0132  *  address of each page backing the event queue.
0133  * @u.init_rxq.index: Index of receive queue to create.
0134  * @u.init_rxq.buf_count: Number of 4k buffers backing receive queue.
0135  * @u.init_rxq.evq: Instance of event queue to target receive events at.
0136  * @u.init_rxq.label: Label used in receive events.
0137  * @u.init_rxq.flags: Unused.
0138  * @u.init_rxq.addr: Array of length %u.init_rxq.buf_count containing DMA
0139  *  address of each page backing the receive queue.
0140  * @u.init_txq.index: Index of transmit queue to create.
0141  * @u.init_txq.buf_count: Number of 4k buffers backing transmit queue.
0142  * @u.init_txq.evq: Instance of event queue to target transmit completion
0143  *  events at.
0144  * @u.init_txq.label: Label used in transmit completion events.
0145  * @u.init_txq.flags: Checksum offload flags.
0146  * @u.init_txq.addr: Array of length %u.init_txq.buf_count containing DMA
0147  *  address of each page backing the transmit queue.
0148  * @u.mac_filter.rxq: Insert MAC filter at VF local address/VLAN targeting
0149  *  all traffic at this receive queue.
0150  * @u.mac_filter.flags: MAC filter flags.
0151  * @u.set_status_page.dma_addr: Base address for the &struct vfdi_status.
0152  *  This address must be page-aligned and the PF may write up to a
0153  *  whole page (allowing for extension of the structure).
0154  * @u.set_status_page.peer_page_count: Number of additional pages the VF
0155  *  has provided into which peer addresses may be DMAd.
0156  * @u.set_status_page.peer_page_addr: Array of DMA addresses of pages.
0157  *  If the number of peers exceeds 256, then the VF must provide
0158  *  additional pages in this array. The PF will then DMA up to
0159  *  512 vfdi_endpoint structures into each page.  These addresses
0160  *  must be page-aligned.
0161  */
0162 struct vfdi_req {
0163     u32 op;
0164     u32 reserved1;
0165     s32 rc;
0166     u32 reserved2;
0167     union {
0168         struct {
0169             u32 index;
0170             u32 buf_count;
0171             u64 addr[];
0172         } init_evq;
0173         struct {
0174             u32 index;
0175             u32 buf_count;
0176             u32 evq;
0177             u32 label;
0178             u32 flags;
0179 #define VFDI_RXQ_FLAG_SCATTER_EN 1
0180             u32 reserved;
0181             u64 addr[];
0182         } init_rxq;
0183         struct {
0184             u32 index;
0185             u32 buf_count;
0186             u32 evq;
0187             u32 label;
0188             u32 flags;
0189 #define VFDI_TXQ_FLAG_IP_CSUM_DIS 1
0190 #define VFDI_TXQ_FLAG_TCPUDP_CSUM_DIS 2
0191             u32 reserved;
0192             u64 addr[];
0193         } init_txq;
0194         struct {
0195             u32 rxq;
0196             u32 flags;
0197 #define VFDI_MAC_FILTER_FLAG_RSS 1
0198 #define VFDI_MAC_FILTER_FLAG_SCATTER 2
0199         } mac_filter;
0200         struct {
0201             u64 dma_addr;
0202             u64 peer_page_count;
0203             u64 peer_page_addr[];
0204         } set_status_page;
0205     } u;
0206 };
0207 
0208 /**
0209  * struct vfdi_status - Status provided by PF driver to VF driver
0210  * @generation_start: A generation count DMA'd to VF *before* the
0211  *  rest of the structure.
0212  * @generation_end: A generation count DMA'd to VF *after* the
0213  *  rest of the structure.
0214  * @version: Version of this structure; currently set to 1.  Later
0215  *  versions must either be layout-compatible or only be sent to VFs
0216  *  that specifically request them.
0217  * @length: Total length of this structure including embedded tables
0218  * @vi_scale: log2 the number of VIs available on this VF. This quantity
0219  *  is used by the hardware for register decoding.
0220  * @max_tx_channels: The maximum number of transmit queues the VF can use.
0221  * @rss_rxq_count: The number of receive queues present in the shared RSS
0222  *  indirection table.
0223  * @peer_count: Total number of peers in the complete peer list. If larger
0224  *  than ARRAY_SIZE(%peers), then the VF must provide sufficient
0225  *  additional pages each of which is filled with vfdi_endpoint structures.
0226  * @local: The MAC address and outer VLAN tag of *this* VF
0227  * @peers: Table of peer addresses.  The @tci fields in these structures
0228  *  are currently unused and must be ignored.  Additional peers are
0229  *  written into any additional pages provided by the VF.
0230  * @timer_quantum_ns: Timer quantum (nominal period between timer ticks)
0231  *  for interrupt moderation timers, in nanoseconds. This member is only
0232  *  present if @length is sufficiently large.
0233  */
0234 struct vfdi_status {
0235     u32 generation_start;
0236     u32 generation_end;
0237     u32 version;
0238     u32 length;
0239     u8 vi_scale;
0240     u8 max_tx_channels;
0241     u8 rss_rxq_count;
0242     u8 reserved1;
0243     u16 peer_count;
0244     u16 reserved2;
0245     struct vfdi_endpoint local;
0246     struct vfdi_endpoint peers[256];
0247 
0248     /* Members below here extend version 1 of this structure */
0249     u32 timer_quantum_ns;
0250 };
0251 
0252 #endif