Fix D_CAN corrupted bytes by using 32 bit register r/w
From: Thor Thayer <[email protected]>
Corrupted bytes in CAN transmission on the Altera CycloneV seem to be an issue because the D_CAN registers are 32 bits [1]. Changing to a 32 bit write fixes the problem and this patch includes one method of fixing the problem by selecting 32 bit writes for D_CAN or 16 bit writes for C_CAN.
Another option would be to remove the D_CAN if test and always use the priv->read_reg32() and priv->write_reg32() for both C_CAN and D_CAN. The C_CAN read_reg32() function performs two 16 bit writes. The code is cleaner without the D_CAN if branch but it adds additional overhead for C_CAN (2nd 16 bit write may not be needed in many cases).
This patch isolates the changes to D_CAN and has been tesed on on the Altera CycloneV devkit using a flood write test.
[1] http://comments.gmane.org/gmane.linux.can/9402
Thor Thayer (1):
can: c_can: Update D_CAN TX and RX functions to 32 bit.
drivers/net/can/c_can/c_can.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-)
Signature · 1 line
1.7.9.5
RFC 1/1 can: c_can: Update D_CAN TX and RX functions to 32 bit.
From: Thor Thayer <[email protected]>
When testing CAN write floods on Altera's CycloneV, the first 2 bytes are sometimes 0x00, 0x00 or corrupted instead of the values sent. Also observed bytes 4 & 5 were corrupted in some cases.
The D_CAN Data registers are 32 bits and changing from 16 bit writes to 32 bit writes fixes the problem.
Testing performed on Altera CycloneV (D_CAN). Requesting tests on other C_CAN & D_CAN platforms.
--- drivers/net/can/c_can/c_can.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-)
drivers/net/can/c_can/c_can.c +31 -7
@@ -332,9 +332,23 @@ static void c_can_setup_tx_object(struct net_device *dev, int iface, priv->write_reg (priv,C_CAN_IFACE (MSGCTRL_REG , iface), ctrl); -for (i =0 ; i < frame->can_dlc; i +=2 ) { - priv->write_reg (priv,C_CAN_IFACE (DATA1_REG , iface) + i /2 , - frame->data[i] | (frame->data[i +1 ] <<8 )); +if (priv->type ==BOSCH_D_CAN ) { +u32 data =0 , dreg =C_CAN_IFACE (DATA1_REG , iface); + +for (i =0 ; i < frame->can_dlc; i +=4 , dreg +=2 ) { + data = (u32 )frame->data[i]; + data |= (u32 )frame->data[i +1 ] <<8 ; + data |= (u32 )frame->data[i +2 ] <<16 ; + data |= (u32 )frame->data[i +3 ] <<24 ; + priv->write_reg32 (priv, dreg, data); + } + }else { +for (i =0 ; i < frame->can_dlc; i +=2 ) { + priv->write_reg (priv, +C_CAN_IFACE (DATA1_REG , iface) + i /2 , + frame->data[i] | + (frame->data[i +1 ] <<8 )); + } } }
@@ -402,10 +416,20 @@ static int c_can_read_msg_object(struct net_device *dev, int iface, u32 ctrl) }else {int i, dreg =C_CAN_IFACE (DATA1_REG , iface); -for (i =0 ; i < frame->can_dlc; i +=2 , dreg ++) { - data = priv->read_reg (priv, dreg); - frame->data[i] = data; - frame->data[i +1 ] = data >>8 ; +if (priv->type ==BOSCH_D_CAN ) { +for (i =0 ; i < frame->can_dlc; i +=4 , dreg +=2 ) { + data = priv->read_reg32 (priv, dreg); + frame->data[i] = data; + frame->data[i +1 ] = data >>8 ; + frame->data[i +2 ] = data >>16 ; + frame->data[i +3 ] = data >>24 ; + } + }else { +for (i =0 ; i < frame->can_dlc; i +=2 , dreg++) { + data = priv->read_reg (priv, dreg); + frame->data[i] = data; + frame->data[i +1 ] = data >>8 ; + } } }
Signature · 1 line
1.7.9.5
Marc Kleine-Budde
maintainerQuoted 8 lines · tthayer at opensource.altera.com
From: Thor Thayer <[email protected]>
Corrupted bytes in CAN transmission on the Altera CycloneV seem to be an issue because the
D_CANregisters are 32 bits [1]. Changing to a 32 bit write fixes the problem and this patch includes one method of fixing the problem by selecting 32 bit writes forD_CANor 16 bit writes forC_CAN.
Quoted 5 lines
Another option would be to remove the
D_CANif test and always use thepriv->read_reg32()andpriv->write_reg32()for bothC_CANandD_CAN. TheC_CANread_reg32()function performs two 16 bit writes. The code is cleaner without theD_CANif branch but it adds additional overhead forC_CAN(2nd 16 bit write may not be needed in many cases).
Better save the overhead, as an additional register access may seems to be quite expensive on some platforms.
Marc
Signature · 12 lines
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 | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 455 bytes Desc: OpenPGP digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160617/550a4c14/attachment.sig>
[RFC] can: c_can: Update D_CAN TX and RX functions to 32 bit.
In reply to tthayer at opensource.altera.comQuoted 7 lines · tthayer at opensource.altera.com
From: Thor Thayer <[email protected]>
When testing CAN write floods on Altera's CycloneV, the first 2 bytes are sometimes
0x00,0x00or corrupted instead of the values sent. Also observed bytes 4 & 5 were corrupted in some cases.
Quoted 8 lines
The
D_CANData registers are 32 bits and changing from 16 bit writes to 32 bit writes fixes the problem.Testing performed on Altera CycloneV (
D_CAN). Requesting tests on otherC_CAN&D_CANplatforms.Reported-by Richard Andrysek <[email protected]>Signed-off-by Thor Thayer <[email protected]>
Applied to can with stable on Cc.
Marc
Signature · 12 lines
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 | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 455 bytes Desc: OpenPGP digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160617/fcc0cd34/attachment.sig>
Richard Andrysek
AppliedAW: [RFC] can: c_can: Update D_CAN TX and RX functions to 32 bit.
Sorry for a delay. I've run my test with 16 messages per channel (can0, can1 concurrently) with a cycle time 2.8ms, 1Mbps. And it works now properly.
Thank you all participated on this issue
Richard
-----Urspr?ngliche Nachricht-----
Von: Marc Kleine-Budde [mailto:mkl at pengutronix.de]
Gesendet: Freitag, 17. Juni 2016 11:04
An: tthayer at opensource.altera.com; socketcan at hartkopp.net; wg at grandegger.com; Richard Andrysek <[email protected]>
Cc: anilkumar at ti.com; linux-can at vger.kernel.org; linux-arm-kernel at lists.infradead.org; tthayer.linux at gmail.com
Betreff: Re: [RFC] can: c_can: Update D_CAN TX and RX functions to 32 bit.
Quoted 6 lines · tthayer at opensource.altera.com
From: Thor Thayer <[email protected]>
When testing CAN write floods on Altera's CycloneV, the first 2 bytes are sometimes
0x00,0x00or corrupted instead of the values sent. Also observed bytes 4 & 5 were corrupted in some cases.
Quoted 8 lines
The
D_CANData registers are 32 bits and changing from 16 bit writes to 32 bit writes fixes the problem.Testing performed on Altera CycloneV (
D_CAN). Requesting tests on otherC_CAN&D_CANplatforms.Reported-by Richard Andrysek <[email protected]>Signed-off-by Thor Thayer <[email protected]>
Applied to can with stable on Cc.
Marc
Signature · 4 lines
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 |