1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* Copyright (c) 2023, 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 /*$FreeBSD$*/ 32 33 /** 34 * @file ice_resmgr.h 35 * @brief Resource manager interface 36 * 37 * Defines an interface for managing PF hardware queues and interrupts for assigning them to 38 * hardware VSIs and VFs. 39 * 40 * For queue management: 41 * The total number of available Tx and Rx queues is not equal, so it is 42 * expected that each PF will allocate two ice_resmgr structures, one for Tx 43 * and one for Rx. These should be allocated in attach() prior to initializing 44 * VSIs, and destroyed in detach(). 45 * 46 * For interrupt management: 47 * The PF allocates an ice_resmgr structure that does not allow scattered 48 * allocations since interrupt allocations must be contiguous. 49 */ 50 51 #ifndef _ICE_RESMGR_H_ 52 #define _ICE_RESMGR_H_ 53 #include <sys/param.h> 54 #include "ice_osdep.h" 55 56 #include <sys/bitstring.h> 57 58 /* 59 * For managing VSI queue allocations 60 */ 61 /* Hardware only supports a limited number of resources in scattered mode */ 62 #define ICE_MAX_SCATTERED_QUEUES 16 63 /* Use highest value to indicate invalid resource mapping */ 64 #define ICE_INVALID_RES_IDX 0xFFFF 65 66 /* 67 * Structures 68 */ 69 70 /** 71 * @struct ice_resmgr 72 * @brief Resource manager 73 * 74 * Represent resource allocations using a bitstring, where bit zero represents 75 * the first resource. If a particular bit is set this indicates that the 76 * resource has been allocated and is not free. 77 */ 78 struct ice_resmgr { 79 bitstr_t *resources; 80 u16 num_res; 81 bool contig_only; 82 }; 83 84 /** 85 * @enum ice_resmgr_alloc_type 86 * @brief resource manager allocation types 87 * 88 * Enumeration of possible allocation types that can be used when 89 * assigning resources. For now, SCATTERED is only used with 90 * managing queue allocations. 91 */ 92 enum ice_resmgr_alloc_type { 93 ICE_RESMGR_ALLOC_INVALID = 0, 94 ICE_RESMGR_ALLOC_CONTIGUOUS, 95 ICE_RESMGR_ALLOC_SCATTERED 96 }; 97 98 /* Public resource manager allocation functions */ 99 int ice_resmgr_init(struct ice_resmgr *resmgr, u16 num_res); 100 int ice_resmgr_init_contig_only(struct ice_resmgr *resmgr, u16 num_res); 101 void ice_resmgr_destroy(struct ice_resmgr *resmgr); 102 103 /* Public resource assignment functions */ 104 int ice_resmgr_assign_contiguous(struct ice_resmgr *resmgr, u16 *idx, u16 num_res); 105 int ice_resmgr_assign_scattered(struct ice_resmgr *resmgr, u16 *idx, u16 num_res); 106 107 /* Release resources */ 108 void ice_resmgr_release_map(struct ice_resmgr *resmgr, u16 *idx, u16 num_res); 109 110 #endif /* _ICE_RESMGR_H_ */ 111 112