All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
To: Jeffrey Hugo <quic_jhugo@quicinc.com>
Cc: ogabbay@kernel.org, airlied@gmail.com, daniel@ffwll.ch,
	dri-devel@lists.freedesktop.org,
	jacek.lawrynowicz@linux.intel.com, quic_pkanojiy@quicinc.com,
	quic_carlv@quicinc.com, quic_ajitpals@quicinc.com,
	linux-doc@vger.kernel.org, linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH v2 5/8] accel/qaic: Add datapath
Date: Fri, 24 Feb 2023 16:25:46 +0100	[thread overview]
Message-ID: <20230224152546.GB3547587@linux.intel.com> (raw)
In-Reply-To: <1675698105-19025-6-git-send-email-quic_jhugo@quicinc.com>

On Mon, Feb 06, 2023 at 08:41:42AM -0700, Jeffrey Hugo wrote:
> +#define SEM_VAL_MASK	GENMASK_ULL(11, 0)
> +#define SEM_INDEX_MASK	GENMASK_ULL(4, 0)
> +#define BULK_XFER	BIT(3)
> +#define GEN_COMPLETION	BIT(4)
> +#define INBOUND_XFER	1
> +#define OUTBOUND_XFER	2
> +#define REQHP_OFF	0x0 /* we read this */
> +#define REQTP_OFF	0x4 /* we write this */
> +#define RSPHP_OFF	0x8 /* we write this */
> +#define RSPTP_OFF	0xc /* we read this */
> +
> +#define ENCODE_SEM(val, index, sync, cmd, flags)			\
> +			((val) |					\
> +			(index) << 16 |					\
> +			(sync) << 22 |					\
> +			(cmd) << 24 |					\
> +			((cmd) ? BIT(31) : 0) |				\
> +			(((flags) & SEM_INSYNCFENCE) ? BIT(30) : 0) |	\
> +			(((flags) & SEM_OUTSYNCFENCE) ? BIT(29) : 0))

This could be probably better coded using FIELD_PREP()
with integrated checks of passed values not exceed
field width.

