board: phytec: common: Add API v3

This API is based on a block structure with a 8 Byte large
API v3 header and various of different blocks following. It extends
our current API v2, which is always 32 Byte large, and is located
directly after v2.

Add the MAC block as first block type. It contains the physical
Ehternet interface number, a MAC address and a CRC checksum over the
MAC payload.

Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
Tested-by: Wadim Egorov <w.egorov@phytec.de>
diff --git a/board/phytec/common/phytec_som_detection_blocks.h b/board/phytec/common/phytec_som_detection_blocks.h
new file mode 100644
index 0000000..2a5a83c
--- /dev/null
+++ b/board/phytec/common/phytec_som_detection_blocks.h
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2024 PHYTEC Messtechnik GmbH
+ * Author: Daniel Schultz <d.schultz@phytec.de>
+ */
+
+#ifndef _PHYTEC_SOM_DETECTION_BLOCKS_H
+#define _PHYTEC_SOM_DETECTION_BLOCKS_H
+
+#define PHYTEC_API3_DATA_HEADER_LEN	8
+#define PHYTEC_API3_BLOCK_HEADER_LEN	4
+#define PHYTEC_API3_PAYLOAD_START					      \
+	(PHYTEC_API2_DATA_LEN + PHYTEC_API3_DATA_HEADER_LEN)
+
+#define PHYTEC_API3_ELEMENT_HEADER_SIZE					      \
+	(sizeof(struct phytec_api3_element *) +				      \
+		sizeof(enum phytec_api3_block_types))
+
+#define PHYTEC_API3_FOREACH_BLOCK(elem, data)				      \
+	for (elem = phytec_get_block_head(data); elem; elem = elem->next)
+
+struct phytec_api3_header {
+	u16 data_length;	/* Total length in Bytes of all blocks */
+	u8 block_count;		/* Number of blocks */
+	u8 sub_version;		/* Block specification version */
+	u8 reserved[3];		/* Reserved */
+	u8 crc8;		/* checksum */
+} __packed;
+
+struct phytec_api3_block_header {
+	u8 block_type;		/* Block payload identifier */
+	u16 next_block;		/* Address of the next block */
+	u8 crc8;		/* checksum */
+} __packed;
+
+enum phytec_api3_block_types {
+	PHYTEC_API3_BLOCK_MAC = 0,
+};
+
+struct phytec_api3_block_mac {
+	u8 interface;		/* Ethernet interface number */
+	u8 address[6];		/* MAC-Address */
+	u8 crc8;		/* checksum */
+} __packed;
+
+struct phytec_api3_element {
+	struct phytec_api3_element *next;
+	enum phytec_api3_block_types block_type;
+	union {
+		struct phytec_api3_block_mac mac;
+	} block;
+} __packed;
+
+struct phytec_api3_element *
+	phytec_blocks_init_mac(struct phytec_api3_block_header *header,
+			       uint8_t *payload);
+
+int __maybe_unused
+phytec_blocks_add_mac_to_env(struct phytec_api3_element *element);
+
+#endif /* _PHYTEC_SOM_DETECTION_BLOCKS_H */