// SPDX-License-Identifier: GPL-2.0 // // mcp251xfd - Microchip MCP251xFD Family CAN controller driver // // Copyright (c) 2019, 2020, 2021, 2023 Pengutronix, // Marc Kleine-Budde <kernel@pengutronix.de> // // Based on: // // CAN bus driver for Microchip 25XXFD CAN Controller with SPI Interface // // Copyright (c) 2019 Martin Sperl <kernel@martin.sperl.org> //
/* Use the MCP2517FD mask on the MCP2518FD, too. We only *compare7bits,thisisenoughtodetectoldTEFobjects.
*/
seq = FIELD_GET(MCP251XFD_OBJ_FLAGS_SEQ_MCP2517FD_MASK,
hw_tef_obj->flags);
tef_tail_masked = priv->tef->tail &
field_mask(MCP251XFD_OBJ_FLAGS_SEQ_MCP2517FD_MASK);
/* According to mcp2518fd erratum DS80000789E 6. the FIFOCI *bitsofaFIFOSTAregister,heretheTXFIFOtailindex *mightbecorruptedandwemightprocesspasttheTEFFIFO's *headintooldCANframes. * *ComparethesequencenumberofthecurrentlyprocessedCAN *framewiththeexpectedsequencenumber.Abortwith *-EBADMSGifanoldCANframeisdetected.
*/ if (seq != tef_tail_masked) {
netdev_dbg(priv->ndev, "%s: chip=0x%02x ring=0x%02x\n", __func__,
seq, tef_tail_masked);
stats->tx_fifo_errors++;
err = regmap_read(priv->map_reg, MCP251XFD_REG_FIFOSTA(priv->tx->fifo_nr),
&fifo_sta); if (err) return err;
/* If the chip says the TX-FIFO is empty, but there are no TX *buffersfreeinthering,weassumeallhavebeensent.
*/ if (mcp251xfd_tx_fifo_sta_empty(fifo_sta) &&
mcp251xfd_get_tx_free(tx_ring) == 0) {
*len_p = tx_ring->obj_num; return0;
}
err = mcp251xfd_check_tef_tail(priv); if (err) return err;
tail = mcp251xfd_get_tef_tail(priv);
/* First shift to full u8. The subtraction works on signed *values,thatkeepsthedifferencesteadyaroundtheu8 *overflow.Therightshiftactsonlen,whichisanu8.
*/
BUILD_BUG_ON(sizeof(tx_ring->obj_num) != sizeof(chip_tx_tail));
BUILD_BUG_ON(sizeof(tx_ring->obj_num) != sizeof(tail));
BUILD_BUG_ON(sizeof(tx_ring->obj_num) != sizeof(len));
len = (chip_tx_tail << shift) - (tail << shift);
len >>= shift;
/* According to mcp2518fd erratum DS80000789E 6. the FIFOCI *bitsofaFIFOSTAregister,heretheTX-FIFOtailindex *mightbecorrupted. * *HoweverhereitseemsthebitindicatingthattheTX-FIFO *isempty(MCP251XFD_REG_FIFOSTA_TFERFFIF)isnotcorrect *whiletheTX-FIFOtailindexis. * *WeassumetheTX-FIFOisempty,i.e.allpendingCANframes *havenbeensend,if: *-Chip'sheadandtailindexareequal(len==0). *-TheTX-FIFOislessthanhalffull. *(TheTX-FIFOemptycasehasalreadybeencheckedatthe *beginningofthisfunction.) *-NofreebuffersintheTXring.
*/ if (len == 0 && mcp251xfd_tx_fifo_sta_less_than_half_full(fifo_sta) &&
mcp251xfd_get_tx_free(tx_ring) == 0)
len = tx_ring->obj_num;
err = mcp251xfd_check_tef_tail(priv); if (err) return err;
}
mcp251xfd_ecc_tefif_successful(priv);
if (mcp251xfd_get_tx_free(priv->tx)) { /* Make sure that anybody stopping the queue after *thisseesthenewtx_ring->tail.
*/
smp_mb();
netif_wake_queue(priv->ndev);
}
if (priv->tx_coalesce_usecs_irq)
hrtimer_start(&priv->tx_irq_timer,
ns_to_ktime(priv->tx_coalesce_usecs_irq *
NSEC_PER_USEC),
HRTIMER_MODE_REL);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.