xref: /freebsd/sys/dev/ice/ice_iov.h (revision 430f1acc451c7084d1d5aa7df7e7ecccea1a8b51)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2025, Intel Corporation
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above copyright notice,
9  *      this list of conditions and the following disclaimer.
10  *
11  *   2. Redistributions in binary form must reproduce the above copyright
12  *      notice, this list of conditions and the following disclaimer in the
13  *      documentation and/or other materials provided with the distribution.
14  *
15  *   3. Neither the name of the Intel Corporation nor the names of its
16  *      contributors may be used to endorse or promote products derived from
17  *      this software without specific prior written permission.
18  *
19  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *  POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /**
33  * @file ice_iov.h
34  * @brief header for IOV functionality
35  *
36  * This header includes definitions used to implement device Virtual Functions
37  * for the ice driver.
38  */
39 
40 #ifndef _ICE_IOV_H_
41 #define _ICE_IOV_H_
42 
43 #include <sys/types.h>
44 #include <sys/bus.h>
45 #include <sys/nv.h>
46 #include <sys/iov_schema.h>
47 #include <sys/param.h>
48 #include <dev/pci/pcivar.h>
49 #include <dev/pci/pcireg.h>
50 
51 #include <dev/pci/pci_iov.h>
52 
53 #include "ice_iflib.h"
54 #include "ice_vf_mbx.h"
55 
56 /**
57  * @enum ice_vf_flags
58  * @brief VF state flags
59  *
60  * Used to indicate the status of a PF's VF, as well as indicating what each VF
61  * is capabile of. Intended to be modified only using atomic operations, so
62  * they can be read and modified in places that aren't locked.
63  *
64  * Used in struct ice_vf's vf_flags field.
65  */
66 enum ice_vf_flags {
67 	VF_FLAG_ENABLED			= BIT(0),
68 	VF_FLAG_SET_MAC_CAP		= BIT(1),
69 	VF_FLAG_VLAN_CAP		= BIT(2),
70 	VF_FLAG_PROMISC_CAP		= BIT(3),
71 	VF_FLAG_MAC_ANTI_SPOOF		= BIT(4),
72 };
73 
74 /**
75  * @struct ice_vf
76  * @brief PF's VF software context
77  *
78  * Represents the state and options for a VF spawned from a PF.
79  */
80 struct ice_vf {
81 	struct ice_vsi *vsi;
82 	u32 vf_flags;
83 
84 	u8 mac[ETHER_ADDR_LEN];
85 	u16 vf_num;
86 	struct virtchnl_version_info version;
87 
88 	u16 mac_filter_limit;
89 	u16 mac_filter_cnt;
90 	u16 vlan_limit;
91 	u16 vlan_cnt;
92 
93 	u16 num_irq_vectors;
94 	u16 *vf_imap;
95 	struct ice_irq_vector *tx_irqvs;
96 	struct ice_irq_vector *rx_irqvs;
97 };
98 
99 #define ICE_PCIE_DEV_STATUS			0xAA
100 
101 #define ICE_PCI_CIAD_WAIT_COUNT			100
102 #define ICE_PCI_CIAD_WAIT_DELAY_US		1
103 #define ICE_VPGEN_VFRSTAT_WAIT_COUNT		100
104 #define ICE_VPGEN_VFRSTAT_WAIT_DELAY_US		20
105 
106 #define ICE_VIRTCHNL_VALID_PROMISC_FLAGS	(FLAG_VF_UNICAST_PROMISC | \
107 						 FLAG_VF_MULTICAST_PROMISC)
108 
109 #define ICE_DEFAULT_VF_VLAN_LIMIT			64
110 #define ICE_DEFAULT_VF_FILTER_LIMIT			16
111 
112 int ice_iov_attach(struct ice_softc *sc);
113 int ice_iov_detach(struct ice_softc *sc);
114 
115 int ice_iov_init(struct ice_softc *sc, uint16_t num_vfs, const nvlist_t *params);
116 int ice_iov_add_vf(struct ice_softc *sc, uint16_t vfnum, const nvlist_t *params);
117 void ice_iov_uninit(struct ice_softc *sc);
118 
119 void ice_iov_handle_vflr(struct ice_softc *sc);
120 
121 void ice_vc_handle_vf_msg(struct ice_softc *sc, struct ice_rq_event_info *event);
122 void ice_vc_notify_all_vfs_link_state(struct ice_softc *sc);
123 
124 #endif /* _ICE_IOV_H_ */
125 
126