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