1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
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_rdma_if.h>
43 #include "qed_dev_api.h"
45 #include "qed_iwarp.h"
48 #define QED_RDMA_MAX_FMR (RDMA_MAX_TIDS)
49 #define QED_RDMA_MAX_P_KEY (1)
50 #define QED_RDMA_MAX_WQE (0x7FFF)
51 #define QED_RDMA_MAX_SRQ_WQE_ELEM (0x7FFF)
52 #define QED_RDMA_PAGE_SIZE_CAPS (0xFFFFF000)
53 #define QED_RDMA_ACK_DELAY (15)
54 #define QED_RDMA_MAX_MR_SIZE (0x10000000000ULL)
55 #define QED_RDMA_MAX_CQS (RDMA_MAX_CQS)
56 #define QED_RDMA_MAX_MRS (RDMA_MAX_TIDS)
57 /* Add 1 for header element */
58 #define QED_RDMA_MAX_SRQ_ELEM_PER_WQE (RDMA_MAX_SGE_PER_RQ_WQE + 1)
59 #define QED_RDMA_MAX_SGE_PER_SRQ_WQE (RDMA_MAX_SGE_PER_RQ_WQE)
60 #define QED_RDMA_SRQ_WQE_ELEM_SIZE (16)
61 #define QED_RDMA_MAX_SRQS (32 * 1024)
63 #define QED_RDMA_MAX_CQE_32_BIT (0x7FFFFFFF - 1)
64 #define QED_RDMA_MAX_CQE_16_BIT (0x7FFF - 1)
66 enum qed_rdma_toggle_bit
{
67 QED_RDMA_TOGGLE_BIT_CLEAR
= 0,
68 QED_RDMA_TOGGLE_BIT_SET
= 1
71 #define QED_RDMA_MAX_BMAP_NAME (10)
73 unsigned long *bitmap
;
75 char name
[QED_RDMA_MAX_BMAP_NAME
];
78 struct qed_rdma_info
{
79 /* spin lock to protect bitmaps */
82 struct qed_bmap cq_map
;
83 struct qed_bmap pd_map
;
84 struct qed_bmap tid_map
;
85 struct qed_bmap qp_map
;
86 struct qed_bmap srq_map
;
87 struct qed_bmap cid_map
;
88 struct qed_bmap tcp_cid_map
;
89 struct qed_bmap real_cid_map
;
90 struct qed_bmap dpi_map
;
91 struct qed_bmap toggle_bits
;
92 struct qed_rdma_events events
;
93 struct qed_rdma_device
*dev
;
94 struct qed_rdma_port
*port
;
101 enum protocol_type proto
;
102 struct qed_iwarp_info iwarp
;
106 struct regpair qp_handle
;
107 struct regpair qp_handle_async
;
110 enum qed_roce_qp_state cur_state
;
111 enum qed_iwarp_qp_state iwarp_state
;
114 bool fmr_and_reserved_lkey
;
116 bool incoming_rdma_read_en
;
117 bool incoming_rdma_write_en
;
118 bool incoming_atomic_en
;
119 bool e2e_flow_control_en
;
126 u8 traffic_class_tos
;
135 u8 min_rnr_nak_timer
;
139 enum roce_mode roce_mode
;
144 u8 max_rd_atomic_req
;
148 dma_addr_t sq_pbl_ptr
;
150 dma_addr_t orq_phys_addr
;
155 u8 max_rd_atomic_resp
;
159 dma_addr_t rq_pbl_ptr
;
161 dma_addr_t irq_phys_addr
;
166 u8 remote_mac_addr
[6];
167 u8 local_mac_addr
[6];
170 dma_addr_t shared_queue_phys_addr
;
171 struct qed_iwarp_ep
*ep
;
174 #if IS_ENABLED(CONFIG_QED_RDMA)
175 void qed_rdma_dpm_bar(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
);
176 void qed_rdma_dpm_conf(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
);
178 static inline void qed_rdma_dpm_conf(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
) {}
179 static inline void qed_rdma_dpm_bar(struct qed_hwfn
*p_hwfn
,
180 struct qed_ptt
*p_ptt
) {}
184 qed_rdma_bmap_alloc(struct qed_hwfn
*p_hwfn
,
185 struct qed_bmap
*bmap
, u32 max_count
, char *name
);
188 qed_rdma_bmap_free(struct qed_hwfn
*p_hwfn
, struct qed_bmap
*bmap
, bool check
);
191 qed_rdma_bmap_alloc_id(struct qed_hwfn
*p_hwfn
,
192 struct qed_bmap
*bmap
, u32
*id_num
);
195 qed_bmap_set_id(struct qed_hwfn
*p_hwfn
, struct qed_bmap
*bmap
, u32 id_num
);
198 qed_bmap_release_id(struct qed_hwfn
*p_hwfn
, struct qed_bmap
*bmap
, u32 id_num
);
201 qed_bmap_test_id(struct qed_hwfn
*p_hwfn
, struct qed_bmap
*bmap
, u32 id_num
);
203 void qed_rdma_set_fw_mac(u16
*p_fw_mac
, u8
*p_qed_mac
);
205 bool qed_rdma_allocated_qps(struct qed_hwfn
*p_hwfn
);