Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include "ena_eth_com.h"
7 : :
8 : : static struct ena_eth_io_rx_cdesc_base *ena_com_get_next_rx_cdesc(
9 : : struct ena_com_io_cq *io_cq)
10 : : {
11 : : struct ena_eth_io_rx_cdesc_base *cdesc;
12 : : u16 expected_phase, head_masked;
13 : : u16 desc_phase;
14 : :
15 : 0 : head_masked = io_cq->head & (io_cq->q_depth - 1);
16 : 0 : expected_phase = io_cq->phase;
17 : :
18 : 0 : cdesc = (struct ena_eth_io_rx_cdesc_base *)(io_cq->cdesc_addr.virt_addr
19 : 0 : + (head_masked * io_cq->cdesc_entry_size_in_bytes));
20 : :
21 : 0 : desc_phase = (READ_ONCE32(cdesc->status) & ENA_ETH_IO_RX_CDESC_BASE_PHASE_MASK) >>
22 : : ENA_ETH_IO_RX_CDESC_BASE_PHASE_SHIFT;
23 : :
24 [ # # ]: 0 : if (desc_phase != expected_phase)
25 : : return NULL;
26 : :
27 : : /* Make sure we read the rest of the descriptor after the phase bit
28 : : * has been read
29 : : */
30 : : dma_rmb();
31 : :
32 : : return cdesc;
33 : : }
34 : :
35 : : static void *get_sq_desc_regular_queue(struct ena_com_io_sq *io_sq)
36 : : {
37 : : u16 tail_masked;
38 : : u32 offset;
39 : :
40 : 0 : tail_masked = io_sq->tail & (io_sq->q_depth - 1);
41 : :
42 : 0 : offset = tail_masked * io_sq->desc_entry_size;
43 : :
44 : 0 : return (void *)((uintptr_t)io_sq->desc_addr.virt_addr + offset);
45 : : }
46 : :
47 : 0 : static int ena_com_write_bounce_buffer_to_dev(struct ena_com_io_sq *io_sq,
48 : : u8 *bounce_buffer)
49 : : {
50 : : struct ena_com_llq_info *llq_info = &io_sq->llq_info;
51 : :
52 : : u16 dst_tail_mask;
53 : : u32 dst_offset;
54 : :
55 : 0 : dst_tail_mask = io_sq->tail & (io_sq->q_depth - 1);
56 [ # # ]: 0 : dst_offset = dst_tail_mask * llq_info->desc_list_entry_size;
57 : :
58 [ # # ]: 0 : if (is_llq_max_tx_burst_exists(io_sq)) {
59 [ # # ]: 0 : if (unlikely(!io_sq->entries_in_tx_burst_left)) {
60 : 0 : ena_trc_err(ena_com_io_sq_to_ena_dev(io_sq),
61 : : "Error: trying to send more packets than tx burst allows\n");
62 : 0 : return ENA_COM_NO_SPACE;
63 : : }
64 : :
65 : 0 : io_sq->entries_in_tx_burst_left--;
66 : 0 : ena_trc_dbg(ena_com_io_sq_to_ena_dev(io_sq),
67 : : "Decreasing entries_in_tx_burst_left of queue %d to %d\n",
68 : : io_sq->qid, io_sq->entries_in_tx_burst_left);
69 : : }
70 : :
71 : : /* Make sure everything was written into the bounce buffer before
72 : : * writing the bounce buffer to the device
73 : : */
74 : : wmb();
75 : :
76 : : /* The line is completed. Copy it to dev */
77 [ # # ]: 0 : ENA_MEMCPY_TO_DEVICE_64(io_sq->desc_addr.pbuf_dev_addr + dst_offset,
78 : : bounce_buffer,
79 : : llq_info->desc_list_entry_size);
80 : :
81 : 0 : io_sq->tail++;
82 : :
83 : : /* Switch phase bit in case of wrap around */
84 [ # # ]: 0 : if (unlikely((io_sq->tail & (io_sq->q_depth - 1)) == 0))
85 : 0 : io_sq->phase ^= 1;
86 : :
87 : : return ENA_COM_OK;
88 : : }
89 : :
90 : 0 : static int ena_com_write_header_to_bounce(struct ena_com_io_sq *io_sq,
91 : : u8 *header_src,
92 : : u16 header_len)
93 : : {
94 : : struct ena_com_llq_pkt_ctrl *pkt_ctrl = &io_sq->llq_buf_ctrl;
95 : : struct ena_com_llq_info *llq_info = &io_sq->llq_info;
96 : 0 : u8 *bounce_buffer = pkt_ctrl->curr_bounce_buf;
97 : : u16 header_offset;
98 : :
99 [ # # ]: 0 : if (unlikely(io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST))
100 : : return 0;
101 : :
102 : 0 : header_offset =
103 : 0 : llq_info->descs_num_before_header * io_sq->desc_entry_size;
104 : :
105 [ # # ]: 0 : if (unlikely((header_offset + header_len) > llq_info->desc_list_entry_size)) {
106 : 0 : ena_trc_err(ena_com_io_sq_to_ena_dev(io_sq),
107 : : "Trying to write header larger than llq entry can accommodate\n");
108 : 0 : return ENA_COM_FAULT;
109 : : }
110 : :
111 [ # # ]: 0 : if (unlikely(!bounce_buffer)) {
112 : 0 : ena_trc_err(ena_com_io_sq_to_ena_dev(io_sq),
113 : : "Bounce buffer is NULL\n");
114 : 0 : return ENA_COM_FAULT;
115 : : }
116 : :
117 [ # # ]: 0 : memcpy(bounce_buffer + header_offset, header_src, header_len);
118 : :
119 : : return 0;
120 : : }
121 : :
122 : 0 : static void *get_sq_desc_llq(struct ena_com_io_sq *io_sq)
123 : : {
124 : : struct ena_com_llq_pkt_ctrl *pkt_ctrl = &io_sq->llq_buf_ctrl;
125 : : u8 *bounce_buffer;
126 : : void *sq_desc;
127 : :
128 : 0 : bounce_buffer = pkt_ctrl->curr_bounce_buf;
129 : :
130 [ # # ]: 0 : if (unlikely(!bounce_buffer)) {
131 : 0 : ena_trc_err(ena_com_io_sq_to_ena_dev(io_sq),
132 : : "Bounce buffer is NULL\n");
133 : 0 : return NULL;
134 : : }
135 : :
136 : 0 : sq_desc = bounce_buffer + pkt_ctrl->idx * io_sq->desc_entry_size;
137 : 0 : pkt_ctrl->idx++;
138 : 0 : pkt_ctrl->descs_left_in_line--;
139 : :
140 : 0 : return sq_desc;
141 : : }
142 : :
143 : 0 : static int ena_com_close_bounce_buffer(struct ena_com_io_sq *io_sq)
144 : : {
145 : : struct ena_com_llq_pkt_ctrl *pkt_ctrl = &io_sq->llq_buf_ctrl;
146 : : struct ena_com_llq_info *llq_info = &io_sq->llq_info;
147 : : int rc;
148 : :
149 [ # # ]: 0 : if (unlikely(io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST))
150 : : return ENA_COM_OK;
151 : :
152 : : /* bounce buffer was used, so write it and get a new one */
153 [ # # ]: 0 : if (likely(pkt_ctrl->idx)) {
154 : 0 : rc = ena_com_write_bounce_buffer_to_dev(io_sq,
155 : : pkt_ctrl->curr_bounce_buf);
156 [ # # ]: 0 : if (unlikely(rc)) {
157 : 0 : ena_trc_err(ena_com_io_sq_to_ena_dev(io_sq),
158 : : "Failed to write bounce buffer to device\n");
159 : 0 : return rc;
160 : : }
161 : :
162 : 0 : pkt_ctrl->curr_bounce_buf =
163 : : ena_com_get_next_bounce_buffer(&io_sq->bounce_buf_ctrl);
164 : 0 : memset(io_sq->llq_buf_ctrl.curr_bounce_buf,
165 : 0 : 0x0, llq_info->desc_list_entry_size);
166 : : }
167 : :
168 : 0 : pkt_ctrl->idx = 0;
169 : 0 : pkt_ctrl->descs_left_in_line = llq_info->descs_num_before_header;
170 : 0 : return ENA_COM_OK;
171 : : }
172 : :
173 : 0 : static void *get_sq_desc(struct ena_com_io_sq *io_sq)
174 : : {
175 [ # # ]: 0 : if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV)
176 : 0 : return get_sq_desc_llq(io_sq);
177 : :
178 : 0 : return get_sq_desc_regular_queue(io_sq);
179 : : }
180 : :
181 : 0 : static int ena_com_sq_update_llq_tail(struct ena_com_io_sq *io_sq)
182 : : {
183 : : struct ena_com_llq_pkt_ctrl *pkt_ctrl = &io_sq->llq_buf_ctrl;
184 : : struct ena_com_llq_info *llq_info = &io_sq->llq_info;
185 : : int rc;
186 : :
187 [ # # ]: 0 : if (!pkt_ctrl->descs_left_in_line) {
188 : 0 : rc = ena_com_write_bounce_buffer_to_dev(io_sq,
189 : : pkt_ctrl->curr_bounce_buf);
190 [ # # ]: 0 : if (unlikely(rc)) {
191 : 0 : ena_trc_err(ena_com_io_sq_to_ena_dev(io_sq),
192 : : "Failed to write bounce buffer to device\n");
193 : 0 : return rc;
194 : : }
195 : :
196 : 0 : pkt_ctrl->curr_bounce_buf =
197 : : ena_com_get_next_bounce_buffer(&io_sq->bounce_buf_ctrl);
198 : 0 : memset(io_sq->llq_buf_ctrl.curr_bounce_buf,
199 [ # # ]: 0 : 0x0, llq_info->desc_list_entry_size);
200 : :
201 : 0 : pkt_ctrl->idx = 0;
202 [ # # ]: 0 : if (unlikely(llq_info->desc_stride_ctrl == ENA_ADMIN_SINGLE_DESC_PER_ENTRY))
203 : 0 : pkt_ctrl->descs_left_in_line = 1;
204 : : else
205 : 0 : pkt_ctrl->descs_left_in_line =
206 : 0 : llq_info->desc_list_entry_size / io_sq->desc_entry_size;
207 : : }
208 : :
209 : : return ENA_COM_OK;
210 : : }
211 : :
212 : 0 : static int ena_com_sq_update_tail(struct ena_com_io_sq *io_sq)
213 : : {
214 [ # # ]: 0 : if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV)
215 : 0 : return ena_com_sq_update_llq_tail(io_sq);
216 : :
217 : 0 : io_sq->tail++;
218 : :
219 : : /* Switch phase bit in case of wrap around */
220 [ # # ]: 0 : if (unlikely((io_sq->tail & (io_sq->q_depth - 1)) == 0))
221 : 0 : io_sq->phase ^= 1;
222 : :
223 : : return ENA_COM_OK;
224 : : }
225 : :
226 : : static struct ena_eth_io_rx_cdesc_base *
227 : : ena_com_rx_cdesc_idx_to_ptr(struct ena_com_io_cq *io_cq, u16 idx)
228 : : {
229 : 0 : idx &= (io_cq->q_depth - 1);
230 : 0 : return (struct ena_eth_io_rx_cdesc_base *)
231 : 0 : ((uintptr_t)io_cq->cdesc_addr.virt_addr +
232 : 0 : idx * io_cq->cdesc_entry_size_in_bytes);
233 : : }
234 : :
235 : 0 : static int ena_com_cdesc_rx_pkt_get(struct ena_com_io_cq *io_cq,
236 : : u16 *first_cdesc_idx,
237 : : u16 *num_descs)
238 : : {
239 : 0 : u16 count = io_cq->cur_rx_pkt_cdesc_count, head_masked;
240 : : struct ena_eth_io_rx_cdesc_base *cdesc;
241 : : u32 last = 0;
242 : :
243 : : do {
244 : : u32 status;
245 : :
246 : : cdesc = ena_com_get_next_rx_cdesc(io_cq);
247 : : if (!cdesc)
248 : : break;
249 [ # # ]: 0 : status = READ_ONCE32(cdesc->status);
250 : :
251 : : ena_com_cq_inc_head(io_cq);
252 [ # # # # ]: 0 : if (unlikely((status & ENA_ETH_IO_RX_CDESC_BASE_FIRST_MASK) >>
253 : : ENA_ETH_IO_RX_CDESC_BASE_FIRST_SHIFT && count != 0)) {
254 : : struct ena_com_dev *dev = ena_com_io_cq_to_ena_dev(io_cq);
255 : :
256 : 0 : ena_trc_err(dev,
257 : : "First bit is on in descriptor #%d on q_id: %d, req_id: %u\n",
258 : : count, io_cq->qid, cdesc->req_id);
259 : 0 : return ENA_COM_FAULT;
260 : : }
261 : 0 : count++;
262 : 0 : last = (status & ENA_ETH_IO_RX_CDESC_BASE_LAST_MASK) >>
263 : : ENA_ETH_IO_RX_CDESC_BASE_LAST_SHIFT;
264 [ # # ]: 0 : } while (!last);
265 : :
266 [ # # ]: 0 : if (last) {
267 : 0 : *first_cdesc_idx = io_cq->cur_rx_pkt_cdesc_start_idx;
268 : :
269 : 0 : head_masked = io_cq->head & (io_cq->q_depth - 1);
270 : :
271 : 0 : *num_descs = count;
272 : 0 : io_cq->cur_rx_pkt_cdesc_count = 0;
273 : 0 : io_cq->cur_rx_pkt_cdesc_start_idx = head_masked;
274 : :
275 : 0 : ena_trc_dbg(ena_com_io_cq_to_ena_dev(io_cq),
276 : : "ENA q_id: %d packets were completed. first desc idx %u descs# %d\n",
277 : : io_cq->qid, *first_cdesc_idx, count);
278 : : } else {
279 : 0 : io_cq->cur_rx_pkt_cdesc_count = count;
280 : 0 : *num_descs = 0;
281 : : }
282 : :
283 : : return ENA_COM_OK;
284 : : }
285 : :
286 : 0 : static int ena_com_create_meta(struct ena_com_io_sq *io_sq,
287 : : struct ena_com_tx_meta *ena_meta)
288 : : {
289 : : struct ena_eth_io_tx_meta_desc *meta_desc = NULL;
290 : :
291 : 0 : meta_desc = get_sq_desc(io_sq);
292 [ # # ]: 0 : if (unlikely(!meta_desc))
293 : : return ENA_COM_FAULT;
294 : :
295 : : memset(meta_desc, 0x0, sizeof(struct ena_eth_io_tx_meta_desc));
296 : :
297 : : meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_META_DESC_MASK;
298 : :
299 : : meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_EXT_VALID_MASK;
300 : :
301 : : /* bits 0-9 of the mss */
302 : 0 : meta_desc->word2 |= ((u32)ena_meta->mss <<
303 : : ENA_ETH_IO_TX_META_DESC_MSS_LO_SHIFT) &
304 : : ENA_ETH_IO_TX_META_DESC_MSS_LO_MASK;
305 : : /* bits 10-13 of the mss */
306 : 0 : meta_desc->len_ctrl |= ((ena_meta->mss >> 10) <<
307 : 0 : ENA_ETH_IO_TX_META_DESC_MSS_HI_SHIFT) &
308 : : ENA_ETH_IO_TX_META_DESC_MSS_HI_MASK;
309 : :
310 : : /* Extended meta desc */
311 : 0 : meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_ETH_META_TYPE_MASK;
312 : 0 : meta_desc->len_ctrl |= ((u32)io_sq->phase <<
313 : 0 : ENA_ETH_IO_TX_META_DESC_PHASE_SHIFT) &
314 : : ENA_ETH_IO_TX_META_DESC_PHASE_MASK;
315 : :
316 : 0 : meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_FIRST_MASK;
317 : 0 : meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_META_STORE_MASK;
318 : :
319 : 0 : meta_desc->word2 |= ena_meta->l3_hdr_len &
320 : : ENA_ETH_IO_TX_META_DESC_L3_HDR_LEN_MASK;
321 : 0 : meta_desc->word2 |= (ena_meta->l3_hdr_offset <<
322 : 0 : ENA_ETH_IO_TX_META_DESC_L3_HDR_OFF_SHIFT) &
323 : : ENA_ETH_IO_TX_META_DESC_L3_HDR_OFF_MASK;
324 : :
325 : 0 : meta_desc->word2 |= ((u32)ena_meta->l4_hdr_len <<
326 : 0 : ENA_ETH_IO_TX_META_DESC_L4_HDR_LEN_IN_WORDS_SHIFT) &
327 : : ENA_ETH_IO_TX_META_DESC_L4_HDR_LEN_IN_WORDS_MASK;
328 : :
329 : 0 : return ena_com_sq_update_tail(io_sq);
330 : : }
331 : :
332 : 0 : static int ena_com_create_and_store_tx_meta_desc(struct ena_com_io_sq *io_sq,
333 : : struct ena_com_tx_ctx *ena_tx_ctx,
334 : : bool *have_meta)
335 : : {
336 : 0 : struct ena_com_tx_meta *ena_meta = &ena_tx_ctx->ena_meta;
337 : :
338 : : /* When disable meta caching is set, don't bother to save the meta and
339 : : * compare it to the stored version, just create the meta
340 : : */
341 [ # # ]: 0 : if (io_sq->disable_meta_caching) {
342 : 0 : *have_meta = true;
343 : 0 : return ena_com_create_meta(io_sq, ena_meta);
344 : : }
345 : :
346 [ # # ]: 0 : if (ena_com_meta_desc_changed(io_sq, ena_tx_ctx)) {
347 [ # # ]: 0 : *have_meta = true;
348 : : /* Cache the meta desc */
349 : : memcpy(&io_sq->cached_tx_meta, ena_meta,
350 : : sizeof(struct ena_com_tx_meta));
351 : 0 : return ena_com_create_meta(io_sq, ena_meta);
352 : : }
353 : :
354 : 0 : *have_meta = false;
355 : 0 : return ENA_COM_OK;
356 : : }
357 : :
358 : 0 : static void ena_com_rx_set_flags(struct ena_com_io_cq *io_cq,
359 : : struct ena_com_rx_ctx *ena_rx_ctx,
360 : : struct ena_eth_io_rx_cdesc_base *cdesc)
361 : : {
362 : 0 : ena_rx_ctx->l3_proto = cdesc->status &
363 : : ENA_ETH_IO_RX_CDESC_BASE_L3_PROTO_IDX_MASK;
364 : 0 : ena_rx_ctx->l4_proto =
365 : 0 : (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_L4_PROTO_IDX_MASK) >>
366 : : ENA_ETH_IO_RX_CDESC_BASE_L4_PROTO_IDX_SHIFT;
367 : 0 : ena_rx_ctx->l3_csum_err =
368 : 0 : !!((cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_L3_CSUM_ERR_MASK) >>
369 : : ENA_ETH_IO_RX_CDESC_BASE_L3_CSUM_ERR_SHIFT);
370 : 0 : ena_rx_ctx->l4_csum_err =
371 : 0 : !!((cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_L4_CSUM_ERR_MASK) >>
372 : : ENA_ETH_IO_RX_CDESC_BASE_L4_CSUM_ERR_SHIFT);
373 : 0 : ena_rx_ctx->l4_csum_checked =
374 : 0 : !!((cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_L4_CSUM_CHECKED_MASK) >>
375 : : ENA_ETH_IO_RX_CDESC_BASE_L4_CSUM_CHECKED_SHIFT);
376 : 0 : ena_rx_ctx->hash = cdesc->hash;
377 : 0 : ena_rx_ctx->frag =
378 : 0 : (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_IPV4_FRAG_MASK) >>
379 : : ENA_ETH_IO_RX_CDESC_BASE_IPV4_FRAG_SHIFT;
380 : :
381 : 0 : ena_trc_dbg(ena_com_io_cq_to_ena_dev(io_cq),
382 : : "l3_proto %d l4_proto %d l3_csum_err %d l4_csum_err %d hash %d frag %d cdesc_status %x\n",
383 : : ena_rx_ctx->l3_proto,
384 : : ena_rx_ctx->l4_proto,
385 : : ena_rx_ctx->l3_csum_err,
386 : : ena_rx_ctx->l4_csum_err,
387 : : ena_rx_ctx->hash,
388 : : ena_rx_ctx->frag,
389 : : cdesc->status);
390 : 0 : }
391 : :
392 : : /*****************************************************************************/
393 : : /***************************** API **********************************/
394 : : /*****************************************************************************/
395 : :
396 : 0 : int ena_com_prepare_tx(struct ena_com_io_sq *io_sq,
397 : : struct ena_com_tx_ctx *ena_tx_ctx,
398 : : int *nb_hw_desc)
399 : : {
400 : : struct ena_eth_io_tx_desc *desc = NULL;
401 : 0 : struct ena_com_buf *ena_bufs = ena_tx_ctx->ena_bufs;
402 : 0 : void *buffer_to_push = ena_tx_ctx->push_header;
403 : 0 : u16 header_len = ena_tx_ctx->header_len;
404 : 0 : u16 num_bufs = ena_tx_ctx->num_bufs;
405 : 0 : u16 start_tail = io_sq->tail;
406 : : int i, rc;
407 : : bool have_meta;
408 : : u64 addr_hi;
409 : :
410 [ # # ]: 0 : ENA_WARN(io_sq->direction != ENA_COM_IO_QUEUE_DIRECTION_TX,
411 : : ena_com_io_sq_to_ena_dev(io_sq), "wrong Q type");
412 : :
413 : : /* num_bufs +1 for potential meta desc */
414 [ # # # # ]: 0 : if (unlikely(!ena_com_sq_have_enough_space(io_sq, num_bufs + 1))) {
415 : 0 : ena_trc_dbg(ena_com_io_sq_to_ena_dev(io_sq),
416 : : "Not enough space in the tx queue\n");
417 : 0 : return ENA_COM_NO_MEM;
418 : : }
419 : :
420 [ # # ]: 0 : if (unlikely(header_len > io_sq->tx_max_header_size)) {
421 : 0 : ena_trc_err(ena_com_io_sq_to_ena_dev(io_sq),
422 : : "Header size is too large %d max header: %d\n",
423 : : header_len, io_sq->tx_max_header_size);
424 : 0 : return ENA_COM_INVAL;
425 : : }
426 : :
427 [ # # # # ]: 0 : if (unlikely(io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV
428 : : && !buffer_to_push)) {
429 : 0 : ena_trc_err(ena_com_io_sq_to_ena_dev(io_sq),
430 : : "Push header wasn't provided in LLQ mode\n");
431 : 0 : return ENA_COM_INVAL;
432 : : }
433 : :
434 : 0 : rc = ena_com_write_header_to_bounce(io_sq, buffer_to_push, header_len);
435 [ # # ]: 0 : if (unlikely(rc))
436 : : return rc;
437 : :
438 : 0 : rc = ena_com_create_and_store_tx_meta_desc(io_sq, ena_tx_ctx, &have_meta);
439 [ # # ]: 0 : if (unlikely(rc)) {
440 : 0 : ena_trc_err(ena_com_io_sq_to_ena_dev(io_sq),
441 : : "Failed to create and store tx meta desc\n");
442 : 0 : return rc;
443 : : }
444 : :
445 : : /* If the caller doesn't want to send packets */
446 [ # # ]: 0 : if (unlikely(!num_bufs && !header_len)) {
447 : 0 : rc = ena_com_close_bounce_buffer(io_sq);
448 [ # # ]: 0 : if (rc)
449 : 0 : ena_trc_err(ena_com_io_sq_to_ena_dev(io_sq),
450 : : "Failed to write buffers to LLQ\n");
451 : 0 : *nb_hw_desc = io_sq->tail - start_tail;
452 : 0 : return rc;
453 : : }
454 : :
455 : 0 : desc = get_sq_desc(io_sq);
456 [ # # ]: 0 : if (unlikely(!desc))
457 : : return ENA_COM_FAULT;
458 : : memset(desc, 0x0, sizeof(struct ena_eth_io_tx_desc));
459 : :
460 : : /* Set first desc when we don't have meta descriptor */
461 [ # # ]: 0 : if (!have_meta)
462 : 0 : desc->len_ctrl |= ENA_ETH_IO_TX_DESC_FIRST_MASK;
463 : :
464 : 0 : desc->buff_addr_hi_hdr_sz |= ((u32)header_len <<
465 : : ENA_ETH_IO_TX_DESC_HEADER_LENGTH_SHIFT) &
466 : : ENA_ETH_IO_TX_DESC_HEADER_LENGTH_MASK;
467 : 0 : desc->len_ctrl |= ((u32)io_sq->phase << ENA_ETH_IO_TX_DESC_PHASE_SHIFT) &
468 : : ENA_ETH_IO_TX_DESC_PHASE_MASK;
469 : :
470 : 0 : desc->len_ctrl |= ENA_ETH_IO_TX_DESC_COMP_REQ_MASK;
471 : :
472 : : /* Bits 0-9 */
473 : 0 : desc->meta_ctrl |= ((u32)ena_tx_ctx->req_id <<
474 : : ENA_ETH_IO_TX_DESC_REQ_ID_LO_SHIFT) &
475 : : ENA_ETH_IO_TX_DESC_REQ_ID_LO_MASK;
476 : :
477 : 0 : desc->meta_ctrl |= (ena_tx_ctx->df <<
478 : 0 : ENA_ETH_IO_TX_DESC_DF_SHIFT) &
479 : : ENA_ETH_IO_TX_DESC_DF_MASK;
480 : :
481 : : /* Bits 10-15 */
482 : 0 : desc->len_ctrl |= ((ena_tx_ctx->req_id >> 10) <<
483 : : ENA_ETH_IO_TX_DESC_REQ_ID_HI_SHIFT) &
484 : : ENA_ETH_IO_TX_DESC_REQ_ID_HI_MASK;
485 : :
486 [ # # ]: 0 : if (ena_tx_ctx->meta_valid) {
487 : 0 : desc->meta_ctrl |= (ena_tx_ctx->tso_enable <<
488 : 0 : ENA_ETH_IO_TX_DESC_TSO_EN_SHIFT) &
489 : : ENA_ETH_IO_TX_DESC_TSO_EN_MASK;
490 : 0 : desc->meta_ctrl |= ena_tx_ctx->l3_proto &
491 : : ENA_ETH_IO_TX_DESC_L3_PROTO_IDX_MASK;
492 : 0 : desc->meta_ctrl |= (ena_tx_ctx->l4_proto <<
493 : 0 : ENA_ETH_IO_TX_DESC_L4_PROTO_IDX_SHIFT) &
494 : : ENA_ETH_IO_TX_DESC_L4_PROTO_IDX_MASK;
495 : 0 : desc->meta_ctrl |= (ena_tx_ctx->l3_csum_enable <<
496 : 0 : ENA_ETH_IO_TX_DESC_L3_CSUM_EN_SHIFT) &
497 : : ENA_ETH_IO_TX_DESC_L3_CSUM_EN_MASK;
498 : 0 : desc->meta_ctrl |= (ena_tx_ctx->l4_csum_enable <<
499 : 0 : ENA_ETH_IO_TX_DESC_L4_CSUM_EN_SHIFT) &
500 : : ENA_ETH_IO_TX_DESC_L4_CSUM_EN_MASK;
501 : 0 : desc->meta_ctrl |= (ena_tx_ctx->l4_csum_partial <<
502 : 0 : ENA_ETH_IO_TX_DESC_L4_CSUM_PARTIAL_SHIFT) &
503 : : ENA_ETH_IO_TX_DESC_L4_CSUM_PARTIAL_MASK;
504 : : }
505 : :
506 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
507 : : /* The first desc share the same desc as the header */
508 [ # # ]: 0 : if (likely(i != 0)) {
509 : 0 : rc = ena_com_sq_update_tail(io_sq);
510 [ # # ]: 0 : if (unlikely(rc)) {
511 : 0 : ena_trc_err(ena_com_io_sq_to_ena_dev(io_sq),
512 : : "Failed to update sq tail\n");
513 : 0 : return rc;
514 : : }
515 : :
516 : 0 : desc = get_sq_desc(io_sq);
517 [ # # ]: 0 : if (unlikely(!desc))
518 : : return ENA_COM_FAULT;
519 : :
520 : : memset(desc, 0x0, sizeof(struct ena_eth_io_tx_desc));
521 : :
522 : 0 : desc->len_ctrl |= ((u32)io_sq->phase <<
523 : 0 : ENA_ETH_IO_TX_DESC_PHASE_SHIFT) &
524 : : ENA_ETH_IO_TX_DESC_PHASE_MASK;
525 : : }
526 : :
527 : 0 : desc->len_ctrl |= ena_bufs->len &
528 : : ENA_ETH_IO_TX_DESC_LENGTH_MASK;
529 : :
530 : 0 : addr_hi = ((ena_bufs->paddr &
531 : 0 : GENMASK_ULL(io_sq->dma_addr_bits - 1, 32)) >> 32);
532 : :
533 : 0 : desc->buff_addr_lo = (u32)ena_bufs->paddr;
534 : 0 : desc->buff_addr_hi_hdr_sz |= addr_hi &
535 : : ENA_ETH_IO_TX_DESC_ADDR_HI_MASK;
536 : 0 : ena_bufs++;
537 : : }
538 : :
539 : : /* set the last desc indicator */
540 : 0 : desc->len_ctrl |= ENA_ETH_IO_TX_DESC_LAST_MASK;
541 : :
542 : 0 : rc = ena_com_sq_update_tail(io_sq);
543 [ # # ]: 0 : if (unlikely(rc)) {
544 : 0 : ena_trc_err(ena_com_io_sq_to_ena_dev(io_sq),
545 : : "Failed to update sq tail of the last descriptor\n");
546 : 0 : return rc;
547 : : }
548 : :
549 : 0 : rc = ena_com_close_bounce_buffer(io_sq);
550 : :
551 : 0 : *nb_hw_desc = io_sq->tail - start_tail;
552 : 0 : return rc;
553 : : }
554 : :
555 : 0 : int ena_com_rx_pkt(struct ena_com_io_cq *io_cq,
556 : : struct ena_com_io_sq *io_sq,
557 : : struct ena_com_rx_ctx *ena_rx_ctx)
558 : : {
559 : 0 : struct ena_com_rx_buf_info *ena_buf = &ena_rx_ctx->ena_bufs[0];
560 : : struct ena_eth_io_rx_cdesc_base *cdesc = NULL;
561 : 0 : u16 q_depth = io_cq->q_depth;
562 : 0 : u16 cdesc_idx = 0;
563 : : u16 nb_hw_desc;
564 : : u16 i = 0;
565 : : int rc;
566 : :
567 [ # # ]: 0 : ENA_WARN(io_cq->direction != ENA_COM_IO_QUEUE_DIRECTION_RX,
568 : : ena_com_io_cq_to_ena_dev(io_cq), "wrong Q type");
569 : :
570 : 0 : rc = ena_com_cdesc_rx_pkt_get(io_cq, &cdesc_idx, &nb_hw_desc);
571 [ # # ]: 0 : if (unlikely(rc != ENA_COM_OK))
572 : : return ENA_COM_FAULT;
573 : :
574 [ # # ]: 0 : if (nb_hw_desc == 0) {
575 : 0 : ena_rx_ctx->descs = nb_hw_desc;
576 : 0 : return 0;
577 : : }
578 : :
579 : 0 : ena_trc_dbg(ena_com_io_cq_to_ena_dev(io_cq),
580 : : "Fetch rx packet: queue %d completed desc: %d\n",
581 : : io_cq->qid, nb_hw_desc);
582 : :
583 [ # # ]: 0 : if (unlikely(nb_hw_desc > ena_rx_ctx->max_bufs)) {
584 : 0 : ena_trc_err(ena_com_io_cq_to_ena_dev(io_cq),
585 : : "Too many RX cdescs (%d) > MAX(%d)\n",
586 : : nb_hw_desc, ena_rx_ctx->max_bufs);
587 : 0 : return ENA_COM_NO_SPACE;
588 : : }
589 : :
590 : 0 : cdesc = ena_com_rx_cdesc_idx_to_ptr(io_cq, cdesc_idx);
591 : 0 : ena_rx_ctx->pkt_offset = cdesc->offset;
592 : :
593 : : do {
594 : 0 : ena_buf[i].len = cdesc->length;
595 : 0 : ena_buf[i].req_id = cdesc->req_id;
596 [ # # ]: 0 : if (unlikely(ena_buf[i].req_id >= q_depth))
597 : : return ENA_COM_EIO;
598 : :
599 [ # # ]: 0 : if (++i >= nb_hw_desc)
600 : : break;
601 : :
602 : 0 : cdesc = ena_com_rx_cdesc_idx_to_ptr(io_cq, cdesc_idx + i);
603 : :
604 : : } while (1);
605 : :
606 : : /* Update SQ head ptr */
607 : 0 : io_sq->next_to_comp += nb_hw_desc;
608 : :
609 : 0 : ena_trc_dbg(ena_com_io_cq_to_ena_dev(io_cq),
610 : : "[%s][QID#%d] Updating SQ head to: %d\n", __func__,
611 : : io_sq->qid, io_sq->next_to_comp);
612 : :
613 : : /* Get rx flags from the last pkt */
614 : 0 : ena_com_rx_set_flags(io_cq, ena_rx_ctx, cdesc);
615 : :
616 : 0 : ena_rx_ctx->descs = nb_hw_desc;
617 : :
618 : 0 : return 0;
619 : : }
620 : :
621 : 0 : int ena_com_add_single_rx_desc(struct ena_com_io_sq *io_sq,
622 : : struct ena_com_buf *ena_buf,
623 : : u16 req_id)
624 : : {
625 : : struct ena_eth_io_rx_desc *desc;
626 : :
627 [ # # ]: 0 : ENA_WARN(io_sq->direction != ENA_COM_IO_QUEUE_DIRECTION_RX,
628 : : ena_com_io_sq_to_ena_dev(io_sq), "wrong Q type");
629 : :
630 [ # # ]: 0 : if (unlikely(!ena_com_sq_have_enough_space(io_sq, 1)))
631 : : return ENA_COM_NO_SPACE;
632 : :
633 : 0 : desc = get_sq_desc(io_sq);
634 [ # # ]: 0 : if (unlikely(!desc))
635 : : return ENA_COM_FAULT;
636 : :
637 : : memset(desc, 0x0, sizeof(struct ena_eth_io_rx_desc));
638 : :
639 : 0 : desc->length = ena_buf->len;
640 : :
641 : 0 : desc->ctrl = ENA_ETH_IO_RX_DESC_FIRST_MASK |
642 : : ENA_ETH_IO_RX_DESC_LAST_MASK |
643 : 0 : ENA_ETH_IO_RX_DESC_COMP_REQ_MASK |
644 : 0 : (io_sq->phase & ENA_ETH_IO_RX_DESC_PHASE_MASK);
645 : :
646 : 0 : desc->req_id = req_id;
647 : :
648 : 0 : ena_trc_dbg(ena_com_io_sq_to_ena_dev(io_sq),
649 : : "[%s] Adding single RX desc, Queue: %u, req_id: %u\n",
650 : : __func__, io_sq->qid, req_id);
651 : :
652 : 0 : desc->buff_addr_lo = (u32)ena_buf->paddr;
653 : 0 : desc->buff_addr_hi =
654 : 0 : ((ena_buf->paddr & GENMASK_ULL(io_sq->dma_addr_bits - 1, 32)) >> 32);
655 : :
656 : 0 : return ena_com_sq_update_tail(io_sq);
657 : : }
658 : :
659 [ # # ]: 0 : bool ena_com_cq_empty(struct ena_com_io_cq *io_cq)
660 : : {
661 : : struct ena_eth_io_rx_cdesc_base *cdesc;
662 : :
663 : : cdesc = ena_com_get_next_rx_cdesc(io_cq);
664 : : if (cdesc)
665 : 0 : return false;
666 : : else
667 : : return true;
668 : : }
|