crypto/virtio: support HMAC-SHA1
[dpdk.git] / drivers / crypto / virtio / virtio_cryptodev.c
index 596a237..df88953 100644 (file)
@@ -15,6 +15,7 @@
 #include "virtio_cryptodev.h"
 #include "virtqueue.h"
 #include "virtio_crypto_algs.h"
+#include "virtio_crypto_capabilities.h"
 
 int virtio_crypto_logtype_init;
 int virtio_crypto_logtype_session;
@@ -29,6 +30,9 @@ static void virtio_crypto_dev_stop(struct rte_cryptodev *dev);
 static int virtio_crypto_dev_close(struct rte_cryptodev *dev);
 static void virtio_crypto_dev_info_get(struct rte_cryptodev *dev,
                struct rte_cryptodev_info *dev_info);
+static void virtio_crypto_dev_stats_get(struct rte_cryptodev *dev,
+               struct rte_cryptodev_stats *stats);
+static void virtio_crypto_dev_stats_reset(struct rte_cryptodev *dev);
 static int virtio_crypto_qp_setup(struct rte_cryptodev *dev,
                uint16_t queue_pair_id,
                const struct rte_cryptodev_qp_conf *qp_conf,
@@ -55,6 +59,11 @@ static const struct rte_pci_id pci_id_virtio_crypto_map[] = {
        { .vendor_id = 0, /* sentinel */ },
 };
 
+static const struct rte_cryptodev_capabilities virtio_capabilities[] = {
+       VIRTIO_SYM_CAPABILITIES,
+       RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
+};
+
 uint8_t cryptodev_virtio_driver_id;
 
 #define NUM_ENTRY_SYM_CREATE_SESSION 4
@@ -501,8 +510,8 @@ static struct rte_cryptodev_ops virtio_crypto_dev_ops = {
        .dev_close                       = virtio_crypto_dev_close,
        .dev_infos_get                   = virtio_crypto_dev_info_get,
 
-       .stats_get                       = NULL,
-       .stats_reset                     = NULL,
+       .stats_get                       = virtio_crypto_dev_stats_get,
+       .stats_reset                     = virtio_crypto_dev_stats_reset,
 
        .queue_pair_setup                = virtio_crypto_qp_setup,
        .queue_pair_release              = virtio_crypto_qp_release,
@@ -518,6 +527,65 @@ static struct rte_cryptodev_ops virtio_crypto_dev_ops = {
        .qp_detach_session = NULL
 };
 
+static void
+virtio_crypto_update_stats(struct rte_cryptodev *dev,
+               struct rte_cryptodev_stats *stats)
+{
+       unsigned int i;
+       struct virtio_crypto_hw *hw = dev->data->dev_private;
+
+       PMD_INIT_FUNC_TRACE();
+
+       if (stats == NULL) {
+               VIRTIO_CRYPTO_DRV_LOG_ERR("invalid pointer");
+               return;
+       }
+
+       for (i = 0; i < hw->max_dataqueues; i++) {
+               const struct virtqueue *data_queue
+                       = dev->data->queue_pairs[i];
+               if (data_queue == NULL)
+                       continue;
+
+               stats->enqueued_count += data_queue->packets_sent_total;
+               stats->enqueue_err_count += data_queue->packets_sent_failed;
+
+               stats->dequeued_count += data_queue->packets_received_total;
+               stats->dequeue_err_count
+                       += data_queue->packets_received_failed;
+       }
+}
+
+static void
+virtio_crypto_dev_stats_get(struct rte_cryptodev *dev,
+               struct rte_cryptodev_stats *stats)
+{
+       PMD_INIT_FUNC_TRACE();
+
+       virtio_crypto_update_stats(dev, stats);
+}
+
+static void
+virtio_crypto_dev_stats_reset(struct rte_cryptodev *dev)
+{
+       unsigned int i;
+       struct virtio_crypto_hw *hw = dev->data->dev_private;
+
+       PMD_INIT_FUNC_TRACE();
+
+       for (i = 0; i < hw->max_dataqueues; i++) {
+               struct virtqueue *data_queue = dev->data->queue_pairs[i];
+               if (data_queue == NULL)
+                       continue;
+
+               data_queue->packets_sent_total = 0;
+               data_queue->packets_sent_failed = 0;
+
+               data_queue->packets_received_total = 0;
+               data_queue->packets_received_failed = 0;
+       }
+}
+
 static int
 virtio_crypto_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
                const struct rte_cryptodev_qp_conf *qp_conf,
@@ -684,6 +752,7 @@ crypto_virtio_create(const char *name, struct rte_pci_device *pci_dev,
 
        hw = cryptodev->data->dev_private;
        hw->dev_id = cryptodev->data->dev_id;
+       hw->virtio_dev_capabilities = virtio_capabilities;
 
        VIRTIO_CRYPTO_INIT_LOG_DBG("dev %d vendorID=0x%x deviceID=0x%x",
                cryptodev->data->dev_id, pci_dev->id.vendor_id,
@@ -1077,6 +1146,9 @@ virtio_crypto_sym_pad_cipher_param(
                struct rte_crypto_cipher_xform *cipher_xform)
 {
        switch (cipher_xform->algo) {
+       case RTE_CRYPTO_CIPHER_AES_CBC:
+               para->algo = VIRTIO_CRYPTO_CIPHER_AES_CBC;
+               break;
        default:
                VIRTIO_CRYPTO_SESSION_LOG_ERR("Crypto: Unsupported "
                                "Cipher alg %u", cipher_xform->algo);
@@ -1124,11 +1196,13 @@ virtio_crypto_sym_pad_auth_param(
        }
 
        switch (auth_xform->algo) {
+       case RTE_CRYPTO_AUTH_SHA1_HMAC:
+               *algo = VIRTIO_CRYPTO_MAC_HMAC_SHA1;
+               break;
        default:
                VIRTIO_CRYPTO_SESSION_LOG_ERR(
                        "Crypto: Undefined Hash algo %u specified",
                        auth_xform->algo);
-               *algo = VIRTIO_CRYPTO_NO_MAC;
                return -1;
        }
 
@@ -1340,6 +1414,7 @@ virtio_crypto_dev_info_get(struct rte_cryptodev *dev,
                info->max_nb_queue_pairs = hw->max_dataqueues;
                info->sym.max_nb_sessions =
                        RTE_VIRTIO_CRYPTO_PMD_MAX_NB_SESSIONS;
+               info->capabilities = hw->virtio_dev_capabilities;
        }
 }