1 #ifndef _CYGONCE_ETH_CL_CS8900_H_
2 #define _CYGONCE_ETH_CL_CS8900_H_
3 //==========================================================================
7 // Cirrus Logic CS8900 Ethernet chip
9 //==========================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 //####BSDCOPYRIGHTBEGIN####
44 // -------------------------------------------
46 // Portions of this software may have been derived from OpenBSD or other sources,
47 // and are covered by the appropriate copyright disclaimers included herein.
49 // -------------------------------------------
51 //####BSDCOPYRIGHTEND####
52 //==========================================================================
53 //#####DESCRIPTIONBEGIN####
56 // Contributors: gthomas, jskov
61 //####DESCRIPTIONEND####
63 //==========================================================================
65 #include <cyg/infra/cyg_type.h>
67 #include <cyg/hal/hal_io.h>
68 #include <pkgconf/devs_eth_cl_cs8900a.h>
71 #include CYGDAT_DEVS_ETH_CL_CS8900A_INL
74 // ------------------------------------------------------------------------
78 // 0 disables all debug output
79 // 1 for process debug output
80 // 2 for added data IO output: get_reg, put_reg
81 // 4 for packet allocation/free output
82 // 8 for only startup status, so we can tell we're installed OK
86 #define DEBUG_FUNCTION() do { diag_printf("%s\n", __FUNCTION__); } while (0)
87 #define DEBUG_LINE() do { diag_printf("%d\n", __LINE__); } while (0)
89 #define DEBUG_FUNCTION() do {} while(0)
90 #define DEBUG_LINE() do {} while(0)
93 // ------------------------------------------------------------------------
94 // Macros for keeping track of statistics
95 #if defined(ETH_DRV_GET_IF_STATS) || defined (ETH_DRV_GET_IF_STATS_UD)
96 #define KEEP_STATISTICS
99 #ifdef KEEP_STATISTICS
100 #define INCR_STAT( _x_ ) (cpd->stats. _x_ ++)
102 #define INCR_STAT( _x_ ) CYG_EMPTY_STATEMENT
105 // ------------------------------------------------------------------------
106 // Private driver structure
107 struct cs8900a_priv_data;
108 typedef cyg_bool (*provide_esa_t)(struct cs8900a_priv_data* cpd);
110 typedef struct cs8900a_priv_data {
111 bool txbusy, hardwired_esa;
114 provide_esa_t provide_esa;
115 cyg_vector_t interrupt; // Interrupt vector used by controller
116 int priority; // Priority level used by controller
117 cyg_handle_t interrupt_handle;
118 cyg_interrupt interrupt_object;
120 cyg_uint32 txkey; // Used to ack when packet sent
121 struct cyg_netdevtab_entry *tab;
123 cyg_tick_count_t txstart;
125 } cs8900a_priv_data_t;
127 // ------------------------------------------------------------------------
128 // Macros for accessing CS registers
129 // These can be overridden by the platform header
132 # define CS_IN(_b_, _o_, _d_) HAL_READ_UINT16 ((cyg_addrword_t)(_b_)+(_o_), (_d_))
133 # define CS_OUT(_b_, _o_, _d_) HAL_WRITE_UINT16((cyg_addrword_t)(_b_)+(_o_), (_d_))
136 // ------------------------------------------------------------------------
137 // Macros allowing platform to customize some of the driver details
139 #ifndef CYGHWR_CL_CS8900A_PLF_RESET
140 # define CYGHWR_CL_CS8900A_PLF_RESET(_b_) do { } while (0)
143 #ifndef CYGHWR_CL_CS8900A_PLF_POST_RESET
144 # define CYGHWR_CL_CS8900A_PLF_POST_RESET(_b_) do { } while (0)
147 #ifndef CYGHWR_CL_CS8900A_PLF_INT_CLEAR
148 # define CYGHWR_CL_CS8900A_PLF_INT_CLEAR(_cdp_)
151 #ifndef CYGHWR_CL_CS8900A_PLF_INIT
152 #define CYGHWR_CL_CS8900A_PLF_INIT(_cdp_) do { } while (0)
156 // ------------------------------------------------------------------------
157 // Directly visible registers.
158 // Platform can override stepping or layout if necessary.
160 # define CS8900A_step 2
162 #ifndef CS8900A_RTDATA
163 # define CS8900A_RTDATA (0*CS8900A_step)
164 # define CS8900A_TxCMD (2*CS8900A_step)
165 # define CS8900A_TxLEN (3*CS8900A_step)
166 # define CS8900A_ISQ (4*CS8900A_step)
167 # define CS8900A_PPTR (5*CS8900A_step)
168 # define CS8900A_PDATA (6*CS8900A_step)
171 #ifndef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
172 #define ISQ_RxEvent 0x0004
173 #define ISQ_TxEvent 0x0008
174 #define ISQ_BufEvent 0x000C
175 #define ISQ_RxMissEvent 0x0010
176 #define ISQ_TxColEvent 0x0012
177 #define ISQ_EventMask 0x003F
179 #define ISQ_RxEvent 0x0400
180 #define ISQ_TxEvent 0x0800
181 #define ISQ_BufEvent 0x0C00
182 #define ISQ_RxMissEvent 0x1000
183 #define ISQ_TxColEvent 0x1200
184 #define ISQ_EventMask 0x3F00
187 // ------------------------------------------------------------------------
188 // Registers available via "page pointer" (indirect access)
189 #ifndef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
191 #define PP_ChipID 0x0000 // Chip identifier - must be 0x630e
192 #define PP_ChipRev 0x0002 // Chip revision, model codes
193 #define PP_ChipID_CL 0x630e
195 #define PP_IntReg 0x0022 // Interrupt configuration
196 #define PP_IntReg_IRQ0 0x0000 // Use INTR0 pin
197 #define PP_IntReg_IRQ1 0x0001 // Use INTR1 pin
198 #define PP_IntReg_IRQ2 0x0002 // Use INTR2 pin
199 #define PP_IntReg_IRQ3 0x0003 // Use INTR3 pin
201 #define PP_RxCFG 0x0102 // Receiver configuration
202 #define PP_RxCFG_Skip1 0x0040 // Skip (i.e. discard) current frame
203 #define PP_RxCFG_Stream 0x0080 // Enable streaming mode
204 #define PP_RxCFG_RxOK 0x0100 // RxOK interrupt enable
205 #define PP_RxCFG_RxDMAonly 0x0200 // Use RxDMA for all frames
206 #define PP_RxCFG_AutoRxDMA 0x0400 // Select RxDMA automatically
207 #define PP_RxCFG_BufferCRC 0x0800 // Include CRC characters in frame
208 #define PP_RxCFG_CRC 0x1000 // Enable interrupt on CRC error
209 #define PP_RxCFG_RUNT 0x2000 // Enable interrupt on RUNT frames
210 #define PP_RxCFG_EXTRA 0x4000 // Enable interrupt on frames with extra data
212 #define PP_RxCTL 0x0104 // Receiver control
213 #define PP_RxCTL_IAHash 0x0040 // Accept frames that match hash
214 #define PP_RxCTL_Promiscuous 0x0080 // Accept any frame
215 #define PP_RxCTL_RxOK 0x0100 // Accept well formed frames
216 #define PP_RxCTL_Multicast 0x0200 // Accept multicast frames
217 #define PP_RxCTL_IA 0x0400 // Accept frame that matches IA
218 #define PP_RxCTL_Broadcast 0x0800 // Accept broadcast frames
219 #define PP_RxCTL_CRC 0x1000 // Accept frames with bad CRC
220 #define PP_RxCTL_RUNT 0x2000 // Accept runt frames
221 #define PP_RxCTL_EXTRA 0x4000 // Accept frames that are too long
223 #define PP_TxCFG 0x0106 // Transmit configuration
224 #define PP_TxCFG_CRS 0x0040 // Enable interrupt on loss of carrier
225 #define PP_TxCFG_SQE 0x0080 // Enable interrupt on Signal Quality Error
226 #define PP_TxCFG_TxOK 0x0100 // Enable interrupt on successful xmits
227 #define PP_TxCFG_Late 0x0200 // Enable interrupt on "out of window"
228 #define PP_TxCFG_Jabber 0x0400 // Enable interrupt on jabber detect
229 #define PP_TxCFG_Collision 0x0800 // Enable interrupt if collision
230 #define PP_TxCFG_16Collisions 0x8000 // Enable interrupt if > 16 collisions
232 #define PP_TxCmd 0x0108 // Transmit command status
233 #define PP_TxCmd_TxStart_5 0x0000 // Start after 5 bytes in buffer
234 #define PP_TxCmd_TxStart_381 0x0040 // Start after 381 bytes in buffer
235 #define PP_TxCmd_TxStart_1021 0x0080 // Start after 1021 bytes in buffer
236 #define PP_TxCmd_TxStart_Full 0x00C0 // Start after all bytes loaded
237 #define PP_TxCmd_Force 0x0100 // Discard any pending packets
238 #define PP_TxCmd_OneCollision 0x0200 // Abort after a single collision
239 #define PP_TxCmd_NoCRC 0x1000 // Do not add CRC
240 #define PP_TxCmd_NoPad 0x2000 // Do not pad short packets
242 #define PP_BufCFG 0x010A // Buffer configuration
243 #define PP_BufCFG_SWI 0x0040 // Force interrupt via software
244 #define PP_BufCFG_RxDMA 0x0080 // Enable interrupt on Rx DMA
245 #define PP_BufCFG_TxRDY 0x0100 // Enable interrupt when ready for Tx
246 #define PP_BufCFG_TxUE 0x0200 // Enable interrupt in Tx underrun
247 #define PP_BufCFG_RxMiss 0x0400 // Enable interrupt on missed Rx packets
248 #define PP_BufCFG_Rx128 0x0800 // Enable Rx interrupt after 128 bytes
249 #define PP_BufCFG_TxCol 0x1000 // Enable int on Tx collision ctr overflow
250 #define PP_BufCFG_Miss 0x2000 // Enable int on Rx miss ctr overflow
251 #define PP_BufCFG_RxDest 0x8000 // Enable int on Rx dest addr match
253 #define PP_LineCTL 0x0112 // Line control
254 #define PP_LineCTL_Rx 0x0040 // Enable receiver
255 #define PP_LineCTL_Tx 0x0080 // Enable transmitter
257 #define PP_RER 0x0124 // Receive event
258 #define PP_RER_IAHash 0x0040 // Frame hash match
259 #define PP_RER_Dribble 0x0080 // Frame had 1-7 extra bits after last byte
260 #define PP_RER_RxOK 0x0100 // Frame received with no errors
261 #define PP_RER_Hashed 0x0200 // Frame address hashed OK
262 #define PP_RER_IA 0x0400 // Frame address matched IA
263 #define PP_RER_Broadcast 0x0800 // Broadcast frame
264 #define PP_RER_CRC 0x1000 // Frame had CRC error
265 #define PP_RER_RUNT 0x2000 // Runt frame
266 #define PP_RER_EXTRA 0x4000 // Frame was too long
268 #define PP_TER 0x0128 // Transmit event
269 #define PP_TER_CRS 0x0040 // Carrier lost
270 #define PP_TER_SQE 0x0080 // Signal Quality Error
271 #define PP_TER_TxOK 0x0100 // Packet sent without error
272 #define PP_TER_Late 0x0200 // Out of window
273 #define PP_TER_Jabber 0x0400 // Stuck transmit?
274 #define PP_TER_NumCollisions 0x7800 // Number of collisions
275 #define PP_TER_16Collisions 0x8000 // > 16 collisions
277 #define PP_SelfCtl 0x0114 // Chip control
278 #define PP_SelfCtl_Reset 0x0040 // Self-clearing reset
280 #define PP_BusCtl 0x0116 // Bus control
281 #define PP_BusCtl_ResetRxDMA 0x0040 // Reset receiver DMA engine
282 #define PP_BusCtl_DMAextend 0x0100
283 #define PP_BusCtl_UseSA 0x0200
284 #define PP_BusCtl_MemoryE 0x0400 // Enable "memory mode"
285 #define PP_BusCtl_DMAburst 0x0800
286 #define PP_BusCtl_IOCH_RDYE 0x1000
287 #define PP_BusCtl_RxDMAsize 0x2000
288 #define PP_BusCtl_EnableIRQ 0x8000 // Enable interrupts
290 #define PP_LineStat 0x0134 // Line status
291 #define PP_LineStat_LinkOK 0x0080 // Line is connected and working
292 #define PP_LineStat_AUI 0x0100 // Connected via AUI
293 #define PP_LineStat_10BT 0x0200 // Connected via twisted pair
294 #define PP_LineStat_Polarity 0x1000 // Line polarity OK (10BT only)
295 #define PP_LineStat_CRS 0x4000 // Frame being received
297 #define PP_SelfStat 0x0136 // Chip status
298 #define PP_SelfStat_InitD 0x0080 // Chip initialization complete
299 #define PP_SelfStat_SIBSY 0x0100 // EEPROM is busy
300 #define PP_SelfStat_EEPROM 0x0200 // EEPROM present
301 #define PP_SelfStat_EEPROM_OK 0x0400 // EEPROM checks out
302 #define PP_SelfStat_ELPresent 0x0800 // External address latch logic available
303 #define PP_SelfStat_EEsize 0x1000 // Size of EEPROM
305 #define PP_BusStat 0x0138 // Bus status
306 #define PP_BusStat_TxBid 0x0080 // Tx error
307 #define PP_BusStat_TxRDY 0x0100 // Ready for Tx data
309 #define PP_LAF 0x0150 // Logical address filter (6 bytes)
310 #define PP_IA 0x0158 // Individual address (MAC)
314 #define PP_ChipID 0x0000 // Chip identifier - must be 0x0e63
315 #define PP_ChipRev 0x0200 // Chip revision, model codes
316 #define PP_ChipID_CL 0x0e63
318 #define PP_IntReg 0x2200 // Interrupt configuration
319 #define PP_IntReg_IRQ0 0x0000 // Use INTR0 pin
320 #define PP_IntReg_IRQ1 0x0100 // Use INTR1 pin
321 #define PP_IntReg_IRQ2 0x0200 // Use INTR2 pin
322 #define PP_IntReg_IRQ3 0x0300 // Use INTR3 pin
324 #define PP_RxCFG 0x0201 // Receiver configuration
325 #define PP_RxCFG_Skip1 0x4000 // Skip (i.e. discard) current frame
326 #define PP_RxCFG_Stream 0x8000 // Enable streaming mode
327 #define PP_RxCFG_RxOK 0x0001 // RxOK interrupt enable
328 #define PP_RxCFG_RxDMAonly 0x0002 // Use RxDMA for all frames
329 #define PP_RxCFG_AutoRxDMA 0x0004 // Select RxDMA automatically
330 #define PP_RxCFG_BufferCRC 0x0008 // Include CRC characters in frame
331 #define PP_RxCFG_CRC 0x0010 // Enable interrupt on CRC error
332 #define PP_RxCFG_RUNT 0x0020 // Enable interrupt on RUNT frames
333 #define PP_RxCFG_EXTRA 0x0040 // Enable interrupt on frames with extra data
335 #define PP_RxCTL 0x0401 // Receiver control
336 #define PP_RxCTL_IAHash 0x4000 // Accept frames that match hash
337 #define PP_RxCTL_Promiscuous 0x8000 // Accept any frame
338 #define PP_RxCTL_RxOK 0x0001 // Accept well formed frames
339 #define PP_RxCTL_Multicast 0x0002 // Accept multicast frames
340 #define PP_RxCTL_IA 0x0004 // Accept frame that matches IA
341 #define PP_RxCTL_Broadcast 0x0008 // Accept broadcast frames
342 #define PP_RxCTL_CRC 0x0010 // Accept frames with bad CRC
343 #define PP_RxCTL_RUNT 0x0020 // Accept runt frames
344 #define PP_RxCTL_EXTRA 0x0040 // Accept frames that are too long
346 #define PP_TxCFG 0x0601 // Transmit configuration
347 #define PP_TxCFG_CRS 0x4000 // Enable interrupt on loss of carrier
348 #define PP_TxCFG_SQE 0x8000 // Enable interrupt on Signal Quality Error
349 #define PP_TxCFG_TxOK 0x0001 // Enable interrupt on successful xmits
350 #define PP_TxCFG_Late 0x0002 // Enable interrupt on "out of window"
351 #define PP_TxCFG_Jabber 0x0004 // Enable interrupt on jabber detect
352 #define PP_TxCFG_Collision 0x0008 // Enable interrupt if collision
353 #define PP_TxCFG_16Collisions 0x0080 // Enable interrupt if > 16 collisions
355 #define PP_TxCmd 0x0801 // Transmit command status
356 #define PP_TxCmd_TxStart_5 0x0000 // Start after 5 bytes in buffer
357 #define PP_TxCmd_TxStart_381 0x4000 // Start after 381 bytes in buffer
358 #define PP_TxCmd_TxStart_1021 0x8000 // Start after 1021 bytes in buffer
359 #define PP_TxCmd_TxStart_Full 0xC000 // Start after all bytes loaded
360 #define PP_TxCmd_Force 0x0001 // Discard any pending packets
361 #define PP_TxCmd_OneCollision 0x0002 // Abort after a single collision
362 #define PP_TxCmd_NoCRC 0x0010 // Do not add CRC
363 #define PP_TxCmd_NoPad 0x0020 // Do not pad short packets
365 #define PP_BufCFG 0x0A01 // Buffer configuration
366 #define PP_BufCFG_SWI 0x4000 // Force interrupt via software
367 #define PP_BufCFG_RxDMA 0x8000 // Enable interrupt on Rx DMA
368 #define PP_BufCFG_TxRDY 0x0001 // Enable interrupt when ready for Tx
369 #define PP_BufCFG_TxUE 0x0002 // Enable interrupt in Tx underrun
370 #define PP_BufCFG_RxMiss 0x0004 // Enable interrupt on missed Rx packets
371 #define PP_BufCFG_Rx128 0x0008 // Enable Rx interrupt after 128 bytes
372 #define PP_BufCFG_TxCol 0x0010 // Enable int on Tx collision ctr overflow
373 #define PP_BufCFG_Miss 0x0020 // Enable int on Rx miss ctr overflow
374 #define PP_BufCFG_RxDest 0x0080 // Enable int on Rx dest addr match
376 #define PP_LineCTL 0x1201 // Line control
377 #define PP_LineCTL_Rx 0x4000 // Enable receiver
378 #define PP_LineCTL_Tx 0x8000 // Enable transmitter
380 #define PP_RER 0x2401 // Receive event
381 #define PP_RER_IAHash 0x4000 // Frame hash match
382 #define PP_RER_Dribble 0x8000 // Frame had 1-7 extra bits after last byte
383 #define PP_RER_RxOK 0x0001 // Frame received with no errors
384 #define PP_RER_Hashed 0x0002 // Frame address hashed OK
385 #define PP_RER_IA 0x0004 // Frame address matched IA
386 #define PP_RER_Broadcast 0x0008 // Broadcast frame
387 #define PP_RER_CRC 0x0010 // Frame had CRC error
388 #define PP_RER_RUNT 0x0020 // Runt frame
389 #define PP_RER_EXTRA 0x0040 // Frame was too long
391 #define PP_TER 0x2801 // Transmit event
392 #define PP_TER_CRS 0x4000 // Carrier lost
393 #define PP_TER_SQE 0x8000 // Signal Quality Error
394 #define PP_TER_TxOK 0x0001 // Packet sent without error
395 #define PP_TER_Late 0x0002 // Out of window
396 #define PP_TER_Jabber 0x0004 // Stuck transmit?
397 #define PP_TER_NumCollisions 0x0078 // Number of collisions
398 #define PP_TER_16Collisions 0x0080 // > 16 collisions
400 #define PP_SelfCtl 0x1401 // Chip control
401 #define PP_SelfCtl_Reset 0x4000 // Self-clearing reset
403 #define PP_BusCtl 0x1601 // Bus control
404 #define PP_BusCtl_ResetRxDMA 0x4000 // Reset receiver DMA engine
405 #define PP_BusCtl_DMAextend 0x0001
406 #define PP_BusCtl_UseSA 0x0002
407 #define PP_BusCtl_MemoryE 0x0004 // Enable "memory mode"
408 #define PP_BusCtl_DMAburst 0x0008
409 #define PP_BusCtl_IOCH_RDYE 0x0010
410 #define PP_BusCtl_RxDMAsize 0x0020
411 #define PP_BusCtl_EnableIRQ 0x0080 // Enable interrupts
413 #define PP_LineStat 0x3401 // Line status
414 #define PP_LineStat_LinkOK 0x8000 // Line is connected and working
415 #define PP_LineStat_AUI 0x0001 // Connected via AUI
416 #define PP_LineStat_10BT 0x0002 // Connected via twisted pair
417 #define PP_LineStat_Polarity 0x0010 // Line polarity OK (10BT only)
418 #define PP_LineStat_CRS 0x0040 // Frame being received
420 #define PP_SelfStat 0x3601 // Chip status
421 #define PP_SelfStat_InitD 0x8000 // Chip initialization complete
422 #define PP_SelfStat_SIBSY 0x0001 // EEPROM is busy
423 #define PP_SelfStat_EEPROM 0x0002 // EEPROM present
424 #define PP_SelfStat_EEPROM_OK 0x0004 // EEPROM checks out
425 #define PP_SelfStat_ELPresent 0x0008 // External address latch logic available
426 #define PP_SelfStat_EEsize 0x0010 // Size of EEPROM
428 #define PP_BusStat 0x3801 // Bus status
429 #define PP_BusStat_TxBid 0x8000 // Tx error
430 #define PP_BusStat_TxRDY 0x0001 // Ready for Tx data
432 #define PP_LAF 0x5001 // Logical address filter (6 bytes)
433 #define PP_IA 0x5801 // Individual address (MAC)
437 // ------------------------------------------------------------------------
438 // "page pointer" access functions
439 static __inline__ cyg_uint16
440 get_reg(cyg_addrword_t base, int regno)
443 HAL_WRITE_UINT16(base+CS8900A_PPTR, regno);
444 HAL_READ_UINT16(base+CS8900A_PDATA, val);
446 diag_printf("get_reg(%p, %d) => 0x%04x\n", base, regno, val);
451 static __inline__ void
452 put_reg(cyg_addrword_t base, int regno, cyg_uint16 val)
455 diag_printf("put_reg(%p, %d, 0x%04x)\n", base, regno, val);
457 HAL_WRITE_UINT16(base+CS8900A_PPTR, regno);
458 HAL_WRITE_UINT16(base+CS8900A_PDATA, val);
461 #endif // _CYGONCE_ETH_CL_CS8900_H_