1 /* QLogic qed NIC Driver 2 * Copyright (c) 2015-2017 QLogic Corporation 3 * 4 * This software is available to you under a choice of one of two 5 * licenses. You may choose to be licensed under the terms of the GNU 6 * General Public License (GPL) Version 2, available from the file 7 * COPYING in the main directory of this source tree, or the 8 * OpenIB.org BSD license below: 9 * 10 * Redistribution and use in source and binary forms, with or 11 * without modification, are permitted provided that the following 12 * conditions are met: 13 * 14 * - Redistributions of source code must retain the above 15 * copyright notice, this list of conditions and the following 16 * disclaimer. 17 * 18 * - Redistributions in binary form must reproduce the above 19 * copyright notice, this list of conditions and the following 20 * disclaimer in the documentation and /or other materials 21 * provided with the distribution. 22 * 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * SOFTWARE. 31 */ 32 33 #ifndef _QED_SP_H 34 #define _QED_SP_H 35 36 #include <linux/types.h> 37 #include <linux/kernel.h> 38 #include <linux/list.h> 39 #include <linux/slab.h> 40 #include <linux/spinlock.h> 41 #include <linux/qed/qed_chain.h> 42 #include "qed.h" 43 #include "qed_hsi.h" 44 45 enum spq_mode { 46 QED_SPQ_MODE_BLOCK, /* Client will poll a designated mem. address */ 47 QED_SPQ_MODE_CB, /* Client supplies a callback */ 48 QED_SPQ_MODE_EBLOCK, /* QED should block until completion */ 49 }; 50 51 struct qed_spq_comp_cb { 52 void (*function)(struct qed_hwfn *, 53 void *, 54 union event_ring_data *, 55 u8 fw_return_code); 56 void *cookie; 57 }; 58 59 /** 60 * @brief qed_eth_cqe_completion - handles the completion of a 61 * ramrod on the cqe ring 62 * 63 * @param p_hwfn 64 * @param cqe 65 * 66 * @return int 67 */ 68 int qed_eth_cqe_completion(struct qed_hwfn *p_hwfn, 69 struct eth_slow_path_rx_cqe *cqe); 70 71 /** 72 * @file 73 * 74 * QED Slow-hwfn queue interface 75 */ 76 77 union ramrod_data { 78 struct pf_start_ramrod_data pf_start; 79 struct pf_update_ramrod_data pf_update; 80 struct rx_queue_start_ramrod_data rx_queue_start; 81 struct rx_queue_update_ramrod_data rx_queue_update; 82 struct rx_queue_stop_ramrod_data rx_queue_stop; 83 struct tx_queue_start_ramrod_data tx_queue_start; 84 struct tx_queue_stop_ramrod_data tx_queue_stop; 85 struct vport_start_ramrod_data vport_start; 86 struct vport_stop_ramrod_data vport_stop; 87 struct vport_update_ramrod_data vport_update; 88 struct core_rx_start_ramrod_data core_rx_queue_start; 89 struct core_rx_stop_ramrod_data core_rx_queue_stop; 90 struct core_tx_start_ramrod_data core_tx_queue_start; 91 struct core_tx_stop_ramrod_data core_tx_queue_stop; 92 struct vport_filter_update_ramrod_data vport_filter_update; 93 94 struct rdma_init_func_ramrod_data rdma_init_func; 95 struct rdma_close_func_ramrod_data rdma_close_func; 96 struct rdma_register_tid_ramrod_data rdma_register_tid; 97 struct rdma_deregister_tid_ramrod_data rdma_deregister_tid; 98 struct roce_create_qp_resp_ramrod_data roce_create_qp_resp; 99 struct roce_create_qp_req_ramrod_data roce_create_qp_req; 100 struct roce_modify_qp_resp_ramrod_data roce_modify_qp_resp; 101 struct roce_modify_qp_req_ramrod_data roce_modify_qp_req; 102 struct roce_query_qp_resp_ramrod_data roce_query_qp_resp; 103 struct roce_query_qp_req_ramrod_data roce_query_qp_req; 104 struct roce_destroy_qp_resp_ramrod_data roce_destroy_qp_resp; 105 struct roce_destroy_qp_req_ramrod_data roce_destroy_qp_req; 106 struct rdma_create_cq_ramrod_data rdma_create_cq; 107 struct rdma_destroy_cq_ramrod_data rdma_destroy_cq; 108 struct rdma_srq_create_ramrod_data rdma_create_srq; 109 struct rdma_srq_destroy_ramrod_data rdma_destroy_srq; 110 struct rdma_srq_modify_ramrod_data rdma_modify_srq; 111 struct roce_init_func_ramrod_data roce_init_func; 112 113 struct iscsi_slow_path_hdr iscsi_empty; 114 struct iscsi_init_ramrod_params iscsi_init; 115 struct iscsi_spe_func_dstry iscsi_destroy; 116 struct iscsi_spe_conn_offload iscsi_conn_offload; 117 struct iscsi_conn_update_ramrod_params iscsi_conn_update; 118 struct iscsi_spe_conn_termination iscsi_conn_terminate; 119 120 struct vf_start_ramrod_data vf_start; 121 struct vf_stop_ramrod_data vf_stop; 122 }; 123 124 #define EQ_MAX_CREDIT 0xffffffff 125 126 enum spq_priority { 127 QED_SPQ_PRIORITY_NORMAL, 128 QED_SPQ_PRIORITY_HIGH, 129 }; 130 131 union qed_spq_req_comp { 132 struct qed_spq_comp_cb cb; 133 u64 *done_addr; 134 }; 135 136 struct qed_spq_comp_done { 137 unsigned int done; 138 u8 fw_return_code; 139 }; 140 141 struct qed_spq_entry { 142 struct list_head list; 143 144 u8 flags; 145 146 /* HSI slow path element */ 147 struct slow_path_element elem; 148 149 union ramrod_data ramrod; 150 151 enum spq_priority priority; 152 153 /* pending queue for this entry */ 154 struct list_head *queue; 155 156 enum spq_mode comp_mode; 157 struct qed_spq_comp_cb comp_cb; 158 struct qed_spq_comp_done comp_done; /* SPQ_MODE_EBLOCK */ 159 }; 160 161 struct qed_eq { 162 struct qed_chain chain; 163 u8 eq_sb_index; /* index within the SB */ 164 __le16 *p_fw_cons; /* ptr to index value */ 165 }; 166 167 struct qed_consq { 168 struct qed_chain chain; 169 }; 170 171 struct qed_spq { 172 spinlock_t lock; /* SPQ lock */ 173 174 struct list_head unlimited_pending; 175 struct list_head pending; 176 struct list_head completion_pending; 177 struct list_head free_pool; 178 179 struct qed_chain chain; 180 181 /* allocated dma-able memory for spq entries (+ramrod data) */ 182 dma_addr_t p_phys; 183 struct qed_spq_entry *p_virt; 184 185 #define SPQ_RING_SIZE \ 186 (CORE_SPQE_PAGE_SIZE_BYTES / sizeof(struct slow_path_element)) 187 188 /* Bitmap for handling out-of-order completions */ 189 DECLARE_BITMAP(p_comp_bitmap, SPQ_RING_SIZE); 190 u8 comp_bitmap_idx; 191 192 /* Statistics */ 193 u32 unlimited_pending_count; 194 u32 normal_count; 195 u32 high_count; 196 u32 comp_sent_count; 197 u32 comp_count; 198 199 u32 cid; 200 }; 201 202 /** 203 * @brief qed_spq_post - Posts a Slow hwfn request to FW, or lacking that 204 * Pends it to the future list. 205 * 206 * @param p_hwfn 207 * @param p_req 208 * 209 * @return int 210 */ 211 int qed_spq_post(struct qed_hwfn *p_hwfn, 212 struct qed_spq_entry *p_ent, 213 u8 *fw_return_code); 214 215 /** 216 * @brief qed_spq_allocate - Alloocates & initializes the SPQ and EQ. 217 * 218 * @param p_hwfn 219 * 220 * @return int 221 */ 222 int qed_spq_alloc(struct qed_hwfn *p_hwfn); 223 224 /** 225 * @brief qed_spq_setup - Reset the SPQ to its start state. 226 * 227 * @param p_hwfn 228 */ 229 void qed_spq_setup(struct qed_hwfn *p_hwfn); 230 231 /** 232 * @brief qed_spq_deallocate - Deallocates the given SPQ struct. 233 * 234 * @param p_hwfn 235 */ 236 void qed_spq_free(struct qed_hwfn *p_hwfn); 237 238 /** 239 * @brief qed_spq_get_entry - Obtain an entrry from the spq 240 * free pool list. 241 * 242 * 243 * 244 * @param p_hwfn 245 * @param pp_ent 246 * 247 * @return int 248 */ 249 int 250 qed_spq_get_entry(struct qed_hwfn *p_hwfn, 251 struct qed_spq_entry **pp_ent); 252 253 /** 254 * @brief qed_spq_return_entry - Return an entry to spq free 255 * pool list 256 * 257 * @param p_hwfn 258 * @param p_ent 259 */ 260 void qed_spq_return_entry(struct qed_hwfn *p_hwfn, 261 struct qed_spq_entry *p_ent); 262 /** 263 * @brief qed_eq_allocate - Allocates & initializes an EQ struct 264 * 265 * @param p_hwfn 266 * @param num_elem number of elements in the eq 267 * 268 * @return struct qed_eq* - a newly allocated structure; NULL upon error. 269 */ 270 struct qed_eq *qed_eq_alloc(struct qed_hwfn *p_hwfn, 271 u16 num_elem); 272 273 /** 274 * @brief qed_eq_setup - Reset the SPQ to its start state. 275 * 276 * @param p_hwfn 277 * @param p_eq 278 */ 279 void qed_eq_setup(struct qed_hwfn *p_hwfn, 280 struct qed_eq *p_eq); 281 282 /** 283 * @brief qed_eq_deallocate - deallocates the given EQ struct. 284 * 285 * @param p_hwfn 286 * @param p_eq 287 */ 288 void qed_eq_free(struct qed_hwfn *p_hwfn, 289 struct qed_eq *p_eq); 290 291 /** 292 * @brief qed_eq_prod_update - update the FW with default EQ producer 293 * 294 * @param p_hwfn 295 * @param prod 296 */ 297 void qed_eq_prod_update(struct qed_hwfn *p_hwfn, 298 u16 prod); 299 300 /** 301 * @brief qed_eq_completion - Completes currently pending EQ elements 302 * 303 * @param p_hwfn 304 * @param cookie 305 * 306 * @return int 307 */ 308 int qed_eq_completion(struct qed_hwfn *p_hwfn, 309 void *cookie); 310 311 /** 312 * @brief qed_spq_completion - Completes a single event 313 * 314 * @param p_hwfn 315 * @param echo - echo value from cookie (used for determining completion) 316 * @param p_data - data from cookie (used in callback function if applicable) 317 * 318 * @return int 319 */ 320 int qed_spq_completion(struct qed_hwfn *p_hwfn, 321 __le16 echo, 322 u8 fw_return_code, 323 union event_ring_data *p_data); 324 325 /** 326 * @brief qed_spq_get_cid - Given p_hwfn, return cid for the hwfn's SPQ 327 * 328 * @param p_hwfn 329 * 330 * @return u32 - SPQ CID 331 */ 332 u32 qed_spq_get_cid(struct qed_hwfn *p_hwfn); 333 334 /** 335 * @brief qed_consq_alloc - Allocates & initializes an ConsQ 336 * struct 337 * 338 * @param p_hwfn 339 * 340 * @return struct qed_eq* - a newly allocated structure; NULL upon error. 341 */ 342 struct qed_consq *qed_consq_alloc(struct qed_hwfn *p_hwfn); 343 344 /** 345 * @brief qed_consq_setup - Reset the ConsQ to its start 346 * state. 347 * 348 * @param p_hwfn 349 * @param p_eq 350 */ 351 void qed_consq_setup(struct qed_hwfn *p_hwfn, 352 struct qed_consq *p_consq); 353 354 /** 355 * @brief qed_consq_free - deallocates the given ConsQ struct. 356 * 357 * @param p_hwfn 358 * @param p_eq 359 */ 360 void qed_consq_free(struct qed_hwfn *p_hwfn, 361 struct qed_consq *p_consq); 362 363 /** 364 * @file 365 * 366 * @brief Slow-hwfn low-level commands (Ramrods) function definitions. 367 */ 368 369 #define QED_SP_EQ_COMPLETION 0x01 370 #define QED_SP_CQE_COMPLETION 0x02 371 372 struct qed_sp_init_data { 373 u32 cid; 374 u16 opaque_fid; 375 376 /* Information regarding operation upon sending & completion */ 377 enum spq_mode comp_mode; 378 struct qed_spq_comp_cb *p_comp_data; 379 }; 380 381 int qed_sp_init_request(struct qed_hwfn *p_hwfn, 382 struct qed_spq_entry **pp_ent, 383 u8 cmd, 384 u8 protocol, 385 struct qed_sp_init_data *p_data); 386 387 /** 388 * @brief qed_sp_pf_start - PF Function Start Ramrod 389 * 390 * This ramrod is sent to initialize a physical function (PF). It will 391 * configure the function related parameters and write its completion to the 392 * event ring specified in the parameters. 393 * 394 * Ramrods complete on the common event ring for the PF. This ring is 395 * allocated by the driver on host memory and its parameters are written 396 * to the internal RAM of the UStorm by the Function Start Ramrod. 397 * 398 * @param p_hwfn 399 * @param p_tunn 400 * @param mode 401 * @param allow_npar_tx_switch 402 * 403 * @return int 404 */ 405 406 int qed_sp_pf_start(struct qed_hwfn *p_hwfn, 407 struct qed_tunn_start_params *p_tunn, 408 enum qed_mf_mode mode, bool allow_npar_tx_switch); 409 410 /** 411 * @brief qed_sp_pf_update - PF Function Update Ramrod 412 * 413 * This ramrod updates function-related parameters. Every parameter can be 414 * updated independently, according to configuration flags. 415 * 416 * @param p_hwfn 417 * 418 * @return int 419 */ 420 421 int qed_sp_pf_update(struct qed_hwfn *p_hwfn); 422 423 /** 424 * @brief qed_sp_pf_stop - PF Function Stop Ramrod 425 * 426 * This ramrod is sent to close a Physical Function (PF). It is the last ramrod 427 * sent and the last completion written to the PFs Event Ring. This ramrod also 428 * deletes the context for the Slowhwfn connection on this PF. 429 * 430 * @note Not required for first packet. 431 * 432 * @param p_hwfn 433 * 434 * @return int 435 */ 436 437 int qed_sp_pf_stop(struct qed_hwfn *p_hwfn); 438 439 int qed_sp_pf_update_tunn_cfg(struct qed_hwfn *p_hwfn, 440 struct qed_tunn_update_params *p_tunn, 441 enum spq_mode comp_mode, 442 struct qed_spq_comp_cb *p_comp_data); 443 /** 444 * @brief qed_sp_heartbeat_ramrod - Send empty Ramrod 445 * 446 * @param p_hwfn 447 * 448 * @return int 449 */ 450 451 int qed_sp_heartbeat_ramrod(struct qed_hwfn *p_hwfn); 452 453 #endif 454