1 /* QLogic qed NIC Driver 2 * Copyright (c) 2015-2016 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 #ifndef _QED_ROCE_H 33 #define _QED_ROCE_H 34 #include <linux/types.h> 35 #include <linux/bitops.h> 36 #include <linux/kernel.h> 37 #include <linux/list.h> 38 #include <linux/slab.h> 39 #include <linux/spinlock.h> 40 #include <linux/qed/qed_if.h> 41 #include <linux/qed/qed_roce_if.h> 42 #include "qed.h" 43 #include "qed_dev_api.h" 44 #include "qed_hsi.h" 45 46 #define QED_RDMA_MAX_FMR (RDMA_MAX_TIDS) 47 #define QED_RDMA_MAX_P_KEY (1) 48 #define QED_RDMA_MAX_WQE (0x7FFF) 49 #define QED_RDMA_MAX_SRQ_WQE_ELEM (0x7FFF) 50 #define QED_RDMA_PAGE_SIZE_CAPS (0xFFFFF000) 51 #define QED_RDMA_ACK_DELAY (15) 52 #define QED_RDMA_MAX_MR_SIZE (0x10000000000ULL) 53 #define QED_RDMA_MAX_CQS (RDMA_MAX_CQS) 54 #define QED_RDMA_MAX_MRS (RDMA_MAX_TIDS) 55 /* Add 1 for header element */ 56 #define QED_RDMA_MAX_SRQ_ELEM_PER_WQE (RDMA_MAX_SGE_PER_RQ_WQE + 1) 57 #define QED_RDMA_MAX_SGE_PER_SRQ_WQE (RDMA_MAX_SGE_PER_RQ_WQE) 58 #define QED_RDMA_SRQ_WQE_ELEM_SIZE (16) 59 #define QED_RDMA_MAX_SRQS (32 * 1024) 60 61 #define QED_RDMA_MAX_CQE_32_BIT (0x7FFFFFFF - 1) 62 #define QED_RDMA_MAX_CQE_16_BIT (0x7FFF - 1) 63 64 enum qed_rdma_toggle_bit { 65 QED_RDMA_TOGGLE_BIT_CLEAR = 0, 66 QED_RDMA_TOGGLE_BIT_SET = 1 67 }; 68 69 struct qed_bmap { 70 unsigned long *bitmap; 71 u32 max_count; 72 }; 73 74 struct qed_rdma_info { 75 /* spin lock to protect bitmaps */ 76 spinlock_t lock; 77 78 struct qed_bmap cq_map; 79 struct qed_bmap pd_map; 80 struct qed_bmap tid_map; 81 struct qed_bmap qp_map; 82 struct qed_bmap srq_map; 83 struct qed_bmap cid_map; 84 struct qed_bmap dpi_map; 85 struct qed_bmap toggle_bits; 86 struct qed_rdma_events events; 87 struct qed_rdma_device *dev; 88 struct qed_rdma_port *port; 89 u32 last_tid; 90 u8 num_cnqs; 91 u32 num_qps; 92 u32 num_mrs; 93 u16 queue_zone_base; 94 enum protocol_type proto; 95 }; 96 97 struct qed_rdma_resize_cq_in_params { 98 u16 icid; 99 u32 cq_size; 100 bool pbl_two_level; 101 u64 pbl_ptr; 102 u16 pbl_num_pages; 103 u8 pbl_page_size_log; 104 }; 105 106 struct qed_rdma_resize_cq_out_params { 107 u32 prod; 108 u32 cons; 109 }; 110 111 struct qed_rdma_resize_cnq_in_params { 112 u32 cnq_id; 113 u32 pbl_page_size_log; 114 u64 pbl_ptr; 115 }; 116 117 int 118 qed_rdma_add_user(void *rdma_cxt, 119 struct qed_rdma_add_user_out_params *out_params); 120 int qed_rdma_alloc_pd(void *rdma_cxt, u16 *pd); 121 int qed_rdma_alloc_tid(void *rdma_cxt, u32 *tid); 122 int qed_rdma_deregister_tid(void *rdma_cxt, u32 tid); 123 void qed_rdma_free_tid(void *rdma_cxt, u32 tid); 124 struct qed_rdma_device *qed_rdma_query_device(void *rdma_cxt); 125 struct qed_rdma_port *qed_rdma_query_port(void *rdma_cxt); 126 int 127 qed_rdma_register_tid(void *rdma_cxt, 128 struct qed_rdma_register_tid_in_params *params); 129 void qed_rdma_remove_user(void *rdma_cxt, u16 dpi); 130 int qed_rdma_start(void *p_hwfn, struct qed_rdma_start_in_params *params); 131 int qed_rdma_stop(void *rdma_cxt); 132 u32 qed_rdma_get_sb_id(void *p_hwfn, u32 rel_sb_id); 133 u32 qed_rdma_query_cau_timer_res(void *p_hwfn); 134 void qed_rdma_cnq_prod_update(void *rdma_cxt, u8 cnq_index, u16 prod); 135 void qed_rdma_resc_free(struct qed_hwfn *p_hwfn); 136 void qed_async_roce_event(struct qed_hwfn *p_hwfn, 137 struct event_ring_entry *p_eqe); 138 139 #if IS_ENABLED(CONFIG_INFINIBAND_QEDR) 140 void qed_rdma_dpm_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt); 141 #else 142 void qed_rdma_dpm_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) {} 143 #endif 144 #endif 145