fix serialization

dev/ns_gige.cc:
    fix serialization and move regsReset into the cc file
dev/ns_gige.hh:
    put regsReset into cc instead of here in hh

--HG--
extra : convert_revision : 3a8796fa583e0765503104a9dbe28cc69f1a8fa9
This commit is contained in:
Lisa Hsu 2004-06-11 15:26:21 -04:00
parent 30ece6cf78
commit e5dba1642b
2 changed files with 129 additions and 84 deletions

View file

@ -99,7 +99,7 @@ NSGigE::NSGigE(const std::string &name, IntrControl *i, Tick intr_delay,
PciConfigData *cd, Tsunami *t, uint32_t bus, uint32_t dev,
uint32_t func, bool rx_filter, const int eaddr[6])
: PciDev(name, mmu, cf, cd, bus, dev, func), tsunami(t),
txPacketBufPtr(NULL), rxPacketBufPtr(NULL),
txPacket(0), rxPacket(0), txPacketBufPtr(NULL), rxPacketBufPtr(NULL),
txXferLen(0), rxXferLen(0), txPktXmitted(0), txState(txIdle), CTDD(false),
txFifoCnt(0), txFifoAvail(MAX_TX_FIFO_SIZE), txHalt(false),
txFragPtr(0), txDescCnt(0), txDmaState(dmaIdle), rxState(rxIdle),
@ -1050,6 +1050,20 @@ NSGigE::rxReset()
rxState = rxIdle;
}
void NSGigE::regsReset()
{
memset(&regs, 0, sizeof(regs));
regs.config = 0x80000000;
regs.mear = 0x12;
regs.isr = 0x00608000;
regs.txcfg = 0x120;
regs.rxcfg = 0x4;
regs.srr = 0x0103;
regs.mibc = 0x2;
regs.vdr = 0x81;
regs.tesr = 0xc000;
}
void
NSGigE::rxDmaReadCopy()
{
@ -2071,22 +2085,52 @@ NSGigE::serialize(ostream &os)
SERIALIZE_ARRAY(rom.perfectMatch, EADDR_LEN);
/*
* Serialize the data Fifos
*/
int txNumPkts = txFifo.size();
SERIALIZE_SCALAR(txNumPkts);
int i = 0;
pktiter_t end = txFifo.end();
for (pktiter_t p = txFifo.begin(); p != end; ++p) {
nameOut(os, csprintf("%s.txFifo%d", name(), i++));
(*p)->serialize(os);
}
int rxNumPkts = rxFifo.size();
SERIALIZE_SCALAR(rxNumPkts);
i = 0;
end = rxFifo.end();
for (pktiter_t p = rxFifo.begin(); p != end; ++p) {
nameOut(os, csprintf("%s.rxFifo%d", name(), i++));
(*p)->serialize(os);
}
/*
* Serialize the various helper variables
*/
uint32_t txPktBufPtr = (uint32_t) txPacketBufPtr;
SERIALIZE_SCALAR(txPktBufPtr);
uint32_t rxPktBufPtr = (uint32_t) rxPktBufPtr;
SERIALIZE_SCALAR(rxPktBufPtr);
bool txPacketExists = txPacket;
SERIALIZE_SCALAR(txPacketExists);
if (txPacketExists) {
nameOut(os, csprintf("%s.txPacket", name()));
txPacket->serialize(os);
uint32_t txPktBufPtr = (uint32_t) (txPacketBufPtr - txPacket->data);
SERIALIZE_SCALAR(txPktBufPtr);
}
bool rxPacketExists = rxPacket;
SERIALIZE_SCALAR(rxPacketExists);
if (rxPacketExists) {
nameOut(os, csprintf("%s.rxPacket", name()));
rxPacket->serialize(os);
uint32_t rxPktBufPtr = (uint32_t) (rxPacketBufPtr - rxPacket->data);
SERIALIZE_SCALAR(rxPktBufPtr);
}
SERIALIZE_SCALAR(txXferLen);
SERIALIZE_SCALAR(rxXferLen);
SERIALIZE_SCALAR(txPktXmitted);
bool txPacketExists = txPacket;
SERIALIZE_SCALAR(txPacketExists);
bool rxPacketExists = rxPacket;
SERIALIZE_SCALAR(rxPacketExists);
/*
* Serialize DescCaches
*/
@ -2102,8 +2146,6 @@ NSGigE::serialize(ostream &os)
/*
* Serialize tx state machine
*/
int txNumPkts = txFifo.size();
SERIALIZE_SCALAR(txNumPkts);
int txState = this->txState;
SERIALIZE_SCALAR(txState);
SERIALIZE_SCALAR(CTDD);
@ -2118,8 +2160,6 @@ NSGigE::serialize(ostream &os)
/*
* Serialize rx state machine
*/
int rxNumPkts = rxFifo.size();
SERIALIZE_SCALAR(rxNumPkts);
int rxState = this->rxState;
SERIALIZE_SCALAR(rxState);
SERIALIZE_SCALAR(CRDD);
@ -2132,13 +2172,23 @@ NSGigE::serialize(ostream &os)
SERIALIZE_SCALAR(extstsEnable);
/*
/*
* If there's a pending transmit, store the time so we can
* reschedule it later
*/
Tick transmitTick = txEvent.scheduled() ? txEvent.when() - curTick : 0;
SERIALIZE_SCALAR(transmitTick);
/*
* receive address filter settings
*/
SERIALIZE_SCALAR(rxFilterEnable);
SERIALIZE_SCALAR(acceptBroadcast);
SERIALIZE_SCALAR(acceptMulticast);
SERIALIZE_SCALAR(acceptUnicast);
SERIALIZE_SCALAR(acceptPerfect);
SERIALIZE_SCALAR(acceptArp);
/*
* Keep track of pending interrupt status.
*/
@ -2149,24 +2199,6 @@ NSGigE::serialize(ostream &os)
intrEventTick = intrEvent->when();
SERIALIZE_SCALAR(intrEventTick);
int i = 0;
for (pktiter_t p = rxFifo.begin(); p != rxFifo.end(); ++p) {
nameOut(os, csprintf("%s.rxFifo%d", name(), i++));
(*p)->serialize(os);
}
if (rxPacketExists) {
nameOut(os, csprintf("%s.rxPacket", name()));
rxPacket->serialize(os);
}
i = 0;
for (pktiter_t p = txFifo.begin(); p != txFifo.end(); ++p) {
nameOut(os, csprintf("%s.txFifo%d", name(), i++));
(*p)->serialize(os);
}
if (txPacketExists) {
nameOut(os, csprintf("%s.txPacket", name()));
txPacket->serialize(os);
}
}
void
@ -2210,24 +2242,56 @@ NSGigE::unserialize(Checkpoint *cp, const std::string &section)
UNSERIALIZE_ARRAY(rom.perfectMatch, EADDR_LEN);
/*
* unserialize the data fifos
*/
int txNumPkts;
UNSERIALIZE_SCALAR(txNumPkts);
int i;
for (i = 0; i < txNumPkts; ++i) {
PacketPtr p = new EtherPacket;
p->unserialize(cp, csprintf("%s.rxFifo%d", section, i));
txFifo.push_back(p);
}
int rxNumPkts;
UNSERIALIZE_SCALAR(rxNumPkts);
for (i = 0; i < rxNumPkts; ++i) {
PacketPtr p = new EtherPacket;
p->unserialize(cp, csprintf("%s.rxFifo%d", section, i));
rxFifo.push_back(p);
}
/*
* unserialize the various helper variables
*/
uint32_t txPktBufPtr;
UNSERIALIZE_SCALAR(txPktBufPtr);
txPacketBufPtr = (uint8_t *) txPktBufPtr;
uint32_t rxPktBufPtr;
UNSERIALIZE_SCALAR(rxPktBufPtr);
rxPacketBufPtr = (uint8_t *) rxPktBufPtr;
bool txPacketExists;
UNSERIALIZE_SCALAR(txPacketExists);
if (txPacketExists) {
txPacket = new EtherPacket;
txPacket->unserialize(cp, csprintf("%s.txPacket", section));
uint32_t txPktBufPtr;
UNSERIALIZE_SCALAR(txPktBufPtr);
txPacketBufPtr = (uint8_t *) txPacket->data + txPktBufPtr;
} else
txPacket = 0;
bool rxPacketExists;
UNSERIALIZE_SCALAR(rxPacketExists);
rxPacket = 0;
if (rxPacketExists) {
rxPacket = new EtherPacket;
rxPacket->unserialize(cp, csprintf("%s.rxPacket", section));
uint32_t rxPktBufPtr;
UNSERIALIZE_SCALAR(rxPktBufPtr);
rxPacketBufPtr = (uint8_t *) rxPacket->data + rxPktBufPtr;
} else
rxPacket = 0;
UNSERIALIZE_SCALAR(txXferLen);
UNSERIALIZE_SCALAR(rxXferLen);
UNSERIALIZE_SCALAR(txPktXmitted);
bool txPacketExists;
UNSERIALIZE_SCALAR(txPacketExists);
bool rxPacketExists;
UNSERIALIZE_SCALAR(rxPacketExists);
/*
* Unserialize DescCaches
*/
@ -2243,8 +2307,6 @@ NSGigE::unserialize(Checkpoint *cp, const std::string &section)
/*
* unserialize tx state machine
*/
int txNumPkts;
UNSERIALIZE_SCALAR(txNumPkts);
int txState;
UNSERIALIZE_SCALAR(txState);
this->txState = (TxState) txState;
@ -2261,8 +2323,6 @@ NSGigE::unserialize(Checkpoint *cp, const std::string &section)
/*
* unserialize rx state machine
*/
int rxNumPkts;
UNSERIALIZE_SCALAR(rxNumPkts);
int rxState;
UNSERIALIZE_SCALAR(rxState);
this->rxState = (RxState) rxState;
@ -2278,14 +2338,23 @@ NSGigE::unserialize(Checkpoint *cp, const std::string &section)
UNSERIALIZE_SCALAR(extstsEnable);
/*
* If there's a pending transmit, store the time so we can
* reschedule it later
* If there's a pending transmit, reschedule it now
*/
Tick transmitTick;
UNSERIALIZE_SCALAR(transmitTick);
if (transmitTick)
txEvent.schedule(curTick + transmitTick);
/*
* unserialize receive address filter settings
*/
UNSERIALIZE_SCALAR(rxFilterEnable);
UNSERIALIZE_SCALAR(acceptBroadcast);
UNSERIALIZE_SCALAR(acceptMulticast);
UNSERIALIZE_SCALAR(acceptUnicast);
UNSERIALIZE_SCALAR(acceptPerfect);
UNSERIALIZE_SCALAR(acceptArp);
/*
* Keep track of pending interrupt status.
*/
@ -2298,28 +2367,15 @@ NSGigE::unserialize(Checkpoint *cp, const std::string &section)
intrEvent->schedule(intrEventTick);
}
for (int i = 0; i < rxNumPkts; ++i) {
PacketPtr p = new EtherPacket;
p->unserialize(cp, csprintf("%s.rxFifo%d", section, i));
rxFifo.push_back(p);
}
rxPacket = NULL;
if (rxPacketExists) {
rxPacket = new EtherPacket;
rxPacket->unserialize(cp, csprintf("%s.rxPacket", section));
}
for (int i = 0; i < txNumPkts; ++i) {
PacketPtr p = new EtherPacket;
p->unserialize(cp, csprintf("%s.rxFifo%d", section, i));
txFifo.push_back(p);
}
if (txPacketExists) {
txPacket = new EtherPacket;
txPacket->unserialize(cp, csprintf("%s.txPacket", section));
/*
* re-add addrRanges to bus bridges
*/
if (pioInterface) {
pioInterface->addAddrRange(BARAddrs[0], BARAddrs[0] + BARSize[0] - 1);
pioInterface->addAddrRange(BARAddrs[1], BARAddrs[1] + BARSize[1] - 1);
}
}
Tick
NSGigE::cacheAccess(MemReqPtr &req)
{

View file

@ -158,12 +158,14 @@ class NSGigE : public PciDev
dp_regs regs;
dp_rom rom;
/*** BASIC STRUCTURES FOR TX/RX ***/
/*** BASIC STRUCTURES FOR TX/RX ***/
/* Data FIFOs */
pktbuf_t txFifo;
pktbuf_t rxFifo;
/** various helper vars */
PacketPtr txPacket;
PacketPtr rxPacket;
uint8_t *txPacketBufPtr;
uint8_t *rxPacketBufPtr;
uint32_t txXferLen;
@ -171,8 +173,6 @@ class NSGigE : public PciDev
uint32_t txPktXmitted;
bool rxDmaFree;
bool txDmaFree;
PacketPtr txPacket;
PacketPtr rxPacket;
/** DescCaches */
ns_desc txDescCache;
@ -261,18 +261,7 @@ class NSGigE : public PciDev
void txReset();
void rxReset();
void regsReset() {
memset(&regs, 0, sizeof(regs));
regs.config = 0x80000000;
regs.mear = 0x12;
regs.isr = 0x00608000;
regs.txcfg = 0x120;
regs.rxcfg = 0x4;
regs.srr = 0x0103;
regs.mibc = 0x2;
regs.vdr = 0x81;
regs.tesr = 0xc000;
}
void regsReset();
void rxKick();
Tick rxKickTick;