ena_eth_com.h revision 1.1.1.1.2.2 1 1.1.1.1.2.2 pgoyette /*-
2 1.1.1.1.2.2 pgoyette * BSD LICENSE
3 1.1.1.1.2.2 pgoyette *
4 1.1.1.1.2.2 pgoyette * Copyright (c) 2015-2017 Amazon.com, Inc. or its affiliates.
5 1.1.1.1.2.2 pgoyette * All rights reserved.
6 1.1.1.1.2.2 pgoyette *
7 1.1.1.1.2.2 pgoyette * Redistribution and use in source and binary forms, with or without
8 1.1.1.1.2.2 pgoyette * modification, are permitted provided that the following conditions
9 1.1.1.1.2.2 pgoyette * are met:
10 1.1.1.1.2.2 pgoyette *
11 1.1.1.1.2.2 pgoyette * * Redistributions of source code must retain the above copyright
12 1.1.1.1.2.2 pgoyette * notice, this list of conditions and the following disclaimer.
13 1.1.1.1.2.2 pgoyette * * Redistributions in binary form must reproduce the above copyright
14 1.1.1.1.2.2 pgoyette * notice, this list of conditions and the following disclaimer in
15 1.1.1.1.2.2 pgoyette * the documentation and/or other materials provided with the
16 1.1.1.1.2.2 pgoyette * distribution.
17 1.1.1.1.2.2 pgoyette * * Neither the name of copyright holder nor the names of its
18 1.1.1.1.2.2 pgoyette * contributors may be used to endorse or promote products derived
19 1.1.1.1.2.2 pgoyette * from this software without specific prior written permission.
20 1.1.1.1.2.2 pgoyette *
21 1.1.1.1.2.2 pgoyette * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 1.1.1.1.2.2 pgoyette * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 1.1.1.1.2.2 pgoyette * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 1.1.1.1.2.2 pgoyette * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 1.1.1.1.2.2 pgoyette * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 1.1.1.1.2.2 pgoyette * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 1.1.1.1.2.2 pgoyette * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1.1.1.2.2 pgoyette * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1.1.1.2.2 pgoyette * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1.1.1.2.2 pgoyette * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 1.1.1.1.2.2 pgoyette * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1.1.1.2.2 pgoyette */
33 1.1.1.1.2.2 pgoyette
34 1.1.1.1.2.2 pgoyette #ifndef ENA_ETH_COM_H_
35 1.1.1.1.2.2 pgoyette #define ENA_ETH_COM_H_
36 1.1.1.1.2.2 pgoyette
37 1.1.1.1.2.2 pgoyette #if defined(__cplusplus)
38 1.1.1.1.2.2 pgoyette extern "C" {
39 1.1.1.1.2.2 pgoyette #endif
40 1.1.1.1.2.2 pgoyette #include "ena_com.h"
41 1.1.1.1.2.2 pgoyette
42 1.1.1.1.2.2 pgoyette /* head update threshold in units of (queue size / ENA_COMP_HEAD_THRESH) */
43 1.1.1.1.2.2 pgoyette #define ENA_COMP_HEAD_THRESH 4
44 1.1.1.1.2.2 pgoyette
45 1.1.1.1.2.2 pgoyette struct ena_com_tx_ctx {
46 1.1.1.1.2.2 pgoyette struct ena_com_tx_meta ena_meta;
47 1.1.1.1.2.2 pgoyette struct ena_com_buf *ena_bufs;
48 1.1.1.1.2.2 pgoyette /* For LLQ, header buffer - pushed to the device mem space */
49 1.1.1.1.2.2 pgoyette void *push_header;
50 1.1.1.1.2.2 pgoyette
51 1.1.1.1.2.2 pgoyette enum ena_eth_io_l3_proto_index l3_proto;
52 1.1.1.1.2.2 pgoyette enum ena_eth_io_l4_proto_index l4_proto;
53 1.1.1.1.2.2 pgoyette u16 num_bufs;
54 1.1.1.1.2.2 pgoyette u16 req_id;
55 1.1.1.1.2.2 pgoyette /* For regular queue, indicate the size of the header
56 1.1.1.1.2.2 pgoyette * For LLQ, indicate the size of the pushed buffer
57 1.1.1.1.2.2 pgoyette */
58 1.1.1.1.2.2 pgoyette u16 header_len;
59 1.1.1.1.2.2 pgoyette
60 1.1.1.1.2.2 pgoyette u8 meta_valid;
61 1.1.1.1.2.2 pgoyette u8 tso_enable;
62 1.1.1.1.2.2 pgoyette u8 l3_csum_enable;
63 1.1.1.1.2.2 pgoyette u8 l4_csum_enable;
64 1.1.1.1.2.2 pgoyette u8 l4_csum_partial;
65 1.1.1.1.2.2 pgoyette u8 df; /* Don't fragment */
66 1.1.1.1.2.2 pgoyette };
67 1.1.1.1.2.2 pgoyette
68 1.1.1.1.2.2 pgoyette struct ena_com_rx_ctx {
69 1.1.1.1.2.2 pgoyette struct ena_com_rx_buf_info *ena_bufs;
70 1.1.1.1.2.2 pgoyette enum ena_eth_io_l3_proto_index l3_proto;
71 1.1.1.1.2.2 pgoyette enum ena_eth_io_l4_proto_index l4_proto;
72 1.1.1.1.2.2 pgoyette bool l3_csum_err;
73 1.1.1.1.2.2 pgoyette bool l4_csum_err;
74 1.1.1.1.2.2 pgoyette /* fragmented packet */
75 1.1.1.1.2.2 pgoyette bool frag;
76 1.1.1.1.2.2 pgoyette u32 hash;
77 1.1.1.1.2.2 pgoyette u16 descs;
78 1.1.1.1.2.2 pgoyette int max_bufs;
79 1.1.1.1.2.2 pgoyette };
80 1.1.1.1.2.2 pgoyette
81 1.1.1.1.2.2 pgoyette int ena_com_prepare_tx(struct ena_com_io_sq *io_sq,
82 1.1.1.1.2.2 pgoyette struct ena_com_tx_ctx *ena_tx_ctx,
83 1.1.1.1.2.2 pgoyette int *nb_hw_desc);
84 1.1.1.1.2.2 pgoyette
85 1.1.1.1.2.2 pgoyette int ena_com_rx_pkt(struct ena_com_io_cq *io_cq,
86 1.1.1.1.2.2 pgoyette struct ena_com_io_sq *io_sq,
87 1.1.1.1.2.2 pgoyette struct ena_com_rx_ctx *ena_rx_ctx);
88 1.1.1.1.2.2 pgoyette
89 1.1.1.1.2.2 pgoyette int ena_com_add_single_rx_desc(struct ena_com_io_sq *io_sq,
90 1.1.1.1.2.2 pgoyette struct ena_com_buf *ena_buf,
91 1.1.1.1.2.2 pgoyette u16 req_id);
92 1.1.1.1.2.2 pgoyette
93 1.1.1.1.2.2 pgoyette int ena_com_tx_comp_req_id_get(struct ena_com_io_cq *io_cq, u16 *req_id);
94 1.1.1.1.2.2 pgoyette
95 1.1.1.1.2.2 pgoyette static inline void ena_com_unmask_intr(struct ena_com_io_cq *io_cq,
96 1.1.1.1.2.2 pgoyette struct ena_eth_io_intr_reg *intr_reg)
97 1.1.1.1.2.2 pgoyette {
98 1.1.1.1.2.2 pgoyette ENA_REG_WRITE32(io_cq->bus, intr_reg->intr_control, io_cq->unmask_reg);
99 1.1.1.1.2.2 pgoyette }
100 1.1.1.1.2.2 pgoyette
101 1.1.1.1.2.2 pgoyette static inline int ena_com_free_desc(struct ena_com_io_sq *io_sq)
102 1.1.1.1.2.2 pgoyette {
103 1.1.1.1.2.2 pgoyette u16 tail, next_to_comp, cnt;
104 1.1.1.1.2.2 pgoyette
105 1.1.1.1.2.2 pgoyette next_to_comp = io_sq->next_to_comp;
106 1.1.1.1.2.2 pgoyette tail = io_sq->tail;
107 1.1.1.1.2.2 pgoyette cnt = tail - next_to_comp;
108 1.1.1.1.2.2 pgoyette
109 1.1.1.1.2.2 pgoyette return io_sq->q_depth - 1 - cnt;
110 1.1.1.1.2.2 pgoyette }
111 1.1.1.1.2.2 pgoyette
112 1.1.1.1.2.2 pgoyette /* Check if the submission queue has enough space to hold required_buffers */
113 1.1.1.1.2.2 pgoyette static inline bool ena_com_sq_have_enough_space(struct ena_com_io_sq *io_sq,
114 1.1.1.1.2.2 pgoyette u16 required_buffers)
115 1.1.1.1.2.2 pgoyette {
116 1.1.1.1.2.2 pgoyette int temp;
117 1.1.1.1.2.2 pgoyette
118 1.1.1.1.2.2 pgoyette if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST)
119 1.1.1.1.2.2 pgoyette return ena_com_free_desc(io_sq) >= required_buffers;
120 1.1.1.1.2.2 pgoyette
121 1.1.1.1.2.2 pgoyette /* This calculation doesn't need to be 100% accurate. So to reduce
122 1.1.1.1.2.2 pgoyette * the calculation overhead just Subtract 2 lines from the free descs
123 1.1.1.1.2.2 pgoyette * (one for the header line and one to compensate the devision
124 1.1.1.1.2.2 pgoyette * down calculation.
125 1.1.1.1.2.2 pgoyette */
126 1.1.1.1.2.2 pgoyette temp = required_buffers / io_sq->llq_info.descs_per_entry + 2;
127 1.1.1.1.2.2 pgoyette
128 1.1.1.1.2.2 pgoyette return ena_com_free_desc(io_sq) > temp;
129 1.1.1.1.2.2 pgoyette }
130 1.1.1.1.2.2 pgoyette
131 1.1.1.1.2.2 pgoyette static inline int ena_com_write_sq_doorbell(struct ena_com_io_sq *io_sq)
132 1.1.1.1.2.2 pgoyette {
133 1.1.1.1.2.2 pgoyette u16 tail;
134 1.1.1.1.2.2 pgoyette
135 1.1.1.1.2.2 pgoyette tail = io_sq->tail;
136 1.1.1.1.2.2 pgoyette
137 1.1.1.1.2.2 pgoyette ena_trc_dbg("write submission queue doorbell for queue: %d tail: %d\n",
138 1.1.1.1.2.2 pgoyette io_sq->qid, tail);
139 1.1.1.1.2.2 pgoyette
140 1.1.1.1.2.2 pgoyette ENA_REG_WRITE32(io_sq->bus, tail, io_sq->db_addr);
141 1.1.1.1.2.2 pgoyette
142 1.1.1.1.2.2 pgoyette return 0;
143 1.1.1.1.2.2 pgoyette }
144 1.1.1.1.2.2 pgoyette
145 1.1.1.1.2.2 pgoyette static inline int ena_com_update_dev_comp_head(struct ena_com_io_cq *io_cq)
146 1.1.1.1.2.2 pgoyette {
147 1.1.1.1.2.2 pgoyette u16 unreported_comp, head;
148 1.1.1.1.2.2 pgoyette bool need_update;
149 1.1.1.1.2.2 pgoyette
150 1.1.1.1.2.2 pgoyette head = io_cq->head;
151 1.1.1.1.2.2 pgoyette unreported_comp = head - io_cq->last_head_update;
152 1.1.1.1.2.2 pgoyette need_update = unreported_comp > (io_cq->q_depth / ENA_COMP_HEAD_THRESH);
153 1.1.1.1.2.2 pgoyette
154 1.1.1.1.2.2 pgoyette if (io_cq->cq_head_db_reg && need_update) {
155 1.1.1.1.2.2 pgoyette ena_trc_dbg("Write completion queue doorbell for queue %d: head: %d\n",
156 1.1.1.1.2.2 pgoyette io_cq->qid, head);
157 1.1.1.1.2.2 pgoyette ENA_REG_WRITE32(io_cq->bus, head, io_cq->cq_head_db_reg);
158 1.1.1.1.2.2 pgoyette io_cq->last_head_update = head;
159 1.1.1.1.2.2 pgoyette }
160 1.1.1.1.2.2 pgoyette
161 1.1.1.1.2.2 pgoyette return 0;
162 1.1.1.1.2.2 pgoyette }
163 1.1.1.1.2.2 pgoyette
164 1.1.1.1.2.2 pgoyette static inline void ena_com_update_numa_node(struct ena_com_io_cq *io_cq,
165 1.1.1.1.2.2 pgoyette u8 numa_node)
166 1.1.1.1.2.2 pgoyette {
167 1.1.1.1.2.2 pgoyette struct ena_eth_io_numa_node_cfg_reg numa_cfg;
168 1.1.1.1.2.2 pgoyette
169 1.1.1.1.2.2 pgoyette if (!io_cq->numa_node_cfg_reg)
170 1.1.1.1.2.2 pgoyette return;
171 1.1.1.1.2.2 pgoyette
172 1.1.1.1.2.2 pgoyette numa_cfg.numa_cfg = (numa_node & ENA_ETH_IO_NUMA_NODE_CFG_REG_NUMA_MASK)
173 1.1.1.1.2.2 pgoyette | ENA_ETH_IO_NUMA_NODE_CFG_REG_ENABLED_MASK;
174 1.1.1.1.2.2 pgoyette
175 1.1.1.1.2.2 pgoyette ENA_REG_WRITE32(io_cq->bus, numa_cfg.numa_cfg, io_cq->numa_node_cfg_reg);
176 1.1.1.1.2.2 pgoyette }
177 1.1.1.1.2.2 pgoyette
178 1.1.1.1.2.2 pgoyette static inline void ena_com_comp_ack(struct ena_com_io_sq *io_sq, u16 elem)
179 1.1.1.1.2.2 pgoyette {
180 1.1.1.1.2.2 pgoyette io_sq->next_to_comp += elem;
181 1.1.1.1.2.2 pgoyette }
182 1.1.1.1.2.2 pgoyette
183 1.1.1.1.2.2 pgoyette #if defined(__cplusplus)
184 1.1.1.1.2.2 pgoyette }
185 1.1.1.1.2.2 pgoyette #endif
186 1.1.1.1.2.2 pgoyette #endif /* ENA_ETH_COM_H_ */
187