xref: /freebsd/sys/dev/ixl/ixl_pf_qmgr.h (revision 8881d206f4e68b564c2c5f50fc717086fc3e827a)
1 /******************************************************************************
2 
3   Copyright (c) 2013-2018, Intel Corporation
4   All rights reserved.
5 
6   Redistribution and use in source and binary forms, with or without
7   modification, are permitted provided that the following conditions are met:
8 
9    1. Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11 
12    2. Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in the
14       documentation and/or other materials provided with the distribution.
15 
16    3. Neither the name of the Intel Corporation nor the names of its
17       contributors may be used to endorse or promote products derived from
18       this software without specific prior written permission.
19 
20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   POSSIBILITY OF SUCH DAMAGE.
31 
32 ******************************************************************************/
33 /*$FreeBSD$*/
34 
35 
36 #include "ixl_pf.h"
37 
38 #ifndef _IXL_PF_QMGR_H_
39 #define _IXL_PF_QMGR_H_
40 
41 /*
42  * Primarily manages the queues that need to be allocated to VSIs.
43  *
44  * Cardinality: There should only be one of these in a PF.
45  * Lifetime: Created and initialized in attach(); destroyed in detach().
46  */
47 
48 #define IXL_MAX_SCATTERED_QUEUES	16
49 #define IXL_MAX_CONTIGUOUS_QUEUES_XL710	64
50 #define IXL_MAX_CONTIGUOUS_QUEUES_X722	128
51 
52 /* Structures */
53 
54 /* Manager */
55 struct ixl_pf_qmgr_qinfo {
56 	u8 allocated;
57 	u8 tx_enabled;
58 	u8 rx_enabled;
59 	u8 tx_configured;
60 	u8 rx_configured;
61 };
62 
63 struct ixl_pf_qmgr {
64 	u16	num_queues;
65 	struct ixl_pf_qmgr_qinfo *qinfo;
66 };
67 
68 /* Tag */
69 enum ixl_pf_qmgr_qalloc_type {
70 	IXL_PF_QALLOC_CONTIGUOUS,
71 	IXL_PF_QALLOC_SCATTERED
72 };
73 
74 struct ixl_pf_qtag {
75 	struct ixl_pf_qmgr *qmgr;
76 	enum ixl_pf_qmgr_qalloc_type type;
77 	union {
78 		u16 qidx[IXL_MAX_SCATTERED_QUEUES];
79 		u16 first_qidx;
80 	};
81 	u16 num_allocated;
82 	u16 num_active;
83 };
84 
85 /* Public manager functions */
86 int	ixl_pf_qmgr_init(struct ixl_pf_qmgr *qmgr, u16 num_queues);
87 void	ixl_pf_qmgr_destroy(struct ixl_pf_qmgr *qmgr);
88 
89 int	ixl_pf_qmgr_get_num_queues(struct ixl_pf_qmgr *qmgr);
90 int	ixl_pf_qmgr_get_first_free(struct ixl_pf_qmgr *qmgr, u16 start);
91 int	ixl_pf_qmgr_get_num_free(struct ixl_pf_qmgr *qmgr);
92 
93 /* Allocate queues for a VF VSI */
94 int	ixl_pf_qmgr_alloc_scattered(struct ixl_pf_qmgr *qmgr, u16 num, struct ixl_pf_qtag *qtag);
95 /* Allocate queues for the LAN VSIs, or X722 VF VSIs */
96 int	ixl_pf_qmgr_alloc_contiguous(struct ixl_pf_qmgr *qmgr, u16 num, struct ixl_pf_qtag *qtag);
97 /* Release a queue allocation */
98 int	ixl_pf_qmgr_release(struct ixl_pf_qmgr *qmgr, struct ixl_pf_qtag *qtag);
99 
100 /* Help manage queues used in VFs */
101 /* Typically hardware refers to RX as 0 and TX as 1, so continue that convention here */
102 void	ixl_pf_qmgr_mark_queue_enabled(struct ixl_pf_qtag *qtag, u16 vsi_qidx, bool tx);
103 void	ixl_pf_qmgr_mark_queue_disabled(struct ixl_pf_qtag *qtag, u16 vsi_qidx, bool tx);
104 void	ixl_pf_qmgr_mark_queue_configured(struct ixl_pf_qtag *qtag, u16 vsi_qidx, bool tx);
105 bool	ixl_pf_qmgr_is_queue_enabled(struct ixl_pf_qtag *qtag, u16 vsi_qidx, bool tx);
106 bool	ixl_pf_qmgr_is_queue_configured(struct ixl_pf_qtag *qtag, u16 vsi_qidx, bool tx);
107 void	ixl_pf_qmgr_clear_queue_flags(struct ixl_pf_qtag *qtag);
108 
109 /* Public tag functions */
110 u16	ixl_pf_qidx_from_vsi_qidx(struct ixl_pf_qtag *qtag, u16 index);
111 
112 #endif /* _IXL_PF_QMGR_H_ */
113 
114