root / hw / rtl8139.c @ beb811bd
History | View | Annotate | Download (100 kB)
1 | a41b2ff2 | pbrook | /**
|
---|---|---|---|
2 | a41b2ff2 | pbrook | * QEMU RTL8139 emulation
|
3 | a41b2ff2 | pbrook | *
|
4 | a41b2ff2 | pbrook | * Copyright (c) 2006 Igor Kovalenko
|
5 | a41b2ff2 | pbrook | *
|
6 | a41b2ff2 | pbrook | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | a41b2ff2 | pbrook | * of this software and associated documentation files (the "Software"), to deal
|
8 | a41b2ff2 | pbrook | * in the Software without restriction, including without limitation the rights
|
9 | a41b2ff2 | pbrook | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | a41b2ff2 | pbrook | * copies of the Software, and to permit persons to whom the Software is
|
11 | a41b2ff2 | pbrook | * furnished to do so, subject to the following conditions:
|
12 | a41b2ff2 | pbrook | *
|
13 | a41b2ff2 | pbrook | * The above copyright notice and this permission notice shall be included in
|
14 | a41b2ff2 | pbrook | * all copies or substantial portions of the Software.
|
15 | a41b2ff2 | pbrook | *
|
16 | a41b2ff2 | pbrook | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | a41b2ff2 | pbrook | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | a41b2ff2 | pbrook | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | a41b2ff2 | pbrook | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | a41b2ff2 | pbrook | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | a41b2ff2 | pbrook | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | a41b2ff2 | pbrook | * THE SOFTWARE.
|
23 | a41b2ff2 | pbrook |
|
24 | a41b2ff2 | pbrook | * Modifications:
|
25 | a41b2ff2 | pbrook | * 2006-Jan-28 Mark Malakanov : TSAD and CSCR implementation (for Windows driver)
|
26 | 6cadb320 | bellard | *
|
27 | 6cadb320 | bellard | * 2006-Apr-28 Juergen Lock : EEPROM emulation changes for FreeBSD driver
|
28 | 6cadb320 | bellard | * HW revision ID changes for FreeBSD driver
|
29 | 6cadb320 | bellard | *
|
30 | 6cadb320 | bellard | * 2006-Jul-01 Igor Kovalenko : Implemented loopback mode for FreeBSD driver
|
31 | 6cadb320 | bellard | * Corrected packet transfer reassembly routine for 8139C+ mode
|
32 | 6cadb320 | bellard | * Rearranged debugging print statements
|
33 | 6cadb320 | bellard | * Implemented PCI timer interrupt (disabled by default)
|
34 | 6cadb320 | bellard | * Implemented Tally Counters, increased VM load/save version
|
35 | 6cadb320 | bellard | * Implemented IP/TCP/UDP checksum task offloading
|
36 | 718da2b9 | bellard | *
|
37 | 718da2b9 | bellard | * 2006-Jul-04 Igor Kovalenko : Implemented TCP segmentation offloading
|
38 | 718da2b9 | bellard | * Fixed MTU=1500 for produced ethernet frames
|
39 | 718da2b9 | bellard | *
|
40 | 718da2b9 | bellard | * 2006-Jul-09 Igor Kovalenko : Fixed TCP header length calculation while processing
|
41 | 718da2b9 | bellard | * segmentation offloading
|
42 | 718da2b9 | bellard | * Removed slirp.h dependency
|
43 | 718da2b9 | bellard | * Added rx/tx buffer reset when enabling rx/tx operation
|
44 | a41b2ff2 | pbrook | */
|
45 | a41b2ff2 | pbrook | |
46 | a41b2ff2 | pbrook | #include "vl.h" |
47 | a41b2ff2 | pbrook | |
48 | a41b2ff2 | pbrook | /* debug RTL8139 card */
|
49 | a41b2ff2 | pbrook | //#define DEBUG_RTL8139 1
|
50 | a41b2ff2 | pbrook | |
51 | 6cadb320 | bellard | #define PCI_FREQUENCY 33000000L |
52 | 6cadb320 | bellard | |
53 | a41b2ff2 | pbrook | /* debug RTL8139 card C+ mode only */
|
54 | a41b2ff2 | pbrook | //#define DEBUG_RTL8139CP 1
|
55 | a41b2ff2 | pbrook | |
56 | a41b2ff2 | pbrook | /* RTL8139 provides frame CRC with received packet, this feature seems to be
|
57 | a41b2ff2 | pbrook | ignored by most drivers, disabled by default */
|
58 | a41b2ff2 | pbrook | //#define RTL8139_CALCULATE_RXCRC 1
|
59 | a41b2ff2 | pbrook | |
60 | 6cadb320 | bellard | /* Uncomment to enable on-board timer interrupts */
|
61 | 6cadb320 | bellard | //#define RTL8139_ONBOARD_TIMER 1
|
62 | a41b2ff2 | pbrook | |
63 | a41b2ff2 | pbrook | #if defined(RTL8139_CALCULATE_RXCRC)
|
64 | a41b2ff2 | pbrook | /* For crc32 */
|
65 | a41b2ff2 | pbrook | #include <zlib.h> |
66 | a41b2ff2 | pbrook | #endif
|
67 | a41b2ff2 | pbrook | |
68 | a41b2ff2 | pbrook | #define SET_MASKED(input, mask, curr) \
|
69 | a41b2ff2 | pbrook | ( ( (input) & ~(mask) ) | ( (curr) & (mask) ) ) |
70 | a41b2ff2 | pbrook | |
71 | a41b2ff2 | pbrook | /* arg % size for size which is a power of 2 */
|
72 | a41b2ff2 | pbrook | #define MOD2(input, size) \
|
73 | a41b2ff2 | pbrook | ( ( input ) & ( size - 1 ) )
|
74 | a41b2ff2 | pbrook | |
75 | 6cadb320 | bellard | #if defined (DEBUG_RTL8139)
|
76 | 6cadb320 | bellard | # define DEBUG_PRINT(x) do { printf x ; } while (0) |
77 | 6cadb320 | bellard | #else
|
78 | 6cadb320 | bellard | # define DEBUG_PRINT(x)
|
79 | 6cadb320 | bellard | #endif
|
80 | 6cadb320 | bellard | |
81 | a41b2ff2 | pbrook | /* Symbolic offsets to registers. */
|
82 | a41b2ff2 | pbrook | enum RTL8139_registers {
|
83 | a41b2ff2 | pbrook | MAC0 = 0, /* Ethernet hardware address. */ |
84 | a41b2ff2 | pbrook | MAR0 = 8, /* Multicast filter. */ |
85 | 6cadb320 | bellard | TxStatus0 = 0x10,/* Transmit status (Four 32bit registers). C mode only */ |
86 | 6cadb320 | bellard | /* Dump Tally Conter control register(64bit). C+ mode only */
|
87 | 6cadb320 | bellard | TxAddr0 = 0x20, /* Tx descriptors (also four 32bit). */ |
88 | a41b2ff2 | pbrook | RxBuf = 0x30,
|
89 | a41b2ff2 | pbrook | ChipCmd = 0x37,
|
90 | a41b2ff2 | pbrook | RxBufPtr = 0x38,
|
91 | a41b2ff2 | pbrook | RxBufAddr = 0x3A,
|
92 | a41b2ff2 | pbrook | IntrMask = 0x3C,
|
93 | a41b2ff2 | pbrook | IntrStatus = 0x3E,
|
94 | a41b2ff2 | pbrook | TxConfig = 0x40,
|
95 | a41b2ff2 | pbrook | RxConfig = 0x44,
|
96 | a41b2ff2 | pbrook | Timer = 0x48, /* A general-purpose counter. */ |
97 | a41b2ff2 | pbrook | RxMissed = 0x4C, /* 24 bits valid, write clears. */ |
98 | a41b2ff2 | pbrook | Cfg9346 = 0x50,
|
99 | a41b2ff2 | pbrook | Config0 = 0x51,
|
100 | a41b2ff2 | pbrook | Config1 = 0x52,
|
101 | a41b2ff2 | pbrook | FlashReg = 0x54,
|
102 | a41b2ff2 | pbrook | MediaStatus = 0x58,
|
103 | a41b2ff2 | pbrook | Config3 = 0x59,
|
104 | a41b2ff2 | pbrook | Config4 = 0x5A, /* absent on RTL-8139A */ |
105 | a41b2ff2 | pbrook | HltClk = 0x5B,
|
106 | a41b2ff2 | pbrook | MultiIntr = 0x5C,
|
107 | a41b2ff2 | pbrook | PCIRevisionID = 0x5E,
|
108 | a41b2ff2 | pbrook | TxSummary = 0x60, /* TSAD register. Transmit Status of All Descriptors*/ |
109 | a41b2ff2 | pbrook | BasicModeCtrl = 0x62,
|
110 | a41b2ff2 | pbrook | BasicModeStatus = 0x64,
|
111 | a41b2ff2 | pbrook | NWayAdvert = 0x66,
|
112 | a41b2ff2 | pbrook | NWayLPAR = 0x68,
|
113 | a41b2ff2 | pbrook | NWayExpansion = 0x6A,
|
114 | a41b2ff2 | pbrook | /* Undocumented registers, but required for proper operation. */
|
115 | a41b2ff2 | pbrook | FIFOTMS = 0x70, /* FIFO Control and test. */ |
116 | a41b2ff2 | pbrook | CSCR = 0x74, /* Chip Status and Configuration Register. */ |
117 | a41b2ff2 | pbrook | PARA78 = 0x78,
|
118 | a41b2ff2 | pbrook | PARA7c = 0x7c, /* Magic transceiver parameter register. */ |
119 | a41b2ff2 | pbrook | Config5 = 0xD8, /* absent on RTL-8139A */ |
120 | a41b2ff2 | pbrook | /* C+ mode */
|
121 | a41b2ff2 | pbrook | TxPoll = 0xD9, /* Tell chip to check Tx descriptors for work */ |
122 | a41b2ff2 | pbrook | RxMaxSize = 0xDA, /* Max size of an Rx packet (8169 only) */ |
123 | a41b2ff2 | pbrook | CpCmd = 0xE0, /* C+ Command register (C+ mode only) */ |
124 | a41b2ff2 | pbrook | IntrMitigate = 0xE2, /* rx/tx interrupt mitigation control */ |
125 | a41b2ff2 | pbrook | RxRingAddrLO = 0xE4, /* 64-bit start addr of Rx ring */ |
126 | a41b2ff2 | pbrook | RxRingAddrHI = 0xE8, /* 64-bit start addr of Rx ring */ |
127 | a41b2ff2 | pbrook | TxThresh = 0xEC, /* Early Tx threshold */ |
128 | a41b2ff2 | pbrook | }; |
129 | a41b2ff2 | pbrook | |
130 | a41b2ff2 | pbrook | enum ClearBitMasks {
|
131 | a41b2ff2 | pbrook | MultiIntrClear = 0xF000,
|
132 | a41b2ff2 | pbrook | ChipCmdClear = 0xE2,
|
133 | a41b2ff2 | pbrook | Config1Clear = (1<<7)|(1<<6)|(1<<3)|(1<<2)|(1<<1), |
134 | a41b2ff2 | pbrook | }; |
135 | a41b2ff2 | pbrook | |
136 | a41b2ff2 | pbrook | enum ChipCmdBits {
|
137 | a41b2ff2 | pbrook | CmdReset = 0x10,
|
138 | a41b2ff2 | pbrook | CmdRxEnb = 0x08,
|
139 | a41b2ff2 | pbrook | CmdTxEnb = 0x04,
|
140 | a41b2ff2 | pbrook | RxBufEmpty = 0x01,
|
141 | a41b2ff2 | pbrook | }; |
142 | a41b2ff2 | pbrook | |
143 | a41b2ff2 | pbrook | /* C+ mode */
|
144 | a41b2ff2 | pbrook | enum CplusCmdBits {
|
145 | 6cadb320 | bellard | CPlusRxVLAN = 0x0040, /* enable receive VLAN detagging */ |
146 | 6cadb320 | bellard | CPlusRxChkSum = 0x0020, /* enable receive checksum offloading */ |
147 | 6cadb320 | bellard | CPlusRxEnb = 0x0002,
|
148 | 6cadb320 | bellard | CPlusTxEnb = 0x0001,
|
149 | a41b2ff2 | pbrook | }; |
150 | a41b2ff2 | pbrook | |
151 | a41b2ff2 | pbrook | /* Interrupt register bits, using my own meaningful names. */
|
152 | a41b2ff2 | pbrook | enum IntrStatusBits {
|
153 | a41b2ff2 | pbrook | PCIErr = 0x8000,
|
154 | a41b2ff2 | pbrook | PCSTimeout = 0x4000,
|
155 | a41b2ff2 | pbrook | RxFIFOOver = 0x40,
|
156 | a41b2ff2 | pbrook | RxUnderrun = 0x20,
|
157 | a41b2ff2 | pbrook | RxOverflow = 0x10,
|
158 | a41b2ff2 | pbrook | TxErr = 0x08,
|
159 | a41b2ff2 | pbrook | TxOK = 0x04,
|
160 | a41b2ff2 | pbrook | RxErr = 0x02,
|
161 | a41b2ff2 | pbrook | RxOK = 0x01,
|
162 | a41b2ff2 | pbrook | |
163 | a41b2ff2 | pbrook | RxAckBits = RxFIFOOver | RxOverflow | RxOK, |
164 | a41b2ff2 | pbrook | }; |
165 | a41b2ff2 | pbrook | |
166 | a41b2ff2 | pbrook | enum TxStatusBits {
|
167 | a41b2ff2 | pbrook | TxHostOwns = 0x2000,
|
168 | a41b2ff2 | pbrook | TxUnderrun = 0x4000,
|
169 | a41b2ff2 | pbrook | TxStatOK = 0x8000,
|
170 | a41b2ff2 | pbrook | TxOutOfWindow = 0x20000000,
|
171 | a41b2ff2 | pbrook | TxAborted = 0x40000000,
|
172 | a41b2ff2 | pbrook | TxCarrierLost = 0x80000000,
|
173 | a41b2ff2 | pbrook | }; |
174 | a41b2ff2 | pbrook | enum RxStatusBits {
|
175 | a41b2ff2 | pbrook | RxMulticast = 0x8000,
|
176 | a41b2ff2 | pbrook | RxPhysical = 0x4000,
|
177 | a41b2ff2 | pbrook | RxBroadcast = 0x2000,
|
178 | a41b2ff2 | pbrook | RxBadSymbol = 0x0020,
|
179 | a41b2ff2 | pbrook | RxRunt = 0x0010,
|
180 | a41b2ff2 | pbrook | RxTooLong = 0x0008,
|
181 | a41b2ff2 | pbrook | RxCRCErr = 0x0004,
|
182 | a41b2ff2 | pbrook | RxBadAlign = 0x0002,
|
183 | a41b2ff2 | pbrook | RxStatusOK = 0x0001,
|
184 | a41b2ff2 | pbrook | }; |
185 | a41b2ff2 | pbrook | |
186 | a41b2ff2 | pbrook | /* Bits in RxConfig. */
|
187 | a41b2ff2 | pbrook | enum rx_mode_bits {
|
188 | a41b2ff2 | pbrook | AcceptErr = 0x20,
|
189 | a41b2ff2 | pbrook | AcceptRunt = 0x10,
|
190 | a41b2ff2 | pbrook | AcceptBroadcast = 0x08,
|
191 | a41b2ff2 | pbrook | AcceptMulticast = 0x04,
|
192 | a41b2ff2 | pbrook | AcceptMyPhys = 0x02,
|
193 | a41b2ff2 | pbrook | AcceptAllPhys = 0x01,
|
194 | a41b2ff2 | pbrook | }; |
195 | a41b2ff2 | pbrook | |
196 | a41b2ff2 | pbrook | /* Bits in TxConfig. */
|
197 | a41b2ff2 | pbrook | enum tx_config_bits {
|
198 | a41b2ff2 | pbrook | |
199 | a41b2ff2 | pbrook | /* Interframe Gap Time. Only TxIFG96 doesn't violate IEEE 802.3 */
|
200 | a41b2ff2 | pbrook | TxIFGShift = 24,
|
201 | a41b2ff2 | pbrook | TxIFG84 = (0 << TxIFGShift), /* 8.4us / 840ns (10 / 100Mbps) */ |
202 | a41b2ff2 | pbrook | TxIFG88 = (1 << TxIFGShift), /* 8.8us / 880ns (10 / 100Mbps) */ |
203 | a41b2ff2 | pbrook | TxIFG92 = (2 << TxIFGShift), /* 9.2us / 920ns (10 / 100Mbps) */ |
204 | a41b2ff2 | pbrook | TxIFG96 = (3 << TxIFGShift), /* 9.6us / 960ns (10 / 100Mbps) */ |
205 | a41b2ff2 | pbrook | |
206 | a41b2ff2 | pbrook | TxLoopBack = (1 << 18) | (1 << 17), /* enable loopback test mode */ |
207 | a41b2ff2 | pbrook | TxCRC = (1 << 16), /* DISABLE appending CRC to end of Tx packets */ |
208 | a41b2ff2 | pbrook | TxClearAbt = (1 << 0), /* Clear abort (WO) */ |
209 | a41b2ff2 | pbrook | TxDMAShift = 8, /* DMA burst value (0-7) is shifted this many bits */ |
210 | a41b2ff2 | pbrook | TxRetryShift = 4, /* TXRR value (0-15) is shifted this many bits */ |
211 | a41b2ff2 | pbrook | |
212 | a41b2ff2 | pbrook | TxVersionMask = 0x7C800000, /* mask out version bits 30-26, 23 */ |
213 | a41b2ff2 | pbrook | }; |
214 | a41b2ff2 | pbrook | |
215 | a41b2ff2 | pbrook | |
216 | a41b2ff2 | pbrook | /* Transmit Status of All Descriptors (TSAD) Register */
|
217 | a41b2ff2 | pbrook | enum TSAD_bits {
|
218 | a41b2ff2 | pbrook | TSAD_TOK3 = 1<<15, // TOK bit of Descriptor 3 |
219 | a41b2ff2 | pbrook | TSAD_TOK2 = 1<<14, // TOK bit of Descriptor 2 |
220 | a41b2ff2 | pbrook | TSAD_TOK1 = 1<<13, // TOK bit of Descriptor 1 |
221 | a41b2ff2 | pbrook | TSAD_TOK0 = 1<<12, // TOK bit of Descriptor 0 |
222 | a41b2ff2 | pbrook | TSAD_TUN3 = 1<<11, // TUN bit of Descriptor 3 |
223 | a41b2ff2 | pbrook | TSAD_TUN2 = 1<<10, // TUN bit of Descriptor 2 |
224 | a41b2ff2 | pbrook | TSAD_TUN1 = 1<<9, // TUN bit of Descriptor 1 |
225 | a41b2ff2 | pbrook | TSAD_TUN0 = 1<<8, // TUN bit of Descriptor 0 |
226 | a41b2ff2 | pbrook | TSAD_TABT3 = 1<<07, // TABT bit of Descriptor 3 |
227 | a41b2ff2 | pbrook | TSAD_TABT2 = 1<<06, // TABT bit of Descriptor 2 |
228 | a41b2ff2 | pbrook | TSAD_TABT1 = 1<<05, // TABT bit of Descriptor 1 |
229 | a41b2ff2 | pbrook | TSAD_TABT0 = 1<<04, // TABT bit of Descriptor 0 |
230 | a41b2ff2 | pbrook | TSAD_OWN3 = 1<<03, // OWN bit of Descriptor 3 |
231 | a41b2ff2 | pbrook | TSAD_OWN2 = 1<<02, // OWN bit of Descriptor 2 |
232 | a41b2ff2 | pbrook | TSAD_OWN1 = 1<<01, // OWN bit of Descriptor 1 |
233 | a41b2ff2 | pbrook | TSAD_OWN0 = 1<<00, // OWN bit of Descriptor 0 |
234 | a41b2ff2 | pbrook | }; |
235 | a41b2ff2 | pbrook | |
236 | a41b2ff2 | pbrook | |
237 | a41b2ff2 | pbrook | /* Bits in Config1 */
|
238 | a41b2ff2 | pbrook | enum Config1Bits {
|
239 | a41b2ff2 | pbrook | Cfg1_PM_Enable = 0x01,
|
240 | a41b2ff2 | pbrook | Cfg1_VPD_Enable = 0x02,
|
241 | a41b2ff2 | pbrook | Cfg1_PIO = 0x04,
|
242 | a41b2ff2 | pbrook | Cfg1_MMIO = 0x08,
|
243 | a41b2ff2 | pbrook | LWAKE = 0x10, /* not on 8139, 8139A */ |
244 | a41b2ff2 | pbrook | Cfg1_Driver_Load = 0x20,
|
245 | a41b2ff2 | pbrook | Cfg1_LED0 = 0x40,
|
246 | a41b2ff2 | pbrook | Cfg1_LED1 = 0x80,
|
247 | a41b2ff2 | pbrook | SLEEP = (1 << 1), /* only on 8139, 8139A */ |
248 | a41b2ff2 | pbrook | PWRDN = (1 << 0), /* only on 8139, 8139A */ |
249 | a41b2ff2 | pbrook | }; |
250 | a41b2ff2 | pbrook | |
251 | a41b2ff2 | pbrook | /* Bits in Config3 */
|
252 | a41b2ff2 | pbrook | enum Config3Bits {
|
253 | a41b2ff2 | pbrook | Cfg3_FBtBEn = (1 << 0), /* 1 = Fast Back to Back */ |
254 | a41b2ff2 | pbrook | Cfg3_FuncRegEn = (1 << 1), /* 1 = enable CardBus Function registers */ |
255 | a41b2ff2 | pbrook | Cfg3_CLKRUN_En = (1 << 2), /* 1 = enable CLKRUN */ |
256 | a41b2ff2 | pbrook | Cfg3_CardB_En = (1 << 3), /* 1 = enable CardBus registers */ |
257 | a41b2ff2 | pbrook | Cfg3_LinkUp = (1 << 4), /* 1 = wake up on link up */ |
258 | a41b2ff2 | pbrook | Cfg3_Magic = (1 << 5), /* 1 = wake up on Magic Packet (tm) */ |
259 | a41b2ff2 | pbrook | Cfg3_PARM_En = (1 << 6), /* 0 = software can set twister parameters */ |
260 | a41b2ff2 | pbrook | Cfg3_GNTSel = (1 << 7), /* 1 = delay 1 clock from PCI GNT signal */ |
261 | a41b2ff2 | pbrook | }; |
262 | a41b2ff2 | pbrook | |
263 | a41b2ff2 | pbrook | /* Bits in Config4 */
|
264 | a41b2ff2 | pbrook | enum Config4Bits {
|
265 | a41b2ff2 | pbrook | LWPTN = (1 << 2), /* not on 8139, 8139A */ |
266 | a41b2ff2 | pbrook | }; |
267 | a41b2ff2 | pbrook | |
268 | a41b2ff2 | pbrook | /* Bits in Config5 */
|
269 | a41b2ff2 | pbrook | enum Config5Bits {
|
270 | a41b2ff2 | pbrook | Cfg5_PME_STS = (1 << 0), /* 1 = PCI reset resets PME_Status */ |
271 | a41b2ff2 | pbrook | Cfg5_LANWake = (1 << 1), /* 1 = enable LANWake signal */ |
272 | a41b2ff2 | pbrook | Cfg5_LDPS = (1 << 2), /* 0 = save power when link is down */ |
273 | a41b2ff2 | pbrook | Cfg5_FIFOAddrPtr = (1 << 3), /* Realtek internal SRAM testing */ |
274 | a41b2ff2 | pbrook | Cfg5_UWF = (1 << 4), /* 1 = accept unicast wakeup frame */ |
275 | a41b2ff2 | pbrook | Cfg5_MWF = (1 << 5), /* 1 = accept multicast wakeup frame */ |
276 | a41b2ff2 | pbrook | Cfg5_BWF = (1 << 6), /* 1 = accept broadcast wakeup frame */ |
277 | a41b2ff2 | pbrook | }; |
278 | a41b2ff2 | pbrook | |
279 | a41b2ff2 | pbrook | enum RxConfigBits {
|
280 | a41b2ff2 | pbrook | /* rx fifo threshold */
|
281 | a41b2ff2 | pbrook | RxCfgFIFOShift = 13,
|
282 | a41b2ff2 | pbrook | RxCfgFIFONone = (7 << RxCfgFIFOShift),
|
283 | a41b2ff2 | pbrook | |
284 | a41b2ff2 | pbrook | /* Max DMA burst */
|
285 | a41b2ff2 | pbrook | RxCfgDMAShift = 8,
|
286 | a41b2ff2 | pbrook | RxCfgDMAUnlimited = (7 << RxCfgDMAShift),
|
287 | a41b2ff2 | pbrook | |
288 | a41b2ff2 | pbrook | /* rx ring buffer length */
|
289 | a41b2ff2 | pbrook | RxCfgRcv8K = 0,
|
290 | a41b2ff2 | pbrook | RxCfgRcv16K = (1 << 11), |
291 | a41b2ff2 | pbrook | RxCfgRcv32K = (1 << 12), |
292 | a41b2ff2 | pbrook | RxCfgRcv64K = (1 << 11) | (1 << 12), |
293 | a41b2ff2 | pbrook | |
294 | a41b2ff2 | pbrook | /* Disable packet wrap at end of Rx buffer. (not possible with 64k) */
|
295 | a41b2ff2 | pbrook | RxNoWrap = (1 << 7), |
296 | a41b2ff2 | pbrook | }; |
297 | a41b2ff2 | pbrook | |
298 | a41b2ff2 | pbrook | /* Twister tuning parameters from RealTek.
|
299 | a41b2ff2 | pbrook | Completely undocumented, but required to tune bad links on some boards. */
|
300 | a41b2ff2 | pbrook | /*
|
301 | a41b2ff2 | pbrook | enum CSCRBits {
|
302 | a41b2ff2 | pbrook | CSCR_LinkOKBit = 0x0400,
|
303 | a41b2ff2 | pbrook | CSCR_LinkChangeBit = 0x0800,
|
304 | a41b2ff2 | pbrook | CSCR_LinkStatusBits = 0x0f000,
|
305 | a41b2ff2 | pbrook | CSCR_LinkDownOffCmd = 0x003c0,
|
306 | a41b2ff2 | pbrook | CSCR_LinkDownCmd = 0x0f3c0,
|
307 | a41b2ff2 | pbrook | */
|
308 | a41b2ff2 | pbrook | enum CSCRBits {
|
309 | a41b2ff2 | pbrook | CSCR_Testfun = 1<<15, /* 1 = Auto-neg speeds up internal timer, WO, def 0 */ |
310 | a41b2ff2 | pbrook | CSCR_LD = 1<<9, /* Active low TPI link disable signal. When low, TPI still transmits link pulses and TPI stays in good link state. def 1*/ |
311 | a41b2ff2 | pbrook | CSCR_HEART_BIT = 1<<8, /* 1 = HEART BEAT enable, 0 = HEART BEAT disable. HEART BEAT function is only valid in 10Mbps mode. def 1*/ |
312 | a41b2ff2 | pbrook | CSCR_JBEN = 1<<7, /* 1 = enable jabber function. 0 = disable jabber function, def 1*/ |
313 | a41b2ff2 | pbrook | CSCR_F_LINK_100 = 1<<6, /* Used to login force good link in 100Mbps for diagnostic purposes. 1 = DISABLE, 0 = ENABLE. def 1*/ |
314 | a41b2ff2 | pbrook | CSCR_F_Connect = 1<<5, /* Assertion of this bit forces the disconnect function to be bypassed. def 0*/ |
315 | a41b2ff2 | pbrook | CSCR_Con_status = 1<<3, /* This bit indicates the status of the connection. 1 = valid connected link detected; 0 = disconnected link detected. RO def 0*/ |
316 | a41b2ff2 | pbrook | CSCR_Con_status_En = 1<<2, /* Assertion of this bit configures LED1 pin to indicate connection status. def 0*/ |
317 | a41b2ff2 | pbrook | CSCR_PASS_SCR = 1<<0, /* Bypass Scramble, def 0*/ |
318 | a41b2ff2 | pbrook | }; |
319 | a41b2ff2 | pbrook | |
320 | a41b2ff2 | pbrook | enum Cfg9346Bits {
|
321 | a41b2ff2 | pbrook | Cfg9346_Lock = 0x00,
|
322 | a41b2ff2 | pbrook | Cfg9346_Unlock = 0xC0,
|
323 | a41b2ff2 | pbrook | }; |
324 | a41b2ff2 | pbrook | |
325 | a41b2ff2 | pbrook | typedef enum { |
326 | a41b2ff2 | pbrook | CH_8139 = 0,
|
327 | a41b2ff2 | pbrook | CH_8139_K, |
328 | a41b2ff2 | pbrook | CH_8139A, |
329 | a41b2ff2 | pbrook | CH_8139A_G, |
330 | a41b2ff2 | pbrook | CH_8139B, |
331 | a41b2ff2 | pbrook | CH_8130, |
332 | a41b2ff2 | pbrook | CH_8139C, |
333 | a41b2ff2 | pbrook | CH_8100, |
334 | a41b2ff2 | pbrook | CH_8100B_8139D, |
335 | a41b2ff2 | pbrook | CH_8101, |
336 | a41b2ff2 | pbrook | } chip_t; |
337 | a41b2ff2 | pbrook | |
338 | a41b2ff2 | pbrook | enum chip_flags {
|
339 | a41b2ff2 | pbrook | HasHltClk = (1 << 0), |
340 | a41b2ff2 | pbrook | HasLWake = (1 << 1), |
341 | a41b2ff2 | pbrook | }; |
342 | a41b2ff2 | pbrook | |
343 | a41b2ff2 | pbrook | #define HW_REVID(b30, b29, b28, b27, b26, b23, b22) \
|
344 | a41b2ff2 | pbrook | (b30<<30 | b29<<29 | b28<<28 | b27<<27 | b26<<26 | b23<<23 | b22<<22) |
345 | a41b2ff2 | pbrook | #define HW_REVID_MASK HW_REVID(1, 1, 1, 1, 1, 1, 1) |
346 | a41b2ff2 | pbrook | |
347 | 6cadb320 | bellard | #define RTL8139_PCI_REVID_8139 0x10 |
348 | 6cadb320 | bellard | #define RTL8139_PCI_REVID_8139CPLUS 0x20 |
349 | 6cadb320 | bellard | |
350 | 6cadb320 | bellard | #define RTL8139_PCI_REVID RTL8139_PCI_REVID_8139CPLUS
|
351 | 6cadb320 | bellard | |
352 | a41b2ff2 | pbrook | /* Size is 64 * 16bit words */
|
353 | a41b2ff2 | pbrook | #define EEPROM_9346_ADDR_BITS 6 |
354 | a41b2ff2 | pbrook | #define EEPROM_9346_SIZE (1 << EEPROM_9346_ADDR_BITS) |
355 | a41b2ff2 | pbrook | #define EEPROM_9346_ADDR_MASK (EEPROM_9346_SIZE - 1) |
356 | a41b2ff2 | pbrook | |
357 | a41b2ff2 | pbrook | enum Chip9346Operation
|
358 | a41b2ff2 | pbrook | { |
359 | a41b2ff2 | pbrook | Chip9346_op_mask = 0xc0, /* 10 zzzzzz */ |
360 | a41b2ff2 | pbrook | Chip9346_op_read = 0x80, /* 10 AAAAAA */ |
361 | a41b2ff2 | pbrook | Chip9346_op_write = 0x40, /* 01 AAAAAA D(15)..D(0) */ |
362 | a41b2ff2 | pbrook | Chip9346_op_ext_mask = 0xf0, /* 11 zzzzzz */ |
363 | a41b2ff2 | pbrook | Chip9346_op_write_enable = 0x30, /* 00 11zzzz */ |
364 | a41b2ff2 | pbrook | Chip9346_op_write_all = 0x10, /* 00 01zzzz */ |
365 | a41b2ff2 | pbrook | Chip9346_op_write_disable = 0x00, /* 00 00zzzz */ |
366 | a41b2ff2 | pbrook | }; |
367 | a41b2ff2 | pbrook | |
368 | a41b2ff2 | pbrook | enum Chip9346Mode
|
369 | a41b2ff2 | pbrook | { |
370 | a41b2ff2 | pbrook | Chip9346_none = 0,
|
371 | a41b2ff2 | pbrook | Chip9346_enter_command_mode, |
372 | a41b2ff2 | pbrook | Chip9346_read_command, |
373 | a41b2ff2 | pbrook | Chip9346_data_read, /* from output register */
|
374 | a41b2ff2 | pbrook | Chip9346_data_write, /* to input register, then to contents at specified address */
|
375 | a41b2ff2 | pbrook | Chip9346_data_write_all, /* to input register, then filling contents */
|
376 | a41b2ff2 | pbrook | }; |
377 | a41b2ff2 | pbrook | |
378 | a41b2ff2 | pbrook | typedef struct EEprom9346 |
379 | a41b2ff2 | pbrook | { |
380 | a41b2ff2 | pbrook | uint16_t contents[EEPROM_9346_SIZE]; |
381 | a41b2ff2 | pbrook | int mode;
|
382 | a41b2ff2 | pbrook | uint32_t tick; |
383 | a41b2ff2 | pbrook | uint8_t address; |
384 | a41b2ff2 | pbrook | uint16_t input; |
385 | a41b2ff2 | pbrook | uint16_t output; |
386 | a41b2ff2 | pbrook | |
387 | a41b2ff2 | pbrook | uint8_t eecs; |
388 | a41b2ff2 | pbrook | uint8_t eesk; |
389 | a41b2ff2 | pbrook | uint8_t eedi; |
390 | a41b2ff2 | pbrook | uint8_t eedo; |
391 | a41b2ff2 | pbrook | } EEprom9346; |
392 | a41b2ff2 | pbrook | |
393 | 6cadb320 | bellard | typedef struct RTL8139TallyCounters |
394 | 6cadb320 | bellard | { |
395 | 6cadb320 | bellard | /* Tally counters */
|
396 | 6cadb320 | bellard | uint64_t TxOk; |
397 | 6cadb320 | bellard | uint64_t RxOk; |
398 | 6cadb320 | bellard | uint64_t TxERR; |
399 | 6cadb320 | bellard | uint32_t RxERR; |
400 | 6cadb320 | bellard | uint16_t MissPkt; |
401 | 6cadb320 | bellard | uint16_t FAE; |
402 | 6cadb320 | bellard | uint32_t Tx1Col; |
403 | 6cadb320 | bellard | uint32_t TxMCol; |
404 | 6cadb320 | bellard | uint64_t RxOkPhy; |
405 | 6cadb320 | bellard | uint64_t RxOkBrd; |
406 | 6cadb320 | bellard | uint32_t RxOkMul; |
407 | 6cadb320 | bellard | uint16_t TxAbt; |
408 | 6cadb320 | bellard | uint16_t TxUndrn; |
409 | 6cadb320 | bellard | } RTL8139TallyCounters; |
410 | 6cadb320 | bellard | |
411 | 6cadb320 | bellard | /* Clears all tally counters */
|
412 | 6cadb320 | bellard | static void RTL8139TallyCounters_clear(RTL8139TallyCounters* counters); |
413 | 6cadb320 | bellard | |
414 | 6cadb320 | bellard | /* Writes tally counters to specified physical memory address */
|
415 | 6cadb320 | bellard | static void RTL8139TallyCounters_physical_memory_write(target_phys_addr_t tc_addr, RTL8139TallyCounters* counters); |
416 | 6cadb320 | bellard | |
417 | 6cadb320 | bellard | /* Loads values of tally counters from VM state file */
|
418 | 6cadb320 | bellard | static void RTL8139TallyCounters_load(QEMUFile* f, RTL8139TallyCounters *tally_counters); |
419 | 6cadb320 | bellard | |
420 | 6cadb320 | bellard | /* Saves values of tally counters to VM state file */
|
421 | 6cadb320 | bellard | static void RTL8139TallyCounters_save(QEMUFile* f, RTL8139TallyCounters *tally_counters); |
422 | 6cadb320 | bellard | |
423 | a41b2ff2 | pbrook | typedef struct RTL8139State { |
424 | a41b2ff2 | pbrook | uint8_t phys[8]; /* mac address */ |
425 | a41b2ff2 | pbrook | uint8_t mult[8]; /* multicast mask array */ |
426 | a41b2ff2 | pbrook | |
427 | 6cadb320 | bellard | uint32_t TxStatus[4]; /* TxStatus0 in C mode*/ /* also DTCCR[0] and DTCCR[1] in C+ mode */ |
428 | a41b2ff2 | pbrook | uint32_t TxAddr[4]; /* TxAddr0 */ |
429 | a41b2ff2 | pbrook | uint32_t RxBuf; /* Receive buffer */
|
430 | a41b2ff2 | pbrook | uint32_t RxBufferSize;/* internal variable, receive ring buffer size in C mode */
|
431 | a41b2ff2 | pbrook | uint32_t RxBufPtr; |
432 | a41b2ff2 | pbrook | uint32_t RxBufAddr; |
433 | a41b2ff2 | pbrook | |
434 | a41b2ff2 | pbrook | uint16_t IntrStatus; |
435 | a41b2ff2 | pbrook | uint16_t IntrMask; |
436 | a41b2ff2 | pbrook | |
437 | a41b2ff2 | pbrook | uint32_t TxConfig; |
438 | a41b2ff2 | pbrook | uint32_t RxConfig; |
439 | a41b2ff2 | pbrook | uint32_t RxMissed; |
440 | a41b2ff2 | pbrook | |
441 | a41b2ff2 | pbrook | uint16_t CSCR; |
442 | a41b2ff2 | pbrook | |
443 | a41b2ff2 | pbrook | uint8_t Cfg9346; |
444 | a41b2ff2 | pbrook | uint8_t Config0; |
445 | a41b2ff2 | pbrook | uint8_t Config1; |
446 | a41b2ff2 | pbrook | uint8_t Config3; |
447 | a41b2ff2 | pbrook | uint8_t Config4; |
448 | a41b2ff2 | pbrook | uint8_t Config5; |
449 | a41b2ff2 | pbrook | |
450 | a41b2ff2 | pbrook | uint8_t clock_enabled; |
451 | a41b2ff2 | pbrook | uint8_t bChipCmdState; |
452 | a41b2ff2 | pbrook | |
453 | a41b2ff2 | pbrook | uint16_t MultiIntr; |
454 | a41b2ff2 | pbrook | |
455 | a41b2ff2 | pbrook | uint16_t BasicModeCtrl; |
456 | a41b2ff2 | pbrook | uint16_t BasicModeStatus; |
457 | a41b2ff2 | pbrook | uint16_t NWayAdvert; |
458 | a41b2ff2 | pbrook | uint16_t NWayLPAR; |
459 | a41b2ff2 | pbrook | uint16_t NWayExpansion; |
460 | a41b2ff2 | pbrook | |
461 | a41b2ff2 | pbrook | uint16_t CpCmd; |
462 | a41b2ff2 | pbrook | uint8_t TxThresh; |
463 | a41b2ff2 | pbrook | |
464 | a41b2ff2 | pbrook | int irq;
|
465 | a41b2ff2 | pbrook | PCIDevice *pci_dev; |
466 | a41b2ff2 | pbrook | VLANClientState *vc; |
467 | a41b2ff2 | pbrook | uint8_t macaddr[6];
|
468 | a41b2ff2 | pbrook | int rtl8139_mmio_io_addr;
|
469 | a41b2ff2 | pbrook | |
470 | a41b2ff2 | pbrook | /* C ring mode */
|
471 | a41b2ff2 | pbrook | uint32_t currTxDesc; |
472 | a41b2ff2 | pbrook | |
473 | a41b2ff2 | pbrook | /* C+ mode */
|
474 | a41b2ff2 | pbrook | uint32_t currCPlusRxDesc; |
475 | a41b2ff2 | pbrook | uint32_t currCPlusTxDesc; |
476 | a41b2ff2 | pbrook | |
477 | a41b2ff2 | pbrook | uint32_t RxRingAddrLO; |
478 | a41b2ff2 | pbrook | uint32_t RxRingAddrHI; |
479 | a41b2ff2 | pbrook | |
480 | a41b2ff2 | pbrook | EEprom9346 eeprom; |
481 | 6cadb320 | bellard | |
482 | 6cadb320 | bellard | uint32_t TCTR; |
483 | 6cadb320 | bellard | uint32_t TimerInt; |
484 | 6cadb320 | bellard | int64_t TCTR_base; |
485 | 6cadb320 | bellard | |
486 | 6cadb320 | bellard | /* Tally counters */
|
487 | 6cadb320 | bellard | RTL8139TallyCounters tally_counters; |
488 | 6cadb320 | bellard | |
489 | 6cadb320 | bellard | /* Non-persistent data */
|
490 | 6cadb320 | bellard | uint8_t *cplus_txbuffer; |
491 | 6cadb320 | bellard | int cplus_txbuffer_len;
|
492 | 6cadb320 | bellard | int cplus_txbuffer_offset;
|
493 | 6cadb320 | bellard | |
494 | 6cadb320 | bellard | /* PCI interrupt timer */
|
495 | 6cadb320 | bellard | QEMUTimer *timer; |
496 | 6cadb320 | bellard | |
497 | a41b2ff2 | pbrook | } RTL8139State; |
498 | a41b2ff2 | pbrook | |
499 | a41b2ff2 | pbrook | void prom9346_decode_command(EEprom9346 *eeprom, uint8_t command)
|
500 | a41b2ff2 | pbrook | { |
501 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: eeprom command 0x%02x\n", command));
|
502 | a41b2ff2 | pbrook | |
503 | a41b2ff2 | pbrook | switch (command & Chip9346_op_mask)
|
504 | a41b2ff2 | pbrook | { |
505 | a41b2ff2 | pbrook | case Chip9346_op_read:
|
506 | a41b2ff2 | pbrook | { |
507 | a41b2ff2 | pbrook | eeprom->address = command & EEPROM_9346_ADDR_MASK; |
508 | a41b2ff2 | pbrook | eeprom->output = eeprom->contents[eeprom->address]; |
509 | a41b2ff2 | pbrook | eeprom->eedo = 0;
|
510 | a41b2ff2 | pbrook | eeprom->tick = 0;
|
511 | a41b2ff2 | pbrook | eeprom->mode = Chip9346_data_read; |
512 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: eeprom read from address 0x%02x data=0x%04x\n",
|
513 | 6cadb320 | bellard | eeprom->address, eeprom->output)); |
514 | a41b2ff2 | pbrook | } |
515 | a41b2ff2 | pbrook | break;
|
516 | a41b2ff2 | pbrook | |
517 | a41b2ff2 | pbrook | case Chip9346_op_write:
|
518 | a41b2ff2 | pbrook | { |
519 | a41b2ff2 | pbrook | eeprom->address = command & EEPROM_9346_ADDR_MASK; |
520 | a41b2ff2 | pbrook | eeprom->input = 0;
|
521 | a41b2ff2 | pbrook | eeprom->tick = 0;
|
522 | a41b2ff2 | pbrook | eeprom->mode = Chip9346_none; /* Chip9346_data_write */
|
523 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: eeprom begin write to address 0x%02x\n",
|
524 | 6cadb320 | bellard | eeprom->address)); |
525 | a41b2ff2 | pbrook | } |
526 | a41b2ff2 | pbrook | break;
|
527 | a41b2ff2 | pbrook | default:
|
528 | a41b2ff2 | pbrook | eeprom->mode = Chip9346_none; |
529 | a41b2ff2 | pbrook | switch (command & Chip9346_op_ext_mask)
|
530 | a41b2ff2 | pbrook | { |
531 | a41b2ff2 | pbrook | case Chip9346_op_write_enable:
|
532 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: eeprom write enabled\n"));
|
533 | a41b2ff2 | pbrook | break;
|
534 | a41b2ff2 | pbrook | case Chip9346_op_write_all:
|
535 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: eeprom begin write all\n"));
|
536 | a41b2ff2 | pbrook | break;
|
537 | a41b2ff2 | pbrook | case Chip9346_op_write_disable:
|
538 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: eeprom write disabled\n"));
|
539 | a41b2ff2 | pbrook | break;
|
540 | a41b2ff2 | pbrook | } |
541 | a41b2ff2 | pbrook | break;
|
542 | a41b2ff2 | pbrook | } |
543 | a41b2ff2 | pbrook | } |
544 | a41b2ff2 | pbrook | |
545 | a41b2ff2 | pbrook | void prom9346_shift_clock(EEprom9346 *eeprom)
|
546 | a41b2ff2 | pbrook | { |
547 | a41b2ff2 | pbrook | int bit = eeprom->eedi?1:0; |
548 | a41b2ff2 | pbrook | |
549 | a41b2ff2 | pbrook | ++ eeprom->tick; |
550 | a41b2ff2 | pbrook | |
551 | 6cadb320 | bellard | DEBUG_PRINT(("eeprom: tick %d eedi=%d eedo=%d\n", eeprom->tick, eeprom->eedi, eeprom->eedo));
|
552 | a41b2ff2 | pbrook | |
553 | a41b2ff2 | pbrook | switch (eeprom->mode)
|
554 | a41b2ff2 | pbrook | { |
555 | a41b2ff2 | pbrook | case Chip9346_enter_command_mode:
|
556 | a41b2ff2 | pbrook | if (bit)
|
557 | a41b2ff2 | pbrook | { |
558 | a41b2ff2 | pbrook | eeprom->mode = Chip9346_read_command; |
559 | a41b2ff2 | pbrook | eeprom->tick = 0;
|
560 | a41b2ff2 | pbrook | eeprom->input = 0;
|
561 | 6cadb320 | bellard | DEBUG_PRINT(("eeprom: +++ synchronized, begin command read\n"));
|
562 | a41b2ff2 | pbrook | } |
563 | a41b2ff2 | pbrook | break;
|
564 | a41b2ff2 | pbrook | |
565 | a41b2ff2 | pbrook | case Chip9346_read_command:
|
566 | a41b2ff2 | pbrook | eeprom->input = (eeprom->input << 1) | (bit & 1); |
567 | a41b2ff2 | pbrook | if (eeprom->tick == 8) |
568 | a41b2ff2 | pbrook | { |
569 | a41b2ff2 | pbrook | prom9346_decode_command(eeprom, eeprom->input & 0xff);
|
570 | a41b2ff2 | pbrook | } |
571 | a41b2ff2 | pbrook | break;
|
572 | a41b2ff2 | pbrook | |
573 | a41b2ff2 | pbrook | case Chip9346_data_read:
|
574 | a41b2ff2 | pbrook | eeprom->eedo = (eeprom->output & 0x8000)?1:0; |
575 | a41b2ff2 | pbrook | eeprom->output <<= 1;
|
576 | a41b2ff2 | pbrook | if (eeprom->tick == 16) |
577 | a41b2ff2 | pbrook | { |
578 | 6cadb320 | bellard | #if 1 |
579 | 6cadb320 | bellard | // the FreeBSD drivers (rl and re) don't explicitly toggle
|
580 | 6cadb320 | bellard | // CS between reads (or does setting Cfg9346 to 0 count too?),
|
581 | 6cadb320 | bellard | // so we need to enter wait-for-command state here
|
582 | 6cadb320 | bellard | eeprom->mode = Chip9346_enter_command_mode; |
583 | 6cadb320 | bellard | eeprom->input = 0;
|
584 | 6cadb320 | bellard | eeprom->tick = 0;
|
585 | 6cadb320 | bellard | |
586 | 6cadb320 | bellard | DEBUG_PRINT(("eeprom: +++ end of read, awaiting next command\n"));
|
587 | 6cadb320 | bellard | #else
|
588 | 6cadb320 | bellard | // original behaviour
|
589 | a41b2ff2 | pbrook | ++eeprom->address; |
590 | a41b2ff2 | pbrook | eeprom->address &= EEPROM_9346_ADDR_MASK; |
591 | a41b2ff2 | pbrook | eeprom->output = eeprom->contents[eeprom->address]; |
592 | a41b2ff2 | pbrook | eeprom->tick = 0;
|
593 | a41b2ff2 | pbrook | |
594 | 6cadb320 | bellard | DEBUG_PRINT(("eeprom: +++ read next address 0x%02x data=0x%04x\n",
|
595 | 6cadb320 | bellard | eeprom->address, eeprom->output)); |
596 | a41b2ff2 | pbrook | #endif
|
597 | a41b2ff2 | pbrook | } |
598 | a41b2ff2 | pbrook | break;
|
599 | a41b2ff2 | pbrook | |
600 | a41b2ff2 | pbrook | case Chip9346_data_write:
|
601 | a41b2ff2 | pbrook | eeprom->input = (eeprom->input << 1) | (bit & 1); |
602 | a41b2ff2 | pbrook | if (eeprom->tick == 16) |
603 | a41b2ff2 | pbrook | { |
604 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: eeprom write to address 0x%02x data=0x%04x\n",
|
605 | 6cadb320 | bellard | eeprom->address, eeprom->input)); |
606 | 6cadb320 | bellard | |
607 | a41b2ff2 | pbrook | eeprom->contents[eeprom->address] = eeprom->input; |
608 | a41b2ff2 | pbrook | eeprom->mode = Chip9346_none; /* waiting for next command after CS cycle */
|
609 | a41b2ff2 | pbrook | eeprom->tick = 0;
|
610 | a41b2ff2 | pbrook | eeprom->input = 0;
|
611 | a41b2ff2 | pbrook | } |
612 | a41b2ff2 | pbrook | break;
|
613 | a41b2ff2 | pbrook | |
614 | a41b2ff2 | pbrook | case Chip9346_data_write_all:
|
615 | a41b2ff2 | pbrook | eeprom->input = (eeprom->input << 1) | (bit & 1); |
616 | a41b2ff2 | pbrook | if (eeprom->tick == 16) |
617 | a41b2ff2 | pbrook | { |
618 | a41b2ff2 | pbrook | int i;
|
619 | a41b2ff2 | pbrook | for (i = 0; i < EEPROM_9346_SIZE; i++) |
620 | a41b2ff2 | pbrook | { |
621 | a41b2ff2 | pbrook | eeprom->contents[i] = eeprom->input; |
622 | a41b2ff2 | pbrook | } |
623 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: eeprom filled with data=0x%04x\n",
|
624 | 6cadb320 | bellard | eeprom->input)); |
625 | 6cadb320 | bellard | |
626 | a41b2ff2 | pbrook | eeprom->mode = Chip9346_enter_command_mode; |
627 | a41b2ff2 | pbrook | eeprom->tick = 0;
|
628 | a41b2ff2 | pbrook | eeprom->input = 0;
|
629 | a41b2ff2 | pbrook | } |
630 | a41b2ff2 | pbrook | break;
|
631 | a41b2ff2 | pbrook | |
632 | a41b2ff2 | pbrook | default:
|
633 | a41b2ff2 | pbrook | break;
|
634 | a41b2ff2 | pbrook | } |
635 | a41b2ff2 | pbrook | } |
636 | a41b2ff2 | pbrook | |
637 | a41b2ff2 | pbrook | int prom9346_get_wire(RTL8139State *s)
|
638 | a41b2ff2 | pbrook | { |
639 | a41b2ff2 | pbrook | EEprom9346 *eeprom = &s->eeprom; |
640 | a41b2ff2 | pbrook | if (!eeprom->eecs)
|
641 | a41b2ff2 | pbrook | return 0; |
642 | a41b2ff2 | pbrook | |
643 | a41b2ff2 | pbrook | return eeprom->eedo;
|
644 | a41b2ff2 | pbrook | } |
645 | a41b2ff2 | pbrook | |
646 | a41b2ff2 | pbrook | void prom9346_set_wire(RTL8139State *s, int eecs, int eesk, int eedi) |
647 | a41b2ff2 | pbrook | { |
648 | a41b2ff2 | pbrook | EEprom9346 *eeprom = &s->eeprom; |
649 | a41b2ff2 | pbrook | uint8_t old_eecs = eeprom->eecs; |
650 | a41b2ff2 | pbrook | uint8_t old_eesk = eeprom->eesk; |
651 | a41b2ff2 | pbrook | |
652 | a41b2ff2 | pbrook | eeprom->eecs = eecs; |
653 | a41b2ff2 | pbrook | eeprom->eesk = eesk; |
654 | a41b2ff2 | pbrook | eeprom->eedi = eedi; |
655 | a41b2ff2 | pbrook | |
656 | 6cadb320 | bellard | DEBUG_PRINT(("eeprom: +++ wires CS=%d SK=%d DI=%d DO=%d\n",
|
657 | 6cadb320 | bellard | eeprom->eecs, eeprom->eesk, eeprom->eedi, eeprom->eedo)); |
658 | a41b2ff2 | pbrook | |
659 | a41b2ff2 | pbrook | if (!old_eecs && eecs)
|
660 | a41b2ff2 | pbrook | { |
661 | a41b2ff2 | pbrook | /* Synchronize start */
|
662 | a41b2ff2 | pbrook | eeprom->tick = 0;
|
663 | a41b2ff2 | pbrook | eeprom->input = 0;
|
664 | a41b2ff2 | pbrook | eeprom->output = 0;
|
665 | a41b2ff2 | pbrook | eeprom->mode = Chip9346_enter_command_mode; |
666 | a41b2ff2 | pbrook | |
667 | 6cadb320 | bellard | DEBUG_PRINT(("=== eeprom: begin access, enter command mode\n"));
|
668 | a41b2ff2 | pbrook | } |
669 | a41b2ff2 | pbrook | |
670 | a41b2ff2 | pbrook | if (!eecs)
|
671 | a41b2ff2 | pbrook | { |
672 | 6cadb320 | bellard | DEBUG_PRINT(("=== eeprom: end access\n"));
|
673 | a41b2ff2 | pbrook | return;
|
674 | a41b2ff2 | pbrook | } |
675 | a41b2ff2 | pbrook | |
676 | a41b2ff2 | pbrook | if (!old_eesk && eesk)
|
677 | a41b2ff2 | pbrook | { |
678 | a41b2ff2 | pbrook | /* SK front rules */
|
679 | a41b2ff2 | pbrook | prom9346_shift_clock(eeprom); |
680 | a41b2ff2 | pbrook | } |
681 | a41b2ff2 | pbrook | } |
682 | a41b2ff2 | pbrook | |
683 | a41b2ff2 | pbrook | static void rtl8139_update_irq(RTL8139State *s) |
684 | a41b2ff2 | pbrook | { |
685 | a41b2ff2 | pbrook | int isr;
|
686 | a41b2ff2 | pbrook | isr = (s->IntrStatus & s->IntrMask) & 0xffff;
|
687 | 6cadb320 | bellard | |
688 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Set IRQ line %d to %d (%04x %04x)\n",
|
689 | 6cadb320 | bellard | s->irq, isr ? 1 : 0, s->IntrStatus, s->IntrMask)); |
690 | 6cadb320 | bellard | |
691 | a41b2ff2 | pbrook | if (s->irq == 16) { |
692 | a41b2ff2 | pbrook | /* PCI irq */
|
693 | a41b2ff2 | pbrook | pci_set_irq(s->pci_dev, 0, (isr != 0)); |
694 | a41b2ff2 | pbrook | } else {
|
695 | a41b2ff2 | pbrook | /* ISA irq */
|
696 | a41b2ff2 | pbrook | pic_set_irq(s->irq, (isr != 0));
|
697 | a41b2ff2 | pbrook | } |
698 | a41b2ff2 | pbrook | } |
699 | a41b2ff2 | pbrook | |
700 | a41b2ff2 | pbrook | #define POLYNOMIAL 0x04c11db6 |
701 | a41b2ff2 | pbrook | |
702 | a41b2ff2 | pbrook | /* From FreeBSD */
|
703 | a41b2ff2 | pbrook | /* XXX: optimize */
|
704 | a41b2ff2 | pbrook | static int compute_mcast_idx(const uint8_t *ep) |
705 | a41b2ff2 | pbrook | { |
706 | a41b2ff2 | pbrook | uint32_t crc; |
707 | a41b2ff2 | pbrook | int carry, i, j;
|
708 | a41b2ff2 | pbrook | uint8_t b; |
709 | a41b2ff2 | pbrook | |
710 | a41b2ff2 | pbrook | crc = 0xffffffff;
|
711 | a41b2ff2 | pbrook | for (i = 0; i < 6; i++) { |
712 | a41b2ff2 | pbrook | b = *ep++; |
713 | a41b2ff2 | pbrook | for (j = 0; j < 8; j++) { |
714 | a41b2ff2 | pbrook | carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01); |
715 | a41b2ff2 | pbrook | crc <<= 1;
|
716 | a41b2ff2 | pbrook | b >>= 1;
|
717 | a41b2ff2 | pbrook | if (carry)
|
718 | a41b2ff2 | pbrook | crc = ((crc ^ POLYNOMIAL) | carry); |
719 | a41b2ff2 | pbrook | } |
720 | a41b2ff2 | pbrook | } |
721 | a41b2ff2 | pbrook | return (crc >> 26); |
722 | a41b2ff2 | pbrook | } |
723 | a41b2ff2 | pbrook | |
724 | a41b2ff2 | pbrook | static int rtl8139_RxWrap(RTL8139State *s) |
725 | a41b2ff2 | pbrook | { |
726 | a41b2ff2 | pbrook | /* wrapping enabled; assume 1.5k more buffer space if size < 65536 */
|
727 | a41b2ff2 | pbrook | return (s->RxConfig & (1 << 7)); |
728 | a41b2ff2 | pbrook | } |
729 | a41b2ff2 | pbrook | |
730 | a41b2ff2 | pbrook | static int rtl8139_receiver_enabled(RTL8139State *s) |
731 | a41b2ff2 | pbrook | { |
732 | a41b2ff2 | pbrook | return s->bChipCmdState & CmdRxEnb;
|
733 | a41b2ff2 | pbrook | } |
734 | a41b2ff2 | pbrook | |
735 | a41b2ff2 | pbrook | static int rtl8139_transmitter_enabled(RTL8139State *s) |
736 | a41b2ff2 | pbrook | { |
737 | a41b2ff2 | pbrook | return s->bChipCmdState & CmdTxEnb;
|
738 | a41b2ff2 | pbrook | } |
739 | a41b2ff2 | pbrook | |
740 | a41b2ff2 | pbrook | static int rtl8139_cp_receiver_enabled(RTL8139State *s) |
741 | a41b2ff2 | pbrook | { |
742 | a41b2ff2 | pbrook | return s->CpCmd & CPlusRxEnb;
|
743 | a41b2ff2 | pbrook | } |
744 | a41b2ff2 | pbrook | |
745 | a41b2ff2 | pbrook | static int rtl8139_cp_transmitter_enabled(RTL8139State *s) |
746 | a41b2ff2 | pbrook | { |
747 | a41b2ff2 | pbrook | return s->CpCmd & CPlusTxEnb;
|
748 | a41b2ff2 | pbrook | } |
749 | a41b2ff2 | pbrook | |
750 | a41b2ff2 | pbrook | static void rtl8139_write_buffer(RTL8139State *s, const void *buf, int size) |
751 | a41b2ff2 | pbrook | { |
752 | a41b2ff2 | pbrook | if (s->RxBufAddr + size > s->RxBufferSize)
|
753 | a41b2ff2 | pbrook | { |
754 | a41b2ff2 | pbrook | int wrapped = MOD2(s->RxBufAddr + size, s->RxBufferSize);
|
755 | a41b2ff2 | pbrook | |
756 | a41b2ff2 | pbrook | /* write packet data */
|
757 | a41b2ff2 | pbrook | if (wrapped && s->RxBufferSize < 65536 && !rtl8139_RxWrap(s)) |
758 | a41b2ff2 | pbrook | { |
759 | 6cadb320 | bellard | DEBUG_PRINT((">>> RTL8139: rx packet wrapped in buffer at %d\n", size-wrapped));
|
760 | a41b2ff2 | pbrook | |
761 | a41b2ff2 | pbrook | if (size > wrapped)
|
762 | a41b2ff2 | pbrook | { |
763 | a41b2ff2 | pbrook | cpu_physical_memory_write( s->RxBuf + s->RxBufAddr, |
764 | a41b2ff2 | pbrook | buf, size-wrapped ); |
765 | a41b2ff2 | pbrook | } |
766 | a41b2ff2 | pbrook | |
767 | a41b2ff2 | pbrook | /* reset buffer pointer */
|
768 | a41b2ff2 | pbrook | s->RxBufAddr = 0;
|
769 | a41b2ff2 | pbrook | |
770 | a41b2ff2 | pbrook | cpu_physical_memory_write( s->RxBuf + s->RxBufAddr, |
771 | a41b2ff2 | pbrook | buf + (size-wrapped), wrapped ); |
772 | a41b2ff2 | pbrook | |
773 | a41b2ff2 | pbrook | s->RxBufAddr = wrapped; |
774 | a41b2ff2 | pbrook | |
775 | a41b2ff2 | pbrook | return;
|
776 | a41b2ff2 | pbrook | } |
777 | a41b2ff2 | pbrook | } |
778 | a41b2ff2 | pbrook | |
779 | a41b2ff2 | pbrook | /* non-wrapping path or overwrapping enabled */
|
780 | a41b2ff2 | pbrook | cpu_physical_memory_write( s->RxBuf + s->RxBufAddr, buf, size ); |
781 | a41b2ff2 | pbrook | |
782 | a41b2ff2 | pbrook | s->RxBufAddr += size; |
783 | a41b2ff2 | pbrook | } |
784 | a41b2ff2 | pbrook | |
785 | a41b2ff2 | pbrook | #define MIN_BUF_SIZE 60 |
786 | a41b2ff2 | pbrook | static inline target_phys_addr_t rtl8139_addr64(uint32_t low, uint32_t high) |
787 | a41b2ff2 | pbrook | { |
788 | a41b2ff2 | pbrook | #if TARGET_PHYS_ADDR_BITS > 32 |
789 | a41b2ff2 | pbrook | return low | ((target_phys_addr_t)high << 32); |
790 | a41b2ff2 | pbrook | #else
|
791 | a41b2ff2 | pbrook | return low;
|
792 | a41b2ff2 | pbrook | #endif
|
793 | a41b2ff2 | pbrook | } |
794 | a41b2ff2 | pbrook | |
795 | a41b2ff2 | pbrook | static int rtl8139_can_receive(void *opaque) |
796 | a41b2ff2 | pbrook | { |
797 | a41b2ff2 | pbrook | RTL8139State *s = opaque; |
798 | a41b2ff2 | pbrook | int avail;
|
799 | a41b2ff2 | pbrook | |
800 | a41b2ff2 | pbrook | /* Recieve (drop) packets if card is disabled. */
|
801 | a41b2ff2 | pbrook | if (!s->clock_enabled)
|
802 | a41b2ff2 | pbrook | return 1; |
803 | a41b2ff2 | pbrook | if (!rtl8139_receiver_enabled(s))
|
804 | a41b2ff2 | pbrook | return 1; |
805 | a41b2ff2 | pbrook | |
806 | a41b2ff2 | pbrook | if (rtl8139_cp_receiver_enabled(s)) {
|
807 | a41b2ff2 | pbrook | /* ??? Flow control not implemented in c+ mode.
|
808 | a41b2ff2 | pbrook | This is a hack to work around slirp deficiencies anyway. */
|
809 | a41b2ff2 | pbrook | return 1; |
810 | a41b2ff2 | pbrook | } else {
|
811 | a41b2ff2 | pbrook | avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, |
812 | a41b2ff2 | pbrook | s->RxBufferSize); |
813 | a41b2ff2 | pbrook | return (avail == 0 || avail >= 1514); |
814 | a41b2ff2 | pbrook | } |
815 | a41b2ff2 | pbrook | } |
816 | a41b2ff2 | pbrook | |
817 | 6cadb320 | bellard | static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int do_interrupt) |
818 | a41b2ff2 | pbrook | { |
819 | a41b2ff2 | pbrook | RTL8139State *s = opaque; |
820 | a41b2ff2 | pbrook | |
821 | a41b2ff2 | pbrook | uint32_t packet_header = 0;
|
822 | a41b2ff2 | pbrook | |
823 | a41b2ff2 | pbrook | uint8_t buf1[60];
|
824 | a41b2ff2 | pbrook | static const uint8_t broadcast_macaddr[6] = |
825 | a41b2ff2 | pbrook | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
826 | a41b2ff2 | pbrook | |
827 | 6cadb320 | bellard | DEBUG_PRINT((">>> RTL8139: received len=%d\n", size));
|
828 | a41b2ff2 | pbrook | |
829 | a41b2ff2 | pbrook | /* test if board clock is stopped */
|
830 | a41b2ff2 | pbrook | if (!s->clock_enabled)
|
831 | a41b2ff2 | pbrook | { |
832 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: stopped ==========================\n"));
|
833 | a41b2ff2 | pbrook | return;
|
834 | a41b2ff2 | pbrook | } |
835 | a41b2ff2 | pbrook | |
836 | a41b2ff2 | pbrook | /* first check if receiver is enabled */
|
837 | a41b2ff2 | pbrook | |
838 | a41b2ff2 | pbrook | if (!rtl8139_receiver_enabled(s))
|
839 | a41b2ff2 | pbrook | { |
840 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: receiver disabled ================\n"));
|
841 | a41b2ff2 | pbrook | return;
|
842 | a41b2ff2 | pbrook | } |
843 | a41b2ff2 | pbrook | |
844 | a41b2ff2 | pbrook | /* XXX: check this */
|
845 | a41b2ff2 | pbrook | if (s->RxConfig & AcceptAllPhys) {
|
846 | a41b2ff2 | pbrook | /* promiscuous: receive all */
|
847 | 6cadb320 | bellard | DEBUG_PRINT((">>> RTL8139: packet received in promiscuous mode\n"));
|
848 | a41b2ff2 | pbrook | |
849 | a41b2ff2 | pbrook | } else {
|
850 | a41b2ff2 | pbrook | if (!memcmp(buf, broadcast_macaddr, 6)) { |
851 | a41b2ff2 | pbrook | /* broadcast address */
|
852 | a41b2ff2 | pbrook | if (!(s->RxConfig & AcceptBroadcast))
|
853 | a41b2ff2 | pbrook | { |
854 | 6cadb320 | bellard | DEBUG_PRINT((">>> RTL8139: broadcast packet rejected\n"));
|
855 | 6cadb320 | bellard | |
856 | 6cadb320 | bellard | /* update tally counter */
|
857 | 6cadb320 | bellard | ++s->tally_counters.RxERR; |
858 | 6cadb320 | bellard | |
859 | a41b2ff2 | pbrook | return;
|
860 | a41b2ff2 | pbrook | } |
861 | a41b2ff2 | pbrook | |
862 | a41b2ff2 | pbrook | packet_header |= RxBroadcast; |
863 | a41b2ff2 | pbrook | |
864 | 6cadb320 | bellard | DEBUG_PRINT((">>> RTL8139: broadcast packet received\n"));
|
865 | 6cadb320 | bellard | |
866 | 6cadb320 | bellard | /* update tally counter */
|
867 | 6cadb320 | bellard | ++s->tally_counters.RxOkBrd; |
868 | 6cadb320 | bellard | |
869 | a41b2ff2 | pbrook | } else if (buf[0] & 0x01) { |
870 | a41b2ff2 | pbrook | /* multicast */
|
871 | a41b2ff2 | pbrook | if (!(s->RxConfig & AcceptMulticast))
|
872 | a41b2ff2 | pbrook | { |
873 | 6cadb320 | bellard | DEBUG_PRINT((">>> RTL8139: multicast packet rejected\n"));
|
874 | 6cadb320 | bellard | |
875 | 6cadb320 | bellard | /* update tally counter */
|
876 | 6cadb320 | bellard | ++s->tally_counters.RxERR; |
877 | 6cadb320 | bellard | |
878 | a41b2ff2 | pbrook | return;
|
879 | a41b2ff2 | pbrook | } |
880 | a41b2ff2 | pbrook | |
881 | a41b2ff2 | pbrook | int mcast_idx = compute_mcast_idx(buf);
|
882 | a41b2ff2 | pbrook | |
883 | a41b2ff2 | pbrook | if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) |
884 | a41b2ff2 | pbrook | { |
885 | 6cadb320 | bellard | DEBUG_PRINT((">>> RTL8139: multicast address mismatch\n"));
|
886 | 6cadb320 | bellard | |
887 | 6cadb320 | bellard | /* update tally counter */
|
888 | 6cadb320 | bellard | ++s->tally_counters.RxERR; |
889 | 6cadb320 | bellard | |
890 | a41b2ff2 | pbrook | return;
|
891 | a41b2ff2 | pbrook | } |
892 | a41b2ff2 | pbrook | |
893 | a41b2ff2 | pbrook | packet_header |= RxMulticast; |
894 | a41b2ff2 | pbrook | |
895 | 6cadb320 | bellard | DEBUG_PRINT((">>> RTL8139: multicast packet received\n"));
|
896 | 6cadb320 | bellard | |
897 | 6cadb320 | bellard | /* update tally counter */
|
898 | 6cadb320 | bellard | ++s->tally_counters.RxOkMul; |
899 | 6cadb320 | bellard | |
900 | a41b2ff2 | pbrook | } else if (s->phys[0] == buf[0] && |
901 | a41b2ff2 | pbrook | s->phys[1] == buf[1] && |
902 | a41b2ff2 | pbrook | s->phys[2] == buf[2] && |
903 | a41b2ff2 | pbrook | s->phys[3] == buf[3] && |
904 | a41b2ff2 | pbrook | s->phys[4] == buf[4] && |
905 | a41b2ff2 | pbrook | s->phys[5] == buf[5]) { |
906 | a41b2ff2 | pbrook | /* match */
|
907 | a41b2ff2 | pbrook | if (!(s->RxConfig & AcceptMyPhys))
|
908 | a41b2ff2 | pbrook | { |
909 | 6cadb320 | bellard | DEBUG_PRINT((">>> RTL8139: rejecting physical address matching packet\n"));
|
910 | 6cadb320 | bellard | |
911 | 6cadb320 | bellard | /* update tally counter */
|
912 | 6cadb320 | bellard | ++s->tally_counters.RxERR; |
913 | 6cadb320 | bellard | |
914 | a41b2ff2 | pbrook | return;
|
915 | a41b2ff2 | pbrook | } |
916 | a41b2ff2 | pbrook | |
917 | a41b2ff2 | pbrook | packet_header |= RxPhysical; |
918 | a41b2ff2 | pbrook | |
919 | 6cadb320 | bellard | DEBUG_PRINT((">>> RTL8139: physical address matching packet received\n"));
|
920 | 6cadb320 | bellard | |
921 | 6cadb320 | bellard | /* update tally counter */
|
922 | 6cadb320 | bellard | ++s->tally_counters.RxOkPhy; |
923 | a41b2ff2 | pbrook | |
924 | a41b2ff2 | pbrook | } else {
|
925 | a41b2ff2 | pbrook | |
926 | 6cadb320 | bellard | DEBUG_PRINT((">>> RTL8139: unknown packet\n"));
|
927 | 6cadb320 | bellard | |
928 | 6cadb320 | bellard | /* update tally counter */
|
929 | 6cadb320 | bellard | ++s->tally_counters.RxERR; |
930 | 6cadb320 | bellard | |
931 | a41b2ff2 | pbrook | return;
|
932 | a41b2ff2 | pbrook | } |
933 | a41b2ff2 | pbrook | } |
934 | a41b2ff2 | pbrook | |
935 | a41b2ff2 | pbrook | /* if too small buffer, then expand it */
|
936 | a41b2ff2 | pbrook | if (size < MIN_BUF_SIZE) {
|
937 | a41b2ff2 | pbrook | memcpy(buf1, buf, size); |
938 | a41b2ff2 | pbrook | memset(buf1 + size, 0, MIN_BUF_SIZE - size);
|
939 | a41b2ff2 | pbrook | buf = buf1; |
940 | a41b2ff2 | pbrook | size = MIN_BUF_SIZE; |
941 | a41b2ff2 | pbrook | } |
942 | a41b2ff2 | pbrook | |
943 | a41b2ff2 | pbrook | if (rtl8139_cp_receiver_enabled(s))
|
944 | a41b2ff2 | pbrook | { |
945 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: in C+ Rx mode ================\n"));
|
946 | a41b2ff2 | pbrook | |
947 | a41b2ff2 | pbrook | /* begin C+ receiver mode */
|
948 | a41b2ff2 | pbrook | |
949 | a41b2ff2 | pbrook | /* w0 ownership flag */
|
950 | a41b2ff2 | pbrook | #define CP_RX_OWN (1<<31) |
951 | a41b2ff2 | pbrook | /* w0 end of ring flag */
|
952 | a41b2ff2 | pbrook | #define CP_RX_EOR (1<<30) |
953 | a41b2ff2 | pbrook | /* w0 bits 0...12 : buffer size */
|
954 | a41b2ff2 | pbrook | #define CP_RX_BUFFER_SIZE_MASK ((1<<13) - 1) |
955 | a41b2ff2 | pbrook | /* w1 tag available flag */
|
956 | a41b2ff2 | pbrook | #define CP_RX_TAVA (1<<16) |
957 | a41b2ff2 | pbrook | /* w1 bits 0...15 : VLAN tag */
|
958 | a41b2ff2 | pbrook | #define CP_RX_VLAN_TAG_MASK ((1<<16) - 1) |
959 | a41b2ff2 | pbrook | /* w2 low 32bit of Rx buffer ptr */
|
960 | a41b2ff2 | pbrook | /* w3 high 32bit of Rx buffer ptr */
|
961 | a41b2ff2 | pbrook | |
962 | a41b2ff2 | pbrook | int descriptor = s->currCPlusRxDesc;
|
963 | a41b2ff2 | pbrook | target_phys_addr_t cplus_rx_ring_desc; |
964 | a41b2ff2 | pbrook | |
965 | a41b2ff2 | pbrook | cplus_rx_ring_desc = rtl8139_addr64(s->RxRingAddrLO, s->RxRingAddrHI); |
966 | a41b2ff2 | pbrook | cplus_rx_ring_desc += 16 * descriptor;
|
967 | a41b2ff2 | pbrook | |
968 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode reading RX descriptor %d from host memory at %08x %08x = %016" PRIx64 "\n", |
969 | 6cadb320 | bellard | descriptor, s->RxRingAddrHI, s->RxRingAddrLO, (uint64_t)cplus_rx_ring_desc)); |
970 | a41b2ff2 | pbrook | |
971 | a41b2ff2 | pbrook | uint32_t val, rxdw0,rxdw1,rxbufLO,rxbufHI; |
972 | a41b2ff2 | pbrook | |
973 | a41b2ff2 | pbrook | cpu_physical_memory_read(cplus_rx_ring_desc, (uint8_t *)&val, 4);
|
974 | a41b2ff2 | pbrook | rxdw0 = le32_to_cpu(val); |
975 | a41b2ff2 | pbrook | cpu_physical_memory_read(cplus_rx_ring_desc+4, (uint8_t *)&val, 4); |
976 | a41b2ff2 | pbrook | rxdw1 = le32_to_cpu(val); |
977 | a41b2ff2 | pbrook | cpu_physical_memory_read(cplus_rx_ring_desc+8, (uint8_t *)&val, 4); |
978 | a41b2ff2 | pbrook | rxbufLO = le32_to_cpu(val); |
979 | a41b2ff2 | pbrook | cpu_physical_memory_read(cplus_rx_ring_desc+12, (uint8_t *)&val, 4); |
980 | a41b2ff2 | pbrook | rxbufHI = le32_to_cpu(val); |
981 | a41b2ff2 | pbrook | |
982 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode RX descriptor %d %08x %08x %08x %08x\n",
|
983 | a41b2ff2 | pbrook | descriptor, |
984 | 6cadb320 | bellard | rxdw0, rxdw1, rxbufLO, rxbufHI)); |
985 | a41b2ff2 | pbrook | |
986 | a41b2ff2 | pbrook | if (!(rxdw0 & CP_RX_OWN))
|
987 | a41b2ff2 | pbrook | { |
988 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: C+ Rx mode : descriptor %d is owned by host\n", descriptor));
|
989 | 6cadb320 | bellard | |
990 | a41b2ff2 | pbrook | s->IntrStatus |= RxOverflow; |
991 | a41b2ff2 | pbrook | ++s->RxMissed; |
992 | 6cadb320 | bellard | |
993 | 6cadb320 | bellard | /* update tally counter */
|
994 | 6cadb320 | bellard | ++s->tally_counters.RxERR; |
995 | 6cadb320 | bellard | ++s->tally_counters.MissPkt; |
996 | 6cadb320 | bellard | |
997 | a41b2ff2 | pbrook | rtl8139_update_irq(s); |
998 | a41b2ff2 | pbrook | return;
|
999 | a41b2ff2 | pbrook | } |
1000 | a41b2ff2 | pbrook | |
1001 | a41b2ff2 | pbrook | uint32_t rx_space = rxdw0 & CP_RX_BUFFER_SIZE_MASK; |
1002 | a41b2ff2 | pbrook | |
1003 | 6cadb320 | bellard | /* TODO: scatter the packet over available receive ring descriptors space */
|
1004 | 6cadb320 | bellard | |
1005 | a41b2ff2 | pbrook | if (size+4 > rx_space) |
1006 | a41b2ff2 | pbrook | { |
1007 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: C+ Rx mode : descriptor %d size %d received %d + 4\n",
|
1008 | 6cadb320 | bellard | descriptor, rx_space, size)); |
1009 | 6cadb320 | bellard | |
1010 | a41b2ff2 | pbrook | s->IntrStatus |= RxOverflow; |
1011 | a41b2ff2 | pbrook | ++s->RxMissed; |
1012 | 6cadb320 | bellard | |
1013 | 6cadb320 | bellard | /* update tally counter */
|
1014 | 6cadb320 | bellard | ++s->tally_counters.RxERR; |
1015 | 6cadb320 | bellard | ++s->tally_counters.MissPkt; |
1016 | 6cadb320 | bellard | |
1017 | a41b2ff2 | pbrook | rtl8139_update_irq(s); |
1018 | a41b2ff2 | pbrook | return;
|
1019 | a41b2ff2 | pbrook | } |
1020 | a41b2ff2 | pbrook | |
1021 | a41b2ff2 | pbrook | target_phys_addr_t rx_addr = rtl8139_addr64(rxbufLO, rxbufHI); |
1022 | a41b2ff2 | pbrook | |
1023 | a41b2ff2 | pbrook | /* receive/copy to target memory */
|
1024 | a41b2ff2 | pbrook | cpu_physical_memory_write( rx_addr, buf, size ); |
1025 | a41b2ff2 | pbrook | |
1026 | 6cadb320 | bellard | if (s->CpCmd & CPlusRxChkSum)
|
1027 | 6cadb320 | bellard | { |
1028 | 6cadb320 | bellard | /* do some packet checksumming */
|
1029 | 6cadb320 | bellard | } |
1030 | 6cadb320 | bellard | |
1031 | a41b2ff2 | pbrook | /* write checksum */
|
1032 | a41b2ff2 | pbrook | #if defined (RTL8139_CALCULATE_RXCRC)
|
1033 | a41b2ff2 | pbrook | val = cpu_to_le32(crc32(~0, buf, size));
|
1034 | a41b2ff2 | pbrook | #else
|
1035 | a41b2ff2 | pbrook | val = 0;
|
1036 | a41b2ff2 | pbrook | #endif
|
1037 | a41b2ff2 | pbrook | cpu_physical_memory_write( rx_addr+size, (uint8_t *)&val, 4);
|
1038 | a41b2ff2 | pbrook | |
1039 | a41b2ff2 | pbrook | /* first segment of received packet flag */
|
1040 | a41b2ff2 | pbrook | #define CP_RX_STATUS_FS (1<<29) |
1041 | a41b2ff2 | pbrook | /* last segment of received packet flag */
|
1042 | a41b2ff2 | pbrook | #define CP_RX_STATUS_LS (1<<28) |
1043 | a41b2ff2 | pbrook | /* multicast packet flag */
|
1044 | a41b2ff2 | pbrook | #define CP_RX_STATUS_MAR (1<<26) |
1045 | a41b2ff2 | pbrook | /* physical-matching packet flag */
|
1046 | a41b2ff2 | pbrook | #define CP_RX_STATUS_PAM (1<<25) |
1047 | a41b2ff2 | pbrook | /* broadcast packet flag */
|
1048 | a41b2ff2 | pbrook | #define CP_RX_STATUS_BAR (1<<24) |
1049 | a41b2ff2 | pbrook | /* runt packet flag */
|
1050 | a41b2ff2 | pbrook | #define CP_RX_STATUS_RUNT (1<<19) |
1051 | a41b2ff2 | pbrook | /* crc error flag */
|
1052 | a41b2ff2 | pbrook | #define CP_RX_STATUS_CRC (1<<18) |
1053 | a41b2ff2 | pbrook | /* IP checksum error flag */
|
1054 | a41b2ff2 | pbrook | #define CP_RX_STATUS_IPF (1<<15) |
1055 | a41b2ff2 | pbrook | /* UDP checksum error flag */
|
1056 | a41b2ff2 | pbrook | #define CP_RX_STATUS_UDPF (1<<14) |
1057 | a41b2ff2 | pbrook | /* TCP checksum error flag */
|
1058 | a41b2ff2 | pbrook | #define CP_RX_STATUS_TCPF (1<<13) |
1059 | a41b2ff2 | pbrook | |
1060 | a41b2ff2 | pbrook | /* transfer ownership to target */
|
1061 | a41b2ff2 | pbrook | rxdw0 &= ~CP_RX_OWN; |
1062 | a41b2ff2 | pbrook | |
1063 | a41b2ff2 | pbrook | /* set first segment bit */
|
1064 | a41b2ff2 | pbrook | rxdw0 |= CP_RX_STATUS_FS; |
1065 | a41b2ff2 | pbrook | |
1066 | a41b2ff2 | pbrook | /* set last segment bit */
|
1067 | a41b2ff2 | pbrook | rxdw0 |= CP_RX_STATUS_LS; |
1068 | a41b2ff2 | pbrook | |
1069 | a41b2ff2 | pbrook | /* set received packet type flags */
|
1070 | a41b2ff2 | pbrook | if (packet_header & RxBroadcast)
|
1071 | a41b2ff2 | pbrook | rxdw0 |= CP_RX_STATUS_BAR; |
1072 | a41b2ff2 | pbrook | if (packet_header & RxMulticast)
|
1073 | a41b2ff2 | pbrook | rxdw0 |= CP_RX_STATUS_MAR; |
1074 | a41b2ff2 | pbrook | if (packet_header & RxPhysical)
|
1075 | a41b2ff2 | pbrook | rxdw0 |= CP_RX_STATUS_PAM; |
1076 | a41b2ff2 | pbrook | |
1077 | a41b2ff2 | pbrook | /* set received size */
|
1078 | a41b2ff2 | pbrook | rxdw0 &= ~CP_RX_BUFFER_SIZE_MASK; |
1079 | a41b2ff2 | pbrook | rxdw0 |= (size+4);
|
1080 | a41b2ff2 | pbrook | |
1081 | a41b2ff2 | pbrook | /* reset VLAN tag flag */
|
1082 | a41b2ff2 | pbrook | rxdw1 &= ~CP_RX_TAVA; |
1083 | a41b2ff2 | pbrook | |
1084 | a41b2ff2 | pbrook | /* update ring data */
|
1085 | a41b2ff2 | pbrook | val = cpu_to_le32(rxdw0); |
1086 | a41b2ff2 | pbrook | cpu_physical_memory_write(cplus_rx_ring_desc, (uint8_t *)&val, 4);
|
1087 | a41b2ff2 | pbrook | val = cpu_to_le32(rxdw1); |
1088 | a41b2ff2 | pbrook | cpu_physical_memory_write(cplus_rx_ring_desc+4, (uint8_t *)&val, 4); |
1089 | a41b2ff2 | pbrook | |
1090 | 6cadb320 | bellard | /* update tally counter */
|
1091 | 6cadb320 | bellard | ++s->tally_counters.RxOk; |
1092 | 6cadb320 | bellard | |
1093 | a41b2ff2 | pbrook | /* seek to next Rx descriptor */
|
1094 | a41b2ff2 | pbrook | if (rxdw0 & CP_RX_EOR)
|
1095 | a41b2ff2 | pbrook | { |
1096 | a41b2ff2 | pbrook | s->currCPlusRxDesc = 0;
|
1097 | a41b2ff2 | pbrook | } |
1098 | a41b2ff2 | pbrook | else
|
1099 | a41b2ff2 | pbrook | { |
1100 | a41b2ff2 | pbrook | ++s->currCPlusRxDesc; |
1101 | a41b2ff2 | pbrook | } |
1102 | a41b2ff2 | pbrook | |
1103 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: done C+ Rx mode ----------------\n"));
|
1104 | a41b2ff2 | pbrook | |
1105 | a41b2ff2 | pbrook | } |
1106 | a41b2ff2 | pbrook | else
|
1107 | a41b2ff2 | pbrook | { |
1108 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: in ring Rx mode ================\n"));
|
1109 | 6cadb320 | bellard | |
1110 | a41b2ff2 | pbrook | /* begin ring receiver mode */
|
1111 | a41b2ff2 | pbrook | int avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, s->RxBufferSize);
|
1112 | a41b2ff2 | pbrook | |
1113 | a41b2ff2 | pbrook | /* if receiver buffer is empty then avail == 0 */
|
1114 | a41b2ff2 | pbrook | |
1115 | a41b2ff2 | pbrook | if (avail != 0 && size + 8 >= avail) |
1116 | a41b2ff2 | pbrook | { |
1117 | 6cadb320 | bellard | DEBUG_PRINT(("rx overflow: rx buffer length %d head 0x%04x read 0x%04x === available 0x%04x need 0x%04x\n",
|
1118 | 6cadb320 | bellard | s->RxBufferSize, s->RxBufAddr, s->RxBufPtr, avail, size + 8));
|
1119 | 6cadb320 | bellard | |
1120 | a41b2ff2 | pbrook | s->IntrStatus |= RxOverflow; |
1121 | a41b2ff2 | pbrook | ++s->RxMissed; |
1122 | a41b2ff2 | pbrook | rtl8139_update_irq(s); |
1123 | a41b2ff2 | pbrook | return;
|
1124 | a41b2ff2 | pbrook | } |
1125 | a41b2ff2 | pbrook | |
1126 | a41b2ff2 | pbrook | packet_header |= RxStatusOK; |
1127 | a41b2ff2 | pbrook | |
1128 | a41b2ff2 | pbrook | packet_header |= (((size+4) << 16) & 0xffff0000); |
1129 | a41b2ff2 | pbrook | |
1130 | a41b2ff2 | pbrook | /* write header */
|
1131 | a41b2ff2 | pbrook | uint32_t val = cpu_to_le32(packet_header); |
1132 | a41b2ff2 | pbrook | |
1133 | a41b2ff2 | pbrook | rtl8139_write_buffer(s, (uint8_t *)&val, 4);
|
1134 | a41b2ff2 | pbrook | |
1135 | a41b2ff2 | pbrook | rtl8139_write_buffer(s, buf, size); |
1136 | a41b2ff2 | pbrook | |
1137 | a41b2ff2 | pbrook | /* write checksum */
|
1138 | a41b2ff2 | pbrook | #if defined (RTL8139_CALCULATE_RXCRC)
|
1139 | a41b2ff2 | pbrook | val = cpu_to_le32(crc32(~0, buf, size));
|
1140 | a41b2ff2 | pbrook | #else
|
1141 | a41b2ff2 | pbrook | val = 0;
|
1142 | a41b2ff2 | pbrook | #endif
|
1143 | a41b2ff2 | pbrook | |
1144 | a41b2ff2 | pbrook | rtl8139_write_buffer(s, (uint8_t *)&val, 4);
|
1145 | a41b2ff2 | pbrook | |
1146 | a41b2ff2 | pbrook | /* correct buffer write pointer */
|
1147 | a41b2ff2 | pbrook | s->RxBufAddr = MOD2((s->RxBufAddr + 3) & ~0x3, s->RxBufferSize); |
1148 | a41b2ff2 | pbrook | |
1149 | a41b2ff2 | pbrook | /* now we can signal we have received something */
|
1150 | a41b2ff2 | pbrook | |
1151 | 6cadb320 | bellard | DEBUG_PRINT((" received: rx buffer length %d head 0x%04x read 0x%04x\n",
|
1152 | 6cadb320 | bellard | s->RxBufferSize, s->RxBufAddr, s->RxBufPtr)); |
1153 | a41b2ff2 | pbrook | } |
1154 | a41b2ff2 | pbrook | |
1155 | a41b2ff2 | pbrook | s->IntrStatus |= RxOK; |
1156 | 6cadb320 | bellard | |
1157 | 6cadb320 | bellard | if (do_interrupt)
|
1158 | 6cadb320 | bellard | { |
1159 | 6cadb320 | bellard | rtl8139_update_irq(s); |
1160 | 6cadb320 | bellard | } |
1161 | 6cadb320 | bellard | } |
1162 | 6cadb320 | bellard | |
1163 | 6cadb320 | bellard | static void rtl8139_receive(void *opaque, const uint8_t *buf, int size) |
1164 | 6cadb320 | bellard | { |
1165 | 6cadb320 | bellard | rtl8139_do_receive(opaque, buf, size, 1);
|
1166 | a41b2ff2 | pbrook | } |
1167 | a41b2ff2 | pbrook | |
1168 | a41b2ff2 | pbrook | static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize) |
1169 | a41b2ff2 | pbrook | { |
1170 | a41b2ff2 | pbrook | s->RxBufferSize = bufferSize; |
1171 | a41b2ff2 | pbrook | s->RxBufPtr = 0;
|
1172 | a41b2ff2 | pbrook | s->RxBufAddr = 0;
|
1173 | a41b2ff2 | pbrook | } |
1174 | a41b2ff2 | pbrook | |
1175 | a41b2ff2 | pbrook | static void rtl8139_reset(RTL8139State *s) |
1176 | a41b2ff2 | pbrook | { |
1177 | a41b2ff2 | pbrook | int i;
|
1178 | a41b2ff2 | pbrook | |
1179 | a41b2ff2 | pbrook | /* restore MAC address */
|
1180 | a41b2ff2 | pbrook | memcpy(s->phys, s->macaddr, 6);
|
1181 | a41b2ff2 | pbrook | |
1182 | a41b2ff2 | pbrook | /* reset interrupt mask */
|
1183 | a41b2ff2 | pbrook | s->IntrStatus = 0;
|
1184 | a41b2ff2 | pbrook | s->IntrMask = 0;
|
1185 | a41b2ff2 | pbrook | |
1186 | a41b2ff2 | pbrook | rtl8139_update_irq(s); |
1187 | a41b2ff2 | pbrook | |
1188 | a41b2ff2 | pbrook | /* prepare eeprom */
|
1189 | a41b2ff2 | pbrook | s->eeprom.contents[0] = 0x8129; |
1190 | 6cadb320 | bellard | #if 1 |
1191 | 6cadb320 | bellard | // PCI vendor and device ID should be mirrored here
|
1192 | 6cadb320 | bellard | s->eeprom.contents[1] = 0x10ec; |
1193 | 6cadb320 | bellard | s->eeprom.contents[2] = 0x8139; |
1194 | 6cadb320 | bellard | #endif
|
1195 | 290a0933 | ths | |
1196 | 290a0933 | ths | s->eeprom.contents[7] = s->macaddr[0] | s->macaddr[1] << 8; |
1197 | 290a0933 | ths | s->eeprom.contents[8] = s->macaddr[2] | s->macaddr[3] << 8; |
1198 | 290a0933 | ths | s->eeprom.contents[9] = s->macaddr[4] | s->macaddr[5] << 8; |
1199 | a41b2ff2 | pbrook | |
1200 | a41b2ff2 | pbrook | /* mark all status registers as owned by host */
|
1201 | a41b2ff2 | pbrook | for (i = 0; i < 4; ++i) |
1202 | a41b2ff2 | pbrook | { |
1203 | a41b2ff2 | pbrook | s->TxStatus[i] = TxHostOwns; |
1204 | a41b2ff2 | pbrook | } |
1205 | a41b2ff2 | pbrook | |
1206 | a41b2ff2 | pbrook | s->currTxDesc = 0;
|
1207 | a41b2ff2 | pbrook | s->currCPlusRxDesc = 0;
|
1208 | a41b2ff2 | pbrook | s->currCPlusTxDesc = 0;
|
1209 | a41b2ff2 | pbrook | |
1210 | a41b2ff2 | pbrook | s->RxRingAddrLO = 0;
|
1211 | a41b2ff2 | pbrook | s->RxRingAddrHI = 0;
|
1212 | a41b2ff2 | pbrook | |
1213 | a41b2ff2 | pbrook | s->RxBuf = 0;
|
1214 | a41b2ff2 | pbrook | |
1215 | a41b2ff2 | pbrook | rtl8139_reset_rxring(s, 8192);
|
1216 | a41b2ff2 | pbrook | |
1217 | a41b2ff2 | pbrook | /* ACK the reset */
|
1218 | a41b2ff2 | pbrook | s->TxConfig = 0;
|
1219 | a41b2ff2 | pbrook | |
1220 | a41b2ff2 | pbrook | #if 0
|
1221 | a41b2ff2 | pbrook | // s->TxConfig |= HW_REVID(1, 0, 0, 0, 0, 0, 0); // RTL-8139 HasHltClk
|
1222 | a41b2ff2 | pbrook | s->clock_enabled = 0;
|
1223 | a41b2ff2 | pbrook | #else
|
1224 | 6cadb320 | bellard | s->TxConfig |= HW_REVID(1, 1, 1, 0, 1, 1, 0); // RTL-8139C+ HasLWake |
1225 | a41b2ff2 | pbrook | s->clock_enabled = 1;
|
1226 | a41b2ff2 | pbrook | #endif
|
1227 | a41b2ff2 | pbrook | |
1228 | a41b2ff2 | pbrook | s->bChipCmdState = CmdReset; /* RxBufEmpty bit is calculated on read from ChipCmd */;
|
1229 | a41b2ff2 | pbrook | |
1230 | a41b2ff2 | pbrook | /* set initial state data */
|
1231 | a41b2ff2 | pbrook | s->Config0 = 0x0; /* No boot ROM */ |
1232 | a41b2ff2 | pbrook | s->Config1 = 0xC; /* IO mapped and MEM mapped registers available */ |
1233 | a41b2ff2 | pbrook | s->Config3 = 0x1; /* fast back-to-back compatible */ |
1234 | a41b2ff2 | pbrook | s->Config5 = 0x0;
|
1235 | a41b2ff2 | pbrook | |
1236 | a41b2ff2 | pbrook | s->CSCR = CSCR_F_LINK_100 | CSCR_HEART_BIT | CSCR_LD; |
1237 | a41b2ff2 | pbrook | |
1238 | a41b2ff2 | pbrook | s->CpCmd = 0x0; /* reset C+ mode */ |
1239 | a41b2ff2 | pbrook | |
1240 | a41b2ff2 | pbrook | // s->BasicModeCtrl = 0x3100; // 100Mbps, full duplex, autonegotiation
|
1241 | a41b2ff2 | pbrook | // s->BasicModeCtrl = 0x2100; // 100Mbps, full duplex
|
1242 | a41b2ff2 | pbrook | s->BasicModeCtrl = 0x1000; // autonegotiation |
1243 | a41b2ff2 | pbrook | |
1244 | a41b2ff2 | pbrook | s->BasicModeStatus = 0x7809;
|
1245 | a41b2ff2 | pbrook | //s->BasicModeStatus |= 0x0040; /* UTP medium */
|
1246 | a41b2ff2 | pbrook | s->BasicModeStatus |= 0x0020; /* autonegotiation completed */ |
1247 | a41b2ff2 | pbrook | s->BasicModeStatus |= 0x0004; /* link is up */ |
1248 | a41b2ff2 | pbrook | |
1249 | a41b2ff2 | pbrook | s->NWayAdvert = 0x05e1; /* all modes, full duplex */ |
1250 | a41b2ff2 | pbrook | s->NWayLPAR = 0x05e1; /* all modes, full duplex */ |
1251 | a41b2ff2 | pbrook | s->NWayExpansion = 0x0001; /* autonegotiation supported */ |
1252 | 6cadb320 | bellard | |
1253 | 6cadb320 | bellard | /* also reset timer and disable timer interrupt */
|
1254 | 6cadb320 | bellard | s->TCTR = 0;
|
1255 | 6cadb320 | bellard | s->TimerInt = 0;
|
1256 | 6cadb320 | bellard | s->TCTR_base = 0;
|
1257 | 6cadb320 | bellard | |
1258 | 6cadb320 | bellard | /* reset tally counters */
|
1259 | 6cadb320 | bellard | RTL8139TallyCounters_clear(&s->tally_counters); |
1260 | 6cadb320 | bellard | } |
1261 | 6cadb320 | bellard | |
1262 | 6cadb320 | bellard | void RTL8139TallyCounters_clear(RTL8139TallyCounters* counters)
|
1263 | 6cadb320 | bellard | { |
1264 | 6cadb320 | bellard | counters->TxOk = 0;
|
1265 | 6cadb320 | bellard | counters->RxOk = 0;
|
1266 | 6cadb320 | bellard | counters->TxERR = 0;
|
1267 | 6cadb320 | bellard | counters->RxERR = 0;
|
1268 | 6cadb320 | bellard | counters->MissPkt = 0;
|
1269 | 6cadb320 | bellard | counters->FAE = 0;
|
1270 | 6cadb320 | bellard | counters->Tx1Col = 0;
|
1271 | 6cadb320 | bellard | counters->TxMCol = 0;
|
1272 | 6cadb320 | bellard | counters->RxOkPhy = 0;
|
1273 | 6cadb320 | bellard | counters->RxOkBrd = 0;
|
1274 | 6cadb320 | bellard | counters->RxOkMul = 0;
|
1275 | 6cadb320 | bellard | counters->TxAbt = 0;
|
1276 | 6cadb320 | bellard | counters->TxUndrn = 0;
|
1277 | 6cadb320 | bellard | } |
1278 | 6cadb320 | bellard | |
1279 | 6cadb320 | bellard | static void RTL8139TallyCounters_physical_memory_write(target_phys_addr_t tc_addr, RTL8139TallyCounters* tally_counters) |
1280 | 6cadb320 | bellard | { |
1281 | 6cadb320 | bellard | uint16_t val16; |
1282 | 6cadb320 | bellard | uint32_t val32; |
1283 | 6cadb320 | bellard | uint64_t val64; |
1284 | 6cadb320 | bellard | |
1285 | 6cadb320 | bellard | val64 = cpu_to_le64(tally_counters->TxOk); |
1286 | 6cadb320 | bellard | cpu_physical_memory_write(tc_addr + 0, (uint8_t *)&val64, 8); |
1287 | 6cadb320 | bellard | |
1288 | 6cadb320 | bellard | val64 = cpu_to_le64(tally_counters->RxOk); |
1289 | 6cadb320 | bellard | cpu_physical_memory_write(tc_addr + 8, (uint8_t *)&val64, 8); |
1290 | 6cadb320 | bellard | |
1291 | 6cadb320 | bellard | val64 = cpu_to_le64(tally_counters->TxERR); |
1292 | 6cadb320 | bellard | cpu_physical_memory_write(tc_addr + 16, (uint8_t *)&val64, 8); |
1293 | 6cadb320 | bellard | |
1294 | 6cadb320 | bellard | val32 = cpu_to_le32(tally_counters->RxERR); |
1295 | 6cadb320 | bellard | cpu_physical_memory_write(tc_addr + 24, (uint8_t *)&val32, 4); |
1296 | 6cadb320 | bellard | |
1297 | 6cadb320 | bellard | val16 = cpu_to_le16(tally_counters->MissPkt); |
1298 | 6cadb320 | bellard | cpu_physical_memory_write(tc_addr + 28, (uint8_t *)&val16, 2); |
1299 | 6cadb320 | bellard | |
1300 | 6cadb320 | bellard | val16 = cpu_to_le16(tally_counters->FAE); |
1301 | 6cadb320 | bellard | cpu_physical_memory_write(tc_addr + 30, (uint8_t *)&val16, 2); |
1302 | 6cadb320 | bellard | |
1303 | 6cadb320 | bellard | val32 = cpu_to_le32(tally_counters->Tx1Col); |
1304 | 6cadb320 | bellard | cpu_physical_memory_write(tc_addr + 32, (uint8_t *)&val32, 4); |
1305 | 6cadb320 | bellard | |
1306 | 6cadb320 | bellard | val32 = cpu_to_le32(tally_counters->TxMCol); |
1307 | 6cadb320 | bellard | cpu_physical_memory_write(tc_addr + 36, (uint8_t *)&val32, 4); |
1308 | 6cadb320 | bellard | |
1309 | 6cadb320 | bellard | val64 = cpu_to_le64(tally_counters->RxOkPhy); |
1310 | 6cadb320 | bellard | cpu_physical_memory_write(tc_addr + 40, (uint8_t *)&val64, 8); |
1311 | 6cadb320 | bellard | |
1312 | 6cadb320 | bellard | val64 = cpu_to_le64(tally_counters->RxOkBrd); |
1313 | 6cadb320 | bellard | cpu_physical_memory_write(tc_addr + 48, (uint8_t *)&val64, 8); |
1314 | 6cadb320 | bellard | |
1315 | 6cadb320 | bellard | val32 = cpu_to_le32(tally_counters->RxOkMul); |
1316 | 6cadb320 | bellard | cpu_physical_memory_write(tc_addr + 56, (uint8_t *)&val32, 4); |
1317 | 6cadb320 | bellard | |
1318 | 6cadb320 | bellard | val16 = cpu_to_le16(tally_counters->TxAbt); |
1319 | 6cadb320 | bellard | cpu_physical_memory_write(tc_addr + 60, (uint8_t *)&val16, 2); |
1320 | 6cadb320 | bellard | |
1321 | 6cadb320 | bellard | val16 = cpu_to_le16(tally_counters->TxUndrn); |
1322 | 6cadb320 | bellard | cpu_physical_memory_write(tc_addr + 62, (uint8_t *)&val16, 2); |
1323 | 6cadb320 | bellard | } |
1324 | 6cadb320 | bellard | |
1325 | 6cadb320 | bellard | /* Loads values of tally counters from VM state file */
|
1326 | 6cadb320 | bellard | static void RTL8139TallyCounters_load(QEMUFile* f, RTL8139TallyCounters *tally_counters) |
1327 | 6cadb320 | bellard | { |
1328 | 6cadb320 | bellard | qemu_get_be64s(f, &tally_counters->TxOk); |
1329 | 6cadb320 | bellard | qemu_get_be64s(f, &tally_counters->RxOk); |
1330 | 6cadb320 | bellard | qemu_get_be64s(f, &tally_counters->TxERR); |
1331 | 6cadb320 | bellard | qemu_get_be32s(f, &tally_counters->RxERR); |
1332 | 6cadb320 | bellard | qemu_get_be16s(f, &tally_counters->MissPkt); |
1333 | 6cadb320 | bellard | qemu_get_be16s(f, &tally_counters->FAE); |
1334 | 6cadb320 | bellard | qemu_get_be32s(f, &tally_counters->Tx1Col); |
1335 | 6cadb320 | bellard | qemu_get_be32s(f, &tally_counters->TxMCol); |
1336 | 6cadb320 | bellard | qemu_get_be64s(f, &tally_counters->RxOkPhy); |
1337 | 6cadb320 | bellard | qemu_get_be64s(f, &tally_counters->RxOkBrd); |
1338 | 6cadb320 | bellard | qemu_get_be32s(f, &tally_counters->RxOkMul); |
1339 | 6cadb320 | bellard | qemu_get_be16s(f, &tally_counters->TxAbt); |
1340 | 6cadb320 | bellard | qemu_get_be16s(f, &tally_counters->TxUndrn); |
1341 | 6cadb320 | bellard | } |
1342 | 6cadb320 | bellard | |
1343 | 6cadb320 | bellard | /* Saves values of tally counters to VM state file */
|
1344 | 6cadb320 | bellard | static void RTL8139TallyCounters_save(QEMUFile* f, RTL8139TallyCounters *tally_counters) |
1345 | 6cadb320 | bellard | { |
1346 | 6cadb320 | bellard | qemu_put_be64s(f, &tally_counters->TxOk); |
1347 | 6cadb320 | bellard | qemu_put_be64s(f, &tally_counters->RxOk); |
1348 | 6cadb320 | bellard | qemu_put_be64s(f, &tally_counters->TxERR); |
1349 | 6cadb320 | bellard | qemu_put_be32s(f, &tally_counters->RxERR); |
1350 | 6cadb320 | bellard | qemu_put_be16s(f, &tally_counters->MissPkt); |
1351 | 6cadb320 | bellard | qemu_put_be16s(f, &tally_counters->FAE); |
1352 | 6cadb320 | bellard | qemu_put_be32s(f, &tally_counters->Tx1Col); |
1353 | 6cadb320 | bellard | qemu_put_be32s(f, &tally_counters->TxMCol); |
1354 | 6cadb320 | bellard | qemu_put_be64s(f, &tally_counters->RxOkPhy); |
1355 | 6cadb320 | bellard | qemu_put_be64s(f, &tally_counters->RxOkBrd); |
1356 | 6cadb320 | bellard | qemu_put_be32s(f, &tally_counters->RxOkMul); |
1357 | 6cadb320 | bellard | qemu_put_be16s(f, &tally_counters->TxAbt); |
1358 | 6cadb320 | bellard | qemu_put_be16s(f, &tally_counters->TxUndrn); |
1359 | a41b2ff2 | pbrook | } |
1360 | a41b2ff2 | pbrook | |
1361 | a41b2ff2 | pbrook | static void rtl8139_ChipCmd_write(RTL8139State *s, uint32_t val) |
1362 | a41b2ff2 | pbrook | { |
1363 | a41b2ff2 | pbrook | val &= 0xff;
|
1364 | a41b2ff2 | pbrook | |
1365 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: ChipCmd write val=0x%08x\n", val));
|
1366 | a41b2ff2 | pbrook | |
1367 | a41b2ff2 | pbrook | if (val & CmdReset)
|
1368 | a41b2ff2 | pbrook | { |
1369 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: ChipCmd reset\n"));
|
1370 | a41b2ff2 | pbrook | rtl8139_reset(s); |
1371 | a41b2ff2 | pbrook | } |
1372 | a41b2ff2 | pbrook | if (val & CmdRxEnb)
|
1373 | a41b2ff2 | pbrook | { |
1374 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: ChipCmd enable receiver\n"));
|
1375 | 718da2b9 | bellard | |
1376 | 718da2b9 | bellard | s->currCPlusRxDesc = 0;
|
1377 | a41b2ff2 | pbrook | } |
1378 | a41b2ff2 | pbrook | if (val & CmdTxEnb)
|
1379 | a41b2ff2 | pbrook | { |
1380 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: ChipCmd enable transmitter\n"));
|
1381 | 718da2b9 | bellard | |
1382 | 718da2b9 | bellard | s->currCPlusTxDesc = 0;
|
1383 | a41b2ff2 | pbrook | } |
1384 | a41b2ff2 | pbrook | |
1385 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
1386 | a41b2ff2 | pbrook | val = SET_MASKED(val, 0xe3, s->bChipCmdState);
|
1387 | a41b2ff2 | pbrook | |
1388 | a41b2ff2 | pbrook | /* Deassert reset pin before next read */
|
1389 | a41b2ff2 | pbrook | val &= ~CmdReset; |
1390 | a41b2ff2 | pbrook | |
1391 | a41b2ff2 | pbrook | s->bChipCmdState = val; |
1392 | a41b2ff2 | pbrook | } |
1393 | a41b2ff2 | pbrook | |
1394 | a41b2ff2 | pbrook | static int rtl8139_RxBufferEmpty(RTL8139State *s) |
1395 | a41b2ff2 | pbrook | { |
1396 | a41b2ff2 | pbrook | int unread = MOD2(s->RxBufferSize + s->RxBufAddr - s->RxBufPtr, s->RxBufferSize);
|
1397 | a41b2ff2 | pbrook | |
1398 | a41b2ff2 | pbrook | if (unread != 0) |
1399 | a41b2ff2 | pbrook | { |
1400 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: receiver buffer data available 0x%04x\n", unread));
|
1401 | a41b2ff2 | pbrook | return 0; |
1402 | a41b2ff2 | pbrook | } |
1403 | a41b2ff2 | pbrook | |
1404 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: receiver buffer is empty\n"));
|
1405 | a41b2ff2 | pbrook | |
1406 | a41b2ff2 | pbrook | return 1; |
1407 | a41b2ff2 | pbrook | } |
1408 | a41b2ff2 | pbrook | |
1409 | a41b2ff2 | pbrook | static uint32_t rtl8139_ChipCmd_read(RTL8139State *s)
|
1410 | a41b2ff2 | pbrook | { |
1411 | a41b2ff2 | pbrook | uint32_t ret = s->bChipCmdState; |
1412 | a41b2ff2 | pbrook | |
1413 | a41b2ff2 | pbrook | if (rtl8139_RxBufferEmpty(s))
|
1414 | a41b2ff2 | pbrook | ret |= RxBufEmpty; |
1415 | a41b2ff2 | pbrook | |
1416 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: ChipCmd read val=0x%04x\n", ret));
|
1417 | a41b2ff2 | pbrook | |
1418 | a41b2ff2 | pbrook | return ret;
|
1419 | a41b2ff2 | pbrook | } |
1420 | a41b2ff2 | pbrook | |
1421 | a41b2ff2 | pbrook | static void rtl8139_CpCmd_write(RTL8139State *s, uint32_t val) |
1422 | a41b2ff2 | pbrook | { |
1423 | a41b2ff2 | pbrook | val &= 0xffff;
|
1424 | a41b2ff2 | pbrook | |
1425 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139C+ command register write(w) val=0x%04x\n", val));
|
1426 | a41b2ff2 | pbrook | |
1427 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
1428 | a41b2ff2 | pbrook | val = SET_MASKED(val, 0xff84, s->CpCmd);
|
1429 | a41b2ff2 | pbrook | |
1430 | a41b2ff2 | pbrook | s->CpCmd = val; |
1431 | a41b2ff2 | pbrook | } |
1432 | a41b2ff2 | pbrook | |
1433 | a41b2ff2 | pbrook | static uint32_t rtl8139_CpCmd_read(RTL8139State *s)
|
1434 | a41b2ff2 | pbrook | { |
1435 | a41b2ff2 | pbrook | uint32_t ret = s->CpCmd; |
1436 | a41b2ff2 | pbrook | |
1437 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139C+ command register read(w) val=0x%04x\n", ret));
|
1438 | 6cadb320 | bellard | |
1439 | 6cadb320 | bellard | return ret;
|
1440 | 6cadb320 | bellard | } |
1441 | 6cadb320 | bellard | |
1442 | 6cadb320 | bellard | static void rtl8139_IntrMitigate_write(RTL8139State *s, uint32_t val) |
1443 | 6cadb320 | bellard | { |
1444 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139C+ IntrMitigate register write(w) val=0x%04x\n", val));
|
1445 | 6cadb320 | bellard | } |
1446 | 6cadb320 | bellard | |
1447 | 6cadb320 | bellard | static uint32_t rtl8139_IntrMitigate_read(RTL8139State *s)
|
1448 | 6cadb320 | bellard | { |
1449 | 6cadb320 | bellard | uint32_t ret = 0;
|
1450 | 6cadb320 | bellard | |
1451 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139C+ IntrMitigate register read(w) val=0x%04x\n", ret));
|
1452 | a41b2ff2 | pbrook | |
1453 | a41b2ff2 | pbrook | return ret;
|
1454 | a41b2ff2 | pbrook | } |
1455 | a41b2ff2 | pbrook | |
1456 | a41b2ff2 | pbrook | int rtl8139_config_writeable(RTL8139State *s)
|
1457 | a41b2ff2 | pbrook | { |
1458 | a41b2ff2 | pbrook | if (s->Cfg9346 & Cfg9346_Unlock)
|
1459 | a41b2ff2 | pbrook | { |
1460 | a41b2ff2 | pbrook | return 1; |
1461 | a41b2ff2 | pbrook | } |
1462 | a41b2ff2 | pbrook | |
1463 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Configuration registers are write-protected\n"));
|
1464 | a41b2ff2 | pbrook | |
1465 | a41b2ff2 | pbrook | return 0; |
1466 | a41b2ff2 | pbrook | } |
1467 | a41b2ff2 | pbrook | |
1468 | a41b2ff2 | pbrook | static void rtl8139_BasicModeCtrl_write(RTL8139State *s, uint32_t val) |
1469 | a41b2ff2 | pbrook | { |
1470 | a41b2ff2 | pbrook | val &= 0xffff;
|
1471 | a41b2ff2 | pbrook | |
1472 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: BasicModeCtrl register write(w) val=0x%04x\n", val));
|
1473 | a41b2ff2 | pbrook | |
1474 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
1475 | a41b2ff2 | pbrook | uint32 mask = 0x4cff;
|
1476 | a41b2ff2 | pbrook | |
1477 | a41b2ff2 | pbrook | if (1 || !rtl8139_config_writeable(s)) |
1478 | a41b2ff2 | pbrook | { |
1479 | a41b2ff2 | pbrook | /* Speed setting and autonegotiation enable bits are read-only */
|
1480 | a41b2ff2 | pbrook | mask |= 0x3000;
|
1481 | a41b2ff2 | pbrook | /* Duplex mode setting is read-only */
|
1482 | a41b2ff2 | pbrook | mask |= 0x0100;
|
1483 | a41b2ff2 | pbrook | } |
1484 | a41b2ff2 | pbrook | |
1485 | a41b2ff2 | pbrook | val = SET_MASKED(val, mask, s->BasicModeCtrl); |
1486 | a41b2ff2 | pbrook | |
1487 | a41b2ff2 | pbrook | s->BasicModeCtrl = val; |
1488 | a41b2ff2 | pbrook | } |
1489 | a41b2ff2 | pbrook | |
1490 | a41b2ff2 | pbrook | static uint32_t rtl8139_BasicModeCtrl_read(RTL8139State *s)
|
1491 | a41b2ff2 | pbrook | { |
1492 | a41b2ff2 | pbrook | uint32_t ret = s->BasicModeCtrl; |
1493 | a41b2ff2 | pbrook | |
1494 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: BasicModeCtrl register read(w) val=0x%04x\n", ret));
|
1495 | a41b2ff2 | pbrook | |
1496 | a41b2ff2 | pbrook | return ret;
|
1497 | a41b2ff2 | pbrook | } |
1498 | a41b2ff2 | pbrook | |
1499 | a41b2ff2 | pbrook | static void rtl8139_BasicModeStatus_write(RTL8139State *s, uint32_t val) |
1500 | a41b2ff2 | pbrook | { |
1501 | a41b2ff2 | pbrook | val &= 0xffff;
|
1502 | a41b2ff2 | pbrook | |
1503 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: BasicModeStatus register write(w) val=0x%04x\n", val));
|
1504 | a41b2ff2 | pbrook | |
1505 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
1506 | a41b2ff2 | pbrook | val = SET_MASKED(val, 0xff3f, s->BasicModeStatus);
|
1507 | a41b2ff2 | pbrook | |
1508 | a41b2ff2 | pbrook | s->BasicModeStatus = val; |
1509 | a41b2ff2 | pbrook | } |
1510 | a41b2ff2 | pbrook | |
1511 | a41b2ff2 | pbrook | static uint32_t rtl8139_BasicModeStatus_read(RTL8139State *s)
|
1512 | a41b2ff2 | pbrook | { |
1513 | a41b2ff2 | pbrook | uint32_t ret = s->BasicModeStatus; |
1514 | a41b2ff2 | pbrook | |
1515 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: BasicModeStatus register read(w) val=0x%04x\n", ret));
|
1516 | a41b2ff2 | pbrook | |
1517 | a41b2ff2 | pbrook | return ret;
|
1518 | a41b2ff2 | pbrook | } |
1519 | a41b2ff2 | pbrook | |
1520 | a41b2ff2 | pbrook | static void rtl8139_Cfg9346_write(RTL8139State *s, uint32_t val) |
1521 | a41b2ff2 | pbrook | { |
1522 | a41b2ff2 | pbrook | val &= 0xff;
|
1523 | a41b2ff2 | pbrook | |
1524 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Cfg9346 write val=0x%02x\n", val));
|
1525 | a41b2ff2 | pbrook | |
1526 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
1527 | a41b2ff2 | pbrook | val = SET_MASKED(val, 0x31, s->Cfg9346);
|
1528 | a41b2ff2 | pbrook | |
1529 | a41b2ff2 | pbrook | uint32_t opmode = val & 0xc0;
|
1530 | a41b2ff2 | pbrook | uint32_t eeprom_val = val & 0xf;
|
1531 | a41b2ff2 | pbrook | |
1532 | a41b2ff2 | pbrook | if (opmode == 0x80) { |
1533 | a41b2ff2 | pbrook | /* eeprom access */
|
1534 | a41b2ff2 | pbrook | int eecs = (eeprom_val & 0x08)?1:0; |
1535 | a41b2ff2 | pbrook | int eesk = (eeprom_val & 0x04)?1:0; |
1536 | a41b2ff2 | pbrook | int eedi = (eeprom_val & 0x02)?1:0; |
1537 | a41b2ff2 | pbrook | prom9346_set_wire(s, eecs, eesk, eedi); |
1538 | a41b2ff2 | pbrook | } else if (opmode == 0x40) { |
1539 | a41b2ff2 | pbrook | /* Reset. */
|
1540 | a41b2ff2 | pbrook | val = 0;
|
1541 | a41b2ff2 | pbrook | rtl8139_reset(s); |
1542 | a41b2ff2 | pbrook | } |
1543 | a41b2ff2 | pbrook | |
1544 | a41b2ff2 | pbrook | s->Cfg9346 = val; |
1545 | a41b2ff2 | pbrook | } |
1546 | a41b2ff2 | pbrook | |
1547 | a41b2ff2 | pbrook | static uint32_t rtl8139_Cfg9346_read(RTL8139State *s)
|
1548 | a41b2ff2 | pbrook | { |
1549 | a41b2ff2 | pbrook | uint32_t ret = s->Cfg9346; |
1550 | a41b2ff2 | pbrook | |
1551 | a41b2ff2 | pbrook | uint32_t opmode = ret & 0xc0;
|
1552 | a41b2ff2 | pbrook | |
1553 | a41b2ff2 | pbrook | if (opmode == 0x80) |
1554 | a41b2ff2 | pbrook | { |
1555 | a41b2ff2 | pbrook | /* eeprom access */
|
1556 | a41b2ff2 | pbrook | int eedo = prom9346_get_wire(s);
|
1557 | a41b2ff2 | pbrook | if (eedo)
|
1558 | a41b2ff2 | pbrook | { |
1559 | a41b2ff2 | pbrook | ret |= 0x01;
|
1560 | a41b2ff2 | pbrook | } |
1561 | a41b2ff2 | pbrook | else
|
1562 | a41b2ff2 | pbrook | { |
1563 | a41b2ff2 | pbrook | ret &= ~0x01;
|
1564 | a41b2ff2 | pbrook | } |
1565 | a41b2ff2 | pbrook | } |
1566 | a41b2ff2 | pbrook | |
1567 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Cfg9346 read val=0x%02x\n", ret));
|
1568 | a41b2ff2 | pbrook | |
1569 | a41b2ff2 | pbrook | return ret;
|
1570 | a41b2ff2 | pbrook | } |
1571 | a41b2ff2 | pbrook | |
1572 | a41b2ff2 | pbrook | static void rtl8139_Config0_write(RTL8139State *s, uint32_t val) |
1573 | a41b2ff2 | pbrook | { |
1574 | a41b2ff2 | pbrook | val &= 0xff;
|
1575 | a41b2ff2 | pbrook | |
1576 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Config0 write val=0x%02x\n", val));
|
1577 | a41b2ff2 | pbrook | |
1578 | a41b2ff2 | pbrook | if (!rtl8139_config_writeable(s))
|
1579 | a41b2ff2 | pbrook | return;
|
1580 | a41b2ff2 | pbrook | |
1581 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
1582 | a41b2ff2 | pbrook | val = SET_MASKED(val, 0xf8, s->Config0);
|
1583 | a41b2ff2 | pbrook | |
1584 | a41b2ff2 | pbrook | s->Config0 = val; |
1585 | a41b2ff2 | pbrook | } |
1586 | a41b2ff2 | pbrook | |
1587 | a41b2ff2 | pbrook | static uint32_t rtl8139_Config0_read(RTL8139State *s)
|
1588 | a41b2ff2 | pbrook | { |
1589 | a41b2ff2 | pbrook | uint32_t ret = s->Config0; |
1590 | a41b2ff2 | pbrook | |
1591 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Config0 read val=0x%02x\n", ret));
|
1592 | a41b2ff2 | pbrook | |
1593 | a41b2ff2 | pbrook | return ret;
|
1594 | a41b2ff2 | pbrook | } |
1595 | a41b2ff2 | pbrook | |
1596 | a41b2ff2 | pbrook | static void rtl8139_Config1_write(RTL8139State *s, uint32_t val) |
1597 | a41b2ff2 | pbrook | { |
1598 | a41b2ff2 | pbrook | val &= 0xff;
|
1599 | a41b2ff2 | pbrook | |
1600 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Config1 write val=0x%02x\n", val));
|
1601 | a41b2ff2 | pbrook | |
1602 | a41b2ff2 | pbrook | if (!rtl8139_config_writeable(s))
|
1603 | a41b2ff2 | pbrook | return;
|
1604 | a41b2ff2 | pbrook | |
1605 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
1606 | a41b2ff2 | pbrook | val = SET_MASKED(val, 0xC, s->Config1);
|
1607 | a41b2ff2 | pbrook | |
1608 | a41b2ff2 | pbrook | s->Config1 = val; |
1609 | a41b2ff2 | pbrook | } |
1610 | a41b2ff2 | pbrook | |
1611 | a41b2ff2 | pbrook | static uint32_t rtl8139_Config1_read(RTL8139State *s)
|
1612 | a41b2ff2 | pbrook | { |
1613 | a41b2ff2 | pbrook | uint32_t ret = s->Config1; |
1614 | a41b2ff2 | pbrook | |
1615 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Config1 read val=0x%02x\n", ret));
|
1616 | a41b2ff2 | pbrook | |
1617 | a41b2ff2 | pbrook | return ret;
|
1618 | a41b2ff2 | pbrook | } |
1619 | a41b2ff2 | pbrook | |
1620 | a41b2ff2 | pbrook | static void rtl8139_Config3_write(RTL8139State *s, uint32_t val) |
1621 | a41b2ff2 | pbrook | { |
1622 | a41b2ff2 | pbrook | val &= 0xff;
|
1623 | a41b2ff2 | pbrook | |
1624 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Config3 write val=0x%02x\n", val));
|
1625 | a41b2ff2 | pbrook | |
1626 | a41b2ff2 | pbrook | if (!rtl8139_config_writeable(s))
|
1627 | a41b2ff2 | pbrook | return;
|
1628 | a41b2ff2 | pbrook | |
1629 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
1630 | a41b2ff2 | pbrook | val = SET_MASKED(val, 0x8F, s->Config3);
|
1631 | a41b2ff2 | pbrook | |
1632 | a41b2ff2 | pbrook | s->Config3 = val; |
1633 | a41b2ff2 | pbrook | } |
1634 | a41b2ff2 | pbrook | |
1635 | a41b2ff2 | pbrook | static uint32_t rtl8139_Config3_read(RTL8139State *s)
|
1636 | a41b2ff2 | pbrook | { |
1637 | a41b2ff2 | pbrook | uint32_t ret = s->Config3; |
1638 | a41b2ff2 | pbrook | |
1639 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Config3 read val=0x%02x\n", ret));
|
1640 | a41b2ff2 | pbrook | |
1641 | a41b2ff2 | pbrook | return ret;
|
1642 | a41b2ff2 | pbrook | } |
1643 | a41b2ff2 | pbrook | |
1644 | a41b2ff2 | pbrook | static void rtl8139_Config4_write(RTL8139State *s, uint32_t val) |
1645 | a41b2ff2 | pbrook | { |
1646 | a41b2ff2 | pbrook | val &= 0xff;
|
1647 | a41b2ff2 | pbrook | |
1648 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Config4 write val=0x%02x\n", val));
|
1649 | a41b2ff2 | pbrook | |
1650 | a41b2ff2 | pbrook | if (!rtl8139_config_writeable(s))
|
1651 | a41b2ff2 | pbrook | return;
|
1652 | a41b2ff2 | pbrook | |
1653 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
1654 | a41b2ff2 | pbrook | val = SET_MASKED(val, 0x0a, s->Config4);
|
1655 | a41b2ff2 | pbrook | |
1656 | a41b2ff2 | pbrook | s->Config4 = val; |
1657 | a41b2ff2 | pbrook | } |
1658 | a41b2ff2 | pbrook | |
1659 | a41b2ff2 | pbrook | static uint32_t rtl8139_Config4_read(RTL8139State *s)
|
1660 | a41b2ff2 | pbrook | { |
1661 | a41b2ff2 | pbrook | uint32_t ret = s->Config4; |
1662 | a41b2ff2 | pbrook | |
1663 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Config4 read val=0x%02x\n", ret));
|
1664 | a41b2ff2 | pbrook | |
1665 | a41b2ff2 | pbrook | return ret;
|
1666 | a41b2ff2 | pbrook | } |
1667 | a41b2ff2 | pbrook | |
1668 | a41b2ff2 | pbrook | static void rtl8139_Config5_write(RTL8139State *s, uint32_t val) |
1669 | a41b2ff2 | pbrook | { |
1670 | a41b2ff2 | pbrook | val &= 0xff;
|
1671 | a41b2ff2 | pbrook | |
1672 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Config5 write val=0x%02x\n", val));
|
1673 | a41b2ff2 | pbrook | |
1674 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
1675 | a41b2ff2 | pbrook | val = SET_MASKED(val, 0x80, s->Config5);
|
1676 | a41b2ff2 | pbrook | |
1677 | a41b2ff2 | pbrook | s->Config5 = val; |
1678 | a41b2ff2 | pbrook | } |
1679 | a41b2ff2 | pbrook | |
1680 | a41b2ff2 | pbrook | static uint32_t rtl8139_Config5_read(RTL8139State *s)
|
1681 | a41b2ff2 | pbrook | { |
1682 | a41b2ff2 | pbrook | uint32_t ret = s->Config5; |
1683 | a41b2ff2 | pbrook | |
1684 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: Config5 read val=0x%02x\n", ret));
|
1685 | a41b2ff2 | pbrook | |
1686 | a41b2ff2 | pbrook | return ret;
|
1687 | a41b2ff2 | pbrook | } |
1688 | a41b2ff2 | pbrook | |
1689 | a41b2ff2 | pbrook | static void rtl8139_TxConfig_write(RTL8139State *s, uint32_t val) |
1690 | a41b2ff2 | pbrook | { |
1691 | a41b2ff2 | pbrook | if (!rtl8139_transmitter_enabled(s))
|
1692 | a41b2ff2 | pbrook | { |
1693 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: transmitter disabled; no TxConfig write val=0x%08x\n", val));
|
1694 | a41b2ff2 | pbrook | return;
|
1695 | a41b2ff2 | pbrook | } |
1696 | a41b2ff2 | pbrook | |
1697 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: TxConfig write val=0x%08x\n", val));
|
1698 | a41b2ff2 | pbrook | |
1699 | a41b2ff2 | pbrook | val = SET_MASKED(val, TxVersionMask | 0x8070f80f, s->TxConfig);
|
1700 | a41b2ff2 | pbrook | |
1701 | a41b2ff2 | pbrook | s->TxConfig = val; |
1702 | a41b2ff2 | pbrook | } |
1703 | a41b2ff2 | pbrook | |
1704 | a41b2ff2 | pbrook | static void rtl8139_TxConfig_writeb(RTL8139State *s, uint32_t val) |
1705 | a41b2ff2 | pbrook | { |
1706 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139C TxConfig via write(b) val=0x%02x\n", val));
|
1707 | 6cadb320 | bellard | |
1708 | 6cadb320 | bellard | uint32_t tc = s->TxConfig; |
1709 | 6cadb320 | bellard | tc &= 0xFFFFFF00;
|
1710 | 6cadb320 | bellard | tc |= (val & 0x000000FF);
|
1711 | 6cadb320 | bellard | rtl8139_TxConfig_write(s, tc); |
1712 | a41b2ff2 | pbrook | } |
1713 | a41b2ff2 | pbrook | |
1714 | a41b2ff2 | pbrook | static uint32_t rtl8139_TxConfig_read(RTL8139State *s)
|
1715 | a41b2ff2 | pbrook | { |
1716 | a41b2ff2 | pbrook | uint32_t ret = s->TxConfig; |
1717 | a41b2ff2 | pbrook | |
1718 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: TxConfig read val=0x%04x\n", ret));
|
1719 | a41b2ff2 | pbrook | |
1720 | a41b2ff2 | pbrook | return ret;
|
1721 | a41b2ff2 | pbrook | } |
1722 | a41b2ff2 | pbrook | |
1723 | a41b2ff2 | pbrook | static void rtl8139_RxConfig_write(RTL8139State *s, uint32_t val) |
1724 | a41b2ff2 | pbrook | { |
1725 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: RxConfig write val=0x%08x\n", val));
|
1726 | a41b2ff2 | pbrook | |
1727 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
1728 | a41b2ff2 | pbrook | val = SET_MASKED(val, 0xf0fc0040, s->RxConfig);
|
1729 | a41b2ff2 | pbrook | |
1730 | a41b2ff2 | pbrook | s->RxConfig = val; |
1731 | a41b2ff2 | pbrook | |
1732 | a41b2ff2 | pbrook | /* reset buffer size and read/write pointers */
|
1733 | a41b2ff2 | pbrook | rtl8139_reset_rxring(s, 8192 << ((s->RxConfig >> 11) & 0x3)); |
1734 | a41b2ff2 | pbrook | |
1735 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: RxConfig write reset buffer size to %d\n", s->RxBufferSize));
|
1736 | a41b2ff2 | pbrook | } |
1737 | a41b2ff2 | pbrook | |
1738 | a41b2ff2 | pbrook | static uint32_t rtl8139_RxConfig_read(RTL8139State *s)
|
1739 | a41b2ff2 | pbrook | { |
1740 | a41b2ff2 | pbrook | uint32_t ret = s->RxConfig; |
1741 | a41b2ff2 | pbrook | |
1742 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: RxConfig read val=0x%08x\n", ret));
|
1743 | a41b2ff2 | pbrook | |
1744 | a41b2ff2 | pbrook | return ret;
|
1745 | a41b2ff2 | pbrook | } |
1746 | a41b2ff2 | pbrook | |
1747 | 718da2b9 | bellard | static void rtl8139_transfer_frame(RTL8139State *s, const uint8_t *buf, int size, int do_interrupt) |
1748 | 718da2b9 | bellard | { |
1749 | 718da2b9 | bellard | if (!size)
|
1750 | 718da2b9 | bellard | { |
1751 | 718da2b9 | bellard | DEBUG_PRINT(("RTL8139: +++ empty ethernet frame\n"));
|
1752 | 718da2b9 | bellard | return;
|
1753 | 718da2b9 | bellard | } |
1754 | 718da2b9 | bellard | |
1755 | 718da2b9 | bellard | if (TxLoopBack == (s->TxConfig & TxLoopBack))
|
1756 | 718da2b9 | bellard | { |
1757 | 718da2b9 | bellard | DEBUG_PRINT(("RTL8139: +++ transmit loopback mode\n"));
|
1758 | 718da2b9 | bellard | rtl8139_do_receive(s, buf, size, do_interrupt); |
1759 | 718da2b9 | bellard | } |
1760 | 718da2b9 | bellard | else
|
1761 | 718da2b9 | bellard | { |
1762 | 718da2b9 | bellard | qemu_send_packet(s->vc, buf, size); |
1763 | 718da2b9 | bellard | } |
1764 | 718da2b9 | bellard | } |
1765 | 718da2b9 | bellard | |
1766 | a41b2ff2 | pbrook | static int rtl8139_transmit_one(RTL8139State *s, int descriptor) |
1767 | a41b2ff2 | pbrook | { |
1768 | a41b2ff2 | pbrook | if (!rtl8139_transmitter_enabled(s))
|
1769 | a41b2ff2 | pbrook | { |
1770 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ cannot transmit from descriptor %d: transmitter disabled\n",
|
1771 | 6cadb320 | bellard | descriptor)); |
1772 | a41b2ff2 | pbrook | return 0; |
1773 | a41b2ff2 | pbrook | } |
1774 | a41b2ff2 | pbrook | |
1775 | a41b2ff2 | pbrook | if (s->TxStatus[descriptor] & TxHostOwns)
|
1776 | a41b2ff2 | pbrook | { |
1777 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ cannot transmit from descriptor %d: owned by host (%08x)\n",
|
1778 | 6cadb320 | bellard | descriptor, s->TxStatus[descriptor])); |
1779 | a41b2ff2 | pbrook | return 0; |
1780 | a41b2ff2 | pbrook | } |
1781 | a41b2ff2 | pbrook | |
1782 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ transmitting from descriptor %d\n", descriptor));
|
1783 | a41b2ff2 | pbrook | |
1784 | a41b2ff2 | pbrook | int txsize = s->TxStatus[descriptor] & 0x1fff; |
1785 | a41b2ff2 | pbrook | uint8_t txbuffer[0x2000];
|
1786 | a41b2ff2 | pbrook | |
1787 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ transmit reading %d bytes from host memory at 0x%08x\n",
|
1788 | 6cadb320 | bellard | txsize, s->TxAddr[descriptor])); |
1789 | a41b2ff2 | pbrook | |
1790 | 6cadb320 | bellard | cpu_physical_memory_read(s->TxAddr[descriptor], txbuffer, txsize); |
1791 | a41b2ff2 | pbrook | |
1792 | a41b2ff2 | pbrook | /* Mark descriptor as transferred */
|
1793 | a41b2ff2 | pbrook | s->TxStatus[descriptor] |= TxHostOwns; |
1794 | a41b2ff2 | pbrook | s->TxStatus[descriptor] |= TxStatOK; |
1795 | a41b2ff2 | pbrook | |
1796 | 718da2b9 | bellard | rtl8139_transfer_frame(s, txbuffer, txsize, 0);
|
1797 | 6cadb320 | bellard | |
1798 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ transmitted %d bytes from descriptor %d\n", txsize, descriptor));
|
1799 | a41b2ff2 | pbrook | |
1800 | a41b2ff2 | pbrook | /* update interrupt */
|
1801 | a41b2ff2 | pbrook | s->IntrStatus |= TxOK; |
1802 | a41b2ff2 | pbrook | rtl8139_update_irq(s); |
1803 | a41b2ff2 | pbrook | |
1804 | a41b2ff2 | pbrook | return 1; |
1805 | a41b2ff2 | pbrook | } |
1806 | a41b2ff2 | pbrook | |
1807 | 718da2b9 | bellard | /* structures and macros for task offloading */
|
1808 | 718da2b9 | bellard | typedef struct ip_header |
1809 | 718da2b9 | bellard | { |
1810 | 718da2b9 | bellard | uint8_t ip_ver_len; /* version and header length */
|
1811 | 718da2b9 | bellard | uint8_t ip_tos; /* type of service */
|
1812 | 718da2b9 | bellard | uint16_t ip_len; /* total length */
|
1813 | 718da2b9 | bellard | uint16_t ip_id; /* identification */
|
1814 | 718da2b9 | bellard | uint16_t ip_off; /* fragment offset field */
|
1815 | 718da2b9 | bellard | uint8_t ip_ttl; /* time to live */
|
1816 | 718da2b9 | bellard | uint8_t ip_p; /* protocol */
|
1817 | 718da2b9 | bellard | uint16_t ip_sum; /* checksum */
|
1818 | 718da2b9 | bellard | uint32_t ip_src,ip_dst; /* source and dest address */
|
1819 | 718da2b9 | bellard | } ip_header; |
1820 | 718da2b9 | bellard | |
1821 | 718da2b9 | bellard | #define IP_HEADER_VERSION_4 4 |
1822 | 718da2b9 | bellard | #define IP_HEADER_VERSION(ip) ((ip->ip_ver_len >> 4)&0xf) |
1823 | 718da2b9 | bellard | #define IP_HEADER_LENGTH(ip) (((ip->ip_ver_len)&0xf) << 2) |
1824 | 718da2b9 | bellard | |
1825 | 718da2b9 | bellard | typedef struct tcp_header |
1826 | 718da2b9 | bellard | { |
1827 | 718da2b9 | bellard | uint16_t th_sport; /* source port */
|
1828 | 718da2b9 | bellard | uint16_t th_dport; /* destination port */
|
1829 | 718da2b9 | bellard | uint32_t th_seq; /* sequence number */
|
1830 | 718da2b9 | bellard | uint32_t th_ack; /* acknowledgement number */
|
1831 | 718da2b9 | bellard | uint16_t th_offset_flags; /* data offset, reserved 6 bits, TCP protocol flags */
|
1832 | 718da2b9 | bellard | uint16_t th_win; /* window */
|
1833 | 718da2b9 | bellard | uint16_t th_sum; /* checksum */
|
1834 | 718da2b9 | bellard | uint16_t th_urp; /* urgent pointer */
|
1835 | 718da2b9 | bellard | } tcp_header; |
1836 | 718da2b9 | bellard | |
1837 | 718da2b9 | bellard | typedef struct udp_header |
1838 | 718da2b9 | bellard | { |
1839 | 718da2b9 | bellard | uint16_t uh_sport; /* source port */
|
1840 | 718da2b9 | bellard | uint16_t uh_dport; /* destination port */
|
1841 | 718da2b9 | bellard | uint16_t uh_ulen; /* udp length */
|
1842 | 718da2b9 | bellard | uint16_t uh_sum; /* udp checksum */
|
1843 | 718da2b9 | bellard | } udp_header; |
1844 | 718da2b9 | bellard | |
1845 | 718da2b9 | bellard | typedef struct ip_pseudo_header |
1846 | 718da2b9 | bellard | { |
1847 | 718da2b9 | bellard | uint32_t ip_src; |
1848 | 718da2b9 | bellard | uint32_t ip_dst; |
1849 | 718da2b9 | bellard | uint8_t zeros; |
1850 | 718da2b9 | bellard | uint8_t ip_proto; |
1851 | 718da2b9 | bellard | uint16_t ip_payload; |
1852 | 718da2b9 | bellard | } ip_pseudo_header; |
1853 | 718da2b9 | bellard | |
1854 | 718da2b9 | bellard | #define IP_PROTO_TCP 6 |
1855 | 718da2b9 | bellard | #define IP_PROTO_UDP 17 |
1856 | 718da2b9 | bellard | |
1857 | 718da2b9 | bellard | #define TCP_HEADER_DATA_OFFSET(tcp) (((be16_to_cpu(tcp->th_offset_flags) >> 12)&0xf) << 2) |
1858 | 718da2b9 | bellard | #define TCP_FLAGS_ONLY(flags) ((flags)&0x3f) |
1859 | 718da2b9 | bellard | #define TCP_HEADER_FLAGS(tcp) TCP_FLAGS_ONLY(be16_to_cpu(tcp->th_offset_flags))
|
1860 | 718da2b9 | bellard | |
1861 | 718da2b9 | bellard | #define TCP_HEADER_CLEAR_FLAGS(tcp, off) ((tcp)->th_offset_flags &= cpu_to_be16(~TCP_FLAGS_ONLY(off)))
|
1862 | 718da2b9 | bellard | |
1863 | 718da2b9 | bellard | #define TCP_FLAG_FIN 0x01 |
1864 | 718da2b9 | bellard | #define TCP_FLAG_PUSH 0x08 |
1865 | 718da2b9 | bellard | |
1866 | 718da2b9 | bellard | /* produces ones' complement sum of data */
|
1867 | 718da2b9 | bellard | static uint16_t ones_complement_sum(uint8_t *data, size_t len)
|
1868 | 718da2b9 | bellard | { |
1869 | 718da2b9 | bellard | uint32_t result = 0;
|
1870 | 718da2b9 | bellard | |
1871 | 718da2b9 | bellard | for (; len > 1; data+=2, len-=2) |
1872 | 718da2b9 | bellard | { |
1873 | 718da2b9 | bellard | result += *(uint16_t*)data; |
1874 | 718da2b9 | bellard | } |
1875 | 718da2b9 | bellard | |
1876 | 718da2b9 | bellard | /* add the remainder byte */
|
1877 | 718da2b9 | bellard | if (len)
|
1878 | 718da2b9 | bellard | { |
1879 | 718da2b9 | bellard | uint8_t odd[2] = {*data, 0}; |
1880 | 718da2b9 | bellard | result += *(uint16_t*)odd; |
1881 | 718da2b9 | bellard | } |
1882 | 718da2b9 | bellard | |
1883 | 718da2b9 | bellard | while (result>>16) |
1884 | 718da2b9 | bellard | result = (result & 0xffff) + (result >> 16); |
1885 | 718da2b9 | bellard | |
1886 | 718da2b9 | bellard | return result;
|
1887 | 718da2b9 | bellard | } |
1888 | 718da2b9 | bellard | |
1889 | 718da2b9 | bellard | static uint16_t ip_checksum(void *data, size_t len) |
1890 | 718da2b9 | bellard | { |
1891 | 718da2b9 | bellard | return ~ones_complement_sum((uint8_t*)data, len);
|
1892 | 718da2b9 | bellard | } |
1893 | 718da2b9 | bellard | |
1894 | a41b2ff2 | pbrook | static int rtl8139_cplus_transmit_one(RTL8139State *s) |
1895 | a41b2ff2 | pbrook | { |
1896 | a41b2ff2 | pbrook | if (!rtl8139_transmitter_enabled(s))
|
1897 | a41b2ff2 | pbrook | { |
1898 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode: transmitter disabled\n"));
|
1899 | a41b2ff2 | pbrook | return 0; |
1900 | a41b2ff2 | pbrook | } |
1901 | a41b2ff2 | pbrook | |
1902 | a41b2ff2 | pbrook | if (!rtl8139_cp_transmitter_enabled(s))
|
1903 | a41b2ff2 | pbrook | { |
1904 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode: C+ transmitter disabled\n"));
|
1905 | a41b2ff2 | pbrook | return 0 ; |
1906 | a41b2ff2 | pbrook | } |
1907 | a41b2ff2 | pbrook | |
1908 | a41b2ff2 | pbrook | int descriptor = s->currCPlusTxDesc;
|
1909 | a41b2ff2 | pbrook | |
1910 | a41b2ff2 | pbrook | target_phys_addr_t cplus_tx_ring_desc = |
1911 | a41b2ff2 | pbrook | rtl8139_addr64(s->TxAddr[0], s->TxAddr[1]); |
1912 | a41b2ff2 | pbrook | |
1913 | a41b2ff2 | pbrook | /* Normal priority ring */
|
1914 | a41b2ff2 | pbrook | cplus_tx_ring_desc += 16 * descriptor;
|
1915 | a41b2ff2 | pbrook | |
1916 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode reading TX descriptor %d from host memory at %08x0x%08x = 0x%8lx\n",
|
1917 | 6cadb320 | bellard | descriptor, s->TxAddr[1], s->TxAddr[0], cplus_tx_ring_desc)); |
1918 | a41b2ff2 | pbrook | |
1919 | a41b2ff2 | pbrook | uint32_t val, txdw0,txdw1,txbufLO,txbufHI; |
1920 | a41b2ff2 | pbrook | |
1921 | a41b2ff2 | pbrook | cpu_physical_memory_read(cplus_tx_ring_desc, (uint8_t *)&val, 4);
|
1922 | a41b2ff2 | pbrook | txdw0 = le32_to_cpu(val); |
1923 | a41b2ff2 | pbrook | cpu_physical_memory_read(cplus_tx_ring_desc+4, (uint8_t *)&val, 4); |
1924 | a41b2ff2 | pbrook | txdw1 = le32_to_cpu(val); |
1925 | a41b2ff2 | pbrook | cpu_physical_memory_read(cplus_tx_ring_desc+8, (uint8_t *)&val, 4); |
1926 | a41b2ff2 | pbrook | txbufLO = le32_to_cpu(val); |
1927 | a41b2ff2 | pbrook | cpu_physical_memory_read(cplus_tx_ring_desc+12, (uint8_t *)&val, 4); |
1928 | a41b2ff2 | pbrook | txbufHI = le32_to_cpu(val); |
1929 | a41b2ff2 | pbrook | |
1930 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode TX descriptor %d %08x %08x %08x %08x\n",
|
1931 | a41b2ff2 | pbrook | descriptor, |
1932 | 6cadb320 | bellard | txdw0, txdw1, txbufLO, txbufHI)); |
1933 | a41b2ff2 | pbrook | |
1934 | a41b2ff2 | pbrook | /* w0 ownership flag */
|
1935 | a41b2ff2 | pbrook | #define CP_TX_OWN (1<<31) |
1936 | a41b2ff2 | pbrook | /* w0 end of ring flag */
|
1937 | a41b2ff2 | pbrook | #define CP_TX_EOR (1<<30) |
1938 | a41b2ff2 | pbrook | /* first segment of received packet flag */
|
1939 | a41b2ff2 | pbrook | #define CP_TX_FS (1<<29) |
1940 | a41b2ff2 | pbrook | /* last segment of received packet flag */
|
1941 | a41b2ff2 | pbrook | #define CP_TX_LS (1<<28) |
1942 | a41b2ff2 | pbrook | /* large send packet flag */
|
1943 | a41b2ff2 | pbrook | #define CP_TX_LGSEN (1<<27) |
1944 | 718da2b9 | bellard | /* large send MSS mask, bits 16...25 */
|
1945 | 718da2b9 | bellard | #define CP_TC_LGSEN_MSS_MASK ((1 << 12) - 1) |
1946 | 718da2b9 | bellard | |
1947 | a41b2ff2 | pbrook | /* IP checksum offload flag */
|
1948 | a41b2ff2 | pbrook | #define CP_TX_IPCS (1<<18) |
1949 | a41b2ff2 | pbrook | /* UDP checksum offload flag */
|
1950 | a41b2ff2 | pbrook | #define CP_TX_UDPCS (1<<17) |
1951 | a41b2ff2 | pbrook | /* TCP checksum offload flag */
|
1952 | a41b2ff2 | pbrook | #define CP_TX_TCPCS (1<<16) |
1953 | a41b2ff2 | pbrook | |
1954 | a41b2ff2 | pbrook | /* w0 bits 0...15 : buffer size */
|
1955 | a41b2ff2 | pbrook | #define CP_TX_BUFFER_SIZE (1<<16) |
1956 | a41b2ff2 | pbrook | #define CP_TX_BUFFER_SIZE_MASK (CP_TX_BUFFER_SIZE - 1) |
1957 | a41b2ff2 | pbrook | /* w1 tag available flag */
|
1958 | a41b2ff2 | pbrook | #define CP_RX_TAGC (1<<17) |
1959 | a41b2ff2 | pbrook | /* w1 bits 0...15 : VLAN tag */
|
1960 | a41b2ff2 | pbrook | #define CP_TX_VLAN_TAG_MASK ((1<<16) - 1) |
1961 | a41b2ff2 | pbrook | /* w2 low 32bit of Rx buffer ptr */
|
1962 | a41b2ff2 | pbrook | /* w3 high 32bit of Rx buffer ptr */
|
1963 | a41b2ff2 | pbrook | |
1964 | a41b2ff2 | pbrook | /* set after transmission */
|
1965 | a41b2ff2 | pbrook | /* FIFO underrun flag */
|
1966 | a41b2ff2 | pbrook | #define CP_TX_STATUS_UNF (1<<25) |
1967 | a41b2ff2 | pbrook | /* transmit error summary flag, valid if set any of three below */
|
1968 | a41b2ff2 | pbrook | #define CP_TX_STATUS_TES (1<<23) |
1969 | a41b2ff2 | pbrook | /* out-of-window collision flag */
|
1970 | a41b2ff2 | pbrook | #define CP_TX_STATUS_OWC (1<<22) |
1971 | a41b2ff2 | pbrook | /* link failure flag */
|
1972 | a41b2ff2 | pbrook | #define CP_TX_STATUS_LNKF (1<<21) |
1973 | a41b2ff2 | pbrook | /* excessive collisions flag */
|
1974 | a41b2ff2 | pbrook | #define CP_TX_STATUS_EXC (1<<20) |
1975 | a41b2ff2 | pbrook | |
1976 | a41b2ff2 | pbrook | if (!(txdw0 & CP_TX_OWN))
|
1977 | a41b2ff2 | pbrook | { |
1978 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: C+ Tx mode : descriptor %d is owned by host\n", descriptor));
|
1979 | a41b2ff2 | pbrook | return 0 ; |
1980 | a41b2ff2 | pbrook | } |
1981 | a41b2ff2 | pbrook | |
1982 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ Tx mode : transmitting from descriptor %d\n", descriptor));
|
1983 | 6cadb320 | bellard | |
1984 | 6cadb320 | bellard | if (txdw0 & CP_TX_FS)
|
1985 | 6cadb320 | bellard | { |
1986 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ Tx mode : descriptor %d is first segment descriptor\n", descriptor));
|
1987 | 6cadb320 | bellard | |
1988 | 6cadb320 | bellard | /* reset internal buffer offset */
|
1989 | 6cadb320 | bellard | s->cplus_txbuffer_offset = 0;
|
1990 | 6cadb320 | bellard | } |
1991 | a41b2ff2 | pbrook | |
1992 | a41b2ff2 | pbrook | int txsize = txdw0 & CP_TX_BUFFER_SIZE_MASK;
|
1993 | a41b2ff2 | pbrook | target_phys_addr_t tx_addr = rtl8139_addr64(txbufLO, txbufHI); |
1994 | a41b2ff2 | pbrook | |
1995 | 6cadb320 | bellard | /* make sure we have enough space to assemble the packet */
|
1996 | 6cadb320 | bellard | if (!s->cplus_txbuffer)
|
1997 | 6cadb320 | bellard | { |
1998 | 6cadb320 | bellard | s->cplus_txbuffer_len = CP_TX_BUFFER_SIZE; |
1999 | 6cadb320 | bellard | s->cplus_txbuffer = malloc(s->cplus_txbuffer_len); |
2000 | 6cadb320 | bellard | s->cplus_txbuffer_offset = 0;
|
2001 | 718da2b9 | bellard | |
2002 | 718da2b9 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode transmission buffer allocated space %d\n", s->cplus_txbuffer_len));
|
2003 | 6cadb320 | bellard | } |
2004 | 6cadb320 | bellard | |
2005 | 6cadb320 | bellard | while (s->cplus_txbuffer && s->cplus_txbuffer_offset + txsize >= s->cplus_txbuffer_len)
|
2006 | 6cadb320 | bellard | { |
2007 | 6cadb320 | bellard | s->cplus_txbuffer_len += CP_TX_BUFFER_SIZE; |
2008 | 6cadb320 | bellard | s->cplus_txbuffer = realloc(s->cplus_txbuffer, s->cplus_txbuffer_len); |
2009 | a41b2ff2 | pbrook | |
2010 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode transmission buffer space changed to %d\n", s->cplus_txbuffer_len));
|
2011 | 6cadb320 | bellard | } |
2012 | 6cadb320 | bellard | |
2013 | 6cadb320 | bellard | if (!s->cplus_txbuffer)
|
2014 | 6cadb320 | bellard | { |
2015 | 6cadb320 | bellard | /* out of memory */
|
2016 | a41b2ff2 | pbrook | |
2017 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode transmiter failed to reallocate %d bytes\n", s->cplus_txbuffer_len));
|
2018 | 6cadb320 | bellard | |
2019 | 6cadb320 | bellard | /* update tally counter */
|
2020 | 6cadb320 | bellard | ++s->tally_counters.TxERR; |
2021 | 6cadb320 | bellard | ++s->tally_counters.TxAbt; |
2022 | 6cadb320 | bellard | |
2023 | 6cadb320 | bellard | return 0; |
2024 | 6cadb320 | bellard | } |
2025 | 6cadb320 | bellard | |
2026 | 6cadb320 | bellard | /* append more data to the packet */
|
2027 | 6cadb320 | bellard | |
2028 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode transmit reading %d bytes from host memory at %016" PRIx64 " to offset %d\n", |
2029 | 6cadb320 | bellard | txsize, (uint64_t)tx_addr, s->cplus_txbuffer_offset)); |
2030 | 6cadb320 | bellard | |
2031 | 6cadb320 | bellard | cpu_physical_memory_read(tx_addr, s->cplus_txbuffer + s->cplus_txbuffer_offset, txsize); |
2032 | 6cadb320 | bellard | s->cplus_txbuffer_offset += txsize; |
2033 | 6cadb320 | bellard | |
2034 | 6cadb320 | bellard | /* seek to next Rx descriptor */
|
2035 | 6cadb320 | bellard | if (txdw0 & CP_TX_EOR)
|
2036 | 6cadb320 | bellard | { |
2037 | 6cadb320 | bellard | s->currCPlusTxDesc = 0;
|
2038 | 6cadb320 | bellard | } |
2039 | 6cadb320 | bellard | else
|
2040 | 6cadb320 | bellard | { |
2041 | 6cadb320 | bellard | ++s->currCPlusTxDesc; |
2042 | 6cadb320 | bellard | if (s->currCPlusTxDesc >= 64) |
2043 | 6cadb320 | bellard | s->currCPlusTxDesc = 0;
|
2044 | 6cadb320 | bellard | } |
2045 | a41b2ff2 | pbrook | |
2046 | a41b2ff2 | pbrook | /* transfer ownership to target */
|
2047 | a41b2ff2 | pbrook | txdw0 &= ~CP_RX_OWN; |
2048 | a41b2ff2 | pbrook | |
2049 | a41b2ff2 | pbrook | /* reset error indicator bits */
|
2050 | a41b2ff2 | pbrook | txdw0 &= ~CP_TX_STATUS_UNF; |
2051 | a41b2ff2 | pbrook | txdw0 &= ~CP_TX_STATUS_TES; |
2052 | a41b2ff2 | pbrook | txdw0 &= ~CP_TX_STATUS_OWC; |
2053 | a41b2ff2 | pbrook | txdw0 &= ~CP_TX_STATUS_LNKF; |
2054 | a41b2ff2 | pbrook | txdw0 &= ~CP_TX_STATUS_EXC; |
2055 | a41b2ff2 | pbrook | |
2056 | a41b2ff2 | pbrook | /* update ring data */
|
2057 | a41b2ff2 | pbrook | val = cpu_to_le32(txdw0); |
2058 | a41b2ff2 | pbrook | cpu_physical_memory_write(cplus_tx_ring_desc, (uint8_t *)&val, 4);
|
2059 | a41b2ff2 | pbrook | // val = cpu_to_le32(txdw1);
|
2060 | a41b2ff2 | pbrook | // cpu_physical_memory_write(cplus_tx_ring_desc+4, &val, 4);
|
2061 | a41b2ff2 | pbrook | |
2062 | 6cadb320 | bellard | /* Now decide if descriptor being processed is holding the last segment of packet */
|
2063 | 6cadb320 | bellard | if (txdw0 & CP_TX_LS)
|
2064 | a41b2ff2 | pbrook | { |
2065 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ Tx mode : descriptor %d is last segment descriptor\n", descriptor));
|
2066 | 6cadb320 | bellard | |
2067 | 6cadb320 | bellard | /* can transfer fully assembled packet */
|
2068 | 6cadb320 | bellard | |
2069 | 6cadb320 | bellard | uint8_t *saved_buffer = s->cplus_txbuffer; |
2070 | 6cadb320 | bellard | int saved_size = s->cplus_txbuffer_offset;
|
2071 | 6cadb320 | bellard | int saved_buffer_len = s->cplus_txbuffer_len;
|
2072 | 6cadb320 | bellard | |
2073 | 6cadb320 | bellard | /* reset the card space to protect from recursive call */
|
2074 | 6cadb320 | bellard | s->cplus_txbuffer = NULL;
|
2075 | 6cadb320 | bellard | s->cplus_txbuffer_offset = 0;
|
2076 | 6cadb320 | bellard | s->cplus_txbuffer_len = 0;
|
2077 | 6cadb320 | bellard | |
2078 | 718da2b9 | bellard | if (txdw0 & (CP_TX_IPCS | CP_TX_UDPCS | CP_TX_TCPCS | CP_TX_LGSEN))
|
2079 | 6cadb320 | bellard | { |
2080 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode offloaded task checksum\n"));
|
2081 | 6cadb320 | bellard | |
2082 | 6cadb320 | bellard | #define ETH_P_IP 0x0800 /* Internet Protocol packet */ |
2083 | 6cadb320 | bellard | #define ETH_HLEN 14 |
2084 | 718da2b9 | bellard | #define ETH_MTU 1500 |
2085 | 6cadb320 | bellard | |
2086 | 6cadb320 | bellard | /* ip packet header */
|
2087 | 718da2b9 | bellard | ip_header *ip = 0;
|
2088 | 6cadb320 | bellard | int hlen = 0; |
2089 | 718da2b9 | bellard | uint8_t ip_protocol = 0;
|
2090 | 718da2b9 | bellard | uint16_t ip_data_len = 0;
|
2091 | 6cadb320 | bellard | |
2092 | 718da2b9 | bellard | uint8_t *eth_payload_data = 0;
|
2093 | 718da2b9 | bellard | size_t eth_payload_len = 0;
|
2094 | 6cadb320 | bellard | |
2095 | 718da2b9 | bellard | int proto = be16_to_cpu(*(uint16_t *)(saved_buffer + 12)); |
2096 | 6cadb320 | bellard | if (proto == ETH_P_IP)
|
2097 | 6cadb320 | bellard | { |
2098 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode has IP packet\n"));
|
2099 | 6cadb320 | bellard | |
2100 | 6cadb320 | bellard | /* not aligned */
|
2101 | 718da2b9 | bellard | eth_payload_data = saved_buffer + ETH_HLEN; |
2102 | 718da2b9 | bellard | eth_payload_len = saved_size - ETH_HLEN; |
2103 | 6cadb320 | bellard | |
2104 | 718da2b9 | bellard | ip = (ip_header*)eth_payload_data; |
2105 | 6cadb320 | bellard | |
2106 | 718da2b9 | bellard | if (IP_HEADER_VERSION(ip) != IP_HEADER_VERSION_4) {
|
2107 | 718da2b9 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode packet has bad IP version %d expected %d\n", IP_HEADER_VERSION(ip), IP_HEADER_VERSION_4));
|
2108 | 6cadb320 | bellard | ip = NULL;
|
2109 | 6cadb320 | bellard | } else {
|
2110 | 718da2b9 | bellard | hlen = IP_HEADER_LENGTH(ip); |
2111 | 718da2b9 | bellard | ip_protocol = ip->ip_p; |
2112 | 718da2b9 | bellard | ip_data_len = be16_to_cpu(ip->ip_len) - hlen; |
2113 | 6cadb320 | bellard | } |
2114 | 6cadb320 | bellard | } |
2115 | 6cadb320 | bellard | |
2116 | 6cadb320 | bellard | if (ip)
|
2117 | 6cadb320 | bellard | { |
2118 | 6cadb320 | bellard | if (txdw0 & CP_TX_IPCS)
|
2119 | 6cadb320 | bellard | { |
2120 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode need IP checksum\n"));
|
2121 | 6cadb320 | bellard | |
2122 | 718da2b9 | bellard | if (hlen<sizeof(ip_header) || hlen>eth_payload_len) {/* min header length */ |
2123 | 6cadb320 | bellard | /* bad packet header len */
|
2124 | 6cadb320 | bellard | /* or packet too short */
|
2125 | 6cadb320 | bellard | } |
2126 | 6cadb320 | bellard | else
|
2127 | 6cadb320 | bellard | { |
2128 | 6cadb320 | bellard | ip->ip_sum = 0;
|
2129 | 718da2b9 | bellard | ip->ip_sum = ip_checksum(ip, hlen); |
2130 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode IP header len=%d checksum=%04x\n", hlen, ip->ip_sum));
|
2131 | 6cadb320 | bellard | } |
2132 | 6cadb320 | bellard | } |
2133 | 6cadb320 | bellard | |
2134 | 718da2b9 | bellard | if ((txdw0 & CP_TX_LGSEN) && ip_protocol == IP_PROTO_TCP)
|
2135 | 6cadb320 | bellard | { |
2136 | 718da2b9 | bellard | #if defined (DEBUG_RTL8139)
|
2137 | 718da2b9 | bellard | int large_send_mss = (txdw0 >> 16) & CP_TC_LGSEN_MSS_MASK; |
2138 | 718da2b9 | bellard | #endif
|
2139 | 718da2b9 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode offloaded task TSO MTU=%d IP data %d frame data %d specified MSS=%d\n",
|
2140 | 718da2b9 | bellard | ETH_MTU, ip_data_len, saved_size - ETH_HLEN, large_send_mss)); |
2141 | 6cadb320 | bellard | |
2142 | 718da2b9 | bellard | int tcp_send_offset = 0; |
2143 | 718da2b9 | bellard | int send_count = 0; |
2144 | 6cadb320 | bellard | |
2145 | 6cadb320 | bellard | /* maximum IP header length is 60 bytes */
|
2146 | 6cadb320 | bellard | uint8_t saved_ip_header[60];
|
2147 | 6cadb320 | bellard | |
2148 | 718da2b9 | bellard | /* save IP header template; data area is used in tcp checksum calculation */
|
2149 | 718da2b9 | bellard | memcpy(saved_ip_header, eth_payload_data, hlen); |
2150 | 718da2b9 | bellard | |
2151 | 718da2b9 | bellard | /* a placeholder for checksum calculation routine in tcp case */
|
2152 | 718da2b9 | bellard | uint8_t *data_to_checksum = eth_payload_data + hlen - 12;
|
2153 | 718da2b9 | bellard | // size_t data_to_checksum_len = eth_payload_len - hlen + 12;
|
2154 | 718da2b9 | bellard | |
2155 | 718da2b9 | bellard | /* pointer to TCP header */
|
2156 | 718da2b9 | bellard | tcp_header *p_tcp_hdr = (tcp_header*)(eth_payload_data + hlen); |
2157 | 718da2b9 | bellard | |
2158 | 718da2b9 | bellard | int tcp_hlen = TCP_HEADER_DATA_OFFSET(p_tcp_hdr);
|
2159 | 718da2b9 | bellard | |
2160 | 718da2b9 | bellard | /* ETH_MTU = ip header len + tcp header len + payload */
|
2161 | 718da2b9 | bellard | int tcp_data_len = ip_data_len - tcp_hlen;
|
2162 | 718da2b9 | bellard | int tcp_chunk_size = ETH_MTU - hlen - tcp_hlen;
|
2163 | 718da2b9 | bellard | |
2164 | 718da2b9 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode TSO IP data len %d TCP hlen %d TCP data len %d TCP chunk size %d\n",
|
2165 | 718da2b9 | bellard | ip_data_len, tcp_hlen, tcp_data_len, tcp_chunk_size)); |
2166 | 718da2b9 | bellard | |
2167 | 718da2b9 | bellard | /* note the cycle below overwrites IP header data,
|
2168 | 718da2b9 | bellard | but restores it from saved_ip_header before sending packet */
|
2169 | 718da2b9 | bellard | |
2170 | 718da2b9 | bellard | int is_last_frame = 0; |
2171 | 718da2b9 | bellard | |
2172 | 718da2b9 | bellard | for (tcp_send_offset = 0; tcp_send_offset < tcp_data_len; tcp_send_offset += tcp_chunk_size) |
2173 | 718da2b9 | bellard | { |
2174 | 718da2b9 | bellard | uint16_t chunk_size = tcp_chunk_size; |
2175 | 718da2b9 | bellard | |
2176 | 718da2b9 | bellard | /* check if this is the last frame */
|
2177 | 718da2b9 | bellard | if (tcp_send_offset + tcp_chunk_size >= tcp_data_len)
|
2178 | 718da2b9 | bellard | { |
2179 | 718da2b9 | bellard | is_last_frame = 1;
|
2180 | 718da2b9 | bellard | chunk_size = tcp_data_len - tcp_send_offset; |
2181 | 718da2b9 | bellard | } |
2182 | 718da2b9 | bellard | |
2183 | 718da2b9 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode TSO TCP seqno %08x\n", be32_to_cpu(p_tcp_hdr->th_seq)));
|
2184 | 718da2b9 | bellard | |
2185 | 718da2b9 | bellard | /* add 4 TCP pseudoheader fields */
|
2186 | 718da2b9 | bellard | /* copy IP source and destination fields */
|
2187 | 718da2b9 | bellard | memcpy(data_to_checksum, saved_ip_header + 12, 8); |
2188 | 718da2b9 | bellard | |
2189 | 718da2b9 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode TSO calculating TCP checksum for packet with %d bytes data\n", tcp_hlen + chunk_size));
|
2190 | 718da2b9 | bellard | |
2191 | 718da2b9 | bellard | if (tcp_send_offset)
|
2192 | 718da2b9 | bellard | { |
2193 | 718da2b9 | bellard | memcpy((uint8_t*)p_tcp_hdr + tcp_hlen, (uint8_t*)p_tcp_hdr + tcp_hlen + tcp_send_offset, chunk_size); |
2194 | 718da2b9 | bellard | } |
2195 | 718da2b9 | bellard | |
2196 | 718da2b9 | bellard | /* keep PUSH and FIN flags only for the last frame */
|
2197 | 718da2b9 | bellard | if (!is_last_frame)
|
2198 | 718da2b9 | bellard | { |
2199 | 718da2b9 | bellard | TCP_HEADER_CLEAR_FLAGS(p_tcp_hdr, TCP_FLAG_PUSH|TCP_FLAG_FIN); |
2200 | 718da2b9 | bellard | } |
2201 | 6cadb320 | bellard | |
2202 | 718da2b9 | bellard | /* recalculate TCP checksum */
|
2203 | 718da2b9 | bellard | ip_pseudo_header *p_tcpip_hdr = (ip_pseudo_header *)data_to_checksum; |
2204 | 718da2b9 | bellard | p_tcpip_hdr->zeros = 0;
|
2205 | 718da2b9 | bellard | p_tcpip_hdr->ip_proto = IP_PROTO_TCP; |
2206 | 718da2b9 | bellard | p_tcpip_hdr->ip_payload = cpu_to_be16(tcp_hlen + chunk_size); |
2207 | 718da2b9 | bellard | |
2208 | 718da2b9 | bellard | p_tcp_hdr->th_sum = 0;
|
2209 | 718da2b9 | bellard | |
2210 | 718da2b9 | bellard | int tcp_checksum = ip_checksum(data_to_checksum, tcp_hlen + chunk_size + 12); |
2211 | 718da2b9 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode TSO TCP checksum %04x\n", tcp_checksum));
|
2212 | 718da2b9 | bellard | |
2213 | 718da2b9 | bellard | p_tcp_hdr->th_sum = tcp_checksum; |
2214 | 718da2b9 | bellard | |
2215 | 718da2b9 | bellard | /* restore IP header */
|
2216 | 718da2b9 | bellard | memcpy(eth_payload_data, saved_ip_header, hlen); |
2217 | 718da2b9 | bellard | |
2218 | 718da2b9 | bellard | /* set IP data length and recalculate IP checksum */
|
2219 | 718da2b9 | bellard | ip->ip_len = cpu_to_be16(hlen + tcp_hlen + chunk_size); |
2220 | 718da2b9 | bellard | |
2221 | 718da2b9 | bellard | /* increment IP id for subsequent frames */
|
2222 | 718da2b9 | bellard | ip->ip_id = cpu_to_be16(tcp_send_offset/tcp_chunk_size + be16_to_cpu(ip->ip_id)); |
2223 | 718da2b9 | bellard | |
2224 | 718da2b9 | bellard | ip->ip_sum = 0;
|
2225 | 718da2b9 | bellard | ip->ip_sum = ip_checksum(eth_payload_data, hlen); |
2226 | 718da2b9 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode TSO IP header len=%d checksum=%04x\n", hlen, ip->ip_sum));
|
2227 | 718da2b9 | bellard | |
2228 | 718da2b9 | bellard | int tso_send_size = ETH_HLEN + hlen + tcp_hlen + chunk_size;
|
2229 | 718da2b9 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode TSO transferring packet size %d\n", tso_send_size));
|
2230 | 718da2b9 | bellard | rtl8139_transfer_frame(s, saved_buffer, tso_send_size, 0);
|
2231 | 718da2b9 | bellard | |
2232 | 718da2b9 | bellard | /* add transferred count to TCP sequence number */
|
2233 | 718da2b9 | bellard | p_tcp_hdr->th_seq = cpu_to_be32(chunk_size + be32_to_cpu(p_tcp_hdr->th_seq)); |
2234 | 718da2b9 | bellard | ++send_count; |
2235 | 718da2b9 | bellard | } |
2236 | 718da2b9 | bellard | |
2237 | 718da2b9 | bellard | /* Stop sending this frame */
|
2238 | 718da2b9 | bellard | saved_size = 0;
|
2239 | 718da2b9 | bellard | } |
2240 | 718da2b9 | bellard | else if (txdw0 & (CP_TX_TCPCS|CP_TX_UDPCS)) |
2241 | 718da2b9 | bellard | { |
2242 | 718da2b9 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode need TCP or UDP checksum\n"));
|
2243 | 718da2b9 | bellard | |
2244 | 718da2b9 | bellard | /* maximum IP header length is 60 bytes */
|
2245 | 718da2b9 | bellard | uint8_t saved_ip_header[60];
|
2246 | 718da2b9 | bellard | memcpy(saved_ip_header, eth_payload_data, hlen); |
2247 | 718da2b9 | bellard | |
2248 | 718da2b9 | bellard | uint8_t *data_to_checksum = eth_payload_data + hlen - 12;
|
2249 | 718da2b9 | bellard | // size_t data_to_checksum_len = eth_payload_len - hlen + 12;
|
2250 | 6cadb320 | bellard | |
2251 | 6cadb320 | bellard | /* add 4 TCP pseudoheader fields */
|
2252 | 6cadb320 | bellard | /* copy IP source and destination fields */
|
2253 | 718da2b9 | bellard | memcpy(data_to_checksum, saved_ip_header + 12, 8); |
2254 | 6cadb320 | bellard | |
2255 | 718da2b9 | bellard | if ((txdw0 & CP_TX_TCPCS) && ip_protocol == IP_PROTO_TCP)
|
2256 | 6cadb320 | bellard | { |
2257 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode calculating TCP checksum for packet with %d bytes data\n", ip_data_len));
|
2258 | 6cadb320 | bellard | |
2259 | 718da2b9 | bellard | ip_pseudo_header *p_tcpip_hdr = (ip_pseudo_header *)data_to_checksum; |
2260 | 718da2b9 | bellard | p_tcpip_hdr->zeros = 0;
|
2261 | 718da2b9 | bellard | p_tcpip_hdr->ip_proto = IP_PROTO_TCP; |
2262 | 718da2b9 | bellard | p_tcpip_hdr->ip_payload = cpu_to_be16(ip_data_len); |
2263 | 6cadb320 | bellard | |
2264 | 718da2b9 | bellard | tcp_header* p_tcp_hdr = (tcp_header *) (data_to_checksum+12);
|
2265 | 6cadb320 | bellard | |
2266 | 6cadb320 | bellard | p_tcp_hdr->th_sum = 0;
|
2267 | 6cadb320 | bellard | |
2268 | 718da2b9 | bellard | int tcp_checksum = ip_checksum(data_to_checksum, ip_data_len + 12); |
2269 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode TCP checksum %04x\n", tcp_checksum));
|
2270 | 6cadb320 | bellard | |
2271 | 6cadb320 | bellard | p_tcp_hdr->th_sum = tcp_checksum; |
2272 | 6cadb320 | bellard | } |
2273 | 718da2b9 | bellard | else if ((txdw0 & CP_TX_UDPCS) && ip_protocol == IP_PROTO_UDP) |
2274 | 6cadb320 | bellard | { |
2275 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode calculating UDP checksum for packet with %d bytes data\n", ip_data_len));
|
2276 | 6cadb320 | bellard | |
2277 | 718da2b9 | bellard | ip_pseudo_header *p_udpip_hdr = (ip_pseudo_header *)data_to_checksum; |
2278 | 718da2b9 | bellard | p_udpip_hdr->zeros = 0;
|
2279 | 718da2b9 | bellard | p_udpip_hdr->ip_proto = IP_PROTO_UDP; |
2280 | 718da2b9 | bellard | p_udpip_hdr->ip_payload = cpu_to_be16(ip_data_len); |
2281 | 6cadb320 | bellard | |
2282 | 718da2b9 | bellard | udp_header *p_udp_hdr = (udp_header *) (data_to_checksum+12);
|
2283 | 6cadb320 | bellard | |
2284 | 6cadb320 | bellard | p_udp_hdr->uh_sum = 0;
|
2285 | 6cadb320 | bellard | |
2286 | 718da2b9 | bellard | int udp_checksum = ip_checksum(data_to_checksum, ip_data_len + 12); |
2287 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode UDP checksum %04x\n", udp_checksum));
|
2288 | 6cadb320 | bellard | |
2289 | 6cadb320 | bellard | p_udp_hdr->uh_sum = udp_checksum; |
2290 | 6cadb320 | bellard | } |
2291 | 6cadb320 | bellard | |
2292 | 6cadb320 | bellard | /* restore IP header */
|
2293 | 718da2b9 | bellard | memcpy(eth_payload_data, saved_ip_header, hlen); |
2294 | 6cadb320 | bellard | } |
2295 | 6cadb320 | bellard | } |
2296 | 6cadb320 | bellard | } |
2297 | 6cadb320 | bellard | |
2298 | 6cadb320 | bellard | /* update tally counter */
|
2299 | 6cadb320 | bellard | ++s->tally_counters.TxOk; |
2300 | 6cadb320 | bellard | |
2301 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode transmitting %d bytes packet\n", saved_size));
|
2302 | 6cadb320 | bellard | |
2303 | 718da2b9 | bellard | rtl8139_transfer_frame(s, saved_buffer, saved_size, 1);
|
2304 | 6cadb320 | bellard | |
2305 | 6cadb320 | bellard | /* restore card space if there was no recursion and reset offset */
|
2306 | 6cadb320 | bellard | if (!s->cplus_txbuffer)
|
2307 | 6cadb320 | bellard | { |
2308 | 6cadb320 | bellard | s->cplus_txbuffer = saved_buffer; |
2309 | 6cadb320 | bellard | s->cplus_txbuffer_len = saved_buffer_len; |
2310 | 6cadb320 | bellard | s->cplus_txbuffer_offset = 0;
|
2311 | 6cadb320 | bellard | } |
2312 | 6cadb320 | bellard | else
|
2313 | 6cadb320 | bellard | { |
2314 | 6cadb320 | bellard | free(saved_buffer); |
2315 | 6cadb320 | bellard | } |
2316 | a41b2ff2 | pbrook | } |
2317 | a41b2ff2 | pbrook | else
|
2318 | a41b2ff2 | pbrook | { |
2319 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: +++ C+ mode transmission continue to next descriptor\n"));
|
2320 | a41b2ff2 | pbrook | } |
2321 | a41b2ff2 | pbrook | |
2322 | a41b2ff2 | pbrook | return 1; |
2323 | a41b2ff2 | pbrook | } |
2324 | a41b2ff2 | pbrook | |
2325 | a41b2ff2 | pbrook | static void rtl8139_cplus_transmit(RTL8139State *s) |
2326 | a41b2ff2 | pbrook | { |
2327 | a41b2ff2 | pbrook | int txcount = 0; |
2328 | a41b2ff2 | pbrook | |
2329 | a41b2ff2 | pbrook | while (rtl8139_cplus_transmit_one(s))
|
2330 | a41b2ff2 | pbrook | { |
2331 | a41b2ff2 | pbrook | ++txcount; |
2332 | a41b2ff2 | pbrook | } |
2333 | a41b2ff2 | pbrook | |
2334 | a41b2ff2 | pbrook | /* Mark transfer completed */
|
2335 | a41b2ff2 | pbrook | if (!txcount)
|
2336 | a41b2ff2 | pbrook | { |
2337 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: C+ mode : transmitter queue stalled, current TxDesc = %d\n",
|
2338 | 6cadb320 | bellard | s->currCPlusTxDesc)); |
2339 | a41b2ff2 | pbrook | } |
2340 | a41b2ff2 | pbrook | else
|
2341 | a41b2ff2 | pbrook | { |
2342 | a41b2ff2 | pbrook | /* update interrupt status */
|
2343 | a41b2ff2 | pbrook | s->IntrStatus |= TxOK; |
2344 | a41b2ff2 | pbrook | rtl8139_update_irq(s); |
2345 | a41b2ff2 | pbrook | } |
2346 | a41b2ff2 | pbrook | } |
2347 | a41b2ff2 | pbrook | |
2348 | a41b2ff2 | pbrook | static void rtl8139_transmit(RTL8139State *s) |
2349 | a41b2ff2 | pbrook | { |
2350 | a41b2ff2 | pbrook | int descriptor = s->currTxDesc, txcount = 0; |
2351 | a41b2ff2 | pbrook | |
2352 | a41b2ff2 | pbrook | /*while*/
|
2353 | a41b2ff2 | pbrook | if (rtl8139_transmit_one(s, descriptor))
|
2354 | a41b2ff2 | pbrook | { |
2355 | a41b2ff2 | pbrook | ++s->currTxDesc; |
2356 | a41b2ff2 | pbrook | s->currTxDesc %= 4;
|
2357 | a41b2ff2 | pbrook | ++txcount; |
2358 | a41b2ff2 | pbrook | } |
2359 | a41b2ff2 | pbrook | |
2360 | a41b2ff2 | pbrook | /* Mark transfer completed */
|
2361 | a41b2ff2 | pbrook | if (!txcount)
|
2362 | a41b2ff2 | pbrook | { |
2363 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: transmitter queue stalled, current TxDesc = %d\n", s->currTxDesc));
|
2364 | a41b2ff2 | pbrook | } |
2365 | a41b2ff2 | pbrook | } |
2366 | a41b2ff2 | pbrook | |
2367 | a41b2ff2 | pbrook | static void rtl8139_TxStatus_write(RTL8139State *s, uint32_t txRegOffset, uint32_t val) |
2368 | a41b2ff2 | pbrook | { |
2369 | a41b2ff2 | pbrook | |
2370 | a41b2ff2 | pbrook | int descriptor = txRegOffset/4; |
2371 | 6cadb320 | bellard | |
2372 | 6cadb320 | bellard | /* handle C+ transmit mode register configuration */
|
2373 | 6cadb320 | bellard | |
2374 | 6cadb320 | bellard | if (rtl8139_cp_transmitter_enabled(s))
|
2375 | 6cadb320 | bellard | { |
2376 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139C+ DTCCR write offset=0x%x val=0x%08x descriptor=%d\n", txRegOffset, val, descriptor));
|
2377 | 6cadb320 | bellard | |
2378 | 6cadb320 | bellard | /* handle Dump Tally Counters command */
|
2379 | 6cadb320 | bellard | s->TxStatus[descriptor] = val; |
2380 | 6cadb320 | bellard | |
2381 | 6cadb320 | bellard | if (descriptor == 0 && (val & 0x8)) |
2382 | 6cadb320 | bellard | { |
2383 | 6cadb320 | bellard | target_phys_addr_t tc_addr = rtl8139_addr64(s->TxStatus[0] & ~0x3f, s->TxStatus[1]); |
2384 | 6cadb320 | bellard | |
2385 | 6cadb320 | bellard | /* dump tally counters to specified memory location */
|
2386 | 6cadb320 | bellard | RTL8139TallyCounters_physical_memory_write( tc_addr, &s->tally_counters); |
2387 | 6cadb320 | bellard | |
2388 | 6cadb320 | bellard | /* mark dump completed */
|
2389 | 6cadb320 | bellard | s->TxStatus[0] &= ~0x8; |
2390 | 6cadb320 | bellard | } |
2391 | 6cadb320 | bellard | |
2392 | 6cadb320 | bellard | return;
|
2393 | 6cadb320 | bellard | } |
2394 | 6cadb320 | bellard | |
2395 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: TxStatus write offset=0x%x val=0x%08x descriptor=%d\n", txRegOffset, val, descriptor));
|
2396 | a41b2ff2 | pbrook | |
2397 | a41b2ff2 | pbrook | /* mask only reserved bits */
|
2398 | a41b2ff2 | pbrook | val &= ~0xff00c000; /* these bits are reset on write */ |
2399 | a41b2ff2 | pbrook | val = SET_MASKED(val, 0x00c00000, s->TxStatus[descriptor]);
|
2400 | a41b2ff2 | pbrook | |
2401 | a41b2ff2 | pbrook | s->TxStatus[descriptor] = val; |
2402 | a41b2ff2 | pbrook | |
2403 | a41b2ff2 | pbrook | /* attempt to start transmission */
|
2404 | a41b2ff2 | pbrook | rtl8139_transmit(s); |
2405 | a41b2ff2 | pbrook | } |
2406 | a41b2ff2 | pbrook | |
2407 | a41b2ff2 | pbrook | static uint32_t rtl8139_TxStatus_read(RTL8139State *s, uint32_t txRegOffset)
|
2408 | a41b2ff2 | pbrook | { |
2409 | a41b2ff2 | pbrook | uint32_t ret = s->TxStatus[txRegOffset/4];
|
2410 | a41b2ff2 | pbrook | |
2411 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: TxStatus read offset=0x%x val=0x%08x\n", txRegOffset, ret));
|
2412 | a41b2ff2 | pbrook | |
2413 | a41b2ff2 | pbrook | return ret;
|
2414 | a41b2ff2 | pbrook | } |
2415 | a41b2ff2 | pbrook | |
2416 | a41b2ff2 | pbrook | static uint16_t rtl8139_TSAD_read(RTL8139State *s)
|
2417 | a41b2ff2 | pbrook | { |
2418 | a41b2ff2 | pbrook | uint16_t ret = 0;
|
2419 | a41b2ff2 | pbrook | |
2420 | a41b2ff2 | pbrook | /* Simulate TSAD, it is read only anyway */
|
2421 | a41b2ff2 | pbrook | |
2422 | a41b2ff2 | pbrook | ret = ((s->TxStatus[3] & TxStatOK )?TSAD_TOK3:0) |
2423 | a41b2ff2 | pbrook | |((s->TxStatus[2] & TxStatOK )?TSAD_TOK2:0) |
2424 | a41b2ff2 | pbrook | |((s->TxStatus[1] & TxStatOK )?TSAD_TOK1:0) |
2425 | a41b2ff2 | pbrook | |((s->TxStatus[0] & TxStatOK )?TSAD_TOK0:0) |
2426 | a41b2ff2 | pbrook | |
2427 | a41b2ff2 | pbrook | |((s->TxStatus[3] & TxUnderrun)?TSAD_TUN3:0) |
2428 | a41b2ff2 | pbrook | |((s->TxStatus[2] & TxUnderrun)?TSAD_TUN2:0) |
2429 | a41b2ff2 | pbrook | |((s->TxStatus[1] & TxUnderrun)?TSAD_TUN1:0) |
2430 | a41b2ff2 | pbrook | |((s->TxStatus[0] & TxUnderrun)?TSAD_TUN0:0) |
2431 | a41b2ff2 | pbrook | |
2432 | a41b2ff2 | pbrook | |((s->TxStatus[3] & TxAborted )?TSAD_TABT3:0) |
2433 | a41b2ff2 | pbrook | |((s->TxStatus[2] & TxAborted )?TSAD_TABT2:0) |
2434 | a41b2ff2 | pbrook | |((s->TxStatus[1] & TxAborted )?TSAD_TABT1:0) |
2435 | a41b2ff2 | pbrook | |((s->TxStatus[0] & TxAborted )?TSAD_TABT0:0) |
2436 | a41b2ff2 | pbrook | |
2437 | a41b2ff2 | pbrook | |((s->TxStatus[3] & TxHostOwns )?TSAD_OWN3:0) |
2438 | a41b2ff2 | pbrook | |((s->TxStatus[2] & TxHostOwns )?TSAD_OWN2:0) |
2439 | a41b2ff2 | pbrook | |((s->TxStatus[1] & TxHostOwns )?TSAD_OWN1:0) |
2440 | a41b2ff2 | pbrook | |((s->TxStatus[0] & TxHostOwns )?TSAD_OWN0:0) ; |
2441 | a41b2ff2 | pbrook | |
2442 | a41b2ff2 | pbrook | |
2443 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: TSAD read val=0x%04x\n", ret));
|
2444 | a41b2ff2 | pbrook | |
2445 | a41b2ff2 | pbrook | return ret;
|
2446 | a41b2ff2 | pbrook | } |
2447 | a41b2ff2 | pbrook | |
2448 | a41b2ff2 | pbrook | static uint16_t rtl8139_CSCR_read(RTL8139State *s)
|
2449 | a41b2ff2 | pbrook | { |
2450 | a41b2ff2 | pbrook | uint16_t ret = s->CSCR; |
2451 | a41b2ff2 | pbrook | |
2452 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: CSCR read val=0x%04x\n", ret));
|
2453 | a41b2ff2 | pbrook | |
2454 | a41b2ff2 | pbrook | return ret;
|
2455 | a41b2ff2 | pbrook | } |
2456 | a41b2ff2 | pbrook | |
2457 | a41b2ff2 | pbrook | static void rtl8139_TxAddr_write(RTL8139State *s, uint32_t txAddrOffset, uint32_t val) |
2458 | a41b2ff2 | pbrook | { |
2459 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: TxAddr write offset=0x%x val=0x%08x\n", txAddrOffset, val));
|
2460 | a41b2ff2 | pbrook | |
2461 | 290a0933 | ths | s->TxAddr[txAddrOffset/4] = val;
|
2462 | a41b2ff2 | pbrook | } |
2463 | a41b2ff2 | pbrook | |
2464 | a41b2ff2 | pbrook | static uint32_t rtl8139_TxAddr_read(RTL8139State *s, uint32_t txAddrOffset)
|
2465 | a41b2ff2 | pbrook | { |
2466 | 290a0933 | ths | uint32_t ret = s->TxAddr[txAddrOffset/4];
|
2467 | a41b2ff2 | pbrook | |
2468 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: TxAddr read offset=0x%x val=0x%08x\n", txAddrOffset, ret));
|
2469 | a41b2ff2 | pbrook | |
2470 | a41b2ff2 | pbrook | return ret;
|
2471 | a41b2ff2 | pbrook | } |
2472 | a41b2ff2 | pbrook | |
2473 | a41b2ff2 | pbrook | static void rtl8139_RxBufPtr_write(RTL8139State *s, uint32_t val) |
2474 | a41b2ff2 | pbrook | { |
2475 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: RxBufPtr write val=0x%04x\n", val));
|
2476 | a41b2ff2 | pbrook | |
2477 | a41b2ff2 | pbrook | /* this value is off by 16 */
|
2478 | a41b2ff2 | pbrook | s->RxBufPtr = MOD2(val + 0x10, s->RxBufferSize);
|
2479 | a41b2ff2 | pbrook | |
2480 | 6cadb320 | bellard | DEBUG_PRINT((" CAPR write: rx buffer length %d head 0x%04x read 0x%04x\n",
|
2481 | 6cadb320 | bellard | s->RxBufferSize, s->RxBufAddr, s->RxBufPtr)); |
2482 | a41b2ff2 | pbrook | } |
2483 | a41b2ff2 | pbrook | |
2484 | a41b2ff2 | pbrook | static uint32_t rtl8139_RxBufPtr_read(RTL8139State *s)
|
2485 | a41b2ff2 | pbrook | { |
2486 | a41b2ff2 | pbrook | /* this value is off by 16 */
|
2487 | a41b2ff2 | pbrook | uint32_t ret = s->RxBufPtr - 0x10;
|
2488 | a41b2ff2 | pbrook | |
2489 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: RxBufPtr read val=0x%04x\n", ret));
|
2490 | 6cadb320 | bellard | |
2491 | 6cadb320 | bellard | return ret;
|
2492 | 6cadb320 | bellard | } |
2493 | 6cadb320 | bellard | |
2494 | 6cadb320 | bellard | static uint32_t rtl8139_RxBufAddr_read(RTL8139State *s)
|
2495 | 6cadb320 | bellard | { |
2496 | 6cadb320 | bellard | /* this value is NOT off by 16 */
|
2497 | 6cadb320 | bellard | uint32_t ret = s->RxBufAddr; |
2498 | 6cadb320 | bellard | |
2499 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: RxBufAddr read val=0x%04x\n", ret));
|
2500 | a41b2ff2 | pbrook | |
2501 | a41b2ff2 | pbrook | return ret;
|
2502 | a41b2ff2 | pbrook | } |
2503 | a41b2ff2 | pbrook | |
2504 | a41b2ff2 | pbrook | static void rtl8139_RxBuf_write(RTL8139State *s, uint32_t val) |
2505 | a41b2ff2 | pbrook | { |
2506 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: RxBuf write val=0x%08x\n", val));
|
2507 | a41b2ff2 | pbrook | |
2508 | a41b2ff2 | pbrook | s->RxBuf = val; |
2509 | a41b2ff2 | pbrook | |
2510 | a41b2ff2 | pbrook | /* may need to reset rxring here */
|
2511 | a41b2ff2 | pbrook | } |
2512 | a41b2ff2 | pbrook | |
2513 | a41b2ff2 | pbrook | static uint32_t rtl8139_RxBuf_read(RTL8139State *s)
|
2514 | a41b2ff2 | pbrook | { |
2515 | a41b2ff2 | pbrook | uint32_t ret = s->RxBuf; |
2516 | a41b2ff2 | pbrook | |
2517 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: RxBuf read val=0x%08x\n", ret));
|
2518 | a41b2ff2 | pbrook | |
2519 | a41b2ff2 | pbrook | return ret;
|
2520 | a41b2ff2 | pbrook | } |
2521 | a41b2ff2 | pbrook | |
2522 | a41b2ff2 | pbrook | static void rtl8139_IntrMask_write(RTL8139State *s, uint32_t val) |
2523 | a41b2ff2 | pbrook | { |
2524 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: IntrMask write(w) val=0x%04x\n", val));
|
2525 | a41b2ff2 | pbrook | |
2526 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
2527 | a41b2ff2 | pbrook | val = SET_MASKED(val, 0x1e00, s->IntrMask);
|
2528 | a41b2ff2 | pbrook | |
2529 | a41b2ff2 | pbrook | s->IntrMask = val; |
2530 | a41b2ff2 | pbrook | |
2531 | a41b2ff2 | pbrook | rtl8139_update_irq(s); |
2532 | a41b2ff2 | pbrook | } |
2533 | a41b2ff2 | pbrook | |
2534 | a41b2ff2 | pbrook | static uint32_t rtl8139_IntrMask_read(RTL8139State *s)
|
2535 | a41b2ff2 | pbrook | { |
2536 | a41b2ff2 | pbrook | uint32_t ret = s->IntrMask; |
2537 | a41b2ff2 | pbrook | |
2538 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: IntrMask read(w) val=0x%04x\n", ret));
|
2539 | a41b2ff2 | pbrook | |
2540 | a41b2ff2 | pbrook | return ret;
|
2541 | a41b2ff2 | pbrook | } |
2542 | a41b2ff2 | pbrook | |
2543 | a41b2ff2 | pbrook | static void rtl8139_IntrStatus_write(RTL8139State *s, uint32_t val) |
2544 | a41b2ff2 | pbrook | { |
2545 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: IntrStatus write(w) val=0x%04x\n", val));
|
2546 | a41b2ff2 | pbrook | |
2547 | a41b2ff2 | pbrook | #if 0
|
2548 | a41b2ff2 | pbrook | |
2549 | a41b2ff2 | pbrook | /* writing to ISR has no effect */
|
2550 | a41b2ff2 | pbrook | |
2551 | a41b2ff2 | pbrook | return;
|
2552 | a41b2ff2 | pbrook | |
2553 | a41b2ff2 | pbrook | #else
|
2554 | a41b2ff2 | pbrook | uint16_t newStatus = s->IntrStatus & ~val; |
2555 | a41b2ff2 | pbrook | |
2556 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
2557 | a41b2ff2 | pbrook | newStatus = SET_MASKED(newStatus, 0x1e00, s->IntrStatus);
|
2558 | a41b2ff2 | pbrook | |
2559 | a41b2ff2 | pbrook | /* writing 1 to interrupt status register bit clears it */
|
2560 | a41b2ff2 | pbrook | s->IntrStatus = 0;
|
2561 | a41b2ff2 | pbrook | rtl8139_update_irq(s); |
2562 | a41b2ff2 | pbrook | |
2563 | a41b2ff2 | pbrook | s->IntrStatus = newStatus; |
2564 | a41b2ff2 | pbrook | rtl8139_update_irq(s); |
2565 | a41b2ff2 | pbrook | #endif
|
2566 | a41b2ff2 | pbrook | } |
2567 | a41b2ff2 | pbrook | |
2568 | a41b2ff2 | pbrook | static uint32_t rtl8139_IntrStatus_read(RTL8139State *s)
|
2569 | a41b2ff2 | pbrook | { |
2570 | a41b2ff2 | pbrook | uint32_t ret = s->IntrStatus; |
2571 | a41b2ff2 | pbrook | |
2572 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: IntrStatus read(w) val=0x%04x\n", ret));
|
2573 | a41b2ff2 | pbrook | |
2574 | a41b2ff2 | pbrook | #if 0
|
2575 | a41b2ff2 | pbrook | |
2576 | a41b2ff2 | pbrook | /* reading ISR clears all interrupts */
|
2577 | a41b2ff2 | pbrook | s->IntrStatus = 0;
|
2578 | a41b2ff2 | pbrook | |
2579 | a41b2ff2 | pbrook | rtl8139_update_irq(s);
|
2580 | a41b2ff2 | pbrook | |
2581 | a41b2ff2 | pbrook | #endif
|
2582 | a41b2ff2 | pbrook | |
2583 | a41b2ff2 | pbrook | return ret;
|
2584 | a41b2ff2 | pbrook | } |
2585 | a41b2ff2 | pbrook | |
2586 | a41b2ff2 | pbrook | static void rtl8139_MultiIntr_write(RTL8139State *s, uint32_t val) |
2587 | a41b2ff2 | pbrook | { |
2588 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: MultiIntr write(w) val=0x%04x\n", val));
|
2589 | a41b2ff2 | pbrook | |
2590 | a41b2ff2 | pbrook | /* mask unwriteable bits */
|
2591 | a41b2ff2 | pbrook | val = SET_MASKED(val, 0xf000, s->MultiIntr);
|
2592 | a41b2ff2 | pbrook | |
2593 | a41b2ff2 | pbrook | s->MultiIntr = val; |
2594 | a41b2ff2 | pbrook | } |
2595 | a41b2ff2 | pbrook | |
2596 | a41b2ff2 | pbrook | static uint32_t rtl8139_MultiIntr_read(RTL8139State *s)
|
2597 | a41b2ff2 | pbrook | { |
2598 | a41b2ff2 | pbrook | uint32_t ret = s->MultiIntr; |
2599 | a41b2ff2 | pbrook | |
2600 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: MultiIntr read(w) val=0x%04x\n", ret));
|
2601 | a41b2ff2 | pbrook | |
2602 | a41b2ff2 | pbrook | return ret;
|
2603 | a41b2ff2 | pbrook | } |
2604 | a41b2ff2 | pbrook | |
2605 | a41b2ff2 | pbrook | static void rtl8139_io_writeb(void *opaque, uint8_t addr, uint32_t val) |
2606 | a41b2ff2 | pbrook | { |
2607 | a41b2ff2 | pbrook | RTL8139State *s = opaque; |
2608 | a41b2ff2 | pbrook | |
2609 | a41b2ff2 | pbrook | addr &= 0xff;
|
2610 | a41b2ff2 | pbrook | |
2611 | a41b2ff2 | pbrook | switch (addr)
|
2612 | a41b2ff2 | pbrook | { |
2613 | a41b2ff2 | pbrook | case MAC0 ... MAC0+5: |
2614 | a41b2ff2 | pbrook | s->phys[addr - MAC0] = val; |
2615 | a41b2ff2 | pbrook | break;
|
2616 | a41b2ff2 | pbrook | case MAC0+6 ... MAC0+7: |
2617 | a41b2ff2 | pbrook | /* reserved */
|
2618 | a41b2ff2 | pbrook | break;
|
2619 | a41b2ff2 | pbrook | case MAR0 ... MAR0+7: |
2620 | a41b2ff2 | pbrook | s->mult[addr - MAR0] = val; |
2621 | a41b2ff2 | pbrook | break;
|
2622 | a41b2ff2 | pbrook | case ChipCmd:
|
2623 | a41b2ff2 | pbrook | rtl8139_ChipCmd_write(s, val); |
2624 | a41b2ff2 | pbrook | break;
|
2625 | a41b2ff2 | pbrook | case Cfg9346:
|
2626 | a41b2ff2 | pbrook | rtl8139_Cfg9346_write(s, val); |
2627 | a41b2ff2 | pbrook | break;
|
2628 | a41b2ff2 | pbrook | case TxConfig: /* windows driver sometimes writes using byte-lenth call */ |
2629 | a41b2ff2 | pbrook | rtl8139_TxConfig_writeb(s, val); |
2630 | a41b2ff2 | pbrook | break;
|
2631 | a41b2ff2 | pbrook | case Config0:
|
2632 | a41b2ff2 | pbrook | rtl8139_Config0_write(s, val); |
2633 | a41b2ff2 | pbrook | break;
|
2634 | a41b2ff2 | pbrook | case Config1:
|
2635 | a41b2ff2 | pbrook | rtl8139_Config1_write(s, val); |
2636 | a41b2ff2 | pbrook | break;
|
2637 | a41b2ff2 | pbrook | case Config3:
|
2638 | a41b2ff2 | pbrook | rtl8139_Config3_write(s, val); |
2639 | a41b2ff2 | pbrook | break;
|
2640 | a41b2ff2 | pbrook | case Config4:
|
2641 | a41b2ff2 | pbrook | rtl8139_Config4_write(s, val); |
2642 | a41b2ff2 | pbrook | break;
|
2643 | a41b2ff2 | pbrook | case Config5:
|
2644 | a41b2ff2 | pbrook | rtl8139_Config5_write(s, val); |
2645 | a41b2ff2 | pbrook | break;
|
2646 | a41b2ff2 | pbrook | case MediaStatus:
|
2647 | a41b2ff2 | pbrook | /* ignore */
|
2648 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: not implemented write(b) to MediaStatus val=0x%02x\n", val));
|
2649 | a41b2ff2 | pbrook | break;
|
2650 | a41b2ff2 | pbrook | |
2651 | a41b2ff2 | pbrook | case HltClk:
|
2652 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: HltClk write val=0x%08x\n", val));
|
2653 | a41b2ff2 | pbrook | if (val == 'R') |
2654 | a41b2ff2 | pbrook | { |
2655 | a41b2ff2 | pbrook | s->clock_enabled = 1;
|
2656 | a41b2ff2 | pbrook | } |
2657 | a41b2ff2 | pbrook | else if (val == 'H') |
2658 | a41b2ff2 | pbrook | { |
2659 | a41b2ff2 | pbrook | s->clock_enabled = 0;
|
2660 | a41b2ff2 | pbrook | } |
2661 | a41b2ff2 | pbrook | break;
|
2662 | a41b2ff2 | pbrook | |
2663 | a41b2ff2 | pbrook | case TxThresh:
|
2664 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139C+ TxThresh write(b) val=0x%02x\n", val));
|
2665 | a41b2ff2 | pbrook | s->TxThresh = val; |
2666 | a41b2ff2 | pbrook | break;
|
2667 | a41b2ff2 | pbrook | |
2668 | a41b2ff2 | pbrook | case TxPoll:
|
2669 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139C+ TxPoll write(b) val=0x%02x\n", val));
|
2670 | a41b2ff2 | pbrook | if (val & (1 << 7)) |
2671 | a41b2ff2 | pbrook | { |
2672 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139C+ TxPoll high priority transmission (not implemented)\n"));
|
2673 | a41b2ff2 | pbrook | //rtl8139_cplus_transmit(s);
|
2674 | a41b2ff2 | pbrook | } |
2675 | a41b2ff2 | pbrook | if (val & (1 << 6)) |
2676 | a41b2ff2 | pbrook | { |
2677 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139C+ TxPoll normal priority transmission\n"));
|
2678 | a41b2ff2 | pbrook | rtl8139_cplus_transmit(s); |
2679 | a41b2ff2 | pbrook | } |
2680 | a41b2ff2 | pbrook | |
2681 | a41b2ff2 | pbrook | break;
|
2682 | a41b2ff2 | pbrook | |
2683 | a41b2ff2 | pbrook | default:
|
2684 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: not implemented write(b) addr=0x%x val=0x%02x\n", addr, val));
|
2685 | a41b2ff2 | pbrook | break;
|
2686 | a41b2ff2 | pbrook | } |
2687 | a41b2ff2 | pbrook | } |
2688 | a41b2ff2 | pbrook | |
2689 | a41b2ff2 | pbrook | static void rtl8139_io_writew(void *opaque, uint8_t addr, uint32_t val) |
2690 | a41b2ff2 | pbrook | { |
2691 | a41b2ff2 | pbrook | RTL8139State *s = opaque; |
2692 | a41b2ff2 | pbrook | |
2693 | a41b2ff2 | pbrook | addr &= 0xfe;
|
2694 | a41b2ff2 | pbrook | |
2695 | a41b2ff2 | pbrook | switch (addr)
|
2696 | a41b2ff2 | pbrook | { |
2697 | a41b2ff2 | pbrook | case IntrMask:
|
2698 | a41b2ff2 | pbrook | rtl8139_IntrMask_write(s, val); |
2699 | a41b2ff2 | pbrook | break;
|
2700 | a41b2ff2 | pbrook | |
2701 | a41b2ff2 | pbrook | case IntrStatus:
|
2702 | a41b2ff2 | pbrook | rtl8139_IntrStatus_write(s, val); |
2703 | a41b2ff2 | pbrook | break;
|
2704 | a41b2ff2 | pbrook | |
2705 | a41b2ff2 | pbrook | case MultiIntr:
|
2706 | a41b2ff2 | pbrook | rtl8139_MultiIntr_write(s, val); |
2707 | a41b2ff2 | pbrook | break;
|
2708 | a41b2ff2 | pbrook | |
2709 | a41b2ff2 | pbrook | case RxBufPtr:
|
2710 | a41b2ff2 | pbrook | rtl8139_RxBufPtr_write(s, val); |
2711 | a41b2ff2 | pbrook | break;
|
2712 | a41b2ff2 | pbrook | |
2713 | a41b2ff2 | pbrook | case BasicModeCtrl:
|
2714 | a41b2ff2 | pbrook | rtl8139_BasicModeCtrl_write(s, val); |
2715 | a41b2ff2 | pbrook | break;
|
2716 | a41b2ff2 | pbrook | case BasicModeStatus:
|
2717 | a41b2ff2 | pbrook | rtl8139_BasicModeStatus_write(s, val); |
2718 | a41b2ff2 | pbrook | break;
|
2719 | a41b2ff2 | pbrook | case NWayAdvert:
|
2720 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: NWayAdvert write(w) val=0x%04x\n", val));
|
2721 | a41b2ff2 | pbrook | s->NWayAdvert = val; |
2722 | a41b2ff2 | pbrook | break;
|
2723 | a41b2ff2 | pbrook | case NWayLPAR:
|
2724 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: forbidden NWayLPAR write(w) val=0x%04x\n", val));
|
2725 | a41b2ff2 | pbrook | break;
|
2726 | a41b2ff2 | pbrook | case NWayExpansion:
|
2727 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: NWayExpansion write(w) val=0x%04x\n", val));
|
2728 | a41b2ff2 | pbrook | s->NWayExpansion = val; |
2729 | a41b2ff2 | pbrook | break;
|
2730 | a41b2ff2 | pbrook | |
2731 | a41b2ff2 | pbrook | case CpCmd:
|
2732 | a41b2ff2 | pbrook | rtl8139_CpCmd_write(s, val); |
2733 | a41b2ff2 | pbrook | break;
|
2734 | a41b2ff2 | pbrook | |
2735 | 6cadb320 | bellard | case IntrMitigate:
|
2736 | 6cadb320 | bellard | rtl8139_IntrMitigate_write(s, val); |
2737 | 6cadb320 | bellard | break;
|
2738 | 6cadb320 | bellard | |
2739 | a41b2ff2 | pbrook | default:
|
2740 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: ioport write(w) addr=0x%x val=0x%04x via write(b)\n", addr, val));
|
2741 | a41b2ff2 | pbrook | |
2742 | a41b2ff2 | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
2743 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr, (val >> 8) & 0xff); |
2744 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr + 1, val & 0xff); |
2745 | a41b2ff2 | pbrook | #else
|
2746 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr, val & 0xff);
|
2747 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr + 1, (val >> 8) & 0xff); |
2748 | a41b2ff2 | pbrook | #endif
|
2749 | a41b2ff2 | pbrook | break;
|
2750 | a41b2ff2 | pbrook | } |
2751 | a41b2ff2 | pbrook | } |
2752 | a41b2ff2 | pbrook | |
2753 | a41b2ff2 | pbrook | static void rtl8139_io_writel(void *opaque, uint8_t addr, uint32_t val) |
2754 | a41b2ff2 | pbrook | { |
2755 | a41b2ff2 | pbrook | RTL8139State *s = opaque; |
2756 | a41b2ff2 | pbrook | |
2757 | a41b2ff2 | pbrook | addr &= 0xfc;
|
2758 | a41b2ff2 | pbrook | |
2759 | a41b2ff2 | pbrook | switch (addr)
|
2760 | a41b2ff2 | pbrook | { |
2761 | a41b2ff2 | pbrook | case RxMissed:
|
2762 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: RxMissed clearing on write\n"));
|
2763 | a41b2ff2 | pbrook | s->RxMissed = 0;
|
2764 | a41b2ff2 | pbrook | break;
|
2765 | a41b2ff2 | pbrook | |
2766 | a41b2ff2 | pbrook | case TxConfig:
|
2767 | a41b2ff2 | pbrook | rtl8139_TxConfig_write(s, val); |
2768 | a41b2ff2 | pbrook | break;
|
2769 | a41b2ff2 | pbrook | |
2770 | a41b2ff2 | pbrook | case RxConfig:
|
2771 | a41b2ff2 | pbrook | rtl8139_RxConfig_write(s, val); |
2772 | a41b2ff2 | pbrook | break;
|
2773 | a41b2ff2 | pbrook | |
2774 | a41b2ff2 | pbrook | case TxStatus0 ... TxStatus0+4*4-1: |
2775 | a41b2ff2 | pbrook | rtl8139_TxStatus_write(s, addr-TxStatus0, val); |
2776 | a41b2ff2 | pbrook | break;
|
2777 | a41b2ff2 | pbrook | |
2778 | a41b2ff2 | pbrook | case TxAddr0 ... TxAddr0+4*4-1: |
2779 | a41b2ff2 | pbrook | rtl8139_TxAddr_write(s, addr-TxAddr0, val); |
2780 | a41b2ff2 | pbrook | break;
|
2781 | a41b2ff2 | pbrook | |
2782 | a41b2ff2 | pbrook | case RxBuf:
|
2783 | a41b2ff2 | pbrook | rtl8139_RxBuf_write(s, val); |
2784 | a41b2ff2 | pbrook | break;
|
2785 | a41b2ff2 | pbrook | |
2786 | a41b2ff2 | pbrook | case RxRingAddrLO:
|
2787 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: C+ RxRing low bits write val=0x%08x\n", val));
|
2788 | a41b2ff2 | pbrook | s->RxRingAddrLO = val; |
2789 | a41b2ff2 | pbrook | break;
|
2790 | a41b2ff2 | pbrook | |
2791 | a41b2ff2 | pbrook | case RxRingAddrHI:
|
2792 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: C+ RxRing high bits write val=0x%08x\n", val));
|
2793 | a41b2ff2 | pbrook | s->RxRingAddrHI = val; |
2794 | a41b2ff2 | pbrook | break;
|
2795 | a41b2ff2 | pbrook | |
2796 | 6cadb320 | bellard | case Timer:
|
2797 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: TCTR Timer reset on write\n"));
|
2798 | 6cadb320 | bellard | s->TCTR = 0;
|
2799 | 6cadb320 | bellard | s->TCTR_base = qemu_get_clock(vm_clock); |
2800 | 6cadb320 | bellard | break;
|
2801 | 6cadb320 | bellard | |
2802 | 6cadb320 | bellard | case FlashReg:
|
2803 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: FlashReg TimerInt write val=0x%08x\n", val));
|
2804 | 6cadb320 | bellard | s->TimerInt = val; |
2805 | 6cadb320 | bellard | break;
|
2806 | 6cadb320 | bellard | |
2807 | a41b2ff2 | pbrook | default:
|
2808 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: ioport write(l) addr=0x%x val=0x%08x via write(b)\n", addr, val));
|
2809 | a41b2ff2 | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
2810 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr, (val >> 24) & 0xff); |
2811 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr + 1, (val >> 16) & 0xff); |
2812 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr + 2, (val >> 8) & 0xff); |
2813 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr + 3, val & 0xff); |
2814 | a41b2ff2 | pbrook | #else
|
2815 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr, val & 0xff);
|
2816 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr + 1, (val >> 8) & 0xff); |
2817 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr + 2, (val >> 16) & 0xff); |
2818 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr + 3, (val >> 24) & 0xff); |
2819 | a41b2ff2 | pbrook | #endif
|
2820 | a41b2ff2 | pbrook | break;
|
2821 | a41b2ff2 | pbrook | } |
2822 | a41b2ff2 | pbrook | } |
2823 | a41b2ff2 | pbrook | |
2824 | a41b2ff2 | pbrook | static uint32_t rtl8139_io_readb(void *opaque, uint8_t addr) |
2825 | a41b2ff2 | pbrook | { |
2826 | a41b2ff2 | pbrook | RTL8139State *s = opaque; |
2827 | a41b2ff2 | pbrook | int ret;
|
2828 | a41b2ff2 | pbrook | |
2829 | a41b2ff2 | pbrook | addr &= 0xff;
|
2830 | a41b2ff2 | pbrook | |
2831 | a41b2ff2 | pbrook | switch (addr)
|
2832 | a41b2ff2 | pbrook | { |
2833 | a41b2ff2 | pbrook | case MAC0 ... MAC0+5: |
2834 | a41b2ff2 | pbrook | ret = s->phys[addr - MAC0]; |
2835 | a41b2ff2 | pbrook | break;
|
2836 | a41b2ff2 | pbrook | case MAC0+6 ... MAC0+7: |
2837 | a41b2ff2 | pbrook | ret = 0;
|
2838 | a41b2ff2 | pbrook | break;
|
2839 | a41b2ff2 | pbrook | case MAR0 ... MAR0+7: |
2840 | a41b2ff2 | pbrook | ret = s->mult[addr - MAR0]; |
2841 | a41b2ff2 | pbrook | break;
|
2842 | a41b2ff2 | pbrook | case ChipCmd:
|
2843 | a41b2ff2 | pbrook | ret = rtl8139_ChipCmd_read(s); |
2844 | a41b2ff2 | pbrook | break;
|
2845 | a41b2ff2 | pbrook | case Cfg9346:
|
2846 | a41b2ff2 | pbrook | ret = rtl8139_Cfg9346_read(s); |
2847 | a41b2ff2 | pbrook | break;
|
2848 | a41b2ff2 | pbrook | case Config0:
|
2849 | a41b2ff2 | pbrook | ret = rtl8139_Config0_read(s); |
2850 | a41b2ff2 | pbrook | break;
|
2851 | a41b2ff2 | pbrook | case Config1:
|
2852 | a41b2ff2 | pbrook | ret = rtl8139_Config1_read(s); |
2853 | a41b2ff2 | pbrook | break;
|
2854 | a41b2ff2 | pbrook | case Config3:
|
2855 | a41b2ff2 | pbrook | ret = rtl8139_Config3_read(s); |
2856 | a41b2ff2 | pbrook | break;
|
2857 | a41b2ff2 | pbrook | case Config4:
|
2858 | a41b2ff2 | pbrook | ret = rtl8139_Config4_read(s); |
2859 | a41b2ff2 | pbrook | break;
|
2860 | a41b2ff2 | pbrook | case Config5:
|
2861 | a41b2ff2 | pbrook | ret = rtl8139_Config5_read(s); |
2862 | a41b2ff2 | pbrook | break;
|
2863 | a41b2ff2 | pbrook | |
2864 | a41b2ff2 | pbrook | case MediaStatus:
|
2865 | a41b2ff2 | pbrook | ret = 0xd0;
|
2866 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: MediaStatus read 0x%x\n", ret));
|
2867 | a41b2ff2 | pbrook | break;
|
2868 | a41b2ff2 | pbrook | |
2869 | a41b2ff2 | pbrook | case HltClk:
|
2870 | a41b2ff2 | pbrook | ret = s->clock_enabled; |
2871 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: HltClk read 0x%x\n", ret));
|
2872 | a41b2ff2 | pbrook | break;
|
2873 | a41b2ff2 | pbrook | |
2874 | a41b2ff2 | pbrook | case PCIRevisionID:
|
2875 | 6cadb320 | bellard | ret = RTL8139_PCI_REVID; |
2876 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: PCI Revision ID read 0x%x\n", ret));
|
2877 | a41b2ff2 | pbrook | break;
|
2878 | a41b2ff2 | pbrook | |
2879 | a41b2ff2 | pbrook | case TxThresh:
|
2880 | a41b2ff2 | pbrook | ret = s->TxThresh; |
2881 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139C+ TxThresh read(b) val=0x%02x\n", ret));
|
2882 | a41b2ff2 | pbrook | break;
|
2883 | a41b2ff2 | pbrook | |
2884 | a41b2ff2 | pbrook | case 0x43: /* Part of TxConfig register. Windows driver tries to read it */ |
2885 | a41b2ff2 | pbrook | ret = s->TxConfig >> 24;
|
2886 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139C TxConfig at 0x43 read(b) val=0x%02x\n", ret));
|
2887 | a41b2ff2 | pbrook | break;
|
2888 | a41b2ff2 | pbrook | |
2889 | a41b2ff2 | pbrook | default:
|
2890 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: not implemented read(b) addr=0x%x\n", addr));
|
2891 | a41b2ff2 | pbrook | ret = 0;
|
2892 | a41b2ff2 | pbrook | break;
|
2893 | a41b2ff2 | pbrook | } |
2894 | a41b2ff2 | pbrook | |
2895 | a41b2ff2 | pbrook | return ret;
|
2896 | a41b2ff2 | pbrook | } |
2897 | a41b2ff2 | pbrook | |
2898 | a41b2ff2 | pbrook | static uint32_t rtl8139_io_readw(void *opaque, uint8_t addr) |
2899 | a41b2ff2 | pbrook | { |
2900 | a41b2ff2 | pbrook | RTL8139State *s = opaque; |
2901 | a41b2ff2 | pbrook | uint32_t ret; |
2902 | a41b2ff2 | pbrook | |
2903 | a41b2ff2 | pbrook | addr &= 0xfe; /* mask lower bit */ |
2904 | a41b2ff2 | pbrook | |
2905 | a41b2ff2 | pbrook | switch (addr)
|
2906 | a41b2ff2 | pbrook | { |
2907 | a41b2ff2 | pbrook | case IntrMask:
|
2908 | a41b2ff2 | pbrook | ret = rtl8139_IntrMask_read(s); |
2909 | a41b2ff2 | pbrook | break;
|
2910 | a41b2ff2 | pbrook | |
2911 | a41b2ff2 | pbrook | case IntrStatus:
|
2912 | a41b2ff2 | pbrook | ret = rtl8139_IntrStatus_read(s); |
2913 | a41b2ff2 | pbrook | break;
|
2914 | a41b2ff2 | pbrook | |
2915 | a41b2ff2 | pbrook | case MultiIntr:
|
2916 | a41b2ff2 | pbrook | ret = rtl8139_MultiIntr_read(s); |
2917 | a41b2ff2 | pbrook | break;
|
2918 | a41b2ff2 | pbrook | |
2919 | a41b2ff2 | pbrook | case RxBufPtr:
|
2920 | a41b2ff2 | pbrook | ret = rtl8139_RxBufPtr_read(s); |
2921 | a41b2ff2 | pbrook | break;
|
2922 | a41b2ff2 | pbrook | |
2923 | 6cadb320 | bellard | case RxBufAddr:
|
2924 | 6cadb320 | bellard | ret = rtl8139_RxBufAddr_read(s); |
2925 | 6cadb320 | bellard | break;
|
2926 | 6cadb320 | bellard | |
2927 | a41b2ff2 | pbrook | case BasicModeCtrl:
|
2928 | a41b2ff2 | pbrook | ret = rtl8139_BasicModeCtrl_read(s); |
2929 | a41b2ff2 | pbrook | break;
|
2930 | a41b2ff2 | pbrook | case BasicModeStatus:
|
2931 | a41b2ff2 | pbrook | ret = rtl8139_BasicModeStatus_read(s); |
2932 | a41b2ff2 | pbrook | break;
|
2933 | a41b2ff2 | pbrook | case NWayAdvert:
|
2934 | a41b2ff2 | pbrook | ret = s->NWayAdvert; |
2935 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: NWayAdvert read(w) val=0x%04x\n", ret));
|
2936 | a41b2ff2 | pbrook | break;
|
2937 | a41b2ff2 | pbrook | case NWayLPAR:
|
2938 | a41b2ff2 | pbrook | ret = s->NWayLPAR; |
2939 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: NWayLPAR read(w) val=0x%04x\n", ret));
|
2940 | a41b2ff2 | pbrook | break;
|
2941 | a41b2ff2 | pbrook | case NWayExpansion:
|
2942 | a41b2ff2 | pbrook | ret = s->NWayExpansion; |
2943 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: NWayExpansion read(w) val=0x%04x\n", ret));
|
2944 | a41b2ff2 | pbrook | break;
|
2945 | a41b2ff2 | pbrook | |
2946 | a41b2ff2 | pbrook | case CpCmd:
|
2947 | a41b2ff2 | pbrook | ret = rtl8139_CpCmd_read(s); |
2948 | a41b2ff2 | pbrook | break;
|
2949 | a41b2ff2 | pbrook | |
2950 | 6cadb320 | bellard | case IntrMitigate:
|
2951 | 6cadb320 | bellard | ret = rtl8139_IntrMitigate_read(s); |
2952 | 6cadb320 | bellard | break;
|
2953 | 6cadb320 | bellard | |
2954 | a41b2ff2 | pbrook | case TxSummary:
|
2955 | a41b2ff2 | pbrook | ret = rtl8139_TSAD_read(s); |
2956 | a41b2ff2 | pbrook | break;
|
2957 | a41b2ff2 | pbrook | |
2958 | a41b2ff2 | pbrook | case CSCR:
|
2959 | a41b2ff2 | pbrook | ret = rtl8139_CSCR_read(s); |
2960 | a41b2ff2 | pbrook | break;
|
2961 | a41b2ff2 | pbrook | |
2962 | a41b2ff2 | pbrook | default:
|
2963 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: ioport read(w) addr=0x%x via read(b)\n", addr));
|
2964 | a41b2ff2 | pbrook | |
2965 | a41b2ff2 | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
2966 | a41b2ff2 | pbrook | ret = rtl8139_io_readb(opaque, addr) << 8;
|
2967 | a41b2ff2 | pbrook | ret |= rtl8139_io_readb(opaque, addr + 1);
|
2968 | a41b2ff2 | pbrook | #else
|
2969 | a41b2ff2 | pbrook | ret = rtl8139_io_readb(opaque, addr); |
2970 | a41b2ff2 | pbrook | ret |= rtl8139_io_readb(opaque, addr + 1) << 8; |
2971 | a41b2ff2 | pbrook | #endif
|
2972 | a41b2ff2 | pbrook | |
2973 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: ioport read(w) addr=0x%x val=0x%04x\n", addr, ret));
|
2974 | a41b2ff2 | pbrook | break;
|
2975 | a41b2ff2 | pbrook | } |
2976 | a41b2ff2 | pbrook | |
2977 | a41b2ff2 | pbrook | return ret;
|
2978 | a41b2ff2 | pbrook | } |
2979 | a41b2ff2 | pbrook | |
2980 | a41b2ff2 | pbrook | static uint32_t rtl8139_io_readl(void *opaque, uint8_t addr) |
2981 | a41b2ff2 | pbrook | { |
2982 | a41b2ff2 | pbrook | RTL8139State *s = opaque; |
2983 | a41b2ff2 | pbrook | uint32_t ret; |
2984 | a41b2ff2 | pbrook | |
2985 | a41b2ff2 | pbrook | addr &= 0xfc; /* also mask low 2 bits */ |
2986 | a41b2ff2 | pbrook | |
2987 | a41b2ff2 | pbrook | switch (addr)
|
2988 | a41b2ff2 | pbrook | { |
2989 | a41b2ff2 | pbrook | case RxMissed:
|
2990 | a41b2ff2 | pbrook | ret = s->RxMissed; |
2991 | a41b2ff2 | pbrook | |
2992 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: RxMissed read val=0x%08x\n", ret));
|
2993 | a41b2ff2 | pbrook | break;
|
2994 | a41b2ff2 | pbrook | |
2995 | a41b2ff2 | pbrook | case TxConfig:
|
2996 | a41b2ff2 | pbrook | ret = rtl8139_TxConfig_read(s); |
2997 | a41b2ff2 | pbrook | break;
|
2998 | a41b2ff2 | pbrook | |
2999 | a41b2ff2 | pbrook | case RxConfig:
|
3000 | a41b2ff2 | pbrook | ret = rtl8139_RxConfig_read(s); |
3001 | a41b2ff2 | pbrook | break;
|
3002 | a41b2ff2 | pbrook | |
3003 | a41b2ff2 | pbrook | case TxStatus0 ... TxStatus0+4*4-1: |
3004 | a41b2ff2 | pbrook | ret = rtl8139_TxStatus_read(s, addr-TxStatus0); |
3005 | a41b2ff2 | pbrook | break;
|
3006 | a41b2ff2 | pbrook | |
3007 | a41b2ff2 | pbrook | case TxAddr0 ... TxAddr0+4*4-1: |
3008 | a41b2ff2 | pbrook | ret = rtl8139_TxAddr_read(s, addr-TxAddr0); |
3009 | a41b2ff2 | pbrook | break;
|
3010 | a41b2ff2 | pbrook | |
3011 | a41b2ff2 | pbrook | case RxBuf:
|
3012 | a41b2ff2 | pbrook | ret = rtl8139_RxBuf_read(s); |
3013 | a41b2ff2 | pbrook | break;
|
3014 | a41b2ff2 | pbrook | |
3015 | a41b2ff2 | pbrook | case RxRingAddrLO:
|
3016 | a41b2ff2 | pbrook | ret = s->RxRingAddrLO; |
3017 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: C+ RxRing low bits read val=0x%08x\n", ret));
|
3018 | a41b2ff2 | pbrook | break;
|
3019 | a41b2ff2 | pbrook | |
3020 | a41b2ff2 | pbrook | case RxRingAddrHI:
|
3021 | a41b2ff2 | pbrook | ret = s->RxRingAddrHI; |
3022 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: C+ RxRing high bits read val=0x%08x\n", ret));
|
3023 | 6cadb320 | bellard | break;
|
3024 | 6cadb320 | bellard | |
3025 | 6cadb320 | bellard | case Timer:
|
3026 | 6cadb320 | bellard | ret = s->TCTR; |
3027 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: TCTR Timer read val=0x%08x\n", ret));
|
3028 | 6cadb320 | bellard | break;
|
3029 | 6cadb320 | bellard | |
3030 | 6cadb320 | bellard | case FlashReg:
|
3031 | 6cadb320 | bellard | ret = s->TimerInt; |
3032 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: FlashReg TimerInt read val=0x%08x\n", ret));
|
3033 | a41b2ff2 | pbrook | break;
|
3034 | a41b2ff2 | pbrook | |
3035 | a41b2ff2 | pbrook | default:
|
3036 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: ioport read(l) addr=0x%x via read(b)\n", addr));
|
3037 | a41b2ff2 | pbrook | |
3038 | a41b2ff2 | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
3039 | a41b2ff2 | pbrook | ret = rtl8139_io_readb(opaque, addr) << 24;
|
3040 | a41b2ff2 | pbrook | ret |= rtl8139_io_readb(opaque, addr + 1) << 16; |
3041 | a41b2ff2 | pbrook | ret |= rtl8139_io_readb(opaque, addr + 2) << 8; |
3042 | a41b2ff2 | pbrook | ret |= rtl8139_io_readb(opaque, addr + 3);
|
3043 | a41b2ff2 | pbrook | #else
|
3044 | a41b2ff2 | pbrook | ret = rtl8139_io_readb(opaque, addr); |
3045 | a41b2ff2 | pbrook | ret |= rtl8139_io_readb(opaque, addr + 1) << 8; |
3046 | a41b2ff2 | pbrook | ret |= rtl8139_io_readb(opaque, addr + 2) << 16; |
3047 | a41b2ff2 | pbrook | ret |= rtl8139_io_readb(opaque, addr + 3) << 24; |
3048 | a41b2ff2 | pbrook | #endif
|
3049 | a41b2ff2 | pbrook | |
3050 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: read(l) addr=0x%x val=%08x\n", addr, ret));
|
3051 | a41b2ff2 | pbrook | break;
|
3052 | a41b2ff2 | pbrook | } |
3053 | a41b2ff2 | pbrook | |
3054 | a41b2ff2 | pbrook | return ret;
|
3055 | a41b2ff2 | pbrook | } |
3056 | a41b2ff2 | pbrook | |
3057 | a41b2ff2 | pbrook | /* */
|
3058 | a41b2ff2 | pbrook | |
3059 | a41b2ff2 | pbrook | static void rtl8139_ioport_writeb(void *opaque, uint32_t addr, uint32_t val) |
3060 | a41b2ff2 | pbrook | { |
3061 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr & 0xFF, val);
|
3062 | a41b2ff2 | pbrook | } |
3063 | a41b2ff2 | pbrook | |
3064 | a41b2ff2 | pbrook | static void rtl8139_ioport_writew(void *opaque, uint32_t addr, uint32_t val) |
3065 | a41b2ff2 | pbrook | { |
3066 | a41b2ff2 | pbrook | rtl8139_io_writew(opaque, addr & 0xFF, val);
|
3067 | a41b2ff2 | pbrook | } |
3068 | a41b2ff2 | pbrook | |
3069 | a41b2ff2 | pbrook | static void rtl8139_ioport_writel(void *opaque, uint32_t addr, uint32_t val) |
3070 | a41b2ff2 | pbrook | { |
3071 | a41b2ff2 | pbrook | rtl8139_io_writel(opaque, addr & 0xFF, val);
|
3072 | a41b2ff2 | pbrook | } |
3073 | a41b2ff2 | pbrook | |
3074 | a41b2ff2 | pbrook | static uint32_t rtl8139_ioport_readb(void *opaque, uint32_t addr) |
3075 | a41b2ff2 | pbrook | { |
3076 | a41b2ff2 | pbrook | return rtl8139_io_readb(opaque, addr & 0xFF); |
3077 | a41b2ff2 | pbrook | } |
3078 | a41b2ff2 | pbrook | |
3079 | a41b2ff2 | pbrook | static uint32_t rtl8139_ioport_readw(void *opaque, uint32_t addr) |
3080 | a41b2ff2 | pbrook | { |
3081 | a41b2ff2 | pbrook | return rtl8139_io_readw(opaque, addr & 0xFF); |
3082 | a41b2ff2 | pbrook | } |
3083 | a41b2ff2 | pbrook | |
3084 | a41b2ff2 | pbrook | static uint32_t rtl8139_ioport_readl(void *opaque, uint32_t addr) |
3085 | a41b2ff2 | pbrook | { |
3086 | a41b2ff2 | pbrook | return rtl8139_io_readl(opaque, addr & 0xFF); |
3087 | a41b2ff2 | pbrook | } |
3088 | a41b2ff2 | pbrook | |
3089 | a41b2ff2 | pbrook | /* */
|
3090 | a41b2ff2 | pbrook | |
3091 | a41b2ff2 | pbrook | static void rtl8139_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
3092 | a41b2ff2 | pbrook | { |
3093 | a41b2ff2 | pbrook | rtl8139_io_writeb(opaque, addr & 0xFF, val);
|
3094 | a41b2ff2 | pbrook | } |
3095 | a41b2ff2 | pbrook | |
3096 | a41b2ff2 | pbrook | static void rtl8139_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val) |
3097 | a41b2ff2 | pbrook | { |
3098 | a41b2ff2 | pbrook | rtl8139_io_writew(opaque, addr & 0xFF, val);
|
3099 | a41b2ff2 | pbrook | } |
3100 | a41b2ff2 | pbrook | |
3101 | a41b2ff2 | pbrook | static void rtl8139_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
3102 | a41b2ff2 | pbrook | { |
3103 | a41b2ff2 | pbrook | rtl8139_io_writel(opaque, addr & 0xFF, val);
|
3104 | a41b2ff2 | pbrook | } |
3105 | a41b2ff2 | pbrook | |
3106 | a41b2ff2 | pbrook | static uint32_t rtl8139_mmio_readb(void *opaque, target_phys_addr_t addr) |
3107 | a41b2ff2 | pbrook | { |
3108 | a41b2ff2 | pbrook | return rtl8139_io_readb(opaque, addr & 0xFF); |
3109 | a41b2ff2 | pbrook | } |
3110 | a41b2ff2 | pbrook | |
3111 | a41b2ff2 | pbrook | static uint32_t rtl8139_mmio_readw(void *opaque, target_phys_addr_t addr) |
3112 | a41b2ff2 | pbrook | { |
3113 | a41b2ff2 | pbrook | return rtl8139_io_readw(opaque, addr & 0xFF); |
3114 | a41b2ff2 | pbrook | } |
3115 | a41b2ff2 | pbrook | |
3116 | a41b2ff2 | pbrook | static uint32_t rtl8139_mmio_readl(void *opaque, target_phys_addr_t addr) |
3117 | a41b2ff2 | pbrook | { |
3118 | a41b2ff2 | pbrook | return rtl8139_io_readl(opaque, addr & 0xFF); |
3119 | a41b2ff2 | pbrook | } |
3120 | a41b2ff2 | pbrook | |
3121 | a41b2ff2 | pbrook | /* */
|
3122 | a41b2ff2 | pbrook | |
3123 | a41b2ff2 | pbrook | static void rtl8139_save(QEMUFile* f,void* opaque) |
3124 | a41b2ff2 | pbrook | { |
3125 | a41b2ff2 | pbrook | RTL8139State* s=(RTL8139State*)opaque; |
3126 | a41b2ff2 | pbrook | int i;
|
3127 | a41b2ff2 | pbrook | |
3128 | 1941d19c | bellard | pci_device_save(s->pci_dev, f); |
3129 | 1941d19c | bellard | |
3130 | a41b2ff2 | pbrook | qemu_put_buffer(f, s->phys, 6);
|
3131 | a41b2ff2 | pbrook | qemu_put_buffer(f, s->mult, 8);
|
3132 | a41b2ff2 | pbrook | |
3133 | a41b2ff2 | pbrook | for (i=0; i<4; ++i) |
3134 | a41b2ff2 | pbrook | { |
3135 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->TxStatus[i]); /* TxStatus0 */
|
3136 | a41b2ff2 | pbrook | } |
3137 | a41b2ff2 | pbrook | for (i=0; i<4; ++i) |
3138 | a41b2ff2 | pbrook | { |
3139 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->TxAddr[i]); /* TxAddr0 */
|
3140 | a41b2ff2 | pbrook | } |
3141 | a41b2ff2 | pbrook | |
3142 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->RxBuf); /* Receive buffer */
|
3143 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->RxBufferSize);/* internal variable, receive ring buffer size in C mode */
|
3144 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->RxBufPtr); |
3145 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->RxBufAddr); |
3146 | a41b2ff2 | pbrook | |
3147 | a41b2ff2 | pbrook | qemu_put_be16s(f, &s->IntrStatus); |
3148 | a41b2ff2 | pbrook | qemu_put_be16s(f, &s->IntrMask); |
3149 | a41b2ff2 | pbrook | |
3150 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->TxConfig); |
3151 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->RxConfig); |
3152 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->RxMissed); |
3153 | a41b2ff2 | pbrook | qemu_put_be16s(f, &s->CSCR); |
3154 | a41b2ff2 | pbrook | |
3155 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->Cfg9346); |
3156 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->Config0); |
3157 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->Config1); |
3158 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->Config3); |
3159 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->Config4); |
3160 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->Config5); |
3161 | a41b2ff2 | pbrook | |
3162 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->clock_enabled); |
3163 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->bChipCmdState); |
3164 | a41b2ff2 | pbrook | |
3165 | a41b2ff2 | pbrook | qemu_put_be16s(f, &s->MultiIntr); |
3166 | a41b2ff2 | pbrook | |
3167 | a41b2ff2 | pbrook | qemu_put_be16s(f, &s->BasicModeCtrl); |
3168 | a41b2ff2 | pbrook | qemu_put_be16s(f, &s->BasicModeStatus); |
3169 | a41b2ff2 | pbrook | qemu_put_be16s(f, &s->NWayAdvert); |
3170 | a41b2ff2 | pbrook | qemu_put_be16s(f, &s->NWayLPAR); |
3171 | a41b2ff2 | pbrook | qemu_put_be16s(f, &s->NWayExpansion); |
3172 | a41b2ff2 | pbrook | |
3173 | a41b2ff2 | pbrook | qemu_put_be16s(f, &s->CpCmd); |
3174 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->TxThresh); |
3175 | a41b2ff2 | pbrook | |
3176 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->irq); |
3177 | a41b2ff2 | pbrook | qemu_put_buffer(f, s->macaddr, 6);
|
3178 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->rtl8139_mmio_io_addr); |
3179 | a41b2ff2 | pbrook | |
3180 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->currTxDesc); |
3181 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->currCPlusRxDesc); |
3182 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->currCPlusTxDesc); |
3183 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->RxRingAddrLO); |
3184 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->RxRingAddrHI); |
3185 | a41b2ff2 | pbrook | |
3186 | a41b2ff2 | pbrook | for (i=0; i<EEPROM_9346_SIZE; ++i) |
3187 | a41b2ff2 | pbrook | { |
3188 | a41b2ff2 | pbrook | qemu_put_be16s(f, &s->eeprom.contents[i]); |
3189 | a41b2ff2 | pbrook | } |
3190 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->eeprom.mode); |
3191 | a41b2ff2 | pbrook | qemu_put_be32s(f, &s->eeprom.tick); |
3192 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->eeprom.address); |
3193 | a41b2ff2 | pbrook | qemu_put_be16s(f, &s->eeprom.input); |
3194 | a41b2ff2 | pbrook | qemu_put_be16s(f, &s->eeprom.output); |
3195 | a41b2ff2 | pbrook | |
3196 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->eeprom.eecs); |
3197 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->eeprom.eesk); |
3198 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->eeprom.eedi); |
3199 | a41b2ff2 | pbrook | qemu_put_8s(f, &s->eeprom.eedo); |
3200 | 6cadb320 | bellard | |
3201 | 6cadb320 | bellard | qemu_put_be32s(f, &s->TCTR); |
3202 | 6cadb320 | bellard | qemu_put_be32s(f, &s->TimerInt); |
3203 | 6cadb320 | bellard | qemu_put_be64s(f, &s->TCTR_base); |
3204 | 6cadb320 | bellard | |
3205 | 6cadb320 | bellard | RTL8139TallyCounters_save(f, &s->tally_counters); |
3206 | a41b2ff2 | pbrook | } |
3207 | a41b2ff2 | pbrook | |
3208 | a41b2ff2 | pbrook | static int rtl8139_load(QEMUFile* f,void* opaque,int version_id) |
3209 | a41b2ff2 | pbrook | { |
3210 | a41b2ff2 | pbrook | RTL8139State* s=(RTL8139State*)opaque; |
3211 | 1941d19c | bellard | int i, ret;
|
3212 | a41b2ff2 | pbrook | |
3213 | 6cadb320 | bellard | /* just 2 versions for now */
|
3214 | 1941d19c | bellard | if (version_id > 3) |
3215 | a41b2ff2 | pbrook | return -EINVAL;
|
3216 | a41b2ff2 | pbrook | |
3217 | 1941d19c | bellard | if (version_id >= 3) { |
3218 | 1941d19c | bellard | ret = pci_device_load(s->pci_dev, f); |
3219 | 1941d19c | bellard | if (ret < 0) |
3220 | 1941d19c | bellard | return ret;
|
3221 | 1941d19c | bellard | } |
3222 | 1941d19c | bellard | |
3223 | 6cadb320 | bellard | /* saved since version 1 */
|
3224 | a41b2ff2 | pbrook | qemu_get_buffer(f, s->phys, 6);
|
3225 | a41b2ff2 | pbrook | qemu_get_buffer(f, s->mult, 8);
|
3226 | a41b2ff2 | pbrook | |
3227 | a41b2ff2 | pbrook | for (i=0; i<4; ++i) |
3228 | a41b2ff2 | pbrook | { |
3229 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->TxStatus[i]); /* TxStatus0 */
|
3230 | a41b2ff2 | pbrook | } |
3231 | a41b2ff2 | pbrook | for (i=0; i<4; ++i) |
3232 | a41b2ff2 | pbrook | { |
3233 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->TxAddr[i]); /* TxAddr0 */
|
3234 | a41b2ff2 | pbrook | } |
3235 | a41b2ff2 | pbrook | |
3236 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->RxBuf); /* Receive buffer */
|
3237 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->RxBufferSize);/* internal variable, receive ring buffer size in C mode */
|
3238 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->RxBufPtr); |
3239 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->RxBufAddr); |
3240 | a41b2ff2 | pbrook | |
3241 | a41b2ff2 | pbrook | qemu_get_be16s(f, &s->IntrStatus); |
3242 | a41b2ff2 | pbrook | qemu_get_be16s(f, &s->IntrMask); |
3243 | a41b2ff2 | pbrook | |
3244 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->TxConfig); |
3245 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->RxConfig); |
3246 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->RxMissed); |
3247 | a41b2ff2 | pbrook | qemu_get_be16s(f, &s->CSCR); |
3248 | a41b2ff2 | pbrook | |
3249 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->Cfg9346); |
3250 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->Config0); |
3251 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->Config1); |
3252 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->Config3); |
3253 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->Config4); |
3254 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->Config5); |
3255 | a41b2ff2 | pbrook | |
3256 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->clock_enabled); |
3257 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->bChipCmdState); |
3258 | a41b2ff2 | pbrook | |
3259 | a41b2ff2 | pbrook | qemu_get_be16s(f, &s->MultiIntr); |
3260 | a41b2ff2 | pbrook | |
3261 | a41b2ff2 | pbrook | qemu_get_be16s(f, &s->BasicModeCtrl); |
3262 | a41b2ff2 | pbrook | qemu_get_be16s(f, &s->BasicModeStatus); |
3263 | a41b2ff2 | pbrook | qemu_get_be16s(f, &s->NWayAdvert); |
3264 | a41b2ff2 | pbrook | qemu_get_be16s(f, &s->NWayLPAR); |
3265 | a41b2ff2 | pbrook | qemu_get_be16s(f, &s->NWayExpansion); |
3266 | a41b2ff2 | pbrook | |
3267 | a41b2ff2 | pbrook | qemu_get_be16s(f, &s->CpCmd); |
3268 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->TxThresh); |
3269 | a41b2ff2 | pbrook | |
3270 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->irq); |
3271 | a41b2ff2 | pbrook | qemu_get_buffer(f, s->macaddr, 6);
|
3272 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->rtl8139_mmio_io_addr); |
3273 | a41b2ff2 | pbrook | |
3274 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->currTxDesc); |
3275 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->currCPlusRxDesc); |
3276 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->currCPlusTxDesc); |
3277 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->RxRingAddrLO); |
3278 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->RxRingAddrHI); |
3279 | a41b2ff2 | pbrook | |
3280 | a41b2ff2 | pbrook | for (i=0; i<EEPROM_9346_SIZE; ++i) |
3281 | a41b2ff2 | pbrook | { |
3282 | a41b2ff2 | pbrook | qemu_get_be16s(f, &s->eeprom.contents[i]); |
3283 | a41b2ff2 | pbrook | } |
3284 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->eeprom.mode); |
3285 | a41b2ff2 | pbrook | qemu_get_be32s(f, &s->eeprom.tick); |
3286 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->eeprom.address); |
3287 | a41b2ff2 | pbrook | qemu_get_be16s(f, &s->eeprom.input); |
3288 | a41b2ff2 | pbrook | qemu_get_be16s(f, &s->eeprom.output); |
3289 | a41b2ff2 | pbrook | |
3290 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->eeprom.eecs); |
3291 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->eeprom.eesk); |
3292 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->eeprom.eedi); |
3293 | a41b2ff2 | pbrook | qemu_get_8s(f, &s->eeprom.eedo); |
3294 | a41b2ff2 | pbrook | |
3295 | 6cadb320 | bellard | /* saved since version 2 */
|
3296 | 6cadb320 | bellard | if (version_id >= 2) |
3297 | 6cadb320 | bellard | { |
3298 | 6cadb320 | bellard | qemu_get_be32s(f, &s->TCTR); |
3299 | 6cadb320 | bellard | qemu_get_be32s(f, &s->TimerInt); |
3300 | 6cadb320 | bellard | qemu_get_be64s(f, &s->TCTR_base); |
3301 | 6cadb320 | bellard | |
3302 | 6cadb320 | bellard | RTL8139TallyCounters_load(f, &s->tally_counters); |
3303 | 6cadb320 | bellard | } |
3304 | 6cadb320 | bellard | else
|
3305 | 6cadb320 | bellard | { |
3306 | 6cadb320 | bellard | /* not saved, use default */
|
3307 | 6cadb320 | bellard | s->TCTR = 0;
|
3308 | 6cadb320 | bellard | s->TimerInt = 0;
|
3309 | 6cadb320 | bellard | s->TCTR_base = 0;
|
3310 | 6cadb320 | bellard | |
3311 | 6cadb320 | bellard | RTL8139TallyCounters_clear(&s->tally_counters); |
3312 | 6cadb320 | bellard | } |
3313 | 6cadb320 | bellard | |
3314 | a41b2ff2 | pbrook | return 0; |
3315 | a41b2ff2 | pbrook | } |
3316 | a41b2ff2 | pbrook | |
3317 | a41b2ff2 | pbrook | /***********************************************************/
|
3318 | a41b2ff2 | pbrook | /* PCI RTL8139 definitions */
|
3319 | a41b2ff2 | pbrook | |
3320 | a41b2ff2 | pbrook | typedef struct PCIRTL8139State { |
3321 | a41b2ff2 | pbrook | PCIDevice dev; |
3322 | a41b2ff2 | pbrook | RTL8139State rtl8139; |
3323 | a41b2ff2 | pbrook | } PCIRTL8139State; |
3324 | a41b2ff2 | pbrook | |
3325 | a41b2ff2 | pbrook | static void rtl8139_mmio_map(PCIDevice *pci_dev, int region_num, |
3326 | a41b2ff2 | pbrook | uint32_t addr, uint32_t size, int type)
|
3327 | a41b2ff2 | pbrook | { |
3328 | a41b2ff2 | pbrook | PCIRTL8139State *d = (PCIRTL8139State *)pci_dev; |
3329 | a41b2ff2 | pbrook | RTL8139State *s = &d->rtl8139; |
3330 | a41b2ff2 | pbrook | |
3331 | a41b2ff2 | pbrook | cpu_register_physical_memory(addr + 0, 0x100, s->rtl8139_mmio_io_addr); |
3332 | a41b2ff2 | pbrook | } |
3333 | a41b2ff2 | pbrook | |
3334 | a41b2ff2 | pbrook | static void rtl8139_ioport_map(PCIDevice *pci_dev, int region_num, |
3335 | a41b2ff2 | pbrook | uint32_t addr, uint32_t size, int type)
|
3336 | a41b2ff2 | pbrook | { |
3337 | a41b2ff2 | pbrook | PCIRTL8139State *d = (PCIRTL8139State *)pci_dev; |
3338 | a41b2ff2 | pbrook | RTL8139State *s = &d->rtl8139; |
3339 | a41b2ff2 | pbrook | |
3340 | a41b2ff2 | pbrook | register_ioport_write(addr, 0x100, 1, rtl8139_ioport_writeb, s); |
3341 | a41b2ff2 | pbrook | register_ioport_read( addr, 0x100, 1, rtl8139_ioport_readb, s); |
3342 | a41b2ff2 | pbrook | |
3343 | a41b2ff2 | pbrook | register_ioport_write(addr, 0x100, 2, rtl8139_ioport_writew, s); |
3344 | a41b2ff2 | pbrook | register_ioport_read( addr, 0x100, 2, rtl8139_ioport_readw, s); |
3345 | a41b2ff2 | pbrook | |
3346 | a41b2ff2 | pbrook | register_ioport_write(addr, 0x100, 4, rtl8139_ioport_writel, s); |
3347 | a41b2ff2 | pbrook | register_ioport_read( addr, 0x100, 4, rtl8139_ioport_readl, s); |
3348 | a41b2ff2 | pbrook | } |
3349 | a41b2ff2 | pbrook | |
3350 | a41b2ff2 | pbrook | static CPUReadMemoryFunc *rtl8139_mmio_read[3] = { |
3351 | a41b2ff2 | pbrook | rtl8139_mmio_readb, |
3352 | a41b2ff2 | pbrook | rtl8139_mmio_readw, |
3353 | a41b2ff2 | pbrook | rtl8139_mmio_readl, |
3354 | a41b2ff2 | pbrook | }; |
3355 | a41b2ff2 | pbrook | |
3356 | a41b2ff2 | pbrook | static CPUWriteMemoryFunc *rtl8139_mmio_write[3] = { |
3357 | a41b2ff2 | pbrook | rtl8139_mmio_writeb, |
3358 | a41b2ff2 | pbrook | rtl8139_mmio_writew, |
3359 | a41b2ff2 | pbrook | rtl8139_mmio_writel, |
3360 | a41b2ff2 | pbrook | }; |
3361 | a41b2ff2 | pbrook | |
3362 | 6cadb320 | bellard | static inline int64_t rtl8139_get_next_tctr_time(RTL8139State *s, int64_t current_time) |
3363 | 6cadb320 | bellard | { |
3364 | 6cadb320 | bellard | int64_t next_time = current_time + |
3365 | 6cadb320 | bellard | muldiv64(1, ticks_per_sec, PCI_FREQUENCY);
|
3366 | 6cadb320 | bellard | if (next_time <= current_time)
|
3367 | 6cadb320 | bellard | next_time = current_time + 1;
|
3368 | 6cadb320 | bellard | return next_time;
|
3369 | 6cadb320 | bellard | } |
3370 | 6cadb320 | bellard | |
3371 | 6cadb320 | bellard | #if RTL8139_ONBOARD_TIMER
|
3372 | 6cadb320 | bellard | static void rtl8139_timer(void *opaque) |
3373 | 6cadb320 | bellard | { |
3374 | 6cadb320 | bellard | RTL8139State *s = opaque; |
3375 | 6cadb320 | bellard | |
3376 | 6cadb320 | bellard | int is_timeout = 0; |
3377 | 6cadb320 | bellard | |
3378 | 6cadb320 | bellard | int64_t curr_time; |
3379 | 6cadb320 | bellard | uint32_t curr_tick; |
3380 | 6cadb320 | bellard | |
3381 | 6cadb320 | bellard | if (!s->clock_enabled)
|
3382 | 6cadb320 | bellard | { |
3383 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: >>> timer: clock is not running\n"));
|
3384 | 6cadb320 | bellard | return;
|
3385 | 6cadb320 | bellard | } |
3386 | 6cadb320 | bellard | |
3387 | 6cadb320 | bellard | curr_time = qemu_get_clock(vm_clock); |
3388 | 6cadb320 | bellard | |
3389 | 6cadb320 | bellard | curr_tick = muldiv64(curr_time - s->TCTR_base, PCI_FREQUENCY, ticks_per_sec); |
3390 | 6cadb320 | bellard | |
3391 | 6cadb320 | bellard | if (s->TimerInt && curr_tick >= s->TimerInt)
|
3392 | 6cadb320 | bellard | { |
3393 | 6cadb320 | bellard | if (s->TCTR < s->TimerInt || curr_tick < s->TCTR)
|
3394 | 6cadb320 | bellard | { |
3395 | 6cadb320 | bellard | is_timeout = 1;
|
3396 | 6cadb320 | bellard | } |
3397 | 6cadb320 | bellard | } |
3398 | 6cadb320 | bellard | |
3399 | 6cadb320 | bellard | s->TCTR = curr_tick; |
3400 | 6cadb320 | bellard | |
3401 | 6cadb320 | bellard | // DEBUG_PRINT(("RTL8139: >>> timer: tick=%08u\n", s->TCTR));
|
3402 | 6cadb320 | bellard | |
3403 | 6cadb320 | bellard | if (is_timeout)
|
3404 | 6cadb320 | bellard | { |
3405 | 6cadb320 | bellard | DEBUG_PRINT(("RTL8139: >>> timer: timeout tick=%08u\n", s->TCTR));
|
3406 | 6cadb320 | bellard | s->IntrStatus |= PCSTimeout; |
3407 | 6cadb320 | bellard | rtl8139_update_irq(s); |
3408 | 6cadb320 | bellard | } |
3409 | 6cadb320 | bellard | |
3410 | 6cadb320 | bellard | qemu_mod_timer(s->timer, |
3411 | 6cadb320 | bellard | rtl8139_get_next_tctr_time(s,curr_time)); |
3412 | 6cadb320 | bellard | } |
3413 | 6cadb320 | bellard | #endif /* RTL8139_ONBOARD_TIMER */ |
3414 | 6cadb320 | bellard | |
3415 | abcebc7e | ths | void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn) |
3416 | a41b2ff2 | pbrook | { |
3417 | a41b2ff2 | pbrook | PCIRTL8139State *d; |
3418 | a41b2ff2 | pbrook | RTL8139State *s; |
3419 | a41b2ff2 | pbrook | uint8_t *pci_conf; |
3420 | a41b2ff2 | pbrook | |
3421 | a41b2ff2 | pbrook | d = (PCIRTL8139State *)pci_register_device(bus, |
3422 | a41b2ff2 | pbrook | "RTL8139", sizeof(PCIRTL8139State), |
3423 | abcebc7e | ths | devfn, |
3424 | a41b2ff2 | pbrook | NULL, NULL); |
3425 | a41b2ff2 | pbrook | pci_conf = d->dev.config; |
3426 | a41b2ff2 | pbrook | pci_conf[0x00] = 0xec; /* Realtek 8139 */ |
3427 | a41b2ff2 | pbrook | pci_conf[0x01] = 0x10; |
3428 | a41b2ff2 | pbrook | pci_conf[0x02] = 0x39; |
3429 | a41b2ff2 | pbrook | pci_conf[0x03] = 0x81; |
3430 | a41b2ff2 | pbrook | pci_conf[0x04] = 0x05; /* command = I/O space, Bus Master */ |
3431 | 6cadb320 | bellard | pci_conf[0x08] = RTL8139_PCI_REVID; /* PCI revision ID; >=0x20 is for 8139C+ */ |
3432 | a41b2ff2 | pbrook | pci_conf[0x0a] = 0x00; /* ethernet network controller */ |
3433 | a41b2ff2 | pbrook | pci_conf[0x0b] = 0x02; |
3434 | a41b2ff2 | pbrook | pci_conf[0x0e] = 0x00; /* header_type */ |
3435 | a41b2ff2 | pbrook | pci_conf[0x3d] = 1; /* interrupt pin 0 */ |
3436 | a41b2ff2 | pbrook | pci_conf[0x34] = 0xdc; |
3437 | a41b2ff2 | pbrook | |
3438 | a41b2ff2 | pbrook | s = &d->rtl8139; |
3439 | a41b2ff2 | pbrook | |
3440 | a41b2ff2 | pbrook | /* I/O handler for memory-mapped I/O */
|
3441 | a41b2ff2 | pbrook | s->rtl8139_mmio_io_addr = |
3442 | a41b2ff2 | pbrook | cpu_register_io_memory(0, rtl8139_mmio_read, rtl8139_mmio_write, s);
|
3443 | a41b2ff2 | pbrook | |
3444 | a41b2ff2 | pbrook | pci_register_io_region(&d->dev, 0, 0x100, |
3445 | a41b2ff2 | pbrook | PCI_ADDRESS_SPACE_IO, rtl8139_ioport_map); |
3446 | a41b2ff2 | pbrook | |
3447 | a41b2ff2 | pbrook | pci_register_io_region(&d->dev, 1, 0x100, |
3448 | a41b2ff2 | pbrook | PCI_ADDRESS_SPACE_MEM, rtl8139_mmio_map); |
3449 | a41b2ff2 | pbrook | |
3450 | a41b2ff2 | pbrook | s->irq = 16; /* PCI interrupt */ |
3451 | a41b2ff2 | pbrook | s->pci_dev = (PCIDevice *)d; |
3452 | a41b2ff2 | pbrook | memcpy(s->macaddr, nd->macaddr, 6);
|
3453 | a41b2ff2 | pbrook | rtl8139_reset(s); |
3454 | a41b2ff2 | pbrook | s->vc = qemu_new_vlan_client(nd->vlan, rtl8139_receive, |
3455 | a41b2ff2 | pbrook | rtl8139_can_receive, s); |
3456 | a41b2ff2 | pbrook | |
3457 | a41b2ff2 | pbrook | snprintf(s->vc->info_str, sizeof(s->vc->info_str),
|
3458 | a41b2ff2 | pbrook | "rtl8139 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
|
3459 | a41b2ff2 | pbrook | s->macaddr[0],
|
3460 | a41b2ff2 | pbrook | s->macaddr[1],
|
3461 | a41b2ff2 | pbrook | s->macaddr[2],
|
3462 | a41b2ff2 | pbrook | s->macaddr[3],
|
3463 | a41b2ff2 | pbrook | s->macaddr[4],
|
3464 | a41b2ff2 | pbrook | s->macaddr[5]);
|
3465 | 6cadb320 | bellard | |
3466 | 6cadb320 | bellard | s->cplus_txbuffer = NULL;
|
3467 | 6cadb320 | bellard | s->cplus_txbuffer_len = 0;
|
3468 | 6cadb320 | bellard | s->cplus_txbuffer_offset = 0;
|
3469 | a41b2ff2 | pbrook | |
3470 | a41b2ff2 | pbrook | /* XXX: instance number ? */
|
3471 | 1941d19c | bellard | register_savevm("rtl8139", 0, 3, rtl8139_save, rtl8139_load, s); |
3472 | 6cadb320 | bellard | |
3473 | 6cadb320 | bellard | #if RTL8139_ONBOARD_TIMER
|
3474 | 6cadb320 | bellard | s->timer = qemu_new_timer(vm_clock, rtl8139_timer, s); |
3475 | 6cadb320 | bellard | |
3476 | 6cadb320 | bellard | qemu_mod_timer(s->timer, |
3477 | 6cadb320 | bellard | rtl8139_get_next_tctr_time(s,qemu_get_clock(vm_clock))); |
3478 | 6cadb320 | bellard | #endif /* RTL8139_ONBOARD_TIMER */ |
3479 | a41b2ff2 | pbrook | } |