AM243x MCU+ SDK  09.00.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 <errno.h>
62 #include "lldenet.h"
63 #include "lldtsync.h"
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 #define htons __htons
70 #define ntohs __ntohs
71 #define htonl __htonl
72 #define ntohl __ntohl
73 
74 #define MAX_NUMBER_ENET_DEVS LLDENET_MAX_PORTS
75 
76 #define CB_SOCKET_VALID(x) ((x)!=NULL)
77 #define CB_SOCKET_INVALID_VALUE NULL
78 #define CB_SOCKET_T lld_socket_t*
79 #define CB_ETHHDR_T struct ethhdr
80 #define CB_SOCKADDR_LL_T lld_sockaddr_t
81 #define CB_SOCK_SENDTO cb_lld_sendto
82 
83 /* does not support */
84 #define CB_IN_ADDR_T void*
85 
86 #define IFNAMSIZ 16
87 #define ETH_ALEN 6 /* Octets in one ethernet addr */
88 #define ETH_HLEN 14 /* Total octets in header. */
89 #define ETH_DATA_LEN 1500 /* Max. octets in payload */
90 
91 #define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */
92 #define ETH_P_1588 0x88F7 /* IEEE 1588 Timesync */
93 #define ETH_P_TSN 0x22F0 /* TSN (IEEE 1722) packet */
94 #define ETH_P_NETLINK 0x22F1 /* A virtual prototol for netlink rawsockt on TI platforms */
95 
96 #define CB_MAX_NETDEVNAME IFNAMSIZ
97 
98 #define MKPIPE(x) (-1)
99 
100 #define CB_LLD_MAX_ETH_FRAME_SIZE (1522U)
101 
105 struct ethhdr {
109  uint8_t h_dest[ETH_ALEN];
113  uint8_t h_source[ETH_ALEN];
117  uint16_t h_proto;
118 } __attribute__((packed));
119 
123 typedef struct {
127  unsigned char sll_addr[6];
131  int macport;
136  int tcid;
138 
139 //-------------------------------------------------------------------------------
140 //FIXME: Add this to make gptp ipc compile okay. We will remove IPC in the future
141 struct sockaddr {
142 };
143 typedef int(* cb_ipcsocket_server_rdcb)(void *cbdata, uint8_t *rdata,
144  int size, struct sockaddr *addr);
145 //-------------------------------------------------------------------------------
146 
150 typedef struct lld_socket lld_socket_t;
151 
155 typedef struct {
159  char *netdev;
163  uint8_t macport;
167  uint8_t srcmac[ETH_ALEN];
168 } lld_ethdev_t;
169 
173 typedef struct {
174  /* below are keys to match the expected socket */
178  const char *dev;
183  uint16_t proto;
187  uint16_t vlanid;
188  /* below are params can be updated to LLDEnetCfg_t */
193  uint32_t nTxPkts;
198  uint32_t nRxPkts;
203  uint32_t pktSize;
217  bool unusedDma;
219 
227 
245 int cb_lld_init_devs_table(lld_ethdev_t *ethdevs, uint32_t ndevs,
246  uint32_t enet_type, uint32_t instance_id);
247 
257 
263 int cb_lld_netdev_to_macport(const char *netdev);
264 
275 int cb_lld_sendto(CB_SOCKET_T sfd, void *sdata, int psize, int flags,
276  CB_SOCKADDR_LL_T *addr, int addrsize);
277 
287 int cb_lld_recv(CB_SOCKET_T sfd, void *buf, int size, int *port);
288 
297 int cb_lld_set_txnotify_cb(CB_SOCKET_T sfd, void (*txnotify_cb)(void *arg), void *arg);
298 
307 int cb_lld_set_rxnotify_cb(CB_SOCKET_T sfd, void (*rxnotify_cb)(void *arg), void *arg);
308 
315 int cb_lld_get_type_instance(uint32_t *enet_type, uint32_t *instance_id);
316 
323 int cb_lld_get_netdevs(char* netdevs[], int *len);
324 
333 int cb_lld_get_link_state(CB_SOCKET_T cfd, const char *dev, uint32_t *linkstate);
334 
344 int cb_lld_get_link_info(CB_SOCKET_T cfd, const char *dev, uint32_t *speed, uint32_t *duplex);
345 
346 #ifdef __cplusplus
347 }
348 #endif
349 #endif //CB_LLD_ETHERNET_H
350 
lld_sockaddr_t::macport
int macport
Definition: cb_lld_ethernet.h:131
ethhdr::h_dest
uint8_t h_dest[ETH_ALEN]
Definition: cb_lld_ethernet.h:109
size
uint16_t size
Definition: tisci_boardcfg.h:1
cb_socket_lldcfg_update_t::unusedDma
bool unusedDma
Definition: cb_lld_ethernet.h:217
ethhdr::h_proto
uint16_t h_proto
Definition: cb_lld_ethernet.h:117
cb_lld_sendto
int cb_lld_sendto(CB_SOCKET_T sfd, void *sdata, int psize, int flags, CB_SOCKADDR_LL_T *addr, int addrsize)
Send a TX ethernet L2 packet.
lld_ethdev_t
Structure representing the lld_ethdev instance.
Definition: cb_lld_ethernet.h:155
lldenet.h
TI Ethernet Low Level Driver abstract APIs.
cb_socket_lldcfg_update_t::dmaTxChId
int dmaTxChId
Definition: cb_lld_ethernet.h:208
lld_socket_t
struct lld_socket lld_socket_t
Structure representing the lld_socket instance.
Definition: cb_lld_ethernet.h:150
lld_sockaddr_t::tcid
int tcid
Definition: cb_lld_ethernet.h:136
ethhdr
Ethernet header structure.
Definition: cb_lld_ethernet.h:105
cb_socket_lldcfg_update_t::nRxPkts
uint32_t nRxPkts
Definition: cb_lld_ethernet.h:198
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
sockaddr
Definition: cb_lld_ethernet.h:141
lld_ethdev_t::netdev
char * netdev
Definition: cb_lld_ethernet.h:159
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:183
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()
__attribute__
typedef __attribute__
UInteger224 (802.1AS, 10.3.4 time-synchronization spanning tree priority vectors )
ethhdr::h_source
uint8_t h_source[ETH_ALEN]
Definition: cb_lld_ethernet.h:113
CB_SOCKADDR_LL_T
#define CB_SOCKADDR_LL_T
Definition: cb_lld_ethernet.h:80
cb_lld_recv
int cb_lld_recv(CB_SOCKET_T sfd, void *buf, int size, int *port)
Receive a RX ethernet L2 packet. This should be called after a rxnotify_cb is invoked.
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:226
cb_socket_lldcfg_update_t::pktSize
uint32_t pktSize
Definition: cb_lld_ethernet.h:203
lld_sockaddr_t
Structure representing the lld_sockaddr instance.
Definition: cb_lld_ethernet.h:123
cb_socket_lldcfg_update_t::nTxPkts
uint32_t nTxPkts
Definition: cb_lld_ethernet.h:193
cb_socket_lldcfg_update_t::dmaRxChId
int dmaRxChId
Definition: cb_lld_ethernet.h:213
lld_ethdev_t::macport
uint8_t macport
Definition: cb_lld_ethernet.h:163
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_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:173
ETH_ALEN
#define ETH_ALEN
Definition: cb_lld_ethernet.h:87
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:187
lldtsync.h
TI Timesync Low Level Driver abstract APIs.
flags
uint32_t flags
Definition: csl_udmap_tr.h:0
cb_ipcsocket_server_rdcb
int(* cb_ipcsocket_server_rdcb)(void *cbdata, uint8_t *rdata, int size, struct sockaddr *addr)
Definition: cb_lld_ethernet.h:143
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:178
CB_SOCKET_T
#define CB_SOCKET_T
Definition: cb_lld_ethernet.h:78
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'