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 "debug/Drain.hh"
48 #include "debug/EthernetAll.hh"
49 #include "dev/i8254xGBe.hh"
50 #include "mem/packet.hh"
51 #include "mem/packet_access.hh"
52 #include "params/IGbE.hh"
53 #include "sim/stats.hh"
54 #include "sim/system.hh"
56 using namespace iGbReg
;
59 IGbE::IGbE(const Params
*p
)
60 : EtherDevice(p
), etherInt(NULL
), drainManager(NULL
),
61 useFlowControl(p
->use_flow_control
),
62 rxFifo(p
->rx_fifo_size
), txFifo(p
->tx_fifo_size
), rxTick(false),
63 txTick(false), txFifoTick(false), rxDmaPacket(false), pktOffset(0),
64 fetchDelay(p
->fetch_delay
), wbDelay(p
->wb_delay
),
65 fetchCompDelay(p
->fetch_comp_delay
), wbCompDelay(p
->wb_comp_delay
),
66 rxWriteDelay(p
->rx_write_delay
), txReadDelay(p
->tx_read_delay
),
67 rdtrEvent(this), radvEvent(this),
68 tadvEvent(this), tidvEvent(this), tickEvent(this), interEvent(this),
69 rxDescCache(this, name()+".RxDesc", p
->rx_desc_cache_size
),
70 txDescCache(this, name()+".TxDesc", p
->tx_desc_cache_size
),
73 etherInt
= new IGbEInt(name() + ".int", this);
75 // Initialized internal registers per Intel documentation
76 // All registers intialized to 0 by per register constructor
81 regs
.sts
.speed(3); // Say we're 1000Mbps
82 regs
.sts
.fd(1); // full duplex
83 regs
.sts
.lu(1); // link up
89 regs
.rxdctl
.wthresh(1);
103 // clear all 64 16 bit words of the eeprom
104 memset(&flash
, 0, EEPROM_SIZE
*2);
106 // Set the MAC address
107 memcpy(flash
, p
->hardware_address
.bytes(), ETH_ADDR_LEN
);
108 for (int x
= 0; x
< ETH_ADDR_LEN
/2; x
++)
109 flash
[x
] = htobe(flash
[x
]);
112 for (int x
= 0; x
< EEPROM_SIZE
; x
++)
113 csum
+= htobe(flash
[x
]);
116 // Magic happy checksum value
117 flash
[EEPROM_SIZE
-1] = htobe((uint16_t)(EEPROM_CSUM
- csum
));
119 // Store the MAC address as queue ID
120 macAddr
= p
->hardware_address
;
139 IGbE::getEthPort(const std::string
&if_name
, int idx
)
142 if (if_name
== "interface") {
143 if (etherInt
->getPeer())
144 panic("Port already connected to\n");
151 IGbE::writeConfig(PacketPtr pkt
)
153 int offset
= pkt
->getAddr() & PCI_CONFIG_SIZE
;
154 if (offset
< PCI_DEVICE_SPECIFIC
)
155 PciDev::writeConfig(pkt
);
157 panic("Device specific PCI config space not implemented.\n");
160 // Some work may need to be done here based for the pci COMMAND bits.
166 // Handy macro for range-testing register access addresses
167 #define IN_RANGE(val, base, len) (val >= base && val < (base + len))
170 IGbE::read(PacketPtr pkt
)
175 if (!getBAR(pkt
->getAddr(), bar
, daddr
))
176 panic("Invalid PCI memory access to unmapped memory.\n");
178 // Only Memory register BAR is allowed
181 // Only 32bit accesses allowed
182 assert(pkt
->getSize() == 4);
184 DPRINTF(Ethernet
, "Read device register %#X\n", daddr
);
189 // Handle read of register here
195 pkt
->set
<uint32_t>(regs
.ctrl());
198 pkt
->set
<uint32_t>(regs
.sts());
201 pkt
->set
<uint32_t>(regs
.eecd());
204 pkt
->set
<uint32_t>(regs
.eerd());
207 pkt
->set
<uint32_t>(regs
.ctrl_ext());
210 pkt
->set
<uint32_t>(regs
.mdic());
213 DPRINTF(Ethernet
, "Reading ICR. ICR=%#x IMR=%#x IAM=%#x IAME=%d\n",
214 regs
.icr(), regs
.imr
, regs
.iam
, regs
.ctrl_ext
.iame());
215 pkt
->set
<uint32_t>(regs
.icr());
216 if (regs
.icr
.int_assert() || regs
.imr
== 0) {
217 regs
.icr
= regs
.icr() & ~mask(30);
218 DPRINTF(Ethernet
, "Cleared ICR. ICR=%#x\n", regs
.icr());
220 if (regs
.ctrl_ext
.iame() && regs
.icr
.int_assert())
221 regs
.imr
&= ~regs
.iam
;
225 // This is only useful for MSI, but the driver reads it every time
226 // Just don't do anything
227 pkt
->set
<uint32_t>(0);
230 pkt
->set
<uint32_t>(regs
.itr());
233 pkt
->set
<uint32_t>(regs
.rctl());
236 pkt
->set
<uint32_t>(regs
.fcttv());
239 pkt
->set
<uint32_t>(regs
.tctl());
242 pkt
->set
<uint32_t>(regs
.pba());
246 pkt
->set
<uint32_t>(0); // We don't care, so just return 0
249 pkt
->set
<uint32_t>(regs
.fcrtl());
252 pkt
->set
<uint32_t>(regs
.fcrth());
255 pkt
->set
<uint32_t>(regs
.rdba
.rdbal());
258 pkt
->set
<uint32_t>(regs
.rdba
.rdbah());
261 pkt
->set
<uint32_t>(regs
.rdlen());
264 pkt
->set
<uint32_t>(regs
.srrctl());
267 pkt
->set
<uint32_t>(regs
.rdh());
270 pkt
->set
<uint32_t>(regs
.rdt());
273 pkt
->set
<uint32_t>(regs
.rdtr());
274 if (regs
.rdtr
.fpd()) {
275 rxDescCache
.writeback(0);
276 DPRINTF(EthernetIntr
,
277 "Posting interrupt because of RDTR.FPD write\n");
278 postInterrupt(IT_RXT
);
283 pkt
->set
<uint32_t>(regs
.rxdctl());
286 pkt
->set
<uint32_t>(regs
.radv());
289 pkt
->set
<uint32_t>(regs
.tdba
.tdbal());
292 pkt
->set
<uint32_t>(regs
.tdba
.tdbah());
295 pkt
->set
<uint32_t>(regs
.tdlen());
298 pkt
->set
<uint32_t>(regs
.tdh());
301 pkt
->set
<uint32_t>(regs
.txdca_ctl());
304 pkt
->set
<uint32_t>(regs
.tdt());
307 pkt
->set
<uint32_t>(regs
.tidv());
310 pkt
->set
<uint32_t>(regs
.txdctl());
313 pkt
->set
<uint32_t>(regs
.tadv());
316 pkt
->set
<uint32_t>(regs
.tdwba
& mask(32));
319 pkt
->set
<uint32_t>(regs
.tdwba
>> 32);
322 pkt
->set
<uint32_t>(regs
.rxcsum());
325 pkt
->set
<uint32_t>(regs
.rlpml
);
328 pkt
->set
<uint32_t>(regs
.rfctl());
331 pkt
->set
<uint32_t>(regs
.manc());
334 pkt
->set
<uint32_t>(regs
.swsm());
338 pkt
->set
<uint32_t>(regs
.fwsm());
341 pkt
->set
<uint32_t>(regs
.sw_fw_sync
);
344 if (!IN_RANGE(daddr
, REG_VFTA
, VLAN_FILTER_TABLE_SIZE
*4) &&
345 !IN_RANGE(daddr
, REG_RAL
, RCV_ADDRESS_TABLE_SIZE
*8) &&
346 !IN_RANGE(daddr
, REG_MTA
, MULTICAST_TABLE_SIZE
*4) &&
347 !IN_RANGE(daddr
, REG_CRCERRS
, STATS_REGS_SIZE
))
348 panic("Read request to unknown register number: %#x\n", daddr
);
350 pkt
->set
<uint32_t>(0);
353 pkt
->makeAtomicResponse();
358 IGbE::write(PacketPtr pkt
)
364 if (!getBAR(pkt
->getAddr(), bar
, daddr
))
365 panic("Invalid PCI memory access to unmapped memory.\n");
367 // Only Memory register BAR is allowed
370 // Only 32bit accesses allowed
371 assert(pkt
->getSize() == sizeof(uint32_t));
373 DPRINTF(Ethernet
, "Wrote device register %#X value %#X\n",
374 daddr
, pkt
->get
<uint32_t>());
377 // Handle write of register here
379 uint32_t val
= pkt
->get
<uint32_t>();
387 if (regs
.ctrl
.tfce())
388 warn("TX Flow control enabled, should implement\n");
389 if (regs
.ctrl
.rfce())
390 warn("RX Flow control enabled, should implement\n");
400 oldClk
= regs
.eecd
.sk();
402 // See if this is a eeprom access and emulate accordingly
403 if (!oldClk
&& regs
.eecd
.sk()) {
405 eeOpcode
= eeOpcode
<< 1 | regs
.eecd
.din();
407 } else if (eeAddrBits
< 8 && eeOpcode
== EEPROM_READ_OPCODE_SPI
) {
408 eeAddr
= eeAddr
<< 1 | regs
.eecd
.din();
410 } else if (eeDataBits
< 16 && eeOpcode
== EEPROM_READ_OPCODE_SPI
) {
411 assert(eeAddr
>>1 < EEPROM_SIZE
);
412 DPRINTF(EthernetEEPROM
, "EEPROM bit read: %d word: %#X\n",
413 flash
[eeAddr
>>1] >> eeDataBits
& 0x1,
415 regs
.eecd
.dout((flash
[eeAddr
>>1] >> (15-eeDataBits
)) & 0x1);
417 } else if (eeDataBits
< 8 && eeOpcode
== EEPROM_RDSR_OPCODE_SPI
) {
421 panic("What's going on with eeprom interface? opcode:"
422 " %#x:%d addr: %#x:%d, data: %d\n", (uint32_t)eeOpcode
,
423 (uint32_t)eeOpBits
, (uint32_t)eeAddr
,
424 (uint32_t)eeAddrBits
, (uint32_t)eeDataBits
);
426 // Reset everything for the next command
427 if ((eeDataBits
== 16 && eeOpcode
== EEPROM_READ_OPCODE_SPI
) ||
428 (eeDataBits
== 8 && eeOpcode
== EEPROM_RDSR_OPCODE_SPI
)) {
436 DPRINTF(EthernetEEPROM
, "EEPROM: opcode: %#X:%d addr: %#X:%d\n",
437 (uint32_t)eeOpcode
, (uint32_t) eeOpBits
,
438 (uint32_t)eeAddr
>>1, (uint32_t)eeAddrBits
);
439 if (eeOpBits
== 8 && !(eeOpcode
== EEPROM_READ_OPCODE_SPI
||
440 eeOpcode
== EEPROM_RDSR_OPCODE_SPI
))
441 panic("Unknown eeprom opcode: %#X:%d\n", (uint32_t)eeOpcode
,
446 // If driver requests eeprom access, immediately give it to it
447 regs
.eecd
.ee_gnt(regs
.eecd
.ee_req());
451 if (regs
.eerd
.start()) {
453 assert(regs
.eerd
.addr() < EEPROM_SIZE
);
454 regs
.eerd
.data(flash
[regs
.eerd
.addr()]);
456 DPRINTF(EthernetEEPROM
, "EEPROM: read addr: %#X data %#x\n",
457 regs
.eerd
.addr(), regs
.eerd
.data());
463 panic("No support for interrupt on mdic complete\n");
464 if (regs
.mdic
.phyadd() != 1)
465 panic("No support for reading anything but phy\n");
466 DPRINTF(Ethernet
, "%s phy address %x\n",
467 regs
.mdic
.op() == 1 ? "Writing" : "Reading",
469 switch (regs
.mdic
.regadd()) {
471 regs
.mdic
.data(0x796D); // link up
474 regs
.mdic
.data(params()->phy_pid
);
477 regs
.mdic
.data(params()->phy_epid
);
480 regs
.mdic
.data(0x7C00);
483 regs
.mdic
.data(0x3000);
486 regs
.mdic
.data(0x180); // some random length
494 DPRINTF(Ethernet
, "Writing ICR. ICR=%#x IMR=%#x IAM=%#x IAME=%d\n",
495 regs
.icr(), regs
.imr
, regs
.iam
, regs
.ctrl_ext
.iame());
496 if (regs
.ctrl_ext
.iame())
497 regs
.imr
&= ~regs
.iam
;
498 regs
.icr
= ~bits(val
,30,0) & regs
.icr();
505 DPRINTF(EthernetIntr
, "Posting interrupt because of ICS write\n");
506 postInterrupt((IntTypes
)val
);
522 if (regs
.rctl
.rst()) {
524 DPRINTF(EthernetSM
, "RXS: Got RESET!\n");
542 if (regs
.tctl
.en() && !oldtctl
.en()) {
548 regs
.pba
.txa(64 - regs
.pba
.rxa());
558 ; // We don't care, so don't store anything
561 warn("Writing to IVAR0, ignoring...\n");
570 regs
.rdba
.rdbal( val
& ~mask(4));
571 rxDescCache
.areaChanged();
574 regs
.rdba
.rdbah(val
);
575 rxDescCache
.areaChanged();
578 regs
.rdlen
= val
& ~mask(7);
579 rxDescCache
.areaChanged();
586 rxDescCache
.areaChanged();
590 DPRINTF(EthernetSM
, "RXS: RDT Updated.\n");
591 if (getDrainState() == Drainable::Running
) {
592 DPRINTF(EthernetSM
, "RXS: RDT Fetching Descriptors!\n");
593 rxDescCache
.fetchDescriptors();
595 DPRINTF(EthernetSM
, "RXS: RDT NOT Fetching Desc b/c draining!\n");
608 regs
.tdba
.tdbal( val
& ~mask(4));
609 txDescCache
.areaChanged();
612 regs
.tdba
.tdbah(val
);
613 txDescCache
.areaChanged();
616 regs
.tdlen
= val
& ~mask(7);
617 txDescCache
.areaChanged();
621 txDescCache
.areaChanged();
624 regs
.txdca_ctl
= val
;
625 if (regs
.txdca_ctl
.enabled())
626 panic("No support for DCA\n");
630 DPRINTF(EthernetSM
, "TXS: TX Tail pointer updated\n");
631 if (getDrainState() == Drainable::Running
) {
632 DPRINTF(EthernetSM
, "TXS: TDT Fetching Descriptors!\n");
633 txDescCache
.fetchDescriptors();
635 DPRINTF(EthernetSM
, "TXS: TDT NOT Fetching Desc b/c draining!\n");
648 regs
.tdwba
&= ~mask(32);
650 txDescCache
.completionWriteback(regs
.tdwba
& ~mask(1),
651 regs
.tdwba
& mask(1));
654 regs
.tdwba
&= mask(32);
655 regs
.tdwba
|= (uint64_t)val
<< 32;
656 txDescCache
.completionWriteback(regs
.tdwba
& ~mask(1),
657 regs
.tdwba
& mask(1));
667 if (regs
.rfctl
.exsten())
668 panic("Extended RX descriptors not implemented\n");
675 if (regs
.fwsm
.eep_fw_semaphore())
676 regs
.swsm
.swesmbi(0);
679 regs
.sw_fw_sync
= val
;
682 if (!IN_RANGE(daddr
, REG_VFTA
, VLAN_FILTER_TABLE_SIZE
*4) &&
683 !IN_RANGE(daddr
, REG_RAL
, RCV_ADDRESS_TABLE_SIZE
*8) &&
684 !IN_RANGE(daddr
, REG_MTA
, MULTICAST_TABLE_SIZE
*4))
685 panic("Write request to unknown register number: %#x\n", daddr
);
688 pkt
->makeAtomicResponse();
693 IGbE::postInterrupt(IntTypes t
, bool now
)
697 // Interrupt is already pending
698 if (t
& regs
.icr() && !now
)
701 regs
.icr
= regs
.icr() | t
;
703 Tick itr_interval
= SimClock::Int::ns
* 256 * regs
.itr
.interval();
704 DPRINTF(EthernetIntr
,
705 "EINT: postInterrupt() curTick(): %d itr: %d interval: %d\n",
706 curTick(), regs
.itr
.interval(), itr_interval
);
708 if (regs
.itr
.interval() == 0 || now
||
709 lastInterrupt
+ itr_interval
<= curTick()) {
710 if (interEvent
.scheduled()) {
711 deschedule(interEvent
);
715 Tick int_time
= lastInterrupt
+ itr_interval
;
716 assert(int_time
> 0);
717 DPRINTF(EthernetIntr
, "EINT: Scheduling timer interrupt for tick %d\n",
719 if (!interEvent
.scheduled()) {
720 schedule(interEvent
, int_time
);
726 IGbE::delayIntEvent()
738 if (!(regs
.icr() & regs
.imr
)) {
739 DPRINTF(Ethernet
, "Interrupt Masked. Not Posting\n");
743 DPRINTF(Ethernet
, "Posting Interrupt\n");
746 if (interEvent
.scheduled()) {
747 deschedule(interEvent
);
750 if (rdtrEvent
.scheduled()) {
752 deschedule(rdtrEvent
);
754 if (radvEvent
.scheduled()) {
756 deschedule(radvEvent
);
758 if (tadvEvent
.scheduled()) {
760 deschedule(tadvEvent
);
762 if (tidvEvent
.scheduled()) {
764 deschedule(tidvEvent
);
767 regs
.icr
.int_assert(1);
768 DPRINTF(EthernetIntr
, "EINT: Posting interrupt to CPU now. Vector %#x\n",
773 lastInterrupt
= curTick();
779 if (regs
.icr
.int_assert()) {
780 regs
.icr
.int_assert(0);
781 DPRINTF(EthernetIntr
,
782 "EINT: Clearing interrupt to CPU now. Vector %#x\n",
791 DPRINTF(Ethernet
, "Checking interrupts icr: %#x imr: %#x\n", regs
.icr(),
793 // Check if we need to clear the cpu interrupt
794 if (!(regs
.icr() & regs
.imr
)) {
795 DPRINTF(Ethernet
, "Mask cleaned all interrupts\n");
796 if (interEvent
.scheduled())
797 deschedule(interEvent
);
798 if (regs
.icr
.int_assert())
801 DPRINTF(Ethernet
, "ITR = %#X itr.interval = %#X\n",
802 regs
.itr(), regs
.itr
.interval());
804 if (regs
.icr() & regs
.imr
) {
805 if (regs
.itr
.interval() == 0) {
809 "Possibly scheduling interrupt because of imr write\n");
810 if (!interEvent
.scheduled()) {
811 Tick t
= curTick() + SimClock::Int::ns
* 256 * regs
.itr
.interval();
812 DPRINTF(Ethernet
, "Scheduling for %d\n", t
);
813 schedule(interEvent
, t
);
820 ///////////////////////////// IGbE::DescCache //////////////////////////////
823 IGbE::DescCache
<T
>::DescCache(IGbE
*i
, const std::string n
, int s
)
824 : igbe(i
), _name(n
), cachePnt(0), size(s
), curFetching(0),
825 wbOut(0), pktPtr(NULL
), wbDelayEvent(this),
826 fetchDelayEvent(this), fetchEvent(this), wbEvent(this)
828 fetchBuf
= new T
[size
];
833 IGbE::DescCache
<T
>::~DescCache()
842 IGbE::DescCache
<T
>::areaChanged()
844 if (usedCache
.size() > 0 || curFetching
|| wbOut
)
845 panic("Descriptor Address, Length or Head changed. Bad\n");
852 IGbE::DescCache
<T
>::writeback(Addr aMask
)
854 int curHead
= descHead();
855 int max_to_wb
= usedCache
.size();
857 // Check if this writeback is less restrictive that the previous
858 // and if so setup another one immediately following it
860 if (aMask
< wbAlignment
) {
864 DPRINTF(EthernetDesc
,
865 "Writing back already in process, returning\n");
873 DPRINTF(EthernetDesc
, "Writing back descriptors head: %d tail: "
874 "%d len: %d cachePnt: %d max_to_wb: %d descleft: %d\n",
875 curHead
, descTail(), descLen(), cachePnt
, max_to_wb
,
878 if (max_to_wb
+ curHead
>= descLen()) {
879 max_to_wb
= descLen() - curHead
;
881 // this is by definition aligned correctly
882 } else if (wbAlignment
!= 0) {
883 // align the wb point to the mask
884 max_to_wb
= max_to_wb
& ~wbAlignment
;
887 DPRINTF(EthernetDesc
, "Writing back %d descriptors\n", max_to_wb
);
889 if (max_to_wb
<= 0) {
890 if (usedCache
.size())
891 igbe
->anBegin(annSmWb
, "Wait Alignment", CPA::FL_WAIT
);
893 igbe
->anWe(annSmWb
, annUsedCacheQ
);
899 assert(!wbDelayEvent
.scheduled());
900 igbe
->schedule(wbDelayEvent
, curTick() + igbe
->wbDelay
);
901 igbe
->anBegin(annSmWb
, "Prepare Writeback Desc");
906 IGbE::DescCache
<T
>::writeback1()
908 // If we're draining delay issuing this DMA
909 if (igbe
->getDrainState() != Drainable::Running
) {
910 igbe
->schedule(wbDelayEvent
, curTick() + igbe
->wbDelay
);
914 DPRINTF(EthernetDesc
, "Begining DMA of %d descriptors\n", wbOut
);
916 for (int x
= 0; x
< wbOut
; x
++) {
917 assert(usedCache
.size());
918 memcpy(&wbBuf
[x
], usedCache
[x
], sizeof(T
));
919 igbe
->anPq(annSmWb
, annUsedCacheQ
);
920 igbe
->anPq(annSmWb
, annDescQ
);
921 igbe
->anQ(annSmWb
, annUsedDescQ
);
925 igbe
->anBegin(annSmWb
, "Writeback Desc DMA");
928 igbe
->dmaWrite(pciToDma(descBase() + descHead() * sizeof(T
)),
929 wbOut
* sizeof(T
), &wbEvent
, (uint8_t*)wbBuf
,
935 IGbE::DescCache
<T
>::fetchDescriptors()
940 DPRINTF(EthernetDesc
,
941 "Currently fetching %d descriptors, returning\n",
946 if (descTail() >= cachePnt
)
947 max_to_fetch
= descTail() - cachePnt
;
949 max_to_fetch
= descLen() - cachePnt
;
951 size_t free_cache
= size
- usedCache
.size() - unusedCache
.size();
954 igbe
->anWe(annSmFetch
, annUnusedDescQ
);
956 igbe
->anPq(annSmFetch
, annUnusedDescQ
, max_to_fetch
);
960 igbe
->anWf(annSmFetch
, annDescQ
);
962 igbe
->anRq(annSmFetch
, annDescQ
, free_cache
);
965 max_to_fetch
= std::min(max_to_fetch
, free_cache
);
968 DPRINTF(EthernetDesc
, "Fetching descriptors head: %d tail: "
969 "%d len: %d cachePnt: %d max_to_fetch: %d descleft: %d\n",
970 descHead(), descTail(), descLen(), cachePnt
,
971 max_to_fetch
, descLeft());
974 if (max_to_fetch
== 0)
977 // So we don't have two descriptor fetches going on at once
978 curFetching
= max_to_fetch
;
980 assert(!fetchDelayEvent
.scheduled());
981 igbe
->schedule(fetchDelayEvent
, curTick() + igbe
->fetchDelay
);
982 igbe
->anBegin(annSmFetch
, "Prepare Fetch Desc");
987 IGbE::DescCache
<T
>::fetchDescriptors1()
989 // If we're draining delay issuing this DMA
990 if (igbe
->getDrainState() != Drainable::Running
) {
991 igbe
->schedule(fetchDelayEvent
, curTick() + igbe
->fetchDelay
);
995 igbe
->anBegin(annSmFetch
, "Fetch Desc");
997 DPRINTF(EthernetDesc
, "Fetching descriptors at %#x (%#x), size: %#x\n",
998 descBase() + cachePnt
* sizeof(T
),
999 pciToDma(descBase() + cachePnt
* sizeof(T
)),
1000 curFetching
* sizeof(T
));
1001 assert(curFetching
);
1002 igbe
->dmaRead(pciToDma(descBase() + cachePnt
* sizeof(T
)),
1003 curFetching
* sizeof(T
), &fetchEvent
, (uint8_t*)fetchBuf
,
1004 igbe
->fetchCompDelay
);
1009 IGbE::DescCache
<T
>::fetchComplete()
1012 igbe
->anBegin(annSmFetch
, "Fetch Complete");
1013 for (int x
= 0; x
< curFetching
; x
++) {
1015 memcpy(newDesc
, &fetchBuf
[x
], sizeof(T
));
1016 unusedCache
.push_back(newDesc
);
1017 igbe
->anDq(annSmFetch
, annUnusedDescQ
);
1018 igbe
->anQ(annSmFetch
, annUnusedCacheQ
);
1019 igbe
->anQ(annSmFetch
, annDescQ
);
1024 int oldCp
= cachePnt
;
1027 cachePnt
+= curFetching
;
1028 assert(cachePnt
<= descLen());
1029 if (cachePnt
== descLen())
1034 DPRINTF(EthernetDesc
, "Fetching complete cachePnt %d -> %d\n",
1037 if ((descTail() >= cachePnt
? (descTail() - cachePnt
) : (descLen() -
1040 igbe
->anWe(annSmFetch
, annUnusedDescQ
);
1041 } else if (!(size
- usedCache
.size() - unusedCache
.size())) {
1042 igbe
->anWf(annSmFetch
, annDescQ
);
1044 igbe
->anBegin(annSmFetch
, "Wait", CPA::FL_WAIT
);
1053 IGbE::DescCache
<T
>::wbComplete()
1056 igbe
->anBegin(annSmWb
, "Finish Writeback");
1058 long curHead
= descHead();
1060 long oldHead
= curHead
;
1063 for (int x
= 0; x
< wbOut
; x
++) {
1064 assert(usedCache
.size());
1065 delete usedCache
[0];
1066 usedCache
.pop_front();
1068 igbe
->anDq(annSmWb
, annUsedCacheQ
);
1069 igbe
->anDq(annSmWb
, annDescQ
);
1075 if (curHead
>= descLen())
1076 curHead
-= descLen();
1079 updateHead(curHead
);
1081 DPRINTF(EthernetDesc
, "Writeback complete curHead %d -> %d\n",
1084 // If we still have more to wb, call wb now
1088 DPRINTF(EthernetDesc
, "Writeback has more todo\n");
1089 writeback(wbAlignment
);
1094 if (usedCache
.size())
1095 igbe
->anBegin(annSmWb
, "Wait", CPA::FL_WAIT
);
1097 igbe
->anWe(annSmWb
, annUsedCacheQ
);
1104 IGbE::DescCache
<T
>::reset()
1106 DPRINTF(EthernetDesc
, "Reseting descriptor cache\n");
1107 for (typename
CacheType::size_type x
= 0; x
< usedCache
.size(); x
++)
1108 delete usedCache
[x
];
1109 for (typename
CacheType::size_type x
= 0; x
< unusedCache
.size(); x
++)
1110 delete unusedCache
[x
];
1113 unusedCache
.clear();
1121 IGbE::DescCache
<T
>::serialize(std::ostream
&os
)
1123 SERIALIZE_SCALAR(cachePnt
);
1124 SERIALIZE_SCALAR(curFetching
);
1125 SERIALIZE_SCALAR(wbOut
);
1126 SERIALIZE_SCALAR(moreToWb
);
1127 SERIALIZE_SCALAR(wbAlignment
);
1129 typename
CacheType::size_type usedCacheSize
= usedCache
.size();
1130 SERIALIZE_SCALAR(usedCacheSize
);
1131 for (typename
CacheType::size_type x
= 0; x
< usedCacheSize
; x
++) {
1132 arrayParamOut(os
, csprintf("usedCache_%d", x
),
1133 (uint8_t*)usedCache
[x
],sizeof(T
));
1136 typename
CacheType::size_type unusedCacheSize
= unusedCache
.size();
1137 SERIALIZE_SCALAR(unusedCacheSize
);
1138 for (typename
CacheType::size_type x
= 0; x
< unusedCacheSize
; x
++) {
1139 arrayParamOut(os
, csprintf("unusedCache_%d", x
),
1140 (uint8_t*)unusedCache
[x
],sizeof(T
));
1143 Tick fetch_delay
= 0, wb_delay
= 0;
1144 if (fetchDelayEvent
.scheduled())
1145 fetch_delay
= fetchDelayEvent
.when();
1146 SERIALIZE_SCALAR(fetch_delay
);
1147 if (wbDelayEvent
.scheduled())
1148 wb_delay
= wbDelayEvent
.when();
1149 SERIALIZE_SCALAR(wb_delay
);
1156 IGbE::DescCache
<T
>::unserialize(Checkpoint
*cp
, const std::string
§ion
)
1158 UNSERIALIZE_SCALAR(cachePnt
);
1159 UNSERIALIZE_SCALAR(curFetching
);
1160 UNSERIALIZE_SCALAR(wbOut
);
1161 UNSERIALIZE_SCALAR(moreToWb
);
1162 UNSERIALIZE_SCALAR(wbAlignment
);
1164 typename
CacheType::size_type usedCacheSize
;
1165 UNSERIALIZE_SCALAR(usedCacheSize
);
1167 for (typename
CacheType::size_type x
= 0; x
< usedCacheSize
; x
++) {
1169 arrayParamIn(cp
, section
, csprintf("usedCache_%d", x
),
1170 (uint8_t*)temp
,sizeof(T
));
1171 usedCache
.push_back(temp
);
1174 typename
CacheType::size_type unusedCacheSize
;
1175 UNSERIALIZE_SCALAR(unusedCacheSize
);
1176 for (typename
CacheType::size_type x
= 0; x
< unusedCacheSize
; x
++) {
1178 arrayParamIn(cp
, section
, csprintf("unusedCache_%d", x
),
1179 (uint8_t*)temp
,sizeof(T
));
1180 unusedCache
.push_back(temp
);
1182 Tick fetch_delay
= 0, wb_delay
= 0;
1183 UNSERIALIZE_SCALAR(fetch_delay
);
1184 UNSERIALIZE_SCALAR(wb_delay
);
1186 igbe
->schedule(fetchDelayEvent
, fetch_delay
);
1188 igbe
->schedule(wbDelayEvent
, wb_delay
);
1193 ///////////////////////////// IGbE::RxDescCache //////////////////////////////
1195 IGbE::RxDescCache::RxDescCache(IGbE
*i
, const std::string n
, int s
)
1196 : DescCache
<RxDesc
>(i
, n
, s
), pktDone(false), splitCount(0),
1197 pktEvent(this), pktHdrEvent(this), pktDataEvent(this)
1200 annSmFetch
= "RX Desc Fetch";
1201 annSmWb
= "RX Desc Writeback";
1202 annUnusedDescQ
= "RX Unused Descriptors";
1203 annUnusedCacheQ
= "RX Unused Descriptor Cache";
1204 annUsedCacheQ
= "RX Used Descriptor Cache";
1205 annUsedDescQ
= "RX Used Descriptors";
1206 annDescQ
= "RX Descriptors";
1210 IGbE::RxDescCache::pktSplitDone()
1213 DPRINTF(EthernetDesc
,
1214 "Part of split packet done: splitcount now %d\n", splitCount
);
1215 assert(splitCount
<= 2);
1216 if (splitCount
!= 2)
1219 DPRINTF(EthernetDesc
,
1220 "Part of split packet done: calling pktComplete()\n");
1225 IGbE::RxDescCache::writePacket(EthPacketPtr packet
, int pkt_offset
)
1227 assert(unusedCache
.size());
1228 //if (!unusedCache.size())
1233 unsigned buf_len
, hdr_len
;
1235 RxDesc
*desc
= unusedCache
.front();
1236 switch (igbe
->regs
.srrctl
.desctype()) {
1238 assert(pkt_offset
== 0);
1239 bytesCopied
= packet
->length
;
1240 DPRINTF(EthernetDesc
, "Packet Length: %d Desc Size: %d\n",
1241 packet
->length
, igbe
->regs
.rctl
.descSize());
1242 assert(packet
->length
< igbe
->regs
.rctl
.descSize());
1243 igbe
->dmaWrite(pciToDma(desc
->legacy
.buf
),
1244 packet
->length
, &pktEvent
, packet
->data
,
1245 igbe
->rxWriteDelay
);
1247 case RXDT_ADV_ONEBUF
:
1248 assert(pkt_offset
== 0);
1249 bytesCopied
= packet
->length
;
1250 buf_len
= igbe
->regs
.rctl
.lpe() ? igbe
->regs
.srrctl
.bufLen() :
1251 igbe
->regs
.rctl
.descSize();
1252 DPRINTF(EthernetDesc
, "Packet Length: %d srrctl: %#x Desc Size: %d\n",
1253 packet
->length
, igbe
->regs
.srrctl(), buf_len
);
1254 assert(packet
->length
< buf_len
);
1255 igbe
->dmaWrite(pciToDma(desc
->adv_read
.pkt
),
1256 packet
->length
, &pktEvent
, packet
->data
,
1257 igbe
->rxWriteDelay
);
1258 desc
->adv_wb
.header_len
= htole(0);
1259 desc
->adv_wb
.sph
= htole(0);
1260 desc
->adv_wb
.pkt_len
= htole((uint16_t)(pktPtr
->length
));
1262 case RXDT_ADV_SPLIT_A
:
1265 buf_len
= igbe
->regs
.rctl
.lpe() ? igbe
->regs
.srrctl
.bufLen() :
1266 igbe
->regs
.rctl
.descSize();
1267 hdr_len
= igbe
->regs
.rctl
.lpe() ? igbe
->regs
.srrctl
.hdrLen() : 0;
1268 DPRINTF(EthernetDesc
,
1269 "lpe: %d Packet Length: %d offset: %d srrctl: %#x "
1270 "hdr addr: %#x Hdr Size: %d desc addr: %#x Desc Size: %d\n",
1271 igbe
->regs
.rctl
.lpe(), packet
->length
, pkt_offset
,
1272 igbe
->regs
.srrctl(), desc
->adv_read
.hdr
, hdr_len
,
1273 desc
->adv_read
.pkt
, buf_len
);
1275 split_point
= hsplit(pktPtr
);
1277 if (packet
->length
<= hdr_len
) {
1278 bytesCopied
= packet
->length
;
1279 assert(pkt_offset
== 0);
1280 DPRINTF(EthernetDesc
, "Hdr split: Entire packet in header\n");
1281 igbe
->dmaWrite(pciToDma(desc
->adv_read
.hdr
),
1282 packet
->length
, &pktEvent
, packet
->data
,
1283 igbe
->rxWriteDelay
);
1284 desc
->adv_wb
.header_len
= htole((uint16_t)packet
->length
);
1285 desc
->adv_wb
.sph
= htole(0);
1286 desc
->adv_wb
.pkt_len
= htole(0);
1287 } else if (split_point
) {
1289 // we are only copying some data, header/data has already been
1292 std::min(packet
->length
- pkt_offset
, buf_len
);
1293 bytesCopied
+= max_to_copy
;
1294 DPRINTF(EthernetDesc
,
1295 "Hdr split: Continuing data buffer copy\n");
1296 igbe
->dmaWrite(pciToDma(desc
->adv_read
.pkt
),
1297 max_to_copy
, &pktEvent
,
1298 packet
->data
+ pkt_offset
, igbe
->rxWriteDelay
);
1299 desc
->adv_wb
.header_len
= htole(0);
1300 desc
->adv_wb
.pkt_len
= htole((uint16_t)max_to_copy
);
1301 desc
->adv_wb
.sph
= htole(0);
1304 std::min(packet
->length
- split_point
, buf_len
);
1305 bytesCopied
+= max_to_copy
+ split_point
;
1307 DPRINTF(EthernetDesc
, "Hdr split: splitting at %d\n",
1309 igbe
->dmaWrite(pciToDma(desc
->adv_read
.hdr
),
1310 split_point
, &pktHdrEvent
,
1311 packet
->data
, igbe
->rxWriteDelay
);
1312 igbe
->dmaWrite(pciToDma(desc
->adv_read
.pkt
),
1313 max_to_copy
, &pktDataEvent
,
1314 packet
->data
+ split_point
, igbe
->rxWriteDelay
);
1315 desc
->adv_wb
.header_len
= htole(split_point
);
1316 desc
->adv_wb
.sph
= 1;
1317 desc
->adv_wb
.pkt_len
= htole((uint16_t)(max_to_copy
));
1320 panic("Header split not fitting within header buffer or "
1321 "undecodable packet not fitting in header unsupported\n");
1325 panic("Unimplemnted RX receive buffer type: %d\n",
1326 igbe
->regs
.srrctl
.desctype());
1333 IGbE::RxDescCache::pktComplete()
1335 assert(unusedCache
.size());
1337 desc
= unusedCache
.front();
1339 igbe
->anBegin("RXS", "Update Desc");
1341 uint16_t crcfixup
= igbe
->regs
.rctl
.secrc() ? 0 : 4 ;
1342 DPRINTF(EthernetDesc
, "pktPtr->length: %d bytesCopied: %d "
1343 "stripcrc offset: %d value written: %d %d\n",
1344 pktPtr
->length
, bytesCopied
, crcfixup
,
1345 htole((uint16_t)(pktPtr
->length
+ crcfixup
)),
1346 (uint16_t)(pktPtr
->length
+ crcfixup
));
1348 // no support for anything but starting at 0
1349 assert(igbe
->regs
.rxcsum
.pcss() == 0);
1351 DPRINTF(EthernetDesc
, "Packet written to memory updating Descriptor\n");
1353 uint16_t status
= RXDS_DD
;
1355 uint16_t ext_err
= 0;
1360 assert(bytesCopied
<= pktPtr
->length
);
1361 if (bytesCopied
== pktPtr
->length
)
1367 DPRINTF(EthernetDesc
, "Proccesing Ip packet with Id=%d\n", ip
->id());
1371 if (igbe
->regs
.rxcsum
.ipofld()) {
1372 DPRINTF(EthernetDesc
, "Checking IP checksum\n");
1373 status
|= RXDS_IPCS
;
1374 csum
= htole(cksum(ip
));
1375 igbe
->rxIpChecksums
++;
1376 if (cksum(ip
) != 0) {
1378 ext_err
|= RXDEE_IPE
;
1379 DPRINTF(EthernetDesc
, "Checksum is bad!!\n");
1383 if (tcp
&& igbe
->regs
.rxcsum
.tuofld()) {
1384 DPRINTF(EthernetDesc
, "Checking TCP checksum\n");
1385 status
|= RXDS_TCPCS
;
1387 csum
= htole(cksum(tcp
));
1388 igbe
->rxTcpChecksums
++;
1389 if (cksum(tcp
) != 0) {
1390 DPRINTF(EthernetDesc
, "Checksum is bad!!\n");
1392 ext_err
|= RXDEE_TCPE
;
1397 if (udp
&& igbe
->regs
.rxcsum
.tuofld()) {
1398 DPRINTF(EthernetDesc
, "Checking UDP checksum\n");
1399 status
|= RXDS_UDPCS
;
1401 csum
= htole(cksum(udp
));
1402 igbe
->rxUdpChecksums
++;
1403 if (cksum(udp
) != 0) {
1404 DPRINTF(EthernetDesc
, "Checksum is bad!!\n");
1405 ext_err
|= RXDEE_TCPE
;
1410 DPRINTF(EthernetSM
, "Proccesing Non-Ip packet\n");
1413 switch (igbe
->regs
.srrctl
.desctype()) {
1415 desc
->legacy
.len
= htole((uint16_t)(pktPtr
->length
+ crcfixup
));
1416 desc
->legacy
.status
= htole(status
);
1417 desc
->legacy
.errors
= htole(err
);
1418 // No vlan support at this point... just set it to 0
1419 desc
->legacy
.vlan
= 0;
1421 case RXDT_ADV_SPLIT_A
:
1422 case RXDT_ADV_ONEBUF
:
1423 desc
->adv_wb
.rss_type
= htole(0);
1424 desc
->adv_wb
.pkt_type
= htole(ptype
);
1425 if (igbe
->regs
.rxcsum
.pcsd()) {
1426 // no rss support right now
1427 desc
->adv_wb
.rss_hash
= htole(0);
1429 desc
->adv_wb
.id
= htole(ip_id
);
1430 desc
->adv_wb
.csum
= htole(csum
);
1432 desc
->adv_wb
.status
= htole(status
);
1433 desc
->adv_wb
.errors
= htole(ext_err
);
1435 desc
->adv_wb
.vlan_tag
= htole(0);
1438 panic("Unimplemnted RX receive buffer type %d\n",
1439 igbe
->regs
.srrctl
.desctype());
1442 DPRINTF(EthernetDesc
, "Descriptor complete w0: %#x w1: %#x\n",
1443 desc
->adv_read
.pkt
, desc
->adv_read
.hdr
);
1445 if (bytesCopied
== pktPtr
->length
) {
1446 DPRINTF(EthernetDesc
,
1447 "Packet completely written to descriptor buffers\n");
1448 // Deal with the rx timer interrupts
1449 if (igbe
->regs
.rdtr
.delay()) {
1450 Tick delay
= igbe
->regs
.rdtr
.delay() * igbe
->intClock();
1451 DPRINTF(EthernetSM
, "RXS: Scheduling DTR for %d\n", delay
);
1452 igbe
->reschedule(igbe
->rdtrEvent
, curTick() + delay
);
1455 if (igbe
->regs
.radv
.idv()) {
1456 Tick delay
= igbe
->regs
.radv
.idv() * igbe
->intClock();
1457 DPRINTF(EthernetSM
, "RXS: Scheduling ADV for %d\n", delay
);
1458 if (!igbe
->radvEvent
.scheduled()) {
1459 igbe
->schedule(igbe
->radvEvent
, curTick() + delay
);
1463 // if neither radv or rdtr, maybe itr is set...
1464 if (!igbe
->regs
.rdtr
.delay() && !igbe
->regs
.radv
.idv()) {
1466 "RXS: Receive interrupt delay disabled, posting IT_RXT\n");
1467 igbe
->postInterrupt(IT_RXT
);
1470 // If the packet is small enough, interrupt appropriately
1471 // I wonder if this is delayed or not?!
1472 if (pktPtr
->length
<= igbe
->regs
.rsrpd
.idv()) {
1474 "RXS: Posting IT_SRPD beacuse small packet received\n");
1475 igbe
->postInterrupt(IT_SRPD
);
1485 igbe
->anBegin("RXS", "Done Updating Desc");
1486 DPRINTF(EthernetDesc
, "Processing of this descriptor complete\n");
1487 igbe
->anDq("RXS", annUnusedCacheQ
);
1488 unusedCache
.pop_front();
1489 igbe
->anQ("RXS", annUsedCacheQ
);
1490 usedCache
.push_back(desc
);
1494 IGbE::RxDescCache::enableSm()
1496 if (!igbe
->drainManager
) {
1497 igbe
->rxTick
= true;
1498 igbe
->restartClock();
1503 IGbE::RxDescCache::packetDone()
1513 IGbE::RxDescCache::hasOutstandingEvents()
1515 return pktEvent
.scheduled() || wbEvent
.scheduled() ||
1516 fetchEvent
.scheduled() || pktHdrEvent
.scheduled() ||
1517 pktDataEvent
.scheduled();
1522 IGbE::RxDescCache::serialize(std::ostream
&os
)
1524 DescCache
<RxDesc
>::serialize(os
);
1525 SERIALIZE_SCALAR(pktDone
);
1526 SERIALIZE_SCALAR(splitCount
);
1527 SERIALIZE_SCALAR(bytesCopied
);
1531 IGbE::RxDescCache::unserialize(Checkpoint
*cp
, const std::string
§ion
)
1533 DescCache
<RxDesc
>::unserialize(cp
, section
);
1534 UNSERIALIZE_SCALAR(pktDone
);
1535 UNSERIALIZE_SCALAR(splitCount
);
1536 UNSERIALIZE_SCALAR(bytesCopied
);
1540 ///////////////////////////// IGbE::TxDescCache //////////////////////////////
1542 IGbE::TxDescCache::TxDescCache(IGbE
*i
, const std::string n
, int s
)
1543 : DescCache
<TxDesc
>(i
,n
, s
), pktDone(false), isTcp(false),
1544 pktWaiting(false), completionAddress(0), completionEnabled(false),
1545 useTso(false), tsoHeaderLen(0), tsoMss(0), tsoTotalLen(0), tsoUsedLen(0),
1546 tsoPrevSeq(0), tsoPktPayloadBytes(0), tsoLoadedHeader(false),
1547 tsoPktHasHeader(false), tsoDescBytesUsed(0), tsoCopyBytes(0), tsoPkts(0),
1548 pktEvent(this), headerEvent(this), nullEvent(this)
1550 annSmFetch
= "TX Desc Fetch";
1551 annSmWb
= "TX Desc Writeback";
1552 annUnusedDescQ
= "TX Unused Descriptors";
1553 annUnusedCacheQ
= "TX Unused Descriptor Cache";
1554 annUsedCacheQ
= "TX Used Descriptor Cache";
1555 annUsedDescQ
= "TX Used Descriptors";
1556 annDescQ
= "TX Descriptors";
1560 IGbE::TxDescCache::processContextDesc()
1562 assert(unusedCache
.size());
1565 DPRINTF(EthernetDesc
, "Checking and processing context descriptors\n");
1567 while (!useTso
&& unusedCache
.size() &&
1568 TxdOp::isContext(unusedCache
.front())) {
1569 DPRINTF(EthernetDesc
, "Got context descriptor type...\n");
1571 desc
= unusedCache
.front();
1572 DPRINTF(EthernetDesc
, "Descriptor upper: %#x lower: %#X\n",
1573 desc
->d1
, desc
->d2
);
1576 // is this going to be a tcp or udp packet?
1577 isTcp
= TxdOp::tcp(desc
) ? true : false;
1579 // setup all the TSO variables, they'll be ignored if we don't use
1580 // tso for this connection
1581 tsoHeaderLen
= TxdOp::hdrlen(desc
);
1582 tsoMss
= TxdOp::mss(desc
);
1584 if (TxdOp::isType(desc
, TxdOp::TXD_CNXT
) && TxdOp::tse(desc
)) {
1585 DPRINTF(EthernetDesc
, "TCP offload enabled for packet hdrlen: "
1586 "%d mss: %d paylen %d\n", TxdOp::hdrlen(desc
),
1587 TxdOp::mss(desc
), TxdOp::getLen(desc
));
1589 tsoTotalLen
= TxdOp::getLen(desc
);
1590 tsoLoadedHeader
= false;
1591 tsoDescBytesUsed
= 0;
1594 tsoPktHasHeader
= false;
1600 unusedCache
.pop_front();
1601 igbe
->anDq("TXS", annUnusedCacheQ
);
1602 usedCache
.push_back(desc
);
1603 igbe
->anQ("TXS", annUsedCacheQ
);
1606 if (!unusedCache
.size())
1609 desc
= unusedCache
.front();
1610 if (!useTso
&& TxdOp::isType(desc
, TxdOp::TXD_ADVDATA
) &&
1612 DPRINTF(EthernetDesc
, "TCP offload(adv) enabled for packet "
1613 "hdrlen: %d mss: %d paylen %d\n",
1614 tsoHeaderLen
, tsoMss
, TxdOp::getTsoLen(desc
));
1616 tsoTotalLen
= TxdOp::getTsoLen(desc
);
1617 tsoLoadedHeader
= false;
1618 tsoDescBytesUsed
= 0;
1621 tsoPktHasHeader
= false;
1625 if (useTso
&& !tsoLoadedHeader
) {
1626 // we need to fetch a header
1627 DPRINTF(EthernetDesc
, "Starting DMA of TSO header\n");
1628 assert(TxdOp::isData(desc
) && TxdOp::getLen(desc
) >= tsoHeaderLen
);
1630 assert(tsoHeaderLen
<= 256);
1631 igbe
->dmaRead(pciToDma(TxdOp::getBuf(desc
)),
1632 tsoHeaderLen
, &headerEvent
, tsoHeader
, 0);
1637 IGbE::TxDescCache::headerComplete()
1639 DPRINTF(EthernetDesc
, "TSO: Fetching TSO header complete\n");
1642 assert(unusedCache
.size());
1643 TxDesc
*desc
= unusedCache
.front();
1644 DPRINTF(EthernetDesc
, "TSO: len: %d tsoHeaderLen: %d\n",
1645 TxdOp::getLen(desc
), tsoHeaderLen
);
1647 if (TxdOp::getLen(desc
) == tsoHeaderLen
) {
1648 tsoDescBytesUsed
= 0;
1649 tsoLoadedHeader
= true;
1650 unusedCache
.pop_front();
1651 usedCache
.push_back(desc
);
1653 DPRINTF(EthernetDesc
, "TSO: header part of larger payload\n");
1654 tsoDescBytesUsed
= tsoHeaderLen
;
1655 tsoLoadedHeader
= true;
1662 IGbE::TxDescCache::getPacketSize(EthPacketPtr p
)
1664 if (!unusedCache
.size())
1667 DPRINTF(EthernetDesc
, "Starting processing of descriptor\n");
1669 assert(!useTso
|| tsoLoadedHeader
);
1670 TxDesc
*desc
= unusedCache
.front();
1673 DPRINTF(EthernetDesc
, "getPacket(): TxDescriptor data "
1674 "d1: %#llx d2: %#llx\n", desc
->d1
, desc
->d2
);
1675 DPRINTF(EthernetDesc
, "TSO: use: %d hdrlen: %d mss: %d total: %d "
1676 "used: %d loaded hdr: %d\n", useTso
, tsoHeaderLen
, tsoMss
,
1677 tsoTotalLen
, tsoUsedLen
, tsoLoadedHeader
);
1679 if (tsoPktHasHeader
)
1680 tsoCopyBytes
= std::min((tsoMss
+ tsoHeaderLen
) - p
->length
,
1681 TxdOp::getLen(desc
) - tsoDescBytesUsed
);
1683 tsoCopyBytes
= std::min(tsoMss
,
1684 TxdOp::getLen(desc
) - tsoDescBytesUsed
);
1686 tsoCopyBytes
+ (tsoPktHasHeader
? 0 : tsoHeaderLen
);
1688 DPRINTF(EthernetDesc
, "TSO: descBytesUsed: %d copyBytes: %d "
1689 "this descLen: %d\n",
1690 tsoDescBytesUsed
, tsoCopyBytes
, TxdOp::getLen(desc
));
1691 DPRINTF(EthernetDesc
, "TSO: pktHasHeader: %d\n", tsoPktHasHeader
);
1692 DPRINTF(EthernetDesc
, "TSO: Next packet is %d bytes\n", pkt_size
);
1696 DPRINTF(EthernetDesc
, "Next TX packet is %d bytes\n",
1697 TxdOp::getLen(unusedCache
.front()));
1698 return TxdOp::getLen(desc
);
1702 IGbE::TxDescCache::getPacketData(EthPacketPtr p
)
1704 assert(unusedCache
.size());
1707 desc
= unusedCache
.front();
1709 DPRINTF(EthernetDesc
, "getPacketData(): TxDescriptor data "
1710 "d1: %#llx d2: %#llx\n", desc
->d1
, desc
->d2
);
1711 assert((TxdOp::isLegacy(desc
) || TxdOp::isData(desc
)) &&
1712 TxdOp::getLen(desc
));
1718 DPRINTF(EthernetDesc
, "Starting DMA of packet at offset %d\n", p
->length
);
1721 assert(tsoLoadedHeader
);
1722 if (!tsoPktHasHeader
) {
1723 DPRINTF(EthernetDesc
,
1724 "Loading TSO header (%d bytes) into start of packet\n",
1726 memcpy(p
->data
, &tsoHeader
,tsoHeaderLen
);
1727 p
->length
+=tsoHeaderLen
;
1728 tsoPktHasHeader
= true;
1733 DPRINTF(EthernetDesc
,
1734 "Starting DMA of packet at offset %d length: %d\n",
1735 p
->length
, tsoCopyBytes
);
1736 igbe
->dmaRead(pciToDma(TxdOp::getBuf(desc
))
1738 tsoCopyBytes
, &pktEvent
, p
->data
+ p
->length
,
1740 tsoDescBytesUsed
+= tsoCopyBytes
;
1741 assert(tsoDescBytesUsed
<= TxdOp::getLen(desc
));
1743 igbe
->dmaRead(pciToDma(TxdOp::getBuf(desc
)),
1744 TxdOp::getLen(desc
), &pktEvent
, p
->data
+ p
->length
,
1750 IGbE::TxDescCache::pktComplete()
1754 assert(unusedCache
.size());
1757 igbe
->anBegin("TXS", "Update Desc");
1759 DPRINTF(EthernetDesc
, "DMA of packet complete\n");
1762 desc
= unusedCache
.front();
1763 assert((TxdOp::isLegacy(desc
) || TxdOp::isData(desc
)) &&
1764 TxdOp::getLen(desc
));
1766 DPRINTF(EthernetDesc
, "TxDescriptor data d1: %#llx d2: %#llx\n",
1767 desc
->d1
, desc
->d2
);
1769 // Set the length of the data in the EtherPacket
1771 DPRINTF(EthernetDesc
, "TSO: use: %d hdrlen: %d mss: %d total: %d "
1772 "used: %d loaded hdr: %d\n", useTso
, tsoHeaderLen
, tsoMss
,
1773 tsoTotalLen
, tsoUsedLen
, tsoLoadedHeader
);
1774 pktPtr
->length
+= tsoCopyBytes
;
1775 tsoUsedLen
+= tsoCopyBytes
;
1776 DPRINTF(EthernetDesc
, "TSO: descBytesUsed: %d copyBytes: %d\n",
1777 tsoDescBytesUsed
, tsoCopyBytes
);
1779 pktPtr
->length
+= TxdOp::getLen(desc
);
1783 if ((!TxdOp::eop(desc
) && !useTso
) ||
1784 (pktPtr
->length
< ( tsoMss
+ tsoHeaderLen
) &&
1785 tsoTotalLen
!= tsoUsedLen
&& useTso
)) {
1786 assert(!useTso
|| (tsoDescBytesUsed
== TxdOp::getLen(desc
)));
1787 igbe
->anDq("TXS", annUnusedCacheQ
);
1788 unusedCache
.pop_front();
1789 igbe
->anQ("TXS", annUsedCacheQ
);
1790 usedCache
.push_back(desc
);
1792 tsoDescBytesUsed
= 0;
1795 pktMultiDesc
= true;
1797 DPRINTF(EthernetDesc
, "Partial Packet Descriptor of %d bytes Done\n",
1807 pktMultiDesc
= false;
1808 // no support for vlans
1809 assert(!TxdOp::vle(desc
));
1811 // we only support single packet descriptors at this point
1813 assert(TxdOp::eop(desc
));
1815 // set that this packet is done
1816 if (TxdOp::rs(desc
))
1819 DPRINTF(EthernetDesc
, "TxDescriptor data d1: %#llx d2: %#llx\n",
1820 desc
->d1
, desc
->d2
);
1825 DPRINTF(EthernetDesc
, "TSO: Modifying IP header. Id + %d\n",
1827 ip
->id(ip
->id() + tsoPkts
++);
1828 ip
->len(pktPtr
->length
- EthPtr(pktPtr
)->size());
1832 DPRINTF(EthernetDesc
,
1833 "TSO: Modifying TCP header. old seq %d + %d\n",
1834 tcp
->seq(), tsoPrevSeq
);
1835 tcp
->seq(tcp
->seq() + tsoPrevSeq
);
1836 if (tsoUsedLen
!= tsoTotalLen
)
1837 tcp
->flags(tcp
->flags() & ~9); // clear fin & psh
1841 DPRINTF(EthernetDesc
, "TSO: Modifying UDP header.\n");
1842 udp
->len(pktPtr
->length
- EthPtr(pktPtr
)->size());
1845 tsoPrevSeq
= tsoUsedLen
;
1848 if (DTRACE(EthernetDesc
)) {
1851 DPRINTF(EthernetDesc
, "Proccesing Ip packet with Id=%d\n",
1854 DPRINTF(EthernetSM
, "Proccesing Non-Ip packet\n");
1857 // Checksums are only ofloaded for new descriptor types
1858 if (TxdOp::isData(desc
) && ( TxdOp::ixsm(desc
) || TxdOp::txsm(desc
)) ) {
1859 DPRINTF(EthernetDesc
, "Calculating checksums for packet\n");
1862 if (TxdOp::ixsm(desc
)) {
1865 igbe
->txIpChecksums
++;
1866 DPRINTF(EthernetDesc
, "Calculated IP checksum\n");
1868 if (TxdOp::txsm(desc
)) {
1873 tcp
->sum(cksum(tcp
));
1874 igbe
->txTcpChecksums
++;
1875 DPRINTF(EthernetDesc
, "Calculated TCP checksum\n");
1879 udp
->sum(cksum(udp
));
1880 igbe
->txUdpChecksums
++;
1881 DPRINTF(EthernetDesc
, "Calculated UDP checksum\n");
1883 panic("Told to checksum, but don't know how\n");
1888 if (TxdOp::ide(desc
)) {
1889 // Deal with the rx timer interrupts
1890 DPRINTF(EthernetDesc
, "Descriptor had IDE set\n");
1891 if (igbe
->regs
.tidv
.idv()) {
1892 Tick delay
= igbe
->regs
.tidv
.idv() * igbe
->intClock();
1893 DPRINTF(EthernetDesc
, "setting tidv\n");
1894 igbe
->reschedule(igbe
->tidvEvent
, curTick() + delay
, true);
1897 if (igbe
->regs
.tadv
.idv() && igbe
->regs
.tidv
.idv()) {
1898 Tick delay
= igbe
->regs
.tadv
.idv() * igbe
->intClock();
1899 DPRINTF(EthernetDesc
, "setting tadv\n");
1900 if (!igbe
->tadvEvent
.scheduled()) {
1901 igbe
->schedule(igbe
->tadvEvent
, curTick() + delay
);
1907 if (!useTso
|| TxdOp::getLen(desc
) == tsoDescBytesUsed
) {
1908 DPRINTF(EthernetDesc
, "Descriptor Done\n");
1909 igbe
->anDq("TXS", annUnusedCacheQ
);
1910 unusedCache
.pop_front();
1911 igbe
->anQ("TXS", annUsedCacheQ
);
1912 usedCache
.push_back(desc
);
1913 tsoDescBytesUsed
= 0;
1916 if (useTso
&& tsoUsedLen
== tsoTotalLen
)
1920 DPRINTF(EthernetDesc
,
1921 "------Packet of %d bytes ready for transmission-------\n",
1926 tsoPktHasHeader
= false;
1928 if (igbe
->regs
.txdctl
.wthresh() == 0) {
1929 igbe
->anBegin("TXS", "Desc Writeback");
1930 DPRINTF(EthernetDesc
, "WTHRESH == 0, writing back descriptor\n");
1932 } else if (!igbe
->regs
.txdctl
.gran() && igbe
->regs
.txdctl
.wthresh() <=
1933 descInBlock(usedCache
.size())) {
1934 DPRINTF(EthernetDesc
, "used > WTHRESH, writing back descriptor\n");
1935 igbe
->anBegin("TXS", "Desc Writeback");
1936 writeback((igbe
->cacheBlockSize()-1)>>4);
1937 } else if (igbe
->regs
.txdctl
.wthresh() <= usedCache
.size()) {
1938 DPRINTF(EthernetDesc
, "used > WTHRESH, writing back descriptor\n");
1939 igbe
->anBegin("TXS", "Desc Writeback");
1940 writeback((igbe
->cacheBlockSize()-1)>>4);
1948 IGbE::TxDescCache::actionAfterWb()
1950 DPRINTF(EthernetDesc
, "actionAfterWb() completionEnabled: %d\n",
1952 igbe
->postInterrupt(iGbReg::IT_TXDW
);
1953 if (completionEnabled
) {
1954 descEnd
= igbe
->regs
.tdh();
1955 DPRINTF(EthernetDesc
,
1956 "Completion writing back value: %d to addr: %#x\n", descEnd
,
1958 igbe
->dmaWrite(pciToDma(mbits(completionAddress
, 63, 2)),
1959 sizeof(descEnd
), &nullEvent
, (uint8_t*)&descEnd
, 0);
1964 IGbE::TxDescCache::serialize(std::ostream
&os
)
1966 DescCache
<TxDesc
>::serialize(os
);
1967 SERIALIZE_SCALAR(pktDone
);
1968 SERIALIZE_SCALAR(isTcp
);
1969 SERIALIZE_SCALAR(pktWaiting
);
1970 SERIALIZE_SCALAR(pktMultiDesc
);
1972 SERIALIZE_SCALAR(useTso
);
1973 SERIALIZE_SCALAR(tsoHeaderLen
);
1974 SERIALIZE_SCALAR(tsoMss
);
1975 SERIALIZE_SCALAR(tsoTotalLen
);
1976 SERIALIZE_SCALAR(tsoUsedLen
);
1977 SERIALIZE_SCALAR(tsoPrevSeq
);;
1978 SERIALIZE_SCALAR(tsoPktPayloadBytes
);
1979 SERIALIZE_SCALAR(tsoLoadedHeader
);
1980 SERIALIZE_SCALAR(tsoPktHasHeader
);
1981 SERIALIZE_ARRAY(tsoHeader
, 256);
1982 SERIALIZE_SCALAR(tsoDescBytesUsed
);
1983 SERIALIZE_SCALAR(tsoCopyBytes
);
1984 SERIALIZE_SCALAR(tsoPkts
);
1986 SERIALIZE_SCALAR(completionAddress
);
1987 SERIALIZE_SCALAR(completionEnabled
);
1988 SERIALIZE_SCALAR(descEnd
);
1992 IGbE::TxDescCache::unserialize(Checkpoint
*cp
, const std::string
§ion
)
1994 DescCache
<TxDesc
>::unserialize(cp
, section
);
1995 UNSERIALIZE_SCALAR(pktDone
);
1996 UNSERIALIZE_SCALAR(isTcp
);
1997 UNSERIALIZE_SCALAR(pktWaiting
);
1998 UNSERIALIZE_SCALAR(pktMultiDesc
);
2000 UNSERIALIZE_SCALAR(useTso
);
2001 UNSERIALIZE_SCALAR(tsoHeaderLen
);
2002 UNSERIALIZE_SCALAR(tsoMss
);
2003 UNSERIALIZE_SCALAR(tsoTotalLen
);
2004 UNSERIALIZE_SCALAR(tsoUsedLen
);
2005 UNSERIALIZE_SCALAR(tsoPrevSeq
);;
2006 UNSERIALIZE_SCALAR(tsoPktPayloadBytes
);
2007 UNSERIALIZE_SCALAR(tsoLoadedHeader
);
2008 UNSERIALIZE_SCALAR(tsoPktHasHeader
);
2009 UNSERIALIZE_ARRAY(tsoHeader
, 256);
2010 UNSERIALIZE_SCALAR(tsoDescBytesUsed
);
2011 UNSERIALIZE_SCALAR(tsoCopyBytes
);
2012 UNSERIALIZE_SCALAR(tsoPkts
);
2014 UNSERIALIZE_SCALAR(completionAddress
);
2015 UNSERIALIZE_SCALAR(completionEnabled
);
2016 UNSERIALIZE_SCALAR(descEnd
);
2020 IGbE::TxDescCache::packetAvailable()
2030 IGbE::TxDescCache::enableSm()
2032 if (!igbe
->drainManager
) {
2033 igbe
->txTick
= true;
2034 igbe
->restartClock();
2039 IGbE::TxDescCache::hasOutstandingEvents()
2041 return pktEvent
.scheduled() || wbEvent
.scheduled() ||
2042 fetchEvent
.scheduled();
2046 ///////////////////////////////////// IGbE /////////////////////////////////
2049 IGbE::restartClock()
2051 if (!tickEvent
.scheduled() && (rxTick
|| txTick
|| txFifoTick
) &&
2052 getDrainState() == Drainable::Running
)
2053 schedule(tickEvent
, clockEdge(Cycles(1)));
2057 IGbE::drain(DrainManager
*dm
)
2060 count
= pioPort
.drain(dm
) + dmaPort
.drain(dm
);
2061 if (rxDescCache
.hasOutstandingEvents() ||
2062 txDescCache
.hasOutstandingEvents()) {
2071 if (tickEvent
.scheduled())
2072 deschedule(tickEvent
);
2075 DPRINTF(Drain
, "IGbE not drained\n");
2076 setDrainState(Drainable::Draining
);
2078 setDrainState(Drainable::Drained
);
2086 Drainable::drainResume();
2093 DPRINTF(EthernetSM
, "resuming from drain");
2105 if (!rxDescCache
.hasOutstandingEvents() &&
2106 !txDescCache
.hasOutstandingEvents()) {
2107 DPRINTF(Drain
, "IGbE done draining, processing drain event\n");
2108 drainManager
->signalDrainDone();
2109 drainManager
= NULL
;
2114 IGbE::txStateMachine()
2116 if (!regs
.tctl
.en()) {
2118 DPRINTF(EthernetSM
, "TXS: TX disabled, stopping ticking\n");
2122 // If we have a packet available and it's length is not 0 (meaning it's not
2123 // a multidescriptor packet) put it in the fifo, otherwise an the next
2124 // iteration we'll get the rest of the data
2125 if (txPacket
&& txDescCache
.packetAvailable()
2126 && !txDescCache
.packetMultiDesc() && txPacket
->length
) {
2127 anQ("TXS", "TX FIFO Q");
2128 DPRINTF(EthernetSM
, "TXS: packet placed in TX FIFO\n");
2132 txFifo
.push(txPacket
);
2133 txFifoTick
= true && !drainManager
;
2136 anBegin("TXS", "Desc Writeback");
2137 txDescCache
.writeback((cacheBlockSize()-1)>>4);
2141 // Only support descriptor granularity
2142 if (regs
.txdctl
.lwthresh() &&
2143 txDescCache
.descLeft() < (regs
.txdctl
.lwthresh() * 8)) {
2144 DPRINTF(EthernetSM
, "TXS: LWTHRESH caused posting of TXDLOW\n");
2145 postInterrupt(IT_TXDLOW
);
2149 txPacket
= new EthPacketData(16384);
2152 if (!txDescCache
.packetWaiting()) {
2153 if (txDescCache
.descLeft() == 0) {
2154 postInterrupt(IT_TXQE
);
2155 anBegin("TXS", "Desc Writeback");
2156 txDescCache
.writeback(0);
2157 anBegin("TXS", "Desc Fetch");
2158 anWe("TXS", txDescCache
.annUnusedCacheQ
);
2159 txDescCache
.fetchDescriptors();
2160 DPRINTF(EthernetSM
, "TXS: No descriptors left in ring, forcing "
2161 "writeback stopping ticking and posting TXQE\n");
2167 if (!(txDescCache
.descUnused())) {
2168 anBegin("TXS", "Desc Fetch");
2169 txDescCache
.fetchDescriptors();
2170 anWe("TXS", txDescCache
.annUnusedCacheQ
);
2171 DPRINTF(EthernetSM
, "TXS: No descriptors available in cache, "
2172 "fetching and stopping ticking\n");
2176 anPq("TXS", txDescCache
.annUnusedCacheQ
);
2179 txDescCache
.processContextDesc();
2180 if (txDescCache
.packetWaiting()) {
2182 "TXS: Fetching TSO header, stopping ticking\n");
2187 unsigned size
= txDescCache
.getPacketSize(txPacket
);
2188 if (size
> 0 && txFifo
.avail() > size
) {
2189 anRq("TXS", "TX FIFO Q");
2190 anBegin("TXS", "DMA Packet");
2191 DPRINTF(EthernetSM
, "TXS: Reserving %d bytes in FIFO and "
2192 "beginning DMA of next packet\n", size
);
2193 txFifo
.reserve(size
);
2194 txDescCache
.getPacketData(txPacket
);
2195 } else if (size
== 0) {
2196 DPRINTF(EthernetSM
, "TXS: getPacketSize returned: %d\n", size
);
2198 "TXS: No packets to get, writing back used descriptors\n");
2199 anBegin("TXS", "Desc Writeback");
2200 txDescCache
.writeback(0);
2202 anWf("TXS", "TX FIFO Q");
2203 DPRINTF(EthernetSM
, "TXS: FIFO full, stopping ticking until space "
2204 "available in FIFO\n");
2211 DPRINTF(EthernetSM
, "TXS: Nothing to do, stopping ticking\n");
2216 IGbE::ethRxPkt(EthPacketPtr pkt
)
2218 rxBytes
+= pkt
->length
;
2221 DPRINTF(Ethernet
, "RxFIFO: Receiving pcakte from wire\n");
2222 anBegin("RXQ", "Wire Recv");
2225 if (!regs
.rctl
.en()) {
2226 DPRINTF(Ethernet
, "RxFIFO: RX not enabled, dropping\n");
2227 anBegin("RXQ", "FIFO Drop", CPA::FL_BAD
);
2231 // restart the state machines if they are stopped
2232 rxTick
= true && !drainManager
;
2233 if ((rxTick
|| txTick
) && !tickEvent
.scheduled()) {
2235 "RXS: received packet into fifo, starting ticking\n");
2239 if (!rxFifo
.push(pkt
)) {
2240 DPRINTF(Ethernet
, "RxFIFO: Packet won't fit in fifo... dropped\n");
2241 postInterrupt(IT_RXO
, true);
2242 anBegin("RXQ", "FIFO Drop", CPA::FL_BAD
);
2246 if (CPA::available() && cpa
->enabled()) {
2247 assert(sys
->numSystemsRunning
<= 2);
2249 if (sys
->systemList
[0] == sys
)
2250 other_sys
= sys
->systemList
[1];
2252 other_sys
= sys
->systemList
[0];
2254 cpa
->hwDq(CPA::FL_NONE
, sys
, macAddr
, "RXQ", "WireQ", 0, other_sys
);
2255 anQ("RXQ", "RX FIFO Q");
2256 cpa
->hwWe(CPA::FL_NONE
, sys
, macAddr
, "RXQ", "WireQ", 0, other_sys
);
2264 IGbE::rxStateMachine()
2266 if (!regs
.rctl
.en()) {
2268 DPRINTF(EthernetSM
, "RXS: RX disabled, stopping ticking\n");
2272 // If the packet is done check for interrupts/descriptors/etc
2273 if (rxDescCache
.packetDone()) {
2274 rxDmaPacket
= false;
2275 DPRINTF(EthernetSM
, "RXS: Packet completed DMA to memory\n");
2276 int descLeft
= rxDescCache
.descLeft();
2277 DPRINTF(EthernetSM
, "RXS: descLeft: %d rdmts: %d rdlen: %d\n",
2278 descLeft
, regs
.rctl
.rdmts(), regs
.rdlen());
2279 switch (regs
.rctl
.rdmts()) {
2280 case 2: if (descLeft
> .125 * regs
.rdlen()) break;
2281 case 1: if (descLeft
> .250 * regs
.rdlen()) break;
2282 case 0: if (descLeft
> .500 * regs
.rdlen()) break;
2283 DPRINTF(Ethernet
, "RXS: Interrupting (RXDMT) "
2284 "because of descriptors left\n");
2285 postInterrupt(IT_RXDMT
);
2290 rxDescCache
.writeback(0);
2292 if (descLeft
== 0) {
2293 anBegin("RXS", "Writeback Descriptors");
2294 rxDescCache
.writeback(0);
2295 DPRINTF(EthernetSM
, "RXS: No descriptors left in ring, forcing"
2296 " writeback and stopping ticking\n");
2300 // only support descriptor granulaties
2301 assert(regs
.rxdctl
.gran());
2303 if (regs
.rxdctl
.wthresh() >= rxDescCache
.descUsed()) {
2305 "RXS: Writing back because WTHRESH >= descUsed\n");
2306 anBegin("RXS", "Writeback Descriptors");
2307 if (regs
.rxdctl
.wthresh() < (cacheBlockSize()>>4))
2308 rxDescCache
.writeback(regs
.rxdctl
.wthresh()-1);
2310 rxDescCache
.writeback((cacheBlockSize()-1)>>4);
2313 if ((rxDescCache
.descUnused() < regs
.rxdctl
.pthresh()) &&
2314 ((rxDescCache
.descLeft() - rxDescCache
.descUnused()) >
2315 regs
.rxdctl
.hthresh())) {
2316 DPRINTF(EthernetSM
, "RXS: Fetching descriptors because "
2317 "descUnused < PTHRESH\n");
2318 anBegin("RXS", "Fetch Descriptors");
2319 rxDescCache
.fetchDescriptors();
2322 if (rxDescCache
.descUnused() == 0) {
2323 anBegin("RXS", "Fetch Descriptors");
2324 rxDescCache
.fetchDescriptors();
2325 anWe("RXS", rxDescCache
.annUnusedCacheQ
);
2326 DPRINTF(EthernetSM
, "RXS: No descriptors available in cache, "
2327 "fetching descriptors and stopping ticking\n");
2335 "RXS: stopping ticking until packet DMA completes\n");
2340 if (!rxDescCache
.descUnused()) {
2341 anBegin("RXS", "Fetch Descriptors");
2342 rxDescCache
.fetchDescriptors();
2343 anWe("RXS", rxDescCache
.annUnusedCacheQ
);
2344 DPRINTF(EthernetSM
, "RXS: No descriptors available in cache, "
2345 "stopping ticking\n");
2347 DPRINTF(EthernetSM
, "RXS: No descriptors available, fetching\n");
2350 anPq("RXS", rxDescCache
.annUnusedCacheQ
);
2352 if (rxFifo
.empty()) {
2353 anWe("RXS", "RX FIFO Q");
2354 DPRINTF(EthernetSM
, "RXS: RxFIFO empty, stopping ticking\n");
2358 anPq("RXS", "RX FIFO Q");
2359 anBegin("RXS", "Get Desc");
2362 pkt
= rxFifo
.front();
2365 pktOffset
= rxDescCache
.writePacket(pkt
, pktOffset
);
2366 DPRINTF(EthernetSM
, "RXS: Writing packet into memory\n");
2367 if (pktOffset
== pkt
->length
) {
2368 anBegin( "RXS", "FIFO Dequeue");
2369 DPRINTF(EthernetSM
, "RXS: Removing packet from FIFO\n");
2371 anDq("RXS", "RX FIFO Q");
2375 DPRINTF(EthernetSM
, "RXS: stopping ticking until packet DMA completes\n");
2378 anBegin("RXS", "DMA Packet");
2384 if (txFifo
.empty()) {
2385 anWe("TXQ", "TX FIFO Q");
2391 anPq("TXQ", "TX FIFO Q");
2392 if (etherInt
->sendPacket(txFifo
.front())) {
2393 cpa
->hwQ(CPA::FL_NONE
, sys
, macAddr
, "TXQ", "WireQ", 0);
2394 if (DTRACE(EthernetSM
)) {
2395 IpPtr
ip(txFifo
.front());
2397 DPRINTF(EthernetSM
, "Transmitting Ip packet with Id=%d\n",
2400 DPRINTF(EthernetSM
, "Transmitting Non-Ip packet\n");
2402 anDq("TXQ", "TX FIFO Q");
2403 anBegin("TXQ", "Wire Send");
2405 "TxFIFO: Successful transmit, bytes available in fifo: %d\n",
2408 txBytes
+= txFifo
.front()->length
;
2414 // We'll get woken up when the packet ethTxDone() gets called
2422 DPRINTF(EthernetSM
, "IGbE: -------------- Cycle --------------\n");
2434 if (rxTick
|| txTick
|| txFifoTick
)
2435 schedule(tickEvent
, curTick() + clockPeriod());
2441 anBegin("TXQ", "Send Done");
2442 // restart the tx state machines if they are stopped
2443 // fifo to send another packet
2444 // tx sm to put more data into the fifo
2445 txFifoTick
= true && !drainManager
;
2446 if (txDescCache
.descLeft() != 0 && !drainManager
)
2451 DPRINTF(EthernetSM
, "TxFIFO: Transmission complete\n");
2455 IGbE::serialize(std::ostream
&os
)
2457 PciDev::serialize(os
);
2460 SERIALIZE_SCALAR(eeOpBits
);
2461 SERIALIZE_SCALAR(eeAddrBits
);
2462 SERIALIZE_SCALAR(eeDataBits
);
2463 SERIALIZE_SCALAR(eeOpcode
);
2464 SERIALIZE_SCALAR(eeAddr
);
2465 SERIALIZE_SCALAR(lastInterrupt
);
2466 SERIALIZE_ARRAY(flash
,iGbReg::EEPROM_SIZE
);
2468 rxFifo
.serialize("rxfifo", os
);
2469 txFifo
.serialize("txfifo", os
);
2471 bool txPktExists
= txPacket
;
2472 SERIALIZE_SCALAR(txPktExists
);
2474 txPacket
->serialize("txpacket", os
);
2476 Tick rdtr_time
= 0, radv_time
= 0, tidv_time
= 0, tadv_time
= 0,
2479 if (rdtrEvent
.scheduled())
2480 rdtr_time
= rdtrEvent
.when();
2481 SERIALIZE_SCALAR(rdtr_time
);
2483 if (radvEvent
.scheduled())
2484 radv_time
= radvEvent
.when();
2485 SERIALIZE_SCALAR(radv_time
);
2487 if (tidvEvent
.scheduled())
2488 tidv_time
= tidvEvent
.when();
2489 SERIALIZE_SCALAR(tidv_time
);
2491 if (tadvEvent
.scheduled())
2492 tadv_time
= tadvEvent
.when();
2493 SERIALIZE_SCALAR(tadv_time
);
2495 if (interEvent
.scheduled())
2496 inter_time
= interEvent
.when();
2497 SERIALIZE_SCALAR(inter_time
);
2499 SERIALIZE_SCALAR(pktOffset
);
2501 nameOut(os
, csprintf("%s.TxDescCache", name()));
2502 txDescCache
.serialize(os
);
2504 nameOut(os
, csprintf("%s.RxDescCache", name()));
2505 rxDescCache
.serialize(os
);
2509 IGbE::unserialize(Checkpoint
*cp
, const std::string
§ion
)
2511 PciDev::unserialize(cp
, section
);
2513 regs
.unserialize(cp
, section
);
2514 UNSERIALIZE_SCALAR(eeOpBits
);
2515 UNSERIALIZE_SCALAR(eeAddrBits
);
2516 UNSERIALIZE_SCALAR(eeDataBits
);
2517 UNSERIALIZE_SCALAR(eeOpcode
);
2518 UNSERIALIZE_SCALAR(eeAddr
);
2519 UNSERIALIZE_SCALAR(lastInterrupt
);
2520 UNSERIALIZE_ARRAY(flash
,iGbReg::EEPROM_SIZE
);
2522 rxFifo
.unserialize("rxfifo", cp
, section
);
2523 txFifo
.unserialize("txfifo", cp
, section
);
2526 UNSERIALIZE_SCALAR(txPktExists
);
2528 txPacket
= new EthPacketData(16384);
2529 txPacket
->unserialize("txpacket", cp
, section
);
2536 Tick rdtr_time
, radv_time
, tidv_time
, tadv_time
, inter_time
;
2537 UNSERIALIZE_SCALAR(rdtr_time
);
2538 UNSERIALIZE_SCALAR(radv_time
);
2539 UNSERIALIZE_SCALAR(tidv_time
);
2540 UNSERIALIZE_SCALAR(tadv_time
);
2541 UNSERIALIZE_SCALAR(inter_time
);
2544 schedule(rdtrEvent
, rdtr_time
);
2547 schedule(radvEvent
, radv_time
);
2550 schedule(tidvEvent
, tidv_time
);
2553 schedule(tadvEvent
, tadv_time
);
2556 schedule(interEvent
, inter_time
);
2558 UNSERIALIZE_SCALAR(pktOffset
);
2560 txDescCache
.unserialize(cp
, csprintf("%s.TxDescCache", section
));
2562 rxDescCache
.unserialize(cp
, csprintf("%s.RxDescCache", section
));
2566 IGbEParams::create()
2568 return new IGbE(this);