[PATCH v12 76/86] media: ipu6: Remove nr_queues and nr_streaming fields in ipu6_isys_stream

Sakari Ailus
2026-04-09T20:15:16Z

nr_queues and nr_streaming fields were being used to determine whether
streaming was to be started in the upstream sub-device. As we store the
streaming state in the CSI-2 sub-device, there's no longer need for that.
Drop these fields.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c | 5 ++++
drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h | 1 +
.../media/pci/intel/ipu6/ipu6-isys-queue.c | 24 +++++++++----------
.../media/pci/intel/ipu6/ipu6-isys-video.c | 19 ++++-----------
.../media/pci/intel/ipu6/ipu6-isys-video.h | 7 ++----
5 files changed, 25 insertions(+), 31 deletions(-)

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
index f37e25063d6d..c2f4ea444e8e 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
@@ -432,6 +432,8 @@ static int ipu6_isys_csi2_enable_streams(struct v4l2_subdev *sd,
if (ret)
goto err_stop_stream_csi2;

+ csi2->streaming = true;
+
return 0;

err_stop_stream_csi2:
@@ -452,6 +454,7 @@ static int ipu6_isys_csi2_disable_streams(struct v4l2_subdev *sd,
u32 pad, u64 streams_mask)
{
struct ipu6_isys_subdev *asd = to_ipu6_isys_subdev(sd);
+ struct ipu6_isys_csi2 *csi2 = ipu6_isys_subdev_to_csi2(asd);
struct media_pad *remote_pad,
*vdev_pad = media_pad_remote_pad_unique(&sd->entity.pads[pad]);
struct ipu6_isys_video *av =
@@ -479,6 +482,8 @@ static int ipu6_isys_csi2_disable_streams(struct v4l2_subdev *sd,

ipu6_isys_close_streaming_firmware(av);

+ csi2->streaming = false;
+
out_del_csi2_entry:
list_del(&av->csi2_entry);

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h
index bcddd5626531..9178638edd37 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h
@@ -44,6 +44,7 @@ struct ipu6_isys_csi2 {
u32 receiver_errors;
unsigned int nlanes;
unsigned int port;
+ bool streaming;
};

struct ipu6_isys_csi2_timing {
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c b/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
index 7df13d330667..b7c7ccae0452 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
@@ -296,6 +296,9 @@ static int ipu6_isys_stream_start(struct ipu6_isys_video *av)
if (ret)
return ret;

+ if (!av->csi2->streaming)
+ return 0;
+
do {
struct ipu6_fw_isys_frame_buff_set_abi *buf = NULL;
struct isys_fw_msgs *msg;
@@ -343,6 +346,7 @@ static void buf_queue(struct vb2_buffer *vb)
struct device *dev = &av->isys->adev->auxdev.dev;
struct ipu6_fw_isys_frame_buff_set_abi *buf = NULL;
struct ipu6_isys_stream *stream = av->stream;
+ struct ipu6_isys_csi2 *csi2;
struct ipu6_isys_buffer_list bl;
struct isys_fw_msgs *msg;
unsigned long flags;
@@ -366,7 +370,8 @@ static void buf_queue(struct vb2_buffer *vb)

mutex_lock(&stream->mutex);

- if (stream->nr_streaming != stream->nr_queues) {
+ csi2 = ipu6_isys_subdev_to_csi2(stream->asd);
+ if (!csi2->streaming) {
dev_dbg(dev, "not streaming yet, adding to incoming\n");
goto out;
}
@@ -530,7 +535,8 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
ipu6_isys_get_isys_format(ipu6_isys_get_format(av), 0);
struct ipu6_isys_stream *stream;
struct media_pad *source_pad, *remote_pad;
- int nr_queues, ret;
+ bool first;
+ int ret;

dev_dbg(dev, "stream: %s: width %u, height %u, css pixelformat %u\n",
av->vdev.name, ipu6_isys_get_frame_width(av),
@@ -550,11 +556,12 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
goto out_return_buffers;
}

- ret = ipu6_isys_setup_video(av, remote_pad, source_pad, &nr_queues);
+ ret = ipu6_isys_setup_video(av, remote_pad, source_pad);
if (ret < 0) {
dev_dbg(dev, "failed to setup video\n");
goto out_return_buffers;
}
+ first = ret;

ret = ipu6_isys_link_fmt_validate(aq);
if (ret) {
@@ -570,17 +577,12 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)

stream = av->stream;
mutex_lock(&stream->mutex);
- if (!stream->nr_streaming) {
- ret = ipu6_isys_video_prepare_stream(av, source_pad->entity,
- nr_queues);
+ if (first) {
+ ret = ipu6_isys_video_prepare_stream(av, source_pad->entity);
if (ret)
goto out_fw_close;
}

- stream->nr_streaming++;
- dev_dbg(dev, "queue %u of %u\n", stream->nr_streaming,
- stream->nr_queues);
-
list_add(&aq->node, &stream->queues);
ipu6_isys_configure_stream_watermark(av, source_pad->entity);
ipu6_isys_update_stream_watermark(av, true);
@@ -596,7 +598,6 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
out_stream_start:
ipu6_isys_update_stream_watermark(av, false);
list_del(&aq->node);
- stream->nr_streaming--;

out_fw_close:
mutex_unlock(&stream->mutex);
@@ -626,7 +627,6 @@ static void stop_streaming(struct vb2_queue *q)
list_del(&aq->node);
mutex_unlock(&av->isys->stream_mutex);

- stream->nr_streaming--;
mutex_unlock(&stream->mutex);

ipu6_isys_stream_cleanup(av);
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-video.c b/drivers/media/pci/intel/ipu6/ipu6-isys-video.c
index 1165d5bc693b..9d0ed47df280 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-video.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-video.c
@@ -714,16 +714,11 @@ void ipu6_isys_close_streaming_firmware(struct ipu6_isys_video *av)
}

int ipu6_isys_video_prepare_stream(struct ipu6_isys_video *av,
- struct media_entity *source_entity,
- int nr_queues)
+ struct media_entity *source_entity)
{
struct ipu6_isys_stream *stream = av->stream;
struct ipu6_isys_csi2 *csi2;

- if (WARN_ON(stream->nr_streaming))
- return -EINVAL;
-
- stream->nr_queues = nr_queues;
atomic_set(&stream->sequence, 0);

stream->seq_index = 0;
@@ -1099,7 +1094,7 @@ void ipu6_isys_fw_close(struct ipu6_isys *isys)

int ipu6_isys_setup_video(struct ipu6_isys_video *av,
struct media_pad *remote_pad,
- struct media_pad *source_pad, int *nr_queues)
+ struct media_pad *source_pad)
{
const struct ipu6_isys_pixelformat *pfmt =
ipu6_isys_get_isys_format(ipu6_isys_get_format(av), 0);
@@ -1113,16 +1108,11 @@ int ipu6_isys_setup_video(struct ipu6_isys_video *av,
struct ipu6_isys_subdev *asd = to_ipu6_isys_subdev(remote_sd);
int ret = -EINVAL;

- *nr_queues = 0;
-
/* Find the root */
state = v4l2_subdev_lock_and_get_active_state(remote_sd);
- for_each_active_route(&state->routing, r) {
- (*nr_queues)++;
-
+ for_each_active_route(&state->routing, r)
if (r->source_pad == remote_pad->index)
route = r;
- }

if (!route) {
v4l2_subdev_unlock_state(state);
@@ -1150,6 +1140,7 @@ int ipu6_isys_setup_video(struct ipu6_isys_video *av,
return ret;
}

+ pipeline = video_device_pipeline(&av->vdev);
ret = video_device_pipeline_alloc_start(&av->vdev);
if (ret < 0) {
dev_dbg(dev, "media pipeline start failed\n");
@@ -1163,7 +1154,7 @@ int ipu6_isys_setup_video(struct ipu6_isys_video *av,
return -EINVAL;
}

- return 0;
+ return !pipeline;
}

/*
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-video.h b/drivers/media/pci/intel/ipu6/ipu6-isys-video.h
index c1d10a9f44f2..5dd70175a857 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-video.h
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-video.h
@@ -51,8 +51,6 @@ struct ipu6_isys_stream {
unsigned int nr_output_pins;
struct ipu6_isys_subdev *asd;

- int nr_queues; /* Number of capture queues */
- int nr_streaming;
struct list_head queues;
struct completion stream_open_completion;
struct completion stream_close_completion;
@@ -106,14 +104,13 @@ int ipu6_isys_start_stream_firmware(struct ipu6_isys_video *av);
void ipu6_isys_stop_streaming_firmware(struct ipu6_isys_video *av);
void ipu6_isys_close_streaming_firmware(struct ipu6_isys_video *av);
int ipu6_isys_video_prepare_stream(struct ipu6_isys_video *av,
- struct media_entity *source_entity,
- int nr_queues);
+ struct media_entity *source_entity);
int ipu6_isys_video_set_streaming(struct ipu6_isys_video *av, int state);
int ipu6_isys_fw_open(struct ipu6_isys *isys);
void ipu6_isys_fw_close(struct ipu6_isys *isys);
int ipu6_isys_setup_video(struct ipu6_isys_video *av,
struct media_pad *remote_pad,
- struct media_pad *source_pad, int *nr_queues);
+ struct media_pad *source_pad);
int ipu6_isys_video_init(struct ipu6_isys_video *av);
void ipu6_isys_video_cleanup(struct ipu6_isys_video *av);
void ipu6_isys_put_stream(struct ipu6_isys_stream *stream);
--
2.47.3