can: rockchip_canfd: implement workaround for erratum 6

The rk3568 CAN-FD errata sheet as of Tue 07 Nov 2023 11:25:31 +08:00
says:

| The CAN controller's transmission of extended frames may
| intermittently change into standard frames.
|
| When using the CAN controller to send extended frames, if the
| 'tx_req' is configured as 1 and coincides with the internal
| transmission point, the extended frame will be transmitted onto the
| bus in the format of a standard frame.

To work around Erratum 6, the driver is in self-receiving mode (RXSTX)
and all received CAN frames are passed through rkcanfd_rxstx_filter().

Add a check in rkcanfd_rxstx_filter() whether the received frame
corresponds to the current outgoing frame, but the extended CAN ID has
been mangled to a standard ID. In this case re-send the original CAN
frame.

Tested-by: Alibek Omarov <a1ba.omarov@gmail.com>
Acked-by: Heiko Stuebner <heiko@sntech.de>
Link: https://patch.msgid.link/20240904-rockchip-canfd-v5-12-8ae22bcb27cc@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:
Marc Kleine-Budde 2023-11-24 09:27:00 +01:00
parent b6661d7329
commit 58d3cc65a2
3 changed files with 71 additions and 0 deletions

View File

@ -95,6 +95,7 @@ static int rkcanfd_rxstx_filter(struct rkcanfd_priv *priv,
const struct canfd_frame *cfd_rx, const u32 ts,
bool *tx_done)
{
struct net_device_stats *stats = &priv->ndev->stats;
const struct canfd_frame *cfd_nominal;
const struct sk_buff *skb;
unsigned int tx_tail;
@ -130,6 +131,49 @@ static int rkcanfd_rxstx_filter(struct rkcanfd_priv *priv,
return 0;
}
if (!(priv->devtype_data.quirks & RKCANFD_QUIRK_RK3568_ERRATUM_6))
return 0;
/* Erratum 6: Extended frames may be send as standard frames.
*
* Not affected if:
* - TX'ed a standard frame -or-
* - RX'ed an extended frame
*/
if (!(cfd_nominal->can_id & CAN_EFF_FLAG) ||
(cfd_rx->can_id & CAN_EFF_FLAG))
return 0;
/* Not affected if:
* - standard part and RTR flag of the TX'ed frame
* is not equal the CAN-ID and RTR flag of the RX'ed frame.
*/
if ((cfd_nominal->can_id & (CAN_RTR_FLAG | CAN_SFF_MASK)) !=
(cfd_rx->can_id & (CAN_RTR_FLAG | CAN_SFF_MASK)))
return 0;
/* Not affected if:
* - length is not the same
*/
if (cfd_nominal->len != cfd_rx->len)
return 0;
/* Not affected if:
* - the data of non RTR frames is different
*/
if (!(cfd_nominal->can_id & CAN_RTR_FLAG) &&
memcmp(cfd_nominal->data, cfd_rx->data, cfd_nominal->len))
return 0;
/* Affected by Erratum 6 */
*tx_done = true;
stats->tx_packets++;
stats->tx_errors++;
rkcanfd_xmit_retry(priv);
return 0;
}

View File

@ -14,6 +14,14 @@ static void rkcanfd_start_xmit_write_cmd(const struct rkcanfd_priv *priv,
rkcanfd_write(priv, RKCANFD_REG_CMD, reg_cmd);
}
void rkcanfd_xmit_retry(struct rkcanfd_priv *priv)
{
const unsigned int tx_head = rkcanfd_get_tx_head(priv);
const u32 reg_cmd = RKCANFD_REG_CMD_TX_REQ(tx_head);
rkcanfd_start_xmit_write_cmd(priv, reg_cmd);
}
int rkcanfd_start_xmit(struct sk_buff *skb, struct net_device *ndev)
{
struct rkcanfd_priv *priv = netdev_priv(ndev);

View File

@ -342,6 +342,24 @@
/* Erratum 6: The CAN controller's transmission of extended frames may
* intermittently change into standard frames
*
* Work around this issue by activating self reception (RXSTX). If we
* have pending TX CAN frames, check all RX'ed CAN frames in
* rkcanfd_rxstx_filter().
*
* If it's a frame we've send and it's OK, call the TX complete
* handler: rkcanfd_handle_tx_done_one(). Mask the TX complete IRQ.
*
* If it's a frame we've send, but the CAN-ID is mangled, resend the
* original extended frame.
*
* To reproduce:
* host:
* canfdtest -evx -g can0
* candump any,0:80000000 -cexdtA
* dut:
* canfdtest -evx can0
* ethtool -S can0
*/
#define RKCANFD_QUIRK_RK3568_ERRATUM_6 BIT(5)
@ -499,6 +517,7 @@ int rkcanfd_handle_rx_int(struct rkcanfd_priv *priv);
void rkcanfd_timestamp_init(struct rkcanfd_priv *priv);
void rkcanfd_xmit_retry(struct rkcanfd_priv *priv);
int rkcanfd_start_xmit(struct sk_buff *skb, struct net_device *ndev);
void rkcanfd_handle_tx_done_one(struct rkcanfd_priv *priv, const u32 ts,
unsigned int *frame_len_p);