b318c5a06152687b3a896ea1a170af601c05930f
[dpdk.git] / drivers / net / bnxt / bnxt_reps.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #include "bnxt.h"
7 #include "bnxt_ring.h"
8 #include "bnxt_reps.h"
9 #include "bnxt_rxq.h"
10 #include "bnxt_rxr.h"
11 #include "bnxt_txq.h"
12 #include "bnxt_txr.h"
13 #include "bnxt_hwrm.h"
14 #include "hsi_struct_def_dpdk.h"
15
16 static const struct eth_dev_ops bnxt_vf_rep_dev_ops = {
17         .dev_infos_get = bnxt_vf_rep_dev_info_get_op,
18         .dev_configure = bnxt_vf_rep_dev_configure_op,
19         .dev_start = bnxt_vf_rep_dev_start_op,
20         .rx_queue_setup = bnxt_vf_rep_rx_queue_setup_op,
21         .rx_queue_release = bnxt_vf_rep_rx_queue_release_op,
22         .tx_queue_setup = bnxt_vf_rep_tx_queue_setup_op,
23         .tx_queue_release = bnxt_vf_rep_tx_queue_release_op,
24         .link_update = bnxt_vf_rep_link_update_op,
25         .dev_close = bnxt_vf_rep_dev_close_op,
26         .dev_stop = bnxt_vf_rep_dev_stop_op,
27         .stats_get = bnxt_vf_rep_stats_get_op,
28         .stats_reset = bnxt_vf_rep_stats_reset_op,
29 };
30
31 uint16_t
32 bnxt_vfr_recv(struct bnxt *bp, uint16_t cfa_code, uint16_t queue_id,
33               struct rte_mbuf *mbuf)
34 {
35         struct bnxt_sw_rx_bd *prod_rx_buf;
36         struct bnxt_rx_ring_info *rep_rxr;
37         struct bnxt_rx_queue *rep_rxq;
38         struct rte_eth_dev *vfr_eth_dev;
39         struct bnxt_vf_representor *vfr_bp;
40         uint16_t vf_id;
41         uint16_t mask;
42         uint8_t que;
43
44         vf_id = bp->cfa_code_map[cfa_code];
45         /* cfa_code is invalid OR vf_id > MAX REP. Assume normal Rx */
46         if (vf_id == BNXT_VF_IDX_INVALID || vf_id > BNXT_MAX_VF_REPS)
47                 return 1;
48         vfr_eth_dev = bp->rep_info[vf_id].vfr_eth_dev;
49         if (!vfr_eth_dev)
50                 return 1;
51         vfr_bp = vfr_eth_dev->data->dev_private;
52         if (vfr_bp->rx_cfa_code != cfa_code) {
53                 /* cfa_code not meant for this VF rep!!?? */
54                 return 1;
55         }
56         /* If rxq_id happens to be > max rep_queue, use rxq0 */
57         que = queue_id < BNXT_MAX_VF_REP_RINGS ? queue_id : 0;
58         rep_rxq = vfr_bp->rx_queues[que];
59         rep_rxr = rep_rxq->rx_ring;
60         mask = rep_rxr->rx_ring_struct->ring_mask;
61
62         /* Put this mbuf on the RxQ of the Representor */
63         prod_rx_buf =
64                 &rep_rxr->rx_buf_ring[rep_rxr->rx_prod++ & mask];
65         if (!prod_rx_buf->mbuf) {
66                 prod_rx_buf->mbuf = mbuf;
67                 vfr_bp->rx_bytes[que] += mbuf->pkt_len;
68                 vfr_bp->rx_pkts[que]++;
69         } else {
70                 vfr_bp->rx_drop_bytes[que] += mbuf->pkt_len;
71                 vfr_bp->rx_drop_pkts[que]++;
72                 rte_free(mbuf); /* Representor Rx ring full, drop pkt */
73         }
74
75         return 0;
76 }
77
78 static uint16_t
79 bnxt_vf_rep_rx_burst(void *rx_queue,
80                      struct rte_mbuf **rx_pkts,
81                      uint16_t nb_pkts)
82 {
83         struct bnxt_rx_queue *rxq = rx_queue;
84         struct bnxt_sw_rx_bd *cons_rx_buf;
85         struct bnxt_rx_ring_info *rxr;
86         uint16_t nb_rx_pkts = 0;
87         uint16_t mask, i;
88
89         if (!rxq)
90                 return 0;
91
92         rxr = rxq->rx_ring;
93         mask = rxr->rx_ring_struct->ring_mask;
94         for (i = 0; i < nb_pkts; i++) {
95                 cons_rx_buf = &rxr->rx_buf_ring[rxr->rx_cons & mask];
96                 if (!cons_rx_buf->mbuf)
97                         return nb_rx_pkts;
98                 rx_pkts[nb_rx_pkts] = cons_rx_buf->mbuf;
99                 rx_pkts[nb_rx_pkts]->port = rxq->port_id;
100                 cons_rx_buf->mbuf = NULL;
101                 nb_rx_pkts++;
102                 rxr->rx_cons++;
103         }
104
105         return nb_rx_pkts;
106 }
107
108 static uint16_t
109 bnxt_vf_rep_tx_burst(void *tx_queue,
110                      struct rte_mbuf **tx_pkts,
111                      __rte_unused uint16_t nb_pkts)
112 {
113         struct bnxt_vf_rep_tx_queue *vfr_txq = tx_queue;
114         struct bnxt_tx_queue *ptxq;
115         struct bnxt *parent;
116         struct  bnxt_vf_representor *vf_rep_bp;
117         int qid;
118         int rc;
119         int i;
120
121         if (!vfr_txq)
122                 return 0;
123
124         qid = vfr_txq->txq->queue_id;
125         vf_rep_bp = vfr_txq->bp;
126         parent = vf_rep_bp->parent_dev->data->dev_private;
127         pthread_mutex_lock(&parent->rep_info->vfr_lock);
128         ptxq = parent->tx_queues[qid];
129
130         ptxq->tx_cfa_action = vf_rep_bp->tx_cfa_action;
131
132         for (i = 0; i < nb_pkts; i++) {
133                 vf_rep_bp->tx_bytes[qid] += tx_pkts[i]->pkt_len;
134                 vf_rep_bp->tx_pkts[qid]++;
135         }
136
137         rc = bnxt_xmit_pkts(ptxq, tx_pkts, nb_pkts);
138         ptxq->tx_cfa_action = 0;
139         pthread_mutex_unlock(&parent->rep_info->vfr_lock);
140
141         return rc;
142
143         return 0;
144 }
145
146 int bnxt_vf_representor_init(struct rte_eth_dev *eth_dev, void *params)
147 {
148         struct bnxt_vf_representor *vf_rep_bp = eth_dev->data->dev_private;
149         struct bnxt_vf_representor *rep_params =
150                                  (struct bnxt_vf_representor *)params;
151         struct rte_eth_link *link;
152         struct bnxt *parent_bp;
153
154         vf_rep_bp->vf_id = rep_params->vf_id;
155         vf_rep_bp->switch_domain_id = rep_params->switch_domain_id;
156         vf_rep_bp->parent_dev = rep_params->parent_dev;
157
158         eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
159         eth_dev->data->representor_id = rep_params->vf_id;
160
161         rte_eth_random_addr(vf_rep_bp->dflt_mac_addr);
162         memcpy(vf_rep_bp->mac_addr, vf_rep_bp->dflt_mac_addr,
163                sizeof(vf_rep_bp->mac_addr));
164         eth_dev->data->mac_addrs =
165                 (struct rte_ether_addr *)&vf_rep_bp->mac_addr;
166         eth_dev->dev_ops = &bnxt_vf_rep_dev_ops;
167
168         /* No data-path, but need stub Rx/Tx functions to avoid crash
169          * when testing with ovs-dpdk
170          */
171         eth_dev->rx_pkt_burst = bnxt_vf_rep_rx_burst;
172         eth_dev->tx_pkt_burst = bnxt_vf_rep_tx_burst;
173         /* Link state. Inherited from PF or trusted VF */
174         parent_bp = vf_rep_bp->parent_dev->data->dev_private;
175         link = &parent_bp->eth_dev->data->dev_link;
176
177         eth_dev->data->dev_link.link_speed = link->link_speed;
178         eth_dev->data->dev_link.link_duplex = link->link_duplex;
179         eth_dev->data->dev_link.link_status = link->link_status;
180         eth_dev->data->dev_link.link_autoneg = link->link_autoneg;
181
182         PMD_DRV_LOG(INFO, "calling bnxt_print_link_info\n");
183         bnxt_print_link_info(eth_dev);
184
185         /* Pass the information to the rte_eth_dev_close() that it should also
186          * release the private port resources.
187          */
188         eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
189         PMD_DRV_LOG(INFO,
190                     "Switch domain id %d: Representor Device %d init done\n",
191                     vf_rep_bp->switch_domain_id, vf_rep_bp->vf_id);
192
193         return 0;
194 }
195
196 int bnxt_vf_representor_uninit(struct rte_eth_dev *eth_dev)
197 {
198         struct bnxt *parent_bp;
199         struct bnxt_vf_representor *rep =
200                 (struct bnxt_vf_representor *)eth_dev->data->dev_private;
201
202         uint16_t vf_id;
203
204         eth_dev->data->mac_addrs = NULL;
205         eth_dev->dev_ops = NULL;
206
207         parent_bp = rep->parent_dev->data->dev_private;
208         if (!parent_bp)
209                 return 0;
210
211         parent_bp->num_reps--;
212         vf_id = rep->vf_id;
213         if (parent_bp->rep_info)
214                 memset(&parent_bp->rep_info[vf_id], 0,
215                        sizeof(parent_bp->rep_info[vf_id]));
216                 /* mark that this representor has been freed */
217         return 0;
218 }
219
220 int bnxt_vf_rep_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_compl)
221 {
222         struct bnxt *parent_bp;
223         struct bnxt_vf_representor *rep =
224                 (struct bnxt_vf_representor *)eth_dev->data->dev_private;
225         struct rte_eth_link *link;
226         int rc;
227
228         parent_bp = rep->parent_dev->data->dev_private;
229         rc = bnxt_link_update_op(parent_bp->eth_dev, wait_to_compl);
230
231         /* Link state. Inherited from PF or trusted VF */
232         link = &parent_bp->eth_dev->data->dev_link;
233
234         eth_dev->data->dev_link.link_speed = link->link_speed;
235         eth_dev->data->dev_link.link_duplex = link->link_duplex;
236         eth_dev->data->dev_link.link_status = link->link_status;
237         eth_dev->data->dev_link.link_autoneg = link->link_autoneg;
238         bnxt_print_link_info(eth_dev);
239
240         return rc;
241 }
242
243 static int bnxt_vfr_alloc(struct bnxt_vf_representor *vfr)
244 {
245         int rc = 0;
246         struct bnxt *parent_bp;
247
248         if (!vfr || !vfr->parent_dev) {
249                 PMD_DRV_LOG(ERR,
250                             "No memory allocated for representor\n");
251                 return -ENOMEM;
252         }
253
254         parent_bp = vfr->parent_dev->data->dev_private;
255
256         /* Check if representor has been already allocated in FW */
257         if (vfr->tx_cfa_action && vfr->rx_cfa_code)
258                 return 0;
259
260         /*
261          * Alloc VF rep rules in CFA after default VNIC is created.
262          * Otherwise the FW will create the VF-rep rules with
263          * default drop action.
264          */
265
266         /*
267          * This is where we need to replace invoking an HWRM cmd
268          * with the new TFLIB ULP API to do more/less the same job
269         rc = bnxt_hwrm_cfa_vfr_alloc(parent_bp,
270                                      vfr->vf_id,
271                                      &vfr->tx_cfa_action,
272                                      &vfr->rx_cfa_code);
273          */
274         if (!rc) {
275                 parent_bp->cfa_code_map[vfr->rx_cfa_code] = vfr->vf_id;
276                 PMD_DRV_LOG(DEBUG, "allocated representor %d in FW\n",
277                             vfr->vf_id);
278         } else {
279                 PMD_DRV_LOG(ERR,
280                             "Failed to alloc representor %d in FW\n",
281                             vfr->vf_id);
282         }
283
284         return rc;
285 }
286
287 static void bnxt_vf_rep_free_rx_mbufs(struct bnxt_vf_representor *rep_bp)
288 {
289         struct bnxt_rx_queue *rxq;
290         unsigned int i;
291
292         for (i = 0; i < rep_bp->rx_nr_rings; i++) {
293                 rxq = rep_bp->rx_queues[i];
294                 bnxt_rx_queue_release_mbufs(rxq);
295         }
296 }
297
298 int bnxt_vf_rep_dev_start_op(struct rte_eth_dev *eth_dev)
299 {
300         struct bnxt_vf_representor *rep_bp = eth_dev->data->dev_private;
301         int rc;
302
303         rc = bnxt_vfr_alloc(rep_bp);
304
305         if (!rc) {
306                 eth_dev->rx_pkt_burst = &bnxt_vf_rep_rx_burst;
307                 eth_dev->tx_pkt_burst = &bnxt_vf_rep_tx_burst;
308
309                 bnxt_vf_rep_link_update_op(eth_dev, 1);
310         } else {
311                 eth_dev->data->dev_link.link_status = 0;
312                 bnxt_vf_rep_free_rx_mbufs(rep_bp);
313         }
314
315         return rc;
316 }
317
318 static int bnxt_vfr_free(struct bnxt_vf_representor *vfr)
319 {
320         int rc = 0;
321         struct bnxt *parent_bp;
322
323         if (!vfr || !vfr->parent_dev) {
324                 PMD_DRV_LOG(ERR,
325                             "No memory allocated for representor\n");
326                 return -ENOMEM;
327         }
328
329         parent_bp = vfr->parent_dev->data->dev_private;
330
331         /* Check if representor has been already freed in FW */
332         if (!vfr->tx_cfa_action && !vfr->rx_cfa_code)
333                 return 0;
334
335         /*
336          * This is where we need to replace invoking an HWRM cmd
337          * with the new TFLIB ULP API to do more/less the same job
338         rc = bnxt_hwrm_cfa_vfr_free(parent_bp,
339                                     vfr->vf_id);
340          */
341         if (rc) {
342                 PMD_DRV_LOG(ERR,
343                             "Failed to free representor %d in FW\n",
344                             vfr->vf_id);
345                 return rc;
346         }
347
348         parent_bp->cfa_code_map[vfr->rx_cfa_code] = BNXT_VF_IDX_INVALID;
349         PMD_DRV_LOG(DEBUG, "freed representor %d in FW\n",
350                     vfr->vf_id);
351         vfr->tx_cfa_action = 0;
352         vfr->rx_cfa_code = 0;
353
354         return rc;
355 }
356
357 void bnxt_vf_rep_dev_stop_op(struct rte_eth_dev *eth_dev)
358 {
359         struct bnxt_vf_representor *vfr_bp = eth_dev->data->dev_private;
360
361         /* Avoid crashes as we are about to free queues */
362         eth_dev->rx_pkt_burst = &bnxt_dummy_recv_pkts;
363         eth_dev->tx_pkt_burst = &bnxt_dummy_xmit_pkts;
364
365         bnxt_vfr_free(vfr_bp);
366
367         if (eth_dev->data->dev_started)
368                 eth_dev->data->dev_link.link_status = 0;
369
370         bnxt_vf_rep_free_rx_mbufs(vfr_bp);
371 }
372
373 void bnxt_vf_rep_dev_close_op(struct rte_eth_dev *eth_dev)
374 {
375         bnxt_vf_representor_uninit(eth_dev);
376 }
377
378 int bnxt_vf_rep_dev_info_get_op(struct rte_eth_dev *eth_dev,
379                                 struct rte_eth_dev_info *dev_info)
380 {
381         struct bnxt_vf_representor *rep_bp = eth_dev->data->dev_private;
382         struct bnxt *parent_bp;
383         uint16_t max_vnics, i, j, vpool, vrxq;
384         unsigned int max_rx_rings;
385         int rc = 0;
386
387         /* MAC Specifics */
388         parent_bp = rep_bp->parent_dev->data->dev_private;
389         if (!parent_bp) {
390                 PMD_DRV_LOG(ERR, "Rep parent NULL!\n");
391                 return rc;
392         }
393         PMD_DRV_LOG(DEBUG, "Representor dev_info_get_op\n");
394         dev_info->max_mac_addrs = parent_bp->max_l2_ctx;
395         dev_info->max_hash_mac_addrs = 0;
396
397         max_rx_rings = BNXT_MAX_VF_REP_RINGS;
398         /* For the sake of symmetry, max_rx_queues = max_tx_queues */
399         dev_info->max_rx_queues = max_rx_rings;
400         dev_info->max_tx_queues = max_rx_rings;
401         dev_info->reta_size = bnxt_rss_hash_tbl_size(parent_bp);
402         dev_info->hash_key_size = 40;
403         max_vnics = parent_bp->max_vnics;
404
405         /* MTU specifics */
406         dev_info->min_mtu = RTE_ETHER_MIN_MTU;
407         dev_info->max_mtu = BNXT_MAX_MTU;
408
409         /* Fast path specifics */
410         dev_info->min_rx_bufsize = 1;
411         dev_info->max_rx_pktlen = BNXT_MAX_PKT_LEN;
412
413         dev_info->rx_offload_capa = BNXT_DEV_RX_OFFLOAD_SUPPORT;
414         if (parent_bp->flags & BNXT_FLAG_PTP_SUPPORTED)
415                 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TIMESTAMP;
416         dev_info->tx_offload_capa = BNXT_DEV_TX_OFFLOAD_SUPPORT;
417         dev_info->flow_type_rss_offloads = BNXT_ETH_RSS_SUPPORT;
418
419         /* *INDENT-OFF* */
420         dev_info->default_rxconf = (struct rte_eth_rxconf) {
421                 .rx_thresh = {
422                         .pthresh = 8,
423                         .hthresh = 8,
424                         .wthresh = 0,
425                 },
426                 .rx_free_thresh = 32,
427                 /* If no descriptors available, pkts are dropped by default */
428                 .rx_drop_en = 1,
429         };
430
431         dev_info->default_txconf = (struct rte_eth_txconf) {
432                 .tx_thresh = {
433                         .pthresh = 32,
434                         .hthresh = 0,
435                         .wthresh = 0,
436                 },
437                 .tx_free_thresh = 32,
438                 .tx_rs_thresh = 32,
439         };
440         eth_dev->data->dev_conf.intr_conf.lsc = 1;
441
442         eth_dev->data->dev_conf.intr_conf.rxq = 1;
443         dev_info->rx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
444         dev_info->rx_desc_lim.nb_max = BNXT_MAX_RX_RING_DESC;
445         dev_info->tx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
446         dev_info->tx_desc_lim.nb_max = BNXT_MAX_TX_RING_DESC;
447
448         /* *INDENT-ON* */
449
450         /*
451          * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
452          *       need further investigation.
453          */
454
455         /* VMDq resources */
456         vpool = 64; /* ETH_64_POOLS */
457         vrxq = 128; /* ETH_VMDQ_DCB_NUM_QUEUES */
458         for (i = 0; i < 4; vpool >>= 1, i++) {
459                 if (max_vnics > vpool) {
460                         for (j = 0; j < 5; vrxq >>= 1, j++) {
461                                 if (dev_info->max_rx_queues > vrxq) {
462                                         if (vpool > vrxq)
463                                                 vpool = vrxq;
464                                         goto found;
465                                 }
466                         }
467                         /* Not enough resources to support VMDq */
468                         break;
469                 }
470         }
471         /* Not enough resources to support VMDq */
472         vpool = 0;
473         vrxq = 0;
474 found:
475         dev_info->max_vmdq_pools = vpool;
476         dev_info->vmdq_queue_num = vrxq;
477
478         dev_info->vmdq_pool_base = 0;
479         dev_info->vmdq_queue_base = 0;
480
481         return 0;
482 }
483
484 int bnxt_vf_rep_dev_configure_op(__rte_unused struct rte_eth_dev *eth_dev)
485 {
486         struct bnxt_vf_representor *rep_bp = eth_dev->data->dev_private;
487
488         PMD_DRV_LOG(DEBUG, "Representor dev_configure_op\n");
489         rep_bp->rx_queues = (void *)eth_dev->data->rx_queues;
490         rep_bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
491         rep_bp->rx_nr_rings = eth_dev->data->nb_rx_queues;
492
493         return 0;
494 }
495
496 int bnxt_vf_rep_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
497                           uint16_t queue_idx,
498                           uint16_t nb_desc,
499                           unsigned int socket_id,
500                           __rte_unused const struct rte_eth_rxconf *rx_conf,
501                           __rte_unused struct rte_mempool *mp)
502 {
503         struct bnxt_vf_representor *rep_bp = eth_dev->data->dev_private;
504         struct bnxt *parent_bp = rep_bp->parent_dev->data->dev_private;
505         struct bnxt_rx_queue *parent_rxq;
506         struct bnxt_rx_queue *rxq;
507         struct bnxt_sw_rx_bd *buf_ring;
508         int rc = 0;
509
510         if (queue_idx >= BNXT_MAX_VF_REP_RINGS) {
511                 PMD_DRV_LOG(ERR,
512                             "Cannot create Rx ring %d. %d rings available\n",
513                             queue_idx, BNXT_MAX_VF_REP_RINGS);
514                 return -EINVAL;
515         }
516
517         if (!nb_desc || nb_desc > MAX_RX_DESC_CNT) {
518                 PMD_DRV_LOG(ERR, "nb_desc %d is invalid\n", nb_desc);
519                 return -EINVAL;
520         }
521
522         parent_rxq = parent_bp->rx_queues[queue_idx];
523         if (!parent_rxq) {
524                 PMD_DRV_LOG(ERR, "Parent RxQ has not been configured yet\n");
525                 return -EINVAL;
526         }
527
528         if (nb_desc != parent_rxq->nb_rx_desc) {
529                 PMD_DRV_LOG(ERR, "nb_desc %d do not match parent rxq", nb_desc);
530                 return -EINVAL;
531         }
532
533         if (eth_dev->data->rx_queues) {
534                 rxq = eth_dev->data->rx_queues[queue_idx];
535                 if (rxq)
536                         bnxt_rx_queue_release_op(rxq);
537         }
538
539         rxq = rte_zmalloc_socket("bnxt_vfr_rx_queue",
540                                  sizeof(struct bnxt_rx_queue),
541                                  RTE_CACHE_LINE_SIZE, socket_id);
542         if (!rxq) {
543                 PMD_DRV_LOG(ERR, "bnxt_vfr_rx_queue allocation failed!\n");
544                 return -ENOMEM;
545         }
546
547         rxq->nb_rx_desc = nb_desc;
548
549         rc = bnxt_init_rx_ring_struct(rxq, socket_id);
550         if (rc)
551                 goto out;
552
553         buf_ring = rte_zmalloc_socket("bnxt_rx_vfr_buf_ring",
554                                       sizeof(struct bnxt_sw_rx_bd) *
555                                       rxq->rx_ring->rx_ring_struct->ring_size,
556                                       RTE_CACHE_LINE_SIZE, socket_id);
557         if (!buf_ring) {
558                 PMD_DRV_LOG(ERR, "bnxt_rx_vfr_buf_ring allocation failed!\n");
559                 rc = -ENOMEM;
560                 goto out;
561         }
562
563         rxq->rx_ring->rx_buf_ring = buf_ring;
564         rxq->queue_id = queue_idx;
565         rxq->port_id = eth_dev->data->port_id;
566         eth_dev->data->rx_queues[queue_idx] = rxq;
567
568         return 0;
569
570 out:
571         if (rxq)
572                 bnxt_rx_queue_release_op(rxq);
573
574         return rc;
575 }
576
577 void bnxt_vf_rep_rx_queue_release_op(void *rx_queue)
578 {
579         struct bnxt_rx_queue *rxq = (struct bnxt_rx_queue *)rx_queue;
580
581         if (!rxq)
582                 return;
583
584         bnxt_rx_queue_release_mbufs(rxq);
585
586         bnxt_free_ring(rxq->rx_ring->rx_ring_struct);
587         bnxt_free_ring(rxq->rx_ring->ag_ring_struct);
588         bnxt_free_ring(rxq->cp_ring->cp_ring_struct);
589
590         rte_free(rxq);
591 }
592
593 int bnxt_vf_rep_tx_queue_setup_op(struct rte_eth_dev *eth_dev,
594                           uint16_t queue_idx,
595                           uint16_t nb_desc,
596                           unsigned int socket_id,
597                           __rte_unused const struct rte_eth_txconf *tx_conf)
598 {
599         struct bnxt_vf_representor *rep_bp = eth_dev->data->dev_private;
600         struct bnxt *parent_bp = rep_bp->parent_dev->data->dev_private;
601         struct bnxt_tx_queue *parent_txq, *txq;
602         struct bnxt_vf_rep_tx_queue *vfr_txq;
603
604         if (queue_idx >= BNXT_MAX_VF_REP_RINGS) {
605                 PMD_DRV_LOG(ERR,
606                             "Cannot create Tx rings %d. %d rings available\n",
607                             queue_idx, BNXT_MAX_VF_REP_RINGS);
608                 return -EINVAL;
609         }
610
611         if (!nb_desc || nb_desc > MAX_TX_DESC_CNT) {
612                 PMD_DRV_LOG(ERR, "nb_desc %d is invalid", nb_desc);
613                 return -EINVAL;
614         }
615
616         parent_txq = parent_bp->tx_queues[queue_idx];
617         if (!parent_txq) {
618                 PMD_DRV_LOG(ERR, "Parent TxQ has not been configured yet\n");
619                 return -EINVAL;
620         }
621
622         if (nb_desc != parent_txq->nb_tx_desc) {
623                 PMD_DRV_LOG(ERR, "nb_desc %d do not match parent txq", nb_desc);
624                 return -EINVAL;
625         }
626
627         if (eth_dev->data->tx_queues) {
628                 vfr_txq = eth_dev->data->tx_queues[queue_idx];
629                 bnxt_vf_rep_tx_queue_release_op(vfr_txq);
630                 vfr_txq = NULL;
631         }
632
633         vfr_txq = rte_zmalloc_socket("bnxt_vfr_tx_queue",
634                                      sizeof(struct bnxt_vf_rep_tx_queue),
635                                      RTE_CACHE_LINE_SIZE, socket_id);
636         if (!vfr_txq) {
637                 PMD_DRV_LOG(ERR, "bnxt_vfr_tx_queue allocation failed!");
638                 return -ENOMEM;
639         }
640         txq = rte_zmalloc_socket("bnxt_tx_queue",
641                                  sizeof(struct bnxt_tx_queue),
642                                  RTE_CACHE_LINE_SIZE, socket_id);
643         if (!txq) {
644                 PMD_DRV_LOG(ERR, "bnxt_tx_queue allocation failed!");
645                 rte_free(vfr_txq);
646                 return -ENOMEM;
647         }
648
649         txq->nb_tx_desc = nb_desc;
650         txq->queue_id = queue_idx;
651         txq->port_id = eth_dev->data->port_id;
652         vfr_txq->txq = txq;
653         vfr_txq->bp = rep_bp;
654         eth_dev->data->tx_queues[queue_idx] = vfr_txq;
655
656         return 0;
657 }
658
659 void bnxt_vf_rep_tx_queue_release_op(void *tx_queue)
660 {
661         struct bnxt_vf_rep_tx_queue *vfr_txq = tx_queue;
662
663         if (!vfr_txq)
664                 return;
665
666         rte_free(vfr_txq->txq);
667         rte_free(vfr_txq);
668 }
669
670 int bnxt_vf_rep_stats_get_op(struct rte_eth_dev *eth_dev,
671                              struct rte_eth_stats *stats)
672 {
673         struct bnxt_vf_representor *rep_bp = eth_dev->data->dev_private;
674         int i;
675
676         memset(stats, 0, sizeof(*stats));
677         for (i = 0; i < BNXT_MAX_VF_REP_RINGS; i++) {
678                 stats->obytes += rep_bp->tx_bytes[i];
679                 stats->opackets += rep_bp->tx_pkts[i];
680                 stats->ibytes += rep_bp->rx_bytes[i];
681                 stats->ipackets += rep_bp->rx_pkts[i];
682                 stats->imissed += rep_bp->rx_drop_pkts[i];
683
684                 stats->q_ipackets[i] = rep_bp->rx_pkts[i];
685                 stats->q_ibytes[i] = rep_bp->rx_bytes[i];
686                 stats->q_opackets[i] = rep_bp->tx_pkts[i];
687                 stats->q_obytes[i] = rep_bp->tx_bytes[i];
688                 stats->q_errors[i] = rep_bp->rx_drop_pkts[i];
689         }
690
691         return 0;
692 }
693
694 int bnxt_vf_rep_stats_reset_op(struct rte_eth_dev *eth_dev)
695 {
696         struct bnxt_vf_representor *rep_bp = eth_dev->data->dev_private;
697         int i;
698
699         for (i = 0; i < BNXT_MAX_VF_REP_RINGS; i++) {
700                 rep_bp->tx_pkts[i] = 0;
701                 rep_bp->tx_bytes[i] = 0;
702                 rep_bp->rx_pkts[i] = 0;
703                 rep_bp->rx_bytes[i] = 0;
704                 rep_bp->rx_drop_pkts[i] = 0;
705         }
706         return 0;
707 }