[PATCH v2 5/6] net: can: flexcan: split the Message Buffer RAM area

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The message buffer RAM area is not a contiguous 1KB area but 2 partitions
of 512 bytes each. Till now, we used Message buffers with payload size 8
bytes, which translates to 32 MBs per partition and no spare space is left
in any partition.
However, in upcoming SOC LX2160A the message buffers can have payload size
greater than 8 bytes. This results in less than 32 MBs per partition and
some empty area is left at the end of each partition.This empty area should
not be accessed.
Therefore, split the Message Buffer RAM area into two partitions.

Signed-off-by: Pankaj Bansal <pankaj.bansal@xxxxxxx>
---

Notes:
    V2:
    - removed mb_count_block1 and mb_count_block2 from priv structure due to
      flexcan_get_mb function introduced in earlier patch

 drivers/net/can/flexcan.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 54eb1039ad20..50ecc21e1b5b 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -223,7 +223,8 @@ struct flexcan_regs {
 	u32 rxfgmask;		/* 0x48 */
 	u32 rxfir;		/* 0x4c */
 	u32 _reserved3[12];	/* 0x50 */
-	u32 mb[256];		/* 0x80 */
+	u32 mb1[128];		/* 0x80 */
+	u32 mb2[128];		/* 0x280 */
 	/* FIFO-mode:
 	 *			MB
 	 * 0x080...0x08f	0	RX message buffer
@@ -363,15 +364,20 @@ static struct flexcan_mb *flexcan_get_mb(const struct flexcan_priv *priv,
 					 u8 mb_index)
 {
 	u8 mb_size;
-	u8 mb_count;
+	u8 mb_count_block;
 
 	mb_size = sizeof(struct flexcan_mb) + priv->devtype_data->payload_size;
-	mb_count = (sizeof(priv->regs->mb) / mb_size);
+	mb_count_block = (sizeof(priv->regs->mb1) / mb_size);
 
-	if (mb_index >= mb_count)
+	if (mb_index < mb_count_block)
+		return (struct flexcan_mb __iomem *)((u8 *)&priv->regs->mb1 +
+						     (mb_size * mb_index));
+
+	mb_index -= mb_count_block;
+	if (mb_index >= mb_count_block)
 		return NULL;
 
-	return (struct flexcan_mb __iomem *)((u8 *)&priv->regs->mb +
+	return (struct flexcan_mb __iomem *)((u8 *)&priv->regs->mb2 +
 					     (mb_size * mb_index));
 }
 
@@ -1018,7 +1024,9 @@ static int flexcan_chip_start(struct net_device *dev)
 	}
 
 	/* clear and invalidate all mailboxes first */
-	for (i = priv->tx_mb_idx; i < (sizeof(regs->mb) / mb_size); i++) {
+	for (i = priv->tx_mb_idx;
+	     i < (sizeof(regs->mb1) / mb_size) + (sizeof(regs->mb2) / mb_size);
+	     i++) {
 		mb = flexcan_get_mb(priv, i);
 		priv->write(FLEXCAN_MB_CODE_RX_INACTIVE, &mb->can_ctrl);
 	}
@@ -1420,7 +1428,8 @@ static int flexcan_probe(struct platform_device *pdev)
 		u64 imask;
 
 		priv->offload.mb_first = FLEXCAN_RX_MB_OFF_TIMESTAMP_FIRST;
-		priv->offload.mb_last = (sizeof(regs->mb) / mb_size) - 1;
+		priv->offload.mb_last = (sizeof(regs->mb1) / mb_size) +
+					(sizeof(regs->mb2) / mb_size) - 1;
 
 		imask = GENMASK_ULL(priv->offload.mb_last, priv->offload.mb_first);
 		priv->reg_imask1_default |= imask;
-- 
2.17.1

--
To unsubscribe from this list: send the line "unsubscribe linux-can" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux