1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2001-2022 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 struct { 67 u32 chnl_retval; 68 u32 chnl_opcode; 69 } mbx; 70 } cookie; 71 union { 72 #define IDPF_DIRECT_CTX_SIZE 16 73 #define IDPF_INDIRECT_CTX_SIZE 8 74 /* 16 bytes of context can be provided or 8 bytes of context 75 * plus the address of a DMA buffer 76 */ 77 u8 direct[IDPF_DIRECT_CTX_SIZE]; 78 struct { 79 u8 context[IDPF_INDIRECT_CTX_SIZE]; 80 struct idpf_dma_mem *payload; 81 } indirect; 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 /* 158 * API supported for control queue management 159 */ 160 161 /* Will init all required q including default mb. "q_info" is an array of 162 * create_info structs equal to the number of control queues to be created. 163 */ 164 int idpf_ctlq_init(struct idpf_hw *hw, u8 num_q, 165 struct idpf_ctlq_create_info *q_info); 166 167 /* Allocate and initialize a single control queue, which will be added to the 168 * control queue list; returns a handle to the created control queue 169 */ 170 int idpf_ctlq_add(struct idpf_hw *hw, 171 struct idpf_ctlq_create_info *qinfo, 172 struct idpf_ctlq_info **cq); 173 174 /* Deinitialize and deallocate a single control queue */ 175 void idpf_ctlq_remove(struct idpf_hw *hw, 176 struct idpf_ctlq_info *cq); 177 178 /* Sends messages to HW and will also free the buffer*/ 179 int idpf_ctlq_send(struct idpf_hw *hw, 180 struct idpf_ctlq_info *cq, 181 u16 num_q_msg, 182 struct idpf_ctlq_msg q_msg[]); 183 184 /* Receives messages and called by interrupt handler/polling 185 * initiated by app/process. Also caller is supposed to free the buffers 186 */ 187 int idpf_ctlq_recv(struct idpf_ctlq_info *cq, u16 *num_q_msg, 188 struct idpf_ctlq_msg *q_msg); 189 190 /* Reclaims send descriptors on HW write back */ 191 int idpf_ctlq_clean_sq(struct idpf_ctlq_info *cq, u16 *clean_count, 192 struct idpf_ctlq_msg *msg_status[]); 193 194 /* Indicate RX buffers are done being processed */ 195 int idpf_ctlq_post_rx_buffs(struct idpf_hw *hw, 196 struct idpf_ctlq_info *cq, 197 u16 *buff_count, 198 struct idpf_dma_mem **buffs); 199 200 /* Will destroy all q including the default mb */ 201 int idpf_ctlq_deinit(struct idpf_hw *hw); 202 203 #endif /* _IDPF_CONTROLQ_API_H_ */ 204