1 /******************************************************************************
3 * Copyright (C) 2007 - 2014 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
34 #include "xlwipconfig.h"
37 #ifdef OS_IS_XILKERNEL
39 #include "sys/process.h"
44 #include "lwip/stats.h"
49 #include "lwip/tcp_impl.h"
51 #include "netif/etharp.h"
52 #include "netif/xadapter.h"
54 #ifdef XLWIP_CONFIG_INCLUDE_EMACLITE
55 #include "netif/xemacliteif.h"
58 #ifdef XLWIP_CONFIG_INCLUDE_TEMAC
59 #include "netif/xlltemacif.h"
62 #ifdef XLWIP_CONFIG_INCLUDE_AXI_ETHERNET
63 #include "netif/xaxiemacif.h"
66 #ifdef XLWIP_CONFIG_INCLUDE_GEM
67 #include "netif/xemacpsif.h"
71 #include "lwip/tcpip.h"
75 /* global lwip debug variable used for debugging */
76 int lwip_runtime_debug = 0;
81 ip_init(); /* Doesn't do much, it should be called to handle future changes. */
83 udp_init(); /* Clears the UDP PCB list. */
86 tcp_init(); /* Clears the TCP PCB list and clears some internal TCP timers. */
87 /* Note: you must call tcp_fasttmr() and tcp_slowtmr() at the */
88 /* predefined regular intervals after this initialization. */
92 static enum xemac_types
93 find_mac_type(unsigned base)
97 for (i = 0; i < xtopology_n_emacs; i++) {
98 if (xtopology[i].emac_baseaddr == base)
99 return xtopology[i].emac_type;
102 return xemac_type_unknown;
106 xtopology_find_index(unsigned base)
110 for (i = 0; i < xtopology_n_emacs; i++) {
111 if (xtopology[i].emac_baseaddr == base)
119 * xemac_add: this is a wrapper around lwIP's netif_add function.
120 * The objective is to provide portability between the different Xilinx MAC's
121 * This function can be used to add both xps_ethernetlite and xps_ll_temac
125 xemac_add(struct netif *netif,
126 struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw,
127 unsigned char *mac_ethernet_address,
128 unsigned mac_baseaddr)
132 /* set mac address */
133 netif->hwaddr_len = 6;
134 for (i = 0; i < 6; i++)
135 netif->hwaddr[i] = mac_ethernet_address[i];
137 /* initialize based on MAC type */
138 switch (find_mac_type(mac_baseaddr)) {
139 case xemac_type_xps_emaclite:
140 #ifdef XLWIP_CONFIG_INCLUDE_EMACLITE
141 return netif_add(netif, ipaddr, netmask, gw,
153 case xemac_type_xps_ll_temac:
154 #ifdef XLWIP_CONFIG_INCLUDE_TEMAC
155 return netif_add(netif, ipaddr, netmask, gw,
167 case xemac_type_axi_ethernet:
168 #ifdef XLWIP_CONFIG_INCLUDE_AXI_ETHERNET
169 return netif_add(netif, ipaddr, netmask, gw,
182 case xemac_type_emacps:
183 #ifdef XLWIP_CONFIG_INCLUDE_GEM
184 return netif_add(netif, ipaddr, netmask, gw,
197 printf("unable to determine type of EMAC with baseaddress 0x%08x\r\n",
205 * The input thread calls lwIP to process any received packets.
206 * This thread waits until a packet is received (sem_rx_data_available),
207 * and then calls xemacif_input which processes 1 packet at a time.
210 xemacif_input_thread(struct netif *netif)
212 struct xemac_s *emac = (struct xemac_s *)netif->state;
214 /* sleep until there are packets to process
215 * This semaphore is set by the packet receive interrupt
218 sys_arch_sem_wait( &emac->sem_rx_data_available, pdMS_TO_TICKS( 250 ) );
220 /* move all received packets to lwIP */
221 xemacif_input(netif);
227 xemacif_input(struct netif *netif)
229 struct xemac_s *emac = (struct xemac_s *)netif->state;
230 SYS_ARCH_DECL_PROTECT(lev);
234 switch (emac->type) {
235 case xemac_type_xps_emaclite:
236 #ifdef XLWIP_CONFIG_INCLUDE_EMACLITE
237 SYS_ARCH_PROTECT(lev);
238 n_packets = xemacliteif_input(netif);
239 SYS_ARCH_UNPROTECT(lev);
242 print("incorrect configuration: xps_ethernetlite drivers not present?");
246 case xemac_type_xps_ll_temac:
247 #ifdef XLWIP_CONFIG_INCLUDE_TEMAC
248 SYS_ARCH_PROTECT(lev);
249 n_packets = xlltemacif_input(netif);
250 SYS_ARCH_UNPROTECT(lev);
253 print("incorrect configuration: xps_ll_temac drivers not present?");
257 case xemac_type_axi_ethernet:
258 #ifdef XLWIP_CONFIG_INCLUDE_AXI_ETHERNET
259 SYS_ARCH_PROTECT(lev);
260 n_packets = xaxiemacif_input(netif);
261 SYS_ARCH_UNPROTECT(lev);
264 print("incorrect configuration: axi_ethernet drivers not present?");
269 case xemac_type_emacps:
270 #ifdef XLWIP_CONFIG_INCLUDE_GEM
271 SYS_ARCH_PROTECT(lev);
272 n_packets = xemacpsif_input(netif);
273 SYS_ARCH_UNPROTECT(lev);
276 xil_printf("incorrect configuration: ps7_ethernet drivers not present?\r\n");
282 print("incorrect configuration: unknown temac type");