1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2016 - 2018 Cavium Inc. 3 * All rights reserved. 4 * www.cavium.com 5 */ 6 7 #ifndef __ECORE_SPQ_H__ 8 #define __ECORE_SPQ_H__ 9 10 #include "ecore_hsi_common.h" 11 #include "ecore_status.h" 12 #include "ecore_hsi_eth.h" 13 #include "ecore_chain.h" 14 #include "ecore_sp_api.h" 15 16 union ramrod_data { 17 struct pf_start_ramrod_data pf_start; 18 struct pf_update_ramrod_data pf_update; 19 struct rl_update_ramrod_data rl_update; 20 struct rx_queue_start_ramrod_data rx_queue_start; 21 struct rx_queue_update_ramrod_data rx_queue_update; 22 struct rx_queue_stop_ramrod_data rx_queue_stop; 23 struct tx_queue_start_ramrod_data tx_queue_start; 24 struct tx_queue_stop_ramrod_data tx_queue_stop; 25 struct vport_start_ramrod_data vport_start; 26 struct vport_stop_ramrod_data vport_stop; 27 struct rx_update_gft_filter_data rx_update_gft; 28 struct vport_update_ramrod_data vport_update; 29 struct core_rx_start_ramrod_data core_rx_queue_start; 30 struct core_rx_stop_ramrod_data core_rx_queue_stop; 31 struct core_tx_start_ramrod_data core_tx_queue_start; 32 struct core_tx_stop_ramrod_data core_tx_queue_stop; 33 struct vport_filter_update_ramrod_data vport_filter_update; 34 35 struct vf_start_ramrod_data vf_start; 36 struct vf_stop_ramrod_data vf_stop; 37 }; 38 39 #define EQ_MAX_CREDIT 0xffffffff 40 41 enum spq_priority { 42 ECORE_SPQ_PRIORITY_NORMAL, 43 ECORE_SPQ_PRIORITY_HIGH, 44 }; 45 46 union ecore_spq_req_comp { 47 struct ecore_spq_comp_cb cb; 48 u64 *done_addr; 49 }; 50 51 /* SPQ_MODE_EBLOCK */ 52 struct ecore_spq_comp_done { 53 u64 done; 54 u8 fw_return_code; 55 }; 56 57 struct ecore_spq_entry { 58 osal_list_entry_t list; 59 60 u8 flags; 61 62 /* HSI slow path element */ 63 struct slow_path_element elem; 64 65 union ramrod_data ramrod; 66 67 enum spq_priority priority; 68 69 /* pending queue for this entry */ 70 osal_list_t *queue; 71 72 enum spq_mode comp_mode; 73 struct ecore_spq_comp_cb comp_cb; 74 struct ecore_spq_comp_done comp_done; /* SPQ_MODE_EBLOCK */ 75 }; 76 77 struct ecore_eq { 78 struct ecore_chain chain; 79 u8 eq_sb_index; /* index within the SB */ 80 __le16 *p_fw_cons; /* ptr to index value */ 81 }; 82 83 struct ecore_consq { 84 struct ecore_chain chain; 85 }; 86 87 typedef enum _ecore_status_t 88 (*ecore_spq_async_comp_cb)(struct ecore_hwfn *p_hwfn, 89 u8 opcode, 90 u16 echo, 91 union event_ring_data *data, 92 u8 fw_return_code); 93 94 enum _ecore_status_t 95 ecore_spq_register_async_cb(struct ecore_hwfn *p_hwfn, 96 enum protocol_type protocol_id, 97 ecore_spq_async_comp_cb cb); 98 99 void 100 ecore_spq_unregister_async_cb(struct ecore_hwfn *p_hwfn, 101 enum protocol_type protocol_id); 102 103 struct ecore_spq { 104 osal_spinlock_t lock; 105 106 osal_list_t unlimited_pending; 107 osal_list_t pending; 108 osal_list_t completion_pending; 109 osal_list_t free_pool; 110 111 struct ecore_chain chain; 112 113 /* allocated dma-able memory for spq entries (+ramrod data) */ 114 dma_addr_t p_phys; 115 struct ecore_spq_entry *p_virt; 116 117 /* SPQ max sleep iterations used in __ecore_spq_block() */ 118 u32 block_sleep_max_iter; 119 120 /* Bitmap for handling out-of-order completions */ 121 #define SPQ_RING_SIZE \ 122 (CORE_SPQE_PAGE_SIZE_BYTES / sizeof(struct slow_path_element)) 123 /* BITS_PER_LONG */ 124 #define SPQ_COMP_BMAP_SIZE (SPQ_RING_SIZE / (sizeof(u32) * 8)) 125 u32 p_comp_bitmap[SPQ_COMP_BMAP_SIZE]; 126 u8 comp_bitmap_idx; 127 #define SPQ_COMP_BMAP_SET_BIT(p_spq, idx) \ 128 (OSAL_SET_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap)) 129 130 #define SPQ_COMP_BMAP_CLEAR_BIT(p_spq, idx) \ 131 (OSAL_CLEAR_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap)) 132 133 #define SPQ_COMP_BMAP_GET_BIT(p_spq, idx) \ 134 (OSAL_GET_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap)) 135 136 /* Statistics */ 137 u32 unlimited_pending_count; 138 u32 normal_count; 139 u32 high_count; 140 u32 comp_sent_count; 141 u32 comp_count; 142 143 u32 cid; 144 145 u32 db_addr_offset; 146 struct core_db_data db_data; 147 ecore_spq_async_comp_cb async_comp_cb[MAX_PROTOCOL_TYPE]; 148 }; 149 150 struct ecore_port; 151 struct ecore_hwfn; 152 153 /** 154 * @brief ecore_set_spq_block_timeout - calculates the maximum sleep 155 * iterations used in __ecore_spq_block(); 156 * 157 * @param p_hwfn 158 * @param spq_timeout_ms 159 */ 160 void ecore_set_spq_block_timeout(struct ecore_hwfn *p_hwfn, 161 u32 spq_timeout_ms); 162 163 /** 164 * @brief ecore_spq_post - Posts a Slow hwfn request to FW, or lacking that 165 * Pends it to the future list. 166 * 167 * @param p_hwfn 168 * @param p_req 169 * 170 * @return enum _ecore_status_t 171 */ 172 enum _ecore_status_t ecore_spq_post(struct ecore_hwfn *p_hwfn, 173 struct ecore_spq_entry *p_ent, 174 u8 *fw_return_code); 175 176 /** 177 * @brief ecore_spq_allocate - Alloocates & initializes the SPQ and EQ. 178 * 179 * @param p_hwfn 180 * 181 * @return enum _ecore_status_t 182 */ 183 enum _ecore_status_t ecore_spq_alloc(struct ecore_hwfn *p_hwfn); 184 185 /** 186 * @brief ecore_spq_setup - Reset the SPQ to its start state. 187 * 188 * @param p_hwfn 189 */ 190 void ecore_spq_setup(struct ecore_hwfn *p_hwfn); 191 192 /** 193 * @brief ecore_spq_deallocate - Deallocates the given SPQ struct. 194 * 195 * @param p_hwfn 196 */ 197 void ecore_spq_free(struct ecore_hwfn *p_hwfn); 198 199 /** 200 * @brief ecore_spq_get_entry - Obtain an entrry from the spq 201 * free pool list. 202 * 203 * 204 * 205 * @param p_hwfn 206 * @param pp_ent 207 * 208 * @return enum _ecore_status_t 209 */ 210 enum _ecore_status_t 211 ecore_spq_get_entry(struct ecore_hwfn *p_hwfn, 212 struct ecore_spq_entry **pp_ent); 213 214 /** 215 * @brief ecore_spq_return_entry - Return an entry to spq free 216 * pool list 217 * 218 * @param p_hwfn 219 * @param p_ent 220 */ 221 void ecore_spq_return_entry(struct ecore_hwfn *p_hwfn, 222 struct ecore_spq_entry *p_ent); 223 /** 224 * @brief ecore_eq_allocate - Allocates & initializes an EQ struct 225 * 226 * @param p_hwfn 227 * @param num_elem number of elements in the eq 228 * 229 * @return enum _ecore_status_t 230 */ 231 enum _ecore_status_t ecore_eq_alloc(struct ecore_hwfn *p_hwfn, u16 num_elem); 232 233 /** 234 * @brief ecore_eq_setup - Reset the EQ to its start state. 235 * 236 * @param p_hwfn 237 */ 238 void ecore_eq_setup(struct ecore_hwfn *p_hwfn); 239 240 /** 241 * @brief ecore_eq_free - deallocates the given EQ struct. 242 * 243 * @param p_hwfn 244 */ 245 void ecore_eq_free(struct ecore_hwfn *p_hwfn); 246 247 /** 248 * @brief ecore_eq_prod_update - update the FW with default EQ producer 249 * 250 * @param p_hwfn 251 * @param prod 252 */ 253 void ecore_eq_prod_update(struct ecore_hwfn *p_hwfn, 254 u16 prod); 255 256 /** 257 * @brief ecore_eq_completion - Completes currently pending EQ elements 258 * 259 * @param p_hwfn 260 * @param cookie 261 * 262 * @return enum _ecore_status_t 263 */ 264 enum _ecore_status_t ecore_eq_completion(struct ecore_hwfn *p_hwfn, 265 void *cookie); 266 267 /** 268 * @brief ecore_spq_completion - Completes a single event 269 * 270 * @param p_hwfn 271 * @param echo - echo value from cookie (used for determining completion) 272 * @param p_data - data from cookie (used in callback function if applicable) 273 * 274 * @return enum _ecore_status_t 275 */ 276 enum _ecore_status_t ecore_spq_completion(struct ecore_hwfn *p_hwfn, 277 __le16 echo, 278 u8 fw_return_code, 279 union event_ring_data *p_data); 280 281 /** 282 * @brief ecore_spq_get_cid - Given p_hwfn, return cid for the hwfn's SPQ 283 * 284 * @param p_hwfn 285 * 286 * @return u32 - SPQ CID 287 */ 288 u32 ecore_spq_get_cid(struct ecore_hwfn *p_hwfn); 289 290 /** 291 * @brief ecore_consq_alloc - Allocates & initializes an ConsQ struct 292 * 293 * @param p_hwfn 294 * 295 * @return enum _ecore_status_t 296 */ 297 enum _ecore_status_t ecore_consq_alloc(struct ecore_hwfn *p_hwfn); 298 299 /** 300 * @brief ecore_consq_setup - Reset the ConsQ to its start state. 301 * 302 * @param p_hwfn 303 */ 304 void ecore_consq_setup(struct ecore_hwfn *p_hwfn); 305 306 /** 307 * @brief ecore_consq_free - deallocates the given ConsQ struct. 308 * 309 * @param p_hwfn 310 */ 311 void ecore_consq_free(struct ecore_hwfn *p_hwfn); 312 313 #endif /* __ECORE_SPQ_H__ */ 314