AM275 FreeRTOS SDK  10.01.00
cb_lld_ethernet.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Texas Instruments Incorporated
3  * Copyright (c) 2023 Excelfore Corporation (https://excelfore.com)
4  *
5  * All rights reserved not granted herein.
6  * Limited License.
7  *
8  * Texas Instruments Incorporated grants a world-wide, royalty-free,
9  * non-exclusive license under copyrights and patents it now or hereafter
10  * owns or controls to make, have made, use, import, offer to sell and sell ("Utilize")
11  * this software subject to the terms herein. With respect to the foregoing patent
12  * license, such license is granted solely to the extent that any such patent is necessary
13  * to Utilize the software alone. The patent license shall not apply to any combinations which
14  * include this software, other than combinations with devices manufactured by or for TI ("TI Devices").
15  * No hardware patent is licensed hereunder.
16  *
17  * Redistributions must preserve existing copyright notices and reproduce this license (including the
18  * above copyright notice and the disclaimer and (if applicable) source code license limitations below)
19  * in the documentation and/or other materials provided with the distribution
20  *
21  * Redistribution and use in binary form, without modification, are permitted provided that the following
22  * conditions are met:
23  *
24  * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any
25  * software provided in binary form.
26  * * any redistribution and use are licensed by TI for use only with TI Devices.
27  * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
28  *
29  * If software source code is provided to you, modification and redistribution of the source code are permitted
30  * provided that the following conditions are met:
31  *
32  * * any redistribution and use of the source code, including any resulting derivative works, are licensed by
33  * TI for use only with TI Devices.
34  * * any redistribution and use of any object code compiled from the source code and any resulting derivative
35  * works, are licensed by TI for use only with TI Devices.
36  *
37  * Neither the name of Texas Instruments Incorporated nor the names of its suppliers may be used to endorse or
38  * promote products derived from this software without specific prior written permission.
39  *
40  * DISCLAIMER.
41  *
42  * THIS SOFTWARE IS PROVIDED BY TI AND TI"S LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
43  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44  * IN NO EVENT SHALL TI AND TI"S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
46  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48  * POSSIBILITY OF SUCH DAMAGE.
49 */
57 #ifndef CB_LLD_ETHERNET_H
58 #define CB_LLD_ETHERNET_H
59 
60 #include <sys/types.h>
61 #include "lldenet.h"
62 #include "lldtsync.h"
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
67 // To prevent dupplicated declaration of below APIs
68 #define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
69 #ifndef htons
70 #define htons __htons
71 #endif
72 #ifndef ntohs
73 #define ntohs __ntohs
74 #endif
75 #ifndef htonl
76 #define htonl __htonl
77 #endif
78 #ifndef ntohl
79 #define ntohl __ntohl
80 #endif
81 
82 #define MAX_NUMBER_ENET_DEVS LLDENET_MAX_PORTS
83 
84 #define CB_SOCKET_VALID(x) ((x)!=NULL)
85 #define CB_SOCKET_INVALID_VALUE NULL
86 #define CB_SOCKET_T lld_socket_t*
87 #define CB_ETHHDR_T struct lld_ethhdr
88 #define CB_SOCKADDR_LL_T struct lld_sockaddr
89 #define CB_SOCKADDR_T struct lld_sockaddr
90 #define CB_SOCK_SENDTO cb_lld_sendto
91 #define CB_SOCK_CLOSE cb_rawsock_close
92 
93 #define CB_OPEN open
94 #define CB_CLOSE close
95 #define CB_WRITE write
96 
97 /* does not support */
98 #define CB_IN_ADDR_T void*
99 
100 #define ETH_ALEN 6 /* Octets in one ethernet addr */
101 #define ETH_HLEN 14 /* Total octets in header. */
102 #define ETH_DATA_LEN 1500 /* Max. octets in payload */
103 
104 #define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */
105 #define ETH_P_1588 0x88F7 /* IEEE 1588 Timesync */
106 #define ETH_P_LLDP 0x88CC /* 802.1AB LLDP */
107 #define ETH_P_TSN 0x22F0 /* TSN (IEEE 1722) packet */
108 #define ETH_P_NETLINK 0x22F1 /* A virtual prototol for netlink rawsockt on TI platforms */
109 
110 #define CB_MAX_NETDEVNAME 16
111 
112 #define MKPIPE(x) (-1)
113 
114 #define CB_LLD_MAX_ETH_FRAME_SIZE (1522U)
115 
119 struct lld_ethhdr {
123  uint8_t h_dest[ETH_ALEN];
127  uint8_t h_source[ETH_ALEN];
131  uint16_t h_proto;
132 } __attribute__((packed));
133 
137 struct lld_sockaddr {
141  unsigned char sll_addr[6];
145  int macport;
150  int tcid;
154  uint64_t rxts;
155 };
156 
160 typedef struct lld_socket lld_socket_t;
161 
165 typedef struct {
169  char *netdev;
173  uint8_t macport;
177  uint8_t srcmac[ETH_ALEN];
178 } lld_ethdev_t;
179 
183 typedef struct {
184  /* below are keys to match the expected socket */
188  const char *dev;
193  uint16_t proto;
197  uint16_t vlanid;
198  /* below are params can be updated to LLDEnetCfg_t */
203  uint32_t nTxPkts;
213  uint32_t pktSize;
246  void (*rxDefaultDataCb)(void *data, int size, int port, void *cbArg);
257 
258 /* Number of elements in a statistics block */
259 #define CB_TILLD_STATS_BLOCK_ELEM_NUM (128U)
260 typedef struct cb_tilld_port_stats {
263 
271 
289 int cb_lld_init_devs_table(lld_ethdev_t *ethdevs, uint32_t ndevs,
290  uint32_t enet_type, uint32_t instance_id);
291 
301 
307 int cb_lld_netdev_to_macport(const char *netdev);
308 
319 int cb_lld_sendto(CB_SOCKET_T sfd, void *sdata, int psize, int flags,
320  const CB_SOCKADDR_LL_T *addr, int addrsize);
321 
330  const CB_SOCKADDR_LL_T *addr);
331 
342 int cb_lld_recv(CB_SOCKET_T sfd, void *buf, int size,
343  CB_SOCKADDR_LL_T *addr, int addrsize);
344 
353 int cb_lld_recv_zerocopy(CB_SOCKET_T sfd, LLDEnetRecvCb_t cblld_recv_cb, void *cbarg);
354 
363 int cb_lld_set_txnotify_cb(CB_SOCKET_T sfd, void (*txnotify_cb)(void *arg), void *arg);
364 
373 int cb_lld_set_rxnotify_cb(CB_SOCKET_T sfd, void (*rxnotify_cb)(void *arg), void *arg);
374 
384  void (*default_rxdata_cb)(void *data, int size, int port, void *arg), void *arg);
385 
392 int cb_lld_get_type_instance(uint32_t *enet_type, uint32_t *instance_id);
393 
400 int cb_lld_get_netdevs(char* netdevs[], int *len);
401 
410 int cb_lld_get_link_state(CB_SOCKET_T cfd, const char *dev, uint32_t *linkstate);
411 
421 int cb_lld_get_link_info(CB_SOCKET_T cfd, const char *dev, uint32_t *speed, uint32_t *duplex);
422 
432 
440 
441 #ifdef __cplusplus
442 }
443 #endif
444 #endif //CB_LLD_ETHERNET_H
445 
cb_lld_get_port_stats
int cb_lld_get_port_stats(CB_SOCKET_T sfd, int port, cb_tilld_port_stats_t *stats)
Get stats info from host or mac port.
size
uint16_t size
Definition: tisci_boardcfg.h:1
cb_lld_sendto
int cb_lld_sendto(CB_SOCKET_T sfd, void *sdata, int psize, int flags, const CB_SOCKADDR_LL_T *addr, int addrsize)
Send a TX ethernet L2 packet.
__attribute__
struct lld_sockaddr __attribute__
cb_lld_recv_zerocopy
int cb_lld_recv_zerocopy(CB_SOCKET_T sfd, LLDEnetRecvCb_t cblld_recv_cb, void *cbarg)
Receive a RX ethernet L2 packet n the zero-copy way. This should be called after a rxnotify_cb is inv...
lld_ethdev_t
Structure representing the lld_ethdev instance.
Definition: cb_lld_ethernet.h:165
lldenet.h
TI Ethernet Low Level Driver abstract APIs.
cb_socket_lldcfg_update_t::dmaRxShared
int dmaRxShared
Definition: cb_lld_ethernet.h:235
cb_socket_lldcfg_update_t::dmaTxChId
int dmaTxChId
Definition: cb_lld_ethernet.h:218
lld_ethhdr::h_proto
uint16_t h_proto
Definition: cb_lld_ethernet.h:131
lld_socket_t
struct lld_socket lld_socket_t
Structure representing the lld_socket instance.
Definition: cb_lld_ethernet.h:160
lld_ethhdr::h_source
uint8_t h_source[ETH_ALEN]
Definition: cb_lld_ethernet.h:127
LLDEnetRecvCb_t
void(* LLDEnetRecvCb_t)(LLDEnetFrame_t *frame, void *cbArg)
Receives callback an Ethernet frame using LLDEnet in the Zero-Copy way.
Definition: lldenet.h:337
lld_sockaddr::sll_addr
unsigned char sll_addr[6]
Definition: cb_lld_ethernet.h:141
data
uint32_t data
Definition: tisci_rm_psil.h:1
lld_sockaddr::macport
int macport
Definition: cb_lld_ethernet.h:145
cb_lld_netdev_to_macport
int cb_lld_netdev_to_macport(const char *netdev)
Convert net device name to mac port.
addr
uint64_t addr
Definition: csl_udmap_tr.h:3
cb_lld_recv
int cb_lld_recv(CB_SOCKET_T sfd, void *buf, int size, CB_SOCKADDR_LL_T *addr, int addrsize)
Receive a RX ethernet L2 packet. This should be called after a rxnotify_cb is invoked.
cb_socket_lldcfg_update_t::numRxChannels
int numRxChannels
Definition: cb_lld_ethernet.h:255
lld_ethdev_t::netdev
char * netdev
Definition: cb_lld_ethernet.h:169
cb_socket_lldcfg_update_t::rxDefaultCbArg
void * rxDefaultCbArg
Definition: cb_lld_ethernet.h:251
cb_socket_set_lldcfg_update_cb
int cb_socket_set_lldcfg_update_cb(cb_socket_lldcfg_update_cb_t lldcfg_update_cb)
This function sets the callback for updating LLD config parameters. It enables the user to update con...
cb_socket_lldcfg_update_t::proto
uint16_t proto
Definition: cb_lld_ethernet.h:193
lld_sockaddr::tcid
int tcid
Definition: cb_lld_ethernet.h:150
cb_lld_get_type_instance
int cb_lld_get_type_instance(uint32_t *enet_type, uint32_t *instance_id)
Get enet type and instance that is set via cb_lld_init_devs_table()
CB_SOCKADDR_LL_T
#define CB_SOCKADDR_LL_T
Definition: cb_lld_ethernet.h:88
cb_socket_lldcfg_update_t::dmaRxOwner
int dmaRxOwner
Definition: cb_lld_ethernet.h:241
MAX_NUM_RX_DMA_CH_PER_INSTANCE
#define MAX_NUM_RX_DMA_CH_PER_INSTANCE
Definition: lldtype.h:114
LLDEnetFrameScatter_t
Structure representing an Ethernet frame.
Definition: lldenet.h:203
cb_socket_lldcfg_update_cb_t
int(* cb_socket_lldcfg_update_cb_t)(cb_socket_lldcfg_update_t *update_cfg)
Callback function type for cb_socket_lldcfg_update.
Definition: cb_lld_ethernet.h:270
cb_socket_lldcfg_update_t::pktSize
uint32_t pktSize
Definition: cb_lld_ethernet.h:213
lld_ethhdr
Ethernet header structure.
Definition: cb_lld_ethernet.h:119
cb_tilld_port_stats_t
Definition: cb_lld_ethernet.h:260
cb_lld_sendto_scatter
int cb_lld_sendto_scatter(CB_SOCKET_T sfd, LLDEnetFrameScatter_t *frame, const CB_SOCKADDR_LL_T *addr)
Send a TX ethernet L2 packet in the scatter way.
cb_socket_lldcfg_update_t::nTxPkts
uint32_t nTxPkts
Definition: cb_lld_ethernet.h:203
CB_TILLD_STATS_BLOCK_ELEM_NUM
#define CB_TILLD_STATS_BLOCK_ELEM_NUM
Definition: cb_lld_ethernet.h:259
lld_ethdev_t::macport
uint8_t macport
Definition: cb_lld_ethernet.h:173
lld_ethhdr::h_dest
uint8_t h_dest[ETH_ALEN]
Definition: cb_lld_ethernet.h:123
cb_socket_lldcfg_update_t::dmaTxShared
int dmaTxShared
Definition: cb_lld_ethernet.h:229
cb_lld_set_rxnotify_cb
int cb_lld_set_rxnotify_cb(CB_SOCKET_T sfd, void(*rxnotify_cb)(void *arg), void *arg)
Set the RX notify callback that is invoked when an RX packet is ready to be received.
cb_lld_set_default_rxdata_cb
int cb_lld_set_default_rxdata_cb(CB_SOCKET_T sfd, void(*default_rxdata_cb)(void *data, int size, int port, void *arg), void *arg)
Set the default RX data callback that is invoked when an RX packet does not match any filters.
cb_lld_init_devs_table
int cb_lld_init_devs_table(lld_ethdev_t *ethdevs, uint32_t ndevs, uint32_t enet_type, uint32_t instance_id)
Initialize a LLD device table.
cb_lld_set_txnotify_cb
int cb_lld_set_txnotify_cb(CB_SOCKET_T sfd, void(*txnotify_cb)(void *arg), void *arg)
Set the TX notify callback that is invoked when an TX packet is sent successfully.
cb_socket_lldcfg_update_t
Structure representing the cb_socket_lldcfg_update instance.
Definition: cb_lld_ethernet.h:183
ETH_ALEN
#define ETH_ALEN
Definition: cb_lld_ethernet.h:100
cb_lld_get_netdevs
int cb_lld_get_netdevs(char *netdevs[], int *len)
Get all virtual network interfaces which were defined for the TI platform.
cb_socket_lldcfg_update_t::vlanid
uint16_t vlanid
Definition: cb_lld_ethernet.h:197
cb_lld_reset_port_stats
void cb_lld_reset_port_stats(CB_SOCKET_T sfd, int port)
reset stats info from host or mac port.
lldtsync.h
TI Timesync Low Level Driver abstract APIs.
flags
uint32_t flags
Definition: csl_udmap_tr.h:0
lld_sockaddr::rxts
uint64_t rxts
Definition: cb_lld_ethernet.h:154
lld_sockaddr
Structure representing the lld_sockaddr instance.
Definition: cb_lld_ethernet.h:137
cb_lld_get_link_state
int cb_lld_get_link_state(CB_SOCKET_T cfd, const char *dev, uint32_t *linkstate)
get link state from device name like 'eth0'
cb_socket_lldcfg_update_t::dev
const char * dev
Definition: cb_lld_ethernet.h:188
CB_SOCKET_T
#define CB_SOCKET_T
Definition: cb_lld_ethernet.h:86
cb_lld_get_link_info
int cb_lld_get_link_info(CB_SOCKET_T cfd, const char *dev, uint32_t *speed, uint32_t *duplex)
get link info(speed and duplex) from device name like 'eth0'