All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/6] can: c_can: add support to 64 message objects
@ 2021-02-28 10:38 Dario Binacchi
  2021-02-28 10:38 ` [PATCH v3 1/6] can: c_can: remove unused code Dario Binacchi
                   ` (5 more replies)
  0 siblings, 6 replies; 23+ messages in thread
From: Dario Binacchi @ 2021-02-28 10:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Federico Vaga, Alexander Stein, Dario Binacchi, David S. Miller,
	Jakub Kicinski, Marc Kleine-Budde, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev


The D_CAN controller supports up to 128 messages. Until now the driver
only managed 32 messages although Sitara processors and DRA7 SOC can
handle 64.

The series was tested on a beaglebone board.

Note:
I have not changed the type of tx_field (belonging to the c_can_priv
structure) to atomic64_t because I think the atomic_t type has size
of at least 32 bits on x86 and arm, which is enough to handle 64
messages.
http://marc.info/?l=linux-can&m=139746476821294&w=2 reports the results
of tests performed just on x86 and arm architectures.

Changes in v3:
- Use unsigned int instead of int as type of the msg_obj_* fields
  in the c_can_priv structure.
- Replace (u64)1 with 1UL in msg_obj_rx_mask setting.
- Use unsigned int instead of int as type of the msg_obj_num field
  in c_can_driver_data and c_can_pci_data structures.

Changes in v2:
- Fix compiling error reported by kernel test robot.
- Add Reported-by tag.
- Pass larger size to alloc_candev() routine to avoid an additional
  memory allocation/deallocation.
- Add message objects number to PCI driver data.

Dario Binacchi (6):
  can: c_can: remove unused code
  can: c_can: fix indentation
  can: c_can: fix control interface used by c_can_do_tx
  can: c_can: use 32-bit write to set arbitration register
  can: c_can: prepare to up the message objects number
  can: c_can: add support to 64 message objects

 drivers/net/can/c_can/c_can.c          | 77 +++++++++++++++-----------
 drivers/net/can/c_can/c_can.h          | 32 +++++------
 drivers/net/can/c_can/c_can_pci.c      |  6 +-
 drivers/net/can/c_can/c_can_platform.c |  6 +-
 4 files changed, 68 insertions(+), 53 deletions(-)

-- 
2.17.1


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

* [PATCH v3 1/6] can: c_can: remove unused code
  2021-02-28 10:38 [PATCH v3 0/6] can: c_can: add support to 64 message objects Dario Binacchi
@ 2021-02-28 10:38 ` Dario Binacchi
  2021-02-28 10:38 ` [PATCH v3 2/6] can: c_can: fix indentation Dario Binacchi
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 23+ messages in thread
From: Dario Binacchi @ 2021-02-28 10:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Federico Vaga, Alexander Stein, Dario Binacchi, David S. Miller,
	Jakub Kicinski, Marc Kleine-Budde, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev

Commit 9d23a9818cb1 ("can: c_can: Remove unused inline function") left
behind C_CAN_MSG_OBJ_TX_LAST constant.

Commit fa39b54ccf28 ("can: c_can: Get rid of pointless interrupts") left
behind C_CAN_MSG_RX_LOW_LAST and C_CAN_MSG_OBJ_RX_SPLIT constants.

The removed code also made a comment useless and misleading.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
---

(no changes since v1)

 drivers/net/can/c_can/c_can.c | 3 +--
 drivers/net/can/c_can/c_can.h | 4 ----
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index ef474bae47a1..a962ceefd44a 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -848,8 +848,7 @@ static inline u32 c_can_get_pending(struct c_can_priv *priv)
  * c_can core saves a received CAN message into the first free message
  * object it finds free (starting with the lowest). Bits NEWDAT and
  * INTPND are set for this message object indicating that a new message
- * has arrived. To work-around this issue, we keep two groups of message
- * objects whose partitioning is defined by C_CAN_MSG_OBJ_RX_SPLIT.
+ * has arrived.
  *
  * We clear the newdat bit right away.
  *
diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index 92213d3d96eb..90d3d2e7a086 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -32,11 +32,7 @@
 				C_CAN_MSG_OBJ_RX_NUM - 1)
 
 #define C_CAN_MSG_OBJ_TX_FIRST	(C_CAN_MSG_OBJ_RX_LAST + 1)
-#define C_CAN_MSG_OBJ_TX_LAST	(C_CAN_MSG_OBJ_TX_FIRST + \
-				C_CAN_MSG_OBJ_TX_NUM - 1)
 
