1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// dev/if_fec.c
|
4 |
|
|
//
|
5 |
|
|
// Fast ethernet device driver for PowerPC MPC8260 boards
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
// Copyright (C) 2002 Gary Thomas
|
13 |
|
|
//
|
14 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
15 |
|
|
// the terms of the GNU General Public License as published by the Free
|
16 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
19 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License along
|
24 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
28 |
|
|
// or inline functions from this file, or you compile this file and link it
|
29 |
|
|
// with other works to produce a work based on this file, this file does not
|
30 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
31 |
|
|
// License. However the source code for this file must still be made available
|
32 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
33 |
|
|
//
|
34 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
35 |
|
|
// this file might be covered by the GNU General Public License.
|
36 |
|
|
//
|
37 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
38 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
39 |
|
|
// -------------------------------------------
|
40 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
41 |
|
|
//==========================================================================
|
42 |
|
|
//#####DESCRIPTIONBEGIN####
|
43 |
|
|
//
|
44 |
|
|
// Author(s): mtek
|
45 |
|
|
// Contributors: pfine
|
46 |
|
|
// Date: 2002-02-20
|
47 |
|
|
// Purpose:
|
48 |
|
|
// Description: hardware driver for MPC8260 FEC
|
49 |
|
|
//
|
50 |
|
|
//
|
51 |
|
|
//####DESCRIPTIONEND####
|
52 |
|
|
//
|
53 |
|
|
//==========================================================================
|
54 |
|
|
|
55 |
|
|
#include <pkgconf/devs_eth_powerpc_quicc2.h>
|
56 |
|
|
#include <cyg/infra/cyg_type.h>
|
57 |
|
|
#include <cyg/infra/diag.h>
|
58 |
|
|
|
59 |
|
|
#include <cyg/hal/hal_arch.h>
|
60 |
|
|
#include <cyg/hal/hal_cache.h>
|
61 |
|
|
#include <cyg/hal/hal_intr.h>
|
62 |
|
|
#include <cyg/hal/var_intr.h>
|
63 |
|
|
#include <cyg/hal/drv_api.h>
|
64 |
|
|
#include <cyg/hal/hal_if.h>
|
65 |
|
|
#include <cyg/hal/mpc8260.h>
|
66 |
|
|
|
67 |
|
|
#include <cyg/io/eth/netdev.h>
|
68 |
|
|
#include <cyg/io/eth/eth_drv.h>
|
69 |
|
|
|
70 |
|
|
#ifdef CYGPKG_NET
|
71 |
|
|
#include <pkgconf/net.h>
|
72 |
|
|
#endif
|
73 |
|
|
|
74 |
|
|
#include "fec.h"
|
75 |
|
|
#include "EnetPHY.h"
|
76 |
|
|
|
77 |
|
|
#define ALIGN_TO_CACHE_LINES(x) ( (long)((x) + 31) & 0xffffffe0 )
|
78 |
|
|
|
79 |
|
|
static unsigned char fec_eth_rxbufs[CYGNUM_DEVS_ETH_POWERPC_QUICC2_RxNUM *
|
80 |
|
|
(CYGNUM_DEVS_ETH_POWERPC_QUICC2_BUFSIZE + 32)];
|
81 |
|
|
static unsigned char fec_eth_txbufs[CYGNUM_DEVS_ETH_POWERPC_QUICC2_TxNUM *
|
82 |
|
|
(CYGNUM_DEVS_ETH_POWERPC_QUICC2_BUFSIZE + 32)];
|
83 |
|
|
|
84 |
|
|
// Buffer descriptors are in dual ported RAM, which is marked non-cached
|
85 |
|
|
#define FEC_BDs_NONCACHED
|
86 |
|
|
static struct fec_bd *const fec_eth_rxring = (struct fec_bd *)
|
87 |
|
|
(QUICC2_VADS_IMM_BASE + FEC_PRAM_RxBD_Base);
|
88 |
|
|
static struct fec_bd *const fec_eth_txring = (struct fec_bd *)
|
89 |
|
|
(QUICC2_VADS_IMM_BASE + FEC_PRAM_TxBD_Base);
|
90 |
|
|
|
91 |
|
|
static struct fec_eth_info fec_eth0_info;
|
92 |
|
|
|
93 |
|
|
static unsigned short _default_enaddr[] = {0x1234, 0x5678, 0x90a1};
|
94 |
|
|
static unsigned char enaddr[6];
|
95 |
|
|
|
96 |
|
|
#ifdef CYGPKG_REDBOOT
|
97 |
|
|
#include <pkgconf/redboot.h>
|
98 |
|
|
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
|
99 |
|
|
#include <redboot.h>
|
100 |
|
|
#include <flash_config.h>
|
101 |
|
|
RedBoot_config_option("Network hardware address [MAC]",
|
102 |
|
|
fec_esa,
|
103 |
|
|
ALWAYS_ENABLED, true,
|
104 |
|
|
CONFIG_ESA, 0
|
105 |
|
|
);
|
106 |
|
|
RedBoot_config_option("Attempt to find 100 Mbps Ethernet",
|
107 |
|
|
fec_100,
|
108 |
|
|
ALWAYS_ENABLED, true,
|
109 |
|
|
CONFIG_BOOL, 0
|
110 |
|
|
);
|
111 |
|
|
#endif
|
112 |
|
|
#endif
|
113 |
|
|
|
114 |
|
|
#define os_printf diag_printf
|
115 |
|
|
|
116 |
|
|
// CONFIG_ESA and CONFIG_BOOL are defined in redboot/include/flash_config.h
|
117 |
|
|
#ifndef CONFIG_ESA
|
118 |
|
|
#define CONFIG_ESA 6 // ethernet address length ...
|
119 |
|
|
#endif
|
120 |
|
|
|
121 |
|
|
#ifndef CONFIG_BOOL
|
122 |
|
|
#define CONFIG_BOOL 1
|
123 |
|
|
#endif
|
124 |
|
|
|
125 |
|
|
ETH_DRV_SC(fec_eth0_sc,
|
126 |
|
|
&fec_eth0_info, // Driver specific data
|
127 |
|
|
"eth0", // Name for this interface
|
128 |
|
|
fec_eth_start,
|
129 |
|
|
fec_eth_stop,
|
130 |
|
|
fec_eth_control,
|
131 |
|
|
fec_eth_can_send,
|
132 |
|
|
fec_eth_send,
|
133 |
|
|
fec_eth_recv,
|
134 |
|
|
fec_eth_deliver,
|
135 |
|
|
fec_eth_int,
|
136 |
|
|
fec_eth_int_vector);
|
137 |
|
|
|
138 |
|
|
NETDEVTAB_ENTRY(fec_netdev,
|
139 |
|
|
"fec_eth",
|
140 |
|
|
fec_eth_init,
|
141 |
|
|
&fec_eth0_sc);
|
142 |
|
|
|
143 |
|
|
#ifdef CYGPKG_NET
|
144 |
|
|
static cyg_interrupt fec_eth_interrupt;
|
145 |
|
|
static cyg_handle_t fec_eth_interrupt_handle;
|
146 |
|
|
#endif
|
147 |
|
|
static void fec_eth_int(struct eth_drv_sc *data);
|
148 |
|
|
|
149 |
|
|
#define FEC_ETH_INT CYGNUM_HAL_INTERRUPT_FCC2
|
150 |
|
|
|
151 |
|
|
// This ISR is called when the ethernet interrupt occurs
|
152 |
|
|
#ifdef CYGPKG_NET
|
153 |
|
|
static int
|
154 |
|
|
fec_eth_isr(cyg_vector_t vector, cyg_addrword_t data, HAL_SavedRegisters *regs)
|
155 |
|
|
{
|
156 |
|
|
cyg_drv_interrupt_mask(FEC_ETH_INT);
|
157 |
|
|
return (CYG_ISR_HANDLED|CYG_ISR_CALL_DSR); // Run the DSR
|
158 |
|
|
}
|
159 |
|
|
#endif
|
160 |
|
|
|
161 |
|
|
// Deliver function (ex-DSR) handles the ethernet [logical] processing
|
162 |
|
|
static void
|
163 |
|
|
fec_eth_deliver(struct eth_drv_sc * sc)
|
164 |
|
|
{
|
165 |
|
|
fec_eth_int(sc);
|
166 |
|
|
#ifdef CYGPKG_NET
|
167 |
|
|
// Clearing the event register acknowledges FCC2 interrupt ...
|
168 |
|
|
// cyg_drv_interrupt_acknowledge(FEC_ETH_INT);
|
169 |
|
|
cyg_drv_interrupt_unmask(FEC_ETH_INT);
|
170 |
|
|
#endif
|
171 |
|
|
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
// Initialize the interface - performed at system startup
|
176 |
|
|
// This function must set up the interface, including arranging to
|
177 |
|
|
// handle interrupts, etc, so that it may be "started" cheaply later.
|
178 |
|
|
static bool
|
179 |
|
|
fec_eth_init(struct cyg_netdevtab_entry *tab)
|
180 |
|
|
{
|
181 |
|
|
struct eth_drv_sc *sc = (struct eth_drv_sc *)tab->device_instance;
|
182 |
|
|
struct fec_eth_info *qi = (struct fec_eth_info *)sc->driver_private;
|
183 |
|
|
|
184 |
|
|
volatile t_PQ2IMM *IMM = (volatile t_PQ2IMM *) QUICC2_VADS_IMM_BASE;
|
185 |
|
|
volatile t_Fcc_Pram *fcc = (volatile t_Fcc_Pram *) (QUICC2_VADS_IMM_BASE + FEC_PRAM_OFFSET);
|
186 |
|
|
volatile t_EnetFcc_Pram *E_fcc = &(fcc->SpecificProtocol.e);
|
187 |
|
|
#ifdef CYGPKG_HAL_POWERPC_VADS
|
188 |
|
|
volatile t_BCSR *CSR = (t_BCSR *) 0x04500000;
|
189 |
|
|
#endif
|
190 |
|
|
|
191 |
|
|
int cache_state;
|
192 |
|
|
int i;
|
193 |
|
|
bool esa_ok;
|
194 |
|
|
bool fec_100;
|
195 |
|
|
unsigned char *c_ptr;
|
196 |
|
|
UINT16 link_speed;
|
197 |
|
|
|
198 |
|
|
// Ensure consistent state between cache and what the FEC sees
|
199 |
|
|
HAL_DCACHE_IS_ENABLED(cache_state);
|
200 |
|
|
if (cache_state) {
|
201 |
|
|
HAL_DCACHE_DISABLE();
|
202 |
|
|
HAL_DCACHE_INVALIDATE_ALL();
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
// Link the memory to the driver control memory
|
206 |
|
|
qi->fcc_reg = & (IMM->fcc_regs[FCC2]);
|
207 |
|
|
|
208 |
|
|
// just in case : disable Transmit and Receive
|
209 |
|
|
qi->fcc_reg->fcc_gfmr &= ~(FEC_GFMR_EN_Rx | FEC_GFMR_EN_Tx);
|
210 |
|
|
|
211 |
|
|
// Via BCSR, (re)start LXT970
|
212 |
|
|
#ifdef CYGPKG_HAL_POWERPC_VADS
|
213 |
|
|
EnableResetPHY(CSR);
|
214 |
|
|
#endif
|
215 |
|
|
|
216 |
|
|
// Try to read the ethernet address of the transciever ...
|
217 |
|
|
#ifdef CYGPKG_REDBOOT
|
218 |
|
|
esa_ok = flash_get_config("fec_100", &fec_100, CONFIG_BOOL);
|
219 |
|
|
#else
|
220 |
|
|
esa_ok = CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
|
221 |
|
|
"fec_100", &fec_100, CONFIG_BOOL);
|
222 |
|
|
#endif
|
223 |
|
|
|
224 |
|
|
link_speed = NOTLINKED;
|
225 |
|
|
if(esa_ok && fec_100){
|
226 |
|
|
// Via MII Management pins, tell LXT970 to initialize
|
227 |
|
|
os_printf("Attempting to acquire 100 Mbps half_duplex link ...");
|
228 |
|
|
InitEthernetPHY((VUINT32 *) &(IMM->io_regs[PORT_C].pdir),
|
229 |
|
|
(VUINT32 *) &(IMM->io_regs[PORT_C].pdat),
|
230 |
|
|
HUNDRED_HD);
|
231 |
|
|
|
232 |
|
|
link_speed = LinkTestPHY();
|
233 |
|
|
os_printf("\n");
|
234 |
|
|
if(link_speed == NOTLINKED){
|
235 |
|
|
os_printf("Failed to get 100 Mbps half_duplex link.\n");
|
236 |
|
|
}
|
237 |
|
|
}
|
238 |
|
|
if(link_speed == NOTLINKED){
|
239 |
|
|
os_printf("Attempting to acquire 10 Mbps half_duplex link ...");
|
240 |
|
|
InitEthernetPHY((VUINT32 *) &(IMM->io_regs[PORT_C].pdir),
|
241 |
|
|
(VUINT32 *) &(IMM->io_regs[PORT_C].pdat),
|
242 |
|
|
TEN_HD);
|
243 |
|
|
link_speed = LinkTestPHY();
|
244 |
|
|
os_printf("\n");
|
245 |
|
|
if(link_speed == NOTLINKED){
|
246 |
|
|
link_speed = LinkTestPHY();
|
247 |
|
|
os_printf("Failed to get 10 Mbps half_duplex link.\n");
|
248 |
|
|
}
|
249 |
|
|
|
250 |
|
|
}
|
251 |
|
|
switch ( link_speed ) {
|
252 |
|
|
|
253 |
|
|
case HUNDRED_FD:
|
254 |
|
|
os_printf("100 MB full-duplex ethernet link \n");
|
255 |
|
|
break;
|
256 |
|
|
case HUNDRED_HD:
|
257 |
|
|
os_printf("100 MB half-duplex ethernet link \n");
|
258 |
|
|
break;
|
259 |
|
|
case TEN_FD:
|
260 |
|
|
os_printf("10 MB full-duplex ethernet link \n");
|
261 |
|
|
break;
|
262 |
|
|
case TEN_HD:
|
263 |
|
|
os_printf("10 MB half-duplex ethernet link \n");
|
264 |
|
|
break;
|
265 |
|
|
default:
|
266 |
|
|
os_printf("NO ethernet link \n");
|
267 |
|
|
}
|
268 |
|
|
|
269 |
|
|
// Connect PORTC pins: (C19) to clk13, (C18) to clk 14
|
270 |
|
|
IMM->io_regs[PORT_C].ppar |= 0x00003000;
|
271 |
|
|
IMM->io_regs[PORT_C].podr &= ~(0x00003000);
|
272 |
|
|
IMM->io_regs[PORT_C].psor &= ~(0x00003000);
|
273 |
|
|
IMM->io_regs[PORT_C].pdir &= ~(0x00003000);
|
274 |
|
|
|
275 |
|
|
// Connect clk13 to RxClk and clk14 to TxClk on FCC2
|
276 |
|
|
IMM->cpm_mux_cmxfcr &= 0x7f007f00; // clear fcc2 clocks
|
277 |
|
|
IMM->cpm_mux_cmxfcr |= 0x00250000; // set fcc2 clocks (see 15-14)
|
278 |
|
|
IMM->cpm_mux_cmxuar = 0x0000; // Utopia address reg, just clear
|
279 |
|
|
|
280 |
|
|
// Initialize parallel port registers to connect FCC2 to MII
|
281 |
|
|
IMM->io_regs[PORT_B].podr &= 0xffffc000; // clear bits 18-31
|
282 |
|
|
IMM->io_regs[PORT_B].psor &= 0xffffc000;
|
283 |
|
|
IMM->io_regs[PORT_B].pdir &= 0xffffc000;
|
284 |
|
|
|
285 |
|
|
IMM->io_regs[PORT_B].psor |= 0x00000004;
|
286 |
|
|
IMM->io_regs[PORT_B].pdir |= 0x000003c5;
|
287 |
|
|
IMM->io_regs[PORT_B].ppar |= 0x00003fff;
|
288 |
|
|
|
289 |
|
|
// Initialize Receive Buffer Descriptors
|
290 |
|
|
qi->rbase = fec_eth_rxring;
|
291 |
|
|
qi->rxbd = fec_eth_rxring;
|
292 |
|
|
qi->rnext = fec_eth_rxring;
|
293 |
|
|
c_ptr = fec_eth_rxbufs;
|
294 |
|
|
|
295 |
|
|
for(i=0; i<CYGNUM_DEVS_ETH_POWERPC_QUICC2_RxNUM; i++) {
|
296 |
|
|
|
297 |
|
|
fec_eth_rxring[i].ctrl = (FEC_BD_Rx_Empty | FEC_BD_Rx_Int);
|
298 |
|
|
fec_eth_rxring[i].length = 0; // reset
|
299 |
|
|
c_ptr = (unsigned char *) ALIGN_TO_CACHE_LINES(c_ptr);
|
300 |
|
|
fec_eth_rxring[i].buffer = (volatile unsigned char *)c_ptr;
|
301 |
|
|
c_ptr += CYGNUM_DEVS_ETH_POWERPC_QUICC2_BUFSIZE;
|
302 |
|
|
}
|
303 |
|
|
|
304 |
|
|
fec_eth_rxring[CYGNUM_DEVS_ETH_POWERPC_QUICC2_RxNUM-1].ctrl |= FEC_BD_Rx_Wrap;
|
305 |
|
|
|
306 |
|
|
// Initialize Transmit Buffer Descriptors
|
307 |
|
|
qi->tbase = fec_eth_txring;
|
308 |
|
|
qi->txbd = fec_eth_txring;
|
309 |
|
|
qi->tnext = fec_eth_txring;
|
310 |
|
|
c_ptr = fec_eth_txbufs;
|
311 |
|
|
|
312 |
|
|
for(i=0; i<CYGNUM_DEVS_ETH_POWERPC_QUICC2_TxNUM; i++) {
|
313 |
|
|
|
314 |
|
|
fec_eth_txring[i].ctrl = (FEC_BD_Tx_Pad | FEC_BD_Tx_Int);
|
315 |
|
|
fec_eth_txring[i].length = 0; // reset : Write before send
|
316 |
|
|
c_ptr = (unsigned char *) ALIGN_TO_CACHE_LINES(c_ptr);
|
317 |
|
|
fec_eth_txring[i].buffer = (volatile unsigned char *)c_ptr;
|
318 |
|
|
c_ptr += CYGNUM_DEVS_ETH_POWERPC_QUICC2_BUFSIZE;
|
319 |
|
|
}
|
320 |
|
|
|
321 |
|
|
fec_eth_txring[CYGNUM_DEVS_ETH_POWERPC_QUICC2_TxNUM-1].ctrl |= FEC_BD_Tx_Wrap;
|
322 |
|
|
|
323 |
|
|
// Common FCC Parameter RAM initialization
|
324 |
|
|
fcc->riptr = FEC_PRAM_RIPTR; // in dual port RAM (see 28-11)
|
325 |
|
|
fcc->tiptr = FEC_PRAM_TIPTR; // in dual port RAM (see 28-11)
|
326 |
|
|
fcc->mrblr = FEC_PRAM_MRBLR; // ?? FROM 8101 code ...
|
327 |
|
|
fcc->rstate &= FEC_FCR_INIT;
|
328 |
|
|
fcc->rstate |= FEC_FCR_MOT_BO;
|
329 |
|
|
fcc->rbase = (long) fec_eth_rxring;
|
330 |
|
|
fcc->tstate &= FEC_FCR_INIT;
|
331 |
|
|
fcc->tstate |= FEC_FCR_MOT_BO;
|
332 |
|
|
fcc->tbase = (long) fec_eth_txring;
|
333 |
|
|
|
334 |
|
|
// Ethernet Specific FCC Parameter RAM Initialization
|
335 |
|
|
E_fcc->c_mask = FEC_PRAM_C_MASK; // (see 30-9)
|
336 |
|
|
E_fcc->c_pres = FEC_PRAM_C_PRES;
|
337 |
|
|
E_fcc->crcec = 0;
|
338 |
|
|
E_fcc->alec = 0;
|
339 |
|
|
E_fcc->disfc = 0;
|
340 |
|
|
E_fcc->ret_lim = FEC_PRAM_RETLIM;
|
341 |
|
|
E_fcc->p_per = FEC_PRAM_PER_LO;
|
342 |
|
|
E_fcc->gaddr_h = 0;
|
343 |
|
|
E_fcc->gaddr_l = 0;
|
344 |
|
|
E_fcc->tfcstat = 0;
|
345 |
|
|
E_fcc->mflr = FEC_MAX_FLR;
|
346 |
|
|
|
347 |
|
|
// Try to read the ethernet address of the transciever ...
|
348 |
|
|
#ifdef CYGPKG_REDBOOT
|
349 |
|
|
esa_ok = flash_get_config("fec_esa", enaddr, CONFIG_ESA);
|
350 |
|
|
#else
|
351 |
|
|
esa_ok = CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
|
352 |
|
|
"fec_esa", enaddr, CONFIG_ESA);
|
353 |
|
|
#endif
|
354 |
|
|
if (!esa_ok) {
|
355 |
|
|
// If can't use the default ...
|
356 |
|
|
os_printf("FEC_ETH - Warning! ESA unknown\n");
|
357 |
|
|
memcpy(enaddr, _default_enaddr, sizeof(enaddr));
|
358 |
|
|
}
|
359 |
|
|
|
360 |
|
|
E_fcc->paddr1_h = ((short)enaddr[5] << 8) | enaddr[4]; // enaddr[2];
|
361 |
|
|
E_fcc->paddr1_m = ((short)enaddr[3] << 8) | enaddr[2]; // enaddr[1];
|
362 |
|
|
E_fcc->paddr1_l = ((short)enaddr[1] << 8) | enaddr[0]; // enaddr[0];
|
363 |
|
|
|
364 |
|
|
E_fcc->iaddr_h = 0;
|
365 |
|
|
E_fcc->iaddr_l = 0;
|
366 |
|
|
E_fcc->minflr = FEC_MIN_FLR;
|
367 |
|
|
E_fcc->taddr_h = 0;
|
368 |
|
|
E_fcc->taddr_m = 0;
|
369 |
|
|
E_fcc->taddr_l = 0;
|
370 |
|
|
E_fcc->pad_ptr = FEC_PRAM_TIPTR; // No special padding char ...
|
371 |
|
|
E_fcc->cf_type = 0;
|
372 |
|
|
E_fcc->maxd1 = FEC_PRAM_MAXD;
|
373 |
|
|
E_fcc->maxd2 = FEC_PRAM_MAXD;
|
374 |
|
|
|
375 |
|
|
// FCC register initialization
|
376 |
|
|
IMM->fcc_regs[FCC2].fcc_gfmr = FEC_GFMR_INIT;
|
377 |
|
|
IMM->fcc_regs[FCC2].fcc_psmr = FEC_PSMR_INIT;
|
378 |
|
|
IMM->fcc_regs[FCC2].fcc_dsr = FEC_DSR_INIT;
|
379 |
|
|
|
380 |
|
|
#ifdef CYGPKG_NET
|
381 |
|
|
// clear the events of FCC2
|
382 |
|
|
IMM->fcc_regs[FCC2].fcc_fcce = 0xFFFF0000;
|
383 |
|
|
IMM->fcc_regs[FCC2].fcc_fccm = FEC_EV_TXE | FEC_EV_TXB | FEC_EV_RXF;
|
384 |
|
|
|
385 |
|
|
// Set up to handle interrupts
|
386 |
|
|
cyg_drv_interrupt_create(FEC_ETH_INT,
|
387 |
|
|
0, // Highest //CYGARC_SIU_PRIORITY_HIGH,
|
388 |
|
|
(cyg_addrword_t)sc, // Data passed to ISR
|
389 |
|
|
(cyg_ISR_t *)fec_eth_isr,
|
390 |
|
|
(cyg_DSR_t *)eth_drv_dsr,
|
391 |
|
|
&fec_eth_interrupt_handle,
|
392 |
|
|
&fec_eth_interrupt);
|
393 |
|
|
cyg_drv_interrupt_attach(fec_eth_interrupt_handle);
|
394 |
|
|
cyg_drv_interrupt_acknowledge(FEC_ETH_INT);
|
395 |
|
|
cyg_drv_interrupt_unmask(FEC_ETH_INT);
|
396 |
|
|
#else
|
397 |
|
|
|
398 |
|
|
// Mask the interrupts
|
399 |
|
|
IMM->fcc_regs[FCC2].fcc_fccm = 0;
|
400 |
|
|
#endif
|
401 |
|
|
|
402 |
|
|
// Issue Init RX & TX Parameters Command for FCC2
|
403 |
|
|
while ((IMM->cpm_cpcr & CPCR_FLG) != CPCR_READY_TO_RX_CMD);
|
404 |
|
|
|
405 |
|
|
IMM->cpm_cpcr = CPCR_INIT_TX_RX_PARAMS |
|
406 |
|
|
CPCR_FCC2_CH |
|
407 |
|
|
CPCR_MCN_FEC |
|
408 |
|
|
CPCR_FLG; /* ISSUE COMMAND */
|
409 |
|
|
|
410 |
|
|
while ((IMM->cpm_cpcr & CPCR_FLG) != CPCR_READY_TO_RX_CMD);
|
411 |
|
|
|
412 |
|
|
if (cache_state)
|
413 |
|
|
HAL_DCACHE_ENABLE();
|
414 |
|
|
|
415 |
|
|
// Initialize upper level driver for ecos
|
416 |
|
|
(sc->funs->eth_drv->init)(sc, (unsigned char *)&enaddr);
|
417 |
|
|
|
418 |
|
|
return true;
|
419 |
|
|
}
|
420 |
|
|
|
421 |
|
|
//
|
422 |
|
|
// This function is called to "start up" the interface. It may be called
|
423 |
|
|
// multiple times, even when the hardware is already running. It will be
|
424 |
|
|
// called whenever something "hardware oriented" changes and should leave
|
425 |
|
|
// the hardware ready to send/receive packets.
|
426 |
|
|
//
|
427 |
|
|
static void
|
428 |
|
|
fec_eth_start(struct eth_drv_sc *sc, unsigned char *enaddr, int flags)
|
429 |
|
|
{
|
430 |
|
|
struct fec_eth_info *qi = (struct fec_eth_info *)sc->driver_private;
|
431 |
|
|
|
432 |
|
|
// Enable the device :
|
433 |
|
|
// Set the ENT/ENR bits in the GFMR -- Enable Transmit/Receive
|
434 |
|
|
qi->fcc_reg->fcc_gfmr |= (FEC_GFMR_EN_Rx | FEC_GFMR_EN_Tx);
|
435 |
|
|
|
436 |
|
|
}
|
437 |
|
|
|
438 |
|
|
//
|
439 |
|
|
// This function is called to shut down the interface.
|
440 |
|
|
//
|
441 |
|
|
static void
|
442 |
|
|
fec_eth_stop(struct eth_drv_sc *sc)
|
443 |
|
|
{
|
444 |
|
|
struct fec_eth_info *qi = (struct fec_eth_info *)sc->driver_private;
|
445 |
|
|
|
446 |
|
|
// Disable the device :
|
447 |
|
|
// Clear the ENT/ENR bits in the GFMR -- Disable Transmit/Receive
|
448 |
|
|
qi->fcc_reg->fcc_gfmr &= ~(FEC_GFMR_EN_Rx | FEC_GFMR_EN_Tx);
|
449 |
|
|
}
|
450 |
|
|
|
451 |
|
|
|
452 |
|
|
//
|
453 |
|
|
// This function is called for low level "control" operations
|
454 |
|
|
//
|
455 |
|
|
static int
|
456 |
|
|
fec_eth_control(struct eth_drv_sc *sc, unsigned long key,
|
457 |
|
|
void *data, int length)
|
458 |
|
|
{
|
459 |
|
|
switch (key) {
|
460 |
|
|
case ETH_DRV_SET_MAC_ADDRESS:
|
461 |
|
|
return 0;
|
462 |
|
|
break;
|
463 |
|
|
default:
|
464 |
|
|
return 1;
|
465 |
|
|
break;
|
466 |
|
|
}
|
467 |
|
|
}
|
468 |
|
|
|
469 |
|
|
|
470 |
|
|
//
|
471 |
|
|
// This function is called to see if another packet can be sent.
|
472 |
|
|
// It should return the number of packets which can be handled.
|
473 |
|
|
// Zero should be returned if the interface is busy and can not send any more.
|
474 |
|
|
//
|
475 |
|
|
static int
|
476 |
|
|
fec_eth_can_send(struct eth_drv_sc *sc)
|
477 |
|
|
{
|
478 |
|
|
struct fec_eth_info *qi = (struct fec_eth_info *)sc->driver_private;
|
479 |
|
|
volatile struct fec_bd *txbd = qi->txbd;
|
480 |
|
|
int cache_state;
|
481 |
|
|
|
482 |
|
|
HAL_DCACHE_IS_ENABLED(cache_state);
|
483 |
|
|
#ifndef FEC_BDs_NONCACHED
|
484 |
|
|
if (cache_state) {
|
485 |
|
|
HAL_DCACHE_INVALIDATE(fec_eth_txring,
|
486 |
|
|
8*CYGNUM_DEVS_ETH_POWERPC_QUICC2_TxNUM);
|
487 |
|
|
}
|
488 |
|
|
#endif
|
489 |
|
|
|
490 |
|
|
return ((txbd->ctrl & FEC_BD_Tx_Ready) == 0);
|
491 |
|
|
}
|
492 |
|
|
|
493 |
|
|
//
|
494 |
|
|
// This routine is called to send data to the hardware.
|
495 |
|
|
static void
|
496 |
|
|
fec_eth_send(struct eth_drv_sc *sc, struct eth_drv_sg *sg_list, int sg_len,
|
497 |
|
|
int total_len, unsigned long key)
|
498 |
|
|
{
|
499 |
|
|
struct fec_eth_info *qi = (struct fec_eth_info *)sc->driver_private;
|
500 |
|
|
struct fec_bd *txbd, *txfirst;
|
501 |
|
|
volatile char *bp;
|
502 |
|
|
int i, txindex, cache_state;
|
503 |
|
|
|
504 |
|
|
HAL_DCACHE_IS_ENABLED(cache_state);
|
505 |
|
|
#ifndef FEC_BDs_NONCACHED
|
506 |
|
|
if (cache_state) {
|
507 |
|
|
HAL_DCACHE_INVALIDATE(fec_eth_txring,
|
508 |
|
|
8*CYGNUM_DEVS_ETH_POWERPC_QUICC2_TxNUM);
|
509 |
|
|
}
|
510 |
|
|
#endif
|
511 |
|
|
|
512 |
|
|
// Find a free buffer
|
513 |
|
|
txbd = txfirst = qi->txbd;
|
514 |
|
|
while (txbd->ctrl & FEC_BD_Tx_Ready) {
|
515 |
|
|
// This buffer is busy, move to next one
|
516 |
|
|
if (txbd->ctrl & FEC_BD_Tx_Wrap) {
|
517 |
|
|
txbd = qi->tbase;
|
518 |
|
|
} else {
|
519 |
|
|
txbd++;
|
520 |
|
|
}
|
521 |
|
|
if (txbd == txfirst) {
|
522 |
|
|
#ifdef CYGPKG_NET
|
523 |
|
|
panic ("No free xmit buffers");
|
524 |
|
|
#else
|
525 |
|
|
os_printf("FEC Ethernet: No free xmit buffers\n");
|
526 |
|
|
#endif
|
527 |
|
|
}
|
528 |
|
|
}
|
529 |
|
|
|
530 |
|
|
// Remember the next buffer to try
|
531 |
|
|
if (txbd->ctrl & FEC_BD_Tx_Wrap) {
|
532 |
|
|
qi->txbd = qi->tbase;
|
533 |
|
|
} else {
|
534 |
|
|
qi->txbd = txbd+1;
|
535 |
|
|
}
|
536 |
|
|
|
537 |
|
|
txindex = ((unsigned long)txbd - (unsigned long)qi->tbase) / sizeof(*txbd);
|
538 |
|
|
qi->txkey[txindex] = key;
|
539 |
|
|
|
540 |
|
|
// Set up buffer
|
541 |
|
|
txbd->length = total_len;
|
542 |
|
|
bp = txbd->buffer;
|
543 |
|
|
for (i = 0; i < sg_len; i++) {
|
544 |
|
|
memcpy((void *)bp, (void *)sg_list[i].buf, sg_list[i].len);
|
545 |
|
|
bp += sg_list[i].len;
|
546 |
|
|
}
|
547 |
|
|
|
548 |
|
|
// Make sure no stale data buffer ...
|
549 |
|
|
if (cache_state) {
|
550 |
|
|
HAL_DCACHE_FLUSH(txbd->buffer, txbd->length);
|
551 |
|
|
}
|
552 |
|
|
// Send it on it's way
|
553 |
|
|
txbd->ctrl |= FEC_BD_Tx_Ready | FEC_BD_Tx_Last | FEC_BD_Tx_TC;
|
554 |
|
|
#ifndef FEC_BDs_NONCACHED
|
555 |
|
|
if (cache_state) {
|
556 |
|
|
HAL_DCACHE_FLUSH(fec_eth_txring,
|
557 |
|
|
8*CYGNUM_DEVS_ETH_POWERPC_QUICC2_TxNUM);
|
558 |
|
|
}
|
559 |
|
|
#endif
|
560 |
|
|
|
561 |
|
|
}
|
562 |
|
|
|
563 |
|
|
//
|
564 |
|
|
// This function is called when a packet has been received. It's job is
|
565 |
|
|
// to prepare to unload the packet from the hardware. Once the length of
|
566 |
|
|
// the packet is known, the upper layer of the driver can be told. When
|
567 |
|
|
// the upper layer is ready to unload the packet, the internal function
|
568 |
|
|
// 'fec_eth_recv' will be called to actually fetch it from the hardware.
|
569 |
|
|
//
|
570 |
|
|
static void
|
571 |
|
|
fec_eth_RxEvent(struct eth_drv_sc *sc)
|
572 |
|
|
{
|
573 |
|
|
struct fec_eth_info *qi = (struct fec_eth_info *)sc->driver_private;
|
574 |
|
|
struct fec_bd *rxbd;
|
575 |
|
|
int cache_state;
|
576 |
|
|
|
577 |
|
|
HAL_DCACHE_IS_ENABLED(cache_state);
|
578 |
|
|
#ifndef FEC_BDs_NONCACHED
|
579 |
|
|
if (cache_state) {
|
580 |
|
|
HAL_DCACHE_INVALIDATE(fec_eth_rxring,
|
581 |
|
|
8*CYGNUM_DEVS_ETH_POWERPC_QUICC2_RxNUM);
|
582 |
|
|
}
|
583 |
|
|
#endif
|
584 |
|
|
|
585 |
|
|
rxbd = qi->rnext;
|
586 |
|
|
while ((rxbd->ctrl & FEC_BD_Rx_Empty) == 0) {
|
587 |
|
|
qi->rxbd = rxbd; // Save for callback
|
588 |
|
|
|
589 |
|
|
// This is the right way of doing it, but dcbi has a bug ...
|
590 |
|
|
// if (cache_state) {
|
591 |
|
|
// HAL_DCACHE_INVALIDATE(rxbd->buffer, rxbd->length);
|
592 |
|
|
// }
|
593 |
|
|
(sc->funs->eth_drv->recv)(sc, rxbd->length);
|
594 |
|
|
if (cache_state) {
|
595 |
|
|
HAL_DCACHE_FLUSH(rxbd->buffer, rxbd->length);
|
596 |
|
|
}
|
597 |
|
|
|
598 |
|
|
rxbd->ctrl |= FEC_BD_Rx_Empty;
|
599 |
|
|
if (rxbd->ctrl & FEC_BD_Rx_Wrap) {
|
600 |
|
|
rxbd = qi->rbase;
|
601 |
|
|
} else {
|
602 |
|
|
rxbd++;
|
603 |
|
|
}
|
604 |
|
|
}
|
605 |
|
|
// Remember where we left off
|
606 |
|
|
qi->rnext = (struct fec_bd *)rxbd;
|
607 |
|
|
|
608 |
|
|
// Make sure no stale data
|
609 |
|
|
#ifndef FEC_BDs_NONCACHED
|
610 |
|
|
if (cache_state) {
|
611 |
|
|
HAL_DCACHE_FLUSH(fec_eth_rxring,
|
612 |
|
|
8*CYGNUM_DEVS_ETH_POWERPC_QUICC2_RxNUM);
|
613 |
|
|
}
|
614 |
|
|
#endif
|
615 |
|
|
|
616 |
|
|
}
|
617 |
|
|
|
618 |
|
|
//
|
619 |
|
|
// This function is called as a result of the "eth_drv_recv()" call above.
|
620 |
|
|
// It's job is to actually fetch data for a packet from the hardware once
|
621 |
|
|
// memory buffers have been allocated for the packet. Note that the buffers
|
622 |
|
|
// may come in pieces, using a scatter-gather list. This allows for more
|
623 |
|
|
// efficient processing in the upper layers of the stack.
|
624 |
|
|
//
|
625 |
|
|
static void
|
626 |
|
|
fec_eth_recv(struct eth_drv_sc *sc, struct eth_drv_sg *sg_list, int sg_len)
|
627 |
|
|
{
|
628 |
|
|
struct fec_eth_info *qi = (struct fec_eth_info *)sc->driver_private;
|
629 |
|
|
unsigned char *bp;
|
630 |
|
|
int i;
|
631 |
|
|
|
632 |
|
|
bp = (unsigned char *)qi->rxbd->buffer;
|
633 |
|
|
|
634 |
|
|
for (i = 0; i < sg_len; i++) {
|
635 |
|
|
if (sg_list[i].buf != 0) {
|
636 |
|
|
memcpy((void *)sg_list[i].buf, bp, sg_list[i].len);
|
637 |
|
|
bp += sg_list[i].len;
|
638 |
|
|
}
|
639 |
|
|
}
|
640 |
|
|
|
641 |
|
|
}
|
642 |
|
|
|
643 |
|
|
static void
|
644 |
|
|
fec_eth_TxEvent(struct eth_drv_sc *sc, int stat)
|
645 |
|
|
{
|
646 |
|
|
struct fec_eth_info *qi = (struct fec_eth_info *)sc->driver_private;
|
647 |
|
|
struct fec_bd *txbd;
|
648 |
|
|
int txindex, cache_state;
|
649 |
|
|
|
650 |
|
|
// Make sure no stale data
|
651 |
|
|
HAL_DCACHE_IS_ENABLED(cache_state);
|
652 |
|
|
#ifndef FEC_BDs_NONCACHED
|
653 |
|
|
if (cache_state) {
|
654 |
|
|
HAL_DCACHE_INVALIDATE(fec_eth_txring,
|
655 |
|
|
8*CYGNUM_DEVS_ETH_POWERPC_QUICC2_TxNUM);
|
656 |
|
|
}
|
657 |
|
|
#endif
|
658 |
|
|
|
659 |
|
|
txbd = qi->tnext;
|
660 |
|
|
// Note: TC field is used to indicate the buffer has/had data in it
|
661 |
|
|
while ( (txbd->ctrl & (FEC_BD_Tx_TC | FEC_BD_Tx_Ready)) == FEC_BD_Tx_TC ) {
|
662 |
|
|
txindex = ((unsigned long)txbd - (unsigned long)qi->tbase) / sizeof(*txbd);
|
663 |
|
|
(sc->funs->eth_drv->tx_done)(sc, qi->txkey[txindex], 0);
|
664 |
|
|
txbd->ctrl &= ~FEC_BD_Tx_TC;
|
665 |
|
|
if (txbd->ctrl & FEC_BD_Tx_Wrap) {
|
666 |
|
|
txbd = qi->tbase;
|
667 |
|
|
} else {
|
668 |
|
|
txbd++;
|
669 |
|
|
}
|
670 |
|
|
}
|
671 |
|
|
// Remember where we left off
|
672 |
|
|
qi->tnext = (struct fec_bd *)txbd;
|
673 |
|
|
|
674 |
|
|
// Make sure no stale data
|
675 |
|
|
#ifndef FEC_BDs_NONCACHED
|
676 |
|
|
if (cache_state) {
|
677 |
|
|
HAL_DCACHE_FLUSH(fec_eth_txring,
|
678 |
|
|
8*CYGNUM_DEVS_ETH_POWERPC_QUICC2_TxNUM);
|
679 |
|
|
}
|
680 |
|
|
#endif
|
681 |
|
|
|
682 |
|
|
}
|
683 |
|
|
|
684 |
|
|
//
|
685 |
|
|
// Interrupt processing
|
686 |
|
|
//
|
687 |
|
|
static void
|
688 |
|
|
fec_eth_int(struct eth_drv_sc *sc)
|
689 |
|
|
{
|
690 |
|
|
struct fec_eth_info *qi = (struct fec_eth_info *)sc->driver_private;
|
691 |
|
|
unsigned long iEvent;
|
692 |
|
|
|
693 |
|
|
while ((iEvent = qi->fcc_reg->fcc_fcce) != 0){
|
694 |
|
|
|
695 |
|
|
// Writing 1's clear fcce, Writing 0's have no effect
|
696 |
|
|
qi->fcc_reg->fcc_fcce = iEvent;
|
697 |
|
|
|
698 |
|
|
// Tx Done or Tx Error
|
699 |
|
|
if ( iEvent & (FEC_EV_TXB | FEC_EV_TXE) ) {
|
700 |
|
|
fec_eth_TxEvent(sc, iEvent);
|
701 |
|
|
}
|
702 |
|
|
|
703 |
|
|
// Complete or non-complete frame receive
|
704 |
|
|
if (iEvent & (FEC_EV_RXF | FEC_EV_RXB) ) {
|
705 |
|
|
fec_eth_RxEvent(sc);
|
706 |
|
|
}
|
707 |
|
|
|
708 |
|
|
}
|
709 |
|
|
|
710 |
|
|
|
711 |
|
|
}
|
712 |
|
|
|
713 |
|
|
//
|
714 |
|
|
// Interrupt vector
|
715 |
|
|
//
|
716 |
|
|
static int
|
717 |
|
|
fec_eth_int_vector(struct eth_drv_sc *sc)
|
718 |
|
|
{
|
719 |
|
|
return (FEC_ETH_INT);
|
720 |
|
|
}
|
721 |
|
|
|