1 /*
2  * Copyright (c) 2010-2013 Xilinx, Inc.  All rights reserved.
3  *
4  * Xilinx, Inc.
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.
16  *
17  */
18 
19 #ifndef __NETIF_XEMACPSIF_H__
20     #define __NETIF_XEMACPSIF_H__
21 
22     #ifdef __cplusplus
23         extern "C" {
24     #endif
25 
26     #include <stdint.h>
27 
28     #include "xstatus.h"
29     #include "xparameters.h"
30     #include "xparameters_ps.h" /* defines XPAR values */
31     #include "xil_types.h"
32     #include "xil_assert.h"
33     #include "xil_io.h"
34     #include "xil_exception.h"
35     #include "xpseudo_asm.h"
36     #include "xil_cache.h"
37     #include "xuartps.h"
38     #include "xscugic.h"
39     #include "xemacps.h" /* defines XEmacPs API */
40 
41 /*#include "netif/xpqueue.h" */
42 /*#include "xlwipconfig.h" */
43 
44     void xemacpsif_setmac( uint32_t index,
45                            uint8_t * addr );
46     uint8_t * xemacpsif_getmac( uint32_t index );
47 /*int   xemacpsif_init(struct netif *netif); */
48 /*int   xemacpsif_input(struct netif *netif); */
49     #ifdef NOTNOW_BHILL
50         unsigned get_IEEE_phy_speed( XLlTemac * xlltemacp );
51     #endif
52 
53 /* xaxiemacif_hw.c */
54     void xemacps_error_handler( XEmacPs * Temac );
55 
56     struct xBD_TYPE
57     {
58         uint32_t address;
59         uint32_t flags;
60     };
61 
62 /*
63  * Missing declaration in 'src/xemacps_hw.h' :
64  * When set, the GEM DMA will automatically
65  * discard receive packets from the receiver packet
66  * buffer memory when no AHB resource is
67  * available.
68  * When low, then received packets will remain to be
69  * stored in the SRAM based packet buffer until
70  * AHB buffer resource next becomes available.
71  */
72     #define XEMACPS_DMACR_DISC_WHEN_NO_AHB_MASK    0x01000000
73 
74     #define EMAC_IF_RX_EVENT                       1
75     #define EMAC_IF_TX_EVENT                       2
76     #define EMAC_IF_ERR_EVENT                      4
77     #define EMAC_IF_ALL_EVENT                      7
78 
79 /* structure within each netif, encapsulating all information required for
80  * using a particular temac instance
81  */
82     typedef struct
83     {
84         XEmacPs emacps;
85 
86         /* pointers to memory holding buffer descriptors (used only with SDMA) */
87         struct xBD_TYPE * rxSegments;
88         struct xBD_TYPE * txSegments;
89 
90         unsigned char * tx_space;
91         unsigned uTxUnitSize;
92 
93         char * remain_mem;
94         unsigned remain_siz;
95 
96         volatile int rxHead, rxTail;
97         volatile int txHead, txTail;
98 
99         volatile int txBusy;
100 
101         volatile uint32_t isr_events;
102 
103         unsigned int last_rx_frms_cntr;
104     } xemacpsif_s;
105 
106 /*extern xemacpsif_s xemacpsif; */
107 
108     int is_tx_space_available( xemacpsif_s * emac );
109 
110 /* xaxiemacif_dma.c */
111 
112     struct xNETWORK_BUFFER;
113 
114     int emacps_check_rx( xemacpsif_s * xemacpsif );
115     void emacps_check_tx( xemacpsif_s * xemacpsif );
116     int emacps_check_errors( xemacpsif_s * xemacps );
117     void emacps_set_rx_buffers( xemacpsif_s * xemacpsif,
118                                 u32 ulCount );
119 
120     extern XStatus emacps_send_message( xemacpsif_s * xemacpsif,
121                                         struct xNETWORK_BUFFER * pxBuffer,
122                                         int iReleaseAfterSend );
123     extern unsigned Phy_Setup( XEmacPs * xemacpsp );
124     extern void setup_isr( xemacpsif_s * xemacpsif );
125     extern XStatus init_dma( xemacpsif_s * xemacpsif );
126     extern void start_emacps( xemacpsif_s * xemacpsif );
127 
128     void EmacEnableIntr( void );
129     void EmacDisableIntr( void );
130 
131     XStatus init_axi_dma( xemacpsif_s * xemacpsif );
132     void process_sent_bds( xemacpsif_s * xemacpsif );
133 
134     void emacps_send_handler( void * arg );
135     void emacps_recv_handler( void * arg );
136     void emacps_error_handler( void * arg,
137                                u8 Direction,
138                                u32 ErrorWord );
139     void HandleTxErrors( xemacpsif_s * xemacpsif );
140     XEmacPs_Config * xemacps_lookup_config( unsigned mac_base );
141 
142     void clean_dma_txdescs( xemacpsif_s * xemacpsif );
143     void resetrx_on_no_rxdata( xemacpsif_s * xemacpsif );
144 
145     #ifdef __cplusplus
146         }
147     #endif
148 
149 #endif /* __NETIF_XAXIEMACIF_H__ */
150