linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] can: m_can: enable transmission of FD frame on latest version
@ 2017-03-06  2:21 Wenyou Yang
  2017-03-06 10:53 ` Marc Kleine-Budde
  0 siblings, 1 reply; 6+ messages in thread
From: Wenyou Yang @ 2017-03-06  2:21 UTC (permalink / raw)
  To: Wolfgang Grandegger, Marc Kleine-Budde, Oliver Hartkopp
  Cc: Alexandre Belloni, Florian Fainelli, Quentin Schulz, Wenyou Yang,
	Nicolas Ferre, linux-can, netdev, linux-kernel, Wenyou Yang

Enables the transmission of CAN FD frames on M_CAN IP core >= v3.1.x
and with the bit rate switching.

Tested on M_CAN IP 3.1.0 (CREL = 0x31040730) of SAMA5D2 SoC.

Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
---
The testing is based on
[RESEND PATCH 1/1] can: m_can: fix bitrate setup on latest silicon
http://lkml.iu.edu/hypermail/linux/kernel/1702.1/05347.html

Changes in v2:
 - Rename TX_BUF_EDL with TX_BUF_FDF.
 - Improve the commit log to avoid misleading.

 drivers/net/can/m_can/m_can.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 246584ed89b6..c2dd2550de40 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -283,8 +283,12 @@ enum m_can_mram_cfg {
 
 /* Tx Buffer Element */
 /* R0 */
+#define TX_BUF_ESI		BIT(31)
 #define TX_BUF_XTD		BIT(30)
 #define TX_BUF_RTR		BIT(29)
+#define TX_BUF_EFC		BIT(23)
+#define TX_BUF_FDF		BIT(21)
+#define TX_BUF_BRS		BIT(20)
 
 /* address offset and element number for each FIFO/Buffer in the Message RAM */
 struct mram_cfg {
@@ -916,7 +920,7 @@ static void m_can_chip_config(struct net_device *dev)
 	}
 
 	if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
-		cccr |= CCCR_CME_CANFD_BRS << CCCR_CME_SHIFT;
+		cccr |= (CCCR_CME_CANFD_BRS | CCCR_CME_CANFD) << CCCR_CME_SHIFT;
 
 	m_can_write(priv, M_CAN_CCCR, cccr);
 	m_can_write(priv, M_CAN_TEST, test);
@@ -1079,6 +1083,7 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,
 	struct canfd_frame *cf = (struct canfd_frame *)skb->data;
 	u32 id, cccr;
 	int i;
+	u32 dlc;
 
 	if (can_dropped_invalid_skb(dev, skb))
 		return NETDEV_TX_OK;
@@ -1097,7 +1102,6 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,
 
 	/* message ram configuration */
 	m_can_fifo_write(priv, 0, M_CAN_FIFO_ID, id);
-	m_can_fifo_write(priv, 0, M_CAN_FIFO_DLC, can_len2dlc(cf->len) << 16);
 
 	for (i = 0; i < cf->len; i += 4)
 		m_can_fifo_write(priv, 0, M_CAN_FIFO_DATA(i / 4),
@@ -1105,20 +1109,29 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,
 
 	can_put_echo_skb(skb, dev, 0);
 
+	dlc = can_len2dlc(cf->len) << 16;
+
 	if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
 		cccr = m_can_read(priv, M_CAN_CCCR);
 		cccr &= ~(CCCR_CMR_MASK << CCCR_CMR_SHIFT);
 		if (can_is_canfd_skb(skb)) {
-			if (cf->flags & CANFD_BRS)
+			dlc |= TX_BUF_FDF;
+			if (cf->flags & CANFD_ESI)
+				dlc |= TX_BUF_ESI;
+			if (cf->flags & CANFD_BRS) {
+				dlc |= TX_BUF_BRS;
 				cccr |= CCCR_CMR_CANFD_BRS << CCCR_CMR_SHIFT;
-			else
+			} else {
 				cccr |= CCCR_CMR_CANFD << CCCR_CMR_SHIFT;
+			}
 		} else {
 			cccr |= CCCR_CMR_CAN << CCCR_CMR_SHIFT;
 		}
 		m_can_write(priv, M_CAN_CCCR, cccr);
 	}
 
+	m_can_fifo_write(priv, 0, M_CAN_FIFO_DLC, dlc);
+
 	/* enable first TX buffer to start transfer  */
 	m_can_write(priv, M_CAN_TXBTIE, 0x1);
 	m_can_write(priv, M_CAN_TXBAR, 0x1);
-- 
2.11.0

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

* Re: [PATCH v2] can: m_can: enable transmission of FD frame on latest version
  2017-03-06  2:21 [PATCH v2] can: m_can: enable transmission of FD frame on latest version Wenyou Yang
@ 2017-03-06 10:53 ` Marc Kleine-Budde
  2017-03-06 19:33   ` Oliver Hartkopp
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2017-03-06 10:53 UTC (permalink / raw)
  To: Wenyou Yang, Wolfgang Grandegger, Oliver Hartkopp
  Cc: Alexandre Belloni, Florian Fainelli, Quentin Schulz, Wenyou Yang,
	Nicolas Ferre, linux-can, netdev, linux-kernel


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

On 03/06/2017 03:21 AM, Wenyou Yang wrote:
> Enables the transmission of CAN FD frames on M_CAN IP core >= v3.1.x
> and with the bit rate switching.
> 
> Tested on M_CAN IP 3.1.0 (CREL = 0x31040730) of SAMA5D2 SoC.

Does this patch work still with the old version of the silicon?

Marc

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


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

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

* Re: [PATCH v2] can: m_can: enable transmission of FD frame on latest version
  2017-03-06 10:53 ` Marc Kleine-Budde
