Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C), 2025, Wuxi Stars Micro System Technologies Co., Ltd.
3 : : */
4 : :
5 : : #include "sxe2_ioctl_chnl_func.h"
6 : : #include "sxe2_drv_cmd.h"
7 : : #include "sxe2_cmd_chnl.h"
8 : : #include "sxe2_ethdev.h"
9 : : #include "sxe2_common_log.h"
10 : :
11 : : static union sxe2_drv_trace_info sxe2_drv_trace_id;
12 : :
13 : 0 : static void sxe2_drv_trace_id_alloc(uint64_t *trace_id)
14 : : {
15 : 0 : union sxe2_drv_trace_info *trace = NULL;
16 : 0 : uint64_t trace_id_count = 0;
17 : :
18 : 0 : trace = &sxe2_drv_trace_id;
19 : :
20 : 0 : trace_id_count = trace->sxe2_drv_trace_id_param.count;
21 : 0 : ++trace_id_count;
22 : 0 : trace->sxe2_drv_trace_id_param.count =
23 : 0 : (trace_id_count & SXE2_DRV_TRACE_ID_COUNT_MASK);
24 : :
25 : 0 : *trace_id = trace->id;
26 : : }
27 : :
28 : 0 : static void __sxe2_drv_cmd_params_fill(struct sxe2_adapter *adapter,
29 : : struct sxe2_drv_cmd_params *cmd, uint32_t opc, const char *opc_str,
30 : : void *in_data, uint32_t in_len, void *out_data, uint32_t out_len)
31 : : {
32 : 0 : PMD_DEV_LOG_DEBUG(adapter, DRV, "cmd opcode:%s", opc_str);
33 : 0 : cmd->timeout = SXE2_DRV_CMD_DFLT_TIMEOUT;
34 : 0 : cmd->opcode = opc;
35 : 0 : cmd->vsi_id = adapter->vsi_ctxt.dpdk_vsi_id;
36 [ # # ]: 0 : cmd->repr_id = (adapter->repr_priv_data != NULL) ?
37 : : adapter->repr_priv_data->repr_id : 0xFFFF;
38 : 0 : cmd->req_len = in_len;
39 : 0 : cmd->req_data = in_data;
40 : 0 : cmd->resp_len = out_len;
41 : 0 : cmd->resp_data = out_data;
42 : :
43 : 0 : sxe2_drv_trace_id_alloc(&cmd->trace_id);
44 : 0 : }
45 : :
46 : : #define sxe2_drv_cmd_params_fill(adapter, cmd, opc, in_data, in_len, out_data, out_len) \
47 : : __sxe2_drv_cmd_params_fill(adapter, cmd, opc, #opc, in_data, in_len, out_data, out_len)
48 : :
49 : :
50 : 0 : int32_t sxe2_drv_dev_caps_get(struct sxe2_adapter *adapter, struct sxe2_drv_dev_caps_resp *dev_caps)
51 : : {
52 : 0 : int32_t ret = 0;
53 : 0 : struct sxe2_common_device *cdev = adapter->cdev;
54 : 0 : struct sxe2_drv_cmd_params param = {0};
55 : :
56 : 0 : sxe2_drv_cmd_params_fill(adapter, ¶m, SXE2_DRV_CMD_DEV_GET_CAPS,
57 : : NULL, 0, dev_caps,
58 : : sizeof(struct sxe2_drv_dev_caps_resp));
59 : :
60 : 0 : ret = sxe2_drv_cmd_exec(cdev, ¶m);
61 [ # # ]: 0 : if (ret)
62 : 0 : PMD_DEV_LOG_ERR(adapter, DRV, "get dev caps failed, ret=%d", ret);
63 : :
64 : 0 : return ret;
65 : : }
66 : :
67 : 0 : int32_t sxe2_drv_dev_info_get(struct sxe2_adapter *adapter,
68 : : struct sxe2_drv_dev_info_resp *dev_info_resp)
69 : : {
70 : 0 : int32_t ret = 0;
71 : 0 : struct sxe2_common_device *cdev = adapter->cdev;
72 : 0 : struct sxe2_drv_cmd_params param = {0};
73 : :
74 : 0 : sxe2_drv_cmd_params_fill(adapter, ¶m, SXE2_DRV_CMD_DEV_GET_INFO,
75 : : NULL, 0, dev_info_resp,
76 : : sizeof(struct sxe2_drv_dev_info_resp));
77 : :
78 : 0 : ret = sxe2_drv_cmd_exec(cdev, ¶m);
79 [ # # ]: 0 : if (ret)
80 : 0 : PMD_DEV_LOG_ERR(adapter, DRV, "get dev info failed, ret=%d", ret);
81 : :
82 : 0 : return ret;
83 : : }
84 : :
85 : 0 : int32_t sxe2_drv_dev_fw_info_get(struct sxe2_adapter *adapter,
86 : : struct sxe2_drv_dev_fw_info_resp *dev_fw_info_resp)
87 : : {
88 : 0 : int32_t ret = 0;
89 : 0 : struct sxe2_common_device *cdev = adapter->cdev;
90 : 0 : struct sxe2_drv_cmd_params param = {0};
91 : :
92 : 0 : sxe2_drv_cmd_params_fill(adapter, ¶m, SXE2_DRV_CMD_DEV_GET_FW_INFO,
93 : : NULL, 0, dev_fw_info_resp,
94 : : sizeof(struct sxe2_drv_dev_fw_info_resp));
95 : :
96 : 0 : ret = sxe2_drv_cmd_exec(cdev, ¶m);
97 [ # # ]: 0 : if (ret)
98 : 0 : PMD_DEV_LOG_ERR(adapter, DRV, "get dev fw info failed, ret=%d", ret);
99 : :
100 : 0 : return ret;
101 : : }
102 : :
103 : 0 : int32_t sxe2_drv_vsi_add(struct sxe2_adapter *adapter, struct sxe2_vsi *vsi)
104 : : {
105 : 0 : int32_t ret = 0;
106 : 0 : struct sxe2_common_device *cdev = adapter->cdev;
107 : 0 : struct sxe2_drv_cmd_params param = {0};
108 : 0 : struct sxe2_drv_vsi_create_req_resp vsi_req = {0};
109 : 0 : struct sxe2_drv_vsi_create_req_resp vsi_resp = {0};
110 : :
111 : 0 : vsi_req.vsi_id = vsi->vsi_id;
112 : :
113 : 0 : vsi_req.used_queues.queues_cnt = RTE_MIN(vsi->txqs.q_cnt, vsi->rxqs.q_cnt);
114 : 0 : vsi_req.used_queues.base_idx_in_pf = vsi->txqs.base_idx_in_func;
115 : 0 : vsi_req.used_msix.msix_vectors_cnt = vsi->irqs.avail_cnt;
116 : 0 : vsi_req.used_msix.base_idx_in_func = vsi->irqs.base_idx_in_pf;
117 : :
118 : 0 : sxe2_drv_cmd_params_fill(adapter, ¶m, SXE2_DRV_CMD_VSI_CREATE,
119 : : &vsi_req, sizeof(struct sxe2_drv_vsi_create_req_resp),
120 : : &vsi_resp, sizeof(struct sxe2_drv_vsi_create_req_resp));
121 : :
122 : 0 : ret = sxe2_drv_cmd_exec(cdev, ¶m);
123 [ # # ]: 0 : if (ret) {
124 : 0 : PMD_DEV_LOG_ERR(adapter, DRV, "dev add vsi failed, ret=%d", ret);
125 : 0 : goto l_end;
126 : : }
127 : :
128 : 0 : vsi->vsi_id = vsi_resp.vsi_id;
129 : 0 : vsi->vsi_type = vsi_resp.vsi_type;
130 : :
131 : 0 : l_end:
132 : 0 : return ret;
133 : : }
134 : :
135 : 0 : int32_t sxe2_drv_vsi_del(struct sxe2_adapter *adapter, struct sxe2_vsi *vsi)
136 : : {
137 : 0 : int32_t ret = 0;
138 : 0 : struct sxe2_common_device *cdev = adapter->cdev;
139 : 0 : struct sxe2_drv_cmd_params param = {0};
140 : 0 : struct sxe2_drv_vsi_free_req vsi_req = {0};
141 : :
142 : 0 : vsi_req.vsi_id = vsi->vsi_id;
143 : :
144 : 0 : sxe2_drv_cmd_params_fill(adapter, ¶m, SXE2_DRV_CMD_VSI_FREE,
145 : : &vsi_req, sizeof(struct sxe2_drv_vsi_free_req),
146 : : NULL, 0);
147 : :
148 : 0 : ret = sxe2_drv_cmd_exec(cdev, ¶m);
149 [ # # ]: 0 : if (ret)
150 : 0 : PMD_DEV_LOG_ERR(adapter, DRV, "dev del vsi failed, ret=%d", ret);
151 : :
152 : 0 : return ret;
153 : : }
154 : :
155 : : #define SXE2_RXQ_CTXT_CFG_BUF_LEN_ALIGN (1 << 7)
156 : : #define SXE2_RX_HDR_SIZE 256
157 : :
158 : 0 : static int32_t sxe2_rxq_ctxt_cfg_fill(struct sxe2_rx_queue *rxq,
159 : : struct sxe2_drv_rxq_cfg_req *req, uint16_t rxq_cnt)
160 : : {
161 : 0 : struct sxe2_adapter *adapter = rxq->vsi->adapter;
162 : 0 : struct sxe2_drv_rxq_ctxt *ctxt = req->cfg;
163 : 0 : struct rte_eth_dev_data *dev_data = adapter->dev_info.dev_data;
164 : 0 : int32_t ret = 0;
165 : :
166 : 0 : req->vsi_id = adapter->vsi_ctxt.main_vsi->vsi_id;
167 : 0 : req->q_cnt = rxq_cnt;
168 : 0 : req->max_frame_size = dev_data->mtu + SXE2_ETH_OVERHEAD;
169 : :
170 : 0 : ctxt->queue_id = rxq->queue_id;
171 : 0 : ctxt->depth = rxq->ring_depth;
172 : 0 : ctxt->buf_len = RTE_ALIGN(rxq->rx_buf_len, SXE2_RXQ_CTXT_CFG_BUF_LEN_ALIGN);
173 : 0 : ctxt->dma_addr = rxq->base_addr;
174 : :
175 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) {
176 : 0 : ctxt->lro_en = 1;
177 : 0 : ctxt->max_lro_size = dev_data->dev_conf.rxmode.max_lro_pkt_size;
178 : : } else {
179 : 0 : ctxt->lro_en = 0;
180 : : }
181 : :
182 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
183 : 0 : ctxt->keep_crc_en = 1;
184 : : else
185 : 0 : ctxt->keep_crc_en = 0;
186 : :
187 : 0 : ctxt->desc_size = sizeof(union sxe2_rx_desc);
188 : 0 : return ret;
189 : : }
190 : :
191 : 0 : int32_t sxe2_drv_rxq_ctxt_cfg(struct sxe2_adapter *adapter,
192 : : struct sxe2_rx_queue *rxq,
193 : : uint16_t rxq_cnt)
194 : : {
195 : 0 : int32_t ret = 0;
196 : 0 : struct sxe2_common_device *cdev = adapter->cdev;
197 : 0 : struct sxe2_drv_cmd_params param = {0};
198 : 0 : struct sxe2_drv_rxq_cfg_req *req = NULL;
199 : 0 : uint16_t len = 0;
200 : :
201 : 0 : len = sizeof(*req) + rxq_cnt * sizeof(struct sxe2_drv_rxq_ctxt);
202 : 0 : req = rte_zmalloc("sxe2_rxq_cfg", len, 0);
203 [ # # ]: 0 : if (req == NULL) {
204 : 0 : PMD_LOG_ERR(RX, "rxq cfg mem alloc failed");
205 : 0 : ret = -ENOMEM;
206 : 0 : goto l_end;
207 : : }
208 : :
209 : 0 : ret = sxe2_rxq_ctxt_cfg_fill(rxq, req, rxq_cnt);
210 [ # # ]: 0 : if (ret) {
211 : 0 : PMD_DEV_LOG_ERR(adapter, DRV, "rxq cfg failed, ret=%d", ret);
212 : 0 : ret = -EINVAL;
213 : 0 : goto l_end;
214 : : }
215 : :
216 : 0 : sxe2_drv_cmd_params_fill(adapter, ¶m, SXE2_DRV_CMD_RXQ_CFG_ENABLE,
217 : : req, len, NULL, 0);
218 : :
219 : 0 : ret = sxe2_drv_cmd_exec(cdev, ¶m);
220 [ # # ]: 0 : if (ret)
221 : 0 : PMD_DEV_LOG_ERR(adapter, DRV, "rxq cfg failed, ret=%d", ret);
222 : :
223 : 0 : l_end:
224 [ # # ]: 0 : if (req)
225 : 0 : rte_free(req);
226 : 0 : return ret;
227 : : }
228 : :
229 : 0 : static void sxe2_txq_ctxt_cfg_fill(struct sxe2_tx_queue *txq,
230 : : struct sxe2_drv_txq_cfg_req *req,
231 : : uint16_t txq_cnt)
232 : : {
233 : 0 : struct sxe2_drv_txq_ctxt *ctxt = req->cfg;
234 : 0 : uint16_t q_idx = 0;
235 : :
236 : 0 : req->vsi_id = txq->vsi->vsi_id;
237 : 0 : req->q_cnt = txq_cnt;
238 : :
239 [ # # ]: 0 : for (q_idx = 0; q_idx < txq_cnt; q_idx++) {
240 : 0 : ctxt = &req->cfg[q_idx];
241 : 0 : ctxt->depth = txq[q_idx].ring_depth;
242 : 0 : ctxt->dma_addr = txq[q_idx].base_addr;
243 : 0 : ctxt->queue_id = txq[q_idx].queue_id;
244 : : }
245 : : }
246 : :
247 : 0 : int32_t sxe2_drv_txq_ctxt_cfg(struct sxe2_adapter *adapter,
248 : : struct sxe2_tx_queue *txq,
249 : : uint16_t txq_cnt)
250 : : {
251 : 0 : int32_t ret = 0;
252 : 0 : struct sxe2_common_device *cdev = adapter->cdev;
253 : 0 : struct sxe2_drv_cmd_params param = {0};
254 : 0 : struct sxe2_drv_txq_cfg_req *req;
255 : 0 : uint16_t len = 0;
256 : :
257 : 0 : len = sizeof(*req) + txq_cnt * sizeof(struct sxe2_drv_txq_ctxt);
258 : 0 : req = rte_zmalloc("sxe2_txq_cfg", len, 0);
259 [ # # ]: 0 : if (req == NULL) {
260 : 0 : PMD_LOG_ERR(TX, "txq cfg mem alloc failed");
261 : 0 : ret = -ENOMEM;
262 : 0 : goto l_end;
263 : : }
264 : :
265 : 0 : sxe2_txq_ctxt_cfg_fill(txq, req, txq_cnt);
266 : :
267 : 0 : sxe2_drv_cmd_params_fill(adapter, ¶m, SXE2_DRV_CMD_TXQ_CFG_ENABLE,
268 : : req, len, NULL, 0);
269 : :
270 : 0 : ret = sxe2_drv_cmd_exec(cdev, ¶m);
271 [ # # ]: 0 : if (ret)
272 : 0 : PMD_DEV_LOG_ERR(adapter, DRV, "txq cfg failed, ret=%d", ret);
273 : :
274 : 0 : l_end:
275 [ # # ]: 0 : if (req)
276 : 0 : rte_free(req);
277 : 0 : return ret;
278 : : }
279 : :
280 : 0 : int32_t sxe2_drv_rxq_switch(struct sxe2_adapter *adapter, struct sxe2_rx_queue *rxq, bool enable)
281 : : {
282 : 0 : int32_t ret = 0;
283 : 0 : struct sxe2_common_device *cdev = adapter->cdev;
284 : 0 : struct sxe2_drv_cmd_params param = {0};
285 : 0 : struct sxe2_drv_q_switch_req req;
286 : :
287 : 0 : req.vsi_id = rte_cpu_to_le_16(rxq->vsi->vsi_id);
288 : 0 : req.q_idx = rxq->queue_id;
289 : :
290 : 0 : req.is_enable = (uint8_t)enable;
291 : 0 : sxe2_drv_cmd_params_fill(adapter, ¶m, SXE2_DRV_CMD_RXQ_DISABLE,
292 : : &req, sizeof(req), NULL, 0);
293 : :
294 : 0 : ret = sxe2_drv_cmd_exec(cdev, ¶m);
295 [ # # ]: 0 : if (ret)
296 : 0 : PMD_DEV_LOG_ERR(adapter, DRV, "rxq switch failed, enable: %d, ret:%d",
297 : : enable, ret);
298 : :
299 : 0 : return ret;
300 : : }
301 : :
302 : 0 : int32_t sxe2_drv_txq_switch(struct sxe2_adapter *adapter, struct sxe2_tx_queue *txq, bool enable)
303 : : {
304 : 0 : int32_t ret = 0;
305 : 0 : struct sxe2_common_device *cdev = adapter->cdev;
306 : 0 : struct sxe2_drv_cmd_params param = {0};
307 : 0 : struct sxe2_drv_q_switch_req req;
308 : :
309 : 0 : req.vsi_id = rte_cpu_to_le_16(txq->vsi->vsi_id);
310 : 0 : req.q_idx = txq->queue_id;
311 : :
312 : 0 : req.is_enable = (uint8_t)enable;
313 : 0 : sxe2_drv_cmd_params_fill(adapter, ¶m, SXE2_DRV_CMD_TXQ_DISABLE,
314 : : &req, sizeof(req), NULL, 0);
315 : :
316 : 0 : ret = sxe2_drv_cmd_exec(cdev, ¶m);
317 [ # # ]: 0 : if (ret) {
318 : 0 : PMD_DEV_LOG_ERR(adapter, DRV, "txq switch failed, enable: %d, ret:%d",
319 : : enable, ret);
320 : : }
321 : :
322 : 0 : return ret;
323 : : }
|