Skip to content

Commit 277bd32

Browse files
hartkoppmarckleinebudde
authored andcommitted
can: add documentation for CAN filter usage optimisation
To benefit from special filters for single SFF or single EFF CAN identifier subscriptions the CAN_EFF_FLAG bit and the CAN_RTR_FLAG bit has to be set together with the CAN_(SFF|EFF)_MASK in can_filter.mask. Signed-off-by: Oliver Hartkopp <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 45c7002 commit 277bd32

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Documentation/networking/can.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,41 @@ solution for a couple of reasons:
469469
having this 'send only' use-case we may remove the receive list in the
470470
Kernel to save a little (really a very little!) CPU usage.
471471

472+
4.1.1.1 CAN filter usage optimisation
473+
474+
The CAN filters are processed in per-device filter lists at CAN frame
475+
reception time. To reduce the number of checks that need to be performed
476+
while walking through the filter lists the CAN core provides an optimized
477+
filter handling when the filter subscription focusses on a single CAN ID.
478+
479+
For the possible 2048 SFF CAN identifiers the identifier is used as an index
480+
to access the corresponding subscription list without any further checks.
481+
For the 2^29 possible EFF CAN identifiers a 10 bit XOR folding is used as
482+
hash function to retrieve the EFF table index.
483+
484+
To benefit from the optimized filters for single CAN identifiers the
485+
CAN_SFF_MASK or CAN_EFF_MASK have to be set into can_filter.mask together
486+
with set CAN_EFF_FLAG and CAN_RTR_FLAG bits. A set CAN_EFF_FLAG bit in the
487+
can_filter.mask makes clear that it matters whether a SFF or EFF CAN ID is
488+
subscribed. E.g. in the example from above
489+
490+
rfilter[0].can_id = 0x123;
491+
rfilter[0].can_mask = CAN_SFF_MASK;
492+
493+
both SFF frames with CAN ID 0x123 and EFF frames with 0xXXXXX123 can pass.
494+
495+
To filter for only 0x123 (SFF) and 0x12345678 (EFF) CAN identifiers the
496+
filter has to be defined in this way to benefit from the optimized filters:
497+
498+
struct can_filter rfilter[2];
499+
500+
rfilter[0].can_id = 0x123;
501+
rfilter[0].can_mask = (CAN_EFF_FLAG | CAN_RTR_FLAG | CAN_SFF_MASK);
502+
rfilter[1].can_id = 0x12345678 | CAN_EFF_FLAG;
503+
rfilter[1].can_mask = (CAN_EFF_FLAG | CAN_RTR_FLAG | CAN_EFF_MASK);
504+
505+
setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));
506+
472507
4.1.2 RAW socket option CAN_RAW_ERR_FILTER
473508

474509
As described in chapter 3.4 the CAN interface driver can generate so

0 commit comments

Comments
 (0)