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