| 
									
										
										
										
											2014-02-05 14:59:28 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * QEMU Freescale eTSEC Emulator | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2011-2013 AdaCore | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  |  * in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  |  * furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The above copyright notice and this permission notice shall be included in | 
					
						
							|  |  |  |  * all copies or substantial portions of the Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | 
					
						
							|  |  |  |  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
					
						
							|  |  |  |  * THE SOFTWARE. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-29 13:47:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifndef ETSEC_H
 | 
					
						
							|  |  |  | #define ETSEC_H
 | 
					
						
							| 
									
										
										
										
											2014-02-05 14:59:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "hw/sysbus.h"
 | 
					
						
							|  |  |  | #include "net/net.h"
 | 
					
						
							|  |  |  | #include "hw/ptimer.h"
 | 
					
						
							| 
									
										
										
										
											2020-09-03 16:43:22 -04:00
										 |  |  | #include "qom/object.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-05 14:59:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Buffer Descriptors */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct eTSEC_rxtx_bd { | 
					
						
							|  |  |  |     uint16_t flags; | 
					
						
							|  |  |  |     uint16_t length; | 
					
						
							|  |  |  |     uint32_t bufptr; | 
					
						
							|  |  |  | } eTSEC_rxtx_bd; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define BD_WRAP       (1 << 13)
 | 
					
						
							|  |  |  | #define BD_INTERRUPT  (1 << 12)
 | 
					
						
							|  |  |  | #define BD_LAST       (1 << 11)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define BD_TX_READY     (1 << 15)
 | 
					
						
							|  |  |  | #define BD_TX_PADCRC    (1 << 14)
 | 
					
						
							|  |  |  | #define BD_TX_TC        (1 << 10)
 | 
					
						
							|  |  |  | #define BD_TX_PREDEF    (1 << 9)
 | 
					
						
							|  |  |  | #define BD_TX_HFELC     (1 << 7)
 | 
					
						
							|  |  |  | #define BD_TX_CFRL      (1 << 6)
 | 
					
						
							|  |  |  | #define BD_TX_RC_MASK   0xF
 | 
					
						
							|  |  |  | #define BD_TX_RC_OFFSET 0x2
 | 
					
						
							|  |  |  | #define BD_TX_TOEUN     (1 << 1)
 | 
					
						
							|  |  |  | #define BD_TX_TR        (1 << 0)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define BD_RX_EMPTY     (1 << 15)
 | 
					
						
							|  |  |  | #define BD_RX_RO1       (1 << 14)
 | 
					
						
							|  |  |  | #define BD_RX_FIRST     (1 << 10)
 | 
					
						
							|  |  |  | #define BD_RX_MISS      (1 << 8)
 | 
					
						
							|  |  |  | #define BD_RX_BROADCAST (1 << 7)
 | 
					
						
							|  |  |  | #define BD_RX_MULTICAST (1 << 6)
 | 
					
						
							|  |  |  | #define BD_RX_LG        (1 << 5)
 | 
					
						
							|  |  |  | #define BD_RX_NO        (1 << 4)
 | 
					
						
							|  |  |  | #define BD_RX_SH        (1 << 3)
 | 
					
						
							|  |  |  | #define BD_RX_CR        (1 << 2)
 | 
					
						
							|  |  |  | #define BD_RX_OV        (1 << 1)
 | 
					
						
							|  |  |  | #define BD_RX_TR        (1 << 0)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Tx FCB flags */ | 
					
						
							|  |  |  | #define FCB_TX_VLN     (1 << 7)
 | 
					
						
							|  |  |  | #define FCB_TX_IP      (1 << 6)
 | 
					
						
							|  |  |  | #define FCB_TX_IP6     (1 << 5)
 | 
					
						
							|  |  |  | #define FCB_TX_TUP     (1 << 4)
 | 
					
						
							|  |  |  | #define FCB_TX_UDP     (1 << 3)
 | 
					
						
							|  |  |  | #define FCB_TX_CIP     (1 << 2)
 | 
					
						
							|  |  |  | #define FCB_TX_CTU     (1 << 1)
 | 
					
						
							|  |  |  | #define FCB_TX_NPH     (1 << 0)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* eTSEC */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Number of register in the device */ | 
					
						
							|  |  |  | #define ETSEC_REG_NUMBER 1024
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct eTSEC_Register { | 
					
						
							|  |  |  |     const char *name; | 
					
						
							|  |  |  |     const char *desc; | 
					
						
							|  |  |  |     uint32_t    access; | 
					
						
							|  |  |  |     uint32_t    value; | 
					
						
							|  |  |  | } eTSEC_Register; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 16:43:22 -04:00
										 |  |  | struct eTSEC { | 
					
						
							| 
									
										
										
										
											2014-02-05 14:59:28 +01:00
										 |  |  |     SysBusDevice  busdev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MemoryRegion  io_area; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     eTSEC_Register regs[ETSEC_REG_NUMBER]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     NICState *nic; | 
					
						
							|  |  |  |     NICConf   conf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Tx */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     uint8_t       *tx_buffer; | 
					
						
							|  |  |  |     uint32_t       tx_buffer_len; | 
					
						
							|  |  |  |     eTSEC_rxtx_bd  first_bd; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Rx */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     uint8_t       *rx_buffer; | 
					
						
							|  |  |  |     uint32_t       rx_buffer_len; | 
					
						
							|  |  |  |     uint32_t       rx_remaining_data; | 
					
						
							|  |  |  |     uint8_t        rx_first_in_frame; | 
					
						
							|  |  |  |     uint8_t        rx_fcb_size; | 
					
						
							|  |  |  |     eTSEC_rxtx_bd  rx_first_bd; | 
					
						
							|  |  |  |     uint8_t        rx_fcb[10]; | 
					
						
							|  |  |  |     uint32_t       rx_padding; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* IRQs */ | 
					
						
							|  |  |  |     qemu_irq     tx_irq; | 
					
						
							|  |  |  |     qemu_irq     rx_irq; | 
					
						
							|  |  |  |     qemu_irq     err_irq; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     uint16_t phy_status; | 
					
						
							|  |  |  |     uint16_t phy_control; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Polling */ | 
					
						
							|  |  |  |     struct ptimer_state *ptimer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-15 18:19:07 +08:00
										 |  |  |     /* Whether we should flush the rx queue when buffer becomes available. */ | 
					
						
							|  |  |  |     bool need_flush; | 
					
						
							| 
									
										
										
										
											2020-09-03 16:43:22 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | typedef struct eTSEC eTSEC; | 
					
						
							| 
									
										
										
										
											2014-02-05 14:59:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define TYPE_ETSEC_COMMON "eTSEC"
 | 
					
						
							| 
									
										
										
										
											2020-09-16 14:25:19 -04:00
										 |  |  | OBJECT_DECLARE_SIMPLE_TYPE(eTSEC, ETSEC_COMMON) | 
					
						
							| 
									
										
										
										
											2014-02-05 14:59:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define eTSEC_TRANSMIT 1
 | 
					
						
							|  |  |  | #define eTSEC_RECEIVE  2
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-12 14:00:52 -07:00
										 |  |  | void etsec_update_irq(eTSEC *etsec); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-05 14:59:28 +01:00
										 |  |  | void etsec_walk_tx_ring(eTSEC *etsec, int ring_nbr); | 
					
						
							|  |  |  | void etsec_walk_rx_ring(eTSEC *etsec, int ring_nbr); | 
					
						
							| 
									
										
										
										
											2015-07-15 18:19:06 +08:00
										 |  |  | ssize_t etsec_rx_ring_write(eTSEC *etsec, const uint8_t *buf, size_t size); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:59:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | void etsec_write_miim(eTSEC          *etsec, | 
					
						
							|  |  |  |                       eTSEC_Register *reg, | 
					
						
							|  |  |  |                       uint32_t        reg_index, | 
					
						
							|  |  |  |                       uint32_t        value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void etsec_miim_link_status(eTSEC *etsec, NetClientState *nc); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 13:47:03 +02:00
										 |  |  | #endif /* ETSEC_H */
 |