All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv
@ 2020-09-14  9:03 Mauro Carvalho Chehab
  2020-09-14  9:03 ` [PATCH RFC 01/11] media: vidtv: add modaliases for the bridge driver Mauro Carvalho Chehab
                   ` (10 more replies)
  0 siblings, 11 replies; 16+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-14  9:03 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media,
	Stephen Rothwell

This patch series is not ready yet. However, as there are some problems reported
when this driver got merged at linux-next, let me send it, in order to avoid
someone to address the same problems I already fixed.

There are still some things to be fixed there. For example, the bitfield 
endiannes logic for MPEG-TS tables are wrong. My plan is to address those
along this week.

Also, Kaffeine is not properly detecting the audio streams. It will likely need
some additional patches for it to properly detect and work with SMPTE 302m
audio streams.

Mauro Carvalho Chehab (11):
  media: vidtv: add modaliases for the bridge driver
  media: vidtv: prefer using dev_foo() instead of pr_foo()
  media: vidtv: fix 32-bit warnings
  media: vidtv: fix frequency tuning logic
  media: vidtv: add an initial channel frequency
  media: vidtv: get rid of some endiannes nonsense
  media: vidtv: remove a wrong endiannes check from s302m generator
  media: vidtv: properly initialize the internal state struct
  media: vidtv: add basic support for DVBv5 stats
  media: vidtv: get rid of the work queue
  media: vidtv: increment byte and block counters

 .../media/test-drivers/vidtv/vidtv_bridge.c   |  35 ++-
 .../media/test-drivers/vidtv/vidtv_bridge.h   |   3 +
 .../media/test-drivers/vidtv/vidtv_channel.c  |  23 +-
 .../media/test-drivers/vidtv/vidtv_common.c   |   4 +-
 .../media/test-drivers/vidtv/vidtv_demod.c    | 242 +++++++++---------
 .../media/test-drivers/vidtv/vidtv_demod.h    |   4 -
 drivers/media/test-drivers/vidtv/vidtv_mux.c  |  32 ++-
 drivers/media/test-drivers/vidtv/vidtv_mux.h  |   9 +-
 drivers/media/test-drivers/vidtv/vidtv_pes.c  |  12 +-
 drivers/media/test-drivers/vidtv/vidtv_psi.c  |  32 ---
 .../media/test-drivers/vidtv/vidtv_s302m.c    |  10 +-
 .../media/test-drivers/vidtv/vidtv_tuner.c    |  41 ++-
 12 files changed, 221 insertions(+), 226 deletions(-)

