2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2021 Microsoft Corp.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #define DEFAULT_LOG2_THROTTLING_FOR_ERROR_EQ 4
41 #define HW_CHANNEL_MAX_REQUEST_SIZE 0x1000
42 #define HW_CHANNEL_MAX_RESPONSE_SIZE 0x1000
44 #define HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH 1
46 #define HWC_INIT_DATA_CQID 1
47 #define HWC_INIT_DATA_RQID 2
48 #define HWC_INIT_DATA_SQID 3
49 #define HWC_INIT_DATA_QUEUE_DEPTH 4
50 #define HWC_INIT_DATA_MAX_REQUEST 5
51 #define HWC_INIT_DATA_MAX_RESPONSE 6
52 #define HWC_INIT_DATA_MAX_NUM_CQS 7
53 #define HWC_INIT_DATA_PDID 8
54 #define HWC_INIT_DATA_GPA_MKEY 9
56 /* Structures labeled with "HW DATA" are exchanged with the hardware. All of
57 * them are naturally aligned and hence don't need __packed.
60 union hwc_init_eq_id_db {
65 uint32_t doorbell: 16;
69 union hwc_init_type_data {
82 uint32_t vendor_err : 8;
83 uint32_t reserved1 : 16;
85 uint32_t src_virt_wq : 24;
86 uint32_t src_vfid : 8;
91 uint32_t wqe_addr_low;
95 uint32_t wqe_addr_high;
97 uint32_t client_data_unit : 14;
98 uint32_t reserved3 : 18;
100 uint32_t tx_oob_data_size;
102 uint32_t chunk_offset : 21;
103 uint32_t reserved4 : 11;
111 uint32_t vrq_id : 24;
112 uint32_t dest_vfid : 8;
114 uint32_t vrcq_id : 24;
115 uint32_t reserved3 : 8;
117 uint32_t vscq_id : 24;
118 uint32_t loopback : 1;
119 uint32_t lso_override: 1;
120 uint32_t dest_pf : 1;
121 uint32_t reserved4 : 5;
123 uint32_t vsq_id : 24;
124 uint32_t reserved5 : 8;
127 struct hwc_work_request {
133 struct gdma_wqe_request wqe_req;
134 struct hwc_tx_oob tx_oob;
139 /* hwc_dma_buf represents the array of in-flight WQEs.
140 * mem_info as know as the GDMA mapped memory is partitioned and used by
142 * The number of WQEs is determined by the number of in-flight messages.
145 struct gdma_mem_info mem_info;
150 struct hwc_work_request reqs[];
153 typedef void hwc_rx_event_handler_t(void *ctx, uint32_t gdma_rxq_id,
154 const struct hwc_rx_oob *rx_oob);
156 typedef void hwc_tx_event_handler_t(void *ctx, uint32_t gdma_txq_id,
157 const struct hwc_rx_oob *rx_oob);
160 struct hw_channel_context *hwc;
162 struct gdma_queue *gdma_cq;
163 struct gdma_queue *gdma_eq;
164 struct gdma_comp *comp_buf;
165 uint16_t queue_depth;
167 hwc_rx_event_handler_t *rx_event_handler;
170 hwc_tx_event_handler_t *tx_event_handler;
175 struct hw_channel_context *hwc;
177 struct gdma_queue *gdma_wq;
178 struct hwc_dma_buf *msg_buf;
179 uint16_t queue_depth;
181 struct hwc_cq *hwc_cq;
184 struct hwc_caller_ctx {
185 struct completion comp_event;
187 uint32_t output_buflen;
189 uint32_t error; /* Error code */
190 uint32_t status_code;
193 struct hw_channel_context {
194 struct gdma_dev *gdma_dev;
197 uint16_t num_inflight_msg;
198 uint32_t max_req_msg_size;
200 uint16_t hwc_init_q_depth_max;
201 uint32_t hwc_init_max_req_msg_size;
202 uint32_t hwc_init_max_resp_msg_size;
204 struct completion hwc_init_eqe_comp;
211 struct gdma_resource inflight_msg_res;
213 struct hwc_caller_ctx *caller_ctx;
216 int mana_hwc_create_channel(struct gdma_context *gc);
217 void mana_hwc_destroy_channel(struct gdma_context *gc);
219 int mana_hwc_send_request(struct hw_channel_context *hwc, uint32_t req_len,
220 const void *req, uint32_t resp_len, void *resp);
222 #endif /* _HW_CHANNEL_H */