1 /*
2  * Copyright (C) 2007 - 2019 Xilinx, Inc.
3  * Copyright (C) 2021 WangHuachen.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without modification,
7  * are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  *    this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  *    this list of conditions and the following disclaimer in the documentation
13  *    and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
22  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
26  * OF SUCH DAMAGE.
27  *
28  * This file is part of the lwIP TCP/IP stack.
29  *
30  */
31 
32 #ifndef __XADAPTER_H_
33 #define __XADAPTER_H_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #include "lwipopts.h"
40 
41 #if !NO_SYS
42 #ifdef OS_IS_XILKERNEL
43 #include "xmk.h"
44 #endif
45 #include "lwip/sys.h"
46 #endif
47 
48 #include "lwip/netif.h"
49 #include "lwip/ip.h"
50 
51 #include "netif/xtopology.h"
52 #include <netif/ethernetif.h>
53 
54 struct xemac_s {
55     enum xemac_types type;
56     int  topology_index;
57     void *state;
58     struct eth_device *rt_eth_device;
59 #if defined(OS_IS_FREERTOS) && defined(__arm__) && !defined(ARMR5)
60     TimerHandle_t xTimer;
61 #endif
62 };
63 
64 enum ethernet_link_status {
65     ETH_LINK_UNDEFINED = 0,
66     ETH_LINK_UP,
67     ETH_LINK_DOWN,
68     ETH_LINK_NEGOTIATING
69 };
70 
71 void eth_link_detect(struct netif *netif);
72 void         lwip_raw_init();
73 int         xemacif_input(struct netif *netif);
74 void         xemacif_input_thread(struct netif *netif);
75 struct netif *    xemac_add(struct netif *netif,
76     ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw,
77     unsigned char *mac_ethernet_address,
78     unsigned mac_baseaddr);
79 #if defined (__arm__) || defined (__aarch64__)
80 void xemacpsif_resetrx_on_no_rxdata(struct netif *netif);
81 #endif
82 
83 /* global lwip debug variable used for debugging */
84 extern int lwip_runtime_debug;
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif
91