xref: /linux/drivers/net/ethernet/freescale/enetc/enetc_mailbox.h (revision b2128290c29902315e632ea59e0504d6bc9e9b42)
1 /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
2 /*
3  * Copyright 2025-2026 NXP
4  *
5  * The VSI-to-PSI message generic format:
6  *
7  * OFFSET  0                               16              24            31
8  *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
9  *  0x0   |       CRC16 (big-endian)      |    CLASS ID   |     CMD ID    |
10  *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
11  *  0x4   |   PROTO VER   |      LEN      |    RESV       | COOKIE|  RESV |
12  *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
13  *  0x8   |                              RESV                             |
14  *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
15  *  0xc   |                              RESV                             |
16  *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
17  *  0x10  |                                                               |
18  *  0x14  |                                                               |
19  *  0x18  |                          Message Body                         |
20  *  0x1c  |                                                               |
21  *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
22  *  0x20  |                                                               |
23  *    ~   |              Extended Message Body: LEN x 32B                 |
24  *  0x3e0 |                                                               |
25  *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
26  *
27  * Field Descriptions:
28  * CRC16 (16-bit): Big endian, CRC16 CCITT-FALSE algorithm, It provides the
29  * equivalent data integrity check functionality as the FCS for standard
30  * Ethernet frames.
31  *
32  * CLASS ID (8-bit) and CMD ID (8-bit): These are 8-bit fields identifying
33  * the command class and the class-specific operations supported. For more
34  * details, please refer to the definitions of the relevant class ID and
35  * cmd ID in this document.
36  *
37  * PROTO VER (8-bit): Supported VSI-PSI command protocol version. Currently
38  * only support version 0. To be incremented for future protocol extensions.
39  *
40  * LEN (8-bit): Extended message body length in increments of 32B. The upper
41  * limit is given by the physical implementation of the NETC VSI-PSI Messaging
42  * mechanism that supports message sizes of up to 1024B (including headers),
43  * that are multiple of 32B.
44  *
45  * COOKIE (4-bit): Optional parameter, which, if not 0, indicates that the
46  * command should be execute asynchronously on PSI side. If COOKIE is not 0
47  * and the command cannot be executed instantly on the PSI side (it would
48  * take longer time to complete), the PSI may enqueue the request in a command
49  * queue of up to 15 entries per VSI and, later after command execution, the
50  * PSI returns the COOKIE to VSI as part of an asynchronous notification
51  * message that indicates the command completion status. If COOKIE is 0 then
52  * the command is considered as blocking, the PSI will wait for the execution
53  * of the command to complete before updating the PSIMSGRR[MC] field with the
54  * corresponding return code.
55  *
56  * The PSI-to-VSI message generic format:
57  *   0               4               8               12          15
58  * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
59  * |       COOKIE      |   CLASS CODE  |          CLASS ID         |
60  * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
61  *
62  * The PSI to VSI message format is mapped to the following PSI message
63  * registers/fields, depending on use case:
64  * 1) PSI_RX_control: PSIMSGRR[MC] - for VSI command return code messages
65  * (blocking requests), and
66  * 2) PSI_TX_control: PSIMSGSR[MC] - for PSI to VSI notification messages
67  * (async mode)
68  *
69  * Note that for some GET messages, there is no COOKIE field, and the CLASS
70  * CODE field is expanded to 8 bits.
71  */
72 
73 #ifndef __ENETC_MAILBOX_H
74 #define __ENETC_MAILBOX_H
75 
76 #include <linux/crc-itu-t.h>
77 
78 #define ENETC_CRC_INIT				0xffff
79 #define ENETC_MSG_ALIGN				32
80 /* s indicates the size of the message */
81 #define ENETC_MSG_EXT_BODY_LEN(s)		((s) / ENETC_MSG_ALIGN - 1)
82 /* l indicates the extended body len (LEN field) of the message */
83 #define ENETC_MSG_SIZE(l)			(((l) + 1) * ENETC_MSG_ALIGN)
84 
85 /* The cookie filed of VSI-to-PSI message */
86 #define ENETC_VF_MSG_COOKIE			GENMASK(3, 0)
87 /* The fileds of PSI-to-VSI message, the message is only 16-bit */
88 #define ENETC_PF_MSG_COOKIE			GENMASK(3, 0)
89 #define ENETC_PF_MSG_CLASS_CODE			GENMASK(7, 4)
90 /* Extend the class code to 8-bit for GET messages without COOKIE */
91 #define ENETC_PF_MSG_CLASS_CODE_U8		GENMASK(7, 0)
92 #define ENETC_PF_MSG_CLASS_ID			GENMASK(15, 8)
93 
94 enum enetc_msg_class_id {
95 	/* Class ID for PSI-to-VSI messages */
96 	ENETC_MSG_CLASS_ID_CMD_SUCCESS		= 1,
97 	ENETC_MSG_CLASS_ID_PERMISSION_DENY,
98 	ENETC_MSG_CLASS_ID_CMD_NOT_SUPPORT,
99 	ENETC_MSG_CLASS_ID_PSI_BUSY,
100 	ENETC_MSG_CLASS_ID_CRC_ERROR,
101 	ENETC_MSG_CLASS_ID_PROTO_NOT_SUPPORT,
102 	ENETC_MSG_CLASS_ID_INVALID_MSG_LEN,
103 	ENETC_MSG_CLASS_ID_CMD_TIMEOUT,
104 	ENETC_MSG_CLASS_ID_CMD_NOT_PERMITTED,
105 	ENETC_MSG_CLASS_ID_CMD_FAIL, /* Generic error code for failure */
106 	ENETC_MSG_CLASS_ID_CMD_DEFERRED		= 0xf,
107 
108 	/* Common Class ID for PSI-to-VSI and VSI-to-PSI messages */
109 	ENETC_MSG_CLASS_ID_MAC_FILTER		= 0x20,
110 	ENETC_MSG_CLASS_ID_IP_REVISION		= 0xf0,
111 };
112 
113 enum enetc_msg_mac_filter_cmd_id {
114 	ENETC_MSG_SET_PRIMARY_MAC,
115 };
116 
117 enum enetc_msg_ip_revision_cmd_id {
118 	ENETC_MSG_GET_IP_MN			= 1,
119 };
120 
121 /* Class-specific error return codes of MAC filter */
122 enum enetc_mac_filter_class_code {
123 	ENETC_MF_CLASS_CODE_INVALID_MAC,
124 };
125 
126 struct enetc_msg_swbd {
127 	void *vaddr;
128 	dma_addr_t dma;
129 	int size;
130 };
131 
132 /* The generic VSI-to-PSI message header */
133 struct enetc_msg_header {
134 	__be16 crc16;
135 	u8 class_id;
136 	u8 cmd_id;
137 	u8 proto_ver;
138 	u8 len;
139 	u8 resv0;
140 	u8 cookie;
141 	u8 resv2[8];
142 };
143 
144 struct enetc_mac_addr {
145 	u8 addr[ETH_ALEN]; /* Network byte order */
146 };
147 
148 /* Message format of class_id 0x20 for exact MAC filter.
149  * cmd_id 0x0: set primary MAC
150  * cmd_id 0x1: Add entries to MAC address filter table
151  * cmd_id 0x2: Delete entries from MAC address filter table
152  * Note that cmd_id 0x1 and 0x2 are not supported yet.
153  */
154 struct enetc_msg_mac_exact_filter {
155 	struct enetc_msg_header hdr;
156 	u8 mac_cnt; /* No need to set for cmd_id 0 */
157 	u8 resv[3];
158 	struct enetc_mac_addr mac[];
159 };
160 
161 /* The generic message format applies to the following messages:
162  * Get IP revision message, class_id 0xf0.
163  * cmd_id 1: get IP minor revision
164  */
165 struct enetc_msg_generic {
166 	struct enetc_msg_header hdr;
167 	u8 resv[16];
168 };
169 
170 #endif
171