xref: /freebsd/sys/dev/ice/ice_resmgr.h (revision 71d104536b513298902be65342afe6f3792f29e4)
1*71d10453SEric Joyner /* SPDX-License-Identifier: BSD-3-Clause */
2*71d10453SEric Joyner /*  Copyright (c) 2020, Intel Corporation
3*71d10453SEric Joyner  *  All rights reserved.
4*71d10453SEric Joyner  *
5*71d10453SEric Joyner  *  Redistribution and use in source and binary forms, with or without
6*71d10453SEric Joyner  *  modification, are permitted provided that the following conditions are met:
7*71d10453SEric Joyner  *
8*71d10453SEric Joyner  *   1. Redistributions of source code must retain the above copyright notice,
9*71d10453SEric Joyner  *      this list of conditions and the following disclaimer.
10*71d10453SEric Joyner  *
11*71d10453SEric Joyner  *   2. Redistributions in binary form must reproduce the above copyright
12*71d10453SEric Joyner  *      notice, this list of conditions and the following disclaimer in the
13*71d10453SEric Joyner  *      documentation and/or other materials provided with the distribution.
14*71d10453SEric Joyner  *
15*71d10453SEric Joyner  *   3. Neither the name of the Intel Corporation nor the names of its
16*71d10453SEric Joyner  *      contributors may be used to endorse or promote products derived from
17*71d10453SEric Joyner  *      this software without specific prior written permission.
18*71d10453SEric Joyner  *
19*71d10453SEric Joyner  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20*71d10453SEric Joyner  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*71d10453SEric Joyner  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*71d10453SEric Joyner  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23*71d10453SEric Joyner  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*71d10453SEric Joyner  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*71d10453SEric Joyner  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*71d10453SEric Joyner  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*71d10453SEric Joyner  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*71d10453SEric Joyner  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*71d10453SEric Joyner  *  POSSIBILITY OF SUCH DAMAGE.
30*71d10453SEric Joyner  */
31*71d10453SEric Joyner /*$FreeBSD$*/
32*71d10453SEric Joyner 
33*71d10453SEric Joyner /**
34*71d10453SEric Joyner  * @file ice_resmgr.h
35*71d10453SEric Joyner  * @brief Resource manager interface
36*71d10453SEric Joyner  *
37*71d10453SEric Joyner  * Defines an interface for managing PF hardware queues and interrupts for assigning them to
38*71d10453SEric Joyner  * hardware VSIs and VFs.
39*71d10453SEric Joyner  *
40*71d10453SEric Joyner  * For queue management:
41*71d10453SEric Joyner  * The total number of available Tx and Rx queues is not equal, so it is
42*71d10453SEric Joyner  * expected that each PF will allocate two ice_resmgr structures, one for Tx
43*71d10453SEric Joyner  * and one for Rx. These should be allocated in attach() prior to initializing
44*71d10453SEric Joyner  * VSIs, and destroyed in detach().
45*71d10453SEric Joyner  *
46*71d10453SEric Joyner  * For interrupt management:
47*71d10453SEric Joyner  * The PF allocates an ice_resmgr structure that does not allow scattered
48*71d10453SEric Joyner  * allocations since interrupt allocations must be contiguous.
49*71d10453SEric Joyner  */
50*71d10453SEric Joyner 
51*71d10453SEric Joyner #ifndef _ICE_RESMGR_H_
52*71d10453SEric Joyner #define _ICE_RESMGR_H_
53*71d10453SEric Joyner #include <sys/param.h>
54*71d10453SEric Joyner #include "ice_osdep.h"
55*71d10453SEric Joyner 
56*71d10453SEric Joyner #include <sys/bitstring.h>
57*71d10453SEric Joyner 
58*71d10453SEric Joyner /*
59*71d10453SEric Joyner  * For managing VSI queue allocations
60*71d10453SEric Joyner  */
61*71d10453SEric Joyner /* Hardware only supports a limited number of resources in scattered mode */
62*71d10453SEric Joyner #define ICE_MAX_SCATTERED_QUEUES	16
63*71d10453SEric Joyner /* Use highest value to indicate invalid resource mapping */
64*71d10453SEric Joyner #define ICE_INVALID_RES_IDX		0xFFFF
65*71d10453SEric Joyner 
66*71d10453SEric Joyner /*
67*71d10453SEric Joyner  * Structures
68*71d10453SEric Joyner  */
69*71d10453SEric Joyner 
70*71d10453SEric Joyner /**
71*71d10453SEric Joyner  * @struct ice_resmgr
72*71d10453SEric Joyner  * @brief Resource manager
73*71d10453SEric Joyner  *
74*71d10453SEric Joyner  * Represent resource allocations using a bitstring, where bit zero represents
75*71d10453SEric Joyner  * the first resource. If a particular bit is set this indicates that the
76*71d10453SEric Joyner  * resource has been allocated and is not free.
77*71d10453SEric Joyner  */
78*71d10453SEric Joyner struct ice_resmgr {
79*71d10453SEric Joyner 	bitstr_t	*resources;
80*71d10453SEric Joyner 	u16		num_res;
81*71d10453SEric Joyner 	bool		contig_only;
82*71d10453SEric Joyner };
83*71d10453SEric Joyner 
84*71d10453SEric Joyner /**
85*71d10453SEric Joyner  * @enum ice_resmgr_alloc_type
86*71d10453SEric Joyner  * @brief resource manager allocation types
87*71d10453SEric Joyner  *
88*71d10453SEric Joyner  * Enumeration of possible allocation types that can be used when
89*71d10453SEric Joyner  * assigning resources. For now, SCATTERED is only used with
90*71d10453SEric Joyner  * managing queue allocations.
91*71d10453SEric Joyner  */
92*71d10453SEric Joyner enum ice_resmgr_alloc_type {
93*71d10453SEric Joyner 	ICE_RESMGR_ALLOC_INVALID = 0,
94*71d10453SEric Joyner 	ICE_RESMGR_ALLOC_CONTIGUOUS,
95*71d10453SEric Joyner 	ICE_RESMGR_ALLOC_SCATTERED
96*71d10453SEric Joyner };
97*71d10453SEric Joyner 
98*71d10453SEric Joyner /* Public resource manager allocation functions */
99*71d10453SEric Joyner int	ice_resmgr_init(struct ice_resmgr *resmgr, u16 num_res);
100*71d10453SEric Joyner int	ice_resmgr_init_contig_only(struct ice_resmgr *resmgr, u16 num_res);
101*71d10453SEric Joyner void	ice_resmgr_destroy(struct ice_resmgr *resmgr);
102*71d10453SEric Joyner 
103*71d10453SEric Joyner /* Public resource assignment functions */
104*71d10453SEric Joyner int	ice_resmgr_assign_contiguous(struct ice_resmgr *resmgr, u16 *idx, u16 num_res);
105*71d10453SEric Joyner int	ice_resmgr_assign_scattered(struct ice_resmgr *resmgr, u16 *idx, u16 num_res);
106*71d10453SEric Joyner 
107*71d10453SEric Joyner /* Release resources */
108*71d10453SEric Joyner void	ice_resmgr_release_map(struct ice_resmgr *resmgr, u16 *idx, u16 num_res);
109*71d10453SEric Joyner 
110*71d10453SEric Joyner #endif /* _ICE_RESMGR_H_ */
111*71d10453SEric Joyner 
112