xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/sfc/vfdi.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /****************************************************************************
3*4882a593Smuzhiyun  * Driver for Solarflare network controllers and boards
4*4882a593Smuzhiyun  * Copyright 2010-2012 Solarflare Communications Inc.
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun #ifndef _VFDI_H
7*4882a593Smuzhiyun #define _VFDI_H
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun /**
10*4882a593Smuzhiyun  * DOC: Virtual Function Driver Interface
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * This file contains software structures used to form a two way
13*4882a593Smuzhiyun  * communication channel between the VF driver and the PF driver,
14*4882a593Smuzhiyun  * named Virtual Function Driver Interface (VFDI).
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * For the purposes of VFDI, a page is a memory region with size and
17*4882a593Smuzhiyun  * alignment of 4K.  All addresses are DMA addresses to be used within
18*4882a593Smuzhiyun  * the domain of the relevant VF.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * The only hardware-defined channels for a VF driver to communicate
21*4882a593Smuzhiyun  * with the PF driver are the event mailboxes (%FR_CZ_USR_EV
22*4882a593Smuzhiyun  * registers).  Writing to these registers generates an event with
23*4882a593Smuzhiyun  * EV_CODE = EV_CODE_USR_EV, USER_QID set to the index of the mailbox
24*4882a593Smuzhiyun  * and USER_EV_REG_VALUE set to the value written.  The PF driver may
25*4882a593Smuzhiyun  * direct or disable delivery of these events by setting
26*4882a593Smuzhiyun  * %FR_CZ_USR_EV_CFG.
27*4882a593Smuzhiyun  *
28*4882a593Smuzhiyun  * The PF driver can send arbitrary events to arbitrary event queues.
29*4882a593Smuzhiyun  * However, for consistency, VFDI events from the PF are defined to
30*4882a593Smuzhiyun  * follow the same form and be sent to the first event queue assigned
31*4882a593Smuzhiyun  * to the VF while that queue is enabled by the VF driver.
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  * The general form of the variable bits of VFDI events is:
34*4882a593Smuzhiyun  *
35*4882a593Smuzhiyun  *       0             16                       24   31
36*4882a593Smuzhiyun  *      | DATA        | TYPE                   | SEQ   |
37*4882a593Smuzhiyun  *
38*4882a593Smuzhiyun  * SEQ is a sequence number which should be incremented by 1 (modulo
39*4882a593Smuzhiyun  * 256) for each event.  The sequence numbers used in each direction
40*4882a593Smuzhiyun  * are independent.
41*4882a593Smuzhiyun  *
42*4882a593Smuzhiyun  * The VF submits requests of type &struct vfdi_req by sending the
43*4882a593Smuzhiyun  * address of the request (ADDR) in a series of 4 events:
44*4882a593Smuzhiyun  *
45*4882a593Smuzhiyun  *       0             16                       24   31
46*4882a593Smuzhiyun  *      | ADDR[0:15]  | VFDI_EV_TYPE_REQ_WORD0 | SEQ   |
47*4882a593Smuzhiyun  *      | ADDR[16:31] | VFDI_EV_TYPE_REQ_WORD1 | SEQ+1 |
48*4882a593Smuzhiyun  *      | ADDR[32:47] | VFDI_EV_TYPE_REQ_WORD2 | SEQ+2 |
49*4882a593Smuzhiyun  *      | ADDR[48:63] | VFDI_EV_TYPE_REQ_WORD3 | SEQ+3 |
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  * The address must be page-aligned.  After receiving such a valid
52*4882a593Smuzhiyun  * series of events, the PF driver will attempt to read the request
53*4882a593Smuzhiyun  * and write a response to the same address.  In case of an invalid
54*4882a593Smuzhiyun  * sequence of events or a DMA error, there will be no response.
55*4882a593Smuzhiyun  *
56*4882a593Smuzhiyun  * The VF driver may request that the PF driver writes status
57*4882a593Smuzhiyun  * information into its domain asynchronously.  After writing the
58*4882a593Smuzhiyun  * status, the PF driver will send an event of the form:
59*4882a593Smuzhiyun  *
60*4882a593Smuzhiyun  *       0             16                       24   31
61*4882a593Smuzhiyun  *      | reserved    | VFDI_EV_TYPE_STATUS    | SEQ   |
62*4882a593Smuzhiyun  *
63*4882a593Smuzhiyun  * In case the VF must be reset for any reason, the PF driver will
64*4882a593Smuzhiyun  * send an event of the form:
65*4882a593Smuzhiyun  *
66*4882a593Smuzhiyun  *       0             16                       24   31
67*4882a593Smuzhiyun  *      | reserved    | VFDI_EV_TYPE_RESET     | SEQ   |
68*4882a593Smuzhiyun  *
69*4882a593Smuzhiyun  * It is then the responsibility of the VF driver to request
70*4882a593Smuzhiyun  * reinitialisation of its queues.
71*4882a593Smuzhiyun  */
72*4882a593Smuzhiyun #define VFDI_EV_SEQ_LBN 24
73*4882a593Smuzhiyun #define VFDI_EV_SEQ_WIDTH 8
74*4882a593Smuzhiyun #define VFDI_EV_TYPE_LBN 16
75*4882a593Smuzhiyun #define VFDI_EV_TYPE_WIDTH 8
76*4882a593Smuzhiyun #define VFDI_EV_TYPE_REQ_WORD0 0
77*4882a593Smuzhiyun #define VFDI_EV_TYPE_REQ_WORD1 1
78*4882a593Smuzhiyun #define VFDI_EV_TYPE_REQ_WORD2 2
79*4882a593Smuzhiyun #define VFDI_EV_TYPE_REQ_WORD3 3
80*4882a593Smuzhiyun #define VFDI_EV_TYPE_STATUS 4
81*4882a593Smuzhiyun #define VFDI_EV_TYPE_RESET 5
82*4882a593Smuzhiyun #define VFDI_EV_DATA_LBN 0
83*4882a593Smuzhiyun #define VFDI_EV_DATA_WIDTH 16
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun struct vfdi_endpoint {
86*4882a593Smuzhiyun 	u8 mac_addr[ETH_ALEN];
87*4882a593Smuzhiyun 	__be16 tci;
88*4882a593Smuzhiyun };
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun /**
91*4882a593Smuzhiyun  * enum vfdi_op - VFDI operation enumeration
92*4882a593Smuzhiyun  * @VFDI_OP_RESPONSE: Indicates a response to the request.
93*4882a593Smuzhiyun  * @VFDI_OP_INIT_EVQ: Initialize SRAM entries and initialize an EVQ.
94*4882a593Smuzhiyun  * @VFDI_OP_INIT_RXQ: Initialize SRAM entries and initialize an RXQ.
95*4882a593Smuzhiyun  * @VFDI_OP_INIT_TXQ: Initialize SRAM entries and initialize a TXQ.
96*4882a593Smuzhiyun  * @VFDI_OP_FINI_ALL_QUEUES: Flush all queues, finalize all queues, then
97*4882a593Smuzhiyun  *	finalize the SRAM entries.
98*4882a593Smuzhiyun  * @VFDI_OP_INSERT_FILTER: Insert a MAC filter targeting the given RXQ.
99*4882a593Smuzhiyun  * @VFDI_OP_REMOVE_ALL_FILTERS: Remove all filters.
100*4882a593Smuzhiyun  * @VFDI_OP_SET_STATUS_PAGE: Set the DMA page(s) used for status updates
101*4882a593Smuzhiyun  *	from PF and write the initial status.
102*4882a593Smuzhiyun  * @VFDI_OP_CLEAR_STATUS_PAGE: Clear the DMA page(s) used for status
103*4882a593Smuzhiyun  *	updates from PF.
104*4882a593Smuzhiyun  */
105*4882a593Smuzhiyun enum vfdi_op {
106*4882a593Smuzhiyun 	VFDI_OP_RESPONSE = 0,
107*4882a593Smuzhiyun 	VFDI_OP_INIT_EVQ = 1,
108*4882a593Smuzhiyun 	VFDI_OP_INIT_RXQ = 2,
109*4882a593Smuzhiyun 	VFDI_OP_INIT_TXQ = 3,
110*4882a593Smuzhiyun 	VFDI_OP_FINI_ALL_QUEUES = 4,
111*4882a593Smuzhiyun 	VFDI_OP_INSERT_FILTER = 5,
112*4882a593Smuzhiyun 	VFDI_OP_REMOVE_ALL_FILTERS = 6,
113*4882a593Smuzhiyun 	VFDI_OP_SET_STATUS_PAGE = 7,
114*4882a593Smuzhiyun 	VFDI_OP_CLEAR_STATUS_PAGE = 8,
115*4882a593Smuzhiyun 	VFDI_OP_LIMIT,
116*4882a593Smuzhiyun };
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun /* Response codes for VFDI operations. Other values may be used in future. */
119*4882a593Smuzhiyun #define VFDI_RC_SUCCESS		0
120*4882a593Smuzhiyun #define VFDI_RC_ENOMEM		(-12)
121*4882a593Smuzhiyun #define VFDI_RC_EINVAL		(-22)
122*4882a593Smuzhiyun #define VFDI_RC_EOPNOTSUPP	(-95)
123*4882a593Smuzhiyun #define VFDI_RC_ETIMEDOUT	(-110)
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun /**
126*4882a593Smuzhiyun  * struct vfdi_req - Request from VF driver to PF driver
127*4882a593Smuzhiyun  * @op: Operation code or response indicator, taken from &enum vfdi_op.
128*4882a593Smuzhiyun  * @rc: Response code.  Set to 0 on success or a negative error code on failure.
129*4882a593Smuzhiyun  * @u.init_evq.index: Index of event queue to create.
130*4882a593Smuzhiyun  * @u.init_evq.buf_count: Number of 4k buffers backing event queue.
131*4882a593Smuzhiyun  * @u.init_evq.addr: Array of length %u.init_evq.buf_count containing DMA
132*4882a593Smuzhiyun  *	address of each page backing the event queue.
133*4882a593Smuzhiyun  * @u.init_rxq.index: Index of receive queue to create.
134*4882a593Smuzhiyun  * @u.init_rxq.buf_count: Number of 4k buffers backing receive queue.
135*4882a593Smuzhiyun  * @u.init_rxq.evq: Instance of event queue to target receive events at.
136*4882a593Smuzhiyun  * @u.init_rxq.label: Label used in receive events.
137*4882a593Smuzhiyun  * @u.init_rxq.flags: Unused.
138*4882a593Smuzhiyun  * @u.init_rxq.addr: Array of length %u.init_rxq.buf_count containing DMA
139*4882a593Smuzhiyun  *	address of each page backing the receive queue.
140*4882a593Smuzhiyun  * @u.init_txq.index: Index of transmit queue to create.
141*4882a593Smuzhiyun  * @u.init_txq.buf_count: Number of 4k buffers backing transmit queue.
142*4882a593Smuzhiyun  * @u.init_txq.evq: Instance of event queue to target transmit completion
143*4882a593Smuzhiyun  *	events at.
144*4882a593Smuzhiyun  * @u.init_txq.label: Label used in transmit completion events.
145*4882a593Smuzhiyun  * @u.init_txq.flags: Checksum offload flags.
146*4882a593Smuzhiyun  * @u.init_txq.addr: Array of length %u.init_txq.buf_count containing DMA
147*4882a593Smuzhiyun  *	address of each page backing the transmit queue.
148*4882a593Smuzhiyun  * @u.mac_filter.rxq: Insert MAC filter at VF local address/VLAN targeting
149*4882a593Smuzhiyun  *	all traffic at this receive queue.
150*4882a593Smuzhiyun  * @u.mac_filter.flags: MAC filter flags.
151*4882a593Smuzhiyun  * @u.set_status_page.dma_addr: Base address for the &struct vfdi_status.
152*4882a593Smuzhiyun  *	This address must be page-aligned and the PF may write up to a
153*4882a593Smuzhiyun  *	whole page (allowing for extension of the structure).
154*4882a593Smuzhiyun  * @u.set_status_page.peer_page_count: Number of additional pages the VF
155*4882a593Smuzhiyun  *	has provided into which peer addresses may be DMAd.
156*4882a593Smuzhiyun  * @u.set_status_page.peer_page_addr: Array of DMA addresses of pages.
157*4882a593Smuzhiyun  *	If the number of peers exceeds 256, then the VF must provide
158*4882a593Smuzhiyun  *	additional pages in this array. The PF will then DMA up to
159*4882a593Smuzhiyun  *	512 vfdi_endpoint structures into each page.  These addresses
160*4882a593Smuzhiyun  *	must be page-aligned.
161*4882a593Smuzhiyun  */
162*4882a593Smuzhiyun struct vfdi_req {
163*4882a593Smuzhiyun 	u32 op;
164*4882a593Smuzhiyun 	u32 reserved1;
165*4882a593Smuzhiyun 	s32 rc;
166*4882a593Smuzhiyun 	u32 reserved2;
167*4882a593Smuzhiyun 	union {
168*4882a593Smuzhiyun 		struct {
169*4882a593Smuzhiyun 			u32 index;
170*4882a593Smuzhiyun 			u32 buf_count;
171*4882a593Smuzhiyun 			u64 addr[];
172*4882a593Smuzhiyun 		} init_evq;
173*4882a593Smuzhiyun 		struct {
174*4882a593Smuzhiyun 			u32 index;
175*4882a593Smuzhiyun 			u32 buf_count;
176*4882a593Smuzhiyun 			u32 evq;
177*4882a593Smuzhiyun 			u32 label;
178*4882a593Smuzhiyun 			u32 flags;
179*4882a593Smuzhiyun #define VFDI_RXQ_FLAG_SCATTER_EN 1
180*4882a593Smuzhiyun 			u32 reserved;
181*4882a593Smuzhiyun 			u64 addr[];
182*4882a593Smuzhiyun 		} init_rxq;
183*4882a593Smuzhiyun 		struct {
184*4882a593Smuzhiyun 			u32 index;
185*4882a593Smuzhiyun 			u32 buf_count;
186*4882a593Smuzhiyun 			u32 evq;
187*4882a593Smuzhiyun 			u32 label;
188*4882a593Smuzhiyun 			u32 flags;
189*4882a593Smuzhiyun #define VFDI_TXQ_FLAG_IP_CSUM_DIS 1
190*4882a593Smuzhiyun #define VFDI_TXQ_FLAG_TCPUDP_CSUM_DIS 2
191*4882a593Smuzhiyun 			u32 reserved;
192*4882a593Smuzhiyun 			u64 addr[];
193*4882a593Smuzhiyun 		} init_txq;
194*4882a593Smuzhiyun 		struct {
195*4882a593Smuzhiyun 			u32 rxq;
196*4882a593Smuzhiyun 			u32 flags;
197*4882a593Smuzhiyun #define VFDI_MAC_FILTER_FLAG_RSS 1
198*4882a593Smuzhiyun #define VFDI_MAC_FILTER_FLAG_SCATTER 2
199*4882a593Smuzhiyun 		} mac_filter;
200*4882a593Smuzhiyun 		struct {
201*4882a593Smuzhiyun 			u64 dma_addr;
202*4882a593Smuzhiyun 			u64 peer_page_count;
203*4882a593Smuzhiyun 			u64 peer_page_addr[];
204*4882a593Smuzhiyun 		} set_status_page;
205*4882a593Smuzhiyun 	} u;
206*4882a593Smuzhiyun };
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun /**
209*4882a593Smuzhiyun  * struct vfdi_status - Status provided by PF driver to VF driver
210*4882a593Smuzhiyun  * @generation_start: A generation count DMA'd to VF *before* the
211*4882a593Smuzhiyun  *	rest of the structure.
212*4882a593Smuzhiyun  * @generation_end: A generation count DMA'd to VF *after* the
213*4882a593Smuzhiyun  *	rest of the structure.
214*4882a593Smuzhiyun  * @version: Version of this structure; currently set to 1.  Later
215*4882a593Smuzhiyun  *	versions must either be layout-compatible or only be sent to VFs
216*4882a593Smuzhiyun  *	that specifically request them.
217*4882a593Smuzhiyun  * @length: Total length of this structure including embedded tables
218*4882a593Smuzhiyun  * @vi_scale: log2 the number of VIs available on this VF. This quantity
219*4882a593Smuzhiyun  *	is used by the hardware for register decoding.
220*4882a593Smuzhiyun  * @max_tx_channels: The maximum number of transmit queues the VF can use.
221*4882a593Smuzhiyun  * @rss_rxq_count: The number of receive queues present in the shared RSS
222*4882a593Smuzhiyun  *	indirection table.
223*4882a593Smuzhiyun  * @peer_count: Total number of peers in the complete peer list. If larger
224*4882a593Smuzhiyun  *	than ARRAY_SIZE(%peers), then the VF must provide sufficient
225*4882a593Smuzhiyun  *	additional pages each of which is filled with vfdi_endpoint structures.
226*4882a593Smuzhiyun  * @local: The MAC address and outer VLAN tag of *this* VF
227*4882a593Smuzhiyun  * @peers: Table of peer addresses.  The @tci fields in these structures
228*4882a593Smuzhiyun  *	are currently unused and must be ignored.  Additional peers are
229*4882a593Smuzhiyun  *	written into any additional pages provided by the VF.
230*4882a593Smuzhiyun  * @timer_quantum_ns: Timer quantum (nominal period between timer ticks)
231*4882a593Smuzhiyun  *	for interrupt moderation timers, in nanoseconds. This member is only
232*4882a593Smuzhiyun  *	present if @length is sufficiently large.
233*4882a593Smuzhiyun  */
234*4882a593Smuzhiyun struct vfdi_status {
235*4882a593Smuzhiyun 	u32 generation_start;
236*4882a593Smuzhiyun 	u32 generation_end;
237*4882a593Smuzhiyun 	u32 version;
238*4882a593Smuzhiyun 	u32 length;
239*4882a593Smuzhiyun 	u8 vi_scale;
240*4882a593Smuzhiyun 	u8 max_tx_channels;
241*4882a593Smuzhiyun 	u8 rss_rxq_count;
242*4882a593Smuzhiyun 	u8 reserved1;
243*4882a593Smuzhiyun 	u16 peer_count;
244*4882a593Smuzhiyun 	u16 reserved2;
245*4882a593Smuzhiyun 	struct vfdi_endpoint local;
246*4882a593Smuzhiyun 	struct vfdi_endpoint peers[256];
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun 	/* Members below here extend version 1 of this structure */
249*4882a593Smuzhiyun 	u32 timer_quantum_ns;
250*4882a593Smuzhiyun };
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun #endif
253