1 /* 2 * Copyright (c) 2017-2018 Cavium, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 * 27 */ 28 29 #ifndef __ECORE_SPQ_H__ 30 #define __ECORE_SPQ_H__ 31 32 #include "ecore_hsi_common.h" 33 #include "ecore_status.h" 34 #include "ecore_hsi_eth.h" 35 #include "ecore_hsi_fcoe.h" 36 #include "tcp_common.h" 37 #include "ecore_hsi_iscsi.h" 38 #include "ecore_hsi_roce.h" 39 #include "ecore_hsi_iwarp.h" 40 #include "ecore_chain.h" 41 #include "ecore_sp_api.h" 42 43 union ramrod_data 44 { 45 struct pf_start_ramrod_data pf_start; 46 struct pf_update_ramrod_data pf_update; 47 struct rl_update_ramrod_data rl_update; 48 struct rx_queue_start_ramrod_data rx_queue_start; 49 struct rx_queue_update_ramrod_data rx_queue_update; 50 struct rx_queue_stop_ramrod_data rx_queue_stop; 51 struct tx_queue_start_ramrod_data tx_queue_start; 52 struct tx_queue_stop_ramrod_data tx_queue_stop; 53 struct vport_start_ramrod_data vport_start; 54 struct vport_stop_ramrod_data vport_stop; 55 struct rx_update_gft_filter_data rx_update_gft; 56 struct vport_update_ramrod_data vport_update; 57 struct core_rx_start_ramrod_data core_rx_queue_start; 58 struct core_rx_stop_ramrod_data core_rx_queue_stop; 59 struct core_tx_start_ramrod_data core_tx_queue_start; 60 struct core_tx_stop_ramrod_data core_tx_queue_stop; 61 struct vport_filter_update_ramrod_data vport_filter_update; 62 63 struct rdma_init_func_ramrod_data rdma_init_func; 64 struct rdma_close_func_ramrod_data rdma_close_func; 65 struct rdma_register_tid_ramrod_data rdma_register_tid; 66 struct rdma_deregister_tid_ramrod_data rdma_deregister_tid; 67 struct roce_create_qp_resp_ramrod_data roce_create_qp_resp; 68 struct roce_create_qp_req_ramrod_data roce_create_qp_req; 69 struct roce_modify_qp_resp_ramrod_data roce_modify_qp_resp; 70 struct roce_modify_qp_req_ramrod_data roce_modify_qp_req; 71 struct roce_query_qp_resp_ramrod_data roce_query_qp_resp; 72 struct roce_query_qp_req_ramrod_data roce_query_qp_req; 73 struct roce_destroy_qp_resp_ramrod_data roce_destroy_qp_resp; 74 struct roce_destroy_qp_req_ramrod_data roce_destroy_qp_req; 75 struct roce_init_func_ramrod_data roce_init_func; 76 77 struct rdma_create_cq_ramrod_data rdma_create_cq; 78 struct rdma_resize_cq_ramrod_data rdma_resize_cq; 79 struct rdma_destroy_cq_ramrod_data rdma_destroy_cq; 80 struct rdma_srq_create_ramrod_data rdma_create_srq; 81 struct rdma_srq_destroy_ramrod_data rdma_destroy_srq; 82 struct rdma_srq_modify_ramrod_data rdma_modify_srq; 83 84 struct iwarp_create_qp_ramrod_data iwarp_create_qp; 85 struct iwarp_tcp_offload_ramrod_data iwarp_tcp_offload; 86 struct iwarp_mpa_offload_ramrod_data iwarp_mpa_offload; 87 struct iwarp_modify_qp_ramrod_data iwarp_modify_qp; 88 struct iwarp_query_qp_ramrod_data iwarp_query_qp; 89 struct iwarp_init_func_ramrod_data iwarp_init_func; 90 91 struct fcoe_init_ramrod_params fcoe_init; 92 struct fcoe_conn_offload_ramrod_params fcoe_conn_ofld; 93 struct fcoe_conn_terminate_ramrod_params fcoe_conn_terminate; 94 struct fcoe_stat_ramrod_params fcoe_stat; 95 96 struct iscsi_slow_path_hdr iscsi_empty; 97 struct iscsi_init_ramrod_params iscsi_init; 98 struct iscsi_spe_func_dstry iscsi_destroy; 99 struct iscsi_spe_conn_offload iscsi_conn_offload; 100 struct iscsi_conn_update_ramrod_params iscsi_conn_update; 101 struct iscsi_spe_conn_mac_update iscsi_conn_mac_update; 102 struct iscsi_spe_conn_termination iscsi_conn_terminate; 103 struct iscsi_spe_conn_statistics iscsi_conn_statistics; 104 105 struct vf_start_ramrod_data vf_start; 106 struct vf_stop_ramrod_data vf_stop; 107 }; 108 109 #define EQ_MAX_CREDIT 0xffffffff 110 111 enum spq_priority { 112 ECORE_SPQ_PRIORITY_NORMAL, 113 ECORE_SPQ_PRIORITY_HIGH, 114 }; 115 116 union ecore_spq_req_comp { 117 struct ecore_spq_comp_cb cb; 118 u64 *done_addr; 119 }; 120 121 /* SPQ_MODE_EBLOCK */ 122 struct ecore_spq_comp_done { 123 u64 done; 124 u8 fw_return_code; 125 }; 126 127 struct ecore_spq_entry { 128 osal_list_entry_t list; 129 130 u8 flags; 131 132 /* HSI slow path element */ 133 struct slow_path_element elem; 134 135 union ramrod_data ramrod; 136 137 enum spq_priority priority; 138 139 /* pending queue for this entry */ 140 osal_list_t *queue; 141 142 enum spq_mode comp_mode; 143 struct ecore_spq_comp_cb comp_cb; 144 struct ecore_spq_comp_done comp_done; /* SPQ_MODE_EBLOCK */ 145 }; 146 147 struct ecore_eq { 148 struct ecore_chain chain; 149 u8 eq_sb_index; /* index within the SB */ 150 __le16 *p_fw_cons; /* ptr to index value */ 151 }; 152 153 struct ecore_consq { 154 struct ecore_chain chain; 155 }; 156 157 typedef enum _ecore_status_t 158 (*ecore_spq_async_comp_cb)(struct ecore_hwfn *p_hwfn, 159 u8 opcode, 160 u16 echo, 161 union event_ring_data *data, 162 u8 fw_return_code); 163 164 enum _ecore_status_t 165 ecore_spq_register_async_cb(struct ecore_hwfn *p_hwfn, 166 enum protocol_type protocol_id, 167 ecore_spq_async_comp_cb cb); 168 169 void 170 ecore_spq_unregister_async_cb(struct ecore_hwfn *p_hwfn, 171 enum protocol_type protocol_id); 172 173 struct ecore_spq { 174 osal_spinlock_t lock; 175 176 osal_list_t unlimited_pending; 177 osal_list_t pending; 178 osal_list_t completion_pending; 179 osal_list_t free_pool; 180 181 struct ecore_chain chain; 182 183 /* allocated dma-able memory for spq entries (+ramrod data) */ 184 dma_addr_t p_phys; 185 struct ecore_spq_entry *p_virt; 186 187 /* Bitmap for handling out-of-order completions */ 188 #define SPQ_RING_SIZE \ 189 (CORE_SPQE_PAGE_SIZE_BYTES / sizeof(struct slow_path_element)) 190 #define SPQ_COMP_BMAP_SIZE (SPQ_RING_SIZE / (sizeof(unsigned long) * 8 /* BITS_PER_LONG */)) 191 unsigned long p_comp_bitmap[SPQ_COMP_BMAP_SIZE]; 192 u8 comp_bitmap_idx; 193 #define SPQ_COMP_BMAP_SET_BIT(p_spq, idx) \ 194 do { \ 195 OSAL_SET_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap); \ 196 } while (0) 197 #define SPQ_COMP_BMAP_CLEAR_BIT(p_spq, idx) \ 198 do { \ 199 OSAL_CLEAR_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap); \ 200 } while (0) 201 #define SPQ_COMP_BMAP_TEST_BIT(p_spq, idx) \ 202 (OSAL_TEST_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap)) 203 204 /* Statistics */ 205 u32 unlimited_pending_count; 206 u32 normal_count; 207 u32 high_count; 208 u32 comp_sent_count; 209 u32 comp_count; 210 211 u32 cid; 212 213 u32 db_addr_offset; 214 struct core_db_data db_data; 215 ecore_spq_async_comp_cb async_comp_cb[MAX_PROTOCOL_TYPE]; 216 }; 217 218 struct ecore_port; 219 struct ecore_hwfn; 220 221 /** 222 * @brief ecore_spq_post - Posts a Slow hwfn request to FW, or lacking that 223 * Pends it to the future list. 224 * 225 * @param p_hwfn 226 * @param p_req 227 * 228 * @return enum _ecore_status_t 229 */ 230 enum _ecore_status_t ecore_spq_post(struct ecore_hwfn *p_hwfn, 231 struct ecore_spq_entry *p_ent, 232 u8 *fw_return_code); 233 234 /** 235 * @brief ecore_spq_allocate - Alloocates & initializes the SPQ and EQ. 236 * 237 * @param p_hwfn 238 * 239 * @return enum _ecore_status_t 240 */ 241 enum _ecore_status_t ecore_spq_alloc(struct ecore_hwfn *p_hwfn); 242 243 /** 244 * @brief ecore_spq_setup - Reset the SPQ to its start state. 245 * 246 * @param p_hwfn 247 */ 248 void ecore_spq_setup(struct ecore_hwfn *p_hwfn); 249 250 /** 251 * @brief ecore_spq_deallocate - Deallocates the given SPQ struct. 252 * 253 * @param p_hwfn 254 */ 255 void ecore_spq_free(struct ecore_hwfn *p_hwfn); 256 257 /** 258 * @brief ecore_spq_get_entry - Obtain an entrry from the spq 259 * free pool list. 260 * 261 * 262 * 263 * @param p_hwfn 264 * @param pp_ent 265 * 266 * @return enum _ecore_status_t 267 */ 268 enum _ecore_status_t 269 ecore_spq_get_entry(struct ecore_hwfn *p_hwfn, 270 struct ecore_spq_entry **pp_ent); 271 272 /** 273 * @brief ecore_spq_return_entry - Return an entry to spq free 274 * pool list 275 * 276 * @param p_hwfn 277 * @param p_ent 278 */ 279 void ecore_spq_return_entry(struct ecore_hwfn *p_hwfn, 280 struct ecore_spq_entry *p_ent); 281 /** 282 * @brief ecore_eq_allocate - Allocates & initializes an EQ struct 283 * 284 * @param p_hwfn 285 * @param num_elem number of elements in the eq 286 * 287 * @return enum _ecore_status_t 288 */ 289 enum _ecore_status_t ecore_eq_alloc(struct ecore_hwfn *p_hwfn, u16 num_elem); 290 291 /** 292 * @brief ecore_eq_setup - Reset the EQ to its start state. 293 * 294 * @param p_hwfn 295 */ 296 void ecore_eq_setup(struct ecore_hwfn *p_hwfn); 297 298 /** 299 * @brief ecore_eq_free - deallocates the given EQ struct. 300 * 301 * @param p_hwfn 302 */ 303 void ecore_eq_free(struct ecore_hwfn *p_hwfn); 304 305 /** 306 * @brief ecore_eq_prod_update - update the FW with default EQ producer 307 * 308 * @param p_hwfn 309 * @param prod 310 */ 311 void ecore_eq_prod_update(struct ecore_hwfn *p_hwfn, 312 u16 prod); 313 314 /** 315 * @brief ecore_eq_completion - Completes currently pending EQ elements 316 * 317 * @param p_hwfn 318 * @param cookie 319 * 320 * @return enum _ecore_status_t 321 */ 322 enum _ecore_status_t ecore_eq_completion(struct ecore_hwfn *p_hwfn, 323 void *cookie); 324 325 /** 326 * @brief ecore_spq_completion - Completes a single event 327 * 328 * @param p_hwfn 329 * @param echo - echo value from cookie (used for determining completion) 330 * @param p_data - data from cookie (used in callback function if applicable) 331 * 332 * @return enum _ecore_status_t 333 */ 334 enum _ecore_status_t ecore_spq_completion(struct ecore_hwfn *p_hwfn, 335 __le16 echo, 336 u8 fw_return_code, 337 union event_ring_data *p_data); 338 339 /** 340 * @brief ecore_spq_get_cid - Given p_hwfn, return cid for the hwfn's SPQ 341 * 342 * @param p_hwfn 343 * 344 * @return u32 - SPQ CID 345 */ 346 u32 ecore_spq_get_cid(struct ecore_hwfn *p_hwfn); 347 348 /** 349 * @brief ecore_consq_alloc - Allocates & initializes an ConsQ struct 350 * 351 * @param p_hwfn 352 * 353 * @return enum _ecore_status_t 354 */ 355 enum _ecore_status_t ecore_consq_alloc(struct ecore_hwfn *p_hwfn); 356 357 /** 358 * @brief ecore_consq_setup - Reset the ConsQ to its start state. 359 * 360 * @param p_hwfn 361 */ 362 void ecore_consq_setup(struct ecore_hwfn *p_hwfn); 363 364 /** 365 * @brief ecore_consq_free - deallocates the given ConsQ struct. 366 * 367 * @param p_hwfn 368 */ 369 void ecore_consq_free(struct ecore_hwfn *p_hwfn); 370 enum _ecore_status_t ecore_spq_pend_post(struct ecore_hwfn *p_hwfn); 371 #endif /* __ECORE_SPQ_H__ */ 372