xref: /freebsd/sys/dev/ice/ice_controlq.h (revision 2dccd21949f26b1bdf5e7cf258b760fffd3bf259)
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 #ifndef _ICE_CONTROLQ_H_
33 #define _ICE_CONTROLQ_H_
34 
35 #include "ice_adminq_cmd.h"
36 
37 /* Maximum buffer lengths for all control queue types */
38 #define ICE_AQ_MAX_BUF_LEN 4096
39 #define ICE_MBXQ_MAX_BUF_LEN 4096
40 #define ICE_SBQ_MAX_BUF_LEN 512
41 
42 #define ICE_CTL_Q_DESC(R, i) \
43 	(&(((struct ice_aq_desc *)((R).desc_buf.va))[i]))
44 
45 #define ICE_CTL_Q_DESC_UNUSED(R) \
46 	((u16)((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
47 	       (R)->next_to_clean - (R)->next_to_use - 1))
48 
49 /* Defines that help manage the driver vs FW API checks.
50  * Take a look at ice_aq_ver_check in ice_controlq.c for actual usage.
51  */
52 #define EXP_FW_API_VER_BRANCH_E830	0x00
53 #define EXP_FW_API_VER_MAJOR_E830	0x01
54 #define EXP_FW_API_VER_MINOR_E830	0x07
55 
56 #define EXP_FW_API_VER_BRANCH_E810	0x00
57 #define EXP_FW_API_VER_MAJOR_E810	0x01
58 #define EXP_FW_API_VER_MINOR_E810	0x05
59 
60 #define EXP_FW_API_VER_BRANCH_BY_MAC(hw) ((hw)->mac_type == ICE_MAC_E830 ? \
61 			EXP_FW_API_VER_BRANCH_E830 : \
62 			EXP_FW_API_VER_BRANCH_E810)
63 
64 #define EXP_FW_API_VER_MAJOR_BY_MAC(hw) ((hw)->mac_type == ICE_MAC_E830 ? \
65 			EXP_FW_API_VER_MAJOR_E830 : \
66 			EXP_FW_API_VER_MAJOR_E810)
67 
68 #define EXP_FW_API_VER_MINOR_BY_MAC(hw) ((hw)->mac_type == ICE_MAC_E830 ? \
69 			EXP_FW_API_VER_MINOR_E830 : \
70 			EXP_FW_API_VER_MINOR_E810)
71 
72 /* Different control queue types: These are mainly for SW consumption. */
73 enum ice_ctl_q {
74 	ICE_CTL_Q_UNKNOWN = 0,
75 	ICE_CTL_Q_ADMIN,
76 	ICE_CTL_Q_MAILBOX,
77 	ICE_CTL_Q_SB,
78 };
79 
80 /* Control Queue timeout settings - max delay 1s */
81 #define ICE_CTL_Q_SQ_CMD_TIMEOUT	100000	/* Count 100000 times */
82 #define ICE_CTL_Q_ADMIN_INIT_TIMEOUT	10    /* Count 10 times */
83 #define ICE_CTL_Q_ADMIN_INIT_MSEC	100   /* Check every 100msec */
84 
85 struct ice_ctl_q_ring {
86 	void *dma_head;			/* Virtual address to DMA head */
87 	struct ice_dma_mem desc_buf;	/* descriptor ring memory */
88 
89 	union {
90 		struct ice_dma_mem *sq_bi;
91 		struct ice_dma_mem *rq_bi;
92 	} r;
93 
94 	u16 count;		/* Number of descriptors */
95 
96 	/* used for interrupt processing */
97 	u16 next_to_use;
98 	u16 next_to_clean;
99 
100 	/* used for queue tracking */
101 	u32 head;
102 	u32 tail;
103 	u32 len;
104 	u32 bah;
105 	u32 bal;
106 	u32 len_mask;
107 	u32 len_ena_mask;
108 	u32 len_crit_mask;
109 	u32 head_mask;
110 };
111 
112 /* sq transaction details */
113 struct ice_sq_cd {
114 	struct ice_aq_desc *wb_desc;
115 };
116 
117 /* rq event information */
118 struct ice_rq_event_info {
119 	struct ice_aq_desc desc;
120 	u16 msg_len;
121 	u16 buf_len;
122 	u8 *msg_buf;
123 };
124 
125 /* Control Queue information */
126 struct ice_ctl_q_info {
127 	enum ice_ctl_q qtype;
128 	struct ice_ctl_q_ring rq;	/* receive queue */
129 	struct ice_ctl_q_ring sq;	/* send queue */
130 	u32 sq_cmd_timeout;		/* send queue cmd write back timeout */
131 	u16 num_rq_entries;		/* receive queue depth */
132 	u16 num_sq_entries;		/* send queue depth */
133 	u16 rq_buf_size;		/* receive queue buffer size */
134 	u16 sq_buf_size;		/* send queue buffer size */
135 	enum ice_aq_err sq_last_status;	/* last status on send queue */
136 	struct ice_lock sq_lock;		/* Send queue lock */
137 	struct ice_lock rq_lock;		/* Receive queue lock */
138 };
139 
140 #endif /* _ICE_CONTROLQ_H_ */
141