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