171d10453SEric Joyner /* SPDX-License-Identifier: BSD-3-Clause */ 2*015f8cc5SEric Joyner /* Copyright (c) 2024, 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 3271d10453SEric Joyner /** 3371d10453SEric Joyner * @file ice_resmgr.h 3471d10453SEric Joyner * @brief Resource manager interface 3571d10453SEric Joyner * 3671d10453SEric Joyner * Defines an interface for managing PF hardware queues and interrupts for assigning them to 3771d10453SEric Joyner * hardware VSIs and VFs. 3871d10453SEric Joyner * 3971d10453SEric Joyner * For queue management: 4071d10453SEric Joyner * The total number of available Tx and Rx queues is not equal, so it is 4171d10453SEric Joyner * expected that each PF will allocate two ice_resmgr structures, one for Tx 4271d10453SEric Joyner * and one for Rx. These should be allocated in attach() prior to initializing 4371d10453SEric Joyner * VSIs, and destroyed in detach(). 4471d10453SEric Joyner * 4571d10453SEric Joyner * For interrupt management: 4671d10453SEric Joyner * The PF allocates an ice_resmgr structure that does not allow scattered 4771d10453SEric Joyner * allocations since interrupt allocations must be contiguous. 4871d10453SEric Joyner */ 4971d10453SEric Joyner 5071d10453SEric Joyner #ifndef _ICE_RESMGR_H_ 5171d10453SEric Joyner #define _ICE_RESMGR_H_ 5271d10453SEric Joyner #include <sys/param.h> 5371d10453SEric Joyner #include "ice_osdep.h" 5471d10453SEric Joyner 5571d10453SEric Joyner #include <sys/bitstring.h> 5671d10453SEric Joyner 5771d10453SEric Joyner /* 5871d10453SEric Joyner * For managing VSI queue allocations 5971d10453SEric Joyner */ 6071d10453SEric Joyner /* Hardware only supports a limited number of resources in scattered mode */ 6171d10453SEric Joyner #define ICE_MAX_SCATTERED_QUEUES 16 6271d10453SEric Joyner /* Use highest value to indicate invalid resource mapping */ 6371d10453SEric Joyner #define ICE_INVALID_RES_IDX 0xFFFF 6471d10453SEric Joyner 6571d10453SEric Joyner /* 6671d10453SEric Joyner * Structures 6771d10453SEric Joyner */ 6871d10453SEric Joyner 6971d10453SEric Joyner /** 7071d10453SEric Joyner * @struct ice_resmgr 7171d10453SEric Joyner * @brief Resource manager 7271d10453SEric Joyner * 7371d10453SEric Joyner * Represent resource allocations using a bitstring, where bit zero represents 7471d10453SEric Joyner * the first resource. If a particular bit is set this indicates that the 7571d10453SEric Joyner * resource has been allocated and is not free. 7671d10453SEric Joyner */ 7771d10453SEric Joyner struct ice_resmgr { 7871d10453SEric Joyner bitstr_t *resources; 7971d10453SEric Joyner u16 num_res; 8071d10453SEric Joyner bool contig_only; 8171d10453SEric Joyner }; 8271d10453SEric Joyner 8371d10453SEric Joyner /** 8471d10453SEric Joyner * @enum ice_resmgr_alloc_type 8571d10453SEric Joyner * @brief resource manager allocation types 8671d10453SEric Joyner * 8771d10453SEric Joyner * Enumeration of possible allocation types that can be used when 8871d10453SEric Joyner * assigning resources. For now, SCATTERED is only used with 8971d10453SEric Joyner * managing queue allocations. 9071d10453SEric Joyner */ 9171d10453SEric Joyner enum ice_resmgr_alloc_type { 9271d10453SEric Joyner ICE_RESMGR_ALLOC_INVALID = 0, 9371d10453SEric Joyner ICE_RESMGR_ALLOC_CONTIGUOUS, 9471d10453SEric Joyner ICE_RESMGR_ALLOC_SCATTERED 9571d10453SEric Joyner }; 9671d10453SEric Joyner 9771d10453SEric Joyner /* Public resource manager allocation functions */ 9871d10453SEric Joyner int ice_resmgr_init(struct ice_resmgr *resmgr, u16 num_res); 9971d10453SEric Joyner int ice_resmgr_init_contig_only(struct ice_resmgr *resmgr, u16 num_res); 10071d10453SEric Joyner void ice_resmgr_destroy(struct ice_resmgr *resmgr); 10171d10453SEric Joyner 10271d10453SEric Joyner /* Public resource assignment functions */ 10371d10453SEric Joyner int ice_resmgr_assign_contiguous(struct ice_resmgr *resmgr, u16 *idx, u16 num_res); 10471d10453SEric Joyner int ice_resmgr_assign_scattered(struct ice_resmgr *resmgr, u16 *idx, u16 num_res); 10571d10453SEric Joyner 10671d10453SEric Joyner /* Release resources */ 10771d10453SEric Joyner void ice_resmgr_release_map(struct ice_resmgr *resmgr, u16 *idx, u16 num_res); 10871d10453SEric Joyner 10971d10453SEric Joyner #endif /* _ICE_RESMGR_H_ */ 11071d10453SEric Joyner 111