2 * Copyright (c) 2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * Device model for Intel's 8254x line of gigabit ethernet controllers.
33 * In particular an 82547 revision 2 (82547GI) MAC because it seems to have the
34 * fewest workarounds in the driver. It will probably work with most of the
35 * other MACs with slight modifications.
40 * @todo really there are multiple dma engines.. we should implement them.
45 #include "base/inet.hh"
46 #include "base/trace.hh"
47 #include "dev/i8254xGBe.hh"
48 #include "mem/packet.hh"
49 #include "mem/packet_access.hh"
50 #include "params/IGbE.hh"
51 #include "sim/stats.hh"
52 #include "sim/system.hh"
54 using namespace iGbReg
;
57 IGbE::IGbE(const Params
*p
)
58 : EtherDevice(p
), etherInt(NULL
), drainEvent(NULL
), useFlowControl(p
->use_flow_control
),
59 rxFifo(p
->rx_fifo_size
), txFifo(p
->tx_fifo_size
), rxTick(false),
60 txTick(false), txFifoTick(false), rdtrEvent(this), radvEvent(this),
61 tadvEvent(this), tidvEvent(this), tickEvent(this), interEvent(this),
62 rxDescCache(this, name()+".RxDesc", p
->rx_desc_cache_size
),
63 txDescCache(this, name()+".TxDesc", p
->tx_desc_cache_size
), clock(p
->clock
)
65 etherInt
= new IGbEInt(name() + ".int", this);
67 // Initialized internal registers per Intel documentation
68 // All registers intialized to 0 by per register constructor
73 regs
.sts
.speed(3); // Say we're 1000Mbps
74 regs
.sts
.fd(1); // full duplex
75 regs
.sts
.lu(1); // link up
81 regs
.rxdctl
.wthresh(1);
92 // clear all 64 16 bit words of the eeprom
93 memset(&flash
, 0, EEPROM_SIZE
*2);
95 // Set the MAC address
96 memcpy(flash
, p
->hardware_address
.bytes(), ETH_ADDR_LEN
);
97 for (int x
= 0; x
< ETH_ADDR_LEN
/2; x
++)
98 flash
[x
] = htobe(flash
[x
]);
101 for (int x
= 0; x
< EEPROM_SIZE
; x
++)
102 csum
+= htobe(flash
[x
]);
105 // Magic happy checksum value
106 flash
[EEPROM_SIZE
-1] = htobe((uint16_t)(EEPROM_CSUM
- csum
));
113 IGbE::getEthPort(const std::string
&if_name
, int idx
)
116 if (if_name
== "interface" && !etherInt
) {
117 if (etherInt
->getPeer())
118 panic("Port already connected to\n");
125 IGbE::writeConfig(PacketPtr pkt
)
127 int offset
= pkt
->getAddr() & PCI_CONFIG_SIZE
;
128 if (offset
< PCI_DEVICE_SPECIFIC
)
129 PciDev::writeConfig(pkt
);
131 panic("Device specific PCI config space not implemented.\n");
134 /// Some work may need to be done here based for the pci COMMAND bits.
141 IGbE::read(PacketPtr pkt
)
146 if (!getBAR(pkt
->getAddr(), bar
, daddr
))
147 panic("Invalid PCI memory access to unmapped memory.\n");
149 // Only Memory register BAR is allowed
152 // Only 32bit accesses allowed
153 assert(pkt
->getSize() == 4);
155 DPRINTF(Ethernet
, "Read device register %#X\n", daddr
);
160 /// Handle read of register here
166 pkt
->set
<uint32_t>(regs
.ctrl());
169 pkt
->set
<uint32_t>(regs
.sts());
172 pkt
->set
<uint32_t>(regs
.eecd());
175 pkt
->set
<uint32_t>(regs
.eerd());
178 pkt
->set
<uint32_t>(regs
.ctrl_ext());
181 pkt
->set
<uint32_t>(regs
.mdic());
184 DPRINTF(Ethernet
, "Reading ICR. ICR=%#x IMR=%#x IAM=%#x IAME=%d\n", regs
.icr(),
185 regs
.imr
, regs
.iam
, regs
.ctrl_ext
.iame());
186 pkt
->set
<uint32_t>(regs
.icr());
187 if (regs
.icr
.int_assert() || regs
.imr
== 0) {
188 regs
.icr
= regs
.icr() & ~mask(30);
189 DPRINTF(Ethernet
, "Cleared ICR. ICR=%#x\n", regs
.icr());
191 if (regs
.ctrl_ext
.iame() && regs
.icr
.int_assert())
192 regs
.imr
&= ~regs
.iam
;
196 pkt
->set
<uint32_t>(regs
.itr());
199 pkt
->set
<uint32_t>(regs
.rctl());
202 pkt
->set
<uint32_t>(regs
.fcttv());
205 pkt
->set
<uint32_t>(regs
.tctl());
208 pkt
->set
<uint32_t>(regs
.pba());
212 pkt
->set
<uint32_t>(0); // We don't care, so just return 0
215 pkt
->set
<uint32_t>(regs
.fcrtl());
218 pkt
->set
<uint32_t>(regs
.fcrth());
221 pkt
->set
<uint32_t>(regs
.rdba
.rdbal());
224 pkt
->set
<uint32_t>(regs
.rdba
.rdbah());
227 pkt
->set
<uint32_t>(regs
.rdlen());
230 pkt
->set
<uint32_t>(regs
.rdh());
233 pkt
->set
<uint32_t>(regs
.rdt());
236 pkt
->set
<uint32_t>(regs
.rdtr());
237 if (regs
.rdtr
.fpd()) {
238 rxDescCache
.writeback(0);
239 DPRINTF(EthernetIntr
, "Posting interrupt because of RDTR.FPD write\n");
240 postInterrupt(IT_RXT
);
245 pkt
->set
<uint32_t>(regs
.radv());
248 pkt
->set
<uint32_t>(regs
.tdba
.tdbal());
251 pkt
->set
<uint32_t>(regs
.tdba
.tdbah());
254 pkt
->set
<uint32_t>(regs
.tdlen());
257 pkt
->set
<uint32_t>(regs
.tdh());
260 pkt
->set
<uint32_t>(regs
.tdt());
263 pkt
->set
<uint32_t>(regs
.tidv());
266 pkt
->set
<uint32_t>(regs
.txdctl());
269 pkt
->set
<uint32_t>(regs
.tadv());
272 pkt
->set
<uint32_t>(regs
.rxcsum());
275 pkt
->set
<uint32_t>(regs
.manc());
278 if (!(daddr
>= REG_VFTA
&& daddr
< (REG_VFTA
+ VLAN_FILTER_TABLE_SIZE
*4)) &&
279 !(daddr
>= REG_RAL
&& daddr
< (REG_RAL
+ RCV_ADDRESS_TABLE_SIZE
*8)) &&
280 !(daddr
>= REG_MTA
&& daddr
< (REG_MTA
+ MULTICAST_TABLE_SIZE
*4)) &&
281 !(daddr
>= REG_CRCERRS
&& daddr
< (REG_CRCERRS
+ STATS_REGS_SIZE
)))
282 panic("Read request to unknown register number: %#x\n", daddr
);
284 pkt
->set
<uint32_t>(0);
287 pkt
->makeAtomicResponse();
292 IGbE::write(PacketPtr pkt
)
298 if (!getBAR(pkt
->getAddr(), bar
, daddr
))
299 panic("Invalid PCI memory access to unmapped memory.\n");
301 // Only Memory register BAR is allowed
304 // Only 32bit accesses allowed
305 assert(pkt
->getSize() == sizeof(uint32_t));
307 DPRINTF(Ethernet
, "Wrote device register %#X value %#X\n", daddr
, pkt
->get
<uint32_t>());
310 /// Handle write of register here
312 uint32_t val
= pkt
->get
<uint32_t>();
320 if (regs
.ctrl
.tfce())
321 warn("TX Flow control enabled, should implement\n");
322 if (regs
.ctrl
.rfce())
323 warn("RX Flow control enabled, should implement\n");
333 oldClk
= regs
.eecd
.sk();
335 // See if this is a eeprom access and emulate accordingly
336 if (!oldClk
&& regs
.eecd
.sk()) {
338 eeOpcode
= eeOpcode
<< 1 | regs
.eecd
.din();
340 } else if (eeAddrBits
< 8 && eeOpcode
== EEPROM_READ_OPCODE_SPI
) {
341 eeAddr
= eeAddr
<< 1 | regs
.eecd
.din();
343 } else if (eeDataBits
< 16 && eeOpcode
== EEPROM_READ_OPCODE_SPI
) {
344 assert(eeAddr
>>1 < EEPROM_SIZE
);
345 DPRINTF(EthernetEEPROM
, "EEPROM bit read: %d word: %#X\n",
346 flash
[eeAddr
>>1] >> eeDataBits
& 0x1, flash
[eeAddr
>>1]);
347 regs
.eecd
.dout((flash
[eeAddr
>>1] >> (15-eeDataBits
)) & 0x1);
349 } else if (eeDataBits
< 8 && eeOpcode
== EEPROM_RDSR_OPCODE_SPI
) {
353 panic("What's going on with eeprom interface? opcode:"
354 " %#x:%d addr: %#x:%d, data: %d\n", (uint32_t)eeOpcode
,
355 (uint32_t)eeOpBits
, (uint32_t)eeAddr
,
356 (uint32_t)eeAddrBits
, (uint32_t)eeDataBits
);
358 // Reset everything for the next command
359 if ((eeDataBits
== 16 && eeOpcode
== EEPROM_READ_OPCODE_SPI
) ||
360 (eeDataBits
== 8 && eeOpcode
== EEPROM_RDSR_OPCODE_SPI
)) {
368 DPRINTF(EthernetEEPROM
, "EEPROM: opcode: %#X:%d addr: %#X:%d\n",
369 (uint32_t)eeOpcode
, (uint32_t) eeOpBits
,
370 (uint32_t)eeAddr
>>1, (uint32_t)eeAddrBits
);
371 if (eeOpBits
== 8 && !(eeOpcode
== EEPROM_READ_OPCODE_SPI
||
372 eeOpcode
== EEPROM_RDSR_OPCODE_SPI
))
373 panic("Unknown eeprom opcode: %#X:%d\n", (uint32_t)eeOpcode
,
378 // If driver requests eeprom access, immediately give it to it
379 regs
.eecd
.ee_gnt(regs
.eecd
.ee_req());
387 panic("No support for interrupt on mdic complete\n");
388 if (regs
.mdic
.phyadd() != 1)
389 panic("No support for reading anything but phy\n");
390 DPRINTF(Ethernet
, "%s phy address %x\n", regs
.mdic
.op() == 1 ? "Writing"
391 : "Reading", regs
.mdic
.regadd());
392 switch (regs
.mdic
.regadd()) {
394 regs
.mdic
.data(0x796D); // link up
397 regs
.mdic
.data(0x02A8);
400 regs
.mdic
.data(0x0380);
403 regs
.mdic
.data(0x7C00);
406 regs
.mdic
.data(0x3000);
409 regs
.mdic
.data(0x180); // some random length
417 DPRINTF(Ethernet
, "Writing ICR. ICR=%#x IMR=%#x IAM=%#x IAME=%d\n", regs
.icr(),
418 regs
.imr
, regs
.iam
, regs
.ctrl_ext
.iame());
419 if (regs
.ctrl_ext
.iame())
420 regs
.imr
&= ~regs
.iam
;
421 regs
.icr
= ~bits(val
,30,0) & regs
.icr();
428 DPRINTF(EthernetIntr
, "Posting interrupt because of ICS write\n");
429 postInterrupt((IntTypes
)val
);
445 if (regs
.rctl
.rst()) {
447 DPRINTF(EthernetSM
, "RXS: Got RESET!\n");
465 if (regs
.tctl
.en() && !oldtctl
.en()) {
471 regs
.pba
.txa(64 - regs
.pba
.rxa());
481 ; // We don't care, so don't store anything
490 regs
.rdba
.rdbal( val
& ~mask(4));
491 rxDescCache
.areaChanged();
494 regs
.rdba
.rdbah(val
);
495 rxDescCache
.areaChanged();
498 regs
.rdlen
= val
& ~mask(7);
499 rxDescCache
.areaChanged();
503 rxDescCache
.areaChanged();
517 regs
.tdba
.tdbal( val
& ~mask(4));
518 txDescCache
.areaChanged();
521 regs
.tdba
.tdbah(val
);
522 txDescCache
.areaChanged();
525 regs
.tdlen
= val
& ~mask(7);
526 txDescCache
.areaChanged();
530 txDescCache
.areaChanged();
553 if (!(daddr
>= REG_VFTA
&& daddr
< (REG_VFTA
+ VLAN_FILTER_TABLE_SIZE
*4)) &&
554 !(daddr
>= REG_RAL
&& daddr
< (REG_RAL
+ RCV_ADDRESS_TABLE_SIZE
*8)) &&
555 !(daddr
>= REG_MTA
&& daddr
< (REG_MTA
+ MULTICAST_TABLE_SIZE
*4)))
556 panic("Write request to unknown register number: %#x\n", daddr
);
559 pkt
->makeAtomicResponse();
564 IGbE::postInterrupt(IntTypes t
, bool now
)
568 // Interrupt is already pending
572 if (regs
.icr() & regs
.imr
)
574 regs
.icr
= regs
.icr() | t
;
575 if (!interEvent
.scheduled())
576 interEvent
.schedule(curTick
+ Clock::Int::ns
* 256 *
577 regs
.itr
.interval());
579 regs
.icr
= regs
.icr() | t
;
580 if (regs
.itr
.interval() == 0 || now
) {
581 if (interEvent
.scheduled())
582 interEvent
.deschedule();
585 DPRINTF(EthernetIntr
, "EINT: Scheduling timer interrupt for %d ticks\n",
586 Clock::Int::ns
* 256 * regs
.itr
.interval());
587 if (!interEvent
.scheduled())
588 interEvent
.schedule(curTick
+ Clock::Int::ns
* 256 * regs
.itr
.interval());
596 if (rdtrEvent
.scheduled()) {
598 rdtrEvent
.deschedule();
600 if (radvEvent
.scheduled()) {
602 radvEvent
.deschedule();
604 if (tadvEvent
.scheduled()) {
606 tadvEvent
.deschedule();
608 if (tidvEvent
.scheduled()) {
610 tidvEvent
.deschedule();
613 regs
.icr
.int_assert(1);
614 DPRINTF(EthernetIntr
, "EINT: Posting interrupt to CPU now. Vector %#x\n",
622 if (regs
.icr
.int_assert()) {
623 regs
.icr
.int_assert(0);
624 DPRINTF(EthernetIntr
, "EINT: Clearing interrupt to CPU now. Vector %#x\n",
633 // Check if we need to clear the cpu interrupt
634 if (!(regs
.icr() & regs
.imr
)) {
635 if (interEvent
.scheduled())
636 interEvent
.deschedule();
637 if (regs
.icr
.int_assert())
641 if (regs
.icr() & regs
.imr
) {
642 if (regs
.itr
.interval() == 0) {
645 if (!interEvent
.scheduled())
646 interEvent
.schedule(curTick
+ Clock::Int::ns
* 256 * regs
.itr
.interval());
654 IGbE::RxDescCache::RxDescCache(IGbE
*i
, const std::string n
, int s
)
655 : DescCache
<RxDesc
>(i
, n
, s
), pktDone(false), pktEvent(this)
661 IGbE::RxDescCache::writePacket(EthPacketPtr packet
)
663 // We shouldn't have to deal with any of these yet
664 DPRINTF(EthernetDesc
, "Packet Length: %d Desc Size: %d\n",
665 packet
->length
, igbe
->regs
.rctl
.descSize());
666 assert(packet
->length
< igbe
->regs
.rctl
.descSize());
668 if (!unusedCache
.size())
673 igbe
->dmaWrite(igbe
->platform
->pciToDma(unusedCache
.front()->buf
),
674 packet
->length
, &pktEvent
, packet
->data
);
679 IGbE::RxDescCache::pktComplete()
681 assert(unusedCache
.size());
683 desc
= unusedCache
.front();
685 uint16_t crcfixup
= igbe
->regs
.rctl
.secrc() ? 0 : 4 ;
686 desc
->len
= htole((uint16_t)(pktPtr
->length
+ crcfixup
));
687 DPRINTF(EthernetDesc
, "pktPtr->length: %d stripcrc offset: %d value written: %d %d\n",
688 pktPtr
->length
, crcfixup
,
689 htole((uint16_t)(pktPtr
->length
+ crcfixup
)),
690 (uint16_t)(pktPtr
->length
+ crcfixup
));
692 // no support for anything but starting at 0
693 assert(igbe
->regs
.rxcsum
.pcss() == 0);
695 DPRINTF(EthernetDesc
, "Packet written to memory updating Descriptor\n");
697 uint8_t status
= RXDS_DD
| RXDS_EOP
;
703 DPRINTF(EthernetDesc
, "Proccesing Ip packet with Id=%d\n", ip
->id());
705 if (igbe
->regs
.rxcsum
.ipofld()) {
706 DPRINTF(EthernetDesc
, "Checking IP checksum\n");
708 desc
->csum
= htole(cksum(ip
));
709 if (cksum(ip
) != 0) {
711 DPRINTF(EthernetDesc
, "Checksum is bad!!\n");
715 if (tcp
&& igbe
->regs
.rxcsum
.tuofld()) {
716 DPRINTF(EthernetDesc
, "Checking TCP checksum\n");
717 status
|= RXDS_TCPCS
;
718 desc
->csum
= htole(cksum(tcp
));
719 if (cksum(tcp
) != 0) {
720 DPRINTF(EthernetDesc
, "Checksum is bad!!\n");
726 if (udp
&& igbe
->regs
.rxcsum
.tuofld()) {
727 DPRINTF(EthernetDesc
, "Checking UDP checksum\n");
728 status
|= RXDS_UDPCS
;
729 desc
->csum
= htole(cksum(udp
));
730 if (cksum(udp
) != 0) {
731 DPRINTF(EthernetDesc
, "Checksum is bad!!\n");
736 DPRINTF(EthernetSM
, "Proccesing Non-Ip packet\n");
740 desc
->status
= htole(status
);
741 desc
->errors
= htole(err
);
743 // No vlan support at this point... just set it to 0
746 // Deal with the rx timer interrupts
747 if (igbe
->regs
.rdtr
.delay()) {
748 DPRINTF(EthernetSM
, "RXS: Scheduling DTR for %d\n",
749 igbe
->regs
.rdtr
.delay() * igbe
->intClock());
750 igbe
->rdtrEvent
.reschedule(curTick
+ igbe
->regs
.rdtr
.delay() *
751 igbe
->intClock(),true);
754 if (igbe
->regs
.radv
.idv() && igbe
->regs
.rdtr
.delay()) {
755 DPRINTF(EthernetSM
, "RXS: Scheduling ADV for %d\n",
756 igbe
->regs
.radv
.idv() * igbe
->intClock());
757 if (!igbe
->radvEvent
.scheduled())
758 igbe
->radvEvent
.schedule(curTick
+ igbe
->regs
.radv
.idv() *
762 // if neither radv or rdtr, maybe itr is set...
763 if (!igbe
->regs
.rdtr
.delay()) {
764 DPRINTF(EthernetSM
, "RXS: Receive interrupt delay disabled, posting IT_RXT\n");
765 igbe
->postInterrupt(IT_RXT
);
768 // If the packet is small enough, interrupt appropriately
769 // I wonder if this is delayed or not?!
770 if (pktPtr
->length
<= igbe
->regs
.rsrpd
.idv()) {
771 DPRINTF(EthernetSM
, "RXS: Posting IT_SRPD beacuse small packet received\n");
772 igbe
->postInterrupt(IT_SRPD
);
775 DPRINTF(EthernetDesc
, "Processing of this descriptor complete\n");
776 unusedCache
.pop_front();
777 usedCache
.push_back(desc
);
785 IGbE::RxDescCache::enableSm()
788 igbe
->restartClock();
792 IGbE::RxDescCache::packetDone()
802 IGbE::RxDescCache::hasOutstandingEvents()
804 return pktEvent
.scheduled() || wbEvent
.scheduled() ||
805 fetchEvent
.scheduled();
809 IGbE::RxDescCache::serialize(std::ostream
&os
)
811 DescCache
<RxDesc
>::serialize(os
);
812 SERIALIZE_SCALAR(pktDone
);
816 IGbE::RxDescCache::unserialize(Checkpoint
*cp
, const std::string
§ion
)
818 DescCache
<RxDesc
>::unserialize(cp
, section
);
819 UNSERIALIZE_SCALAR(pktDone
);
823 ///////////////////////////////////// IGbE::TxDesc /////////////////////////////////
825 IGbE::TxDescCache::TxDescCache(IGbE
*i
, const std::string n
, int s
)
826 : DescCache
<TxDesc
>(i
,n
, s
), pktDone(false), isTcp(false), pktWaiting(false),
833 IGbE::TxDescCache::getPacketSize()
835 assert(unusedCache
.size());
839 DPRINTF(EthernetDesc
, "Starting processing of descriptor\n");
841 while (unusedCache
.size() && TxdOp::isContext(unusedCache
.front())) {
842 DPRINTF(EthernetDesc
, "Got context descriptor type... skipping\n");
844 // I think we can just ignore these for now?
845 desc
= unusedCache
.front();
846 // is this going to be a tcp or udp packet?
847 isTcp
= TxdOp::tcp(desc
) ? true : false;
849 // make sure it's ipv4
850 assert(TxdOp::ip(desc
));
853 unusedCache
.pop_front();
854 usedCache
.push_back(desc
);
857 if (!unusedCache
.size())
860 DPRINTF(EthernetDesc
, "Next TX packet is %d bytes\n",
861 TxdOp::getLen(unusedCache
.front()));
863 return TxdOp::getLen(unusedCache
.front());
867 IGbE::TxDescCache::getPacketData(EthPacketPtr p
)
869 assert(unusedCache
.size());
872 desc
= unusedCache
.front();
874 assert((TxdOp::isLegacy(desc
) || TxdOp::isData(desc
)) && TxdOp::getLen(desc
));
880 DPRINTF(EthernetDesc
, "Starting DMA of packet\n");
881 igbe
->dmaRead(igbe
->platform
->pciToDma(TxdOp::getBuf(desc
)),
882 TxdOp::getLen(desc
), &pktEvent
, p
->data
+ p
->length
);
888 IGbE::TxDescCache::pktComplete()
892 assert(unusedCache
.size());
895 DPRINTF(EthernetDesc
, "DMA of packet complete\n");
898 desc
= unusedCache
.front();
899 assert((TxdOp::isLegacy(desc
) || TxdOp::isData(desc
)) && TxdOp::getLen(desc
));
901 DPRINTF(EthernetDesc
, "TxDescriptor data d1: %#llx d2: %#llx\n", desc
->d1
, desc
->d2
);
903 if (!TxdOp::eop(desc
)) {
904 // This only supports two descriptors per tx packet
905 assert(pktPtr
->length
== 0);
906 pktPtr
->length
= TxdOp::getLen(desc
);
907 unusedCache
.pop_front();
908 usedCache
.push_back(desc
);
913 DPRINTF(EthernetDesc
, "Partial Packet Descriptor Done\n");
918 // Set the length of the data in the EtherPacket
919 pktPtr
->length
+= TxdOp::getLen(desc
);
921 // no support for vlans
922 assert(!TxdOp::vle(desc
));
924 // we alway report status
925 assert(TxdOp::rs(desc
));
927 // we only support single packet descriptors at this point
928 assert(TxdOp::eop(desc
));
930 // set that this packet is done
933 DPRINTF(EthernetDesc
, "TxDescriptor data d1: %#llx d2: %#llx\n", desc
->d1
, desc
->d2
);
935 if (DTRACE(EthernetDesc
)) {
938 DPRINTF(EthernetDesc
, "Proccesing Ip packet with Id=%d\n",
941 DPRINTF(EthernetSM
, "Proccesing Non-Ip packet\n");
944 // Checksums are only ofloaded for new descriptor types
945 if (TxdOp::isData(desc
) && ( TxdOp::ixsm(desc
) || TxdOp::txsm(desc
)) ) {
946 DPRINTF(EthernetDesc
, "Calculating checksums for packet\n");
949 if (TxdOp::ixsm(desc
)) {
952 DPRINTF(EthernetDesc
, "Calculated IP checksum\n");
954 if (TxdOp::txsm(desc
)) {
959 tcp
->sum(cksum(tcp
));
960 DPRINTF(EthernetDesc
, "Calculated TCP checksum\n");
965 udp
->sum(cksum(udp
));
966 DPRINTF(EthernetDesc
, "Calculated UDP checksum\n");
971 if (TxdOp::ide(desc
)) {
972 // Deal with the rx timer interrupts
973 DPRINTF(EthernetDesc
, "Descriptor had IDE set\n");
974 if (igbe
->regs
.tidv
.idv()) {
975 DPRINTF(EthernetDesc
, "setting tidv\n");
976 igbe
->tidvEvent
.reschedule(curTick
+ igbe
->regs
.tidv
.idv() *
977 igbe
->intClock(), true);
980 if (igbe
->regs
.tadv
.idv() && igbe
->regs
.tidv
.idv()) {
981 DPRINTF(EthernetDesc
, "setting tadv\n");
982 if (!igbe
->tadvEvent
.scheduled())
983 igbe
->tadvEvent
.schedule(curTick
+ igbe
->regs
.tadv
.idv() *
990 unusedCache
.pop_front();
991 usedCache
.push_back(desc
);
996 DPRINTF(EthernetDesc
, "Descriptor Done\n");
998 if (igbe
->regs
.txdctl
.wthresh() == 0) {
999 DPRINTF(EthernetDesc
, "WTHRESH == 0, writing back descriptor\n");
1001 } else if (igbe
->regs
.txdctl
.wthresh() >= usedCache
.size()) {
1002 DPRINTF(EthernetDesc
, "used > WTHRESH, writing back descriptor\n");
1003 writeback((igbe
->cacheBlockSize()-1)>>4);
1010 IGbE::TxDescCache::serialize(std::ostream
&os
)
1012 DescCache
<TxDesc
>::serialize(os
);
1013 SERIALIZE_SCALAR(pktDone
);
1014 SERIALIZE_SCALAR(isTcp
);
1015 SERIALIZE_SCALAR(pktWaiting
);
1019 IGbE::TxDescCache::unserialize(Checkpoint
*cp
, const std::string
§ion
)
1021 DescCache
<TxDesc
>::unserialize(cp
, section
);
1022 UNSERIALIZE_SCALAR(pktDone
);
1023 UNSERIALIZE_SCALAR(isTcp
);
1024 UNSERIALIZE_SCALAR(pktWaiting
);
1028 IGbE::TxDescCache::packetAvailable()
1038 IGbE::TxDescCache::enableSm()
1040 igbe
->txTick
= true;
1041 igbe
->restartClock();
1045 IGbE::TxDescCache::hasOutstandingEvents()
1047 return pktEvent
.scheduled() || wbEvent
.scheduled() ||
1048 fetchEvent
.scheduled();
1052 ///////////////////////////////////// IGbE /////////////////////////////////
1055 IGbE::restartClock()
1057 if (!tickEvent
.scheduled() && (rxTick
|| txTick
|| txFifoTick
) && getState() ==
1059 tickEvent
.schedule((curTick
/cycles(1)) * cycles(1) + cycles(1));
1063 IGbE::drain(Event
*de
)
1066 count
= pioPort
->drain(de
) + dmaPort
->drain(de
);
1067 if (rxDescCache
.hasOutstandingEvents() ||
1068 txDescCache
.hasOutstandingEvents()) {
1077 if (tickEvent
.scheduled())
1078 tickEvent
.deschedule();
1081 changeState(Draining
);
1083 changeState(Drained
);
1091 SimObject::resume();
1106 if (rxDescCache
.hasOutstandingEvents() ||
1107 txDescCache
.hasOutstandingEvents()) {
1108 drainEvent
->process();
1114 IGbE::txStateMachine()
1116 if (!regs
.tctl
.en()) {
1118 DPRINTF(EthernetSM
, "TXS: TX disabled, stopping ticking\n");
1122 // If we have a packet available and it's length is not 0 (meaning it's not
1123 // a multidescriptor packet) put it in the fifo, otherwise an the next
1124 // iteration we'll get the rest of the data
1125 if (txPacket
&& txDescCache
.packetAvailable() && txPacket
->length
) {
1127 DPRINTF(EthernetSM
, "TXS: packet placed in TX FIFO\n");
1128 success
= txFifo
.push(txPacket
);
1132 txDescCache
.writeback((cacheBlockSize()-1)>>4);
1136 // Only support descriptor granularity
1137 assert(regs
.txdctl
.gran());
1138 if (regs
.txdctl
.lwthresh() && txDescCache
.descLeft() < (regs
.txdctl
.lwthresh() * 8)) {
1139 DPRINTF(EthernetSM
, "TXS: LWTHRESH caused posting of TXDLOW\n");
1140 postInterrupt(IT_TXDLOW
);
1144 txPacket
= new EthPacketData(16384);
1147 if (!txDescCache
.packetWaiting()) {
1148 if (txDescCache
.descLeft() == 0) {
1149 DPRINTF(EthernetSM
, "TXS: No descriptors left in ring, forcing "
1150 "writeback stopping ticking and posting TXQE\n");
1151 txDescCache
.writeback(0);
1153 postInterrupt(IT_TXQE
, true);
1158 if (!(txDescCache
.descUnused())) {
1159 DPRINTF(EthernetSM
, "TXS: No descriptors available in cache, fetching and stopping ticking\n");
1161 txDescCache
.fetchDescriptors();
1166 size
= txDescCache
.getPacketSize();
1167 if (size
> 0 && txFifo
.avail() > size
) {
1168 DPRINTF(EthernetSM
, "TXS: Reserving %d bytes in FIFO and begining "
1169 "DMA of next packet\n", size
);
1170 txFifo
.reserve(size
);
1171 txDescCache
.getPacketData(txPacket
);
1172 } else if (size
<= 0) {
1173 DPRINTF(EthernetSM
, "TXS: No packets to get, writing back used descriptors\n");
1174 txDescCache
.writeback(0);
1176 DPRINTF(EthernetSM
, "TXS: FIFO full, stopping ticking until space "
1177 "available in FIFO\n");
1178 txDescCache
.writeback((cacheBlockSize()-1)>>4);
1185 DPRINTF(EthernetSM
, "TXS: Nothing to do, stopping ticking\n");
1190 IGbE::ethRxPkt(EthPacketPtr pkt
)
1192 DPRINTF(Ethernet
, "RxFIFO: Receiving pcakte from wire\n");
1193 if (!regs
.rctl
.en()) {
1194 DPRINTF(Ethernet
, "RxFIFO: RX not enabled, dropping\n");
1198 // restart the state machines if they are stopped
1200 if ((rxTick
|| txTick
) && !tickEvent
.scheduled()) {
1201 DPRINTF(EthernetSM
, "RXS: received packet into fifo, starting ticking\n");
1205 if (!rxFifo
.push(pkt
)) {
1206 DPRINTF(Ethernet
, "RxFIFO: Packet won't fit in fifo... dropped\n");
1207 postInterrupt(IT_RXO
, true);
1215 IGbE::rxStateMachine()
1217 if (!regs
.rctl
.en()) {
1219 DPRINTF(EthernetSM
, "RXS: RX disabled, stopping ticking\n");
1223 // If the packet is done check for interrupts/descriptors/etc
1224 if (rxDescCache
.packetDone()) {
1225 rxDmaPacket
= false;
1226 DPRINTF(EthernetSM
, "RXS: Packet completed DMA to memory\n");
1227 int descLeft
= rxDescCache
.descLeft();
1228 switch (regs
.rctl
.rdmts()) {
1229 case 2: if (descLeft
> .125 * regs
.rdlen()) break;
1230 case 1: if (descLeft
> .250 * regs
.rdlen()) break;
1231 case 0: if (descLeft
> .500 * regs
.rdlen()) break;
1232 DPRINTF(Ethernet
, "RXS: Interrupting (RXDMT) because of descriptors left\n");
1233 postInterrupt(IT_RXDMT
);
1237 if (descLeft
== 0) {
1238 DPRINTF(EthernetSM
, "RXS: No descriptors left in ring, forcing"
1239 " writeback and stopping ticking\n");
1240 rxDescCache
.writeback(0);
1244 // only support descriptor granulaties
1245 assert(regs
.rxdctl
.gran());
1247 if (regs
.rxdctl
.wthresh() >= rxDescCache
.descUsed()) {
1248 DPRINTF(EthernetSM
, "RXS: Writing back because WTHRESH >= descUsed\n");
1249 if (regs
.rxdctl
.wthresh() < (cacheBlockSize()>>4))
1250 rxDescCache
.writeback(regs
.rxdctl
.wthresh()-1);
1252 rxDescCache
.writeback((cacheBlockSize()-1)>>4);
1255 if ((rxDescCache
.descUnused() < regs
.rxdctl
.pthresh()) &&
1256 ((rxDescCache
.descLeft() - rxDescCache
.descUnused()) > regs
.rxdctl
.hthresh())) {
1257 DPRINTF(EthernetSM
, "RXS: Fetching descriptors because descUnused < PTHRESH\n");
1258 rxDescCache
.fetchDescriptors();
1261 if (rxDescCache
.descUnused() == 0) {
1262 DPRINTF(EthernetSM
, "RXS: No descriptors available in cache, "
1263 "fetching descriptors and stopping ticking\n");
1265 rxDescCache
.fetchDescriptors();
1271 DPRINTF(EthernetSM
, "RXS: stopping ticking until packet DMA completes\n");
1276 if (!rxDescCache
.descUnused()) {
1277 DPRINTF(EthernetSM
, "RXS: No descriptors available in cache, stopping ticking\n");
1279 DPRINTF(EthernetSM
, "RXS: No descriptors available, fetching\n");
1280 rxDescCache
.fetchDescriptors();
1284 if (rxFifo
.empty()) {
1285 DPRINTF(EthernetSM
, "RXS: RxFIFO empty, stopping ticking\n");
1291 pkt
= rxFifo
.front();
1293 DPRINTF(EthernetSM
, "RXS: Writing packet into memory\n");
1294 if (!rxDescCache
.writePacket(pkt
)) {
1298 DPRINTF(EthernetSM
, "RXS: Removing packet from FIFO\n");
1300 DPRINTF(EthernetSM
, "RXS: stopping ticking until packet DMA completes\n");
1308 if (txFifo
.empty()) {
1314 if (etherInt
->sendPacket(txFifo
.front())) {
1315 DPRINTF(EthernetSM
, "TxFIFO: Successful transmit, bytes available in fifo: %d\n",
1319 // We'll get woken up when the packet ethTxDone() gets called
1328 DPRINTF(EthernetSM
, "IGbE: -------------- Cycle --------------\n");
1340 if (rxTick
|| txTick
|| txFifoTick
)
1341 tickEvent
.schedule(curTick
+ cycles(1));
1347 // restart the tx state machines if they are stopped
1348 // fifo to send another packet
1349 // tx sm to put more data into the fifo
1354 DPRINTF(EthernetSM
, "TxFIFO: Transmission complete\n");
1358 IGbE::serialize(std::ostream
&os
)
1360 PciDev::serialize(os
);
1363 SERIALIZE_SCALAR(eeOpBits
);
1364 SERIALIZE_SCALAR(eeAddrBits
);
1365 SERIALIZE_SCALAR(eeDataBits
);
1366 SERIALIZE_SCALAR(eeOpcode
);
1367 SERIALIZE_SCALAR(eeAddr
);
1368 SERIALIZE_ARRAY(flash
,iGbReg::EEPROM_SIZE
);
1370 rxFifo
.serialize("rxfifo", os
);
1371 txFifo
.serialize("txfifo", os
);
1373 bool txPktExists
= txPacket
;
1374 SERIALIZE_SCALAR(txPktExists
);
1376 txPacket
->serialize("txpacket", os
);
1378 Tick rdtr_time
= 0, radv_time
= 0, tidv_time
= 0, tadv_time
= 0,
1381 if (rdtrEvent
.scheduled())
1382 rdtr_time
= rdtrEvent
.when();
1383 SERIALIZE_SCALAR(rdtr_time
);
1385 if (radvEvent
.scheduled())
1386 radv_time
= radvEvent
.when();
1387 SERIALIZE_SCALAR(radv_time
);
1389 if (tidvEvent
.scheduled())
1390 rdtr_time
= tidvEvent
.when();
1391 SERIALIZE_SCALAR(tidv_time
);
1393 if (tadvEvent
.scheduled())
1394 rdtr_time
= tadvEvent
.when();
1395 SERIALIZE_SCALAR(tadv_time
);
1397 if (interEvent
.scheduled())
1398 rdtr_time
= interEvent
.when();
1399 SERIALIZE_SCALAR(inter_time
);
1401 nameOut(os
, csprintf("%s.TxDescCache", name()));
1402 txDescCache
.serialize(os
);
1404 nameOut(os
, csprintf("%s.RxDescCache", name()));
1405 rxDescCache
.serialize(os
);
1409 IGbE::unserialize(Checkpoint
*cp
, const std::string
§ion
)
1411 PciDev::unserialize(cp
, section
);
1413 regs
.unserialize(cp
, section
);
1414 UNSERIALIZE_SCALAR(eeOpBits
);
1415 UNSERIALIZE_SCALAR(eeAddrBits
);
1416 UNSERIALIZE_SCALAR(eeDataBits
);
1417 UNSERIALIZE_SCALAR(eeOpcode
);
1418 UNSERIALIZE_SCALAR(eeAddr
);
1419 UNSERIALIZE_ARRAY(flash
,iGbReg::EEPROM_SIZE
);
1421 rxFifo
.unserialize("rxfifo", cp
, section
);
1422 txFifo
.unserialize("txfifo", cp
, section
);
1425 UNSERIALIZE_SCALAR(txPktExists
);
1427 txPacket
= new EthPacketData(16384);
1428 txPacket
->unserialize("txpacket", cp
, section
);
1435 Tick rdtr_time
, radv_time
, tidv_time
, tadv_time
, inter_time
;
1436 UNSERIALIZE_SCALAR(rdtr_time
);
1437 UNSERIALIZE_SCALAR(radv_time
);
1438 UNSERIALIZE_SCALAR(tidv_time
);
1439 UNSERIALIZE_SCALAR(tadv_time
);
1440 UNSERIALIZE_SCALAR(inter_time
);
1443 rdtrEvent
.schedule(rdtr_time
);
1446 radvEvent
.schedule(radv_time
);
1449 tidvEvent
.schedule(tidv_time
);
1452 tadvEvent
.schedule(tadv_time
);
1455 interEvent
.schedule(inter_time
);
1457 txDescCache
.unserialize(cp
, csprintf("%s.TxDescCache", section
));
1459 rxDescCache
.unserialize(cp
, csprintf("%s.RxDescCache", section
));
1463 IGbEParams::create()
1465 return new IGbE(this);