gem5  v22.1.0.0
ns_gige.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2005 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 
34 #ifndef __DEV_NET_NS_GIGE_HH__
35 #define __DEV_NET_NS_GIGE_HH__
36 
37 #include "base/inet.hh"
38 #include "dev/io_device.hh"
39 #include "dev/net/etherdevice.hh"
40 #include "dev/net/etherint.hh"
41 #include "dev/net/etherpkt.hh"
42 #include "dev/net/ns_gige_reg.h"
43 #include "dev/net/pktfifo.hh"
44 #include "params/NSGigE.hh"
45 #include "sim/eventq.hh"
46 
47 namespace gem5
48 {
49 
50 // Hash filtering constants
51 const uint16_t FHASH_ADDR = 0x100;
52 const uint16_t FHASH_SIZE = 0x100;
53 
54 // EEPROM constants
55 const uint8_t EEPROM_READ = 0x2;
56 const uint8_t EEPROM_SIZE = 64; // Size in words of NSC93C46 EEPROM
57 const uint8_t EEPROM_PMATCH2_ADDR = 0xA; // EEPROM Address of PMATCH word 2
58 const uint8_t EEPROM_PMATCH1_ADDR = 0xB; // EEPROM Address of PMATCH word 1
59 const uint8_t EEPROM_PMATCH0_ADDR = 0xC; // EEPROM Address of PMATCH word 0
60 
64 struct dp_regs
65 {
66  uint32_t command;
67  uint32_t config;
68  uint32_t mear;
69  uint32_t ptscr;
70  uint32_t isr;
71  uint32_t imr;
72  uint32_t ier;
73  uint32_t ihr;
74  uint32_t txdp;
75  uint32_t txdp_hi;
76  uint32_t txcfg;
77  uint32_t gpior;
78  uint32_t rxdp;
79  uint32_t rxdp_hi;
80  uint32_t rxcfg;
81  uint32_t pqcr;
82  uint32_t wcsr;
83  uint32_t pcr;
84  uint32_t rfcr;
85  uint32_t rfdr;
86  uint32_t brar;
87  uint32_t brdr;
88  uint32_t srr;
89  uint32_t mibc;
90  uint32_t vrcr;
91  uint32_t vtcr;
92  uint32_t vdr;
93  uint32_t ccsr;
94  uint32_t tbicr;
95  uint32_t tbisr;
96  uint32_t tanar;
97  uint32_t tanlpar;
98  uint32_t taner;
99  uint32_t tesr;
100 };
101 
102 struct dp_rom
103 {
108  uint8_t perfectMatch[ETH_ADDR_LEN];
109 
115 };
116 
117 class NSGigEInt;
118 class Packet;
119 
123 class NSGigE : public EtherDevBase
124 {
125  public:
127  enum TxState
128  {
135  txAdvance
136  };
137 
139  enum RxState
140  {
147  rxAdvance
148  };
149 
150  enum DmaState
151  {
157  };
158 
161  {
165  eepromRead
166  };
167 
168  protected:
172 
174  bool ioEnable;
175 
176  /*** BASIC STRUCTURES FOR TX/RX ***/
177  /* Data FIFOs */
180 
184  uint8_t *txPacketBufPtr;
185  uint8_t *rxPacketBufPtr;
186  uint32_t txXferLen;
187  uint32_t rxXferLen;
188  bool rxDmaFree;
189  bool txDmaFree;
190 
196 
197  /* tx State Machine */
199  bool txEnable;
200 
202  bool CTDD;
204  bool txHalt;
208  uint32_t txDescCnt;
210 
213  bool rxEnable;
214 
216  bool CRDD;
218  uint32_t rxPktBytes;
220  bool rxHalt;
224  uint32_t rxDescCnt;
226 
228 
231  bool eepromClk;
232  uint8_t eepromBitsToRx;
233  uint8_t eepromOpcode;
234  uint8_t eepromAddress;
235  uint16_t eepromData;
236 
237  protected:
240 
243 
244  void *rxDmaData;
246  int rxDmaLen;
247  bool doRxDmaRead();
248  bool doRxDmaWrite();
249 
250  void *txDmaData;
252  int txDmaLen;
253  bool doTxDmaRead();
254  bool doTxDmaWrite();
255 
256  void rxDmaReadDone();
258 
259  void rxDmaWriteDone();
261 
262  void txDmaReadDone();
264 
265  void txDmaWriteDone();
267 
270 
271  protected:
274 
275  void txReset();
276  void rxReset();
277  void regsReset();
278 
279  void rxKick();
282 
283  void txKick();
286 
287  void eepromKick();
288 
292  void transmit();
294  {
295  transmit();
296  if (txState == txFifoBlock)
297  txKick();
298  }
300 
301  void txDump() const;
302  void rxDump() const;
303 
308  bool rxFilter(const EthPacketPtr &packet);
313  bool acceptArp;
315 
319  void devIntrPost(uint32_t interrupts);
320  void devIntrClear(uint32_t interrupts);
321  void devIntrChangeMask();
322 
326  void cpuIntrPost(Tick when);
327  void cpuInterrupt();
328  void cpuIntrClear();
329 
332 
333  public:
335 
336  NSGigE(const Params &params);
337  ~NSGigE();
338 
339  Port &getPort(const std::string &if_name,
340  PortID idx=InvalidPortID) override;
341 
342  Tick writeConfig(PacketPtr pkt) override;
343 
344  Tick read(PacketPtr pkt) override;
345  Tick write(PacketPtr pkt) override;
346 
347  bool cpuIntrPending() const;
348  void cpuIntrAck() { cpuIntrClear(); }
349 
350  bool recvPacket(EthPacketPtr packet);
351  void transferDone();
352 
353  void serialize(CheckpointOut &cp) const override;
354  void unserialize(CheckpointIn &cp) override;
355 
356  void drainResume() override;
357 };
358 
359 /*
360  * Ethernet Interface for an Ethernet Device
361  */
362 class NSGigEInt : public EtherInt
363 {
364  private:
366 
367  public:
368  NSGigEInt(const std::string &name, NSGigE *d)
369  : EtherInt(name), dev(d)
370  { }
371 
372  virtual bool recvPacket(EthPacketPtr pkt) { return dev->recvPacket(pkt); }
373  virtual void sendDone() { dev->transferDone(); }
374 };
375 
376 } // namespace gem5
377 
378 #endif // __DEV_NET_NS_GIGE_HH__
DmaDeviceParams Params
Definition: dma_device.hh:209
Dummy class to keep the Python class hierarchy in sync with the C++ object hierarchy.
Definition: etherdevice.hh:144
const std::string & name() const
Return port name (for DPRINTF).
Definition: etherint.hh:62
NSGigE * dev
Definition: ns_gige.hh:365
NSGigEInt(const std::string &name, NSGigE *d)
Definition: ns_gige.hh:368
virtual bool recvPacket(EthPacketPtr pkt)
Definition: ns_gige.hh:372
virtual void sendDone()
Definition: ns_gige.hh:373
NS DP83820 Ethernet device model.
Definition: ns_gige.hh:124
void rxDmaReadDone()
Definition: ns_gige.cc:993
uint32_t txDescCnt
count of bytes remaining in the current descriptor
Definition: ns_gige.hh:208
uint32_t rxPktBytes
num of bytes in the current packet being drained from rxDataFifo
Definition: ns_gige.hh:218
bool dmaDescFree
Definition: ns_gige.hh:268
void eepromKick()
Advance the EEPROM state machine Called on rising edge of EEPROM clock bit in MEAR.
Definition: ns_gige.cc:1799
void * txDmaData
Definition: ns_gige.hh:250
Tick rxKickTick
Definition: ns_gige.hh:280
bool CRDD
Current Receive Descriptor Done.
Definition: ns_gige.hh:216
bool rxDmaFree
Definition: ns_gige.hh:188
NSGigEInt * interface
Definition: ns_gige.hh:331
uint32_t txXferLen
Definition: ns_gige.hh:186
void cpuInterrupt()
Definition: ns_gige.cc:880
EEPROMState eepromState
EEPROM State Machine.
Definition: ns_gige.hh:230
bool rxFilterEnable
receive address filter
Definition: ns_gige.hh:307
bool doRxDmaRead()
Definition: ns_gige.cc:979
bool txHalt
halt the tx state machine after next packet
Definition: ns_gige.hh:204
Addr rxDmaAddr
Definition: ns_gige.hh:245
void cpuIntrAck()
Definition: ns_gige.hh:348
EventFunctionWrapper rxDmaWriteEvent
Definition: ns_gige.hh:260
bool acceptBroadcast
Definition: ns_gige.hh:309
void rxKick()
Definition: ns_gige.cc:1040
Tick dmaWriteDelay
Definition: ns_gige.hh:239
uint8_t * rxPacketBufPtr
Definition: ns_gige.hh:185
bool eepromClk
Definition: ns_gige.hh:231
Tick txDelay
Definition: ns_gige.hh:272
void txDmaWriteDone()
Definition: ns_gige.cc:1450
RxState rxState
rx State Machine
Definition: ns_gige.hh:212
int rxDmaLen
Definition: ns_gige.hh:246
bool acceptPerfect
Definition: ns_gige.hh:312
DmaState txDmaState
Definition: ns_gige.hh:209
void devIntrClear(uint32_t interrupts)
Definition: ns_gige.cc:790
Tick intrTick
Definition: ns_gige.hh:324
TxState txState
Definition: ns_gige.hh:198
Tick rxDelay
Definition: ns_gige.hh:273
void devIntrChangeMask()
Definition: ns_gige.cc:832
void drainResume() override
Resume execution after a successful drain.
Definition: ns_gige.cc:2002
@ dmaWriteWaiting
Definition: ns_gige.hh:156
@ dmaReadWaiting
Definition: ns_gige.hh:155
Tick writeConfig(PacketPtr pkt) override
This is to write to the PCI general configuration registers.
Definition: ns_gige.cc:151
EthPacketPtr rxPacket
Definition: ns_gige.hh:183
bool acceptUnicast
Definition: ns_gige.hh:311
Tick dmaReadDelay
Definition: ns_gige.hh:238
EventFunctionWrapper txDmaReadEvent
Definition: ns_gige.hh:263
ns_desc64 rxDesc64
Definition: ns_gige.hh:195
bool txEnable
Definition: ns_gige.hh:199
bool acceptMulticast
Definition: ns_gige.hh:310
void rxReset()
Definition: ns_gige.cc:941
ns_desc32 txDesc32
DescCaches.
Definition: ns_gige.hh:192
uint8_t * txPacketBufPtr
Definition: ns_gige.hh:184
EventFunctionWrapper txEvent
Definition: ns_gige.hh:299
bool cpuPendingIntr
Definition: ns_gige.hh:325
ns_desc64 txDesc64
Definition: ns_gige.hh:194
bool dmaDataFree
Definition: ns_gige.hh:269
void transmit()
Retransmit event.
Definition: ns_gige.cc:1355
Addr txDmaAddr
Definition: ns_gige.hh:251
ns_desc32 rxDesc32
Definition: ns_gige.hh:193
void cpuIntrPost(Tick when)
Definition: ns_gige.cc:844
void rxDump() const
EventFunctionWrapper * intrEvent
Definition: ns_gige.hh:330
dp_rom rom
Definition: ns_gige.hh:171
bool txDmaFree
Definition: ns_gige.hh:189
void txKick()
Definition: ns_gige.cc:1467
bool extstsEnable
Definition: ns_gige.hh:227
void cpuIntrClear()
Definition: ns_gige.cc:903
Tick read(PacketPtr pkt) override
This reads the device registers, which are detailed in the NS83820 spec sheet.
Definition: ns_gige.cc:187
bool doTxDmaWrite()
Definition: ns_gige.cc:1437
EventFunctionWrapper txDmaWriteEvent
Definition: ns_gige.hh:266
EEPROMState
EEPROM State Machine States.
Definition: ns_gige.hh:161
@ eepromGetAddress
Definition: ns_gige.hh:164
@ eepromGetOpcode
Definition: ns_gige.hh:163
uint32_t rxXferLen
Definition: ns_gige.hh:187
Tick txKickTick
Definition: ns_gige.hh:284
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: ns_gige.cc:2191
bool CTDD
Current Transmit Descriptor Done.
Definition: ns_gige.hh:202
bool acceptArp
Definition: ns_gige.hh:313
bool recvPacket(EthPacketPtr packet)
Definition: ns_gige.cc:1952
Tick intrDelay
Definition: ns_gige.hh:323
bool multicastHashEnable
Definition: ns_gige.hh:314
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: ns_gige.cc:175
bool ioEnable
pci settings
Definition: ns_gige.hh:174
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: ns_gige.cc:409
DmaState rxDmaState
Definition: ns_gige.hh:225
EventFunctionWrapper rxDmaReadEvent
Definition: ns_gige.hh:257
void * rxDmaData
Definition: ns_gige.hh:244
void devIntrPost(uint32_t interrupts)
Interrupt management.
Definition: ns_gige.cc:733
void txReset()
Definition: ns_gige.cc:926
EventFunctionWrapper rxKickEvent
Definition: ns_gige.hh:281
bool doTxDmaRead()
Definition: ns_gige.cc:1406
void regsReset()
Definition: ns_gige.cc:956
void transferDone()
Definition: ns_gige.cc:1896
Addr rxFragPtr
ptr to the next byte in current fragment
Definition: ns_gige.hh:222
Addr txFragPtr
ptr to the next byte in the current fragment
Definition: ns_gige.hh:206
PARAMS(NSGigE)
uint8_t eepromOpcode
Definition: ns_gige.hh:233
void rxDmaWriteDone()
Definition: ns_gige.cc:1023
uint8_t eepromAddress
Definition: ns_gige.hh:234
bool rxEnable
Definition: ns_gige.hh:213
bool doRxDmaWrite()
Definition: ns_gige.cc:1010
int txDmaLen
Definition: ns_gige.hh:252
dp_regs regs
device register file
Definition: ns_gige.hh:170
bool rxFilter(const EthPacketPtr &packet)
Definition: ns_gige.cc:1909
uint16_t eepromData
Definition: ns_gige.hh:235
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: ns_gige.cc:2018
uint32_t rxDescCnt
count of bytes remaining in the current descriptor
Definition: ns_gige.hh:224
PacketFifo rxFifo
Definition: ns_gige.hh:179
Tick dmaReadFactor
Definition: ns_gige.hh:241
TxState
Transmit State Machine states.
Definition: ns_gige.hh:128
bool rxHalt
halt the rx state machine after current packet
Definition: ns_gige.hh:220
RxState
Receive State Machine States.
Definition: ns_gige.hh:140
PacketFifo txFifo
Definition: ns_gige.hh:178
Tick dmaWriteFactor
Definition: ns_gige.hh:242
bool cpuIntrPending() const
Definition: ns_gige.cc:922
uint8_t eepromBitsToRx
Definition: ns_gige.hh:232
NSGigE(const Params &params)
Definition: ns_gige.cc:97
EthPacketPtr txPacket
various helper vars
Definition: ns_gige.hh:182
void txEventTransmit()
Definition: ns_gige.hh:293
EventFunctionWrapper txKickEvent
Definition: ns_gige.hh:285
void txDmaReadDone()
Definition: ns_gige.cc:1420
void txDump() const
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Ports are used to interface objects to each other.
Definition: port.hh:62
Base Ethernet Device declaration.
const Params & params() const
Definition: sim_object.hh:176
Bitfield< 9 > d
Definition: misc_types.hh:64
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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
const uint16_t FHASH_SIZE
Definition: ns_gige.hh:52
const uint8_t EEPROM_SIZE
Definition: ns_gige.hh:56
const uint16_t FHASH_ADDR
Definition: ns_gige.hh:51
const uint8_t EEPROM_PMATCH2_ADDR
Definition: ns_gige.hh:57
const uint8_t EEPROM_PMATCH0_ADDR
Definition: ns_gige.hh:59
const uint8_t EEPROM_READ
Definition: ns_gige.hh:55
const uint8_t EEPROM_PMATCH1_ADDR
Definition: ns_gige.hh:58
std::shared_ptr< EthPacketData > EthPacketPtr
Definition: etherpkt.hh:90
Ethernet device register definitions for the National Semiconductor DP83820 Ethernet controller.
Ethernet device registers.
Definition: ns_gige.hh:65
uint32_t brar
Definition: ns_gige.hh:86
uint32_t ihr
Definition: ns_gige.hh:73
uint32_t rfdr
Definition: ns_gige.hh:85
uint32_t isr
Definition: ns_gige.hh:70
uint32_t tbicr
Definition: ns_gige.hh:94
uint32_t rxdp
Definition: ns_gige.hh:78
uint32_t rxcfg
Definition: ns_gige.hh:80
uint32_t txdp
Definition: ns_gige.hh:74
uint32_t vtcr
Definition: ns_gige.hh:91
uint32_t pcr
Definition: ns_gige.hh:83
uint32_t imr
Definition: ns_gige.hh:71
uint32_t srr
Definition: ns_gige.hh:88
uint32_t rfcr
Definition: ns_gige.hh:84
uint32_t config
Definition: ns_gige.hh:67
uint32_t mear
Definition: ns_gige.hh:68
uint32_t txdp_hi
Definition: ns_gige.hh:75
uint32_t vdr
Definition: ns_gige.hh:92
uint32_t brdr
Definition: ns_gige.hh:87
uint32_t tesr
Definition: ns_gige.hh:99
uint32_t tbisr
Definition: ns_gige.hh:95
uint32_t taner
Definition: ns_gige.hh:98
uint32_t command
Definition: ns_gige.hh:66
uint32_t wcsr
Definition: ns_gige.hh:82
uint32_t rxdp_hi
Definition: ns_gige.hh:79
uint32_t ptscr
Definition: ns_gige.hh:69
uint32_t vrcr
Definition: ns_gige.hh:90
uint32_t ccsr
Definition: ns_gige.hh:93
uint32_t mibc
Definition: ns_gige.hh:89
uint32_t gpior
Definition: ns_gige.hh:77
uint32_t txcfg
Definition: ns_gige.hh:76
uint32_t tanar
Definition: ns_gige.hh:96
uint32_t tanlpar
Definition: ns_gige.hh:97
uint32_t ier
Definition: ns_gige.hh:72
uint32_t pqcr
Definition: ns_gige.hh:81
uint8_t perfectMatch[ETH_ADDR_LEN]
for perfect match memory.
Definition: ns_gige.hh:108
uint8_t filterHash[FHASH_SIZE]
for hash table memory.
Definition: ns_gige.hh:114

Generated on Wed Dec 21 2022 10:22:34 for gem5 by doxygen 1.9.1