162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/****************************************************************************
362306a36Sopenharmony_ci * Driver for Solarflare network controllers and boards
462306a36Sopenharmony_ci * Copyright 2010-2012 Solarflare Communications Inc.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef _VFDI_H
762306a36Sopenharmony_ci#define _VFDI_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci/**
1062306a36Sopenharmony_ci * DOC: Virtual Function Driver Interface
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci * This file contains software structures used to form a two way
1362306a36Sopenharmony_ci * communication channel between the VF driver and the PF driver,
1462306a36Sopenharmony_ci * named Virtual Function Driver Interface (VFDI).
1562306a36Sopenharmony_ci *
1662306a36Sopenharmony_ci * For the purposes of VFDI, a page is a memory region with size and
1762306a36Sopenharmony_ci * alignment of 4K.  All addresses are DMA addresses to be used within
1862306a36Sopenharmony_ci * the domain of the relevant VF.
1962306a36Sopenharmony_ci *
2062306a36Sopenharmony_ci * The only hardware-defined channels for a VF driver to communicate
2162306a36Sopenharmony_ci * with the PF driver are the event mailboxes (%FR_CZ_USR_EV
2262306a36Sopenharmony_ci * registers).  Writing to these registers generates an event with
2362306a36Sopenharmony_ci * EV_CODE = EV_CODE_USR_EV, USER_QID set to the index of the mailbox
2462306a36Sopenharmony_ci * and USER_EV_REG_VALUE set to the value written.  The PF driver may
2562306a36Sopenharmony_ci * direct or disable delivery of these events by setting
2662306a36Sopenharmony_ci * %FR_CZ_USR_EV_CFG.
2762306a36Sopenharmony_ci *
2862306a36Sopenharmony_ci * The PF driver can send arbitrary events to arbitrary event queues.
2962306a36Sopenharmony_ci * However, for consistency, VFDI events from the PF are defined to
3062306a36Sopenharmony_ci * follow the same form and be sent to the first event queue assigned
3162306a36Sopenharmony_ci * to the VF while that queue is enabled by the VF driver.
3262306a36Sopenharmony_ci *
3362306a36Sopenharmony_ci * The general form of the variable bits of VFDI events is:
3462306a36Sopenharmony_ci *
3562306a36Sopenharmony_ci *       0             16                       24   31
3662306a36Sopenharmony_ci *      | DATA        | TYPE                   | SEQ   |
3762306a36Sopenharmony_ci *
3862306a36Sopenharmony_ci * SEQ is a sequence number which should be incremented by 1 (modulo
3962306a36Sopenharmony_ci * 256) for each event.  The sequence numbers used in each direction
4062306a36Sopenharmony_ci * are independent.
4162306a36Sopenharmony_ci *
4262306a36Sopenharmony_ci * The VF submits requests of type &struct vfdi_req by sending the
4362306a36Sopenharmony_ci * address of the request (ADDR) in a series of 4 events:
4462306a36Sopenharmony_ci *
4562306a36Sopenharmony_ci *       0             16                       24   31
4662306a36Sopenharmony_ci *      | ADDR[0:15]  | VFDI_EV_TYPE_REQ_WORD0 | SEQ   |
4762306a36Sopenharmony_ci *      | ADDR[16:31] | VFDI_EV_TYPE_REQ_WORD1 | SEQ+1 |
4862306a36Sopenharmony_ci *      | ADDR[32:47] | VFDI_EV_TYPE_REQ_WORD2 | SEQ+2 |
4962306a36Sopenharmony_ci *      | ADDR[48:63] | VFDI_EV_TYPE_REQ_WORD3 | SEQ+3 |
5062306a36Sopenharmony_ci *
5162306a36Sopenharmony_ci * The address must be page-aligned.  After receiving such a valid
5262306a36Sopenharmony_ci * series of events, the PF driver will attempt to read the request
5362306a36Sopenharmony_ci * and write a response to the same address.  In case of an invalid
5462306a36Sopenharmony_ci * sequence of events or a DMA error, there will be no response.
5562306a36Sopenharmony_ci *
5662306a36Sopenharmony_ci * The VF driver may request that the PF driver writes status
5762306a36Sopenharmony_ci * information into its domain asynchronously.  After writing the
5862306a36Sopenharmony_ci * status, the PF driver will send an event of the form:
5962306a36Sopenharmony_ci *
6062306a36Sopenharmony_ci *       0             16                       24   31
6162306a36Sopenharmony_ci *      | reserved    | VFDI_EV_TYPE_STATUS    | SEQ   |
6262306a36Sopenharmony_ci *
6362306a36Sopenharmony_ci * In case the VF must be reset for any reason, the PF driver will
6462306a36Sopenharmony_ci * send an event of the form:
6562306a36Sopenharmony_ci *
6662306a36Sopenharmony_ci *       0             16                       24   31
6762306a36Sopenharmony_ci *      | reserved    | VFDI_EV_TYPE_RESET     | SEQ   |
6862306a36Sopenharmony_ci *
6962306a36Sopenharmony_ci * It is then the responsibility of the VF driver to request
7062306a36Sopenharmony_ci * reinitialisation of its queues.
7162306a36Sopenharmony_ci */
7262306a36Sopenharmony_ci#define VFDI_EV_SEQ_LBN 24
7362306a36Sopenharmony_ci#define VFDI_EV_SEQ_WIDTH 8
7462306a36Sopenharmony_ci#define VFDI_EV_TYPE_LBN 16
7562306a36Sopenharmony_ci#define VFDI_EV_TYPE_WIDTH 8
7662306a36Sopenharmony_ci#define VFDI_EV_TYPE_REQ_WORD0 0
7762306a36Sopenharmony_ci#define VFDI_EV_TYPE_REQ_WORD1 1
7862306a36Sopenharmony_ci#define VFDI_EV_TYPE_REQ_WORD2 2
7962306a36Sopenharmony_ci#define VFDI_EV_TYPE_REQ_WORD3 3
8062306a36Sopenharmony_ci#define VFDI_EV_TYPE_STATUS 4
8162306a36Sopenharmony_ci#define VFDI_EV_TYPE_RESET 5
8262306a36Sopenharmony_ci#define VFDI_EV_DATA_LBN 0
8362306a36Sopenharmony_ci#define VFDI_EV_DATA_WIDTH 16
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_cistruct vfdi_endpoint {
8662306a36Sopenharmony_ci	u8 mac_addr[ETH_ALEN];
8762306a36Sopenharmony_ci	__be16 tci;
8862306a36Sopenharmony_ci};
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci/**
9162306a36Sopenharmony_ci * enum vfdi_op - VFDI operation enumeration
9262306a36Sopenharmony_ci * @VFDI_OP_RESPONSE: Indicates a response to the request.
9362306a36Sopenharmony_ci * @VFDI_OP_INIT_EVQ: Initialize SRAM entries and initialize an EVQ.
9462306a36Sopenharmony_ci * @VFDI_OP_INIT_RXQ: Initialize SRAM entries and initialize an RXQ.
9562306a36Sopenharmony_ci * @VFDI_OP_INIT_TXQ: Initialize SRAM entries and initialize a TXQ.
9662306a36Sopenharmony_ci * @VFDI_OP_FINI_ALL_QUEUES: Flush all queues, finalize all queues, then
9762306a36Sopenharmony_ci *	finalize the SRAM entries.
9862306a36Sopenharmony_ci * @VFDI_OP_INSERT_FILTER: Insert a MAC filter targeting the given RXQ.
9962306a36Sopenharmony_ci * @VFDI_OP_REMOVE_ALL_FILTERS: Remove all filters.
10062306a36Sopenharmony_ci * @VFDI_OP_SET_STATUS_PAGE: Set the DMA page(s) used for status updates
10162306a36Sopenharmony_ci *	from PF and write the initial status.
10262306a36Sopenharmony_ci * @VFDI_OP_CLEAR_STATUS_PAGE: Clear the DMA page(s) used for status
10362306a36Sopenharmony_ci *	updates from PF.
10462306a36Sopenharmony_ci */
10562306a36Sopenharmony_cienum vfdi_op {
10662306a36Sopenharmony_ci	VFDI_OP_RESPONSE = 0,
10762306a36Sopenharmony_ci	VFDI_OP_INIT_EVQ = 1,
10862306a36Sopenharmony_ci	VFDI_OP_INIT_RXQ = 2,
10962306a36Sopenharmony_ci	VFDI_OP_INIT_TXQ = 3,
11062306a36Sopenharmony_ci	VFDI_OP_FINI_ALL_QUEUES = 4,
11162306a36Sopenharmony_ci	VFDI_OP_INSERT_FILTER = 5,
11262306a36Sopenharmony_ci	VFDI_OP_REMOVE_ALL_FILTERS = 6,
11362306a36Sopenharmony_ci	VFDI_OP_SET_STATUS_PAGE = 7,
11462306a36Sopenharmony_ci	VFDI_OP_CLEAR_STATUS_PAGE = 8,
11562306a36Sopenharmony_ci	VFDI_OP_LIMIT,
11662306a36Sopenharmony_ci};
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci/* Response codes for VFDI operations. Other values may be used in future. */
11962306a36Sopenharmony_ci#define VFDI_RC_SUCCESS		0
12062306a36Sopenharmony_ci#define VFDI_RC_ENOMEM		(-12)
12162306a36Sopenharmony_ci#define VFDI_RC_EINVAL		(-22)
12262306a36Sopenharmony_ci#define VFDI_RC_EOPNOTSUPP	(-95)
12362306a36Sopenharmony_ci#define VFDI_RC_ETIMEDOUT	(-110)
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci/**
12662306a36Sopenharmony_ci * struct vfdi_req - Request from VF driver to PF driver
12762306a36Sopenharmony_ci * @op: Operation code or response indicator, taken from &enum vfdi_op.
12862306a36Sopenharmony_ci * @rc: Response code.  Set to 0 on success or a negative error code on failure.
12962306a36Sopenharmony_ci * @u.init_evq.index: Index of event queue to create.
13062306a36Sopenharmony_ci * @u.init_evq.buf_count: Number of 4k buffers backing event queue.
13162306a36Sopenharmony_ci * @u.init_evq.addr: Array of length %u.init_evq.buf_count containing DMA
13262306a36Sopenharmony_ci *	address of each page backing the event queue.
13362306a36Sopenharmony_ci * @u.init_rxq.index: Index of receive queue to create.
13462306a36Sopenharmony_ci * @u.init_rxq.buf_count: Number of 4k buffers backing receive queue.
13562306a36Sopenharmony_ci * @u.init_rxq.evq: Instance of event queue to target receive events at.
13662306a36Sopenharmony_ci * @u.init_rxq.label: Label used in receive events.
13762306a36Sopenharmony_ci * @u.init_rxq.flags: Unused.
13862306a36Sopenharmony_ci * @u.init_rxq.addr: Array of length %u.init_rxq.buf_count containing DMA
13962306a36Sopenharmony_ci *	address of each page backing the receive queue.
14062306a36Sopenharmony_ci * @u.init_txq.index: Index of transmit queue to create.
14162306a36Sopenharmony_ci * @u.init_txq.buf_count: Number of 4k buffers backing transmit queue.
14262306a36Sopenharmony_ci * @u.init_txq.evq: Instance of event queue to target transmit completion
14362306a36Sopenharmony_ci *	events at.
14462306a36Sopenharmony_ci * @u.init_txq.label: Label used in transmit completion events.
14562306a36Sopenharmony_ci * @u.init_txq.flags: Checksum offload flags.
14662306a36Sopenharmony_ci * @u.init_txq.addr: Array of length %u.init_txq.buf_count containing DMA
14762306a36Sopenharmony_ci *	address of each page backing the transmit queue.
14862306a36Sopenharmony_ci * @u.mac_filter.rxq: Insert MAC filter at VF local address/VLAN targeting
14962306a36Sopenharmony_ci *	all traffic at this receive queue.
15062306a36Sopenharmony_ci * @u.mac_filter.flags: MAC filter flags.
15162306a36Sopenharmony_ci * @u.set_status_page.dma_addr: Base address for the &struct vfdi_status.
15262306a36Sopenharmony_ci *	This address must be page-aligned and the PF may write up to a
15362306a36Sopenharmony_ci *	whole page (allowing for extension of the structure).
15462306a36Sopenharmony_ci * @u.set_status_page.peer_page_count: Number of additional pages the VF
15562306a36Sopenharmony_ci *	has provided into which peer addresses may be DMAd.
15662306a36Sopenharmony_ci * @u.set_status_page.peer_page_addr: Array of DMA addresses of pages.
15762306a36Sopenharmony_ci *	If the number of peers exceeds 256, then the VF must provide
15862306a36Sopenharmony_ci *	additional pages in this array. The PF will then DMA up to
15962306a36Sopenharmony_ci *	512 vfdi_endpoint structures into each page.  These addresses
16062306a36Sopenharmony_ci *	must be page-aligned.
16162306a36Sopenharmony_ci */
16262306a36Sopenharmony_cistruct vfdi_req {
16362306a36Sopenharmony_ci	u32 op;
16462306a36Sopenharmony_ci	u32 reserved1;
16562306a36Sopenharmony_ci	s32 rc;
16662306a36Sopenharmony_ci	u32 reserved2;
16762306a36Sopenharmony_ci	union {
16862306a36Sopenharmony_ci		struct {
16962306a36Sopenharmony_ci			u32 index;
17062306a36Sopenharmony_ci			u32 buf_count;
17162306a36Sopenharmony_ci			u64 addr[];
17262306a36Sopenharmony_ci		} init_evq;
17362306a36Sopenharmony_ci		struct {
17462306a36Sopenharmony_ci			u32 index;
17562306a36Sopenharmony_ci			u32 buf_count;
17662306a36Sopenharmony_ci			u32 evq;
17762306a36Sopenharmony_ci			u32 label;
17862306a36Sopenharmony_ci			u32 flags;
17962306a36Sopenharmony_ci#define VFDI_RXQ_FLAG_SCATTER_EN 1
18062306a36Sopenharmony_ci			u32 reserved;
18162306a36Sopenharmony_ci			u64 addr[];
18262306a36Sopenharmony_ci		} init_rxq;
18362306a36Sopenharmony_ci		struct {
18462306a36Sopenharmony_ci			u32 index;
18562306a36Sopenharmony_ci			u32 buf_count;
18662306a36Sopenharmony_ci			u32 evq;
18762306a36Sopenharmony_ci			u32 label;
18862306a36Sopenharmony_ci			u32 flags;
18962306a36Sopenharmony_ci#define VFDI_TXQ_FLAG_IP_CSUM_DIS 1
19062306a36Sopenharmony_ci#define VFDI_TXQ_FLAG_TCPUDP_CSUM_DIS 2
19162306a36Sopenharmony_ci			u32 reserved;
19262306a36Sopenharmony_ci			u64 addr[];
19362306a36Sopenharmony_ci		} init_txq;
19462306a36Sopenharmony_ci		struct {
19562306a36Sopenharmony_ci			u32 rxq;
19662306a36Sopenharmony_ci			u32 flags;
19762306a36Sopenharmony_ci#define VFDI_MAC_FILTER_FLAG_RSS 1
19862306a36Sopenharmony_ci#define VFDI_MAC_FILTER_FLAG_SCATTER 2
19962306a36Sopenharmony_ci		} mac_filter;
20062306a36Sopenharmony_ci		struct {
20162306a36Sopenharmony_ci			u64 dma_addr;
20262306a36Sopenharmony_ci			u64 peer_page_count;
20362306a36Sopenharmony_ci			u64 peer_page_addr[];
20462306a36Sopenharmony_ci		} set_status_page;
20562306a36Sopenharmony_ci	} u;
20662306a36Sopenharmony_ci};
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci/**
20962306a36Sopenharmony_ci * struct vfdi_status - Status provided by PF driver to VF driver
21062306a36Sopenharmony_ci * @generation_start: A generation count DMA'd to VF *before* the
21162306a36Sopenharmony_ci *	rest of the structure.
21262306a36Sopenharmony_ci * @generation_end: A generation count DMA'd to VF *after* the
21362306a36Sopenharmony_ci *	rest of the structure.
21462306a36Sopenharmony_ci * @version: Version of this structure; currently set to 1.  Later
21562306a36Sopenharmony_ci *	versions must either be layout-compatible or only be sent to VFs
21662306a36Sopenharmony_ci *	that specifically request them.
21762306a36Sopenharmony_ci * @length: Total length of this structure including embedded tables
21862306a36Sopenharmony_ci * @vi_scale: log2 the number of VIs available on this VF. This quantity
21962306a36Sopenharmony_ci *	is used by the hardware for register decoding.
22062306a36Sopenharmony_ci * @max_tx_channels: The maximum number of transmit queues the VF can use.
22162306a36Sopenharmony_ci * @rss_rxq_count: The number of receive queues present in the shared RSS
22262306a36Sopenharmony_ci *	indirection table.
22362306a36Sopenharmony_ci * @peer_count: Total number of peers in the complete peer list. If larger
22462306a36Sopenharmony_ci *	than ARRAY_SIZE(%peers), then the VF must provide sufficient
22562306a36Sopenharmony_ci *	additional pages each of which is filled with vfdi_endpoint structures.
22662306a36Sopenharmony_ci * @local: The MAC address and outer VLAN tag of *this* VF
22762306a36Sopenharmony_ci * @peers: Table of peer addresses.  The @tci fields in these structures
22862306a36Sopenharmony_ci *	are currently unused and must be ignored.  Additional peers are
22962306a36Sopenharmony_ci *	written into any additional pages provided by the VF.
23062306a36Sopenharmony_ci * @timer_quantum_ns: Timer quantum (nominal period between timer ticks)
23162306a36Sopenharmony_ci *	for interrupt moderation timers, in nanoseconds. This member is only
23262306a36Sopenharmony_ci *	present if @length is sufficiently large.
23362306a36Sopenharmony_ci */
23462306a36Sopenharmony_cistruct vfdi_status {
23562306a36Sopenharmony_ci	u32 generation_start;
23662306a36Sopenharmony_ci	u32 generation_end;
23762306a36Sopenharmony_ci	u32 version;
23862306a36Sopenharmony_ci	u32 length;
23962306a36Sopenharmony_ci	u8 vi_scale;
24062306a36Sopenharmony_ci	u8 max_tx_channels;
24162306a36Sopenharmony_ci	u8 rss_rxq_count;
24262306a36Sopenharmony_ci	u8 reserved1;
24362306a36Sopenharmony_ci	u16 peer_count;
24462306a36Sopenharmony_ci	u16 reserved2;
24562306a36Sopenharmony_ci	struct vfdi_endpoint local;
24662306a36Sopenharmony_ci	struct vfdi_endpoint peers[256];
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci	/* Members below here extend version 1 of this structure */
24962306a36Sopenharmony_ci	u32 timer_quantum_ns;
25062306a36Sopenharmony_ci};
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci#endif
253