@ 2017-03-06 19:33   ` Oliver Hartkopp
  2017-03-06 21:26     ` Oliver Hartkopp
  0 siblings, 1 reply; 6+ messages in thread
From: Oliver Hartkopp @ 2017-03-06 19:33 UTC (permalink / raw)
  To: Marc Kleine-Budde, Wenyou Yang, Wolfgang Grandegger
  Cc: Alexandre Belloni, Florian Fainelli, Quentin Schulz, Wenyou Yang,
	Nicolas Ferre, linux-can, netdev, linux-kernel

Hi Marc,

On 03/06/2017 11:53 AM, Marc Kleine-Budde wrote:
> On 03/06/2017 03:21 AM, Wenyou Yang wrote:
>> Enables the transmission of CAN FD frames on M_CAN IP core >= v3.1.x
>> and with the bit rate switching.
>>
>> Tested on M_CAN IP 3.1.0 (CREL = 0x31040730) of SAMA5D2 SoC.
>
> Does this patch work still with the old version of the silicon?

The bits that were added in the TX FIFO element are 'reserved' in the 
old silicon - so it should not harm.

This code enables

  if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
-	cccr |= CCCR_CME_CANFD_BRS << CCCR_CME_SHIFT;
+	cccr |= (CCCR_CME_CANFD_BRS | CCCR_CME_CANFD) << CCCR_CME_SHIFT;

the CAN FD support in the new silicon.

This register is set for the old silicon EVERY time a CAN frame is sent.
So this change should not harm the old silicon either.

In fact I was told that the v3.0.x IP core is rather seldom in the wild.
Although I don't have a v3.0.x to test it should work from the 
documentation side of view.

Reviewed-by: Oliver Hartkopp <socketcan@hartkopp.net>

If we would like to make it really better, the code in 
m_can_start_xmit() should only fiddle with the M_CAN_CCCR register when 
working with the v3.0.x silicon.

In fact I would suggest to use the

	if (m_can_read_core_rev(priv) < M_CAN_COREREL_3_1_0)

method from

	http://marc.info/?l=linux-can&m=148716783119090&w=2

to split the code in m_can_start_xmit() accordingly.

@Wenyou Yang: Can you please send a v3 which splits the tx function?

Regards,
Oliver

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

* Re: [PATCH v2] can: m_can: enable transmission of FD frame on latest version
  2017-03-06 19:33   ` Oliver Hartkopp
@ 2017-03-06 21:26     ` Oliver Hartkopp
  2017-03-07  1:03       ` Wenyou.Yang
  0 siblings, 1 reply; 6+ messages in thread
From: Oliver Hartkopp @ 2017-03-06 21:26 UTC (permalink / raw)
  To: Marc Kleine-Budde, Wenyou Yang, Wolfgang Grandegger
  Cc: Alexandre Belloni, Florian Fainelli, Quentin Schulz, Wenyou Yang,
	Nicolas Ferre, linux-can, netdev, linux-kernel

@Wenyou Yang: Can you please test the two patches posted here:

[PATCH 1/2] can: m_can: handle bitrate setup on IP core >= 3.1.x
http://marc.info/?l=linux-can&m=148883529927720&w=2

[PATCH 2/2] can: m_can: handle frame transmission on IP core >= 3.1.x
http://marc.info/?l=linux-can&m=148883529927718&w=2

Tnx & regards,
Oliver

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

* RE: [PATCH v2] can: m_can: enable transmission of FD frame on latest version
  2017-03-06 21:26     ` Oliver Hartkopp
@ 2017-03-07  1:03       ` Wenyou.Yang
  2017-04-07 11:41         ` Quentin Schulz
  0 siblings, 1 reply; 6+ messages in thread
