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