xref: /dpdk/drivers/common/idpf/base/idpf_controlq_api.h (revision 9510c5f874f652fcaa3cc6e6d9bce2c0f834a1d2)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2023 Intel Corporation
3  */
4 
5 #ifndef _IDPF_CONTROLQ_API_H_
6 #define _IDPF_CONTROLQ_API_H_
7 
8 #include "idpf_osdep.h"
9 
10 struct idpf_hw;
11 
12 /* Used for queue init, response and events */
13 enum idpf_ctlq_type {
14 	IDPF_CTLQ_TYPE_MAILBOX_TX	= 0,
15 	IDPF_CTLQ_TYPE_MAILBOX_RX	= 1,
16 	IDPF_CTLQ_TYPE_CONFIG_TX	= 2,
17 	IDPF_CTLQ_TYPE_CONFIG_RX	= 3,
18 	IDPF_CTLQ_TYPE_EVENT_RX		= 4,
19 	IDPF_CTLQ_TYPE_RDMA_TX		= 5,
20 	IDPF_CTLQ_TYPE_RDMA_RX		= 6,
21 	IDPF_CTLQ_TYPE_RDMA_COMPL	= 7
22 };
23 
24 /* Generic Control Queue Structures */
25 struct idpf_ctlq_reg {
26 	/* used for queue tracking */
27 	u32 head;
28 	u32 tail;
29 	/* Below applies only to default mb (if present) */
30 	u32 len;
31 	u32 bah;
32 	u32 bal;
33 	u32 len_mask;
34 	u32 len_ena_mask;
35 	u32 head_mask;
36 };
37 
38 /* Generic queue msg structure */
39 struct idpf_ctlq_msg {
40 	u8 vmvf_type; /* represents the source of the message on recv */
41 #define IDPF_VMVF_TYPE_VF 0
42 #define IDPF_VMVF_TYPE_VM 1
43 #define IDPF_VMVF_TYPE_PF 2
44 	u8 host_id;
45 	/* 3b field used only when sending a message to peer - to be used in
46 	 * combination with target func_id to route the message
47 	 */
48 #define IDPF_HOST_ID_MASK 0x7
49 
50 	u16 opcode;
51 	u16 data_len;	/* data_len = 0 when no payload is attached */
52 	union {
53 		u16 func_id;	/* when sending a message */
54 		u16 status;	/* when receiving a message */
55 	};
56 	union {
57 #ifndef __KERNEL__
58 #define FILL_OPCODE_V1(msg, opcode) ((msg).cookie.cfg.mbx.chnl_opcode = opcode)
59 #define FILL_RETVAL_V1(msg, retval) ((msg).cookie.cfg.mbx.chnl_retval = retval)
60 #endif /* __KERNEL__ */
61 		struct {
62 			u32 chnl_opcode;
63 			u32 chnl_retval;
64 		} mbx;
65 	} cookie;
66 	union {
67 #define IDPF_DIRECT_CTX_SIZE	16
68 #define IDPF_INDIRECT_CTX_SIZE	8
69 		/* 16 bytes of context can be provided or 8 bytes of context
70 		 * plus the address of a DMA buffer
71 		 */
72 		u8 direct[IDPF_DIRECT_CTX_SIZE];
73 		struct {
74 			u8 context[IDPF_INDIRECT_CTX_SIZE];
75 			struct idpf_dma_mem *payload;
76 		} indirect;
77 		struct {
78 			u32 rsvd;
79 			u16 data;
80 			u16 flags;
81 		} sw_cookie;
82 	} ctx;
83 };
84 
85 /* Generic queue info structures */
86 /* MB, CONFIG and EVENT q do not have extended info */
87 struct idpf_ctlq_create_info {
88 	enum idpf_ctlq_type type;
89 	int id; /* absolute queue offset passed as input
90 		 * -1 for default mailbox if present
91 		 */
92 	u16 len; /* Queue length passed as input */
93 	u16 buf_size; /* buffer size passed as input */
94 	u64 base_address; /* output, HPA of the Queue start  */
95 	struct idpf_ctlq_reg reg; /* registers accessed by ctlqs */
96 
97 	int ext_info_size;
98 	void *ext_info; /* Specific to q type */
99 };
100 
101 /* Control Queue information */
102 struct idpf_ctlq_info {
103 	LIST_ENTRY_TYPE(idpf_ctlq_info) cq_list;
104 
105 	enum idpf_ctlq_type cq_type;
106 	int q_id;
107 	idpf_lock cq_lock;		/* queue lock
108 					 * idpf_lock is defined in OSdep.h
109 					 */
110 	/* used for interrupt processing */
111 	u16 next_to_use;
112 	u16 next_to_clean;
113 	u16 next_to_post;		/* starting descriptor to post buffers
114 					 * to after recev
115 					 */
116 
117 	struct idpf_dma_mem desc_ring;	/* descriptor ring memory
118 					 * idpf_dma_mem is defined in OSdep.h
119 					 */
120 	union {
121 		struct idpf_dma_mem **rx_buff;
122 		struct idpf_ctlq_msg **tx_msg;
123 	} bi;
124 
125 	u16 buf_size;			/* queue buffer size */
126 	u16 ring_size;			/* Number of descriptors */
127 	struct idpf_ctlq_reg reg;	/* registers accessed by ctlqs */
128 };
129 
130 /* PF/VF mailbox commands */
131 enum idpf_mbx_opc {
132 	/* idpf_mbq_opc_send_msg_to_pf:
133 	 *	usage: used by PF or VF to send a message to its CPF
134 	 *	target: RX queue and function ID of parent PF taken from HW
135 	 */
136 	idpf_mbq_opc_send_msg_to_pf		= 0x0801,
137 
138 	/* idpf_mbq_opc_send_msg_to_vf:
139 	 *	usage: used by PF to send message to a VF
140 	 *	target: VF control queue ID must be specified in descriptor
141 	 */
142 	idpf_mbq_opc_send_msg_to_vf		= 0x0802,
143 
144 	/* idpf_mbq_opc_send_msg_to_peer_pf:
145 	 *	usage: used by any function to send message to any peer PF
146 	 *	target: RX queue and host of parent PF taken from HW
147 	 */
148 	idpf_mbq_opc_send_msg_to_peer_pf	= 0x0803,
149 
150 	/* idpf_mbq_opc_send_msg_to_peer_drv:
151 	 *	usage: used by any function to send message to any peer driver
152 	 *	target: RX queue and target host must be specific in descriptor
153 	 */
154 	idpf_mbq_opc_send_msg_to_peer_drv	= 0x0804,
155 };
156 
157 /* Define the APF hardware struct to replace other control structs as needed
158  * Align to ctlq_hw_info
159  */
160 struct idpf_hw {
161 	/* Some part of BAR0 address space is not mapped by the LAN driver.
162 	 * This results in 2 regions of BAR0 to be mapped by LAN driver which
163 	 * will have its own base hardware address when mapped.
164 	 */
165 	u8 *hw_addr;
166 	u8 *hw_addr_region2;
167 	u64 hw_addr_len;
168 	u64 hw_addr_region2_len;
169 
170 	void *back;
171 
172 	/* control queue - send and receive */
173 	struct idpf_ctlq_info *asq;
174 	struct idpf_ctlq_info *arq;
175 
176 	/* subsystem structs */
177 	struct idpf_mac_info mac;
178 	struct idpf_bus_info bus;
179 	struct idpf_hw_func_caps func_caps;
180 
181 	/* pci info */
182 	u16 device_id;
183 	u16 vendor_id;
184 	u16 subsystem_device_id;
185 	u16 subsystem_vendor_id;
186 	u8 revision_id;
187 	bool adapter_stopped;
188 
189 	LIST_HEAD_TYPE(list_head, idpf_ctlq_info) cq_list_head;
190 };
191 
192 /* API supported for control queue management */
193 /* Will init all required q including default mb.  "q_info" is an array of
194  * create_info structs equal to the number of control queues to be created.
195  */
196 int idpf_ctlq_init(struct idpf_hw *hw, u8 num_q,
197 		   struct idpf_ctlq_create_info *q_info);
198 
199 /* Allocate and initialize a single control queue, which will be added to the
200  * control queue list; returns a handle to the created control queue
201  */
202 int idpf_ctlq_add(struct idpf_hw *hw,
203 		  struct idpf_ctlq_create_info *qinfo,
204 		  struct idpf_ctlq_info **cq);
205 
206 /* Deinitialize and deallocate a single control queue */
207 void idpf_ctlq_remove(struct idpf_hw *hw,
208 		      struct idpf_ctlq_info *cq);
209 
210 /* Sends messages to HW and will also free the buffer*/
211 int idpf_ctlq_send(struct idpf_hw *hw,
212 		   struct idpf_ctlq_info *cq,
213 		   u16 num_q_msg,
214 		   struct idpf_ctlq_msg q_msg[]);
215 
216 /* Receives messages and called by interrupt handler/polling
217  * initiated by app/process. Also caller is supposed to free the buffers
218  */
219 int idpf_ctlq_recv(struct idpf_ctlq_info *cq, u16 *num_q_msg,
220 		   struct idpf_ctlq_msg *q_msg);
221 
222 /* Reclaims all descriptors on HW write back */
223 int idpf_ctlq_clean_sq_force(struct idpf_ctlq_info *cq, u16 *clean_count,
224 			     struct idpf_ctlq_msg *msg_status[]);
225 
226 /* Reclaims send descriptors on HW write back */
227 int idpf_ctlq_clean_sq(struct idpf_ctlq_info *cq, u16 *clean_count,
228 		       struct idpf_ctlq_msg *msg_status[]);
229 
230 /* Indicate RX buffers are done being processed */
231 int idpf_ctlq_post_rx_buffs(struct idpf_hw *hw,
232 			    struct idpf_ctlq_info *cq,
233 			    u16 *buff_count,
234 			    struct idpf_dma_mem **buffs);
235 
236 /* Will destroy all q including the default mb */
237 void idpf_ctlq_deinit(struct idpf_hw *hw);
238 
239 #endif /* _IDPF_CONTROLQ_API_H_ */
240