Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose len8_dlc field of can_frame struct. #3357

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

de-vri-es
Copy link
Contributor

@de-vri-es de-vri-es commented Sep 19, 2023

The can_frame struct on Linux has a len8_dlc field which can be used to stuff a few extra bits in the dlc field of the actual CAN frame on the wire (only allowed when the data length itself is 8, and if the hardware CAN controller allows it).

However, that field is not currently exposed. This PR exposes it as pub len8_dlc: u8 so we can get those extra 2.8 bits from our CAN frames 😅

It would have been nice to name the current can_dlc field as len, instead of the old deprecated name, but I guess that ship has sailed.

Upstream documentation: https://www.kernel.org/doc/html/latest/networking/can.html#how-to-use-socketcan

struct can_frame {
        canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
        union {
                /* CAN frame payload length in byte (0 .. CAN_MAX_DLEN)
                 * was previously named can_dlc so we need to carry that
                 * name for legacy support
                 */
                __u8 len;
                __u8 can_dlc; /* deprecated */
        };
        __u8    __pad;   /* padding */
        __u8    __res0;  /* reserved / padding */
        __u8    len8_dlc; /* optional DLC for 8 byte payload length (9 .. 15) */
        __u8    data[8] __attribute__((aligned(8)));
};

Remark: The len element contains the payload length in bytes and should be used instead of can_dlc. The deprecated can_dlc was misleadingly named as it always contained the plain payload length in bytes and not the so called 'data length code' (DLC).

To pass the raw DLC from/to a Classical CAN network device the len8_dlc element can contain values 9 .. 15 when the len element is 8 (the real payload length for all DLC values greater or equal to 8).

@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2023

r? @JohnTitor

(rustbot has picked a reviewer for you, use r? to override)

@de-vri-es de-vri-es changed the title Expose len8_dlc field of can_frame struct. Expose len8_dlc field of can_frame struct. Sep 19, 2023
@JohnTitor
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Sep 21, 2023

📌 Commit 85dbb12 has been approved by JohnTitor

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Sep 21, 2023

⌛ Testing commit 85dbb12 with merge 5c5c419...

bors added a commit that referenced this pull request Sep 21, 2023
Expose `len8_dlc` field of `can_frame` struct.

The `can_frame` struct on Linux has a `len8_dlc` field which can be used to stuff a few extra bits in the `dlc` field of the actual CAN frame on the wire (only allowed when the data length itself is 8, and if the hardware CAN controller allows it).

However, that field is not currently exposed. This PR exposes it as `pub len8_dlc: u8` so we can get those extra 2.8 bits from our CAN frames 😅

It would have been nice to name the current `can_dlc` field as `len`, instead of the old deprecated name, but I guess that ship has sailed.

Upstream documentation: https://www.kernel.org/doc/html/latest/networking/can.html#how-to-use-socketcan

> ```c
> struct can_frame {
>         canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
>         union {
>                 /* CAN frame payload length in byte (0 .. CAN_MAX_DLEN)
>                  * was previously named can_dlc so we need to carry that
>                  * name for legacy support
>                  */
>                 __u8 len;
>                 __u8 can_dlc; /* deprecated */
>         };
>         __u8    __pad;   /* padding */
>         __u8    __res0;  /* reserved / padding */
>         __u8    len8_dlc; /* optional DLC for 8 byte payload length (9 .. 15) */
>         __u8    data[8] __attribute__((aligned(8)));
> };
> ```
>
> Remark: The len element contains the payload length in bytes and should be used instead of can_dlc. The deprecated can_dlc was misleadingly named as it always contained the plain payload length in bytes and not the so called 'data length code' (DLC).
>
> To pass the raw DLC from/to a Classical CAN network device the len8_dlc element can contain values 9 .. 15 when the len element is 8 (the real payload length for all DLC values greater or equal to 8).
@bors
Copy link
Contributor

bors commented Sep 21, 2023

💔 Test failed - checks-actions

@de-vri-es
Copy link
Contributor Author

I don't see any reason for the failure. Is it correct to assume that this was an unrelated CI failure? :o

@JohnTitor
Copy link
Member

The failure is related. I think mips doesn't have it or our musl header is too old.

@de-vri-es
Copy link
Contributor Author

Oh, sorry, the link just pointed to a job running "exit 1" and I didn't notice the other red check.

@de-vri-es
Copy link
Contributor Author

de-vri-es commented Sep 30, 2023

Note that the can_frame struct comes from a Linux header, not from a glibc or musl header. I'm also pretty sure that mips has it too, but the headers are pulled in from the openwrt sdk which includes headers from linux 4.14, and the len8_dlc field was added in Linux commit ea7800565a128 which was released in 5.11.

What would be a good way forward for me to unblock this? Find a different linux mips distro with a newer kernel?

/edit: This openwrt release would fit the bill: https://downloads.openwrt.org/releases/23.05.0-rc4/targets/bcm47xx/generic/openwrt-sdk-23.05.0-rc4-bcm47xx-generic_gcc-12.3.0_musl.Linux-x86_64.tar.xz

@de-vri-es
Copy link
Contributor Author

Hmm, updating to https://downloads.openwrt.org/releases/23.05.0-rc4/targets/bcm47xx/generic/openwrt-sdk-23.05.0-rc4-bcm47xx-generic_gcc-12.3.0_musl.Linux-x86_64.tar.xz breaks other tests, atleast if I locally run ci/run-docker.sh mipsel-unknown-linux-musl.

I guess I need to figure out why first :(

@bors
Copy link
Contributor

bors commented Nov 11, 2023

☔ The latest upstream changes (presumably #3429) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants