* [PATCH 1/4] soc/fsl/qe: qe.c: drop useless static qualifier
2019-02-28 10:30 ` [PATCH 0/4] soc/fsl/qe: qe.c: cleanups and support for MPC8309 Rasmus Villemoes
@ 2019-02-28 10:30 ` Rasmus Villemoes
2019-02-28 10:30 ` [PATCH 2/4] soc/fsl/qe: qe.c: reduce static memory footprint by 1.7K Rasmus Villemoes
` (2 subsequent siblings)
3 siblings, 0 replies; 13+ messages in thread
From: Rasmus Villemoes @ 2019-02-28 10:30 UTC (permalink / raw)
To: Qiang Zhao, Leo Li; +Cc: Scott Wood, linux-kernel, Timur Tabi, Rasmus Villemoes
The local variable snum_init has no reason to have static storage duration.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
drivers/soc/fsl/qe/qe.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c
index 2ef6fc6487c1..4b6aa6b3b685 100644
--- a/drivers/soc/fsl/qe/qe.c
+++ b/drivers/soc/fsl/qe/qe.c
@@ -306,7 +306,7 @@ static void qe_snums_init(void)
0x28, 0x29, 0x38, 0x39, 0x48, 0x49, 0x58, 0x59,
0x68, 0x69, 0x78, 0x79, 0x80, 0x81,
};
- static const u8 *snum_init;
+ const u8 *snum_init;
qe_num_of_snum = qe_get_num_of_snums();
--
2.20.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/4] soc/fsl/qe: qe.c: reduce static memory footprint by 1.7K
2019-02-28 10:30 ` [PATCH 0/4] soc/fsl/qe: qe.c: cleanups and support for MPC8309 Rasmus Villemoes
2019-02-28 10:30 ` [PATCH 1/4] soc/fsl/qe: qe.c: drop useless static qualifier Rasmus Villemoes
@ 2019-02-28 10:30 ` Rasmus Villemoes
2019-02-28 10:30 ` [PATCH 3/4] soc/fsl/qe: qe.c: introduce qe_get_device_node helper Rasmus Villemoes
2019-02-28 10:30 ` [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property Rasmus Villemoes
3 siblings, 0 replies; 13+ messages in thread
From: Rasmus Villemoes @ 2019-02-28 10:30 UTC (permalink / raw)
To: Qiang Zhao, Leo Li; +Cc: Scott Wood, linux-kernel, Timur Tabi, Rasmus Villemoes
The current array of struct qe_snum use 256*4 bytes for just keeping
track of the free/used state of each index, and the struct layout
means there's another 768 bytes of padding. If we just unzip that
structure, the array of snum values just use 256 bytes, while the
free/inuse state can be tracked in a 32 byte bitmap.
So this reduces the .data footprint by 1760 bytes. It also serves as
preparation for introducing another DT binding for specifying the snum
values.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
drivers/soc/fsl/qe/qe.c | 37 ++++++++++++-------------------------
1 file changed, 12 insertions(+), 25 deletions(-)
diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c
index 4b6aa6b3b685..9b9737a583ef 100644
--- a/drivers/soc/fsl/qe/qe.c
+++ b/drivers/soc/fsl/qe/qe.c
@@ -14,6 +14,7 @@
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
+#include <linux/bitmap.h>
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/kernel.h>
@@ -43,25 +44,14 @@ static DEFINE_SPINLOCK(qe_lock);
DEFINE_SPINLOCK(cmxgcr_lock);
EXPORT_SYMBOL(cmxgcr_lock);
-/* QE snum state */
-enum qe_snum_state {
- QE_SNUM_STATE_USED,
- QE_SNUM_STATE_FREE
-};
-
-/* QE snum */
-struct qe_snum {
- u8 num;
- enum qe_snum_state state;
-};
-
/* We allocate this here because it is used almost exclusively for
* the communication processor devices.
*/
struct qe_immap __iomem *qe_immr;
EXPORT_SYMBOL(qe_immr);
-static struct qe_snum snums[QE_NUM_OF_SNUM]; /* Dynamically allocated SNUMs */
+static u8 snums[QE_NUM_OF_SNUM]; /* Dynamically allocated SNUMs */
+static DECLARE_BITMAP(snum_state, QE_NUM_OF_SNUM);
static unsigned int qe_num_of_snum;
static phys_addr_t qebase = -1;
@@ -308,6 +298,7 @@ static void qe_snums_init(void)
};
const u8 *snum_init;
+ bitmap_zero(snum_state, QE_NUM_OF_SNUM);
qe_num_of_snum = qe_get_num_of_snums();
if (qe_num_of_snum == 76)
@@ -315,10 +306,8 @@ static void qe_snums_init(void)
else
snum_init = snum_init_46;
- for (i = 0; i < qe_num_of_snum; i++) {
- snums[i].num = snum_init[i];
- snums[i].state = QE_SNUM_STATE_FREE;
- }
+ for (i = 0; i < qe_num_of_snum; i++)
+ snums[i] = snum_init[i];
}
int qe_get_snum(void)
@@ -328,12 +317,10 @@ int qe_get_snum(void)
int i;
spin_lock_irqsave(&qe_lock, flags);
- for (i = 0; i < qe_num_of_snum; i++) {
- if (snums[i].state == QE_SNUM_STATE_FREE) {
- snums[i].state = QE_SNUM_STATE_USED;
- snum = snums[i].num;
- break;
- }
+ i = find_first_zero_bit(snum_state, qe_num_of_snum);
+ if (i < qe_num_of_snum) {
+ set_bit(i, snum_state);
+ snum = snums[i];
}
spin_unlock_irqrestore(&qe_lock, flags);
@@ -346,8 +333,8 @@ void qe_put_snum(u8 snum)
int i;
for (i = 0; i < qe_num_of_snum; i++) {
- if (snums[i].num == snum) {
- snums[i].state = QE_SNUM_STATE_FREE;
+ if (snums[i] == snum) {
+ clear_bit(i, snum_state);
break;
}
}
--
2.20.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 3/4] soc/fsl/qe: qe.c: introduce qe_get_device_node helper
2019-02-28 10:30 ` [PATCH 0/4] soc/fsl/qe: qe.c: cleanups and support for MPC8309 Rasmus Villemoes
2019-02-28 10:30 ` [PATCH 1/4] soc/fsl/qe: qe.c: drop useless static qualifier Rasmus Villemoes
2019-02-28 10:30 ` [PATCH 2/4] soc/fsl/qe: qe.c: reduce static memory footprint by 1.7K Rasmus Villemoes
@ 2019-02-28 10:30 ` Rasmus Villemoes
2019-02-28 10:30 ` [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property Rasmus Villemoes
3 siblings, 0 replies; 13+ messages in thread
From: Rasmus Villemoes @ 2019-02-28 10:30 UTC (permalink / raw)
To: Qiang Zhao, Leo Li; +Cc: Scott Wood, linux-kernel, Timur Tabi, Rasmus Villemoes
The 'try of_find_compatible_node(NULL, NULL, "fsl,qe"), fall back to
of_find_node_by_type(NULL, "qe")' pattern is repeated five
times. Factor it into a common helper.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
drivers/soc/fsl/qe/qe.c | 71 +++++++++++++++++------------------------
1 file changed, 29 insertions(+), 42 deletions(-)
diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c
index 9b9737a583ef..71beeb72eee4 100644
--- a/drivers/soc/fsl/qe/qe.c
+++ b/drivers/soc/fsl/qe/qe.c
@@ -56,6 +56,20 @@ static unsigned int qe_num_of_snum;
static phys_addr_t qebase = -1;
+static struct device_node *qe_get_device_node(void)
+{
+ struct device_node *qe;
+
+ /*
+ * Newer device trees have an "fsl,qe" compatible property for the QE
+ * node, but we still need to support older device trees.
+ */
+ qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
+ if (qe)
+ return qe;
+ return of_find_node_by_type(NULL, "qe");
+}
+
static phys_addr_t get_qe_base(void)
{
struct device_node *qe;
@@ -65,12 +79,9 @@ static phys_addr_t get_qe_base(void)
if (qebase != -1)
return qebase;
- qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
- if (!qe) {
- qe = of_find_node_by_type(NULL, "qe");
- if (!qe)
- return qebase;
- }
+ qe = qe_get_device_node();
+ if (!qe)
+ return qebase;
ret = of_address_to_resource(qe, 0, &res);
if (!ret)
@@ -164,12 +175,9 @@ unsigned int qe_get_brg_clk(void)
if (brg_clk)
return brg_clk;
- qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
- if (!qe) {
- qe = of_find_node_by_type(NULL, "qe");
- if (!qe)
- return brg_clk;
- }
+ qe = qe_get_device_node();
+ if (!qe)
+ return brg_clk;
prop = of_get_property(qe, "brg-frequency", &size);
if (prop && size == sizeof(*prop))
@@ -563,16 +571,9 @@ struct qe_firmware_info *qe_get_firmware_info(void)
initialized = 1;
- /*
- * Newer device trees have an "fsl,qe" compatible property for the QE
- * node, but we still need to support older device trees.
- */
- qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
- if (!qe) {
- qe = of_find_node_by_type(NULL, "qe");
- if (!qe)
- return NULL;
- }
+ qe = qe_get_device_node();
+ if (!qe)
+ return NULL;
/* Find the 'firmware' child node */
for_each_child_of_node(qe, fw) {
@@ -622,16 +623,9 @@ unsigned int qe_get_num_of_risc(void)
unsigned int num_of_risc = 0;
const u32 *prop;
- qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
- if (!qe) {
- /* Older devices trees did not have an "fsl,qe"
- * compatible property, so we need to look for
- * the QE node by name.
- */
- qe = of_find_node_by_type(NULL, "qe");
- if (!qe)
- return num_of_risc;
- }
+ qe = qe_get_device_node();
+ if (!qe)
+ return num_of_risc;
prop = of_get_property(qe, "fsl,qe-num-riscs", &size);
if (prop && size == sizeof(*prop))
@@ -651,16 +645,9 @@ unsigned int qe_get_num_of_snums(void)
const u32 *prop;
num_of_snums = 28; /* The default number of snum for threads is 28 */
- qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
- if (!qe) {
- /* Older devices trees did not have an "fsl,qe"
- * compatible property, so we need to look for
- * the QE node by name.
- */
- qe = of_find_node_by_type(NULL, "qe");
- if (!qe)
- return num_of_snums;
- }
+ qe = qe_get_device_node();
+ if (!qe)
+ return num_of_snums;
prop = of_get_property(qe, "fsl,qe-num-snums", &size);
if (prop && size == sizeof(*prop)) {
--
2.20.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property
2019-02-28 10:30 ` [PATCH 0/4] soc/fsl/qe: qe.c: cleanups and support for MPC8309 Rasmus Villemoes
` (2 preceding siblings ...)
2019-02-28 10:30 ` [PATCH 3/4] soc/fsl/qe: qe.c: introduce qe_get_device_node helper Rasmus Villemoes
@ 2019-02-28 10:30 ` Rasmus Villemoes
2019-03-01 3:36 ` Qiang Zhao
3 siblings, 1 reply; 13+ messages in thread
From: Rasmus Villemoes @ 2019-02-28 10:30 UTC (permalink / raw)
To: Qiang Zhao, Leo Li; +Cc: Scott Wood, linux-kernel, Timur Tabi, Rasmus Villemoes
The current code assumes that the set of snum _values_ to populate the
snums[] array with is a function of the _number_ of snums
alone. However, reading table 4-30, and its footnotes, of the QUICC
Engine Block Reference Manual shows that that is a bit too naive.
As an alternative, this introduces a new binding fsl,qe-snums, which
automatically encodes both the number of snums and the actual values to
use. Conveniently, of_property_read_variable_u8_array does exactly
what we need.
For example, for the MPC8309, one would specify the property as
fsl,qe-snums = /bits/ 8 <
0x88 0x89 0x98 0x99 0xa8 0xa9 0xb8 0xb9
0xc8 0xc9 0xd8 0xd9 0xe8 0xe9>;
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
.../devicetree/bindings/soc/fsl/cpm_qe/qe.txt | 8 +++++++-
drivers/soc/fsl/qe/qe.c | 14 +++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/soc/fsl/cpm_qe/qe.txt b/Documentation/devicetree/bindings/soc/fsl/cpm_qe/qe.txt
index d7afaff5faff..05f5f485562a 100644
--- a/Documentation/devicetree/bindings/soc/fsl/cpm_qe/qe.txt
+++ b/Documentation/devicetree/bindings/soc/fsl/cpm_qe/qe.txt
@@ -18,7 +18,8 @@ Required properties:
- reg : offset and length of the device registers.
- bus-frequency : the clock frequency for QUICC Engine.
- fsl,qe-num-riscs: define how many RISC engines the QE has.
-- fsl,qe-num-snums: define how many serial number(SNUM) the QE can use for the
+- fsl,qe-snums: This property has to be specified as '/bits/ 8' value,
+ defining the array of serial number (SNUM) values for the virtual
threads.
Optional properties:
@@ -34,6 +35,11 @@ Recommended properties
- brg-frequency : the internal clock source frequency for baud-rate
generators in Hz.
+Deprecated properties
+- fsl,qe-num-snums: define how many serial number(SNUM) the QE can use
+ for the threads. Use fsl,qe-snums instead to not only specify the
+ number of snums, but also their values.
+
Example:
qe@e0100000 {
#address-cells = <1>;
diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c
index 71beeb72eee4..049b36d6aeee 100644
--- a/drivers/soc/fsl/qe/qe.c
+++ b/drivers/soc/fsl/qe/qe.c
@@ -283,7 +283,6 @@ EXPORT_SYMBOL(qe_clock_source);
*/
static void qe_snums_init(void)
{
- int i;
static const u8 snum_init_76[] = {
0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D,
0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x88, 0x89,
@@ -304,9 +303,22 @@ static void qe_snums_init(void)
0x28, 0x29, 0x38, 0x39, 0x48, 0x49, 0x58, 0x59,
0x68, 0x69, 0x78, 0x79, 0x80, 0x81,
};
+ struct device_node *qe;
const u8 *snum_init;
+ int i;
bitmap_zero(snum_state, QE_NUM_OF_SNUM);
+ qe = qe_get_device_node();
+ if (qe) {
+ i = of_property_read_variable_u8_array(qe, "fsl,qe-snums",
+ snums, 14, QE_NUM_OF_SNUM);
+ of_node_put(qe);
+ if (i > 0) {
+ qe_num_of_snum = i;
+ return;
+ }
+ }
+
qe_num_of_snum = qe_get_num_of_snums();
if (qe_num_of_snum == 76)
--
2.20.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* RE: [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property
2019-02-28 10:30 ` [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property Rasmus Villemoes
@ 2019-03-01 3:36 ` Qiang Zhao
2019-03-01 7:50 ` Rasmus Villemoes
0 siblings, 1 reply; 13+ messages in thread
From: Qiang Zhao @ 2019-03-01 3:36 UTC (permalink / raw)
To: Rasmus Villemoes, Leo Li
Cc: Scott Wood, linux-kernel, Timur Tabi, Rasmus Villemoes
On 2019年2月28日 18:31,Rasmus Villemoes wrote:
> -----Original Message-----
> From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> Sent: 2019年2月28日 18:31
> To: Qiang Zhao <qiang.zhao@nxp.com>; Leo Li <leoyang.li@nxp.com>
> Cc: Scott Wood <oss@buserror.net>; linux-kernel@vger.kernel.org; Timur Tabi
> <timur@freescale.com>; Rasmus Villemoes <Rasmus.Villemoes@prevas.se>
> Subject: [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property
>
> The current code assumes that the set of snum _values_ to populate the
> snums[] array with is a function of the _number_ of snums alone. However,
> reading table 4-30, and its footnotes, of the QUICC Engine Block Reference
> Manual shows that that is a bit too naive.
>
> As an alternative, this introduces a new binding fsl,qe-snums, which
> automatically encodes both the number of snums and the actual values to use.
> Conveniently, of_property_read_variable_u8_array does exactly what we need.
>
> For example, for the MPC8309, one would specify the property as
>
> fsl,qe-snums = /bits/ 8 <
> 0x88 0x89 0x98 0x99 0xa8 0xa9 0xb8 0xb9
> 0xc8 0xc9 0xd8 0xd9 0xe8 0xe9>;
>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
> .../devicetree/bindings/soc/fsl/cpm_qe/qe.txt | 8 +++++++-
> drivers/soc/fsl/qe/qe.c | 14 +++++++++++++-
> 2 files changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/soc/fsl/cpm_qe/qe.txt
> b/Documentation/devicetree/bindings/soc/fsl/cpm_qe/qe.txt
> index d7afaff5faff..05f5f485562a 100644
> --- a/Documentation/devicetree/bindings/soc/fsl/cpm_qe/qe.txt
> +++ b/Documentation/devicetree/bindings/soc/fsl/cpm_qe/qe.txt
> @@ -18,7 +18,8 @@ Required properties:
> - reg : offset and length of the device registers.
> - bus-frequency : the clock frequency for QUICC Engine.
> - fsl,qe-num-riscs: define how many RISC engines the QE has.
> -- fsl,qe-num-snums: define how many serial number(SNUM) the QE can use
> for the
> +- fsl,qe-snums: This property has to be specified as '/bits/ 8' value,
> + defining the array of serial number (SNUM) values for the virtual
> threads.
>
> Optional properties:
> @@ -34,6 +35,11 @@ Recommended properties
> - brg-frequency : the internal clock source frequency for baud-rate
> generators in Hz.
>
> +Deprecated properties
> +- fsl,qe-num-snums: define how many serial number(SNUM) the QE can use
> + for the threads. Use fsl,qe-snums instead to not only specify the
> + number of snums, but also their values.
> +
> Example:
> qe@e0100000 {
> #address-cells = <1>;
> diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c index
> 71beeb72eee4..049b36d6aeee 100644
> --- a/drivers/soc/fsl/qe/qe.c
> +++ b/drivers/soc/fsl/qe/qe.c
> @@ -283,7 +283,6 @@ EXPORT_SYMBOL(qe_clock_source);
> */
> static void qe_snums_init(void)
> {
> - int i;
> static const u8 snum_init_76[] = {
> 0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D,
> 0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x88, 0x89, @@ -304,9
> +303,22 @@ static void qe_snums_init(void)
> 0x28, 0x29, 0x38, 0x39, 0x48, 0x49, 0x58, 0x59,
> 0x68, 0x69, 0x78, 0x79, 0x80, 0x81,
> };
> + struct device_node *qe;
> const u8 *snum_init;
> + int i;
>
> bitmap_zero(snum_state, QE_NUM_OF_SNUM);
> + qe = qe_get_device_node();
> + if (qe) {
> + i = of_property_read_variable_u8_array(qe, "fsl,qe-snums",
> + snums, 14, QE_NUM_OF_SNUM);
> + of_node_put(qe);
> + if (i > 0) {
> + qe_num_of_snum = i;
> + return;
> + }
> + }
> +
> qe_num_of_snum = qe_get_num_of_snums();
>
> if (qe_num_of_snum == 76)
So you define 14 snums for MPC8309, but there still be the comment "/* No QE ever has fewer than 28 SNUMs */" and it will check if
The num_of_snums "is >28", it will cause confusion, so I suggest to modify 28 to 14.
I read the old version QUICC Engine Block Reference Manual, it said snums table is not available on MPC8306/MPC8306S/MPC8309,
So I think the code it written long before with this version RM, and at that time, the snums is at least 28, and nobody modify the code later.
And now with the new version RM, it support MPC8306/MPC8306S/MPC8309 with snums and have snums fewer then 28, so I think the minimum value should
Be modified to 14.
Thank you!
-Qiang Zhao
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property
2019-03-01 3:36 ` Qiang Zhao
@ 2019-03-01 7:50 ` Rasmus Villemoes
2019-03-01 9:43 ` Qiang Zhao
0 siblings, 1 reply; 13+ messages in thread
From: Rasmus Villemoes @ 2019-03-01 7:50 UTC (permalink / raw)
To: Qiang Zhao, Leo Li; +Cc: Scott Wood, linux-kernel, Timur Tabi, Rasmus Villemoes
On 01/03/2019 04.36, Qiang Zhao wrote:
> On 2019年2月28日 18:31,Rasmus Villemoes wrote:
>
>> -----Original Message-----
>> From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
>> Sent: 2019年2月28日 18:31
>> To: Qiang Zhao <qiang.zhao@nxp.com>; Leo Li <leoyang.li@nxp.com>
>> Cc: Scott Wood <oss@buserror.net>; linux-kernel@vger.kernel.org; Timur Tabi
>> <timur@freescale.com>; Rasmus Villemoes <Rasmus.Villemoes@prevas.se>
>> Subject: [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property
>>
>> The current code assumes that the set of snum _values_ to populate the
>> snums[] array with is a function of the _number_ of snums alone. However,
>> reading table 4-30, and its footnotes, of the QUICC Engine Block Reference
>> Manual shows that that is a bit too naive.
>>
>> As an alternative, this introduces a new binding fsl,qe-snums, which
>> automatically encodes both the number of snums and the actual values to use.
>> Conveniently, of_property_read_variable_u8_array does exactly what we need.
>>
>> For example, for the MPC8309, one would specify the property as
>>
>> fsl,qe-snums = /bits/ 8 <
>> 0x88 0x89 0x98 0x99 0xa8 0xa9 0xb8 0xb9
>> 0xc8 0xc9 0xd8 0xd9 0xe8 0xe9>;
>>
>> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
>> ---
>> .../devicetree/bindings/soc/fsl/cpm_qe/qe.txt | 8 +++++++-
>> drivers/soc/fsl/qe/qe.c | 14 +++++++++++++-
>> 2 files changed, 20 insertions(+), 2 deletions(-)
>>
>> diff --git a/Documentation/devicetree/bindings/soc/fsl/cpm_qe/qe.txt
>> b/Documentation/devicetree/bindings/soc/fsl/cpm_qe/qe.txt
>> index d7afaff5faff..05f5f485562a 100644
>> --- a/Documentation/devicetree/bindings/soc/fsl/cpm_qe/qe.txt
>> +++ b/Documentation/devicetree/bindings/soc/fsl/cpm_qe/qe.txt
>> @@ -18,7 +18,8 @@ Required properties:
>> - reg : offset and length of the device registers.
>> - bus-frequency : the clock frequency for QUICC Engine.
>> - fsl,qe-num-riscs: define how many RISC engines the QE has.
>> -- fsl,qe-num-snums: define how many serial number(SNUM) the QE can use
>> for the
>> +- fsl,qe-snums: This property has to be specified as '/bits/ 8' value,
>> + defining the array of serial number (SNUM) values for the virtual
>> threads.
>>
>> Optional properties:
>> @@ -34,6 +35,11 @@ Recommended properties
>> - brg-frequency : the internal clock source frequency for baud-rate
>> generators in Hz.
>>
>> +Deprecated properties
>> +- fsl,qe-num-snums: define how many serial number(SNUM) the QE can use
>> + for the threads. Use fsl,qe-snums instead to not only specify the
>> + number of snums, but also their values.
>> +
>> Example:
>> qe@e0100000 {
>> #address-cells = <1>;
>> diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c index
>> 71beeb72eee4..049b36d6aeee 100644
>> --- a/drivers/soc/fsl/qe/qe.c
>> +++ b/drivers/soc/fsl/qe/qe.c
>> @@ -283,7 +283,6 @@ EXPORT_SYMBOL(qe_clock_source);
>> */
>> static void qe_snums_init(void)
>> {
>> - int i;
>> static const u8 snum_init_76[] = {
>> 0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D,
>> 0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x88, 0x89, @@ -304,9
>> +303,22 @@ static void qe_snums_init(void)
>> 0x28, 0x29, 0x38, 0x39, 0x48, 0x49, 0x58, 0x59,
>> 0x68, 0x69, 0x78, 0x79, 0x80, 0x81,
>> };
>> + struct device_node *qe;
>> const u8 *snum_init;
>> + int i;
>>
>> bitmap_zero(snum_state, QE_NUM_OF_SNUM);
>> + qe = qe_get_device_node();
>> + if (qe) {
>> + i = of_property_read_variable_u8_array(qe, "fsl,qe-snums",
>> + snums, 14, QE_NUM_OF_SNUM);
>> + of_node_put(qe);
>> + if (i > 0) {
>> + qe_num_of_snum = i;
>> + return;
>> + }
>> + }
>> +
>> qe_num_of_snum = qe_get_num_of_snums();
>>
>> if (qe_num_of_snum == 76)
>
> So you define 14 snums for MPC8309, but there still be the comment "/* No QE ever has fewer than 28 SNUMs */" and it will check if
> The num_of_snums "is >28", it will cause confusion, so I suggest to modify 28 to 14.
Sure, that needs updating. My thinking was that only legacy DTs would
use the fsl,qe-num-snums, and there would be no need to support lower
values than we used to, since the logic back in qe_snums_init wouldn't
handle such values appropriately anyway.
> I read the old version QUICC Engine Block Reference Manual, it said snums table is not available on MPC8306/MPC8306S/MPC8309,
> So I think the code it written long before with this version RM, and at that time, the snums is at least 28, and nobody modify the code later.
> And now with the new version RM, it support MPC8306/MPC8306S/MPC8309 with snums and have snums fewer then 28, so I think the minimum value should
> Be modified to 14.
Yes. I'll do an extra cleanup patch modifying the code comments
appropriately. But what do you think about the core idea behind this
change (and the preceding cleanup patches)?
Rasmus
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property
2019-03-01 7:50 ` Rasmus Villemoes
@ 2019-03-01 9:43 ` Qiang Zhao
2019-03-01 10:21 ` Rasmus Villemoes
0 siblings, 1 reply; 13+ messages in thread
From: Qiang Zhao @ 2019-03-01 9:43 UTC (permalink / raw)
To: Rasmus Villemoes, Leo Li
Cc: Scott Wood, linux-kernel, Timur Tabi, Rasmus Villemoes
On 01/03/2019 15.50,Rasmus Villemoes wrote:
> -----Original Message-----
> From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> Sent: 2019年3月1日 15:50
> To: Qiang Zhao <qiang.zhao@nxp.com>; Leo Li <leoyang.li@nxp.com>
> Cc: Scott Wood <oss@buserror.net>; linux-kernel@vger.kernel.org; Timur Tabi
> <timur@freescale.com>; Rasmus Villemoes <Rasmus.Villemoes@prevas.se>
> Subject: Re: [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property
>
> On 01/03/2019 04.36, Qiang Zhao wrote:
> > On 2019年2月28日 18:31,Rasmus Villemoes wrote:
> >
> >> -----Original Message-----
> >> From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> >> Sent: 2019年2月28日 18:31
> >> To: Qiang Zhao <qiang.zhao@nxp.com>; Leo Li <leoyang.li@nxp.com>
> >> Cc: Scott Wood <oss@buserror.net>; linux-kernel@vger.kernel.org;
> >> Timur Tabi <timur@freescale.com>; Rasmus Villemoes
> >> <Rasmus.Villemoes@prevas.se>
> >> Subject: [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property
> >>
> >
> > So you define 14 snums for MPC8309, but there still be the comment "/*
> > No QE ever has fewer than 28 SNUMs */" and it will check if The
> num_of_snums "is >28", it will cause confusion, so I suggest to modify 28 to
> 14.
>
> Sure, that needs updating. My thinking was that only legacy DTs would use the
> fsl,qe-num-snums, and there would be no need to support lower values than
> we used to, since the logic back in qe_snums_init wouldn't handle such values
> appropriately anyway.
>
> > I read the old version QUICC Engine Block Reference Manual, it said
> > snums table is not available on MPC8306/MPC8306S/MPC8309, So I think
> the code it written long before with this version RM, and at that time, the
> snums is at least 28, and nobody modify the code later.
> > And now with the new version RM, it support
> MPC8306/MPC8306S/MPC8309
> > with snums and have snums fewer then 28, so I think the minimum value
> should Be modified to 14.
>
> Yes. I'll do an extra cleanup patch modifying the code comments appropriately.
> But what do you think about the core idea behind this change (and the
> preceding cleanup patches)?
Maybe we could modify the comments in this patch, Anyway, the MPC8306/MPC8306S/MPC8309
Is supported with snums and the number is 14, In addition, you assign qe_num_of_snum to i as below.
The variable stands for num of snums.
Or we could add comments to explain it clearly why qe_num_of_snum is assign to a value fewer than 28
While it says " No QE ever has fewer than 28 SNUMs ".
+ qe = qe_get_device_node();
+ if (qe) {
+ i = of_property_read_variable_u8_array(qe, "fsl,qe-snums",
+ snums, 14, QE_NUM_OF_SNUM);
+ of_node_put(qe);
+ if (i > 0) {
+ qe_num_of_snum = i;
+ return;
+ }
+ }
Best Regards
Qiang Zhao
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property
2019-03-01 9:43 ` Qiang Zhao
@ 2019-03-01 10:21 ` Rasmus Villemoes
2019-03-01 14:57 ` [PATCH 5/4] soc/fsl/qe: qe.c: fold qe_get_num_of_snums into qe_snums_init Rasmus Villemoes
0 siblings, 1 reply; 13+ messages in thread
From: Rasmus Villemoes @ 2019-03-01 10:21 UTC (permalink / raw)
To: Qiang Zhao, Leo Li; +Cc: Scott Wood, linux-kernel, Timur Tabi, Rasmus Villemoes
On 01/03/2019 10.43, Qiang Zhao wrote:
> On 01/03/2019 15.50,Rasmus Villemoes wrote:
>> -----Original Message-----
>> From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
>> Sent: 2019年3月1日 15:50
>> To: Qiang Zhao <qiang.zhao@nxp.com>; Leo Li <leoyang.li@nxp.com>
>> Cc: Scott Wood <oss@buserror.net>; linux-kernel@vger.kernel.org; Timur Tabi
>> <timur@freescale.com>; Rasmus Villemoes <Rasmus.Villemoes@prevas.se>
>> Subject: Re: [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property
>>
>> On 01/03/2019 04.36, Qiang Zhao wrote:
>>> On 2019年2月28日 18:31,Rasmus Villemoes wrote:
>>>
>>>> -----Original Message-----
>>>> From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
>>>> Sent: 2019年2月28日 18:31
>>>> To: Qiang Zhao <qiang.zhao@nxp.com>; Leo Li <leoyang.li@nxp.com>
>>>> Cc: Scott Wood <oss@buserror.net>; linux-kernel@vger.kernel.org;
>>>> Timur Tabi <timur@freescale.com>; Rasmus Villemoes
>>>> <Rasmus.Villemoes@prevas.se>
>>>> Subject: [PATCH 4/4] soc/fsl/qe: qe.c: support fsl,qe-snums property
>>>>
>>>
>>> So you define 14 snums for MPC8309, but there still be the comment "/*
>>> No QE ever has fewer than 28 SNUMs */" and it will check if The
>> num_of_snums "is >28", it will cause confusion, so I suggest to modify 28 to
>> 14.
>>
>> Sure, that needs updating. My thinking was that only legacy DTs would use the
>> fsl,qe-num-snums, and there would be no need to support lower values than
>> we used to, since the logic back in qe_snums_init wouldn't handle such values
>> appropriately anyway.
>>
>>> I read the old version QUICC Engine Block Reference Manual, it said
>>> snums table is not available on MPC8306/MPC8306S/MPC8309, So I think
>> the code it written long before with this version RM, and at that time, the
>> snums is at least 28, and nobody modify the code later.
>>> And now with the new version RM, it support
>> MPC8306/MPC8306S/MPC8309
>>> with snums and have snums fewer then 28, so I think the minimum value
>> should Be modified to 14.
>>
>> Yes. I'll do an extra cleanup patch modifying the code comments appropriately.
>> But what do you think about the core idea behind this change (and the
>> preceding cleanup patches)?
>
> Maybe we could modify the comments in this patch, Anyway, the MPC8306/MPC8306S/MPC8309
> Is supported with snums and the number is 14, In addition, you assign qe_num_of_snum to i as below.
> The variable stands for num of snums.
Yes, but I can't assign it directly, because qe_num_of_snum is unsigned,
and I need to test whether the return value is negative.
> Or we could add comments to explain it clearly why qe_num_of_snum is assign to a value fewer than 28
> While it says " No QE ever has fewer than 28 SNUMs ".
OK, I'll fold in some comment updating in a v2 patch.
>
> + qe = qe_get_device_node();
> + if (qe) {
> + i = of_property_read_variable_u8_array(qe, "fsl,qe-snums",
> + snums, 14, QE_NUM_OF_SNUM);
> + of_node_put(qe);
> + if (i > 0) {
> + qe_num_of_snum = i;
> + return;
> + }
> + }
Actually, putting in a lower bound of 14 here is a mistake - it should
just be 1, and then the code would also work for any QE variant that
might be shipped in the future. It's up to the DT author to make sure
the data is correct.
Can you figure out why the old code defaults to 28, and why its ok for
all those variants to just end up using the first 28 elements of the _46
array? What's the purpose of those surplus 18 elements?
Rasmus
> Best Regards
> Qiang Zhao
>
--
Rasmus Villemoes
Software Developer
Prevas A/S
Hedeager 3
DK-8200 Aarhus N
+45 51210274
rasmus.villemoes@prevas.dk
www.prevas.dk
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 5/4] soc/fsl/qe: qe.c: fold qe_get_num_of_snums into qe_snums_init
2019-03-01 10:21 ` Rasmus Villemoes
@ 2019-03-01 14:57 ` Rasmus Villemoes
0 siblings, 0 replies; 13+ messages in thread
From: Rasmus Villemoes @ 2019-03-01 14:57 UTC (permalink / raw)
To: Qiang Zhao, Leo Li; +Cc: Scott Wood, linux-kernel, Rasmus Villemoes
The comment "No QE ever has fewer than 28 SNUMs" is false; e.g. the
MPC8309 has 14. The code path returning -EINVAL is also a recipe for
instant disaster, since the caller (qe_snums_init) uncritically
assigns the return value to the unsigned qe_num_of_snum, and would
thus proceed to attempt to copy 4GB from snum_init_46[] to the snum[]
array.
So fold the handling of the legacy fsl,qe-num-snums into
qe_snums_init, and make sure we do not end up using the snum_init_46
array in cases other than the two where we know it makes sense.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
Qiang: Something like this. I prefer not to fold it into patch 4/4
since it really fixes unrelated issues (the wrong comment and the
bogus handling of unexpected return values from qe_get_num_of_snums),
but I can do so if you wish.
drivers/net/ethernet/freescale/ucc_geth.c | 2 +-
drivers/soc/fsl/qe/qe.c | 54 +++++++----------------
include/soc/fsl/qe/qe.h | 2 +-
3 files changed, 19 insertions(+), 39 deletions(-)
diff --git a/drivers/net/ethernet/freescale/ucc_geth.c b/drivers/net/ethernet/freescale/ucc_geth.c
index 22a817da861e..3b2e28614e7b 100644
--- a/drivers/net/ethernet/freescale/ucc_geth.c
+++ b/drivers/net/ethernet/freescale/ucc_geth.c
@@ -3842,7 +3842,7 @@ static int ucc_geth_probe(struct platform_device* ofdev)
}
if (max_speed == SPEED_1000) {
- unsigned int snums = qe_get_num_of_snums();
+ unsigned int snums = qe_num_of_snum;
/* configure muram FIFOs for gigabit operation */
ug_info->uf_info.urfs = UCC_GETH_URFS_GIGA_INIT;
diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c
index 8b915129077a..f8ddbb5b0eb5 100644
--- a/drivers/soc/fsl/qe/qe.c
+++ b/drivers/soc/fsl/qe/qe.c
@@ -52,7 +52,8 @@ EXPORT_SYMBOL(qe_immr);
static u8 snums[QE_NUM_OF_SNUM]; /* Dynamically allocated SNUMs */
static DECLARE_BITMAP(snum_state, QE_NUM_OF_SNUM);
-static unsigned int qe_num_of_snum;
+unsigned int qe_num_of_snum;
+EXPORT_SYMBOL(qe_num_of_snum);
static phys_addr_t qebase = -1;
@@ -308,26 +309,34 @@ static void qe_snums_init(void)
int i;
bitmap_zero(snum_state, QE_NUM_OF_SNUM);
+ qe_num_of_snum = 28; /* The default number of snum for threads is 28 */
qe = qe_get_device_node();
if (qe) {
i = of_property_read_variable_u8_array(qe, "fsl,qe-snums",
snums, 1, QE_NUM_OF_SNUM);
- of_node_put(qe);
if (i > 0) {
+ of_node_put(qe);
qe_num_of_snum = i;
return;
}
+ /*
+ * Fall back to legacy binding of using the value of
+ * fsl,qe-num-snums to choose one of the static arrays
+ * above.
+ */
+ of_property_read_u32(qe, "fsl,qe-num-snums", &qe_num_of_snum);
+ of_node_put(qe);
}
- qe_num_of_snum = qe_get_num_of_snums();
-
if (qe_num_of_snum == 76)
snum_init = snum_init_76;
- else
+ else if (qe_num_of_snum == 28 || qe_num_of_snum == 46)
snum_init = snum_init_46;
-
- for (i = 0; i < qe_num_of_snum; i++)
- snums[i] = snum_init[i];
+ else {
+ pr_err("QE: unsupported value of fsl,qe-num-snums: %u\n", qe_num_of_snum);
+ return;
+ }
+ memcpy(snums, snum_init, qe_num_of_snum);
}
int qe_get_snum(void)
@@ -649,35 +658,6 @@ unsigned int qe_get_num_of_risc(void)
}
EXPORT_SYMBOL(qe_get_num_of_risc);
-unsigned int qe_get_num_of_snums(void)
-{
- struct device_node *qe;
- int size;
- unsigned int num_of_snums;
- const u32 *prop;
-
- num_of_snums = 28; /* The default number of snum for threads is 28 */
- qe = qe_get_device_node();
- if (!qe)
- return num_of_snums;
-
- prop = of_get_property(qe, "fsl,qe-num-snums", &size);
- if (prop && size == sizeof(*prop)) {
- num_of_snums = *prop;
- if ((num_of_snums < 28) || (num_of_snums > QE_NUM_OF_SNUM)) {
- /* No QE ever has fewer than 28 SNUMs */
- pr_err("QE: number of snum is invalid\n");
- of_node_put(qe);
- return -EINVAL;
- }
- }
-
- of_node_put(qe);
-
- return num_of_snums;
-}
-EXPORT_SYMBOL(qe_get_num_of_snums);
-
static int __init qe_init(void)
{
struct device_node *np;
diff --git a/include/soc/fsl/qe/qe.h b/include/soc/fsl/qe/qe.h
index b3d1aff5e8ad..af5739850bf4 100644
--- a/include/soc/fsl/qe/qe.h
+++ b/include/soc/fsl/qe/qe.h
@@ -212,7 +212,7 @@ int qe_setbrg(enum qe_clock brg, unsigned int rate, unsigned int multiplier);
int qe_get_snum(void);
void qe_put_snum(u8 snum);
unsigned int qe_get_num_of_risc(void);
-unsigned int qe_get_num_of_snums(void);
+extern unsigned int qe_num_of_snum;
static inline int qe_alive_during_sleep(void)
{
--
2.20.1
^ permalink raw reply related [flat|nested] 13+ messages in thread