| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * QEMU NS SONIC DP8393x netcard | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2008-2009 Herve Poussineau | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation; either version 2 of | 
					
						
							|  |  |  |  * the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License along | 
					
						
							| 
									
										
										
										
											2009-07-16 20:47:01 +00:00
										 |  |  |  * with this program; if not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 18:17:11 +00:00
										 |  |  | #include "qemu/osdep.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 07:23:42 +02:00
										 |  |  | #include "hw/irq.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 07:23:51 +02:00
										 |  |  | #include "hw/qdev-properties.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  | #include "hw/sysbus.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 07:23:45 +02:00
										 |  |  | #include "migration/vmstate.h"
 | 
					
						
							| 
									
										
										
										
											2012-10-24 08:43:34 +02:00
										 |  |  | #include "net/net.h"
 | 
					
						
							| 
									
										
											  
											
												include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef.  Since then, we've moved to include qemu/osdep.h
everywhere.  Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h.  That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h.  Include qapi/error.h in .c files that need it and don't
get it now.  Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly.  Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h.  Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third.  Unfortunately, the number depending on
qapi-types.h shrinks only a little.  More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
											
										 
											2016-03-14 09:01:28 +01:00
										 |  |  | #include "qapi/error.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-23 16:35:07 +02:00
										 |  |  | #include "qemu/module.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  | #include "qemu/timer.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:42 +02:00
										 |  |  | #include <zlib.h>
 | 
					
						
							| 
									
										
										
										
											2020-09-03 16:43:22 -04:00
										 |  |  | #include "qom/object.h"
 | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  | #include "trace.h"
 | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  | static const char *reg_names[] = { | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     "CR", "DCR", "RCR", "TCR", "IMR", "ISR", "UTDA", "CTDA", | 
					
						
							|  |  |  |     "TPS", "TFC", "TSA0", "TSA1", "TFS", "URDA", "CRDA", "CRBA0", | 
					
						
							|  |  |  |     "CRBA1", "RBWC0", "RBWC1", "EOBC", "URRA", "RSA", "REA", "RRP", | 
					
						
							|  |  |  |     "RWP", "TRBA0", "TRBA1", "0x1b", "0x1c", "0x1d", "0x1e", "LLFA", | 
					
						
							|  |  |  |     "TTDA", "CEP", "CAP2", "CAP1", "CAP0", "CE", "CDP", "CDC", | 
					
						
							|  |  |  |     "SR", "WT0", "WT1", "RSC", "CRCT", "FAET", "MPT", "MDT", | 
					
						
							|  |  |  |     "0x30", "0x31", "0x32", "0x33", "0x34", "0x35", "0x36", "0x37", | 
					
						
							|  |  |  |     "0x38", "0x39", "0x3a", "0x3b", "0x3c", "0x3d", "0x3e", "DCR2" }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define SONIC_CR     0x00
 | 
					
						
							|  |  |  | #define SONIC_DCR    0x01
 | 
					
						
							|  |  |  | #define SONIC_RCR    0x02
 | 
					
						
							|  |  |  | #define SONIC_TCR    0x03
 | 
					
						
							|  |  |  | #define SONIC_IMR    0x04
 | 
					
						
							|  |  |  | #define SONIC_ISR    0x05
 | 
					
						
							|  |  |  | #define SONIC_UTDA   0x06
 | 
					
						
							|  |  |  | #define SONIC_CTDA   0x07
 | 
					
						
							|  |  |  | #define SONIC_TPS    0x08
 | 
					
						
							|  |  |  | #define SONIC_TFC    0x09
 | 
					
						
							|  |  |  | #define SONIC_TSA0   0x0a
 | 
					
						
							|  |  |  | #define SONIC_TSA1   0x0b
 | 
					
						
							|  |  |  | #define SONIC_TFS    0x0c
 | 
					
						
							|  |  |  | #define SONIC_URDA   0x0d
 | 
					
						
							|  |  |  | #define SONIC_CRDA   0x0e
 | 
					
						
							|  |  |  | #define SONIC_CRBA0  0x0f
 | 
					
						
							|  |  |  | #define SONIC_CRBA1  0x10
 | 
					
						
							|  |  |  | #define SONIC_RBWC0  0x11
 | 
					
						
							|  |  |  | #define SONIC_RBWC1  0x12
 | 
					
						
							|  |  |  | #define SONIC_EOBC   0x13
 | 
					
						
							|  |  |  | #define SONIC_URRA   0x14
 | 
					
						
							|  |  |  | #define SONIC_RSA    0x15
 | 
					
						
							|  |  |  | #define SONIC_REA    0x16
 | 
					
						
							|  |  |  | #define SONIC_RRP    0x17
 | 
					
						
							|  |  |  | #define SONIC_RWP    0x18
 | 
					
						
							|  |  |  | #define SONIC_TRBA0  0x19
 | 
					
						
							|  |  |  | #define SONIC_TRBA1  0x1a
 | 
					
						
							|  |  |  | #define SONIC_LLFA   0x1f
 | 
					
						
							|  |  |  | #define SONIC_TTDA   0x20
 | 
					
						
							|  |  |  | #define SONIC_CEP    0x21
 | 
					
						
							|  |  |  | #define SONIC_CAP2   0x22
 | 
					
						
							|  |  |  | #define SONIC_CAP1   0x23
 | 
					
						
							|  |  |  | #define SONIC_CAP0   0x24
 | 
					
						
							|  |  |  | #define SONIC_CE     0x25
 | 
					
						
							|  |  |  | #define SONIC_CDP    0x26
 | 
					
						
							|  |  |  | #define SONIC_CDC    0x27
 | 
					
						
							|  |  |  | #define SONIC_SR     0x28
 | 
					
						
							|  |  |  | #define SONIC_WT0    0x29
 | 
					
						
							|  |  |  | #define SONIC_WT1    0x2a
 | 
					
						
							|  |  |  | #define SONIC_RSC    0x2b
 | 
					
						
							|  |  |  | #define SONIC_CRCT   0x2c
 | 
					
						
							|  |  |  | #define SONIC_FAET   0x2d
 | 
					
						
							|  |  |  | #define SONIC_MPT    0x2e
 | 
					
						
							|  |  |  | #define SONIC_MDT    0x2f
 | 
					
						
							|  |  |  | #define SONIC_DCR2   0x3f
 | 
					
						
							| 
									
										
										
										
											2021-07-08 00:30:46 +02:00
										 |  |  | #define SONIC_REG_COUNT  0x40
 | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define SONIC_CR_HTX     0x0001
 | 
					
						
							|  |  |  | #define SONIC_CR_TXP     0x0002
 | 
					
						
							|  |  |  | #define SONIC_CR_RXDIS   0x0004
 | 
					
						
							|  |  |  | #define SONIC_CR_RXEN    0x0008
 | 
					
						
							|  |  |  | #define SONIC_CR_STP     0x0010
 | 
					
						
							|  |  |  | #define SONIC_CR_ST      0x0020
 | 
					
						
							|  |  |  | #define SONIC_CR_RST     0x0080
 | 
					
						
							|  |  |  | #define SONIC_CR_RRRA    0x0100
 | 
					
						
							|  |  |  | #define SONIC_CR_LCAM    0x0200
 | 
					
						
							|  |  |  | #define SONIC_CR_MASK    0x03bf
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define SONIC_DCR_DW     0x0020
 | 
					
						
							|  |  |  | #define SONIC_DCR_LBR    0x2000
 | 
					
						
							|  |  |  | #define SONIC_DCR_EXBUS  0x8000
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define SONIC_RCR_PRX    0x0001
 | 
					
						
							|  |  |  | #define SONIC_RCR_LBK    0x0002
 | 
					
						
							|  |  |  | #define SONIC_RCR_FAER   0x0004
 | 
					
						
							|  |  |  | #define SONIC_RCR_CRCR   0x0008
 | 
					
						
							|  |  |  | #define SONIC_RCR_CRS    0x0020
 | 
					
						
							|  |  |  | #define SONIC_RCR_LPKT   0x0040
 | 
					
						
							|  |  |  | #define SONIC_RCR_BC     0x0080
 | 
					
						
							|  |  |  | #define SONIC_RCR_MC     0x0100
 | 
					
						
							|  |  |  | #define SONIC_RCR_LB0    0x0200
 | 
					
						
							|  |  |  | #define SONIC_RCR_LB1    0x0400
 | 
					
						
							|  |  |  | #define SONIC_RCR_AMC    0x0800
 | 
					
						
							|  |  |  | #define SONIC_RCR_PRO    0x1000
 | 
					
						
							|  |  |  | #define SONIC_RCR_BRD    0x2000
 | 
					
						
							|  |  |  | #define SONIC_RCR_RNT    0x4000
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define SONIC_TCR_PTX    0x0001
 | 
					
						
							|  |  |  | #define SONIC_TCR_BCM    0x0002
 | 
					
						
							|  |  |  | #define SONIC_TCR_FU     0x0004
 | 
					
						
							|  |  |  | #define SONIC_TCR_EXC    0x0040
 | 
					
						
							|  |  |  | #define SONIC_TCR_CRSL   0x0080
 | 
					
						
							|  |  |  | #define SONIC_TCR_NCRS   0x0100
 | 
					
						
							|  |  |  | #define SONIC_TCR_EXD    0x0400
 | 
					
						
							|  |  |  | #define SONIC_TCR_CRCI   0x2000
 | 
					
						
							|  |  |  | #define SONIC_TCR_PINT   0x8000
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  | #define SONIC_ISR_RBAE   0x0010
 | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | #define SONIC_ISR_RBE    0x0020
 | 
					
						
							|  |  |  | #define SONIC_ISR_RDE    0x0040
 | 
					
						
							|  |  |  | #define SONIC_ISR_TC     0x0080
 | 
					
						
							|  |  |  | #define SONIC_ISR_TXDN   0x0200
 | 
					
						
							|  |  |  | #define SONIC_ISR_PKTRX  0x0400
 | 
					
						
							|  |  |  | #define SONIC_ISR_PINT   0x0800
 | 
					
						
							|  |  |  | #define SONIC_ISR_LCD    0x1000
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 09:59:21 +11:00
										 |  |  | #define SONIC_DESC_EOL   0x0001
 | 
					
						
							|  |  |  | #define SONIC_DESC_ADDR  0xFFFE
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  | #define TYPE_DP8393X "dp8393x"
 | 
					
						
							| 
									
										
										
										
											2020-09-16 14:25:19 -04:00
										 |  |  | OBJECT_DECLARE_SIMPLE_TYPE(dp8393xState, DP8393X) | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 16:43:22 -04:00
										 |  |  | struct dp8393xState { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  |     SysBusDevice parent_obj; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     /* Hardware */ | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  |     uint8_t it_shift; | 
					
						
							| 
									
										
										
										
											2019-10-26 18:45:39 +02:00
										 |  |  |     bool big_endian; | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     bool last_rba_is_full; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     qemu_irq irq; | 
					
						
							|  |  |  |     int irq_level; | 
					
						
							|  |  |  |     QEMUTimer *watchdog; | 
					
						
							|  |  |  |     int64_t wt_last_update; | 
					
						
							| 
									
										
										
										
											2009-11-25 18:49:17 +00:00
										 |  |  |     NICConf conf; | 
					
						
							|  |  |  |     NICState *nic; | 
					
						
							| 
									
										
										
										
											2011-11-09 18:22:37 +02:00
										 |  |  |     MemoryRegion mmio; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Registers */ | 
					
						
							| 
									
										
										
										
											2021-07-03 15:42:51 +02:00
										 |  |  |     uint16_t cam[16][3]; | 
					
						
							| 
									
										
										
										
											2021-07-08 00:30:46 +02:00
										 |  |  |     uint16_t regs[SONIC_REG_COUNT]; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Temporaries */ | 
					
						
							|  |  |  |     uint8_t tx_buffer[0x10000]; | 
					
						
							|  |  |  |     int loopback_packet; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Memory access */ | 
					
						
							| 
									
										
										
										
											2019-10-17 18:03:43 +02:00
										 |  |  |     MemoryRegion *dma_mr; | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:37 +02:00
										 |  |  |     AddressSpace as; | 
					
						
							| 
									
										
										
										
											2020-09-03 16:43:22 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Accessor functions for values which are formed by | 
					
						
							| 
									
										
										
										
											2017-01-09 18:43:57 +00:00
										 |  |  |  * concatenating two 16 bit device registers. By putting these | 
					
						
							|  |  |  |  * in their own functions with a uint32_t return type we avoid the | 
					
						
							|  |  |  |  * pitfall of implicit sign extension where ((x << 16) | y) is a | 
					
						
							|  |  |  |  * signed 32 bit integer that might get sign-extended to a 64 bit integer. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static uint32_t dp8393x_cdp(dp8393xState *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return (s->regs[SONIC_URRA] << 16) | s->regs[SONIC_CDP]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static uint32_t dp8393x_crba(dp8393xState *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return (s->regs[SONIC_CRBA1] << 16) | s->regs[SONIC_CRBA0]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static uint32_t dp8393x_crda(dp8393xState *s) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-01-20 09:59:21 +11:00
										 |  |  |     return (s->regs[SONIC_URDA] << 16) | | 
					
						
							|  |  |  |            (s->regs[SONIC_CRDA] & SONIC_DESC_ADDR); | 
					
						
							| 
									
										
										
										
											2017-01-09 18:43:57 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static uint32_t dp8393x_rbwc(dp8393xState *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return (s->regs[SONIC_RBWC1] << 16) | s->regs[SONIC_RBWC0]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static uint32_t dp8393x_rrp(dp8393xState *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return (s->regs[SONIC_URRA] << 16) | s->regs[SONIC_RRP]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static uint32_t dp8393x_tsa(dp8393xState *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return (s->regs[SONIC_TSA1] << 16) | s->regs[SONIC_TSA0]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static uint32_t dp8393x_ttda(dp8393xState *s) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-01-20 09:59:21 +11:00
										 |  |  |     return (s->regs[SONIC_UTDA] << 16) | | 
					
						
							|  |  |  |            (s->regs[SONIC_TTDA] & SONIC_DESC_ADDR); | 
					
						
							| 
									
										
										
										
											2017-01-09 18:43:57 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static uint32_t dp8393x_wt(dp8393xState *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return s->regs[SONIC_WT1] << 16 | s->regs[SONIC_WT0]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  | static uint16_t dp8393x_get(dp8393xState *s, hwaddr addr, int offset) | 
					
						
							| 
									
										
										
										
											2019-10-26 18:45:39 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |     const MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED; | 
					
						
							| 
									
										
										
										
											2019-10-26 18:45:39 +02:00
										 |  |  |     uint16_t val; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |     if (s->regs[SONIC_DCR] & SONIC_DCR_DW) { | 
					
						
							|  |  |  |         addr += offset << 2; | 
					
						
							|  |  |  |         if (s->big_endian) { | 
					
						
							|  |  |  |             val = address_space_ldl_be(&s->as, addr, attrs, NULL); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             val = address_space_ldl_le(&s->as, addr, attrs, NULL); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-10-26 18:45:39 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |         addr += offset << 1; | 
					
						
							|  |  |  |         if (s->big_endian) { | 
					
						
							|  |  |  |             val = address_space_lduw_be(&s->as, addr, attrs, NULL); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             val = address_space_lduw_le(&s->as, addr, attrs, NULL); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-10-26 18:45:39 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-26 18:45:39 +02:00
										 |  |  |     return val; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  | static void dp8393x_put(dp8393xState *s, | 
					
						
							|  |  |  |                         hwaddr addr, int offset, uint16_t val) | 
					
						
							| 
									
										
										
										
											2019-10-26 18:45:39 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |     const MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (s->regs[SONIC_DCR] & SONIC_DCR_DW) { | 
					
						
							|  |  |  |         addr += offset << 2; | 
					
						
							|  |  |  |         if (s->big_endian) { | 
					
						
							|  |  |  |             address_space_stl_be(&s->as, addr, val, attrs, NULL); | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |             address_space_stl_le(&s->as, addr, val, attrs, NULL); | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-10-26 18:45:39 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |         addr += offset << 1; | 
					
						
							|  |  |  |         if (s->big_endian) { | 
					
						
							|  |  |  |             address_space_stw_be(&s->as, addr, val, attrs, NULL); | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |             address_space_stw_le(&s->as, addr, val, attrs, NULL); | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-10-26 18:45:39 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | static void dp8393x_update_irq(dp8393xState *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int level = (s->regs[SONIC_IMR] & s->regs[SONIC_ISR]) ? 1 : 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (level != s->irq_level) { | 
					
						
							|  |  |  |         s->irq_level = level; | 
					
						
							|  |  |  |         if (level) { | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |             trace_dp8393x_raise_irq(s->regs[SONIC_ISR]); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |             trace_dp8393x_lower_irq(); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     qemu_set_irq(s->irq, level); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static void dp8393x_do_load_cam(dp8393xState *s) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int width, size; | 
					
						
							| 
									
										
										
										
											2021-06-25 07:54:00 +01:00
										 |  |  |     uint16_t index; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     width = (s->regs[SONIC_DCR] & SONIC_DCR_DW) ? 2 : 1; | 
					
						
							|  |  |  |     size = sizeof(uint16_t) * 4 * width; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while (s->regs[SONIC_CDC] & 0x1f) { | 
					
						
							|  |  |  |         /* Fill current entry */ | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |         index = dp8393x_get(s, dp8393x_cdp(s), 0) & 0xf; | 
					
						
							|  |  |  |         s->cam[index][0] = dp8393x_get(s, dp8393x_cdp(s), 1); | 
					
						
							|  |  |  |         s->cam[index][1] = dp8393x_get(s, dp8393x_cdp(s), 2); | 
					
						
							|  |  |  |         s->cam[index][2] = dp8393x_get(s, dp8393x_cdp(s), 3); | 
					
						
							| 
									
										
										
										
											2021-07-03 15:42:51 +02:00
										 |  |  |         trace_dp8393x_load_cam(index, | 
					
						
							|  |  |  |                                s->cam[index][0] >> 8, s->cam[index][0] & 0xff, | 
					
						
							|  |  |  |                                s->cam[index][1] >> 8, s->cam[index][1] & 0xff, | 
					
						
							|  |  |  |                                s->cam[index][2] >> 8, s->cam[index][2] & 0xff); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         /* Move to next entry */ | 
					
						
							|  |  |  |         s->regs[SONIC_CDC]--; | 
					
						
							|  |  |  |         s->regs[SONIC_CDP] += size; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Read CAM enable */ | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |     s->regs[SONIC_CE] = dp8393x_get(s, dp8393x_cdp(s), 0); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |     trace_dp8393x_load_cam_done(s->regs[SONIC_CE]); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Done */ | 
					
						
							|  |  |  |     s->regs[SONIC_CR] &= ~SONIC_CR_LCAM; | 
					
						
							|  |  |  |     s->regs[SONIC_ISR] |= SONIC_ISR_LCD; | 
					
						
							|  |  |  |     dp8393x_update_irq(s); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static void dp8393x_do_read_rra(dp8393xState *s) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int width, size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Read memory */ | 
					
						
							|  |  |  |     width = (s->regs[SONIC_DCR] & SONIC_DCR_DW) ? 2 : 1; | 
					
						
							|  |  |  |     size = sizeof(uint16_t) * 4 * width; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Update SONIC registers */ | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |     s->regs[SONIC_CRBA0] = dp8393x_get(s, dp8393x_rrp(s), 0); | 
					
						
							|  |  |  |     s->regs[SONIC_CRBA1] = dp8393x_get(s, dp8393x_rrp(s), 1); | 
					
						
							|  |  |  |     s->regs[SONIC_RBWC0] = dp8393x_get(s, dp8393x_rrp(s), 2); | 
					
						
							|  |  |  |     s->regs[SONIC_RBWC1] = dp8393x_get(s, dp8393x_rrp(s), 3); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |     trace_dp8393x_read_rra_regs(s->regs[SONIC_CRBA0], s->regs[SONIC_CRBA1], | 
					
						
							|  |  |  |                                 s->regs[SONIC_RBWC0], s->regs[SONIC_RBWC1]); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Go to next entry */ | 
					
						
							|  |  |  |     s->regs[SONIC_RRP] += size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Handle wrap */ | 
					
						
							|  |  |  |     if (s->regs[SONIC_RRP] == s->regs[SONIC_REA]) { | 
					
						
							|  |  |  |         s->regs[SONIC_RRP] = s->regs[SONIC_RSA]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     /* Warn the host if CRBA now has the last available resource */ | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     if (s->regs[SONIC_RRP] == s->regs[SONIC_RWP]) { | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         s->regs[SONIC_ISR] |= SONIC_ISR_RBE; | 
					
						
							|  |  |  |         dp8393x_update_irq(s); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Allow packet reception */ | 
					
						
							|  |  |  |     s->last_rba_is_full = false; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static void dp8393x_do_software_reset(dp8393xState *s) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-08-21 16:03:08 +01:00
										 |  |  |     timer_del(s->watchdog); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     s->regs[SONIC_CR] &= ~(SONIC_CR_LCAM | SONIC_CR_RRRA | SONIC_CR_TXP | | 
					
						
							|  |  |  |                            SONIC_CR_HTX); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     s->regs[SONIC_CR] |= SONIC_CR_RST | SONIC_CR_RXDIS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static void dp8393x_set_next_tick(dp8393xState *s) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     uint32_t ticks; | 
					
						
							|  |  |  |     int64_t delay; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (s->regs[SONIC_CR] & SONIC_CR_STP) { | 
					
						
							| 
									
										
										
										
											2013-08-21 16:03:08 +01:00
										 |  |  |         timer_del(s->watchdog); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-09 18:43:57 +00:00
										 |  |  |     ticks = dp8393x_wt(s); | 
					
						
							| 
									
										
										
										
											2013-08-21 16:03:08 +01:00
										 |  |  |     s->wt_last_update = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | 
					
						
							| 
									
										
										
										
											2016-03-21 21:32:30 +05:30
										 |  |  |     delay = NANOSECONDS_PER_SECOND * ticks / 5000000; | 
					
						
							| 
									
										
										
										
											2013-08-21 16:03:08 +01:00
										 |  |  |     timer_mod(s->watchdog, s->wt_last_update + delay); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static void dp8393x_update_wt_regs(dp8393xState *s) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int64_t elapsed; | 
					
						
							|  |  |  |     uint32_t val; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (s->regs[SONIC_CR] & SONIC_CR_STP) { | 
					
						
							| 
									
										
										
										
											2013-08-21 16:03:08 +01:00
										 |  |  |         timer_del(s->watchdog); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-21 16:03:08 +01:00
										 |  |  |     elapsed = s->wt_last_update - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | 
					
						
							| 
									
										
										
										
											2017-01-09 18:43:57 +00:00
										 |  |  |     val = dp8393x_wt(s); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     val -= elapsed / 5000000; | 
					
						
							|  |  |  |     s->regs[SONIC_WT1] = (val >> 16) & 0xffff; | 
					
						
							|  |  |  |     s->regs[SONIC_WT0] = (val >> 0)  & 0xffff; | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |     dp8393x_set_next_tick(s); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static void dp8393x_do_start_timer(dp8393xState *s) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     s->regs[SONIC_CR] &= ~SONIC_CR_STP; | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |     dp8393x_set_next_tick(s); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static void dp8393x_do_stop_timer(dp8393xState *s) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     s->regs[SONIC_CR] &= ~SONIC_CR_ST; | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |     dp8393x_update_wt_regs(s); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-05 18:56:49 +01:00
										 |  |  | static bool dp8393x_can_receive(NetClientState *nc); | 
					
						
							| 
									
										
										
										
											2015-07-15 18:19:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static void dp8393x_do_receiver_enable(dp8393xState *s) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     s->regs[SONIC_CR] &= ~SONIC_CR_RXDIS; | 
					
						
							| 
									
										
										
										
											2015-07-15 18:19:12 +08:00
										 |  |  |     if (dp8393x_can_receive(s->nic->ncs)) { | 
					
						
							|  |  |  |         qemu_flush_queued_packets(qemu_get_queue(s->nic)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static void dp8393x_do_receiver_disable(dp8393xState *s) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     s->regs[SONIC_CR] &= ~SONIC_CR_RXEN; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static void dp8393x_do_transmit_packets(dp8393xState *s) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-01-30 19:12:22 +08:00
										 |  |  |     NetClientState *nc = qemu_get_queue(s->nic); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     int tx_len, len; | 
					
						
							|  |  |  |     uint16_t i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while (1) { | 
					
						
							|  |  |  |         /* Read memory */ | 
					
						
							|  |  |  |         s->regs[SONIC_TTDA] = s->regs[SONIC_CTDA]; | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |         trace_dp8393x_transmit_packet(dp8393x_ttda(s)); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         tx_len = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* Update registers */ | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |         s->regs[SONIC_TCR] = dp8393x_get(s, dp8393x_ttda(s), 1) & 0xf000; | 
					
						
							|  |  |  |         s->regs[SONIC_TPS] = dp8393x_get(s, dp8393x_ttda(s), 2); | 
					
						
							|  |  |  |         s->regs[SONIC_TFC] = dp8393x_get(s, dp8393x_ttda(s), 3); | 
					
						
							|  |  |  |         s->regs[SONIC_TSA0] = dp8393x_get(s, dp8393x_ttda(s), 4); | 
					
						
							|  |  |  |         s->regs[SONIC_TSA1] = dp8393x_get(s, dp8393x_ttda(s), 5); | 
					
						
							|  |  |  |         s->regs[SONIC_TFS] = dp8393x_get(s, dp8393x_ttda(s), 6); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /* Handle programmable interrupt */ | 
					
						
							|  |  |  |         if (s->regs[SONIC_TCR] & SONIC_TCR_PINT) { | 
					
						
							|  |  |  |             s->regs[SONIC_ISR] |= SONIC_ISR_PINT; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             s->regs[SONIC_ISR] &= ~SONIC_ISR_PINT; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (i = 0; i < s->regs[SONIC_TFC]; ) { | 
					
						
							|  |  |  |             /* Append fragment */ | 
					
						
							|  |  |  |             len = s->regs[SONIC_TFS]; | 
					
						
							|  |  |  |             if (tx_len + len > sizeof(s->tx_buffer)) { | 
					
						
							|  |  |  |                 len = sizeof(s->tx_buffer) - tx_len; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-02-18 11:24:57 +00:00
										 |  |  |             address_space_read(&s->as, dp8393x_tsa(s), MEMTXATTRS_UNSPECIFIED, | 
					
						
							|  |  |  |                                &s->tx_buffer[tx_len], len); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |             tx_len += len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             i++; | 
					
						
							|  |  |  |             if (i != s->regs[SONIC_TFC]) { | 
					
						
							|  |  |  |                 /* Read next fragment details */ | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |                 s->regs[SONIC_TSA0] = dp8393x_get(s, dp8393x_ttda(s), | 
					
						
							|  |  |  |                                                   4 + 3 * i); | 
					
						
							|  |  |  |                 s->regs[SONIC_TSA1] = dp8393x_get(s, dp8393x_ttda(s), | 
					
						
							|  |  |  |                                                   5 + 3 * i); | 
					
						
							|  |  |  |                 s->regs[SONIC_TFS] = dp8393x_get(s, dp8393x_ttda(s), | 
					
						
							|  |  |  |                                                  6 + 3 * i); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* Handle Ethernet checksum */ | 
					
						
							|  |  |  |         if (!(s->regs[SONIC_TCR] & SONIC_TCR_CRCI)) { | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |             /*
 | 
					
						
							|  |  |  |              * Don't append FCS there, to look like slirp packets | 
					
						
							|  |  |  |              * which don't have one | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             /* Remove existing FCS */ | 
					
						
							|  |  |  |             tx_len -= 4; | 
					
						
							| 
									
										
										
										
											2020-11-24 10:24:45 +01:00
										 |  |  |             if (tx_len < 0) { | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |                 trace_dp8393x_transmit_txlen_error(tx_len); | 
					
						
							| 
									
										
										
										
											2020-11-24 10:24:45 +01:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (s->regs[SONIC_RCR] & (SONIC_RCR_LB1 | SONIC_RCR_LB0)) { | 
					
						
							|  |  |  |             /* Loopback */ | 
					
						
							|  |  |  |             s->regs[SONIC_TCR] |= SONIC_TCR_CRSL; | 
					
						
							| 
									
										
										
										
											2013-01-30 19:12:22 +08:00
										 |  |  |             if (nc->info->can_receive(nc)) { | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |                 s->loopback_packet = 1; | 
					
						
							| 
									
										
										
										
											2021-02-24 12:57:40 +08:00
										 |  |  |                 qemu_receive_packet(nc, s->tx_buffer, tx_len); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             /* Transmit packet */ | 
					
						
							| 
									
										
										
										
											2013-01-30 19:12:22 +08:00
										 |  |  |             qemu_send_packet(nc, s->tx_buffer, tx_len); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         s->regs[SONIC_TCR] |= SONIC_TCR_PTX; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* Write status */ | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |         dp8393x_put(s, dp8393x_ttda(s), 0, s->regs[SONIC_TCR] & 0x0fff); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (!(s->regs[SONIC_CR] & SONIC_CR_HTX)) { | 
					
						
							|  |  |  |             /* Read footer of packet */ | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |             s->regs[SONIC_CTDA] = dp8393x_get(s, dp8393x_ttda(s), | 
					
						
							|  |  |  |                                               4 + 3 * s->regs[SONIC_TFC]); | 
					
						
							| 
									
										
										
										
											2020-03-04 14:23:05 +11:00
										 |  |  |             if (s->regs[SONIC_CTDA] & SONIC_DESC_EOL) { | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |                 /* EOL detected */ | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Done */ | 
					
						
							|  |  |  |     s->regs[SONIC_CR] &= ~SONIC_CR_TXP; | 
					
						
							|  |  |  |     s->regs[SONIC_ISR] |= SONIC_ISR_TXDN; | 
					
						
							|  |  |  |     dp8393x_update_irq(s); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static void dp8393x_do_halt_transmission(dp8393xState *s) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     /* Nothing to do */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static void dp8393x_do_command(dp8393xState *s, uint16_t command) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     if ((s->regs[SONIC_CR] & SONIC_CR_RST) && !(command & SONIC_CR_RST)) { | 
					
						
							|  |  |  |         s->regs[SONIC_CR] &= ~SONIC_CR_RST; | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     s->regs[SONIC_CR] |= (command & SONIC_CR_MASK); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     if (command & SONIC_CR_HTX) { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |         dp8393x_do_halt_transmission(s); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (command & SONIC_CR_TXP) { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |         dp8393x_do_transmit_packets(s); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (command & SONIC_CR_RXDIS) { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |         dp8393x_do_receiver_disable(s); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (command & SONIC_CR_RXEN) { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |         dp8393x_do_receiver_enable(s); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (command & SONIC_CR_STP) { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |         dp8393x_do_stop_timer(s); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (command & SONIC_CR_ST) { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |         dp8393x_do_start_timer(s); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (command & SONIC_CR_RST) { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |         dp8393x_do_software_reset(s); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     if (command & SONIC_CR_RRRA) { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |         dp8393x_do_read_rra(s); | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         s->regs[SONIC_CR] &= ~SONIC_CR_RRRA; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     if (command & SONIC_CR_LCAM) { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |         dp8393x_do_load_cam(s); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:43 +02:00
										 |  |  | static uint64_t dp8393x_read(void *opaque, hwaddr addr, unsigned int size) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:43 +02:00
										 |  |  |     dp8393xState *s = opaque; | 
					
						
							|  |  |  |     int reg = addr >> s->it_shift; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     uint16_t val = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (reg) { | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     /* Update data before reading it */ | 
					
						
							|  |  |  |     case SONIC_WT0: | 
					
						
							|  |  |  |     case SONIC_WT1: | 
					
						
							|  |  |  |         dp8393x_update_wt_regs(s); | 
					
						
							|  |  |  |         val = s->regs[reg]; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     /* Accept read to some registers only when in reset mode */ | 
					
						
							|  |  |  |     case SONIC_CAP2: | 
					
						
							|  |  |  |     case SONIC_CAP1: | 
					
						
							|  |  |  |     case SONIC_CAP0: | 
					
						
							|  |  |  |         if (s->regs[SONIC_CR] & SONIC_CR_RST) { | 
					
						
							| 
									
										
										
										
											2021-07-03 15:42:51 +02:00
										 |  |  |             val = s->cam[s->regs[SONIC_CEP] & 0xf][SONIC_CAP0 - reg]; | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     /* All other registers have no special contraints */ | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         val = s->regs[reg]; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |     trace_dp8393x_read(reg, reg_names[reg], val, size); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 22:49:26 +01:00
										 |  |  |     return val; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 22:49:26 +01:00
										 |  |  | static void dp8393x_write(void *opaque, hwaddr addr, uint64_t val, | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:43 +02:00
										 |  |  |                           unsigned int size) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:43 +02:00
										 |  |  |     dp8393xState *s = opaque; | 
					
						
							|  |  |  |     int reg = addr >> s->it_shift; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |     trace_dp8393x_write(reg, reg_names[reg], val, size); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     switch (reg) { | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     /* Command register */ | 
					
						
							|  |  |  |     case SONIC_CR: | 
					
						
							|  |  |  |         dp8393x_do_command(s, val); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     /* Prevent write to read-only registers */ | 
					
						
							|  |  |  |     case SONIC_CAP2: | 
					
						
							|  |  |  |     case SONIC_CAP1: | 
					
						
							|  |  |  |     case SONIC_CAP0: | 
					
						
							|  |  |  |     case SONIC_SR: | 
					
						
							|  |  |  |     case SONIC_MDT: | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |         trace_dp8393x_write_invalid(reg); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |         break; | 
					
						
							|  |  |  |     /* Accept write to some registers only when in reset mode */ | 
					
						
							|  |  |  |     case SONIC_DCR: | 
					
						
							|  |  |  |         if (s->regs[SONIC_CR] & SONIC_CR_RST) { | 
					
						
							|  |  |  |             s->regs[reg] = val & 0xbfff; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |             trace_dp8393x_write_invalid_dcr("DCR"); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case SONIC_DCR2: | 
					
						
							|  |  |  |         if (s->regs[SONIC_CR] & SONIC_CR_RST) { | 
					
						
							|  |  |  |             s->regs[reg] = val & 0xf017; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |             trace_dp8393x_write_invalid_dcr("DCR2"); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     /* 12 lower bytes are Read Only */ | 
					
						
							|  |  |  |     case SONIC_TCR: | 
					
						
							|  |  |  |         s->regs[reg] = val & 0xf000; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     /* 9 lower bytes are Read Only */ | 
					
						
							|  |  |  |     case SONIC_RCR: | 
					
						
							|  |  |  |         s->regs[reg] = val & 0xffe0; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     /* Ignore most significant bit */ | 
					
						
							|  |  |  |     case SONIC_IMR: | 
					
						
							|  |  |  |         s->regs[reg] = val & 0x7fff; | 
					
						
							|  |  |  |         dp8393x_update_irq(s); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     /* Clear bits by writing 1 to them */ | 
					
						
							|  |  |  |     case SONIC_ISR: | 
					
						
							|  |  |  |         val &= s->regs[reg]; | 
					
						
							|  |  |  |         s->regs[reg] &= ~val; | 
					
						
							|  |  |  |         if (val & SONIC_ISR_RBE) { | 
					
						
							|  |  |  |             dp8393x_do_read_rra(s); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         dp8393x_update_irq(s); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     /* The guest is required to store aligned pointers here */ | 
					
						
							|  |  |  |     case SONIC_RSA: | 
					
						
							|  |  |  |     case SONIC_REA: | 
					
						
							|  |  |  |     case SONIC_RRP: | 
					
						
							|  |  |  |     case SONIC_RWP: | 
					
						
							|  |  |  |         if (s->regs[SONIC_DCR] & SONIC_DCR_DW) { | 
					
						
							|  |  |  |             s->regs[reg] = val & 0xfffc; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             s->regs[reg] = val & 0xfffe; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     /* Invert written value for some registers */ | 
					
						
							|  |  |  |     case SONIC_CRCT: | 
					
						
							|  |  |  |     case SONIC_FAET: | 
					
						
							|  |  |  |     case SONIC_MPT: | 
					
						
							|  |  |  |         s->regs[reg] = val ^ 0xffff; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     /* All other registers have no special contrainst */ | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         s->regs[reg] = val; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (reg == SONIC_WT0 || reg == SONIC_WT1) { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |         dp8393x_set_next_tick(s); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 22:49:26 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Since .impl.max_access_size is effectively controlled by the it_shift | 
					
						
							|  |  |  |  * property, leave it unspecified for now to allow the memory API to | 
					
						
							|  |  |  |  * correctly zero extend the 16-bit register values to the access size up to and | 
					
						
							|  |  |  |  * including it_shift. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:43 +02:00
										 |  |  | static const MemoryRegionOps dp8393x_ops = { | 
					
						
							|  |  |  |     .read = dp8393x_read, | 
					
						
							|  |  |  |     .write = dp8393x_write, | 
					
						
							| 
									
										
										
										
											2021-07-05 22:49:26 +01:00
										 |  |  |     .impl.min_access_size = 2, | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:43 +02:00
										 |  |  |     .endianness = DEVICE_NATIVE_ENDIAN, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | static void dp8393x_watchdog(void *opaque) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     dp8393xState *s = opaque; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (s->regs[SONIC_CR] & SONIC_CR_STP) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     s->regs[SONIC_WT1] = 0xffff; | 
					
						
							|  |  |  |     s->regs[SONIC_WT0] = 0xffff; | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |     dp8393x_set_next_tick(s); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Signal underflow */ | 
					
						
							|  |  |  |     s->regs[SONIC_ISR] |= SONIC_ISR_TC; | 
					
						
							|  |  |  |     dp8393x_update_irq(s); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-05 18:56:49 +01:00
										 |  |  | static bool dp8393x_can_receive(NetClientState *nc) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-01-30 19:12:23 +08:00
										 |  |  |     dp8393xState *s = qemu_get_nic_opaque(nc); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-05 18:56:49 +01:00
										 |  |  |     return !!(s->regs[SONIC_CR] & SONIC_CR_RXEN); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static int dp8393x_receive_filter(dp8393xState *s, const uint8_t * buf, | 
					
						
							|  |  |  |                                   int size) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     static const uint8_t bcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | 
					
						
							|  |  |  |     int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Check promiscuous mode */ | 
					
						
							|  |  |  |     if ((s->regs[SONIC_RCR] & SONIC_RCR_PRO) && (buf[0] & 1) == 0) { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Check multicast packets */ | 
					
						
							|  |  |  |     if ((s->regs[SONIC_RCR] & SONIC_RCR_AMC) && (buf[0] & 1) == 1) { | 
					
						
							|  |  |  |         return SONIC_RCR_MC; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Check broadcast */ | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     if ((s->regs[SONIC_RCR] & SONIC_RCR_BRD) && | 
					
						
							|  |  |  |          !memcmp(buf, bcast, sizeof(bcast))) { | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         return SONIC_RCR_BC; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Check CAM */ | 
					
						
							|  |  |  |     for (i = 0; i < 16; i++) { | 
					
						
							|  |  |  |         if (s->regs[SONIC_CE] & (1 << i)) { | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |             /* Entry enabled */ | 
					
						
							|  |  |  |             if (!memcmp(buf, s->cam[i], sizeof(s->cam[i]))) { | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  | static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf, | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |                                size_t pkt_size) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-01-30 19:12:23 +08:00
										 |  |  |     dp8393xState *s = qemu_get_nic_opaque(nc); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     int packet_type; | 
					
						
							|  |  |  |     uint32_t available, address; | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |     int rx_len, padded_len; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     uint32_t checksum; | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     int size; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     s->regs[SONIC_RCR] &= ~(SONIC_RCR_PRX | SONIC_RCR_LBK | SONIC_RCR_FAER | | 
					
						
							|  |  |  |         SONIC_RCR_CRCR | SONIC_RCR_LPKT | SONIC_RCR_BC | SONIC_RCR_MC); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     if (s->last_rba_is_full) { | 
					
						
							|  |  |  |         return pkt_size; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     rx_len = pkt_size + sizeof(checksum); | 
					
						
							|  |  |  |     if (s->regs[SONIC_DCR] & SONIC_DCR_DW) { | 
					
						
							|  |  |  |         padded_len = ((rx_len - 1) | 3) + 1; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         padded_len = ((rx_len - 1) | 1) + 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (padded_len > dp8393x_rbwc(s) * 2) { | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |         trace_dp8393x_receive_oversize(pkt_size); | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         s->regs[SONIC_ISR] |= SONIC_ISR_RBAE; | 
					
						
							|  |  |  |         dp8393x_update_irq(s); | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         s->regs[SONIC_RCR] |= SONIC_RCR_LPKT; | 
					
						
							|  |  |  |         goto done; | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     packet_type = dp8393x_receive_filter(s, buf, pkt_size); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     if (packet_type < 0) { | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |         trace_dp8393x_receive_not_netcard(); | 
					
						
							| 
									
										
										
										
											2009-05-18 13:40:55 +01:00
										 |  |  |         return -1; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Check for EOL */ | 
					
						
							| 
									
										
										
										
											2020-01-20 09:59:21 +11:00
										 |  |  |     if (s->regs[SONIC_LLFA] & SONIC_DESC_EOL) { | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         /* Are we still in resource exhaustion? */ | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |         s->regs[SONIC_LLFA] = dp8393x_get(s, dp8393x_crda(s), 5); | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         if (s->regs[SONIC_LLFA] & SONIC_DESC_EOL) { | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |             /* Still EOL ; stop reception */ | 
					
						
							| 
									
										
										
										
											2009-05-18 13:40:55 +01:00
										 |  |  |             return -1; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         /* Link has been updated by host */ | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /* Clear in_use */ | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |         dp8393x_put(s, dp8393x_crda(s), 6, 0x0000); | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /* Move to next descriptor */ | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA]; | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         s->regs[SONIC_ISR] |= SONIC_ISR_PKTRX; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Save current position */ | 
					
						
							|  |  |  |     s->regs[SONIC_TRBA1] = s->regs[SONIC_CRBA1]; | 
					
						
							|  |  |  |     s->regs[SONIC_TRBA0] = s->regs[SONIC_CRBA0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Calculate the ethernet checksum */ | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     checksum = cpu_to_le32(crc32(0, buf, pkt_size)); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Put packet into RBA */ | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |     trace_dp8393x_receive_packet(dp8393x_crba(s)); | 
					
						
							| 
									
										
										
										
											2017-01-09 18:43:57 +00:00
										 |  |  |     address = dp8393x_crba(s); | 
					
						
							| 
									
										
										
										
											2020-02-18 11:24:57 +00:00
										 |  |  |     address_space_write(&s->as, address, MEMTXATTRS_UNSPECIFIED, | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |                         buf, pkt_size); | 
					
						
							|  |  |  |     address += pkt_size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Put frame checksum into RBA */ | 
					
						
							| 
									
										
										
										
											2020-02-18 11:24:57 +00:00
										 |  |  |     address_space_write(&s->as, address, MEMTXATTRS_UNSPECIFIED, | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |                         &checksum, sizeof(checksum)); | 
					
						
							|  |  |  |     address += sizeof(checksum); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Pad short packets to keep pointers aligned */ | 
					
						
							|  |  |  |     if (rx_len < padded_len) { | 
					
						
							|  |  |  |         size = padded_len - rx_len; | 
					
						
							| 
									
										
										
										
											2021-07-03 15:38:33 +02:00
										 |  |  |         address_space_write(&s->as, address, MEMTXATTRS_UNSPECIFIED, | 
					
						
							|  |  |  |                             "\xFF\xFF\xFF", size); | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         address += size; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     s->regs[SONIC_CRBA1] = address >> 16; | 
					
						
							|  |  |  |     s->regs[SONIC_CRBA0] = address & 0xffff; | 
					
						
							| 
									
										
										
										
											2017-01-09 18:43:57 +00:00
										 |  |  |     available = dp8393x_rbwc(s); | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     available -= padded_len >> 1; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     s->regs[SONIC_RBWC1] = available >> 16; | 
					
						
							|  |  |  |     s->regs[SONIC_RBWC0] = available & 0xffff; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Update status */ | 
					
						
							| 
									
										
										
										
											2017-01-09 18:43:57 +00:00
										 |  |  |     if (dp8393x_rbwc(s) < s->regs[SONIC_EOBC]) { | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         s->regs[SONIC_RCR] |= SONIC_RCR_LPKT; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     s->regs[SONIC_RCR] |= packet_type; | 
					
						
							|  |  |  |     s->regs[SONIC_RCR] |= SONIC_RCR_PRX; | 
					
						
							|  |  |  |     if (s->loopback_packet) { | 
					
						
							|  |  |  |         s->regs[SONIC_RCR] |= SONIC_RCR_LBK; | 
					
						
							|  |  |  |         s->loopback_packet = 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Write status to memory */ | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:53 +01:00
										 |  |  |     trace_dp8393x_receive_write_status(dp8393x_crda(s)); | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |     dp8393x_put(s, dp8393x_crda(s), 0, s->regs[SONIC_RCR]); /* status */ | 
					
						
							|  |  |  |     dp8393x_put(s, dp8393x_crda(s), 1, rx_len); /* byte count */ | 
					
						
							|  |  |  |     dp8393x_put(s, dp8393x_crda(s), 2, s->regs[SONIC_TRBA0]); /* pkt_ptr0 */ | 
					
						
							|  |  |  |     dp8393x_put(s, dp8393x_crda(s), 3, s->regs[SONIC_TRBA1]); /* pkt_ptr1 */ | 
					
						
							|  |  |  |     dp8393x_put(s, dp8393x_crda(s), 4, s->regs[SONIC_RSC]); /* seq_no */ | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     /* Check link field */ | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |     s->regs[SONIC_LLFA] = dp8393x_get(s, dp8393x_crda(s), 5); | 
					
						
							| 
									
										
										
										
											2020-01-20 09:59:21 +11:00
										 |  |  |     if (s->regs[SONIC_LLFA] & SONIC_DESC_EOL) { | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         /* EOL detected */ | 
					
						
							|  |  |  |         s->regs[SONIC_ISR] |= SONIC_ISR_RDE; | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         /* Clear in_use */ | 
					
						
							| 
									
										
										
										
											2021-07-03 15:44:33 +02:00
										 |  |  |         dp8393x_put(s, dp8393x_crda(s), 6, 0x0000); | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /* Move to next descriptor */ | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |         s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA]; | 
					
						
							|  |  |  |         s->regs[SONIC_ISR] |= SONIC_ISR_PKTRX; | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     dp8393x_update_irq(s); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     s->regs[SONIC_RSC] = (s->regs[SONIC_RSC] & 0xff00) | | 
					
						
							|  |  |  |                          ((s->regs[SONIC_RSC] + 1) & 0x00ff); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  | done: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     if (s->regs[SONIC_RCR] & SONIC_RCR_LPKT) { | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |         if (s->regs[SONIC_RRP] == s->regs[SONIC_RWP]) { | 
					
						
							|  |  |  |             /* Stop packet reception */ | 
					
						
							|  |  |  |             s->last_rba_is_full = true; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             /* Read next resource */ | 
					
						
							|  |  |  |             dp8393x_do_read_rra(s); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     return pkt_size; | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  | static void dp8393x_reset(DeviceState *dev) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  |     dp8393xState *s = DP8393X(dev); | 
					
						
							| 
									
										
										
										
											2013-08-21 16:03:08 +01:00
										 |  |  |     timer_del(s->watchdog); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:49 +02:00
										 |  |  |     memset(s->regs, 0, sizeof(s->regs)); | 
					
						
							| 
									
										
										
										
											2020-01-29 20:27:49 +11:00
										 |  |  |     s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux/mips */ | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     s->regs[SONIC_CR] = SONIC_CR_RST | SONIC_CR_STP | SONIC_CR_RXDIS; | 
					
						
							|  |  |  |     s->regs[SONIC_DCR] &= ~(SONIC_DCR_EXBUS | SONIC_DCR_LBR); | 
					
						
							| 
									
										
										
										
											2021-06-25 07:53:52 +01:00
										 |  |  |     s->regs[SONIC_RCR] &= ~(SONIC_RCR_LB0 | SONIC_RCR_LB1 | SONIC_RCR_BRD | | 
					
						
							|  |  |  |                             SONIC_RCR_RNT); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  |     s->regs[SONIC_TCR] |= SONIC_TCR_NCRS | SONIC_TCR_PTX; | 
					
						
							|  |  |  |     s->regs[SONIC_TCR] &= ~SONIC_TCR_BCM; | 
					
						
							|  |  |  |     s->regs[SONIC_IMR] = 0; | 
					
						
							|  |  |  |     s->regs[SONIC_ISR] = 0; | 
					
						
							|  |  |  |     s->regs[SONIC_DCR2] = 0; | 
					
						
							|  |  |  |     s->regs[SONIC_EOBC] = 0x02F8; | 
					
						
							|  |  |  |     s->regs[SONIC_RSC] = 0; | 
					
						
							|  |  |  |     s->regs[SONIC_CE] = 0; | 
					
						
							|  |  |  |     s->regs[SONIC_RSC] = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Network cable is connected */ | 
					
						
							|  |  |  |     s->regs[SONIC_RCR] |= SONIC_RCR_CRS; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dp8393x_update_irq(s); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-25 18:49:17 +00:00
										 |  |  | static NetClientInfo net_dp83932_info = { | 
					
						
							| 
									
										
											  
											
												qapi: Change Netdev into a flat union
This is a mostly-mechanical conversion that creates a new flat
union 'Netdev' QAPI type that covers all the branches of the
former 'NetClientOptions' simple union, where the branches are
now listed in a new 'NetClientDriver' enum rather than generated
from the simple union.  The existence of a flat union has no
change to the command line syntax accepted for new code, and
will make it possible for a future patch to switch the QMP
command to parse a boxed union for no change to valid QMP; but
it does have some ripple effect on the C code when dealing with
the new types.
While making the conversion, note that the 'NetLegacy' type
remains unchanged: it applies only to legacy command line options,
and will not be ported to QMP, so it should remain a wrapper
around a simple union; to avoid confusion, the type named
'NetClientOptions' is now gone, and we introduce 'NetLegacyOptions'
in its place.  Then, in the C code, we convert from NetLegacy to
Netdev as soon as possible, so that the bulk of the net stack
only has to deal with one QAPI type, not two.  Note that since
the old legacy code always rejected 'hubport', we can just omit
that branch from the new 'NetLegacyOptions' simple union.
Based on an idea originally by Zoltán Kővágó <DirtY.iCE.hu@gmail.com>:
Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com>
although the sed script in that patch no longer applies due to
other changes in the tree since then, and I also did some manual
cleanups (such as fixing whitespace to keep checkpatch happy).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Fixup from Eric squashed in]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
											
										 
											2016-07-13 21:50:23 -06:00
										 |  |  |     .type = NET_CLIENT_DRIVER_NIC, | 
					
						
							| 
									
										
										
										
											2009-11-25 18:49:17 +00:00
										 |  |  |     .size = sizeof(NICState), | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:44 +02:00
										 |  |  |     .can_receive = dp8393x_can_receive, | 
					
						
							|  |  |  |     .receive = dp8393x_receive, | 
					
						
							| 
									
										
										
										
											2009-11-25 18:49:17 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  | static void dp8393x_instance_init(Object *obj) | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  |     SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | 
					
						
							|  |  |  |     dp8393xState *s = DP8393X(obj); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  |     sysbus_init_mmio(sbd, &s->mmio); | 
					
						
							|  |  |  |     sysbus_init_irq(sbd, &s->irq); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dp8393x_realize(DeviceState *dev, Error **errp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     dp8393xState *s = DP8393X(dev); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  |     address_space_init(&s->as, s->dma_mr, "dp8393x"); | 
					
						
							|  |  |  |     memory_region_init_io(&s->mmio, OBJECT(dev), &dp8393x_ops, s, | 
					
						
							| 
									
										
										
										
											2021-07-08 00:30:46 +02:00
										 |  |  |                           "dp8393x-regs", SONIC_REG_COUNT << s->it_shift); | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     s->nic = qemu_new_nic(&net_dp83932_info, &s->conf, | 
					
						
							|  |  |  |                           object_get_typename(OBJECT(dev)), dev->id, s); | 
					
						
							|  |  |  |     qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-21 16:03:08 +01:00
										 |  |  |     s->watchdog = timer_new_ns(QEMU_CLOCK_VIRTUAL, dp8393x_watchdog, s); | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:47 +02:00
										 |  |  | static const VMStateDescription vmstate_dp8393x = { | 
					
						
							|  |  |  |     .name = "dp8393x", | 
					
						
							| 
									
										
										
										
											2021-07-03 15:42:51 +02:00
										 |  |  |     .version_id = 1, | 
					
						
							|  |  |  |     .minimum_version_id = 1, | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:47 +02:00
										 |  |  |     .fields = (VMStateField []) { | 
					
						
							| 
									
										
										
										
											2021-07-03 15:42:51 +02:00
										 |  |  |         VMSTATE_UINT16_2DARRAY(cam, dp8393xState, 16, 3), | 
					
						
							| 
									
										
										
										
											2021-07-08 00:30:46 +02:00
										 |  |  |         VMSTATE_UINT16_ARRAY(regs, dp8393xState, SONIC_REG_COUNT), | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:47 +02:00
										 |  |  |         VMSTATE_END_OF_LIST() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  | static Property dp8393x_properties[] = { | 
					
						
							|  |  |  |     DEFINE_NIC_PROPERTIES(dp8393xState, conf), | 
					
						
							| 
									
										
										
										
											2019-10-17 18:03:43 +02:00
										 |  |  |     DEFINE_PROP_LINK("dma_mr", dp8393xState, dma_mr, | 
					
						
							|  |  |  |                      TYPE_MEMORY_REGION, MemoryRegion *), | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  |     DEFINE_PROP_UINT8("it_shift", dp8393xState, it_shift, 0), | 
					
						
							| 
									
										
										
										
											2019-10-26 18:45:39 +02:00
										 |  |  |     DEFINE_PROP_BOOL("big_endian", dp8393xState, big_endian, false), | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-11-25 18:49:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  | static void dp8393x_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  |     set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); | 
					
						
							|  |  |  |     dc->realize = dp8393x_realize; | 
					
						
							|  |  |  |     dc->reset = dp8393x_reset; | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:47 +02:00
										 |  |  |     dc->vmsd = &vmstate_dp8393x; | 
					
						
							| 
									
										
										
										
											2020-01-10 19:30:32 +04:00
										 |  |  |     device_class_set_props(dc, dp8393x_properties); | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  | static const TypeInfo dp8393x_info = { | 
					
						
							|  |  |  |     .name          = TYPE_DP8393X, | 
					
						
							|  |  |  |     .parent        = TYPE_SYS_BUS_DEVICE, | 
					
						
							|  |  |  |     .instance_size = sizeof(dp8393xState), | 
					
						
							|  |  |  |     .instance_init = dp8393x_instance_init, | 
					
						
							|  |  |  |     .class_init    = dp8393x_class_init, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dp8393x_register_types(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     type_register_static(&dp8393x_info); | 
					
						
							| 
									
										
										
										
											2009-04-15 14:57:54 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-06-03 22:45:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | type_init(dp8393x_register_types) |