I'm hacking a vendor network driver to include in the mainline kernel.
The vendor (Attansic) has given permission for this, and I don't work
for them; I just own a motherboard containing their network device.
Recently I received this comment in connection with the csum_param
struct below.
"Bitfields should not be used for hardware datastructures ever.
Please convert this to explicit masking and shifting."
struct csum_param {
unsigned buf_len:14;
unsigned dma_int:1;
unsigned pkt_int:1;
u16 valan_tag;
unsigned eop:1;
/* command */
unsigned coalese:1;
unsigned ins_vlag:1;
unsigned custom_chksum:1;
unsigned segment:1;
unsigned ip_chksum:1;
unsigned tcp_chksum:1;
unsigned udp_chksum:1;
/* packet state */
unsigned vlan_tagged:1;
unsigned eth_type:1;
unsigned iphl:4;
unsigned:2;
unsigned payload_offset:8;
unsigned xsum_offset:8;
} _ATL1_ATTRIB_PACK_;
The preceding struct is a 64-bit structure when all is said and done.
Am I on the right track with the following defines? When using
shift/mask semantics, I'll have to replace the struct with two u32
variables, right? Or can I use a single u64?
#define CSUM_PARAM_BUFLEN_MASK 0x3FFF
#define CSUM_PARAM_BUFLEN_SHIFT 0
#define CSUM_PARAM_DMAINT_MASK 0x1
#define CSUM_PARAM_DMAINT_SHIFT 14
#define CSUM_PARAM_PKTINT_MASK 0x1
#define CSUM_PARAM_PKTINT_SHIFT 15
#define CSUM_PARAM_VLANTAG_MASK 0xFFFF
#define CSUM_PARAM_VLAN_SHIFT 16
#define CSUM_PARAM_EOP_MASK 0x1
#define CSUM_PARAM_EOP_SHIFT 0
#define CSUM_PARAM_COALESCE_MASK 0x1
#define CSUM_PARAM_COALESCE_SHIFT 1
#define CSUM_PARAM_INSVLAG_MASK 0x1
#define CSUM_PARAM_INSVLAG_SHIFT 2
#define CSUM_PARAM_CUSTOMCKSUM_MASK 0x1
#define CSUM_PARAM_CUSTOMCKSUM_SHIFT 3
#define CSUM_PARAM_SEGMENT_MASK 0x1
#define CSUM_PARAM_SEGMENT_SHIFT 4
#define CSUM_PARAM_IPCKSUM_MASK 0x1
#define CSUM_PARAM_IPCKSUM_SHIFT 5
#define CSUM_PARAM_TCPCKSUM_MASK 0x1
#define CSUM_PARAM_TCPCKSUM_SHIFT 6
#define CSUM_PARAM_UDPCKSUM_MASK 0x1
#define CSUM_PARAM_UDPCKSUM_SHIFT 7
#define CSUM_PARAM_VLANTAGGED_MASK 0x1
#define CSUM_PARAM_VLANTAGGED_SHIFT 8
#define CSUM_PARAM_ETHTYPE_MASK 0x1
#define CSUM_PARAM_ETHTYPE_SHIFT 9
#define CSUM_PARAM_IPHL_MASK 0xF
#define CSUM_PARAM_IPHL_SHIFT 10
#define CSUM_PARAM_PLOADOFFSET_MASK 0xFF
#define CSUM_PARAM_PLOADOFFSET_SHIFT 14
#define CSUM_PARAM_XSUMOFFSET_MASK 0xFF
#define CSUM_PARAM_XSUMOFFSET_SHIFT 22
Thanks,
Jay
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/