2 * Copyright (c) 2007-2013 Xilinx, Inc. All rights reserved.
5 * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
6 * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
7 * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
8 * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
9 * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
10 * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
11 * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
12 * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
13 * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
14 * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE.
20 #include "xlwipconfig.h"
23 #ifdef OS_IS_XILKERNEL
25 #include "sys/process.h"
30 #include "lwip/stats.h"
35 #include "lwip/tcp_impl.h"
37 #include "netif/etharp.h"
38 #include "netif/xadapter.h"
40 #ifdef XLWIP_CONFIG_INCLUDE_EMACLITE
41 #include "netif/xemacliteif.h"
44 #ifdef XLWIP_CONFIG_INCLUDE_TEMAC
45 #include "netif/xlltemacif.h"
48 #ifdef XLWIP_CONFIG_INCLUDE_AXI_ETHERNET
49 #include "netif/xaxiemacif.h"
52 #ifdef XLWIP_CONFIG_INCLUDE_GEM
53 #include "netif/xemacpsif.h"
57 #include "lwip/tcpip.h"
61 /* global lwip debug variable used for debugging */
62 int lwip_runtime_debug = 0;
67 ip_init(); /* Doesn't do much, it should be called to handle future changes. */
69 udp_init(); /* Clears the UDP PCB list. */
72 tcp_init(); /* Clears the TCP PCB list and clears some internal TCP timers. */
73 /* Note: you must call tcp_fasttmr() and tcp_slowtmr() at the */
74 /* predefined regular intervals after this initialization. */
78 static enum xemac_types
79 find_mac_type(unsigned base)
83 for (i = 0; i < xtopology_n_emacs; i++) {
84 if (xtopology[i].emac_baseaddr == base)
85 return xtopology[i].emac_type;
88 return xemac_type_unknown;
92 xtopology_find_index(unsigned base)
96 for (i = 0; i < xtopology_n_emacs; i++) {
97 if (xtopology[i].emac_baseaddr == base)
105 * xemac_add: this is a wrapper around lwIP's netif_add function.
106 * The objective is to provide portability between the different Xilinx MAC's
107 * This function can be used to add both xps_ethernetlite and xps_ll_temac
111 xemac_add(struct netif *netif,
112 struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw,
113 unsigned char *mac_ethernet_address,
114 unsigned mac_baseaddr)
118 /* set mac address */
119 netif->hwaddr_len = 6;
120 for (i = 0; i < 6; i++)
121 netif->hwaddr[i] = mac_ethernet_address[i];
123 /* initialize based on MAC type */
124 switch (find_mac_type(mac_baseaddr)) {
125 case xemac_type_xps_emaclite:
126 #ifdef XLWIP_CONFIG_INCLUDE_EMACLITE
127 return netif_add(netif, ipaddr, netmask, gw,
139 case xemac_type_xps_ll_temac:
140 #ifdef XLWIP_CONFIG_INCLUDE_TEMAC
141 return netif_add(netif, ipaddr, netmask, gw,
153 case xemac_type_axi_ethernet:
154 #ifdef XLWIP_CONFIG_INCLUDE_AXI_ETHERNET
155 return netif_add(netif, ipaddr, netmask, gw,
168 case xemac_type_emacps:
169 #ifdef XLWIP_CONFIG_INCLUDE_GEM
170 return netif_add(netif, ipaddr, netmask, gw,
183 printf("unable to determine type of EMAC with baseaddress 0x%08x\r\n",
191 * The input thread calls lwIP to process any received packets.
192 * This thread waits until a packet is received (sem_rx_data_available),
193 * and then calls xemacif_input which processes 1 packet at a time.
196 xemacif_input_thread(struct netif *netif)
198 struct xemac_s *emac = (struct xemac_s *)netif->state;
200 /* sleep until there are packets to process
201 * This semaphore is set by the packet receive interrupt
204 sys_arch_sem_wait( &emac->sem_rx_data_available, 250 / portTICK_PERIOD_MS );
206 /* move all received packets to lwIP */
207 xemacif_input(netif);
213 xemacif_input(struct netif *netif)
215 struct xemac_s *emac = (struct xemac_s *)netif->state;
216 SYS_ARCH_DECL_PROTECT(lev);
220 switch (emac->type) {
221 case xemac_type_xps_emaclite:
222 #ifdef XLWIP_CONFIG_INCLUDE_EMACLITE
223 SYS_ARCH_PROTECT(lev);
224 n_packets = xemacliteif_input(netif);
225 SYS_ARCH_UNPROTECT(lev);
228 print("incorrect configuration: xps_ethernetlite drivers not present?");
232 case xemac_type_xps_ll_temac:
233 #ifdef XLWIP_CONFIG_INCLUDE_TEMAC
234 SYS_ARCH_PROTECT(lev);
235 n_packets = xlltemacif_input(netif);
236 SYS_ARCH_UNPROTECT(lev);
239 print("incorrect configuration: xps_ll_temac drivers not present?");
243 case xemac_type_axi_ethernet:
244 #ifdef XLWIP_CONFIG_INCLUDE_AXI_ETHERNET
245 SYS_ARCH_PROTECT(lev);
246 n_packets = xaxiemacif_input(netif);
247 SYS_ARCH_UNPROTECT(lev);
250 print("incorrect configuration: axi_ethernet drivers not present?");
255 case xemac_type_emacps:
256 #ifdef XLWIP_CONFIG_INCLUDE_GEM
257 SYS_ARCH_PROTECT(lev);
258 n_packets = xemacpsif_input(netif);
259 SYS_ARCH_UNPROTECT(lev);
262 xil_printf("incorrect configuration: ps7_ethernet drivers not present?\r\n");
268 print("incorrect configuration: unknown temac type");