Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2024-2026 NXP
3 : : */
4 : :
5 : : #include <stdbool.h>
6 : : #include <rte_kvargs.h>
7 : : #include <rte_random.h>
8 : : #include <dpaax_iova_table.h>
9 : :
10 : : #include "base/enetc4_hw.h"
11 : : #include "enetc_logs.h"
12 : : #include "enetc.h"
13 : :
14 : : #define ENETC4_TXQ_PRIORITIES "enetc4_txq_prior"
15 : : #define ENETC4_NC_MEMORY "nc"
16 : :
17 : : static int
18 : 0 : parse_txq_prior(const char *key __rte_unused, const char *value, void *opaque)
19 : : {
20 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)opaque;
21 : : struct enetc_eth_hw *hw =
22 : 0 : ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
23 : 0 : char *input_str = strdup(value);
24 : : char *str;
25 : : uint32_t i = 0;
26 : :
27 [ # # ]: 0 : if (!input_str)
28 : : return -ENOMEM;
29 : :
30 : 0 : hw->txq_prior = calloc(hw->max_tx_queues, sizeof(uint32_t));
31 [ # # ]: 0 : if (!hw->txq_prior) {
32 : 0 : free(input_str);
33 : 0 : return -ENOMEM;
34 : : }
35 : :
36 : 0 : str = strtok(input_str, "|");
37 [ # # # # ]: 0 : while (str != NULL && i < hw->max_tx_queues) {
38 : 0 : hw->txq_prior[i++] = (uint32_t)atoi(str);
39 : 0 : str = strtok(NULL, "|");
40 : : }
41 : :
42 : 0 : free(input_str);
43 : 0 : return 0;
44 : : }
45 : :
46 : : static int
47 : 0 : parse_nc(const char *key __rte_unused, const char *value, void *extra_args)
48 : : {
49 : : struct rte_eth_dev *dev = extra_args;
50 : : struct enetc_eth_hw *hw =
51 : 0 : ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
52 : :
53 [ # # # # ]: 0 : if (value && atoi(value) == 1)
54 : 0 : hw->nc_mode = 1;
55 : :
56 : 0 : return 0;
57 : : }
58 : :
59 : : static int
60 : 0 : enetc4_get_devargs(struct rte_eth_dev *dev, const char *key)
61 : : {
62 : 0 : struct rte_devargs *devargs = dev->device->devargs;
63 : : struct rte_kvargs *kvlist;
64 : :
65 [ # # ]: 0 : if (!devargs)
66 : : return 0;
67 : :
68 : 0 : kvlist = rte_kvargs_parse(devargs->args, NULL);
69 [ # # ]: 0 : if (!kvlist)
70 : : return 0;
71 : :
72 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, key)) {
73 : 0 : rte_kvargs_free(kvlist);
74 : 0 : return 0;
75 : : }
76 : :
77 [ # # ]: 0 : if (!strcmp(key, ENETC4_TXQ_PRIORITIES)) {
78 [ # # ]: 0 : if (rte_kvargs_process(kvlist, key,
79 : : parse_txq_prior, (void *)dev) < 0) {
80 : 0 : rte_kvargs_free(kvlist);
81 : 0 : return 0;
82 : : }
83 : : }
84 [ # # ]: 0 : if (!strcmp(key, ENETC4_NC_MEMORY)) {
85 [ # # ]: 0 : if (rte_kvargs_process(kvlist, key,
86 : : parse_nc, (void *)dev) < 0) {
87 : 0 : rte_kvargs_free(kvlist);
88 : 0 : return 0;
89 : : }
90 : : }
91 : :
92 : 0 : rte_kvargs_free(kvlist);
93 : 0 : return 0;
94 : : }
95 : :
96 : : /* Supported Rx offloads */
97 : : static uint64_t dev_rx_offloads_sup =
98 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
99 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
100 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
101 : : RTE_ETH_RX_OFFLOAD_SCATTER;
102 : :
103 : : /* Supported Tx offloads */
104 : : static uint64_t dev_tx_offloads_sup =
105 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
106 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
107 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
108 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
109 : :
110 : : static int
111 : 0 : enetc4_dev_start(struct rte_eth_dev *dev)
112 : : {
113 : : struct enetc_eth_hw *hw =
114 : 0 : ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
115 : : struct enetc_hw *enetc_hw = &hw->hw;
116 : : struct enetc_bdr *txq, *rxq;
117 : : uint32_t val;
118 : : int i, ret;
119 : :
120 : 0 : PMD_INIT_FUNC_TRACE();
121 : :
122 : : /* Start TX queues that are not deferred */
123 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
124 : 0 : txq = dev->data->tx_queues[i];
125 [ # # # # ]: 0 : if (txq && !txq->tx_deferred_start) {
126 : 0 : ret = enetc4_tx_queue_start(dev, i);
127 [ # # ]: 0 : if (ret < 0)
128 : 0 : return ret;
129 : : }
130 : : }
131 : :
132 : : /* Start RX queues that are not deferred */
133 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
134 : 0 : rxq = dev->data->rx_queues[i];
135 [ # # # # ]: 0 : if (rxq && !rxq->rx_deferred_start) {
136 : 0 : ret = enetc4_rx_queue_start(dev, i);
137 [ # # ]: 0 : if (ret < 0)
138 : 0 : return ret;
139 : : }
140 : : }
141 : :
142 : 0 : val = enetc4_port_rd(enetc_hw, ENETC4_PM_CMD_CFG(0));
143 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PM_CMD_CFG(0),
144 : : val | PM_CMD_CFG_TX_EN | PM_CMD_CFG_RX_EN);
145 : :
146 : 0 : val = enetc4_port_rd(enetc_hw, ENETC4_PM_CMD_CFG(1));
147 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PM_CMD_CFG(1),
148 : : val | PM_CMD_CFG_TX_EN | PM_CMD_CFG_RX_EN);
149 : :
150 : : /* Enable port */
151 : 0 : val = enetc4_port_rd(enetc_hw, ENETC4_PMR);
152 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PMR, val | ENETC4_PMR_EN);
153 : :
154 : : /* Enable port transmit/receive */
155 : 0 : enetc4_port_wr(enetc_hw, ENETC4_POR, 0);
156 : :
157 : 0 : return 0;
158 : : }
159 : :
160 : : static int
161 : 0 : enetc4_dev_stop(struct rte_eth_dev *dev)
162 : : {
163 : : struct enetc_eth_hw *hw =
164 : 0 : ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
165 : : struct enetc_hw *enetc_hw = &hw->hw;
166 : : uint32_t val;
167 : :
168 : 0 : PMD_INIT_FUNC_TRACE();
169 : :
170 : : /* Disable port */
171 : 0 : val = enetc4_port_rd(enetc_hw, ENETC4_PMR);
172 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PMR, val & (~ENETC4_PMR_EN));
173 : :
174 : 0 : val = enetc4_port_rd(enetc_hw, ENETC4_PM_CMD_CFG(0));
175 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PM_CMD_CFG(0),
176 : : val & (~(PM_CMD_CFG_TX_EN | PM_CMD_CFG_RX_EN)));
177 : :
178 : 0 : val = enetc4_port_rd(enetc_hw, ENETC4_PM_CMD_CFG(1));
179 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PM_CMD_CFG(1),
180 : : val & (~(PM_CMD_CFG_TX_EN | PM_CMD_CFG_RX_EN)));
181 : :
182 : 0 : return 0;
183 : : }
184 : :
185 : : /* return 0 means link status changed, -1 means not changed */
186 : : static int
187 : 0 : enetc4_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
188 : : {
189 : : struct enetc_eth_hw *hw =
190 : 0 : ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
191 : : struct enetc_hw *enetc_hw = &hw->hw;
192 : : struct rte_eth_link link;
193 : : uint32_t status;
194 : :
195 : 0 : PMD_INIT_FUNC_TRACE();
196 : :
197 : : memset(&link, 0, sizeof(link));
198 : :
199 : 0 : status = enetc4_port_rd(enetc_hw, ENETC4_PM_IF_STATUS(0));
200 : :
201 [ # # ]: 0 : if (status & ENETC4_LINK_MODE)
202 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
203 : : else
204 : 0 : link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
205 : :
206 [ # # ]: 0 : if (status & ENETC4_LINK_STATUS)
207 : 0 : link.link_status = RTE_ETH_LINK_UP;
208 : : else
209 : 0 : link.link_status = RTE_ETH_LINK_DOWN;
210 : :
211 [ # # # ]: 0 : switch (status & ENETC4_LINK_SPEED_MASK) {
212 : 0 : case ENETC4_LINK_SPEED_1G:
213 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_1G;
214 : 0 : break;
215 : :
216 : 0 : case ENETC4_LINK_SPEED_100M:
217 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_100M;
218 : 0 : break;
219 : :
220 : 0 : default:
221 : : case ENETC4_LINK_SPEED_10M:
222 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_10M;
223 : : }
224 : :
225 : 0 : return rte_eth_linkstatus_set(dev, &link);
226 : : }
227 : :
228 : : static int
229 : 0 : enetc4_mac_init(struct enetc_eth_hw *hw, struct rte_eth_dev *eth_dev)
230 : : {
231 : : struct enetc_hw *enetc_hw = &hw->hw;
232 : : uint32_t high_mac = 0;
233 : : uint16_t low_mac = 0;
234 : : char eth_name[ENETC_ETH_NAMESIZE];
235 : :
236 : 0 : PMD_INIT_FUNC_TRACE();
237 : :
238 : : /* Enabling Station Interface */
239 : 0 : enetc4_wr(enetc_hw, ENETC_SIMR, ENETC_SIMR_EN);
240 : :
241 : 0 : high_mac = (uint32_t)enetc4_port_rd(enetc_hw, ENETC4_PSIPMAR0(0));
242 : 0 : low_mac = (uint16_t)enetc4_port_rd(enetc_hw, ENETC4_PSIPMAR1(0));
243 : :
244 [ # # ]: 0 : if ((high_mac | low_mac) == 0) {
245 : 0 : ENETC_PMD_NOTICE("MAC is not available for this SI, "
246 : : "set random MAC");
247 : 0 : rte_eth_random_addr(hw->mac.addr);
248 : 0 : high_mac = *(uint32_t *)hw->mac.addr;
249 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PMAR0, high_mac);
250 : 0 : low_mac = *(uint16_t *)(hw->mac.addr + 4);
251 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PMAR1, low_mac);
252 : 0 : enetc_print_ethaddr("New address: ",
253 : : (const struct rte_ether_addr *)hw->mac.addr);
254 : : }
255 : :
256 : : /* Allocate memory for storing MAC addresses */
257 : 0 : snprintf(eth_name, sizeof(eth_name), "enetc4_eth_%d", eth_dev->data->port_id);
258 : 0 : eth_dev->data->mac_addrs = rte_zmalloc(eth_name,
259 : : RTE_ETHER_ADDR_LEN, 0);
260 [ # # ]: 0 : if (!eth_dev->data->mac_addrs) {
261 : 0 : ENETC_PMD_ERR("Failed to allocate %d bytes needed to "
262 : : "store MAC addresses",
263 : : RTE_ETHER_ADDR_LEN * 1);
264 : 0 : return -ENOMEM;
265 : : }
266 : :
267 : : /* Copy the permanent MAC address */
268 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
269 : : ð_dev->data->mac_addrs[0]);
270 : :
271 : 0 : return 0;
272 : : }
273 : :
274 : : int
275 : 0 : enetc4_dev_infos_get(struct rte_eth_dev *dev,
276 : : struct rte_eth_dev_info *dev_info)
277 : : {
278 : : struct enetc_eth_hw *hw =
279 : 0 : ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
280 : :
281 : 0 : PMD_INIT_FUNC_TRACE();
282 : :
283 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
284 : : .nb_max = MAX_BD_COUNT,
285 : : .nb_min = MIN_BD_COUNT,
286 : : .nb_align = BD_ALIGN,
287 : : .nb_seg_max = ENETC4_MAX_SEGS,
288 : : .nb_mtu_seg_max = ENETC4_MAX_SEGS,
289 : : };
290 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
291 : : .nb_max = MAX_BD_COUNT,
292 : : .nb_min = MIN_BD_COUNT,
293 : : .nb_align = BD_ALIGN,
294 : : .nb_seg_max = ENETC4_MAX_SEGS,
295 : : .nb_mtu_seg_max = ENETC4_MAX_SEGS,
296 : : };
297 : 0 : dev_info->max_rx_queues = hw->max_rx_queues;
298 : 0 : dev_info->max_tx_queues = hw->max_tx_queues;
299 : 0 : dev_info->max_rx_pktlen = ENETC4_MAC_MAXFRM_SIZE;
300 : 0 : dev_info->rx_offload_capa = dev_rx_offloads_sup;
301 : 0 : dev_info->tx_offload_capa = dev_tx_offloads_sup;
302 : 0 : dev_info->flow_type_rss_offloads = ENETC_RSS_OFFLOAD_ALL;
303 : :
304 : 0 : return 0;
305 : : }
306 : :
307 : : static int
308 : 0 : enetc4_alloc_txbdr(struct enetc_bdr *txr, uint16_t nb_desc)
309 : : {
310 : : int size;
311 : :
312 : 0 : size = nb_desc * sizeof(struct enetc_swbd);
313 : : /* Zero q_swbd so buffer_addr is NULL for all uninitialized slots. */
314 : 0 : txr->q_swbd = rte_zmalloc(NULL, size, ENETC_BD_RING_ALIGN);
315 [ # # ]: 0 : if (txr->q_swbd == NULL)
316 : : return -ENOMEM;
317 : :
318 : : /* Allocate the TX BD ring: each BD is struct enetc_tx_bd (16 bytes). */
319 : 0 : size = nb_desc * sizeof(struct enetc_tx_bd);
320 : 0 : txr->bd_base = rte_zmalloc(NULL, size, ENETC_BD_RING_ALIGN);
321 [ # # ]: 0 : if (txr->bd_base == NULL) {
322 : 0 : rte_free(txr->q_swbd);
323 : 0 : txr->q_swbd = NULL;
324 : 0 : return -ENOMEM;
325 : : }
326 : 0 : txr->bd_count = nb_desc;
327 : 0 : txr->next_to_clean = 0;
328 : 0 : txr->next_to_use = 0;
329 : :
330 : 0 : return 0;
331 : : }
332 : :
333 : : static void
334 : : enetc4_free_bdr(struct enetc_bdr *rxr)
335 : : {
336 : 0 : rte_free(rxr->bd_base);
337 : 0 : rte_free(rxr->q_swbd);
338 : 0 : rxr->q_swbd = NULL;
339 : 0 : rxr->bd_base = NULL;
340 : : }
341 : :
342 : : static void
343 : 0 : enetc4_setup_txbdr(struct enetc_hw *hw, struct enetc_bdr *tx_ring)
344 : : {
345 : 0 : int idx = tx_ring->index;
346 : : phys_addr_t bd_address;
347 : :
348 : : bd_address = (phys_addr_t)
349 : 0 : rte_mem_virt2iova((const void *)tx_ring->bd_base);
350 : 0 : enetc4_txbdr_wr(hw, idx, ENETC_TBBAR0,
351 : : lower_32_bits((uint64_t)bd_address));
352 : 0 : enetc4_txbdr_wr(hw, idx, ENETC_TBBAR1,
353 : : upper_32_bits((uint64_t)bd_address));
354 : 0 : enetc4_txbdr_wr(hw, idx, ENETC_TBLENR,
355 : : ENETC_RTBLENR_LEN(tx_ring->bd_count));
356 : :
357 : 0 : enetc4_txbdr_wr(hw, idx, ENETC_TBCIR, 0);
358 : 0 : enetc4_txbdr_wr(hw, idx, ENETC_TBCISR, 0);
359 : 0 : tx_ring->tcir = (void *)((size_t)hw->reg +
360 : : ENETC_BDR(TX, idx, ENETC_TBCIR));
361 : 0 : tx_ring->tcisr = (void *)((size_t)hw->reg +
362 : : ENETC_BDR(TX, idx, ENETC_TBCISR));
363 : 0 : }
364 : :
365 : : int
366 : 0 : enetc4_tx_queue_setup(struct rte_eth_dev *dev,
367 : : uint16_t queue_idx,
368 : : uint16_t nb_desc,
369 : : unsigned int socket_id __rte_unused,
370 : : const struct rte_eth_txconf *tx_conf)
371 : : {
372 : : int err;
373 : : uint32_t tx_data;
374 : : struct enetc_bdr *tx_ring;
375 : 0 : struct rte_eth_dev_data *data = dev->data;
376 : 0 : struct enetc_eth_adapter *priv =
377 : : ENETC_DEV_PRIVATE(data->dev_private);
378 : :
379 : 0 : PMD_INIT_FUNC_TRACE();
380 [ # # ]: 0 : if (nb_desc > MAX_BD_COUNT)
381 : : return -1;
382 : :
383 : 0 : tx_ring = rte_zmalloc(NULL, sizeof(struct enetc_bdr), 0);
384 [ # # ]: 0 : if (tx_ring == NULL) {
385 : 0 : ENETC_PMD_ERR("Failed to allocate TX ring memory");
386 : : err = -ENOMEM;
387 : 0 : return err;
388 : : }
389 : :
390 : 0 : tx_ring->index = queue_idx;
391 : 0 : err = enetc4_alloc_txbdr(tx_ring, nb_desc);
392 [ # # ]: 0 : if (err)
393 : 0 : goto fail;
394 : :
395 : 0 : tx_ring->ndev = dev;
396 : : /* reset queue */
397 : 0 : tx_data = enetc4_txbdr_rd(&priv->hw.hw, tx_ring->index, ENETC_TBMR);
398 : 0 : tx_data &= ~ENETC_TBMR_EN;
399 : 0 : enetc4_txbdr_wr(&priv->hw.hw, tx_ring->index, ENETC_TBMR, tx_data);
400 : 0 : enetc4_setup_txbdr(&priv->hw.hw, tx_ring);
401 : 0 : data->tx_queues[queue_idx] = tx_ring;
402 : 0 : tx_ring->tx_deferred_start = tx_conf->tx_deferred_start;
403 [ # # ]: 0 : if (!tx_conf->tx_deferred_start) {
404 : : uint32_t tx_en = ENETC_TBMR_EN;
405 : :
406 : : /* apply TX queue priority if configured */
407 [ # # ]: 0 : if (priv->hw.txq_prior)
408 : 0 : tx_en |= priv->hw.txq_prior[tx_ring->index];
409 : : /* enable ring */
410 : 0 : enetc4_txbdr_wr(&priv->hw.hw, tx_ring->index,
411 : : ENETC_TBMR, tx_en);
412 : 0 : dev->data->tx_queue_state[tx_ring->index] =
413 : : RTE_ETH_QUEUE_STATE_STARTED;
414 : : } else {
415 : 0 : dev->data->tx_queue_state[tx_ring->index] =
416 : : RTE_ETH_QUEUE_STATE_STOPPED;
417 : : }
418 : :
419 : : return 0;
420 : : fail:
421 : 0 : rte_free(tx_ring);
422 : :
423 : 0 : return err;
424 : : }
425 : :
426 : : void
427 : 0 : enetc4_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
428 : : {
429 : 0 : void *txq = dev->data->tx_queues[qid];
430 : : struct enetc_hw *hw;
431 : : struct enetc_swbd *tx_swbd;
432 : : int i;
433 : : uint32_t val;
434 : : struct enetc_bdr *tx_ring;
435 : : struct enetc_eth_hw *eth_hw;
436 : :
437 : 0 : PMD_INIT_FUNC_TRACE();
438 [ # # ]: 0 : if (txq == NULL)
439 : : return;
440 : :
441 : : tx_ring = (struct enetc_bdr *)txq;
442 : : eth_hw =
443 : 0 : ENETC_DEV_PRIVATE_TO_HW(tx_ring->ndev->data->dev_private);
444 : :
445 : : /* Disable the ring */
446 : : hw = ð_hw->hw;
447 : 0 : val = enetc4_txbdr_rd(hw, tx_ring->index, ENETC_TBMR);
448 : 0 : val &= (~ENETC_TBMR_EN);
449 : 0 : enetc4_txbdr_wr(hw, tx_ring->index, ENETC_TBMR, val);
450 : :
451 : : /* clean the ring*/
452 : 0 : i = tx_ring->next_to_clean;
453 : 0 : tx_swbd = &tx_ring->q_swbd[i];
454 [ # # ]: 0 : while (tx_swbd->buffer_addr != NULL) {
455 : 0 : rte_pktmbuf_free(tx_swbd->buffer_addr);
456 : 0 : tx_swbd->buffer_addr = NULL;
457 : 0 : tx_swbd++;
458 : 0 : i++;
459 [ # # ]: 0 : if (unlikely(i == tx_ring->bd_count)) {
460 : : i = 0;
461 : 0 : tx_swbd = &tx_ring->q_swbd[i];
462 : : }
463 : : }
464 : :
465 : : enetc4_free_bdr(tx_ring);
466 : 0 : rte_free(tx_ring);
467 : : }
468 : :
469 : : static int
470 : 0 : enetc4_alloc_rxbdr(struct enetc_bdr *rxr, uint16_t nb_desc)
471 : : {
472 : : int size;
473 : :
474 : 0 : size = nb_desc * sizeof(struct enetc_swbd);
475 : : /* Zero q_swbd so buffer_addr is NULL for all uninitialized slots. */
476 : 0 : rxr->q_swbd = rte_zmalloc(NULL, size, ENETC_BD_RING_ALIGN);
477 [ # # ]: 0 : if (rxr->q_swbd == NULL)
478 : : return -ENOMEM;
479 : :
480 : : /* Allocate the RX BD ring: each BD is union enetc_rx_bd (16 bytes). */
481 : 0 : size = nb_desc * sizeof(union enetc_rx_bd);
482 : 0 : rxr->bd_base = rte_zmalloc(NULL, size, ENETC_BD_RING_ALIGN);
483 [ # # ]: 0 : if (rxr->bd_base == NULL) {
484 : 0 : rte_free(rxr->q_swbd);
485 : 0 : rxr->q_swbd = NULL;
486 : 0 : return -ENOMEM;
487 : : }
488 : 0 : rxr->bd_count = nb_desc;
489 : 0 : rxr->next_to_clean = 0;
490 : 0 : rxr->next_to_use = 0;
491 : 0 : rxr->next_to_alloc = 0;
492 : :
493 : 0 : return 0;
494 : : }
495 : :
496 : : static void
497 : 0 : enetc4_setup_rxbdr(struct enetc_hw *hw, struct enetc_bdr *rx_ring,
498 : : struct rte_mempool *mb_pool)
499 : : {
500 : 0 : int idx = rx_ring->index;
501 : : uint16_t buf_size;
502 : : phys_addr_t bd_address;
503 : :
504 : : bd_address = (phys_addr_t)
505 : 0 : rte_mem_virt2iova((const void *)rx_ring->bd_base);
506 : :
507 : 0 : enetc4_rxbdr_wr(hw, idx, ENETC_RBBAR0,
508 : : lower_32_bits((uint64_t)bd_address));
509 : 0 : enetc4_rxbdr_wr(hw, idx, ENETC_RBBAR1,
510 : : upper_32_bits((uint64_t)bd_address));
511 : 0 : enetc4_rxbdr_wr(hw, idx, ENETC_RBLENR,
512 : : ENETC_RTBLENR_LEN(rx_ring->bd_count));
513 : :
514 : 0 : rx_ring->mb_pool = mb_pool;
515 : 0 : rx_ring->rcir = (void *)((size_t)hw->reg +
516 [ # # ]: 0 : ENETC_BDR(RX, idx, ENETC_RBCIR));
517 : 0 : enetc_refill_rx_ring(rx_ring, ENETC_BD_ALIGN_DOWN(enetc_bd_unused(rx_ring)));
518 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rx_ring->mb_pool) -
519 : : RTE_PKTMBUF_HEADROOM);
520 : 0 : enetc4_rxbdr_wr(hw, idx, ENETC_RBBSR, buf_size);
521 : 0 : enetc4_rxbdr_wr(hw, idx, ENETC_RBPIR, 0);
522 : 0 : }
523 : :
524 : : int
525 : 0 : enetc4_rx_queue_setup(struct rte_eth_dev *dev,
526 : : uint16_t rx_queue_id,
527 : : uint16_t nb_rx_desc,
528 : : unsigned int socket_id __rte_unused,
529 : : const struct rte_eth_rxconf *rx_conf,
530 : : struct rte_mempool *mb_pool)
531 : : {
532 : : int err = 0;
533 : : uint32_t rx_enable;
534 : : struct enetc_bdr *rx_ring;
535 : 0 : struct rte_eth_dev_data *data = dev->data;
536 : 0 : struct enetc_eth_adapter *adapter =
537 : : ENETC_DEV_PRIVATE(data->dev_private);
538 : 0 : uint64_t rx_offloads = data->dev_conf.rxmode.offloads;
539 : :
540 : 0 : PMD_INIT_FUNC_TRACE();
541 [ # # ]: 0 : if (nb_rx_desc > MAX_BD_COUNT)
542 : : return -1;
543 : :
544 : 0 : rx_ring = rte_zmalloc(NULL, sizeof(struct enetc_bdr), 0);
545 [ # # ]: 0 : if (rx_ring == NULL) {
546 : 0 : ENETC_PMD_ERR("Failed to allocate RX ring memory");
547 : : err = -ENOMEM;
548 : 0 : return err;
549 : : }
550 : :
551 : 0 : rx_ring->index = rx_queue_id;
552 : 0 : err = enetc4_alloc_rxbdr(rx_ring, nb_rx_desc);
553 [ # # ]: 0 : if (err)
554 : 0 : goto fail;
555 : :
556 : 0 : rx_ring->ndev = dev;
557 : : /* reset queue */
558 : 0 : rx_enable = enetc4_rxbdr_rd(&adapter->hw.hw, rx_ring->index, ENETC_RBMR);
559 : 0 : rx_enable &= ~ENETC_RBMR_EN;
560 : 0 : enetc4_rxbdr_wr(&adapter->hw.hw, rx_ring->index, ENETC_RBMR, rx_enable);
561 : 0 : enetc4_setup_rxbdr(&adapter->hw.hw, rx_ring, mb_pool);
562 : 0 : data->rx_queues[rx_queue_id] = rx_ring;
563 : 0 : rx_ring->rx_deferred_start = rx_conf->rx_deferred_start;
564 : :
565 [ # # ]: 0 : if (!rx_conf->rx_deferred_start) {
566 : : /* enable ring */
567 : 0 : enetc4_rxbdr_wr(&adapter->hw.hw, rx_ring->index, ENETC_RBMR,
568 : : ENETC_RBMR_EN);
569 : 0 : dev->data->rx_queue_state[rx_ring->index] =
570 : : RTE_ETH_QUEUE_STATE_STARTED;
571 : : } else {
572 : 0 : dev->data->rx_queue_state[rx_ring->index] =
573 : : RTE_ETH_QUEUE_STATE_STOPPED;
574 : : }
575 : :
576 : 0 : rx_ring->crc_len = (uint8_t)((rx_offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) ?
577 : : RTE_ETHER_CRC_LEN : 0);
578 : 0 : return 0;
579 : : fail:
580 : 0 : rte_free(rx_ring);
581 : :
582 : 0 : return err;
583 : : }
584 : :
585 : : void
586 : 0 : enetc4_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
587 : : {
588 : 0 : void *rxq = dev->data->rx_queues[qid];
589 : : struct enetc_swbd *q_swbd;
590 : : struct enetc_hw *hw;
591 : : uint32_t val;
592 : : int i;
593 : : struct enetc_bdr *rx_ring;
594 : : struct enetc_eth_hw *eth_hw;
595 : :
596 : 0 : PMD_INIT_FUNC_TRACE();
597 [ # # ]: 0 : if (rxq == NULL)
598 : : return;
599 : :
600 : : rx_ring = (struct enetc_bdr *)rxq;
601 : : eth_hw =
602 : 0 : ENETC_DEV_PRIVATE_TO_HW(rx_ring->ndev->data->dev_private);
603 : :
604 : : /* Disable the ring */
605 : : hw = ð_hw->hw;
606 : 0 : val = enetc4_rxbdr_rd(hw, rx_ring->index, ENETC_RBMR);
607 : 0 : val &= (~ENETC_RBMR_EN);
608 : 0 : enetc4_rxbdr_wr(hw, rx_ring->index, ENETC_RBMR, val);
609 : :
610 : : /* Clean the ring */
611 : 0 : i = rx_ring->next_to_clean;
612 : 0 : q_swbd = &rx_ring->q_swbd[i];
613 [ # # ]: 0 : while (i != rx_ring->next_to_use) {
614 : 0 : rte_pktmbuf_free(q_swbd->buffer_addr);
615 : 0 : q_swbd->buffer_addr = NULL;
616 : 0 : q_swbd++;
617 : 0 : i++;
618 [ # # ]: 0 : if (unlikely(i == rx_ring->bd_count)) {
619 : : i = 0;
620 : 0 : q_swbd = &rx_ring->q_swbd[i];
621 : : }
622 : : }
623 : :
624 : : enetc4_free_bdr(rx_ring);
625 : 0 : rte_free(rx_ring);
626 : : }
627 : :
628 : : static
629 : 0 : int enetc4_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
630 : : struct eth_queue_stats *qstats __rte_unused)
631 : : {
632 : : struct enetc_eth_hw *hw =
633 : 0 : ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
634 : : struct enetc_hw *enetc_hw = &hw->hw;
635 : :
636 : : /*
637 : : * Total received packets, bad + good, if we want to get counters
638 : : * of only good received packets then use ENETC4_PM_RFRM,
639 : : * ENETC4_PM_TFRM registers.
640 : : */
641 : 0 : stats->ipackets = enetc4_port_rd(enetc_hw, ENETC4_PM_RPKT(0));
642 : 0 : stats->opackets = enetc4_port_rd(enetc_hw, ENETC4_PM_TPKT(0));
643 : 0 : stats->ibytes = enetc4_port_rd(enetc_hw, ENETC4_PM_REOCT(0));
644 : 0 : stats->obytes = enetc4_port_rd(enetc_hw, ENETC4_PM_TEOCT(0));
645 : : /*
646 : : * Dropped + Truncated packets, use ENETC4_PM_RDRNTP(0) for without
647 : : * truncated packets
648 : : */
649 : 0 : stats->imissed = enetc4_port_rd(enetc_hw, ENETC4_PM_RDRP(0));
650 : 0 : stats->ierrors = enetc4_port_rd(enetc_hw, ENETC4_PM_RERR(0));
651 : 0 : stats->oerrors = enetc4_port_rd(enetc_hw, ENETC4_PM_TERR(0));
652 : :
653 : 0 : return 0;
654 : : }
655 : :
656 : : static int
657 : 0 : enetc4_stats_reset(struct rte_eth_dev *dev)
658 : : {
659 : : struct enetc_eth_hw *hw =
660 : 0 : ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
661 : : struct enetc_hw *enetc_hw = &hw->hw;
662 : :
663 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PM0_STAT_CONFIG, ENETC4_CLEAR_STATS);
664 : :
665 : 0 : return 0;
666 : : }
667 : :
668 : : static void
669 : : enetc4_rss_configure(struct enetc_hw *hw, int enable)
670 : : {
671 : : uint32_t reg;
672 : :
673 : 0 : reg = enetc4_rd(hw, ENETC_SIMR);
674 : 0 : reg &= ~ENETC_SIMR_RSSE;
675 : 0 : reg |= (enable) ? ENETC_SIMR_RSSE : 0;
676 : 0 : enetc4_wr(hw, ENETC_SIMR, reg);
677 : 0 : }
678 : :
679 : : int
680 : 0 : enetc4_dev_close(struct rte_eth_dev *dev)
681 : : {
682 : 0 : struct enetc_eth_hw *hw = ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
683 : : struct enetc_hw *enetc_hw = &hw->hw;
684 : : uint16_t i;
685 : : int ret;
686 : :
687 : 0 : PMD_INIT_FUNC_TRACE();
688 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
689 : : return 0;
690 : :
691 [ # # ]: 0 : if (hw->device_id == ENETC4_DEV_ID_VF) {
692 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
693 : 0 : enetc4_vf_dev_intr(dev, false);
694 : 0 : ret = enetc4_vf_dev_stop(dev);
695 : : } else {
696 : 0 : ret = enetc4_dev_stop(dev);
697 : : }
698 : :
699 [ # # ]: 0 : if (dev->data->nb_rx_queues > 1) {
700 : : /* Disable RSS */
701 : : enetc4_rss_configure(enetc_hw, false);
702 : : /* Free CBDR */
703 : 0 : enetc_free_cbdr(&hw->cbdr);
704 : : }
705 : :
706 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
707 : 0 : enetc4_rx_queue_release(dev, i);
708 : 0 : dev->data->rx_queues[i] = NULL;
709 : : }
710 : 0 : dev->data->nb_rx_queues = 0;
711 : :
712 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
713 : 0 : enetc4_tx_queue_release(dev, i);
714 : 0 : dev->data->tx_queues[i] = NULL;
715 : : }
716 : 0 : dev->data->nb_tx_queues = 0;
717 : :
718 [ # # ]: 0 : if (rte_eal_iova_mode() == RTE_IOVA_PA)
719 : 0 : dpaax_iova_table_depopulate();
720 : :
721 : : return ret;
722 : : }
723 : :
724 : : static int
725 : 0 : enetc4_promiscuous_enable(struct rte_eth_dev *dev)
726 : : {
727 : : struct enetc_eth_hw *hw =
728 : 0 : ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
729 : : struct enetc_hw *enetc_hw = &hw->hw;
730 : : uint32_t psipmr = 0;
731 : :
732 : 0 : psipmr = enetc4_port_rd(enetc_hw, ENETC4_PSIPMMR);
733 : :
734 : : /* Setting to enable promiscuous mode for all ports*/
735 : 0 : psipmr |= PSIPMMR_SI_MAC_UP | PSIPMMR_SI_MAC_MP;
736 : :
737 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PSIPMMR, psipmr);
738 : :
739 : 0 : return 0;
740 : : }
741 : :
742 : : static int
743 : 0 : enetc4_promiscuous_disable(struct rte_eth_dev *dev)
744 : : {
745 : : struct enetc_eth_hw *hw =
746 : 0 : ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
747 : : struct enetc_hw *enetc_hw = &hw->hw;
748 : : uint32_t psipmr = 0;
749 : :
750 : : /* Setting to disable promiscuous mode for SI0*/
751 : 0 : psipmr = enetc4_port_rd(enetc_hw, ENETC4_PSIPMMR);
752 : 0 : psipmr &= (~PSIPMMR_SI_MAC_UP);
753 : :
754 [ # # ]: 0 : if (dev->data->all_multicast == 0)
755 : 0 : psipmr &= (~PSIPMMR_SI_MAC_MP);
756 : :
757 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PSIPMMR, psipmr);
758 : :
759 : 0 : return 0;
760 : : }
761 : :
762 : : int
763 : 0 : enetc4_dev_configure(struct rte_eth_dev *dev)
764 : : {
765 : : struct enetc_eth_hw *hw =
766 : 0 : ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
767 : : struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
768 : 0 : uint64_t rx_offloads = eth_conf->rxmode.offloads;
769 : 0 : uint64_t tx_offloads = eth_conf->txmode.offloads;
770 : : uint32_t checksum = L3_CKSUM | L4_CKSUM;
771 : 0 : struct enetc_hw *enetc_hw = &hw->hw;
772 : : uint32_t max_len;
773 : : uint32_t val, num_rss;
774 : : uint32_t ret = 0, i;
775 : : uint32_t *rss_table;
776 : :
777 : 0 : PMD_INIT_FUNC_TRACE();
778 : :
779 : : /* Port-level register writes are PF-only; skip for VF devices */
780 [ # # ]: 0 : if (hw->device_id != ENETC4_DEV_ID_VF) {
781 : 0 : max_len = dev->data->dev_conf.rxmode.mtu + RTE_ETHER_HDR_LEN +
782 : : RTE_ETHER_CRC_LEN;
783 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PM_MAXFRM(0),
784 : : ENETC_SET_MAXFRM(max_len));
785 : :
786 : : val = ENETC4_MAC_MAXFRM_SIZE | SDU_TYPE_MPDU;
787 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PTCTMSDUR(0),
788 : : val | SDU_TYPE_MPDU);
789 : : }
790 : :
791 : : /* Rx offloads which are enabled by default */
792 [ # # ]: 0 : if (dev_rx_offloads_sup & ~rx_offloads) {
793 : 0 : ENETC_PMD_INFO("Some of rx offloads enabled by default"
794 : : " - requested 0x%" PRIx64 " fixed are 0x%" PRIx64,
795 : : rx_offloads, dev_rx_offloads_sup);
796 : : }
797 : :
798 : : /* Tx offloads which are enabled by default */
799 [ # # ]: 0 : if (dev_tx_offloads_sup & ~tx_offloads) {
800 : 0 : ENETC_PMD_INFO("Some of tx offloads enabled by default"
801 : : " - requested 0x%" PRIx64 " fixed are 0x%" PRIx64,
802 : : tx_offloads, dev_tx_offloads_sup);
803 : : }
804 : :
805 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM)
806 : : checksum &= ~L3_CKSUM;
807 : :
808 [ # # ]: 0 : if (rx_offloads & (RTE_ETH_RX_OFFLOAD_UDP_CKSUM | RTE_ETH_RX_OFFLOAD_TCP_CKSUM))
809 : 0 : checksum &= ~L4_CKSUM;
810 : :
811 [ # # ]: 0 : if (hw->device_id != ENETC4_DEV_ID_VF)
812 : 0 : enetc4_port_wr(enetc_hw, ENETC4_PARCSCR, checksum);
813 : :
814 : : /* Enable interrupts */
815 [ # # ]: 0 : if (hw->device_id == ENETC4_DEV_ID_VF) {
816 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0) {
817 : 0 : ret = enetc4_vf_dev_intr(dev, true);
818 [ # # ]: 0 : if (ret)
819 : 0 : ENETC_PMD_WARN("Failed to setup link interrupts");
820 : : }
821 : : }
822 : :
823 : : /* Disable and reset RX and TX rings */
824 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
825 : 0 : enetc4_rxbdr_wr(enetc_hw, i, ENETC_RBMR, ENETC_BMR_RESET);
826 : :
827 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
828 : 0 : enetc4_rxbdr_wr(enetc_hw, i, ENETC_TBMR, ENETC_BMR_RESET);
829 : :
830 [ # # ]: 0 : if (dev->data->nb_rx_queues <= 1)
831 : : return 0;
832 : :
833 : : /* Setup RSS */
834 : : /* Setup control BDR */
835 : 0 : ret = enetc4_setup_cbdr(dev, enetc_hw, ENETC_CBDR_SIZE, &hw->cbdr);
836 [ # # ]: 0 : if (ret) {
837 : : /* Disable RSS */
838 : : enetc4_rss_configure(enetc_hw, false);
839 : 0 : return ret;
840 : : }
841 : :
842 : : /* Reset CIR again after enable CBDR*/
843 : 0 : rte_delay_us(ENETC_CBDR_DELAY);
844 : 0 : ENETC_PMD_DEBUG("CIR %x after CBDR enable", rte_read32(hw->cbdr.regs.cir));
845 : 0 : rte_write32(0, hw->cbdr.regs.cir);
846 : 0 : ENETC_PMD_DEBUG("CIR %x after reset", rte_read32(hw->cbdr.regs.cir));
847 : :
848 : 0 : val = enetc_rd(enetc_hw, ENETC_SIPCAPR0);
849 [ # # ]: 0 : if (val & ENETC_SIPCAPR0_RSS) {
850 : 0 : num_rss = enetc_rd(enetc_hw, ENETC_SIRSSCAPR);
851 : 0 : hw->num_rss = ENETC_SIRSSCAPR_GET_NUM_RSS(num_rss);
852 : 0 : ENETC_PMD_DEBUG("num_rss = %d", hw->num_rss);
853 : :
854 : : /* Add number of BDR groups */
855 : 0 : enetc4_wr(enetc_hw, ENETC_SIRBGCR, dev->data->nb_rx_queues);
856 : :
857 : :
858 : : /* Configuring indirecton table with default values
859 : : * Hash algorithm and RSS secret key to be filled by PF
860 : : */
861 : 0 : rss_table = rte_malloc(NULL, hw->num_rss * sizeof(*rss_table), ENETC_CBDR_ALIGN);
862 [ # # ]: 0 : if (!rss_table) {
863 : : enetc4_rss_configure(enetc_hw, false);
864 : 0 : enetc_free_cbdr(&hw->cbdr);
865 : 0 : return -ENOMEM;
866 : : }
867 : :
868 : 0 : ENETC_PMD_DEBUG("Enabling RSS for port %s with queues = %d", dev->device->name,
869 : : dev->data->nb_rx_queues);
870 [ # # ]: 0 : for (i = 0; i < hw->num_rss; i++)
871 : 0 : rss_table[i] = i % dev->data->nb_rx_queues;
872 : :
873 : 0 : ret = enetc_ntmp_rsst_query_or_update_entry(&hw->cbdr,
874 : : rss_table, hw->num_rss, false);
875 [ # # ]: 0 : if (ret) {
876 : 0 : ENETC_PMD_WARN("RSS indirection table update fails,"
877 : : "Scaling behaviour is undefined");
878 : : enetc4_rss_configure(enetc_hw, false);
879 : 0 : enetc_free_cbdr(&hw->cbdr);
880 : : }
881 : 0 : rte_free(rss_table);
882 : :
883 : : /* Enable RSS */
884 : : enetc4_rss_configure(enetc_hw, true);
885 : : }
886 : :
887 : : return 0;
888 : : }
889 : :
890 : : int
891 : 0 : enetc4_rx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
892 : : {
893 : 0 : struct enetc_eth_adapter *priv =
894 : 0 : ENETC_DEV_PRIVATE(dev->data->dev_private);
895 : : struct enetc_bdr *rx_ring;
896 : : uint32_t rx_data;
897 : :
898 : 0 : PMD_INIT_FUNC_TRACE();
899 : 0 : rx_ring = dev->data->rx_queues[qidx];
900 [ # # ]: 0 : if (dev->data->rx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED) {
901 : 0 : rx_data = enetc4_rxbdr_rd(&priv->hw.hw, rx_ring->index,
902 : : ENETC_RBMR);
903 : 0 : rx_data = rx_data | ENETC_RBMR_EN;
904 : 0 : enetc4_rxbdr_wr(&priv->hw.hw, rx_ring->index, ENETC_RBMR,
905 : : rx_data);
906 : 0 : dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
907 : : }
908 : :
909 : 0 : return 0;
910 : : }
911 : :
912 : : int
913 : 0 : enetc4_rx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
914 : : {
915 : 0 : struct enetc_eth_adapter *priv =
916 : 0 : ENETC_DEV_PRIVATE(dev->data->dev_private);
917 : : struct enetc_bdr *rx_ring;
918 : : uint32_t rx_data;
919 : :
920 : 0 : PMD_INIT_FUNC_TRACE();
921 : 0 : rx_ring = dev->data->rx_queues[qidx];
922 [ # # ]: 0 : if (dev->data->rx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED) {
923 : 0 : rx_data = enetc4_rxbdr_rd(&priv->hw.hw, rx_ring->index,
924 : : ENETC_RBMR);
925 : 0 : rx_data = rx_data & (~ENETC_RBMR_EN);
926 : 0 : enetc4_rxbdr_wr(&priv->hw.hw, rx_ring->index, ENETC_RBMR,
927 : : rx_data);
928 : 0 : dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
929 : : }
930 : :
931 : 0 : return 0;
932 : : }
933 : :
934 : : int
935 : 0 : enetc4_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
936 : : {
937 : 0 : struct enetc_eth_adapter *priv =
938 : 0 : ENETC_DEV_PRIVATE(dev->data->dev_private);
939 : : struct enetc_bdr *tx_ring;
940 : : uint32_t tx_data;
941 : :
942 : 0 : PMD_INIT_FUNC_TRACE();
943 : 0 : tx_ring = dev->data->tx_queues[qidx];
944 [ # # ]: 0 : if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED) {
945 : 0 : tx_data = enetc4_txbdr_rd(&priv->hw.hw, tx_ring->index,
946 : : ENETC_TBMR);
947 : 0 : tx_data = tx_data | ENETC_TBMR_EN;
948 : 0 : enetc4_txbdr_wr(&priv->hw.hw, tx_ring->index, ENETC_TBMR,
949 : : tx_data);
950 : 0 : dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
951 : : }
952 : :
953 : 0 : return 0;
954 : : }
955 : :
956 : : int
957 : 0 : enetc4_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
958 : : {
959 : 0 : struct enetc_eth_adapter *priv =
960 : 0 : ENETC_DEV_PRIVATE(dev->data->dev_private);
961 : : struct enetc_bdr *tx_ring;
962 : : uint32_t tx_data;
963 : :
964 : 0 : PMD_INIT_FUNC_TRACE();
965 : 0 : tx_ring = dev->data->tx_queues[qidx];
966 [ # # ]: 0 : if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED) {
967 : 0 : tx_data = enetc4_txbdr_rd(&priv->hw.hw, tx_ring->index,
968 : : ENETC_TBMR);
969 : 0 : tx_data = tx_data & (~ENETC_TBMR_EN);
970 : 0 : enetc4_txbdr_wr(&priv->hw.hw, tx_ring->index, ENETC_TBMR,
971 : : tx_data);
972 : 0 : dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
973 : : }
974 : :
975 : 0 : return 0;
976 : : }
977 : :
978 : : static void
979 : 0 : enetc4_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
980 : : struct rte_eth_rxq_info *qinfo)
981 : : {
982 : 0 : struct enetc_bdr *rxq = dev->data->rx_queues[queue_id];
983 : :
984 : 0 : qinfo->mp = rxq->mb_pool;
985 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
986 : 0 : qinfo->nb_desc = rxq->bd_count;
987 : 0 : qinfo->conf.rx_free_thresh = 0;
988 : 0 : qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
989 : 0 : qinfo->conf.rx_drop_en = 0;
990 : 0 : }
991 : :
992 : : static void
993 : 0 : enetc4_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
994 : : struct rte_eth_txq_info *qinfo)
995 : : {
996 : 0 : struct enetc_bdr *txq = dev->data->tx_queues[queue_id];
997 : :
998 : 0 : qinfo->nb_desc = txq->bd_count;
999 : 0 : qinfo->conf.tx_thresh.pthresh = 0;
1000 : 0 : qinfo->conf.tx_thresh.hthresh = 0;
1001 : 0 : qinfo->conf.tx_thresh.wthresh = 0;
1002 : 0 : qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
1003 : 0 : qinfo->conf.tx_free_thresh = 0;
1004 : 0 : qinfo->conf.tx_rs_thresh = 0;
1005 : 0 : }
1006 : :
1007 : : const uint32_t *
1008 : 0 : enetc4_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused,
1009 : : size_t *no_of_elements)
1010 : : {
1011 : 0 : PMD_INIT_FUNC_TRACE();
1012 : : static const uint32_t ptypes[] = {
1013 : : RTE_PTYPE_L2_ETHER,
1014 : : RTE_PTYPE_L3_IPV4,
1015 : : RTE_PTYPE_L3_IPV6,
1016 : : RTE_PTYPE_L4_TCP,
1017 : : RTE_PTYPE_L4_UDP,
1018 : : RTE_PTYPE_L4_SCTP,
1019 : : RTE_PTYPE_L4_ICMP,
1020 : : RTE_PTYPE_L4_FRAG,
1021 : : RTE_PTYPE_TUNNEL_ESP,
1022 : : RTE_PTYPE_UNKNOWN
1023 : : };
1024 : :
1025 : 0 : *no_of_elements = RTE_DIM(ptypes);
1026 : 0 : return ptypes;
1027 : : }
1028 : :
1029 : : /*
1030 : : * The set of PCI devices this driver supports
1031 : : */
1032 : : static const struct rte_pci_id pci_id_enetc4_map[] = {
1033 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_NXP, ENETC4_DEV_ID) },
1034 : : { .vendor_id = 0, /* sentinel */ },
1035 : : };
1036 : :
1037 : : /* Features supported by this driver */
1038 : : static const struct eth_dev_ops enetc4_ops = {
1039 : : .dev_configure = enetc4_dev_configure,
1040 : : .dev_start = enetc4_dev_start,
1041 : : .dev_stop = enetc4_dev_stop,
1042 : : .dev_close = enetc4_dev_close,
1043 : : .dev_infos_get = enetc4_dev_infos_get,
1044 : : .link_update = enetc4_link_update,
1045 : : .stats_get = enetc4_stats_get,
1046 : : .stats_reset = enetc4_stats_reset,
1047 : : .promiscuous_enable = enetc4_promiscuous_enable,
1048 : : .promiscuous_disable = enetc4_promiscuous_disable,
1049 : : .rx_queue_setup = enetc4_rx_queue_setup,
1050 : : .rx_queue_start = enetc4_rx_queue_start,
1051 : : .rx_queue_stop = enetc4_rx_queue_stop,
1052 : : .rx_queue_release = enetc4_rx_queue_release,
1053 : : .rxq_info_get = enetc4_rxq_info_get,
1054 : : .tx_queue_setup = enetc4_tx_queue_setup,
1055 : : .tx_queue_start = enetc4_tx_queue_start,
1056 : : .tx_queue_stop = enetc4_tx_queue_stop,
1057 : : .tx_queue_release = enetc4_tx_queue_release,
1058 : : .txq_info_get = enetc4_txq_info_get,
1059 : : .dev_supported_ptypes_get = enetc4_supported_ptypes_get,
1060 : : };
1061 : :
1062 : : /*
1063 : : * Storing the HW base addresses
1064 : : *
1065 : : * @param eth_dev
1066 : : * - Pointer to the structure rte_eth_dev
1067 : : */
1068 : : void
1069 : 0 : enetc4_dev_hw_init(struct rte_eth_dev *eth_dev)
1070 : : {
1071 : : struct enetc_eth_hw *hw =
1072 : 0 : ENETC_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1073 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(eth_dev, *pci_dev);
1074 : :
1075 : 0 : eth_dev->rx_pkt_burst = &enetc_recv_pkts_cacheable;
1076 : 0 : eth_dev->tx_pkt_burst = &enetc_xmit_pkts_cacheable;
1077 : :
1078 : : /* Retrieving and storing the HW base address of device */
1079 : 0 : hw->hw.reg = (void *)pci_dev->mem_resource[0].addr;
1080 : 0 : hw->device_id = pci_dev->id.device_id;
1081 : :
1082 : : /* Calculating and storing the base HW addresses */
1083 : 0 : hw->hw.port = (void *)((size_t)hw->hw.reg + ENETC_PORT_BASE);
1084 : 0 : hw->hw.global = (void *)((size_t)hw->hw.reg + ENETC_GLOBAL_BASE);
1085 : 0 : }
1086 : :
1087 : : /**
1088 : : * Initialisation of the enetc4 device
1089 : : *
1090 : : * @param eth_dev
1091 : : * - Pointer to the structure rte_eth_dev
1092 : : *
1093 : : * @return
1094 : : * - On success, zero.
1095 : : * - On failure, negative value.
1096 : : */
1097 : :
1098 : : static int
1099 : 0 : enetc4_dev_init(struct rte_eth_dev *eth_dev)
1100 : : {
1101 : 0 : struct enetc_eth_hw *hw =
1102 : 0 : ENETC_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1103 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(eth_dev, *pci_dev);
1104 : : int error = 0;
1105 : : uint32_t si_cap;
1106 : : struct enetc_hw *enetc_hw = &hw->hw;
1107 : :
1108 : 0 : PMD_INIT_FUNC_TRACE();
1109 : 0 : eth_dev->dev_ops = &enetc4_ops;
1110 : 0 : enetc4_dev_hw_init(eth_dev);
1111 : :
1112 : 0 : si_cap = enetc_rd(enetc_hw, ENETC_SICAPR0);
1113 : 0 : hw->max_tx_queues = si_cap & ENETC_SICAPR0_BDR_MASK;
1114 : 0 : hw->max_rx_queues = (si_cap >> 16) & ENETC_SICAPR0_BDR_MASK;
1115 : :
1116 : 0 : hw->nc_mode = 0;
1117 : 0 : enetc4_get_devargs(eth_dev, ENETC4_TXQ_PRIORITIES);
1118 : 0 : enetc4_get_devargs(eth_dev, ENETC4_NC_MEMORY);
1119 [ # # ]: 0 : if (hw->nc_mode) {
1120 : 0 : eth_dev->rx_pkt_burst = &enetc_recv_pkts_nc;
1121 : 0 : eth_dev->tx_pkt_burst = &enetc_xmit_pkts_nc;
1122 : 0 : ENETC_PMD_LOG(INFO, "nc=1: using non-cacheable BD ops (_nc)");
1123 : : }
1124 : :
1125 : 0 : ENETC_PMD_DEBUG("Max RX queues = %d Max TX queues = %d",
1126 : : hw->max_rx_queues, hw->max_tx_queues);
1127 : 0 : error = enetc4_mac_init(hw, eth_dev);
1128 [ # # ]: 0 : if (error != 0) {
1129 : 0 : ENETC_PMD_ERR("MAC initialization failed");
1130 : 0 : return -1;
1131 : : }
1132 : :
1133 : : /* Set MTU */
1134 : 0 : enetc_port_wr(&hw->hw, ENETC4_PM_MAXFRM(0),
1135 : : ENETC_SET_MAXFRM(RTE_ETHER_MAX_LEN));
1136 : 0 : eth_dev->data->mtu = RTE_ETHER_MAX_LEN - RTE_ETHER_HDR_LEN -
1137 : : RTE_ETHER_CRC_LEN;
1138 : :
1139 [ # # ]: 0 : if (rte_eal_iova_mode() == RTE_IOVA_PA)
1140 : 0 : dpaax_iova_table_populate();
1141 : :
1142 : 0 : ENETC_PMD_DEBUG("port_id %d vendorID=0x%x deviceID=0x%x",
1143 : : eth_dev->data->port_id, pci_dev->id.vendor_id,
1144 : : pci_dev->id.device_id);
1145 : 0 : return 0;
1146 : : }
1147 : :
1148 : : static int
1149 : 0 : enetc4_dev_uninit(struct rte_eth_dev *eth_dev)
1150 : : {
1151 : : struct enetc_eth_hw *hw =
1152 : 0 : ENETC_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1153 : :
1154 : 0 : PMD_INIT_FUNC_TRACE();
1155 : :
1156 [ # # ]: 0 : if (hw->txq_prior) {
1157 : 0 : free(hw->txq_prior);
1158 : 0 : hw->txq_prior = NULL;
1159 : : }
1160 : :
1161 : 0 : return enetc4_dev_close(eth_dev);
1162 : : }
1163 : :
1164 : : static int
1165 : 0 : enetc4_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1166 : : struct rte_pci_device *pci_dev)
1167 : : {
1168 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
1169 : : sizeof(struct enetc_eth_adapter),
1170 : : enetc4_dev_init);
1171 : : }
1172 : :
1173 : : int
1174 : 0 : enetc4_pci_remove(struct rte_pci_device *pci_dev)
1175 : : {
1176 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, enetc4_dev_uninit);
1177 : : }
1178 : :
1179 : : static struct rte_pci_driver rte_enetc4_pmd = {
1180 : : .id_table = pci_id_enetc4_map,
1181 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1182 : : .probe = enetc4_pci_probe,
1183 : : .remove = enetc4_pci_remove,
1184 : : };
1185 : :
1186 : 303 : RTE_PMD_REGISTER_PCI(net_enetc4, rte_enetc4_pmd);
1187 : : RTE_PMD_REGISTER_PCI_TABLE(net_enetc4, pci_id_enetc4_map);
1188 : : RTE_PMD_REGISTER_KMOD_DEP(net_enetc4, "* vfio-pci");
1189 : : RTE_PMD_REGISTER_PARAM_STRING(net_enetc4,
1190 : : ENETC4_TXQ_PRIORITIES "=<string> "
1191 : : ENETC4_NC_MEMORY "=<int>");
1192 [ - + ]: 303 : RTE_LOG_REGISTER_DEFAULT(enetc4_logtype_pmd, NOTICE);
|