+
+/**
+ * Reset stream state for the next use.
+ *
+ * @param stream
+ * handle of pmd's private stream data
+ */
+static void
+qat_comp_stream_reset(struct qat_comp_stream *stream)
+{
+ if (stream) {
+ memset(&stream->qat_xform, 0, sizeof(struct qat_comp_xform));
+ stream->start_of_packet = 1;
+ stream->op_in_progress = 0;
+ }
+}
+
+/**
+ * Create driver private stream data.
+ *
+ * @param dev
+ * Compressdev device
+ * @param xform
+ * xform data
+ * @param stream
+ * ptr where handle of pmd's private stream data should be stored
+ * @return
+ * - Returns 0 if private stream structure has been created successfully.
+ * - Returns -EINVAL if input parameters are invalid.
+ * - Returns -ENOTSUP if comp device does not support STATEFUL operations.
+ * - Returns -ENOTSUP if comp device does not support the comp transform.
+ * - Returns -ENOMEM if the private stream could not be allocated.
+ */
+int
+qat_comp_stream_create(struct rte_compressdev *dev,
+ const struct rte_comp_xform *xform,
+ void **stream)
+{
+ struct qat_comp_dev_private *qat = dev->data->dev_private;
+ struct qat_comp_stream *ptr;
+
+ if (unlikely(stream == NULL)) {
+ QAT_LOG(ERR, "QAT: stream parameter is NULL");
+ return -EINVAL;
+ }
+ if (unlikely(xform->type == RTE_COMP_COMPRESS)) {
+ QAT_LOG(ERR, "QAT: stateful compression not supported");
+ return -ENOTSUP;
+ }
+ if (unlikely(qat->streampool == NULL)) {
+ QAT_LOG(ERR, "QAT device has no stream mempool");
+ return -ENOMEM;
+ }
+ if (rte_mempool_get(qat->streampool, stream)) {
+ QAT_LOG(ERR, "Couldn't get object from qat stream mempool");
+ return -ENOMEM;
+ }
+
+ ptr = (struct qat_comp_stream *) *stream;
+ qat_comp_stream_reset(ptr);
+ ptr->qat_xform.qat_comp_request_type = QAT_COMP_REQUEST_DECOMPRESS;
+ ptr->qat_xform.checksum_type = xform->decompress.chksum;
+
+ if (qat_comp_create_templates(&ptr->qat_xform, qat->interm_buff_mz,
+ xform, ptr, RTE_COMP_OP_STATEFUL)) {
+ QAT_LOG(ERR, "QAT: problem with creating descriptor template for stream");
+ rte_mempool_put(qat->streampool, *stream);
+ *stream = NULL;
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+/**
+ * Free driver private stream data.
+ *
+ * @param dev
+ * Compressdev device
+ * @param stream
+ * handle of pmd's private stream data
+ * @return
+ * - 0 if successful
+ * - <0 in error cases
+ * - Returns -EINVAL if input parameters are invalid.
+ * - Returns -ENOTSUP if comp device does not support STATEFUL operations.
+ * - Returns -EBUSY if can't free stream as there are inflight operations
+ */
+int
+qat_comp_stream_free(struct rte_compressdev *dev, void *stream)
+{
+ if (stream) {
+ struct qat_comp_dev_private *qat = dev->data->dev_private;
+ qat_comp_stream_reset((struct qat_comp_stream *) stream);
+ rte_mempool_put(qat->streampool, stream);
+ return 0;
+ }
+ return -EINVAL;
+}