2006-09-19 02:12:45 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006 The Regents of The University of Michigan
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Authors: Ali Saidi
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* @file
|
|
|
|
* Device model for Intel's 8254x line of gigabit ethernet controllers.
|
2006-10-20 19:00:05 +02:00
|
|
|
* In particular an 82547 revision 2 (82547GI) MAC because it seems to have the
|
|
|
|
* fewest workarounds in the driver. It will probably work with most of the
|
|
|
|
* other MACs with slight modifications.
|
2006-09-19 02:12:45 +02:00
|
|
|
*/
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @todo really there are multiple dma engines.. we should implement them.
|
|
|
|
*/
|
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
2006-09-19 02:12:45 +02:00
|
|
|
#include "base/inet.hh"
|
2007-03-22 23:39:41 +01:00
|
|
|
#include "base/trace.hh"
|
2006-09-19 02:12:45 +02:00
|
|
|
#include "dev/i8254xGBe.hh"
|
|
|
|
#include "mem/packet.hh"
|
2006-10-27 15:10:50 +02:00
|
|
|
#include "mem/packet_access.hh"
|
2007-07-24 06:51:38 +02:00
|
|
|
#include "params/IGbE.hh"
|
2006-09-19 02:12:45 +02:00
|
|
|
#include "sim/stats.hh"
|
|
|
|
#include "sim/system.hh"
|
|
|
|
|
2006-10-20 19:00:05 +02:00
|
|
|
using namespace iGbReg;
|
2007-03-22 23:39:41 +01:00
|
|
|
using namespace Net;
|
2006-10-20 19:00:05 +02:00
|
|
|
|
2007-08-16 22:49:02 +02:00
|
|
|
IGbE::IGbE(const Params *p)
|
|
|
|
: EtherDevice(p), etherInt(NULL), drainEvent(NULL), useFlowControl(p->use_flow_control),
|
2007-03-22 23:39:41 +01:00
|
|
|
rxFifo(p->rx_fifo_size), txFifo(p->tx_fifo_size), rxTick(false),
|
2007-08-27 06:45:40 +02:00
|
|
|
txTick(false), txFifoTick(false), rxDmaPacket(false), rdtrEvent(this), radvEvent(this),
|
2007-03-28 02:44:21 +02:00
|
|
|
tadvEvent(this), tidvEvent(this), tickEvent(this), interEvent(this),
|
2007-03-27 00:40:18 +02:00
|
|
|
rxDescCache(this, name()+".RxDesc", p->rx_desc_cache_size),
|
|
|
|
txDescCache(this, name()+".TxDesc", p->tx_desc_cache_size), clock(p->clock)
|
2006-09-19 02:12:45 +02:00
|
|
|
{
|
2007-08-16 22:49:02 +02:00
|
|
|
etherInt = new IGbEInt(name() + ".int", this);
|
|
|
|
|
2006-10-20 19:00:05 +02:00
|
|
|
// Initialized internal registers per Intel documentation
|
2007-03-22 23:39:41 +01:00
|
|
|
// All registers intialized to 0 by per register constructor
|
2007-03-15 20:16:23 +01:00
|
|
|
regs.ctrl.fd(1);
|
|
|
|
regs.ctrl.lrst(1);
|
|
|
|
regs.ctrl.speed(2);
|
|
|
|
regs.ctrl.frcspd(1);
|
|
|
|
regs.sts.speed(3); // Say we're 1000Mbps
|
|
|
|
regs.sts.fd(1); // full duplex
|
2007-03-27 00:40:18 +02:00
|
|
|
regs.sts.lu(1); // link up
|
2007-03-15 20:16:23 +01:00
|
|
|
regs.eecd.fwe(1);
|
|
|
|
regs.eecd.ee_type(1);
|
2007-03-22 23:39:41 +01:00
|
|
|
regs.imr = 0;
|
|
|
|
regs.iam = 0;
|
|
|
|
regs.rxdctl.gran(1);
|
|
|
|
regs.rxdctl.wthresh(1);
|
2007-03-15 20:16:23 +01:00
|
|
|
regs.fcrth(1);
|
|
|
|
|
|
|
|
regs.pba.rxa(0x30);
|
|
|
|
regs.pba.txa(0x10);
|
2006-10-27 15:10:50 +02:00
|
|
|
|
2006-10-20 19:00:05 +02:00
|
|
|
eeOpBits = 0;
|
|
|
|
eeAddrBits = 0;
|
|
|
|
eeDataBits = 0;
|
|
|
|
eeOpcode = 0;
|
2006-09-19 02:12:45 +02:00
|
|
|
|
2006-10-27 15:10:50 +02:00
|
|
|
// clear all 64 16 bit words of the eeprom
|
|
|
|
memset(&flash, 0, EEPROM_SIZE*2);
|
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
// Set the MAC address
|
|
|
|
memcpy(flash, p->hardware_address.bytes(), ETH_ADDR_LEN);
|
|
|
|
for (int x = 0; x < ETH_ADDR_LEN/2; x++)
|
|
|
|
flash[x] = htobe(flash[x]);
|
2007-03-15 20:16:23 +01:00
|
|
|
|
|
|
|
uint16_t csum = 0;
|
|
|
|
for (int x = 0; x < EEPROM_SIZE; x++)
|
2007-03-27 00:40:18 +02:00
|
|
|
csum += htobe(flash[x]);
|
|
|
|
|
2007-03-15 20:16:23 +01:00
|
|
|
|
2006-10-20 19:00:05 +02:00
|
|
|
// Magic happy checksum value
|
2007-03-15 20:16:23 +01:00
|
|
|
flash[EEPROM_SIZE-1] = htobe((uint16_t)(EEPROM_CSUM - csum));
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
rxFifo.clear();
|
|
|
|
txFifo.clear();
|
2006-09-19 02:12:45 +02:00
|
|
|
}
|
|
|
|
|
2007-08-16 22:49:02 +02:00
|
|
|
EtherInt*
|
|
|
|
IGbE::getEthPort(const std::string &if_name, int idx)
|
|
|
|
{
|
|
|
|
|
2007-08-27 06:45:40 +02:00
|
|
|
if (if_name == "interface") {
|
2007-08-16 22:49:02 +02:00
|
|
|
if (etherInt->getPeer())
|
|
|
|
panic("Port already connected to\n");
|
|
|
|
return etherInt;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-09-19 02:12:45 +02:00
|
|
|
|
|
|
|
Tick
|
2006-10-20 09:10:12 +02:00
|
|
|
IGbE::writeConfig(PacketPtr pkt)
|
2006-09-19 02:12:45 +02:00
|
|
|
{
|
|
|
|
int offset = pkt->getAddr() & PCI_CONFIG_SIZE;
|
|
|
|
if (offset < PCI_DEVICE_SPECIFIC)
|
|
|
|
PciDev::writeConfig(pkt);
|
|
|
|
else
|
|
|
|
panic("Device specific PCI config space not implemented.\n");
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Some work may need to be done here based for the pci COMMAND bits.
|
|
|
|
///
|
|
|
|
|
|
|
|
return pioDelay;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tick
|
2006-10-20 09:10:12 +02:00
|
|
|
IGbE::read(PacketPtr pkt)
|
2006-09-19 02:12:45 +02:00
|
|
|
{
|
|
|
|
int bar;
|
|
|
|
Addr daddr;
|
|
|
|
|
|
|
|
if (!getBAR(pkt->getAddr(), bar, daddr))
|
|
|
|
panic("Invalid PCI memory access to unmapped memory.\n");
|
|
|
|
|
|
|
|
// Only Memory register BAR is allowed
|
|
|
|
assert(bar == 0);
|
|
|
|
|
2006-10-20 19:00:05 +02:00
|
|
|
// Only 32bit accesses allowed
|
|
|
|
assert(pkt->getSize() == 4);
|
2006-09-19 02:12:45 +02:00
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
DPRINTF(Ethernet, "Read device register %#X\n", daddr);
|
2006-09-19 02:12:45 +02:00
|
|
|
|
2006-10-20 19:00:05 +02:00
|
|
|
pkt->allocate();
|
2006-09-19 02:12:45 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Handle read of register here
|
|
|
|
///
|
|
|
|
|
2006-10-27 15:10:50 +02:00
|
|
|
|
2006-10-20 19:00:05 +02:00
|
|
|
switch (daddr) {
|
2007-03-15 20:16:23 +01:00
|
|
|
case REG_CTRL:
|
|
|
|
pkt->set<uint32_t>(regs.ctrl());
|
|
|
|
break;
|
|
|
|
case REG_STATUS:
|
|
|
|
pkt->set<uint32_t>(regs.sts());
|
|
|
|
break;
|
|
|
|
case REG_EECD:
|
|
|
|
pkt->set<uint32_t>(regs.eecd());
|
|
|
|
break;
|
|
|
|
case REG_EERD:
|
|
|
|
pkt->set<uint32_t>(regs.eerd());
|
|
|
|
break;
|
|
|
|
case REG_CTRL_EXT:
|
|
|
|
pkt->set<uint32_t>(regs.ctrl_ext());
|
|
|
|
break;
|
|
|
|
case REG_MDIC:
|
|
|
|
pkt->set<uint32_t>(regs.mdic());
|
|
|
|
break;
|
|
|
|
case REG_ICR:
|
2007-03-27 00:40:18 +02:00
|
|
|
DPRINTF(Ethernet, "Reading ICR. ICR=%#x IMR=%#x IAM=%#x IAME=%d\n", regs.icr(),
|
|
|
|
regs.imr, regs.iam, regs.ctrl_ext.iame());
|
2007-03-15 20:16:23 +01:00
|
|
|
pkt->set<uint32_t>(regs.icr());
|
2007-03-27 00:40:18 +02:00
|
|
|
if (regs.icr.int_assert() || regs.imr == 0) {
|
|
|
|
regs.icr = regs.icr() & ~mask(30);
|
|
|
|
DPRINTF(Ethernet, "Cleared ICR. ICR=%#x\n", regs.icr());
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
2007-03-27 00:40:18 +02:00
|
|
|
if (regs.ctrl_ext.iame() && regs.icr.int_assert())
|
|
|
|
regs.imr &= ~regs.iam;
|
|
|
|
chkInterrupt();
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_ITR:
|
|
|
|
pkt->set<uint32_t>(regs.itr());
|
|
|
|
break;
|
|
|
|
case REG_RCTL:
|
|
|
|
pkt->set<uint32_t>(regs.rctl());
|
|
|
|
break;
|
|
|
|
case REG_FCTTV:
|
|
|
|
pkt->set<uint32_t>(regs.fcttv());
|
|
|
|
break;
|
|
|
|
case REG_TCTL:
|
|
|
|
pkt->set<uint32_t>(regs.tctl());
|
|
|
|
break;
|
|
|
|
case REG_PBA:
|
|
|
|
pkt->set<uint32_t>(regs.pba());
|
|
|
|
break;
|
|
|
|
case REG_WUC:
|
|
|
|
case REG_LEDCTL:
|
|
|
|
pkt->set<uint32_t>(0); // We don't care, so just return 0
|
|
|
|
break;
|
|
|
|
case REG_FCRTL:
|
|
|
|
pkt->set<uint32_t>(regs.fcrtl());
|
|
|
|
break;
|
|
|
|
case REG_FCRTH:
|
|
|
|
pkt->set<uint32_t>(regs.fcrth());
|
|
|
|
break;
|
|
|
|
case REG_RDBAL:
|
|
|
|
pkt->set<uint32_t>(regs.rdba.rdbal());
|
|
|
|
break;
|
|
|
|
case REG_RDBAH:
|
|
|
|
pkt->set<uint32_t>(regs.rdba.rdbah());
|
|
|
|
break;
|
|
|
|
case REG_RDLEN:
|
|
|
|
pkt->set<uint32_t>(regs.rdlen());
|
|
|
|
break;
|
|
|
|
case REG_RDH:
|
|
|
|
pkt->set<uint32_t>(regs.rdh());
|
|
|
|
break;
|
|
|
|
case REG_RDT:
|
|
|
|
pkt->set<uint32_t>(regs.rdt());
|
|
|
|
break;
|
|
|
|
case REG_RDTR:
|
|
|
|
pkt->set<uint32_t>(regs.rdtr());
|
2007-03-22 23:39:41 +01:00
|
|
|
if (regs.rdtr.fpd()) {
|
|
|
|
rxDescCache.writeback(0);
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetIntr, "Posting interrupt because of RDTR.FPD write\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
postInterrupt(IT_RXT);
|
|
|
|
regs.rdtr.fpd(0);
|
|
|
|
}
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_RADV:
|
|
|
|
pkt->set<uint32_t>(regs.radv());
|
|
|
|
break;
|
|
|
|
case REG_TDBAL:
|
|
|
|
pkt->set<uint32_t>(regs.tdba.tdbal());
|
|
|
|
break;
|
|
|
|
case REG_TDBAH:
|
|
|
|
pkt->set<uint32_t>(regs.tdba.tdbah());
|
|
|
|
break;
|
|
|
|
case REG_TDLEN:
|
|
|
|
pkt->set<uint32_t>(regs.tdlen());
|
|
|
|
break;
|
|
|
|
case REG_TDH:
|
|
|
|
pkt->set<uint32_t>(regs.tdh());
|
|
|
|
break;
|
|
|
|
case REG_TDT:
|
|
|
|
pkt->set<uint32_t>(regs.tdt());
|
|
|
|
break;
|
|
|
|
case REG_TIDV:
|
|
|
|
pkt->set<uint32_t>(regs.tidv());
|
|
|
|
break;
|
|
|
|
case REG_TXDCTL:
|
|
|
|
pkt->set<uint32_t>(regs.txdctl());
|
|
|
|
break;
|
|
|
|
case REG_TADV:
|
|
|
|
pkt->set<uint32_t>(regs.tadv());
|
|
|
|
break;
|
|
|
|
case REG_RXCSUM:
|
|
|
|
pkt->set<uint32_t>(regs.rxcsum());
|
|
|
|
break;
|
|
|
|
case REG_MANC:
|
|
|
|
pkt->set<uint32_t>(regs.manc());
|
|
|
|
break;
|
2006-10-20 19:00:05 +02:00
|
|
|
default:
|
2007-03-15 20:16:23 +01:00
|
|
|
if (!(daddr >= REG_VFTA && daddr < (REG_VFTA + VLAN_FILTER_TABLE_SIZE*4)) &&
|
|
|
|
!(daddr >= REG_RAL && daddr < (REG_RAL + RCV_ADDRESS_TABLE_SIZE*8)) &&
|
|
|
|
!(daddr >= REG_MTA && daddr < (REG_MTA + MULTICAST_TABLE_SIZE*4)) &&
|
|
|
|
!(daddr >= REG_CRCERRS && daddr < (REG_CRCERRS + STATS_REGS_SIZE)))
|
|
|
|
panic("Read request to unknown register number: %#x\n", daddr);
|
|
|
|
else
|
|
|
|
pkt->set<uint32_t>(0);
|
2006-10-20 19:00:05 +02:00
|
|
|
};
|
|
|
|
|
2007-06-30 19:16:18 +02:00
|
|
|
pkt->makeAtomicResponse();
|
2006-09-19 02:12:45 +02:00
|
|
|
return pioDelay;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tick
|
2006-10-20 09:10:12 +02:00
|
|
|
IGbE::write(PacketPtr pkt)
|
2006-09-19 02:12:45 +02:00
|
|
|
{
|
|
|
|
int bar;
|
|
|
|
Addr daddr;
|
|
|
|
|
2006-10-20 19:00:05 +02:00
|
|
|
|
2006-09-19 02:12:45 +02:00
|
|
|
if (!getBAR(pkt->getAddr(), bar, daddr))
|
|
|
|
panic("Invalid PCI memory access to unmapped memory.\n");
|
|
|
|
|
|
|
|
// Only Memory register BAR is allowed
|
|
|
|
assert(bar == 0);
|
|
|
|
|
2006-10-20 19:00:05 +02:00
|
|
|
// Only 32bit accesses allowed
|
|
|
|
assert(pkt->getSize() == sizeof(uint32_t));
|
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
DPRINTF(Ethernet, "Wrote device register %#X value %#X\n", daddr, pkt->get<uint32_t>());
|
2006-09-19 02:12:45 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Handle write of register here
|
|
|
|
///
|
2006-10-20 19:00:05 +02:00
|
|
|
uint32_t val = pkt->get<uint32_t>();
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
Regs::RCTL oldrctl;
|
|
|
|
Regs::TCTL oldtctl;
|
|
|
|
|
2006-10-20 19:00:05 +02:00
|
|
|
switch (daddr) {
|
2007-03-15 20:16:23 +01:00
|
|
|
case REG_CTRL:
|
|
|
|
regs.ctrl = val;
|
|
|
|
if (regs.ctrl.tfce())
|
|
|
|
warn("TX Flow control enabled, should implement\n");
|
|
|
|
if (regs.ctrl.rfce())
|
|
|
|
warn("RX Flow control enabled, should implement\n");
|
|
|
|
break;
|
|
|
|
case REG_CTRL_EXT:
|
|
|
|
regs.ctrl_ext = val;
|
|
|
|
break;
|
|
|
|
case REG_STATUS:
|
|
|
|
regs.sts = val;
|
|
|
|
break;
|
|
|
|
case REG_EECD:
|
|
|
|
int oldClk;
|
|
|
|
oldClk = regs.eecd.sk();
|
|
|
|
regs.eecd = val;
|
|
|
|
// See if this is a eeprom access and emulate accordingly
|
|
|
|
if (!oldClk && regs.eecd.sk()) {
|
|
|
|
if (eeOpBits < 8) {
|
|
|
|
eeOpcode = eeOpcode << 1 | regs.eecd.din();
|
|
|
|
eeOpBits++;
|
|
|
|
} else if (eeAddrBits < 8 && eeOpcode == EEPROM_READ_OPCODE_SPI) {
|
|
|
|
eeAddr = eeAddr << 1 | regs.eecd.din();
|
|
|
|
eeAddrBits++;
|
|
|
|
} else if (eeDataBits < 16 && eeOpcode == EEPROM_READ_OPCODE_SPI) {
|
|
|
|
assert(eeAddr>>1 < EEPROM_SIZE);
|
|
|
|
DPRINTF(EthernetEEPROM, "EEPROM bit read: %d word: %#X\n",
|
|
|
|
flash[eeAddr>>1] >> eeDataBits & 0x1, flash[eeAddr>>1]);
|
|
|
|
regs.eecd.dout((flash[eeAddr>>1] >> (15-eeDataBits)) & 0x1);
|
|
|
|
eeDataBits++;
|
|
|
|
} else if (eeDataBits < 8 && eeOpcode == EEPROM_RDSR_OPCODE_SPI) {
|
|
|
|
regs.eecd.dout(0);
|
|
|
|
eeDataBits++;
|
|
|
|
} else
|
|
|
|
panic("What's going on with eeprom interface? opcode:"
|
|
|
|
" %#x:%d addr: %#x:%d, data: %d\n", (uint32_t)eeOpcode,
|
|
|
|
(uint32_t)eeOpBits, (uint32_t)eeAddr,
|
|
|
|
(uint32_t)eeAddrBits, (uint32_t)eeDataBits);
|
|
|
|
|
|
|
|
// Reset everything for the next command
|
|
|
|
if ((eeDataBits == 16 && eeOpcode == EEPROM_READ_OPCODE_SPI) ||
|
2006-10-20 19:00:05 +02:00
|
|
|
(eeDataBits == 8 && eeOpcode == EEPROM_RDSR_OPCODE_SPI)) {
|
2007-03-15 20:16:23 +01:00
|
|
|
eeOpBits = 0;
|
|
|
|
eeAddrBits = 0;
|
|
|
|
eeDataBits = 0;
|
2006-10-20 19:00:05 +02:00
|
|
|
eeOpcode = 0;
|
2007-03-15 20:16:23 +01:00
|
|
|
eeAddr = 0;
|
|
|
|
}
|
2006-10-20 19:00:05 +02:00
|
|
|
|
2006-10-27 15:10:50 +02:00
|
|
|
DPRINTF(EthernetEEPROM, "EEPROM: opcode: %#X:%d addr: %#X:%d\n",
|
2007-03-15 20:16:23 +01:00
|
|
|
(uint32_t)eeOpcode, (uint32_t) eeOpBits,
|
|
|
|
(uint32_t)eeAddr>>1, (uint32_t)eeAddrBits);
|
2006-10-20 19:00:05 +02:00
|
|
|
if (eeOpBits == 8 && !(eeOpcode == EEPROM_READ_OPCODE_SPI ||
|
2007-03-15 20:16:23 +01:00
|
|
|
eeOpcode == EEPROM_RDSR_OPCODE_SPI ))
|
|
|
|
panic("Unknown eeprom opcode: %#X:%d\n", (uint32_t)eeOpcode,
|
|
|
|
(uint32_t)eeOpBits);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
// If driver requests eeprom access, immediately give it to it
|
|
|
|
regs.eecd.ee_gnt(regs.eecd.ee_req());
|
|
|
|
break;
|
|
|
|
case REG_EERD:
|
|
|
|
regs.eerd = val;
|
|
|
|
break;
|
|
|
|
case REG_MDIC:
|
|
|
|
regs.mdic = val;
|
|
|
|
if (regs.mdic.i())
|
|
|
|
panic("No support for interrupt on mdic complete\n");
|
|
|
|
if (regs.mdic.phyadd() != 1)
|
|
|
|
panic("No support for reading anything but phy\n");
|
|
|
|
DPRINTF(Ethernet, "%s phy address %x\n", regs.mdic.op() == 1 ? "Writing"
|
|
|
|
: "Reading", regs.mdic.regadd());
|
|
|
|
switch (regs.mdic.regadd()) {
|
|
|
|
case PHY_PSTATUS:
|
|
|
|
regs.mdic.data(0x796D); // link up
|
|
|
|
break;
|
|
|
|
case PHY_PID:
|
|
|
|
regs.mdic.data(0x02A8);
|
|
|
|
break;
|
|
|
|
case PHY_EPID:
|
|
|
|
regs.mdic.data(0x0380);
|
|
|
|
break;
|
|
|
|
case PHY_GSTATUS:
|
|
|
|
regs.mdic.data(0x7C00);
|
|
|
|
break;
|
|
|
|
case PHY_EPSTATUS:
|
|
|
|
regs.mdic.data(0x3000);
|
|
|
|
break;
|
|
|
|
case PHY_AGC:
|
|
|
|
regs.mdic.data(0x180); // some random length
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
regs.mdic.data(0);
|
|
|
|
}
|
|
|
|
regs.mdic.r(1);
|
|
|
|
break;
|
|
|
|
case REG_ICR:
|
2007-03-27 00:40:18 +02:00
|
|
|
DPRINTF(Ethernet, "Writing ICR. ICR=%#x IMR=%#x IAM=%#x IAME=%d\n", regs.icr(),
|
|
|
|
regs.imr, regs.iam, regs.ctrl_ext.iame());
|
|
|
|
if (regs.ctrl_ext.iame())
|
|
|
|
regs.imr &= ~regs.iam;
|
2007-03-22 23:39:41 +01:00
|
|
|
regs.icr = ~bits(val,30,0) & regs.icr();
|
2007-03-27 00:40:18 +02:00
|
|
|
chkInterrupt();
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_ITR:
|
|
|
|
regs.itr = val;
|
|
|
|
break;
|
|
|
|
case REG_ICS:
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetIntr, "Posting interrupt because of ICS write\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
postInterrupt((IntTypes)val);
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_IMS:
|
|
|
|
regs.imr |= val;
|
2007-03-22 23:39:41 +01:00
|
|
|
chkInterrupt();
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_IMC:
|
2007-03-22 23:39:41 +01:00
|
|
|
regs.imr &= ~val;
|
|
|
|
chkInterrupt();
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_IAM:
|
|
|
|
regs.iam = val;
|
|
|
|
break;
|
|
|
|
case REG_RCTL:
|
2007-03-22 23:39:41 +01:00
|
|
|
oldrctl = regs.rctl;
|
2007-03-15 20:16:23 +01:00
|
|
|
regs.rctl = val;
|
2007-03-22 23:39:41 +01:00
|
|
|
if (regs.rctl.rst()) {
|
|
|
|
rxDescCache.reset();
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetSM, "RXS: Got RESET!\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
rxFifo.clear();
|
|
|
|
regs.rctl.rst(0);
|
|
|
|
}
|
|
|
|
if (regs.rctl.en())
|
|
|
|
rxTick = true;
|
2007-03-27 00:40:18 +02:00
|
|
|
restartClock();
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_FCTTV:
|
|
|
|
regs.fcttv = val;
|
|
|
|
break;
|
|
|
|
case REG_TCTL:
|
|
|
|
regs.tctl = val;
|
2007-03-22 23:39:41 +01:00
|
|
|
oldtctl = regs.tctl;
|
|
|
|
regs.tctl = val;
|
|
|
|
if (regs.tctl.en())
|
|
|
|
txTick = true;
|
2007-03-27 00:40:18 +02:00
|
|
|
restartClock();
|
2007-03-22 23:39:41 +01:00
|
|
|
if (regs.tctl.en() && !oldtctl.en()) {
|
|
|
|
txDescCache.reset();
|
|
|
|
}
|
|
|
|
break;
|
2007-03-15 20:16:23 +01:00
|
|
|
case REG_PBA:
|
|
|
|
regs.pba.rxa(val);
|
|
|
|
regs.pba.txa(64 - regs.pba.rxa());
|
|
|
|
break;
|
|
|
|
case REG_WUC:
|
|
|
|
case REG_LEDCTL:
|
|
|
|
case REG_FCAL:
|
|
|
|
case REG_FCAH:
|
|
|
|
case REG_FCT:
|
|
|
|
case REG_VET:
|
|
|
|
case REG_AIFS:
|
|
|
|
case REG_TIPG:
|
|
|
|
; // We don't care, so don't store anything
|
|
|
|
break;
|
|
|
|
case REG_FCRTL:
|
|
|
|
regs.fcrtl = val;
|
|
|
|
break;
|
|
|
|
case REG_FCRTH:
|
|
|
|
regs.fcrth = val;
|
|
|
|
break;
|
|
|
|
case REG_RDBAL:
|
|
|
|
regs.rdba.rdbal( val & ~mask(4));
|
2007-03-22 23:39:41 +01:00
|
|
|
rxDescCache.areaChanged();
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_RDBAH:
|
|
|
|
regs.rdba.rdbah(val);
|
2007-03-22 23:39:41 +01:00
|
|
|
rxDescCache.areaChanged();
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_RDLEN:
|
|
|
|
regs.rdlen = val & ~mask(7);
|
2007-03-22 23:39:41 +01:00
|
|
|
rxDescCache.areaChanged();
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_RDH:
|
|
|
|
regs.rdh = val;
|
2007-03-22 23:39:41 +01:00
|
|
|
rxDescCache.areaChanged();
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_RDT:
|
|
|
|
regs.rdt = val;
|
2007-08-27 06:45:40 +02:00
|
|
|
DPRINTF(EthernetSM, "RXS: RDT Updated.\n");
|
|
|
|
if (getState() == SimObject::Running) {
|
|
|
|
DPRINTF(EthernetSM, "RXS: RDT Fetching Descriptors!\n");
|
|
|
|
rxDescCache.fetchDescriptors();
|
|
|
|
} else {
|
|
|
|
DPRINTF(EthernetSM, "RXS: RDT NOT Fetching Desc b/c draining!\n");
|
|
|
|
}
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_RDTR:
|
|
|
|
regs.rdtr = val;
|
|
|
|
break;
|
|
|
|
case REG_RADV:
|
|
|
|
regs.radv = val;
|
|
|
|
break;
|
|
|
|
case REG_TDBAL:
|
|
|
|
regs.tdba.tdbal( val & ~mask(4));
|
2007-03-22 23:39:41 +01:00
|
|
|
txDescCache.areaChanged();
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_TDBAH:
|
|
|
|
regs.tdba.tdbah(val);
|
2007-03-22 23:39:41 +01:00
|
|
|
txDescCache.areaChanged();
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_TDLEN:
|
|
|
|
regs.tdlen = val & ~mask(7);
|
2007-03-22 23:39:41 +01:00
|
|
|
txDescCache.areaChanged();
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_TDH:
|
|
|
|
regs.tdh = val;
|
2007-03-22 23:39:41 +01:00
|
|
|
txDescCache.areaChanged();
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_TDT:
|
|
|
|
regs.tdt = val;
|
2007-08-27 06:45:40 +02:00
|
|
|
DPRINTF(EthernetSM, "TXS: TX Tail pointer updated\n");
|
|
|
|
if (getState() == SimObject::Running) {
|
|
|
|
DPRINTF(EthernetSM, "TXS: TDT Fetching Descriptors!\n");
|
|
|
|
txDescCache.fetchDescriptors();
|
|
|
|
} else {
|
|
|
|
DPRINTF(EthernetSM, "TXS: TDT NOT Fetching Desc b/c draining!\n");
|
|
|
|
}
|
2007-03-15 20:16:23 +01:00
|
|
|
break;
|
|
|
|
case REG_TIDV:
|
|
|
|
regs.tidv = val;
|
|
|
|
break;
|
|
|
|
case REG_TXDCTL:
|
|
|
|
regs.txdctl = val;
|
|
|
|
break;
|
|
|
|
case REG_TADV:
|
|
|
|
regs.tadv = val;
|
|
|
|
break;
|
|
|
|
case REG_RXCSUM:
|
|
|
|
regs.rxcsum = val;
|
|
|
|
break;
|
|
|
|
case REG_MANC:
|
|
|
|
regs.manc = val;
|
|
|
|
break;
|
2006-10-20 19:00:05 +02:00
|
|
|
default:
|
2007-03-15 20:16:23 +01:00
|
|
|
if (!(daddr >= REG_VFTA && daddr < (REG_VFTA + VLAN_FILTER_TABLE_SIZE*4)) &&
|
|
|
|
!(daddr >= REG_RAL && daddr < (REG_RAL + RCV_ADDRESS_TABLE_SIZE*8)) &&
|
|
|
|
!(daddr >= REG_MTA && daddr < (REG_MTA + MULTICAST_TABLE_SIZE*4)))
|
2006-10-27 15:10:50 +02:00
|
|
|
panic("Write request to unknown register number: %#x\n", daddr);
|
2006-10-20 19:00:05 +02:00
|
|
|
};
|
2006-09-19 02:12:45 +02:00
|
|
|
|
2007-06-30 19:16:18 +02:00
|
|
|
pkt->makeAtomicResponse();
|
2006-09-19 02:12:45 +02:00
|
|
|
return pioDelay;
|
|
|
|
}
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
void
|
|
|
|
IGbE::postInterrupt(IntTypes t, bool now)
|
|
|
|
{
|
2007-03-27 00:40:18 +02:00
|
|
|
assert(t);
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
// Interrupt is already pending
|
2007-08-27 06:45:40 +02:00
|
|
|
if (t & regs.icr() && !now)
|
2007-03-22 23:39:41 +01:00
|
|
|
return;
|
|
|
|
|
2007-08-27 06:45:40 +02:00
|
|
|
regs.icr = regs.icr() | t;
|
|
|
|
if (regs.itr.interval() == 0 || now) {
|
|
|
|
if (interEvent.scheduled()) {
|
|
|
|
interEvent.deschedule();
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
2007-08-27 06:45:40 +02:00
|
|
|
cpuPostInt();
|
|
|
|
} else {
|
|
|
|
DPRINTF(EthernetIntr, "EINT: Scheduling timer interrupt for %d ticks\n",
|
|
|
|
Clock::Int::ns * 256 * regs.itr.interval());
|
|
|
|
if (!interEvent.scheduled()) {
|
|
|
|
interEvent.schedule(curTick + Clock::Int::ns * 256 * regs.itr.interval());
|
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-27 06:45:40 +02:00
|
|
|
void
|
|
|
|
IGbE::delayIntEvent()
|
|
|
|
{
|
|
|
|
cpuPostInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
void
|
|
|
|
IGbE::cpuPostInt()
|
|
|
|
{
|
2007-08-27 06:45:40 +02:00
|
|
|
|
|
|
|
if (!(regs.icr() & regs.imr)) {
|
|
|
|
DPRINTF(Ethernet, "Interrupt Masked. Not Posting\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(Ethernet, "Posting Interrupt\n");
|
|
|
|
|
|
|
|
|
|
|
|
if (interEvent.scheduled()) {
|
|
|
|
interEvent.deschedule();
|
|
|
|
}
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
if (rdtrEvent.scheduled()) {
|
|
|
|
regs.icr.rxt0(1);
|
|
|
|
rdtrEvent.deschedule();
|
|
|
|
}
|
|
|
|
if (radvEvent.scheduled()) {
|
|
|
|
regs.icr.rxt0(1);
|
|
|
|
radvEvent.deschedule();
|
|
|
|
}
|
|
|
|
if (tadvEvent.scheduled()) {
|
|
|
|
regs.icr.txdw(1);
|
|
|
|
tadvEvent.deschedule();
|
|
|
|
}
|
|
|
|
if (tidvEvent.scheduled()) {
|
|
|
|
regs.icr.txdw(1);
|
|
|
|
tidvEvent.deschedule();
|
|
|
|
}
|
|
|
|
|
|
|
|
regs.icr.int_assert(1);
|
|
|
|
DPRINTF(EthernetIntr, "EINT: Posting interrupt to CPU now. Vector %#x\n",
|
|
|
|
regs.icr());
|
2007-08-27 06:45:40 +02:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
intrPost();
|
2007-08-27 06:45:40 +02:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::cpuClearInt()
|
|
|
|
{
|
2007-03-27 00:40:18 +02:00
|
|
|
if (regs.icr.int_assert()) {
|
|
|
|
regs.icr.int_assert(0);
|
|
|
|
DPRINTF(EthernetIntr, "EINT: Clearing interrupt to CPU now. Vector %#x\n",
|
|
|
|
regs.icr());
|
|
|
|
intrClear();
|
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::chkInterrupt()
|
|
|
|
{
|
2007-08-27 06:45:40 +02:00
|
|
|
DPRINTF(Ethernet, "Checking interrupts icr: %#x imr: %#x\n", regs.icr(),
|
|
|
|
regs.imr);
|
2007-03-22 23:39:41 +01:00
|
|
|
// Check if we need to clear the cpu interrupt
|
2007-03-27 00:40:18 +02:00
|
|
|
if (!(regs.icr() & regs.imr)) {
|
2007-08-27 06:45:40 +02:00
|
|
|
DPRINTF(Ethernet, "Mask cleaned all interrupts\n");
|
2007-03-27 00:40:18 +02:00
|
|
|
if (interEvent.scheduled())
|
|
|
|
interEvent.deschedule();
|
|
|
|
if (regs.icr.int_assert())
|
|
|
|
cpuClearInt();
|
|
|
|
}
|
2007-08-27 06:45:40 +02:00
|
|
|
DPRINTF(Ethernet, "ITR = %#X itr.interval = %#X\n", regs.itr(), regs.itr.interval());
|
2007-03-27 00:40:18 +02:00
|
|
|
|
|
|
|
if (regs.icr() & regs.imr) {
|
|
|
|
if (regs.itr.interval() == 0) {
|
|
|
|
cpuPostInt();
|
|
|
|
} else {
|
2007-08-27 06:45:40 +02:00
|
|
|
DPRINTF(Ethernet, "Possibly scheduling interrupt because of imr write\n");
|
|
|
|
if (!interEvent.scheduled()) {
|
|
|
|
DPRINTF(Ethernet, "Scheduling for %d\n", curTick + Clock::Int::ns
|
|
|
|
* 256 * regs.itr.interval());
|
2007-03-27 00:40:18 +02:00
|
|
|
interEvent.schedule(curTick + Clock::Int::ns * 256 * regs.itr.interval());
|
2007-08-27 06:45:40 +02:00
|
|
|
}
|
2007-03-27 00:40:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IGbE::RxDescCache::RxDescCache(IGbE *i, const std::string n, int s)
|
|
|
|
: DescCache<RxDesc>(i, n, s), pktDone(false), pktEvent(this)
|
|
|
|
|
|
|
|
{
|
|
|
|
}
|
2006-09-19 02:12:45 +02:00
|
|
|
|
|
|
|
bool
|
2007-03-22 23:39:41 +01:00
|
|
|
IGbE::RxDescCache::writePacket(EthPacketPtr packet)
|
2006-09-19 02:12:45 +02:00
|
|
|
{
|
2007-03-22 23:39:41 +01:00
|
|
|
// We shouldn't have to deal with any of these yet
|
2007-03-27 00:40:18 +02:00
|
|
|
DPRINTF(EthernetDesc, "Packet Length: %d Desc Size: %d\n",
|
|
|
|
packet->length, igbe->regs.rctl.descSize());
|
2007-03-22 23:39:41 +01:00
|
|
|
assert(packet->length < igbe->regs.rctl.descSize());
|
|
|
|
|
2007-09-12 21:24:23 +02:00
|
|
|
assert(unusedCache.size());
|
|
|
|
//if (!unusedCache.size())
|
|
|
|
// return false;
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
pktPtr = packet;
|
2007-05-14 22:37:00 +02:00
|
|
|
pktDone = false;
|
2007-03-27 00:40:18 +02:00
|
|
|
igbe->dmaWrite(igbe->platform->pciToDma(unusedCache.front()->buf),
|
|
|
|
packet->length, &pktEvent, packet->data);
|
2007-03-22 23:39:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::RxDescCache::pktComplete()
|
|
|
|
{
|
|
|
|
assert(unusedCache.size());
|
|
|
|
RxDesc *desc;
|
|
|
|
desc = unusedCache.front();
|
|
|
|
|
2007-08-27 06:45:40 +02:00
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
uint16_t crcfixup = igbe->regs.rctl.secrc() ? 0 : 4 ;
|
|
|
|
desc->len = htole((uint16_t)(pktPtr->length + crcfixup));
|
|
|
|
DPRINTF(EthernetDesc, "pktPtr->length: %d stripcrc offset: %d value written: %d %d\n",
|
|
|
|
pktPtr->length, crcfixup,
|
|
|
|
htole((uint16_t)(pktPtr->length + crcfixup)),
|
|
|
|
(uint16_t)(pktPtr->length + crcfixup));
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
// no support for anything but starting at 0
|
|
|
|
assert(igbe->regs.rxcsum.pcss() == 0);
|
|
|
|
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Packet written to memory updating Descriptor\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
uint8_t status = RXDS_DD | RXDS_EOP;
|
|
|
|
uint8_t err = 0;
|
2007-05-14 22:37:00 +02:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
IpPtr ip(pktPtr);
|
2007-05-14 22:37:00 +02:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
if (ip) {
|
2007-05-14 22:37:00 +02:00
|
|
|
DPRINTF(EthernetDesc, "Proccesing Ip packet with Id=%d\n", ip->id());
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
if (igbe->regs.rxcsum.ipofld()) {
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Checking IP checksum\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
status |= RXDS_IPCS;
|
2007-03-27 00:40:18 +02:00
|
|
|
desc->csum = htole(cksum(ip));
|
2007-03-22 23:39:41 +01:00
|
|
|
if (cksum(ip) != 0) {
|
|
|
|
err |= RXDE_IPE;
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Checksum is bad!!\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TcpPtr tcp(ip);
|
|
|
|
if (tcp && igbe->regs.rxcsum.tuofld()) {
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Checking TCP checksum\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
status |= RXDS_TCPCS;
|
2007-03-27 00:40:18 +02:00
|
|
|
desc->csum = htole(cksum(tcp));
|
2007-03-22 23:39:41 +01:00
|
|
|
if (cksum(tcp) != 0) {
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Checksum is bad!!\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
err |= RXDE_TCPE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UdpPtr udp(ip);
|
|
|
|
if (udp && igbe->regs.rxcsum.tuofld()) {
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Checking UDP checksum\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
status |= RXDS_UDPCS;
|
2007-03-27 00:40:18 +02:00
|
|
|
desc->csum = htole(cksum(udp));
|
2007-04-30 19:18:44 +02:00
|
|
|
if (cksum(udp) != 0) {
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Checksum is bad!!\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
err |= RXDE_TCPE;
|
|
|
|
}
|
|
|
|
}
|
2007-05-14 22:37:00 +02:00
|
|
|
} else { // if ip
|
|
|
|
DPRINTF(EthernetSM, "Proccesing Non-Ip packet\n");
|
|
|
|
}
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
desc->status = htole(status);
|
|
|
|
desc->errors = htole(err);
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
// No vlan support at this point... just set it to 0
|
|
|
|
desc->vlan = 0;
|
|
|
|
|
|
|
|
// Deal with the rx timer interrupts
|
|
|
|
if (igbe->regs.rdtr.delay()) {
|
|
|
|
DPRINTF(EthernetSM, "RXS: Scheduling DTR for %d\n",
|
|
|
|
igbe->regs.rdtr.delay() * igbe->intClock());
|
2007-05-10 04:34:54 +02:00
|
|
|
igbe->rdtrEvent.reschedule(curTick + igbe->regs.rdtr.delay() *
|
|
|
|
igbe->intClock(),true);
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (igbe->regs.radv.idv() && igbe->regs.rdtr.delay()) {
|
|
|
|
DPRINTF(EthernetSM, "RXS: Scheduling ADV for %d\n",
|
|
|
|
igbe->regs.radv.idv() * igbe->intClock());
|
2007-08-27 06:45:40 +02:00
|
|
|
if (!igbe->radvEvent.scheduled()) {
|
2007-03-22 23:39:41 +01:00
|
|
|
igbe->radvEvent.schedule(curTick + igbe->regs.radv.idv() *
|
|
|
|
igbe->intClock());
|
2007-08-27 06:45:40 +02:00
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
// if neither radv or rdtr, maybe itr is set...
|
|
|
|
if (!igbe->regs.rdtr.delay()) {
|
|
|
|
DPRINTF(EthernetSM, "RXS: Receive interrupt delay disabled, posting IT_RXT\n");
|
|
|
|
igbe->postInterrupt(IT_RXT);
|
|
|
|
}
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
// If the packet is small enough, interrupt appropriately
|
2007-03-27 00:40:18 +02:00
|
|
|
// I wonder if this is delayed or not?!
|
2007-03-28 02:44:21 +02:00
|
|
|
if (pktPtr->length <= igbe->regs.rsrpd.idv()) {
|
|
|
|
DPRINTF(EthernetSM, "RXS: Posting IT_SRPD beacuse small packet received\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
igbe->postInterrupt(IT_SRPD);
|
2007-03-28 02:44:21 +02:00
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Processing of this descriptor complete\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
unusedCache.pop_front();
|
|
|
|
usedCache.push_back(desc);
|
2007-08-27 06:45:40 +02:00
|
|
|
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
pktPtr = NULL;
|
|
|
|
enableSm();
|
|
|
|
pktDone = true;
|
2007-03-30 04:00:01 +02:00
|
|
|
igbe->checkDrain();
|
2007-08-27 06:45:40 +02:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::RxDescCache::enableSm()
|
|
|
|
{
|
2007-09-12 21:24:23 +02:00
|
|
|
if (!igbe->drainEvent) {
|
|
|
|
igbe->rxTick = true;
|
|
|
|
igbe->restartClock();
|
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IGbE::RxDescCache::packetDone()
|
|
|
|
{
|
|
|
|
if (pktDone) {
|
|
|
|
pktDone = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-30 04:00:01 +02:00
|
|
|
bool
|
|
|
|
IGbE::RxDescCache::hasOutstandingEvents()
|
|
|
|
{
|
|
|
|
return pktEvent.scheduled() || wbEvent.scheduled() ||
|
|
|
|
fetchEvent.scheduled();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::RxDescCache::serialize(std::ostream &os)
|
|
|
|
{
|
|
|
|
DescCache<RxDesc>::serialize(os);
|
|
|
|
SERIALIZE_SCALAR(pktDone);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::RxDescCache::unserialize(Checkpoint *cp, const std::string §ion)
|
|
|
|
{
|
|
|
|
DescCache<RxDesc>::unserialize(cp, section);
|
|
|
|
UNSERIALIZE_SCALAR(pktDone);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
///////////////////////////////////// IGbE::TxDesc /////////////////////////////////
|
|
|
|
|
|
|
|
IGbE::TxDescCache::TxDescCache(IGbE *i, const std::string n, int s)
|
|
|
|
: DescCache<TxDesc>(i,n, s), pktDone(false), isTcp(false), pktWaiting(false),
|
2007-03-30 04:00:01 +02:00
|
|
|
pktEvent(this)
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
IGbE::TxDescCache::getPacketSize()
|
|
|
|
{
|
|
|
|
assert(unusedCache.size());
|
|
|
|
|
|
|
|
TxDesc *desc;
|
|
|
|
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Starting processing of descriptor\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
while (unusedCache.size() && TxdOp::isContext(unusedCache.front())) {
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Got context descriptor type... skipping\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
// I think we can just ignore these for now?
|
|
|
|
desc = unusedCache.front();
|
2007-08-27 06:45:40 +02:00
|
|
|
DPRINTF(EthernetDesc, "Descriptor upper: %#x lower: %#X\n", desc->d1,
|
|
|
|
desc->d2);
|
2007-03-22 23:39:41 +01:00
|
|
|
// is this going to be a tcp or udp packet?
|
|
|
|
isTcp = TxdOp::tcp(desc) ? true : false;
|
|
|
|
|
|
|
|
// make sure it's ipv4
|
2007-08-27 06:45:40 +02:00
|
|
|
//assert(TxdOp::ip(desc));
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
TxdOp::setDd(desc);
|
|
|
|
unusedCache.pop_front();
|
|
|
|
usedCache.push_back(desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!unusedCache.size())
|
|
|
|
return -1;
|
|
|
|
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Next TX packet is %d bytes\n",
|
2007-03-22 23:39:41 +01:00
|
|
|
TxdOp::getLen(unusedCache.front()));
|
|
|
|
|
|
|
|
return TxdOp::getLen(unusedCache.front());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::TxDescCache::getPacketData(EthPacketPtr p)
|
|
|
|
{
|
|
|
|
assert(unusedCache.size());
|
|
|
|
|
|
|
|
TxDesc *desc;
|
|
|
|
desc = unusedCache.front();
|
|
|
|
|
|
|
|
assert((TxdOp::isLegacy(desc) || TxdOp::isData(desc)) && TxdOp::getLen(desc));
|
|
|
|
|
|
|
|
pktPtr = p;
|
|
|
|
|
|
|
|
pktWaiting = true;
|
|
|
|
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Starting DMA of packet\n");
|
2007-03-27 00:40:18 +02:00
|
|
|
igbe->dmaRead(igbe->platform->pciToDma(TxdOp::getBuf(desc)),
|
2007-03-30 04:00:01 +02:00
|
|
|
TxdOp::getLen(desc), &pktEvent, p->data + p->length);
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::TxDescCache::pktComplete()
|
|
|
|
{
|
|
|
|
|
|
|
|
TxDesc *desc;
|
|
|
|
assert(unusedCache.size());
|
|
|
|
assert(pktPtr);
|
|
|
|
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "DMA of packet complete\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
desc = unusedCache.front();
|
|
|
|
assert((TxdOp::isLegacy(desc) || TxdOp::isData(desc)) && TxdOp::getLen(desc));
|
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
DPRINTF(EthernetDesc, "TxDescriptor data d1: %#llx d2: %#llx\n", desc->d1, desc->d2);
|
|
|
|
|
|
|
|
if (!TxdOp::eop(desc)) {
|
2007-03-30 04:00:01 +02:00
|
|
|
// This only supports two descriptors per tx packet
|
|
|
|
assert(pktPtr->length == 0);
|
|
|
|
pktPtr->length = TxdOp::getLen(desc);
|
2007-03-27 00:40:18 +02:00
|
|
|
unusedCache.pop_front();
|
|
|
|
usedCache.push_back(desc);
|
|
|
|
pktDone = true;
|
|
|
|
pktWaiting = false;
|
|
|
|
pktPtr = NULL;
|
|
|
|
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Partial Packet Descriptor Done\n");
|
2007-05-10 04:39:43 +02:00
|
|
|
enableSm();
|
2007-09-12 21:24:23 +02:00
|
|
|
igbe->checkDrain();
|
2007-03-27 00:40:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the length of the data in the EtherPacket
|
2007-03-30 04:00:01 +02:00
|
|
|
pktPtr->length += TxdOp::getLen(desc);
|
2007-03-27 00:40:18 +02:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
// no support for vlans
|
|
|
|
assert(!TxdOp::vle(desc));
|
|
|
|
|
|
|
|
// we alway report status
|
|
|
|
assert(TxdOp::rs(desc));
|
|
|
|
|
|
|
|
// we only support single packet descriptors at this point
|
|
|
|
assert(TxdOp::eop(desc));
|
|
|
|
|
|
|
|
// set that this packet is done
|
|
|
|
TxdOp::setDd(desc);
|
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
DPRINTF(EthernetDesc, "TxDescriptor data d1: %#llx d2: %#llx\n", desc->d1, desc->d2);
|
|
|
|
|
2007-05-14 22:37:00 +02:00
|
|
|
if (DTRACE(EthernetDesc)) {
|
|
|
|
IpPtr ip(pktPtr);
|
|
|
|
if (ip)
|
|
|
|
DPRINTF(EthernetDesc, "Proccesing Ip packet with Id=%d\n",
|
|
|
|
ip->id());
|
|
|
|
else
|
|
|
|
DPRINTF(EthernetSM, "Proccesing Non-Ip packet\n");
|
|
|
|
}
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
// Checksums are only ofloaded for new descriptor types
|
|
|
|
if (TxdOp::isData(desc) && ( TxdOp::ixsm(desc) || TxdOp::txsm(desc)) ) {
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Calculating checksums for packet\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
IpPtr ip(pktPtr);
|
2007-05-14 22:37:00 +02:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
if (TxdOp::ixsm(desc)) {
|
|
|
|
ip->sum(0);
|
|
|
|
ip->sum(cksum(ip));
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Calculated IP checksum\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
2007-08-27 06:45:40 +02:00
|
|
|
if (TxdOp::txsm(desc)) {
|
|
|
|
TcpPtr tcp(ip);
|
|
|
|
UdpPtr udp(ip);
|
|
|
|
if (tcp) {
|
|
|
|
tcp->sum(0);
|
|
|
|
tcp->sum(cksum(tcp));
|
|
|
|
DPRINTF(EthernetDesc, "Calculated TCP checksum\n");
|
|
|
|
} else if (udp) {
|
|
|
|
assert(udp);
|
|
|
|
udp->sum(0);
|
|
|
|
udp->sum(cksum(udp));
|
|
|
|
DPRINTF(EthernetDesc, "Calculated UDP checksum\n");
|
|
|
|
} else {
|
|
|
|
panic("Told to checksum, but don't know how\n");
|
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TxdOp::ide(desc)) {
|
|
|
|
// Deal with the rx timer interrupts
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Descriptor had IDE set\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
if (igbe->regs.tidv.idv()) {
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "setting tidv\n");
|
2007-05-10 04:34:54 +02:00
|
|
|
igbe->tidvEvent.reschedule(curTick + igbe->regs.tidv.idv() *
|
|
|
|
igbe->intClock(), true);
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (igbe->regs.tadv.idv() && igbe->regs.tidv.idv()) {
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "setting tadv\n");
|
2007-08-27 06:45:40 +02:00
|
|
|
if (!igbe->tadvEvent.scheduled()) {
|
2007-03-22 23:39:41 +01:00
|
|
|
igbe->tadvEvent.schedule(curTick + igbe->regs.tadv.idv() *
|
|
|
|
igbe->intClock());
|
2007-08-27 06:45:40 +02:00
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
unusedCache.pop_front();
|
|
|
|
usedCache.push_back(desc);
|
|
|
|
pktDone = true;
|
|
|
|
pktWaiting = false;
|
|
|
|
pktPtr = NULL;
|
|
|
|
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "Descriptor Done\n");
|
2007-03-27 00:40:18 +02:00
|
|
|
|
|
|
|
if (igbe->regs.txdctl.wthresh() == 0) {
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "WTHRESH == 0, writing back descriptor\n");
|
2007-03-27 00:40:18 +02:00
|
|
|
writeback(0);
|
|
|
|
} else if (igbe->regs.txdctl.wthresh() >= usedCache.size()) {
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "used > WTHRESH, writing back descriptor\n");
|
2007-03-27 00:40:18 +02:00
|
|
|
writeback((igbe->cacheBlockSize()-1)>>4);
|
|
|
|
}
|
2007-05-10 04:39:43 +02:00
|
|
|
enableSm();
|
2007-03-30 04:00:01 +02:00
|
|
|
igbe->checkDrain();
|
|
|
|
}
|
2007-03-27 00:40:18 +02:00
|
|
|
|
2007-03-30 04:00:01 +02:00
|
|
|
void
|
|
|
|
IGbE::TxDescCache::serialize(std::ostream &os)
|
|
|
|
{
|
|
|
|
DescCache<TxDesc>::serialize(os);
|
|
|
|
SERIALIZE_SCALAR(pktDone);
|
|
|
|
SERIALIZE_SCALAR(isTcp);
|
|
|
|
SERIALIZE_SCALAR(pktWaiting);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::TxDescCache::unserialize(Checkpoint *cp, const std::string §ion)
|
|
|
|
{
|
|
|
|
DescCache<TxDesc>::unserialize(cp, section);
|
|
|
|
UNSERIALIZE_SCALAR(pktDone);
|
|
|
|
UNSERIALIZE_SCALAR(isTcp);
|
|
|
|
UNSERIALIZE_SCALAR(pktWaiting);
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IGbE::TxDescCache::packetAvailable()
|
|
|
|
{
|
|
|
|
if (pktDone) {
|
|
|
|
pktDone = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::TxDescCache::enableSm()
|
|
|
|
{
|
2007-09-12 21:24:23 +02:00
|
|
|
if (!igbe->drainEvent) {
|
|
|
|
igbe->txTick = true;
|
|
|
|
igbe->restartClock();
|
|
|
|
}
|
2006-09-19 02:12:45 +02:00
|
|
|
}
|
|
|
|
|
2007-03-30 04:00:01 +02:00
|
|
|
bool
|
|
|
|
IGbE::TxDescCache::hasOutstandingEvents()
|
|
|
|
{
|
|
|
|
return pktEvent.scheduled() || wbEvent.scheduled() ||
|
|
|
|
fetchEvent.scheduled();
|
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////// IGbE /////////////////////////////////
|
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
void
|
|
|
|
IGbE::restartClock()
|
|
|
|
{
|
2007-04-30 19:18:44 +02:00
|
|
|
if (!tickEvent.scheduled() && (rxTick || txTick || txFifoTick) && getState() ==
|
2007-03-30 04:00:01 +02:00
|
|
|
SimObject::Running)
|
2007-03-27 00:40:18 +02:00
|
|
|
tickEvent.schedule((curTick/cycles(1)) * cycles(1) + cycles(1));
|
|
|
|
}
|
|
|
|
|
2007-03-30 04:00:01 +02:00
|
|
|
unsigned int
|
|
|
|
IGbE::drain(Event *de)
|
|
|
|
{
|
|
|
|
unsigned int count;
|
|
|
|
count = pioPort->drain(de) + dmaPort->drain(de);
|
|
|
|
if (rxDescCache.hasOutstandingEvents() ||
|
|
|
|
txDescCache.hasOutstandingEvents()) {
|
|
|
|
count++;
|
|
|
|
drainEvent = de;
|
|
|
|
}
|
|
|
|
|
|
|
|
txFifoTick = false;
|
|
|
|
txTick = false;
|
|
|
|
rxTick = false;
|
|
|
|
|
|
|
|
if (tickEvent.scheduled())
|
|
|
|
tickEvent.deschedule();
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
changeState(Draining);
|
|
|
|
else
|
|
|
|
changeState(Drained);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::resume()
|
|
|
|
{
|
|
|
|
SimObject::resume();
|
|
|
|
|
|
|
|
txFifoTick = true;
|
|
|
|
txTick = true;
|
|
|
|
rxTick = true;
|
|
|
|
|
|
|
|
restartClock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::checkDrain()
|
|
|
|
{
|
|
|
|
if (!drainEvent)
|
|
|
|
return;
|
|
|
|
|
2007-08-27 06:45:40 +02:00
|
|
|
txFifoTick = false;
|
|
|
|
txTick = false;
|
|
|
|
rxTick = false;
|
|
|
|
if (!rxDescCache.hasOutstandingEvents() &&
|
|
|
|
!txDescCache.hasOutstandingEvents()) {
|
2007-03-30 04:00:01 +02:00
|
|
|
drainEvent->process();
|
|
|
|
drainEvent = NULL;
|
|
|
|
}
|
|
|
|
}
|
2007-03-27 00:40:18 +02:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
void
|
|
|
|
IGbE::txStateMachine()
|
|
|
|
{
|
|
|
|
if (!regs.tctl.en()) {
|
|
|
|
txTick = false;
|
2007-03-27 00:40:18 +02:00
|
|
|
DPRINTF(EthernetSM, "TXS: TX disabled, stopping ticking\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
// If we have a packet available and it's length is not 0 (meaning it's not
|
|
|
|
// a multidescriptor packet) put it in the fifo, otherwise an the next
|
|
|
|
// iteration we'll get the rest of the data
|
|
|
|
if (txPacket && txDescCache.packetAvailable() && txPacket->length) {
|
2007-03-22 23:39:41 +01:00
|
|
|
bool success;
|
2007-08-27 06:45:40 +02:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
DPRINTF(EthernetSM, "TXS: packet placed in TX FIFO\n");
|
|
|
|
success = txFifo.push(txPacket);
|
2007-09-12 21:24:23 +02:00
|
|
|
txFifoTick = true && !drainEvent;
|
2007-03-22 23:39:41 +01:00
|
|
|
assert(success);
|
|
|
|
txPacket = NULL;
|
2007-03-28 02:44:21 +02:00
|
|
|
txDescCache.writeback((cacheBlockSize()-1)>>4);
|
2007-03-22 23:39:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only support descriptor granularity
|
|
|
|
assert(regs.txdctl.gran());
|
|
|
|
if (regs.txdctl.lwthresh() && txDescCache.descLeft() < (regs.txdctl.lwthresh() * 8)) {
|
|
|
|
DPRINTF(EthernetSM, "TXS: LWTHRESH caused posting of TXDLOW\n");
|
|
|
|
postInterrupt(IT_TXDLOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!txPacket) {
|
|
|
|
txPacket = new EthPacketData(16384);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!txDescCache.packetWaiting()) {
|
|
|
|
if (txDescCache.descLeft() == 0) {
|
2007-08-27 06:45:40 +02:00
|
|
|
postInterrupt(IT_TXQE);
|
|
|
|
txDescCache.writeback(0);
|
2007-09-12 21:24:23 +02:00
|
|
|
txDescCache.fetchDescriptors();
|
2007-03-27 00:40:18 +02:00
|
|
|
DPRINTF(EthernetSM, "TXS: No descriptors left in ring, forcing "
|
|
|
|
"writeback stopping ticking and posting TXQE\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
txTick = false;
|
2007-03-28 02:44:21 +02:00
|
|
|
return;
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
if (!(txDescCache.descUnused())) {
|
2007-09-12 21:24:23 +02:00
|
|
|
txDescCache.fetchDescriptors();
|
2007-03-27 00:40:18 +02:00
|
|
|
DPRINTF(EthernetSM, "TXS: No descriptors available in cache, fetching and stopping ticking\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
txTick = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int size;
|
|
|
|
size = txDescCache.getPacketSize();
|
2007-03-27 00:40:18 +02:00
|
|
|
if (size > 0 && txFifo.avail() > size) {
|
|
|
|
DPRINTF(EthernetSM, "TXS: Reserving %d bytes in FIFO and begining "
|
|
|
|
"DMA of next packet\n", size);
|
|
|
|
txFifo.reserve(size);
|
2007-03-22 23:39:41 +01:00
|
|
|
txDescCache.getPacketData(txPacket);
|
2007-03-28 02:44:21 +02:00
|
|
|
} else if (size <= 0) {
|
2007-08-27 06:45:40 +02:00
|
|
|
DPRINTF(EthernetSM, "TXS: getPacketSize returned: %d\n", size);
|
2007-03-22 23:39:41 +01:00
|
|
|
DPRINTF(EthernetSM, "TXS: No packets to get, writing back used descriptors\n");
|
|
|
|
txDescCache.writeback(0);
|
2007-03-28 02:44:21 +02:00
|
|
|
} else {
|
|
|
|
DPRINTF(EthernetSM, "TXS: FIFO full, stopping ticking until space "
|
|
|
|
"available in FIFO\n");
|
|
|
|
txTick = false;
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
2007-03-28 02:44:21 +02:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
return;
|
|
|
|
}
|
2007-05-10 04:39:43 +02:00
|
|
|
DPRINTF(EthernetSM, "TXS: Nothing to do, stopping ticking\n");
|
|
|
|
txTick = false;
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IGbE::ethRxPkt(EthPacketPtr pkt)
|
|
|
|
{
|
|
|
|
DPRINTF(Ethernet, "RxFIFO: Receiving pcakte from wire\n");
|
2007-08-27 06:45:40 +02:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
if (!regs.rctl.en()) {
|
|
|
|
DPRINTF(Ethernet, "RxFIFO: RX not enabled, dropping\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// restart the state machines if they are stopped
|
2007-09-12 21:24:23 +02:00
|
|
|
rxTick = true && !drainEvent;
|
2007-03-22 23:39:41 +01:00
|
|
|
if ((rxTick || txTick) && !tickEvent.scheduled()) {
|
|
|
|
DPRINTF(EthernetSM, "RXS: received packet into fifo, starting ticking\n");
|
2007-03-27 00:40:18 +02:00
|
|
|
restartClock();
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!rxFifo.push(pkt)) {
|
|
|
|
DPRINTF(Ethernet, "RxFIFO: Packet won't fit in fifo... dropped\n");
|
|
|
|
postInterrupt(IT_RXO, true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::rxStateMachine()
|
|
|
|
{
|
|
|
|
if (!regs.rctl.en()) {
|
|
|
|
rxTick = false;
|
|
|
|
DPRINTF(EthernetSM, "RXS: RX disabled, stopping ticking\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the packet is done check for interrupts/descriptors/etc
|
|
|
|
if (rxDescCache.packetDone()) {
|
2007-05-14 22:37:00 +02:00
|
|
|
rxDmaPacket = false;
|
2007-03-22 23:39:41 +01:00
|
|
|
DPRINTF(EthernetSM, "RXS: Packet completed DMA to memory\n");
|
|
|
|
int descLeft = rxDescCache.descLeft();
|
|
|
|
switch (regs.rctl.rdmts()) {
|
|
|
|
case 2: if (descLeft > .125 * regs.rdlen()) break;
|
|
|
|
case 1: if (descLeft > .250 * regs.rdlen()) break;
|
|
|
|
case 0: if (descLeft > .500 * regs.rdlen()) break;
|
|
|
|
DPRINTF(Ethernet, "RXS: Interrupting (RXDMT) because of descriptors left\n");
|
|
|
|
postInterrupt(IT_RXDMT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (descLeft == 0) {
|
|
|
|
rxDescCache.writeback(0);
|
|
|
|
rxTick = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only support descriptor granulaties
|
|
|
|
assert(regs.rxdctl.gran());
|
|
|
|
|
|
|
|
if (regs.rxdctl.wthresh() >= rxDescCache.descUsed()) {
|
|
|
|
DPRINTF(EthernetSM, "RXS: Writing back because WTHRESH >= descUsed\n");
|
2007-03-27 00:40:18 +02:00
|
|
|
if (regs.rxdctl.wthresh() < (cacheBlockSize()>>4))
|
|
|
|
rxDescCache.writeback(regs.rxdctl.wthresh()-1);
|
|
|
|
else
|
|
|
|
rxDescCache.writeback((cacheBlockSize()-1)>>4);
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((rxDescCache.descUnused() < regs.rxdctl.pthresh()) &&
|
|
|
|
((rxDescCache.descLeft() - rxDescCache.descUnused()) > regs.rxdctl.hthresh())) {
|
|
|
|
DPRINTF(EthernetSM, "RXS: Fetching descriptors because descUnused < PTHRESH\n");
|
|
|
|
rxDescCache.fetchDescriptors();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rxDescCache.descUnused() == 0) {
|
2007-09-12 21:24:23 +02:00
|
|
|
rxDescCache.fetchDescriptors();
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetSM, "RXS: No descriptors available in cache, "
|
|
|
|
"fetching descriptors and stopping ticking\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
rxTick = false;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-14 22:37:00 +02:00
|
|
|
if (rxDmaPacket) {
|
|
|
|
DPRINTF(EthernetSM, "RXS: stopping ticking until packet DMA completes\n");
|
|
|
|
rxTick = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
if (!rxDescCache.descUnused()) {
|
2007-09-12 21:24:23 +02:00
|
|
|
rxDescCache.fetchDescriptors();
|
2007-03-22 23:39:41 +01:00
|
|
|
DPRINTF(EthernetSM, "RXS: No descriptors available in cache, stopping ticking\n");
|
|
|
|
rxTick = false;
|
|
|
|
DPRINTF(EthernetSM, "RXS: No descriptors available, fetching\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rxFifo.empty()) {
|
|
|
|
DPRINTF(EthernetSM, "RXS: RxFIFO empty, stopping ticking\n");
|
|
|
|
rxTick = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EthPacketPtr pkt;
|
|
|
|
pkt = rxFifo.front();
|
|
|
|
|
|
|
|
DPRINTF(EthernetSM, "RXS: Writing packet into memory\n");
|
2007-09-12 21:24:23 +02:00
|
|
|
if (rxDescCache.writePacket(pkt)) {
|
|
|
|
DPRINTF(EthernetSM, "RXS: Removing packet from FIFO\n");
|
|
|
|
rxFifo.pop();
|
|
|
|
DPRINTF(EthernetSM, "RXS: stopping ticking until packet DMA completes\n");
|
|
|
|
rxTick = false;
|
|
|
|
rxDmaPacket = true;
|
2007-03-22 23:39:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::txWire()
|
|
|
|
{
|
|
|
|
if (txFifo.empty()) {
|
2007-03-28 02:44:21 +02:00
|
|
|
txFifoTick = false;
|
2007-03-22 23:39:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-27 06:45:40 +02:00
|
|
|
if (etherInt->askBusy()) {
|
|
|
|
// We'll get woken up when the packet ethTxDone() gets called
|
|
|
|
txFifoTick = false;
|
|
|
|
} else {
|
|
|
|
if (DTRACE(EthernetSM)) {
|
|
|
|
IpPtr ip(txFifo.front());
|
|
|
|
if (ip)
|
|
|
|
DPRINTF(EthernetSM, "Transmitting Ip packet with Id=%d\n",
|
|
|
|
ip->id());
|
|
|
|
else
|
|
|
|
DPRINTF(EthernetSM, "Transmitting Non-Ip packet\n");
|
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2007-08-27 06:45:40 +02:00
|
|
|
bool r = etherInt->sendPacket(txFifo.front());
|
|
|
|
assert(r);
|
|
|
|
r += 1;
|
2007-03-30 04:00:01 +02:00
|
|
|
DPRINTF(EthernetSM, "TxFIFO: Successful transmit, bytes available in fifo: %d\n",
|
2007-03-22 23:39:41 +01:00
|
|
|
txFifo.avail());
|
|
|
|
txFifo.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::tick()
|
|
|
|
{
|
2007-03-27 00:40:18 +02:00
|
|
|
DPRINTF(EthernetSM, "IGbE: -------------- Cycle --------------\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
if (rxTick)
|
|
|
|
rxStateMachine();
|
|
|
|
|
2007-03-28 02:44:21 +02:00
|
|
|
if (txTick)
|
2007-03-22 23:39:41 +01:00
|
|
|
txStateMachine();
|
2007-03-28 02:44:21 +02:00
|
|
|
|
|
|
|
if (txFifoTick)
|
2007-03-22 23:39:41 +01:00
|
|
|
txWire();
|
|
|
|
|
2007-03-28 02:44:21 +02:00
|
|
|
|
|
|
|
if (rxTick || txTick || txFifoTick)
|
2007-03-22 23:39:41 +01:00
|
|
|
tickEvent.schedule(curTick + cycles(1));
|
|
|
|
}
|
|
|
|
|
2006-09-19 02:12:45 +02:00
|
|
|
void
|
|
|
|
IGbE::ethTxDone()
|
|
|
|
{
|
2007-03-28 02:44:21 +02:00
|
|
|
// restart the tx state machines if they are stopped
|
|
|
|
// fifo to send another packet
|
|
|
|
// tx sm to put more data into the fifo
|
2007-09-12 21:24:23 +02:00
|
|
|
txFifoTick = true && !drainEvent;
|
|
|
|
if (txDescCache.descLeft() != 0 && !drainEvent)
|
2007-08-27 06:45:40 +02:00
|
|
|
txTick = true;
|
2007-03-28 02:44:21 +02:00
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
restartClock();
|
2007-03-30 04:00:01 +02:00
|
|
|
DPRINTF(EthernetSM, "TxFIFO: Transmission complete\n");
|
2006-09-19 02:12:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::serialize(std::ostream &os)
|
|
|
|
{
|
2007-03-30 04:00:01 +02:00
|
|
|
PciDev::serialize(os);
|
|
|
|
|
|
|
|
regs.serialize(os);
|
|
|
|
SERIALIZE_SCALAR(eeOpBits);
|
|
|
|
SERIALIZE_SCALAR(eeAddrBits);
|
|
|
|
SERIALIZE_SCALAR(eeDataBits);
|
|
|
|
SERIALIZE_SCALAR(eeOpcode);
|
|
|
|
SERIALIZE_SCALAR(eeAddr);
|
|
|
|
SERIALIZE_ARRAY(flash,iGbReg::EEPROM_SIZE);
|
|
|
|
|
|
|
|
rxFifo.serialize("rxfifo", os);
|
|
|
|
txFifo.serialize("txfifo", os);
|
|
|
|
|
|
|
|
bool txPktExists = txPacket;
|
|
|
|
SERIALIZE_SCALAR(txPktExists);
|
|
|
|
if (txPktExists)
|
|
|
|
txPacket->serialize("txpacket", os);
|
|
|
|
|
|
|
|
Tick rdtr_time = 0, radv_time = 0, tidv_time = 0, tadv_time = 0,
|
|
|
|
inter_time = 0;
|
|
|
|
|
|
|
|
if (rdtrEvent.scheduled())
|
|
|
|
rdtr_time = rdtrEvent.when();
|
|
|
|
SERIALIZE_SCALAR(rdtr_time);
|
|
|
|
|
|
|
|
if (radvEvent.scheduled())
|
|
|
|
radv_time = radvEvent.when();
|
|
|
|
SERIALIZE_SCALAR(radv_time);
|
|
|
|
|
|
|
|
if (tidvEvent.scheduled())
|
2007-08-27 06:45:40 +02:00
|
|
|
tidv_time = tidvEvent.when();
|
2007-03-30 04:00:01 +02:00
|
|
|
SERIALIZE_SCALAR(tidv_time);
|
|
|
|
|
|
|
|
if (tadvEvent.scheduled())
|
2007-08-27 06:45:40 +02:00
|
|
|
tadv_time = tadvEvent.when();
|
2007-03-30 04:00:01 +02:00
|
|
|
SERIALIZE_SCALAR(tadv_time);
|
|
|
|
|
|
|
|
if (interEvent.scheduled())
|
2007-08-27 06:45:40 +02:00
|
|
|
inter_time = interEvent.when();
|
2007-03-30 04:00:01 +02:00
|
|
|
SERIALIZE_SCALAR(inter_time);
|
|
|
|
|
|
|
|
nameOut(os, csprintf("%s.TxDescCache", name()));
|
|
|
|
txDescCache.serialize(os);
|
|
|
|
|
|
|
|
nameOut(os, csprintf("%s.RxDescCache", name()));
|
|
|
|
rxDescCache.serialize(os);
|
2006-09-19 02:12:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::unserialize(Checkpoint *cp, const std::string §ion)
|
|
|
|
{
|
2007-03-30 04:00:01 +02:00
|
|
|
PciDev::unserialize(cp, section);
|
|
|
|
|
|
|
|
regs.unserialize(cp, section);
|
|
|
|
UNSERIALIZE_SCALAR(eeOpBits);
|
|
|
|
UNSERIALIZE_SCALAR(eeAddrBits);
|
|
|
|
UNSERIALIZE_SCALAR(eeDataBits);
|
|
|
|
UNSERIALIZE_SCALAR(eeOpcode);
|
|
|
|
UNSERIALIZE_SCALAR(eeAddr);
|
|
|
|
UNSERIALIZE_ARRAY(flash,iGbReg::EEPROM_SIZE);
|
|
|
|
|
|
|
|
rxFifo.unserialize("rxfifo", cp, section);
|
|
|
|
txFifo.unserialize("txfifo", cp, section);
|
|
|
|
|
|
|
|
bool txPktExists;
|
|
|
|
UNSERIALIZE_SCALAR(txPktExists);
|
|
|
|
if (txPktExists) {
|
|
|
|
txPacket = new EthPacketData(16384);
|
|
|
|
txPacket->unserialize("txpacket", cp, section);
|
|
|
|
}
|
|
|
|
|
|
|
|
rxTick = true;
|
|
|
|
txTick = true;
|
|
|
|
txFifoTick = true;
|
|
|
|
|
|
|
|
Tick rdtr_time, radv_time, tidv_time, tadv_time, inter_time;
|
|
|
|
UNSERIALIZE_SCALAR(rdtr_time);
|
|
|
|
UNSERIALIZE_SCALAR(radv_time);
|
|
|
|
UNSERIALIZE_SCALAR(tidv_time);
|
|
|
|
UNSERIALIZE_SCALAR(tadv_time);
|
|
|
|
UNSERIALIZE_SCALAR(inter_time);
|
|
|
|
|
|
|
|
if (rdtr_time)
|
|
|
|
rdtrEvent.schedule(rdtr_time);
|
|
|
|
|
|
|
|
if (radv_time)
|
|
|
|
radvEvent.schedule(radv_time);
|
|
|
|
|
|
|
|
if (tidv_time)
|
|
|
|
tidvEvent.schedule(tidv_time);
|
|
|
|
|
|
|
|
if (tadv_time)
|
|
|
|
tadvEvent.schedule(tadv_time);
|
|
|
|
|
|
|
|
if (inter_time)
|
|
|
|
interEvent.schedule(inter_time);
|
|
|
|
|
|
|
|
txDescCache.unserialize(cp, csprintf("%s.TxDescCache", section));
|
|
|
|
|
|
|
|
rxDescCache.unserialize(cp, csprintf("%s.RxDescCache", section));
|
2006-09-19 02:12:45 +02:00
|
|
|
}
|
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
IGbE *
|
|
|
|
IGbEParams::create()
|
2006-09-19 02:12:45 +02:00
|
|
|
{
|
2007-07-24 06:51:38 +02:00
|
|
|
return new IGbE(this);
|
2006-09-19 02:12:45 +02:00
|
|
|
}
|