2 * Copyright (c) 2004-2005 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.
28 * Authors: Nathan Binkert
33 * Device module for modelling the National Semiconductor
34 * DP83820 ethernet controller
37 #ifndef __DEV_NS_GIGE_HH__
38 #define __DEV_NS_GIGE_HH__
40 #include "base/inet.hh"
41 #include "base/statistics.hh"
42 #include "dev/etherint.hh"
43 #include "dev/etherpkt.hh"
44 #include "dev/io_device.hh"
45 #include "dev/ns_gige_reg.h"
46 #include "dev/pcidev.hh"
47 #include "dev/pktfifo.hh"
48 #include "sim/eventq.hh"
50 // Hash filtering constants
51 const uint16_t FHASH_ADDR = 0x100;
52 const uint16_t FHASH_SIZE = 0x100;
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
62 * Ethernet device registers
103 * for perfect match memory.
104 * the linux driver doesn't use any other ROM
106 uint8_t perfectMatch[ETH_ADDR_LEN];
109 * for hash table memory.
110 * used by the freebsd driver
112 uint8_t filterHash[FHASH_SIZE];
119 * NS DP83820 Ethernet device model
121 class NSGigE : public PciDev
124 /** Transmit State Machine states */
136 /** Receive State Machine States */
157 /** EEPROM State Machine States */
167 /** device register file */
178 /*** BASIC STRUCTURES FOR TX/RX ***/
183 /** various helper vars */
184 EthPacketPtr txPacket;
185 EthPacketPtr rxPacket;
186 uint8_t *txPacketBufPtr;
187 uint8_t *rxPacketBufPtr;
199 /* state machine cycle time */
201 inline Tick cycles(int numCycles) const { return numCycles * clock; }
203 /* tx State Machine */
207 /** Current Transmit Descriptor Done */
209 /** halt the tx state machine after next packet */
211 /** ptr to the next byte in the current fragment */
213 /** count of bytes remaining in the current descriptor */
217 /** rx State Machine */
221 /** Current Receive Descriptor Done */
223 /** num of bytes in the current packet being drained from rxDataFifo */
225 /** halt the rx state machine after current packet */
227 /** ptr to the next byte in current fragment */
229 /** count of bytes remaining in the current descriptor */
235 /** EEPROM State Machine */
236 EEPROMState eepromState;
238 uint8_t eepromBitsToRx;
239 uint8_t eepromOpcode;
240 uint8_t eepromAddress;
262 void rxDmaReadDone();
263 friend class EventWrapper<NSGigE, &NSGigE::rxDmaReadDone>;
264 EventWrapper<NSGigE, &NSGigE::rxDmaReadDone> rxDmaReadEvent;
266 void rxDmaWriteDone();
267 friend class EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone>;
268 EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone> rxDmaWriteEvent;
270 void txDmaReadDone();
271 friend class EventWrapper<NSGigE, &NSGigE::txDmaReadDone>;
272 EventWrapper<NSGigE, &NSGigE::txDmaReadDone> txDmaReadEvent;
274 void txDmaWriteDone();
275 friend class EventWrapper<NSGigE, &NSGigE::txDmaWriteDone>;
276 EventWrapper<NSGigE, &NSGigE::txDmaWriteDone> txDmaWriteEvent;
291 typedef EventWrapper<NSGigE, &NSGigE::rxKick> RxKickEvent;
292 friend void RxKickEvent::process();
293 RxKickEvent rxKickEvent;
297 typedef EventWrapper<NSGigE, &NSGigE::txKick> TxKickEvent;
298 friend void TxKickEvent::process();
299 TxKickEvent txKickEvent;
307 void txEventTransmit()
310 if (txState == txFifoBlock)
313 typedef EventWrapper<NSGigE, &NSGigE::txEventTransmit> TxEvent;
314 friend void TxEvent::process();
321 * receive address filter
324 bool rxFilter(const EthPacketPtr &packet);
325 bool acceptBroadcast;
326 bool acceptMulticast;
330 bool multicastHashEnable;
333 * Interrupt management
335 void devIntrPost(uint32_t interrupts);
336 void devIntrClear(uint32_t interrupts);
337 void devIntrChangeMask();
342 void cpuIntrPost(Tick when);
346 typedef EventWrapper<NSGigE, &NSGigE::cpuInterrupt> IntrEvent;
347 friend void IntrEvent::process();
348 IntrEvent *intrEvent;
349 NSGigEInt *interface;
352 struct Params : public PciDev::Params
361 Tick dma_write_delay;
362 Tick dma_read_factor;
363 Tick dma_write_factor;
366 uint32_t tx_fifo_size;
367 uint32_t rx_fifo_size;
371 bool dma_no_allocate;
374 NSGigE(Params *params);
376 const Params *params() const { return (const Params *)_params; }
378 virtual Tick writeConfig(PacketPtr pkt);
380 virtual Tick read(PacketPtr pkt);
381 virtual Tick write(PacketPtr pkt);
383 bool cpuIntrPending() const;
384 void cpuIntrAck() { cpuIntrClear(); }
386 bool recvPacket(EthPacketPtr packet);
389 void setInterface(NSGigEInt *i) { assert(!interface); interface = i; }
391 virtual void serialize(std::ostream &os);
392 virtual void unserialize(Checkpoint *cp, const std::string §ion);
394 virtual void resume();
400 Stats::Scalar<> txBytes;
401 Stats::Scalar<> rxBytes;
402 Stats::Scalar<> txPackets;
403 Stats::Scalar<> rxPackets;
404 Stats::Scalar<> txIpChecksums;
405 Stats::Scalar<> rxIpChecksums;
406 Stats::Scalar<> txTcpChecksums;
407 Stats::Scalar<> rxTcpChecksums;
408 Stats::Scalar<> txUdpChecksums;
409 Stats::Scalar<> rxUdpChecksums;
410 Stats::Scalar<> descDmaReads;
411 Stats::Scalar<> descDmaWrites;
412 Stats::Scalar<> descDmaRdBytes;
413 Stats::Scalar<> descDmaWrBytes;
414 Stats::Formula totBandwidth;
415 Stats::Formula totPackets;
416 Stats::Formula totBytes;
417 Stats::Formula totPacketRate;
418 Stats::Formula txBandwidth;
419 Stats::Formula rxBandwidth;
420 Stats::Formula txPacketRate;
421 Stats::Formula rxPacketRate;
422 Stats::Scalar<> postedSwi;
423 Stats::Formula coalescedSwi;
424 Stats::Scalar<> totalSwi;
425 Stats::Scalar<> postedRxIdle;
426 Stats::Formula coalescedRxIdle;
427 Stats::Scalar<> totalRxIdle;
428 Stats::Scalar<> postedRxOk;
429 Stats::Formula coalescedRxOk;
430 Stats::Scalar<> totalRxOk;
431 Stats::Scalar<> postedRxDesc;
432 Stats::Formula coalescedRxDesc;
433 Stats::Scalar<> totalRxDesc;
434 Stats::Scalar<> postedTxOk;
435 Stats::Formula coalescedTxOk;
436 Stats::Scalar<> totalTxOk;
437 Stats::Scalar<> postedTxIdle;
438 Stats::Formula coalescedTxIdle;
439 Stats::Scalar<> totalTxIdle;
440 Stats::Scalar<> postedTxDesc;
441 Stats::Formula coalescedTxDesc;
442 Stats::Scalar<> totalTxDesc;
443 Stats::Scalar<> postedRxOrn;
444 Stats::Formula coalescedRxOrn;
445 Stats::Scalar<> totalRxOrn;
446 Stats::Formula coalescedTotal;
447 Stats::Scalar<> postedInterrupts;
448 Stats::Scalar<> droppedPackets;
452 * Ethernet Interface for an Ethernet Device
454 class NSGigEInt : public EtherInt
460 NSGigEInt(const std::string &name, NSGigE *d)
461 : EtherInt(name), dev(d) { dev->setInterface(this); }
463 virtual bool recvPacket(EthPacketPtr pkt) { return dev->recvPacket(pkt); }
464 virtual void sendDone() { dev->transferDone(); }
467 #endif // __DEV_NS_GIGE_HH__