From: Wenyou.Yang @ 2017-03-07  1:03 UTC (permalink / raw)
  To: socketcan, mkl, wg
  Cc: alexandre.belloni, f.fainelli, quentin.schulz, nicolas.ferre,
	linux-can, netdev, linux-kernel

HI Oliver, 

> -----Original Message-----
> From: Oliver Hartkopp [mailto:socketcan@hartkopp.net]
> Sent: 2017年3月7日 5:26
> To: Marc Kleine-Budde <mkl@pengutronix.de>; Wenyou Yang - A41535
> <Wenyou.Yang@microchip.com>; Wolfgang Grandegger <wg@grandegger.com>
> Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>; Florian Fainelli
> <f.fainelli@gmail.com>; Quentin Schulz <quentin.schulz@free-electrons.com>;
> Wenyou Yang - A41535 <Wenyou.Yang@microchip.com>; Nicolas Ferre
> <nicolas.ferre@atmel.com>; linux-can@vger.kernel.org; netdev@vger.kernel.org;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v2] can: m_can: enable transmission of FD frame on latest
> version
> 
> @Wenyou Yang: Can you please test the two patches posted here:

Tested on SAMA5D2 SoC, It works.

> 
> [PATCH 1/2] can: m_can: handle bitrate setup on IP core >= 3.1.x
> http://marc.info/?l=linux-can&m=148883529927720&w=2
> 
> [PATCH 2/2] can: m_can: handle frame transmission on IP core >= 3.1.x
> http://marc.info/?l=linux-can&m=148883529927718&w=2
> 
> Tnx & regards,
> Oliver

Thank you.

Best Regards,
Wenyou Yang

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

* Re: [PATCH v2] can: m_can: enable transmission of FD frame on latest version
  2017-03-07  1:03       ` Wenyou.Yang
@ 2017-04-07 11:41         ` Quentin Schulz
  0 siblings, 0 replies; 6+ messages in thread
From: Quentin Schulz @ 2017-04-07 11:41 UTC (permalink / raw)
  To: Wenyou.Yang, socketcan, mkl, wg
  Cc: alexandre.belloni, f.fainelli, nicolas.ferre, linux-can, netdev,
	linux-kernel

Hi Oliver and Marc,

On 07/03/2017 02:03, Wenyou.Yang@microchip.com wrote:
> HI Oliver, 
> 
>> -----Original Message-----
>> From: Oliver Hartkopp [mailto:socketcan@hartkopp.net]
>> Sent: 2017年3月7日 5:26
>> To: Marc Kleine-Budde <mkl@pengutronix.de>; Wenyou Yang - A41535
>> <Wenyou.Yang@microchip.com>; Wolfgang Grandegger <wg@grandegger.com>
>> Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>; Florian Fainelli
>> <f.fainelli@gmail.com>; Quentin Schulz <quentin.schulz@free-electrons.com>;
>> Wenyou Yang - A41535 <Wenyou.Yang@microchip.com>; Nicolas Ferre
>> <nicolas.ferre@atmel.com>; linux-can@vger.kernel.org; netdev@vger.kernel.org;
>> linux-kernel@vger.kernel.org
>> Subject: Re: [PATCH v2] can: m_can: enable transmission of FD frame on latest
>> version
>>
>> @Wenyou Yang: Can you please test the two patches posted here:
> 
> Tested on SAMA5D2 SoC, It works.
> 
>>
>> [PATCH 1/2] can: m_can: handle bitrate setup on IP core >= 3.1.x
>> http://marc.info/?l=linux-can&m=148883529927720&w=2
>>
>> [PATCH 2/2] can: m_can: handle frame transmission on IP core >= 3.1.x
>> http://marc.info/?l=linux-can&m=148883529927718&w=2
>>

Sorry, never received those mails so didn't know I had to do something.
I forgot to add my Signed-off-by when resending it so of course you can
add it to your next version:

Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>

That gives me the opportunity to relaunch the discussion on it. What's
the status?

Quentin

>> Tnx & regards,
>> Oliver
> 
> Thank you.
> 
> Best Regards,
> Wenyou Yang
> 

-- 
Quentin Schulz, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

end of thread, other threads:[~2017-04-07 11:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-06  2:21 [PATCH v2] can: m_can: enable transmission of FD frame on latest version Wenyou Yang
2017-03-06 10:53 ` Marc Kleine-Budde
2017-03-06 19:33   ` Oliver Hartkopp
2017-03-06 21:26     ` Oliver Hartkopp
2017-03-07  1:03       ` Wenyou.Yang
2017-04-07 11:41         ` Quentin Schulz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).