mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrzej Kacprowski <andrzej.kacprowski@linux.intel.com>
To: Alexander Usyskin <alexander.usyskin@intel.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH char-misc-next v3 4/4] issei: add driver to driver interface
Date: Wed, 2 Dec 2026 11:14:37 +0100	[thread overview]
Message-ID: <c6cce0c8-114f-4001-98a3-ec1ca75551e5@linux.intel.com> (raw)
In-Reply-To: <20261111-issei_pm_and_itf-v3-4-4f4f6d626ff3@intel.com>

On 11-Nov-26 8:40 AM, Alexander Usyskin wrote:
> Add new interface that enables communication with ISSEI device
> from the kernel modules.
> First intended consumer is an NPU driver.
> 
> Co-developed-by: Reuven Abliyev <reuvenab@gmail.com>
> Signed-off-by: Reuven Abliyev <reuvenab@gmail.com>
> Co-developed-by: Andrzej Kacprowski <andrzej.kacprowski@linux.intel.com>
> Signed-off-by: Andrzej Kacprowski <andrzej.kacprowski@linux.intel.com>
> Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
> ---
>   MAINTAINERS                       |   1 +
>   drivers/misc/issei/Makefile       |   1 +
>   drivers/misc/issei/cdev.c         |  12 +-
>   drivers/misc/issei/issei_device.c | 269 ++++++++++++++++++++++++++++++++++++++
>   include/linux/issei_device.h      |  31 +++++
>   5 files changed, 308 insertions(+), 6 deletions(-)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 93abbb315065..1633cc41d95b 100644


...
> +ssize_t issei_device_write(void *ctx, const u8 *ubuf, size_t length, unsigned long timeout)
> +{
> +	struct issei_host_client *cl = ctx;
> +	struct issei_device *idev = cl->idev;
> +	ssize_t ret;
> +	long wret;
> +
> +	if (idev->rst_state != ISSEI_RST_STATE_DONE) {
> +		dev_dbg(&idev->dev, "Device is in transition\n");
> +		return -EBUSY;
> +	}
> +
> +	if (!length)
> +		return 0;
> +
> +	/* sanity check */
> +	if (length > idev->dma.length.h2f) {
> +		dev_dbg(&idev->dev, "Write is too big %zu > %zu\n", length,
> +			idev->dma.length.h2f);
> +		return -EFBIG;
> +	}
> +
> +	u8 *buf __free(kfree) = kmemdup(ubuf, length, GFP_KERNEL);
> +	if (!buf)
> +		return -ENOMEM;
> +
> +	do {
> +		ret = issei_cl_write(cl, buf, length);
> +		if (ret < 0 && ret != -EAGAIN)
> +			return ret;
> +		/* buf is consumed by issei_cl_write on success */
> +		if (ret >= 0)
> +			retain_and_null_ptr(buf);
> +		wret = wait_event_interruptible_timeout(cl->write_wait,
> +							issei_cl_check_write(cl) != 1,
> +							msecs_to_jiffies(timeout));
Here the timeout parameter is converted to jiffies.

> +		if (wret == 0) /* timeout */
> +			wret = -ETIMEDOUT;
> +		if (wret < 0) {
> +			issei_cl_clean_all_wbuf(cl);
> +			dev_dbg(&idev->dev, "Failed writing data ret = %zd\n", ret);
> +			return wret;
> +		}
> +	} while (ret == -EAGAIN);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(issei_device_write);
> +
> +/**
> + * issei_device_read - receive data from the firmware client.
> + * @ctx: opaque context
> + * @ubuf: buffer for data
> + * @length: buffer length
> + * @timeout: operation timeout in milliseconds
> + *
> + * Return: >=0 data length on success, <0 on error
> + */
> +ssize_t issei_device_read(void *ctx, u8 *ubuf, size_t length, unsigned long timeout)

I suggest to rename `timeout` to `timeout_ms` - it will make it easier 
to spot mistakes like below.

> +{
> +	struct issei_host_client *cl = ctx;
> +	struct issei_device *idev = cl->idev;
> +	u8 *data = NULL;
> +	ssize_t ret;
> +
> +	if (idev->rst_state != ISSEI_RST_STATE_DONE) {
> +		dev_dbg(&idev->dev, "Device is in transition\n");
> +		return -EBUSY;
> +	}
> +
> +	if (!length)
> +		return 0;
> +
> +	/* sanity check */
> +	if (length > idev->dma.length.f2h) {
> +		dev_dbg(&idev->dev, "Read is too big %zu > %zu\n", length,
> +			idev->dma.length.f2h);
> +		return -EFBIG;
> +	}
> +
> +	ret = issei_cl_read(cl, &data, length);
> +	if (ret < 0) {
> +		if (ret != -ENOENT)
> +			return ret;
> +
> +		ret = wait_event_interruptible_timeout(cl->read_wait,
> +						       issei_cl_check_read(cl) != 0,
> +						       timeout);

Here the timeout is in milliseconds but it's passed directly to function 
that takes jiffies - it must be converted to jiffies first with 
msecs_to_jiffies().
The similar function issei_device_write() already does this conversion.

BR,
Andrzej




      parent reply	other threads:[~2026-12-02 10:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  7:40 [PATCH char-misc-next v3 0/4] issei: runtime power management, dma and in-kernel interface Alexander Usyskin
2026-11-11  7:40 ` [PATCH char-misc-next v3 1/4] issei: save power_down flag while processing event Alexander Usyskin
2026-11-19  9:09   ` Karol Wachowski
2026-11-11  7:40 ` [PATCH char-misc-next v3 2/4] issei: add runtime pm Alexander Usyskin
2026-11-19  9:11   ` Karol Wachowski
2026-11-11  7:40 ` [PATCH char-misc-next v3 3/4] issei: host_client: add dma allocation support Alexander Usyskin
2026-11-19  9:09   ` Karol Wachowski
2026-11-11  7:40 ` [PATCH char-misc-next v3 4/4] issei: add driver to driver interface Alexander Usyskin
2026-11-19  9:10   ` Karol Wachowski
2026-12-02 10:14   ` Andrzej Kacprowski [this message]

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=c6cce0c8-114f-4001-98a3-ec1ca75551e5@linux.intel.com \
    --to=andrzej.kacprowski@linux.intel.com \
    --cc=alexander.usyskin@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®