xref: /freebsd/sys/dev/ixl/ixl_pf_qmgr.h (revision cbd30a72ca196976c1c700400ecd424baa1b9c16)
1 /******************************************************************************
2 
3   Copyright (c) 2013-2015, 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 	bool allocated;
57 	bool tx_enabled;
58 	bool rx_enabled;
59 	bool tx_configured;
60 	bool 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 	u16 qidx[IXL_MAX_SCATTERED_QUEUES];
78 	u16 num_allocated;
79 	u16 num_active;
80 };
81 
82 /* Public manager functions */
83 int	ixl_pf_qmgr_init(struct ixl_pf_qmgr *qmgr, u16 num_queues);
84 void	ixl_pf_qmgr_destroy(struct ixl_pf_qmgr *qmgr);
85 
86 int	ixl_pf_qmgr_get_num_queues(struct ixl_pf_qmgr *qmgr);
87 int	ixl_pf_qmgr_get_first_free(struct ixl_pf_qmgr *qmgr, u16 start);
88 int	ixl_pf_qmgr_get_num_free(struct ixl_pf_qmgr *qmgr);
89 
90 /* Allocate queues for a VF VSI */
91 int	ixl_pf_qmgr_alloc_scattered(struct ixl_pf_qmgr *qmgr, u16 num, struct ixl_pf_qtag *qtag);
92 /* Allocate queues for the LAN VSIs, or X722 VF VSIs */
93 int	ixl_pf_qmgr_alloc_contiguous(struct ixl_pf_qmgr *qmgr, u16 num, struct ixl_pf_qtag *qtag);
94 /* Release a queue allocation */
95 int	ixl_pf_qmgr_release(struct ixl_pf_qmgr *qmgr, struct ixl_pf_qtag *qtag);
96 
97 /* Help manage queues used in VFs */
98 /* Typically hardware refers to RX as 0 and TX as 1, so continue that convention here */
99 void	ixl_pf_qmgr_mark_queue_enabled(struct ixl_pf_qtag *qtag, u16 vsi_qidx, bool tx);
100 void	ixl_pf_qmgr_mark_queue_disabled(struct ixl_pf_qtag *qtag, u16 vsi_qidx, bool tx);
101 void	ixl_pf_qmgr_mark_queue_configured(struct ixl_pf_qtag *qtag, u16 vsi_qidx, bool tx);
102 bool	ixl_pf_qmgr_is_queue_enabled(struct ixl_pf_qtag *qtag, u16 vsi_qidx, bool tx);
103 bool	ixl_pf_qmgr_is_queue_configured(struct ixl_pf_qtag *qtag, u16 vsi_qidx, bool tx);
104 
105 /* Public tag functions */
106 u16	ixl_pf_qidx_from_vsi_qidx(struct ixl_pf_qtag *qtag, u16 index);
107 
108 #endif /* _IXL_PF_QMGR_H_ */
109 
110