Michal Simek | 78d19a3 | 2009-09-07 09:08:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007-2009 Michal Simek |
| 3 | * (C) Copyright 2003 Xilinx Inc. |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 4 | * |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 5 | * Michal SIMEK <monstr@monstr.eu> |
| 6 | * |
Michal Simek | 78d19a3 | 2009-09-07 09:08:02 +0200 | [diff] [blame] | 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 9 | * |
Michal Simek | 78d19a3 | 2009-09-07 09:08:02 +0200 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 25 | |
| 26 | #include <common.h> |
| 27 | #include <net.h> |
| 28 | #include <config.h> |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 29 | #include <malloc.h> |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 30 | #include <asm/io.h> |
| 31 | |
| 32 | #undef DEBUG |
| 33 | |
| 34 | #define ENET_MAX_MTU PKTSIZE |
| 35 | #define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN |
| 36 | #define ENET_ADDR_LENGTH 6 |
| 37 | |
| 38 | /* EmacLite constants */ |
| 39 | #define XEL_BUFFER_OFFSET 0x0800 /* Next buffer's offset */ |
| 40 | #define XEL_TPLR_OFFSET 0x07F4 /* Tx packet length */ |
| 41 | #define XEL_TSR_OFFSET 0x07FC /* Tx status */ |
| 42 | #define XEL_RSR_OFFSET 0x17FC /* Rx status */ |
| 43 | #define XEL_RXBUFF_OFFSET 0x1000 /* Receive Buffer */ |
| 44 | |
| 45 | /* Xmit complete */ |
| 46 | #define XEL_TSR_XMIT_BUSY_MASK 0x00000001UL |
| 47 | /* Xmit interrupt enable bit */ |
| 48 | #define XEL_TSR_XMIT_IE_MASK 0x00000008UL |
| 49 | /* Buffer is active, SW bit only */ |
| 50 | #define XEL_TSR_XMIT_ACTIVE_MASK 0x80000000UL |
| 51 | /* Program the MAC address */ |
| 52 | #define XEL_TSR_PROGRAM_MASK 0x00000002UL |
| 53 | /* define for programming the MAC address into the EMAC Lite */ |
| 54 | #define XEL_TSR_PROG_MAC_ADDR (XEL_TSR_XMIT_BUSY_MASK | XEL_TSR_PROGRAM_MASK) |
| 55 | |
| 56 | /* Transmit packet length upper byte */ |
| 57 | #define XEL_TPLR_LENGTH_MASK_HI 0x0000FF00UL |
| 58 | /* Transmit packet length lower byte */ |
| 59 | #define XEL_TPLR_LENGTH_MASK_LO 0x000000FFUL |
| 60 | |
| 61 | /* Recv complete */ |
| 62 | #define XEL_RSR_RECV_DONE_MASK 0x00000001UL |
| 63 | /* Recv interrupt enable bit */ |
| 64 | #define XEL_RSR_RECV_IE_MASK 0x00000008UL |
| 65 | |
Michal Simek | 773cfa8 | 2011-08-25 12:47:56 +0200 | [diff] [blame] | 66 | struct xemaclite { |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 67 | u32 nexttxbuffertouse; /* Next TX buffer to write to */ |
| 68 | u32 nextrxbuffertouse; /* Next RX buffer to read from */ |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 69 | u32 txpp; /* TX ping pong buffer */ |
| 70 | u32 rxpp; /* RX ping pong buffer */ |
Michal Simek | 773cfa8 | 2011-08-25 12:47:56 +0200 | [diff] [blame] | 71 | }; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 72 | |
Clive Stubbings | f2a7806f | 2008-10-27 15:05:00 +0000 | [diff] [blame] | 73 | static u32 etherrxbuff[PKTSIZE_ALIGN/4]; /* Receive buffer */ |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 74 | |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 75 | static void xemaclite_alignedread (u32 *srcptr, void *destptr, u32 bytecount) |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 76 | { |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 77 | u32 i; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 78 | u32 alignbuffer; |
| 79 | u32 *to32ptr; |
| 80 | u32 *from32ptr; |
| 81 | u8 *to8ptr; |
| 82 | u8 *from8ptr; |
| 83 | |
| 84 | from32ptr = (u32 *) srcptr; |
| 85 | |
| 86 | /* Word aligned buffer, no correction needed. */ |
| 87 | to32ptr = (u32 *) destptr; |
| 88 | while (bytecount > 3) { |
| 89 | *to32ptr++ = *from32ptr++; |
| 90 | bytecount -= 4; |
| 91 | } |
| 92 | to8ptr = (u8 *) to32ptr; |
| 93 | |
| 94 | alignbuffer = *from32ptr++; |
| 95 | from8ptr = (u8 *) & alignbuffer; |
| 96 | |
| 97 | for (i = 0; i < bytecount; i++) { |
| 98 | *to8ptr++ = *from8ptr++; |
| 99 | } |
| 100 | } |
| 101 | |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 102 | static void xemaclite_alignedwrite (void *srcptr, u32 destptr, u32 bytecount) |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 103 | { |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 104 | u32 i; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 105 | u32 alignbuffer; |
| 106 | u32 *to32ptr = (u32 *) destptr; |
| 107 | u32 *from32ptr; |
| 108 | u8 *to8ptr; |
| 109 | u8 *from8ptr; |
| 110 | |
| 111 | from32ptr = (u32 *) srcptr; |
| 112 | while (bytecount > 3) { |
| 113 | |
| 114 | *to32ptr++ = *from32ptr++; |
| 115 | bytecount -= 4; |
| 116 | } |
| 117 | |
| 118 | alignbuffer = 0; |
| 119 | to8ptr = (u8 *) & alignbuffer; |
| 120 | from8ptr = (u8 *) from32ptr; |
| 121 | |
| 122 | for (i = 0; i < bytecount; i++) { |
| 123 | *to8ptr++ = *from8ptr++; |
| 124 | } |
| 125 | |
| 126 | *to32ptr++ = alignbuffer; |
| 127 | } |
| 128 | |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 129 | static void emaclite_halt(struct eth_device *dev) |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 130 | { |
| 131 | debug ("eth_halt\n"); |
| 132 | } |
| 133 | |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 134 | static int emaclite_init(struct eth_device *dev, bd_t *bis) |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 135 | { |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 136 | struct xemaclite *emaclite = dev->priv; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 137 | debug ("EmacLite Initialization Started\n"); |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 138 | |
| 139 | /* |
| 140 | * TX - TX_PING & TX_PONG initialization |
| 141 | */ |
| 142 | /* Restart PING TX */ |
Michal Simek | 8d95ddb | 2011-08-25 12:36:39 +0200 | [diff] [blame] | 143 | out_be32 (dev->iobase + XEL_TSR_OFFSET, 0); |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 144 | /* Copy MAC address */ |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 145 | xemaclite_alignedwrite (dev->enetaddr, |
Michal Simek | 8d95ddb | 2011-08-25 12:36:39 +0200 | [diff] [blame] | 146 | dev->iobase, ENET_ADDR_LENGTH); |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 147 | /* Set the length */ |
Michal Simek | 8d95ddb | 2011-08-25 12:36:39 +0200 | [diff] [blame] | 148 | out_be32 (dev->iobase + XEL_TPLR_OFFSET, ENET_ADDR_LENGTH); |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 149 | /* Update the MAC address in the EMAC Lite */ |
Michal Simek | 8d95ddb | 2011-08-25 12:36:39 +0200 | [diff] [blame] | 150 | out_be32 (dev->iobase + XEL_TSR_OFFSET, XEL_TSR_PROG_MAC_ADDR); |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 151 | /* Wait for EMAC Lite to finish with the MAC address update */ |
Michal Simek | 8d95ddb | 2011-08-25 12:36:39 +0200 | [diff] [blame] | 152 | while ((in_be32 (dev->iobase + XEL_TSR_OFFSET) & |
| 153 | XEL_TSR_PROG_MAC_ADDR) != 0) |
| 154 | ; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 155 | |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 156 | if (emaclite->txpp) { |
| 157 | /* The same operation with PONG TX */ |
| 158 | out_be32 (dev->iobase + XEL_TSR_OFFSET + XEL_BUFFER_OFFSET, 0); |
| 159 | xemaclite_alignedwrite(dev->enetaddr, dev->iobase + |
| 160 | XEL_BUFFER_OFFSET, ENET_ADDR_LENGTH); |
| 161 | out_be32 (dev->iobase + XEL_TPLR_OFFSET, ENET_ADDR_LENGTH); |
| 162 | out_be32 (dev->iobase + XEL_TSR_OFFSET + XEL_BUFFER_OFFSET, |
| 163 | XEL_TSR_PROG_MAC_ADDR); |
| 164 | while ((in_be32 (dev->iobase + XEL_TSR_OFFSET + |
| 165 | XEL_BUFFER_OFFSET) & XEL_TSR_PROG_MAC_ADDR) != 0) |
| 166 | ; |
| 167 | } |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 168 | |
| 169 | /* |
| 170 | * RX - RX_PING & RX_PONG initialization |
| 171 | */ |
| 172 | /* Write out the value to flush the RX buffer */ |
Michal Simek | 8d95ddb | 2011-08-25 12:36:39 +0200 | [diff] [blame] | 173 | out_be32 (dev->iobase + XEL_RSR_OFFSET, XEL_RSR_RECV_IE_MASK); |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 174 | |
| 175 | if (emaclite->rxpp) |
| 176 | out_be32 (dev->iobase + XEL_RSR_OFFSET + XEL_BUFFER_OFFSET, |
| 177 | XEL_RSR_RECV_IE_MASK); |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 178 | |
| 179 | debug ("EmacLite Initialization complete\n"); |
| 180 | return 0; |
| 181 | } |
| 182 | |
Michal Simek | 773cfa8 | 2011-08-25 12:47:56 +0200 | [diff] [blame] | 183 | static int xemaclite_txbufferavailable(struct eth_device *dev) |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 184 | { |
| 185 | u32 reg; |
| 186 | u32 txpingbusy; |
| 187 | u32 txpongbusy; |
Michal Simek | 773cfa8 | 2011-08-25 12:47:56 +0200 | [diff] [blame] | 188 | struct xemaclite *emaclite = dev->priv; |
| 189 | |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 190 | /* |
| 191 | * Read the other buffer register |
| 192 | * and determine if the other buffer is available |
| 193 | */ |
Michal Simek | 773cfa8 | 2011-08-25 12:47:56 +0200 | [diff] [blame] | 194 | reg = in_be32 (dev->iobase + |
| 195 | emaclite->nexttxbuffertouse + 0); |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 196 | txpingbusy = ((reg & XEL_TSR_XMIT_BUSY_MASK) == |
| 197 | XEL_TSR_XMIT_BUSY_MASK); |
| 198 | |
Michal Simek | 773cfa8 | 2011-08-25 12:47:56 +0200 | [diff] [blame] | 199 | reg = in_be32 (dev->iobase + |
| 200 | (emaclite->nexttxbuffertouse ^ XEL_TSR_OFFSET) + 0); |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 201 | txpongbusy = ((reg & XEL_TSR_XMIT_BUSY_MASK) == |
| 202 | XEL_TSR_XMIT_BUSY_MASK); |
| 203 | |
| 204 | return (!(txpingbusy && txpongbusy)); |
| 205 | } |
| 206 | |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 207 | static int emaclite_send (struct eth_device *dev, volatile void *ptr, int len) |
| 208 | { |
| 209 | u32 reg; |
| 210 | u32 baseaddress; |
Michal Simek | 773cfa8 | 2011-08-25 12:47:56 +0200 | [diff] [blame] | 211 | struct xemaclite *emaclite = dev->priv; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 212 | |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 213 | u32 maxtry = 1000; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 214 | |
| 215 | if (len > ENET_MAX_MTU) |
| 216 | len = ENET_MAX_MTU; |
| 217 | |
Michal Simek | 773cfa8 | 2011-08-25 12:47:56 +0200 | [diff] [blame] | 218 | while (!xemaclite_txbufferavailable(dev) && maxtry) { |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 219 | udelay (10); |
| 220 | maxtry--; |
| 221 | } |
| 222 | |
| 223 | if (!maxtry) { |
| 224 | printf ("Error: Timeout waiting for ethernet TX buffer\n"); |
| 225 | /* Restart PING TX */ |
Michal Simek | 8d95ddb | 2011-08-25 12:36:39 +0200 | [diff] [blame] | 226 | out_be32 (dev->iobase + XEL_TSR_OFFSET, 0); |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 227 | if (emaclite->txpp) { |
| 228 | out_be32 (dev->iobase + XEL_TSR_OFFSET + |
| 229 | XEL_BUFFER_OFFSET, 0); |
| 230 | } |
Michal Simek | 95efa79 | 2011-03-08 04:25:53 +0000 | [diff] [blame] | 231 | return -1; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /* Determine the expected TX buffer address */ |
Michal Simek | 773cfa8 | 2011-08-25 12:47:56 +0200 | [diff] [blame] | 235 | baseaddress = (dev->iobase + emaclite->nexttxbuffertouse); |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 236 | |
| 237 | /* Determine if the expected buffer address is empty */ |
| 238 | reg = in_be32 (baseaddress + XEL_TSR_OFFSET); |
| 239 | if (((reg & XEL_TSR_XMIT_BUSY_MASK) == 0) |
| 240 | && ((in_be32 ((baseaddress) + XEL_TSR_OFFSET) |
| 241 | & XEL_TSR_XMIT_ACTIVE_MASK) == 0)) { |
| 242 | |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 243 | if (emaclite->txpp) |
| 244 | emaclite->nexttxbuffertouse ^= XEL_BUFFER_OFFSET; |
| 245 | |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 246 | debug ("Send packet from 0x%x\n", baseaddress); |
| 247 | /* Write the frame to the buffer */ |
| 248 | xemaclite_alignedwrite ((void *) ptr, baseaddress, len); |
| 249 | out_be32 (baseaddress + XEL_TPLR_OFFSET,(len & |
| 250 | (XEL_TPLR_LENGTH_MASK_HI | XEL_TPLR_LENGTH_MASK_LO))); |
| 251 | reg = in_be32 (baseaddress + XEL_TSR_OFFSET); |
| 252 | reg |= XEL_TSR_XMIT_BUSY_MASK; |
| 253 | if ((reg & XEL_TSR_XMIT_IE_MASK) != 0) { |
| 254 | reg |= XEL_TSR_XMIT_ACTIVE_MASK; |
| 255 | } |
| 256 | out_be32 (baseaddress + XEL_TSR_OFFSET, reg); |
Michal Simek | 95efa79 | 2011-03-08 04:25:53 +0000 | [diff] [blame] | 257 | return 0; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 258 | } |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 259 | |
| 260 | if (emaclite->txpp) { |
| 261 | /* Switch to second buffer */ |
| 262 | baseaddress ^= XEL_BUFFER_OFFSET; |
| 263 | /* Determine if the expected buffer address is empty */ |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 264 | reg = in_be32 (baseaddress + XEL_TSR_OFFSET); |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 265 | if (((reg & XEL_TSR_XMIT_BUSY_MASK) == 0) |
| 266 | && ((in_be32 ((baseaddress) + XEL_TSR_OFFSET) |
| 267 | & XEL_TSR_XMIT_ACTIVE_MASK) == 0)) { |
| 268 | debug("Send packet from 0x%x\n", baseaddress); |
| 269 | /* Write the frame to the buffer */ |
| 270 | xemaclite_alignedwrite((void *) ptr, baseaddress, len); |
| 271 | out_be32 (baseaddress + XEL_TPLR_OFFSET, (len & |
| 272 | (XEL_TPLR_LENGTH_MASK_HI | |
| 273 | XEL_TPLR_LENGTH_MASK_LO))); |
| 274 | reg = in_be32 (baseaddress + XEL_TSR_OFFSET); |
| 275 | reg |= XEL_TSR_XMIT_BUSY_MASK; |
| 276 | if ((reg & XEL_TSR_XMIT_IE_MASK) != 0) |
| 277 | reg |= XEL_TSR_XMIT_ACTIVE_MASK; |
| 278 | out_be32 (baseaddress + XEL_TSR_OFFSET, reg); |
| 279 | return 0; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 280 | } |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 281 | } |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 282 | |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 283 | puts ("Error while sending frame\n"); |
Michal Simek | 95efa79 | 2011-03-08 04:25:53 +0000 | [diff] [blame] | 284 | return -1; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 287 | static int emaclite_recv(struct eth_device *dev) |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 288 | { |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 289 | u32 length; |
| 290 | u32 reg; |
| 291 | u32 baseaddress; |
Michal Simek | 773cfa8 | 2011-08-25 12:47:56 +0200 | [diff] [blame] | 292 | struct xemaclite *emaclite = dev->priv; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 293 | |
Michal Simek | 773cfa8 | 2011-08-25 12:47:56 +0200 | [diff] [blame] | 294 | baseaddress = dev->iobase + emaclite->nextrxbuffertouse; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 295 | reg = in_be32 (baseaddress + XEL_RSR_OFFSET); |
| 296 | debug ("Testing data at address 0x%x\n", baseaddress); |
| 297 | if ((reg & XEL_RSR_RECV_DONE_MASK) == XEL_RSR_RECV_DONE_MASK) { |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 298 | if (emaclite->rxpp) |
| 299 | emaclite->nextrxbuffertouse ^= XEL_BUFFER_OFFSET; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 300 | } else { |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 301 | |
| 302 | if (!emaclite->rxpp) { |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 303 | debug ("No data was available - address 0x%x\n", |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 304 | baseaddress); |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 305 | return 0; |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 306 | } else { |
| 307 | baseaddress ^= XEL_BUFFER_OFFSET; |
| 308 | reg = in_be32 (baseaddress + XEL_RSR_OFFSET); |
| 309 | if ((reg & XEL_RSR_RECV_DONE_MASK) != |
| 310 | XEL_RSR_RECV_DONE_MASK) { |
| 311 | debug("No data was available - address 0x%x\n", |
| 312 | baseaddress); |
| 313 | return 0; |
| 314 | } |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 315 | } |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 316 | } |
| 317 | /* Get the length of the frame that arrived */ |
Michal Simek | 3f91ec0 | 2010-10-11 11:41:46 +1000 | [diff] [blame] | 318 | switch(((ntohl(in_be32 (baseaddress + XEL_RXBUFF_OFFSET + 0xC))) & |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 319 | 0xFFFF0000 ) >> 16) { |
| 320 | case 0x806: |
| 321 | length = 42 + 20; /* FIXME size of ARP */ |
| 322 | debug ("ARP Packet\n"); |
| 323 | break; |
| 324 | case 0x800: |
| 325 | length = 14 + 14 + |
Michal Simek | 3f91ec0 | 2010-10-11 11:41:46 +1000 | [diff] [blame] | 326 | (((ntohl(in_be32 (baseaddress + XEL_RXBUFF_OFFSET + 0x10))) & |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 327 | 0xFFFF0000) >> 16); /* FIXME size of IP packet */ |
| 328 | debug ("IP Packet\n"); |
| 329 | break; |
| 330 | default: |
| 331 | debug ("Other Packet\n"); |
| 332 | length = ENET_MAX_MTU; |
| 333 | break; |
| 334 | } |
| 335 | |
| 336 | xemaclite_alignedread ((u32 *) (baseaddress + XEL_RXBUFF_OFFSET), |
| 337 | etherrxbuff, length); |
| 338 | |
| 339 | /* Acknowledge the frame */ |
| 340 | reg = in_be32 (baseaddress + XEL_RSR_OFFSET); |
| 341 | reg &= ~XEL_RSR_RECV_DONE_MASK; |
| 342 | out_be32 (baseaddress + XEL_RSR_OFFSET, reg); |
| 343 | |
| 344 | debug ("Packet receive from 0x%x, length %dB\n", baseaddress, length); |
| 345 | NetReceive ((uchar *) etherrxbuff, length); |
Michal Simek | 95efa79 | 2011-03-08 04:25:53 +0000 | [diff] [blame] | 346 | return length; |
Michal Simek | 89c5389 | 2008-03-28 12:41:56 +0100 | [diff] [blame] | 347 | |
| 348 | } |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 349 | |
| 350 | int xilinx_emaclite_initialize (bd_t *bis, int base_addr) |
| 351 | { |
| 352 | struct eth_device *dev; |
Michal Simek | 773cfa8 | 2011-08-25 12:47:56 +0200 | [diff] [blame] | 353 | struct xemaclite *emaclite; |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 354 | |
Michal Simek | 28ae02e | 2011-08-25 12:28:47 +0200 | [diff] [blame] | 355 | dev = calloc(1, sizeof(*dev)); |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 356 | if (dev == NULL) |
Michal Simek | 95efa79 | 2011-03-08 04:25:53 +0000 | [diff] [blame] | 357 | return -1; |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 358 | |
Michal Simek | 773cfa8 | 2011-08-25 12:47:56 +0200 | [diff] [blame] | 359 | emaclite = calloc(1, sizeof(struct xemaclite)); |
| 360 | if (emaclite == NULL) { |
| 361 | free(dev); |
| 362 | return -1; |
| 363 | } |
| 364 | |
| 365 | dev->priv = emaclite; |
| 366 | |
Michal Simek | 947324b | 2011-09-12 21:10:01 +0000 | [diff] [blame^] | 367 | #ifdef CONFIG_XILINX_EMACLITE_TX_PING_PONG |
| 368 | emaclite->txpp = 1; |
| 369 | #endif |
| 370 | #ifdef CONFIG_XILINX_EMACLITE_RX_PING_PONG |
| 371 | emaclite->rxpp = 1; |
| 372 | #endif |
| 373 | |
Michal Simek | 25a0255 | 2011-08-25 12:25:14 +0200 | [diff] [blame] | 374 | sprintf(dev->name, "Xelite.%x", base_addr); |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 375 | |
| 376 | dev->iobase = base_addr; |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 377 | dev->init = emaclite_init; |
| 378 | dev->halt = emaclite_halt; |
| 379 | dev->send = emaclite_send; |
| 380 | dev->recv = emaclite_recv; |
| 381 | |
| 382 | eth_register(dev); |
| 383 | |
Michal Simek | 95efa79 | 2011-03-08 04:25:53 +0000 | [diff] [blame] | 384 | return 1; |
Michal Simek | 042272a | 2010-10-11 11:41:47 +1000 | [diff] [blame] | 385 | } |