Re: [RFC PATCH V2 net-next 03/11] net: hibmcge: Add mdio and hardware configuration supported in this module
From: Jijie Shao <shaojijie@huawei.com>
Date: 2024-08-16 06:10:40
Also in:
lkml
From: Jijie Shao <shaojijie@huawei.com>
Date: 2024-08-16 06:10:40
Also in:
lkml
on 2024/8/16 10:25, Andrew Lunn wrote:
quoted
+struct hbg_mdio_command { + union { + struct { + u32 mdio_devad : 5; + u32 mdio_prtad :5; + u32 mdio_op : 2; + u32 mdio_st : 2; + u32 mdio_start : 1; + u32 mdio_clk_sel : 1; + u32 mdio_auto_scan : 1; + u32 mdio_clk_sel_exp : 1; + u32 rev : 14; + }; + u32 bits; + }; +};This is generally not the way to do this. Please look at the macros in include/linux/bitfield.h. FIELD_PREP, GENMASK, BIT, FIELD_GET etc. These are guaranteed to work for both big and little endian, and you avoid issues where the compiler decides to add padding in your bitfields. Andrew
Thanks, I already know about macros like FIELD_PREP or FIELD_GET. and these macros are already used in parts of this patch set. But I think this writing style in here very convenient. Although padding needs to be added during definition, but you can use command.mdio_start or command->mdio_start to access specific bitfields. Although FIELD_PREP/FIELD_GET is convenient, But it also needs to define the mask using BIT or GENMASK, and the mask can only be a static constant, which makes it difficult to use sometimes. Thanks a lot! Jijie Shao