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 /* API supported for control queue management */ 158 /* Will init all required q including default mb. "q_info" is an array of 159 * create_info structs equal to the number of control queues to be created. 160 */ 161 int idpf_ctlq_init(struct idpf_hw *hw, u8 num_q, 162 struct idpf_ctlq_create_info *q_info); 163 164 /* Allocate and initialize a single control queue, which will be added to the 165 * control queue list; returns a handle to the created control queue 166 */ 167 int idpf_ctlq_add(struct idpf_hw *hw, 168 struct idpf_ctlq_create_info *qinfo, 169 struct idpf_ctlq_info **cq); 170 171 /* Deinitialize and deallocate a single control queue */ 172 void idpf_ctlq_remove(struct idpf_hw *hw, 173 struct idpf_ctlq_info *cq); 174 175 /* Sends messages to HW and will also free the buffer*/ 176 int idpf_ctlq_send(struct idpf_hw *hw, 177 struct idpf_ctlq_info *cq, 178 u16 num_q_msg, 179 struct idpf_ctlq_msg q_msg[]); 180 181 /* Receives messages and called by interrupt handler/polling 182 * initiated by app/process. Also caller is supposed to free the buffers 183 */ 184 int idpf_ctlq_recv(struct idpf_ctlq_info *cq, u16 *num_q_msg, 185 struct idpf_ctlq_msg *q_msg); 186 187 /* Reclaims all descriptors on HW write back */ 188 int idpf_ctlq_clean_sq_force(struct idpf_ctlq_info *cq, u16 *clean_count, 189 struct idpf_ctlq_msg *msg_status[]); 190 191 /* Reclaims send descriptors on HW write back */ 192 int idpf_ctlq_clean_sq(struct idpf_ctlq_info *cq, u16 *clean_count, 193 struct idpf_ctlq_msg *msg_status[]); 194 195 /* Indicate RX buffers are done being processed */ 196 int idpf_ctlq_post_rx_buffs(struct idpf_hw *hw, 197 struct idpf_ctlq_info *cq, 198 u16 *buff_count, 199 struct idpf_dma_mem **buffs); 200 201 /* Will destroy all q including the default mb */ 202 void idpf_ctlq_deinit(struct idpf_hw *hw); 203 204 #endif /* _IDPF_CONTROLQ_API_H_ */ 205