no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
oa_tc6.h
Go to the documentation of this file.
1/*******************************************************************************
2 * @file oa_tc6.h
3 * @brief Header file for the Open Alliance TC6 SPI driver.
4 * @author Ciprian Regus (ciprian.regus@analog.com)
5 ********************************************************************************
6 * Copyright 2025(c) Analog Devices, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 *
18 * 3. Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25 * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *******************************************************************************/
33#ifndef _NO_OS_OA_TC6_H
34#define _NO_OS_OA_TC6_H
35
36#include "no_os_spi.h"
37#include "no_os_util.h"
38#include <stdint.h>
39
40#ifndef CONFIG_OA_TX_FRAME_BUFF_NUM
41#define CONFIG_OA_TX_FRAME_BUFF_NUM 2
42#endif
43
44#ifndef CONFIG_OA_RX_FRAME_BUFF_NUM
45#define CONFIG_OA_RX_FRAME_BUFF_NUM 5
46#endif
47
48#ifndef CONFIG_OA_CHUNK_BUFFER_SIZE
49#define CONFIG_OA_CHUNK_BUFFER_SIZE 1514
50#endif
51
52#define OA_TX_FRAME_BUFF_NUM CONFIG_OA_TX_FRAME_BUFF_NUM
53#define OA_RX_FRAME_BUFF_NUM CONFIG_OA_RX_FRAME_BUFF_NUM
54
55/* Space for one full frame + 24 chunk headers (68 * 24)*/
56#define OA_SPI_BUFF_LEN 1632
57#define OA_CHUNK_SIZE 64
58#define OA_REG_LEN 4
59#define OA_HEADER_LEN 4
60#define OA_FOOTER_LEN 4
61
62#define OA_MMS_REG(m, r) (((m) << 16) | ((r) & NO_OS_GENMASK(15, 0)))
63#define OA_CTRL_ADDR_MMS_MASK NO_OS_GENMASK(27, 8)
64
65#define OA_CTRL_HDRB_MASK NO_OS_BIT(30)
66#define OA_CTRL_WNR_MASK NO_OS_BIT(29)
67#define OA_CTRL_AID_MASK NO_OS_BIT(28)
68#define OA_CTRL_MMS_MASK NO_OS_GENMASK(27, 24)
69#define OA_CTRL_ADDR_MASK NO_OS_GENMASK(23, 8)
70#define OA_CTRL_LEN_MASK NO_OS_GENMASK(7, 1)
71#define OA_CTRL_P_MASK NO_OS_BIT(0)
72
73#define OA_DATA_FOOTER_EXST_MASK NO_OS_BIT(31)
74#define OA_DATA_FOOTER_HDRB_MASK NO_OS_BIT(30)
75#define OA_DATA_FOOTER_SYNC_MASK NO_OS_BIT(29)
76#define OA_DATA_FOOTER_RCA_MASK NO_OS_GENMASK(28, 24)
77#define OA_DATA_FOOTER_VS_MASK NO_OS_GENMASK(23, 22)
78#define OA_DATA_FOOTER_DV_MASK NO_OS_BIT(21)
79#define OA_DATA_FOOTER_SV_MASK NO_OS_BIT(20)
80#define OA_DATA_FOOTER_SWO_MASK NO_OS_GENMASK(19, 16)
81#define OA_DATA_FOOTER_EV_MASK NO_OS_BIT(14)
82#define OA_DATA_FOOTER_EBO_MASK NO_OS_GENMASK(13, 8)
83#define OA_DATA_FOOTER_TXC_MASK NO_OS_GENMASK(5, 1)
84#define OA_DATA_FOOTER_P_MASK NO_OS_BIT(0)
85
86#define OA_DATA_HEADER_DNC_MASK NO_OS_BIT(31)
87#define OA_DATA_HEADER_SEQ_MASK NO_OS_BIT(30)
88#define OA_DATA_HEADER_NORX_MASK NO_OS_BIT(29)
89#define OA_DATA_HEADER_VS_MASK NO_OS_GENMASK(23, 22)
90#define OA_DATA_HEADER_DV_MASK NO_OS_BIT(21)
91#define OA_DATA_HEADER_SV_MASK NO_OS_BIT(20)
92#define OA_DATA_HEADER_SWO_MASK NO_OS_GENMASK(19, 16)
93#define OA_DATA_HEADER_EV_MASK NO_OS_BIT(14)
94#define OA_DATA_HEADER_EBO_MASK NO_OS_GENMASK(13, 8)
95#define OA_DATA_HEADER_P_MASK NO_OS_BIT(0)
96
97/* Standard control and status registers (MMS 0) */
98
99#define OA_TC6_IDVER_REG OA_MMS_REG(0x0, 0x0000)
100#define OA_TC6_PHYID_REG OA_MMS_REG(0x0, 0x0001)
101#define OA_TC6_STDCAP_REG OA_MMS_REG(0x0, 0x0002)
102#define OA_TC6_RESET_REG OA_MMS_REG(0x0, 0x0003)
103#define OA_TC6_CONFIG0_REG OA_MMS_REG(0x0, 0x0004)
104#define OA_TC6_CONFIG1_REG OA_MMS_REG(0x0, 0x0005)
105#define OA_TC6_CONFIG2_REG OA_MMS_REG(0x0, 0x0006)
106#define OA_TC6_STATUS0_REG OA_MMS_REG(0x0, 0x0008)
107#define OA_TC6_STATUS1_REG OA_MMS_REG(0x0, 0x0009)
108#define OA_TC6_BUFST_REG OA_MMS_REG(0x0, 0x000B)
109#define OA_TC6_IMSK0_REG OA_MMS_REG(0x0, 0x000C)
110#define OA_TC6_IMSK1_REG OA_MMS_REG(0x0, 0x000D)
111
112#define OA_TC6_TTSCAH_REG OA_MMS_REG(0x0, 0x0010)
113#define OA_TC6_TTSCAL_REG OA_MMS_REG(0x0, 0x0011)
114#define OA_TC6_TTSCBH_REG OA_MMS_REG(0x0, 0x0012)
115#define OA_TC6_TTSCBL_REG OA_MMS_REG(0x0, 0x0013)
116#define OA_TC6_TTSCCH_REG OA_MMS_REG(0x0, 0x0014)
117#define OA_TC6_TTSCCL_REG OA_MMS_REG(0x0, 0x0015)
118#define OA_TC6_MDIOACC0_REG OA_MMS_REG(0x0, 0x0020)
119#define OA_TC6_MDIOACC1_REG OA_MMS_REG(0x0, 0x0021)
120#define OA_TC6_MDIOACC2_REG OA_MMS_REG(0x0, 0x0022)
121#define OA_TC6_MDIOACC3_REG OA_MMS_REG(0x0, 0x0023)
122#define OA_TC6_MDIOACC4_REG OA_MMS_REG(0x0, 0x0024)
123#define OA_TC6_MDIOACC5_REG OA_MMS_REG(0x0, 0x0025)
124#define OA_TC6_MDIOACC6_REG OA_MMS_REG(0x0, 0x0026)
125#define OA_TC6_MDIOACC7_REG OA_MMS_REG(0x0, 0x0027)
126
127#define OA_TC6_CONFIG0_ZARFE_MASK NO_OS_BIT(12)
128
129#define OA_TC6_BUFSTS_TXC_MASK NO_OS_GENMASK(15, 8)
130#define OA_TC6_BUFSTS_RCA_MASK NO_OS_GENMASK(7, 0)
131
136 /*
137 * Neither the OA nor the user application doesn't currently
138 * use this buffer. OA can start writing it.
139 */
141
142 /*
143 * The buffer is currently written by OA, but it doesn't yet
144 * contain a complete frame. The user application cannot reference
145 * the data yet.
146 */
148
149 /*
150 * The buffer has a complete frame, and is no longer accessed by OA.
151 * The user application could use this.
152 */
154
155 /* The buffer is accessed by the user application. OA will not overwrite it */
157
158 /* The user writes to this buffer. OA doesn't access it. */
160
161 /* The buffer is ready to be transmitted. The user won't access it anymore. */
163};
164
177
195
202
203/* Read a register from the MAC device */
204int oa_tc6_reg_read(struct oa_tc6_desc *, uint32_t, uint32_t *);
205
206/* Write a register of the MAC device */
207int oa_tc6_reg_write(struct oa_tc6_desc *, uint32_t, uint32_t);
208
209/* Update a register field */
210int oa_tc6_reg_update(struct oa_tc6_desc *, uint32_t, uint32_t, uint32_t);
211
212/* Get a received frame with a matching VS field (in the RX chunks) */
214 struct oa_tc6_frame_buffer **,
215 uint8_t, uint8_t);
216
217/* Get the first frame in the RX queue */
219
220/* Mark the frame buffer as ready to be reused for a new frame. */
222
223/* Get a frame buffer which can be filled and submitted for transmission */
225
226/* Mark the frame buffer as filled and ready for transmission */
228
229/*
230 * Transmit all the frames in the OA_BUFF_TX_READY state and receive the
231 * available chunks.
232 */
233int oa_tc6_thread(struct oa_tc6_desc *);
234
235/* Initialize the OA TC6 SPI driver */
236int oa_tc6_init(struct oa_tc6_desc **, struct oa_tc6_init_param *);
237
238/* Free the resources allocated by the oa_tc6_init() function */
239int oa_tc6_remove(struct oa_tc6_desc *);
240
241#endif /* _NO_OS_OA_TC6_H */
Header file of SPI Interface.
Header file of utility functions.
int oa_tc6_get_tx_frame(struct oa_tc6_desc *, struct oa_tc6_frame_buffer **)
Get a frame buffer that can be filled by user.
Definition oa_tc6.c:180
oa_tc6_user_buffer_state
State for data buffers containing Ethernet frames.
Definition oa_tc6.h:135
@ OA_BUFF_RX_IN_PROGRESS
Definition oa_tc6.h:147
@ OA_BUFF_TX_READY
Definition oa_tc6.h:162
@ OA_BUFF_FREE
Definition oa_tc6.h:140
@ OA_BUFF_RX_COMPLETE
Definition oa_tc6.h:153
@ OA_BUFF_RX_USER_OWNED
Definition oa_tc6.h:156
@ OA_BUFF_TX_BUSY
Definition oa_tc6.h:159
int oa_tc6_init(struct oa_tc6_desc **, struct oa_tc6_init_param *)
Allocate resources for the OA TC6 driver.
Definition oa_tc6.c:641
int oa_tc6_remove(struct oa_tc6_desc *)
Free a device descriptor.
Definition oa_tc6.c:674
#define OA_TX_FRAME_BUFF_NUM
Definition oa_tc6.h:52
int oa_tc6_get_rx_frame_match_vs(struct oa_tc6_desc *, struct oa_tc6_frame_buffer **, uint8_t, uint8_t)
Get a frame buffer that is ready to be read by the user. The VS field in the chunk footer fields shou...
Definition oa_tc6.c:281
#define OA_RX_FRAME_BUFF_NUM
Definition oa_tc6.h:53
int oa_tc6_reg_update(struct oa_tc6_desc *, uint32_t, uint32_t, uint32_t)
Update a field inside a register.
Definition oa_tc6.c:158
int oa_tc6_reg_read(struct oa_tc6_desc *, uint32_t, uint32_t *)
Read a register value.
Definition oa_tc6.c:108
int oa_tc6_put_rx_frame(struct oa_tc6_desc *, struct oa_tc6_frame_buffer *)
Mark a frame buffer as used and ready to be rewritten.
Definition oa_tc6.c:325
int oa_tc6_put_tx_frame(struct oa_tc6_desc *, struct oa_tc6_frame_buffer *)
Mark a frame buffer as ready to be transmitted.
Definition oa_tc6.c:206
int oa_tc6_get_rx_frame(struct oa_tc6_desc *, struct oa_tc6_frame_buffer **)
Get a frame buffer that is ready to be read by the user.
Definition oa_tc6.c:304
int oa_tc6_reg_write(struct oa_tc6_desc *, uint32_t, uint32_t)
Write a register value.
Definition oa_tc6.c:133
#define OA_SPI_BUFF_LEN
Definition oa_tc6.h:56
int oa_tc6_thread(struct oa_tc6_desc *)
Transmit all the frames in the OA_BUFF_TX_READY state and receive the frames in the OA_BUFF_RX_COMPLE...
Definition oa_tc6.c:571
#define CONFIG_OA_CHUNK_BUFFER_SIZE
Definition oa_tc6.h:49
Structure holding SPI descriptor.
Definition no_os_spi.h:180
Holds the frame buffers and the communication descriptor for the OA TC6 driver.
Definition oa_tc6.h:181
uint32_t data_rx_credit
Definition oa_tc6.h:190
struct oa_tc6_frame_buffer user_rx_frame_buffer[OA_RX_FRAME_BUFF_NUM]
Definition oa_tc6.h:186
uint32_t ctrl_rx_credit
Definition oa_tc6.h:193
uint8_t ctrl_chunks[12]
Definition oa_tc6.h:183
struct no_os_spi_desc * comm_desc
Definition oa_tc6.h:182
uint8_t data_chunks[OA_SPI_BUFF_LEN]
Definition oa_tc6.h:184
uint32_t ctrl_tx_credit
Definition oa_tc6.h:192
struct oa_tc6_frame_buffer user_tx_frame_buffer[OA_TX_FRAME_BUFF_NUM]
Definition oa_tc6.h:187
uint32_t data_tx_credit
Definition oa_tc6.h:189
Stores an Ethernet frame along with metadata needed for parsing. The MAC driver or the user applicati...
Definition oa_tc6.h:170
enum oa_tc6_user_buffer_state state
Definition oa_tc6.h:174
uint8_t data[CONFIG_OA_CHUNK_BUFFER_SIZE]
Definition oa_tc6.h:173
uint8_t vs
Definition oa_tc6.h:175
uint32_t index
Definition oa_tc6.h:171
uint32_t len
Definition oa_tc6.h:172
Holds the initialization parameters for the OA TC6 driver.
Definition oa_tc6.h:199
struct no_os_spi_desc * comm_desc
Definition oa_tc6.h:200