xref: /freebsd/sys/dev/ice/virtchnl.h (revision 9cf1841c4aaf8fbab06132ab9f76094f34ad7c7b)
171d10453SEric Joyner /* SPDX-License-Identifier: BSD-3-Clause */
2d08b8680SEric Joyner /*  Copyright (c) 2021, Intel Corporation
371d10453SEric Joyner  *  All rights reserved.
471d10453SEric Joyner  *
571d10453SEric Joyner  *  Redistribution and use in source and binary forms, with or without
671d10453SEric Joyner  *  modification, are permitted provided that the following conditions are met:
771d10453SEric Joyner  *
871d10453SEric Joyner  *   1. Redistributions of source code must retain the above copyright notice,
971d10453SEric Joyner  *      this list of conditions and the following disclaimer.
1071d10453SEric Joyner  *
1171d10453SEric Joyner  *   2. Redistributions in binary form must reproduce the above copyright
1271d10453SEric Joyner  *      notice, this list of conditions and the following disclaimer in the
1371d10453SEric Joyner  *      documentation and/or other materials provided with the distribution.
1471d10453SEric Joyner  *
1571d10453SEric Joyner  *   3. Neither the name of the Intel Corporation nor the names of its
1671d10453SEric Joyner  *      contributors may be used to endorse or promote products derived from
1771d10453SEric Joyner  *      this software without specific prior written permission.
1871d10453SEric Joyner  *
1971d10453SEric Joyner  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2071d10453SEric Joyner  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2171d10453SEric Joyner  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2271d10453SEric Joyner  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2371d10453SEric Joyner  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2471d10453SEric Joyner  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2571d10453SEric Joyner  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2671d10453SEric Joyner  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2771d10453SEric Joyner  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2871d10453SEric Joyner  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2971d10453SEric Joyner  *  POSSIBILITY OF SUCH DAMAGE.
3071d10453SEric Joyner  */
3171d10453SEric Joyner /*$FreeBSD$*/
3271d10453SEric Joyner 
3371d10453SEric Joyner #ifndef _VIRTCHNL_H_
3471d10453SEric Joyner #define _VIRTCHNL_H_
3571d10453SEric Joyner 
3671d10453SEric Joyner /* Description:
37*9cf1841cSEric Joyner  * This header file describes the Virtual Function (VF) - Physical Function
38*9cf1841cSEric Joyner  * (PF) communication protocol used by the drivers for all devices starting
39*9cf1841cSEric Joyner  * from our 40G product line
4071d10453SEric Joyner  *
4171d10453SEric Joyner  * Admin queue buffer usage:
4271d10453SEric Joyner  * desc->opcode is always aqc_opc_send_msg_to_pf
4371d10453SEric Joyner  * flags, retval, datalen, and data addr are all used normally.
4471d10453SEric Joyner  * The Firmware copies the cookie fields when sending messages between the
4571d10453SEric Joyner  * PF and VF, but uses all other fields internally. Due to this limitation,
4671d10453SEric Joyner  * we must send all messages as "indirect", i.e. using an external buffer.
4771d10453SEric Joyner  *
4871d10453SEric Joyner  * All the VSI indexes are relative to the VF. Each VF can have maximum of
4971d10453SEric Joyner  * three VSIs. All the queue indexes are relative to the VSI.  Each VF can
5071d10453SEric Joyner  * have a maximum of sixteen queues for all of its VSIs.
5171d10453SEric Joyner  *
5271d10453SEric Joyner  * The PF is required to return a status code in v_retval for all messages
53*9cf1841cSEric Joyner  * except RESET_VF, which does not require any response. The returned value
54*9cf1841cSEric Joyner  * is of virtchnl_status_code type, defined in the shared type.h.
5571d10453SEric Joyner  *
5671d10453SEric Joyner  * In general, VF driver initialization should roughly follow the order of
5771d10453SEric Joyner  * these opcodes. The VF driver must first validate the API version of the
5871d10453SEric Joyner  * PF driver, then request a reset, then get resources, then configure
5971d10453SEric Joyner  * queues and interrupts. After these operations are complete, the VF
6071d10453SEric Joyner  * driver may start its queues, optionally add MAC and VLAN filters, and
6171d10453SEric Joyner  * process traffic.
6271d10453SEric Joyner  */
6371d10453SEric Joyner 
6471d10453SEric Joyner /* START GENERIC DEFINES
6571d10453SEric Joyner  * Need to ensure the following enums and defines hold the same meaning and
6671d10453SEric Joyner  * value in current and future projects
6771d10453SEric Joyner  */
6871d10453SEric Joyner 
6971d10453SEric Joyner /* Error Codes */
7071d10453SEric Joyner enum virtchnl_status_code {
7171d10453SEric Joyner 	VIRTCHNL_STATUS_SUCCESS				= 0,
7271d10453SEric Joyner 	VIRTCHNL_STATUS_ERR_PARAM			= -5,
7371d10453SEric Joyner 	VIRTCHNL_STATUS_ERR_NO_MEMORY			= -18,
7471d10453SEric Joyner 	VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH		= -38,
7571d10453SEric Joyner 	VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR		= -39,
7671d10453SEric Joyner 	VIRTCHNL_STATUS_ERR_INVALID_VF_ID		= -40,
7771d10453SEric Joyner 	VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR		= -53,
7871d10453SEric Joyner 	VIRTCHNL_STATUS_ERR_NOT_SUPPORTED		= -64,
7971d10453SEric Joyner };
8071d10453SEric Joyner 
8171d10453SEric Joyner /* Backward compatibility */
8271d10453SEric Joyner #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM
8371d10453SEric Joyner #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED
8471d10453SEric Joyner 
8571d10453SEric Joyner #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT		0x0
8671d10453SEric Joyner #define VIRTCHNL_LINK_SPEED_100MB_SHIFT		0x1
8771d10453SEric Joyner #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT	0x2
8871d10453SEric Joyner #define VIRTCHNL_LINK_SPEED_10GB_SHIFT		0x3
8971d10453SEric Joyner #define VIRTCHNL_LINK_SPEED_40GB_SHIFT		0x4
9071d10453SEric Joyner #define VIRTCHNL_LINK_SPEED_20GB_SHIFT		0x5
9171d10453SEric Joyner #define VIRTCHNL_LINK_SPEED_25GB_SHIFT		0x6
9271d10453SEric Joyner #define VIRTCHNL_LINK_SPEED_5GB_SHIFT		0x7
9371d10453SEric Joyner 
9471d10453SEric Joyner enum virtchnl_link_speed {
9571d10453SEric Joyner 	VIRTCHNL_LINK_SPEED_UNKNOWN	= 0,
9671d10453SEric Joyner 	VIRTCHNL_LINK_SPEED_100MB	= BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
9771d10453SEric Joyner 	VIRTCHNL_LINK_SPEED_1GB		= BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
9871d10453SEric Joyner 	VIRTCHNL_LINK_SPEED_10GB	= BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
9971d10453SEric Joyner 	VIRTCHNL_LINK_SPEED_40GB	= BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
10071d10453SEric Joyner 	VIRTCHNL_LINK_SPEED_20GB	= BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
10171d10453SEric Joyner 	VIRTCHNL_LINK_SPEED_25GB	= BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
10271d10453SEric Joyner 	VIRTCHNL_LINK_SPEED_2_5GB	= BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT),
10371d10453SEric Joyner 	VIRTCHNL_LINK_SPEED_5GB		= BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT),
10471d10453SEric Joyner };
10571d10453SEric Joyner 
10671d10453SEric Joyner /* for hsplit_0 field of Rx HMC context */
10771d10453SEric Joyner /* deprecated with AVF 1.0 */
10871d10453SEric Joyner enum virtchnl_rx_hsplit {
10971d10453SEric Joyner 	VIRTCHNL_RX_HSPLIT_NO_SPLIT      = 0,
11071d10453SEric Joyner 	VIRTCHNL_RX_HSPLIT_SPLIT_L2      = 1,
11171d10453SEric Joyner 	VIRTCHNL_RX_HSPLIT_SPLIT_IP      = 2,
11271d10453SEric Joyner 	VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4,
11371d10453SEric Joyner 	VIRTCHNL_RX_HSPLIT_SPLIT_SCTP    = 8,
11471d10453SEric Joyner };
11571d10453SEric Joyner 
11671d10453SEric Joyner #define VIRTCHNL_ETH_LENGTH_OF_ADDRESS	6
11771d10453SEric Joyner /* END GENERIC DEFINES */
11871d10453SEric Joyner 
11971d10453SEric Joyner /* Opcodes for VF-PF communication. These are placed in the v_opcode field
12071d10453SEric Joyner  * of the virtchnl_msg structure.
12171d10453SEric Joyner  */
12271d10453SEric Joyner enum virtchnl_ops {
12371d10453SEric Joyner /* The PF sends status change events to VFs using
12471d10453SEric Joyner  * the VIRTCHNL_OP_EVENT opcode.
12571d10453SEric Joyner  * VFs send requests to the PF using the other ops.
12671d10453SEric Joyner  * Use of "advanced opcode" features must be negotiated as part of capabilities
12771d10453SEric Joyner  * exchange and are not considered part of base mode feature set.
12871d10453SEric Joyner  */
12971d10453SEric Joyner 	VIRTCHNL_OP_UNKNOWN = 0,
13071d10453SEric Joyner 	VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
13171d10453SEric Joyner 	VIRTCHNL_OP_RESET_VF = 2,
13271d10453SEric Joyner 	VIRTCHNL_OP_GET_VF_RESOURCES = 3,
13371d10453SEric Joyner 	VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
13471d10453SEric Joyner 	VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
13571d10453SEric Joyner 	VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
13671d10453SEric Joyner 	VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
13771d10453SEric Joyner 	VIRTCHNL_OP_ENABLE_QUEUES = 8,
13871d10453SEric Joyner 	VIRTCHNL_OP_DISABLE_QUEUES = 9,
13971d10453SEric Joyner 	VIRTCHNL_OP_ADD_ETH_ADDR = 10,
14071d10453SEric Joyner 	VIRTCHNL_OP_DEL_ETH_ADDR = 11,
14171d10453SEric Joyner 	VIRTCHNL_OP_ADD_VLAN = 12,
14271d10453SEric Joyner 	VIRTCHNL_OP_DEL_VLAN = 13,
14371d10453SEric Joyner 	VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
14471d10453SEric Joyner 	VIRTCHNL_OP_GET_STATS = 15,
14571d10453SEric Joyner 	VIRTCHNL_OP_RSVD = 16,
14671d10453SEric Joyner 	VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
14771d10453SEric Joyner 	/* opcode 19 is reserved */
14871d10453SEric Joyner 	/* opcodes 20, 21, and 22 are reserved */
14971d10453SEric Joyner 	VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
15071d10453SEric Joyner 	VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
15171d10453SEric Joyner 	VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
15271d10453SEric Joyner 	VIRTCHNL_OP_SET_RSS_HENA = 26,
15371d10453SEric Joyner 	VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27,
15471d10453SEric Joyner 	VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28,
15571d10453SEric Joyner 	VIRTCHNL_OP_REQUEST_QUEUES = 29,
15671d10453SEric Joyner 	VIRTCHNL_OP_ENABLE_CHANNELS = 30,
15771d10453SEric Joyner 	VIRTCHNL_OP_DISABLE_CHANNELS = 31,
15871d10453SEric Joyner 	VIRTCHNL_OP_ADD_CLOUD_FILTER = 32,
15971d10453SEric Joyner 	VIRTCHNL_OP_DEL_CLOUD_FILTER = 33,
1607d7af7f8SEric Joyner 	/* opcode 34 is reserved */
161*9cf1841cSEric Joyner 	/* opcodes 38, 39, 40, 41, 42 and 43 are reserved */
1627d7af7f8SEric Joyner 	/* opcode 44 is reserved */
1637d7af7f8SEric Joyner 	/* opcode 45, 46, 47, 48 and 49 are reserved */
164d08b8680SEric Joyner 	VIRTCHNL_OP_GET_MAX_RSS_QREGION = 50,
165*9cf1841cSEric Joyner 	VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS = 51,
166*9cf1841cSEric Joyner 	VIRTCHNL_OP_ADD_VLAN_V2 = 52,
167*9cf1841cSEric Joyner 	VIRTCHNL_OP_DEL_VLAN_V2 = 53,
168*9cf1841cSEric Joyner 	VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 = 54,
169*9cf1841cSEric Joyner 	VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 = 55,
170*9cf1841cSEric Joyner 	VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 = 56,
171*9cf1841cSEric Joyner 	VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 = 57,
172*9cf1841cSEric Joyner 	VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2 = 58,
173*9cf1841cSEric Joyner 	VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 = 59,
174*9cf1841cSEric Joyner 	/* opcodes 60 through 69 are reserved */
175d08b8680SEric Joyner 	VIRTCHNL_OP_ENABLE_QUEUES_V2 = 107,
176d08b8680SEric Joyner 	VIRTCHNL_OP_DISABLE_QUEUES_V2 = 108,
177d08b8680SEric Joyner 	VIRTCHNL_OP_MAP_QUEUE_VECTOR = 111,
1787d7af7f8SEric Joyner 	VIRTCHNL_OP_MAX,
17971d10453SEric Joyner };
18071d10453SEric Joyner 
181d08b8680SEric Joyner static inline const char *virtchnl_op_str(enum virtchnl_ops v_opcode)
182d08b8680SEric Joyner {
183d08b8680SEric Joyner 	switch (v_opcode) {
184d08b8680SEric Joyner 	case VIRTCHNL_OP_UNKNOWN:
185d08b8680SEric Joyner 		return "VIRTCHNL_OP_UNKNOWN";
186d08b8680SEric Joyner 	case VIRTCHNL_OP_VERSION:
187d08b8680SEric Joyner 		return "VIRTCHNL_OP_VERSION";
188d08b8680SEric Joyner 	case VIRTCHNL_OP_RESET_VF:
189d08b8680SEric Joyner 		return "VIRTCHNL_OP_RESET_VF";
190d08b8680SEric Joyner 	case VIRTCHNL_OP_GET_VF_RESOURCES:
191d08b8680SEric Joyner 		return "VIRTCHNL_OP_GET_VF_RESOURCES";
192d08b8680SEric Joyner 	case VIRTCHNL_OP_CONFIG_TX_QUEUE:
193d08b8680SEric Joyner 		return "VIRTCHNL_OP_CONFIG_TX_QUEUE";
194d08b8680SEric Joyner 	case VIRTCHNL_OP_CONFIG_RX_QUEUE:
195d08b8680SEric Joyner 		return "VIRTCHNL_OP_CONFIG_RX_QUEUE";
196d08b8680SEric Joyner 	case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
197d08b8680SEric Joyner 		return "VIRTCHNL_OP_CONFIG_VSI_QUEUES";
198d08b8680SEric Joyner 	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
199d08b8680SEric Joyner 		return "VIRTCHNL_OP_CONFIG_IRQ_MAP";
200d08b8680SEric Joyner 	case VIRTCHNL_OP_ENABLE_QUEUES:
201d08b8680SEric Joyner 		return "VIRTCHNL_OP_ENABLE_QUEUES";
202d08b8680SEric Joyner 	case VIRTCHNL_OP_DISABLE_QUEUES:
203d08b8680SEric Joyner 		return "VIRTCHNL_OP_DISABLE_QUEUES";
204d08b8680SEric Joyner 	case VIRTCHNL_OP_ADD_ETH_ADDR:
205d08b8680SEric Joyner 		return "VIRTCHNL_OP_ADD_ETH_ADDR";
206d08b8680SEric Joyner 	case VIRTCHNL_OP_DEL_ETH_ADDR:
207d08b8680SEric Joyner 		return "VIRTCHNL_OP_DEL_ETH_ADDR";
208d08b8680SEric Joyner 	case VIRTCHNL_OP_ADD_VLAN:
209d08b8680SEric Joyner 		return "VIRTCHNL_OP_ADD_VLAN";
210d08b8680SEric Joyner 	case VIRTCHNL_OP_DEL_VLAN:
211d08b8680SEric Joyner 		return "VIRTCHNL_OP_DEL_VLAN";
212d08b8680SEric Joyner 	case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
213d08b8680SEric Joyner 		return "VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE";
214d08b8680SEric Joyner 	case VIRTCHNL_OP_GET_STATS:
215d08b8680SEric Joyner 		return "VIRTCHNL_OP_GET_STATS";
216d08b8680SEric Joyner 	case VIRTCHNL_OP_RSVD:
217d08b8680SEric Joyner 		return "VIRTCHNL_OP_RSVD";
218d08b8680SEric Joyner 	case VIRTCHNL_OP_EVENT:
219d08b8680SEric Joyner 		return "VIRTCHNL_OP_EVENT";
220d08b8680SEric Joyner 	case VIRTCHNL_OP_CONFIG_RSS_KEY:
221d08b8680SEric Joyner 		return "VIRTCHNL_OP_CONFIG_RSS_KEY";
222d08b8680SEric Joyner 	case VIRTCHNL_OP_CONFIG_RSS_LUT:
223d08b8680SEric Joyner 		return "VIRTCHNL_OP_CONFIG_RSS_LUT";
224d08b8680SEric Joyner 	case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
225d08b8680SEric Joyner 		return "VIRTCHNL_OP_GET_RSS_HENA_CAPS";
226d08b8680SEric Joyner 	case VIRTCHNL_OP_SET_RSS_HENA:
227d08b8680SEric Joyner 		return "VIRTCHNL_OP_SET_RSS_HENA";
228d08b8680SEric Joyner 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
229d08b8680SEric Joyner 		return "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING";
230d08b8680SEric Joyner 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
231d08b8680SEric Joyner 		return "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING";
232d08b8680SEric Joyner 	case VIRTCHNL_OP_REQUEST_QUEUES:
233d08b8680SEric Joyner 		return "VIRTCHNL_OP_REQUEST_QUEUES";
234d08b8680SEric Joyner 	case VIRTCHNL_OP_ENABLE_CHANNELS:
235d08b8680SEric Joyner 		return "VIRTCHNL_OP_ENABLE_CHANNELS";
236d08b8680SEric Joyner 	case VIRTCHNL_OP_DISABLE_CHANNELS:
237d08b8680SEric Joyner 		return "VIRTCHNL_OP_DISABLE_CHANNELS";
238d08b8680SEric Joyner 	case VIRTCHNL_OP_ADD_CLOUD_FILTER:
239d08b8680SEric Joyner 		return "VIRTCHNL_OP_ADD_CLOUD_FILTER";
240d08b8680SEric Joyner 	case VIRTCHNL_OP_DEL_CLOUD_FILTER:
241d08b8680SEric Joyner 		return "VIRTCHNL_OP_DEL_CLOUD_FILTER";
242d08b8680SEric Joyner 	case VIRTCHNL_OP_GET_MAX_RSS_QREGION:
243d08b8680SEric Joyner 		return "VIRTCHNL_OP_GET_MAX_RSS_QREGION";
244d08b8680SEric Joyner 	case VIRTCHNL_OP_ENABLE_QUEUES_V2:
245d08b8680SEric Joyner 		return "VIRTCHNL_OP_ENABLE_QUEUES_V2";
246d08b8680SEric Joyner 	case VIRTCHNL_OP_DISABLE_QUEUES_V2:
247d08b8680SEric Joyner 		return "VIRTCHNL_OP_DISABLE_QUEUES_V2";
248d08b8680SEric Joyner 	case VIRTCHNL_OP_MAP_QUEUE_VECTOR:
249d08b8680SEric Joyner 		return "VIRTCHNL_OP_MAP_QUEUE_VECTOR";
250*9cf1841cSEric Joyner 	case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
251*9cf1841cSEric Joyner 		return "VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS";
252*9cf1841cSEric Joyner 	case VIRTCHNL_OP_ADD_VLAN_V2:
253*9cf1841cSEric Joyner 		return "VIRTCHNL_OP_ADD_VLAN_V2";
254*9cf1841cSEric Joyner 	case VIRTCHNL_OP_DEL_VLAN_V2:
255*9cf1841cSEric Joyner 		return "VIRTCHNL_OP_DEL_VLAN_V2";
256*9cf1841cSEric Joyner 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
257*9cf1841cSEric Joyner 		return "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2";
258*9cf1841cSEric Joyner 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
259*9cf1841cSEric Joyner 		return "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2";
260*9cf1841cSEric Joyner 	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
261*9cf1841cSEric Joyner 		return "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2";
262*9cf1841cSEric Joyner 	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
263*9cf1841cSEric Joyner 		return "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2";
264*9cf1841cSEric Joyner 	case VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2:
265*9cf1841cSEric Joyner 		return "VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2";
266*9cf1841cSEric Joyner 	case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
267*9cf1841cSEric Joyner 		return "VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2";
268d08b8680SEric Joyner 	case VIRTCHNL_OP_MAX:
269d08b8680SEric Joyner 		return "VIRTCHNL_OP_MAX";
270d08b8680SEric Joyner 	default:
271d08b8680SEric Joyner 		return "Unsupported (update virtchnl.h)";
272d08b8680SEric Joyner 	}
273d08b8680SEric Joyner }
274d08b8680SEric Joyner 
27571d10453SEric Joyner /* These macros are used to generate compilation errors if a structure/union
27671d10453SEric Joyner  * is not exactly the correct length. It gives a divide by zero error if the
27771d10453SEric Joyner  * structure/union is not of the correct size, otherwise it creates an enum
27871d10453SEric Joyner  * that is never used.
27971d10453SEric Joyner  */
28071d10453SEric Joyner #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
28171d10453SEric Joyner 	{ virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
28271d10453SEric Joyner #define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \
28371d10453SEric Joyner 	{ virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
28471d10453SEric Joyner 
28571d10453SEric Joyner /* Virtual channel message descriptor. This overlays the admin queue
28671d10453SEric Joyner  * descriptor. All other data is passed in external buffers.
28771d10453SEric Joyner  */
28871d10453SEric Joyner 
28971d10453SEric Joyner struct virtchnl_msg {
29071d10453SEric Joyner 	u8 pad[8];			 /* AQ flags/opcode/len/retval fields */
291*9cf1841cSEric Joyner 
292*9cf1841cSEric Joyner 	/* avoid confusion with desc->opcode */
293*9cf1841cSEric Joyner 	enum virtchnl_ops v_opcode;
294*9cf1841cSEric Joyner 
295*9cf1841cSEric Joyner 	/* ditto for desc->retval */
296*9cf1841cSEric Joyner 	enum virtchnl_status_code v_retval;
29771d10453SEric Joyner 	u32 vfid;			 /* used by PF when sending to VF */
29871d10453SEric Joyner };
29971d10453SEric Joyner 
30071d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
30171d10453SEric Joyner 
30271d10453SEric Joyner /* Message descriptions and data structures. */
30371d10453SEric Joyner 
30471d10453SEric Joyner /* VIRTCHNL_OP_VERSION
30571d10453SEric Joyner  * VF posts its version number to the PF. PF responds with its version number
30671d10453SEric Joyner  * in the same format, along with a return code.
30771d10453SEric Joyner  * Reply from PF has its major/minor versions also in param0 and param1.
30871d10453SEric Joyner  * If there is a major version mismatch, then the VF cannot operate.
30971d10453SEric Joyner  * If there is a minor version mismatch, then the VF can operate but should
31071d10453SEric Joyner  * add a warning to the system log.
31171d10453SEric Joyner  *
31271d10453SEric Joyner  * This enum element MUST always be specified as == 1, regardless of other
31371d10453SEric Joyner  * changes in the API. The PF must always respond to this message without
31471d10453SEric Joyner  * error regardless of version mismatch.
31571d10453SEric Joyner  */
31671d10453SEric Joyner #define VIRTCHNL_VERSION_MAJOR		1
31771d10453SEric Joyner #define VIRTCHNL_VERSION_MINOR		1
318*9cf1841cSEric Joyner #define VIRTCHNL_VERSION_MAJOR_2	2
319*9cf1841cSEric Joyner #define VIRTCHNL_VERSION_MINOR_0	0
32071d10453SEric Joyner #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS	0
32171d10453SEric Joyner 
32271d10453SEric Joyner struct virtchnl_version_info {
32371d10453SEric Joyner 	u32 major;
32471d10453SEric Joyner 	u32 minor;
32571d10453SEric Joyner };
32671d10453SEric Joyner 
32771d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
32871d10453SEric Joyner 
32971d10453SEric Joyner #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
33071d10453SEric Joyner #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
33171d10453SEric Joyner 
33271d10453SEric Joyner /* VIRTCHNL_OP_RESET_VF
33371d10453SEric Joyner  * VF sends this request to PF with no parameters
33471d10453SEric Joyner  * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
33571d10453SEric Joyner  * until reset completion is indicated. The admin queue must be reinitialized
33671d10453SEric Joyner  * after this operation.
33771d10453SEric Joyner  *
33871d10453SEric Joyner  * When reset is complete, PF must ensure that all queues in all VSIs associated
33971d10453SEric Joyner  * with the VF are stopped, all queue configurations in the HMC are set to 0,
34071d10453SEric Joyner  * and all MAC and VLAN filters (except the default MAC address) on all VSIs
34171d10453SEric Joyner  * are cleared.
34271d10453SEric Joyner  */
34371d10453SEric Joyner 
34471d10453SEric Joyner /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
34571d10453SEric Joyner  * vsi_type should always be 6 for backward compatibility. Add other fields
34671d10453SEric Joyner  * as needed.
34771d10453SEric Joyner  */
34871d10453SEric Joyner enum virtchnl_vsi_type {
34971d10453SEric Joyner 	VIRTCHNL_VSI_TYPE_INVALID = 0,
35071d10453SEric Joyner 	VIRTCHNL_VSI_SRIOV = 6,
35171d10453SEric Joyner };
35271d10453SEric Joyner 
35371d10453SEric Joyner /* VIRTCHNL_OP_GET_VF_RESOURCES
35471d10453SEric Joyner  * Version 1.0 VF sends this request to PF with no parameters
35571d10453SEric Joyner  * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
35671d10453SEric Joyner  * PF responds with an indirect message containing
35771d10453SEric Joyner  * virtchnl_vf_resource and one or more
35871d10453SEric Joyner  * virtchnl_vsi_resource structures.
35971d10453SEric Joyner  */
36071d10453SEric Joyner 
36171d10453SEric Joyner struct virtchnl_vsi_resource {
36271d10453SEric Joyner 	u16 vsi_id;
36371d10453SEric Joyner 	u16 num_queue_pairs;
364*9cf1841cSEric Joyner 
365*9cf1841cSEric Joyner 	/* see enum virtchnl_vsi_type */
366*9cf1841cSEric Joyner 	s32 vsi_type;
36771d10453SEric Joyner 	u16 qset_handle;
36871d10453SEric Joyner 	u8 default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
36971d10453SEric Joyner };
37071d10453SEric Joyner 
37171d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
37271d10453SEric Joyner 
37371d10453SEric Joyner /* VF capability flags
37471d10453SEric Joyner  * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
37571d10453SEric Joyner  * TX/RX Checksum offloading and TSO for non-tunnelled packets.
37671d10453SEric Joyner  */
37771d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_L2			0x00000001
37871d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_IWARP		0x00000002
37971d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_RSVD		0x00000004
38071d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_RSS_AQ		0x00000008
38171d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_RSS_REG		0x00000010
38271d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR		0x00000020
38371d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES		0x00000040
38471d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_CRC			0x00000080
385d08b8680SEric Joyner 	/* 0X00000100 is reserved */
386d08b8680SEric Joyner #define VIRTCHNL_VF_LARGE_NUM_QPAIRS		0x00000200
387*9cf1841cSEric Joyner #define VIRTCHNL_VF_OFFLOAD_VLAN_V2		0x00008000
38871d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_VLAN		0x00010000
38971d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_RX_POLLING		0x00020000
39071d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2	0x00040000
39171d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_RSS_PF		0X00080000
39271d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_ENCAP		0X00100000
39371d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM		0X00200000
39471d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM	0X00400000
39571d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_ADQ			0X00800000
39671d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_ADQ_V2		0X01000000
39771d10453SEric Joyner #define VIRTCHNL_VF_OFFLOAD_USO			0X02000000
3987d7af7f8SEric Joyner 	/* 0x04000000 is reserved */
3997d7af7f8SEric Joyner 	/* 0X08000000 and 0X10000000 are reserved */
4007d7af7f8SEric Joyner 	/* 0X20000000 is reserved */
40171d10453SEric Joyner 	/* 0X40000000 is reserved */
402*9cf1841cSEric Joyner 	/* 0X80000000 is reserved */
40371d10453SEric Joyner 
40471d10453SEric Joyner /* Define below the capability flags that are not offloads */
40571d10453SEric Joyner #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED		0x00000080
40671d10453SEric Joyner #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
40771d10453SEric Joyner 			       VIRTCHNL_VF_OFFLOAD_VLAN | \
40871d10453SEric Joyner 			       VIRTCHNL_VF_OFFLOAD_RSS_PF)
40971d10453SEric Joyner 
41071d10453SEric Joyner struct virtchnl_vf_resource {
41171d10453SEric Joyner 	u16 num_vsis;
41271d10453SEric Joyner 	u16 num_queue_pairs;
41371d10453SEric Joyner 	u16 max_vectors;
41471d10453SEric Joyner 	u16 max_mtu;
41571d10453SEric Joyner 
41671d10453SEric Joyner 	u32 vf_cap_flags;
41771d10453SEric Joyner 	u32 rss_key_size;
41871d10453SEric Joyner 	u32 rss_lut_size;
41971d10453SEric Joyner 
42071d10453SEric Joyner 	struct virtchnl_vsi_resource vsi_res[1];
42171d10453SEric Joyner };
42271d10453SEric Joyner 
42371d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
42471d10453SEric Joyner 
42571d10453SEric Joyner /* VIRTCHNL_OP_CONFIG_TX_QUEUE
42671d10453SEric Joyner  * VF sends this message to set up parameters for one TX queue.
42771d10453SEric Joyner  * External data buffer contains one instance of virtchnl_txq_info.
42871d10453SEric Joyner  * PF configures requested queue and returns a status code.
42971d10453SEric Joyner  */
43071d10453SEric Joyner 
43171d10453SEric Joyner /* Tx queue config info */
43271d10453SEric Joyner struct virtchnl_txq_info {
43371d10453SEric Joyner 	u16 vsi_id;
43471d10453SEric Joyner 	u16 queue_id;
43571d10453SEric Joyner 	u16 ring_len;		/* number of descriptors, multiple of 8 */
43671d10453SEric Joyner 	u16 headwb_enabled; /* deprecated with AVF 1.0 */
43771d10453SEric Joyner 	u64 dma_ring_addr;
43871d10453SEric Joyner 	u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
43971d10453SEric Joyner };
44071d10453SEric Joyner 
44171d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
44271d10453SEric Joyner 
44371d10453SEric Joyner /* VIRTCHNL_OP_CONFIG_RX_QUEUE
44471d10453SEric Joyner  * VF sends this message to set up parameters for one RX queue.
44571d10453SEric Joyner  * External data buffer contains one instance of virtchnl_rxq_info.
44671d10453SEric Joyner  * PF configures requested queue and returns a status code. The
44771d10453SEric Joyner  * crc_disable flag disables CRC stripping on the VF. Setting
44871d10453SEric Joyner  * the crc_disable flag to 1 will disable CRC stripping for each
44971d10453SEric Joyner  * queue in the VF where the flag is set. The VIRTCHNL_VF_OFFLOAD_CRC
45071d10453SEric Joyner  * offload must have been set prior to sending this info or the PF
45171d10453SEric Joyner  * will ignore the request. This flag should be set the same for
45271d10453SEric Joyner  * all of the queues for a VF.
45371d10453SEric Joyner  */
45471d10453SEric Joyner 
45571d10453SEric Joyner /* Rx queue config info */
45671d10453SEric Joyner struct virtchnl_rxq_info {
45771d10453SEric Joyner 	u16 vsi_id;
45871d10453SEric Joyner 	u16 queue_id;
45971d10453SEric Joyner 	u32 ring_len;		/* number of descriptors, multiple of 32 */
46071d10453SEric Joyner 	u16 hdr_size;
46171d10453SEric Joyner 	u16 splithdr_enabled; /* deprecated with AVF 1.0 */
46271d10453SEric Joyner 	u32 databuffer_size;
46371d10453SEric Joyner 	u32 max_pkt_size;
46471d10453SEric Joyner 	u8 crc_disable;
46571d10453SEric Joyner 	u8 pad1[3];
46671d10453SEric Joyner 	u64 dma_ring_addr;
467*9cf1841cSEric Joyner 
468*9cf1841cSEric Joyner 	/* see enum virtchnl_rx_hsplit; deprecated with AVF 1.0 */
469*9cf1841cSEric Joyner 	s32 rx_split_pos;
47071d10453SEric Joyner 	u32 pad2;
47171d10453SEric Joyner };
47271d10453SEric Joyner 
47371d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
47471d10453SEric Joyner 
47571d10453SEric Joyner /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
47671d10453SEric Joyner  * VF sends this message to set parameters for active TX and RX queues
47771d10453SEric Joyner  * associated with the specified VSI.
47871d10453SEric Joyner  * PF configures queues and returns status.
47971d10453SEric Joyner  * If the number of queues specified is greater than the number of queues
48071d10453SEric Joyner  * associated with the VSI, an error is returned and no queues are configured.
48171d10453SEric Joyner  * NOTE: The VF is not required to configure all queues in a single request.
48271d10453SEric Joyner  * It may send multiple messages. PF drivers must correctly handle all VF
48371d10453SEric Joyner  * requests.
48471d10453SEric Joyner  */
48571d10453SEric Joyner struct virtchnl_queue_pair_info {
48671d10453SEric Joyner 	/* NOTE: vsi_id and queue_id should be identical for both queues. */
48771d10453SEric Joyner 	struct virtchnl_txq_info txq;
48871d10453SEric Joyner 	struct virtchnl_rxq_info rxq;
48971d10453SEric Joyner };
49071d10453SEric Joyner 
49171d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
49271d10453SEric Joyner 
49371d10453SEric Joyner struct virtchnl_vsi_queue_config_info {
49471d10453SEric Joyner 	u16 vsi_id;
49571d10453SEric Joyner 	u16 num_queue_pairs;
49671d10453SEric Joyner 	u32 pad;
49771d10453SEric Joyner 	struct virtchnl_queue_pair_info qpair[1];
49871d10453SEric Joyner };
49971d10453SEric Joyner 
50071d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
50171d10453SEric Joyner 
50271d10453SEric Joyner /* VIRTCHNL_OP_REQUEST_QUEUES
50371d10453SEric Joyner  * VF sends this message to request the PF to allocate additional queues to
50471d10453SEric Joyner  * this VF.  Each VF gets a guaranteed number of queues on init but asking for
50571d10453SEric Joyner  * additional queues must be negotiated.  This is a best effort request as it
50671d10453SEric Joyner  * is possible the PF does not have enough queues left to support the request.
50771d10453SEric Joyner  * If the PF cannot support the number requested it will respond with the
50871d10453SEric Joyner  * maximum number it is able to support.  If the request is successful, PF will
50971d10453SEric Joyner  * then reset the VF to institute required changes.
51071d10453SEric Joyner  */
51171d10453SEric Joyner 
51271d10453SEric Joyner /* VF resource request */
51371d10453SEric Joyner struct virtchnl_vf_res_request {
51471d10453SEric Joyner 	u16 num_queue_pairs;
51571d10453SEric Joyner };
51671d10453SEric Joyner 
51771d10453SEric Joyner /* VIRTCHNL_OP_CONFIG_IRQ_MAP
51871d10453SEric Joyner  * VF uses this message to map vectors to queues.
51971d10453SEric Joyner  * The rxq_map and txq_map fields are bitmaps used to indicate which queues
52071d10453SEric Joyner  * are to be associated with the specified vector.
52171d10453SEric Joyner  * The "other" causes are always mapped to vector 0. The VF may not request
52271d10453SEric Joyner  * that vector 0 be used for traffic.
52371d10453SEric Joyner  * PF configures interrupt mapping and returns status.
52471d10453SEric Joyner  * NOTE: due to hardware requirements, all active queues (both TX and RX)
52571d10453SEric Joyner  * should be mapped to interrupts, even if the driver intends to operate
52671d10453SEric Joyner  * only in polling mode. In this case the interrupt may be disabled, but
52771d10453SEric Joyner  * the ITR timer will still run to trigger writebacks.
52871d10453SEric Joyner  */
52971d10453SEric Joyner struct virtchnl_vector_map {
53071d10453SEric Joyner 	u16 vsi_id;
53171d10453SEric Joyner 	u16 vector_id;
53271d10453SEric Joyner 	u16 rxq_map;
53371d10453SEric Joyner 	u16 txq_map;
53471d10453SEric Joyner 	u16 rxitr_idx;
53571d10453SEric Joyner 	u16 txitr_idx;
53671d10453SEric Joyner };
53771d10453SEric Joyner 
53871d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
53971d10453SEric Joyner 
54071d10453SEric Joyner struct virtchnl_irq_map_info {
54171d10453SEric Joyner 	u16 num_vectors;
54271d10453SEric Joyner 	struct virtchnl_vector_map vecmap[1];
54371d10453SEric Joyner };
54471d10453SEric Joyner 
54571d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
54671d10453SEric Joyner 
54771d10453SEric Joyner /* VIRTCHNL_OP_ENABLE_QUEUES
54871d10453SEric Joyner  * VIRTCHNL_OP_DISABLE_QUEUES
54971d10453SEric Joyner  * VF sends these message to enable or disable TX/RX queue pairs.
55071d10453SEric Joyner  * The queues fields are bitmaps indicating which queues to act upon.
55171d10453SEric Joyner  * (Currently, we only support 16 queues per VF, but we make the field
55271d10453SEric Joyner  * u32 to allow for expansion.)
55371d10453SEric Joyner  * PF performs requested action and returns status.
55471d10453SEric Joyner  * NOTE: The VF is not required to enable/disable all queues in a single
55571d10453SEric Joyner  * request. It may send multiple messages.
55671d10453SEric Joyner  * PF drivers must correctly handle all VF requests.
55771d10453SEric Joyner  */
55871d10453SEric Joyner struct virtchnl_queue_select {
55971d10453SEric Joyner 	u16 vsi_id;
56071d10453SEric Joyner 	u16 pad;
56171d10453SEric Joyner 	u32 rx_queues;
56271d10453SEric Joyner 	u32 tx_queues;
56371d10453SEric Joyner };
56471d10453SEric Joyner 
56571d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
56671d10453SEric Joyner 
567d08b8680SEric Joyner /* VIRTCHNL_OP_GET_MAX_RSS_QREGION
568d08b8680SEric Joyner  *
569d08b8680SEric Joyner  * if VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES
570d08b8680SEric Joyner  * then this op must be supported.
571d08b8680SEric Joyner  *
572d08b8680SEric Joyner  * VF sends this message in order to query the max RSS queue region
573d08b8680SEric Joyner  * size supported by PF, when VIRTCHNL_VF_LARGE_NUM_QPAIRS is enabled.
574d08b8680SEric Joyner  * This information should be used when configuring the RSS LUT and/or
575d08b8680SEric Joyner  * configuring queue region based filters.
576d08b8680SEric Joyner  *
577d08b8680SEric Joyner  * The maximum RSS queue region is 2^qregion_width. So, a qregion_width
578d08b8680SEric Joyner  * of 6 would inform the VF that the PF supports a maximum RSS queue region
579d08b8680SEric Joyner  * of 64.
580d08b8680SEric Joyner  *
581d08b8680SEric Joyner  * A queue region represents a range of queues that can be used to configure
582d08b8680SEric Joyner  * a RSS LUT. For example, if a VF is given 64 queues, but only a max queue
583d08b8680SEric Joyner  * region size of 16 (i.e. 2^qregion_width = 16) then it will only be able
584d08b8680SEric Joyner  * to configure the RSS LUT with queue indices from 0 to 15. However, other
585d08b8680SEric Joyner  * filters can be used to direct packets to queues >15 via specifying a queue
586d08b8680SEric Joyner  * base/offset and queue region width.
587d08b8680SEric Joyner  */
588d08b8680SEric Joyner struct virtchnl_max_rss_qregion {
589d08b8680SEric Joyner 	u16 vport_id;
590d08b8680SEric Joyner 	u16 qregion_width;
591d08b8680SEric Joyner 	u8 pad[4];
592d08b8680SEric Joyner };
593d08b8680SEric Joyner 
594d08b8680SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_max_rss_qregion);
595d08b8680SEric Joyner 
59671d10453SEric Joyner /* VIRTCHNL_OP_ADD_ETH_ADDR
59771d10453SEric Joyner  * VF sends this message in order to add one or more unicast or multicast
59871d10453SEric Joyner  * address filters for the specified VSI.
59971d10453SEric Joyner  * PF adds the filters and returns status.
60071d10453SEric Joyner  */
60171d10453SEric Joyner 
60271d10453SEric Joyner /* VIRTCHNL_OP_DEL_ETH_ADDR
60371d10453SEric Joyner  * VF sends this message in order to remove one or more unicast or multicast
60471d10453SEric Joyner  * filters for the specified VSI.
60571d10453SEric Joyner  * PF removes the filters and returns status.
60671d10453SEric Joyner  */
60771d10453SEric Joyner 
6087d7af7f8SEric Joyner /* VIRTCHNL_ETHER_ADDR_LEGACY
6097d7af7f8SEric Joyner  * Prior to adding the @type member to virtchnl_ether_addr, there were 2 pad
6107d7af7f8SEric Joyner  * bytes. Moving forward all VF drivers should not set type to
6117d7af7f8SEric Joyner  * VIRTCHNL_ETHER_ADDR_LEGACY. This is only here to not break previous/legacy
6127d7af7f8SEric Joyner  * behavior. The control plane function (i.e. PF) can use a best effort method
6137d7af7f8SEric Joyner  * of tracking the primary/device unicast in this case, but there is no
6147d7af7f8SEric Joyner  * guarantee and functionality depends on the implementation of the PF.
6157d7af7f8SEric Joyner  */
6167d7af7f8SEric Joyner 
6177d7af7f8SEric Joyner /* VIRTCHNL_ETHER_ADDR_PRIMARY
6187d7af7f8SEric Joyner  * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_PRIMARY for the
6197d7af7f8SEric Joyner  * primary/device unicast MAC address filter for VIRTCHNL_OP_ADD_ETH_ADDR and
6207d7af7f8SEric Joyner  * VIRTCHNL_OP_DEL_ETH_ADDR. This allows for the underlying control plane
6217d7af7f8SEric Joyner  * function (i.e. PF) to accurately track and use this MAC address for
6227d7af7f8SEric Joyner  * displaying on the host and for VM/function reset.
6237d7af7f8SEric Joyner  */
6247d7af7f8SEric Joyner 
6257d7af7f8SEric Joyner /* VIRTCHNL_ETHER_ADDR_EXTRA
6267d7af7f8SEric Joyner  * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_EXTRA for any extra
6277d7af7f8SEric Joyner  * unicast and/or multicast filters that are being added/deleted via
6287d7af7f8SEric Joyner  * VIRTCHNL_OP_DEL_ETH_ADDR/VIRTCHNL_OP_ADD_ETH_ADDR respectively.
6297d7af7f8SEric Joyner  */
63071d10453SEric Joyner struct virtchnl_ether_addr {
63171d10453SEric Joyner 	u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
6327d7af7f8SEric Joyner 	u8 type;
6337d7af7f8SEric Joyner #define VIRTCHNL_ETHER_ADDR_LEGACY	0
6347d7af7f8SEric Joyner #define VIRTCHNL_ETHER_ADDR_PRIMARY	1
6357d7af7f8SEric Joyner #define VIRTCHNL_ETHER_ADDR_EXTRA	2
6367d7af7f8SEric Joyner #define VIRTCHNL_ETHER_ADDR_TYPE_MASK	3 /* first two bits of type are valid */
6377d7af7f8SEric Joyner 	u8 pad;
63871d10453SEric Joyner };
63971d10453SEric Joyner 
64071d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
64171d10453SEric Joyner 
64271d10453SEric Joyner struct virtchnl_ether_addr_list {
64371d10453SEric Joyner 	u16 vsi_id;
64471d10453SEric Joyner 	u16 num_elements;
64571d10453SEric Joyner 	struct virtchnl_ether_addr list[1];
64671d10453SEric Joyner };
64771d10453SEric Joyner 
64871d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
64971d10453SEric Joyner 
65071d10453SEric Joyner /* VIRTCHNL_OP_ADD_VLAN
65171d10453SEric Joyner  * VF sends this message to add one or more VLAN tag filters for receives.
65271d10453SEric Joyner  * PF adds the filters and returns status.
65371d10453SEric Joyner  * If a port VLAN is configured by the PF, this operation will return an
65471d10453SEric Joyner  * error to the VF.
65571d10453SEric Joyner  */
65671d10453SEric Joyner 
65771d10453SEric Joyner /* VIRTCHNL_OP_DEL_VLAN
65871d10453SEric Joyner  * VF sends this message to remove one or more VLAN tag filters for receives.
65971d10453SEric Joyner  * PF removes the filters and returns status.
66071d10453SEric Joyner  * If a port VLAN is configured by the PF, this operation will return an
66171d10453SEric Joyner  * error to the VF.
66271d10453SEric Joyner  */
66371d10453SEric Joyner 
66471d10453SEric Joyner struct virtchnl_vlan_filter_list {
66571d10453SEric Joyner 	u16 vsi_id;
66671d10453SEric Joyner 	u16 num_elements;
66771d10453SEric Joyner 	u16 vlan_id[1];
66871d10453SEric Joyner };
66971d10453SEric Joyner 
67071d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
67171d10453SEric Joyner 
672*9cf1841cSEric Joyner /* This enum is used for all of the VIRTCHNL_VF_OFFLOAD_VLAN_V2_CAPS related
673*9cf1841cSEric Joyner  * structures and opcodes.
674*9cf1841cSEric Joyner  *
675*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_UNSUPPORTED - This field is not supported and if a VF driver
676*9cf1841cSEric Joyner  * populates it the PF should return VIRTCHNL_STATUS_ERR_NOT_SUPPORTED.
677*9cf1841cSEric Joyner  *
678*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_ETHERTYPE_8100 - This field supports 0x8100 ethertype.
679*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_ETHERTYPE_88A8 - This field supports 0x88A8 ethertype.
680*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_ETHERTYPE_9100 - This field supports 0x9100 ethertype.
681*9cf1841cSEric Joyner  *
682*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_ETHERTYPE_AND - Used when multiple ethertypes can be supported
683*9cf1841cSEric Joyner  * by the PF concurrently. For example, if the PF can support
684*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_ETHERTYPE_8100 AND VIRTCHNL_VLAN_ETHERTYPE_88A8 filters it
685*9cf1841cSEric Joyner  * would OR the following bits:
686*9cf1841cSEric Joyner  *
687*9cf1841cSEric Joyner  *	VIRTHCNL_VLAN_ETHERTYPE_8100 |
688*9cf1841cSEric Joyner  *	VIRTCHNL_VLAN_ETHERTYPE_88A8 |
689*9cf1841cSEric Joyner  *	VIRTCHNL_VLAN_ETHERTYPE_AND;
690*9cf1841cSEric Joyner  *
691*9cf1841cSEric Joyner  * The VF would interpret this as VLAN filtering can be supported on both 0x8100
692*9cf1841cSEric Joyner  * and 0x88A8 VLAN ethertypes.
693*9cf1841cSEric Joyner  *
694*9cf1841cSEric Joyner  * VIRTCHNL_ETHERTYPE_XOR - Used when only a single ethertype can be supported
695*9cf1841cSEric Joyner  * by the PF concurrently. For example if the PF can support
696*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_ETHERTYPE_8100 XOR VIRTCHNL_VLAN_ETHERTYPE_88A8 stripping
697*9cf1841cSEric Joyner  * offload it would OR the following bits:
698*9cf1841cSEric Joyner  *
699*9cf1841cSEric Joyner  *	VIRTCHNL_VLAN_ETHERTYPE_8100 |
700*9cf1841cSEric Joyner  *	VIRTCHNL_VLAN_ETHERTYPE_88A8 |
701*9cf1841cSEric Joyner  *	VIRTCHNL_VLAN_ETHERTYPE_XOR;
702*9cf1841cSEric Joyner  *
703*9cf1841cSEric Joyner  * The VF would interpret this as VLAN stripping can be supported on either
704*9cf1841cSEric Joyner  * 0x8100 or 0x88a8 VLAN ethertypes. So when requesting VLAN stripping via
705*9cf1841cSEric Joyner  * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 the specified ethertype will override
706*9cf1841cSEric Joyner  * the previously set value.
707*9cf1841cSEric Joyner  *
708*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 - Used to tell the VF to insert and/or
709*9cf1841cSEric Joyner  * strip the VLAN tag using the L2TAG1 field of the Tx/Rx descriptors.
710*9cf1841cSEric Joyner  *
711*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to insert hardware
712*9cf1841cSEric Joyner  * offloaded VLAN tags using the L2TAG2 field of the Tx descriptor.
713*9cf1841cSEric Joyner  *
714*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to strip hardware
715*9cf1841cSEric Joyner  * offloaded VLAN tags using the L2TAG2_2 field of the Rx descriptor.
716*9cf1841cSEric Joyner  *
717*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_PRIO - This field supports VLAN priority bits. This is used for
718*9cf1841cSEric Joyner  * VLAN filtering if the underlying PF supports it.
719*9cf1841cSEric Joyner  *
720*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_TOGGLE_ALLOWED - This field is used to say whether a
721*9cf1841cSEric Joyner  * certain VLAN capability can be toggled. For example if the underlying PF/CP
722*9cf1841cSEric Joyner  * allows the VF to toggle VLAN filtering, stripping, and/or insertion it should
723*9cf1841cSEric Joyner  * set this bit along with the supported ethertypes.
724*9cf1841cSEric Joyner  */
725*9cf1841cSEric Joyner enum virtchnl_vlan_support {
726*9cf1841cSEric Joyner 	VIRTCHNL_VLAN_UNSUPPORTED =		0,
727*9cf1841cSEric Joyner 	VIRTCHNL_VLAN_ETHERTYPE_8100 =		0x00000001,
728*9cf1841cSEric Joyner 	VIRTCHNL_VLAN_ETHERTYPE_88A8 =		0x00000002,
729*9cf1841cSEric Joyner 	VIRTCHNL_VLAN_ETHERTYPE_9100 =		0x00000004,
730*9cf1841cSEric Joyner 	VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 =	0x00000100,
731*9cf1841cSEric Joyner 	VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 =	0x00000200,
732*9cf1841cSEric Joyner 	VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 =	0x00000400,
733*9cf1841cSEric Joyner 	VIRTCHNL_VLAN_PRIO =			0x01000000,
734*9cf1841cSEric Joyner 	VIRTCHNL_VLAN_FILTER_MASK =		0x10000000,
735*9cf1841cSEric Joyner 	VIRTCHNL_VLAN_ETHERTYPE_AND =		0x20000000,
736*9cf1841cSEric Joyner 	VIRTCHNL_VLAN_ETHERTYPE_XOR =		0x40000000,
737*9cf1841cSEric Joyner 	VIRTCHNL_VLAN_TOGGLE =			0x80000000
738*9cf1841cSEric Joyner };
739*9cf1841cSEric Joyner 
740*9cf1841cSEric Joyner /* This structure is used as part of the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
741*9cf1841cSEric Joyner  * for filtering, insertion, and stripping capabilities.
742*9cf1841cSEric Joyner  *
743*9cf1841cSEric Joyner  * If only outer capabilities are supported (for filtering, insertion, and/or
744*9cf1841cSEric Joyner  * stripping) then this refers to the outer most or single VLAN from the VF's
745*9cf1841cSEric Joyner  * perspective.
746*9cf1841cSEric Joyner  *
747*9cf1841cSEric Joyner  * If only inner capabilities are supported (for filtering, insertion, and/or
748*9cf1841cSEric Joyner  * stripping) then this refers to the outer most or single VLAN from the VF's
749*9cf1841cSEric Joyner  * perspective. Functionally this is the same as if only outer capabilities are
750*9cf1841cSEric Joyner  * supported. The VF driver is just forced to use the inner fields when
751*9cf1841cSEric Joyner  * adding/deleting filters and enabling/disabling offloads (if supported).
752*9cf1841cSEric Joyner  *
753*9cf1841cSEric Joyner  * If both outer and inner capabilities are supported (for filtering, insertion,
754*9cf1841cSEric Joyner  * and/or stripping) then outer refers to the outer most or single VLAN and
755*9cf1841cSEric Joyner  * inner refers to the second VLAN, if it exists, in the packet.
756*9cf1841cSEric Joyner  *
757*9cf1841cSEric Joyner  * There is no support for tunneled VLAN offloads, so outer or inner are never
758*9cf1841cSEric Joyner  * referring to a tunneled packet from the VF's perspective.
759*9cf1841cSEric Joyner  */
760*9cf1841cSEric Joyner struct virtchnl_vlan_supported_caps {
761*9cf1841cSEric Joyner 	u32 outer;
762*9cf1841cSEric Joyner 	u32 inner;
763*9cf1841cSEric Joyner };
764*9cf1841cSEric Joyner 
765*9cf1841cSEric Joyner /* The PF populates these fields based on the supported VLAN filtering. If a
766*9cf1841cSEric Joyner  * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
767*9cf1841cSEric Joyner  * reject any VIRTCHNL_OP_ADD_VLAN_V2 or VIRTCHNL_OP_DEL_VLAN_V2 messages using
768*9cf1841cSEric Joyner  * the unsupported fields.
769*9cf1841cSEric Joyner  *
770*9cf1841cSEric Joyner  * Also, a VF is only allowed to toggle its VLAN filtering setting if the
771*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_TOGGLE bit is set.
772*9cf1841cSEric Joyner  *
773*9cf1841cSEric Joyner  * The ethertype(s) specified in the ethertype_init field are the ethertypes
774*9cf1841cSEric Joyner  * enabled for VLAN filtering. VLAN filtering in this case refers to the outer
775*9cf1841cSEric Joyner  * most VLAN from the VF's perspective. If both inner and outer filtering are
776*9cf1841cSEric Joyner  * allowed then ethertype_init only refers to the outer most VLAN as only
777*9cf1841cSEric Joyner  * VLAN ethertype supported for inner VLAN filtering is
778*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_ETHERTYPE_8100. By default, inner VLAN filtering is disabled
779*9cf1841cSEric Joyner  * when both inner and outer filtering are allowed.
780*9cf1841cSEric Joyner  *
781*9cf1841cSEric Joyner  * The max_filters field tells the VF how many VLAN filters it's allowed to have
782*9cf1841cSEric Joyner  * at any one time. If it exceeds this amount and tries to add another filter,
783*9cf1841cSEric Joyner  * then the request will be rejected by the PF. To prevent failures, the VF
784*9cf1841cSEric Joyner  * should keep track of how many VLAN filters it has added and not attempt to
785*9cf1841cSEric Joyner  * add more than max_filters.
786*9cf1841cSEric Joyner  */
787*9cf1841cSEric Joyner struct virtchnl_vlan_filtering_caps {
788*9cf1841cSEric Joyner 	struct virtchnl_vlan_supported_caps filtering_support;
789*9cf1841cSEric Joyner 	u32 ethertype_init;
790*9cf1841cSEric Joyner 	u16 max_filters;
791*9cf1841cSEric Joyner 	u8 pad[2];
792*9cf1841cSEric Joyner };
793*9cf1841cSEric Joyner 
794*9cf1841cSEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_filtering_caps);
795*9cf1841cSEric Joyner 
796*9cf1841cSEric Joyner /* This enum is used for the virtchnl_vlan_offload_caps structure to specify
797*9cf1841cSEric Joyner  * if the PF supports a different ethertype for stripping and insertion.
798*9cf1841cSEric Joyner  *
799*9cf1841cSEric Joyner  * VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION - The ethertype(s) specified
800*9cf1841cSEric Joyner  * for stripping affect the ethertype(s) specified for insertion and visa versa
801*9cf1841cSEric Joyner  * as well. If the VF tries to configure VLAN stripping via
802*9cf1841cSEric Joyner  * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 with VIRTCHNL_VLAN_ETHERTYPE_8100 then
803*9cf1841cSEric Joyner  * that will be the ethertype for both stripping and insertion.
804*9cf1841cSEric Joyner  *
805*9cf1841cSEric Joyner  * VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED - The ethertype(s) specified for
806*9cf1841cSEric Joyner  * stripping do not affect the ethertype(s) specified for insertion and visa
807*9cf1841cSEric Joyner  * versa.
808*9cf1841cSEric Joyner  */
809*9cf1841cSEric Joyner enum virtchnl_vlan_ethertype_match {
810*9cf1841cSEric Joyner 	VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION = 0,
811*9cf1841cSEric Joyner 	VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED = 1,
812*9cf1841cSEric Joyner };
813*9cf1841cSEric Joyner 
814*9cf1841cSEric Joyner /* The PF populates these fields based on the supported VLAN offloads. If a
815*9cf1841cSEric Joyner  * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
816*9cf1841cSEric Joyner  * reject any VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 or
817*9cf1841cSEric Joyner  * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 messages using the unsupported fields.
818*9cf1841cSEric Joyner  *
819*9cf1841cSEric Joyner  * Also, a VF is only allowed to toggle its VLAN offload setting if the
820*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_TOGGLE_ALLOWED bit is set.
821*9cf1841cSEric Joyner  *
822*9cf1841cSEric Joyner  * The VF driver needs to be aware of how the tags are stripped by hardware and
823*9cf1841cSEric Joyner  * inserted by the VF driver based on the level of offload support. The PF will
824*9cf1841cSEric Joyner  * populate these fields based on where the VLAN tags are expected to be
825*9cf1841cSEric Joyner  * offloaded via the VIRTHCNL_VLAN_TAG_LOCATION_* bits. The VF will need to
826*9cf1841cSEric Joyner  * interpret these fields. See the definition of the
827*9cf1841cSEric Joyner  * VIRTCHNL_VLAN_TAG_LOCATION_* bits above the virtchnl_vlan_support
828*9cf1841cSEric Joyner  * enumeration.
829*9cf1841cSEric Joyner  */
830*9cf1841cSEric Joyner struct virtchnl_vlan_offload_caps {
831*9cf1841cSEric Joyner 	struct virtchnl_vlan_supported_caps stripping_support;
832*9cf1841cSEric Joyner 	struct virtchnl_vlan_supported_caps insertion_support;
833*9cf1841cSEric Joyner 	u32 ethertype_init;
834*9cf1841cSEric Joyner 	u8 ethertype_match;
835*9cf1841cSEric Joyner 	u8 pad[3];
836*9cf1841cSEric Joyner };
837*9cf1841cSEric Joyner 
838*9cf1841cSEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_vlan_offload_caps);
839*9cf1841cSEric Joyner 
840*9cf1841cSEric Joyner /* VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
841*9cf1841cSEric Joyner  * VF sends this message to determine its VLAN capabilities.
842*9cf1841cSEric Joyner  *
843*9cf1841cSEric Joyner  * PF will mark which capabilities it supports based on hardware support and
844*9cf1841cSEric Joyner  * current configuration. For example, if a port VLAN is configured the PF will
845*9cf1841cSEric Joyner  * not allow outer VLAN filtering, stripping, or insertion to be configured so
846*9cf1841cSEric Joyner  * it will block these features from the VF.
847*9cf1841cSEric Joyner  *
848*9cf1841cSEric Joyner  * The VF will need to cross reference its capabilities with the PFs
849*9cf1841cSEric Joyner  * capabilities in the response message from the PF to determine the VLAN
850*9cf1841cSEric Joyner  * support.
851*9cf1841cSEric Joyner  */
852*9cf1841cSEric Joyner struct virtchnl_vlan_caps {
853*9cf1841cSEric Joyner 	struct virtchnl_vlan_filtering_caps filtering;
854*9cf1841cSEric Joyner 	struct virtchnl_vlan_offload_caps offloads;
855*9cf1841cSEric Joyner };
856*9cf1841cSEric Joyner 
857*9cf1841cSEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_caps);
858*9cf1841cSEric Joyner 
859*9cf1841cSEric Joyner struct virtchnl_vlan {
860*9cf1841cSEric Joyner 	u16 tci;	/* tci[15:13] = PCP and tci[11:0] = VID */
861*9cf1841cSEric Joyner 	u16 tci_mask;	/* only valid if VIRTCHNL_VLAN_FILTER_MASK set in
862*9cf1841cSEric Joyner 			 * filtering caps
863*9cf1841cSEric Joyner 			 */
864*9cf1841cSEric Joyner 	u16 tpid;	/* 0x8100, 0x88a8, etc. and only type(s) set in
865*9cf1841cSEric Joyner 			 * filtering caps. Note that tpid here does not refer to
866*9cf1841cSEric Joyner 			 * VIRTCHNL_VLAN_ETHERTYPE_*, but it refers to the
867*9cf1841cSEric Joyner 			 * actual 2-byte VLAN TPID
868*9cf1841cSEric Joyner 			 */
869*9cf1841cSEric Joyner 	u8 pad[2];
870*9cf1841cSEric Joyner };
871*9cf1841cSEric Joyner 
872*9cf1841cSEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_vlan);
873*9cf1841cSEric Joyner 
874*9cf1841cSEric Joyner struct virtchnl_vlan_filter {
875*9cf1841cSEric Joyner 	struct virtchnl_vlan inner;
876*9cf1841cSEric Joyner 	struct virtchnl_vlan outer;
877*9cf1841cSEric Joyner 	u8 pad[16];
878*9cf1841cSEric Joyner };
879*9cf1841cSEric Joyner 
880*9cf1841cSEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(32, virtchnl_vlan_filter);
881*9cf1841cSEric Joyner 
882*9cf1841cSEric Joyner /* VIRTCHNL_OP_ADD_VLAN_V2
883*9cf1841cSEric Joyner  * VIRTCHNL_OP_DEL_VLAN_V2
884*9cf1841cSEric Joyner  *
885*9cf1841cSEric Joyner  * VF sends these messages to add/del one or more VLAN tag filters for Rx
886*9cf1841cSEric Joyner  * traffic.
887*9cf1841cSEric Joyner  *
888*9cf1841cSEric Joyner  * The PF attempts to add the filters and returns status.
889*9cf1841cSEric Joyner  *
890*9cf1841cSEric Joyner  * The VF should only ever attempt to add/del virtchnl_vlan_filter(s) using the
891*9cf1841cSEric Joyner  * supported fields negotiated via VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS.
892*9cf1841cSEric Joyner  */
893*9cf1841cSEric Joyner struct virtchnl_vlan_filter_list_v2 {
894*9cf1841cSEric Joyner 	u16 vport_id;
895*9cf1841cSEric Joyner 	u16 num_elements;
896*9cf1841cSEric Joyner 	u8 pad[4];
897*9cf1841cSEric Joyner 	struct virtchnl_vlan_filter filters[1];
898*9cf1841cSEric Joyner };
899*9cf1841cSEric Joyner 
900*9cf1841cSEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_filter_list_v2);
901*9cf1841cSEric Joyner 
902*9cf1841cSEric Joyner /* VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2
903*9cf1841cSEric Joyner  * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2
904*9cf1841cSEric Joyner  * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2
905*9cf1841cSEric Joyner  * VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2
906*9cf1841cSEric Joyner  *
907*9cf1841cSEric Joyner  * VF sends this message to enable or disable VLAN stripping or insertion. It
908*9cf1841cSEric Joyner  * also needs to specify an ethertype. The VF knows which VLAN ethertypes are
909*9cf1841cSEric Joyner  * allowed and whether or not it's allowed to enable/disable the specific
910*9cf1841cSEric Joyner  * offload via the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. The VF needs to
911*9cf1841cSEric Joyner  * parse the virtchnl_vlan_caps.offloads fields to determine which offload
912*9cf1841cSEric Joyner  * messages are allowed.
913*9cf1841cSEric Joyner  *
914*9cf1841cSEric Joyner  * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
915*9cf1841cSEric Joyner  * following manner the VF will be allowed to enable and/or disable 0x8100 inner
916*9cf1841cSEric Joyner  * VLAN insertion and/or stripping via the opcodes listed above. Inner in this
917*9cf1841cSEric Joyner  * case means the outer most or single VLAN from the VF's perspective. This is
918*9cf1841cSEric Joyner  * because no outer offloads are supported. See the comments above the
919*9cf1841cSEric Joyner  * virtchnl_vlan_supported_caps structure for more details.
920*9cf1841cSEric Joyner  *
921*9cf1841cSEric Joyner  * virtchnl_vlan_caps.offloads.stripping_support.inner =
922*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_TOGGLE |
923*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_8100;
924*9cf1841cSEric Joyner  *
925*9cf1841cSEric Joyner  * virtchnl_vlan_caps.offloads.insertion_support.inner =
926*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_TOGGLE |
927*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_8100;
928*9cf1841cSEric Joyner  *
929*9cf1841cSEric Joyner  * In order to enable inner (again note that in this case inner is the outer
930*9cf1841cSEric Joyner  * most or single VLAN from the VF's perspective) VLAN stripping for 0x8100
931*9cf1841cSEric Joyner  * VLANs, the VF would populate the virtchnl_vlan_setting structure in the
932*9cf1841cSEric Joyner  * following manner and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
933*9cf1841cSEric Joyner  *
934*9cf1841cSEric Joyner  * virtchnl_vlan_setting.inner_ethertype_setting =
935*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_8100;
936*9cf1841cSEric Joyner  *
937*9cf1841cSEric Joyner  * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
938*9cf1841cSEric Joyner  * initialization.
939*9cf1841cSEric Joyner  *
940*9cf1841cSEric Joyner  * The reason that VLAN TPID(s) are not being used for the
941*9cf1841cSEric Joyner  * outer_ethertype_setting and inner_ethertype_setting fields is because it's
942*9cf1841cSEric Joyner  * possible a device could support VLAN insertion and/or stripping offload on
943*9cf1841cSEric Joyner  * multiple ethertypes concurrently, so this method allows a VF to request
944*9cf1841cSEric Joyner  * multiple ethertypes in one message using the virtchnl_vlan_support
945*9cf1841cSEric Joyner  * enumeration.
946*9cf1841cSEric Joyner  *
947*9cf1841cSEric Joyner  * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
948*9cf1841cSEric Joyner  * following manner the VF will be allowed to enable 0x8100 and 0x88a8 outer
949*9cf1841cSEric Joyner  * VLAN insertion and stripping simultaneously. The
950*9cf1841cSEric Joyner  * virtchnl_vlan_caps.offloads.ethertype_match field will also have to be
951*9cf1841cSEric Joyner  * populated based on what the PF can support.
952*9cf1841cSEric Joyner  *
953*9cf1841cSEric Joyner  * virtchnl_vlan_caps.offloads.stripping_support.outer =
954*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_TOGGLE |
955*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
956*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
957*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_AND;
958*9cf1841cSEric Joyner  *
959*9cf1841cSEric Joyner  * virtchnl_vlan_caps.offloads.insertion_support.outer =
960*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_TOGGLE |
961*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
962*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
963*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_AND;
964*9cf1841cSEric Joyner  *
965*9cf1841cSEric Joyner  * In order to enable outer VLAN stripping for 0x8100 and 0x88a8 VLANs, the VF
966*9cf1841cSEric Joyner  * would populate the virthcnl_vlan_offload_structure in the following manner
967*9cf1841cSEric Joyner  * and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
968*9cf1841cSEric Joyner  *
969*9cf1841cSEric Joyner  * virtchnl_vlan_setting.outer_ethertype_setting =
970*9cf1841cSEric Joyner  *			VIRTHCNL_VLAN_ETHERTYPE_8100 |
971*9cf1841cSEric Joyner  *			VIRTHCNL_VLAN_ETHERTYPE_88A8;
972*9cf1841cSEric Joyner  *
973*9cf1841cSEric Joyner  * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
974*9cf1841cSEric Joyner  * initialization.
975*9cf1841cSEric Joyner  *
976*9cf1841cSEric Joyner  * There is also the case where a PF and the underlying hardware can support
977*9cf1841cSEric Joyner  * VLAN offloads on multiple ethertypes, but not concurrently. For example, if
978*9cf1841cSEric Joyner  * the PF populates the virtchnl_vlan_caps.offloads in the following manner the
979*9cf1841cSEric Joyner  * VF will be allowed to enable and/or disable 0x8100 XOR 0x88a8 outer VLAN
980*9cf1841cSEric Joyner  * offloads. The ethertypes must match for stripping and insertion.
981*9cf1841cSEric Joyner  *
982*9cf1841cSEric Joyner  * virtchnl_vlan_caps.offloads.stripping_support.outer =
983*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_TOGGLE |
984*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
985*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
986*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_XOR;
987*9cf1841cSEric Joyner  *
988*9cf1841cSEric Joyner  * virtchnl_vlan_caps.offloads.insertion_support.outer =
989*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_TOGGLE |
990*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
991*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
992*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_XOR;
993*9cf1841cSEric Joyner  *
994*9cf1841cSEric Joyner  * virtchnl_vlan_caps.offloads.ethertype_match =
995*9cf1841cSEric Joyner  *			VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
996*9cf1841cSEric Joyner  *
997*9cf1841cSEric Joyner  * In order to enable outer VLAN stripping for 0x88a8 VLANs, the VF would
998*9cf1841cSEric Joyner  * populate the virtchnl_vlan_setting structure in the following manner and send
999*9cf1841cSEric Joyner  * the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2. Also, this will change the
1000*9cf1841cSEric Joyner  * ethertype for VLAN insertion if it's enabled. So, for completeness, a
1001*9cf1841cSEric Joyner  * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 with the same ethertype should be sent.
1002*9cf1841cSEric Joyner  *
1003*9cf1841cSEric Joyner  * virtchnl_vlan_setting.outer_ethertype_setting = VIRTHCNL_VLAN_ETHERTYPE_88A8;
1004*9cf1841cSEric Joyner  *
1005*9cf1841cSEric Joyner  * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
1006*9cf1841cSEric Joyner  * initialization.
1007*9cf1841cSEric Joyner  *
1008*9cf1841cSEric Joyner  * VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2
1009*9cf1841cSEric Joyner  * VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2
1010*9cf1841cSEric Joyner  *
1011*9cf1841cSEric Joyner  * VF sends this message to enable or disable VLAN filtering. It also needs to
1012*9cf1841cSEric Joyner  * specify an ethertype. The VF knows which VLAN ethertypes are allowed and
1013*9cf1841cSEric Joyner  * whether or not it's allowed to enable/disable filtering via the
1014*9cf1841cSEric Joyner  * VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. The VF needs to
1015*9cf1841cSEric Joyner  * parse the virtchnl_vlan_caps.filtering fields to determine which, if any,
1016*9cf1841cSEric Joyner  * filtering messages are allowed.
1017*9cf1841cSEric Joyner  *
1018*9cf1841cSEric Joyner  * For example, if the PF populates the virtchnl_vlan_caps.filtering in the
1019*9cf1841cSEric Joyner  * following manner the VF will be allowed to enable/disable 0x8100 and 0x88a8
1020*9cf1841cSEric Joyner  * outer VLAN filtering together. Note, that the VIRTCHNL_VLAN_ETHERTYPE_AND
1021*9cf1841cSEric Joyner  * means that all filtering ethertypes will to be enabled and disabled together
1022*9cf1841cSEric Joyner  * regardless of the request from the VF. This means that the underlying
1023*9cf1841cSEric Joyner  * hardware only supports VLAN filtering for all VLAN the specified ethertypes
1024*9cf1841cSEric Joyner  * or none of them.
1025*9cf1841cSEric Joyner  *
1026*9cf1841cSEric Joyner  * virtchnl_vlan_caps.filtering.filtering_support.outer =
1027*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_TOGGLE |
1028*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
1029*9cf1841cSEric Joyner  *			VIRTHCNL_VLAN_ETHERTYPE_88A8 |
1030*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_9100 |
1031*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_AND;
1032*9cf1841cSEric Joyner  *
1033*9cf1841cSEric Joyner  * In order to enable outer VLAN filtering for 0x88a8 and 0x8100 VLANs (0x9100
1034*9cf1841cSEric Joyner  * VLANs aren't supported by the VF driver), the VF would populate the
1035*9cf1841cSEric Joyner  * virtchnl_vlan_setting structure in the following manner and send the
1036*9cf1841cSEric Joyner  * VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2. The same message format would be used
1037*9cf1841cSEric Joyner  * to disable outer VLAN filtering for 0x88a8 and 0x8100 VLANs, but the
1038*9cf1841cSEric Joyner  * VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 opcode is used.
1039*9cf1841cSEric Joyner  *
1040*9cf1841cSEric Joyner  * virtchnl_vlan_setting.outer_ethertype_setting =
1041*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
1042*9cf1841cSEric Joyner  *			VIRTCHNL_VLAN_ETHERTYPE_88A8;
1043*9cf1841cSEric Joyner  *
1044*9cf1841cSEric Joyner  */
1045*9cf1841cSEric Joyner struct virtchnl_vlan_setting {
1046*9cf1841cSEric Joyner 	u32 outer_ethertype_setting;
1047*9cf1841cSEric Joyner 	u32 inner_ethertype_setting;
1048*9cf1841cSEric Joyner 	u16 vport_id;
1049*9cf1841cSEric Joyner 	u8 pad[6];
1050*9cf1841cSEric Joyner };
1051*9cf1841cSEric Joyner 
1052*9cf1841cSEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_setting);
1053*9cf1841cSEric Joyner 
105471d10453SEric Joyner /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
105571d10453SEric Joyner  * VF sends VSI id and flags.
105671d10453SEric Joyner  * PF returns status code in retval.
105771d10453SEric Joyner  * Note: we assume that broadcast accept mode is always enabled.
105871d10453SEric Joyner  */
105971d10453SEric Joyner struct virtchnl_promisc_info {
106071d10453SEric Joyner 	u16 vsi_id;
106171d10453SEric Joyner 	u16 flags;
106271d10453SEric Joyner };
106371d10453SEric Joyner 
106471d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
106571d10453SEric Joyner 
106671d10453SEric Joyner #define FLAG_VF_UNICAST_PROMISC	0x00000001
106771d10453SEric Joyner #define FLAG_VF_MULTICAST_PROMISC	0x00000002
106871d10453SEric Joyner 
106971d10453SEric Joyner /* VIRTCHNL_OP_GET_STATS
107071d10453SEric Joyner  * VF sends this message to request stats for the selected VSI. VF uses
107171d10453SEric Joyner  * the virtchnl_queue_select struct to specify the VSI. The queue_id
107271d10453SEric Joyner  * field is ignored by the PF.
107371d10453SEric Joyner  *
107471d10453SEric Joyner  * PF replies with struct virtchnl_eth_stats in an external buffer.
107571d10453SEric Joyner  */
107671d10453SEric Joyner 
107771d10453SEric Joyner struct virtchnl_eth_stats {
107871d10453SEric Joyner 	u64 rx_bytes;			/* received bytes */
107971d10453SEric Joyner 	u64 rx_unicast;			/* received unicast pkts */
108071d10453SEric Joyner 	u64 rx_multicast;		/* received multicast pkts */
108171d10453SEric Joyner 	u64 rx_broadcast;		/* received broadcast pkts */
108271d10453SEric Joyner 	u64 rx_discards;
108371d10453SEric Joyner 	u64 rx_unknown_protocol;
108471d10453SEric Joyner 	u64 tx_bytes;			/* transmitted bytes */
108571d10453SEric Joyner 	u64 tx_unicast;			/* transmitted unicast pkts */
108671d10453SEric Joyner 	u64 tx_multicast;		/* transmitted multicast pkts */
108771d10453SEric Joyner 	u64 tx_broadcast;		/* transmitted broadcast pkts */
108871d10453SEric Joyner 	u64 tx_discards;
108971d10453SEric Joyner 	u64 tx_errors;
109071d10453SEric Joyner };
109171d10453SEric Joyner 
109271d10453SEric Joyner /* VIRTCHNL_OP_CONFIG_RSS_KEY
109371d10453SEric Joyner  * VIRTCHNL_OP_CONFIG_RSS_LUT
109471d10453SEric Joyner  * VF sends these messages to configure RSS. Only supported if both PF
109571d10453SEric Joyner  * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
109671d10453SEric Joyner  * configuration negotiation. If this is the case, then the RSS fields in
109771d10453SEric Joyner  * the VF resource struct are valid.
109871d10453SEric Joyner  * Both the key and LUT are initialized to 0 by the PF, meaning that
109971d10453SEric Joyner  * RSS is effectively disabled until set up by the VF.
110071d10453SEric Joyner  */
110171d10453SEric Joyner struct virtchnl_rss_key {
110271d10453SEric Joyner 	u16 vsi_id;
110371d10453SEric Joyner 	u16 key_len;
110471d10453SEric Joyner 	u8 key[1];         /* RSS hash key, packed bytes */
110571d10453SEric Joyner };
110671d10453SEric Joyner 
110771d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
110871d10453SEric Joyner 
110971d10453SEric Joyner struct virtchnl_rss_lut {
111071d10453SEric Joyner 	u16 vsi_id;
111171d10453SEric Joyner 	u16 lut_entries;
111271d10453SEric Joyner 	u8 lut[1];        /* RSS lookup table */
111371d10453SEric Joyner };
111471d10453SEric Joyner 
111571d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
111671d10453SEric Joyner 
111771d10453SEric Joyner /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
111871d10453SEric Joyner  * VIRTCHNL_OP_SET_RSS_HENA
111971d10453SEric Joyner  * VF sends these messages to get and set the hash filter enable bits for RSS.
112071d10453SEric Joyner  * By default, the PF sets these to all possible traffic types that the
112171d10453SEric Joyner  * hardware supports. The VF can query this value if it wants to change the
112271d10453SEric Joyner  * traffic types that are hashed by the hardware.
112371d10453SEric Joyner  */
112471d10453SEric Joyner struct virtchnl_rss_hena {
112571d10453SEric Joyner 	u64 hena;
112671d10453SEric Joyner };
112771d10453SEric Joyner 
112871d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
112971d10453SEric Joyner 
113071d10453SEric Joyner /* This is used by PF driver to enforce how many channels can be supported.
113171d10453SEric Joyner  * When ADQ_V2 capability is negotiated, it will allow 16 channels otherwise
113271d10453SEric Joyner  * PF driver will allow only max 4 channels
113371d10453SEric Joyner  */
113471d10453SEric Joyner #define VIRTCHNL_MAX_ADQ_CHANNELS 4
113571d10453SEric Joyner #define VIRTCHNL_MAX_ADQ_V2_CHANNELS 16
113671d10453SEric Joyner 
113771d10453SEric Joyner /* VIRTCHNL_OP_ENABLE_CHANNELS
113871d10453SEric Joyner  * VIRTCHNL_OP_DISABLE_CHANNELS
113971d10453SEric Joyner  * VF sends these messages to enable or disable channels based on
114071d10453SEric Joyner  * the user specified queue count and queue offset for each traffic class.
114171d10453SEric Joyner  * This struct encompasses all the information that the PF needs from
114271d10453SEric Joyner  * VF to create a channel.
114371d10453SEric Joyner  */
114471d10453SEric Joyner struct virtchnl_channel_info {
114571d10453SEric Joyner 	u16 count; /* number of queues in a channel */
114671d10453SEric Joyner 	u16 offset; /* queues in a channel start from 'offset' */
114771d10453SEric Joyner 	u32 pad;
114871d10453SEric Joyner 	u64 max_tx_rate;
114971d10453SEric Joyner };
115071d10453SEric Joyner 
115171d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info);
115271d10453SEric Joyner 
115371d10453SEric Joyner struct virtchnl_tc_info {
115471d10453SEric Joyner 	u32	num_tc;
115571d10453SEric Joyner 	u32	pad;
115671d10453SEric Joyner 	struct	virtchnl_channel_info list[1];
115771d10453SEric Joyner };
115871d10453SEric Joyner 
115971d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info);
116071d10453SEric Joyner 
116171d10453SEric Joyner /* VIRTCHNL_ADD_CLOUD_FILTER
116271d10453SEric Joyner  * VIRTCHNL_DEL_CLOUD_FILTER
116371d10453SEric Joyner  * VF sends these messages to add or delete a cloud filter based on the
116471d10453SEric Joyner  * user specified match and action filters. These structures encompass
116571d10453SEric Joyner  * all the information that the PF needs from the VF to add/delete a
116671d10453SEric Joyner  * cloud filter.
116771d10453SEric Joyner  */
116871d10453SEric Joyner 
116971d10453SEric Joyner struct virtchnl_l4_spec {
1170d08b8680SEric Joyner 	u8	src_mac[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
1171d08b8680SEric Joyner 	u8	dst_mac[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
117271d10453SEric Joyner 	/* vlan_prio is part of this 16 bit field even from OS perspective
117371d10453SEric Joyner 	 * vlan_id:12 is actual vlan_id, then vlanid:bit14..12 is vlan_prio
117471d10453SEric Joyner 	 * in future, when decided to offload vlan_prio, pass that information
117571d10453SEric Joyner 	 * as part of the "vlan_id" field, Bit14..12
117671d10453SEric Joyner 	 */
117771d10453SEric Joyner 	__be16	vlan_id;
117871d10453SEric Joyner 	__be16	pad; /* reserved for future use */
117971d10453SEric Joyner 	__be32	src_ip[4];
118071d10453SEric Joyner 	__be32	dst_ip[4];
118171d10453SEric Joyner 	__be16	src_port;
118271d10453SEric Joyner 	__be16	dst_port;
118371d10453SEric Joyner };
118471d10453SEric Joyner 
118571d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec);
118671d10453SEric Joyner 
118771d10453SEric Joyner union virtchnl_flow_spec {
118871d10453SEric Joyner 	struct	virtchnl_l4_spec tcp_spec;
118971d10453SEric Joyner 	u8	buffer[128]; /* reserved for future use */
119071d10453SEric Joyner };
119171d10453SEric Joyner 
119271d10453SEric Joyner VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec);
119371d10453SEric Joyner 
119471d10453SEric Joyner enum virtchnl_action {
119571d10453SEric Joyner 	/* action types */
119671d10453SEric Joyner 	VIRTCHNL_ACTION_DROP = 0,
119771d10453SEric Joyner 	VIRTCHNL_ACTION_TC_REDIRECT,
11987d7af7f8SEric Joyner 	VIRTCHNL_ACTION_PASSTHRU,
11997d7af7f8SEric Joyner 	VIRTCHNL_ACTION_QUEUE,
12007d7af7f8SEric Joyner 	VIRTCHNL_ACTION_Q_REGION,
12017d7af7f8SEric Joyner 	VIRTCHNL_ACTION_MARK,
12027d7af7f8SEric Joyner 	VIRTCHNL_ACTION_COUNT,
120371d10453SEric Joyner };
120471d10453SEric Joyner 
120571d10453SEric Joyner enum virtchnl_flow_type {
120671d10453SEric Joyner 	/* flow types */
120771d10453SEric Joyner 	VIRTCHNL_TCP_V4_FLOW = 0,
120871d10453SEric Joyner 	VIRTCHNL_TCP_V6_FLOW,
120971d10453SEric Joyner 	VIRTCHNL_UDP_V4_FLOW,
121071d10453SEric Joyner 	VIRTCHNL_UDP_V6_FLOW,
121171d10453SEric Joyner };
121271d10453SEric Joyner 
121371d10453SEric Joyner struct virtchnl_filter {
121471d10453SEric Joyner 	union	virtchnl_flow_spec data;
121571d10453SEric Joyner 	union	virtchnl_flow_spec mask;
1216*9cf1841cSEric Joyner 
1217*9cf1841cSEric Joyner 	/* see enum virtchnl_flow_type */
1218*9cf1841cSEric Joyner 	s32 	flow_type;
1219*9cf1841cSEric Joyner 
1220*9cf1841cSEric Joyner 	/* see enum virtchnl_action */
1221*9cf1841cSEric Joyner 	s32	action;
122271d10453SEric Joyner 	u32	action_meta;
122371d10453SEric Joyner 	u8	field_flags;
122471d10453SEric Joyner };
122571d10453SEric Joyner 
122671d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter);
122771d10453SEric Joyner 
122871d10453SEric Joyner /* VIRTCHNL_OP_EVENT
122971d10453SEric Joyner  * PF sends this message to inform the VF driver of events that may affect it.
123071d10453SEric Joyner  * No direct response is expected from the VF, though it may generate other
123171d10453SEric Joyner  * messages in response to this one.
123271d10453SEric Joyner  */
123371d10453SEric Joyner enum virtchnl_event_codes {
123471d10453SEric Joyner 	VIRTCHNL_EVENT_UNKNOWN = 0,
123571d10453SEric Joyner 	VIRTCHNL_EVENT_LINK_CHANGE,
123671d10453SEric Joyner 	VIRTCHNL_EVENT_RESET_IMPENDING,
123771d10453SEric Joyner 	VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
123871d10453SEric Joyner };
123971d10453SEric Joyner 
124071d10453SEric Joyner #define PF_EVENT_SEVERITY_INFO		0
124171d10453SEric Joyner #define PF_EVENT_SEVERITY_ATTENTION	1
124271d10453SEric Joyner #define PF_EVENT_SEVERITY_ACTION_REQUIRED	2
124371d10453SEric Joyner #define PF_EVENT_SEVERITY_CERTAIN_DOOM	255
124471d10453SEric Joyner 
124571d10453SEric Joyner struct virtchnl_pf_event {
1246*9cf1841cSEric Joyner 	/* see enum virtchnl_event_codes */
1247*9cf1841cSEric Joyner 	s32 event;
124871d10453SEric Joyner 	union {
124971d10453SEric Joyner 		/* If the PF driver does not support the new speed reporting
125071d10453SEric Joyner 		 * capabilities then use link_event else use link_event_adv to
125171d10453SEric Joyner 		 * get the speed and link information. The ability to understand
125271d10453SEric Joyner 		 * new speeds is indicated by setting the capability flag
125371d10453SEric Joyner 		 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter
125471d10453SEric Joyner 		 * in virtchnl_vf_resource struct and can be used to determine
125571d10453SEric Joyner 		 * which link event struct to use below.
125671d10453SEric Joyner 		 */
125771d10453SEric Joyner 		struct {
125871d10453SEric Joyner 			enum virtchnl_link_speed link_speed;
1259*9cf1841cSEric Joyner 			bool link_status;
1260*9cf1841cSEric Joyner 			u8 pad[3];
126171d10453SEric Joyner 		} link_event;
126271d10453SEric Joyner 		struct {
126371d10453SEric Joyner 			/* link_speed provided in Mbps */
126471d10453SEric Joyner 			u32 link_speed;
126571d10453SEric Joyner 			u8 link_status;
1266*9cf1841cSEric Joyner 			u8 pad[3];
126771d10453SEric Joyner 		} link_event_adv;
1268*9cf1841cSEric Joyner 		struct {
1269*9cf1841cSEric Joyner 			/* link_speed provided in Mbps */
1270*9cf1841cSEric Joyner 			u32 link_speed;
1271*9cf1841cSEric Joyner 			u16 vport_id;
1272*9cf1841cSEric Joyner 			u8 link_status;
1273*9cf1841cSEric Joyner 			u8 pad;
1274*9cf1841cSEric Joyner 		} link_event_adv_vport;
127571d10453SEric Joyner 	} event_data;
127671d10453SEric Joyner 
1277*9cf1841cSEric Joyner 	s32 severity;
127871d10453SEric Joyner };
127971d10453SEric Joyner 
128071d10453SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
128171d10453SEric Joyner 
1282d08b8680SEric Joyner /* VF reset states - these are written into the RSTAT register:
1283d08b8680SEric Joyner  * VFGEN_RSTAT on the VF
1284d08b8680SEric Joyner  * When the PF initiates a reset, it writes 0
1285d08b8680SEric Joyner  * When the reset is complete, it writes 1
1286d08b8680SEric Joyner  * When the PF detects that the VF has recovered, it writes 2
1287d08b8680SEric Joyner  * VF checks this register periodically to determine if a reset has occurred,
1288d08b8680SEric Joyner  * then polls it to know when the reset is complete.
1289d08b8680SEric Joyner  * If either the PF or VF reads the register while the hardware
1290d08b8680SEric Joyner  * is in a reset state, it will return DEADBEEF, which, when masked
1291d08b8680SEric Joyner  * will result in 3.
1292d08b8680SEric Joyner  */
1293d08b8680SEric Joyner enum virtchnl_vfr_states {
1294d08b8680SEric Joyner 	VIRTCHNL_VFR_INPROGRESS = 0,
1295d08b8680SEric Joyner 	VIRTCHNL_VFR_COMPLETED,
1296d08b8680SEric Joyner 	VIRTCHNL_VFR_VFACTIVE,
1297d08b8680SEric Joyner };
1298d08b8680SEric Joyner 
1299d08b8680SEric Joyner /* TX and RX queue types are valid in legacy as well as split queue models.
1300d08b8680SEric Joyner  * With Split Queue model, 2 additional types are introduced - TX_COMPLETION
1301d08b8680SEric Joyner  * and RX_BUFFER. In split queue model, RX corresponds to the queue where HW
1302d08b8680SEric Joyner  * posts completions.
1303d08b8680SEric Joyner  */
1304d08b8680SEric Joyner enum virtchnl_queue_type {
1305d08b8680SEric Joyner 	VIRTCHNL_QUEUE_TYPE_TX			= 0,
1306d08b8680SEric Joyner 	VIRTCHNL_QUEUE_TYPE_RX			= 1,
1307d08b8680SEric Joyner 	VIRTCHNL_QUEUE_TYPE_TX_COMPLETION	= 2,
1308d08b8680SEric Joyner 	VIRTCHNL_QUEUE_TYPE_RX_BUFFER		= 3,
1309d08b8680SEric Joyner 	VIRTCHNL_QUEUE_TYPE_CONFIG_TX		= 4,
1310d08b8680SEric Joyner 	VIRTCHNL_QUEUE_TYPE_CONFIG_RX		= 5
1311d08b8680SEric Joyner };
1312d08b8680SEric Joyner 
1313d08b8680SEric Joyner /* structure to specify a chunk of contiguous queues */
1314d08b8680SEric Joyner struct virtchnl_queue_chunk {
1315*9cf1841cSEric Joyner 	/* see enum virtchnl_queue_type */
1316*9cf1841cSEric Joyner 	s32 type;
1317d08b8680SEric Joyner 	u16 start_queue_id;
1318d08b8680SEric Joyner 	u16 num_queues;
1319d08b8680SEric Joyner };
1320d08b8680SEric Joyner 
1321d08b8680SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_queue_chunk);
1322d08b8680SEric Joyner 
1323d08b8680SEric Joyner /* structure to specify several chunks of contiguous queues */
1324d08b8680SEric Joyner struct virtchnl_queue_chunks {
1325d08b8680SEric Joyner 	u16 num_chunks;
1326d08b8680SEric Joyner 	u16 rsvd;
1327d08b8680SEric Joyner 	struct virtchnl_queue_chunk chunks[1];
1328d08b8680SEric Joyner };
1329d08b8680SEric Joyner 
1330d08b8680SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_chunks);
1331d08b8680SEric Joyner 
1332d08b8680SEric Joyner /* VIRTCHNL_OP_ENABLE_QUEUES_V2
1333d08b8680SEric Joyner  * VIRTCHNL_OP_DISABLE_QUEUES_V2
1334d08b8680SEric Joyner  * VIRTCHNL_OP_DEL_QUEUES
1335d08b8680SEric Joyner  *
1336*9cf1841cSEric Joyner  * If VIRTCHNL version was negotiated in VIRTCHNL_OP_VERSION as 2.0
1337d08b8680SEric Joyner  * then all of these ops are available.
1338d08b8680SEric Joyner  *
1339d08b8680SEric Joyner  * If VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES
1340d08b8680SEric Joyner  * then VIRTCHNL_OP_ENABLE_QUEUES_V2 and VIRTCHNL_OP_DISABLE_QUEUES_V2 are
1341d08b8680SEric Joyner  * available.
1342d08b8680SEric Joyner  *
1343d08b8680SEric Joyner  * PF sends these messages to enable, disable or delete queues specified in
1344d08b8680SEric Joyner  * chunks. PF sends virtchnl_del_ena_dis_queues struct to specify the queues
1345d08b8680SEric Joyner  * to be enabled/disabled/deleted. Also applicable to single queue RX or
1346d08b8680SEric Joyner  * TX. CP performs requested action and returns status.
1347d08b8680SEric Joyner  */
1348d08b8680SEric Joyner struct virtchnl_del_ena_dis_queues {
1349d08b8680SEric Joyner 	u16 vport_id;
1350d08b8680SEric Joyner 	u16 pad;
1351d08b8680SEric Joyner 	struct virtchnl_queue_chunks chunks;
1352d08b8680SEric Joyner };
1353d08b8680SEric Joyner 
1354d08b8680SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_del_ena_dis_queues);
1355d08b8680SEric Joyner 
1356d08b8680SEric Joyner /* Virtchannel interrupt throttling rate index */
1357d08b8680SEric Joyner enum virtchnl_itr_idx {
1358d08b8680SEric Joyner 	VIRTCHNL_ITR_IDX_0	= 0,
1359d08b8680SEric Joyner 	VIRTCHNL_ITR_IDX_1	= 1,
1360d08b8680SEric Joyner 	VIRTCHNL_ITR_IDX_NO_ITR	= 3,
1361d08b8680SEric Joyner };
1362d08b8680SEric Joyner 
1363d08b8680SEric Joyner /* Queue to vector mapping */
1364d08b8680SEric Joyner struct virtchnl_queue_vector {
1365d08b8680SEric Joyner 	u16 queue_id;
1366d08b8680SEric Joyner 	u16 vector_id;
1367d08b8680SEric Joyner 	u8 pad[4];
1368*9cf1841cSEric Joyner 
1369*9cf1841cSEric Joyner 	/* see enum virtchnl_itr_idx */
1370*9cf1841cSEric Joyner 	s32 itr_idx;
1371*9cf1841cSEric Joyner 
1372*9cf1841cSEric Joyner 	/* see enum virtchnl_queue_type */
1373*9cf1841cSEric Joyner 	s32 queue_type;
1374d08b8680SEric Joyner };
1375d08b8680SEric Joyner 
1376d08b8680SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_queue_vector);
1377d08b8680SEric Joyner 
1378d08b8680SEric Joyner /* VIRTCHNL_OP_MAP_QUEUE_VECTOR
1379d08b8680SEric Joyner  *
1380d08b8680SEric Joyner  * If VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES
1381d08b8680SEric Joyner  * then only VIRTCHNL_OP_MAP_QUEUE_VECTOR is available.
1382d08b8680SEric Joyner  *
1383d08b8680SEric Joyner  * PF sends this message to map or unmap queues to vectors and ITR index
1384d08b8680SEric Joyner  * registers. External data buffer contains virtchnl_queue_vector_maps structure
1385d08b8680SEric Joyner  * that contains num_qv_maps of virtchnl_queue_vector structures.
1386d08b8680SEric Joyner  * CP maps the requested queue vector maps after validating the queue and vector
1387d08b8680SEric Joyner  * ids and returns a status code.
1388d08b8680SEric Joyner  */
1389d08b8680SEric Joyner struct virtchnl_queue_vector_maps {
1390d08b8680SEric Joyner 	u16 vport_id;
1391d08b8680SEric Joyner 	u16 num_qv_maps;
1392d08b8680SEric Joyner 	u8 pad[4];
1393d08b8680SEric Joyner 	struct virtchnl_queue_vector qv_maps[1];
1394d08b8680SEric Joyner };
1395d08b8680SEric Joyner 
1396d08b8680SEric Joyner VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_queue_vector_maps);
1397d08b8680SEric Joyner 
139871d10453SEric Joyner /* Since VF messages are limited by u16 size, precalculate the maximum possible
139971d10453SEric Joyner  * values of nested elements in virtchnl structures that virtual channel can
140071d10453SEric Joyner  * possibly handle in a single message.
140171d10453SEric Joyner  */
140271d10453SEric Joyner enum virtchnl_vector_limits {
140371d10453SEric Joyner 	VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX	=
140471d10453SEric Joyner 		((u16)(~0) - sizeof(struct virtchnl_vsi_queue_config_info)) /
140571d10453SEric Joyner 		sizeof(struct virtchnl_queue_pair_info),
140671d10453SEric Joyner 
140771d10453SEric Joyner 	VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX		=
140871d10453SEric Joyner 		((u16)(~0) - sizeof(struct virtchnl_irq_map_info)) /
140971d10453SEric Joyner 		sizeof(struct virtchnl_vector_map),
141071d10453SEric Joyner 
141171d10453SEric Joyner 	VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX	=
141271d10453SEric Joyner 		((u16)(~0) - sizeof(struct virtchnl_ether_addr_list)) /
141371d10453SEric Joyner 		sizeof(struct virtchnl_ether_addr),
141471d10453SEric Joyner 
141571d10453SEric Joyner 	VIRTCHNL_OP_ADD_DEL_VLAN_MAX		=
141671d10453SEric Joyner 		((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list)) /
141771d10453SEric Joyner 		sizeof(u16),
141871d10453SEric Joyner 
141971d10453SEric Joyner 	VIRTCHNL_OP_ENABLE_CHANNELS_MAX		=
142071d10453SEric Joyner 		((u16)(~0) - sizeof(struct virtchnl_tc_info)) /
142171d10453SEric Joyner 		sizeof(struct virtchnl_channel_info),
142271d10453SEric Joyner 
1423d08b8680SEric Joyner 	VIRTCHNL_OP_ENABLE_DISABLE_DEL_QUEUES_V2_MAX	=
1424d08b8680SEric Joyner 		((u16)(~0) - sizeof(struct virtchnl_del_ena_dis_queues)) /
1425d08b8680SEric Joyner 		sizeof(struct virtchnl_queue_chunk),
1426d08b8680SEric Joyner 
1427d08b8680SEric Joyner 	VIRTCHNL_OP_MAP_UNMAP_QUEUE_VECTOR_MAX	=
1428d08b8680SEric Joyner 		((u16)(~0) - sizeof(struct virtchnl_queue_vector_maps)) /
1429d08b8680SEric Joyner 		sizeof(struct virtchnl_queue_vector),
1430*9cf1841cSEric Joyner 
1431*9cf1841cSEric Joyner 	VIRTCHNL_OP_ADD_DEL_VLAN_V2_MAX		=
1432*9cf1841cSEric Joyner 		((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list_v2)) /
1433*9cf1841cSEric Joyner 		sizeof(struct virtchnl_vlan_filter),
143471d10453SEric Joyner };
143571d10453SEric Joyner 
143671d10453SEric Joyner /**
143771d10453SEric Joyner  * virtchnl_vc_validate_vf_msg
143871d10453SEric Joyner  * @ver: Virtchnl version info
143971d10453SEric Joyner  * @v_opcode: Opcode for the message
144071d10453SEric Joyner  * @msg: pointer to the msg buffer
144171d10453SEric Joyner  * @msglen: msg length
144271d10453SEric Joyner  *
144371d10453SEric Joyner  * validate msg format against struct for each opcode
144471d10453SEric Joyner  */
144571d10453SEric Joyner static inline int
144671d10453SEric Joyner virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
144771d10453SEric Joyner 			    u8 *msg, u16 msglen)
144871d10453SEric Joyner {
144971d10453SEric Joyner 	bool err_msg_format = false;
14507d7af7f8SEric Joyner 	u32 valid_len = 0;
145171d10453SEric Joyner 
145271d10453SEric Joyner 	/* Validate message length. */
145371d10453SEric Joyner 	switch (v_opcode) {
145471d10453SEric Joyner 	case VIRTCHNL_OP_VERSION:
145571d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_version_info);
145671d10453SEric Joyner 		break;
145771d10453SEric Joyner 	case VIRTCHNL_OP_RESET_VF:
145871d10453SEric Joyner 		break;
145971d10453SEric Joyner 	case VIRTCHNL_OP_GET_VF_RESOURCES:
146071d10453SEric Joyner 		if (VF_IS_V11(ver))
146171d10453SEric Joyner 			valid_len = sizeof(u32);
146271d10453SEric Joyner 		break;
146371d10453SEric Joyner 	case VIRTCHNL_OP_CONFIG_TX_QUEUE:
146471d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_txq_info);
146571d10453SEric Joyner 		break;
146671d10453SEric Joyner 	case VIRTCHNL_OP_CONFIG_RX_QUEUE:
146771d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_rxq_info);
146871d10453SEric Joyner 		break;
146971d10453SEric Joyner 	case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
147071d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
147171d10453SEric Joyner 		if (msglen >= valid_len) {
147271d10453SEric Joyner 			struct virtchnl_vsi_queue_config_info *vqc =
147371d10453SEric Joyner 			    (struct virtchnl_vsi_queue_config_info *)msg;
147471d10453SEric Joyner 
147571d10453SEric Joyner 			if (vqc->num_queue_pairs == 0 || vqc->num_queue_pairs >
147671d10453SEric Joyner 			    VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX) {
147771d10453SEric Joyner 				err_msg_format = true;
147871d10453SEric Joyner 				break;
147971d10453SEric Joyner 			}
148071d10453SEric Joyner 
148171d10453SEric Joyner 			valid_len += (vqc->num_queue_pairs *
148271d10453SEric Joyner 				      sizeof(struct
148371d10453SEric Joyner 					     virtchnl_queue_pair_info));
148471d10453SEric Joyner 		}
148571d10453SEric Joyner 		break;
148671d10453SEric Joyner 	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
148771d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_irq_map_info);
148871d10453SEric Joyner 		if (msglen >= valid_len) {
148971d10453SEric Joyner 			struct virtchnl_irq_map_info *vimi =
149071d10453SEric Joyner 			    (struct virtchnl_irq_map_info *)msg;
149171d10453SEric Joyner 
149271d10453SEric Joyner 			if (vimi->num_vectors == 0 || vimi->num_vectors >
149371d10453SEric Joyner 			    VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX) {
149471d10453SEric Joyner 				err_msg_format = true;
149571d10453SEric Joyner 				break;
149671d10453SEric Joyner 			}
149771d10453SEric Joyner 
149871d10453SEric Joyner 			valid_len += (vimi->num_vectors *
149971d10453SEric Joyner 				      sizeof(struct virtchnl_vector_map));
150071d10453SEric Joyner 		}
150171d10453SEric Joyner 		break;
150271d10453SEric Joyner 	case VIRTCHNL_OP_ENABLE_QUEUES:
150371d10453SEric Joyner 	case VIRTCHNL_OP_DISABLE_QUEUES:
150471d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_queue_select);
150571d10453SEric Joyner 		break;
1506d08b8680SEric Joyner 	case VIRTCHNL_OP_GET_MAX_RSS_QREGION:
1507d08b8680SEric Joyner 		break;
150871d10453SEric Joyner 	case VIRTCHNL_OP_ADD_ETH_ADDR:
150971d10453SEric Joyner 	case VIRTCHNL_OP_DEL_ETH_ADDR:
151071d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_ether_addr_list);
151171d10453SEric Joyner 		if (msglen >= valid_len) {
151271d10453SEric Joyner 			struct virtchnl_ether_addr_list *veal =
151371d10453SEric Joyner 			    (struct virtchnl_ether_addr_list *)msg;
151471d10453SEric Joyner 
151571d10453SEric Joyner 			if (veal->num_elements == 0 || veal->num_elements >
151671d10453SEric Joyner 			    VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX) {
151771d10453SEric Joyner 				err_msg_format = true;
151871d10453SEric Joyner 				break;
151971d10453SEric Joyner 			}
152071d10453SEric Joyner 
152171d10453SEric Joyner 			valid_len += veal->num_elements *
152271d10453SEric Joyner 			    sizeof(struct virtchnl_ether_addr);
152371d10453SEric Joyner 		}
152471d10453SEric Joyner 		break;
152571d10453SEric Joyner 	case VIRTCHNL_OP_ADD_VLAN:
152671d10453SEric Joyner 	case VIRTCHNL_OP_DEL_VLAN:
152771d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_vlan_filter_list);
152871d10453SEric Joyner 		if (msglen >= valid_len) {
152971d10453SEric Joyner 			struct virtchnl_vlan_filter_list *vfl =
153071d10453SEric Joyner 			    (struct virtchnl_vlan_filter_list *)msg;
153171d10453SEric Joyner 
153271d10453SEric Joyner 			if (vfl->num_elements == 0 || vfl->num_elements >
153371d10453SEric Joyner 			    VIRTCHNL_OP_ADD_DEL_VLAN_MAX) {
153471d10453SEric Joyner 				err_msg_format = true;
153571d10453SEric Joyner 				break;
153671d10453SEric Joyner 			}
153771d10453SEric Joyner 
153871d10453SEric Joyner 			valid_len += vfl->num_elements * sizeof(u16);
153971d10453SEric Joyner 		}
154071d10453SEric Joyner 		break;
154171d10453SEric Joyner 	case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
154271d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_promisc_info);
154371d10453SEric Joyner 		break;
154471d10453SEric Joyner 	case VIRTCHNL_OP_GET_STATS:
154571d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_queue_select);
154671d10453SEric Joyner 		break;
154771d10453SEric Joyner 	case VIRTCHNL_OP_CONFIG_RSS_KEY:
154871d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_rss_key);
154971d10453SEric Joyner 		if (msglen >= valid_len) {
155071d10453SEric Joyner 			struct virtchnl_rss_key *vrk =
155171d10453SEric Joyner 				(struct virtchnl_rss_key *)msg;
155271d10453SEric Joyner 
155371d10453SEric Joyner 			if (vrk->key_len == 0) {
155471d10453SEric Joyner 				/* zero length is allowed as input */
155571d10453SEric Joyner 				break;
155671d10453SEric Joyner 			}
155771d10453SEric Joyner 
155871d10453SEric Joyner 			valid_len += vrk->key_len - 1;
155971d10453SEric Joyner 		}
156071d10453SEric Joyner 		break;
156171d10453SEric Joyner 	case VIRTCHNL_OP_CONFIG_RSS_LUT:
156271d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_rss_lut);
156371d10453SEric Joyner 		if (msglen >= valid_len) {
156471d10453SEric Joyner 			struct virtchnl_rss_lut *vrl =
156571d10453SEric Joyner 				(struct virtchnl_rss_lut *)msg;
156671d10453SEric Joyner 
156771d10453SEric Joyner 			if (vrl->lut_entries == 0) {
156871d10453SEric Joyner 				/* zero entries is allowed as input */
156971d10453SEric Joyner 				break;
157071d10453SEric Joyner 			}
157171d10453SEric Joyner 
157271d10453SEric Joyner 			valid_len += vrl->lut_entries - 1;
157371d10453SEric Joyner 		}
157471d10453SEric Joyner 		break;
157571d10453SEric Joyner 	case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
157671d10453SEric Joyner 		break;
157771d10453SEric Joyner 	case VIRTCHNL_OP_SET_RSS_HENA:
157871d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_rss_hena);
157971d10453SEric Joyner 		break;
158071d10453SEric Joyner 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
158171d10453SEric Joyner 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
158271d10453SEric Joyner 		break;
158371d10453SEric Joyner 	case VIRTCHNL_OP_REQUEST_QUEUES:
158471d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_vf_res_request);
158571d10453SEric Joyner 		break;
158671d10453SEric Joyner 	case VIRTCHNL_OP_ENABLE_CHANNELS:
158771d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_tc_info);
158871d10453SEric Joyner 		if (msglen >= valid_len) {
158971d10453SEric Joyner 			struct virtchnl_tc_info *vti =
159071d10453SEric Joyner 				(struct virtchnl_tc_info *)msg;
159171d10453SEric Joyner 
159271d10453SEric Joyner 			if (vti->num_tc == 0 || vti->num_tc >
159371d10453SEric Joyner 			    VIRTCHNL_OP_ENABLE_CHANNELS_MAX) {
159471d10453SEric Joyner 				err_msg_format = true;
159571d10453SEric Joyner 				break;
159671d10453SEric Joyner 			}
159771d10453SEric Joyner 
159871d10453SEric Joyner 			valid_len += (vti->num_tc - 1) *
159971d10453SEric Joyner 				     sizeof(struct virtchnl_channel_info);
160071d10453SEric Joyner 		}
160171d10453SEric Joyner 		break;
160271d10453SEric Joyner 	case VIRTCHNL_OP_DISABLE_CHANNELS:
160371d10453SEric Joyner 		break;
160471d10453SEric Joyner 	case VIRTCHNL_OP_ADD_CLOUD_FILTER:
160571d10453SEric Joyner 	case VIRTCHNL_OP_DEL_CLOUD_FILTER:
160671d10453SEric Joyner 		valid_len = sizeof(struct virtchnl_filter);
160771d10453SEric Joyner 		break;
1608*9cf1841cSEric Joyner 	case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
1609*9cf1841cSEric Joyner 		break;
1610*9cf1841cSEric Joyner 	case VIRTCHNL_OP_ADD_VLAN_V2:
1611*9cf1841cSEric Joyner 	case VIRTCHNL_OP_DEL_VLAN_V2:
1612*9cf1841cSEric Joyner 		valid_len = sizeof(struct virtchnl_vlan_filter_list_v2);
1613*9cf1841cSEric Joyner 		if (msglen >= valid_len) {
1614*9cf1841cSEric Joyner 			struct virtchnl_vlan_filter_list_v2 *vfl =
1615*9cf1841cSEric Joyner 			    (struct virtchnl_vlan_filter_list_v2 *)msg;
1616*9cf1841cSEric Joyner 
1617*9cf1841cSEric Joyner 			if (vfl->num_elements == 0 || vfl->num_elements >
1618*9cf1841cSEric Joyner 			    VIRTCHNL_OP_ADD_DEL_VLAN_V2_MAX) {
1619*9cf1841cSEric Joyner 				err_msg_format = true;
1620*9cf1841cSEric Joyner 				break;
1621*9cf1841cSEric Joyner 			}
1622*9cf1841cSEric Joyner 
1623*9cf1841cSEric Joyner 			valid_len += (vfl->num_elements - 1) *
1624*9cf1841cSEric Joyner 				sizeof(struct virtchnl_vlan_filter);
1625*9cf1841cSEric Joyner 		}
1626*9cf1841cSEric Joyner 		break;
1627*9cf1841cSEric Joyner 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1628*9cf1841cSEric Joyner 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1629*9cf1841cSEric Joyner 	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1630*9cf1841cSEric Joyner 	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1631*9cf1841cSEric Joyner 	case VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2:
1632*9cf1841cSEric Joyner 	case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
1633*9cf1841cSEric Joyner 		valid_len = sizeof(struct virtchnl_vlan_setting);
1634*9cf1841cSEric Joyner 		break;
1635d08b8680SEric Joyner 	case VIRTCHNL_OP_ENABLE_QUEUES_V2:
1636d08b8680SEric Joyner 	case VIRTCHNL_OP_DISABLE_QUEUES_V2:
1637d08b8680SEric Joyner 		valid_len = sizeof(struct virtchnl_del_ena_dis_queues);
1638d08b8680SEric Joyner 		if (msglen >= valid_len) {
1639d08b8680SEric Joyner 			struct virtchnl_del_ena_dis_queues *qs =
1640d08b8680SEric Joyner 				(struct virtchnl_del_ena_dis_queues *)msg;
1641d08b8680SEric Joyner 			if (qs->chunks.num_chunks == 0 ||
1642d08b8680SEric Joyner 			    qs->chunks.num_chunks > VIRTCHNL_OP_ENABLE_DISABLE_DEL_QUEUES_V2_MAX) {
1643d08b8680SEric Joyner 				err_msg_format = true;
1644d08b8680SEric Joyner 				break;
1645d08b8680SEric Joyner 			}
1646d08b8680SEric Joyner 			valid_len += (qs->chunks.num_chunks - 1) *
1647d08b8680SEric Joyner 				      sizeof(struct virtchnl_queue_chunk);
1648d08b8680SEric Joyner 		}
1649d08b8680SEric Joyner 		break;
1650d08b8680SEric Joyner 	case VIRTCHNL_OP_MAP_QUEUE_VECTOR:
1651d08b8680SEric Joyner 		valid_len = sizeof(struct virtchnl_queue_vector_maps);
1652d08b8680SEric Joyner 		if (msglen >= valid_len) {
1653d08b8680SEric Joyner 			struct virtchnl_queue_vector_maps *v_qp =
1654d08b8680SEric Joyner 				(struct virtchnl_queue_vector_maps *)msg;
1655d08b8680SEric Joyner 			if (v_qp->num_qv_maps == 0 ||
1656d08b8680SEric Joyner 			    v_qp->num_qv_maps > VIRTCHNL_OP_MAP_UNMAP_QUEUE_VECTOR_MAX) {
1657d08b8680SEric Joyner 				err_msg_format = true;
1658d08b8680SEric Joyner 				break;
1659d08b8680SEric Joyner 			}
1660d08b8680SEric Joyner 			valid_len += (v_qp->num_qv_maps - 1) *
1661d08b8680SEric Joyner 				      sizeof(struct virtchnl_queue_vector);
1662d08b8680SEric Joyner 		}
1663d08b8680SEric Joyner 		break;
166471d10453SEric Joyner 	/* These are always errors coming from the VF. */
166571d10453SEric Joyner 	case VIRTCHNL_OP_EVENT:
166671d10453SEric Joyner 	case VIRTCHNL_OP_UNKNOWN:
166771d10453SEric Joyner 	default:
166871d10453SEric Joyner 		return VIRTCHNL_STATUS_ERR_PARAM;
166971d10453SEric Joyner 	}
167071d10453SEric Joyner 	/* few more checks */
167171d10453SEric Joyner 	if (err_msg_format || valid_len != msglen)
167271d10453SEric Joyner 		return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
167371d10453SEric Joyner 
167471d10453SEric Joyner 	return 0;
167571d10453SEric Joyner }
167671d10453SEric Joyner #endif /* _VIRTCHNL_H_ */
1677