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