Skip to content

Commit ec0befb

Browse files
henrikbrixandersencfriedt
authored andcommitted
drivers: can: mcan: acknowledge all received frames
The Bosch M_CAN IP does not support RX filtering of the RTR bit, so the driver handles this bit in software. If a recevied frame matches a filter with RTR enabled, the RTR bit of the frame must match that of the filter in order to be passed to the RX callback function. If the RTR bits do not match the frame must be dropped. Improve the readability of the the logic for determining if a frame should be dropped and add a missing FIFO acknowledge write for dropped frames. Fixes: #47204 Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent 273e90a commit ec0befb

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

drivers/can/can_mcan.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ static void can_mcan_get_message(struct can_mcan_data *data,
512512
int data_length;
513513
void *cb_arg;
514514
struct can_mcan_rx_fifo_hdr hdr;
515+
bool rtr_filter_mask;
516+
bool rtr_filter;
515517

516518
while ((*fifo_status_reg & CAN_MCAN_RXF0S_F0FL)) {
517519
get_idx = (*fifo_status_reg & CAN_MCAN_RXF0S_F0GI) >>
@@ -537,11 +539,17 @@ static void can_mcan_get_message(struct can_mcan_data *data,
537539

538540
filt_idx = hdr.fidx;
539541

540-
/* Check if RTR must match */
541-
if ((hdr.xtd && data->ext_filt_rtr_mask & (1U << filt_idx) &&
542-
((data->ext_filt_rtr >> filt_idx) & 1U) != frame.rtr) ||
543-
(data->std_filt_rtr_mask & (1U << filt_idx) &&
544-
((data->std_filt_rtr >> filt_idx) & 1U) != frame.rtr)) {
542+
if (hdr.xtd != 0) {
543+
rtr_filter_mask = (data->ext_filt_rtr_mask & BIT(filt_idx)) != 0;
544+
rtr_filter = (data->ext_filt_rtr & BIT(filt_idx)) != 0;
545+
} else {
546+
rtr_filter_mask = (data->std_filt_rtr_mask & BIT(filt_idx)) != 0;
547+
rtr_filter = (data->std_filt_rtr & BIT(filt_idx)) != 0;
548+
}
549+
550+
if (rtr_filter_mask && (rtr_filter != frame.rtr)) {
551+
/* RTR bit does not match filter RTR mask and bit, drop frame */
552+
*fifo_ack_reg = get_idx;
545553
continue;
546554
}
547555

0 commit comments

Comments
 (0)