1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Xilinx xps_ll_temac ethernet driver for u-boot
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * FIFO sub-controller
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 2011 - 2012 Stephan Linz <linz@li-pro.net>
7*4882a593Smuzhiyun * Copyright (C) 2008 - 2011 Michal Simek <monstr@monstr.eu>
8*4882a593Smuzhiyun * Copyright (C) 2008 - 2011 PetaLogix
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * Based on Yoshio Kashiwagi kashiwagi@co-nss.co.jp driver
11*4882a593Smuzhiyun * Copyright (C) 2008 Nissin Systems Co.,Ltd.
12*4882a593Smuzhiyun * March 2008 created
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * CREDITS: tsec driver
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+
17*4882a593Smuzhiyun *
18*4882a593Smuzhiyun * [0]: http://www.xilinx.com/support/documentation
19*4882a593Smuzhiyun *
20*4882a593Smuzhiyun * [F]: [0]/ip_documentation/xps_ll_fifo.pdf
21*4882a593Smuzhiyun * [S]: [0]/ip_documentation/xps_ll_temac.pdf
22*4882a593Smuzhiyun * [A]: [0]/application_notes/xapp1041.pdf
23*4882a593Smuzhiyun */
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun #include <config.h>
26*4882a593Smuzhiyun #include <common.h>
27*4882a593Smuzhiyun #include <net.h>
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun #include <asm/types.h>
30*4882a593Smuzhiyun #include <asm/io.h>
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #include "xilinx_ll_temac.h"
33*4882a593Smuzhiyun #include "xilinx_ll_temac_fifo.h"
34*4882a593Smuzhiyun
ll_temac_reset_fifo(struct eth_device * dev)35*4882a593Smuzhiyun int ll_temac_reset_fifo(struct eth_device *dev)
36*4882a593Smuzhiyun {
37*4882a593Smuzhiyun struct ll_temac *ll_temac = dev->priv;
38*4882a593Smuzhiyun struct fifo_ctrl *fifo_ctrl = (void *)ll_temac->ctrladdr;
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun out_be32(&fifo_ctrl->tdfr, LL_FIFO_TDFR_KEY);
41*4882a593Smuzhiyun out_be32(&fifo_ctrl->rdfr, LL_FIFO_RDFR_KEY);
42*4882a593Smuzhiyun out_be32(&fifo_ctrl->isr, ~0UL);
43*4882a593Smuzhiyun out_be32(&fifo_ctrl->ier, 0);
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun return 0;
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun
ll_temac_recv_fifo(struct eth_device * dev)48*4882a593Smuzhiyun int ll_temac_recv_fifo(struct eth_device *dev)
49*4882a593Smuzhiyun {
50*4882a593Smuzhiyun int i, length = 0;
51*4882a593Smuzhiyun u32 *buf = (u32 *)net_rx_packets[0];
52*4882a593Smuzhiyun struct ll_temac *ll_temac = dev->priv;
53*4882a593Smuzhiyun struct fifo_ctrl *fifo_ctrl = (void *)ll_temac->ctrladdr;
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun if (in_be32(&fifo_ctrl->isr) & LL_FIFO_ISR_RC) {
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun /* reset isr */
58*4882a593Smuzhiyun out_be32(&fifo_ctrl->isr, ~0UL);
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun /*
61*4882a593Smuzhiyun * MAYBE here:
62*4882a593Smuzhiyun * while (fifo_ctrl->isr);
63*4882a593Smuzhiyun */
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun /*
66*4882a593Smuzhiyun * The length is written (into RLR) by the XPS LL FIFO
67*4882a593Smuzhiyun * when the packet is received across the RX LocalLink
68*4882a593Smuzhiyun * interface and the receive data FIFO had enough
69*4882a593Smuzhiyun * locations that all of the packet data has been saved.
70*4882a593Smuzhiyun * The RLR should only be read when a receive packet is
71*4882a593Smuzhiyun * available for processing (the receive occupancy is
72*4882a593Smuzhiyun * not zero). Once the RLR is read, the receive packet
73*4882a593Smuzhiyun * data should be read from the receive data FIFO before
74*4882a593Smuzhiyun * the RLR is read again.
75*4882a593Smuzhiyun *
76*4882a593Smuzhiyun * [F] page 17, Receive Length Register (RLR)
77*4882a593Smuzhiyun */
78*4882a593Smuzhiyun if (in_be32(&fifo_ctrl->rdfo) & LL_FIFO_RDFO_MASK) {
79*4882a593Smuzhiyun length = in_be32(&fifo_ctrl->rlf) & LL_FIFO_RLF_MASK;
80*4882a593Smuzhiyun } else {
81*4882a593Smuzhiyun printf("%s: Got error, no receive occupancy\n",
82*4882a593Smuzhiyun __func__);
83*4882a593Smuzhiyun return -1;
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun if (length > PKTSIZE_ALIGN) {
87*4882a593Smuzhiyun printf("%s: Got error, receive package too big (%i)\n",
88*4882a593Smuzhiyun __func__, length);
89*4882a593Smuzhiyun ll_temac_reset_fifo(dev);
90*4882a593Smuzhiyun return -1;
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun for (i = 0; i < length; i += 4)
94*4882a593Smuzhiyun *buf++ = in_be32(&fifo_ctrl->rdfd);
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun net_process_received_packet(net_rx_packets[0], length);
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun return 0;
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun
ll_temac_send_fifo(struct eth_device * dev,void * packet,int length)102*4882a593Smuzhiyun int ll_temac_send_fifo(struct eth_device *dev, void *packet, int length)
103*4882a593Smuzhiyun {
104*4882a593Smuzhiyun int i;
105*4882a593Smuzhiyun u32 *buf = (u32 *)packet;
106*4882a593Smuzhiyun struct ll_temac *ll_temac = dev->priv;
107*4882a593Smuzhiyun struct fifo_ctrl *fifo_ctrl = (void *)ll_temac->ctrladdr;
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun if (length < LL_FIFO_TLF_MIN) {
110*4882a593Smuzhiyun printf("%s: Got error, transmit package too small (%i)\n",
111*4882a593Smuzhiyun __func__, length);
112*4882a593Smuzhiyun return -1;
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun if (length > LL_FIFO_TLF_MAX) {
116*4882a593Smuzhiyun printf("%s: Got error, transmit package too big (%i)\n",
117*4882a593Smuzhiyun __func__, length);
118*4882a593Smuzhiyun return -1;
119*4882a593Smuzhiyun }
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun for (i = 0; i < length; i += 4)
122*4882a593Smuzhiyun out_be32(&fifo_ctrl->tdfd, *buf++);
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun /*
125*4882a593Smuzhiyun * Once the packet length is written to the TLR it is
126*4882a593Smuzhiyun * automatically moved to the transmit data FIFO with
127*4882a593Smuzhiyun * the packet data freeing up the TLR for another value.
128*4882a593Smuzhiyun * The packet length must be written to the TLR after
129*4882a593Smuzhiyun * the packet data is written to the transmit data FIFO.
130*4882a593Smuzhiyun * It is not valid to write data for multiple packets
131*4882a593Smuzhiyun * to the transmit data FIFO before writing the packet
132*4882a593Smuzhiyun * length values.
133*4882a593Smuzhiyun *
134*4882a593Smuzhiyun * [F] page 17, Transmit Length Register (TLR)
135*4882a593Smuzhiyun */
136*4882a593Smuzhiyun out_be32(&fifo_ctrl->tlf, length);
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun return 0;
139*4882a593Smuzhiyun }
140