DevPCNet.cpp revision 338551da72e3c19c23ab74182e47cac2551540fb
/* $Id$ */
/** @file
* DevPCNet - AMD PCnet-PCI II / PCnet-FAST III (Am79C970A / Am79C973) Ethernet Controller Emulation.
*
* This software was written to be compatible with the specifications:
* AMD Am79C970A PCnet-PCI II Ethernet Controller Data-Sheet
* AMD Publication# 19436 Rev:E Amendment/0 Issue Date: June 2000
* and
* todo
*/
/*
* Copyright (C) 2006-2008 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
* --------------------------------------------------------------------
*
* This code is based on:
*
* AMD PC-Net II (Am79C970A) emulation
*
* Copyright (c) 2004 Antony T Curtis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DEV_PCNET
#include <VBox/DevPCNet.h>
#include <iprt/critsect.h>
#ifdef IN_RING3
# include <iprt/semaphore.h>
#endif
#include "../Builtins.h"
/* Enable this to catch writes to the ring descriptors instead of using excessive polling */
/* #define PCNET_NO_POLLING */
/* Enable to handle frequent io reads in the guest context (recommended) */
#define PCNET_GC_ENABLED
/* Experimental: queue TX packets */
//#define PCNET_QUEUE_SEND_PACKETS
#if defined(LOG_ENABLED)
#define PCNET_DEBUG_IO
#define PCNET_DEBUG_BCR
#define PCNET_DEBUG_CSR
#define PCNET_DEBUG_RMD
#define PCNET_DEBUG_TMD
#define PCNET_DEBUG_MATCH
#define PCNET_DEBUG_MII
#endif
#define PCNET_IOPORT_SIZE 0x20
#define PCNET_PNPMMIO_SIZE 0x20
#define PCNET_SAVEDSTATE_VERSION 10
#define BCR_MAX_RAP 50
#define MII_MAX_REG 32
#define CSR_MAX_REG 128
/* Maximum number of times we report a link down to the guest (failure to send frame) */
#define PCNET_MAX_LINKDOWN_REPORTED 3
/* Maximum frame size we handle */
#define MAX_FRAME 1536
typedef struct PCNetState_st PCNetState;
struct PCNetState_st
{
#ifndef PCNET_NO_POLLING
/** Poll timer - R3. */
/** Poll timer - R0. */
/** Poll timer - RC. */
#endif
#if HC_ARCH_BITS == 64
#endif
/** Software Interrupt timer - R3. */
/** Software Interrupt timer - R0. */
/** Software Interrupt timer - RC. */
/** Register Address Pointer */
/** Internal interrupt service */
/** ??? */
/** Address of the RX descriptor table (ring). Loaded at init. */
/** Address of the TX descriptor table (ring). Loaded at init. */
/** Last time we polled the queues */
/** Size of current send frame */
#if HC_ARCH_BITS == 64
#endif
/** Buffer address of current send frame */
/** The xmit buffer. */
/** The recv buffer. */
/** Pending send packet counter. */
int iLog2DescSize;
/** Bits 16..23 in 16-bit mode */
/** Transmit signaller - RC. */
/** Transmit signaller - R3. */
/** Transmit signaller - R0. */
/** Receive signaller - R3. */
/** Receive signaller - R0. */
/** Receive signaller - RC. */
/** Pointer to the device instance - RC. */
/** Pointer to the device instance - R3. */
/** Pointer to the device instance - R0. */
/** Restore timer.
* This is used to disconnect and reconnect the link after a restore. */
/** Pointer to the connector of the attached network driver. */
/** Pointer to the attached network driver. */
/** The base interface. */
/** The network port interface. */
/** The network config port interface. */
/** Base address of the MMIO region. */
/** Base port of the I/O space region. */
/** If set the link is currently up. */
bool fLinkUp;
/** If set the link is temporarily down because of a saved state load. */
bool fLinkTempDown;
/** Number of times we've reported the link down. */
/** The configured MAC address. */
/** Alignment padding. */
/** The LED. */
/** The LED ports. */
/** Partner of ILeds. */
/** Async send thread */
/** The Async send thread. */
/** Access critical section. */
/** Event semaphore for blocking on receive. */
bool volatile fMaybeOutOfSpace;
/** True if we signal the guest that RX packets are missing. */
bool fSignalRxMiss;
#ifdef PCNET_NO_POLLING
DECLRCCALLBACKMEMBER(int, pfnEMInterpretInstructionRC, (PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, uint32_t *pcbSize));
DECLR0CALLBACKMEMBER(int, pfnEMInterpretInstructionR0, (PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, uint32_t *pcbSize));
#endif
/** The shared memory used for the private interface - R3. */
/** The shared memory used for the private interface - R0. */
/** The shared memory used for the private interface - RC. */
/** Error counter for bad receive descriptors. */
/** True if host and guest admitted to use the private interface. */
bool fPrivIfEnabled;
bool fGCEnabled;
bool fR0Enabled;
bool fAm79C973;
#ifdef PCNET_QUEUE_SEND_PACKETS
# define PCNET_MAX_XMIT_SLOTS 128
/** @todo XXX currently atomic operations on this variable are overkill */
volatile int32_t cXmitRingBufPending;
#endif
#ifdef VBOX_WITH_STATISTICS
# ifdef PCNET_NO_POLLING
# endif
#endif /* VBOX_WITH_STATISTICS */
};
/* BUS CONFIGURATION REGISTERS */
#define BCR_MSRDA 0
#define BCR_MSWRA 1
#define BCR_MC 2
#define BCR_RESERVED3 3
#define BCR_LNKST 4
#define BCR_LED1 5
#define BCR_LED2 6
#define BCR_LED3 7
#define BCR_RESERVED8 8
#define BCR_FDC 9
/* 10 - 15 = reserved */
#define BCR_BSBC 18
#define BCR_EECAS 19
#define BCR_SWS 20
#define BCR_PLAT 22
#define BCR_PCISVID 23
#define BCR_PCISID 24
#define BCR_SRAMSIZ 25
#define BCR_SRAMB 26
#define BCR_SRAMIC 27
#define BCR_EBADDRL 28
#define BCR_EBADDRU 29
#define BCR_EBD 30
#define BCR_STVAL 31
#define BCR_MIICAS 32
#define BCR_MIIADDR 33
#define BCR_MIIMDR 34
#define BCR_PCIVID 35
#define BCR_PMC_A 36
#define BCR_DATA0 37
#define BCR_DATA1 38
#define BCR_DATA2 39
#define BCR_DATA3 40
#define BCR_DATA4 41
#define BCR_DATA5 42
#define BCR_DATA6 43
#define BCR_DATA7 44
#define BCR_PMR1 45
#define BCR_PMR2 46
#define BCR_PMR3 47
#define CSR_TDMD(S) !!((S)->aCSR[0] & 0x0008) /**< Transmit demand. (perform xmit poll now (readable, settable, not clearable) */
#if !defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)
#endif
#define PHYSADDR(S,A) ((A) | (S)->GCUpperPhys)
#define CSR_VERSION_HIGH 0x0262
/** @todo All structs: big endian? */
struct INITBLK16
{
};
/** bird: I've changed the type for the bitfields. They should only be 16-bit all together.
* frank: I've changed the bitfiled types to uint32_t to prevent compiler warnings. */
struct INITBLK32
{
};
/** Transmit Message Descriptor */
typedef struct TMD
{
struct
{
} tmd0;
struct
{
transmitter FCS generation is activated. */
} tmd1;
struct
{
} tmd2;
struct
{
} tmd3;
} TMD;
/** Receive Message Descriptor */
typedef struct RMD
{
struct
{
} rmd0;
struct
{
} rmd1;
struct
{
} rmd2;
struct
{
} rmd3;
} RMD;
#ifndef VBOX_DEVICE_STRUCT_TESTCASE
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
"TMD0 : TBADR=%#010x\n" \
"TMD1 : OWN=%d, ERR=%d, FCS=%d, LTI=%d, " \
"ONE=%d, DEF=%d, STP=%d, ENP=%d,\n" \
" BPE=%d, BCNT=%d\n" \
"TMD2 : BUF=%d, UFL=%d, EXD=%d, LCO=%d, " \
"LCA=%d, RTR=%d,\n" \
" TDR=%d, TRC=%d\n", \
"RMD0 : RBADR=%#010x\n" \
"RMD1 : OWN=%d, ERR=%d, FRAM=%d, OFLO=%d, " \
"CRC=%d, BUFF=%d, STP=%d, ENP=%d,\n " \
"BPE=%d, PAM=%d, LAFM=%d, BAM=%d, ONES=%d, BCNT=%d\n" \
"RMD2 : RCC=%d, RPC=%d, MCNT=%d, ZEROS=%d\n", \
#if defined(PCNET_QUEUE_SEND_PACKETS) && defined(IN_RING3)
#endif
/**
* Load transmit message descriptor
* Make sure we read the own flag first.
*
* @param pThis adapter private data
* @param addr physical address of the descriptor
* @param fRetIfNotOwn return immediately after reading the own flag if we don't own the descriptor
* @return true if we own the descriptor, false otherwise
*/
{
if (pThis->fPrivIfEnabled)
{
return false;
return true;
}
{
return false;
}
{
return false;
}
else
{
return false;
}
/* Double check the own bit; guest drivers might be buggy and lock prefixes in the recompiler are ignored by other threads. */
#ifdef DEBUG
Log(("pcnetTmdLoad: own bit flipped while reading!!\n"));
#endif
if (!(ownbyte & 0x80))
}
/**
* Store transmit message descriptor and hand it over to the host (the VM guest).
* Make sure that all data are transmitted before we clear the own flag.
*/
{
if (pThis->fPrivIfEnabled)
{
}
{
}
{
}
else
{
}
}
/**
* Load receive message descriptor
* Make sure we read the own flag first.
*
* @param pThis adapter private data
* @param addr physical address of the descriptor
* @param fRetIfNotOwn return immediately after reading the own flag if we don't own the descriptor
* @return true if we own the descriptor, false otherwise
*/
{
if (pThis->fPrivIfEnabled)
{
return false;
return true;
}
{
return false;
}
{
return false;
}
else
{
return false;
}
/* Double check the own bit; guest drivers might be buggy and lock prefixes in the recompiler are ignored by other threads. */
#ifdef DEBUG
Log(("pcnetRmdLoad: own bit flipped while reading!!\n"));
#endif
if (!(ownbyte & 0x80))
}
#ifdef IN_RING3
/**
* Store receive message descriptor and hand it over to the host (the VM guest).
* Make sure that all data are transmitted before we clear the own flag.
*/
{
if (pThis->fPrivIfEnabled)
{
}
{
}
{
}
else
{
}
}
/**
* pages later when we shouldn't schedule to EMT. Temporarily hack.
*/
{
if (!pThis->fPrivIfEnabled)
{
cbDesc = 8;
else
cbDesc = 16;
}
}
#endif /* IN_RING3 */
/** Checks if it's a bad (as in invalid) RMD.*/
#ifndef ETHER_IS_MULTICAST /* Net/Open BSD macro it seems */
#endif
#define ETHER_ADDR_LEN ETH_ALEN
#define ETH_ALEN 6
#pragma pack(1)
struct ether_header /** @todo Use RTNETETHERHDR */
{
};
#pragma pack()
#define PRINT_PKTHDR(BUF) do { \
Log(("#%d packet dhost=%02x:%02x:%02x:%02x:%02x:%02x, " \
"shost=%02x:%02x:%02x:%02x:%02x:%02x, " \
"type=%#06x (bcast=%d)\n", PCNET_INST_NR, \
} while (0)
#ifdef IN_RING3
/**
* Initialize the shared memory for the private guest interface.
*
* @note Changing this layout will break SSM for guests using the private guest interface!
*/
{
/* Clear the entire block for pcnetReset usage. */
/*
* The Descriptor arrays.
*/
/* Make sure all the descriptors are mapped into HMA space (and later ring-0). The 8192
bytes limit is hardcoded in the PDMDevHlpMMHyperMapMMIO2 call down in pcnetConstruct. */
/*
* The buffer arrays.
*/
#if 0
/* Don't allocate TX buffers since Windows guests cannot use it */
#endif
/* Update the header with the final size. */
}
#define MULTICAST_FILTER_LEN 8
{
#define LNC_POLYNOMIAL 0xEDB88320UL
{
{
data >>= 1;
}
}
return crc;
}
/* generated using the AUTODIN II polynomial
* x^32 + x^26 + x^23 + x^22 + x^16 +
* x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + 1
*/
{
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
{
int result;
#else
#endif
#ifdef PCNET_DEBUG_MATCH
Log(("#%d packet dhost=%02x:%02x:%02x:%02x:%02x:%02x, "
"padr=%02x:%02x:%02x:%02x:%02x:%02x => %d\n", PCNET_INST_NR,
#endif
return result;
}
{
#ifdef PCNET_DEBUG_MATCH
#endif
return result;
}
{
{
int index;
#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)
#else
#endif
}
return 0;
}
#endif /* IN_RING3 */
/**
* Get the receive descriptor ring address with a given index.
*/
{
}
/**
* Get the transmit descriptor ring address with a given index.
*/
{
}
#ifndef IN_RING3
#endif
#define htonl(x) ASMByteSwapU32(x)
#ifdef PCNET_NO_POLLING
# ifndef IN_RING3
/**
* #PF Virtual Handler callback for Guest write access to the ring descriptor page(pThis)
*
* @return VBox status code (appropriate for trap handling and GC return).
* @param pVM VM Handle.
* @param uErrorCode CPU Error code.
* @param pRegFrame Trap register frame.
* @param pvFault The fault address (cr2).
* @param GCPhysFault The GC physical address corresponding to pvFault.
* @param pvUser User argument.
*/
{
{
#ifdef PCNET_MONITOR_RECEIVE_RING
#endif
)
{
if (RT_SUCCESS(rc))
{
/* Check if we can do something now */
return VINF_SUCCESS;
}
}
else
{
return VINF_SUCCESS; /* outside of the ring range */
}
}
return VINF_IOM_HC_MMIO_WRITE; /* handle in ring3 */
}
# else /* IN_RING3 */
/**
* #PF Handler callback for physical access handler ranges (MMIO among others) in HC.
*
* The handler can not raise any faults, it's mainly for monitoring write access
* to certain pages.
*
* @returns VINF_SUCCESS if the handler have carried out the operation.
* @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
* @param pVM VM Handle.
* @param GCPhys The physical address the guest is writing to.
* @param pvPhys The HC mapping of that address.
* @param enmAccessType The access type.
* @param pvUser User argument.
*/
{
#ifdef VBOX_WITH_STATISTICS
#endif
/* Perform the actual write */
/* Writes done by our code don't require polling of course */
{
#ifdef PCNET_MONITOR_RECEIVE_RING
#endif
)
{
/* Check if we can do something now */
}
}
return VINF_SUCCESS;
}
# endif /* !IN_RING3 */
#endif /* PCNET_NO_POLLING */
{
}
/**
* Check if we have to send an interrupt to the guest. An interrupt can occur on
* - csr0 (written quite often)
* - csr4 (only written by pcnetSoftReset(), pcnetStop() or by the guest driver)
* - csr5 (only written by pcnetSoftReset(), pcnetStop or by the driver guest)
*/
{
register int iISR = 0;
/* Linux guests set csr4=0x0915
* W2k guests set csr3=0x4940 (disable BABL, MERR, IDON, DXSUFLO */
#if 1
#else
#endif
{
}
#ifdef VBOX
{
}
{
iISR = 1;
}
#else /* !VBOX */
{
iISR = 1;
}
#endif /* !VBOX */
#if 1
#else
#endif
{
iISR = 1;
}
iISR = 1;
/* normal path is to _not_ change the IRQ status */
{
}
}
/**
*/
{
{
LogRel(("PCNet#%d: %s private interface\n", PCNET_INST_NR, fPrivIfEnabled ? "Enabling" : "Disabling"));
}
}
#ifdef IN_RING3
#ifdef PCNET_NO_POLLING
{
int rc;
Log(("pcnetUpdateRingHandlers TD %RX32 size %#x -> %RX32 ?size? %#x\n", pThis->TDRAPhysOld, pThis->cbTDRAOld, pThis->GCTDRA, pcnetTdraAddr(pThis, 0)));
Log(("pcnetUpdateRingHandlers RX %RX32 size %#x -> %RX32 ?size? %#x\n", pThis->RDRAPhysOld, pThis->cbRDRAOld, pThis->GCRDRA, pcnetRdraAddr(pThis, 0)));
/** @todo unregister order not correct! */
#ifdef PCNET_MONITOR_RECEIVE_RING
{
if (pThis->RDRAPhysOld != 0)
"PCNet receive ring write access handler");
}
#endif /* PCNET_MONITOR_RECEIVE_RING */
#ifdef PCNET_MONITOR_RECEIVE_RING
/* 3 possibilities:
* 1) TDRA on different physical page as RDRA
* 2) TDRA completely on same physical page as RDRA
* 3) TDRA & RDRA overlap partly with different physical pages
*/
if ( RDRAPageStart > TDRAPageEnd
|| TDRAPageStart > RDRAPageEnd)
{
#endif /* PCNET_MONITOR_RECEIVE_RING */
/* 1) */
{
if (pThis->TDRAPhysOld != 0)
"PCNet transmit ring write access handler");
}
#ifdef PCNET_MONITOR_RECEIVE_RING
}
else
if ( RDRAPageStart != TDRAPageStart
&& ( TDRAPageStart == RDRAPageEnd
|| TDRAPageEnd == RDRAPageStart
)
)
{
/* 3) */
AssertFailed();
}
/* else 2) */
#endif
}
#endif /* PCNET_NO_POLLING */
{
/** @todo Documentation says that RCVRL and XMTRL are stored as two's complement!
* Software is allowed to write these registers directly. */
#define PCNET_INIT() do { \
} while (0)
if (BCR_SSIZE32(pThis))
{
pThis->GCUpperPhys = 0;
PCNET_INIT();
}
else
{
PCNET_INIT();
}
size_t cbRxBuffers = 0;
{
/* At this time it is not guaranteed that the buffers are already initialized. */
{
cbRxBuffers += cbBuf;
}
}
{
}
/*
* Heuristics: The Solaris pcn driver allocates too few RX buffers (128 buffers of a
* size of 128 bytes are 16KB in summary) leading to frequent RX buffer overflows. In
* that case we don't signal RX overflows through the CSR0_MISS flag as the driver
* re-initializes the device on every miss. Other guests use at least 32 buffers of
* usually 1536 bytes and should therefore not run into condition. If they are still
* short in RX buffers we notify this condition.
*/
#ifdef PCNET_NO_POLLING
#endif
/* Reset cached RX and TX states */
LogRel(("PCNet#%d: Init: ss32=%d GCRDRA=%#010x[%d] GCTDRA=%#010x[%d]%s\n",
}
#endif /* IN_RING3 */
/**
*/
{
}
/**
*/
{
}
#ifdef IN_RING3
{
}
{
return true;
}
#endif /* IN_RING3 */
/**
* Poll Receive Descriptor Table Entry and cache the results in the appropriate registers.
* Note: Once a descriptor belongs to the network card (this driver), it cannot be changed
* by the host (the guest driver) anymore. Well, it could but the results are undefined by
* definition.
* @param fSkipCurrent if true, don't scan the current RDTE.
*/
{
/* assume lack of a next receive descriptor */
{
/*
* The current receive message descriptor.
*/
if (i < 1)
if (!fSkipCurrent)
{
{
return;
}
{
if (pThis->fMaybeOutOfSpace)
{
#ifdef IN_RING3
#else
if (pItem)
#endif
}
}
else
{
/* This is not problematic since we don't own the descriptor
* We actually do own it, otherwise pcnetRmdLoad would have returned false.
* Don't flood the release log with errors.
*/
LogRel(("PCNet#%d: BAD RMD ENTRIES AT %#010x (i=%d)\n",
PCNET_INST_NR, addr, i));
return;
}
}
/*
* The next descriptor.
*/
if (--i < 1)
{
return;
}
{
}
else
{
/* This is not problematic since we don't own the descriptor
* We actually do own it, otherwise pcnetRmdLoad would have returned false.
* Don't flood the release log with errors.
*/
LogRel(("PCNet#%d: BAD RMD ENTRIES + AT %#010x (i=%d)\n",
PCNET_INST_NR, addr, i));
return;
}
/**
* @todo NNRD
*/
}
else
{
}
}
/**
* Poll Transmit Descriptor Table Entry
* @return true if transmit descriptors available
*/
{
{
{
return 0;
}
{
LogRel(("PCNet#%d: BAD TMD XDA=%#010x\n",
return 0;
}
/* previous xmit descriptor */
/* set current trasmit decriptor. */
}
else
{
/** @todo consistency with previous receive descriptor */
return 0;
}
}
#ifdef IN_RING3
/**
* Write data into guest receive buffers.
*/
{
unsigned iRxDesc;
int cbPacket;
return;
/*
*/
return;
/*
* Perform address matching.
*/
{
{
/* Not owned by controller. This should not be possible as
* we already called pcnetCanReceive(). */
LogRel(("PCNet#%d: no buffer: RCVRC=%d\n",
/* Dump the status of all RX descriptors */
while (iRxDesc-- > 0)
{
}
}
else
{
if (!CSR_ASTRP_RCV(pThis))
{
while (cbToRecv < 60)
/* FCS at end of packet */
}
cbToRecv += 4;
#ifdef PCNET_DEBUG_MATCH
#endif
/*if (!CSR_LAPPEN(pThis))*/
/* save the old value to check if it was changed as long as we didn't
* hold the critical section */
/* We have to leave the critical section here or we risk deadlocking
* with EMT when the write is to an unallocated page or has an access
* handler associated with it.
*
* This shouldn't be a problem because:
* - any modification to the RX descriptor by the driver is
* forbidden as long as it is owned by the device
* - we don't cache any register state beyond this point
*/
/* RX disabled in the meantime? If so, abort RX. */
return;
/* Was the register modified in the meantime? If so, don't touch the
* register but still update the RX descriptor. */
{
if (iRxDesc-- < 2)
}
else
while (cbToRecv > 0)
{
/* Read the entire next descriptor as we're likely to need it. */
/* Check next descriptor's own bit. If we don't own it, we have
* to quit and write error status into the last descriptor we own.
*/
break;
/* Write back current descriptor, clear the own bit. */
/* Switch to the next descriptor */
/* We have to leave the critical section here or we risk deadlocking
* with EMT when the write is to an unallocated page or has an access
* handler associated with it. See above for additional comments. */
/* RX disabled in the meantime? If so, abort RX. */
return;
/* Was the register modified in the meantime? If so, don't touch the
* register but still update the RX descriptor. */
{
if (iRxDesc-- < 2)
}
else
}
{
}
else
{
}
/* write back, clear the own bit */
#ifdef PCNET_DEBUG_RMD
#endif
/* guest driver is owner: force repoll of current and next RDTEs */
}
}
/* see description of TXDPOLL:
* ``transmit polling will take place following receive activities'' */
}
/**
* Checks if the link is up.
* @returns true if the link is up.
* @returns false if the link is down.
*/
{
}
/**
* Transmit queue consumer
* This is just a very simple way of delaying sending to R3.
*
* @returns Success indicator.
* If false the item will not be removed and the flushing will stop.
* @param pDevIns The device instance.
* @param pItem The item to consume. Upon return this item will be freed.
*/
{
/* Clear counter .*/
#ifdef PCNET_QUEUE_SEND_PACKETS
#else
#endif
return true;
}
/**
* Scraps the top frame.
* This is done as a precaution against mess left over by on
*/
{
pThis->cbSendFrame = 0;
}
/**
* Reads the first part of a frame
*/
DECLINLINE(void) pcnetXmitRead1st(PCNetState *pThis, RTGCPHYS32 GCPhysFrame, const unsigned cbFrame)
{
#ifdef PCNET_QUEUE_SEND_PACKETS
#else
#endif
}
/**
* Reads more into the current frame.
*/
DECLINLINE(void) pcnetXmitReadMore(PCNetState *pThis, RTGCPHYS32 GCPhysFrame, const unsigned cbFrame)
{
PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), GCPhysFrame, pThis->pvSendFrame + pThis->cbSendFrame, cbFrame);
}
/**
* Completes the current frame.
* If we've reached the maxium number of frames, they will be flushed.
*/
{
#ifdef PCNET_QUEUE_SEND_PACKETS
return VINF_SUCCESS;
#else
/* Don't hold the critical section while transmitting data. */
/** @note also avoids deadlocks with NAT as it can call us right back. */
#endif
}
/**
* Fails a TMD with a link down error.
*/
{
/* make carrier error - hope this is correct. */
Log(("#%d pcnetTransmit: Signaling send error. swstyle=%#x\n",
}
/**
* Fails a TMD with a generic error.
*/
{
/* make carrier error - hope this is correct. */
Log(("#%d pcnetTransmit: Signaling send error. swstyle=%#x\n",
}
/**
* Transmit a loopback frame.
*/
{
}
/**
* Flushes queued frames.
*/
{
}
#endif /* IN_RING3 */
/**
* Try to transmit frames
*/
{
{
return;
}
/*
* Check the current transmit descriptors.
*/
return;
/*
* Clear TDMD.
*/
/*
*/
#ifdef IN_RING3
#else
# if 1
if (RT_UNLIKELY(pItem))
# else
{
if (RT_UNLIKELY(pItem))
}
else
# endif
#endif
}
#ifdef IN_RING3
/**
* Try to transmit frames
*/
#ifdef PCNET_QUEUE_SEND_PACKETS
{
while ((pThis->cXmitRingBufPending > 0))
{
/* Don't hold the critical section while transmitting data. */
/** @note also avoids deadlocks with NAT as it can call us right back. */
}
return VINF_SUCCESS;
}
#else
#endif
{
unsigned cFlushIrq = 0;
{
return VINF_SUCCESS;
}
/*
* Iterate the transmit descriptors.
*/
do
{
#ifdef VBOX_WITH_STATISTICS
unsigned cBuffers = 1;
#endif
break;
/* Don't continue sending packets when the link is down. */
)
break;
#ifdef PCNET_DEBUG_TMD
#endif
/*
* The typical case - a complete packet.
*/
{
{
/* From the manual: ``A zero length buffer is acceptable as
* long as it is not the last buffer in a chain (STP = 0 and
* ENP = 1).'' That means that the first buffer might have a
* zero length if it is not the last one in the chain. */
{
else
{
}
}
else if (cb == 4096)
{
/* The Windows NT4 pcnet driver sometimes marks the first
* unused descriptor as owned by us. Ignore that (by
* passing it back). Do not update the ring counter in this
* case (otherwise that driver becomes even more confused,
* which causes transmit to stall for about 10 seconds).
* This is just a workaround, not a final solution. */
/* r=frank: IMHO this is the correct implementation. The
* manual says: ``If the OWN bit is set and the buffer
* length is 0, the OWN bit will be cleared. In the C-LANCE
* the buffer length of 0 is interpreted as a 4096-byte
* buffer.'' */
break;
}
else
{
/* Signal error, as this violates the Ethernet specs. */
/** @todo check if the correct error is generated. */
}
}
else
/* Write back the TMD and pass it to the host (clear own bit). */
/* advance the ring counter register */
else
}
{
/*
* Read TMDs until end-of-packet or tdte poll fails (underflow).
*/
bool fDropFrame = false;
for (;;)
{
/*
* Advance the ring counter register and check the next tmd.
*/
#ifdef LOG_ENABLED
#endif
else
{
/*
* Underflow!
*/
AssertMsgFailed(("pcnetTransmit: Underflow!!!\n"));
break;
}
/* release & save the previous tmd, pass it to the host */
/*
* The next tdm.
*/
#ifdef VBOX_WITH_STATISTICS
cBuffers++;
#endif
&& !fDropFrame)
else
{
fDropFrame = true;
}
{
{
}
else
{
if (!fDropFrame)
}
/* Write back the TMD, pass it to the host */
/* advance the ring counter register */
else
break;
}
}
}
else
{
/*
* We underflowed in a previous transfer, or the driver is giving us shit.
* Simply stop the transmitting for now.
*/
/** @todo according to the specs we're supposed to clear the own bit and move on to the next one. */
break;
}
/* Update TDMD, TXSTRT and TINT. */
{
cFlushIrq++;
}
/** @todo should we continue after an error (tmd.tmd1.err) or not? */
if (cFlushIrq)
{
STAM_COUNTER_INC(&pThis->aStatXmitFlush[RT_MIN(cFlushIrq, RT_ELEMENTS(pThis->aStatXmitFlush)) - 1]);
}
return VINF_SUCCESS;
}
/**
* Async I/O thread for delayed sending of packets.
*
* @returns VBox status code. Returning failure will naturally terminate the thread.
* @param pDevIns The pcnet device instance.
* @param pThread The thread.
*/
{
/*
* We can enter this function in two states, initializing or resuming.
*
* The idea about the initializing bit is that we can do per-thread
* initialization while the creator thread can still pick up errors.
* At present, there is nothing to init, or at least nothing that
* need initing in the thread.
*/
return VINF_SUCCESS;
/*
* Stay in the run-loop until we're supposed to leave the
* running state. If something really bad happens, we'll
* quit the loop while in the running state and return
* an error status to PDM and let it terminate the thread.
*/
{
/*
* Block until we've got something to send or is supposed
* to leave the running state.
*/
break;
/*
* Perform async send. Mind that we might be requested to
* suspended while waiting for the critical section.
*/
{
}
}
/* The thread is being suspended or terminated. */
return VINF_SUCCESS;
}
/**
* Unblock the send thread so it can respond to a state change.
*
* @returns VBox status code.
* @param pDevIns The pcnet device instance.
* @param pThread The send thread.
*/
{
}
#endif /* IN_RING3 */
/**
* Poll for changes in RX and TX descriptor rings.
*/
{
}
/**
* Start the poller timer.
* Poll timer interval is fixed to 500Hz. Don't stop it.
* @thread EMT, TAP.
*/
{
}
/**
* Update the poller timer.
* @thread EMT.
*/
{
#ifdef LOG_ENABLED
Log2(("#%d pcnetPollTimer time=%#010llx CSR_STOP=%d CSR_SPND=%d\n",
else
Log2(("#%d pcnetPollTimer time=%#010llx TDMD=%d TXON=%d POLL=%d TDTE=%d TDRA=%#x\n",
Log2(("#%d pcnetPollTimer: CSR_CXDA=%#x CSR_XMTRL=%d CSR_XMTRC=%d\n",
#endif
#ifdef PCNET_DEBUG_TMD
{
}
#endif
* disabled. We wouldn't need to poll for new TX descriptors in that case but it will
* not hurt as waiting for RX descriptors should occur very seldom */
|| pThis->fMaybeOutOfSpace)))
{
/* We ensure that we poll at least every 2ms (500Hz) but not more often than
* 5000 times per second. This way we completely prevent the overhead from
* heavy reprogramming the timer which turned out to be very CPU-intensive.
* The drawback is that csr46 and csr47 are not updated properly anymore
* but so far I have not seen any guest depending on these values. The 2ms
* interval is the default polling interval of the PCNet card (65536/33MHz). */
#ifdef PCNET_NO_POLLING
#else
{
}
#endif
}
}
{
int rc = VINF_SUCCESS;
#ifdef PCNET_DEBUG_CSR
#endif
switch (u32RAP)
{
case 0:
{
/* Clear any interrupt flags.
* Don't clear an interrupt flag which was not seen by the guest yet. */
/* Iff STOP, STRT and INIT are set, clear STRT and INIT */
val &= ~3;
#ifndef IN_RING3
{
return VINF_IOM_HC_IOPORT_WRITE;
}
#endif
#ifdef IN_RING3
#endif
return rc;
}
case 1: /* IADRL */
case 2: /* IADRH */
case 8: /* LADRF 0..15 */
case 9: /* LADRF 16..31 */
case 10: /* LADRF 32..47 */
case 11: /* LADRF 48..63 */
case 12: /* PADR 0..15 */
case 13: /* PADR 16..31 */
case 14: /* PADR 32..47 */
case 18: /* CRBAL */
case 19: /* CRBAU */
case 20: /* CXBAL */
case 21: /* CXBAU */
case 22: /* NRBAL */
case 23: /* NRBAU */
case 26: /* NRDAL */
case 27: /* NRDAU */
case 28: /* CRDAL */
case 29: /* CRDAU */
case 32: /* NXDAL */
case 33: /* NXDAU */
case 34: /* CXDAL */
case 35: /* CXDAU */
case 36: /* NNRDL */
case 37: /* NNRDU */
case 38: /* NNXDL */
case 39: /* NNXDU */
case 40: /* CRBCL */
case 41: /* CRBCU */
case 42: /* CXBCL */
case 43: /* CXBCU */
case 44: /* NRBCL */
case 45: /* NRBCU */
case 46: /* POLL */
case 47: /* POLLINT */
case 72: /* RCVRC */
case 74: /* XMTRC */
case 112: /* MISSC */
break;
case 3: /* Interrupt Mask and Deferral Control */
break;
case 4: /* Test and Features Control */
val &= ~0x026a;
break;
case 5: /* Extended Control and Interrupt 1 */
val &= ~0x0a90;
break;
case 7: /* Extended Control and Interrupt 2 */
{
csr7 &= ~0x0400 ;
return rc;
}
case 15: /* Mode */
{
#ifndef IN_RING3
return VINF_IOM_HC_IOPORT_WRITE;
#else
/* check for promiscuous mode change */
#endif
}
break;
case 16: /* IADRL */
case 17: /* IADRH */
/*
* 24 and 25 are the Base Address of Receive Descriptor.
* We combine and mirror these in GCRDRA.
*/
case 24: /* BADRL */
case 25: /* BADRU */
{
return rc;
}
if (u32RAP == 24)
else
Log(("#%d: WRITE CSR%d, %#06x => GCRDRA=%08x (alt init)\n", PCNET_INST_NR, u32RAP, val, pThis->GCRDRA));
break;
/*
* 30 & 31 are the Base Address of Transmit Descriptor.
* We combine and mirrorthese in GCTDRA.
*/
case 30: /* BADXL */
case 31: /* BADXU */
{
return rc;
}
if (u32RAP == 30)
else
Log(("#%d: WRITE CSR%d, %#06x => GCTDRA=%08x (alt init)\n", PCNET_INST_NR, u32RAP, val, pThis->GCTDRA));
break;
case 58: /* Software Style */
break;
/*
* Registers 76 and 78 aren't stored correctly (see todos), but I'm don't dare
* try fix that right now. So, as a quick hack for 'alt init' I'll just correct them here.
*/
case 76: /* RCVRL */ /** @todo call pcnetUpdateRingHandlers */
/** @todo receive ring length is stored in two's complement! */
case 78: /* XMTRL */ /** @todo call pcnetUpdateRingHandlers */
/** @todo transmit ring length is stored in two's complement! */
{
return rc;
}
/*
* HACK ALERT! Set the counter registers too.
*/
break;
default:
return rc;
}
return rc;
}
/**
* Encode a 32-bit link speed into a custom 16-bit floating-point value
*/
{
unsigned exp = 0;
while (speed & 0xFFFFE000)
{
speed /= 10;
++exp;
}
}
{
switch (u32RAP)
{
case 0:
break;
case 16:
case 17:
case 58:
case 68: /* Custom register to pass link speed to driver */
case 88:
val <<= 16;
break;
default:
}
#ifdef PCNET_DEBUG_CSR
#endif
return val;
}
{
int rc = VINF_SUCCESS;
u32RAP &= 0x7f;
#ifdef PCNET_DEBUG_BCR
#endif
switch (u32RAP)
{
case BCR_SWS:
return rc;
val &= ~0x0300;
switch (val & 0x00ff)
{
default:
// fall through
case 0:
break;
case 1:
pThis->GCUpperPhys = 0;
break;
case 2:
case 3:
pThis->GCUpperPhys = 0;
break;
}
/* fall through */
case BCR_LNKST:
case BCR_LED1:
case BCR_LED2:
case BCR_LED3:
case BCR_MC:
case BCR_FDC:
case BCR_BSBC:
case BCR_EECAS:
case BCR_PLAT:
case BCR_MIICAS:
case BCR_MIIADDR:
break;
case BCR_STVAL:
val &= 0xffff;
break;
case BCR_MIIMDR:
#ifdef PCNET_DEBUG_MII
#endif
break;
default:
break;
}
return rc;
}
{
switch (miiaddr)
{
case 0:
/* MII basic mode control register. */
val = 0;
if (autoneg)
if (fast)
if (duplex) /* Full duplex forced */
break;
case 1:
/* MII basic mode status register. */
| 0x0040 /* Mgmt frame preamble not required. */
| 0x0020 /* Auto-negotiation complete. */
| 0x0008 /* Able to do auto-negotiation. */
| 0x0004 /* Link up. */
| 0x0001; /* Extended Capability, i.e. registers 4+ valid. */
}
if (!autoneg) {
/* Auto-negotiation disabled. */
if (duplex)
/* Full duplex forced. */
val &= ~0x2800;
else
/* Half duplex forced. */
val &= ~0x5000;
if (fast)
/* 100 Mbps forced */
val &= ~0x1800;
else
/* 10 Mbps forced */
val &= ~0x6000;
}
break;
case 2:
/* PHY identifier 1. */
break;
case 3:
/* PHY identifier 2. */
break;
case 4:
/* Advertisement control register. */
#if 0
// Advertising flow control is a) not the default, and b) confuses
// the link speed detection routine in Windows PCnet driver
| 0x0400 /* Try flow control. */
#endif
| 0x0001; /* CSMA selector. */
break;
case 5:
/* Link partner ability register. */
| 0x4000 /* Link partner acked us. */
| 0x0400 /* Can do flow control. */
| 0x0001; /* Use CSMA selector. */
else
{
val = 0;
}
break;
case 6:
/* Auto negotiation expansion register. */
| 0x0004 /* Enable npage words. */
| 0x0001; /* Can do N-way auto-negotiation. */
else
{
val = 0;
}
break;
default:
val = 0;
break;
}
#ifdef PCNET_DEBUG_MII
#endif
return val;
}
{
u32RAP &= 0x7f;
switch (u32RAP)
{
case BCR_LNKST:
case BCR_LED1:
case BCR_LED2:
case BCR_LED3:
/* Clear LNKSTE if we're not connected or if we've just loaded a VM state. */
{
if (u32RAP == 4)
val &= ~0x40;
}
break;
case BCR_MIIMDR:
{
}
else
val = 0xffff;
break;
default:
break;
}
#ifdef PCNET_DEBUG_BCR
#endif
return val;
}
#ifdef IN_RING3 /* move down */
{
int i;
/* Initialize the PROM */
for (i = 0, checksum = 0; i < 16; i++)
/* Reset the error counter. */
pThis->uCntBadRMD = 0;
}
#endif /* IN_RING3 */
{
addr &= 0x0f;
val &= 0xff;
/* Check APROMWE bit to enable write access */
}
{
return val;
}
{
int rc = VINF_SUCCESS;
#ifdef PCNET_DEBUG_IO
#endif
{
switch (addr & 0x0f)
{
case 0x04: /* RESET */
break;
}
}
else
return rc;
}
{
*pRC = VINF_SUCCESS;
{
switch (addr & 0x0f)
{
case 0x04: /* RESET */
val = 0;
break;
}
}
else
Log(("#%d pcnetIoportReadU8: addr=%#010x val=%#06x BCR_DWIO !!\n", PCNET_INST_NR, addr, val & 0xff));
#ifdef PCNET_DEBUG_IO
#endif
return val;
}
{
int rc = VINF_SUCCESS;
#ifdef PCNET_DEBUG_IO
#endif
{
switch (addr & 0x0f)
{
case 0x00: /* RDP */
break;
case 0x02: /* RAP */
break;
case 0x06: /* BDP */
break;
}
}
else
return rc;
}
{
*pRC = VINF_SUCCESS;
{
switch (addr & 0x0f)
{
case 0x00: /* RDP */
/** @note if we're not polling, then the guest will tell us when to poll by setting TDMD in CSR0 */
/** Polling is then useless here and possibly expensive. */
goto skip_update_irq;
break;
case 0x02: /* RAP */
goto skip_update_irq;
case 0x04: /* RESET */
val = 0;
break;
case 0x06: /* BDP */
break;
}
}
else
Log(("#%d pcnetIoportReadU16: addr=%#010x val=%#06x BCR_DWIO !!\n", PCNET_INST_NR, addr, val & 0xffff));
#ifdef PCNET_DEBUG_IO
#endif
return val;
}
{
int rc = VINF_SUCCESS;
#ifdef PCNET_DEBUG_IO
#endif
{
switch (addr & 0x0f)
{
case 0x00: /* RDP */
break;
case 0x04: /* RAP */
break;
case 0x0c: /* BDP */
break;
}
}
else if ((addr & 0x0f) == 0)
{
/* switch device to dword I/O mode */
#ifdef PCNET_DEBUG_IO
Log2(("device switched into dword i/o mode\n"));
#endif
}
else
return rc;
}
{
*pRC = VINF_SUCCESS;
{
switch (addr & 0x0f)
{
case 0x00: /* RDP */
/** @note if we're not polling, then the guest will tell us when to poll by setting TDMD in CSR0 */
/** Polling is then useless here and possibly expensive. */
goto skip_update_irq;
break;
case 0x04: /* RAP */
goto skip_update_irq;
case 0x08: /* RESET */
val = 0;
break;
case 0x0c: /* BDP */
break;
}
}
else
#ifdef PCNET_DEBUG_IO
#endif
return val;
}
{
#ifdef PCNET_DEBUG_IO
#endif
if (!(addr & 0x10))
}
{
if (!(addr & 0x10))
#ifdef PCNET_DEBUG_IO
#endif
return val;
}
{
#ifdef PCNET_DEBUG_IO
#endif
if (addr & 0x10)
else
{
}
}
{
int rc;
if (addr & 0x10)
else
{
val <<= 8;
}
#ifdef PCNET_DEBUG_IO
#endif
return val;
}
{
#ifdef PCNET_DEBUG_IO
#endif
if (addr & 0x10)
else
{
}
}
{
int rc;
if (addr & 0x10)
else
{
val <<= 8;
val <<= 8;
val <<= 8;
}
#ifdef PCNET_DEBUG_IO
#endif
return val;
}
/**
* Port I/O Handler for IN operations.
*
* @returns VBox status code.
*
* @param pDevIns The device instance.
* @param pvUser User argument.
* @param Port Port number used for the IN operation.
* @param pu32 Where to store the result.
* @param cb Number of bytes read.
*/
{
int rc;
if (rc == VINF_SUCCESS)
{
/* FreeBSD is accessing in dwords. */
if (cb == 1)
else
{
}
}
LogFlow(("#%d pcnetIOPortAPromRead: Port=%RTiop *pu32=%#RX32 cb=%d rc=%Rrc\n", PCNET_INST_NR, Port, *pu32, cb, rc));
return rc;
}
/**
* Port I/O Handler for OUT operations.
*
* @returns VBox status code.
*
* @param pDevIns The device instance.
* @param pvUser User argument.
* @param Port Port number used for the IN operation.
* @param u32 The value to output.
* @param cb The value size in bytes.
*/
{
int rc;
if (cb == 1)
{
{
}
}
else
{
rc = VINF_SUCCESS;
}
LogFlow(("#%d pcnetIOPortAPromWrite: Port=%RTiop u32=%#RX32 cb=%d rc=%Rrc\n", PCNET_INST_NR, Port, u32, cb, rc));
#ifdef LOG_ENABLED
if (rc == VINF_IOM_HC_IOPORT_WRITE)
#endif
return rc;
}
/**
* Port I/O Handler for IN operations.
*
* @returns VBox status code.
*
* @param pDevIns The device instance.
* @param pvUser User argument.
* @param Port Port number used for the IN operation.
* @param pu32 Where to store the result.
* @param cb Number of bytes read.
*/
{
int rc = VINF_SUCCESS;
{
switch (cb)
{
default:
"pcnetIOPortRead: unsupported op size: offset=%#10x cb=%u\n",
}
}
Log2(("#%d pcnetIOPortRead: Port=%RTiop *pu32=%#RX32 cb=%d rc=%Rrc\n", PCNET_INST_NR, Port, *pu32, cb, rc));
#ifdef LOG_ENABLED
if (rc == VINF_IOM_HC_IOPORT_READ)
#endif
return rc;
}
/**
* Port I/O Handler for OUT operations.
*
* @returns VBox status code.
*
* @param pDevIns The device instance.
* @param pvUser User argument.
* @param Port Port number used for the IN operation.
* @param u32 The value to output.
* @param cb The value size in bytes.
*/
{
int rc = VINF_SUCCESS;
{
switch (cb)
{
default:
"pcnetIOPortWrite: unsupported op size: offset=%#10x cb=%u\n",
}
}
Log2(("#%d pcnetIOPortWrite: Port=%RTiop u32=%#RX32 cb=%d rc=%Rrc\n", PCNET_INST_NR, Port, u32, cb, rc));
#ifdef LOG_ENABLED
if (rc == VINF_IOM_HC_IOPORT_WRITE)
#endif
return rc;
}
/**
* Memory mapped I/O Handler for read operations.
*
* @returns VBox status code.
*
* @param pDevIns The device instance.
* @param pvUser User argument.
* @param GCPhysAddr Physical address (in GC) where the read starts.
* @param pv Where to store the result.
* @param cb Number of bytes read.
*/
{
int rc = VINF_SUCCESS;
/*
* We have to check the range, because we're page aligning the MMIO stuff presently.
*/
{
{
switch (cb)
{
default:
"pcnetMMIORead: unsupported op size: address=%RGp cb=%u\n",
GCPhysAddr, cb);
}
}
}
else
LogFlow(("#%d pcnetMMIORead: pvUser=%p:{%.*Rhxs} cb=%d GCPhysAddr=%RGp rc=%Rrc\n",
#ifdef LOG_ENABLED
if (rc == VINF_IOM_HC_MMIO_READ)
#endif
return rc;
}
/**
* Port I/O Handler for write operations.
*
* @returns VBox status code.
*
* @param pDevIns The device instance.
* @param pvUser User argument.
* @param GCPhysAddr Physical address (in GC) where the read starts.
* @param pv Where to fetch the result.
* @param cb Number of bytes to write.
*/
{
int rc = VINF_SUCCESS;
/*
* We have to check the range, because we're page aligning the MMIO stuff presently.
*/
{
{
switch (cb)
{
default:
"pcnetMMIOWrite: unsupported op size: address=%RGp cb=%u\n",
GCPhysAddr, cb);
}
}
// else rc == VINF_IOM_HC_MMIO_WRITE => handle in ring3
}
LogFlow(("#%d pcnetMMIOWrite: pvUser=%p:{%.*Rhxs} cb=%d GCPhysAddr=%RGp rc=%Rrc\n",
#ifdef LOG_ENABLED
if (rc == VINF_IOM_HC_MMIO_WRITE)
#endif
return rc;
}
#ifdef IN_RING3
/**
* Device timer callback function.
*
* @param pDevIns Device instance of the device which registered the timer.
* @param pTimer The timer handle.
* @thread EMT
*/
{
}
/**
* Software interrupt timer callback function.
*
* @param pDevIns Device instance of the device which registered the timer.
* @param pTimer The timer handle.
* @thread EMT
*/
{
/** @todo why aren't we taking any critsect here?!? */
}
/**
* Restore timer callback.
*
* This is only called when've restored a saved state and temporarily
* disconnected the network link to inform the guest that network connections
* should be considered lost.
*
* @param pDevIns Device instance of the device which registered the timer.
* @param pTimer The timer handle.
*/
{
if (RT_FAILURE(rc))
{
pThis->fLinkTempDown = false;
{
LogRel(("PCNet#%d: The link is back up again after the restore.\n",
Log(("#%d pcnetTimerRestore: Clearing ERR and CERR after load. cLinkDownReported=%d\n",
pThis->aCSR[0] &= ~(RT_BIT(15) | RT_BIT(13)); /* ERR | CERR - probably not 100% correct either... */
}
}
else
Log(("#%d pcnetTimerRestore: cLinkDownReported=%d, wait another 1500ms...\n",
}
/**
* Callback function for mapping an PCI I/O region.
*
* @return VBox status code.
* @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
* @param iRegion The region number.
* @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
* I/O port, else it's a physical address.
* This address is *NOT* relative to pci_mem_base like earlier!
* @param cb Region size.
* @param enmType One of the PCI_ADDRESS_SPACE_* values.
*/
{
int rc;
if (RT_FAILURE(rc))
return rc;
if (RT_FAILURE(rc))
return rc;
if (pThis->fGCEnabled)
{
if (RT_FAILURE(rc))
return rc;
if (RT_FAILURE(rc))
return rc;
}
if (pThis->fR0Enabled)
{
if (RT_FAILURE(rc))
return rc;
if (RT_FAILURE(rc))
return rc;
}
return VINF_SUCCESS;
}
/**
* Callback function for mapping the MMIO region.
*
* @return VBox status code.
* @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
* @param iRegion The region number.
* @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
* I/O port, else it's a physical address.
* This address is *NOT* relative to pci_mem_base like earlier!
* @param cb Region size.
* @param enmType One of the PCI_ADDRESS_SPACE_* values.
*/
{
int rc;
/* We use the assigned size here, because we currently only support page aligned MMIO ranges. */
if (RT_FAILURE(rc))
return rc;
return rc;
}
/**
* Callback function for mapping the MMIO region.
*
* @return VBox status code.
* @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
* @param iRegion The region number.
* @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
* I/O port, else it's a physical address.
* This address is *NOT* relative to pci_mem_base like earlier!
* @param cb Region size.
* @param enmType One of the PCI_ADDRESS_SPACE_* values.
*/
{
if (GCPhysAddress != NIL_RTGCPHYS)
/* nothing to clean up */
return VINF_SUCCESS;
}
/**
* PCNET status info callback.
*
* @param pDevIns The device instance.
* @param pHlp The output helpers.
* @param pszArgs The arguments.
*/
{
bool fRcvRing = false;
bool fXmtRing = false;
/*
* Parse args.
*/
if (pszArgs)
{
}
/*
* Show info.
*/
"pcnet #%d: port=%RTiop mmio=%RX32 mac-cfg=%.*Rhxs %s\n",
pThis->fAm79C973 ? "Am79C973" : "Am79C970A", pThis->fGCEnabled ? " GC" : "", pThis->fR0Enabled ? " R0" : "");
PDMCritSectEnter(&pThis->CritSect, VERR_INTERNAL_ERROR); /* Take it here so we know why we're hanging... */
"CSR0=%#06x:\n",
"CSR1=%#06x:\n",
"CSR2=%#06x:\n",
"CSR3=%#06x: BSWP=%d EMBA=%d DXMT2PD=%d LAPPEN=%d DXSUFLO=%d IDONM=%d TINTM=%d RINTM=%d MERRM=%d MISSM=%d BABLM=%d\n",
!!(pThis->aCSR[3] & RT_BIT(2)), !!(pThis->aCSR[3] & RT_BIT(3)), !!(pThis->aCSR[3] & RT_BIT(4)), CSR_LAPPEN(pThis),
CSR_DXSUFLO(pThis), !!(pThis->aCSR[3] & RT_BIT(8)), !!(pThis->aCSR[3] & RT_BIT(9)), !!(pThis->aCSR[3] & RT_BIT(10)),
"CSR4=%#06x: JABM=%d JAB=%d TXSTRM=%d TXSTRT=%d RCVCOOM=%d RCVCCO=%d UINT=%d UINTCMD=%d\n"
" MFCOM=%d MFCO=%d ASTRP_RCV=%d APAD_XMT=%d DPOLL=%d TIMER=%d EMAPLUS=%d EN124=%d\n",
!!(pThis->aCSR[4] & RT_BIT( 0)), !!(pThis->aCSR[4] & RT_BIT( 1)), !!(pThis->aCSR[4] & RT_BIT( 2)), !!(pThis->aCSR[4] & RT_BIT( 3)),
!!(pThis->aCSR[4] & RT_BIT( 4)), !!(pThis->aCSR[4] & RT_BIT( 5)), !!(pThis->aCSR[4] & RT_BIT( 6)), !!(pThis->aCSR[4] & RT_BIT( 7)),
!!(pThis->aCSR[4] & RT_BIT( 8)), !!(pThis->aCSR[4] & RT_BIT( 9)), !!(pThis->aCSR[4] & RT_BIT(10)), !!(pThis->aCSR[4] & RT_BIT(11)),
!!(pThis->aCSR[4] & RT_BIT(12)), !!(pThis->aCSR[4] & RT_BIT(13)), !!(pThis->aCSR[4] & RT_BIT(14)), !!(pThis->aCSR[4] & RT_BIT(15)));
"CSR5=%#06x:\n",
"CSR6=%#06x: RLEN=%#x* TLEN=%#x* [* encoded]\n",
"CSR8..11=%#06x,%#06x,%#06x,%#06x: LADRF=%#018llx\n",
"CSR12..14=%#06x,%#06x,%#06x: PADR=%02x:%02x:%02x:%02x:%02x:%02x (Current MAC Address)\n",
"CSR15=%#06x: DXR=%d DTX=%d LOOP=%d DXMTFCS=%d FCOLL=%d DRTY=%d INTL=%d PORTSEL=%d LTR=%d\n"
" MENDECL=%d DAPC=%d DLNKTST=%d DRCVPV=%d DRCVBC=%d PROM=%d\n",
!!(pThis->aCSR[15] & RT_BIT( 0)), !!(pThis->aCSR[15] & RT_BIT( 1)), !!(pThis->aCSR[15] & RT_BIT( 2)), !!(pThis->aCSR[15] & RT_BIT( 3)),
!!(pThis->aCSR[15] & RT_BIT( 4)), !!(pThis->aCSR[15] & RT_BIT( 5)), !!(pThis->aCSR[15] & RT_BIT( 6)), (pThis->aCSR[15] >> 7) & 3,
!!(pThis->aCSR[15] & RT_BIT( 9)), !!(pThis->aCSR[15] & RT_BIT(10)), !!(pThis->aCSR[15] & RT_BIT(11)),
!!(pThis->aCSR[15] & RT_BIT(12)), !!(pThis->aCSR[15] & RT_BIT(13)), !!(pThis->aCSR[15] & RT_BIT(14)), !!(pThis->aCSR[15] & RT_BIT(15)));
"CSR46=%#06x: POLL=%#06x (Poll Time Counter)\n",
"CSR47=%#06x: POLLINT=%#06x (Poll Time Interval)\n",
"CSR58=%#06x: SWSTYLE=%d %s SSIZE32=%d CSRPCNET=%d APERRENT=%d\n",
: "!!reserved!!",
!!(pThis->aCSR[58] & RT_BIT(8)), !!(pThis->aCSR[58] & RT_BIT(9)), !!(pThis->aCSR[58] & RT_BIT(10)));
"CSR112=%04RX32: MFC=%04x (Missed receive Frame Count)\n",
"CSR122=%04RX32: RCVALGN=%04x (Receive Frame Align)\n",
"CSR124=%04RX32: RPA=%04x (Runt Packet Accept)\n",
/*
* Dump the receive ring.
*/
"RCVRL=%04x RCVRC=%04x GCRDRA=%RX32 \n"
"CRDA=%08RX32 CRBA=%08RX32 CRBC=%03x CRST=%04x\n"
"NRDA=%08RX32 NRBA=%08RX32 NRBC=%03x NRST=%04x\n"
"NNRDA=%08RX32\n"
,
if (fRcvRing)
{
while (i-- > 0)
{
"%04x %RX32:%c%c RBADR=%08RX32 BCNT=%03x MCNT=%03x "
"OWN=%d ERR=%d FRAM=%d OFLO=%d CRC=%d BUFF=%d STP=%d ENP=%d BPE=%d "
"PAM=%d LAFM=%d BAM=%d RCC=%02x RPC=%02x ONES=%#x ZEROS=%d\n",
}
}
/*
* Dump the transmit ring.
*/
"XMTRL=%04x XMTRC=%04x GCTDRA=%08RX32 BADX=%08RX32\n"
"PXDA=%08RX32 PXBC=%03x PXST=%04x\n"
"CXDA=%08RX32 CXBA=%08RX32 CXBC=%03x CXST=%04x\n"
"NXDA=%08RX32 NXBA=%08RX32 NXBC=%03x NXST=%04x\n"
"NNXDA=%08RX32\n"
,
if (fXmtRing)
{
while (i-- > 0)
{
"%04x %RX32:%c%c TBADR=%08RX32 BCNT=%03x OWN=%d "
"ERR=%d NOFCS=%d LTINT=%d ONE=%d DEF=%d STP=%d ENP=%d BPE=%d "
"BUFF=%d UFLO=%d EXDEF=%d LCOL=%d LCAR=%d RTRY=%d TDR=%03x TRC=%#x ONES=%#x\n"
,
}
}
}
/**
* Takes down the link temporarily if it's current status is up.
*
* This is used during restore and when replumbing the network link.
*
* The temporary link outage is supposed to indicate to the OS that all network
* connections have been lost and that it for instance is appropriate to
* renegotiate any DHCP lease.
*
* @param pThis The PCNet instance data.
*/
{
{
pThis->fLinkTempDown = true;
pThis->cLinkDownReported = 0;
}
}
/**
* Serializes the receive thread, it may be working inside the critsect.
*
* @returns VBox status code.
* @param pDevIns The device instance.
* @param pSSMHandle The handle to save the state to.
*/
{
return VINF_SUCCESS;
}
/**
* Saves a state of the PC-Net II device.
*
* @returns VBox status code.
* @param pDevIns The device instance.
* @param pSSMHandle The handle to save the state to.
*/
{
int rc = VINF_SUCCESS;
#ifdef PCNET_NO_POLLING
return VINF_SUCCESS;
#else
if (RT_FAILURE(rc))
return rc;
#endif
return rc;
}
/**
* Serializes the receive thread, it may be working inside the critsect.
*
* @returns VBox status code.
* @param pDevIns The device instance.
* @param pSSMHandle The handle to save the state to.
*/
{
return VINF_SUCCESS;
}
/**
* Loads a saved PC-Net II device state.
*
* @returns VBox status code.
* @param pDevIns The device instance.
* @param pSSMHandle The handle to the saved state.
* @param u32Version The data unit version number.
*/
static DECLCALLBACK(int) pcnetLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, uint32_t u32Version)
{
/* restore data */
if ( SSM_VERSION_MAJOR(u32Version) > 0
{
if (pThis->fPrivIfEnabled)
}
if ( SSM_VERSION_MAJOR(u32Version) > 0
{
}
#ifndef PCNET_NO_POLLING
#endif
{
if ( SSM_VERSION_MAJOR(u32Version) > 0
}
? 4
: 3;
? 0
/* update promiscuous mode. */
#ifdef PCNET_NO_POLLING
/* Enable physical monitoring again (!) */
#endif
/* Indicate link down to the guest OS that all network connections have been lost. */
return VINF_SUCCESS;
}
/**
* Queries an interface to the driver.
*
* @returns Pointer to interface.
* @returns NULL if the interface was not supported by the driver.
* @param pInterface Pointer to this interface structure.
* @param enmInterface The requested interface identification.
* @thread Any thread.
*/
static DECLCALLBACK(void *) pcnetQueryInterface(struct PDMIBASE *pInterface, PDMINTERFACE enmInterface)
{
switch (enmInterface)
{
case PDMINTERFACE_BASE:
return &pThis->INetworkPort;
return &pThis->INetworkConfig;
case PDMINTERFACE_LED_PORTS:
default:
return NULL;
}
}
/** Converts a pointer to PCNetState::INetworkPort to a PCNetState pointer. */
#define INETWORKPORT_2_DATA(pInterface) ( (PCNetState *)((uintptr_t)pInterface - RT_OFFSETOF(PCNetState, INetworkPort)) )
/**
* This must be called before the pfnRecieve() method is called.
*
* @returns VBox status code.
* @param pInterface Pointer to the interface structure containing the called function pointer.
*/
{
{
{
/** @todo Notify the guest _now_. Will potentially increase the interrupt load */
if (pThis->fSignalRxMiss)
}
else
rc = VINF_SUCCESS;
}
return rc;
}
/**
*
*/
{
if (RT_SUCCESS(rc))
return VINF_SUCCESS;
if (RT_UNLIKELY(cMillies == 0))
return VERR_NET_NO_BUFFER_SPACE;
{
if (RT_SUCCESS(rc2))
{
rc = VINF_SUCCESS;
break;
}
/* Start the poll timer once which will remain active as long fMaybeOutOfSpace
* is true -- even if (transmit) polling is disabled (CSR_DPOLL). */
}
return rc;
}
/**
* Receive data from the network.
*
* @returns VBox status code.
* @param pInterface Pointer to the interface structure containing the called function pointer.
* @param pvBuf The available data.
* @param cb Number of bytes available in the buffer.
* @thread EMT
*/
{
int rc;
/*
* Check for the max ethernet frame size, taking the IEEE 802.1Q (VLAN) tag into
* account. Note that we are *not* expecting the CRC Checksum.
* Ethernet frames consists of a 14-byte header [+ 4-byte vlan tag] + a 1500-byte body.
*/
|| ( cb <= 1518
{
}
#ifdef LOG_ENABLED
else
{
static bool s_fFirstBigFrameLoss = true;
? 1518 : 1514;
if (s_fFirstBigFrameLoss)
{
s_fFirstBigFrameLoss = false;
Log(("PCNet#%d: Received giant frame %zu, max %u. (Further giants will be reported at level5.)\n",
}
else
Log5(("PCNet#%d: Received giant frame %zu bytes, max %u.\n",
}
#endif /* LOG_ENABLED */
return VINF_SUCCESS;
}
/** Converts a pointer to PCNetState::INetworkConfig to a PCNetState pointer. */
#define INETWORKCONFIG_2_DATA(pInterface) ( (PCNetState *)((uintptr_t)pInterface - RT_OFFSETOF(PCNetState, INetworkConfig)) )
/**
* Gets the current Media Access Control (MAC) address.
*
* @returns VBox status code.
* @param pInterface Pointer to the interface structure containing the called function pointer.
* @param pMac Where to store the MAC address.
* @thread EMT
*/
{
return VINF_SUCCESS;
}
/**
* Gets the new link state.
*
* @returns The current link state.
* @param pInterface Pointer to the interface structure containing the called function pointer.
* @thread EMT
*/
{
return PDMNETWORKLINKSTATE_UP;
return PDMNETWORKLINKSTATE_DOWN;
if (pThis->fLinkTempDown)
return PDMNETWORKLINKSTATE_DOWN_RESUME;
AssertMsgFailed(("Invalid link state!\n"));
return PDMNETWORKLINKSTATE_INVALID;
}
/**
* Sets the new link state.
*
* @returns VBox status code.
* @param pInterface Pointer to the interface structure containing the called function pointer.
* @param enmState The new link state
* @thread EMT
*/
static DECLCALLBACK(int) pcnetSetLinkState(PPDMINETWORKCONFIG pInterface, PDMNETWORKLINKSTATE enmState)
{
bool fLinkUp;
if ( enmState != PDMNETWORKLINKSTATE_DOWN
&& enmState != PDMNETWORKLINKSTATE_UP)
{
return VERR_INVALID_PARAMETER;
}
/* has the state changed? */
{
if (fLinkUp)
{
/* connect */
pThis->aCSR[0] &= ~(RT_BIT(15) | RT_BIT(13)); /* ERR | CERR - probably not 100% correct either... */
}
else
{
/* disconnect */
pThis->cLinkDownReported = 0;
}
}
return VINF_SUCCESS;
}
/**
* Gets the pointer to the status LED of a unit.
*
* @returns VBox status code.
* @param pInterface Pointer to the interface structure containing the called function pointer.
* @param iLUN The unit which status LED we desire.
* @param ppLed Where to store the LED pointer.
*/
static DECLCALLBACK(int) pcnetQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
{
if (iLUN == 0)
{
return VINF_SUCCESS;
}
return VERR_PDM_LUN_NOT_FOUND;
}
/**
* @copydoc FNPDMDEVPOWEROFF
*/
{
/* Poke thread waiting for buffer space. */
}
#ifdef VBOX_DYNAMIC_NET_ATTACH
/**
* Detach notification.
*
* One port on the network card has been disconnected from the network.
*
* @param pDevIns The device instance.
* @param iLUN The logical unit which is being detached.
* @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
*/
{
AssertLogRelReturnVoid(iLUN == 0);
/** @todo: r=pritesh still need to check if i missed
* to clean something in this function
*/
/*
* Zero some important members.
*/
}
/**
* Attach the Network attachment.
*
* One port on the network card has been connected to a network.
*
* @returns VBox status code.
* @param pDevIns The device instance.
* @param iLUN The logical unit which is being attached.
* @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
*
* @remarks This code path is not used during construction.
*/
{
/*
* Attach the driver.
*/
if (RT_SUCCESS(rc))
{
if (rc == VINF_NAT_DNS)
{
#ifdef RT_OS_LINUX
N_("A Domain Name Server (DNS) for NAT networking could not be determined. Please check your /etc/resolv.conf for <tt>nameserver</tt> entries. Either add one manually (<i>man resolv.conf</i>) or ensure that your host is correctly connected to an ISP. If you ignore this warning the guest will not be able to perform nameserver lookups and it will probably observe delays if trying so"));
#else
N_("A Domain Name Server (DNS) for NAT networking could not be determined. Ensure that your host is correctly connected to an ISP. If you ignore this warning the guest will not be able to perform nameserver lookups and it will probably observe delays if trying so"));
#endif
}
pThis->pDrv = (PPDMINETWORKCONNECTOR)pThis->pDrvBase->pfnQueryInterface(pThis->pDrvBase, PDMINTERFACE_NETWORK_CONNECTOR);
{
AssertMsgFailed(("Failed to obtain the PDMINTERFACE_NETWORK_CONNECTOR interface!\n"));
}
}
else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
/*
* Temporary set the link down if it was up so that the guest
* will know that we have change the configuration of the
* network card
*/
if (RT_SUCCESS(rc))
return rc;
}
#endif /* VBOX_DYNAMIC_NET_ATTACH */
/**
* @copydoc FNPDMDEVSUSPEND
*/
{
/* Poke thread waiting for buffer space. */
}
/**
* @copydoc FNPDMDEVRESET
*/
{
if (pThis->fLinkTempDown)
{
}
if (pThis->pSharedMMIOR3)
/** @todo How to flush the queues? */
}
/**
* @copydoc FNPDMDEVRELOCATE
*/
{
if (pThis->pSharedMMIOR3)
#ifdef PCNET_NO_POLLING
#else
#endif
}
/**
* Destruct a device instance.
*
* Most VM resources are freed by the VM. This callback is provided so that any non-VM
* resources can be freed correctly.
*
* @returns VBox status.
* @param pDevIns The device instance data.
*/
{
{
/*
* At this point the send thread is suspended and will not enter
* this module again. So, no coordination is needed here and PDM
* will take care of terminating and cleaning up the thread.
*/
}
#ifdef PCNET_QUEUE_SEND_PACKETS
if (pThis->apXmitRingBuffer)
#endif
return VINF_SUCCESS;
}
/**
* Construct a device instance for a VM.
*
* @returns VBox status.
* @param pDevIns The device instance data.
* If the registration structure is needed, pDevIns->pDevReg points to it.
* @param iInstance Instance number. Use this to figure out which registers and such to use.
* The device number is also found in pDevIns->iInstance, but since it's
* likely to be freqently used PDM passes it as parameter.
* @param pCfgHandle Configuration node handle for the device. Use this to obtain the configuration
* of the device instance. It's also found in pDevIns->pCfgHandle, but like
* iInstance it's expected to be used a bit in this function.
*/
{
char szTmp[128];
int rc;
/* up to eight instances are supported */
/*
* Init what's required to make the destructor safe.
*/
/*
* Validate configuration.
*/
if (!CFGMR3AreValuesValid(pCfgHandle, "MAC\0" "CableConnected\0" "Am79C973\0" "LineSpeed\0" "GCEnabled\0" "R0Enabled\0" "PrivIfEnabled\0"))
N_("Invalid configuraton for pcnet device"));
/*
* Read the configuration.
*/
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"MAC\" value"));
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"CableConnected\" value"));
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"Am79C973\" value"));
rc = CFGMR3QueryU32Def(pCfgHandle, "LineSpeed", &pThis->u32LinkSpeed, 1000000); /* 1GBit/s (in kbps units)*/
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"LineSpeed\" value"));
#ifdef PCNET_GC_ENABLED
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"GCEnabled\" value"));
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"R0Enabled\" value"));
#else /* !PCNET_GC_ENABLED */
pThis->fGCEnabled = false;
pThis->fR0Enabled = false;
#endif /* !PCNET_GC_ENABLED */
/*
* Initialize data (most of it anyway).
*/
/* IBase */
/* INeworkPort */
/* INetworkConfig */
/* ILeds */
/* PCI Device */
/* subsystem and subvendor IDs */
/*
* Register the PCI device, its I/O regions, the timer and the saved state item.
*/
if (RT_FAILURE(rc))
return rc;
if (RT_FAILURE(rc))
return rc;
if (RT_FAILURE(rc))
return rc;
bool fPrivIfEnabled;
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
fPrivIfEnabled = true;
else if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"PrivIfEnabled\" value"));
if (fPrivIfEnabled)
{
/*
* Initialize shared memory between host and guest for descriptors and RX buffers. Most guests
* should not care if there is an additional PCI ressource but just in case we made this configurable.
*/
rc = PDMDevHlpMMIO2Register(pDevIns, 2, PCNET_GUEST_SHARED_MEMORY_SIZE, 0, (void **)&pThis->pSharedMMIOR3, "PCNetShMem");
if (RT_FAILURE(rc))
if (RT_FAILURE(rc))
N_("Failed to map 8192 bytes of memory for the PCNet device into the hyper memory"));
if (RT_FAILURE(rc))
return rc;
}
/*
* Initialize critical section.
* This must be done before register the critsect with the timer code, and also before
* attaching drivers or anything else that may call us back.
*/
char szName[24];
if (RT_FAILURE(rc))
return rc;
#ifdef PCNET_NO_POLLING
/*
* Resolve the R0 and RC handlers.
*/
rc = PDMR3LdrGetSymbolR0Lazy(PDMDevHlpGetVM(pDevIns), NULL, "EMInterpretInstruction", &pThis->pfnEMInterpretInstructionR0);
if (RT_SUCCESS(rc))
rc = PDMR3LdrGetSymbolRCLazy(PDMDevHlpGetVM(pDevIns), NULL, "EMInterpretInstruction", (RTGCPTR *)&pThis->pfnEMInterpretInstructionRC);
#else
if (RT_FAILURE(rc))
return rc;
#endif
{
/* Software Interrupt timer */
rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, pcnetTimerSoftInt, pThis, /** @todo r=bird: the locking here looks bogus now with SMP... */
if (RT_FAILURE(rc))
return rc;
}
if (RT_FAILURE(rc))
return rc;
PCNET_SAVEDSTATE_VERSION, sizeof(*pThis),
if (RT_FAILURE(rc))
return rc;
/*
* Create the transmit queue.
*/
if (RT_FAILURE(rc))
return rc;
/*
* Create the RX notifer signaller.
*/
if (RT_FAILURE(rc))
return rc;
/*
* Register the info item.
*/
/*
* Attach status driver (optional).
*/
if (RT_SUCCESS(rc))
else if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
{
return rc;
}
/*
* Attach driver.
*/
if (RT_SUCCESS(rc))
{
if (rc == VINF_NAT_DNS)
{
#ifdef RT_OS_LINUX
N_("A Domain Name Server (DNS) for NAT networking could not be determined. Please check your /etc/resolv.conf for <tt>nameserver</tt> entries. Either add one manually (<i>man resolv.conf</i>) or ensure that your host is correctly connected to an ISP. If you ignore this warning the guest will not be able to perform nameserver lookups and it will probably observe delays if trying so"));
#else
N_("A Domain Name Server (DNS) for NAT networking could not be determined. Ensure that your host is correctly connected to an ISP. If you ignore this warning the guest will not be able to perform nameserver lookups and it will probably observe delays if trying so"));
#endif
}
{
AssertMsgFailed(("Failed to obtain the PDMINTERFACE_NETWORK_CONNECTOR interface!\n"));
return VERR_PDM_MISSING_INTERFACE_BELOW;
}
}
else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
Log(("No attached driver!\n"));
else
return rc;
/*
* Reset the device state. (Do after attaching.)
*/
/* Create send queue for the async send thread. */
/* Create asynchronous thread */
rc = PDMDevHlpPDMThreadCreate(pDevIns, &pThis->pSendThread, pThis, pcnetAsyncSendThread, pcnetAsyncSendThreadWakeUp, 0, RTTHREADTYPE_IO, "PCNET_TX");
#ifdef PCNET_QUEUE_SEND_PACKETS
for (unsigned i = 1; i < PCNET_MAX_XMIT_SLOTS; i++)
#endif
#ifdef VBOX_WITH_STATISTICS
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatMMIOReadGC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling MMIO reads in GC", "/Devices/PCNet%d/MMIO/ReadGC", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatMMIOReadHC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling MMIO reads in HC", "/Devices/PCNet%d/MMIO/ReadHC", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatMMIOWriteGC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling MMIO writes in GC", "/Devices/PCNet%d/MMIO/WriteGC", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatMMIOWriteHC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling MMIO writes in HC", "/Devices/PCNet%d/MMIO/WriteHC", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatAPROMRead, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling APROM reads", "/Devices/PCNet%d/IO/APROMRead", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatAPROMWrite, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling APROM writes", "/Devices/PCNet%d/IO/APROMWrite", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatIOReadGC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling IO reads in GC", "/Devices/PCNet%d/IO/ReadGC", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatIOReadHC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling IO reads in HC", "/Devices/PCNet%d/IO/ReadHC", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatIOWriteGC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling IO writes in GC", "/Devices/PCNet%d/IO/WriteGC", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatIOWriteHC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling IO writes in HC", "/Devices/PCNet%d/IO/WriteHC", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTimer, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling Timer", "/Devices/PCNet%d/Timer", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatReceive, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling receive", "/Devices/PCNet%d/Receive", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRxOverflow, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, "Profiling RX overflows", "/Devices/PCNet%d/RxOverflow", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRxOverflowWakeup, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, "Nr of RX overflow wakeups", "/Devices/PCNet%d/RxOverflowWakeup", iInstance);
#endif
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatReceiveBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Amount of data received", "/Devices/PCNet%d/ReceiveBytes", iInstance);
#ifdef VBOX_WITH_STATISTICS
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTransmit, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling transmits in HC", "/Devices/PCNet%d/Transmit/Total", iInstance);
#endif
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTransmitBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Amount of data transmitted", "/Devices/PCNet%d/TransmitBytes", iInstance);
#ifdef VBOX_WITH_STATISTICS
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTransmitSend, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling PCNet send transmit in HC","/Devices/PCNet%d/Transmit/Send", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTdtePollGC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling PCNet TdtePoll in GC", "/Devices/PCNet%d/TdtePollGC", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTdtePollHC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling PCNet TdtePoll in HC", "/Devices/PCNet%d/TdtePollHC", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRdtePollGC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling PCNet RdtePoll in GC", "/Devices/PCNet%d/RdtePollGC", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRdtePollHC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling PCNet RdtePoll in HC", "/Devices/PCNet%d/RdtePollHC", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTmdStoreGC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling PCNet TmdStore in GC", "/Devices/PCNet%d/TmdStoreGC", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTmdStoreHC, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling PCNet TmdStore in HC", "/Devices/PCNet%d/TmdStoreHC", iInstance);
unsigned i;
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aStatXmitFlush[i], STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, "", "/Devices/PCNet%d/XmitFlushIrq/%d", iInstance, i + 1);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aStatXmitFlush[i], STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, "", "/Devices/PCNet%d/XmitFlushIrq/%d+", iInstance, i + 1);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aStatXmitChainCounts[i], STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, "", "/Devices/PCNet%d/XmitChainCounts/%d", iInstance, i + 1);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aStatXmitChainCounts[i], STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, "", "/Devices/PCNet%d/XmitChainCounts/%d+", iInstance, i + 1);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatXmitSkipCurrent, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "", "/Devices/PCNet%d/Xmit/Skipped", iInstance, i + 1);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatInterrupt, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling interrupt checks", "/Devices/PCNet%d/UpdateIRQ", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatPollTimer, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling poll timer", "/Devices/PCNet%d/PollTimer", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatMIIReads, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Number of MII reads", "/Devices/PCNet%d/MIIReads", iInstance);
# ifdef PCNET_NO_POLLING
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRCVRingWrite, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Nr of receive ring writes", "/Devices/PCNet%d/Ring/RCVWrites", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTXRingWrite, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Nr of transmit ring writes", "/Devices/PCNet%d/Ring/TXWrites", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRingWriteHC, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Nr of monitored ring page writes", "/Devices/PCNet%d/Ring/HC/Writes", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRingWriteR0, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Nr of monitored ring page writes", "/Devices/PCNet%d/Ring/R0/Writes", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRingWriteGC, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Nr of monitored ring page writes", "/Devices/PCNet%d/Ring/GC/Writes", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRingWriteFailedHC, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Nr of failed ring page writes", "/Devices/PCNet%d/Ring/HC/Failed", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRingWriteFailedR0, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Nr of failed ring page writes", "/Devices/PCNet%d/Ring/R0/Failed", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRingWriteFailedGC, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Nr of failed ring page writes", "/Devices/PCNet%d/Ring/GC/Failed", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRingWriteOutsideHC, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Nr of monitored writes outside ring","/Devices/PCNet%d/Ring/HC/Outside", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRingWriteOutsideR0, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Nr of monitored writes outside ring","/Devices/PCNet%d/Ring/R0/Outside", iInstance);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRingWriteOutsideGC, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Nr of monitored writes outside ring","/Devices/PCNet%d/Ring/GC/Outside", iInstance);
# endif /* PCNET_NO_POLLING */
#endif
return VINF_SUCCESS;
}
/**
* The device registration structure.
*/
const PDMDEVREG g_DevicePCNet =
{
/* u32Version */
/* szDeviceName */
"pcnet",
/* szRCMod */
#ifdef PCNET_GC_ENABLED
"VBoxDDGC.gc",
"VBoxDDR0.r0",
#else
"",
"",
#endif
/* pszDescription */
"AMD PC-Net II Ethernet controller.\n",
/* fFlags */
#ifdef PCNET_GC_ENABLED
#else
#endif
/* fClass */
/* cMaxInstances */
8,
/* cbInstance */
sizeof(PCNetState),
/* pfnConstruct */
/* pfnDestruct */
/* pfnRelocate */
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
/* pfnSuspend */
/* pfnResume */
NULL,
#ifdef VBOX_DYNAMIC_NET_ATTACH
/* pfnAttach */
/* pfnDetach */
#else /* !VBOX_DYNAMIC_NET_ATTACH */
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
#endif /* !VBOX_DYNAMIC_NET_ATTACH */
/* pfnQueryInterface. */
NULL,
/* pfnInitComplete. */
NULL,
/* pfnPowerOff. */
/* pfnSoftReset */
NULL,
/* u32VersionEnd */
};
#endif /* IN_RING3 */
#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */