diff mbox

[dpdk-dev,v1,3/7] compress/octeontx: add xform and stream create support

Message ID 1528194913-25893-4-git-send-email-shally.verma@caviumnetworks.com (mailing list archive)
State Changes Requested, archived
Delegated to: Pablo de Lara Guarch
Headers show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Shally Verma June 5, 2018, 10:35 a.m. UTC
implement private xform and stream create ops

Signed-off-by: Ashish Gupta <ashish.gupta@caviumnetworks.com>
Signed-off-by: Shally Verma <shally.verma@caviumnetworks.com>
Signed-off-by: Sunila Sahu <sunila.sahu@caviumnetworks.com>
---
 drivers/compress/octeontx/zip_pmd.c | 138 ++++++++++++++++++++++++++++++++++++
 drivers/compress/octeontx/zipvf.h   |  29 ++++++++
 2 files changed, 167 insertions(+)

Comments

Pablo de Lara June 19, 2018, 10:13 p.m. UTC | #1
> -----Original Message-----
> From: Shally Verma [mailto:shally.verma@caviumnetworks.com]
> Sent: Tuesday, June 5, 2018 11:35 AM
> To: De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
> Cc: Trahe, Fiona <fiona.trahe@intel.com>; dev@dpdk.org;
> pathreya@caviumnetworks.com; mchalla@caviumnetworks.com; Ashish Gupta
> <ashish.gupta@caviumnetworks.com>; Sunila Sahu
> <sunila.sahu@caviumnetworks.com>
> Subject: [PATCH v1 3/7] compress/octeontx: add xform and stream create
> support
> 
> implement private xform and stream create ops
> 
> Signed-off-by: Ashish Gupta <ashish.gupta@caviumnetworks.com>
> Signed-off-by: Shally Verma <shally.verma@caviumnetworks.com>
> Signed-off-by: Sunila Sahu <sunila.sahu@caviumnetworks.com>
> ---
>  drivers/compress/octeontx/zip_pmd.c | 138
> ++++++++++++++++++++++++++++++++++++
>  drivers/compress/octeontx/zipvf.h   |  29 ++++++++
>  2 files changed, 167 insertions(+)
> 
> diff --git a/drivers/compress/octeontx/zip_pmd.c
> b/drivers/compress/octeontx/zip_pmd.c
> index 3bb7f6896..349114626 100644
> --- a/drivers/compress/octeontx/zip_pmd.c
> +++ b/drivers/compress/octeontx/zip_pmd.c

...

