Re: [PATCH char-misc-next v3 4/4] issei: add driver to driver interface

From: Andrzej Kacprowski

Date: Wed Dec 02 2026 - 05:14:58 EST


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@xxxxxxxxx>
Signed-off-by: Reuven Abliyev <reuvenab@xxxxxxxxx>
Co-developed-by: Andrzej Kacprowski <andrzej.kacprowski@xxxxxxxxxxxxxxx>
Signed-off-by: Andrzej Kacprowski <andrzej.kacprowski@xxxxxxxxxxxxxxx>
Signed-off-by: Alexander Usyskin <alexander.usyskin@xxxxxxxxx>
---
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