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)
|
2009-04-22 07:58:53 +02:00
|
|
|
: 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),
|
2009-01-06 16:36:57 +01:00
|
|
|
txTick(false), txFifoTick(false), rxDmaPacket(false), pktOffset(0),
|
2008-08-13 23:41:58 +02:00
|
|
|
fetchDelay(p->fetch_delay), wbDelay(p->wb_delay),
|
|
|
|
fetchCompDelay(p->fetch_comp_delay), wbCompDelay(p->wb_comp_delay),
|
|
|
|
rxWriteDelay(p->rx_write_delay), txReadDelay(p->tx_read_delay),
|
|
|
|
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),
|
2008-07-01 16:30:08 +02:00
|
|
|
txDescCache(this, name()+".TxDesc", p->tx_desc_cache_size),
|
|
|
|
clock(p->clock), lastInterrupt(0)
|
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);
|
2008-12-05 19:58:22 +01:00
|
|
|
regs.tdwba = 0;
|
|
|
|
regs.rlpml = 0;
|
|
|
|
regs.sw_fw_sync = 0;
|
2007-03-15 20:16:23 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2009-02-27 01:29:17 +01:00
|
|
|
// Store the MAC address as queue ID
|
|
|
|
macAddr = p->hardware_address;
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
rxFifo.clear();
|
|
|
|
txFifo.clear();
|
2006-09-19 02:12:45 +02:00
|
|
|
}
|
|
|
|
|
2009-02-27 01:29:17 +01:00
|
|
|
void
|
|
|
|
IGbE::init()
|
|
|
|
{
|
|
|
|
cpa = CPA::cpa();
|
|
|
|
PciDev::init();
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
//
|
|
|
|
// Some work may need to be done here based for the pci COMMAND bits.
|
|
|
|
//
|
2006-09-19 02:12:45 +02:00
|
|
|
|
|
|
|
return pioDelay;
|
|
|
|
}
|
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
// Handy macro for range-testing register access addresses
|
|
|
|
#define IN_RANGE(val, base, len) (val >= base && val < (base + len))
|
|
|
|
|
2006-09-19 02:12:45 +02:00
|
|
|
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
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
//
|
|
|
|
// Handle read of register here
|
|
|
|
//
|
2006-09-19 02:12:45 +02:00
|
|
|
|
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:
|
2009-04-22 07:58:53 +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;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_EICR:
|
|
|
|
// This is only useful for MSI, but the driver reads it every time
|
|
|
|
// Just don't do anything
|
|
|
|
pkt->set<uint32_t>(0);
|
|
|
|
break;
|
2007-03-15 20:16:23 +01:00
|
|
|
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;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_SRRCTL:
|
|
|
|
pkt->set<uint32_t>(regs.srrctl());
|
|
|
|
break;
|
2007-03-15 20:16:23 +01:00
|
|
|
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);
|
2009-04-22 07:58:53 +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;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_RXDCTL:
|
|
|
|
pkt->set<uint32_t>(regs.rxdctl());
|
|
|
|
break;
|
2007-03-15 20:16:23 +01:00
|
|
|
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;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_TXDCA_CTL:
|
|
|
|
pkt->set<uint32_t>(regs.txdca_ctl());
|
|
|
|
break;
|
2007-03-15 20:16:23 +01:00
|
|
|
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;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_TDWBAL:
|
|
|
|
pkt->set<uint32_t>(regs.tdwba & mask(32));
|
|
|
|
break;
|
|
|
|
case REG_TDWBAH:
|
|
|
|
pkt->set<uint32_t>(regs.tdwba >> 32);
|
|
|
|
break;
|
2007-03-15 20:16:23 +01:00
|
|
|
case REG_RXCSUM:
|
|
|
|
pkt->set<uint32_t>(regs.rxcsum());
|
|
|
|
break;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_RLPML:
|
|
|
|
pkt->set<uint32_t>(regs.rlpml);
|
|
|
|
break;
|
|
|
|
case REG_RFCTL:
|
|
|
|
pkt->set<uint32_t>(regs.rfctl());
|
|
|
|
break;
|
2007-03-15 20:16:23 +01:00
|
|
|
case REG_MANC:
|
|
|
|
pkt->set<uint32_t>(regs.manc());
|
|
|
|
break;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_SWSM:
|
|
|
|
pkt->set<uint32_t>(regs.swsm());
|
|
|
|
regs.swsm.smbi(1);
|
|
|
|
break;
|
|
|
|
case REG_FWSM:
|
|
|
|
pkt->set<uint32_t>(regs.fwsm());
|
|
|
|
break;
|
|
|
|
case REG_SWFWSYNC:
|
|
|
|
pkt->set<uint32_t>(regs.sw_fw_sync);
|
|
|
|
break;
|
2006-10-20 19:00:05 +02:00
|
|
|
default:
|
2009-04-22 07:58:53 +02:00
|
|
|
if (!IN_RANGE(daddr, REG_VFTA, VLAN_FILTER_TABLE_SIZE*4) &&
|
|
|
|
!IN_RANGE(daddr, REG_RAL, RCV_ADDRESS_TABLE_SIZE*8) &&
|
|
|
|
!IN_RANGE(daddr, REG_MTA, MULTICAST_TABLE_SIZE*4) &&
|
|
|
|
!IN_RANGE(daddr, REG_CRCERRS, STATS_REGS_SIZE))
|
2007-03-15 20:16:23 +01:00
|
|
|
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));
|
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(Ethernet, "Wrote device register %#X value %#X\n",
|
|
|
|
daddr, pkt->get<uint32_t>());
|
2006-09-19 02:12:45 +02:00
|
|
|
|
2009-04-22 07:58:53 +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",
|
2009-04-22 07:58:53 +02:00
|
|
|
flash[eeAddr>>1] >> eeDataBits & 0x1,
|
|
|
|
flash[eeAddr>>1]);
|
2007-03-15 20:16:23 +01:00
|
|
|
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:"
|
2009-04-22 07:58:53 +02:00
|
|
|
" %#x:%d addr: %#x:%d, data: %d\n", (uint32_t)eeOpcode,
|
|
|
|
(uint32_t)eeOpBits, (uint32_t)eeAddr,
|
|
|
|
(uint32_t)eeAddrBits, (uint32_t)eeDataBits);
|
2007-03-15 20:16:23 +01:00
|
|
|
|
|
|
|
// Reset everything for the next command
|
|
|
|
if ((eeDataBits == 16 && eeOpcode == EEPROM_READ_OPCODE_SPI) ||
|
2009-04-22 07:58:53 +02:00
|
|
|
(eeDataBits == 8 && eeOpcode == EEPROM_RDSR_OPCODE_SPI)) {
|
2007-03-15 20:16:23 +01:00
|
|
|
eeOpBits = 0;
|
|
|
|
eeAddrBits = 0;
|
|
|
|
eeDataBits = 0;
|
2009-04-22 07:58:53 +02:00
|
|
|
eeOpcode = 0;
|
2007-03-15 20:16:23 +01:00
|
|
|
eeAddr = 0;
|
|
|
|
}
|
2006-10-20 19:00:05 +02:00
|
|
|
|
2009-04-22 07:58:53 +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);
|
2009-04-22 07:58:53 +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,
|
2009-04-22 07:58:53 +02:00
|
|
|
(uint32_t)eeOpBits);
|
2007-03-15 20:16:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
// 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;
|
2008-12-05 19:58:22 +01:00
|
|
|
if (regs.eerd.start()) {
|
|
|
|
regs.eerd.done(1);
|
|
|
|
assert(regs.eerd.addr() < EEPROM_SIZE);
|
|
|
|
regs.eerd.data(flash[regs.eerd.addr()]);
|
|
|
|
regs.eerd.start(0);
|
|
|
|
DPRINTF(EthernetEEPROM, "EEPROM: read addr: %#X data %#x\n",
|
|
|
|
regs.eerd.addr(), regs.eerd.data());
|
|
|
|
}
|
2007-03-15 20:16:23 +01:00
|
|
|
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");
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(Ethernet, "%s phy address %x\n",
|
|
|
|
regs.mdic.op() == 1 ? "Writing" : "Reading",
|
|
|
|
regs.mdic.regadd());
|
2007-03-15 20:16:23 +01:00
|
|
|
switch (regs.mdic.regadd()) {
|
2009-04-22 07:58:53 +02:00
|
|
|
case PHY_PSTATUS:
|
|
|
|
regs.mdic.data(0x796D); // link up
|
|
|
|
break;
|
|
|
|
case PHY_PID:
|
|
|
|
regs.mdic.data(params()->phy_pid);
|
|
|
|
break;
|
|
|
|
case PHY_EPID:
|
|
|
|
regs.mdic.data(params()->phy_epid);
|
|
|
|
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);
|
2007-03-15 20:16:23 +01:00
|
|
|
}
|
|
|
|
regs.mdic.r(1);
|
|
|
|
break;
|
|
|
|
case REG_ICR:
|
2009-04-22 07:58:53 +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());
|
2007-03-27 00:40:18 +02:00
|
|
|
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;
|
2009-04-22 07:58:53 +02:00
|
|
|
case REG_IMS:
|
2007-03-15 20:16:23 +01:00
|
|
|
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())
|
2009-04-22 07:58:53 +02:00
|
|
|
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();
|
|
|
|
}
|
2009-04-22 07:58:53 +02:00
|
|
|
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;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_IVAR0:
|
|
|
|
warn("Writing to IVAR0, ignoring...\n");
|
|
|
|
break;
|
2007-03-15 20:16:23 +01:00
|
|
|
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;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_SRRCTL:
|
|
|
|
regs.srrctl = val;
|
|
|
|
break;
|
2007-03-15 20:16:23 +01:00
|
|
|
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;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_RXDCTL:
|
|
|
|
regs.rxdctl = val;
|
|
|
|
break;
|
2007-03-15 20:16:23 +01:00
|
|
|
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;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_TXDCA_CTL:
|
|
|
|
regs.txdca_ctl = val;
|
|
|
|
if (regs.txdca_ctl.enabled())
|
|
|
|
panic("No support for DCA\n");
|
|
|
|
break;
|
2007-03-15 20:16:23 +01:00
|
|
|
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;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_TDWBAL:
|
|
|
|
regs.tdwba &= ~mask(32);
|
|
|
|
regs.tdwba |= val;
|
2009-04-22 07:58:53 +02:00
|
|
|
txDescCache.completionWriteback(regs.tdwba & ~mask(1),
|
|
|
|
regs.tdwba & mask(1));
|
2008-12-05 19:58:22 +01:00
|
|
|
break;
|
|
|
|
case REG_TDWBAH:
|
|
|
|
regs.tdwba &= mask(32);
|
|
|
|
regs.tdwba |= (uint64_t)val << 32;
|
2009-04-22 07:58:53 +02:00
|
|
|
txDescCache.completionWriteback(regs.tdwba & ~mask(1),
|
|
|
|
regs.tdwba & mask(1));
|
2008-12-05 19:58:22 +01:00
|
|
|
break;
|
2007-03-15 20:16:23 +01:00
|
|
|
case REG_RXCSUM:
|
|
|
|
regs.rxcsum = val;
|
|
|
|
break;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_RLPML:
|
|
|
|
regs.rlpml = val;
|
|
|
|
break;
|
|
|
|
case REG_RFCTL:
|
|
|
|
regs.rfctl = val;
|
|
|
|
if (regs.rfctl.exsten())
|
|
|
|
panic("Extended RX descriptors not implemented\n");
|
|
|
|
break;
|
2007-03-15 20:16:23 +01:00
|
|
|
case REG_MANC:
|
|
|
|
regs.manc = val;
|
|
|
|
break;
|
2008-12-05 19:58:22 +01:00
|
|
|
case REG_SWSM:
|
|
|
|
regs.swsm = val;
|
|
|
|
if (regs.fwsm.eep_fw_semaphore())
|
|
|
|
regs.swsm.swesmbi(0);
|
|
|
|
break;
|
|
|
|
case REG_SWFWSYNC:
|
|
|
|
regs.sw_fw_sync = val;
|
|
|
|
break;
|
2006-10-20 19:00:05 +02:00
|
|
|
default:
|
2009-04-22 07:58:53 +02:00
|
|
|
if (!IN_RANGE(daddr, REG_VFTA, VLAN_FILTER_TABLE_SIZE*4) &&
|
|
|
|
!IN_RANGE(daddr, REG_RAL, RCV_ADDRESS_TABLE_SIZE*8) &&
|
|
|
|
!IN_RANGE(daddr, REG_MTA, MULTICAST_TABLE_SIZE*4))
|
|
|
|
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;
|
2008-07-01 16:30:08 +02:00
|
|
|
|
2010-04-16 01:24:12 +02:00
|
|
|
Tick itr_interval = SimClock::Int::ns * 256 * regs.itr.interval();
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetIntr,
|
|
|
|
"EINT: postInterrupt() curTick: %d itr: %d interval: %d\n",
|
2008-08-24 21:27:49 +02:00
|
|
|
curTick, regs.itr.interval(), itr_interval);
|
2008-07-01 16:30:08 +02:00
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
if (regs.itr.interval() == 0 || now ||
|
|
|
|
lastInterrupt + itr_interval <= curTick) {
|
2007-08-27 06:45:40 +02:00
|
|
|
if (interEvent.scheduled()) {
|
2008-10-09 13:58:24 +02:00
|
|
|
deschedule(interEvent);
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
2007-08-27 06:45:40 +02:00
|
|
|
cpuPostInt();
|
|
|
|
} else {
|
2009-04-22 07:58:53 +02:00
|
|
|
Tick int_time = lastInterrupt + itr_interval;
|
|
|
|
assert(int_time > 0);
|
|
|
|
DPRINTF(EthernetIntr, "EINT: Scheduling timer interrupt for tick %d\n",
|
2008-07-01 16:30:08 +02:00
|
|
|
int_time);
|
2009-04-22 07:58:53 +02:00
|
|
|
if (!interEvent.scheduled()) {
|
|
|
|
schedule(interEvent, int_time);
|
|
|
|
}
|
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
|
|
|
|
2008-08-13 22:30:30 +02:00
|
|
|
postedInterrupts++;
|
|
|
|
|
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()) {
|
2008-10-09 13:58:24 +02:00
|
|
|
deschedule(interEvent);
|
2007-08-27 06:45:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
if (rdtrEvent.scheduled()) {
|
|
|
|
regs.icr.rxt0(1);
|
2008-10-09 13:58:24 +02:00
|
|
|
deschedule(rdtrEvent);
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
if (radvEvent.scheduled()) {
|
|
|
|
regs.icr.rxt0(1);
|
2008-10-09 13:58:24 +02:00
|
|
|
deschedule(radvEvent);
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
if (tadvEvent.scheduled()) {
|
|
|
|
regs.icr.txdw(1);
|
2008-10-09 13:58:24 +02:00
|
|
|
deschedule(tadvEvent);
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
if (tidvEvent.scheduled()) {
|
|
|
|
regs.icr.txdw(1);
|
2008-10-09 13:58:24 +02:00
|
|
|
deschedule(tidvEvent);
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2008-08-24 21:27:49 +02:00
|
|
|
lastInterrupt = curTick;
|
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);
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetIntr,
|
|
|
|
"EINT: Clearing interrupt to CPU now. Vector %#x\n",
|
2007-03-27 00:40:18 +02:00
|
|
|
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())
|
2009-04-22 07:58:53 +02:00
|
|
|
deschedule(interEvent);
|
2007-03-27 00:40:18 +02:00
|
|
|
if (regs.icr.int_assert())
|
|
|
|
cpuClearInt();
|
|
|
|
}
|
2009-04-22 07:58:53 +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 {
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(Ethernet,
|
|
|
|
"Possibly scheduling interrupt because of imr write\n");
|
2007-08-27 06:45:40 +02:00
|
|
|
if (!interEvent.scheduled()) {
|
2010-04-16 01:24:12 +02:00
|
|
|
Tick t = curTick + SimClock::Int::ns * 256 * regs.itr.interval();
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(Ethernet, "Scheduling for %d\n", t);
|
|
|
|
schedule(interEvent, t);
|
2007-08-27 06:45:40 +02:00
|
|
|
}
|
2007-03-27 00:40:18 +02:00
|
|
|
}
|
|
|
|
}
|
2009-04-22 07:58:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////// IGbE::DescCache //////////////////////////////
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
IGbE::DescCache<T>::DescCache(IGbE *i, const std::string n, int s)
|
|
|
|
: igbe(i), _name(n), cachePnt(0), size(s), curFetching(0),
|
|
|
|
wbOut(0), pktPtr(NULL), wbDelayEvent(this),
|
|
|
|
fetchDelayEvent(this), fetchEvent(this), wbEvent(this)
|
|
|
|
{
|
|
|
|
fetchBuf = new T[size];
|
|
|
|
wbBuf = new T[size];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
IGbE::DescCache<T>::~DescCache()
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
IGbE::DescCache<T>::areaChanged()
|
|
|
|
{
|
|
|
|
if (usedCache.size() > 0 || curFetching || wbOut)
|
|
|
|
panic("Descriptor Address, Length or Head changed. Bad\n");
|
|
|
|
reset();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
IGbE::DescCache<T>::writeback(Addr aMask)
|
|
|
|
{
|
|
|
|
int curHead = descHead();
|
|
|
|
int max_to_wb = usedCache.size();
|
|
|
|
|
|
|
|
// Check if this writeback is less restrictive that the previous
|
|
|
|
// and if so setup another one immediately following it
|
|
|
|
if (wbOut) {
|
|
|
|
if (aMask < wbAlignment) {
|
|
|
|
moreToWb = true;
|
|
|
|
wbAlignment = aMask;
|
|
|
|
}
|
|
|
|
DPRINTF(EthernetDesc,
|
|
|
|
"Writing back already in process, returning\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
moreToWb = false;
|
|
|
|
wbAlignment = aMask;
|
|
|
|
|
|
|
|
|
|
|
|
DPRINTF(EthernetDesc, "Writing back descriptors head: %d tail: "
|
|
|
|
"%d len: %d cachePnt: %d max_to_wb: %d descleft: %d\n",
|
|
|
|
curHead, descTail(), descLen(), cachePnt, max_to_wb,
|
|
|
|
descLeft());
|
|
|
|
|
|
|
|
if (max_to_wb + curHead >= descLen()) {
|
|
|
|
max_to_wb = descLen() - curHead;
|
|
|
|
moreToWb = true;
|
|
|
|
// this is by definition aligned correctly
|
|
|
|
} else if (wbAlignment != 0) {
|
|
|
|
// align the wb point to the mask
|
|
|
|
max_to_wb = max_to_wb & ~wbAlignment;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(EthernetDesc, "Writing back %d descriptors\n", max_to_wb);
|
|
|
|
|
|
|
|
if (max_to_wb <= 0) {
|
|
|
|
if (usedCache.size())
|
|
|
|
igbe->anBegin(annSmWb, "Wait Alignment", CPA::FL_WAIT);
|
|
|
|
else
|
|
|
|
igbe->anWe(annSmWb, annUsedCacheQ);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wbOut = max_to_wb;
|
|
|
|
|
|
|
|
assert(!wbDelayEvent.scheduled());
|
|
|
|
igbe->schedule(wbDelayEvent, curTick + igbe->wbDelay);
|
|
|
|
igbe->anBegin(annSmWb, "Prepare Writeback Desc");
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
IGbE::DescCache<T>::writeback1()
|
|
|
|
{
|
|
|
|
// If we're draining delay issuing this DMA
|
|
|
|
if (igbe->getState() != SimObject::Running) {
|
|
|
|
igbe->schedule(wbDelayEvent, curTick + igbe->wbDelay);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-27 00:40:18 +02:00
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc, "Begining DMA of %d descriptors\n", wbOut);
|
|
|
|
|
|
|
|
for (int x = 0; x < wbOut; x++) {
|
|
|
|
assert(usedCache.size());
|
|
|
|
memcpy(&wbBuf[x], usedCache[x], sizeof(T));
|
|
|
|
igbe->anPq(annSmWb, annUsedCacheQ);
|
|
|
|
igbe->anPq(annSmWb, annDescQ);
|
|
|
|
igbe->anQ(annSmWb, annUsedDescQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
igbe->anBegin(annSmWb, "Writeback Desc DMA");
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
assert(wbOut);
|
|
|
|
igbe->dmaWrite(pciToDma(descBase() + descHead() * sizeof(T)),
|
|
|
|
wbOut * sizeof(T), &wbEvent, (uint8_t*)wbBuf,
|
|
|
|
igbe->wbCompDelay);
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
IGbE::DescCache<T>::fetchDescriptors()
|
|
|
|
{
|
|
|
|
size_t max_to_fetch;
|
|
|
|
|
|
|
|
if (curFetching) {
|
|
|
|
DPRINTF(EthernetDesc,
|
|
|
|
"Currently fetching %d descriptors, returning\n",
|
|
|
|
curFetching);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (descTail() >= cachePnt)
|
|
|
|
max_to_fetch = descTail() - cachePnt;
|
|
|
|
else
|
|
|
|
max_to_fetch = descLen() - cachePnt;
|
|
|
|
|
|
|
|
size_t free_cache = size - usedCache.size() - unusedCache.size();
|
|
|
|
|
|
|
|
if (!max_to_fetch)
|
|
|
|
igbe->anWe(annSmFetch, annUnusedDescQ);
|
|
|
|
else
|
|
|
|
igbe->anPq(annSmFetch, annUnusedDescQ, max_to_fetch);
|
|
|
|
|
|
|
|
if (max_to_fetch) {
|
|
|
|
if (!free_cache)
|
|
|
|
igbe->anWf(annSmFetch, annDescQ);
|
|
|
|
else
|
|
|
|
igbe->anRq(annSmFetch, annDescQ, free_cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
max_to_fetch = std::min(max_to_fetch, free_cache);
|
|
|
|
|
|
|
|
|
|
|
|
DPRINTF(EthernetDesc, "Fetching descriptors head: %d tail: "
|
|
|
|
"%d len: %d cachePnt: %d max_to_fetch: %d descleft: %d\n",
|
|
|
|
descHead(), descTail(), descLen(), cachePnt,
|
|
|
|
max_to_fetch, descLeft());
|
|
|
|
|
|
|
|
// Nothing to do
|
|
|
|
if (max_to_fetch == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// So we don't have two descriptor fetches going on at once
|
|
|
|
curFetching = max_to_fetch;
|
|
|
|
|
|
|
|
assert(!fetchDelayEvent.scheduled());
|
|
|
|
igbe->schedule(fetchDelayEvent, curTick + igbe->fetchDelay);
|
|
|
|
igbe->anBegin(annSmFetch, "Prepare Fetch Desc");
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
IGbE::DescCache<T>::fetchDescriptors1()
|
|
|
|
{
|
|
|
|
// If we're draining delay issuing this DMA
|
|
|
|
if (igbe->getState() != SimObject::Running) {
|
|
|
|
igbe->schedule(fetchDelayEvent, curTick + igbe->fetchDelay);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
igbe->anBegin(annSmFetch, "Fetch Desc");
|
|
|
|
|
|
|
|
DPRINTF(EthernetDesc, "Fetching descriptors at %#x (%#x), size: %#x\n",
|
|
|
|
descBase() + cachePnt * sizeof(T),
|
|
|
|
pciToDma(descBase() + cachePnt * sizeof(T)),
|
|
|
|
curFetching * sizeof(T));
|
|
|
|
assert(curFetching);
|
|
|
|
igbe->dmaRead(pciToDma(descBase() + cachePnt * sizeof(T)),
|
|
|
|
curFetching * sizeof(T), &fetchEvent, (uint8_t*)fetchBuf,
|
|
|
|
igbe->fetchCompDelay);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
IGbE::DescCache<T>::fetchComplete()
|
|
|
|
{
|
|
|
|
T *newDesc;
|
|
|
|
igbe->anBegin(annSmFetch, "Fetch Complete");
|
|
|
|
for (int x = 0; x < curFetching; x++) {
|
|
|
|
newDesc = new T;
|
|
|
|
memcpy(newDesc, &fetchBuf[x], sizeof(T));
|
|
|
|
unusedCache.push_back(newDesc);
|
|
|
|
igbe->anDq(annSmFetch, annUnusedDescQ);
|
|
|
|
igbe->anQ(annSmFetch, annUnusedCacheQ);
|
|
|
|
igbe->anQ(annSmFetch, annDescQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
int oldCp = cachePnt;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
cachePnt += curFetching;
|
|
|
|
assert(cachePnt <= descLen());
|
|
|
|
if (cachePnt == descLen())
|
|
|
|
cachePnt = 0;
|
|
|
|
|
|
|
|
curFetching = 0;
|
|
|
|
|
|
|
|
DPRINTF(EthernetDesc, "Fetching complete cachePnt %d -> %d\n",
|
|
|
|
oldCp, cachePnt);
|
|
|
|
|
|
|
|
if ((descTail() >= cachePnt ? (descTail() - cachePnt) : (descLen() -
|
|
|
|
cachePnt)) == 0)
|
|
|
|
{
|
|
|
|
igbe->anWe(annSmFetch, annUnusedDescQ);
|
|
|
|
} else if (!(size - usedCache.size() - unusedCache.size())) {
|
|
|
|
igbe->anWf(annSmFetch, annDescQ);
|
|
|
|
} else {
|
|
|
|
igbe->anBegin(annSmFetch, "Wait", CPA::FL_WAIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
enableSm();
|
|
|
|
igbe->checkDrain();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
IGbE::DescCache<T>::wbComplete()
|
|
|
|
{
|
|
|
|
|
|
|
|
igbe->anBegin(annSmWb, "Finish Writeback");
|
|
|
|
|
|
|
|
long curHead = descHead();
|
|
|
|
#ifndef NDEBUG
|
|
|
|
long oldHead = curHead;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (int x = 0; x < wbOut; x++) {
|
|
|
|
assert(usedCache.size());
|
|
|
|
delete usedCache[0];
|
|
|
|
usedCache.pop_front();
|
|
|
|
|
|
|
|
igbe->anDq(annSmWb, annUsedCacheQ);
|
|
|
|
igbe->anDq(annSmWb, annDescQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
curHead += wbOut;
|
|
|
|
wbOut = 0;
|
|
|
|
|
|
|
|
if (curHead >= descLen())
|
|
|
|
curHead -= descLen();
|
|
|
|
|
|
|
|
// Update the head
|
|
|
|
updateHead(curHead);
|
|
|
|
|
|
|
|
DPRINTF(EthernetDesc, "Writeback complete curHead %d -> %d\n",
|
|
|
|
oldHead, curHead);
|
|
|
|
|
|
|
|
// If we still have more to wb, call wb now
|
|
|
|
actionAfterWb();
|
|
|
|
if (moreToWb) {
|
|
|
|
moreToWb = false;
|
|
|
|
DPRINTF(EthernetDesc, "Writeback has more todo\n");
|
|
|
|
writeback(wbAlignment);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wbOut) {
|
|
|
|
igbe->checkDrain();
|
|
|
|
if (usedCache.size())
|
|
|
|
igbe->anBegin(annSmWb, "Wait", CPA::FL_WAIT);
|
|
|
|
else
|
|
|
|
igbe->anWe(annSmWb, annUsedCacheQ);
|
|
|
|
}
|
|
|
|
fetchAfterWb();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
IGbE::DescCache<T>::reset()
|
|
|
|
{
|
|
|
|
DPRINTF(EthernetDesc, "Reseting descriptor cache\n");
|
2009-06-05 20:40:02 +02:00
|
|
|
for (typename CacheType::size_type x = 0; x < usedCache.size(); x++)
|
2009-04-22 07:58:53 +02:00
|
|
|
delete usedCache[x];
|
2009-06-05 20:40:02 +02:00
|
|
|
for (typename CacheType::size_type x = 0; x < unusedCache.size(); x++)
|
2009-04-22 07:58:53 +02:00
|
|
|
delete unusedCache[x];
|
|
|
|
|
|
|
|
usedCache.clear();
|
|
|
|
unusedCache.clear();
|
|
|
|
|
|
|
|
cachePnt = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
IGbE::DescCache<T>::serialize(std::ostream &os)
|
|
|
|
{
|
|
|
|
SERIALIZE_SCALAR(cachePnt);
|
|
|
|
SERIALIZE_SCALAR(curFetching);
|
|
|
|
SERIALIZE_SCALAR(wbOut);
|
|
|
|
SERIALIZE_SCALAR(moreToWb);
|
|
|
|
SERIALIZE_SCALAR(wbAlignment);
|
|
|
|
|
2009-06-05 20:40:02 +02:00
|
|
|
typename CacheType::size_type usedCacheSize = usedCache.size();
|
2009-04-22 07:58:53 +02:00
|
|
|
SERIALIZE_SCALAR(usedCacheSize);
|
2009-06-05 20:40:02 +02:00
|
|
|
for (typename CacheType::size_type x = 0; x < usedCacheSize; x++) {
|
2009-04-22 07:58:53 +02:00
|
|
|
arrayParamOut(os, csprintf("usedCache_%d", x),
|
|
|
|
(uint8_t*)usedCache[x],sizeof(T));
|
|
|
|
}
|
|
|
|
|
2009-06-05 20:40:02 +02:00
|
|
|
typename CacheType::size_type unusedCacheSize = unusedCache.size();
|
2009-04-22 07:58:53 +02:00
|
|
|
SERIALIZE_SCALAR(unusedCacheSize);
|
2009-06-05 20:40:02 +02:00
|
|
|
for (typename CacheType::size_type x = 0; x < unusedCacheSize; x++) {
|
2009-04-22 07:58:53 +02:00
|
|
|
arrayParamOut(os, csprintf("unusedCache_%d", x),
|
|
|
|
(uint8_t*)unusedCache[x],sizeof(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
Tick fetch_delay = 0, wb_delay = 0;
|
|
|
|
if (fetchDelayEvent.scheduled())
|
|
|
|
fetch_delay = fetchDelayEvent.when();
|
|
|
|
SERIALIZE_SCALAR(fetch_delay);
|
|
|
|
if (wbDelayEvent.scheduled())
|
|
|
|
wb_delay = wbDelayEvent.when();
|
|
|
|
SERIALIZE_SCALAR(wb_delay);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
IGbE::DescCache<T>::unserialize(Checkpoint *cp, const std::string §ion)
|
|
|
|
{
|
|
|
|
UNSERIALIZE_SCALAR(cachePnt);
|
|
|
|
UNSERIALIZE_SCALAR(curFetching);
|
|
|
|
UNSERIALIZE_SCALAR(wbOut);
|
|
|
|
UNSERIALIZE_SCALAR(moreToWb);
|
|
|
|
UNSERIALIZE_SCALAR(wbAlignment);
|
|
|
|
|
2009-06-05 20:40:02 +02:00
|
|
|
typename CacheType::size_type usedCacheSize;
|
2009-04-22 07:58:53 +02:00
|
|
|
UNSERIALIZE_SCALAR(usedCacheSize);
|
|
|
|
T *temp;
|
2009-06-05 20:40:02 +02:00
|
|
|
for (typename CacheType::size_type x = 0; x < usedCacheSize; x++) {
|
2009-04-22 07:58:53 +02:00
|
|
|
temp = new T;
|
|
|
|
arrayParamIn(cp, section, csprintf("usedCache_%d", x),
|
|
|
|
(uint8_t*)temp,sizeof(T));
|
|
|
|
usedCache.push_back(temp);
|
|
|
|
}
|
|
|
|
|
2009-06-05 20:40:02 +02:00
|
|
|
typename CacheType::size_type unusedCacheSize;
|
2009-04-22 07:58:53 +02:00
|
|
|
UNSERIALIZE_SCALAR(unusedCacheSize);
|
2009-06-05 20:40:02 +02:00
|
|
|
for (typename CacheType::size_type x = 0; x < unusedCacheSize; x++) {
|
2009-04-22 07:58:53 +02:00
|
|
|
temp = new T;
|
|
|
|
arrayParamIn(cp, section, csprintf("unusedCache_%d", x),
|
|
|
|
(uint8_t*)temp,sizeof(T));
|
|
|
|
unusedCache.push_back(temp);
|
|
|
|
}
|
|
|
|
Tick fetch_delay = 0, wb_delay = 0;
|
|
|
|
UNSERIALIZE_SCALAR(fetch_delay);
|
|
|
|
UNSERIALIZE_SCALAR(wb_delay);
|
|
|
|
if (fetch_delay)
|
|
|
|
igbe->schedule(fetchDelayEvent, fetch_delay);
|
|
|
|
if (wb_delay)
|
|
|
|
igbe->schedule(wbDelayEvent, wb_delay);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////// IGbE::RxDescCache //////////////////////////////
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
IGbE::RxDescCache::RxDescCache(IGbE *i, const std::string n, int s)
|
2009-01-06 16:36:57 +01:00
|
|
|
: DescCache<RxDesc>(i, n, s), pktDone(false), splitCount(0),
|
|
|
|
pktEvent(this), pktHdrEvent(this), pktDataEvent(this)
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
{
|
2009-02-27 01:29:17 +01:00
|
|
|
annSmFetch = "RX Desc Fetch";
|
|
|
|
annSmWb = "RX Desc Writeback";
|
|
|
|
annUnusedDescQ = "RX Unused Descriptors";
|
|
|
|
annUnusedCacheQ = "RX Unused Descriptor Cache";
|
|
|
|
annUsedCacheQ = "RX Used Descriptor Cache";
|
|
|
|
annUsedDescQ = "RX Used Descriptors";
|
|
|
|
annDescQ = "RX Descriptors";
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
2006-09-19 02:12:45 +02:00
|
|
|
|
2008-02-11 01:32:12 +01:00
|
|
|
void
|
2009-01-06 16:36:57 +01:00
|
|
|
IGbE::RxDescCache::pktSplitDone()
|
|
|
|
{
|
|
|
|
splitCount++;
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc,
|
|
|
|
"Part of split packet done: splitcount now %d\n", splitCount);
|
2009-01-06 16:36:57 +01:00
|
|
|
assert(splitCount <= 2);
|
|
|
|
if (splitCount != 2)
|
|
|
|
return;
|
|
|
|
splitCount = 0;
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc,
|
|
|
|
"Part of split packet done: calling pktComplete()\n");
|
2009-01-06 16:36:57 +01:00
|
|
|
pktComplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
IGbE::RxDescCache::writePacket(EthPacketPtr packet, int pkt_offset)
|
2006-09-19 02:12:45 +02:00
|
|
|
{
|
2009-04-22 07:58:53 +02:00
|
|
|
assert(unusedCache.size());
|
2007-09-12 21:24:23 +02:00
|
|
|
//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;
|
2009-06-05 08:21:12 +02:00
|
|
|
unsigned buf_len, hdr_len;
|
2008-12-05 19:58:22 +01:00
|
|
|
|
|
|
|
RxDesc *desc = unusedCache.front();
|
|
|
|
switch (igbe->regs.srrctl.desctype()) {
|
|
|
|
case RXDT_LEGACY:
|
2009-01-06 16:36:57 +01:00
|
|
|
assert(pkt_offset == 0);
|
|
|
|
bytesCopied = packet->length;
|
2008-12-05 19:58:22 +01:00
|
|
|
DPRINTF(EthernetDesc, "Packet Length: %d Desc Size: %d\n",
|
2009-04-22 07:58:53 +02:00
|
|
|
packet->length, igbe->regs.rctl.descSize());
|
2008-12-05 19:58:22 +01:00
|
|
|
assert(packet->length < igbe->regs.rctl.descSize());
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->dmaWrite(pciToDma(desc->legacy.buf),
|
|
|
|
packet->length, &pktEvent, packet->data,
|
|
|
|
igbe->rxWriteDelay);
|
2008-12-05 19:58:22 +01:00
|
|
|
break;
|
|
|
|
case RXDT_ADV_ONEBUF:
|
2009-01-06 16:36:57 +01:00
|
|
|
assert(pkt_offset == 0);
|
|
|
|
bytesCopied = packet->length;
|
2008-12-05 19:58:22 +01:00
|
|
|
buf_len = igbe->regs.rctl.lpe() ? igbe->regs.srrctl.bufLen() :
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->regs.rctl.descSize();
|
2008-12-05 19:58:22 +01:00
|
|
|
DPRINTF(EthernetDesc, "Packet Length: %d srrctl: %#x Desc Size: %d\n",
|
2009-04-22 07:58:53 +02:00
|
|
|
packet->length, igbe->regs.srrctl(), buf_len);
|
2008-12-05 19:58:22 +01:00
|
|
|
assert(packet->length < buf_len);
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->dmaWrite(pciToDma(desc->adv_read.pkt),
|
|
|
|
packet->length, &pktEvent, packet->data,
|
|
|
|
igbe->rxWriteDelay);
|
2009-01-06 16:36:57 +01:00
|
|
|
desc->adv_wb.header_len = htole(0);
|
|
|
|
desc->adv_wb.sph = htole(0);
|
|
|
|
desc->adv_wb.pkt_len = htole((uint16_t)(pktPtr->length));
|
|
|
|
break;
|
|
|
|
case RXDT_ADV_SPLIT_A:
|
|
|
|
int split_point;
|
|
|
|
|
|
|
|
buf_len = igbe->regs.rctl.lpe() ? igbe->regs.srrctl.bufLen() :
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->regs.rctl.descSize();
|
2009-01-06 16:36:57 +01:00
|
|
|
hdr_len = igbe->regs.rctl.lpe() ? igbe->regs.srrctl.hdrLen() : 0;
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc,
|
|
|
|
"lpe: %d Packet Length: %d offset: %d srrctl: %#x "
|
|
|
|
"hdr addr: %#x Hdr Size: %d desc addr: %#x Desc Size: %d\n",
|
|
|
|
igbe->regs.rctl.lpe(), packet->length, pkt_offset,
|
|
|
|
igbe->regs.srrctl(), desc->adv_read.hdr, hdr_len,
|
|
|
|
desc->adv_read.pkt, buf_len);
|
2009-01-06 16:36:57 +01:00
|
|
|
|
|
|
|
split_point = hsplit(pktPtr);
|
|
|
|
|
|
|
|
if (packet->length <= hdr_len) {
|
|
|
|
bytesCopied = packet->length;
|
|
|
|
assert(pkt_offset == 0);
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc, "Hdr split: Entire packet in header\n");
|
|
|
|
igbe->dmaWrite(pciToDma(desc->adv_read.hdr),
|
|
|
|
packet->length, &pktEvent, packet->data,
|
|
|
|
igbe->rxWriteDelay);
|
2009-01-06 16:36:57 +01:00
|
|
|
desc->adv_wb.header_len = htole((uint16_t)packet->length);
|
|
|
|
desc->adv_wb.sph = htole(0);
|
|
|
|
desc->adv_wb.pkt_len = htole(0);
|
|
|
|
} else if (split_point) {
|
|
|
|
if (pkt_offset) {
|
|
|
|
// we are only copying some data, header/data has already been
|
|
|
|
// copied
|
2009-04-22 07:58:53 +02:00
|
|
|
int max_to_copy =
|
|
|
|
std::min(packet->length - pkt_offset, buf_len);
|
2009-01-06 16:36:57 +01:00
|
|
|
bytesCopied += max_to_copy;
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc,
|
|
|
|
"Hdr split: Continuing data buffer copy\n");
|
|
|
|
igbe->dmaWrite(pciToDma(desc->adv_read.pkt),
|
|
|
|
max_to_copy, &pktEvent,
|
|
|
|
packet->data + pkt_offset, igbe->rxWriteDelay);
|
2009-01-06 16:36:57 +01:00
|
|
|
desc->adv_wb.header_len = htole(0);
|
|
|
|
desc->adv_wb.pkt_len = htole((uint16_t)max_to_copy);
|
|
|
|
desc->adv_wb.sph = htole(0);
|
|
|
|
} else {
|
2009-04-22 07:58:53 +02:00
|
|
|
int max_to_copy =
|
|
|
|
std::min(packet->length - split_point, buf_len);
|
2009-01-06 16:36:57 +01:00
|
|
|
bytesCopied += max_to_copy + split_point;
|
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc, "Hdr split: splitting at %d\n",
|
2009-01-06 16:36:57 +01:00
|
|
|
split_point);
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->dmaWrite(pciToDma(desc->adv_read.hdr),
|
|
|
|
split_point, &pktHdrEvent,
|
|
|
|
packet->data, igbe->rxWriteDelay);
|
|
|
|
igbe->dmaWrite(pciToDma(desc->adv_read.pkt),
|
|
|
|
max_to_copy, &pktDataEvent,
|
|
|
|
packet->data + split_point, igbe->rxWriteDelay);
|
2009-01-06 16:36:57 +01:00
|
|
|
desc->adv_wb.header_len = htole(split_point);
|
|
|
|
desc->adv_wb.sph = 1;
|
|
|
|
desc->adv_wb.pkt_len = htole((uint16_t)(max_to_copy));
|
|
|
|
}
|
|
|
|
} else {
|
2009-04-22 07:58:53 +02:00
|
|
|
panic("Header split not fitting within header buffer or "
|
|
|
|
"undecodable packet not fitting in header unsupported\n");
|
2009-01-06 16:36:57 +01:00
|
|
|
}
|
2008-12-05 19:58:22 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("Unimplemnted RX receive buffer type: %d\n",
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->regs.srrctl.desctype());
|
2008-12-05 19:58:22 +01:00
|
|
|
}
|
2009-01-06 16:36:57 +01:00
|
|
|
return bytesCopied;
|
2008-12-05 19:58:22 +01:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::RxDescCache::pktComplete()
|
|
|
|
{
|
|
|
|
assert(unusedCache.size());
|
|
|
|
RxDesc *desc;
|
|
|
|
desc = unusedCache.front();
|
|
|
|
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anBegin("RXS", "Update Desc");
|
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
uint16_t crcfixup = igbe->regs.rctl.secrc() ? 0 : 4 ;
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc, "pktPtr->length: %d bytesCopied: %d "
|
|
|
|
"stripcrc offset: %d value written: %d %d\n",
|
2009-01-06 16:36:57 +01:00
|
|
|
pktPtr->length, bytesCopied, crcfixup,
|
2007-03-27 00:40:18 +02:00
|
|
|
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
|
|
|
|
2009-01-06 16:36:57 +01:00
|
|
|
uint16_t status = RXDS_DD;
|
2007-03-22 23:39:41 +01:00
|
|
|
uint8_t err = 0;
|
2008-12-05 19:58:22 +01:00
|
|
|
uint16_t ext_err = 0;
|
|
|
|
uint16_t csum = 0;
|
|
|
|
uint16_t ptype = 0;
|
|
|
|
uint16_t ip_id = 0;
|
2007-05-14 22:37:00 +02:00
|
|
|
|
2009-01-06 16:36:57 +01:00
|
|
|
assert(bytesCopied <= pktPtr->length);
|
|
|
|
if (bytesCopied == pktPtr->length)
|
|
|
|
status |= RXDS_EOP;
|
|
|
|
|
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());
|
2008-12-05 19:58:22 +01:00
|
|
|
ptype |= RXDP_IPV4;
|
|
|
|
ip_id = ip->id();
|
2007-05-14 22:37:00 +02:00
|
|
|
|
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;
|
2008-12-05 19:58:22 +01:00
|
|
|
csum = htole(cksum(ip));
|
2008-06-18 07:22:44 +02:00
|
|
|
igbe->rxIpChecksums++;
|
2007-03-22 23:39:41 +01:00
|
|
|
if (cksum(ip) != 0) {
|
|
|
|
err |= RXDE_IPE;
|
2008-12-05 19:58:22 +01:00
|
|
|
ext_err |= RXDEE_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;
|
2008-12-05 19:58:22 +01:00
|
|
|
ptype |= RXDP_TCP;
|
|
|
|
csum = htole(cksum(tcp));
|
2008-06-18 07:22:44 +02:00
|
|
|
igbe->rxTcpChecksums++;
|
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;
|
2008-12-05 19:58:22 +01:00
|
|
|
ext_err |= RXDEE_TCPE;
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2008-12-05 19:58:22 +01:00
|
|
|
ptype |= RXDP_UDP;
|
|
|
|
csum = htole(cksum(udp));
|
2008-06-18 07:22:44 +02:00
|
|
|
igbe->rxUdpChecksums++;
|
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");
|
2008-12-05 19:58:22 +01:00
|
|
|
ext_err |= RXDEE_TCPE;
|
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");
|
|
|
|
}
|
|
|
|
|
2008-12-05 19:58:22 +01:00
|
|
|
switch (igbe->regs.srrctl.desctype()) {
|
|
|
|
case RXDT_LEGACY:
|
|
|
|
desc->legacy.len = htole((uint16_t)(pktPtr->length + crcfixup));
|
|
|
|
desc->legacy.status = htole(status);
|
|
|
|
desc->legacy.errors = htole(err);
|
|
|
|
// No vlan support at this point... just set it to 0
|
|
|
|
desc->legacy.vlan = 0;
|
|
|
|
break;
|
2009-01-06 16:36:57 +01:00
|
|
|
case RXDT_ADV_SPLIT_A:
|
2008-12-05 19:58:22 +01:00
|
|
|
case RXDT_ADV_ONEBUF:
|
|
|
|
desc->adv_wb.rss_type = htole(0);
|
|
|
|
desc->adv_wb.pkt_type = htole(ptype);
|
|
|
|
if (igbe->regs.rxcsum.pcsd()) {
|
|
|
|
// no rss support right now
|
|
|
|
desc->adv_wb.rss_hash = htole(0);
|
|
|
|
} else {
|
|
|
|
desc->adv_wb.id = htole(ip_id);
|
|
|
|
desc->adv_wb.csum = htole(csum);
|
|
|
|
}
|
|
|
|
desc->adv_wb.status = htole(status);
|
|
|
|
desc->adv_wb.errors = htole(ext_err);
|
|
|
|
// no vlan support
|
|
|
|
desc->adv_wb.vlan_tag = htole(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("Unimplemnted RX receive buffer type %d\n",
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->regs.srrctl.desctype());
|
2008-12-05 19:58:22 +01:00
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2009-01-06 16:36:57 +01:00
|
|
|
DPRINTF(EthernetDesc, "Descriptor complete w0: %#x w1: %#x\n",
|
|
|
|
desc->adv_read.pkt, desc->adv_read.hdr);
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2009-01-06 16:36:57 +01:00
|
|
|
if (bytesCopied == pktPtr->length) {
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc,
|
|
|
|
"Packet completely written to descriptor buffers\n");
|
2009-01-06 16:36:57 +01:00
|
|
|
// Deal with the rx timer interrupts
|
|
|
|
if (igbe->regs.rdtr.delay()) {
|
2009-04-22 07:58:53 +02:00
|
|
|
Tick delay = igbe->regs.rdtr.delay() * igbe->intClock();
|
|
|
|
DPRINTF(EthernetSM, "RXS: Scheduling DTR for %d\n", delay);
|
|
|
|
igbe->reschedule(igbe->rdtrEvent, curTick + delay);
|
2009-01-06 16:36:57 +01:00
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2009-01-06 16:36:57 +01:00
|
|
|
if (igbe->regs.radv.idv()) {
|
2009-04-22 07:58:53 +02:00
|
|
|
Tick delay = igbe->regs.radv.idv() * igbe->intClock();
|
|
|
|
DPRINTF(EthernetSM, "RXS: Scheduling ADV for %d\n", delay);
|
2009-01-06 16:36:57 +01:00
|
|
|
if (!igbe->radvEvent.scheduled()) {
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->schedule(igbe->radvEvent, curTick + delay);
|
2009-01-06 16:36:57 +01:00
|
|
|
}
|
2007-08-27 06:45:40 +02:00
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2009-01-06 16:36:57 +01:00
|
|
|
// if neither radv or rdtr, maybe itr is set...
|
|
|
|
if (!igbe->regs.rdtr.delay() && !igbe->regs.radv.idv()) {
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetSM,
|
|
|
|
"RXS: Receive interrupt delay disabled, posting IT_RXT\n");
|
2009-01-06 16:36:57 +01:00
|
|
|
igbe->postInterrupt(IT_RXT);
|
|
|
|
}
|
2007-03-27 00:40:18 +02:00
|
|
|
|
2009-01-06 16:36:57 +01:00
|
|
|
// If the packet is small enough, interrupt appropriately
|
|
|
|
// I wonder if this is delayed or not?!
|
|
|
|
if (pktPtr->length <= igbe->regs.rsrpd.idv()) {
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetSM,
|
|
|
|
"RXS: Posting IT_SRPD beacuse small packet received\n");
|
2009-01-06 16:36:57 +01:00
|
|
|
igbe->postInterrupt(IT_SRPD);
|
|
|
|
}
|
|
|
|
bytesCopied = 0;
|
2007-03-28 02:44:21 +02:00
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
pktPtr = NULL;
|
2009-01-06 16:36:57 +01:00
|
|
|
igbe->checkDrain();
|
2007-03-22 23:39:41 +01:00
|
|
|
enableSm();
|
|
|
|
pktDone = true;
|
2007-08-27 06:45:40 +02:00
|
|
|
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anBegin("RXS", "Done Updating Desc");
|
2009-01-06 16:36:57 +01:00
|
|
|
DPRINTF(EthernetDesc, "Processing of this descriptor complete\n");
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anDq("RXS", annUnusedCacheQ);
|
2009-01-06 16:36:57 +01:00
|
|
|
unusedCache.pop_front();
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anQ("RXS", annUsedCacheQ);
|
2009-01-06 16:36:57 +01:00
|
|
|
usedCache.push_back(desc);
|
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() ||
|
2009-01-06 16:36:57 +01:00
|
|
|
fetchEvent.scheduled() || pktHdrEvent.scheduled() ||
|
|
|
|
pktDataEvent.scheduled();
|
|
|
|
|
2007-03-30 04:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::RxDescCache::serialize(std::ostream &os)
|
|
|
|
{
|
|
|
|
DescCache<RxDesc>::serialize(os);
|
|
|
|
SERIALIZE_SCALAR(pktDone);
|
2009-01-06 16:36:57 +01:00
|
|
|
SERIALIZE_SCALAR(splitCount);
|
|
|
|
SERIALIZE_SCALAR(bytesCopied);
|
2007-03-30 04:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::RxDescCache::unserialize(Checkpoint *cp, const std::string §ion)
|
|
|
|
{
|
|
|
|
DescCache<RxDesc>::unserialize(cp, section);
|
|
|
|
UNSERIALIZE_SCALAR(pktDone);
|
2009-01-06 16:36:57 +01:00
|
|
|
UNSERIALIZE_SCALAR(splitCount);
|
|
|
|
UNSERIALIZE_SCALAR(bytesCopied);
|
2007-03-30 04:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
///////////////////////////// IGbE::TxDescCache //////////////////////////////
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
IGbE::TxDescCache::TxDescCache(IGbE *i, const std::string n, int s)
|
2009-04-22 07:58:53 +02:00
|
|
|
: DescCache<TxDesc>(i,n, s), pktDone(false), isTcp(false),
|
|
|
|
pktWaiting(false), completionAddress(0), completionEnabled(false),
|
|
|
|
useTso(false), pktEvent(this), headerEvent(this), nullEvent(this)
|
2007-03-22 23:39:41 +01:00
|
|
|
{
|
2009-02-27 01:29:17 +01:00
|
|
|
annSmFetch = "TX Desc Fetch";
|
|
|
|
annSmWb = "TX Desc Writeback";
|
|
|
|
annUnusedDescQ = "TX Unused Descriptors";
|
|
|
|
annUnusedCacheQ = "TX Unused Descriptor Cache";
|
|
|
|
annUsedCacheQ = "TX Used Descriptor Cache";
|
|
|
|
annUsedDescQ = "TX Used Descriptors";
|
|
|
|
annDescQ = "TX Descriptors";
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
2008-12-05 19:58:21 +01:00
|
|
|
void
|
|
|
|
IGbE::TxDescCache::processContextDesc()
|
2007-03-22 23:39:41 +01:00
|
|
|
{
|
|
|
|
assert(unusedCache.size());
|
|
|
|
TxDesc *desc;
|
2008-12-05 19:58:21 +01:00
|
|
|
|
|
|
|
DPRINTF(EthernetDesc, "Checking and processing context descriptors\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
while (!useTso && unusedCache.size() &&
|
|
|
|
TxdOp::isContext(unusedCache.front())) {
|
2008-12-05 19:58:21 +01:00
|
|
|
DPRINTF(EthernetDesc, "Got context descriptor type...\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
desc = unusedCache.front();
|
2008-12-05 19:58:21 +01:00
|
|
|
DPRINTF(EthernetDesc, "Descriptor upper: %#x lower: %#X\n",
|
2009-04-22 07:58:53 +02:00
|
|
|
desc->d1, desc->d2);
|
2008-12-05 19:58:21 +01:00
|
|
|
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
// is this going to be a tcp or udp packet?
|
|
|
|
isTcp = TxdOp::tcp(desc) ? true : false;
|
|
|
|
|
2008-12-05 19:58:22 +01:00
|
|
|
// setup all the TSO variables, they'll be ignored if we don't use
|
|
|
|
// tso for this connection
|
|
|
|
tsoHeaderLen = TxdOp::hdrlen(desc);
|
|
|
|
tsoMss = TxdOp::mss(desc);
|
|
|
|
|
|
|
|
if (TxdOp::isType(desc, TxdOp::TXD_CNXT) && TxdOp::tse(desc)) {
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc, "TCP offload enabled for packet hdrlen: "
|
|
|
|
"%d mss: %d paylen %d\n", TxdOp::hdrlen(desc),
|
|
|
|
TxdOp::mss(desc), TxdOp::getLen(desc));
|
2008-12-05 19:58:21 +01:00
|
|
|
useTso = true;
|
|
|
|
tsoTotalLen = TxdOp::getLen(desc);
|
|
|
|
tsoLoadedHeader = false;
|
|
|
|
tsoDescBytesUsed = 0;
|
|
|
|
tsoUsedLen = 0;
|
|
|
|
tsoPrevSeq = 0;
|
|
|
|
tsoPktHasHeader = false;
|
|
|
|
tsoPkts = 0;
|
2008-12-05 19:58:22 +01:00
|
|
|
|
2008-12-05 19:58:21 +01:00
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
TxdOp::setDd(desc);
|
|
|
|
unusedCache.pop_front();
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anDq("TXS", annUnusedCacheQ);
|
2007-03-22 23:39:41 +01:00
|
|
|
usedCache.push_back(desc);
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anQ("TXS", annUsedCacheQ);
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
2008-12-05 19:58:21 +01:00
|
|
|
if (!unusedCache.size())
|
|
|
|
return;
|
|
|
|
|
2008-12-05 19:58:22 +01:00
|
|
|
desc = unusedCache.front();
|
2009-04-22 07:58:53 +02:00
|
|
|
if (!useTso && TxdOp::isType(desc, TxdOp::TXD_ADVDATA) &&
|
|
|
|
TxdOp::tse(desc)) {
|
|
|
|
DPRINTF(EthernetDesc, "TCP offload(adv) enabled for packet "
|
|
|
|
"hdrlen: %d mss: %d paylen %d\n",
|
2008-12-05 19:58:22 +01:00
|
|
|
tsoHeaderLen, tsoMss, TxdOp::getTsoLen(desc));
|
|
|
|
useTso = true;
|
|
|
|
tsoTotalLen = TxdOp::getTsoLen(desc);
|
|
|
|
tsoLoadedHeader = false;
|
|
|
|
tsoDescBytesUsed = 0;
|
|
|
|
tsoUsedLen = 0;
|
|
|
|
tsoPrevSeq = 0;
|
|
|
|
tsoPktHasHeader = false;
|
|
|
|
tsoPkts = 0;
|
|
|
|
}
|
|
|
|
|
2008-12-05 19:58:21 +01:00
|
|
|
if (useTso && !tsoLoadedHeader) {
|
|
|
|
// we need to fetch a header
|
|
|
|
DPRINTF(EthernetDesc, "Starting DMA of TSO header\n");
|
|
|
|
assert(TxdOp::isData(desc) && TxdOp::getLen(desc) >= tsoHeaderLen);
|
|
|
|
pktWaiting = true;
|
|
|
|
assert(tsoHeaderLen <= 256);
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->dmaRead(pciToDma(TxdOp::getBuf(desc)),
|
|
|
|
tsoHeaderLen, &headerEvent, tsoHeader, 0);
|
2008-12-05 19:58:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::TxDescCache::headerComplete()
|
|
|
|
{
|
|
|
|
DPRINTF(EthernetDesc, "TSO: Fetching TSO header complete\n");
|
|
|
|
pktWaiting = false;
|
|
|
|
|
|
|
|
assert(unusedCache.size());
|
|
|
|
TxDesc *desc = unusedCache.front();
|
|
|
|
DPRINTF(EthernetDesc, "TSO: len: %d tsoHeaderLen: %d\n",
|
|
|
|
TxdOp::getLen(desc), tsoHeaderLen);
|
|
|
|
|
|
|
|
if (TxdOp::getLen(desc) == tsoHeaderLen) {
|
|
|
|
tsoDescBytesUsed = 0;
|
|
|
|
tsoLoadedHeader = true;
|
|
|
|
unusedCache.pop_front();
|
|
|
|
usedCache.push_back(desc);
|
|
|
|
} else {
|
|
|
|
// I don't think this case happens, I think the headrer is always
|
|
|
|
// it's own packet, if it wasn't it might be as simple as just
|
|
|
|
// incrementing descBytesUsed by the header length, but I'm not
|
|
|
|
// completely sure
|
|
|
|
panic("TSO header part of bigger packet, not implemented\n");
|
|
|
|
}
|
|
|
|
enableSm();
|
|
|
|
igbe->checkDrain();
|
|
|
|
}
|
|
|
|
|
2009-06-05 08:21:12 +02:00
|
|
|
unsigned
|
2008-12-05 19:58:21 +01:00
|
|
|
IGbE::TxDescCache::getPacketSize(EthPacketPtr p)
|
|
|
|
{
|
2007-03-22 23:39:41 +01:00
|
|
|
if (!unusedCache.size())
|
2009-06-05 08:21:12 +02:00
|
|
|
return 0;
|
2008-12-05 19:58:21 +01:00
|
|
|
|
|
|
|
DPRINTF(EthernetDesc, "Starting processing of descriptor\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2008-12-05 19:58:21 +01:00
|
|
|
assert(!useTso || tsoLoadedHeader);
|
2009-06-05 08:21:12 +02:00
|
|
|
TxDesc *desc = unusedCache.front();
|
2008-12-05 19:58:21 +01:00
|
|
|
|
|
|
|
if (useTso) {
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc, "getPacket(): TxDescriptor data "
|
|
|
|
"d1: %#llx d2: %#llx\n", desc->d1, desc->d2);
|
|
|
|
DPRINTF(EthernetDesc, "TSO: use: %d hdrlen: %d mss: %d total: %d "
|
|
|
|
"used: %d loaded hdr: %d\n", useTso, tsoHeaderLen, tsoMss,
|
|
|
|
tsoTotalLen, tsoUsedLen, tsoLoadedHeader);
|
|
|
|
DPRINTF(EthernetDesc, "TSO: descBytesUsed: %d copyBytes: %d "
|
|
|
|
"this descLen: %d\n",
|
2008-12-05 19:58:21 +01:00
|
|
|
tsoDescBytesUsed, tsoCopyBytes, TxdOp::getLen(desc));
|
|
|
|
DPRINTF(EthernetDesc, "TSO: pktHasHeader: %d\n", tsoPktHasHeader);
|
|
|
|
|
|
|
|
if (tsoPktHasHeader)
|
2009-04-22 07:58:53 +02:00
|
|
|
tsoCopyBytes = std::min((tsoMss + tsoHeaderLen) - p->length,
|
|
|
|
TxdOp::getLen(desc) - tsoDescBytesUsed);
|
2008-12-05 19:58:21 +01:00
|
|
|
else
|
2009-04-22 07:58:53 +02:00
|
|
|
tsoCopyBytes = std::min(tsoMss,
|
|
|
|
TxdOp::getLen(desc) - tsoDescBytesUsed);
|
2009-06-05 08:21:12 +02:00
|
|
|
unsigned pkt_size =
|
|
|
|
tsoCopyBytes + (tsoPktHasHeader ? 0 : tsoHeaderLen);
|
2008-12-05 19:58:21 +01:00
|
|
|
DPRINTF(EthernetDesc, "TSO: Next packet is %d bytes\n", pkt_size);
|
|
|
|
return pkt_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(EthernetDesc, "Next TX packet is %d bytes\n",
|
2009-04-22 07:58:53 +02:00
|
|
|
TxdOp::getLen(unusedCache.front()));
|
2008-12-05 19:58:21 +01:00
|
|
|
return TxdOp::getLen(desc);
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::TxDescCache::getPacketData(EthPacketPtr p)
|
|
|
|
{
|
|
|
|
assert(unusedCache.size());
|
|
|
|
|
|
|
|
TxDesc *desc;
|
|
|
|
desc = unusedCache.front();
|
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc, "getPacketData(): TxDescriptor data "
|
|
|
|
"d1: %#llx d2: %#llx\n", desc->d1, desc->d2);
|
|
|
|
assert((TxdOp::isLegacy(desc) || TxdOp::isData(desc)) &&
|
|
|
|
TxdOp::getLen(desc));
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
pktPtr = p;
|
|
|
|
|
|
|
|
pktWaiting = true;
|
|
|
|
|
2008-05-20 22:06:56 +02:00
|
|
|
DPRINTF(EthernetDesc, "Starting DMA of packet at offset %d\n", p->length);
|
2008-12-05 19:58:21 +01:00
|
|
|
|
|
|
|
if (useTso) {
|
|
|
|
assert(tsoLoadedHeader);
|
|
|
|
if (!tsoPktHasHeader) {
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc,
|
|
|
|
"Loading TSO header (%d bytes) into start of packet\n",
|
|
|
|
tsoHeaderLen);
|
2008-12-05 19:58:21 +01:00
|
|
|
memcpy(p->data, &tsoHeader,tsoHeaderLen);
|
|
|
|
p->length +=tsoHeaderLen;
|
|
|
|
tsoPktHasHeader = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useTso) {
|
|
|
|
tsoDescBytesUsed += tsoCopyBytes;
|
|
|
|
assert(tsoDescBytesUsed <= TxdOp::getLen(desc));
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc,
|
|
|
|
"Starting DMA of packet at offset %d length: %d\n",
|
2008-12-05 19:58:21 +01:00
|
|
|
p->length, tsoCopyBytes);
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->dmaRead(pciToDma(TxdOp::getBuf(desc))
|
|
|
|
+ tsoDescBytesUsed,
|
|
|
|
tsoCopyBytes, &pktEvent, p->data + p->length,
|
|
|
|
igbe->txReadDelay);
|
2008-12-05 19:58:21 +01:00
|
|
|
} else {
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->dmaRead(pciToDma(TxdOp::getBuf(desc)),
|
|
|
|
TxdOp::getLen(desc), &pktEvent, p->data + p->length,
|
|
|
|
igbe->txReadDelay);
|
2008-12-05 19:58:21 +01:00
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::TxDescCache::pktComplete()
|
|
|
|
{
|
|
|
|
|
|
|
|
TxDesc *desc;
|
|
|
|
assert(unusedCache.size());
|
|
|
|
assert(pktPtr);
|
|
|
|
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anBegin("TXS", "Update Desc");
|
|
|
|
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "DMA of packet complete\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2008-02-11 01:32:12 +01:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
desc = unusedCache.front();
|
2009-04-22 07:58:53 +02:00
|
|
|
assert((TxdOp::isLegacy(desc) || TxdOp::isData(desc)) &&
|
|
|
|
TxdOp::getLen(desc));
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc, "TxDescriptor data d1: %#llx d2: %#llx\n",
|
|
|
|
desc->d1, desc->d2);
|
|
|
|
DPRINTF(EthernetDesc, "TSO: use: %d hdrlen: %d mss: %d total: %d "
|
|
|
|
"used: %d loaded hdr: %d\n", useTso, tsoHeaderLen, tsoMss,
|
|
|
|
tsoTotalLen, tsoUsedLen, tsoLoadedHeader);
|
2007-03-27 00:40:18 +02:00
|
|
|
|
2008-12-05 19:58:21 +01:00
|
|
|
// Set the length of the data in the EtherPacket
|
|
|
|
if (useTso) {
|
|
|
|
pktPtr->length += tsoCopyBytes;
|
|
|
|
tsoUsedLen += tsoCopyBytes;
|
|
|
|
} else
|
2008-05-20 22:06:56 +02:00
|
|
|
pktPtr->length += TxdOp::getLen(desc);
|
2008-12-05 19:58:21 +01:00
|
|
|
|
|
|
|
DPRINTF(EthernetDesc, "TSO: descBytesUsed: %d copyBytes: %d\n",
|
|
|
|
tsoDescBytesUsed, tsoCopyBytes);
|
|
|
|
|
|
|
|
|
|
|
|
if ((!TxdOp::eop(desc) && !useTso) ||
|
2009-04-22 07:58:53 +02:00
|
|
|
(pktPtr->length < ( tsoMss + tsoHeaderLen) &&
|
|
|
|
tsoTotalLen != tsoUsedLen && useTso)) {
|
2008-12-05 19:58:21 +01:00
|
|
|
assert(!useTso || (tsoDescBytesUsed == TxdOp::getLen(desc)));
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anDq("TXS", annUnusedCacheQ);
|
2007-03-27 00:40:18 +02:00
|
|
|
unusedCache.pop_front();
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anQ("TXS", annUsedCacheQ);
|
2007-03-27 00:40:18 +02:00
|
|
|
usedCache.push_back(desc);
|
2008-12-05 19:58:21 +01:00
|
|
|
|
|
|
|
tsoDescBytesUsed = 0;
|
2007-03-27 00:40:18 +02:00
|
|
|
pktDone = true;
|
|
|
|
pktWaiting = false;
|
2008-05-20 22:06:56 +02:00
|
|
|
pktMultiDesc = true;
|
|
|
|
|
|
|
|
DPRINTF(EthernetDesc, "Partial Packet Descriptor of %d bytes Done\n",
|
|
|
|
pktPtr->length);
|
2007-03-27 00:40:18 +02:00
|
|
|
pktPtr = NULL;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-05 19:58:21 +01:00
|
|
|
pktMultiDesc = false;
|
2007-03-22 23:39:41 +01:00
|
|
|
// no support for vlans
|
|
|
|
assert(!TxdOp::vle(desc));
|
|
|
|
|
|
|
|
// we only support single packet descriptors at this point
|
2008-12-05 19:58:21 +01:00
|
|
|
if (!useTso)
|
|
|
|
assert(TxdOp::eop(desc));
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
// set that this packet is done
|
2008-12-05 19:58:21 +01:00
|
|
|
if (TxdOp::rs(desc))
|
|
|
|
TxdOp::setDd(desc);
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc, "TxDescriptor data d1: %#llx d2: %#llx\n",
|
|
|
|
desc->d1, desc->d2);
|
2007-03-27 00:40:18 +02:00
|
|
|
|
2008-12-05 19:58:21 +01:00
|
|
|
if (useTso) {
|
|
|
|
IpPtr ip(pktPtr);
|
|
|
|
if (ip) {
|
|
|
|
DPRINTF(EthernetDesc, "TSO: Modifying IP header. Id + %d\n",
|
|
|
|
tsoPkts);
|
|
|
|
ip->id(ip->id() + tsoPkts++);
|
|
|
|
ip->len(pktPtr->length - EthPtr(pktPtr)->size());
|
|
|
|
|
|
|
|
TcpPtr tcp(ip);
|
|
|
|
if (tcp) {
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc,
|
|
|
|
"TSO: Modifying TCP header. old seq %d + %d\n",
|
|
|
|
tcp->seq(), tsoPrevSeq);
|
2008-12-05 19:58:21 +01:00
|
|
|
tcp->seq(tcp->seq() + tsoPrevSeq);
|
|
|
|
if (tsoUsedLen != tsoTotalLen)
|
|
|
|
tcp->flags(tcp->flags() & ~9); // clear fin & psh
|
|
|
|
}
|
|
|
|
UdpPtr udp(ip);
|
|
|
|
if (udp) {
|
|
|
|
DPRINTF(EthernetDesc, "TSO: Modifying UDP header.\n");
|
|
|
|
udp->len(pktPtr->length - EthPtr(pktPtr)->size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tsoPrevSeq = tsoUsedLen;
|
|
|
|
}
|
|
|
|
|
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);
|
2008-05-20 22:06:56 +02:00
|
|
|
assert(ip);
|
2007-03-22 23:39:41 +01:00
|
|
|
if (TxdOp::ixsm(desc)) {
|
|
|
|
ip->sum(0);
|
|
|
|
ip->sum(cksum(ip));
|
2008-06-18 07:22:44 +02:00
|
|
|
igbe->txIpChecksums++;
|
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) {
|
2009-04-22 07:58:53 +02:00
|
|
|
tcp->sum(0);
|
|
|
|
tcp->sum(cksum(tcp));
|
|
|
|
igbe->txTcpChecksums++;
|
|
|
|
DPRINTF(EthernetDesc, "Calculated TCP checksum\n");
|
2007-08-27 06:45:40 +02:00
|
|
|
} else if (udp) {
|
2009-04-22 07:58:53 +02:00
|
|
|
assert(udp);
|
|
|
|
udp->sum(0);
|
|
|
|
udp->sum(cksum(udp));
|
|
|
|
igbe->txUdpChecksums++;
|
|
|
|
DPRINTF(EthernetDesc, "Calculated UDP checksum\n");
|
2007-08-27 06:45:40 +02:00
|
|
|
} 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()) {
|
2009-04-22 07:58:53 +02:00
|
|
|
Tick delay = igbe->regs.tidv.idv() * igbe->intClock();
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "setting tidv\n");
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->reschedule(igbe->tidvEvent, curTick + delay, true);
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (igbe->regs.tadv.idv() && igbe->regs.tidv.idv()) {
|
2009-04-22 07:58:53 +02:00
|
|
|
Tick delay = igbe->regs.tadv.idv() * igbe->intClock();
|
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()) {
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->schedule(igbe->tadvEvent, curTick + delay);
|
2007-08-27 06:45:40 +02:00
|
|
|
}
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-27 00:40:18 +02:00
|
|
|
|
2008-12-05 19:58:21 +01:00
|
|
|
if (!useTso || TxdOp::getLen(desc) == tsoDescBytesUsed) {
|
|
|
|
DPRINTF(EthernetDesc, "Descriptor Done\n");
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anDq("TXS", annUnusedCacheQ);
|
2008-12-05 19:58:21 +01:00
|
|
|
unusedCache.pop_front();
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anQ("TXS", annUsedCacheQ);
|
2008-12-05 19:58:21 +01:00
|
|
|
usedCache.push_back(desc);
|
|
|
|
tsoDescBytesUsed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useTso && tsoUsedLen == tsoTotalLen)
|
|
|
|
useTso = false;
|
2007-03-27 00:40:18 +02:00
|
|
|
|
2008-12-05 19:58:21 +01:00
|
|
|
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc,
|
|
|
|
"------Packet of %d bytes ready for transmission-------\n",
|
2008-12-05 19:58:21 +01:00
|
|
|
pktPtr->length);
|
2007-03-22 23:39:41 +01:00
|
|
|
pktDone = true;
|
|
|
|
pktWaiting = false;
|
|
|
|
pktPtr = NULL;
|
2008-12-05 19:58:21 +01:00
|
|
|
tsoPktHasHeader = false;
|
2007-03-27 00:40:18 +02:00
|
|
|
|
|
|
|
if (igbe->regs.txdctl.wthresh() == 0) {
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anBegin("TXS", "Desc Writeback");
|
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);
|
2008-12-05 19:58:22 +01:00
|
|
|
} else if (igbe->regs.txdctl.gran() && igbe->regs.txdctl.wthresh() >=
|
2009-04-22 07:58:53 +02:00
|
|
|
descInBlock(usedCache.size())) {
|
2008-12-05 19:58:22 +01:00
|
|
|
DPRINTF(EthernetDesc, "used > WTHRESH, writing back descriptor\n");
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anBegin("TXS", "Desc Writeback");
|
2008-12-05 19:58:22 +01:00
|
|
|
writeback((igbe->cacheBlockSize()-1)>>4);
|
2007-03-27 00:40:18 +02:00
|
|
|
} else if (igbe->regs.txdctl.wthresh() >= usedCache.size()) {
|
2007-03-28 02:44:21 +02:00
|
|
|
DPRINTF(EthernetDesc, "used > WTHRESH, writing back descriptor\n");
|
2009-02-27 01:29:17 +01:00
|
|
|
igbe->anBegin("TXS", "Desc Writeback");
|
2007-03-27 00:40:18 +02:00
|
|
|
writeback((igbe->cacheBlockSize()-1)>>4);
|
|
|
|
}
|
2008-12-05 19:58:22 +01:00
|
|
|
|
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
|
|
|
|
2008-12-05 19:58:22 +01:00
|
|
|
void
|
|
|
|
IGbE::TxDescCache::actionAfterWb()
|
|
|
|
{
|
|
|
|
DPRINTF(EthernetDesc, "actionAfterWb() completionEnabled: %d\n",
|
|
|
|
completionEnabled);
|
|
|
|
igbe->postInterrupt(iGbReg::IT_TXDW);
|
|
|
|
if (completionEnabled) {
|
|
|
|
descEnd = igbe->regs.tdh();
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetDesc,
|
|
|
|
"Completion writing back value: %d to addr: %#x\n", descEnd,
|
2008-12-05 19:58:22 +01:00
|
|
|
completionAddress);
|
2009-04-22 07:58:53 +02:00
|
|
|
igbe->dmaWrite(pciToDma(mbits(completionAddress, 63, 2)),
|
|
|
|
sizeof(descEnd), &nullEvent, (uint8_t*)&descEnd, 0);
|
2008-12-05 19:58:22 +01: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);
|
2008-05-20 22:06:56 +02:00
|
|
|
SERIALIZE_SCALAR(pktMultiDesc);
|
2008-12-05 19:58:21 +01:00
|
|
|
|
|
|
|
SERIALIZE_SCALAR(useTso);
|
|
|
|
SERIALIZE_SCALAR(tsoHeaderLen);
|
|
|
|
SERIALIZE_SCALAR(tsoMss);
|
|
|
|
SERIALIZE_SCALAR(tsoTotalLen);
|
|
|
|
SERIALIZE_SCALAR(tsoUsedLen);
|
|
|
|
SERIALIZE_SCALAR(tsoPrevSeq);;
|
|
|
|
SERIALIZE_SCALAR(tsoPktPayloadBytes);
|
|
|
|
SERIALIZE_SCALAR(tsoLoadedHeader);
|
|
|
|
SERIALIZE_SCALAR(tsoPktHasHeader);
|
|
|
|
SERIALIZE_ARRAY(tsoHeader, 256);
|
|
|
|
SERIALIZE_SCALAR(tsoDescBytesUsed);
|
|
|
|
SERIALIZE_SCALAR(tsoCopyBytes);
|
|
|
|
SERIALIZE_SCALAR(tsoPkts);
|
|
|
|
|
2008-12-05 19:58:22 +01:00
|
|
|
SERIALIZE_SCALAR(completionAddress);
|
|
|
|
SERIALIZE_SCALAR(completionEnabled);
|
|
|
|
SERIALIZE_SCALAR(descEnd);
|
2007-03-30 04:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::TxDescCache::unserialize(Checkpoint *cp, const std::string §ion)
|
|
|
|
{
|
|
|
|
DescCache<TxDesc>::unserialize(cp, section);
|
|
|
|
UNSERIALIZE_SCALAR(pktDone);
|
|
|
|
UNSERIALIZE_SCALAR(isTcp);
|
|
|
|
UNSERIALIZE_SCALAR(pktWaiting);
|
2008-05-20 22:06:56 +02:00
|
|
|
UNSERIALIZE_SCALAR(pktMultiDesc);
|
2008-12-05 19:58:21 +01:00
|
|
|
|
|
|
|
UNSERIALIZE_SCALAR(useTso);
|
|
|
|
UNSERIALIZE_SCALAR(tsoHeaderLen);
|
|
|
|
UNSERIALIZE_SCALAR(tsoMss);
|
|
|
|
UNSERIALIZE_SCALAR(tsoTotalLen);
|
|
|
|
UNSERIALIZE_SCALAR(tsoUsedLen);
|
|
|
|
UNSERIALIZE_SCALAR(tsoPrevSeq);;
|
|
|
|
UNSERIALIZE_SCALAR(tsoPktPayloadBytes);
|
|
|
|
UNSERIALIZE_SCALAR(tsoLoadedHeader);
|
|
|
|
UNSERIALIZE_SCALAR(tsoPktHasHeader);
|
|
|
|
UNSERIALIZE_ARRAY(tsoHeader, 256);
|
|
|
|
UNSERIALIZE_SCALAR(tsoDescBytesUsed);
|
|
|
|
UNSERIALIZE_SCALAR(tsoCopyBytes);
|
|
|
|
UNSERIALIZE_SCALAR(tsoPkts);
|
2008-12-05 19:58:22 +01:00
|
|
|
|
|
|
|
UNSERIALIZE_SCALAR(completionAddress);
|
|
|
|
UNSERIALIZE_SCALAR(completionEnabled);
|
|
|
|
UNSERIALIZE_SCALAR(descEnd);
|
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()
|
|
|
|
{
|
2008-10-09 13:58:24 +02:00
|
|
|
if (!tickEvent.scheduled() && (rxTick || txTick || txFifoTick) &&
|
|
|
|
getState() == SimObject::Running)
|
|
|
|
schedule(tickEvent, (curTick / ticks(1)) * ticks(1) + ticks(1));
|
2007-03-27 00:40:18 +02:00
|
|
|
}
|
|
|
|
|
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() ||
|
2009-04-22 07:58:53 +02:00
|
|
|
txDescCache.hasOutstandingEvents()) {
|
2007-03-30 04:00:01 +02:00
|
|
|
count++;
|
|
|
|
drainEvent = de;
|
|
|
|
}
|
|
|
|
|
|
|
|
txFifoTick = false;
|
|
|
|
txTick = false;
|
|
|
|
rxTick = false;
|
|
|
|
|
|
|
|
if (tickEvent.scheduled())
|
2008-10-09 13:58:24 +02:00
|
|
|
deschedule(tickEvent);
|
2007-03-30 04:00:01 +02:00
|
|
|
|
|
|
|
if (count)
|
|
|
|
changeState(Draining);
|
|
|
|
else
|
|
|
|
changeState(Drained);
|
|
|
|
|
2009-02-27 01:29:17 +01:00
|
|
|
DPRINTF(EthernetSM, "got drain() returning %d", count);
|
2007-03-30 04:00:01 +02:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::resume()
|
|
|
|
{
|
|
|
|
SimObject::resume();
|
|
|
|
|
|
|
|
txFifoTick = true;
|
|
|
|
txTick = true;
|
|
|
|
rxTick = true;
|
|
|
|
|
|
|
|
restartClock();
|
2009-02-27 01:29:17 +01:00
|
|
|
DPRINTF(EthernetSM, "resuming from drain");
|
2007-03-30 04:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::checkDrain()
|
|
|
|
{
|
|
|
|
if (!drainEvent)
|
|
|
|
return;
|
|
|
|
|
2009-02-27 01:29:17 +01:00
|
|
|
DPRINTF(EthernetSM, "checkDrain() in drain\n");
|
2007-08-27 06:45:40 +02:00
|
|
|
txFifoTick = false;
|
|
|
|
txTick = false;
|
|
|
|
rxTick = false;
|
|
|
|
if (!rxDescCache.hasOutstandingEvents() &&
|
2009-04-22 07:58:53 +02:00
|
|
|
!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
|
2008-05-20 22:06:56 +02:00
|
|
|
if (txPacket && txDescCache.packetAvailable()
|
2009-04-22 07:58:53 +02:00
|
|
|
&& !txDescCache.packetMultiDesc() && txPacket->length) {
|
2007-03-22 23:39:41 +01:00
|
|
|
bool success;
|
2007-08-27 06:45:40 +02:00
|
|
|
|
2009-02-27 01:29:17 +01:00
|
|
|
anQ("TXS", "TX FIFO Q");
|
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;
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("TXS", "Desc Writeback");
|
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
|
2009-04-22 07:58:53 +02:00
|
|
|
if (regs.txdctl.lwthresh() &&
|
|
|
|
txDescCache.descLeft() < (regs.txdctl.lwthresh() * 8)) {
|
2007-03-22 23:39:41 +01:00
|
|
|
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);
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("TXS", "Desc Writeback");
|
2007-08-27 06:45:40 +02:00
|
|
|
txDescCache.writeback(0);
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("TXS", "Desc Fetch");
|
|
|
|
anWe("TXS", txDescCache.annUnusedCacheQ);
|
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())) {
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("TXS", "Desc Fetch");
|
2007-09-12 21:24:23 +02:00
|
|
|
txDescCache.fetchDescriptors();
|
2009-02-27 01:29:17 +01:00
|
|
|
anWe("TXS", txDescCache.annUnusedCacheQ);
|
2009-04-22 07:58:53 +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;
|
|
|
|
}
|
2009-02-27 01:29:17 +01:00
|
|
|
anPq("TXS", txDescCache.annUnusedCacheQ);
|
2007-03-22 23:39:41 +01:00
|
|
|
|
2008-02-11 01:32:12 +01:00
|
|
|
|
2008-12-05 19:58:21 +01:00
|
|
|
txDescCache.processContextDesc();
|
|
|
|
if (txDescCache.packetWaiting()) {
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetSM,
|
|
|
|
"TXS: Fetching TSO header, stopping ticking\n");
|
2008-12-05 19:58:21 +01:00
|
|
|
txTick = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-05 08:21:12 +02:00
|
|
|
unsigned size = txDescCache.getPacketSize(txPacket);
|
2007-03-27 00:40:18 +02:00
|
|
|
if (size > 0 && txFifo.avail() > size) {
|
2009-02-27 01:29:17 +01:00
|
|
|
anRq("TXS", "TX FIFO Q");
|
|
|
|
anBegin("TXS", "DMA Packet");
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetSM, "TXS: Reserving %d bytes in FIFO and "
|
|
|
|
"beginning DMA of next packet\n", size);
|
2007-03-27 00:40:18 +02:00
|
|
|
txFifo.reserve(size);
|
2007-03-22 23:39:41 +01:00
|
|
|
txDescCache.getPacketData(txPacket);
|
2009-06-05 08:21:12 +02:00
|
|
|
} else if (size == 0) {
|
2007-08-27 06:45:40 +02:00
|
|
|
DPRINTF(EthernetSM, "TXS: getPacketSize returned: %d\n", size);
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetSM,
|
|
|
|
"TXS: No packets to get, writing back used descriptors\n");
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("TXS", "Desc Writeback");
|
2007-03-22 23:39:41 +01:00
|
|
|
txDescCache.writeback(0);
|
2007-03-28 02:44:21 +02:00
|
|
|
} else {
|
2009-02-27 01:29:17 +01:00
|
|
|
anWf("TXS", "TX FIFO Q");
|
2007-03-28 02:44:21 +02:00
|
|
|
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)
|
|
|
|
{
|
2008-06-18 07:22:44 +02:00
|
|
|
rxBytes += pkt->length;
|
|
|
|
rxPackets++;
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
DPRINTF(Ethernet, "RxFIFO: Receiving pcakte from wire\n");
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("RXQ", "Wire Recv");
|
|
|
|
|
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");
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("RXQ", "FIFO Drop", CPA::FL_BAD);
|
2007-03-22 23:39:41 +01:00
|
|
|
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()) {
|
2009-04-22 07:58:53 +02:00
|
|
|
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);
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("RXQ", "FIFO Drop", CPA::FL_BAD);
|
2007-03-22 23:39:41 +01:00
|
|
|
return false;
|
|
|
|
}
|
2008-02-11 01:32:12 +01:00
|
|
|
|
2009-02-27 01:29:17 +01:00
|
|
|
if (CPA::available() && cpa->enabled()) {
|
|
|
|
assert(sys->numSystemsRunning <= 2);
|
|
|
|
System *other_sys;
|
|
|
|
if (sys->systemList[0] == sys)
|
|
|
|
other_sys = sys->systemList[1];
|
|
|
|
else
|
|
|
|
other_sys = sys->systemList[0];
|
|
|
|
|
|
|
|
cpa->hwDq(CPA::FL_NONE, sys, macAddr, "RXQ", "WireQ", 0, other_sys);
|
|
|
|
anQ("RXQ", "RX FIFO Q");
|
|
|
|
cpa->hwWe(CPA::FL_NONE, sys, macAddr, "RXQ", "WireQ", 0, other_sys);
|
|
|
|
}
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
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();
|
2009-01-06 16:36:57 +01:00
|
|
|
DPRINTF(EthernetSM, "RXS: descLeft: %d rdmts: %d rdlen: %d\n",
|
|
|
|
descLeft, regs.rctl.rdmts(), regs.rdlen());
|
2007-03-22 23:39:41 +01:00
|
|
|
switch (regs.rctl.rdmts()) {
|
2009-04-22 07:58:53 +02:00
|
|
|
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;
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
2009-01-06 16:36:57 +01:00
|
|
|
if (rxFifo.empty())
|
|
|
|
rxDescCache.writeback(0);
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
if (descLeft == 0) {
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("RXS", "Writeback Descriptors");
|
2007-03-22 23:39:41 +01:00
|
|
|
rxDescCache.writeback(0);
|
2008-02-11 01:32:12 +01:00
|
|
|
DPRINTF(EthernetSM, "RXS: No descriptors left in ring, forcing"
|
|
|
|
" writeback and stopping ticking\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
rxTick = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only support descriptor granulaties
|
|
|
|
assert(regs.rxdctl.gran());
|
|
|
|
|
|
|
|
if (regs.rxdctl.wthresh() >= rxDescCache.descUsed()) {
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetSM,
|
|
|
|
"RXS: Writing back because WTHRESH >= descUsed\n");
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("RXS", "Writeback Descriptors");
|
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()) &&
|
2009-04-22 07:58:53 +02:00
|
|
|
((rxDescCache.descLeft() - rxDescCache.descUnused()) >
|
|
|
|
regs.rxdctl.hthresh())) {
|
|
|
|
DPRINTF(EthernetSM, "RXS: Fetching descriptors because "
|
|
|
|
"descUnused < PTHRESH\n");
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("RXS", "Fetch Descriptors");
|
2007-03-22 23:39:41 +01:00
|
|
|
rxDescCache.fetchDescriptors();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rxDescCache.descUnused() == 0) {
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("RXS", "Fetch Descriptors");
|
2007-09-12 21:24:23 +02:00
|
|
|
rxDescCache.fetchDescriptors();
|
2009-02-27 01:29:17 +01:00
|
|
|
anWe("RXS", rxDescCache.annUnusedCacheQ);
|
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) {
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetSM,
|
|
|
|
"RXS: stopping ticking until packet DMA completes\n");
|
2007-05-14 22:37:00 +02:00
|
|
|
rxTick = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
if (!rxDescCache.descUnused()) {
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("RXS", "Fetch Descriptors");
|
2007-09-12 21:24:23 +02:00
|
|
|
rxDescCache.fetchDescriptors();
|
2009-02-27 01:29:17 +01:00
|
|
|
anWe("RXS", rxDescCache.annUnusedCacheQ);
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetSM, "RXS: No descriptors available in cache, "
|
|
|
|
"stopping ticking\n");
|
2007-03-22 23:39:41 +01:00
|
|
|
rxTick = false;
|
|
|
|
DPRINTF(EthernetSM, "RXS: No descriptors available, fetching\n");
|
|
|
|
return;
|
|
|
|
}
|
2009-02-27 01:29:17 +01:00
|
|
|
anPq("RXS", rxDescCache.annUnusedCacheQ);
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
if (rxFifo.empty()) {
|
2009-02-27 01:29:17 +01:00
|
|
|
anWe("RXS", "RX FIFO Q");
|
2007-03-22 23:39:41 +01:00
|
|
|
DPRINTF(EthernetSM, "RXS: RxFIFO empty, stopping ticking\n");
|
|
|
|
rxTick = false;
|
|
|
|
return;
|
|
|
|
}
|
2009-02-27 01:29:17 +01:00
|
|
|
anPq("RXS", "RX FIFO Q");
|
|
|
|
anBegin("RXS", "Get Desc");
|
2007-03-22 23:39:41 +01:00
|
|
|
|
|
|
|
EthPacketPtr pkt;
|
|
|
|
pkt = rxFifo.front();
|
|
|
|
|
|
|
|
|
2009-01-06 16:36:57 +01:00
|
|
|
pktOffset = rxDescCache.writePacket(pkt, pktOffset);
|
2008-02-11 01:32:12 +01:00
|
|
|
DPRINTF(EthernetSM, "RXS: Writing packet into memory\n");
|
2009-01-06 16:36:57 +01:00
|
|
|
if (pktOffset == pkt->length) {
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin( "RXS", "FIFO Dequeue");
|
2009-01-06 16:36:57 +01:00
|
|
|
DPRINTF(EthernetSM, "RXS: Removing packet from FIFO\n");
|
|
|
|
pktOffset = 0;
|
2009-02-27 01:29:17 +01:00
|
|
|
anDq("RXS", "RX FIFO Q");
|
2009-01-06 16:36:57 +01:00
|
|
|
rxFifo.pop();
|
|
|
|
}
|
|
|
|
|
2008-02-11 01:32:12 +01:00
|
|
|
DPRINTF(EthernetSM, "RXS: stopping ticking until packet DMA completes\n");
|
|
|
|
rxTick = false;
|
|
|
|
rxDmaPacket = true;
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("RXS", "DMA Packet");
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IGbE::txWire()
|
|
|
|
{
|
|
|
|
if (txFifo.empty()) {
|
2009-02-27 01:29:17 +01:00
|
|
|
anWe("TXQ", "TX FIFO Q");
|
2007-03-28 02:44:21 +02:00
|
|
|
txFifoTick = false;
|
2007-03-22 23:39:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-11 01:32:12 +01:00
|
|
|
|
2009-02-27 01:29:17 +01:00
|
|
|
anPq("TXQ", "TX FIFO Q");
|
2008-02-11 01:32:12 +01:00
|
|
|
if (etherInt->sendPacket(txFifo.front())) {
|
2009-02-27 01:29:17 +01:00
|
|
|
cpa->hwQ(CPA::FL_NONE, sys, macAddr, "TXQ", "WireQ", 0);
|
2007-08-27 06:45:40 +02:00
|
|
|
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");
|
|
|
|
}
|
2009-02-27 01:29:17 +01:00
|
|
|
anDq("TXQ", "TX FIFO Q");
|
|
|
|
anBegin("TXQ", "Wire Send");
|
2009-04-22 07:58:53 +02:00
|
|
|
DPRINTF(EthernetSM,
|
|
|
|
"TxFIFO: Successful transmit, bytes available in fifo: %d\n",
|
2007-03-22 23:39:41 +01:00
|
|
|
txFifo.avail());
|
2008-06-18 07:22:44 +02:00
|
|
|
|
|
|
|
txBytes += txFifo.front()->length;
|
|
|
|
txPackets++;
|
2008-08-24 21:27:49 +02:00
|
|
|
txFifoTick = false;
|
2008-06-18 07:22:44 +02:00
|
|
|
|
2007-03-22 23:39:41 +01:00
|
|
|
txFifo.pop();
|
2008-02-11 01:32:12 +01:00
|
|
|
} else {
|
|
|
|
// We'll get woken up when the packet ethTxDone() gets called
|
|
|
|
txFifoTick = false;
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2008-10-09 13:58:24 +02:00
|
|
|
schedule(tickEvent, curTick + ticks(1));
|
2007-03-22 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
2006-09-19 02:12:45 +02:00
|
|
|
void
|
|
|
|
IGbE::ethTxDone()
|
|
|
|
{
|
2009-02-27 01:29:17 +01:00
|
|
|
anBegin("TXQ", "Send Done");
|
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();
|
2008-03-25 20:58:54 +01:00
|
|
|
txWire();
|
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);
|
2008-07-01 16:30:08 +02:00
|
|
|
SERIALIZE_SCALAR(lastInterrupt);
|
2007-03-30 04:00:01 +02:00
|
|
|
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,
|
2009-04-22 07:58:53 +02:00
|
|
|
inter_time = 0;
|
2007-03-30 04:00:01 +02:00
|
|
|
|
|
|
|
if (rdtrEvent.scheduled())
|
2009-04-22 07:58:53 +02:00
|
|
|
rdtr_time = rdtrEvent.when();
|
2007-03-30 04:00:01 +02:00
|
|
|
SERIALIZE_SCALAR(rdtr_time);
|
|
|
|
|
|
|
|
if (radvEvent.scheduled())
|
2009-04-22 07:58:53 +02:00
|
|
|
radv_time = radvEvent.when();
|
2007-03-30 04:00:01 +02:00
|
|
|
SERIALIZE_SCALAR(radv_time);
|
|
|
|
|
|
|
|
if (tidvEvent.scheduled())
|
2009-04-22 07:58:53 +02:00
|
|
|
tidv_time = tidvEvent.when();
|
2007-03-30 04:00:01 +02:00
|
|
|
SERIALIZE_SCALAR(tidv_time);
|
|
|
|
|
|
|
|
if (tadvEvent.scheduled())
|
2009-04-22 07:58:53 +02:00
|
|
|
tadv_time = tadvEvent.when();
|
2007-03-30 04:00:01 +02:00
|
|
|
SERIALIZE_SCALAR(tadv_time);
|
|
|
|
|
|
|
|
if (interEvent.scheduled())
|
2009-04-22 07:58:53 +02:00
|
|
|
inter_time = interEvent.when();
|
2007-03-30 04:00:01 +02:00
|
|
|
SERIALIZE_SCALAR(inter_time);
|
|
|
|
|
2009-01-06 16:36:57 +01:00
|
|
|
SERIALIZE_SCALAR(pktOffset);
|
|
|
|
|
2007-03-30 04:00:01 +02:00
|
|
|
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);
|
2008-07-01 16:30:08 +02:00
|
|
|
UNSERIALIZE_SCALAR(lastInterrupt);
|
2007-03-30 04:00:01 +02:00
|
|
|
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)
|
2008-10-09 13:58:24 +02:00
|
|
|
schedule(rdtrEvent, rdtr_time);
|
2007-03-30 04:00:01 +02:00
|
|
|
|
|
|
|
if (radv_time)
|
2008-10-09 13:58:24 +02:00
|
|
|
schedule(radvEvent, radv_time);
|
2007-03-30 04:00:01 +02:00
|
|
|
|
|
|
|
if (tidv_time)
|
2008-10-09 13:58:24 +02:00
|
|
|
schedule(tidvEvent, tidv_time);
|
2007-03-30 04:00:01 +02:00
|
|
|
|
|
|
|
if (tadv_time)
|
2008-10-09 13:58:24 +02:00
|
|
|
schedule(tadvEvent, tadv_time);
|
2007-03-30 04:00:01 +02:00
|
|
|
|
|
|
|
if (inter_time)
|
2008-10-09 13:58:24 +02:00
|
|
|
schedule(interEvent, inter_time);
|
2007-03-30 04:00:01 +02:00
|
|
|
|
2009-01-06 16:36:57 +01:00
|
|
|
UNSERIALIZE_SCALAR(pktOffset);
|
|
|
|
|
2007-03-30 04:00:01 +02:00
|
|
|
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
|
|
|
}
|