4c6e26651bd49c49bada38756d2e81ffda229f2d
[dpdk.git] / drivers / crypto / octeontx / otx_cryptodev_ops.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Cavium, Inc
3  */
4
5 #include <rte_alarm.h>
6 #include <rte_bus_pci.h>
7 #include <rte_cryptodev.h>
8 #include <rte_cryptodev_pmd.h>
9 #include <rte_errno.h>
10 #include <rte_malloc.h>
11 #include <rte_mempool.h>
12
13 #include "otx_cryptodev.h"
14 #include "otx_cryptodev_capabilities.h"
15 #include "otx_cryptodev_hw_access.h"
16 #include "otx_cryptodev_mbox.h"
17 #include "otx_cryptodev_ops.h"
18
19 #include "cpt_pmd_logs.h"
20 #include "cpt_ucode.h"
21
22 /* Forward declarations */
23
24 static int
25 otx_cpt_que_pair_release(struct rte_cryptodev *dev, uint16_t que_pair_id);
26
27 /* Alarm routines */
28
29 static void
30 otx_cpt_alarm_cb(void *arg)
31 {
32         struct cpt_vf *cptvf = arg;
33         otx_cpt_poll_misc(cptvf);
34         rte_eal_alarm_set(CPT_INTR_POLL_INTERVAL_MS * 1000,
35                           otx_cpt_alarm_cb, cptvf);
36 }
37
38 static int
39 otx_cpt_periodic_alarm_start(void *arg)
40 {
41         return rte_eal_alarm_set(CPT_INTR_POLL_INTERVAL_MS * 1000,
42                                  otx_cpt_alarm_cb, arg);
43 }
44
45 static int
46 otx_cpt_periodic_alarm_stop(void *arg)
47 {
48         return rte_eal_alarm_cancel(otx_cpt_alarm_cb, arg);
49 }
50
51 /* PMD ops */
52
53 static int
54 otx_cpt_dev_config(struct rte_cryptodev *dev __rte_unused,
55                    struct rte_cryptodev_config *config __rte_unused)
56 {
57         CPT_PMD_INIT_FUNC_TRACE();
58         return 0;
59 }
60
61 static int
62 otx_cpt_dev_start(struct rte_cryptodev *c_dev)
63 {
64         void *cptvf = c_dev->data->dev_private;
65
66         CPT_PMD_INIT_FUNC_TRACE();
67
68         return otx_cpt_start_device(cptvf);
69 }
70
71 static void
72 otx_cpt_dev_stop(struct rte_cryptodev *c_dev)
73 {
74         void *cptvf = c_dev->data->dev_private;
75
76         CPT_PMD_INIT_FUNC_TRACE();
77
78         otx_cpt_stop_device(cptvf);
79 }
80
81 static int
82 otx_cpt_dev_close(struct rte_cryptodev *c_dev)
83 {
84         void *cptvf = c_dev->data->dev_private;
85         int i, ret;
86
87         CPT_PMD_INIT_FUNC_TRACE();
88
89         for (i = 0; i < c_dev->data->nb_queue_pairs; i++) {
90                 ret = otx_cpt_que_pair_release(c_dev, i);
91                 if (ret)
92                         return ret;
93         }
94
95         otx_cpt_periodic_alarm_stop(cptvf);
96         otx_cpt_deinit_device(cptvf);
97
98         return 0;
99 }
100
101 static void
102 otx_cpt_dev_info_get(struct rte_cryptodev *dev, struct rte_cryptodev_info *info)
103 {
104         CPT_PMD_INIT_FUNC_TRACE();
105         if (info != NULL) {
106                 info->max_nb_queue_pairs = CPT_NUM_QS_PER_VF;
107                 info->feature_flags = dev->feature_flags;
108                 info->capabilities = otx_get_capabilities();
109                 info->sym.max_nb_sessions = 0;
110                 info->driver_id = otx_cryptodev_driver_id;
111                 info->min_mbuf_headroom_req = OTX_CPT_MIN_HEADROOM_REQ;
112                 info->min_mbuf_tailroom_req = OTX_CPT_MIN_TAILROOM_REQ;
113         }
114 }
115
116 static void
117 otx_cpt_stats_get(struct rte_cryptodev *dev __rte_unused,
118                   struct rte_cryptodev_stats *stats __rte_unused)
119 {
120         CPT_PMD_INIT_FUNC_TRACE();
121 }
122
123 static void
124 otx_cpt_stats_reset(struct rte_cryptodev *dev __rte_unused)
125 {
126         CPT_PMD_INIT_FUNC_TRACE();
127 }
128
129 static int
130 otx_cpt_que_pair_setup(struct rte_cryptodev *dev,
131                        uint16_t que_pair_id,
132                        const struct rte_cryptodev_qp_conf *qp_conf,
133                        int socket_id __rte_unused)
134 {
135         struct cpt_instance *instance = NULL;
136         struct rte_pci_device *pci_dev;
137         int ret = -1;
138
139         CPT_PMD_INIT_FUNC_TRACE();
140
141         if (dev->data->queue_pairs[que_pair_id] != NULL) {
142                 ret = otx_cpt_que_pair_release(dev, que_pair_id);
143                 if (ret)
144                         return ret;
145         }
146
147         if (qp_conf->nb_descriptors > DEFAULT_CMD_QLEN) {
148                 CPT_LOG_INFO("Number of descriptors too big %d, using default "
149                              "queue length of %d", qp_conf->nb_descriptors,
150                              DEFAULT_CMD_QLEN);
151         }
152
153         pci_dev = RTE_DEV_TO_PCI(dev->device);
154
155         if (pci_dev->mem_resource[0].addr == NULL) {
156                 CPT_LOG_ERR("PCI mem address null");
157                 return -EIO;
158         }
159
160         ret = otx_cpt_get_resource(dev, 0, &instance, que_pair_id);
161         if (ret != 0 || instance == NULL) {
162                 CPT_LOG_ERR("Error getting instance handle from device %s : "
163                             "ret = %d", dev->data->name, ret);
164                 return ret;
165         }
166
167         instance->queue_id = que_pair_id;
168         instance->sess_mp = qp_conf->mp_session;
169         instance->sess_mp_priv = qp_conf->mp_session_private;
170         dev->data->queue_pairs[que_pair_id] = instance;
171
172         return 0;
173 }
174
175 static int
176 otx_cpt_que_pair_release(struct rte_cryptodev *dev, uint16_t que_pair_id)
177 {
178         struct cpt_instance *instance = dev->data->queue_pairs[que_pair_id];
179         int ret;
180
181         CPT_PMD_INIT_FUNC_TRACE();
182
183         ret = otx_cpt_put_resource(instance);
184         if (ret != 0) {
185                 CPT_LOG_ERR("Error putting instance handle of device %s : "
186                             "ret = %d", dev->data->name, ret);
187                 return ret;
188         }
189
190         dev->data->queue_pairs[que_pair_id] = NULL;
191
192         return 0;
193 }
194
195 static unsigned int
196 otx_cpt_get_session_size(struct rte_cryptodev *dev __rte_unused)
197 {
198         return cpt_get_session_size();
199 }
200
201 static void
202 otx_cpt_session_init(void *sym_sess, uint8_t driver_id)
203 {
204         struct rte_cryptodev_sym_session *sess = sym_sess;
205         struct cpt_sess_misc *cpt_sess =
206          (struct cpt_sess_misc *) get_sym_session_private_data(sess, driver_id);
207
208         CPT_PMD_INIT_FUNC_TRACE();
209         cpt_sess->ctx_dma_addr = rte_mempool_virt2iova(cpt_sess) +
210                         sizeof(struct cpt_sess_misc);
211 }
212
213 static int
214 otx_cpt_session_cfg(struct rte_cryptodev *dev,
215                     struct rte_crypto_sym_xform *xform,
216                     struct rte_cryptodev_sym_session *sess,
217                     struct rte_mempool *mempool)
218 {
219         struct rte_crypto_sym_xform *chain;
220         void *sess_private_data = NULL;
221
222         CPT_PMD_INIT_FUNC_TRACE();
223
224         if (cpt_is_algo_supported(xform))
225                 goto err;
226
227         if (unlikely(sess == NULL)) {
228                 CPT_LOG_ERR("invalid session struct");
229                 return -EINVAL;
230         }
231
232         if (rte_mempool_get(mempool, &sess_private_data)) {
233                 CPT_LOG_ERR("Could not allocate sess_private_data");
234                 return -ENOMEM;
235         }
236
237         chain = xform;
238         while (chain) {
239                 switch (chain->type) {
240                 case RTE_CRYPTO_SYM_XFORM_AEAD:
241                         if (fill_sess_aead(chain, sess_private_data))
242                                 goto err;
243                         break;
244                 case RTE_CRYPTO_SYM_XFORM_CIPHER:
245                         if (fill_sess_cipher(chain, sess_private_data))
246                                 goto err;
247                         break;
248                 case RTE_CRYPTO_SYM_XFORM_AUTH:
249                         if (chain->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC) {
250                                 if (fill_sess_gmac(chain, sess_private_data))
251                                         goto err;
252                         } else {
253                                 if (fill_sess_auth(chain, sess_private_data))
254                                         goto err;
255                         }
256                         break;
257                 default:
258                         CPT_LOG_ERR("Invalid crypto xform type");
259                         break;
260                 }
261                 chain = chain->next;
262         }
263         set_sym_session_private_data(sess, dev->driver_id, sess_private_data);
264         otx_cpt_session_init(sess, dev->driver_id);
265         return 0;
266
267 err:
268         if (sess_private_data)
269                 rte_mempool_put(mempool, sess_private_data);
270         return -EPERM;
271 }
272
273 static void
274 otx_cpt_session_clear(struct rte_cryptodev *dev,
275                   struct rte_cryptodev_sym_session *sess)
276 {
277         void *sess_priv = get_sym_session_private_data(sess, dev->driver_id);
278
279         CPT_PMD_INIT_FUNC_TRACE();
280         if (sess_priv) {
281                 memset(sess_priv, 0, otx_cpt_get_session_size(dev));
282                 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
283                 set_sym_session_private_data(sess, dev->driver_id, NULL);
284                 rte_mempool_put(sess_mp, sess_priv);
285         }
286 }
287
288 static __rte_always_inline int32_t __hot
289 otx_cpt_request_enqueue(struct cpt_instance *instance,
290                         struct pending_queue *pqueue,
291                         void *req)
292 {
293         struct cpt_request_info *user_req = (struct cpt_request_info *)req;
294
295         if (unlikely(pqueue->pending_count >= DEFAULT_CMD_QLEN))
296                 return -EAGAIN;
297
298         fill_cpt_inst(instance, req);
299
300         CPT_LOG_DP_DEBUG("req: %p op: %p ", req, user_req->op);
301
302         /* Fill time_out cycles */
303         user_req->time_out = rte_get_timer_cycles() +
304                         DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
305         user_req->extra_time = 0;
306
307         /* Default mode of software queue */
308         mark_cpt_inst(instance);
309
310         pqueue->rid_queue[pqueue->enq_tail].rid = (uintptr_t)user_req;
311
312         /* We will use soft queue length here to limit requests */
313         MOD_INC(pqueue->enq_tail, DEFAULT_CMD_QLEN);
314         pqueue->pending_count += 1;
315
316         CPT_LOG_DP_DEBUG("Submitted NB cmd with request: %p "
317                          "op: %p", user_req, user_req->op);
318         return 0;
319 }
320
321 static __rte_always_inline int __hot
322 otx_cpt_enq_single_sym(struct cpt_instance *instance,
323                        struct rte_crypto_op *op,
324                        struct pending_queue *pqueue)
325 {
326         struct cpt_sess_misc *sess;
327         struct rte_crypto_sym_op *sym_op = op->sym;
328         void *prep_req, *mdata = NULL;
329         int ret = 0;
330         uint64_t cpt_op;
331
332         sess = (struct cpt_sess_misc *)
333                         get_sym_session_private_data(sym_op->session,
334                                                      otx_cryptodev_driver_id);
335
336         cpt_op = sess->cpt_op;
337
338         if (likely(cpt_op & CPT_OP_CIPHER_MASK))
339                 ret = fill_fc_params(op, sess, &instance->meta_info, &mdata,
340                                      &prep_req);
341         else
342                 ret = fill_digest_params(op, sess, &instance->meta_info,
343                                          &mdata, &prep_req);
344
345         if (unlikely(ret)) {
346                 CPT_LOG_DP_ERR("prep cryto req : op %p, cpt_op 0x%x "
347                                "ret 0x%x", op, (unsigned int)cpt_op, ret);
348                 return ret;
349         }
350
351         /* Enqueue prepared instruction to h/w */
352         ret = otx_cpt_request_enqueue(instance, pqueue, prep_req);
353
354         if (unlikely(ret)) {
355                 /* Buffer allocated for request preparation need to be freed */
356                 free_op_meta(mdata, instance->meta_info.pool);
357                 return ret;
358         }
359
360         return 0;
361 }
362
363 static __rte_always_inline int __hot
364 otx_cpt_enq_single_sym_sessless(struct cpt_instance *instance,
365                                 struct rte_crypto_op *op,
366                                 struct pending_queue *pqueue)
367 {
368         struct cpt_sess_misc *sess;
369         struct rte_crypto_sym_op *sym_op = op->sym;
370         int ret;
371         void *sess_t = NULL;
372         void *sess_private_data_t = NULL;
373
374         /* Create tmp session */
375
376         if (rte_mempool_get(instance->sess_mp, (void **)&sess_t)) {
377                 ret = -ENOMEM;
378                 goto exit;
379         }
380
381         if (rte_mempool_get(instance->sess_mp_priv,
382                         (void **)&sess_private_data_t)) {
383                 ret = -ENOMEM;
384                 goto free_sess;
385         }
386
387         sess = (struct cpt_sess_misc *)sess_private_data_t;
388
389         sess->ctx_dma_addr = rte_mempool_virt2iova(sess) +
390                         sizeof(struct cpt_sess_misc);
391
392         ret = instance_session_cfg(sym_op->xform, (void *)sess);
393         if (unlikely(ret)) {
394                 ret = -EINVAL;
395                 goto free_sess_priv;
396         }
397
398         /* Save tmp session in op */
399
400         sym_op->session = (struct rte_cryptodev_sym_session *)sess_t;
401         set_sym_session_private_data(sym_op->session, otx_cryptodev_driver_id,
402                                      sess_private_data_t);
403
404         /* Enqueue op with the tmp session set */
405         ret = otx_cpt_enq_single_sym(instance, op, pqueue);
406
407         if (unlikely(ret))
408                 goto free_sess_priv;
409
410         return 0;
411
412 free_sess_priv:
413         rte_mempool_put(instance->sess_mp_priv, sess_private_data_t);
414 free_sess:
415         rte_mempool_put(instance->sess_mp, sess_t);
416 exit:
417         return ret;
418 }
419
420 static __rte_always_inline int __hot
421 otx_cpt_enq_single(struct cpt_instance *inst,
422                    struct rte_crypto_op *op,
423                    struct pending_queue *pqueue)
424 {
425         /* Check for the type */
426
427         if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
428                 return otx_cpt_enq_single_sym(inst, op, pqueue);
429         else if (unlikely(op->sess_type == RTE_CRYPTO_OP_SESSIONLESS))
430                 return otx_cpt_enq_single_sym_sessless(inst, op, pqueue);
431
432         /* Should not reach here */
433         return -EINVAL;
434 }
435
436 static uint16_t
437 otx_cpt_pkt_enqueue(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
438 {
439         struct cpt_instance *instance = (struct cpt_instance *)qptr;
440         uint16_t count;
441         int ret;
442         struct cpt_vf *cptvf = (struct cpt_vf *)instance;
443         struct pending_queue *pqueue = &cptvf->pqueue;
444
445         count = DEFAULT_CMD_QLEN - pqueue->pending_count;
446         if (nb_ops > count)
447                 nb_ops = count;
448
449         count = 0;
450         while (likely(count < nb_ops)) {
451
452                 /* Enqueue single op */
453                 ret = otx_cpt_enq_single(instance, ops[count], pqueue);
454
455                 if (unlikely(ret))
456                         break;
457                 count++;
458         }
459         otx_cpt_ring_dbell(instance, count);
460         return count;
461 }
462
463 static __rte_always_inline void
464 otx_cpt_dequeue_post_process(struct rte_crypto_op *cop, uintptr_t *rsp)
465 {
466         /* H/w has returned success */
467         cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
468
469         /* Perform further post processing */
470
471         if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
472                 /* Check if auth verify need to be completed */
473                 if (unlikely(rsp[2]))
474                         compl_auth_verify(cop, (uint8_t *)rsp[2], rsp[3]);
475                 return;
476         }
477 }
478
479 static uint16_t
480 otx_cpt_pkt_dequeue(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
481 {
482         struct cpt_instance *instance = (struct cpt_instance *)qptr;
483         struct cpt_request_info *user_req;
484         struct cpt_vf *cptvf = (struct cpt_vf *)instance;
485         struct rid *rid_e;
486         uint8_t cc[nb_ops];
487         int i, count, pcount;
488         uint8_t ret;
489         int nb_completed;
490         struct pending_queue *pqueue = &cptvf->pqueue;
491         struct rte_crypto_op *cop;
492         void *metabuf;
493         uintptr_t *rsp;
494
495         pcount = pqueue->pending_count;
496         count = (nb_ops > pcount) ? pcount : nb_ops;
497
498         for (i = 0; i < count; i++) {
499                 rid_e = &pqueue->rid_queue[pqueue->deq_head];
500                 user_req = (struct cpt_request_info *)(rid_e->rid);
501
502                 if (likely((i+1) < count))
503                         rte_prefetch_non_temporal((void *)rid_e[1].rid);
504
505                 ret = check_nb_command_id(user_req, instance);
506
507                 if (unlikely(ret == ERR_REQ_PENDING)) {
508                         /* Stop checking for completions */
509                         break;
510                 }
511
512                 /* Return completion code and op handle */
513                 cc[i] = ret;
514                 ops[i] = user_req->op;
515
516                 CPT_LOG_DP_DEBUG("Request %p Op %p completed with code %d",
517                                  user_req, user_req->op, ret);
518
519                 MOD_INC(pqueue->deq_head, DEFAULT_CMD_QLEN);
520                 pqueue->pending_count -= 1;
521         }
522
523         nb_completed = i;
524
525         for (i = 0; i < nb_completed; i++) {
526
527                 rsp = (void *)ops[i];
528
529                 if (likely((i + 1) < nb_completed))
530                         rte_prefetch0(ops[i+1]);
531
532                 metabuf = (void *)rsp[0];
533                 cop = (void *)rsp[1];
534
535                 ops[i] = cop;
536
537                 /* Check completion code */
538
539                 if (likely(cc[i] == 0)) {
540                         /* H/w success pkt. Post process */
541                         otx_cpt_dequeue_post_process(cop, rsp);
542                 } else if (cc[i] == ERR_GC_ICV_MISCOMPARE) {
543                         /* auth data mismatch */
544                         cop->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
545                 } else {
546                         /* Error */
547                         cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
548                 }
549
550                 if (unlikely(cop->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) {
551                         void *sess_private_data_t =
552                                 get_sym_session_private_data(cop->sym->session,
553                                                 otx_cryptodev_driver_id);
554                         memset(sess_private_data_t, 0,
555                                         cpt_get_session_size());
556                         memset(cop->sym->session, 0,
557                         rte_cryptodev_sym_get_existing_header_session_size(
558                                         cop->sym->session));
559                         rte_mempool_put(instance->sess_mp_priv,
560                                         sess_private_data_t);
561                         rte_mempool_put(instance->sess_mp, cop->sym->session);
562                         cop->sym->session = NULL;
563                 }
564                 free_op_meta(metabuf, instance->meta_info.pool);
565         }
566
567         return nb_completed;
568 }
569
570 static struct rte_cryptodev_ops cptvf_ops = {
571         /* Device related operations */
572         .dev_configure = otx_cpt_dev_config,
573         .dev_start = otx_cpt_dev_start,
574         .dev_stop = otx_cpt_dev_stop,
575         .dev_close = otx_cpt_dev_close,
576         .dev_infos_get = otx_cpt_dev_info_get,
577
578         .stats_get = otx_cpt_stats_get,
579         .stats_reset = otx_cpt_stats_reset,
580         .queue_pair_setup = otx_cpt_que_pair_setup,
581         .queue_pair_release = otx_cpt_que_pair_release,
582         .queue_pair_count = NULL,
583
584         /* Crypto related operations */
585         .sym_session_get_size = otx_cpt_get_session_size,
586         .sym_session_configure = otx_cpt_session_cfg,
587         .sym_session_clear = otx_cpt_session_clear
588 };
589
590 int
591 otx_cpt_dev_create(struct rte_cryptodev *c_dev)
592 {
593         struct rte_pci_device *pdev = RTE_DEV_TO_PCI(c_dev->device);
594         struct cpt_vf *cptvf = NULL;
595         void *reg_base;
596         char dev_name[32];
597         int ret;
598
599         if (pdev->mem_resource[0].phys_addr == 0ULL)
600                 return -EIO;
601
602         /* for secondary processes, we don't initialise any further as primary
603          * has already done this work.
604          */
605         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
606                 return 0;
607
608         cptvf = rte_zmalloc_socket("otx_cryptodev_private_mem",
609                         sizeof(struct cpt_vf), RTE_CACHE_LINE_SIZE,
610                         rte_socket_id());
611
612         if (cptvf == NULL) {
613                 CPT_LOG_ERR("Cannot allocate memory for device private data");
614                 return -ENOMEM;
615         }
616
617         snprintf(dev_name, 32, "%02x:%02x.%x",
618                         pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
619
620         reg_base = pdev->mem_resource[0].addr;
621         if (!reg_base) {
622                 CPT_LOG_ERR("Failed to map BAR0 of %s", dev_name);
623                 ret = -ENODEV;
624                 goto fail;
625         }
626
627         ret = otx_cpt_hw_init(cptvf, pdev, reg_base, dev_name);
628         if (ret) {
629                 CPT_LOG_ERR("Failed to init cptvf %s", dev_name);
630                 ret = -EIO;
631                 goto fail;
632         }
633
634         switch (cptvf->vftype) {
635         case OTX_CPT_VF_TYPE_AE:
636                 /* Set asymmetric cpt feature flags */
637                 c_dev->feature_flags = RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO |
638                                 RTE_CRYPTODEV_FF_HW_ACCELERATED;
639                 break;
640         case OTX_CPT_VF_TYPE_SE:
641                 /* Set symmetric cpt feature flags */
642                 c_dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
643                                 RTE_CRYPTODEV_FF_HW_ACCELERATED |
644                                 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
645                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
646                                 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
647                                 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT;
648                 break;
649         default:
650                 /* Feature not supported. Abort */
651                 CPT_LOG_ERR("VF type not supported by %s", dev_name);
652                 ret = -EIO;
653                 goto deinit_dev;
654         }
655
656         /* Start off timer for mailbox interrupts */
657         otx_cpt_periodic_alarm_start(cptvf);
658
659         c_dev->dev_ops = &cptvf_ops;
660
661         c_dev->enqueue_burst = otx_cpt_pkt_enqueue;
662         c_dev->dequeue_burst = otx_cpt_pkt_dequeue;
663
664         /* Save dev private data */
665         c_dev->data->dev_private = cptvf;
666
667         return 0;
668
669 deinit_dev:
670         otx_cpt_deinit_device(cptvf);
671
672 fail:
673         if (cptvf) {
674                 /* Free private data allocated */
675                 rte_free(cptvf);
676         }
677
678         return ret;
679 }