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