> +struct dbc_req { /* everything must be little endian encoded */

This comment does not provide much value IMHO ...

> +inline int get_dbc_req_elem_size(void)
> +{
> +	return sizeof(struct dbc_req);
> +}
> +
> +inline int get_dbc_rsp_elem_size(void)
> +{
> +	return sizeof(struct dbc_rsp);
> +}

.. as those those inliners, instead of using sizeof() directly.
Up to you to change.

> +static int reserve_pages(unsigned long start_pfn, unsigned long nr_pages,
> +			 bool reserve)
> +{
> +	unsigned long pfn;
> +	unsigned long end_pfn = start_pfn + nr_pages;
> +	struct page *page;
> +
> +	for (pfn = start_pfn; pfn < end_pfn; pfn++) {
> +		if (!pfn_valid(pfn))
> +			return -EINVAL;
> +		page =  pfn_to_page(pfn);
> +		if (reserve)
> +			SetPageReserved(page);
> +		else
> +			ClearPageReserved(page);

It is needed? Looks like taken from some legacy code.

> +static int copy_sgt(struct qaic_device *qdev, struct sg_table **sgt_out,
> +		    struct sg_table *sgt_in, u64 size, u64 offset)
> +{
> +	int total_len, len, nents, offf = 0, offl = 0;
> +	struct scatterlist *sg, *sgn, *sgf, *sgl;
> +	struct sg_table *sgt;
> +	int ret, j;
> +
> +	/* find out number of relevant nents needed for this mem */
> +	total_len = 0;
> +	sgf = NULL;
> +	sgl = NULL;
> +	nents = 0;
> +
> +	size = size ? size : PAGE_SIZE;
> +	for (sg = sgt_in->sgl; sg; sg = sg_next(sg)) {
> +		len = sg_dma_len(sg);
> +
> +		if (!len)
> +			continue;
> +		if (offset >= total_len && offset < total_len + len) {
> +			sgf = sg;
> +			offf = offset - total_len;
> +		}
> +		if (sgf)
> +			nents++;
> +		if (offset + size >= total_len &&
> +		    offset + size <= total_len + len) {
> +			sgl = sg;
> +			offl = offset + size - total_len;
> +			break;
> +		}
> +		total_len += len;
> +	}
> +
> +	if (!sgf || !sgl) {
> +		ret = -EINVAL;
> +		goto out;
> +	}
> +
> +	sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
> +	if (!sgt) {
> +		ret = -ENOMEM;
> +		goto out;
> +	}
> +
> +	ret = sg_alloc_table(sgt, nents, GFP_KERNEL);
> +	if (ret)
> +		goto free_sgt;
> +
> +	/* copy relevant sg node and fix page and length */
> +	sgn = sgf;
> +	for_each_sgtable_sg(sgt, sg, j) {
> +		memcpy(sg, sgn, sizeof(*sg));
> +		if (sgn == sgf) {
> +			sg_dma_address(sg) += offf;
> +			sg_dma_len(sg) -= offf;
> +			sg_set_page(sg, sg_page(sgn),
> +				    sg_dma_len(sg), offf);
> +		} else {
> +			offf = 0;
> +		}
> +		if (sgn == sgl) {
> +			sg_dma_len(sg) = offl - offf;
> +			sg_set_page(sg, sg_page(sgn),
> +				    offl - offf, offf);
> +			sg_mark_end(sg);
> +			break;
> +		}
> +		sgn = sg_next(sgn);
> +	}

Why not use sg_copy_table() ? Overall copy_sgt() seems to be something
that could be replaced by generic helper or at least simplify.

Regards
Stanislaw


WARNING: multiple messages have this Message-ID (diff)
From: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
To: Jeffrey Hugo <quic_jhugo@quicinc.com>
Cc: linux-doc@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	ogabbay@kernel.org, dri-devel@lists.freedesktop.org,
	quic_ajitpals@quicinc.com, quic_pkanojiy@quicinc.com,
	quic_carlv@quicinc.com, jacek.lawrynowicz@linux.intel.com
Subject: Re: [PATCH v2 5/8] accel/qaic: Add datapath
Date: Fri, 24 Feb 2023 16:25:46 +0100	[thread overview]
Message-ID: <20230224152546.GB3547587@linux.intel.com> (raw)
In-Reply-To: <1675698105-19025-6-git-send-email-quic_jhugo@quicinc.com>

On Mon, Feb 06, 2023 at 08:41:42AM -0700, Jeffrey Hugo wrote:
> +#define SEM_VAL_MASK	GENMASK_ULL(11, 0)
> +#define SEM_INDEX_MASK	GENMASK_ULL(4, 0)
> +#define BULK_XFER	BIT(3)
> +#define GEN_COMPLETION	BIT(4)
> +#define INBOUND_XFER	1
> +#define OUTBOUND_XFER	2
> +#define REQHP_OFF	0x0 /* we read this */
> +#define REQTP_OFF	0x4 /* we write this */
> +#define RSPHP_OFF	0x8 /* we write this */
> +#define RSPTP_OFF	0xc /* we read this */
> +
> +#define ENCODE_SEM(val, index, sync, cmd, flags)			\
> +			((val) |					\
> +			(index) << 16 |					\
> +			(sync) << 22 |					\
> +			(cmd) << 24 |					\
> +			((cmd) ? BIT(31) : 0) |				\
> +			(((flags) & SEM_INSYNCFENCE) ? BIT(30) : 0) |	\
> +			(((flags) & SEM_OUTSYNCFENCE) ? BIT(29) : 0))

This could be probably better coded using FIELD_PREP()
with integrated checks of passed values not exceed
field width.

> +struct dbc_req { /* everything must be little endian encoded */

This comment does not provide much value IMHO ...

> +inline int get_dbc_req_elem_size(void)
> +{
> +	return sizeof(struct dbc_req);
> +}
> +
> +inline int get_dbc_rsp_elem_size(void)
> +{
> +	return sizeof(struct dbc_rsp);
> +}

.. as those those inliners, instead of using sizeof() directly.
Up to you to change.

> +static int reserve_pages(unsigned long start_pfn, unsigned long nr_pages,
> +			 bool reserve)
> +{
> +	unsigned long pfn;
> +	unsigned long end_pfn = start_pfn + nr_pages;
> +	struct page *page;
> +
> +	for (pfn = start_pfn; pfn < end_pfn; pfn++) {
> +		if (!pfn_valid(pfn))
> +			return -EINVAL;
> +		page =  pfn_to_page(pfn);
> +		if (reserve)
> +			SetPageReserved(page);
> +		else
> +			ClearPageReserved(page);

It is needed? Looks like taken from some legacy code.

> +static int copy_sgt(struct qaic_device *qdev, struct sg_table **sgt_out,
> +		    struct sg_table *sgt_in, u64 size, u64 offset)
> +{
> +	int total_len, len, nents, offf = 0, offl = 0;
> +	struct scatterlist *sg, *sgn, *sgf, *sgl;
> +	struct sg_table *sgt;
> +	int ret, j;
> +
> +	/* find out number of relevant nents needed for this mem */
> +	total_len = 0;
> +	sgf = NULL;
> +	sgl = NULL;
> +	nents = 0;
> +
> +	size = size ? size : PAGE_SIZE;
> +	for (sg = sgt_in->sgl; sg; sg = sg_next(sg)) {
> +		len = sg_dma_len(sg);
> +
> +		if (!len)
> +			continue;
> +		if (offset >= total_len && offset < total_len + len) {
> +			sgf = sg;
> +			offf = offset - total_len;
> +		}
> +		if (sgf)
> +			nents++;
> +		if (offset + size >= total_len &&
> +		    offset + size <= total_len + len) {
> +			sgl = sg;
> +			offl = offset + size - total_len;
> +			break;
> +		}
> +		total_len += len;
> +	}
> +
> +	if (!sgf || !sgl) {
> +		ret = -EINVAL;
> +		goto out;
> +	}
> +
> +	sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
> +	if (!sgt) {
> +		ret = -ENOMEM;
> +		goto out;
> +	}
> +
> +	ret = sg_alloc_table(sgt, nents, GFP_KERNEL);
> +	if (ret)
> +		goto free_sgt;
> +
> +	/* copy relevant sg node and fix page and length */
> +	sgn = sgf;
> +	for_each_sgtable_sg(sgt, sg, j) {
> +		memcpy(sg, sgn, sizeof(*sg));
> +		if (sgn == sgf) {
> +			sg_dma_address(sg) += offf;
> +			sg_dma_len(sg) -= offf;
> +			sg_set_page(sg, sg_page(sgn),
> +				    sg_dma_len(sg), offf);
> +		} else {
> +			offf = 0;
> +		}
> +		if (sgn == sgl) {
> +			sg_dma_len(sg) = offl - offf;
> +			sg_set_page(sg, sg_page(sgn),
> +				    offl - offf, offf);
> +			sg_mark_end(sg);
> +			break;
> +		}
> +		sgn = sg_next(sgn);
> +	}

Why not use sg_copy_table() ? Overall copy_sgt() seems to be something
that could be replaced by generic helper or at least simplify.

Regards
Stanislaw


  reply	other threads:[~2023-02-24 15:25 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06 15:41 [PATCH v2 0/8] QAIC accel driver Jeffrey Hugo
2023-02-06 15:41 ` Jeffrey Hugo
2023-02-06 15:41 ` [PATCH v2 1/8] accel/qaic: Add documentation for AIC100 accelerator driver Jeffrey Hugo
2023-02-06 15:41   ` Jeffrey Hugo
2023-02-14 11:08   ` Jacek Lawrynowicz
2023-02-15 15:41     ` Jeffrey Hugo
2023-02-15 15:41       ` Jeffrey Hugo
2023-02-16 14:18       ` Jacek Lawrynowicz
2023-02-16 15:20         ` Jeffrey Hugo
2023-02-16 15:20           ` Jeffrey Hugo
2023-02-06 15:41 ` [PATCH v2 2/8] accel/qaic: Add uapi and core driver file Jeffrey Hugo
2023-02-06 15:41   ` Jeffrey Hugo
2023-02-16 14:13   ` Jacek Lawrynowicz
2023-02-17 18:15     ` Jeffrey Hugo
2023-02-17 18:15       ` Jeffrey Hugo
2023-02-22 15:52       ` Dafna Hirschfeld
2023-02-22 15:52         ` Dafna Hirschfeld
2023-02-24 21:21         ` Jeffrey Hugo
2023-02-24 21:21           ` Jeffrey Hugo
2023-03-01 19:46       ` Jeffrey Hugo
2023-03-01 19:46         ` Jeffrey Hugo
2023-02-06 15:41 ` [PATCH v2 3/8] accel/qaic: Add MHI controller Jeffrey Hugo
2023-02-06 15:41   ` Jeffrey Hugo
2023-02-28 11:52   ` Stanislaw Gruszka
2023-02-28 11:52     ` Stanislaw Gruszka
2023-03-01 16:09     ` Jeffrey Hugo
2023-03-01 16:09       ` Jeffrey Hugo
2023-03-03 13:57       ` Stanislaw Gruszka
2023-02-06 15:41 ` [PATCH v2 4/8] accel/qaic: Add control path Jeffrey Hugo
2023-02-06 15:41   ` Jeffrey Hugo
2023-03-01 13:18   ` Stanislaw Gruszka
2023-03-01 13:18     ` Stanislaw Gruszka
2023-03-01 17:02     ` Jeffrey Hugo
2023-03-01 17:02       ` Jeffrey Hugo
2023-02-06 15:41 ` [PATCH v2 5/8] accel/qaic: Add datapath Jeffrey Hugo
2023-02-06 15:41   ` Jeffrey Hugo
2023-02-24 15:25   ` Stanislaw Gruszka [this message]
2023-02-24 15:25     ` Stanislaw Gruszka
2023-02-24 19:36     ` Jeffrey Hugo
2023-02-24 19:36       ` Jeffrey Hugo
2023-02-27 17:14       ` Stanislaw Gruszka
2023-02-27 17:14         ` Stanislaw Gruszka
2023-03-01 16:08         ` Jeffrey Hugo
2023-03-01 16:08           ` Jeffrey Hugo
2023-03-01 17:05           ` Stanislaw Gruszka
2023-03-01 18:14             ` Jeffrey Hugo
2023-03-01 18:14               ` Jeffrey Hugo
2023-03-03 13:49               ` Stanislaw Gruszka
2023-02-06 15:41 ` [PATCH v2 6/8] accel/qaic: Add mhi_qaic_cntl Jeffrey Hugo
2023-02-06 15:41   ` Jeffrey Hugo
2023-03-01 13:19   ` Stanislaw Gruszka
2023-03-01 13:19     ` Stanislaw Gruszka
2023-02-06 15:41 ` [PATCH v2 7/8] accel/qaic: Add qaic driver to the build system Jeffrey Hugo
2023-02-06 15:41   ` Jeffrey Hugo
2023-03-01 13:02   ` Stanislaw Gruszka
2023-03-01 13:02     ` Stanislaw Gruszka
2023-03-01 16:10     ` Jeffrey Hugo
2023-03-01 16:10       ` Jeffrey Hugo
2023-02-06 15:41 ` [PATCH v2 8/8] MAINTAINERS: Add entry for QAIC driver Jeffrey Hugo
2023-02-06 15:41   ` Jeffrey Hugo
2023-03-01 13:03   ` Stanislaw Gruszka
2023-03-01 13:03     ` Stanislaw Gruszka
2023-03-01 16:15     ` Jeffrey Hugo
2023-03-01 16:15       ` Jeffrey Hugo
2023-02-08 22:01 ` [PATCH v2 0/8] QAIC accel driver Jeffrey Hugo
2023-02-08 22:01   ` Jeffrey Hugo
2023-02-17 16:14   ` Jeffrey Hugo
2023-02-17 16:14     ` Jeffrey Hugo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230224152546.GB3547587@linux.intel.com \
    --to=stanislaw.gruszka@linux.intel.com \
    --cc=airlied@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jacek.lawrynowicz@linux.intel.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=ogabbay@kernel.org \
    --cc=quic_ajitpals@quicinc.com \
    --cc=quic_carlv@quicinc.com \
    --cc=quic_jhugo@quicinc.com \
    --cc=quic_pkanojiy@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.