-#define C_CAN_MSG_OBJ_RX_SPLIT	9
-#define C_CAN_MSG_RX_LOW_LAST	(C_CAN_MSG_OBJ_RX_SPLIT - 1)
 #define RECEIVE_OBJECT_BITS	0x0000ffff
 
 enum reg {
-- 
2.17.1


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

* [PATCH v3 2/6] can: c_can: fix indentation
  2021-02-28 10:38 [PATCH v3 0/6] can: c_can: add support to 64 message objects Dario Binacchi
  2021-02-28 10:38 ` [PATCH v3 1/6] can: c_can: remove unused code Dario Binacchi
@ 2021-02-28 10:38 ` Dario Binacchi
  2021-02-28 10:38 ` [PATCH v3 3/6] can: c_can: fix control interface used by c_can_do_tx Dario Binacchi
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 23+ messages in thread
From: Dario Binacchi @ 2021-02-28 10:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Federico Vaga, Alexander Stein, Dario Binacchi, David S. Miller,
	Jakub Kicinski, Marc Kleine-Budde, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev

Commit 524369e2391f ("can: c_can: remove obsolete STRICT_FRAME_ORDERING Kconfig option")
left behind wrong indentation, fix it.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
---

(no changes since v1)

 drivers/net/can/c_can/c_can.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index a962ceefd44a..dbcc1c1c92d6 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -786,7 +786,7 @@ static u32 c_can_adjust_pending(u32 pend)
 static inline void c_can_rx_object_get(struct net_device *dev,
 				       struct c_can_priv *priv, u32 obj)
 {
-		c_can_object_get(dev, IF_RX, obj, priv->comm_rcv_high);
+	c_can_object_get(dev, IF_RX, obj, priv->comm_rcv_high);
 }
 
 static inline void c_can_rx_finalize(struct net_device *dev,
-- 
2.17.1


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

* [PATCH v3 3/6] can: c_can: fix control interface used by c_can_do_tx
  2021-02-28 10:38 [PATCH v3 0/6] can: c_can: add support to 64 message objects Dario Binacchi
  2021-02-28 10:38 ` [PATCH v3 1/6] can: c_can: remove unused code Dario Binacchi
  2021-02-28 10:38 ` [PATCH v3 2/6] can: c_can: fix indentation Dario Binacchi
@ 2021-02-28 10:38 ` Dario Binacchi
  2021-03-02 18:44   ` Kurt Van Dijck
  2021-02-28 10:38 ` [PATCH v3 4/6] can: c_can: use 32-bit write to set arbitration register Dario Binacchi
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 23+ messages in thread
From: Dario Binacchi @ 2021-02-28 10:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Federico Vaga, Alexander Stein, Dario Binacchi, David S. Miller,
	Jakub Kicinski, Marc Kleine-Budde, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev

According to commit 640916db2bf7 ("can: c_can: Make it SMP safe") let RX use
IF1 (i.e. IF_RX) and TX use IF2 (i.e. IF_TX).

Signed-off-by: Dario Binacchi <dariobin@libero.it>
---

(no changes since v1)

 drivers/net/can/c_can/c_can.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index dbcc1c1c92d6..69526c3a671c 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -732,7 +732,7 @@ static void c_can_do_tx(struct net_device *dev)
 		idx--;
 		pend &= ~(1 << idx);
 		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
-		c_can_inval_tx_object(dev, IF_RX, obj);
+		c_can_inval_tx_object(dev, IF_TX, obj);
 		can_get_echo_skb(dev, idx, NULL);
 		bytes += priv->dlc[idx];
 		pkts++;
-- 
2.17.1


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

* [PATCH v3 4/6] can: c_can: use 32-bit write to set arbitration register
  2021-02-28 10:38 [PATCH v3 0/6] can: c_can: add support to 64 message objects Dario Binacchi
                   ` (2 preceding siblings ...)
  2021-02-28 10:38 ` [PATCH v3 3/6] can: c_can: fix control interface used by c_can_do_tx Dario Binacchi
@ 2021-02-28 10:38 ` Dario Binacchi
  2021-02-28 10:38 ` [PATCH v3 5/6] can: c_can: prepare to up the message objects number Dario Binacchi
  2021-02-28 10:38 ` [PATCH v3 6/6] can: c_can: add support to 64 message objects Dario Binacchi
  5 siblings, 0 replies; 23+ messages in thread
From: Dario Binacchi @ 2021-02-28 10:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Federico Vaga, Alexander Stein, Dario Binacchi, David S. Miller,
	Jakub Kicinski, Marc Kleine-Budde, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev

The arbitration register is already set up with 32-bit writes in the
other parts of the code except for this point.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
---

(no changes since v1)

 drivers/net/can/c_can/c_can.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index 69526c3a671c..7081cfaf62e2 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -297,8 +297,7 @@ static void c_can_inval_msg_object(struct net_device *dev, int iface, int obj)
 {
 	struct c_can_priv *priv = netdev_priv(dev);
 
-	priv->write_reg(priv, C_CAN_IFACE(ARB1_REG, iface), 0);
-	priv->write_reg(priv, C_CAN_IFACE(ARB2_REG, iface), 0);
+	priv->write_reg32(priv, C_CAN_IFACE(ARB1_REG, iface), 0);
 	c_can_inval_tx_object(dev, iface, obj);
 }
 
-- 
2.17.1


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

* [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-02-28 10:38 [PATCH v3 0/6] can: c_can: add support to 64 message objects Dario Binacchi
                   ` (3 preceding siblings ...)
  2021-02-28 10:38 ` [PATCH v3 4/6] can: c_can: use 32-bit write to set arbitration register Dario Binacchi
@ 2021-02-28 10:38 ` Dario Binacchi
  2021-03-01 11:38   ` Marc Kleine-Budde
  2021-03-02 18:49   ` Kurt Van Dijck
  2021-02-28 10:38 ` [PATCH v3 6/6] can: c_can: add support to 64 message objects Dario Binacchi
  5 siblings, 2 replies; 23+ messages in thread
From: Dario Binacchi @ 2021-02-28 10:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Federico Vaga, Alexander Stein, Dario Binacchi, David S. Miller,
	Jakub Kicinski, Marc Kleine-Budde, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev

As pointed by commit c0a9f4d396c9 ("can: c_can: Reduce register access")
the "driver casts the 16 message objects in stone, which is completely
braindead as contemporary hardware has up to 128 message objects".

The patch prepares the module to extend the number of message objects
beyond the 32 currently managed. This was achieved by transforming the
constants used to manage RX/TX messages into variables without changing
the driver policy.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
Reported-by: kernel test robot <lkp@intel.com>

---

Changes in v3:
- Use unsigned int instead of int as type of the msg_obj_* fields
  in the c_can_priv structure.
- Replace (u64)1 with 1UL in msg_obj_rx_mask setting.

Changes in v2:
- Fix compiling error reported by kernel test robot.
- Add Reported-by tag.
- Pass larger size to alloc_candev() routine to avoid an additional
  memory allocation/deallocation.

 drivers/net/can/c_can/c_can.c          | 50 ++++++++++++++++----------
 drivers/net/can/c_can/c_can.h          | 23 ++++++------
 drivers/net/can/c_can/c_can_pci.c      |  2 +-
 drivers/net/can/c_can/c_can_platform.c |  2 +-
 4 files changed, 43 insertions(+), 34 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index 7081cfaf62e2..ede6f4d62095 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -173,9 +173,6 @@
 /* Wait for ~1 sec for INIT bit */
 #define INIT_WAIT_MS		1000
 
-/* napi related */
-#define C_CAN_NAPI_WEIGHT	C_CAN_MSG_OBJ_RX_NUM
-
 /* c_can lec values */
 enum c_can_lec_type {
 	LEC_NO_ERROR = 0,
@@ -325,7 +322,7 @@ static void c_can_setup_tx_object(struct net_device *dev, int iface,
 	 * first, i.e. clear the MSGVAL flag in the arbiter.
 	 */
 	if (rtr != (bool)test_bit(idx, &priv->tx_dir)) {
-		u32 obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
+		u32 obj = idx + priv->msg_obj_tx_first;
 
 		c_can_inval_msg_object(dev, iface, obj);
 		change_bit(idx, &priv->tx_dir);
@@ -463,10 +460,10 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,
 	 * prioritized. The lowest buffer number wins.
 	 */
 	idx = fls(atomic_read(&priv->tx_active));
-	obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
+	obj = idx + priv->msg_obj_tx_first;
 
 	/* If this is the last buffer, stop the xmit queue */
-	if (idx == C_CAN_MSG_OBJ_TX_NUM - 1)
+	if (idx == priv->msg_obj_tx_num - 1)
 		netif_stop_queue(dev);
 	/*
 	 * Store the message in the interface so we can call
@@ -549,17 +546,18 @@ static int c_can_set_bittiming(struct net_device *dev)
  */
 static void c_can_configure_msg_objects(struct net_device *dev)
 {
+	struct c_can_priv *priv = netdev_priv(dev);
 	int i;
 
 	/* first invalidate all message objects */
-	for (i = C_CAN_MSG_OBJ_RX_FIRST; i <= C_CAN_NO_OF_OBJECTS; i++)
+	for (i = priv->msg_obj_rx_first; i <= priv->msg_obj_num; i++)
 		c_can_inval_msg_object(dev, IF_RX, i);
 
 	/* setup receive message objects */
-	for (i = C_CAN_MSG_OBJ_RX_FIRST; i < C_CAN_MSG_OBJ_RX_LAST; i++)
+	for (i = priv->msg_obj_rx_first; i < priv->msg_obj_rx_last; i++)
 		c_can_setup_receive_object(dev, IF_RX, i, 0, 0, IF_MCONT_RCV);
 
-	c_can_setup_receive_object(dev, IF_RX, C_CAN_MSG_OBJ_RX_LAST, 0, 0,
+	c_can_setup_receive_object(dev, IF_RX, priv->msg_obj_rx_last, 0, 0,
 				   IF_MCONT_RCV_EOB);
 }
 
@@ -730,7 +728,7 @@ static void c_can_do_tx(struct net_device *dev)
 	while ((idx = ffs(pend))) {
 		idx--;
 		pend &= ~(1 << idx);
-		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
+		obj = idx + priv->msg_obj_tx_first;
 		c_can_inval_tx_object(dev, IF_TX, obj);
 		can_get_echo_skb(dev, idx, NULL);
 		bytes += priv->dlc[idx];
@@ -740,7 +738,7 @@ static void c_can_do_tx(struct net_device *dev)
 	/* Clear the bits in the tx_active mask */
 	atomic_sub(clr, &priv->tx_active);
 
-	if (clr & (1 << (C_CAN_MSG_OBJ_TX_NUM - 1)))
+	if (clr & (1 << (priv->msg_obj_tx_num - 1)))
 		netif_wake_queue(dev);
 
 	if (pkts) {
@@ -755,11 +753,11 @@ static void c_can_do_tx(struct net_device *dev)
  * raced with the hardware or failed to readout all upper
  * objects in the last run due to quota limit.
  */
-static u32 c_can_adjust_pending(u32 pend)
+static u32 c_can_adjust_pending(u32 pend, u32 rx_mask)
 {
 	u32 weight, lasts;
 
-	if (pend == RECEIVE_OBJECT_BITS)
+	if (pend == rx_mask)
 		return pend;
 
 	/*
@@ -862,8 +860,7 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)
 	 * It is faster to read only one 16bit register. This is only possible
 	 * for a maximum number of 16 objects.
 	 */
-	BUILD_BUG_ON_MSG(C_CAN_MSG_OBJ_RX_LAST > 16,
-			"Implementation does not support more message objects than 16");
+	WARN_ON(priv->msg_obj_rx_last > 16);
 
 	while (quota > 0) {
 		if (!pend) {
@@ -874,7 +871,8 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)
 			 * If the pending field has a gap, handle the
 			 * bits above the gap first.
 			 */
-			toread = c_can_adjust_pending(pend);
+			toread = c_can_adjust_pending(pend,
+						      priv->msg_obj_rx_mask);
 		} else {
 			toread = pend;
 		}
@@ -1205,17 +1203,31 @@ static int c_can_close(struct net_device *dev)
 	return 0;
 }
 
-struct net_device *alloc_c_can_dev(void)
+struct net_device *alloc_c_can_dev(int msg_obj_num)
 {
 	struct net_device *dev;
 	struct c_can_priv *priv;
+	int msg_obj_tx_num = msg_obj_num / 2;
 
-	dev = alloc_candev(sizeof(struct c_can_priv), C_CAN_MSG_OBJ_TX_NUM);
+	dev = alloc_candev(sizeof(*priv) + sizeof(u32) * msg_obj_tx_num,
+			   msg_obj_tx_num);
 	if (!dev)
 		return NULL;
 
 	priv = netdev_priv(dev);
-	netif_napi_add(dev, &priv->napi, c_can_poll, C_CAN_NAPI_WEIGHT);
+	priv->msg_obj_num = msg_obj_num;
+	priv->msg_obj_rx_num = msg_obj_num - msg_obj_tx_num;
+	priv->msg_obj_rx_first = 1;
+	priv->msg_obj_rx_last =
+		priv->msg_obj_rx_first + priv->msg_obj_rx_num - 1;
+	priv->msg_obj_rx_mask = (1UL << priv->msg_obj_rx_num) - 1;
+
+	priv->msg_obj_tx_num = msg_obj_tx_num;
+	priv->msg_obj_tx_first = priv->msg_obj_rx_last + 1;
+	priv->msg_obj_tx_last =
+		priv->msg_obj_tx_first + priv->msg_obj_tx_num - 1;
+
+	netif_napi_add(dev, &priv->napi, c_can_poll, priv->msg_obj_rx_num);
 
 	priv->dev = dev;
 	priv->can.bittiming_const = &c_can_bittiming_const;
diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index 90d3d2e7a086..68295fab83d9 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -22,18 +22,7 @@
 #ifndef C_CAN_H
 #define C_CAN_H
 
-/* message object split */
 #define C_CAN_NO_OF_OBJECTS	32
-#define C_CAN_MSG_OBJ_RX_NUM	16
-#define C_CAN_MSG_OBJ_TX_NUM	16
-
-#define C_CAN_MSG_OBJ_RX_FIRST	1
-#define C_CAN_MSG_OBJ_RX_LAST	(C_CAN_MSG_OBJ_RX_FIRST + \
-				C_CAN_MSG_OBJ_RX_NUM - 1)
-
-#define C_CAN_MSG_OBJ_TX_FIRST	(C_CAN_MSG_OBJ_RX_LAST + 1)
-
-#define RECEIVE_OBJECT_BITS	0x0000ffff
 
 enum reg {
 	C_CAN_CTRL_REG = 0,
@@ -193,6 +182,14 @@ struct c_can_priv {
 	struct napi_struct napi;
 	struct net_device *dev;
 	struct device *device;
+	unsigned int msg_obj_num;
+	unsigned int msg_obj_rx_num;
+	unsigned int msg_obj_tx_num;
+	unsigned int msg_obj_rx_first;
+	unsigned int msg_obj_rx_last;
+	unsigned int msg_obj_tx_first;
+	unsigned int msg_obj_tx_last;
+	u32 msg_obj_rx_mask;
 	atomic_t tx_active;
 	atomic_t sie_pending;
 	unsigned long tx_dir;
@@ -209,10 +206,10 @@ struct c_can_priv {
 	void (*raminit) (const struct c_can_priv *priv, bool enable);
 	u32 comm_rcv_high;
 	u32 rxmasked;
-	u32 dlc[C_CAN_MSG_OBJ_TX_NUM];
+	u32 dlc[];
 };
 
-struct net_device *alloc_c_can_dev(void);
+struct net_device *alloc_c_can_dev(int msg_obj_num);
 void free_c_can_dev(struct net_device *dev);
 int register_c_can_dev(struct net_device *dev);
 void unregister_c_can_dev(struct net_device *dev);
diff --git a/drivers/net/can/c_can/c_can_pci.c b/drivers/net/can/c_can/c_can_pci.c
index 406b4847e5dc..3752f68d095e 100644
--- a/drivers/net/can/c_can/c_can_pci.c
+++ b/drivers/net/can/c_can/c_can_pci.c
@@ -149,7 +149,7 @@ static int c_can_pci_probe(struct pci_dev *pdev,
 	}
 
 	/* allocate the c_can device */
-	dev = alloc_c_can_dev();
+	dev = alloc_c_can_dev(C_CAN_NO_OF_OBJECTS);
 	if (!dev) {
 		ret = -ENOMEM;
 		goto out_iounmap;
diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
index 05f425ceb53a..a5b9b1a93702 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -293,7 +293,7 @@ static int c_can_plat_probe(struct platform_device *pdev)
 	}
 
 	/* allocate the c_can device */
-	dev = alloc_c_can_dev();
+	dev = alloc_c_can_dev(C_CAN_NO_OF_OBJECTS);
 	if (!dev) {
 		ret = -ENOMEM;
 		goto exit;
-- 
2.17.1


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

* [PATCH v3 6/6] can: c_can: add support to 64 message objects
  2021-02-28 10:38 [PATCH v3 0/6] can: c_can: add support to 64 message objects Dario Binacchi
                   ` (4 preceding siblings ...)
  2021-02-28 10:38 ` [PATCH v3 5/6] can: c_can: prepare to up the message objects number Dario Binacchi
@ 2021-02-28 10:38 ` Dario Binacchi
  5 siblings, 0 replies; 23+ messages in thread
From: Dario Binacchi @ 2021-02-28 10:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Federico Vaga, Alexander Stein, Dario Binacchi, David S. Miller,
	Jakub Kicinski, Marc Kleine-Budde, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev

D_CAN controller supports 16, 32, 64 or 128 message objects, comparing
to 32 on C_CAN.
AM335x/AM437x Sitara processors and DRA7 SOC all instantiate a D_CAN
controller with 64 message objects, as described in the "DCAN features"
subsection of the CAN chapter of their technical reference manuals.

The driver policy has been kept unchanged, and as in the previous
version, the first half of the message objects is used for reception and
the second for transmission.

The I/O load is increased only in the case of 64 message objects,
keeping it unchanged in the case of 32. Two 32-bit read accesses are in
fact required, which however remained at 16-bit for configurations with
32 message objects.

Signed-off-by: Dario Binacchi <dariobin@libero.it>

---

Changes in v3:
- Use unsigned int instead of int as type of the msg_obj_num field
  in c_can_driver_data and c_can_pci_data structures.

Changes in v2:
- Add message objects number to PCI driver data.

 drivers/net/can/c_can/c_can.c          | 19 +++++++++++--------
 drivers/net/can/c_can/c_can.h          |  5 +++--
 drivers/net/can/c_can/c_can_pci.c      |  6 +++++-
 drivers/net/can/c_can/c_can_platform.c |  6 +++++-
 4 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index ede6f4d62095..bb766904636b 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -723,8 +723,12 @@ static void c_can_do_tx(struct net_device *dev)
 	struct net_device_stats *stats = &dev->stats;
 	u32 idx, obj, pkts = 0, bytes = 0, pend, clr;
 
-	clr = pend = priv->read_reg(priv, C_CAN_INTPND2_REG);
+	if (priv->msg_obj_tx_last > 32)
+		pend = priv->read_reg32(priv, C_CAN_INTPND3_REG);
+	else
+		pend = priv->read_reg(priv, C_CAN_INTPND2_REG);
 
+	clr = pend;
 	while ((idx = ffs(pend))) {
 		idx--;
 		pend &= ~(1 << idx);
@@ -834,7 +838,12 @@ static int c_can_read_objects(struct net_device *dev, struct c_can_priv *priv,
 
 static inline u32 c_can_get_pending(struct c_can_priv *priv)
 {
-	u32 pend = priv->read_reg(priv, C_CAN_NEWDAT1_REG);
+	u32 pend;
+
+	if (priv->msg_obj_rx_last > 16)
+		pend = priv->read_reg32(priv, C_CAN_NEWDAT1_REG);
+	else
+		pend = priv->read_reg(priv, C_CAN_NEWDAT1_REG);
 
 	return pend;
 }
@@ -856,12 +865,6 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)
 	struct c_can_priv *priv = netdev_priv(dev);
 	u32 pkts = 0, pend = 0, toread, n;
 
-	/*
-	 * It is faster to read only one 16bit register. This is only possible
-	 * for a maximum number of 16 objects.
-	 */
-	WARN_ON(priv->msg_obj_rx_last > 16);
-
 	while (quota > 0) {
 		if (!pend) {
 			pend = c_can_get_pending(priv);
diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index 68295fab83d9..bd291e998a51 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -22,8 +22,6 @@
 #ifndef C_CAN_H
 #define C_CAN_H
 
-#define C_CAN_NO_OF_OBJECTS	32
-
 enum reg {
 	C_CAN_CTRL_REG = 0,
 	C_CAN_CTRL_EX_REG,
@@ -61,6 +59,7 @@ enum reg {
 	C_CAN_NEWDAT2_REG,
 	C_CAN_INTPND1_REG,
 	C_CAN_INTPND2_REG,
+	C_CAN_INTPND3_REG,
 	C_CAN_MSGVAL1_REG,
 	C_CAN_MSGVAL2_REG,
 	C_CAN_FUNCTION_REG,
@@ -122,6 +121,7 @@ static const u16 __maybe_unused reg_map_d_can[] = {
 	[C_CAN_NEWDAT2_REG]	= 0x9E,
 	[C_CAN_INTPND1_REG]	= 0xB0,
 	[C_CAN_INTPND2_REG]	= 0xB2,
+	[C_CAN_INTPND3_REG]	= 0xB4,
 	[C_CAN_MSGVAL1_REG]	= 0xC4,
 	[C_CAN_MSGVAL2_REG]	= 0xC6,
 	[C_CAN_IF1_COMREQ_REG]	= 0x100,
@@ -161,6 +161,7 @@ struct raminit_bits {
 
 struct c_can_driver_data {
 	enum c_can_dev_id id;
+	unsigned int msg_obj_num;
 
 	/* RAMINIT register description. Optional. */
 	const struct raminit_bits *raminit_bits; /* Array of START/DONE bit positions */
diff --git a/drivers/net/can/c_can/c_can_pci.c b/drivers/net/can/c_can/c_can_pci.c
index 3752f68d095e..9415b12d26c8 100644
--- a/drivers/net/can/c_can/c_can_pci.c
+++ b/drivers/net/can/c_can/c_can_pci.c
@@ -31,6 +31,8 @@ enum c_can_pci_reg_align {
 struct c_can_pci_data {
 	/* Specify if is C_CAN or D_CAN */
 	enum c_can_dev_id type;
+	/* Number of message objects */
+	unsigned int msg_obj_num;
 	/* Set the register alignment in the memory */
 	enum c_can_pci_reg_align reg_align;
 	/* Set the frequency */
@@ -149,7 +151,7 @@ static int c_can_pci_probe(struct pci_dev *pdev,
 	}
 
 	/* allocate the c_can device */
-	dev = alloc_c_can_dev(C_CAN_NO_OF_OBJECTS);
+	dev = alloc_c_can_dev(c_can_pci_data->msg_obj_num);
 	if (!dev) {
 		ret = -ENOMEM;
 		goto out_iounmap;
@@ -253,6 +255,7 @@ static void c_can_pci_remove(struct pci_dev *pdev)
 
 static const struct c_can_pci_data c_can_sta2x11= {
 	.type = BOSCH_C_CAN,
+	.msg_obj_num = 32,
 	.reg_align = C_CAN_REG_ALIGN_32,
 	.freq = 52000000, /* 52 Mhz */
 	.bar = 0,
@@ -260,6 +263,7 @@ static const struct c_can_pci_data c_can_sta2x11= {
 
 static const struct c_can_pci_data c_can_pch = {
 	.type = BOSCH_C_CAN,
+	.msg_obj_num = 32,
 	.reg_align = C_CAN_REG_32,
 	.freq = 50000000, /* 50 MHz */
 	.init = c_can_pci_reset_pch,
diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
index a5b9b1a93702..87a145b67a2f 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -192,10 +192,12 @@ static void c_can_hw_raminit(const struct c_can_priv *priv, bool enable)
 
 static const struct c_can_driver_data c_can_drvdata = {
 	.id = BOSCH_C_CAN,
+	.msg_obj_num = 32,
 };
 
 static const struct c_can_driver_data d_can_drvdata = {
 	.id = BOSCH_D_CAN,
+	.msg_obj_num = 32,
 };
 
 static const struct raminit_bits dra7_raminit_bits[] = {
@@ -205,6 +207,7 @@ static const struct raminit_bits dra7_raminit_bits[] = {
 
 static const struct c_can_driver_data dra7_dcan_drvdata = {
 	.id = BOSCH_D_CAN,
+	.msg_obj_num = 64,
 	.raminit_num = ARRAY_SIZE(dra7_raminit_bits),
 	.raminit_bits = dra7_raminit_bits,
 	.raminit_pulse = true,
@@ -217,6 +220,7 @@ static const struct raminit_bits am3352_raminit_bits[] = {
 
 static const struct c_can_driver_data am3352_dcan_drvdata = {
 	.id = BOSCH_D_CAN,
+	.msg_obj_num = 64,
 	.raminit_num = ARRAY_SIZE(am3352_raminit_bits),
 	.raminit_bits = am3352_raminit_bits,
 };
@@ -293,7 +297,7 @@ static int c_can_plat_probe(struct platform_device *pdev)
 	}
 
 	/* allocate the c_can device */
-	dev = alloc_c_can_dev(C_CAN_NO_OF_OBJECTS);
+	dev = alloc_c_can_dev(drvdata->msg_obj_num);
 	if (!dev) {
 		ret = -ENOMEM;
 		goto exit;
-- 
2.17.1


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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-02-28 10:38 ` [PATCH v3 5/6] can: c_can: prepare to up the message objects number Dario Binacchi
@ 2021-03-01 11:38   ` Marc Kleine-Budde
  2021-03-01 13:08     ` Marc Kleine-Budde
  2021-03-01 17:21     ` Dario Binacchi
  2021-03-02 18:49   ` Kurt Van Dijck
  1 sibling, 2 replies; 23+ messages in thread
From: Marc Kleine-Budde @ 2021-03-01 11:38 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: linux-kernel, Federico Vaga, Alexander Stein, David S. Miller,
	Jakub Kicinski, Oliver Hartkopp, Vincent Mailhol,
	Wolfgang Grandegger, YueHaibing, Zhang Qilong, linux-can, netdev

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

On 28.02.2021 11:38:54, Dario Binacchi wrote:
[...]

> @@ -730,7 +728,7 @@ static void c_can_do_tx(struct net_device *dev)
>  	while ((idx = ffs(pend))) {
>  		idx--;
>  		pend &= ~(1 << idx);
> -		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> +		obj = idx + priv->msg_obj_tx_first;
>  		c_can_inval_tx_object(dev, IF_TX, obj);
>  		can_get_echo_skb(dev, idx, NULL);
>  		bytes += priv->dlc[idx];
> @@ -740,7 +738,7 @@ static void c_can_do_tx(struct net_device *dev)
>  	/* Clear the bits in the tx_active mask */
>  	atomic_sub(clr, &priv->tx_active);
>  
> -	if (clr & (1 << (C_CAN_MSG_OBJ_TX_NUM - 1)))
> +	if (clr & (1 << (priv->msg_obj_tx_num - 1)))

Do we need 1UL here, too?

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-03-01 11:38   ` Marc Kleine-Budde
@ 2021-03-01 13:08     ` Marc Kleine-Budde
  2021-03-01 16:54       ` Marc Kleine-Budde
  2021-03-01 17:24       ` Dario Binacchi
  2021-03-01 17:21     ` Dario Binacchi
  1 sibling, 2 replies; 23+ messages in thread
From: Marc Kleine-Budde @ 2021-03-01 13:08 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: linux-kernel, Federico Vaga, Oliver Hartkopp, Vincent Mailhol,
	YueHaibing, Zhang Qilong, linux-can, netdev

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

On 01.03.2021 12:38:05, Marc Kleine-Budde wrote:
> On 28.02.2021 11:38:54, Dario Binacchi wrote:
> [...]
> 
> > @@ -730,7 +728,7 @@ static void c_can_do_tx(struct net_device *dev)
> >  	while ((idx = ffs(pend))) {
> >  		idx--;
> >  		pend &= ~(1 << idx);
> > -		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> > +		obj = idx + priv->msg_obj_tx_first;
> >  		c_can_inval_tx_object(dev, IF_TX, obj);
> >  		can_get_echo_skb(dev, idx, NULL);
> >  		bytes += priv->dlc[idx];
> > @@ -740,7 +738,7 @@ static void c_can_do_tx(struct net_device *dev)
> >  	/* Clear the bits in the tx_active mask */
> >  	atomic_sub(clr, &priv->tx_active);
> >  
> > -	if (clr & (1 << (C_CAN_MSG_OBJ_TX_NUM - 1)))
> > +	if (clr & (1 << (priv->msg_obj_tx_num - 1)))
> 
> Do we need 1UL here, too?

There are several more "1 <<" in the driver. As the right side of the
sift operation can be up to 32, I think you should replace all "1 <<"
with "1UL <<".

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-03-01 13:08     ` Marc Kleine-Budde
@ 2021-03-01 16:54       ` Marc Kleine-Budde
  2021-03-01 17:24       ` Dario Binacchi
  1 sibling, 0 replies; 23+ messages in thread
From: Marc Kleine-Budde @ 2021-03-01 16:54 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: linux-kernel, Federico Vaga, Oliver Hartkopp, Vincent Mailhol,
	YueHaibing, Zhang Qilong, linux-can, netdev

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

On 01.03.2021 14:08:45, Marc Kleine-Budde wrote:
> On 01.03.2021 12:38:05, Marc Kleine-Budde wrote:
> > On 28.02.2021 11:38:54, Dario Binacchi wrote:
> > [...]
> > 
> > > @@ -730,7 +728,7 @@ static void c_can_do_tx(struct net_device *dev)
> > >  	while ((idx = ffs(pend))) {
> > >  		idx--;
> > >  		pend &= ~(1 << idx);
> > > -		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> > > +		obj = idx + priv->msg_obj_tx_first;
> > >  		c_can_inval_tx_object(dev, IF_TX, obj);
> > >  		can_get_echo_skb(dev, idx, NULL);
> > >  		bytes += priv->dlc[idx];
> > > @@ -740,7 +738,7 @@ static void c_can_do_tx(struct net_device *dev)
> > >  	/* Clear the bits in the tx_active mask */
> > >  	atomic_sub(clr, &priv->tx_active);
> > >  
> > > -	if (clr & (1 << (C_CAN_MSG_OBJ_TX_NUM - 1)))
> > > +	if (clr & (1 << (priv->msg_obj_tx_num - 1)))
> > 
> > Do we need 1UL here, too?
> 
> There are several more "1 <<" in the driver. As the right side of the
> sift operation can be up to 32, I think you should replace all "1 <<"
> with "1UL <<".

Even better use BIT() for setting single bits and GENMASK() to generate
masks.

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-03-01 11:38   ` Marc Kleine-Budde
  2021-03-01 13:08     ` Marc Kleine-Budde
@ 2021-03-01 17:21     ` Dario Binacchi
  2021-03-01 19:45       ` Marc Kleine-Budde
  1 sibling, 1 reply; 23+ messages in thread
From: Dario Binacchi @ 2021-03-01 17:21 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: linux-kernel, Federico Vaga, Alexander Stein, David S. Miller,
	Jakub Kicinski, Oliver Hartkopp, Vincent Mailhol,
	Wolfgang Grandegger, YueHaibing, Zhang Qilong, linux-can, netdev

Hi Marc,

> Il 01/03/2021 12:38 Marc Kleine-Budde <mkl@pengutronix.de> ha scritto:
> 
>  
> On 28.02.2021 11:38:54, Dario Binacchi wrote:
> [...]
> 
> > @@ -730,7 +728,7 @@ static void c_can_do_tx(struct net_device *dev)
> >  	while ((idx = ffs(pend))) {
> >  		idx--;
> >  		pend &= ~(1 << idx);
> > -		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> > +		obj = idx + priv->msg_obj_tx_first;
> >  		c_can_inval_tx_object(dev, IF_TX, obj);
> >  		can_get_echo_skb(dev, idx, NULL);
> >  		bytes += priv->dlc[idx];
> > @@ -740,7 +738,7 @@ static void c_can_do_tx(struct net_device *dev)
> >  	/* Clear the bits in the tx_active mask */
> >  	atomic_sub(clr, &priv->tx_active);
> >  
> > -	if (clr & (1 << (C_CAN_MSG_OBJ_TX_NUM - 1)))
> > +	if (clr & (1 << (priv->msg_obj_tx_num - 1)))
> 
> Do we need 1UL here, too?

Do you agree if I use the BIT macro ?

Thanks and regards
Dario

> 
> Marc
> 
> -- 
> Pengutronix e.K.                 | Marc Kleine-Budde           |
> Embedded Linux                   | https://www.pengutronix.de  |
> Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
> Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-03-01 13:08     ` Marc Kleine-Budde
  2021-03-01 16:54       ` Marc Kleine-Budde
@ 2021-03-01 17:24       ` Dario Binacchi
  2021-03-01 19:46         ` Marc Kleine-Budde
  1 sibling, 1 reply; 23+ messages in thread
From: Dario Binacchi @ 2021-03-01 17:24 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: linux-kernel, Federico Vaga, Oliver Hartkopp, Vincent Mailhol,
	YueHaibing, Zhang Qilong, linux-can, netdev

Hi Marc,

> Il 01/03/2021 14:08 Marc Kleine-Budde <mkl@pengutronix.de> ha scritto:
> 
>  
> On 01.03.2021 12:38:05, Marc Kleine-Budde wrote:
> > On 28.02.2021 11:38:54, Dario Binacchi wrote:
> > [...]
> > 
> > > @@ -730,7 +728,7 @@ static void c_can_do_tx(struct net_device *dev)
> > >  	while ((idx = ffs(pend))) {
> > >  		idx--;
> > >  		pend &= ~(1 << idx);
> > > -		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> > > +		obj = idx + priv->msg_obj_tx_first;
> > >  		c_can_inval_tx_object(dev, IF_TX, obj);
> > >  		can_get_echo_skb(dev, idx, NULL);
> > >  		bytes += priv->dlc[idx];
> > > @@ -740,7 +738,7 @@ static void c_can_do_tx(struct net_device *dev)
> > >  	/* Clear the bits in the tx_active mask */
> > >  	atomic_sub(clr, &priv->tx_active);
> > >  
> > > -	if (clr & (1 << (C_CAN_MSG_OBJ_TX_NUM - 1)))
> > > +	if (clr & (1 << (priv->msg_obj_tx_num - 1)))
> > 
> > Do we need 1UL here, too?
> 
> There are several more "1 <<" in the driver. As the right side of the
> sift operation can be up to 32, I think you should replace all "1 <<"
> with "1UL <<".

Do you agree if I use the BIT macro for all these shift operations?

Thanks and regards
Dario

> 
> regards,
> Marc
> 
> -- 
> Pengutronix e.K.                 | Marc Kleine-Budde           |
> Embedded Linux                   | https://www.pengutronix.de  |
> Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
> Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-03-01 17:21     ` Dario Binacchi
@ 2021-03-01 19:45       ` Marc Kleine-Budde
  2021-03-02 10:50         ` Dario Binacchi
  0 siblings, 1 reply; 23+ messages in thread
From: Marc Kleine-Budde @ 2021-03-01 19:45 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: linux-kernel, Federico Vaga, Alexander Stein, David S. Miller,
	Jakub Kicinski, Oliver Hartkopp, Vincent Mailhol,
	Wolfgang Grandegger, YueHaibing, Zhang Qilong, linux-can, netdev

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

On 01.03.2021 18:21:42, Dario Binacchi wrote:
> > > @@ -730,7 +728,7 @@ static void c_can_do_tx(struct net_device *dev)
> > >  	while ((idx = ffs(pend))) {
> > >  		idx--;
> > >  		pend &= ~(1 << idx);
> > > -		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> > > +		obj = idx + priv->msg_obj_tx_first;
> > >  		c_can_inval_tx_object(dev, IF_TX, obj);
> > >  		can_get_echo_skb(dev, idx, NULL);
> > >  		bytes += priv->dlc[idx];
> > > @@ -740,7 +738,7 @@ static void c_can_do_tx(struct net_device *dev)
> > >  	/* Clear the bits in the tx_active mask */
> > >  	atomic_sub(clr, &priv->tx_active);
> > >  
> > > -	if (clr & (1 << (C_CAN_MSG_OBJ_TX_NUM - 1)))
> > > +	if (clr & (1 << (priv->msg_obj_tx_num - 1)))
> > 
> > Do we need 1UL here, too?
> 
> Do you agree if I use the BIT macro ?

No, please use GENMASK(priv->msg_obj_tx_num, 0) here.

regrads,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-03-01 17:24       ` Dario Binacchi
@ 2021-03-01 19:46         ` Marc Kleine-Budde
  0 siblings, 0 replies; 23+ messages in thread
From: Marc Kleine-Budde @ 2021-03-01 19:46 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: linux-kernel, Federico Vaga, Oliver Hartkopp, Vincent Mailhol,
	YueHaibing, Zhang Qilong, linux-can, netdev

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

On 01.03.2021 18:24:31, Dario Binacchi wrote:
> Hi Marc,
> 
> > Il 01/03/2021 14:08 Marc Kleine-Budde <mkl@pengutronix.de> ha scritto:
> > 
> >  
> > On 01.03.2021 12:38:05, Marc Kleine-Budde wrote:
> > > On 28.02.2021 11:38:54, Dario Binacchi wrote:
> > > [...]
> > > 
> > > > @@ -730,7 +728,7 @@ static void c_can_do_tx(struct net_device *dev)
> > > >  	while ((idx = ffs(pend))) {
> > > >  		idx--;
> > > >  		pend &= ~(1 << idx);
> > > > -		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> > > > +		obj = idx + priv->msg_obj_tx_first;
> > > >  		c_can_inval_tx_object(dev, IF_TX, obj);
> > > >  		can_get_echo_skb(dev, idx, NULL);
> > > >  		bytes += priv->dlc[idx];
> > > > @@ -740,7 +738,7 @@ static void c_can_do_tx(struct net_device *dev)
> > > >  	/* Clear the bits in the tx_active mask */
> > > >  	atomic_sub(clr, &priv->tx_active);
> > > >  
> > > > -	if (clr & (1 << (C_CAN_MSG_OBJ_TX_NUM - 1)))
> > > > +	if (clr & (1 << (priv->msg_obj_tx_num - 1)))
> > > 
> > > Do we need 1UL here, too?
> > 
> > There are several more "1 <<" in the driver. As the right side of the
> > sift operation can be up to 32, I think you should replace all "1 <<"
> > with "1UL <<".
> 
> Do you agree if I use the BIT macro for all these shift operations?

No, only use BIT(), where you want to set a single bit, use GENMASK()
for masks.

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-03-01 19:45       ` Marc Kleine-Budde
@ 2021-03-02 10:50         ` Dario Binacchi
  2021-03-02 10:56           ` Marc Kleine-Budde
  0 siblings, 1 reply; 23+ messages in thread
From: Dario Binacchi @ 2021-03-02 10:50 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: linux-kernel, Federico Vaga, Alexander Stein, David S. Miller,
	Jakub Kicinski, Oliver Hartkopp, Vincent Mailhol,
	Wolfgang Grandegger, YueHaibing, Zhang Qilong, linux-can, netdev

Hi Marc,

> Il 01/03/2021 20:45 Marc Kleine-Budde <mkl@pengutronix.de> ha scritto:
> 
>  
> On 01.03.2021 18:21:42, Dario Binacchi wrote:
> > > > @@ -730,7 +728,7 @@ static void c_can_do_tx(struct net_device *dev)
> > > >  	while ((idx = ffs(pend))) {
> > > >  		idx--;
> > > >  		pend &= ~(1 << idx);
> > > > -		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> > > > +		obj = idx + priv->msg_obj_tx_first;
> > > >  		c_can_inval_tx_object(dev, IF_TX, obj);
> > > >  		can_get_echo_skb(dev, idx, NULL);
> > > >  		bytes += priv->dlc[idx];
> > > > @@ -740,7 +738,7 @@ static void c_can_do_tx(struct net_device *dev)
> > > >  	/* Clear the bits in the tx_active mask */
> > > >  	atomic_sub(clr, &priv->tx_active);
> > > >  
> > > > -	if (clr & (1 << (C_CAN_MSG_OBJ_TX_NUM - 1)))
> > > > +	if (clr & (1 << (priv->msg_obj_tx_num - 1)))
> > > 
> > > Do we need 1UL here, too?
> > 
> > Do you agree if I use the BIT macro ?
> 
> No, please use GENMASK(priv->msg_obj_tx_num, 0) here.
> 

In case of 64 message objects, msg_obj_tx_num = 32, and 1 << (priv->msg_obj_tx_num - 1) = 0x80000000. 
GENMASK(priv->msg_obj_tx_num, 0) = 0. 
BIT(priv->msg_obj_tx_num - 1) = 0x80000000.

Thanks and regards,
Dario

> regrads,
> Marc
> 
> -- 
> Pengutronix e.K.                 | Marc Kleine-Budde           |
> Embedded Linux                   | https://www.pengutronix.de  |
> Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
> Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-03-02 10:50         ` Dario Binacchi
@ 2021-03-02 10:56           ` Marc Kleine-Budde
  0 siblings, 0 replies; 23+ messages in thread
From: Marc Kleine-Budde @ 2021-03-02 10:56 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: linux-kernel, Federico Vaga, Alexander Stein, David S. Miller,
	Jakub Kicinski, Oliver Hartkopp, Vincent Mailhol,
	Wolfgang Grandegger, YueHaibing, Zhang Qilong, linux-can, netdev


[-- Attachment #1.1: Type: text/plain, Size: 1536 bytes --]

On 3/2/21 11:50 AM, Dario Binacchi wrote:
> Hi Marc,
> 
>> Il 01/03/2021 20:45 Marc Kleine-Budde <mkl@pengutronix.de> ha scritto:
>>
>>  
>> On 01.03.2021 18:21:42, Dario Binacchi wrote:
>>>>> @@ -730,7 +728,7 @@ static void c_can_do_tx(struct net_device *dev)
>>>>>  	while ((idx = ffs(pend))) {
>>>>>  		idx--;
>>>>>  		pend &= ~(1 << idx);
>>>>> -		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
>>>>> +		obj = idx + priv->msg_obj_tx_first;
>>>>>  		c_can_inval_tx_object(dev, IF_TX, obj);
>>>>>  		can_get_echo_skb(dev, idx, NULL);
>>>>>  		bytes += priv->dlc[idx];
>>>>> @@ -740,7 +738,7 @@ static void c_can_do_tx(struct net_device *dev)
>>>>>  	/* Clear the bits in the tx_active mask */
>>>>>  	atomic_sub(clr, &priv->tx_active);
>>>>>  
>>>>> -	if (clr & (1 << (C_CAN_MSG_OBJ_TX_NUM - 1)))
>>>>> +	if (clr & (1 << (priv->msg_obj_tx_num - 1)))
>>>>
>>>> Do we need 1UL here, too?
>>>
>>> Do you agree if I use the BIT macro ?
>>
>> No, please use GENMASK(priv->msg_obj_tx_num, 0) here.
> 
> In case of 64 message objects, msg_obj_tx_num = 32, and 1 << (priv->msg_obj_tx_num - 1) = 0x80000000. 
> GENMASK(priv->msg_obj_tx_num, 0) = 0. 
> BIT(priv->msg_obj_tx_num - 1) = 0x80000000.

Doh! I've misread where the -1 is places.

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v3 3/6] can: c_can: fix control interface used by c_can_do_tx
  2021-02-28 10:38 ` [PATCH v3 3/6] can: c_can: fix control interface used by c_can_do_tx Dario Binacchi
@ 2021-03-02 18:44   ` Kurt Van Dijck
  2021-03-03  7:22     ` Dario Binacchi
  0 siblings, 1 reply; 23+ messages in thread
From: Kurt Van Dijck @ 2021-03-02 18:44 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: linux-kernel, Federico Vaga, Alexander Stein, David S. Miller,
	Jakub Kicinski, Marc Kleine-Budde, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev

On Sun, 28 Feb 2021 11:38:52 +0100, Dario Binacchi wrote:
> According to commit 640916db2bf7 ("can: c_can: Make it SMP safe") let RX use
> IF1 (i.e. IF_RX) and TX use IF2 (i.e. IF_TX).
> 
> Signed-off-by: Dario Binacchi <dariobin@libero.it>
> ---
> 
> (no changes since v1)
> 
>  drivers/net/can/c_can/c_can.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
> index dbcc1c1c92d6..69526c3a671c 100644
> --- a/drivers/net/can/c_can/c_can.c
> +++ b/drivers/net/can/c_can/c_can.c
> @@ -732,7 +732,7 @@ static void c_can_do_tx(struct net_device *dev)
>  		idx--;
>  		pend &= ~(1 << idx);
>  		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> -		c_can_inval_tx_object(dev, IF_RX, obj);
> +		c_can_inval_tx_object(dev, IF_TX, obj);

Right. I had a similar effort last year to increase the reception
throughput, but I ended with some sporadic strange tx echo problems.
This fix may have fixed my problem as wel.

>  		can_get_echo_skb(dev, idx, NULL);
>  		bytes += priv->dlc[idx];
>  		pkts++;
> -- 
> 2.17.1
> 

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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-02-28 10:38 ` [PATCH v3 5/6] can: c_can: prepare to up the message objects number Dario Binacchi
  2021-03-01 11:38   ` Marc Kleine-Budde
@ 2021-03-02 18:49   ` Kurt Van Dijck
  2021-03-03  8:23     ` Dario Binacchi
  1 sibling, 1 reply; 23+ messages in thread
From: Kurt Van Dijck @ 2021-03-02 18:49 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: linux-kernel, Federico Vaga, Alexander Stein, David S. Miller,
	Jakub Kicinski, Marc Kleine-Budde, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev

On Sun, 28 Feb 2021 11:38:54 +0100, Dario Binacchi wrote:
> Date:   Sun, 28 Feb 2021 11:38:54 +0100
> From: Dario Binacchi <dariobin@libero.it>
> To: linux-kernel@vger.kernel.org
> Cc: Federico Vaga <federico.vaga@gmail.com>, Alexander Stein
>  <alexander.stein@systec-electronic.com>, Dario Binacchi
>  <dariobin@libero.it>, "David S. Miller" <davem@davemloft.net>, Jakub
>  Kicinski <kuba@kernel.org>, Marc Kleine-Budde <mkl@pengutronix.de>, Oliver
>  Hartkopp <socketcan@hartkopp.net>, Vincent Mailhol
>  <mailhol.vincent@wanadoo.fr>, Wolfgang Grandegger <wg@grandegger.com>,
>  YueHaibing <yuehaibing@huawei.com>, Zhang Qilong
>  <zhangqilong3@huawei.com>, linux-can@vger.kernel.org,
>  netdev@vger.kernel.org
> Subject: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
> X-Mailer: git-send-email 2.17.1
> 
> As pointed by commit c0a9f4d396c9 ("can: c_can: Reduce register access")
> the "driver casts the 16 message objects in stone, which is completely
> braindead as contemporary hardware has up to 128 message objects".
> 
> The patch prepares the module to extend the number of message objects
> beyond the 32 currently managed. This was achieved by transforming the
> constants used to manage RX/TX messages into variables without changing
> the driver policy.
> 
> Signed-off-by: Dario Binacchi <dariobin@libero.it>
> Reported-by: kernel test robot <lkp@intel.com>
> 
> ---
> 
> Changes in v3:
> - Use unsigned int instead of int as type of the msg_obj_* fields
>   in the c_can_priv structure.
> - Replace (u64)1 with 1UL in msg_obj_rx_mask setting.
> 
> Changes in v2:
> - Fix compiling error reported by kernel test robot.
> - Add Reported-by tag.
> - Pass larger size to alloc_candev() routine to avoid an additional
>   memory allocation/deallocation.
> 
>  drivers/net/can/c_can/c_can.c          | 50 ++++++++++++++++----------
>  drivers/net/can/c_can/c_can.h          | 23 ++++++------
>  drivers/net/can/c_can/c_can_pci.c      |  2 +-
>  drivers/net/can/c_can/c_can_platform.c |  2 +-
>  4 files changed, 43 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
> index 7081cfaf62e2..ede6f4d62095 100644
> --- a/drivers/net/can/c_can/c_can.c
> +++ b/drivers/net/can/c_can/c_can.c
> @@ -173,9 +173,6 @@
>  /* Wait for ~1 sec for INIT bit */
>  #define INIT_WAIT_MS		1000
>  
> -/* napi related */
> -#define C_CAN_NAPI_WEIGHT	C_CAN_MSG_OBJ_RX_NUM
> -
>  /* c_can lec values */
>  enum c_can_lec_type {
>  	LEC_NO_ERROR = 0,
> @@ -325,7 +322,7 @@ static void c_can_setup_tx_object(struct net_device *dev, int iface,
>  	 * first, i.e. clear the MSGVAL flag in the arbiter.
>  	 */
>  	if (rtr != (bool)test_bit(idx, &priv->tx_dir)) {
> -		u32 obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> +		u32 obj = idx + priv->msg_obj_tx_first;
>  
>  		c_can_inval_msg_object(dev, iface, obj);
>  		change_bit(idx, &priv->tx_dir);
> @@ -463,10 +460,10 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,
>  	 * prioritized. The lowest buffer number wins.
>  	 */
>  	idx = fls(atomic_read(&priv->tx_active));
> -	obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> +	obj = idx + priv->msg_obj_tx_first;
>  
>  	/* If this is the last buffer, stop the xmit queue */
> -	if (idx == C_CAN_MSG_OBJ_TX_NUM - 1)
> +	if (idx == priv->msg_obj_tx_num - 1)
>  		netif_stop_queue(dev);
>  	/*
>  	 * Store the message in the interface so we can call
> @@ -549,17 +546,18 @@ static int c_can_set_bittiming(struct net_device *dev)
>   */
>  static void c_can_configure_msg_objects(struct net_device *dev)
>  {
> +	struct c_can_priv *priv = netdev_priv(dev);
>  	int i;
>  
>  	/* first invalidate all message objects */
> -	for (i = C_CAN_MSG_OBJ_RX_FIRST; i <= C_CAN_NO_OF_OBJECTS; i++)
> +	for (i = priv->msg_obj_rx_first; i <= priv->msg_obj_num; i++)
>  		c_can_inval_msg_object(dev, IF_RX, i);
>  
>  	/* setup receive message objects */
> -	for (i = C_CAN_MSG_OBJ_RX_FIRST; i < C_CAN_MSG_OBJ_RX_LAST; i++)
> +	for (i = priv->msg_obj_rx_first; i < priv->msg_obj_rx_last; i++)
>  		c_can_setup_receive_object(dev, IF_RX, i, 0, 0, IF_MCONT_RCV);
>  
> -	c_can_setup_receive_object(dev, IF_RX, C_CAN_MSG_OBJ_RX_LAST, 0, 0,
> +	c_can_setup_receive_object(dev, IF_RX, priv->msg_obj_rx_last, 0, 0,
>  				   IF_MCONT_RCV_EOB);
>  }
>  
> @@ -730,7 +728,7 @@ static void c_can_do_tx(struct net_device *dev)
>  	while ((idx = ffs(pend))) {
>  		idx--;
>  		pend &= ~(1 << idx);
> -		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> +		obj = idx + priv->msg_obj_tx_first;
>  		c_can_inval_tx_object(dev, IF_TX, obj);
>  		can_get_echo_skb(dev, idx, NULL);
>  		bytes += priv->dlc[idx];
> @@ -740,7 +738,7 @@ static void c_can_do_tx(struct net_device *dev)
>  	/* Clear the bits in the tx_active mask */
>  	atomic_sub(clr, &priv->tx_active);
>  
> -	if (clr & (1 << (C_CAN_MSG_OBJ_TX_NUM - 1)))
> +	if (clr & (1 << (priv->msg_obj_tx_num - 1)))
>  		netif_wake_queue(dev);
>  
>  	if (pkts) {
> @@ -755,11 +753,11 @@ static void c_can_do_tx(struct net_device *dev)
>   * raced with the hardware or failed to readout all upper
>   * objects in the last run due to quota limit.
>   */
> -static u32 c_can_adjust_pending(u32 pend)
> +static u32 c_can_adjust_pending(u32 pend, u32 rx_mask)
>  {
>  	u32 weight, lasts;
>  
> -	if (pend == RECEIVE_OBJECT_BITS)
> +	if (pend == rx_mask)
>  		return pend;
>  
>  	/*
> @@ -862,8 +860,7 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)
>  	 * It is faster to read only one 16bit register. This is only possible
>  	 * for a maximum number of 16 objects.
>  	 */
> -	BUILD_BUG_ON_MSG(C_CAN_MSG_OBJ_RX_LAST > 16,
> -			"Implementation does not support more message objects than 16");
> +	WARN_ON(priv->msg_obj_rx_last > 16);
>  
>  	while (quota > 0) {
>  		if (!pend) {
> @@ -874,7 +871,8 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)
>  			 * If the pending field has a gap, handle the
>  			 * bits above the gap first.
>  			 */
> -			toread = c_can_adjust_pending(pend);
> +			toread = c_can_adjust_pending(pend,
> +						      priv->msg_obj_rx_mask);
>  		} else {
>  			toread = pend;
>  		}
> @@ -1205,17 +1203,31 @@ static int c_can_close(struct net_device *dev)
>  	return 0;
>  }
>  
> -struct net_device *alloc_c_can_dev(void)
> +struct net_device *alloc_c_can_dev(int msg_obj_num)
>  {
>  	struct net_device *dev;
>  	struct c_can_priv *priv;
> +	int msg_obj_tx_num = msg_obj_num / 2;

IMO, a bigger tx queue is not usefull.
A bigger rx queue however is.

My series last year took a fixed lenght of 8 for tx,
and use the remaining as rx queue.

>  
> -	dev = alloc_candev(sizeof(struct c_can_priv), C_CAN_MSG_OBJ_TX_NUM);
> +	dev = alloc_candev(sizeof(*priv) + sizeof(u32) * msg_obj_tx_num,
> +			   msg_obj_tx_num);
>  	if (!dev)
>  		return NULL;
>  
>  	priv = netdev_priv(dev);
> -	netif_napi_add(dev, &priv->napi, c_can_poll, C_CAN_NAPI_WEIGHT);
> +	priv->msg_obj_num = msg_obj_num;
> +	priv->msg_obj_rx_num = msg_obj_num - msg_obj_tx_num;
> +	priv->msg_obj_rx_first = 1;
> +	priv->msg_obj_rx_last =
> +		priv->msg_obj_rx_first + priv->msg_obj_rx_num - 1;
> +	priv->msg_obj_rx_mask = (1UL << priv->msg_obj_rx_num) - 1;
> +
> +	priv->msg_obj_tx_num = msg_obj_tx_num;
> +	priv->msg_obj_tx_first = priv->msg_obj_rx_last + 1;
> +	priv->msg_obj_tx_last =
> +		priv->msg_obj_tx_first + priv->msg_obj_tx_num - 1;
> +
> +	netif_napi_add(dev, &priv->napi, c_can_poll, priv->msg_obj_rx_num);
>  
>  	priv->dev = dev;
>  	priv->can.bittiming_const = &c_can_bittiming_const;
> diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
> index 90d3d2e7a086..68295fab83d9 100644
> --- a/drivers/net/can/c_can/c_can.h
> +++ b/drivers/net/can/c_can/c_can.h
> @@ -22,18 +22,7 @@
>  #ifndef C_CAN_H
>  #define C_CAN_H
>  
> -/* message object split */
>  #define C_CAN_NO_OF_OBJECTS	32
> -#define C_CAN_MSG_OBJ_RX_NUM	16
> -#define C_CAN_MSG_OBJ_TX_NUM	16
> -
> -#define C_CAN_MSG_OBJ_RX_FIRST	1
> -#define C_CAN_MSG_OBJ_RX_LAST	(C_CAN_MSG_OBJ_RX_FIRST + \
> -				C_CAN_MSG_OBJ_RX_NUM - 1)
> -
> -#define C_CAN_MSG_OBJ_TX_FIRST	(C_CAN_MSG_OBJ_RX_LAST + 1)
> -
> -#define RECEIVE_OBJECT_BITS	0x0000ffff
>  
>  enum reg {
>  	C_CAN_CTRL_REG = 0,
> @@ -193,6 +182,14 @@ struct c_can_priv {
>  	struct napi_struct napi;
>  	struct net_device *dev;
>  	struct device *device;
> +	unsigned int msg_obj_num;
> +	unsigned int msg_obj_rx_num;
> +	unsigned int msg_obj_tx_num;
> +	unsigned int msg_obj_rx_first;
> +	unsigned int msg_obj_rx_last;
> +	unsigned int msg_obj_tx_first;
> +	unsigned int msg_obj_tx_last;
> +	u32 msg_obj_rx_mask;
>  	atomic_t tx_active;
>  	atomic_t sie_pending;
>  	unsigned long tx_dir;
> @@ -209,10 +206,10 @@ struct c_can_priv {
>  	void (*raminit) (const struct c_can_priv *priv, bool enable);
>  	u32 comm_rcv_high;
>  	u32 rxmasked;
> -	u32 dlc[C_CAN_MSG_OBJ_TX_NUM];
> +	u32 dlc[];
>  };
>  
> -struct net_device *alloc_c_can_dev(void);
> +struct net_device *alloc_c_can_dev(int msg_obj_num);
>  void free_c_can_dev(struct net_device *dev);
>  int register_c_can_dev(struct net_device *dev);
>  void unregister_c_can_dev(struct net_device *dev);
> diff --git a/drivers/net/can/c_can/c_can_pci.c b/drivers/net/can/c_can/c_can_pci.c
> index 406b4847e5dc..3752f68d095e 100644
> --- a/drivers/net/can/c_can/c_can_pci.c
> +++ b/drivers/net/can/c_can/c_can_pci.c
> @@ -149,7 +149,7 @@ static int c_can_pci_probe(struct pci_dev *pdev,
>  	}
>  
>  	/* allocate the c_can device */
> -	dev = alloc_c_can_dev();
> +	dev = alloc_c_can_dev(C_CAN_NO_OF_OBJECTS);
>  	if (!dev) {
>  		ret = -ENOMEM;
>  		goto out_iounmap;
> diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
> index 05f425ceb53a..a5b9b1a93702 100644
> --- a/drivers/net/can/c_can/c_can_platform.c
> +++ b/drivers/net/can/c_can/c_can_platform.c
> @@ -293,7 +293,7 @@ static int c_can_plat_probe(struct platform_device *pdev)
>  	}
>  
>  	/* allocate the c_can device */
> -	dev = alloc_c_can_dev();
> +	dev = alloc_c_can_dev(C_CAN_NO_OF_OBJECTS);
>  	if (!dev) {
>  		ret = -ENOMEM;
>  		goto exit;
> -- 
> 2.17.1
> 

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

* Re: [PATCH v3 3/6] can: c_can: fix control interface used by c_can_do_tx
  2021-03-02 18:44   ` Kurt Van Dijck
@ 2021-03-03  7:22     ` Dario Binacchi
  0 siblings, 0 replies; 23+ messages in thread
From: Dario Binacchi @ 2021-03-03  7:22 UTC (permalink / raw)
  To: Kurt Van Dijck
  Cc: linux-kernel, Federico Vaga, Alexander Stein, David S. Miller,
	Jakub Kicinski, Marc Kleine-Budde, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev

Hi Kurt,

> Il 02/03/2021 19:44 Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be> ha scritto:
> 
>  
> On Sun, 28 Feb 2021 11:38:52 +0100, Dario Binacchi wrote:
> > According to commit 640916db2bf7 ("can: c_can: Make it SMP safe") let RX use
> > IF1 (i.e. IF_RX) and TX use IF2 (i.e. IF_TX).
> > 
> > Signed-off-by: Dario Binacchi <dariobin@libero.it>
> > ---
> > 
> > (no changes since v1)
> > 
> >  drivers/net/can/c_can/c_can.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
> > index dbcc1c1c92d6..69526c3a671c 100644
> > --- a/drivers/net/can/c_can/c_can.c
> > +++ b/drivers/net/can/c_can/c_can.c
> > @@ -732,7 +732,7 @@ static void c_can_do_tx(struct net_device *dev)
> >  		idx--;
> >  		pend &= ~(1 << idx);
> >  		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> > -		c_can_inval_tx_object(dev, IF_RX, obj);
> > +		c_can_inval_tx_object(dev, IF_TX, obj);
> 
> Right. I had a similar effort last year to increase the reception
> throughput, but I ended with some sporadic strange tx echo problems.
> This fix may have fixed my problem as well.

Take a look at https://lore.kernel.org/patchwork/patch/1384649/

Thanks and regards,
Dario
> 
> >  		can_get_echo_skb(dev, idx, NULL);
> >  		bytes += priv->dlc[idx];
> >  		pkts++;
> > -- 
> > 2.17.1
> >

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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-03-02 18:49   ` Kurt Van Dijck
@ 2021-03-03  8:23     ` Dario Binacchi
  2021-03-03  9:00       ` Marc Kleine-Budde
  0 siblings, 1 reply; 23+ messages in thread
From: Dario Binacchi @ 2021-03-03  8:23 UTC (permalink / raw)
  To: Kurt Van Dijck
  Cc: linux-kernel, Federico Vaga, Alexander Stein, David S. Miller,
	Jakub Kicinski, Marc Kleine-Budde, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev

Hi Kurt,

> Il 02/03/2021 19:49 Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be> ha scritto:
> 
>  
> On Sun, 28 Feb 2021 11:38:54 +0100, Dario Binacchi wrote:
> > Date:   Sun, 28 Feb 2021 11:38:54 +0100
> > From: Dario Binacchi <dariobin@libero.it>
> > To: linux-kernel@vger.kernel.org
> > Cc: Federico Vaga <federico.vaga@gmail.com>, Alexander Stein
> >  <alexander.stein@systec-electronic.com>, Dario Binacchi
> >  <dariobin@libero.it>, "David S. Miller" <davem@davemloft.net>, Jakub
> >  Kicinski <kuba@kernel.org>, Marc Kleine-Budde <mkl@pengutronix.de>, Oliver
> >  Hartkopp <socketcan@hartkopp.net>, Vincent Mailhol
> >  <mailhol.vincent@wanadoo.fr>, Wolfgang Grandegger <wg@grandegger.com>,
> >  YueHaibing <yuehaibing@huawei.com>, Zhang Qilong
> >  <zhangqilong3@huawei.com>, linux-can@vger.kernel.org,
> >  netdev@vger.kernel.org
> > Subject: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
> > X-Mailer: git-send-email 2.17.1
> > 
> > As pointed by commit c0a9f4d396c9 ("can: c_can: Reduce register access")
> > the "driver casts the 16 message objects in stone, which is completely
> > braindead as contemporary hardware has up to 128 message objects".
> > 
> > The patch prepares the module to extend the number of message objects
> > beyond the 32 currently managed. This was achieved by transforming the
> > constants used to manage RX/TX messages into variables without changing
> > the driver policy.
> > 
> > Signed-off-by: Dario Binacchi <dariobin@libero.it>
> > Reported-by: kernel test robot <lkp@intel.com>
> > 
> > ---
> > 
> > Changes in v3:
> > - Use unsigned int instead of int as type of the msg_obj_* fields
> >   in the c_can_priv structure.
> > - Replace (u64)1 with 1UL in msg_obj_rx_mask setting.
> > 
> > Changes in v2:
> > - Fix compiling error reported by kernel test robot.
> > - Add Reported-by tag.
> > - Pass larger size to alloc_candev() routine to avoid an additional
> >   memory allocation/deallocation.
> > 
> >  drivers/net/can/c_can/c_can.c          | 50 ++++++++++++++++----------
> >  drivers/net/can/c_can/c_can.h          | 23 ++++++------
> >  drivers/net/can/c_can/c_can_pci.c      |  2 +-
> >  drivers/net/can/c_can/c_can_platform.c |  2 +-
> >  4 files changed, 43 insertions(+), 34 deletions(-)
> > 
> > diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
> > index 7081cfaf62e2..ede6f4d62095 100644
> > --- a/drivers/net/can/c_can/c_can.c
> > +++ b/drivers/net/can/c_can/c_can.c
> > @@ -173,9 +173,6 @@
> >  /* Wait for ~1 sec for INIT bit */
> >  #define INIT_WAIT_MS		1000
> >  
> > -/* napi related */
> > -#define C_CAN_NAPI_WEIGHT	C_CAN_MSG_OBJ_RX_NUM
> > -
> >  /* c_can lec values */
> >  enum c_can_lec_type {
> >  	LEC_NO_ERROR = 0,
> > @@ -325,7 +322,7 @@ static void c_can_setup_tx_object(struct net_device *dev, int iface,
> >  	 * first, i.e. clear the MSGVAL flag in the arbiter.
> >  	 */
> >  	if (rtr != (bool)test_bit(idx, &priv->tx_dir)) {
> > -		u32 obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> > +		u32 obj = idx + priv->msg_obj_tx_first;
> >  
> >  		c_can_inval_msg_object(dev, iface, obj);
> >  		change_bit(idx, &priv->tx_dir);
> > @@ -463,10 +460,10 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,
> >  	 * prioritized. The lowest buffer number wins.
> >  	 */
> >  	idx = fls(atomic_read(&priv->tx_active));
> > -	obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> > +	obj = idx + priv->msg_obj_tx_first;
> >  
> >  	/* If this is the last buffer, stop the xmit queue */
> > -	if (idx == C_CAN_MSG_OBJ_TX_NUM - 1)
> > +	if (idx == priv->msg_obj_tx_num - 1)
> >  		netif_stop_queue(dev);
> >  	/*
> >  	 * Store the message in the interface so we can call
> > @@ -549,17 +546,18 @@ static int c_can_set_bittiming(struct net_device *dev)
> >   */
> >  static void c_can_configure_msg_objects(struct net_device *dev)
> >  {
> > +	struct c_can_priv *priv = netdev_priv(dev);
> >  	int i;
> >  
> >  	/* first invalidate all message objects */
> > -	for (i = C_CAN_MSG_OBJ_RX_FIRST; i <= C_CAN_NO_OF_OBJECTS; i++)
> > +	for (i = priv->msg_obj_rx_first; i <= priv->msg_obj_num; i++)
> >  		c_can_inval_msg_object(dev, IF_RX, i);
> >  
> >  	/* setup receive message objects */
> > -	for (i = C_CAN_MSG_OBJ_RX_FIRST; i < C_CAN_MSG_OBJ_RX_LAST; i++)
> > +	for (i = priv->msg_obj_rx_first; i < priv->msg_obj_rx_last; i++)
> >  		c_can_setup_receive_object(dev, IF_RX, i, 0, 0, IF_MCONT_RCV);
> >  
> > -	c_can_setup_receive_object(dev, IF_RX, C_CAN_MSG_OBJ_RX_LAST, 0, 0,
> > +	c_can_setup_receive_object(dev, IF_RX, priv->msg_obj_rx_last, 0, 0,
> >  				   IF_MCONT_RCV_EOB);
> >  }
> >  
> > @@ -730,7 +728,7 @@ static void c_can_do_tx(struct net_device *dev)
> >  	while ((idx = ffs(pend))) {
> >  		idx--;
> >  		pend &= ~(1 << idx);
> > -		obj = idx + C_CAN_MSG_OBJ_TX_FIRST;
> > +		obj = idx + priv->msg_obj_tx_first;
> >  		c_can_inval_tx_object(dev, IF_TX, obj);
> >  		can_get_echo_skb(dev, idx, NULL);
> >  		bytes += priv->dlc[idx];
> > @@ -740,7 +738,7 @@ static void c_can_do_tx(struct net_device *dev)
> >  	/* Clear the bits in the tx_active mask */
> >  	atomic_sub(clr, &priv->tx_active);
> >  
> > -	if (clr & (1 << (C_CAN_MSG_OBJ_TX_NUM - 1)))
> > +	if (clr & (1 << (priv->msg_obj_tx_num - 1)))
> >  		netif_wake_queue(dev);
> >  
> >  	if (pkts) {
> > @@ -755,11 +753,11 @@ static void c_can_do_tx(struct net_device *dev)
> >   * raced with the hardware or failed to readout all upper
> >   * objects in the last run due to quota limit.
> >   */
> > -static u32 c_can_adjust_pending(u32 pend)
> > +static u32 c_can_adjust_pending(u32 pend, u32 rx_mask)
> >  {
> >  	u32 weight, lasts;
> >  
> > -	if (pend == RECEIVE_OBJECT_BITS)
> > +	if (pend == rx_mask)
> >  		return pend;
> >  
> >  	/*
> > @@ -862,8 +860,7 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)
> >  	 * It is faster to read only one 16bit register. This is only possible
> >  	 * for a maximum number of 16 objects.
> >  	 */
> > -	BUILD_BUG_ON_MSG(C_CAN_MSG_OBJ_RX_LAST > 16,
> > -			"Implementation does not support more message objects than 16");
> > +	WARN_ON(priv->msg_obj_rx_last > 16);
> >  
> >  	while (quota > 0) {
> >  		if (!pend) {
> > @@ -874,7 +871,8 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)
> >  			 * If the pending field has a gap, handle the
> >  			 * bits above the gap first.
> >  			 */
> > -			toread = c_can_adjust_pending(pend);
> > +			toread = c_can_adjust_pending(pend,
> > +						      priv->msg_obj_rx_mask);
> >  		} else {
> >  			toread = pend;
> >  		}
> > @@ -1205,17 +1203,31 @@ static int c_can_close(struct net_device *dev)
> >  	return 0;
> >  }
> >  
> > -struct net_device *alloc_c_can_dev(void)
> > +struct net_device *alloc_c_can_dev(int msg_obj_num)
> >  {
> >  	struct net_device *dev;
> >  	struct c_can_priv *priv;
> > +	int msg_obj_tx_num = msg_obj_num / 2;
> 
> IMO, a bigger tx queue is not usefull.
> A bigger rx queue however is.

This would not be good for my application. 
I think it really depends on the type of application. 
We can probably say that being able to size rx/tx queue
would be a useful feature.

Thanks and regards,
Dario

> 
> My series last year took a fixed lenght of 8 for tx,
> and use the remaining as rx queue.
> 
> >  
> > -	dev = alloc_candev(sizeof(struct c_can_priv), C_CAN_MSG_OBJ_TX_NUM);
> > +	dev = alloc_candev(sizeof(*priv) + sizeof(u32) * msg_obj_tx_num,
> > +			   msg_obj_tx_num);
> >  	if (!dev)
> >  		return NULL;
> >  
> >  	priv = netdev_priv(dev);
> > -	netif_napi_add(dev, &priv->napi, c_can_poll, C_CAN_NAPI_WEIGHT);
> > +	priv->msg_obj_num = msg_obj_num;
> > +	priv->msg_obj_rx_num = msg_obj_num - msg_obj_tx_num;
> > +	priv->msg_obj_rx_first = 1;
> > +	priv->msg_obj_rx_last =
> > +		priv->msg_obj_rx_first + priv->msg_obj_rx_num - 1;
> > +	priv->msg_obj_rx_mask = (1UL << priv->msg_obj_rx_num) - 1;
> > +
> > +	priv->msg_obj_tx_num = msg_obj_tx_num;
> > +	priv->msg_obj_tx_first = priv->msg_obj_rx_last + 1;
> > +	priv->msg_obj_tx_last =
> > +		priv->msg_obj_tx_first + priv->msg_obj_tx_num - 1;
> > +
> > +	netif_napi_add(dev, &priv->napi, c_can_poll, priv->msg_obj_rx_num);
> >  
> >  	priv->dev = dev;
> >  	priv->can.bittiming_const = &c_can_bittiming_const;
> > diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
> > index 90d3d2e7a086..68295fab83d9 100644
> > --- a/drivers/net/can/c_can/c_can.h
> > +++ b/drivers/net/can/c_can/c_can.h
> > @@ -22,18 +22,7 @@
> >  #ifndef C_CAN_H
> >  #define C_CAN_H
> >  
> > -/* message object split */
> >  #define C_CAN_NO_OF_OBJECTS	32
> > -#define C_CAN_MSG_OBJ_RX_NUM	16
> > -#define C_CAN_MSG_OBJ_TX_NUM	16
> > -
> > -#define C_CAN_MSG_OBJ_RX_FIRST	1
> > -#define C_CAN_MSG_OBJ_RX_LAST	(C_CAN_MSG_OBJ_RX_FIRST + \
> > -				C_CAN_MSG_OBJ_RX_NUM - 1)
> > -
> > -#define C_CAN_MSG_OBJ_TX_FIRST	(C_CAN_MSG_OBJ_RX_LAST + 1)
> > -
> > -#define RECEIVE_OBJECT_BITS	0x0000ffff
> >  
> >  enum reg {
> >  	C_CAN_CTRL_REG = 0,
> > @@ -193,6 +182,14 @@ struct c_can_priv {
> >  	struct napi_struct napi;
> >  	struct net_device *dev;
> >  	struct device *device;
> > +	unsigned int msg_obj_num;
> > +	unsigned int msg_obj_rx_num;
> > +	unsigned int msg_obj_tx_num;
> > +	unsigned int msg_obj_rx_first;
> > +	unsigned int msg_obj_rx_last;
> > +	unsigned int msg_obj_tx_first;
> > +	unsigned int msg_obj_tx_last;
> > +	u32 msg_obj_rx_mask;
> >  	atomic_t tx_active;
> >  	atomic_t sie_pending;
> >  	unsigned long tx_dir;
> > @@ -209,10 +206,10 @@ struct c_can_priv {
> >  	void (*raminit) (const struct c_can_priv *priv, bool enable);
> >  	u32 comm_rcv_high;
> >  	u32 rxmasked;
> > -	u32 dlc[C_CAN_MSG_OBJ_TX_NUM];
> > +	u32 dlc[];
> >  };
> >  
> > -struct net_device *alloc_c_can_dev(void);
> > +struct net_device *alloc_c_can_dev(int msg_obj_num);
> >  void free_c_can_dev(struct net_device *dev);
> >  int register_c_can_dev(struct net_device *dev);
> >  void unregister_c_can_dev(struct net_device *dev);
> > diff --git a/drivers/net/can/c_can/c_can_pci.c b/drivers/net/can/c_can/c_can_pci.c
> > index 406b4847e5dc..3752f68d095e 100644
> > --- a/drivers/net/can/c_can/c_can_pci.c
> > +++ b/drivers/net/can/c_can/c_can_pci.c
> > @@ -149,7 +149,7 @@ static int c_can_pci_probe(struct pci_dev *pdev,
> >  	}
> >  
> >  	/* allocate the c_can device */
> > -	dev = alloc_c_can_dev();
> > +	dev = alloc_c_can_dev(C_CAN_NO_OF_OBJECTS);
> >  	if (!dev) {
> >  		ret = -ENOMEM;
> >  		goto out_iounmap;
> > diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
> > index 05f425ceb53a..a5b9b1a93702 100644
> > --- a/drivers/net/can/c_can/c_can_platform.c
> > +++ b/drivers/net/can/c_can/c_can_platform.c
> > @@ -293,7 +293,7 @@ static int c_can_plat_probe(struct platform_device *pdev)
> >  	}
> >  
> >  	/* allocate the c_can device */
> > -	dev = alloc_c_can_dev();
> > +	dev = alloc_c_can_dev(C_CAN_NO_OF_OBJECTS);
> >  	if (!dev) {
> >  		ret = -ENOMEM;
> >  		goto exit;
> > -- 
> > 2.17.1
> >

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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-03-03  8:23     ` Dario Binacchi
@ 2021-03-03  9:00       ` Marc Kleine-Budde
  2021-03-03 10:31         ` Dario Binacchi
  0 siblings, 1 reply; 23+ messages in thread
From: Marc Kleine-Budde @ 2021-03-03  9:00 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: Kurt Van Dijck, linux-kernel, Federico Vaga, Alexander Stein,
	David S. Miller, Jakub Kicinski, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev

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

On 03.03.2021 09:23:13, Dario Binacchi wrote:
[...]
> > > @@ -1205,17 +1203,31 @@ static int c_can_close(struct net_device *dev)
> > >  	return 0;
> > >  }
> > >  
> > > -struct net_device *alloc_c_can_dev(void)
> > > +struct net_device *alloc_c_can_dev(int msg_obj_num)
> > >  {
> > >  	struct net_device *dev;
> > >  	struct c_can_priv *priv;
> > > +	int msg_obj_tx_num = msg_obj_num / 2;
> > 
> > IMO, a bigger tx queue is not usefull.
> > A bigger rx queue however is.
> 
> This would not be good for my application. I think it really depends
> on the type of application. We can probably say that being able to
> size rx/tx queue would be a useful feature.

Ok. There is an ethtool interface to configure the size of the RX and TX
queues. In ethtool it's called the RX/TX "ring" size and you can get it
via the -g parameter, e.g. here for by Ethernet interface:

| $ ethtool -g enp0s25
| Ring parameters for enp0s25:
| Pre-set maximums:
| RX:		4096
| RX Mini:	n/a
| RX Jumbo:	n/a
| TX:		4096
| Current hardware settings:
| RX:		256
| RX Mini:	n/a
| RX Jumbo:	n/a
| TX:		256

If I understand correctly patch 6 has some assumptions that RX and TX
are max 32. To support up to 64 RX objects, you have to convert:
- u32 -> u64
- BIT() -> BIT_ULL()
- GENMASK() -> GENMASK_ULL()

The register access has to be converted, too. For performance reasons
you want to do as least as possible. Which is probably the most
complicated.

In the flexcan driver I have a similar problem. The driver keeps masks,
which mailboxes are RX and which TX and I added wrapper functions to
minimize IO access:

https://elixir.bootlin.com/linux/v5.11/source/drivers/net/can/flexcan.c#L904

This should to IMHO into patch 6.

Adding the ethtool support and making the rings configurable would be a
separate patch.

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-03-03  9:00       ` Marc Kleine-Budde
@ 2021-03-03 10:31         ` Dario Binacchi
  2021-03-03 10:36           ` Marc Kleine-Budde
  0 siblings, 1 reply; 23+ messages in thread
From: Dario Binacchi @ 2021-03-03 10:31 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Kurt Van Dijck, linux-kernel, Federico Vaga, Alexander Stein,
	David S. Miller, Jakub Kicinski, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev

Hi Marc,

> Il 03/03/2021 10:00 Marc Kleine-Budde <mkl@pengutronix.de> ha scritto:
> 
>  
> On 03.03.2021 09:23:13, Dario Binacchi wrote:
> [...]
> > > > @@ -1205,17 +1203,31 @@ static int c_can_close(struct net_device *dev)
> > > >  	return 0;
> > > >  }
> > > >  
> > > > -struct net_device *alloc_c_can_dev(void)
> > > > +struct net_device *alloc_c_can_dev(int msg_obj_num)
> > > >  {
> > > >  	struct net_device *dev;
> > > >  	struct c_can_priv *priv;
> > > > +	int msg_obj_tx_num = msg_obj_num / 2;
> > > 
> > > IMO, a bigger tx queue is not usefull.
> > > A bigger rx queue however is.
> > 
> > This would not be good for my application. I think it really depends
> > on the type of application. We can probably say that being able to
> > size rx/tx queue would be a useful feature.
> 
> Ok. There is an ethtool interface to configure the size of the RX and TX
> queues. In ethtool it's called the RX/TX "ring" size and you can get it
> via the -g parameter, e.g. here for by Ethernet interface:
> 
> | $ ethtool -g enp0s25
> | Ring parameters for enp0s25:
> | Pre-set maximums:
> | RX:		4096
> | RX Mini:	n/a
> | RX Jumbo:	n/a
> | TX:		4096
> | Current hardware settings:
> | RX:		256
> | RX Mini:	n/a
> | RX Jumbo:	n/a
> | TX:		256
> 
> If I understand correctly patch 6 has some assumptions that RX and TX
> are max 32. To support up to 64 RX objects, you have to convert:
> - u32 -> u64
> - BIT() -> BIT_ULL()
> - GENMASK() -> GENMASK_ULL()
> 
> The register access has to be converted, too. For performance reasons
> you want to do as least as possible. Which is probably the most
> complicated.
> 
> In the flexcan driver I have a similar problem. The driver keeps masks,
> which mailboxes are RX and which TX and I added wrapper functions to
> minimize IO access:
> 
> https://elixir.bootlin.com/linux/v5.11/source/drivers/net/can/flexcan.c#L904
> 
> This should to IMHO into patch 6.
> 
> Adding the ethtool support and making the rings configurable would be a
> separate patch.
> 

I think these features need to be developed in a later series. 
I would stay with the extension to 64 messages equally divided 
between reception and transmission.

Thanks and regards,
Dario

> regards,
> Marc
> 
> -- 
> Pengutronix e.K.                 | Marc Kleine-Budde           |
> Embedded Linux                   | https://www.pengutronix.de  |
> Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
> Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH v3 5/6] can: c_can: prepare to up the message objects number
  2021-03-03 10:31         ` Dario Binacchi
@ 2021-03-03 10:36           ` Marc Kleine-Budde
  0 siblings, 0 replies; 23+ messages in thread
From: Marc Kleine-Budde @ 2021-03-03 10:36 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: Kurt Van Dijck, linux-kernel, Federico Vaga, Alexander Stein,
	David S. Miller, Jakub Kicinski, Oliver Hartkopp,
	Vincent Mailhol, Wolfgang Grandegger, YueHaibing, Zhang Qilong,
	linux-can, netdev

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

On 03.03.2021 11:31:10, Dario Binacchi wrote:
> I think these features need to be developed in a later series. 
> I would stay with the extension to 64 messages equally divided 
> between reception and transmission.

Fine with me.

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2021-03-04  0:27 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-28 10:38 [PATCH v3 0/6] can: c_can: add support to 64 message objects Dario Binacchi
2021-02-28 10:38 ` [PATCH v3 1/6] can: c_can: remove unused code Dario Binacchi
2021-02-28 10:38 ` [PATCH v3 2/6] can: c_can: fix indentation Dario Binacchi
2021-02-28 10:38 ` [PATCH v3 3/6] can: c_can: fix control interface used by c_can_do_tx Dario Binacchi
2021-03-02 18:44   ` Kurt Van Dijck
2021-03-03  7:22     ` Dario Binacchi
2021-02-28 10:38 ` [PATCH v3 4/6] can: c_can: use 32-bit write to set arbitration register Dario Binacchi
2021-02-28 10:38 ` [PATCH v3 5/6] can: c_can: prepare to up the message objects number Dario Binacchi
2021-03-01 11:38   ` Marc Kleine-Budde
2021-03-01 13:08     ` Marc Kleine-Budde
2021-03-01 16:54       ` Marc Kleine-Budde
2021-03-01 17:24       ` Dario Binacchi
2021-03-01 19:46         ` Marc Kleine-Budde
2021-03-01 17:21     ` Dario Binacchi
2021-03-01 19:45       ` Marc Kleine-Budde
2021-03-02 10:50         ` Dario Binacchi
2021-03-02 10:56           ` Marc Kleine-Budde
2021-03-02 18:49   ` Kurt Van Dijck
2021-03-03  8:23     ` Dario Binacchi
2021-03-03  9:00       ` Marc Kleine-Budde
2021-03-03 10:31         ` Dario Binacchi
2021-03-03 10:36           ` Marc Kleine-Budde
2021-02-28 10:38 ` [PATCH v3 6/6] can: c_can: add support to 64 message objects Dario Binacchi

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.