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.
30 * Device module for modelling the National Semiconductor
31 * DP83820 ethernet controller
34 #ifndef __DEV_NS_GIGE_HH__
35 #define __DEV_NS_GIGE_HH__
37 #include "base/inet.hh"
38 #include "base/statistics.hh"
39 #include "dev/etherint.hh"
40 #include "dev/etherpkt.hh"
41 #include "dev/io_device.hh"
42 #include "dev/ns_gige_reg.h"
43 #include "dev/pcidev.hh"
44 #include "dev/pktfifo.hh"
45 #include "mem/bus/bus.hh"
46 #include "sim/eventq.hh"
48 // Hash filtering constants
49 const uint16_t FHASH_ADDR = 0x100;
50 const uint16_t FHASH_SIZE = 0x100;
53 const uint8_t EEPROM_READ = 0x2;
54 const uint8_t EEPROM_SIZE = 64; // Size in words of NSC93C46 EEPROM
55 const uint8_t EEPROM_PMATCH2_ADDR = 0xA; // EEPROM Address of PMATCH word 2
56 const uint8_t EEPROM_PMATCH1_ADDR = 0xB; // EEPROM Address of PMATCH word 1
57 const uint8_t EEPROM_PMATCH0_ADDR = 0xC; // EEPROM Address of PMATCH word 0
60 * Ethernet device registers
101 * for perfect match memory.
102 * the linux driver doesn't use any other ROM
104 uint8_t perfectMatch[ETH_ADDR_LEN];
107 * for hash table memory.
108 * used by the freebsd driver
110 uint8_t filterHash[FHASH_SIZE];
114 class PhysicalMemory;
121 * NS DP83820 Ethernet device model
123 class NSGigE : public PciDev
126 /** Transmit State Machine states */
138 /** Receive State Machine States */
159 /** EEPROM State Machine States */
170 static const Addr size = sizeof(dp_regs);
173 typedef std::deque<PacketPtr> pktbuf_t;
174 typedef pktbuf_t::iterator pktiter_t;
176 /** device register file */
187 /*** BASIC STRUCTURES FOR TX/RX ***/
192 /** various helper vars */
195 uint8_t *txPacketBufPtr;
196 uint8_t *rxPacketBufPtr;
208 /* state machine cycle time */
210 inline Tick cycles(int numCycles) const { return numCycles * clock; }
212 /* tx State Machine */
216 /** Current Transmit Descriptor Done */
218 /** halt the tx state machine after next packet */
220 /** ptr to the next byte in the current fragment */
222 /** count of bytes remaining in the current descriptor */
226 /** rx State Machine */
230 /** Current Receive Descriptor Done */
232 /** num of bytes in the current packet being drained from rxDataFifo */
234 /** halt the rx state machine after current packet */
236 /** ptr to the next byte in current fragment */
238 /** count of bytes remaining in the current descriptor */
244 /** EEPROM State Machine */
245 EEPROMState eepromState;
247 uint8_t eepromBitsToRx;
248 uint8_t eepromOpcode;
249 uint8_t eepromAddress;
264 void rxDmaReadCopy();
265 void rxDmaWriteCopy();
272 void txDmaReadCopy();
273 void txDmaWriteCopy();
275 void rxDmaReadDone();
276 friend class EventWrapper<NSGigE, &NSGigE::rxDmaReadDone>;
277 EventWrapper<NSGigE, &NSGigE::rxDmaReadDone> rxDmaReadEvent;
279 void rxDmaWriteDone();
280 friend class EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone>;
281 EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone> rxDmaWriteEvent;
283 void txDmaReadDone();
284 friend class EventWrapper<NSGigE, &NSGigE::txDmaReadDone>;
285 EventWrapper<NSGigE, &NSGigE::txDmaReadDone> txDmaReadEvent;
287 void txDmaWriteDone();
288 friend class EventWrapper<NSGigE, &NSGigE::txDmaWriteDone>;
289 EventWrapper<NSGigE, &NSGigE::txDmaWriteDone> txDmaWriteEvent;
304 typedef EventWrapper<NSGigE, &NSGigE::rxKick> RxKickEvent;
305 friend void RxKickEvent::process();
306 RxKickEvent rxKickEvent;
310 typedef EventWrapper<NSGigE, &NSGigE::txKick> TxKickEvent;
311 friend void TxKickEvent::process();
312 TxKickEvent txKickEvent;
320 void txEventTransmit()
323 if (txState == txFifoBlock)
326 typedef EventWrapper<NSGigE, &NSGigE::txEventTransmit> TxEvent;
327 friend void TxEvent::process();
334 * receive address filter
337 bool rxFilter(const PacketPtr &packet);
338 bool acceptBroadcast;
339 bool acceptMulticast;
343 bool multicastHashEnable;
345 PhysicalMemory *physmem;
348 * Interrupt management
350 void devIntrPost(uint32_t interrupts);
351 void devIntrClear(uint32_t interrupts);
352 void devIntrChangeMask();
357 void cpuIntrPost(Tick when);
361 typedef EventWrapper<NSGigE, &NSGigE::cpuInterrupt> IntrEvent;
362 friend void IntrEvent::process();
363 IntrEvent *intrEvent;
364 NSGigEInt *interface;
367 struct Params : public PciDev::Params
369 PhysicalMemory *pmem;
382 Tick dma_write_delay;
383 Tick dma_read_factor;
384 Tick dma_write_factor;
387 uint32_t tx_fifo_size;
388 uint32_t rx_fifo_size;
390 bool dma_no_allocate;
393 NSGigE(Params *params);
395 const Params *params() const { return (const Params *)_params; }
397 virtual void writeConfig(int offset, int size, const uint8_t *data);
398 virtual void readConfig(int offset, int size, uint8_t *data);
400 virtual Fault read(MemReqPtr &req, uint8_t *data);
401 virtual Fault write(MemReqPtr &req, const uint8_t *data);
403 bool cpuIntrPending() const;
404 void cpuIntrAck() { cpuIntrClear(); }
406 bool recvPacket(PacketPtr packet);
409 void setInterface(NSGigEInt *i) { assert(!interface); interface = i; }
411 virtual void serialize(std::ostream &os);
412 virtual void unserialize(Checkpoint *cp, const std::string §ion);
418 Stats::Scalar<> txBytes;
419 Stats::Scalar<> rxBytes;
420 Stats::Scalar<> txPackets;
421 Stats::Scalar<> rxPackets;
422 Stats::Scalar<> txIpChecksums;
423 Stats::Scalar<> rxIpChecksums;
424 Stats::Scalar<> txTcpChecksums;
425 Stats::Scalar<> rxTcpChecksums;
426 Stats::Scalar<> txUdpChecksums;
427 Stats::Scalar<> rxUdpChecksums;
428 Stats::Scalar<> descDmaReads;
429 Stats::Scalar<> descDmaWrites;
430 Stats::Scalar<> descDmaRdBytes;
431 Stats::Scalar<> descDmaWrBytes;
432 Stats::Formula totBandwidth;
433 Stats::Formula totPackets;
434 Stats::Formula totBytes;
435 Stats::Formula totPacketRate;
436 Stats::Formula txBandwidth;
437 Stats::Formula rxBandwidth;
438 Stats::Formula txPacketRate;
439 Stats::Formula rxPacketRate;
440 Stats::Scalar<> postedSwi;
441 Stats::Formula coalescedSwi;
442 Stats::Scalar<> totalSwi;
443 Stats::Scalar<> postedRxIdle;
444 Stats::Formula coalescedRxIdle;
445 Stats::Scalar<> totalRxIdle;
446 Stats::Scalar<> postedRxOk;
447 Stats::Formula coalescedRxOk;
448 Stats::Scalar<> totalRxOk;
449 Stats::Scalar<> postedRxDesc;
450 Stats::Formula coalescedRxDesc;
451 Stats::Scalar<> totalRxDesc;
452 Stats::Scalar<> postedTxOk;
453 Stats::Formula coalescedTxOk;
454 Stats::Scalar<> totalTxOk;
455 Stats::Scalar<> postedTxIdle;
456 Stats::Formula coalescedTxIdle;
457 Stats::Scalar<> totalTxIdle;
458 Stats::Scalar<> postedTxDesc;
459 Stats::Formula coalescedTxDesc;
460 Stats::Scalar<> totalTxDesc;
461 Stats::Scalar<> postedRxOrn;
462 Stats::Formula coalescedRxOrn;
463 Stats::Scalar<> totalRxOrn;
464 Stats::Formula coalescedTotal;
465 Stats::Scalar<> postedInterrupts;
466 Stats::Scalar<> droppedPackets;
469 Tick cacheAccess(MemReqPtr &req);
473 * Ethernet Interface for an Ethernet Device
475 class NSGigEInt : public EtherInt
481 NSGigEInt(const std::string &name, NSGigE *d)
482 : EtherInt(name), dev(d) { dev->setInterface(this); }
484 virtual bool recvPacket(PacketPtr pkt) { return dev->recvPacket(pkt); }
485 virtual void sendDone() { dev->transferDone(); }
488 #endif // __DEV_NS_GIGE_HH__