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/bitstring.h> 45 #include <sys/bus.h> 46 #include <sys/nv.h> 47 #include <sys/iov_schema.h> 48 #include <sys/param.h> 49 #include <dev/pci/pcivar.h> 50 #include <dev/pci/pcireg.h> 51 52 #include <dev/pci/pci_iov.h> 53 54 #include "ice_iflib.h" 55 #include "ice_vf_mbx.h" 56 57 /** 58 * @enum ice_vf_flags 59 * @brief VF state flags 60 * 61 * Used to indicate the status of a PF's VF, as well as indicating what each VF 62 * is capabile of. Intended to be modified only using atomic operations, so 63 * they can be read and modified in places that aren't locked. 64 * 65 * Used in struct ice_vf's vf_flags field. 66 */ 67 enum ice_vf_flags { 68 VF_FLAG_ENABLED = BIT(0), 69 VF_FLAG_SET_MAC_CAP = BIT(1), 70 VF_FLAG_VLAN_CAP = BIT(2), 71 VF_FLAG_PROMISC_CAP = BIT(3), 72 VF_FLAG_MAC_ANTI_SPOOF = BIT(4), 73 VF_FLAG_INITIALIZED = BIT(5), 74 VF_FLAG_REBUILD_REQUIRED = BIT(6), 75 VF_FLAG_RESET_FAILED = BIT(7), 76 VF_FLAG_MDD_BLOCKED = BIT(8), 77 VF_FLAG_MBX_BLOCKED = BIT(9), 78 }; 79 80 struct ice_vf_mac_filter { 81 u8 addr[ETHER_ADDR_LEN]; 82 }; 83 84 /** 85 * @struct ice_vf 86 * @brief PF's VF software context 87 * 88 * Represents the state and options for a VF spawned from a PF. 89 */ 90 struct ice_vf { 91 struct ice_vsi *vsi; 92 u32 vf_flags; 93 94 u8 mac[ETHER_ADDR_LEN]; 95 u16 vf_num; 96 struct virtchnl_version_info version; 97 98 u16 mac_filter_limit; 99 u16 mac_filter_cnt; 100 struct ice_vf_mac_filter *mac_filters; 101 u16 vlan_limit; 102 u16 vlan_cnt; 103 #define ICE_VF_VLAN_MAP_LEN (EVL_VLID_MASK + 1) 104 bitstr_t bit_decl(vlans_map, ICE_VF_VLAN_MAP_LEN); 105 106 u16 num_irq_vectors; 107 u16 *vf_imap; 108 struct ice_irq_vector *tx_irqvs; 109 struct ice_irq_vector *rx_irqvs; 110 111 /* VF-relative queue state, indexed by virtchnl queue ID. */ 112 u32 txq_configured; 113 u32 rxq_configured; 114 u32 rxq_enabled; 115 116 u64 mdd_tx_events; 117 u64 mdd_rx_events; 118 struct ice_mbx_vf_info mbx_info; 119 u64 mbx_overflow_events; 120 struct timeval last_mdd_log; 121 }; 122 123 #define ICE_PCIE_DEV_STATUS 0xAA 124 125 #define ICE_PCI_CIAD_WAIT_COUNT 100 126 #define ICE_PCI_CIAD_WAIT_DELAY_US 1 127 #define ICE_VPGEN_VFRSTAT_WAIT_COUNT 100 128 #define ICE_VPGEN_VFRSTAT_WAIT_DELAY_US 20 129 130 #define ICE_VIRTCHNL_VALID_PROMISC_FLAGS (FLAG_VF_UNICAST_PROMISC | \ 131 FLAG_VF_MULTICAST_PROMISC) 132 133 #define ICE_DEFAULT_VF_VLAN_LIMIT 64 134 #define ICE_DEFAULT_VF_FILTER_LIMIT 16 135 136 int ice_iov_attach(struct ice_softc *sc); 137 int ice_iov_detach(struct ice_softc *sc); 138 139 int ice_iov_init(struct ice_softc *sc, uint16_t num_vfs, const nvlist_t *params); 140 int ice_iov_add_vf(struct ice_softc *sc, uint16_t vfnum, const nvlist_t *params); 141 int ice_iov_rebuild_vf(struct ice_softc *sc, struct ice_vsi *vsi); 142 struct if_vf_status; 143 int ice_iov_vf_status(struct ice_softc *sc, struct if_vf_status **statusp); 144 void ice_iov_uninit(struct ice_softc *sc); 145 146 void ice_iov_handle_vflr(struct ice_softc *sc); 147 u32 ice_iov_handle_mdd(struct ice_softc *sc); 148 void ice_iov_notify_vfs_reset(struct ice_softc *sc); 149 int ice_iov_quiesce_vfs_for_reset(struct ice_softc *sc); 150 void ice_iov_reconfigure_mbx(struct ice_softc *sc); 151 152 void ice_vc_handle_vf_msg(struct ice_softc *sc, struct ice_rq_event_info *event, 153 struct ice_mbx_data *mbx_data); 154 void ice_vc_notify_all_vfs_link_state(struct ice_softc *sc); 155 156 #endif /* _ICE_IOV_H_ */ 157