2 * Copyright (c) 2010-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.
19 #include "netif/xemacpsif.h"
22 /*** IMPORTANT: Define PEEP in xemacpsif.h and sys_arch_raw.c
23 *** to run it on a PEEP board
26 unsigned int link_speed = 100;
28 XEmacPs_Config *xemacps_lookup_config(unsigned mac_base)
30 extern XEmacPs_Config XEmacPs_ConfigTable[];
31 XEmacPs_Config *CfgPtr = NULL;
34 for (i = 0; i < XPAR_XEMACPS_NUM_INSTANCES; i++) {
35 if (XEmacPs_ConfigTable[i].BaseAddress == mac_base) {
36 CfgPtr = &XEmacPs_ConfigTable[i];
44 void init_emacps(xemacpsif_s *xemacps, struct netif *netif)
46 unsigned mac_address = (unsigned)(netif->state);
48 XEmacPs_Config *mac_config;
49 int Status = XST_SUCCESS;
51 /* obtain config of this emac */
52 mac_config = (XEmacPs_Config *)xemacps_lookup_config(mac_address);
54 /* Does not appear to be used. */
57 xemacpsp = &xemacps->emacps;
60 Status = XEmacPs_SetMacAddress(xemacpsp, (void*)(netif->hwaddr), 1);
61 if (Status != XST_SUCCESS) {
62 xil_printf("In %s:Emac Mac Address set failed...\r\n",__func__);
64 XEmacPs_SetMdioDivisor(xemacpsp, MDC_DIV_224);
65 link_speed = Phy_Setup(xemacpsp);
66 XEmacPs_SetOperatingSpeed(xemacpsp, link_speed);
67 /* Setting the operating speed of the MAC needs a delay. */
70 for (wait=0; wait < 20000; wait++);
74 void init_emacps_on_error (xemacpsif_s *xemacps, struct netif *netif)
76 unsigned mac_address = (unsigned)(netif->state);
78 XEmacPs_Config *mac_config;
79 int Status = XST_SUCCESS;
81 /* obtain config of this emac */
82 mac_config = (XEmacPs_Config *)xemacps_lookup_config(mac_address);
84 /* Does not appear to be used? */
87 xemacpsp = &xemacps->emacps;
90 Status = XEmacPs_SetMacAddress(xemacpsp, (void*)(netif->hwaddr), 1);
91 if (Status != XST_SUCCESS) {
92 xil_printf("In %s:Emac Mac Address set failed...\r\n",__func__);
95 XEmacPs_SetOperatingSpeed(xemacpsp, link_speed);
97 /* Setting the operating speed of the MAC needs a delay. */
100 for (wait=0; wait < 20000; wait++);
104 void setup_isr (struct xemac_s *xemac)
106 xemacpsif_s *xemacpsif;
108 xemacpsif = (xemacpsif_s *)(xemac->state);
112 XEmacPs_SetHandler(&xemacpsif->emacps, XEMACPS_HANDLER_DMASEND,
113 (void *) emacps_send_handler,
116 XEmacPs_SetHandler(&xemacpsif->emacps, XEMACPS_HANDLER_DMARECV,
117 (void *) emacps_recv_handler,
120 XEmacPs_SetHandler(&xemacpsif->emacps, XEMACPS_HANDLER_ERROR,
121 (void *) emacps_error_handler,
125 void start_emacps (xemacpsif_s *xemacps)
127 /* start the temac */
128 XEmacPs_Start(&xemacps->emacps);
131 void restart_emacps_transmitter (xemacpsif_s *xemacps) {
133 Reg = XEmacPs_ReadReg(xemacps->emacps.Config.BaseAddress,
134 XEMACPS_NWCTRL_OFFSET);
135 Reg = Reg & (~XEMACPS_NWCTRL_TXEN_MASK);
136 XEmacPs_WriteReg(xemacps->emacps.Config.BaseAddress,
137 XEMACPS_NWCTRL_OFFSET, Reg);
139 Reg = XEmacPs_ReadReg(xemacps->emacps.Config.BaseAddress,
140 XEMACPS_NWCTRL_OFFSET);
141 Reg = Reg | (XEMACPS_NWCTRL_TXEN_MASK);
142 XEmacPs_WriteReg(xemacps->emacps.Config.BaseAddress,
143 XEMACPS_NWCTRL_OFFSET, Reg);
146 void emacps_error_handler(void *arg,u8 Direction, u32 ErrorWord)
148 struct xemac_s *xemac;
149 xemacpsif_s *xemacpsif;
150 struct xtopology_t *xtopologyp;
152 XEmacPs_BdRing *rxring;
153 XEmacPs_BdRing *txring;
155 xemac = (struct xemac_s *)(arg);
156 xemacpsif = (xemacpsif_s *)(xemac->state);
157 rxring = &XEmacPs_GetRxRing(&xemacpsif->emacps);
158 txring = &XEmacPs_GetRxRing(&xemacpsif->emacps);
159 xtopologyp = &xtopology[xemac->topology_index];
160 xemacps = &xemacpsif->emacps;
162 /* Do not appear to be used. */
166 if (ErrorWord != 0) {
169 if (ErrorWord & XEMACPS_RXSR_HRESPNOK_MASK) {
170 LWIP_DEBUGF(NETIF_DEBUG, ("Receive DMA error\r\n"));
171 HandleEmacPsError(xemac);
173 if (ErrorWord & XEMACPS_RXSR_RXOVR_MASK) {
174 LWIP_DEBUGF(NETIF_DEBUG, ("Receive over run\r\n"));
175 emacps_recv_handler(arg);
176 setup_rx_bds(rxring);
178 if (ErrorWord & XEMACPS_RXSR_BUFFNA_MASK) {
179 LWIP_DEBUGF(NETIF_DEBUG, ("Receive buffer not available\r\n"));
180 emacps_recv_handler(arg);
181 setup_rx_bds(rxring);
185 if (ErrorWord & XEMACPS_TXSR_HRESPNOK_MASK) {
186 LWIP_DEBUGF(NETIF_DEBUG, ("Transmit DMA error\r\n"));
187 HandleEmacPsError(xemac);
189 if (ErrorWord & XEMACPS_TXSR_URUN_MASK) {
190 LWIP_DEBUGF(NETIF_DEBUG, ("Transmit under run\r\n"));
191 HandleTxErrors(xemac);
193 if (ErrorWord & XEMACPS_TXSR_BUFEXH_MASK) {
194 LWIP_DEBUGF(NETIF_DEBUG, ("Transmit buffer exhausted\r\n"));
195 HandleTxErrors(xemac);
197 if (ErrorWord & XEMACPS_TXSR_RXOVR_MASK) {
198 LWIP_DEBUGF(NETIF_DEBUG, ("Transmit retry excessed limits\r\n"));
199 HandleTxErrors(xemac);
201 if (ErrorWord & XEMACPS_TXSR_FRAMERX_MASK) {
202 LWIP_DEBUGF(NETIF_DEBUG, ("Transmit collision\r\n"));
203 process_sent_bds(txring);