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