-- 
2.26.2



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH RFC 01/11] media: vidtv: add modaliases for the bridge driver
  2020-09-14  9:03 [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv Mauro Carvalho Chehab
@ 2020-09-14  9:03 ` Mauro Carvalho Chehab
  2020-09-14  9:03 ` [PATCH RFC 02/11] media: vidtv: prefer using dev_foo() instead of pr_foo() Mauro Carvalho Chehab
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-14  9:03 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media

As this virtual driver is probed manually, add modaliases
for this driver.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/test-drivers/vidtv/vidtv_bridge.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_bridge.c b/drivers/media/test-drivers/vidtv/vidtv_bridge.c
index 82e375048b99..9f0e53e9fe69 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_bridge.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_bridge.c
@@ -530,3 +530,5 @@ module_exit(vidtv_bridge_exit);
 MODULE_DESCRIPTION("Virtual Digital TV Test Driver");
 MODULE_AUTHOR("Daniel W. S. Almeida");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("vidtv");
+MODULE_ALIAS("dvb_vidtv");
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 02/11] media: vidtv: prefer using dev_foo() instead of pr_foo()
  2020-09-14  9:03 [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv Mauro Carvalho Chehab
  2020-09-14  9:03 ` [PATCH RFC 01/11] media: vidtv: add modaliases for the bridge driver Mauro Carvalho Chehab
@ 2020-09-14  9:03 ` Mauro Carvalho Chehab
  2020-09-14  9:03 ` [PATCH RFC 03/11] media: vidtv: fix 32-bit warnings Mauro Carvalho Chehab
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-14  9:03 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media

It is better to use the higher level dev_foo() than pr_foo()
for printks.

Change them at vidtv at the more trivial places.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 .../media/test-drivers/vidtv/vidtv_bridge.c   | 19 +++++++--------
 .../media/test-drivers/vidtv/vidtv_channel.c  | 23 ++++++++++---------
 .../media/test-drivers/vidtv/vidtv_demod.c    | 10 ++++----
 drivers/media/test-drivers/vidtv/vidtv_mux.c  | 18 ++++++++-------
 drivers/media/test-drivers/vidtv/vidtv_mux.h  |  5 +++-
 .../media/test-drivers/vidtv/vidtv_tuner.c    | 17 +++++++-------
 6 files changed, 51 insertions(+), 41 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_bridge.c b/drivers/media/test-drivers/vidtv/vidtv_bridge.c
index 9f0e53e9fe69..270c183b1d67 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_bridge.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_bridge.c
@@ -9,12 +9,10 @@
  * Copyright (C) 2020 Daniel W. S. Almeida
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ":%s, %d: " fmt, __func__, __LINE__
-
 #include <linux/moduleparam.h>
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
-#include <linux/printk.h>
+#include <linux/dev_printk.h>
 #include <linux/time.h>
 #include <linux/types.h>
 #include <linux/workqueue.h>
@@ -146,10 +144,11 @@ vidtv_bridge_on_new_pkts_avail(void *priv, u8 *buf, u32 npkts)
 static int vidtv_start_streaming(struct vidtv_dvb *dvb)
 {
 	struct vidtv_mux_init_args mux_args = {0};
+	struct device *dev = &dvb->pdev->dev;
 	u32 mux_buf_sz;
 
 	if (dvb->streaming) {
-		pr_warn_ratelimited("Already streaming. Skipping.\n");
+		dev_warn_ratelimited(dev, "Already streaming. Skipping.\n");
 		return 0;
 	}
 
@@ -165,21 +164,23 @@ static int vidtv_start_streaming(struct vidtv_dvb *dvb)
 	mux_args.priv                        = dvb;
 
 	dvb->streaming = true;
-	dvb->mux = vidtv_mux_init(mux_args);
+	dvb->mux = vidtv_mux_init(dev, mux_args);
 	vidtv_mux_start_thread(dvb->mux);
 
-	pr_info_ratelimited("Started streaming\n");
+	dev_dbg_ratelimited(dev, "Started streaming\n");
 	return 0;
 }
 
 static int vidtv_stop_streaming(struct vidtv_dvb *dvb)
 {
+	struct device *dev = &dvb->pdev->dev;
+
 	dvb->streaming = false;
 	vidtv_mux_stop_thread(dvb->mux);
 	vidtv_mux_destroy(dvb->mux);
 	dvb->mux = NULL;
 
-	pr_info_ratelimited("Stopped streaming\n");
+	dev_dbg_ratelimited(dev, "Stopped streaming\n");
 	return 0;
 }
 
@@ -438,8 +439,8 @@ static int vidtv_bridge_dvb_init(struct vidtv_dvb *dvb)
 
 static int vidtv_bridge_probe(struct platform_device *pdev)
 {
-	int ret;
 	struct vidtv_dvb *dvb;
+	int ret;
 
 	dvb = kzalloc(sizeof(*dvb), GFP_KERNEL);
 	if (!dvb)
@@ -455,7 +456,7 @@ static int vidtv_bridge_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, dvb);
 
-	pr_info("Successfully initialized vidtv!\n");
+	dev_info(&pdev->dev, "Successfully initialized vidtv!\n");
 	return ret;
 
 err_dvb:
diff --git a/drivers/media/test-drivers/vidtv/vidtv_channel.c b/drivers/media/test-drivers/vidtv/vidtv_channel.c
index ac4bdf05395e..0a62b97e6a27 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_channel.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_channel.c
@@ -18,11 +18,9 @@
  * Copyright (C) 2020 Daniel W. S. Almeida
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ":%s, %d: " fmt, __func__, __LINE__
-
 #include <linux/types.h>
 #include <linux/slab.h>
-#include <linux/printk.h>
+#include <linux/dev_printk.h>
 #include <linux/ratelimit.h>
 
 #include "vidtv_channel.h"
@@ -104,10 +102,10 @@ struct vidtv_channel
 }
 
 static struct vidtv_psi_table_sdt_service
-*vidtv_channel_sdt_serv_cat_into_new(const struct vidtv_channel *channels)
+*vidtv_channel_sdt_serv_cat_into_new(struct vidtv_mux *m)
 {
 	/* Concatenate the services */
-	const struct vidtv_channel *cur_chnl = channels;
+	const struct vidtv_channel *cur_chnl = m->channels;
 
 	struct vidtv_psi_table_sdt_service *curr = NULL;
 	struct vidtv_psi_table_sdt_service *head = NULL;
@@ -123,7 +121,8 @@ static struct vidtv_psi_table_sdt_service
 		curr = cur_chnl->service;
 
 		if (!curr)
-			pr_warn_ratelimited("No services found for channel %s\n", cur_chnl->name);
+			dev_warn_ratelimited(m->dev,
+					     "No services found for channel %s\n", cur_chnl->name);
 
 		while (curr) {
 			service_id = be16_to_cpu(curr->service_id);
@@ -145,10 +144,10 @@ static struct vidtv_psi_table_sdt_service
 }
 
 static struct vidtv_psi_table_pat_program*
-vidtv_channel_pat_prog_cat_into_new(const struct vidtv_channel *channels)
+vidtv_channel_pat_prog_cat_into_new(struct vidtv_mux *m)
 {
 	/* Concatenate the programs */
-	const struct vidtv_channel *cur_chnl = channels;
+	const struct vidtv_channel *cur_chnl = m->channels;
 	struct vidtv_psi_table_pat_program *curr = NULL;
 	struct vidtv_psi_table_pat_program *head = NULL;
 	struct vidtv_psi_table_pat_program *tail = NULL;
@@ -162,7 +161,9 @@ vidtv_channel_pat_prog_cat_into_new(const struct vidtv_channel *channels)
 		curr = cur_chnl->program;
 
 		if (!curr)
-			pr_warn_ratelimited("No programs found for channel %s\n", cur_chnl->name);
+			dev_warn_ratelimited(m->dev,
+					     "No programs found for channel %s\n",
+					     cur_chnl->name);
 
 		while (curr) {
 			serv_id = be16_to_cpu(curr->service_id);
@@ -251,8 +252,8 @@ void vidtv_channel_si_init(struct vidtv_mux *m)
 
 	m->si.sdt = vidtv_psi_sdt_table_init(m->transport_stream_id);
 
-	programs = vidtv_channel_pat_prog_cat_into_new(m->channels);
-	services = vidtv_channel_sdt_serv_cat_into_new(m->channels);
+	programs = vidtv_channel_pat_prog_cat_into_new(m);
+	services = vidtv_channel_sdt_serv_cat_into_new(m);
 
 	/* assemble all programs and assign to PAT */
 	vidtv_psi_pat_program_assign(m->si.pat, programs);
diff --git a/drivers/media/test-drivers/vidtv/vidtv_demod.c b/drivers/media/test-drivers/vidtv/vidtv_demod.c
index d18860fcb0e7..3eb48b4a9a6b 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_demod.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_demod.c
@@ -76,8 +76,9 @@ static const struct vidtv_demod_cnr_to_qual_s vidtv_demod_t_cnr_2_qual[] = {
 static const struct vidtv_demod_cnr_to_qual_s
 	     *vidtv_match_cnr_s(struct dvb_frontend *fe)
 {
+	const struct vidtv_demod_cnr_to_qual_s *cnr2qual = NULL;
+	struct device *dev = fe->dvb->device;
 	struct dtv_frontend_properties *c;
-	const struct vidtv_demod_cnr_to_qual_s *cnr2qual = NULL;
 	u32 array_size = 0;
 	u32 i;
 
@@ -106,9 +107,10 @@ static const struct vidtv_demod_cnr_to_qual_s
 		break;
 
 	default:
-		pr_warn_ratelimited("%s: unsupported delivery system: %u\n",
-				    __func__,
-				    c->delivery_system);
+		dev_warn_ratelimited(dev,
+				     "%s: unsupported delivery system: %u\n",
+				     __func__,
+				     c->delivery_system);
 		break;
 	}
 
diff --git a/drivers/media/test-drivers/vidtv/vidtv_mux.c b/drivers/media/test-drivers/vidtv/vidtv_mux.c
index 540f404372aa..d1db9dc6dc89 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_mux.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_mux.c
@@ -12,13 +12,11 @@
  * Copyright (C) 2020 Daniel W. S. Almeida
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ":%s, %d: " fmt, __func__, __LINE__
-
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/jiffies.h>
 #include <linux/kernel.h>
-#include <linux/printk.h>
+#include <linux/dev_printk.h>
 #include <linux/ratelimit.h>
 #include <linux/delay.h>
 #include <linux/vmalloc.h>
@@ -147,7 +145,8 @@ static u32 vidtv_mux_push_si(struct vidtv_mux *m)
 						m->si.pat);
 
 		if (pmt_pid > TS_LAST_VALID_PID) {
-			pr_warn_ratelimited("PID: %d not found\n", pmt_pid);
+			dev_warn_ratelimited(m->dev,
+					     "PID: %d not found\n", pmt_pid);
 			continue;
 		}
 
@@ -331,7 +330,8 @@ static u32 vidtv_mux_pad_with_nulls(struct vidtv_mux *m, u32 npkts)
 
 	/* sanity check */
 	if (nbytes != npkts * TS_PACKET_LEN)
-		pr_err_ratelimited("%d != %d\n", nbytes, npkts * TS_PACKET_LEN);
+		dev_err_ratelimited(m->dev, "%d != %d\n",
+				    nbytes, npkts * TS_PACKET_LEN);
 
 	return nbytes;
 }
@@ -402,7 +402,7 @@ static void vidtv_mux_tick(struct work_struct *work)
 
 		/* if the buffer is not aligned there is a bug somewhere */
 		if (nbytes % TS_PACKET_LEN)
-			pr_err_ratelimited("Misaligned buffer\n");
+			dev_err_ratelimited(m->dev, "Misaligned buffer\n");
 
 		if (m->on_new_packets_available_cb)
 			m->on_new_packets_available_cb(m->priv,
@@ -418,7 +418,7 @@ static void vidtv_mux_tick(struct work_struct *work)
 void vidtv_mux_start_thread(struct vidtv_mux *m)
 {
 	if (m->streaming) {
-		pr_warn_ratelimited("Already streaming. Skipping.\n");
+		dev_warn_ratelimited(m->dev, "Already streaming. Skipping.\n");
 		return;
 	}
 
@@ -435,10 +435,12 @@ void vidtv_mux_stop_thread(struct vidtv_mux *m)
 	}
 }
 
-struct vidtv_mux *vidtv_mux_init(struct vidtv_mux_init_args args)
+struct vidtv_mux *vidtv_mux_init(struct device *dev,
+				 struct vidtv_mux_init_args args)
 {
 	struct vidtv_mux *m = kzalloc(sizeof(*m), GFP_KERNEL);
 
+	m->dev = dev;
 	m->timing.pcr_period_usecs = args.pcr_period_usecs;
 	m->timing.si_period_usecs  = args.si_period_usecs;
 
diff --git a/drivers/media/test-drivers/vidtv/vidtv_mux.h b/drivers/media/test-drivers/vidtv/vidtv_mux.h
index 8622a62cd9bc..67de85fd50aa 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_mux.h
+++ b/drivers/media/test-drivers/vidtv/vidtv_mux.h
@@ -100,6 +100,8 @@ struct vidtv_mux_pid_ctx {
  * @priv: Private data.
  */
 struct vidtv_mux {
+	struct device *dev;
+
 	struct vidtv_mux_timing timing;
 
 	u32 mux_rate_kbytes_sec;
@@ -151,7 +153,8 @@ struct vidtv_mux_init_args {
 	void *priv;
 };
 
-struct vidtv_mux *vidtv_mux_init(struct vidtv_mux_init_args args);
+struct vidtv_mux *vidtv_mux_init(struct device *dev,
+				 struct vidtv_mux_init_args args);
 void vidtv_mux_destroy(struct vidtv_mux *m);
 
 void vidtv_mux_start_thread(struct vidtv_mux *m);
diff --git a/drivers/media/test-drivers/vidtv/vidtv_tuner.c b/drivers/media/test-drivers/vidtv/vidtv_tuner.c
index c8e64bab0379..39e848ae5836 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_tuner.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_tuner.c
@@ -10,8 +10,6 @@
  * Copyright (C) 2020 Daniel W. S. Almeida
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ":%s, %d: " fmt, __func__, __LINE__
-
 #include <linux/errno.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
@@ -149,9 +147,10 @@ static s32 vidtv_tuner_check_frequency_shift(struct dvb_frontend *fe)
 		break;
 
 	default:
-		pr_warn("%s: unsupported delivery system: %u\n",
-			__func__,
-			c->delivery_system);
+		dev_warn(fe->dvb->device,
+			 "%s: unsupported delivery system: %u\n",
+			 __func__,
+			 c->delivery_system);
 
 		return -EINVAL;
 	}
@@ -179,6 +178,7 @@ vidtv_tuner_get_signal_strength(struct dvb_frontend *fe, u16 *strength)
 {
 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 	const struct vidtv_tuner_cnr_to_qual_s *cnr2qual = NULL;
+	struct device *dev = fe->dvb->device;
 	u32 array_size = 0;
 	s32 shift;
 	u32 i;
@@ -208,9 +208,10 @@ vidtv_tuner_get_signal_strength(struct dvb_frontend *fe, u16 *strength)
 		break;
 
 	default:
-		pr_warn_ratelimited("%s: unsupported delivery system: %u\n",
-				    __func__,
-				    c->delivery_system);
+		dev_warn_ratelimited(dev,
+				     "%s: unsupported delivery system: %u\n",
+				     __func__,
+				     c->delivery_system);
 		return -EINVAL;
 	}
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 03/11] media: vidtv: fix 32-bit warnings
  2020-09-14  9:03 [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv Mauro Carvalho Chehab
  2020-09-14  9:03 ` [PATCH RFC 01/11] media: vidtv: add modaliases for the bridge driver Mauro Carvalho Chehab
  2020-09-14  9:03 ` [PATCH RFC 02/11] media: vidtv: prefer using dev_foo() instead of pr_foo() Mauro Carvalho Chehab
@ 2020-09-14  9:03 ` Mauro Carvalho Chehab
  2020-09-14  9:03 ` [PATCH RFC 04/11] media: vidtv: fix frequency tuning logic Mauro Carvalho Chehab
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-14  9:03 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media, Hans Verkuil

There are several warnings produced when the driver is built
for 32-bit archs. Solve them.

Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/test-drivers/vidtv/vidtv_common.c |  4 ++--
 drivers/media/test-drivers/vidtv/vidtv_pes.c    | 12 +++---------
 drivers/media/test-drivers/vidtv/vidtv_s302m.c  |  2 +-
 3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_common.c b/drivers/media/test-drivers/vidtv/vidtv_common.c
index 9093df32e0ab..63b3055bd715 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_common.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_common.c
@@ -42,7 +42,7 @@ u32 vidtv_memcpy(void *to,
 		 size_t len)
 {
 	if (unlikely(to_offset + len > to_size)) {
-		pr_err_ratelimited("overflow detected, skipping. Try increasing the buffer size. Needed %lu, had %zu\n",
+		pr_err_ratelimited("overflow detected, skipping. Try increasing the buffer size. Needed %zu, had %zu\n",
 				   to_offset + len,
 				   to_size);
 		return 0;
@@ -78,7 +78,7 @@ u32 vidtv_memset(void *to,
 		 size_t len)
 {
 	if (unlikely(to_offset + len > to_size)) {
-		pr_err_ratelimited("overflow detected, skipping. Try increasing the buffer size. Needed %lu, had %zu\n",
+		pr_err_ratelimited("overflow detected, skipping. Try increasing the buffer size. Needed %zu, had %zu\n",
 				   to_offset + len,
 				   to_size);
 		return 0;
diff --git a/drivers/media/test-drivers/vidtv/vidtv_pes.c b/drivers/media/test-drivers/vidtv/vidtv_pes.c
index 8237434f3fc2..34518ef042f7 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_pes.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_pes.c
@@ -90,15 +90,9 @@ static u32 vidtv_pes_write_pts_dts(struct pes_header_write_args args)
 	if (!args.send_pts && args.send_dts)
 		return 0;
 
-	#ifdef __BIG_ENDIAN
-	mask1 = GENMASK(30, 32);
-	mask2 = GENMASK(15, 29);
-	mask3 = GENMASK(0, 14);
-	#else
-	mask1 = GENMASK(32, 30);
-	mask2 = GENMASK(29, 15);
-	mask3 = GENMASK(14, 0);
-	#endif
+	mask1 = GENMASK_ULL(32, 30);
+	mask2 = GENMASK_ULL(29, 15);
+	mask3 = GENMASK_ULL(14, 0);
 
 	/* see ISO/IEC 13818-1 : 2000 p. 32 */
 	if (args.send_pts && args.send_dts) {
diff --git a/drivers/media/test-drivers/vidtv/vidtv_s302m.c b/drivers/media/test-drivers/vidtv/vidtv_s302m.c
index 3b20a26d8721..5ae2ede951eb 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_s302m.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_s302m.c
@@ -422,7 +422,7 @@ static void vidtv_s302m_write_frames(struct vidtv_encoder *e)
 		au->nbytes = nbytes_per_unit;
 
 		if (au_sz + sizeof(struct vidtv_smpte_s302m_es) != nbytes_per_unit) {
-			pr_warn_ratelimited("write size was %d, expected %lu\n",
+			pr_warn_ratelimited("write size was %u, expected %zu\n",
 					    nbytes_per_unit,
 					    au_sz + sizeof(struct vidtv_smpte_s302m_es));
 		}
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 04/11] media: vidtv: fix frequency tuning logic
  2020-09-14  9:03 [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv Mauro Carvalho Chehab
                   ` (2 preceding siblings ...)
  2020-09-14  9:03 ` [PATCH RFC 03/11] media: vidtv: fix 32-bit warnings Mauro Carvalho Chehab
@ 2020-09-14  9:03 ` Mauro Carvalho Chehab
  2020-09-14  9:03 ` [PATCH RFC 05/11] media: vidtv: add an initial channel frequency Mauro Carvalho Chehab
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-14  9:03 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media

Right now, there are some issues at the tuning logic:

1) the config struct is not copied at the tuner driver.
   so, it won't use any frequency table at all;
2) the code that checks for frequency shifts is called
   at set_params. So, lock_status will never be zeroed;
3) the signal strength will also report a strong
   signal, even if not tuned;
4) the logic is not excluding non-set frequencies.

Fix those issues.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 .../media/test-drivers/vidtv/vidtv_tuner.c    | 22 ++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_tuner.c b/drivers/media/test-drivers/vidtv/vidtv_tuner.c
index 39e848ae5836..0f397fe12989 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_tuner.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_tuner.c
@@ -120,7 +120,7 @@ vidtv_tuner_get_dev(struct dvb_frontend *fe)
 	return i2c_get_clientdata(fe->tuner_priv);
 }
 
-static s32 vidtv_tuner_check_frequency_shift(struct dvb_frontend *fe)
+static int vidtv_tuner_check_frequency_shift(struct dvb_frontend *fe)
 {
 	struct vidtv_tuner_dev *tuner_dev = vidtv_tuner_get_dev(fe);
 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
@@ -156,6 +156,8 @@ static s32 vidtv_tuner_check_frequency_shift(struct dvb_frontend *fe)
 	}
 
 	for (i = 0; i < array_sz; i++) {
+		if (!valid_freqs[i])
+			break;
 		shift = abs(c->frequency - valid_freqs[i]);
 
 		if (!shift)
@@ -177,6 +179,7 @@ static int
 vidtv_tuner_get_signal_strength(struct dvb_frontend *fe, u16 *strength)
 {
 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+	struct vidtv_tuner_dev *tuner_dev = vidtv_tuner_get_dev(fe);
 	const struct vidtv_tuner_cnr_to_qual_s *cnr2qual = NULL;
 	struct device *dev = fe->dvb->device;
 	u32 array_size = 0;
@@ -184,6 +187,10 @@ vidtv_tuner_get_signal_strength(struct dvb_frontend *fe, u16 *strength)
 	u32 i;
 
 	shift = vidtv_tuner_check_frequency_shift(fe);
+	if (shift < 0) {
+		tuner_dev->hw_state.lock_status = 0;
+		return 0;
+	}
 
 	switch (c->delivery_system) {
 	case SYS_DVBT:
@@ -224,10 +231,6 @@ vidtv_tuner_get_signal_strength(struct dvb_frontend *fe, u16 *strength)
 			*strength = cnr2qual[i].cnr_good;
 			return 0;
 		}
-		if (shift < 0) {	/* Channel not tuned */
-			*strength = 0;
-			return 0;
-		}
 		/*
 		 * Channel tuned at wrong frequency. Simulate that the
 		 * Carrier S/N ratio is not too good.
@@ -288,6 +291,7 @@ static int vidtv_tuner_set_params(struct dvb_frontend *fe)
 	struct vidtv_tuner_dev *tuner_dev = vidtv_tuner_get_dev(fe);
 	struct vidtv_tuner_config config  = tuner_dev->config;
 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+	s32 shift;
 
 	u32 min_freq = fe->ops.tuner_ops.info.frequency_min_hz;
 	u32 max_freq = fe->ops.tuner_ops.info.frequency_max_hz;
@@ -305,6 +309,13 @@ static int vidtv_tuner_set_params(struct dvb_frontend *fe)
 	tuner_dev->hw_state.lock_status = TUNER_STATUS_LOCKED;
 
 	msleep_interruptible(config.mock_tune_delay_msec);
+
+	shift = vidtv_tuner_check_frequency_shift(fe);
+	if (shift < 0) {
+		tuner_dev->hw_state.lock_status = 0;
+		return shift;
+	}
+
 	return 0;
 }
 
@@ -395,6 +406,7 @@ static int vidtv_tuner_i2c_probe(struct i2c_client *client,
 	       &vidtv_tuner_ops,
 	       sizeof(struct dvb_tuner_ops));
 
+	memcpy(&tuner_dev->config, config, sizeof(tuner_dev->config));
 	fe->tuner_priv = client;
 
 	return 0;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 05/11] media: vidtv: add an initial channel frequency
  2020-09-14  9:03 [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv Mauro Carvalho Chehab
                   ` (3 preceding siblings ...)
  2020-09-14  9:03 ` [PATCH RFC 04/11] media: vidtv: fix frequency tuning logic Mauro Carvalho Chehab
@ 2020-09-14  9:03 ` Mauro Carvalho Chehab
  2020-09-14  9:03 ` [PATCH RFC 06/11] media: vidtv: get rid of some endiannes nonsense Mauro Carvalho Chehab
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-14  9:03 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media

Use 474 MHz frequency for DVB-T/DVB-C, as this is the first
channel that it is valid on most places for DVB-T.

In the case of DVB-S, let's add Astra 19.2E initial
frequency at the scan files as the default, e. g. 12.5515 GHz.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/test-drivers/vidtv/vidtv_bridge.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_bridge.c b/drivers/media/test-drivers/vidtv/vidtv_bridge.c
index 270c183b1d67..cb32f82f88f9 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_bridge.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_bridge.c
@@ -47,17 +47,25 @@ static unsigned int mock_tune_delay_msec;
 module_param(mock_tune_delay_msec, uint, 0);
 MODULE_PARM_DESC(mock_tune_delay_msec, "Simulate a tune delay");
 
-static unsigned int vidtv_valid_dvb_t_freqs[NUM_VALID_TUNER_FREQS];
+static unsigned int vidtv_valid_dvb_t_freqs[NUM_VALID_TUNER_FREQS] = {
+	474000000
+};
+
 module_param_array(vidtv_valid_dvb_t_freqs, uint, NULL, 0);
 MODULE_PARM_DESC(vidtv_valid_dvb_t_freqs,
 		 "Valid DVB-T frequencies to simulate");
 
-static unsigned int vidtv_valid_dvb_c_freqs[NUM_VALID_TUNER_FREQS];
+static unsigned int vidtv_valid_dvb_c_freqs[NUM_VALID_TUNER_FREQS] = {
+	474000000
+};
+
 module_param_array(vidtv_valid_dvb_c_freqs, uint, NULL, 0);
 MODULE_PARM_DESC(vidtv_valid_dvb_c_freqs,
 		 "Valid DVB-C frequencies to simulate");
 
-static unsigned int vidtv_valid_dvb_s_freqs[NUM_VALID_TUNER_FREQS];
+static unsigned int vidtv_valid_dvb_s_freqs[NUM_VALID_TUNER_FREQS] = {
+	12551500
+};
 module_param_array(vidtv_valid_dvb_s_freqs, uint, NULL, 0);
 MODULE_PARM_DESC(vidtv_valid_dvb_s_freqs,
 		 "Valid DVB-C frequencies to simulate");
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 06/11] media: vidtv: get rid of some endiannes nonsense
  2020-09-14  9:03 [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv Mauro Carvalho Chehab
                   ` (4 preceding siblings ...)
  2020-09-14  9:03 ` [PATCH RFC 05/11] media: vidtv: add an initial channel frequency Mauro Carvalho Chehab
@ 2020-09-14  9:03 ` Mauro Carvalho Chehab
  2020-09-14 15:14   ` Daniel W. S. Almeida
  2020-09-14  9:03 ` [PATCH RFC 07/11] media: vidtv: remove a wrong endiannes check from s302m generator Mauro Carvalho Chehab
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 16+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-14  9:03 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media

Genmask is always highest order to low order. It doesn't make
any sense to make it depends on endiannes.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/test-drivers/vidtv/vidtv_psi.c | 32 --------------------
 1 file changed, 32 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_psi.c b/drivers/media/test-drivers/vidtv/vidtv_psi.c
index 761034d10d9d..b8b638244b1d 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_psi.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_psi.c
@@ -99,11 +99,7 @@ static inline u16 vidtv_psi_sdt_serv_get_desc_loop_len(struct vidtv_psi_table_sd
 	u16 mask;
 	u16 ret;
 
-	#if defined(__BIG_ENDIAN)
-	mask = GENMASK(0, 11);
-	#else
 	mask = GENMASK(11, 0);
-	#endif
 
 	ret = be16_to_cpu(s->bitfield) & mask;
 	return ret;
@@ -114,11 +110,7 @@ static inline u16 vidtv_psi_pmt_stream_get_desc_loop_len(struct vidtv_psi_table_
 	u16 mask;
 	u16 ret;
 
-	#if defined(__BIG_ENDIAN)
-	mask = GENMASK(0, 9);
-	#else
 	mask = GENMASK(9, 0);
-	#endif
 
 	ret = be16_to_cpu(s->bitfield2) & mask;
 	return ret;
@@ -129,11 +121,7 @@ static inline u16 vidtv_psi_pmt_get_desc_loop_len(struct vidtv_psi_table_pmt *p)
 	u16 mask;
 	u16 ret;
 
-	#if defined(__BIG_ENDIAN)
-	mask = GENMASK(0, 9);
-	#else
 	mask = GENMASK(9, 0);
-	#endif
 
 	ret = be16_to_cpu(p->bitfield2) & mask;
 	return ret;
@@ -144,11 +132,7 @@ static inline u16 vidtv_psi_get_sec_len(struct vidtv_psi_table_header *h)
 	u16 mask;
 	u16 ret;
 
-	#if defined(__BIG_ENDIAN)
-	mask = GENMASK(0, 11);
-	#else
 	mask = GENMASK(11, 0);
-	#endif
 
 	ret = be16_to_cpu(h->bitfield) & mask;
 	return ret;
@@ -159,11 +143,7 @@ inline u16 vidtv_psi_get_pat_program_pid(struct vidtv_psi_table_pat_program *p)
 	u16 mask;
 	u16 ret;
 
-	#if defined(__BIG_ENDIAN)
-	mask = GENMASK(0, 12);
-	#else
 	mask = GENMASK(12, 0);
-	#endif
 
 	ret = be16_to_cpu(p->bitfield) & mask;
 	return ret;
@@ -174,11 +154,7 @@ inline u16 vidtv_psi_pmt_stream_get_elem_pid(struct vidtv_psi_table_pmt_stream *
 	u16 mask;
 	u16 ret;
 
-	#if defined(__BIG_ENDIAN)
-	mask = GENMASK(0, 12);
-	#else
 	mask = GENMASK(12, 0);
-	#endif
 
 	ret = be16_to_cpu(s->bitfield) & mask;
 	return ret;
@@ -189,11 +165,7 @@ static inline void vidtv_psi_set_desc_loop_len(__be16 *bitfield, u16 new_len, u8
 	u16 mask;
 	__be16 new;
 
-	#if defined(__BIG_ENDIAN)
-	mask = GENMASK(desc_len_nbits, 15);
-	#else
 	mask = GENMASK(15, desc_len_nbits);
-	#endif
 
 	new = cpu_to_be16((be16_to_cpu(*bitfield) & mask) | new_len);
 	*bitfield = new;
@@ -205,11 +177,7 @@ static void vidtv_psi_set_sec_len(struct vidtv_psi_table_header *h, u16 new_len)
 	__be16 new;
 	u16 mask;
 
-	#if defined(__BIG_ENDIAN)
-	mask = GENMASK(13, 15);
-	#else
 	mask = GENMASK(15, 13);
-	#endif
 
 	new = cpu_to_be16((be16_to_cpu(h->bitfield) & mask) | new_len);
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 07/11] media: vidtv: remove a wrong endiannes check from s302m generator
  2020-09-14  9:03 [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv Mauro Carvalho Chehab
                   ` (5 preceding siblings ...)
  2020-09-14  9:03 ` [PATCH RFC 06/11] media: vidtv: get rid of some endiannes nonsense Mauro Carvalho Chehab
@ 2020-09-14  9:03 ` Mauro Carvalho Chehab
  2020-09-16 18:13     ` kernel test robot
  2020-09-14  9:03 ` [PATCH RFC 08/11] media: vidtv: properly initialize the internal state struct Mauro Carvalho Chehab
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 16+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-14  9:03 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media

The code there is already doing the right thing, as it uses
value & 0xff, value & 0xff00, which already ensures the
expected endiannes.

So, it doesn't make any sense to touch the order depending on
the CPU endiannes.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/test-drivers/vidtv/vidtv_s302m.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_s302m.c b/drivers/media/test-drivers/vidtv/vidtv_s302m.c
index 5ae2ede951eb..1bab2e231a55 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_s302m.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_s302m.c
@@ -352,14 +352,6 @@ static u32 vidtv_s302m_write_frame(struct vidtv_encoder *e,
 	f.data[3] = (sample & 0x0FF0) >>  4;
 	f.data[4] = (sample & 0xF000) >> 12;
 
-	#ifdef __LITTLE_ENDIAN
-	f.data[0] = reverse[f.data[0]];
-	f.data[1] = reverse[f.data[1]];
-	f.data[2] = reverse[f.data[2]];
-	f.data[3] = reverse[f.data[3]];
-	f.data[4] = reverse[f.data[4]];
-	#endif
-
 	nbytes += vidtv_memcpy(e->encoder_buf,
 			       e->encoder_buf_offset,
 			       VIDTV_S302M_BUF_SZ,
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 08/11] media: vidtv: properly initialize the internal state struct
  2020-09-14  9:03 [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv Mauro Carvalho Chehab
                   ` (6 preceding siblings ...)
  2020-09-14  9:03 ` [PATCH RFC 07/11] media: vidtv: remove a wrong endiannes check from s302m generator Mauro Carvalho Chehab
@ 2020-09-14  9:03 ` Mauro Carvalho Chehab
  2020-09-14  9:03 ` [PATCH RFC 09/11] media: vidtv: add basic support for DVBv5 stats Mauro Carvalho Chehab
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-14  9:03 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media

Right now, the config data passed from the bridge driver is
just ignored.

Also, let's initialize the delayed work at probing time.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/test-drivers/vidtv/vidtv_demod.c | 10 +++++-----
 drivers/media/test-drivers/vidtv/vidtv_demod.h |  1 -
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_demod.c b/drivers/media/test-drivers/vidtv/vidtv_demod.c
index 3eb48b4a9a6b..6199a4e06ff9 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_demod.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_demod.c
@@ -268,10 +268,6 @@ static int vidtv_demod_init(struct dvb_frontend *fe)
 	struct vidtv_demod_state *state = fe->demodulator_priv;
 	u32    tuner_status             = 0;
 
-	if (state->cold_start)
-		INIT_DELAYED_WORK(&state->poll_snr,
-				  &vidtv_demod_poll_snr_handler);
-
 	/*
 	 * At resume, start the snr poll thread only if it was suspended with
 	 * the thread running. Extra care should be taken here, as some tuner
@@ -288,7 +284,6 @@ static int vidtv_demod_init(struct dvb_frontend *fe)
 		state->poll_snr_thread_restart = false;
 	}
 
-	state->cold_start = false;
 	return 0;
 }
 
@@ -396,6 +391,7 @@ MODULE_DEVICE_TABLE(i2c, vidtv_demod_i2c_id_table);
 static int vidtv_demod_i2c_probe(struct i2c_client *client,
 				 const struct i2c_device_id *id)
 {
+	struct vidtv_tuner_config *config = client->dev.platform_data;
 	struct vidtv_demod_state *state;
 
 	/* allocate memory for the internal state */
@@ -408,6 +404,10 @@ static int vidtv_demod_i2c_probe(struct i2c_client *client,
 	       &vidtv_demod_ops,
 	       sizeof(struct dvb_frontend_ops));
 
+	memcpy(&state->config, config, sizeof(state->config));
+
+	INIT_DELAYED_WORK(&state->poll_snr, &vidtv_demod_poll_snr_handler);
+
 	state->frontend.demodulator_priv = state;
 	i2c_set_clientdata(client, state);
 
diff --git a/drivers/media/test-drivers/vidtv/vidtv_demod.h b/drivers/media/test-drivers/vidtv/vidtv_demod.h
index dfb36c515e4d..7f52a537935b 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_demod.h
+++ b/drivers/media/test-drivers/vidtv/vidtv_demod.h
@@ -66,7 +66,6 @@ struct vidtv_demod_state {
 	struct delayed_work poll_snr;
 	enum fe_status status;
 	u16 tuner_cnr;
-	bool cold_start;
 	bool poll_snr_thread_running;
 	bool poll_snr_thread_restart;
 };
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 09/11] media: vidtv: add basic support for DVBv5 stats
  2020-09-14  9:03 [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv Mauro Carvalho Chehab
                   ` (7 preceding siblings ...)
  2020-09-14  9:03 ` [PATCH RFC 08/11] media: vidtv: properly initialize the internal state struct Mauro Carvalho Chehab
@ 2020-09-14  9:03 ` Mauro Carvalho Chehab
  2020-09-14  9:03 ` [PATCH RFC 10/11] media: vidtv: get rid of the work queue Mauro Carvalho Chehab
  2020-09-14  9:03 ` [PATCH RFC 11/11] media: vidtv: increment byte and block counters Mauro Carvalho Chehab
  10 siblings, 0 replies; 16+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-14  9:03 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media

The current stats code is broken on so many ways. It ends
reporting 0 for signal strengh, and the work queue doesn't
run. If it would run, the code would crash.

Fix such issues and add the minimum stuff for DVBv5 stats.

Right now, only strength and cnr and UCB are implemented.
pre/post BER stats will always return zero.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 .../media/test-drivers/vidtv/vidtv_demod.c    | 185 ++++++++++++------
 .../media/test-drivers/vidtv/vidtv_tuner.c    |   2 +-
 2 files changed, 122 insertions(+), 65 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_demod.c b/drivers/media/test-drivers/vidtv/vidtv_demod.c
index 6199a4e06ff9..bfe63d7160f2 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_demod.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_demod.c
@@ -122,6 +122,74 @@ static const struct vidtv_demod_cnr_to_qual_s
 	return NULL; /* not found */
 }
 
+static void vidtv_clean_stats(struct dvb_frontend *fe)
+{
+	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+
+	/* Fill the length of each status counter */
+
+	/* Signal is always available */
+	c->strength.len = 1;
+	c->strength.stat[0].scale = FE_SCALE_DECIBEL;
+	c->strength.stat[0].svalue = 0;
+
+	/* Usually available only after Viterbi lock */
+	c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	c->cnr.stat[0].svalue = 0;
+	c->cnr.len = 1;
+
+	/* Those depends on full lock */
+	c->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	c->pre_bit_error.stat[0].uvalue = 0;
+	c->pre_bit_error.len = 1;
+	c->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	c->pre_bit_count.stat[0].uvalue = 0;
+	c->pre_bit_count.len = 1;
+	c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	c->post_bit_error.stat[0].uvalue = 0;
+	c->post_bit_error.len = 1;
+	c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	c->post_bit_count.stat[0].uvalue = 0;
+	c->post_bit_count.len = 1;
+	c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	c->block_error.stat[0].uvalue = 0;
+	c->block_error.len = 1;
+	c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	c->block_count.stat[0].uvalue = 0;
+	c->block_count.len = 1;
+}
+
+static void vidtv_demod_update_stats(struct dvb_frontend *fe)
+{
+	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+	struct vidtv_demod_state *state = fe->demodulator_priv;
+	u32 scale;
+
+	if (state->status & FE_HAS_LOCK) {
+		scale = FE_SCALE_COUNTER;
+		c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
+	} else {
+		scale = FE_SCALE_NOT_AVAILABLE;
+		c->cnr.stat[0].scale = scale;
+	}
+
+	c->pre_bit_error.stat[0].scale = scale;
+	c->pre_bit_count.stat[0].scale = scale;
+	c->post_bit_error.stat[0].scale = scale;
+	c->post_bit_count.stat[0].scale = scale;
+	c->block_error.stat[0].scale = scale;
+	c->block_count.stat[0].scale = scale;
+
+	/*
+	 * Add a 0.5% of randomness at the signal streangth and CNR,
+	 * and make them different, as we want to have something closer
+	 * to a real case scenario.
+	 */
+	c->strength.stat[0].svalue = state->tuner_cnr + prandom_u32_max(state->tuner_cnr / 50);
+	c->cnr.stat[0].svalue = state->tuner_cnr - prandom_u32_max(state->tuner_cnr / 50);
+
+}
+
 static void vidtv_demod_poll_snr_handler(struct work_struct *work)
 {
 	/*
@@ -133,33 +201,34 @@ static void vidtv_demod_poll_snr_handler(struct work_struct *work)
 	struct vidtv_demod_config *config;
 	u16 snr = 0;
 
-	state  = container_of(work, struct vidtv_demod_state, poll_snr.work);
+	state = container_of(work, struct vidtv_demod_state, poll_snr.work);
 	config = &state->config;
 
-	if (!state->frontend.ops.tuner_ops.get_rf_strength)
-		return;
-
-	state->frontend.ops.tuner_ops.get_rf_strength(&state->frontend, &snr);
-
+	/* Simulate random lost of signal due to a bad-tuned channel */
 	cnr2qual = vidtv_match_cnr_s(&state->frontend);
-	if (!cnr2qual)
-		return;
 
-	if (snr < cnr2qual->cnr_ok) {
-		/* eventually lose the TS lock */
-		if (prandom_u32_max(100) < config->drop_tslock_prob_on_low_snr)
-			state->status = 0;
-	} else {
-		/* recover if the signal improves */
-		if (prandom_u32_max(100) <
-		    config->recover_tslock_prob_on_good_snr)
-			state->status = FE_HAS_SIGNAL  |
-					FE_HAS_CARRIER |
-					FE_HAS_VITERBI |
-					FE_HAS_SYNC    |
-					FE_HAS_LOCK;
+	if (cnr2qual && state->tuner_cnr < cnr2qual->cnr_good &&
+	    state->frontend.ops.tuner_ops.get_rf_strength) {
+		state->frontend.ops.tuner_ops.get_rf_strength(&state->frontend, &snr);
+
+		if (snr < cnr2qual->cnr_ok) {
+			/* eventually lose the TS lock */
+			if (prandom_u32_max(100) < config->drop_tslock_prob_on_low_snr)
+				state->status = 0;
+		} else {
+			/* recover if the signal improves */
+			if (prandom_u32_max(100) <
+			    config->recover_tslock_prob_on_good_snr)
+				state->status = FE_HAS_SIGNAL  |
+						FE_HAS_CARRIER |
+						FE_HAS_VITERBI |
+						FE_HAS_SYNC    |
+						FE_HAS_LOCK;
+		}
 	}
 
+	vidtv_demod_update_stats(&state->frontend);
+
 	schedule_delayed_work(&state->poll_snr,
 			      msecs_to_jiffies(POLL_THRD_TIME));
 }
@@ -174,28 +243,13 @@ static int vidtv_demod_read_status(struct dvb_frontend *fe,
 	return 0;
 }
 
-static int vidtv_demod_read_ber(struct dvb_frontend *fe, u32 *ber)
-{
-	*ber = 0;
-	return 0;
-}
-
 static int vidtv_demod_read_signal_strength(struct dvb_frontend *fe,
 					    u16 *strength)
 {
-	*strength = 0;
-	return 0;
-}
+	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 
-static int vidtv_demod_read_snr(struct dvb_frontend *fe, u16 *snr)
-{
-	*snr = 0;
-	return 0;
-}
+	*strength = c->strength.stat[0].uvalue;
 
-static int vidtv_demod_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
-{
-	*ucblocks = 0;
 	return 0;
 }
 
@@ -216,38 +270,42 @@ static int vidtv_demod_get_frontend(struct dvb_frontend *fe,
 
 static int vidtv_demod_set_frontend(struct dvb_frontend *fe)
 {
-	struct vidtv_demod_state *state            = fe->demodulator_priv;
 	const struct vidtv_demod_cnr_to_qual_s *cnr2qual = NULL;
-	u32 tuner_status                        = 0;
+	struct vidtv_demod_state *state = fe->demodulator_priv;
+	u32 tuner_status = 0;
+	int ret;
 
-	if (fe->ops.tuner_ops.set_params) {
-		fe->ops.tuner_ops.set_params(fe);
+	if (!fe->ops.tuner_ops.set_params)
+		return 0;
 
-		/* store the CNR returned by the tuner */
-		fe->ops.tuner_ops.get_rf_strength(fe, &state->tuner_cnr);
+	fe->ops.tuner_ops.set_params(fe);
 
-		fe->ops.tuner_ops.get_status(fe, &tuner_status);
-		state->status = (state->tuner_cnr > 0) ?  FE_HAS_SIGNAL  |
-							  FE_HAS_CARRIER |
-							  FE_HAS_VITERBI |
-							  FE_HAS_SYNC    |
-							  FE_HAS_LOCK	 :
-							  0;
-		cnr2qual = vidtv_match_cnr_s(fe);
+	/* store the CNR returned by the tuner */
+	ret = fe->ops.tuner_ops.get_rf_strength(fe, &state->tuner_cnr);
+	if (ret < 0)
+		return ret;
 
-		/* signal isn't good: might lose the lock eventually */
-		if (tuner_status == TUNER_STATUS_LOCKED &&
-		    state->tuner_cnr < cnr2qual->cnr_good) {
-			schedule_delayed_work(&state->poll_snr,
-					      msecs_to_jiffies(POLL_THRD_TIME));
+	fe->ops.tuner_ops.get_status(fe, &tuner_status);
+	state->status = (state->tuner_cnr > 0) ?  FE_HAS_SIGNAL  |
+						    FE_HAS_CARRIER |
+						    FE_HAS_VITERBI |
+						    FE_HAS_SYNC    |
+						    FE_HAS_LOCK	 :
+						    0;
+	cnr2qual = vidtv_match_cnr_s(fe);
 
-			state->poll_snr_thread_running = true;
-		}
+	vidtv_demod_update_stats(fe);
 
-		if (fe->ops.i2c_gate_ctrl)
-			fe->ops.i2c_gate_ctrl(fe, 0);
+	if (state->tuner_cnr > 0) {
+		schedule_delayed_work(&state->poll_snr,
+					msecs_to_jiffies(POLL_THRD_TIME));
+
+		state->poll_snr_thread_running = true;
 	}
 
+	if (fe->ops.i2c_gate_ctrl)
+		fe->ops.i2c_gate_ctrl(fe, 0);
+
 	return 0;
 }
 
@@ -372,10 +430,7 @@ static const struct dvb_frontend_ops vidtv_demod_ops = {
 	.get_frontend = vidtv_demod_get_frontend,
 
 	.read_status          = vidtv_demod_read_status,
-	.read_ber             = vidtv_demod_read_ber,
 	.read_signal_strength = vidtv_demod_read_signal_strength,
-	.read_snr             = vidtv_demod_read_snr,
-	.read_ucblocks        = vidtv_demod_read_ucblocks,
 
 	/* For DVB-S/S2 */
 	.set_voltage = vidtv_demod_set_voltage,
@@ -411,6 +466,8 @@ static int vidtv_demod_i2c_probe(struct i2c_client *client,
 	state->frontend.demodulator_priv = state;
 	i2c_set_clientdata(client, state);
 
+	vidtv_clean_stats(&state->frontend);
+
 	return 0;
 }
 
diff --git a/drivers/media/test-drivers/vidtv/vidtv_tuner.c b/drivers/media/test-drivers/vidtv/vidtv_tuner.c
index 0f397fe12989..2956e2339996 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_tuner.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_tuner.c
@@ -245,7 +245,7 @@ vidtv_tuner_get_signal_strength(struct dvb_frontend *fe, u16 *strength)
 	 * do a linear interpolation between 34dB and 10dB if we can't
 	 * match against the table
 	 */
-	*strength = 34 - 24 * shift / 100;
+	*strength = 34000 - 24000 * shift / 100;
 	return 0;
 }
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 10/11] media: vidtv: get rid of the work queue
  2020-09-14  9:03 [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv Mauro Carvalho Chehab
                   ` (8 preceding siblings ...)
  2020-09-14  9:03 ` [PATCH RFC 09/11] media: vidtv: add basic support for DVBv5 stats Mauro Carvalho Chehab
@ 2020-09-14  9:03 ` Mauro Carvalho Chehab
  2020-09-14  9:03 ` [PATCH RFC 11/11] media: vidtv: increment byte and block counters Mauro Carvalho Chehab
  10 siblings, 0 replies; 16+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-14  9:03 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media

The dvb_frontend will already call status periodically, when
a channel is tuned. So, no need to have a work queue for
such purpose.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 .../media/test-drivers/vidtv/vidtv_demod.c    | 77 ++-----------------
 .../media/test-drivers/vidtv/vidtv_demod.h    |  3 -
 2 files changed, 6 insertions(+), 74 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_demod.c b/drivers/media/test-drivers/vidtv/vidtv_demod.c
index bfe63d7160f2..c54c88cac84f 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_demod.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_demod.c
@@ -190,26 +190,21 @@ static void vidtv_demod_update_stats(struct dvb_frontend *fe)
 
 }
 
-static void vidtv_demod_poll_snr_handler(struct work_struct *work)
+static int vidtv_demod_read_status(struct dvb_frontend *fe,
+				   enum fe_status *status)
 {
-	/*
-	 * periodically check the signal quality and eventually
-	 * lose the TS lock if it dips too low
-	 */
-	struct vidtv_demod_state *state;
+	struct vidtv_demod_state *state = fe->demodulator_priv;
 	const struct vidtv_demod_cnr_to_qual_s *cnr2qual = NULL;
-	struct vidtv_demod_config *config;
+	struct vidtv_demod_config *config = &state->config;
 	u16 snr = 0;
 
-	state = container_of(work, struct vidtv_demod_state, poll_snr.work);
-	config = &state->config;
-
 	/* Simulate random lost of signal due to a bad-tuned channel */
 	cnr2qual = vidtv_match_cnr_s(&state->frontend);
 
 	if (cnr2qual && state->tuner_cnr < cnr2qual->cnr_good &&
 	    state->frontend.ops.tuner_ops.get_rf_strength) {
-		state->frontend.ops.tuner_ops.get_rf_strength(&state->frontend, &snr);
+		state->frontend.ops.tuner_ops.get_rf_strength(&state->frontend,
+							      &snr);
 
 		if (snr < cnr2qual->cnr_ok) {
 			/* eventually lose the TS lock */
@@ -229,15 +224,6 @@ static void vidtv_demod_poll_snr_handler(struct work_struct *work)
 
 	vidtv_demod_update_stats(&state->frontend);
 
-	schedule_delayed_work(&state->poll_snr,
-			      msecs_to_jiffies(POLL_THRD_TIME));
-}
-
-static int vidtv_demod_read_status(struct dvb_frontend *fe,
-				   enum fe_status *status)
-{
-	struct vidtv_demod_state *state = fe->demodulator_priv;
-
 	*status = state->status;
 
 	return 0;
@@ -296,55 +282,12 @@ static int vidtv_demod_set_frontend(struct dvb_frontend *fe)
 
 	vidtv_demod_update_stats(fe);
 
-	if (state->tuner_cnr > 0) {
-		schedule_delayed_work(&state->poll_snr,
-					msecs_to_jiffies(POLL_THRD_TIME));
-
-		state->poll_snr_thread_running = true;
-	}
-
 	if (fe->ops.i2c_gate_ctrl)
 		fe->ops.i2c_gate_ctrl(fe, 0);
 
 	return 0;
 }
 
-static int vidtv_demod_sleep(struct dvb_frontend *fe)
-{
-	struct vidtv_demod_state *state = fe->demodulator_priv;
-
-	if (state->poll_snr_thread_running) {
-		cancel_delayed_work_sync(&state->poll_snr);
-		state->poll_snr_thread_running = false;
-		state->poll_snr_thread_restart = true;
-	}
-	return 0;
-}
-
-static int vidtv_demod_init(struct dvb_frontend *fe)
-{
-	struct vidtv_demod_state *state = fe->demodulator_priv;
-	u32    tuner_status             = 0;
-
-	/*
-	 * At resume, start the snr poll thread only if it was suspended with
-	 * the thread running. Extra care should be taken here, as some tuner
-	 * status change might happen at resume time (for example, due to an
-	 * ioctl syscall to set_frontend, or due to a release syscall).
-	 */
-	fe->ops.tuner_ops.get_status(fe, &tuner_status);
-
-	if (tuner_status == TUNER_STATUS_LOCKED &&
-	    state->poll_snr_thread_restart) {
-		schedule_delayed_work(&state->poll_snr,
-				      msecs_to_jiffies(POLL_THRD_TIME));
-
-		state->poll_snr_thread_restart = false;
-	}
-
-	return 0;
-}
-
 /*
  * NOTE:
  * This is implemented here just to be used as an example for real
@@ -375,9 +318,6 @@ static void vidtv_demod_release(struct dvb_frontend *fe)
 {
 	struct vidtv_demod_state *state = fe->demodulator_priv;
 
-	if (state->poll_snr_thread_running)
-		cancel_delayed_work_sync(&state->poll_snr);
-
 	kfree(state);
 }
 
@@ -423,9 +363,6 @@ static const struct dvb_frontend_ops vidtv_demod_ops = {
 
 	.release = vidtv_demod_release,
 
-	.init  = vidtv_demod_init,
-	.sleep = vidtv_demod_sleep,
-
 	.set_frontend = vidtv_demod_set_frontend,
 	.get_frontend = vidtv_demod_get_frontend,
 
@@ -461,8 +398,6 @@ static int vidtv_demod_i2c_probe(struct i2c_client *client,
 
 	memcpy(&state->config, config, sizeof(state->config));
 
-	INIT_DELAYED_WORK(&state->poll_snr, &vidtv_demod_poll_snr_handler);
-
 	state->frontend.demodulator_priv = state;
 	i2c_set_clientdata(client, state);
 
diff --git a/drivers/media/test-drivers/vidtv/vidtv_demod.h b/drivers/media/test-drivers/vidtv/vidtv_demod.h
index 7f52a537935b..87651b0193e6 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_demod.h
+++ b/drivers/media/test-drivers/vidtv/vidtv_demod.h
@@ -63,10 +63,7 @@ struct vidtv_demod_config {
 struct vidtv_demod_state {
 	struct dvb_frontend frontend;
 	struct vidtv_demod_config config;
-	struct delayed_work poll_snr;
 	enum fe_status status;
 	u16 tuner_cnr;
-	bool poll_snr_thread_running;
-	bool poll_snr_thread_restart;
 };
 #endif // VIDTV_DEMOD_H
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 11/11] media: vidtv: increment byte and block counters
  2020-09-14  9:03 [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv Mauro Carvalho Chehab
                   ` (9 preceding siblings ...)
  2020-09-14  9:03 ` [PATCH RFC 10/11] media: vidtv: get rid of the work queue Mauro Carvalho Chehab
@ 2020-09-14  9:03 ` Mauro Carvalho Chehab
  10 siblings, 0 replies; 16+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-14  9:03 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media

Add support for incrementing DVBv5 stats for block counters
and post/pre BER byte counts.

For now, the errors won't be incremented yet.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/test-drivers/vidtv/vidtv_bridge.c |  2 +-
 drivers/media/test-drivers/vidtv/vidtv_bridge.h |  3 +++
 drivers/media/test-drivers/vidtv/vidtv_mux.c    | 16 +++++++++++++++-
 drivers/media/test-drivers/vidtv/vidtv_mux.h    |  6 +++++-
 4 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_bridge.c b/drivers/media/test-drivers/vidtv/vidtv_bridge.c
index cb32f82f88f9..108e7937e9c1 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_bridge.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_bridge.c
@@ -172,7 +172,7 @@ static int vidtv_start_streaming(struct vidtv_dvb *dvb)
 	mux_args.priv                        = dvb;
 
 	dvb->streaming = true;
-	dvb->mux = vidtv_mux_init(dev, mux_args);
+	dvb->mux = vidtv_mux_init(dvb->fe[0], dev, mux_args);
 	vidtv_mux_start_thread(dvb->mux);
 
 	dev_dbg_ratelimited(dev, "Started streaming\n");
diff --git a/drivers/media/test-drivers/vidtv/vidtv_bridge.h b/drivers/media/test-drivers/vidtv/vidtv_bridge.h
index fd65f9838b10..78fe8472fa37 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_bridge.h
+++ b/drivers/media/test-drivers/vidtv/vidtv_bridge.h
@@ -12,6 +12,9 @@
 #ifndef VIDTV_BRIDGE_H
 #define VIDTV_BRIDGE_H
 
+/*
+ * For now, only one frontend is supported. See vidtv_start_streaming()
+ */
 #define NUM_FE 1
 
 #include <linux/i2c.h>
diff --git a/drivers/media/test-drivers/vidtv/vidtv_mux.c b/drivers/media/test-drivers/vidtv/vidtv_mux.c
index d1db9dc6dc89..5d1a275d504b 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_mux.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_mux.c
@@ -381,6 +381,7 @@ static void vidtv_mux_tick(struct work_struct *work)
 	struct vidtv_mux *m = container_of(work,
 					   struct vidtv_mux,
 					   mpeg_thread);
+	struct dtv_frontend_properties *c = &m->fe->dtv_property_cache;
 	u32 nbytes;
 	u32 npkts;
 
@@ -411,6 +412,17 @@ static void vidtv_mux_tick(struct work_struct *work)
 
 		vidtv_mux_clear(m);
 
+		/*
+		 * Update bytes and packet counts at DVBv5 stats
+		 *
+		 * For now, both pre and post bit counts are identical,
+		 * but post BER count can be lower than pre BER, if the error
+		 * correction logic discards packages.
+		 */
+		c->pre_bit_count.stat[0].uvalue = nbytes;
+		c->post_bit_count.stat[0].uvalue = nbytes;
+		c->block_count.stat[0].uvalue += npkts;
+
 		usleep_range(VIDTV_SLEEP_USECS, VIDTV_MAX_SLEEP_USECS);
 	}
 }
@@ -435,12 +447,14 @@ void vidtv_mux_stop_thread(struct vidtv_mux *m)
 	}
 }
 
-struct vidtv_mux *vidtv_mux_init(struct device *dev,
+struct vidtv_mux *vidtv_mux_init(struct dvb_frontend *fe,
+				 struct device *dev,
 				 struct vidtv_mux_init_args args)
 {
 	struct vidtv_mux *m = kzalloc(sizeof(*m), GFP_KERNEL);
 
 	m->dev = dev;
+	m->fe = fe;
 	m->timing.pcr_period_usecs = args.pcr_period_usecs;
 	m->timing.si_period_usecs  = args.si_period_usecs;
 
diff --git a/drivers/media/test-drivers/vidtv/vidtv_mux.h b/drivers/media/test-drivers/vidtv/vidtv_mux.h
index 67de85fd50aa..2caa60623e97 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_mux.h
+++ b/drivers/media/test-drivers/vidtv/vidtv_mux.h
@@ -18,6 +18,8 @@
 #include <linux/types.h>
 #include <linux/hashtable.h>
 #include <linux/workqueue.h>
+#include <media/dvb_frontend.h>
+
 #include "vidtv_psi.h"
 
 /**
@@ -100,6 +102,7 @@ struct vidtv_mux_pid_ctx {
  * @priv: Private data.
  */
 struct vidtv_mux {
+	struct dvb_frontend *fe;
 	struct device *dev;
 
 	struct vidtv_mux_timing timing;
@@ -153,7 +156,8 @@ struct vidtv_mux_init_args {
 	void *priv;
 };
 
-struct vidtv_mux *vidtv_mux_init(struct device *dev,
+struct vidtv_mux *vidtv_mux_init(struct dvb_frontend *fe,
+				 struct device *dev,
 				 struct vidtv_mux_init_args args);
 void vidtv_mux_destroy(struct vidtv_mux *m);
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH RFC 06/11] media: vidtv: get rid of some endiannes nonsense
  2020-09-14  9:03 ` [PATCH RFC 06/11] media: vidtv: get rid of some endiannes nonsense Mauro Carvalho Chehab
@ 2020-09-14 15:14   ` Daniel W. S. Almeida
  2020-09-15 11:49     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 16+ messages in thread
From: Daniel W. S. Almeida @ 2020-09-14 15:14 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: linux-kernel, linux-media

Hi Mauro,

> Genmask is always highest order to low order. It doesn't make
> any sense to make it depends on endiannes.
> 

I added these #ifdefs due to this:

https://lwn.net/Articles/741762/

i.e.

Fields to access are specified as GENMASK() values - an N-bit field
starting at bit #M is encoded as GENMASK(M + N - 1, N).  Note that
bit numbers refer to endianness of the object we are working with -
e.g. GENMASK(11, 0) in __be16 refers to the second byte and the lower
4 bits of the first byte.  In __le16 it would refer to the first byte
and the lower 4 bits of the second byte, etc.

I am not 100% sure, but maybe we actually need them? 

- Daniel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH RFC 06/11] media: vidtv: get rid of some endiannes nonsense
  2020-09-14 15:14   ` Daniel W. S. Almeida
@ 2020-09-15 11:49     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 16+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-15 11:49 UTC (permalink / raw)
  To: Daniel W. S. Almeida; +Cc: linux-kernel, linux-media

Hi Daniel,

Em Mon, 14 Sep 2020 12:14:38 -0300
"Daniel W. S. Almeida" <dwlsalmeida@gmail.com> escreveu:

> Hi Mauro,
> 
> > Genmask is always highest order to low order. It doesn't make
> > any sense to make it depends on endiannes.
> >   
> 
> I added these #ifdefs due to this:
> 
> https://lwn.net/Articles/741762/
> 
> i.e.
> 
> Fields to access are specified as GENMASK() values - an N-bit field
> starting at bit #M is encoded as GENMASK(M + N - 1, N).  Note that
> bit numbers refer to endianness of the object we are working with -
> e.g. GENMASK(11, 0) in __be16 refers to the second byte and the lower
> 4 bits of the first byte.  In __le16 it would refer to the first byte
> and the lower 4 bits of the second byte, etc.
> 
> I am not 100% sure, but maybe we actually need them? 

By looking at the changes you did with regards to bitfields,
it sounds that you didn't quite get how BE/LE works.

Basically, if the CPU needs to store a value (like 0x8001) on some 
place, it will store two values: 0x80 and 0x01. Depending on the
endiannes, either 0x80 or 0x01 will be stored first. See:

	https://en.wikipedia.org/wiki/Endianness

In any case, when you do something like:

	mask = GENMASK(11, 0);
	ret = be16_to_cpu(s->bitfield) & mask;

The be16_to_cpu() will ensure that the bits will be at the
position expected by the CPU endiannes. So, no need to check
for __BIG_ENDIAN or __LITTLE_ENDIAN when be*_to_cpu() macros 
are used.

Please also notice that, when there's just one byte to be
stored (e. g. 8 bits), the endiannes won't matter, as the bits 
will still be stored at the same way. that's why there's no
be8_to_cpu() or cpu_to_be8() macros.

Thanks,
Mauro

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH RFC 07/11] media: vidtv: remove a wrong endiannes check from s302m generator
  2020-09-14  9:03 ` [PATCH RFC 07/11] media: vidtv: remove a wrong endiannes check from s302m generator Mauro Carvalho Chehab
@ 2020-09-16 18:13     ` kernel test robot
  0 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2020-09-16 18:13 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: kbuild-all, clang-built-linux, linux-media

[-- Attachment #1: Type: text/plain, Size: 5025 bytes --]

Hi Mauro,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linuxtv-media/master]
[cannot apply to v5.9-rc5 next-20200916]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mauro-Carvalho-Chehab/Solve-some-issues-and-do-some-improvements-at-vidtv/20200914-170723
base:   git://linuxtv.org/media_tree.git master
config: x86_64-randconfig-a014-20200916 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 9e3842d60351f986d77dfe0a94f76e4fd895f188)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/media/test-drivers/vidtv/vidtv_s302m.c:41:17: warning: unused variable 'reverse' [-Wunused-const-variable]
   static const u8 reverse[256] = {
                   ^
   1 warning generated.

# https://github.com/0day-ci/linux/commit/f86488b9fb99bd7755b01f7881fe3fbb857c175a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mauro-Carvalho-Chehab/Solve-some-issues-and-do-some-improvements-at-vidtv/20200914-170723
git checkout f86488b9fb99bd7755b01f7881fe3fbb857c175a
vim +/reverse +41 drivers/media/test-drivers/vidtv/vidtv_s302m.c

f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  40  
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21 @41  static const u8 reverse[256] = {
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  42  	/* from ffmpeg */
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  43  	0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  44  	0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  45  	0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 0x04, 0x84, 0x44, 0xC4,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  46  	0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  47  	0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  48  	0x3C, 0xBC, 0x7C, 0xFC, 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  49  	0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, 0x0A, 0x8A, 0x4A, 0xCA,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  50  	0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  51  	0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  52  	0x36, 0xB6, 0x76, 0xF6, 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  53  	0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, 0x01, 0x81, 0x41, 0xC1,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  54  	0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  55  	0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  56  	0x39, 0xB9, 0x79, 0xF9, 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  57  	0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, 0x0D, 0x8D, 0x4D, 0xCD,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  58  	0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  59  	0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  60  	0x33, 0xB3, 0x73, 0xF3, 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  61  	0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 0x07, 0x87, 0x47, 0xC7,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  62  	0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  63  	0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  64  	0x3F, 0xBF, 0x7F, 0xFF,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  65  };
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  66  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 36122 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH RFC 07/11] media: vidtv: remove a wrong endiannes check from s302m generator
@ 2020-09-16 18:13     ` kernel test robot
  0 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2020-09-16 18:13 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 5095 bytes --]

Hi Mauro,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linuxtv-media/master]
[cannot apply to v5.9-rc5 next-20200916]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mauro-Carvalho-Chehab/Solve-some-issues-and-do-some-improvements-at-vidtv/20200914-170723
base:   git://linuxtv.org/media_tree.git master
config: x86_64-randconfig-a014-20200916 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 9e3842d60351f986d77dfe0a94f76e4fd895f188)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/media/test-drivers/vidtv/vidtv_s302m.c:41:17: warning: unused variable 'reverse' [-Wunused-const-variable]
   static const u8 reverse[256] = {
                   ^
   1 warning generated.

# https://github.com/0day-ci/linux/commit/f86488b9fb99bd7755b01f7881fe3fbb857c175a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mauro-Carvalho-Chehab/Solve-some-issues-and-do-some-improvements-at-vidtv/20200914-170723
git checkout f86488b9fb99bd7755b01f7881fe3fbb857c175a
vim +/reverse +41 drivers/media/test-drivers/vidtv/vidtv_s302m.c

f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  40  
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21 @41  static const u8 reverse[256] = {
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  42  	/* from ffmpeg */
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  43  	0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  44  	0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  45  	0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 0x04, 0x84, 0x44, 0xC4,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  46  	0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  47  	0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  48  	0x3C, 0xBC, 0x7C, 0xFC, 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  49  	0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, 0x0A, 0x8A, 0x4A, 0xCA,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  50  	0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  51  	0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  52  	0x36, 0xB6, 0x76, 0xF6, 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  53  	0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, 0x01, 0x81, 0x41, 0xC1,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  54  	0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  55  	0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  56  	0x39, 0xB9, 0x79, 0xF9, 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  57  	0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, 0x0D, 0x8D, 0x4D, 0xCD,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  58  	0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  59  	0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  60  	0x33, 0xB3, 0x73, 0xF3, 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  61  	0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 0x07, 0x87, 0x47, 0xC7,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  62  	0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  63  	0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  64  	0x3F, 0xBF, 0x7F, 0xFF,
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  65  };
f90cf6079bf6798 Daniel W. S. Almeida 2020-08-21  66  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 36122 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2020-09-16 18:21 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-14  9:03 [PATCH RFC 00/11] Solve some issues and do some improvements at vidtv Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 01/11] media: vidtv: add modaliases for the bridge driver Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 02/11] media: vidtv: prefer using dev_foo() instead of pr_foo() Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 03/11] media: vidtv: fix 32-bit warnings Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 04/11] media: vidtv: fix frequency tuning logic Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 05/11] media: vidtv: add an initial channel frequency Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 06/11] media: vidtv: get rid of some endiannes nonsense Mauro Carvalho Chehab
2020-09-14 15:14   ` Daniel W. S. Almeida
2020-09-15 11:49     ` Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 07/11] media: vidtv: remove a wrong endiannes check from s302m generator Mauro Carvalho Chehab
2020-09-16 18:13   ` kernel test robot
2020-09-16 18:13     ` kernel test robot
2020-09-14  9:03 ` [PATCH RFC 08/11] media: vidtv: properly initialize the internal state struct Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 09/11] media: vidtv: add basic support for DVBv5 stats Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 10/11] media: vidtv: get rid of the work queue Mauro Carvalho Chehab
2020-09-14  9:03 ` [PATCH RFC 11/11] media: vidtv: increment byte and block counters Mauro Carvalho Chehab

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.