AM243x MCU+ SDK  09.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 <errno.h>
62 #include "lldenet.h"
63 #include "lldtsync.h"
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
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 #ifndef ECONNREFUSED
83 /* Use to fix the compiling error, no real usage */
84 #define ECONNREFUSED 100
85 #endif
86 #define MAX_NUMBER_ENET_DEVS LLDENET_MAX_PORTS
87 
88 #define CB_SOCKET_VALID(x) ((x)!=NULL)
89 #define CB_SOCKET_INVALID_VALUE NULL
90 #define CB_SOCKET_T lld_socket_t*
91 #define CB_ETHHDR_T struct ethhdr
92 #define CB_SOCKADDR_LL_T struct sockaddr
93 #define CB_SOCK_SENDTO cb_lld_sendto
94 #define CB_SOCK_CLOSE cb_rawsock_close
95 #define CB_OPEN open
96 #define CB_CLOSE close
97 #define CB_WRITE write
98 
99 /* does not support */
100 #define CB_IN_ADDR_T void*
101 
102 #ifndef IFNAMSIZ
103 #define IFNAMSIZ 16
104 #endif
105 
106 #define ETH_ALEN 6 /* Octets in one ethernet addr */
107 #define ETH_HLEN 14 /* Total octets in header. */
108 #define ETH_DATA_LEN 1500 /* Max. octets in payload */
109 
110 #define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */
111 #define ETH_P_1588 0x88F7 /* IEEE 1588 Timesync */
112 #define ETH_P_LLDP 0x88CC /* 802.1AB LLDP */
113 #define ETH_P_TSN 0x22F0 /* TSN (IEEE 1722) packet */
114 #define ETH_P_NETLINK 0x22F1 /* A virtual prototol for netlink rawsockt on TI platforms */
115 
116 #define CB_MAX_NETDEVNAME IFNAMSIZ
117 
118 #define MKPIPE(x) (-1)
119 
120 #define CB_LLD_MAX_ETH_FRAME_SIZE (1522U)
121 
125 struct ethhdr {
129  uint8_t h_dest[ETH_ALEN];
133  uint8_t h_source[ETH_ALEN];
137  uint16_t h_proto;
138 } __attribute__((packed));
139 
143 struct sockaddr {
147  unsigned char sll_addr[6];
151  int macport;
156  int tcid;
157 };
158 
162 typedef struct lld_socket lld_socket_t;
163 
167 typedef struct {
171  char *netdev;
175  uint8_t macport;
179  uint8_t srcmac[ETH_ALEN];
180 } lld_ethdev_t;
181 
185 typedef struct {
186  /* below are keys to match the expected socket */
190  const char *dev;
195  uint16_t proto;
199  uint16_t vlanid;
200  /* below are params can be updated to LLDEnetCfg_t */
205  uint32_t nTxPkts;
215  uint32_t pktSize;
252  void (*rxDefaultDataCb)(void *data, int size, int port, void *cbArg);
261  uint32_t numRxChannels;
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 
331 int cb_lld_recv(CB_SOCKET_T sfd, void *buf, int size, int *port);
332 
341 int cb_lld_set_txnotify_cb(CB_SOCKET_T sfd, void (*txnotify_cb)(void *arg), void *arg);
342 
351 int cb_lld_set_rxnotify_cb(CB_SOCKET_T sfd, void (*rxnotify_cb)(void *arg), void *arg);
352 
362  void (*default_rxdata_cb)(void *data, int size, int port, void *arg), void *arg);
363 
370 int cb_lld_get_type_instance(uint32_t *enet_type, uint32_t *instance_id);
371 
378 int cb_lld_get_netdevs(char* netdevs[], int *len);
379 
388 int cb_lld_get_link_state(CB_SOCKET_T cfd, const char *dev, uint32_t *linkstate);
389 
399 int cb_lld_get_link_info(CB_SOCKET_T cfd, const char *dev, uint32_t *speed, uint32_t *duplex);
400 
407 
408 #ifdef __cplusplus
409 }
410 #endif
411 #endif //CB_LLD_ETHERNET_H
412 
ethhdr::h_dest
uint8_t h_dest[ETH_ALEN]
Definition: cb_lld_ethernet.h:129
sockaddr::sll_addr
unsigned char sll_addr[6]
Definition: cb_lld_ethernet.h:147
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.
ethhdr::h_proto
uint16_t h_proto
Definition: cb_lld_ethernet.h:137
lld_ethdev_t
Structure representing the lld_ethdev instance.
Definition: cb_lld_ethernet.h:167
lldenet.h
TI Ethernet Low Level Driver abstract APIs.
cb_socket_lldcfg_update_t::dmaRxShared
int dmaRxShared
Definition: cb_lld_ethernet.h:241
cb_socket_lldcfg_update_t::dmaTxChId
int dmaTxChId
Definition: cb_lld_ethernet.h:220
lld_socket_t
struct lld_socket lld_socket_t
Structure representing the lld_socket instance.
Definition: cb_lld_ethernet.h:162
ethhdr
Ethernet header structure.
Definition: cb_lld_ethernet.h:125
data
uint32_t data
Definition: tisci_rm_psil.h:1
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
Structure representing the lld_sockaddr instance.
Definition: cb_lld_ethernet.h:143
lld_ethdev_t::netdev
char * netdev
Definition: cb_lld_ethernet.h:171
cb_socket_lldcfg_update_t::rxDefaultCbArg
void * rxDefaultCbArg
Definition: cb_lld_ethernet.h:257
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:195
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()
ethhdr::h_source
uint8_t h_source[ETH_ALEN]
Definition: cb_lld_ethernet.h:133
CB_SOCKADDR_LL_T
#define CB_SOCKADDR_LL_T
Definition: cb_lld_ethernet.h:92
cb_socket_lldcfg_update_t::dmaRxOwner
int dmaRxOwner
Definition: cb_lld_ethernet.h:247
MAX_NUM_RX_DMA_CH_PER_INSTANCE
#define MAX_NUM_RX_DMA_CH_PER_INSTANCE
Definition: lldenet.h:66
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:270
cb_socket_lldcfg_update_t::pktSize
uint32_t pktSize
Definition: cb_lld_ethernet.h:215
cb_socket_lldcfg_update_t::nTxPkts
uint32_t nTxPkts
Definition: cb_lld_ethernet.h:205
__attribute__
struct sockaddr __attribute__
lld_ethdev_t::macport
uint8_t macport
Definition: cb_lld_ethernet.h:175
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:185
cb_socket_lldcfg_update_t::unusedDmaTx
int unusedDmaTx
Definition: cb_lld_ethernet.h:235
ETH_ALEN
#define ETH_ALEN
Definition: cb_lld_ethernet.h:106
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.
sockaddr::macport
int macport
Definition: cb_lld_ethernet.h:151
cb_socket_lldcfg_update_t::vlanid
uint16_t vlanid
Definition: cb_lld_ethernet.h:199
lldtsync.h
TI Timesync Low Level Driver abstract APIs.
flags
uint32_t flags
Definition: csl_udmap_tr.h:0
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:190
cb_socket_lldcfg_update_t::numRxChannels
uint32_t numRxChannels
Definition: cb_lld_ethernet.h:261
cb_lld_is_rxts_inbuff
bool cb_lld_is_rxts_inbuff(CB_SOCKET_T sfd)
Checks the receive packet timestamping mode.
CB_SOCKET_T
#define CB_SOCKET_T
Definition: cb_lld_ethernet.h:90
sockaddr::tcid
int tcid
Definition: cb_lld_ethernet.h:156
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'
cb_socket_lldcfg_update_t::unusedDmaRx
int unusedDmaRx
Definition: cb_lld_ethernet.h:230