1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (C) 2024 PHYTEC Messtechnik GmbH
4  * Author: Daniel Schultz <d.schultz@phytec.de>
5  */
6 
7 #ifndef _PHYTEC_SOM_DETECTION_BLOCKS_H
8 #define _PHYTEC_SOM_DETECTION_BLOCKS_H
9 
10 #define PHYTEC_API3_DATA_HEADER_LEN	8
11 #define PHYTEC_API3_BLOCK_HEADER_LEN	4
12 #define PHYTEC_API3_PAYLOAD_START					      \
13 	(PHYTEC_API2_DATA_LEN + PHYTEC_API3_DATA_HEADER_LEN)
14 
15 #define PHYTEC_API3_ELEMENT_HEADER_SIZE					      \
16 	(sizeof(struct phytec_api3_element *) +				      \
17 		sizeof(enum phytec_api3_block_types))
18 
19 #define PHYTEC_API3_FOREACH_BLOCK(elem, data)				      \
20 	for (elem = phytec_get_block_head(data); elem; elem = elem->next)
21 
22 struct phytec_api3_header {
23 	u16 data_length;	/* Total length in Bytes of all blocks */
24 	u8 block_count;		/* Number of blocks */
25 	u8 sub_version;		/* Block specification version */
26 	u8 reserved[3];		/* Reserved */
27 	u8 crc8;		/* checksum */
28 } __packed;
29 
30 struct phytec_api3_block_header {
31 	u8 block_type;		/* Block payload identifier */
32 	u16 next_block;		/* Address of the next block */
33 	u8 crc8;		/* checksum */
34 } __packed;
35 
36 enum phytec_api3_block_types {
37 	PHYTEC_API3_BLOCK_MAC = 0,
38 };
39 
40 struct phytec_api3_block_mac {
41 	u8 interface;		/* Ethernet interface number */
42 	u8 address[6];		/* MAC-Address */
43 	u8 crc8;		/* checksum */
44 } __packed;
45 
46 struct phytec_api3_element {
47 	struct phytec_api3_element *next;
48 	enum phytec_api3_block_types block_type;
49 	union {
50 		struct phytec_api3_block_mac mac;
51 	} block;
52 } __packed;
53 
54 struct phytec_api3_element *
55 	phytec_blocks_init_mac(struct phytec_api3_block_header *header,
56 			       uint8_t *payload);
57 
58 int __maybe_unused
59 phytec_blocks_add_mac_to_env(struct phytec_api3_element *element);
60 
61 #endif /* _PHYTEC_SOM_DETECTION_BLOCKS_H */
62