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