> +static int
> +zip_pmd_stream_create(struct rte_compressdev *dev,
> +		const struct rte_comp_xform *xform, void **stream) {
> +	int ret;
> +	struct zip_stream *strm;
> +
> +	strm = rte_malloc(NULL,
> +			sizeof(struct zip_stream), 0);

Should not this come from a mempool, as there is an option
in the configuration for max number of sessions.


> +	ret = zip_set_stream_parameters(dev, xform, strm);
> +	if (ret < 0) {
> +		ZIP_PMD_ERR("failed configure xform parameters");
> +		rte_free(strm);
> +		return ret;
> +	}
> +	*stream = strm;		
> +	return 0;
> +}
> +
> +static int
> +zip_pmd_stream_free(struct rte_compressdev *dev, void *stream) {
> +	struct zip_vf *vf = (struct zip_vf *) (dev->data->dev_private);
> +	struct zip_stream *z_stream;
> +
> +	if (stream == NULL)
> +		return -1;
> +
> +	z_stream = (struct zip_stream *)stream;
> +	rte_mempool_put_bulk(vf->zip_mp,
> +			     (void *)&(z_stream->bufs[0]),
> +			     MAX_BUFS_PER_STREAM);
> +
> +	/* Zero out the whole structure */
> +	memset(stream, 0, sizeof(struct zip_stream));
> +	rte_free(stream);

I was expecting this stream to be put back into a mempool,
but anyway, there is no need to reset this structure if you are freeing the memory then.
Verma, Shally June 20, 2018, 6:12 a.m. UTC | #2
>-----Original Message-----
>From: De Lara Guarch, Pablo [mailto:pablo.de.lara.guarch@intel.com]
>Sent: 20 June 2018 03:43
>To: Verma, Shally <Shally.Verma@cavium.com>
>Cc: Trahe, Fiona <fiona.trahe@intel.com>; dev@dpdk.org; Athreya, Narayana Prasad <NarayanaPrasad.Athreya@cavium.com>;
>Challa, Mahipal <Mahipal.Challa@cavium.com>; Gupta, Ashish <Ashish.Gupta@cavium.com>; Sahu, Sunila
><Sunila.Sahu@cavium.com>
>Subject: RE: [PATCH v1 3/7] compress/octeontx: add xform and stream create support
>
>External Email
>
>> -----Original Message-----
>> From: Shally Verma [mailto:shally.verma@caviumnetworks.com]
>> Sent: Tuesday, June 5, 2018 11:35 AM
>> To: De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
>> Cc: Trahe, Fiona <fiona.trahe@intel.com>; dev@dpdk.org;
>> pathreya@caviumnetworks.com; mchalla@caviumnetworks.com; Ashish Gupta
>> <ashish.gupta@caviumnetworks.com>; Sunila Sahu
>> <sunila.sahu@caviumnetworks.com>
>> Subject: [PATCH v1 3/7] compress/octeontx: add xform and stream create
>> support
>>
>> implement private xform and stream create ops
>>
>> Signed-off-by: Ashish Gupta <ashish.gupta@caviumnetworks.com>
>> Signed-off-by: Shally Verma <shally.verma@caviumnetworks.com>
>> Signed-off-by: Sunila Sahu <sunila.sahu@caviumnetworks.com>
>> ---
>>  drivers/compress/octeontx/zip_pmd.c | 138
>> ++++++++++++++++++++++++++++++++++++
>>  drivers/compress/octeontx/zipvf.h   |  29 ++++++++
>>  2 files changed, 167 insertions(+)
>>
>> diff --git a/drivers/compress/octeontx/zip_pmd.c
>> b/drivers/compress/octeontx/zip_pmd.c
>> index 3bb7f6896..349114626 100644
>> --- a/drivers/compress/octeontx/zip_pmd.c
>> +++ b/drivers/compress/octeontx/zip_pmd.c
>
>...
>
>> +static int
>> +zip_pmd_stream_create(struct rte_compressdev *dev,
>> +             const struct rte_comp_xform *xform, void **stream) {
>> +     int ret;
>> +     struct zip_stream *strm;
>> +
>> +     strm = rte_malloc(NULL,
>> +                     sizeof(struct zip_stream), 0);
>
>Should not this come from a mempool, as there is an option
>in the configuration for max number of sessions.
>
[Shally] We're using mempool for per-stream resources but not specifically for stream struct itself.
We, though, had thought about approach too but it turns out to be more feasible to keep it this way for now.
>
>> +     ret = zip_set_stream_parameters(dev, xform, strm);
>> +     if (ret < 0) {
>> +             ZIP_PMD_ERR("failed configure xform parameters");
>> +             rte_free(strm);
>> +             return ret;
>> +     }
>> +     *stream = strm;
>> +     return 0;
>> +}
>> +
>> +static int
>> +zip_pmd_stream_free(struct rte_compressdev *dev, void *stream) {
>> +     struct zip_vf *vf = (struct zip_vf *) (dev->data->dev_private);
>> +     struct zip_stream *z_stream;
>> +
>> +     if (stream == NULL)
>> +             return -1;
>> +
>> +     z_stream = (struct zip_stream *)stream;
>> +     rte_mempool_put_bulk(vf->zip_mp,
>> +                          (void *)&(z_stream->bufs[0]),
>> +                          MAX_BUFS_PER_STREAM);
>> +
>> +     /* Zero out the whole structure */
>> +     memset(stream, 0, sizeof(struct zip_stream));
>> +     rte_free(stream);
>
>I was expecting this stream to be put back into a mempool,
>but anyway, there is no need to reset this structure if you are freeing the memory then.
>
Thanks for review.
Shally
diff mbox

Patch

diff --git a/drivers/compress/octeontx/zip_pmd.c b/drivers/compress/octeontx/zip_pmd.c
index 3bb7f6896..349114626 100644
--- a/drivers/compress/octeontx/zip_pmd.c
+++ b/drivers/compress/octeontx/zip_pmd.c
@@ -30,6 +30,104 @@  static const struct rte_compressdev_capabilities
 	RTE_COMP_END_OF_CAPABILITIES_LIST()
 };
 
+/** Parse xform parameters and setup a stream */
+int
+zip_set_stream_parameters(struct rte_compressdev *dev,
+			const struct rte_comp_xform *xform,
+			struct zip_stream *z_stream)
+{
+	int ret;
+	union zip_inst_s *inst;
+	struct zip_vf *vf = (struct zip_vf *)dev->data->dev_private;
+	void *res;
+
+	ret = rte_mempool_get_bulk(vf->zip_mp,
+			z_stream->bufs, MAX_BUFS_PER_STREAM);
+	if (ret < 0)
+		return -1;
+
+	inst = (union zip_inst_s *)z_stream->bufs[CMD_BUF];
+	res = z_stream->bufs[RES_BUF];
+
+	/* get one command buffer from pool and set up */
+
+	memset(inst->u, 0, sizeof(inst->u));
+
+	/* set bf for only first ops of stream */
+	inst->s.bf = 1;
+
+	if (xform->type == RTE_COMP_COMPRESS) {
+		inst->s.op = ZIP_OP_E_COMP;
+
+		switch (xform->compress.deflate.huffman) {
+		case RTE_COMP_HUFFMAN_DEFAULT:
+			inst->s.cc = ZIP_CC_DEFAULT;
+			break;
+		case RTE_COMP_HUFFMAN_FIXED:
+			inst->s.cc = ZIP_CC_FIXED_HUFF;
+			break;
+		case RTE_COMP_HUFFMAN_DYNAMIC:
+			inst->s.cc = ZIP_CC_DYN_HUFF;
+			break;
+		default:
+			ret = -1;
+			goto err;
+		}
+
+		switch (xform->compress.level) {
+		case RTE_COMP_LEVEL_MIN:
+			inst->s.ss = ZIP_COMP_E_LEVEL_MIN;
+			break;
+		case RTE_COMP_LEVEL_MAX:
+			inst->s.ss = ZIP_COMP_E_LEVEL_MAX;
+			break;
+		case RTE_COMP_LEVEL_NONE:
+			ZIP_PMD_ERR("Compression level not supported");
+			ret = -1;
+			goto err;
+		default:
+			/* for any value between min and max , choose
+			 * PMD default.
+			 */
+			inst->s.ss = ZIP_COMP_E_LEVEL_MED; /** PMD default **/
+			break;
+		}
+	} else if (xform->type == RTE_COMP_DECOMPRESS) {
+		inst->s.op = ZIP_OP_E_DECOMP;
+		/* from HRM,
+		 * For DEFLATE decompression, [CC] must be 0x0.
+		 * For decompression, [SS] must be 0x0
+		 */
+		inst->s.cc = 0;
+		/* Speed bit should not be set for decompression */
+		inst->s.ss = 0;
+		/* decompression context is supported only for STATEFUL
+		 * operations. Currently we support STATELESS ONLY so
+		 * skip setting of ctx pointer
+		 */
+
+	} else {
+		ZIP_PMD_ERR("\nxform type not supported");
+		ret = -1;
+		goto err;
+	}
+
+	inst->s.res_ptr_addr.s.addr = rte_mempool_virt2iova(res);
+	inst->s.res_ptr_ctl.s.length = 0;
+
+	z_stream->inst = inst;
+	z_stream->func = zip_process_op;
+
+	return 0;
+
+err:
+	rte_mempool_put_bulk(vf->zip_mp,
+			     (void *)&(z_stream->bufs[0]),
+			     MAX_BUFS_PER_STREAM);
+
+	return ret;
+}
+
 /** Configure device */
 static int
 zip_pmd_config(struct rte_compressdev *dev,
@@ -261,6 +359,46 @@  zip_pmd_qp_setup(struct rte_compressdev *dev, uint16_t qp_id,
 	return -1;
 }
 
+static int
+zip_pmd_stream_create(struct rte_compressdev *dev,
+		const struct rte_comp_xform *xform, void **stream)
+{
+	int ret;
+	struct zip_stream *strm;
+
+	strm = rte_malloc(NULL,
+			sizeof(struct zip_stream), 0);
+	ret = zip_set_stream_parameters(dev, xform, strm);
+	if (ret < 0) {
+		ZIP_PMD_ERR("failed configure xform parameters");
+		rte_free(strm);
+		return ret;
+	}
+	*stream = strm;
+	return 0;
+}
+
+static int
+zip_pmd_stream_free(struct rte_compressdev *dev, void *stream)
+{
+	struct zip_vf *vf = (struct zip_vf *) (dev->data->dev_private);
+	struct zip_stream *z_stream;
+
+	if (stream == NULL)
+		return -1;
+
+	z_stream = (struct zip_stream *)stream;
+	rte_mempool_put_bulk(vf->zip_mp,
+			     (void *)&(z_stream->bufs[0]),
+			     MAX_BUFS_PER_STREAM);
+
+	/* Zero out the whole structure */
+	memset(stream, 0, sizeof(struct zip_stream));
+	rte_free(stream);
+
+	return 0;
+}
+
 struct rte_compressdev_ops octtx_zip_pmd_ops = {
 		.dev_configure		= zip_pmd_config,
 		.dev_start		= zip_pmd_start,
diff --git a/drivers/compress/octeontx/zipvf.h b/drivers/compress/octeontx/zipvf.h
index 9582d6119..2388e2947 100644
--- a/drivers/compress/octeontx/zipvf.h
+++ b/drivers/compress/octeontx/zipvf.h
@@ -77,6 +77,25 @@  int octtx_zip_logtype_driver;
 #define ZIP_PMD_WARN(fmt, args...) \
 	ZIP_PMD_LOG(WARNING, fmt, ## args)
 
+/* resources required to process stream */
+enum {
+	RES_BUF = 0,
+	CMD_BUF,
+	HASH_CTX_BUF,
+	DECOMP_CTX_BUF,
+	IN_DATA_BUF,
+	OUT_DATA_BUF,
+	HISTORY_DATA_BUF,
+	MAX_BUFS_PER_STREAM
+} NUM_BUFS_PER_STREAM;
+
+struct zip_stream;
+struct zipvf_qp;
+
+/* Algorithm handler function prototype */
+typedef int (*comp_func_t)(struct rte_comp_op *op,
+			   struct zipvf_qp *qp, struct zip_stream *zstrm);
+
 struct zip_pmd_private {
 	struct zip_vf *zipvf_table[ZIP_MAX_VFS];
 	/**< ZIP Devices List */
@@ -84,6 +103,16 @@  struct zip_pmd_private {
 	/**< Number of ZIP VFs attached to a Guest */
 };
 
+/** ZIP private stream structure */
+struct zip_stream {
+	union zip_inst_s *inst;
+	/**< zip instruction pointer */
+	comp_func_t func;
+	/**< function to process comp operation */
+	void *bufs[MAX_BUFS_PER_STREAM];
+} _rte_cache_aligned;
+
+
 /**
  * ZIP instruction Queue
  */