Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2024 Marvell.
3 : : */
4 : :
5 : : #include <cnxk_rep.h>
6 : : #include <cnxk_rep_msg.h>
7 : :
8 : : #define MEMPOOL_CACHE_SIZE 256
9 : : #define TX_DESC_PER_QUEUE 512
10 : : #define RX_DESC_PER_QUEUE 256
11 : : #define NB_REP_VDEV_MBUF 1024
12 : :
13 : : static const struct rte_eth_xstat_name cnxk_rep_xstats_string[] = {
14 : : {"rep_nb_rx"},
15 : : {"rep_nb_tx"},
16 : : };
17 : :
18 : : static uint16_t
19 : 0 : cnxk_rep_tx_burst(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
20 : : {
21 : : struct cnxk_rep_txq *txq = tx_queue;
22 : : struct cnxk_rep_dev *rep_dev;
23 : : uint16_t n_tx;
24 : :
25 [ # # ]: 0 : if (unlikely(!txq))
26 : : return 0;
27 : :
28 : 0 : rep_dev = txq->rep_dev;
29 : 0 : plt_rep_dbg("Transmitting %d packets on eswitch queue %d", nb_pkts, txq->qid);
30 : 0 : n_tx = cnxk_eswitch_dev_tx_burst(rep_dev->parent_dev, txq->qid, tx_pkts, nb_pkts,
31 : : NIX_TX_OFFLOAD_VLAN_QINQ_F);
32 : 0 : txq->stats.pkts += n_tx;
33 : 0 : return n_tx;
34 : : }
35 : :
36 : : static uint16_t
37 : 0 : cnxk_rep_rx_burst(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
38 : : {
39 : : struct cnxk_rep_rxq *rxq = rx_queue;
40 : : struct cnxk_rep_dev *rep_dev;
41 : : uint16_t n_rx;
42 : :
43 [ # # ]: 0 : if (unlikely(!rxq))
44 : : return 0;
45 : :
46 : 0 : rep_dev = rxq->rep_dev;
47 : 0 : n_rx = cnxk_eswitch_dev_rx_burst(rep_dev->parent_dev, rxq->qid, rx_pkts, nb_pkts);
48 [ # # ]: 0 : if (n_rx == 0)
49 : : return 0;
50 : :
51 : 0 : plt_rep_dbg("Received %d packets on eswitch queue %d", n_rx, rxq->qid);
52 : 0 : rxq->stats.pkts += n_rx;
53 : 0 : return n_rx;
54 : : }
55 : :
56 : : uint16_t
57 : 0 : cnxk_rep_tx_burst_dummy(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
58 : : {
59 : : PLT_SET_USED(tx_queue);
60 : : PLT_SET_USED(tx_pkts);
61 : : PLT_SET_USED(nb_pkts);
62 : :
63 : 0 : return 0;
64 : : }
65 : :
66 : : uint16_t
67 : 0 : cnxk_rep_rx_burst_dummy(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
68 : : {
69 : : PLT_SET_USED(rx_queue);
70 : : PLT_SET_USED(rx_pkts);
71 : : PLT_SET_USED(nb_pkts);
72 : :
73 : 0 : return 0;
74 : : }
75 : :
76 : : int
77 [ # # ]: 0 : cnxk_rep_link_update(struct rte_eth_dev *ethdev, int wait_to_complete)
78 : : {
79 : : struct rte_eth_link link;
80 : : PLT_SET_USED(wait_to_complete);
81 : :
82 : : memset(&link, 0, sizeof(link));
83 [ # # ]: 0 : if (ethdev->data->dev_started) {
84 : 0 : link.link_status = RTE_ETH_LINK_UP;
85 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
86 : : link.link_autoneg = RTE_ETH_LINK_FIXED;
87 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
88 : : }
89 : :
90 : 0 : return rte_eth_linkstatus_set(ethdev, &link);
91 : : }
92 : :
93 : : int
94 : 0 : cnxk_rep_dev_info_get(struct rte_eth_dev *ethdev, struct rte_eth_dev_info *dev_info)
95 : : {
96 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(ethdev);
97 : : uint32_t max_rx_pktlen;
98 : :
99 : 0 : max_rx_pktlen = (roc_nix_max_pkt_len(&rep_dev->parent_dev->nix) + RTE_ETHER_CRC_LEN -
100 : : CNXK_NIX_MAX_VTAG_ACT_SIZE);
101 : :
102 : 0 : dev_info->min_rx_bufsize = NIX_MIN_HW_FRS + RTE_ETHER_CRC_LEN;
103 : 0 : dev_info->max_rx_pktlen = max_rx_pktlen;
104 : 0 : dev_info->max_mac_addrs = roc_nix_mac_max_entries_get(&rep_dev->parent_dev->nix);
105 : :
106 : 0 : dev_info->rx_offload_capa = CNXK_REP_RX_OFFLOAD_CAPA;
107 : 0 : dev_info->tx_offload_capa = CNXK_REP_TX_OFFLOAD_CAPA;
108 : 0 : dev_info->rx_queue_offload_capa = 0;
109 : 0 : dev_info->tx_queue_offload_capa = 0;
110 : :
111 : : /* For the sake of symmetry, max_rx_queues = max_tx_queues */
112 : 0 : dev_info->max_rx_queues = 1;
113 : 0 : dev_info->max_tx_queues = 1;
114 : :
115 : : /* MTU specifics */
116 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN);
117 : 0 : dev_info->min_mtu = dev_info->min_rx_bufsize - CNXK_NIX_L2_OVERHEAD;
118 : :
119 : : /* Switch info specific */
120 : 0 : dev_info->switch_info.name = ethdev->device->name;
121 : 0 : dev_info->switch_info.domain_id = rep_dev->switch_domain_id;
122 : 0 : dev_info->switch_info.port_id = rep_dev->port_id;
123 : :
124 : 0 : return 0;
125 : : }
126 : :
127 : : int
128 : 0 : cnxk_rep_representor_info_get(struct rte_eth_dev *ethdev, struct rte_eth_representor_info *info)
129 : : {
130 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(ethdev);
131 : :
132 : 0 : return cnxk_eswitch_representor_info_get(rep_dev->parent_dev, info);
133 : : }
134 : :
135 : : static int
136 : 0 : rep_eth_conf_chk(const struct rte_eth_conf *conf, uint16_t nb_rx_queues)
137 : : {
138 : : const struct rte_eth_rss_conf *rss_conf;
139 : : int ret = 0;
140 : :
141 [ # # ]: 0 : if (conf->link_speeds != 0) {
142 : 0 : plt_err("specific link speeds not supported");
143 : : ret = -EINVAL;
144 : : }
145 : :
146 [ # # # ]: 0 : switch (conf->rxmode.mq_mode) {
147 : 0 : case RTE_ETH_MQ_RX_RSS:
148 [ # # ]: 0 : if (nb_rx_queues != 1) {
149 : 0 : plt_err("Rx RSS is not supported with %u queues", nb_rx_queues);
150 : : ret = -EINVAL;
151 : 0 : break;
152 : : }
153 : :
154 : : rss_conf = &conf->rx_adv_conf.rss_conf;
155 [ # # # # ]: 0 : if (rss_conf->rss_key != NULL || rss_conf->rss_key_len != 0 ||
156 [ # # ]: 0 : rss_conf->rss_hf != 0) {
157 : 0 : plt_err("Rx RSS configuration is not supported");
158 : : ret = -EINVAL;
159 : : }
160 : : break;
161 : : case RTE_ETH_MQ_RX_NONE:
162 : : break;
163 : 0 : default:
164 : 0 : plt_err("Rx mode MQ modes other than RSS not supported");
165 : : ret = -EINVAL;
166 : 0 : break;
167 : : }
168 : :
169 [ # # ]: 0 : if (conf->txmode.mq_mode != RTE_ETH_MQ_TX_NONE) {
170 : 0 : plt_err("Tx mode MQ modes not supported");
171 : : ret = -EINVAL;
172 : : }
173 : :
174 [ # # ]: 0 : if (conf->lpbk_mode != 0) {
175 : 0 : plt_err("loopback not supported");
176 : : ret = -EINVAL;
177 : : }
178 : :
179 [ # # ]: 0 : if (conf->dcb_capability_en != 0) {
180 : 0 : plt_err("priority-based flow control not supported");
181 : : ret = -EINVAL;
182 : : }
183 : :
184 [ # # ]: 0 : if (conf->intr_conf.lsc != 0) {
185 : 0 : plt_err("link status change interrupt not supported");
186 : : ret = -EINVAL;
187 : : }
188 : :
189 [ # # ]: 0 : if (conf->intr_conf.rxq != 0) {
190 : 0 : plt_err("receive queue interrupt not supported");
191 : : ret = -EINVAL;
192 : : }
193 : :
194 [ # # ]: 0 : if (conf->intr_conf.rmv != 0) {
195 : 0 : plt_err("remove interrupt not supported");
196 : : ret = -EINVAL;
197 : : }
198 : :
199 : 0 : return ret;
200 : : }
201 : :
202 : : int
203 : 0 : cnxk_rep_dev_configure(struct rte_eth_dev *ethdev)
204 : : {
205 : 0 : struct rte_eth_dev_data *ethdev_data = ethdev->data;
206 : : int rc = -1;
207 : :
208 : 0 : rc = rep_eth_conf_chk(ðdev_data->dev_conf, ethdev_data->nb_rx_queues);
209 [ # # ]: 0 : if (rc)
210 : 0 : goto fail;
211 : :
212 : : return 0;
213 : : fail:
214 : 0 : return rc;
215 : : }
216 : :
217 : : int
218 : 0 : cnxk_rep_promiscuous_enable(struct rte_eth_dev *ethdev)
219 : : {
220 : : PLT_SET_USED(ethdev);
221 : 0 : return 0;
222 : : }
223 : :
224 : : int
225 : 0 : cnxk_rep_promiscuous_disable(struct rte_eth_dev *ethdev)
226 : : {
227 : : PLT_SET_USED(ethdev);
228 : 0 : return 0;
229 : : }
230 : :
231 : : int
232 [ # # ]: 0 : cnxk_rep_dev_start(struct rte_eth_dev *ethdev)
233 : : {
234 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(ethdev);
235 : : struct rte_eth_link link;
236 : : int rc = 0, qid;
237 : :
238 : 0 : ethdev->rx_pkt_burst = cnxk_rep_rx_burst;
239 : 0 : ethdev->tx_pkt_burst = cnxk_rep_tx_burst;
240 : :
241 [ # # ]: 0 : if (!rep_dev->is_vf_active)
242 : : return 0;
243 : :
244 [ # # # # ]: 0 : if (!rep_dev->rxq || !rep_dev->txq) {
245 : 0 : plt_err("Invalid rxq or txq for representor id %d", rep_dev->rep_id);
246 : : rc = -EINVAL;
247 : 0 : goto fail;
248 : : }
249 : :
250 : : /* Start rx queues */
251 : 0 : qid = rep_dev->rxq->qid;
252 : 0 : rc = cnxk_eswitch_rxq_start(rep_dev->parent_dev, qid);
253 [ # # ]: 0 : if (rc) {
254 : 0 : plt_err("Failed to start rxq %d, rc=%d", qid, rc);
255 : 0 : goto fail;
256 : : }
257 : :
258 : : /* Start tx queues */
259 : 0 : qid = rep_dev->txq->qid;
260 : 0 : rc = cnxk_eswitch_txq_start(rep_dev->parent_dev, qid);
261 [ # # ]: 0 : if (rc) {
262 : 0 : plt_err("Failed to start txq %d, rc=%d", qid, rc);
263 : 0 : goto fail;
264 : : }
265 : :
266 : : /* Start rep_xport device only once after first representor gets active */
267 [ # # ]: 0 : if (!rep_dev->parent_dev->repr_cnt.nb_repr_started) {
268 : 0 : rc = cnxk_eswitch_nix_rsrc_start(rep_dev->parent_dev);
269 [ # # ]: 0 : if (rc) {
270 : 0 : plt_err("Failed to start nix dev, rc %d", rc);
271 : 0 : goto fail;
272 : : }
273 : : }
274 : :
275 : 0 : ethdev->data->tx_queue_state[0] = RTE_ETH_QUEUE_STATE_STARTED;
276 : 0 : ethdev->data->rx_queue_state[0] = RTE_ETH_QUEUE_STATE_STARTED;
277 : :
278 : 0 : rep_dev->parent_dev->repr_cnt.nb_repr_started++;
279 : :
280 : 0 : link.link_status = RTE_ETH_LINK_UP;
281 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
282 : 0 : link.link_autoneg = RTE_ETH_LINK_FIXED;
283 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
284 : 0 : rte_eth_linkstatus_set(ethdev, &link);
285 : 0 : ethdev->data->dev_started = 1;
286 : :
287 : 0 : return 0;
288 : : fail:
289 : : return rc;
290 : : }
291 : :
292 : : int
293 : 0 : cnxk_rep_dev_close(struct rte_eth_dev *ethdev)
294 : : {
295 : 0 : return cnxk_rep_dev_uninit(ethdev);
296 : : }
297 : :
298 : : int
299 : 0 : cnxk_rep_dev_stop(struct rte_eth_dev *ethdev)
300 : : {
301 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(ethdev);
302 : : struct rte_eth_link link;
303 : :
304 : 0 : ethdev->rx_pkt_burst = cnxk_rep_rx_burst_dummy;
305 : 0 : ethdev->tx_pkt_burst = cnxk_rep_tx_burst_dummy;
306 : 0 : cnxk_rep_rx_queue_stop(ethdev, 0);
307 : 0 : cnxk_rep_tx_queue_stop(ethdev, 0);
308 : 0 : rep_dev->parent_dev->repr_cnt.nb_repr_started--;
309 : :
310 : : /* Bring down link status internally */
311 : : memset(&link, 0, sizeof(link));
312 : 0 : rte_eth_linkstatus_set(ethdev, &link);
313 : 0 : ethdev->data->dev_started = 0;
314 : :
315 : 0 : return 0;
316 : : }
317 : :
318 : : int
319 [ # # ]: 0 : cnxk_rep_rx_queue_setup(struct rte_eth_dev *ethdev, uint16_t rx_queue_id, uint16_t nb_rx_desc,
320 : : unsigned int socket_id, const struct rte_eth_rxconf *rx_conf,
321 : : struct rte_mempool *mb_pool)
322 : : {
323 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(ethdev);
324 : : struct cnxk_rep_rxq *rxq = NULL;
325 : : uint16_t qid = 0;
326 : : int rc;
327 : :
328 : : PLT_SET_USED(socket_id);
329 : : /* If no representee assigned, store the respective rxq parameters */
330 [ # # # # ]: 0 : if (!rep_dev->is_vf_active && !rep_dev->rxq) {
331 : 0 : rxq = plt_zmalloc(sizeof(*rxq), RTE_CACHE_LINE_SIZE);
332 [ # # ]: 0 : if (!rxq) {
333 : : rc = -ENOMEM;
334 : 0 : plt_err("Failed to alloc RxQ for rep id %d", rep_dev->rep_id);
335 : 0 : goto fail;
336 : : }
337 : :
338 : 0 : rxq->qid = qid;
339 : 0 : rxq->nb_desc = nb_rx_desc;
340 : 0 : rxq->rep_dev = rep_dev;
341 : 0 : rxq->mpool = mb_pool;
342 : 0 : rxq->rx_conf = rx_conf;
343 : 0 : rep_dev->rxq = rxq;
344 : 0 : ethdev->data->rx_queues[rx_queue_id] = NULL;
345 : :
346 : 0 : return 0;
347 : : }
348 : :
349 : 0 : qid = rep_dev->rep_id;
350 : 0 : rc = cnxk_eswitch_rxq_setup(rep_dev->parent_dev, qid, nb_rx_desc, rx_conf, mb_pool);
351 [ # # ]: 0 : if (rc) {
352 : 0 : plt_err("failed to setup eswitch queue id %d", qid);
353 : 0 : goto fail;
354 : : }
355 : :
356 : 0 : rxq = rep_dev->rxq;
357 [ # # ]: 0 : if (!rxq) {
358 : 0 : plt_err("Invalid RXQ handle for representor port %d rep id %d", rep_dev->port_id,
359 : : rep_dev->rep_id);
360 : 0 : goto free_queue;
361 : : }
362 : :
363 : 0 : rxq->qid = qid;
364 : 0 : ethdev->data->rx_queues[rx_queue_id] = rxq;
365 : 0 : ethdev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
366 : 0 : plt_rep_dbg("representor id %d portid %d rxq id %d", rep_dev->port_id,
367 : : ethdev->data->port_id, rxq->qid);
368 : :
369 : 0 : return 0;
370 : : free_queue:
371 : 0 : cnxk_eswitch_rxq_release(rep_dev->parent_dev, qid);
372 : : fail:
373 : : return rc;
374 : : }
375 : :
376 : : void
377 : 0 : cnxk_rep_rx_queue_stop(struct rte_eth_dev *ethdev, uint16_t queue_id)
378 : : {
379 [ # # ]: 0 : struct cnxk_rep_rxq *rxq = ethdev->data->rx_queues[queue_id];
380 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(ethdev);
381 : : int rc;
382 : :
383 [ # # ]: 0 : if (!rxq)
384 : : return;
385 : :
386 : 0 : plt_rep_dbg("Stopping rxq %u", rxq->qid);
387 : :
388 : 0 : rc = cnxk_eswitch_rxq_stop(rep_dev->parent_dev, rxq->qid);
389 [ # # ]: 0 : if (rc)
390 : 0 : plt_err("Failed to stop rxq %d, rc=%d", rc, rxq->qid);
391 : :
392 : 0 : ethdev->data->rx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
393 : : }
394 : :
395 : : void
396 : 0 : cnxk_rep_rx_queue_release(struct rte_eth_dev *ethdev, uint16_t queue_id)
397 : : {
398 [ # # ]: 0 : struct cnxk_rep_rxq *rxq = ethdev->data->rx_queues[queue_id];
399 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(ethdev);
400 : : int rc;
401 : :
402 [ # # ]: 0 : if (!rxq) {
403 : 0 : plt_err("Invalid rxq retrieved for rep_id %d", rep_dev->rep_id);
404 : 0 : return;
405 : : }
406 : :
407 : 0 : plt_rep_dbg("Releasing rxq %u", rxq->qid);
408 : :
409 : 0 : rc = cnxk_eswitch_rxq_release(rep_dev->parent_dev, rxq->qid);
410 [ # # ]: 0 : if (rc)
411 : 0 : plt_err("Failed to release rxq %d, rc=%d", rc, rxq->qid);
412 : : }
413 : :
414 : : int
415 [ # # ]: 0 : cnxk_rep_tx_queue_setup(struct rte_eth_dev *ethdev, uint16_t tx_queue_id, uint16_t nb_tx_desc,
416 : : unsigned int socket_id, const struct rte_eth_txconf *tx_conf)
417 : : {
418 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(ethdev);
419 : : struct cnxk_rep_txq *txq = NULL;
420 : : int rc = 0, qid = 0;
421 : :
422 : : PLT_SET_USED(socket_id);
423 : : /* If no representee assigned, store the respective rxq parameters */
424 [ # # # # ]: 0 : if (!rep_dev->is_vf_active && !rep_dev->txq) {
425 : 0 : txq = plt_zmalloc(sizeof(*txq), RTE_CACHE_LINE_SIZE);
426 [ # # ]: 0 : if (!txq) {
427 : : rc = -ENOMEM;
428 : 0 : plt_err("failed to alloc txq for rep id %d", rep_dev->rep_id);
429 : 0 : goto free_queue;
430 : : }
431 : :
432 : 0 : txq->qid = qid;
433 : 0 : txq->nb_desc = nb_tx_desc;
434 : 0 : txq->tx_conf = tx_conf;
435 : 0 : txq->rep_dev = rep_dev;
436 : 0 : rep_dev->txq = txq;
437 : :
438 : 0 : ethdev->data->tx_queues[tx_queue_id] = NULL;
439 : :
440 : 0 : return 0;
441 : : }
442 : :
443 : 0 : qid = rep_dev->rep_id;
444 : 0 : rc = cnxk_eswitch_txq_setup(rep_dev->parent_dev, qid, nb_tx_desc, tx_conf);
445 [ # # ]: 0 : if (rc) {
446 : 0 : plt_err("failed to setup eswitch queue id %d", qid);
447 : 0 : goto fail;
448 : : }
449 : :
450 : 0 : txq = rep_dev->txq;
451 [ # # ]: 0 : if (!txq) {
452 : 0 : plt_err("Invalid TXQ handle for representor port %d rep id %d", rep_dev->port_id,
453 : : rep_dev->rep_id);
454 : 0 : goto free_queue;
455 : : }
456 : :
457 : 0 : txq->qid = qid;
458 : 0 : ethdev->data->tx_queues[tx_queue_id] = txq;
459 : 0 : ethdev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
460 : 0 : plt_rep_dbg("representor id %d portid %d txq id %d", rep_dev->port_id,
461 : : ethdev->data->port_id, txq->qid);
462 : :
463 : 0 : return 0;
464 : 0 : free_queue:
465 : 0 : cnxk_eswitch_txq_release(rep_dev->parent_dev, qid);
466 : : fail:
467 : : return rc;
468 : : }
469 : :
470 : : void
471 : 0 : cnxk_rep_tx_queue_stop(struct rte_eth_dev *ethdev, uint16_t queue_id)
472 : : {
473 [ # # ]: 0 : struct cnxk_rep_txq *txq = ethdev->data->tx_queues[queue_id];
474 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(ethdev);
475 : : int rc;
476 : :
477 [ # # ]: 0 : if (!txq)
478 : : return;
479 : :
480 : 0 : plt_rep_dbg("Releasing txq %u", txq->qid);
481 : :
482 : 0 : rc = cnxk_eswitch_txq_stop(rep_dev->parent_dev, txq->qid);
483 [ # # ]: 0 : if (rc)
484 : 0 : plt_err("Failed to stop txq %d, rc=%d", rc, txq->qid);
485 : :
486 : 0 : ethdev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
487 : : }
488 : :
489 : : void
490 : 0 : cnxk_rep_tx_queue_release(struct rte_eth_dev *ethdev, uint16_t queue_id)
491 : : {
492 [ # # ]: 0 : struct cnxk_rep_txq *txq = ethdev->data->tx_queues[queue_id];
493 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(ethdev);
494 : : int rc;
495 : :
496 [ # # ]: 0 : if (!txq) {
497 : 0 : plt_err("Invalid txq retrieved for rep_id %d", rep_dev->rep_id);
498 : 0 : return;
499 : : }
500 : :
501 : 0 : plt_rep_dbg("Releasing txq %u", txq->qid);
502 : :
503 : 0 : rc = cnxk_eswitch_txq_release(rep_dev->parent_dev, txq->qid);
504 [ # # ]: 0 : if (rc)
505 : 0 : plt_err("Failed to release txq %d, rc=%d", rc, txq->qid);
506 : : }
507 : :
508 : : static int
509 : 0 : process_eth_stats(struct cnxk_rep_dev *rep_dev, cnxk_rep_msg_ack_data_t *adata, cnxk_rep_msg_t msg)
510 : : {
511 : : cnxk_rep_msg_eth_stats_meta_t msg_st_meta;
512 : 0 : uint32_t len = 0, rc;
513 : : void *buffer;
514 : : size_t size;
515 : :
516 : : size = CNXK_REP_MSG_MAX_BUFFER_SZ;
517 : 0 : buffer = plt_zmalloc(size, 0);
518 [ # # ]: 0 : if (!buffer) {
519 : 0 : plt_err("Failed to allocate mem");
520 : : rc = -ENOMEM;
521 : 0 : goto fail;
522 : : }
523 : :
524 : 0 : cnxk_rep_msg_populate_header(buffer, &len);
525 : :
526 : 0 : msg_st_meta.portid = rep_dev->rep_id;
527 : 0 : cnxk_rep_msg_populate_command_meta(buffer, &len, &msg_st_meta,
528 : : sizeof(cnxk_rep_msg_eth_stats_meta_t), msg);
529 : 0 : cnxk_rep_msg_populate_msg_end(buffer, &len);
530 : :
531 : 0 : rc = cnxk_rep_msg_send_process(rep_dev, buffer, len, adata);
532 [ # # ]: 0 : if (rc) {
533 : 0 : plt_err("Failed to process the message, err %d", rc);
534 : 0 : goto fail;
535 : : }
536 : :
537 : 0 : rte_free(buffer);
538 : :
539 : 0 : return 0;
540 : 0 : fail:
541 : 0 : rte_free(buffer);
542 : 0 : return rc;
543 : : }
544 : :
545 : : static int
546 : 0 : native_repte_eth_stats(struct cnxk_rep_dev *rep_dev, struct rte_eth_stats *stats)
547 : : {
548 : : struct roc_nix_stats nix_stats;
549 : : int rc = 0;
550 : :
551 : 0 : rc = roc_eswitch_nix_repte_stats(&rep_dev->parent_dev->nix, rep_dev->hw_func, &nix_stats);
552 [ # # ]: 0 : if (rc) {
553 : 0 : plt_err("Failed to get stats for representee %x, err %d", rep_dev->hw_func, rc);
554 : 0 : goto fail;
555 : : }
556 : :
557 : : memset(stats, 0, sizeof(struct rte_eth_stats));
558 : 0 : stats->opackets = nix_stats.tx_ucast;
559 : 0 : stats->opackets += nix_stats.tx_mcast;
560 : 0 : stats->opackets += nix_stats.tx_bcast;
561 : 0 : stats->oerrors = nix_stats.tx_drop;
562 : 0 : stats->obytes = nix_stats.tx_octs;
563 : :
564 : 0 : stats->ipackets = nix_stats.rx_ucast;
565 : 0 : stats->ipackets += nix_stats.rx_mcast;
566 : 0 : stats->ipackets += nix_stats.rx_bcast;
567 : 0 : stats->imissed = nix_stats.rx_drop;
568 : 0 : stats->ibytes = nix_stats.rx_octs;
569 : 0 : stats->ierrors = nix_stats.rx_err;
570 : :
571 : 0 : return 0;
572 : : fail:
573 : 0 : return rc;
574 : : }
575 : :
576 : : int
577 [ # # ]: 0 : cnxk_rep_stats_get(struct rte_eth_dev *ethdev, struct rte_eth_stats *stats)
578 : : {
579 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(ethdev);
580 : : struct rte_eth_stats vf_stats;
581 : : cnxk_rep_msg_ack_data_t adata;
582 : : int rc;
583 : :
584 : : /* If representor not representing any active VF, return 0 */
585 [ # # ]: 0 : if (!rep_dev->is_vf_active)
586 : : return 0;
587 : :
588 [ # # ]: 0 : if (rep_dev->native_repte) {
589 : : /* For representees which are independent */
590 : 0 : rc = native_repte_eth_stats(rep_dev, &vf_stats);
591 [ # # ]: 0 : if (rc) {
592 : 0 : plt_err("Failed to get stats for vf rep %x (hw_func %x), err %d",
593 : : rep_dev->port_id, rep_dev->hw_func, rc);
594 : 0 : goto fail;
595 : : }
596 : : } else {
597 : : /* For representees which are part of companian app */
598 : 0 : rc = process_eth_stats(rep_dev, &adata, CNXK_REP_MSG_ETH_STATS_GET);
599 [ # # # # ]: 0 : if (rc || adata.u.sval < 0) {
600 [ # # ]: 0 : if (adata.u.sval < 0)
601 : 0 : rc = adata.u.sval;
602 : :
603 : 0 : plt_err("Failed to get stats for vf rep %x, err %d", rep_dev->port_id, rc);
604 : : }
605 : :
606 [ # # ]: 0 : if (adata.size != sizeof(struct rte_eth_stats)) {
607 : : rc = -EINVAL;
608 : 0 : plt_err("Incomplete stats received for vf rep %d", rep_dev->port_id);
609 : 0 : goto fail;
610 : : }
611 : :
612 [ # # ]: 0 : rte_memcpy(&vf_stats, adata.u.data, adata.size);
613 : : }
614 : :
615 : 0 : stats->q_ipackets[0] = vf_stats.ipackets;
616 : 0 : stats->q_ibytes[0] = vf_stats.ibytes;
617 : 0 : stats->ipackets = vf_stats.ipackets;
618 : 0 : stats->ibytes = vf_stats.ibytes;
619 : :
620 : 0 : stats->q_opackets[0] = vf_stats.opackets;
621 : 0 : stats->q_obytes[0] = vf_stats.obytes;
622 : 0 : stats->opackets = vf_stats.opackets;
623 : 0 : stats->obytes = vf_stats.obytes;
624 : :
625 : 0 : plt_rep_dbg("Input packets %" PRId64 " Output packets %" PRId64 "", stats->ipackets,
626 : : stats->opackets);
627 : :
628 : 0 : return 0;
629 : : fail:
630 : : return rc;
631 : : }
632 : :
633 : : int
634 [ # # ]: 0 : cnxk_rep_stats_reset(struct rte_eth_dev *ethdev)
635 : : {
636 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(ethdev);
637 : : cnxk_rep_msg_ack_data_t adata;
638 : : int rc = 0;
639 : :
640 : : /* If representor not representing any active VF, return 0 */
641 [ # # ]: 0 : if (!rep_dev->is_vf_active)
642 : : return 0;
643 : :
644 [ # # ]: 0 : if (rep_dev->native_repte)
645 : : return -ENOTSUP;
646 : :
647 : 0 : rc = process_eth_stats(rep_dev, &adata, CNXK_REP_MSG_ETH_STATS_CLEAR);
648 [ # # # # ]: 0 : if (rc || adata.u.sval < 0) {
649 [ # # ]: 0 : if (adata.u.sval < 0)
650 : 0 : rc = adata.u.sval;
651 : :
652 : 0 : plt_err("Failed to clear stats for vf rep %x, err %d", rep_dev->port_id, rc);
653 : : }
654 : :
655 : : return rc;
656 : : }
657 : :
658 : : int
659 : 0 : cnxk_rep_flow_ops_get(struct rte_eth_dev *ethdev, const struct rte_flow_ops **ops)
660 : : {
661 : : PLT_SET_USED(ethdev);
662 : 0 : *ops = &cnxk_rep_flow_ops;
663 : :
664 : 0 : return 0;
665 : : }
666 : :
667 : : int
668 [ # # ]: 0 : cnxk_rep_mac_addr_set(struct rte_eth_dev *eth_dev, struct rte_ether_addr *addr)
669 : : {
670 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(eth_dev);
671 : : cnxk_rep_msg_eth_set_mac_meta_t msg_sm_meta;
672 : : cnxk_rep_msg_ack_data_t adata;
673 : 0 : uint32_t len = 0, rc;
674 : : void *buffer;
675 : : size_t size;
676 : :
677 : : /* If representor not representing any VF, return 0 */
678 [ # # ]: 0 : if (!rep_dev->is_vf_active)
679 : : return 0;
680 : :
681 : : size = CNXK_REP_MSG_MAX_BUFFER_SZ;
682 : 0 : buffer = plt_zmalloc(size, 0);
683 [ # # ]: 0 : if (!buffer) {
684 : 0 : plt_err("Failed to allocate mem");
685 : : rc = -ENOMEM;
686 : 0 : goto fail;
687 : : }
688 : :
689 : 0 : cnxk_rep_msg_populate_header(buffer, &len);
690 : :
691 : 0 : msg_sm_meta.portid = rep_dev->rep_id;
692 [ # # ]: 0 : rte_memcpy(&msg_sm_meta.addr_bytes, addr->addr_bytes, RTE_ETHER_ADDR_LEN);
693 : 0 : cnxk_rep_msg_populate_command_meta(buffer, &len, &msg_sm_meta,
694 : : sizeof(cnxk_rep_msg_eth_set_mac_meta_t),
695 : : CNXK_REP_MSG_ETH_SET_MAC);
696 : 0 : cnxk_rep_msg_populate_msg_end(buffer, &len);
697 : :
698 : 0 : rc = cnxk_rep_msg_send_process(rep_dev, buffer, len, &adata);
699 [ # # ]: 0 : if (rc) {
700 : 0 : plt_err("Failed to process the message, err %d", rc);
701 : 0 : goto fail;
702 : : }
703 : :
704 [ # # ]: 0 : if (adata.u.sval < 0) {
705 : 0 : rc = adata.u.sval;
706 : 0 : plt_err("Failed to set mac address, err %d", rc);
707 : 0 : goto fail;
708 : : }
709 : :
710 : 0 : rte_free(buffer);
711 : :
712 : 0 : return 0;
713 : 0 : fail:
714 : 0 : rte_free(buffer);
715 : 0 : return rc;
716 : : }
717 : :
718 : : int
719 [ # # ]: 0 : cnxk_rep_xstats_get(struct rte_eth_dev *eth_dev, struct rte_eth_xstat *stats, unsigned int n)
720 : : {
721 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(eth_dev);
722 : : unsigned int num = RTE_DIM(cnxk_rep_xstats_string);
723 : : int cnt = 0;
724 : :
725 [ # # ]: 0 : if (!rep_dev)
726 : : return -EINVAL;
727 : :
728 [ # # ]: 0 : if (n < num)
729 : : return num;
730 : :
731 : 0 : stats[cnt].id = cnt;
732 : 0 : stats[cnt].value = rep_dev->rxq->stats.pkts;
733 : : cnt++;
734 : 0 : stats[cnt].id = cnt;
735 : 0 : stats[cnt].value = rep_dev->txq->stats.pkts;
736 : : cnt++;
737 : :
738 : 0 : return cnt;
739 : : }
740 : :
741 : : int
742 [ # # ]: 0 : cnxk_rep_xstats_reset(struct rte_eth_dev *eth_dev)
743 : : {
744 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(eth_dev);
745 : : int rc;
746 : :
747 [ # # ]: 0 : if (!rep_dev)
748 : : return -EINVAL;
749 : :
750 : 0 : rc = cnxk_rep_stats_reset(eth_dev);
751 [ # # ]: 0 : if (rc < 0 && rc != -ENOTSUP)
752 : : return rc;
753 : :
754 : 0 : rep_dev->rxq->stats.pkts = 0;
755 : 0 : rep_dev->txq->stats.pkts = 0;
756 : :
757 : 0 : return 0;
758 : : }
759 : :
760 : : int
761 : 0 : cnxk_rep_xstats_get_names(__rte_unused struct rte_eth_dev *eth_dev,
762 : : struct rte_eth_xstat_name *xstats_names, unsigned int n)
763 : : {
764 : : unsigned int num = RTE_DIM(cnxk_rep_xstats_string);
765 : : unsigned int i;
766 : :
767 [ # # ]: 0 : if (xstats_names == NULL)
768 : : return num;
769 : :
770 [ # # ]: 0 : if (n < num)
771 : : return num;
772 : :
773 [ # # ]: 0 : for (i = 0; i < num; i++)
774 : 0 : rte_strscpy(xstats_names[i].name, cnxk_rep_xstats_string[i].name,
775 : : sizeof(xstats_names[i].name));
776 : :
777 : : return num;
778 : : }
779 : :
780 : : int
781 [ # # ]: 0 : cnxk_rep_xstats_get_by_id(struct rte_eth_dev *eth_dev, const uint64_t *ids, uint64_t *values,
782 : : unsigned int n)
783 : : {
784 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(eth_dev);
785 : : unsigned int num = RTE_DIM(cnxk_rep_xstats_string);
786 : : unsigned int i;
787 : :
788 [ # # ]: 0 : if (!rep_dev)
789 : : return -EINVAL;
790 : :
791 [ # # ]: 0 : if (n < num)
792 : : return num;
793 : :
794 [ # # ]: 0 : if (n > num)
795 : : return -EINVAL;
796 : :
797 [ # # ]: 0 : for (i = 0; i < n; i++) {
798 [ # # # ]: 0 : switch (ids[i]) {
799 : 0 : case 0:
800 : 0 : values[i] = rep_dev->rxq->stats.pkts;
801 : 0 : break;
802 : 0 : case 1:
803 : 0 : values[i] = rep_dev->txq->stats.pkts;
804 : 0 : break;
805 : : default:
806 : : return -EINVAL;
807 : : }
808 : : }
809 : :
810 : : return n;
811 : : }
812 : :
813 : : int
814 : 0 : cnxk_rep_xstats_get_names_by_id(__rte_unused struct rte_eth_dev *eth_dev, const uint64_t *ids,
815 : : struct rte_eth_xstat_name *xstats_names, unsigned int n)
816 : : {
817 : : unsigned int num = RTE_DIM(cnxk_rep_xstats_string);
818 : : unsigned int i;
819 : :
820 [ # # ]: 0 : if (n < num)
821 : : return num;
822 : :
823 [ # # ]: 0 : if (n > num)
824 : : return -EINVAL;
825 : :
826 [ # # ]: 0 : for (i = 0; i < n; i++) {
827 [ # # ]: 0 : if (ids[i] >= num)
828 : : return -EINVAL;
829 : 0 : rte_strscpy(xstats_names[i].name, cnxk_rep_xstats_string[ids[i]].name,
830 : : sizeof(xstats_names[i].name));
831 : : }
832 : :
833 : : return n;
834 : : }
835 : :
836 : : int
837 [ # # ]: 0 : cnxk_rep_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
838 : : {
839 : : struct cnxk_rep_dev *rep_dev = cnxk_rep_pmd_priv(eth_dev);
840 : : uint32_t frame_size = mtu + CNXK_NIX_L2_OVERHEAD;
841 : : int rc = -EINVAL;
842 : :
843 : : /* Check if MTU is within the allowed range */
844 [ # # ]: 0 : if ((frame_size - RTE_ETHER_CRC_LEN) < NIX_MIN_HW_FRS) {
845 : 0 : plt_err("MTU is lesser than minimum");
846 : 0 : goto exit;
847 : : }
848 : :
849 : 0 : if ((frame_size - RTE_ETHER_CRC_LEN) >
850 [ # # ]: 0 : ((uint32_t)roc_nix_max_pkt_len(&rep_dev->parent_dev->nix))) {
851 : 0 : plt_err("MTU is greater than maximum");
852 : 0 : goto exit;
853 : : }
854 : :
855 : : frame_size -= RTE_ETHER_CRC_LEN;
856 : :
857 : : /* Set frame size on Rx */
858 : 0 : rc = roc_nix_mac_max_rx_len_set(&rep_dev->parent_dev->nix, frame_size);
859 [ # # ]: 0 : if (rc) {
860 : 0 : plt_err("Failed to max Rx frame length, rc=%d", rc);
861 : 0 : goto exit;
862 : : }
863 : 0 : exit:
864 : 0 : return rc;
865 : : }
866 : :
867 : : /* CNXK platform representor dev ops */
868 : : struct eth_dev_ops cnxk_rep_dev_ops = {
869 : : .dev_infos_get = cnxk_rep_dev_info_get,
870 : : .representor_info_get = cnxk_rep_representor_info_get,
871 : : .dev_configure = cnxk_rep_dev_configure,
872 : : .dev_start = cnxk_rep_dev_start,
873 : : .rx_queue_setup = cnxk_rep_rx_queue_setup,
874 : : .rx_queue_release = cnxk_rep_rx_queue_release,
875 : : .tx_queue_setup = cnxk_rep_tx_queue_setup,
876 : : .tx_queue_release = cnxk_rep_tx_queue_release,
877 : : .promiscuous_enable = cnxk_rep_promiscuous_enable,
878 : : .promiscuous_disable = cnxk_rep_promiscuous_disable,
879 : : .mac_addr_set = cnxk_rep_mac_addr_set,
880 : : .link_update = cnxk_rep_link_update,
881 : : .dev_close = cnxk_rep_dev_close,
882 : : .dev_stop = cnxk_rep_dev_stop,
883 : : .stats_get = cnxk_rep_stats_get,
884 : : .stats_reset = cnxk_rep_stats_reset,
885 : : .flow_ops_get = cnxk_rep_flow_ops_get,
886 : : .xstats_get = cnxk_rep_xstats_get,
887 : : .xstats_reset = cnxk_rep_xstats_reset,
888 : : .xstats_get_names = cnxk_rep_xstats_get_names,
889 : : .xstats_get_by_id = cnxk_rep_xstats_get_by_id,
890 : : .xstats_get_names_by_id = cnxk_rep_xstats_get_names_by_id,
891 : : .mtu_set = cnxk_rep_mtu_set
892 : : };
|