1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// dev/if_cs8900a.c
|
4 |
|
|
//
|
5 |
|
|
// Device driver for Cirrus Logic CS8900A ethernet controller
|
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 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//####BSDCOPYRIGHTBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// -------------------------------------------
|
43 |
|
|
//
|
44 |
|
|
// Portions of this software may have been derived from OpenBSD or other sources,
|
45 |
|
|
// and are covered by the appropriate copyright disclaimers included herein.
|
46 |
|
|
//
|
47 |
|
|
// -------------------------------------------
|
48 |
|
|
//
|
49 |
|
|
//####BSDCOPYRIGHTEND####
|
50 |
|
|
//==========================================================================
|
51 |
|
|
//#####DESCRIPTIONBEGIN####
|
52 |
|
|
//
|
53 |
|
|
// Author(s): gthomas
|
54 |
|
|
// Contributors: gthomas, jskov
|
55 |
|
|
// Date: 2001-11-02
|
56 |
|
|
// Purpose:
|
57 |
|
|
// Description: Driver for CS8900 ethernet controller
|
58 |
|
|
//
|
59 |
|
|
// Note: Platform can define CYGSEM_DEVS_ETH_CL_CS8900A_NOINTS
|
60 |
|
|
// to get a timer thread polling instead of interupt based
|
61 |
|
|
// operation.
|
62 |
|
|
//
|
63 |
|
|
// Note: Driver will need some changes to support multiple instances
|
64 |
|
|
//
|
65 |
|
|
//####DESCRIPTIONEND####
|
66 |
|
|
//
|
67 |
|
|
//==========================================================================
|
68 |
|
|
|
69 |
|
|
#include <pkgconf/system.h>
|
70 |
|
|
#ifdef CYGPKG_KERNEL
|
71 |
|
|
#include <cyg/kernel/kapi.h>
|
72 |
|
|
#endif
|
73 |
|
|
#include <pkgconf/io_eth_drivers.h>
|
74 |
|
|
|
75 |
|
|
#include <cyg/infra/cyg_type.h>
|
76 |
|
|
#include <cyg/hal/hal_arch.h>
|
77 |
|
|
#include <cyg/hal/hal_intr.h>
|
78 |
|
|
#include <cyg/infra/diag.h>
|
79 |
|
|
#include <cyg/hal/drv_api.h>
|
80 |
|
|
#undef __ECOS
|
81 |
|
|
#define __ECOS
|
82 |
|
|
#include <cyg/io/eth/eth_drv.h>
|
83 |
|
|
#include <cyg/io/eth/netdev.h>
|
84 |
|
|
|
85 |
|
|
#include <cyg/io/cs8900.h>
|
86 |
|
|
|
87 |
|
|
#define __WANT_DEVS
|
88 |
|
|
#include CYGDAT_DEVS_ETH_CL_CS8900A_INL
|
89 |
|
|
#undef __WANT_DEVS
|
90 |
|
|
|
91 |
|
|
// NOINTS operation only relevant when the NET package is loaded
|
92 |
|
|
#if !defined(CYGPKG_NET) || !defined(CYGPKG_KERNEL)
|
93 |
|
|
# undef CYGSEM_DEVS_ETH_CL_CS8900A_NOINTS
|
94 |
|
|
#endif
|
95 |
|
|
|
96 |
|
|
#ifdef CYGSEM_DEVS_ETH_CL_CS8900A_NOINTS
|
97 |
|
|
#define STACK_SIZE CYGNUM_HAL_STACK_SIZE_MINIMUM
|
98 |
|
|
static char cs8900a_fake_int_stack[STACK_SIZE];
|
99 |
|
|
static cyg_thread cs8900a_fake_int_thread_data;
|
100 |
|
|
static cyg_handle_t cs8900a_fake_int_thread_handle;
|
101 |
|
|
static void cs8900a_fake_int(cyg_addrword_t);
|
102 |
|
|
#endif
|
103 |
|
|
|
104 |
|
|
#ifdef CYGDBG_IO_ETH_DRIVERS_DEBUG
|
105 |
|
|
extern int cyg_io_eth_net_debug;
|
106 |
|
|
#endif
|
107 |
|
|
|
108 |
|
|
static void cs8900a_poll(struct eth_drv_sc *sc);
|
109 |
|
|
#ifdef CYGINT_IO_ETH_INT_SUPPORT_REQUIRED
|
110 |
|
|
// This ISR is called when the ethernet interrupt occurs
|
111 |
|
|
static int
|
112 |
|
|
cs8900a_isr(cyg_vector_t vector, cyg_addrword_t data, HAL_SavedRegisters *regs)
|
113 |
|
|
{
|
114 |
|
|
cs8900a_priv_data_t* cpd = (cs8900a_priv_data_t *)data;
|
115 |
|
|
cyg_drv_interrupt_mask(cpd->interrupt);
|
116 |
|
|
cyg_drv_interrupt_acknowledge(cpd->interrupt);
|
117 |
|
|
return (CYG_ISR_HANDLED|CYG_ISR_CALL_DSR); // Run the DSR
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
static void
|
121 |
|
|
cs8900a_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
|
122 |
|
|
{
|
123 |
|
|
// This conditioning out is necessary because of explicit calls to this
|
124 |
|
|
// DSR - which would not ever be called in the case of a polled mode
|
125 |
|
|
// usage ie. in RedBoot.
|
126 |
|
|
#ifdef CYGINT_IO_ETH_INT_SUPPORT_REQUIRED
|
127 |
|
|
cs8900a_priv_data_t* cpd = (cs8900a_priv_data_t *)data;
|
128 |
|
|
struct cyg_netdevtab_entry *ndp = (struct cyg_netdevtab_entry *)(cpd->tab);
|
129 |
|
|
struct eth_drv_sc *sc = (struct eth_drv_sc *)(ndp->device_instance);
|
130 |
|
|
|
131 |
|
|
DEBUG_FUNCTION();
|
132 |
|
|
|
133 |
|
|
// but here, it must be a *sc:
|
134 |
|
|
eth_drv_dsr( vector, count, (cyg_addrword_t)sc );
|
135 |
|
|
#else
|
136 |
|
|
# ifndef CYGPKG_REDBOOT
|
137 |
|
|
# error Empty CS8900A ethernet DSR is compiled. Is this what you want?
|
138 |
|
|
# endif
|
139 |
|
|
#endif
|
140 |
|
|
}
|
141 |
|
|
#endif
|
142 |
|
|
|
143 |
|
|
// The deliver function (ex-DSR) handles the ethernet [logical] processing
|
144 |
|
|
static void
|
145 |
|
|
cs8900a_deliver(struct eth_drv_sc *sc)
|
146 |
|
|
{
|
147 |
|
|
cs8900a_poll(sc);
|
148 |
|
|
#ifdef CYGINT_IO_ETH_INT_SUPPORT_REQUIRED
|
149 |
|
|
{
|
150 |
|
|
cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private;
|
151 |
|
|
// Allow interrupts to happen again
|
152 |
|
|
cyg_drv_interrupt_unmask(cpd->interrupt);
|
153 |
|
|
}
|
154 |
|
|
#endif
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
static int
|
158 |
|
|
cs8900a_int_vector(struct eth_drv_sc *sc)
|
159 |
|
|
{
|
160 |
|
|
cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private;
|
161 |
|
|
return (cpd->interrupt) ? 1 : 0;
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
static bool
|
165 |
|
|
cs8900a_init(struct cyg_netdevtab_entry *tab)
|
166 |
|
|
{
|
167 |
|
|
struct eth_drv_sc *sc = (struct eth_drv_sc *)tab->device_instance;
|
168 |
|
|
cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private;
|
169 |
|
|
cyg_addrword_t base = cpd->base;
|
170 |
|
|
cyg_uint16 chip_type, chip_rev, chip_status;
|
171 |
|
|
int i;
|
172 |
|
|
long timeout = 500000;
|
173 |
|
|
cyg_bool esa_configured = false;
|
174 |
|
|
|
175 |
|
|
cpd->tab = tab;
|
176 |
|
|
|
177 |
|
|
CYGHWR_CL_CS8900A_PLF_INIT(cpd);
|
178 |
|
|
|
179 |
|
|
#ifdef CYGINT_IO_ETH_INT_SUPPORT_REQUIRED
|
180 |
|
|
// Initialize environment, setup interrupt handler
|
181 |
|
|
cyg_drv_interrupt_create(cpd->interrupt,
|
182 |
|
|
0, // Priority - what goes here?
|
183 |
|
|
(cyg_addrword_t)cpd, // Data item passed to interrupt handler
|
184 |
|
|
(cyg_ISR_t *)cs8900a_isr,
|
185 |
|
|
(cyg_DSR_t *)cs8900a_dsr,
|
186 |
|
|
&cpd->interrupt_handle,
|
187 |
|
|
&cpd->interrupt_object);
|
188 |
|
|
cyg_drv_interrupt_attach(cpd->interrupt_handle);
|
189 |
|
|
cyg_drv_interrupt_acknowledge(cpd->interrupt);
|
190 |
|
|
cyg_drv_interrupt_unmask(cpd->interrupt);
|
191 |
|
|
|
192 |
|
|
#ifdef CYGSEM_DEVS_ETH_CL_CS8900A_NOINTS
|
193 |
|
|
cyg_thread_create(1, // Priority
|
194 |
|
|
cs8900a_fake_int, // entry
|
195 |
|
|
(cyg_addrword_t)sc, // entry parameter
|
196 |
|
|
"CS8900 int", // Name
|
197 |
|
|
&cs8900a_fake_int_stack[0], // Stack
|
198 |
|
|
STACK_SIZE, // Size
|
199 |
|
|
&cs8900a_fake_int_thread_handle, // Handle
|
200 |
|
|
&cs8900a_fake_int_thread_data // Thread data structure
|
201 |
|
|
);
|
202 |
|
|
cyg_thread_resume(cs8900a_fake_int_thread_handle); // Start it
|
203 |
|
|
#endif
|
204 |
|
|
#endif
|
205 |
|
|
|
206 |
|
|
// Read controller ID - the first is a dummy read, since (on some
|
207 |
|
|
// platforms) the first access to the controller seems to skip the
|
208 |
|
|
// MSB 8 bits.
|
209 |
|
|
get_reg(base, PP_ChipID);
|
210 |
|
|
chip_type = get_reg(base, PP_ChipID);
|
211 |
|
|
chip_rev = get_reg(base, PP_ChipRev);
|
212 |
|
|
#if DEBUG & 8
|
213 |
|
|
diag_printf("CS8900A[%p] - type: 0x%04x, rev: 0x%04x\n", base, chip_type, chip_rev);
|
214 |
|
|
#endif
|
215 |
|
|
if (chip_type != 0x630e) {
|
216 |
|
|
#if DEBUG & 8
|
217 |
|
|
diag_printf("CS8900 - invalid type (0x%04x), must be 0x630e\n", chip_type);
|
218 |
|
|
#endif
|
219 |
|
|
return false;
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
CYGHWR_CL_CS8900A_PLF_RESET(base);
|
223 |
|
|
put_reg(base, PP_SelfCtl, PP_SelfCtl_Reset); // Reset chip
|
224 |
|
|
|
225 |
|
|
CYGHWR_CL_CS8900A_PLF_POST_RESET(base);
|
226 |
|
|
|
227 |
|
|
while ((get_reg(base, PP_SelfStat) & PP_SelfStat_InitD) == 0) {
|
228 |
|
|
if (--timeout <= 0) {
|
229 |
|
|
#if DEBUG & 8
|
230 |
|
|
diag_printf("CS8900 didn't reset - abort!\n");
|
231 |
|
|
#endif
|
232 |
|
|
return false;
|
233 |
|
|
}
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
chip_status = get_reg(base, PP_SelfStat);
|
237 |
|
|
#if DEBUG & 8
|
238 |
|
|
diag_printf("CS8900 - status: 0x%04x (%sEEPROM present)\n", chip_status,
|
239 |
|
|
chip_status & PP_SelfStat_EEPROM ? "" : "no ");
|
240 |
|
|
#endif
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
// Disable reception whilst finding the ESA
|
244 |
|
|
put_reg(base, PP_LineCTL, 0 );
|
245 |
|
|
// Find ESA - check possible sources in sequence and stop when
|
246 |
|
|
// one provides the ESA:
|
247 |
|
|
// RedBoot option (via provide_esa)
|
248 |
|
|
// Compile-time configuration
|
249 |
|
|
// EEPROM
|
250 |
|
|
// <fail configuration of device>
|
251 |
|
|
if (NULL != cpd->provide_esa) {
|
252 |
|
|
esa_configured = cpd->provide_esa(cpd);
|
253 |
|
|
# if DEBUG & 8
|
254 |
|
|
if (esa_configured)
|
255 |
|
|
diag_printf("Got ESA from RedBoot option\n");
|
256 |
|
|
# endif
|
257 |
|
|
}
|
258 |
|
|
if (!esa_configured && cpd->hardwired_esa) {
|
259 |
|
|
// ESA is already set in cpd->esa[]
|
260 |
|
|
esa_configured = true;
|
261 |
|
|
}
|
262 |
|
|
if (!esa_configured && (chip_status & PP_SelfStat_EEPROM)) {
|
263 |
|
|
// Get ESA from EEPROM - via the PP_IA registers
|
264 |
|
|
cyg_uint16 esa_word;
|
265 |
|
|
for (i = 0; i < sizeof(cpd->esa); i += 2) {
|
266 |
|
|
esa_word = get_reg(base, PP_IA+i);
|
267 |
|
|
cpd->esa[i] = (esa_word & 0xFF);
|
268 |
|
|
cpd->esa[i+1] = (esa_word >> 8) & 0xFF;
|
269 |
|
|
}
|
270 |
|
|
esa_configured = true;
|
271 |
|
|
}
|
272 |
|
|
if (!esa_configured) {
|
273 |
|
|
# if DEBUG & 8
|
274 |
|
|
diag_printf("CS8900 - no EEPROM, static ESA or RedBoot config option.\n");
|
275 |
|
|
# endif
|
276 |
|
|
return false;
|
277 |
|
|
}
|
278 |
|
|
|
279 |
|
|
// Tell the chip what ESA to use
|
280 |
|
|
for (i = 0; i < sizeof(cpd->esa); i += 2) {
|
281 |
|
|
put_reg(base, PP_IA+i, cpd->esa[i] | (cpd->esa[i+1] << 8));
|
282 |
|
|
}
|
283 |
|
|
// Set logical address mask
|
284 |
|
|
for (i = 0; i < 8; i += 2) {
|
285 |
|
|
put_reg(base, PP_LAF+i, 0xFFFF);
|
286 |
|
|
}
|
287 |
|
|
# if DEBUG & 8
|
288 |
|
|
diag_printf("ESA %02x:%02x:%02x:%02x:%02x:%02x\n",
|
289 |
|
|
cpd->esa[0], cpd->esa[1], cpd->esa[2],
|
290 |
|
|
cpd->esa[3], cpd->esa[4], cpd->esa[5]);
|
291 |
|
|
# endif
|
292 |
|
|
|
293 |
|
|
// Initialize upper level driver
|
294 |
|
|
(sc->funs->eth_drv->init)(sc, cpd->esa);
|
295 |
|
|
|
296 |
|
|
return true;
|
297 |
|
|
}
|
298 |
|
|
|
299 |
|
|
static void
|
300 |
|
|
cs8900a_stop(struct eth_drv_sc *sc)
|
301 |
|
|
{
|
302 |
|
|
cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private;
|
303 |
|
|
cyg_addrword_t base = cpd->base;
|
304 |
|
|
|
305 |
|
|
put_reg(base, PP_LineCTL, 0);
|
306 |
|
|
}
|
307 |
|
|
|
308 |
|
|
// This function is called to "start up" the interface. It may be called
|
309 |
|
|
// multiple times, even when the hardware is already running. It will be
|
310 |
|
|
// called whenever something "hardware oriented" changes and should leave
|
311 |
|
|
// the hardware ready to send/receive packets.
|
312 |
|
|
static void
|
313 |
|
|
cs8900a_start(struct eth_drv_sc *sc, cyg_uint8 *esa, int flags)
|
314 |
|
|
{
|
315 |
|
|
cyg_uint16 stat;
|
316 |
|
|
cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private;
|
317 |
|
|
cyg_addrword_t base = cpd->base;
|
318 |
|
|
|
319 |
|
|
put_reg(base, PP_BusCtl, PP_BusCtl_MemoryE); // Disable interrupts, memory mode
|
320 |
|
|
put_reg(base, PP_IntReg, PP_IntReg_IRQ0); // Only possibility
|
321 |
|
|
put_reg(base, PP_RxCFG, PP_RxCFG_RxOK | PP_RxCFG_CRC |
|
322 |
|
|
PP_RxCFG_RUNT | PP_RxCFG_EXTRA);
|
323 |
|
|
cpd->rxmode = PP_RxCTL_RxOK | PP_RxCTL_Broadcast | PP_RxCTL_IA;
|
324 |
|
|
put_reg(base, PP_RxCTL, cpd->rxmode);
|
325 |
|
|
put_reg(base, PP_TxCFG, PP_TxCFG_TxOK | PP_TxCFG_Collision |
|
326 |
|
|
PP_TxCFG_CRS | PP_TxCFG_SQE | PP_TxCFG_Late |
|
327 |
|
|
PP_TxCFG_Jabber | PP_TxCFG_16Collisions);
|
328 |
|
|
put_reg(base, PP_BufCFG, PP_BufCFG_TxRDY | PP_BufCFG_TxUE | PP_BufCFG_RxMiss |
|
329 |
|
|
PP_BufCFG_TxCol | PP_BufCFG_Miss | PP_BufCFG_SWI);
|
330 |
|
|
put_reg(base, PP_IntReg, PP_IntReg_IRQ0); // Only possibility
|
331 |
|
|
put_reg(base, PP_LineCTL, PP_LineCTL_Rx | PP_LineCTL_Tx);
|
332 |
|
|
// Clear Interrupt Status Queue before enabling interrupts
|
333 |
|
|
do {
|
334 |
|
|
HAL_READ_UINT16(cpd->base+CS8900A_ISQ, stat);
|
335 |
|
|
} while (stat != 0) ;
|
336 |
|
|
cpd->txbusy = false;
|
337 |
|
|
put_reg(base, PP_BusCtl, PP_BusCtl_EnableIRQ);
|
338 |
|
|
}
|
339 |
|
|
|
340 |
|
|
// This routine is called to perform special "control" opertions
|
341 |
|
|
static int
|
342 |
|
|
cs8900a_control(struct eth_drv_sc *sc, unsigned long key, void *data, int data_length)
|
343 |
|
|
{
|
344 |
|
|
cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private;
|
345 |
|
|
cyg_addrword_t base = cpd->base;
|
346 |
|
|
struct eth_drv_mc_list *mc_list = data;
|
347 |
|
|
|
348 |
|
|
switch (key) {
|
349 |
|
|
case ETH_DRV_SET_MAC_ADDRESS:
|
350 |
|
|
return 0;
|
351 |
|
|
break;
|
352 |
|
|
case ETH_DRV_SET_MC_LIST:
|
353 |
|
|
case ETH_DRV_SET_MC_ALL:
|
354 |
|
|
// Note: this code always accepts all multicast addresses if any
|
355 |
|
|
// are desired. It would be possible to accept a subset by adjusting
|
356 |
|
|
// the Logical Address Filter (LAF), but that would require scanning
|
357 |
|
|
// this list and building a suitable mask.
|
358 |
|
|
if (mc_list->len) {
|
359 |
|
|
cpd->rxmode |= PP_RxCTL_Multicast;
|
360 |
|
|
} else {
|
361 |
|
|
cpd->rxmode &= ~PP_RxCTL_Multicast;
|
362 |
|
|
}
|
363 |
|
|
put_reg(base, PP_RxCTL, cpd->rxmode); // When is it safe to do this?
|
364 |
|
|
return 0;
|
365 |
|
|
default:
|
366 |
|
|
return 1;
|
367 |
|
|
break;
|
368 |
|
|
}
|
369 |
|
|
}
|
370 |
|
|
|
371 |
|
|
// This routine is called to see if it is possible to send another packet.
|
372 |
|
|
// It will return non-zero if a transmit is possible, zero otherwise.
|
373 |
|
|
static int
|
374 |
|
|
cs8900a_can_send(struct eth_drv_sc *sc)
|
375 |
|
|
{
|
376 |
|
|
cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private;
|
377 |
|
|
cyg_addrword_t base = cpd->base;
|
378 |
|
|
cyg_uint16 stat;
|
379 |
|
|
|
380 |
|
|
stat = get_reg(base, PP_LineStat);
|
381 |
|
|
if ((stat & PP_LineStat_LinkOK) == 0) {
|
382 |
|
|
return false; // Link not connected
|
383 |
|
|
}
|
384 |
|
|
#ifdef CYGPKG_KERNEL
|
385 |
|
|
// Horrible hack!
|
386 |
|
|
if (cpd->txbusy) {
|
387 |
|
|
cyg_tick_count_t now = cyg_current_time();
|
388 |
|
|
if ((now - cpd->txstart) > 25) {
|
389 |
|
|
// 250ms is more than enough to transmit one frame
|
390 |
|
|
#if DEBUG & 1
|
391 |
|
|
diag_printf("CS8900: Tx interrupt lost\n");
|
392 |
|
|
#endif
|
393 |
|
|
cpd->txbusy = false;
|
394 |
|
|
// Free up the buffer (with error indication)
|
395 |
|
|
(sc->funs->eth_drv->tx_done)(sc, cpd->txkey, 1);
|
396 |
|
|
}
|
397 |
|
|
}
|
398 |
|
|
#endif
|
399 |
|
|
return (cpd->txbusy == false);
|
400 |
|
|
}
|
401 |
|
|
|
402 |
|
|
// This routine is called to send data to the hardware.
|
403 |
|
|
static void
|
404 |
|
|
cs8900a_send(struct eth_drv_sc *sc, struct eth_drv_sg *sg_list, int sg_len,
|
405 |
|
|
int total_len, unsigned long key)
|
406 |
|
|
{
|
407 |
|
|
cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private;
|
408 |
|
|
cyg_addrword_t base = cpd->base;
|
409 |
|
|
int i;
|
410 |
|
|
int len;
|
411 |
|
|
cyg_uint8 *data;
|
412 |
|
|
cyg_uint16 saved_data = 0, *sdata;
|
413 |
|
|
cyg_uint16 stat;
|
414 |
|
|
bool odd_byte = false;
|
415 |
|
|
|
416 |
|
|
// Mark xmitter busy
|
417 |
|
|
cpd->txbusy = true;
|
418 |
|
|
cpd->txkey = key;
|
419 |
|
|
#ifdef CYGPKG_KERNEL
|
420 |
|
|
cpd->txstart = cyg_current_time();
|
421 |
|
|
#endif
|
422 |
|
|
// Start the xmit sequence
|
423 |
|
|
|
424 |
|
|
// The hardware indicates that there are options as to when the actual
|
425 |
|
|
// packet transmission will start wrt moving of data into the transmit
|
426 |
|
|
// buffer. However, impirical results seem to indicate that if the
|
427 |
|
|
// packet is large and transmission is allowed to start before the
|
428 |
|
|
// entire packet has been pushed into the buffer, the hardware gets
|
429 |
|
|
// confused and the packet is lost, along with a "lost" Tx interrupt.
|
430 |
|
|
// This may be a case of the copy loop below being interrupted, e.g.
|
431 |
|
|
// a system timer interrupt, and the hardware getting unhappy that
|
432 |
|
|
// not all of the data was provided before the transmission should
|
433 |
|
|
// have completed (i.e. buffer underrun).
|
434 |
|
|
// For now, the solution is to not allow this overlap.
|
435 |
|
|
//HAL_WRITE_UINT16(cpd->base+CS8900A_TxCMD, PP_TxCmd_TxStart_5)
|
436 |
|
|
|
437 |
|
|
// Start only when all data sent to chip
|
438 |
|
|
HAL_WRITE_UINT16(cpd->base+CS8900A_TxCMD, PP_TxCmd_TxStart_Full);
|
439 |
|
|
|
440 |
|
|
HAL_WRITE_UINT16(cpd->base+CS8900A_TxLEN, total_len);
|
441 |
|
|
// Wait for controller ready signal
|
442 |
|
|
do {
|
443 |
|
|
stat = get_reg(base, PP_BusStat);
|
444 |
|
|
} while (!(stat & PP_BusStat_TxRDY));
|
445 |
|
|
|
446 |
|
|
// Put data into buffer
|
447 |
|
|
for (i = 0; i < sg_len; i++) {
|
448 |
|
|
data = (cyg_uint8 *)sg_list[i].buf;
|
449 |
|
|
len = sg_list[i].len;
|
450 |
|
|
|
451 |
|
|
if (len > 0) {
|
452 |
|
|
/* Finish the last word. */
|
453 |
|
|
if (odd_byte) {
|
454 |
|
|
saved_data |= ((cyg_uint16)*data++) << 8;
|
455 |
|
|
HAL_WRITE_UINT16(cpd->base+CS8900A_RTDATA, saved_data);
|
456 |
|
|
len--;
|
457 |
|
|
odd_byte = false;
|
458 |
|
|
}
|
459 |
|
|
/* Output contiguous words. */
|
460 |
|
|
sdata = (cyg_uint16 *)data;
|
461 |
|
|
while (len > 1) {
|
462 |
|
|
HAL_WRITE_UINT16(cpd->base+CS8900A_RTDATA, *sdata++);
|
463 |
|
|
len -= sizeof(cyg_uint16);
|
464 |
|
|
}
|
465 |
|
|
/* Save last byte, if necessary. */
|
466 |
|
|
if (len == 1) {
|
467 |
|
|
data = (cyg_uint8 *)sdata;
|
468 |
|
|
saved_data = (cyg_uint16)*data;
|
469 |
|
|
odd_byte = true;
|
470 |
|
|
}
|
471 |
|
|
}
|
472 |
|
|
}
|
473 |
|
|
if (odd_byte) {
|
474 |
|
|
HAL_WRITE_UINT16(cpd->base+CS8900A_RTDATA, saved_data);
|
475 |
|
|
}
|
476 |
|
|
}
|
477 |
|
|
|
478 |
|
|
// This function is called when a packet has been received. It's job is
|
479 |
|
|
// to prepare to unload the packet from the hardware. Once the length of
|
480 |
|
|
// the packet is known, the upper layer of the driver can be told. When
|
481 |
|
|
// the upper layer is ready to unload the packet, the internal function
|
482 |
|
|
// 'cs8900a_recv' will be called to actually fetch it from the hardware.
|
483 |
|
|
static void
|
484 |
|
|
cs8900a_RxEvent(struct eth_drv_sc *sc)
|
485 |
|
|
{
|
486 |
|
|
cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private;
|
487 |
|
|
cyg_addrword_t base = cpd->base;
|
488 |
|
|
cyg_uint16 stat, len;
|
489 |
|
|
|
490 |
|
|
HAL_READ_UINT16(base+CS8900A_RTDATA, stat);
|
491 |
|
|
HAL_READ_UINT16(base+CS8900A_RTDATA, len);
|
492 |
|
|
#ifdef CYGDBG_IO_ETH_DRIVERS_DEBUG
|
493 |
|
|
if (cyg_io_eth_net_debug) {
|
494 |
|
|
diag_printf("RxEvent - stat: %x, len: %d\n", stat, len);
|
495 |
|
|
}
|
496 |
|
|
#endif
|
497 |
|
|
(sc->funs->eth_drv->recv)(sc, len);
|
498 |
|
|
}
|
499 |
|
|
|
500 |
|
|
// This function is called as a result of the "eth_drv_recv()" call above.
|
501 |
|
|
// It's job is to actually fetch data for a packet from the hardware once
|
502 |
|
|
// memory buffers have been allocated for the packet. Note that the buffers
|
503 |
|
|
// may come in pieces, using a scatter-gather list. This allows for more
|
504 |
|
|
// efficient processing in the upper layers of the stack.
|
505 |
|
|
static void
|
506 |
|
|
cs8900a_recv(struct eth_drv_sc *sc, struct eth_drv_sg *sg_list, int sg_len)
|
507 |
|
|
{
|
508 |
|
|
cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private;
|
509 |
|
|
cyg_addrword_t base = cpd->base;
|
510 |
|
|
int i, mlen;
|
511 |
|
|
cyg_uint16 *data, val;
|
512 |
|
|
cyg_uint8 *cp, cval;
|
513 |
|
|
|
514 |
|
|
for (i = 0; i < sg_len; i++) {
|
515 |
|
|
data = (cyg_uint16 *)sg_list[i].buf;
|
516 |
|
|
mlen = sg_list[i].len;
|
517 |
|
|
while (mlen >= sizeof(*data)) {
|
518 |
|
|
HAL_READ_UINT16(base+CS8900A_RTDATA, val);
|
519 |
|
|
if (data) {
|
520 |
|
|
*data++ = val;
|
521 |
|
|
}
|
522 |
|
|
mlen -= sizeof(*data);
|
523 |
|
|
}
|
524 |
|
|
if (mlen) {
|
525 |
|
|
// Fetch last odd byte
|
526 |
|
|
HAL_READ_UINT16(base+CS8900A_RTDATA, cval);
|
527 |
|
|
cval &= 0xFF;
|
528 |
|
|
if ((cp = (cyg_uint8 *)data) != 0) {
|
529 |
|
|
*cp = cval;
|
530 |
|
|
}
|
531 |
|
|
}
|
532 |
|
|
}
|
533 |
|
|
}
|
534 |
|
|
|
535 |
|
|
static void
|
536 |
|
|
cs8900a_TxEvent(struct eth_drv_sc *sc, int stat)
|
537 |
|
|
{
|
538 |
|
|
cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private;
|
539 |
|
|
cyg_addrword_t base = cpd->base;
|
540 |
|
|
|
541 |
|
|
stat = get_reg(base, PP_TER);
|
542 |
|
|
#ifdef CYGDBG_IO_ETH_DRIVERS_DEBUG
|
543 |
|
|
if (cyg_io_eth_net_debug) {
|
544 |
|
|
diag_printf("Tx event: %x\n", stat);
|
545 |
|
|
}
|
546 |
|
|
#endif
|
547 |
|
|
cpd->txbusy = false;
|
548 |
|
|
(sc->funs->eth_drv->tx_done)(sc, cpd->txkey, 0);
|
549 |
|
|
}
|
550 |
|
|
|
551 |
|
|
static void
|
552 |
|
|
cs8900a_BufEvent(struct eth_drv_sc *sc, int stat)
|
553 |
|
|
{
|
554 |
|
|
if (stat & PP_BufCFG_RxMiss) {
|
555 |
|
|
}
|
556 |
|
|
if (stat & PP_BufCFG_TxUE) {
|
557 |
|
|
}
|
558 |
|
|
}
|
559 |
|
|
|
560 |
|
|
static void
|
561 |
|
|
cs8900a_poll(struct eth_drv_sc *sc)
|
562 |
|
|
{
|
563 |
|
|
cyg_uint16 event;
|
564 |
|
|
cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private;
|
565 |
|
|
cyg_addrword_t base = cpd->base;
|
566 |
|
|
|
567 |
|
|
HAL_READ_UINT16(base+CS8900A_ISQ, event);
|
568 |
|
|
while (event != 0) {
|
569 |
|
|
switch (event & ISQ_EventMask) {
|
570 |
|
|
case ISQ_RxEvent:
|
571 |
|
|
cs8900a_RxEvent(sc);
|
572 |
|
|
break;
|
573 |
|
|
case ISQ_TxEvent:
|
574 |
|
|
cs8900a_TxEvent(sc, event);
|
575 |
|
|
break;
|
576 |
|
|
case ISQ_BufEvent:
|
577 |
|
|
cs8900a_BufEvent(sc, event);
|
578 |
|
|
break;
|
579 |
|
|
case ISQ_RxMissEvent:
|
580 |
|
|
// Receive miss counter has overflowed
|
581 |
|
|
break;
|
582 |
|
|
case ISQ_TxColEvent:
|
583 |
|
|
// Transmit collision counter has overflowed
|
584 |
|
|
break;
|
585 |
|
|
default:
|
586 |
|
|
#if DEBUG & 1
|
587 |
|
|
diag_printf("%s: Unknown event: %x\n", __FUNCTION__, event);
|
588 |
|
|
#endif
|
589 |
|
|
break;
|
590 |
|
|
}
|
591 |
|
|
HAL_READ_UINT16(base+CS8900A_ISQ, event);
|
592 |
|
|
}
|
593 |
|
|
|
594 |
|
|
CYGHWR_CL_CS8900A_PLF_INT_CLEAR(cpd);
|
595 |
|
|
}
|
596 |
|
|
|
597 |
|
|
#ifdef CYGSEM_DEVS_ETH_CL_CS8900A_NOINTS
|
598 |
|
|
void
|
599 |
|
|
cs8900a_fake_int(cyg_addrword_t param)
|
600 |
|
|
{
|
601 |
|
|
struct eth_drv_sc *sc = (struct eth_drv_sc *) param;
|
602 |
|
|
int s;
|
603 |
|
|
|
604 |
|
|
#if DEBUG & 1
|
605 |
|
|
diag_printf("cs8900a_fake_int()\n");
|
606 |
|
|
#endif
|
607 |
|
|
|
608 |
|
|
while (true) {
|
609 |
|
|
cyg_thread_delay(5);
|
610 |
|
|
s = splnet();
|
611 |
|
|
cs8900a_poll(sc);
|
612 |
|
|
splx(s);
|
613 |
|
|
}
|
614 |
|
|
}
|
615 |
|
|
#endif
|