All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org,
	kernel@pengutronix.de, Dario Binacchi <dariobin@libero.it>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [net-next 39/39] can: c_can: add support to 64 message objects
Date: Tue, 30 Mar 2021 13:45:59 +0200	[thread overview]
Message-ID: <20210330114559.1114855-40-mkl@pengutronix.de> (raw)
In-Reply-To: <20210330114559.1114855-1-mkl@pengutronix.de>

From: Dario Binacchi <dariobin@libero.it>

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.

Link: https://lore.kernel.org/r/20210302215435.18286-7-dariobin@libero.it
Signed-off-by: Dario Binacchi <dariobin@libero.it>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/c_can/c_can.c          | 27 ++++++++++++++------------
 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, 28 insertions(+), 16 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index 032f8200668a..313793f6922d 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -454,7 +454,7 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,
 	can_put_echo_skb(skb, dev, idx, 0);
 
 	/* Update the active bits */
-	atomic_add((1 << idx), &priv->tx_active);
+	atomic_add(BIT(idx), &priv->tx_active);
 	/* Start transmission */
 	c_can_object_put(dev, IF_TX, obj, IF_COMM_TX);
 
@@ -700,12 +700,15 @@ 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;
 
-	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);
+		pend &= ~BIT(idx);
 		obj = idx + priv->msg_obj_tx_first;
 
 		/* We use IF_RX interface instead of IF_TX because we
@@ -721,7 +724,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 << (priv->msg_obj_tx_num - 1)))
+	if (clr & BIT(priv->msg_obj_tx_num - 1))
 		netif_wake_queue(dev);
 
 	if (pkts) {
@@ -755,10 +758,10 @@ static u32 c_can_adjust_pending(u32 pend, u32 rx_mask)
 	/* Find the first set bit after the gap. We walk backwards
 	 * from the last set bit.
 	 */
-	for (lasts--; pend & (1 << (lasts - 1)); lasts--)
+	for (lasts--; pend & BIT(lasts - 1); lasts--)
 		;
 
-	return pend & ~((1 << lasts) - 1);
+	return pend & ~GENMASK(lasts - 1, 0);
 }
 
 static inline void c_can_rx_object_get(struct net_device *dev,
@@ -814,7 +817,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;
 }
@@ -835,11 +843,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 ee703b7ed42d..8acedd9e63a7 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 fa419e795498..bf2f8c3da1c1 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 */
@@ -147,7 +149,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;
@@ -252,6 +254,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,
@@ -259,6 +262,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 7ece36f61c6f..36950363682f 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -193,10 +193,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[] = {
@@ -206,6 +208,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,
@@ -218,6 +221,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,
 };
@@ -294,7 +298,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.30.2



  parent reply	other threads:[~2021-03-30 11:47 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30 11:45 pull-request: can-next 2021-03-30 Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 01/39] MAINTAINERS: remove Dan Murphy from m_can and tcan4x5x Marc Kleine-Budde
2021-03-30 20:10   ` patchwork-bot+netdevbpf
2021-03-30 11:45 ` [net-next 02/39] MAINTAINERS: Update MCAN MMIO device driver maintainer Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 03/39] can: dev: always create TX echo skb Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 04/39] can: dev: can_free_echo_skb(): don't crash the kernel if can_priv::echo_skb is accessed out of bounds Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 05/39] can: dev: can_free_echo_skb(): extend to return can frame length Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 06/39] can: add new CAN FD bittiming parameters: Transmitter Delay Compensation (TDC) Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 07/39] can: dev: reorder struct can_priv members for better packing Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 08/39] can: netlink: move '=' operators back to previous line (checkpatch fix) Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 09/39] can: bittiming: add calculation for CAN FD Transmitter Delay Compensation (TDC) Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 10/39] can: bittiming: add CAN_KBPS, CAN_MBPS and CAN_MHZ macros Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 11/39] can: grcan: add missing Kconfig dependency to HAS_IOMEM Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 12/39] can: xilinx_can: Simplify code by using dev_err_probe() Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 13/39] can: ucan: fix alignment constraints Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 14/39] can: peak_usb: pcan_usb_pro_encode_msg(): use macros for flags instead of plain integers Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 15/39] can: peak_usb: add support of ethtool set_phys_id() Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 16/39] can: peak_usb: add support of ONE_SHOT mode Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 17/39] can: m_can: m_can_class_allocate_dev(): remove impossible error return judgment Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 18/39] can: m_can: add infrastructure for internal timestamps Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 19/39] can: m_can: m_can_chip_config(): enable and configure " Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 20/39] can: m_can: fix periph RX path: use rx-offload to ensure skbs are sent from softirq context Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 21/39] can: tcan4x5x: remove duplicate include of regmap.h Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 22/39] can: mcp251xfd: add dev coredump support Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 23/39] can: mcp251xfd: simplify UINC handling Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 24/39] can: mcp251xfd: move netdevice.h to mcp251xfd.h Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 25/39] can: mcp251xfd: mcp251xfd_get_timestamp(): move " Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 26/39] can: mcp251xfd: add HW timestamp infrastructure Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 27/39] can: mcp251xfd: add HW timestamp to RX, TX and error CAN frames Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 28/39] can: c_can: convert block comments to network style comments Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 29/39] can: c_can: remove unnecessary blank lines and add suggested ones Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 30/39] can: c_can: fix indention Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 31/39] can: c_can: fix print formating string Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 32/39] can: c_can: replace double assignments by two single ones Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 33/39] can: c_can: fix remaining checkpatch warnings Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 34/39] can: c_can: remove unused code Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 35/39] can: c_can: fix indentation Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 36/39] can: c_can: add a comment about IF_RX interface's use Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 37/39] can: c_can: use 32-bit write to set arbitration register Marc Kleine-Budde
2021-03-30 11:45 ` [net-next 38/39] can: c_can: prepare to up the message objects number Marc Kleine-Budde
2021-03-30 11:45 ` Marc Kleine-Budde [this message]
2021-03-30 20:10 ` pull-request: can-next 2021-03-30 patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210330114559.1114855-40-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=dariobin@libero.it \
    --cc=davem@davemloft.net \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.