DPDK  2.2.0
rte_cryptodev.h
Go to the documentation of this file.
1 /*-
2  *
3  * Copyright(c) 2015 Intel Corporation. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * * Neither the name of Intel Corporation nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _RTE_CRYPTODEV_H_
33 #define _RTE_CRYPTODEV_H_
34 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 #include "stddef.h"
52 
53 #include "rte_crypto.h"
54 #include "rte_dev.h"
55 
56 #define CRYPTODEV_NAME_NULL_PMD ("cryptodev_null_pmd")
57 
58 #define CRYPTODEV_NAME_AESNI_MB_PMD ("cryptodev_aesni_mb_pmd")
59 
60 #define CRYPTODEV_NAME_QAT_PMD ("cryptodev_qat_pmd")
61 
68 };
69 
70 /* Logging Macros */
71 
72 #define CDEV_LOG_ERR(fmt, args...) \
73  RTE_LOG(ERR, CRYPTODEV, "%s() line %u: " fmt "\n", \
74  __func__, __LINE__, ## args)
75 
76 #define CDEV_PMD_LOG_ERR(dev, fmt, args...) \
77  RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
78  dev, __func__, __LINE__, ## args)
79 
80 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
81 #define CDEV_LOG_DEBUG(fmt, args...) \
82  RTE_LOG(DEBUG, CRYPTODEV, "%s() line %u: " fmt "\n", \
83  __func__, __LINE__, ## args) \
84 
85 #define CDEV_PMD_TRACE(fmt, args...) \
86  RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s: " fmt "\n", \
87  dev, __func__, ## args)
88 
89 #else
90 #define CDEV_LOG_DEBUG(fmt, args...)
91 #define CDEV_PMD_TRACE(fmt, args...)
92 #endif
93 
96  const char *driver_name;
100  unsigned max_nb_queue_pairs;
102  unsigned max_nb_sessions;
104 };
105 
106 #define RTE_CRYPTODEV_DETACHED (0)
107 #define RTE_CRYPTODEV_ATTACHED (1)
108 
114 };
115 
118  uint32_t nb_descriptors;
119 };
120 
130 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
131  enum rte_cryptodev_event_type event, void *cb_arg);
132 
133 #ifdef RTE_CRYPTODEV_PERF
134 
138 struct rte_cryptodev_perf_stats {
139  uint64_t t_accumlated;
140  uint64_t t_min;
141  uint64_t t_max;
142 };
143 #endif
144 
147  uint64_t enqueued_count;
149  uint64_t dequeued_count;
152  uint64_t enqueue_err_count;
154  uint64_t dequeue_err_count;
157 #ifdef RTE_CRYPTODEV_DETAILED_STATS
158  struct {
159  uint64_t encrypt_ops;
160  uint64_t encrypt_bytes;
162  uint64_t decrypt_ops;
163  uint64_t decrypt_bytes;
164  } cipher;
166  struct {
167  uint64_t generate_ops;
168  uint64_t bytes_hashed;
170  uint64_t verify_ops;
171  uint64_t bytes_verified;
172  } hash;
173 #endif
174 
175 #ifdef RTE_CRYPTODEV_PERF
176  struct rte_cryptodev_perf_stats op_perf;
177 #endif
179 
191 extern int
192 rte_cryptodev_create_vdev(const char *name, const char *args);
193 
203 extern int
204 rte_cryptodev_get_dev_id(const char *name);
205 
213 extern uint8_t
214 rte_cryptodev_count(void);
215 
216 extern uint8_t
217 rte_cryptodev_count_devtype(enum rte_cryptodev_type type);
218 /*
219  * Return the NUMA socket to which a device is connected
220  *
221  * @param dev_id
222  * The identifier of the device
223  * @return
224  * The NUMA socket id to which the device is connected or
225  * a default of zero if the socket could not be determined.
226  * -1 if returned is the dev_id value is out of range.
227  */
228 extern int
229 rte_cryptodev_socket_id(uint8_t dev_id);
230 
233  int socket_id;
234  uint16_t nb_queue_pairs;
237  struct {
238  uint32_t nb_objs;
239  uint32_t cache_size;
240  } session_mp;
241 };
242 
259 extern int
260 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
261 
277 extern int
278 rte_cryptodev_start(uint8_t dev_id);
279 
286 extern void
287 rte_cryptodev_stop(uint8_t dev_id);
288 
298 extern int
299 rte_cryptodev_close(uint8_t dev_id);
300 
324 extern int
325 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
326  const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
327 
342 extern int
343 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
344 
358 extern int
359 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
360 
368 extern uint16_t
369 rte_cryptodev_queue_pair_count(uint8_t dev_id);
370 
371 
383 extern int
384 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
385 
391 extern void
392 rte_cryptodev_stats_reset(uint8_t dev_id);
393 
402 extern void
403 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
404 
405 
419 extern int
420 rte_cryptodev_callback_register(uint8_t dev_id,
421  enum rte_cryptodev_event_type event,
422  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
423 
437 extern int
438 rte_cryptodev_callback_unregister(uint8_t dev_id,
439  enum rte_cryptodev_event_type event,
440  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
441 
442 
443 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp, struct rte_mbuf **pkts,
444  uint16_t nb_pkts);
447 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp, struct rte_mbuf **pkts,
448  uint16_t nb_pkts);
452 struct rte_cryptodev_callback;
453 
455 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
456 
478  struct rte_cryptodev_cb_list link_intr_cbs;
481  uint8_t attached : 1;
484 
485 
486 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
487 
497  uint8_t dev_id;
499  uint8_t socket_id;
504  uint8_t dev_started : 1;
509  void **queue_pairs;
511  uint16_t nb_queue_pairs;
514  void *dev_private;
517 
518 extern struct rte_cryptodev *rte_cryptodevs;
554 static inline uint16_t
555 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
556  struct rte_mbuf **pkts, uint16_t nb_pkts)
557 {
558  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
559 
560  nb_pkts = (*dev->dequeue_burst)
561  (dev->data->queue_pairs[qp_id], pkts, nb_pkts);
562 
563  return nb_pkts;
564 }
565 
599 static inline uint16_t
600 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
601  struct rte_mbuf **pkts, uint16_t nb_pkts)
602 {
603  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
604 
605  return (*dev->enqueue_burst)(
606  dev->data->queue_pairs[qp_id], pkts, nb_pkts);
607 }
608 
609 
631 extern struct rte_cryptodev_session *
632 rte_cryptodev_session_create(uint8_t dev_id,
633  struct rte_crypto_xform *xform);
634 
635 
647 extern struct rte_cryptodev_session *
648 rte_cryptodev_session_free(uint8_t dev_id,
649  struct rte_cryptodev_session *session);
650 
651 
652 #ifdef __cplusplus
653 }
654 #endif
655 
656 #endif /* _RTE_CRYPTODEV_H_ */