gem5 v24.0.0.0
Loading...
Searching...
No Matches
i8254xGBe.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 */
28
29/* @file
30 * Device model for Intel's 8254x line of gigabit ethernet controllers.
31 */
32
33#ifndef __DEV_NET_I8254XGBE_HH__
34#define __DEV_NET_I8254XGBE_HH__
35
36#include <cstdint>
37#include <deque>
38#include <string>
39
40#include "base/inet.hh"
41#include "base/trace.hh"
42#include "base/types.hh"
43#include "debug/EthernetDesc.hh"
44#include "debug/EthernetIntr.hh"
46#include "dev/net/etherint.hh"
47#include "dev/net/etherpkt.hh"
49#include "dev/net/pktfifo.hh"
50#include "dev/pci/device.hh"
51#include "params/IGbE.hh"
52#include "sim/eventq.hh"
53#include "sim/serialize.hh"
54
55namespace gem5
56{
57
58class IGbEInt;
59
60class IGbE : public EtherDevice
61{
62 private:
64
65 // device registers
67
68 // eeprom data, status and control bits
70 uint8_t eeOpcode, eeAddr;
72
73 // packet fifos
76
77 // Packet that we are currently putting into the txFifo
79
80 // Should to Rx/Tx State machine tick?
81 bool inTick;
82 bool rxTick;
83 bool txTick;
85
87
88 // Number of bytes copied from current RX packet
89 unsigned pktOffset;
90
91 // Delays in managaging descriptors
95
96 // Event and function to deal with RDTR timer expiring
97 void rdtrProcess() {
99 DPRINTF(EthernetIntr,
100 "Posting RXT interrupt because RDTR timer expired\n");
102 }
103
105
106 // Event and function to deal with RADV timer expiring
107 void radvProcess() {
109 DPRINTF(EthernetIntr,
110 "Posting RXT interrupt because RADV timer expired\n");
112 }
113
115
116 // Event and function to deal with TADV timer expiring
117 void tadvProcess() {
119 DPRINTF(EthernetIntr,
120 "Posting TXDW interrupt because TADV timer expired\n");
122 }
123
125
126 // Event and function to deal with TIDV timer expiring
127 void tidvProcess() {
129 DPRINTF(EthernetIntr,
130 "Posting TXDW interrupt because TIDV timer expired\n");
132 }
134
135 // Main event to tick the device
136 void tick();
138
139
140 uint64_t macAddr;
141
142 void rxStateMachine();
143 void txStateMachine();
144 void txWire();
145
151 void postInterrupt(igbreg::IntTypes t, bool now = false);
152
156 void chkInterrupt();
157
160 void delayIntEvent();
161 void cpuPostInt();
162 // Event to moderate interrupts
164
167 void cpuClearInt();
168
170
173 void restartClock();
174
178 void checkDrain();
179
180 template<class T>
181 class DescCache : public Serializable
182 {
183 protected:
184 virtual Addr descBase() const = 0;
185 virtual long descHead() const = 0;
186 virtual long descTail() const = 0;
187 virtual long descLen() const = 0;
188 virtual void updateHead(long h) = 0;
189 virtual void enableSm() = 0;
190 virtual void actionAfterWb() {}
191 virtual void fetchAfterWb() = 0;
192
196
199
200 // Pointer to the device we cache for
202
203 // Name of this descriptor cache
204 std::string _name;
205
206 // How far we've cached
208
209 // The size of the descriptor cache
210 int size;
211
212 // How many descriptors we are currently fetching
214
215 // How many descriptors we are currently writing back
216 int wbOut;
217
218 // if the we wrote back to the end of the descriptor ring and are going
219 // to have to wrap and write more
221
222 // What the alignment is of the next descriptor writeback
224
227
230
231 public:
235
236 DescCache(IGbE *i, const std::string n, int s);
237 virtual ~DescCache();
238
239 std::string name() { return _name; }
240
245 void areaChanged();
246
247 void writeback(Addr aMask);
248 void writeback1();
250
254 void fetchDescriptors();
255 void fetchDescriptors1();
257
260 void fetchComplete();
262
265 void wbComplete();
267
268 /* Return the number of descriptors left in the ring, so the device has
269 * a way to figure out if it needs to interrupt.
270 */
271 unsigned
272 descLeft() const
273 {
274 unsigned left = unusedCache.size();
275 if (cachePnt > descTail())
276 left += (descLen() - cachePnt + descTail());
277 else
278 left += (descTail() - cachePnt);
279
280 return left;
281 }
282
283 /* Return the number of descriptors used and not written back.
284 */
285 unsigned descUsed() const { return usedCache.size(); }
286
287 /* Return the number of cache unused descriptors we have. */
288 unsigned descUnused() const { return unusedCache.size(); }
289
290 /* Get into a state where the descriptor address/head/etc colud be
291 * changed */
292 void reset();
293
294
295 void serialize(CheckpointOut &cp) const override;
296 void unserialize(CheckpointIn &cp) override;
297
298 virtual bool hasOutstandingEvents() {
300 }
301
302 };
303
304
305 class RxDescCache : public DescCache<igbreg::RxDesc>
306 {
307 protected:
308 Addr descBase() const override { return igbe->regs.rdba(); }
309 long descHead() const override { return igbe->regs.rdh(); }
310 long descLen() const override { return igbe->regs.rdlen() >> 4; }
311 long descTail() const override { return igbe->regs.rdt(); }
312 void updateHead(long h) override { igbe->regs.rdh(h); }
313 void enableSm() override;
314 void fetchAfterWb() override {
317 }
318
320
323
326 unsigned bytesCopied;
327
328 public:
329 RxDescCache(IGbE *i, std::string n, int s);
330
338 int writePacket(EthPacketPtr packet, int pkt_offset);
339
342 void pktComplete();
343
347 bool packetDone();
348
350
351 // Event to handle issuing header and data write at the same time
352 // and only callking pktComplete() when both are completed
353 void pktSplitDone();
356
357 bool hasOutstandingEvents() override;
358
359 void serialize(CheckpointOut &cp) const override;
360 void unserialize(CheckpointIn &cp) override;
361 };
362 friend class RxDescCache;
363
365
366 class TxDescCache : public DescCache<igbreg::TxDesc>
367 {
368 protected:
369 Addr descBase() const override { return igbe->regs.tdba(); }
370 long descHead() const override { return igbe->regs.tdh(); }
371 long descTail() const override { return igbe->regs.tdt(); }
372 long descLen() const override { return igbe->regs.tdlen() >> 4; }
373 void updateHead(long h) override { igbe->regs.tdh(h); }
374 void enableSm() override;
375 void actionAfterWb() override;
376 void fetchAfterWb() override {
379 }
380
381
382
384 bool isTcp;
389 uint32_t descEnd;
390
391
392 // tso variables
393 bool useTso;
402 uint8_t tsoHeader[256];
406
407 public:
408 TxDescCache(IGbE *i, std::string n, int s);
409
414 unsigned getPacketSize(EthPacketPtr p);
416 void processContextDesc();
417
421 unsigned
422 descInBlock(unsigned num_desc)
423 {
424 return num_desc / igbe->cacheBlockSize() / sizeof(igbreg::TxDesc);
425 }
426
431 bool packetAvailable();
432
436 bool packetWaiting() { return pktWaiting; }
437
445
448 void pktComplete();
450
451 void headerComplete();
453
454
456 DPRINTF(EthernetDesc,
457 "Completion writeback Addr: %#x enabled: %d\n",
458 a, enabled);
461 }
462
463 bool hasOutstandingEvents() override;
464
466 DPRINTF(EthernetDesc, "Completion writeback complete\n");
467 }
469
470 void serialize(CheckpointOut &cp) const override;
471 void unserialize(CheckpointIn &cp) override;
472 };
473
474 friend class TxDescCache;
475
477
478 public:
480
481 IGbE(const Params &params);
482 ~IGbE();
483 void init() override;
484
485 Port &getPort(const std::string &if_name,
486 PortID idx=InvalidPortID) override;
487
489
490 Tick read(PacketPtr pkt) override;
491 Tick write(PacketPtr pkt) override;
492
493 Tick writeConfig(PacketPtr pkt) override;
494
495 bool ethRxPkt(EthPacketPtr packet);
496 void ethTxDone();
497
498 void serialize(CheckpointOut &cp) const override;
499 void unserialize(CheckpointIn &cp) override;
500
501 DrainState drain() override;
502 void drainResume() override;
503
504};
505
506class IGbEInt : public EtherInt
507{
508 private:
510
511 public:
512 IGbEInt(const std::string &name, IGbE *d)
513 : EtherInt(name), dev(d)
514 { }
515
516 virtual bool recvPacket(EthPacketPtr pkt) { return dev->ethRxPkt(pkt); }
517 virtual void sendDone() { dev->ethTxDone(); }
518};
519
520} // namespace gem5
521
522#endif //__DEV_NET_I8254XGBE_HH__
#define DPRINTF(x,...)
Definition trace.hh:210
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Addr cacheBlockSize() const
EtherDeviceParams Params
const std::string & name() const
Return port name (for DPRINTF).
Definition etherint.hh:62
IGbEInt(const std::string &name, IGbE *d)
Definition i8254xGBe.hh:512
virtual void sendDone()
Definition i8254xGBe.hh:517
virtual bool recvPacket(EthPacketPtr pkt)
Definition i8254xGBe.hh:516
virtual long descLen() const =0
virtual long descHead() const =0
void wbComplete()
Called by event when dma to writeback descriptors is completed.
unsigned descUsed() const
Definition i8254xGBe.hh:285
virtual void updateHead(long h)=0
virtual void actionAfterWb()
Definition i8254xGBe.hh:190
virtual Addr descBase() const =0
std::string annUsedCacheQ
Definition i8254xGBe.hh:233
std::string annUsedDescQ
Definition i8254xGBe.hh:234
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void areaChanged()
If the address/len/head change when we've got descriptors that are dirty that is very bad.
Definition i8254xGBe.cc:849
Addr pciToDma(Addr a)
Shortcut for DMA address translation.
Definition i8254xGBe.hh:229
EventFunctionWrapper fetchDelayEvent
Definition i8254xGBe.hh:256
unsigned descUnused() const
Definition i8254xGBe.hh:288
virtual void fetchAfterWb()=0
std::deque< T * > CacheType
Definition i8254xGBe.hh:193
virtual bool hasOutstandingEvents()
Definition i8254xGBe.hh:298
void fetchComplete()
Called by event when dma to read descriptors is completed.
Definition i8254xGBe.cc:990
std::string annUnusedDescQ
Definition i8254xGBe.hh:233
std::string annUnusedCacheQ
Definition i8254xGBe.hh:234
EventFunctionWrapper fetchEvent
Definition i8254xGBe.hh:261
std::string name()
Definition i8254xGBe.hh:239
virtual void enableSm()=0
unsigned descLeft() const
Definition i8254xGBe.hh:272
EthPacketPtr pktPtr
The packet that is currently being dmad to memory if any.
Definition i8254xGBe.hh:226
void serialize(CheckpointOut &cp) const override
Serialize an object.
virtual long descTail() const =0
void writeback(Addr aMask)
Definition i8254xGBe.cc:859
EventFunctionWrapper wbDelayEvent
Definition i8254xGBe.hh:249
void fetchDescriptors()
Fetch a chunk of descriptors into the descriptor cache.
Definition i8254xGBe.cc:931
EventFunctionWrapper wbEvent
Definition i8254xGBe.hh:266
DescCache(IGbE *i, const std::string n, int s)
Definition i8254xGBe.cc:827
std::string annSmFetch
Annotate sm.
Definition i8254xGBe.hh:233
bool hasOutstandingEvents() override
long descTail() const override
Definition i8254xGBe.hh:311
void fetchAfterWb() override
Definition i8254xGBe.hh:314
long descHead() const override
Definition i8254xGBe.hh:309
EventFunctionWrapper pktEvent
Definition i8254xGBe.hh:349
void pktComplete()
Called by event when dma to write packet is completed.
Addr descBase() const override
Definition i8254xGBe.hh:308
void updateHead(long h) override
Definition i8254xGBe.hh:312
int writePacket(EthPacketPtr packet, int pkt_offset)
Write the given packet into the buffer(s) pointed to by the descriptor and update the book keeping.
long descLen() const override
Definition i8254xGBe.hh:310
void serialize(CheckpointOut &cp) const override
Serialize an object.
unsigned bytesCopied
Bytes of packet that have been copied, so we know when to set EOP.
Definition i8254xGBe.hh:326
void unserialize(CheckpointIn &cp) override
Unserialize an object.
EventFunctionWrapper pktHdrEvent
Definition i8254xGBe.hh:354
void enableSm() override
int splitCount
Variable to head with header/data completion events.
Definition i8254xGBe.hh:322
bool packetDone()
Check if the dma on the packet has completed and RX state machine can continue.
EventFunctionWrapper pktDataEvent
Definition i8254xGBe.hh:355
unsigned descInBlock(unsigned num_desc)
Return the number of dsecriptors in a cache block for threshold operations.
Definition i8254xGBe.hh:422
bool packetMultiDesc()
Ask if this packet is composed of multiple descriptors so even if we've got data, we need to wait for...
Definition i8254xGBe.hh:444
void completionWriteback(Addr a, bool enabled)
Definition i8254xGBe.hh:455
bool packetAvailable()
Ask if the packet has been transfered so the state machine can give it to the fifo.
bool packetWaiting()
Ask if we are still waiting for the packet to be transfered.
Definition i8254xGBe.hh:436
void fetchAfterWb() override
Definition i8254xGBe.hh:376
void getPacketData(EthPacketPtr p)
long descLen() const override
Definition i8254xGBe.hh:372
long descTail() const override
Definition i8254xGBe.hh:371
EventFunctionWrapper pktEvent
Definition i8254xGBe.hh:449
long descHead() const override
Definition i8254xGBe.hh:370
bool hasOutstandingEvents() override
unsigned getPacketSize(EthPacketPtr p)
Tell the cache to DMA a packet from main memory into its buffer and return the size the of the packet...
EventFunctionWrapper headerEvent
Definition i8254xGBe.hh:452
void updateHead(long h) override
Definition i8254xGBe.hh:373
EventFunctionWrapper nullEvent
Definition i8254xGBe.hh:468
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Addr descBase() const override
Definition i8254xGBe.hh:369
void pktComplete()
Called by event when dma to write packet is completed.
void enableSm() override
void actionAfterWb() override
void serialize(CheckpointOut &cp) const override
Serialize an object.
Tick lastInterrupt
Definition i8254xGBe.hh:488
uint64_t macAddr
Definition i8254xGBe.hh:140
void radvProcess()
Definition i8254xGBe.hh:107
EventFunctionWrapper interEvent
Definition i8254xGBe.hh:163
Tick fetchDelay
Definition i8254xGBe.hh:92
bool rxTick
Definition i8254xGBe.hh:82
void ethTxDone()
TxDescCache txDescCache
Definition i8254xGBe.hh:476
Tick wbDelay
Definition i8254xGBe.hh:92
void rxStateMachine()
IGbEInt * etherInt
Definition i8254xGBe.hh:63
void postInterrupt(igbreg::IntTypes t, bool now=false)
Write an interrupt into the interrupt pending register and check mask and interrupt limit timer befor...
Definition i8254xGBe.cc:696
uint8_t eeAddr
Definition i8254xGBe.hh:70
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition i8254xGBe.cc:358
Tick txReadDelay
Definition i8254xGBe.hh:94
void chkInterrupt()
Check and see if changes to the mask register have caused an interrupt to need to be sent or perhaps ...
Definition i8254xGBe.cc:792
EventFunctionWrapper tickEvent
Definition i8254xGBe.hh:137
bool txTick
Definition i8254xGBe.hh:83
PARAMS(IGbE)
PacketFifo txFifo
Definition i8254xGBe.hh:75
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
friend class RxDescCache
Definition i8254xGBe.hh:362
IGbE(const Params &params)
Definition i8254xGBe.cc:61
PacketFifo rxFifo
Definition i8254xGBe.hh:74
uint16_t flash[igbreg::EEPROM_SIZE]
Definition i8254xGBe.hh:71
void drainResume() override
Resume execution after a successful drain.
void cpuClearInt()
Clear the interupt line to the cpu.
Definition i8254xGBe.cc:780
EventFunctionWrapper radvEvent
Definition i8254xGBe.hh:114
uint8_t eeOpcode
Definition i8254xGBe.hh:70
void cpuPostInt()
Definition i8254xGBe.cc:736
Tick wbCompDelay
Definition i8254xGBe.hh:93
bool txFifoTick
Definition i8254xGBe.hh:84
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition i8254xGBe.cc:170
RxDescCache rxDescCache
Definition i8254xGBe.hh:364
Tick rxWriteDelay
Definition i8254xGBe.hh:94
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition i8254xGBe.cc:143
bool inTick
Definition i8254xGBe.hh:81
EventFunctionWrapper tidvEvent
Definition i8254xGBe.hh:133
void serialize(CheckpointOut &cp) const override
Serialize an object.
unsigned pktOffset
Definition i8254xGBe.hh:89
void tadvProcess()
Definition i8254xGBe.hh:117
Tick writeConfig(PacketPtr pkt) override
Write to the PCI config space data that is stored locally.
Definition i8254xGBe.cc:151
void rdtrProcess()
Definition i8254xGBe.hh:97
void unserialize(CheckpointIn &cp) override
Unserialize an object.
EthPacketPtr txPacket
Definition i8254xGBe.hh:78
int eeDataBits
Definition i8254xGBe.hh:69
EventFunctionWrapper tadvEvent
Definition i8254xGBe.hh:124
void tidvProcess()
Definition i8254xGBe.hh:127
void checkDrain()
Check if all the draining things that need to occur have occured and handle the drain event if so.
friend class TxDescCache
Definition i8254xGBe.hh:474
bool ethRxPkt(EthPacketPtr packet)
void delayIntEvent()
Send an interrupt to the cpu.
Definition i8254xGBe.cc:729
void tick()
Tick intClock()
Definition i8254xGBe.hh:169
void txStateMachine()
Tick fetchCompDelay
Definition i8254xGBe.hh:93
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition i8254xGBe.cc:137
igbreg::Regs regs
Definition i8254xGBe.hh:66
bool rxDmaPacket
Definition i8254xGBe.hh:86
void restartClock()
This function is used to restart the clock so it can handle things like draining and resume in one pl...
int eeAddrBits
Definition i8254xGBe.hh:69
EventFunctionWrapper rdtrEvent
Definition i8254xGBe.hh:104
void txWire()
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Addr pciToDma(Addr pci_addr) const
Definition device.hh:359
Ports are used to interface objects to each other.
Definition port.hh:62
Basic support for object serialization.
Definition serialize.hh:170
STL deque class.
Definition stl.hh:44
Base Ethernet Device declaration.
DrainState drainState() const
Return the current drain state of an object.
Definition drain.hh:324
DrainState
Object drain/handover states.
Definition drain.hh:75
@ Running
Running normally.
bool scheduled() const
Determine if the current event is scheduled.
Definition eventq.hh:458
const Params & params() const
Bitfield< 31 > n
Bitfield< 5 > t
Definition misc_types.hh:71
Bitfield< 4 > s
Bitfield< 21 > writeback
Definition types.hh:126
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 8 > a
Definition misc_types.hh:66
Bitfield< 9 > d
Definition misc_types.hh:64
Bitfield< 0 > p
const uint8_t EEPROM_SIZE
Tick ns
nanosecond
Definition core.cc:68
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
const PortID InvalidPortID
Definition types.hh:246
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
uint64_t Tick
Tick count type.
Definition types.hh:58
std::shared_ptr< EthPacketData > EthPacketPtr
Definition etherpkt.hh:90

Generated on Tue Jun 18 2024 16:24:03 for gem5 by doxygen 1.11.0