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 */
242 struct RegWriteData {
245 RegWriteData(Addr da, uint32_t val) : daddr(da), value(val) {}
248 std::vector<std::list<RegWriteData> > writeQueue;
253 /** EEPROM State Machine */
254 EEPROMState eepromState;
256 uint8_t eepromBitsToRx;
257 uint8_t eepromOpcode;
258 uint8_t eepromAddress;
273 void rxDmaReadCopy();
274 void rxDmaWriteCopy();
281 void txDmaReadCopy();
282 void txDmaWriteCopy();
284 void rxDmaReadDone();
285 friend class EventWrapper<NSGigE, &NSGigE::rxDmaReadDone>;
286 EventWrapper<NSGigE, &NSGigE::rxDmaReadDone> rxDmaReadEvent;
288 void rxDmaWriteDone();
289 friend class EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone>;
290 EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone> rxDmaWriteEvent;
292 void txDmaReadDone();
293 friend class EventWrapper<NSGigE, &NSGigE::txDmaReadDone>;
294 EventWrapper<NSGigE, &NSGigE::txDmaReadDone> txDmaReadEvent;
296 void txDmaWriteDone();
297 friend class EventWrapper<NSGigE, &NSGigE::txDmaWriteDone>;
298 EventWrapper<NSGigE, &NSGigE::txDmaWriteDone> txDmaWriteEvent;
313 typedef EventWrapper<NSGigE, &NSGigE::rxKick> RxKickEvent;
314 friend void RxKickEvent::process();
315 RxKickEvent rxKickEvent;
319 typedef EventWrapper<NSGigE, &NSGigE::txKick> TxKickEvent;
320 friend void TxKickEvent::process();
321 TxKickEvent txKickEvent;
329 void txEventTransmit()
332 if (txState == txFifoBlock)
335 typedef EventWrapper<NSGigE, &NSGigE::txEventTransmit> TxEvent;
336 friend void TxEvent::process();
343 * receive address filter
346 bool rxFilter(const PacketPtr &packet);
347 bool acceptBroadcast;
348 bool acceptMulticast;
352 bool multicastHashEnable;
354 PhysicalMemory *physmem;
357 * Interrupt management
359 void devIntrPost(uint32_t interrupts);
360 void devIntrClear(uint32_t interrupts);
361 void devIntrChangeMask();
366 void cpuIntrPost(Tick when);
370 typedef EventWrapper<NSGigE, &NSGigE::cpuInterrupt> IntrEvent;
371 friend void IntrEvent::process();
372 IntrEvent *intrEvent;
373 NSGigEInt *interface;
376 struct Params : public PciDev::Params
378 PhysicalMemory *pmem;
388 bool pio_delay_write;
392 Tick dma_write_delay;
393 Tick dma_read_factor;
394 Tick dma_write_factor;
397 uint32_t tx_fifo_size;
398 uint32_t rx_fifo_size;
400 bool dma_no_allocate;
403 NSGigE(Params *params);
405 const Params *params() const { return (const Params *)_params; }
407 virtual void writeConfig(int offset, int size, const uint8_t *data);
408 virtual void readConfig(int offset, int size, uint8_t *data);
410 virtual Fault read(MemReqPtr &req, uint8_t *data);
411 virtual Fault write(MemReqPtr &req, const uint8_t *data);
413 bool cpuIntrPending() const;
414 void cpuIntrAck() { cpuIntrClear(); }
416 bool recvPacket(PacketPtr packet);
419 void setInterface(NSGigEInt *i) { assert(!interface); interface = i; }
421 virtual void serialize(std::ostream &os);
422 virtual void unserialize(Checkpoint *cp, const std::string §ion);
428 Stats::Scalar<> txBytes;
429 Stats::Scalar<> rxBytes;
430 Stats::Scalar<> txPackets;
431 Stats::Scalar<> rxPackets;
432 Stats::Scalar<> txIpChecksums;
433 Stats::Scalar<> rxIpChecksums;
434 Stats::Scalar<> txTcpChecksums;
435 Stats::Scalar<> rxTcpChecksums;
436 Stats::Scalar<> txUdpChecksums;
437 Stats::Scalar<> rxUdpChecksums;
438 Stats::Scalar<> descDmaReads;
439 Stats::Scalar<> descDmaWrites;
440 Stats::Scalar<> descDmaRdBytes;
441 Stats::Scalar<> descDmaWrBytes;
442 Stats::Formula totBandwidth;
443 Stats::Formula totPackets;
444 Stats::Formula totBytes;
445 Stats::Formula totPacketRate;
446 Stats::Formula txBandwidth;
447 Stats::Formula rxBandwidth;
448 Stats::Formula txPacketRate;
449 Stats::Formula rxPacketRate;
450 Stats::Scalar<> postedSwi;
451 Stats::Formula coalescedSwi;
452 Stats::Scalar<> totalSwi;
453 Stats::Scalar<> postedRxIdle;
454 Stats::Formula coalescedRxIdle;
455 Stats::Scalar<> totalRxIdle;
456 Stats::Scalar<> postedRxOk;
457 Stats::Formula coalescedRxOk;
458 Stats::Scalar<> totalRxOk;
459 Stats::Scalar<> postedRxDesc;
460 Stats::Formula coalescedRxDesc;
461 Stats::Scalar<> totalRxDesc;
462 Stats::Scalar<> postedTxOk;
463 Stats::Formula coalescedTxOk;
464 Stats::Scalar<> totalTxOk;
465 Stats::Scalar<> postedTxIdle;
466 Stats::Formula coalescedTxIdle;
467 Stats::Scalar<> totalTxIdle;
468 Stats::Scalar<> postedTxDesc;
469 Stats::Formula coalescedTxDesc;
470 Stats::Scalar<> totalTxDesc;
471 Stats::Scalar<> postedRxOrn;
472 Stats::Formula coalescedRxOrn;
473 Stats::Scalar<> totalRxOrn;
474 Stats::Formula coalescedTotal;
475 Stats::Scalar<> postedInterrupts;
476 Stats::Scalar<> droppedPackets;
479 Tick cacheAccess(MemReqPtr &req);
483 * Ethernet Interface for an Ethernet Device
485 class NSGigEInt : public EtherInt
491 NSGigEInt(const std::string &name, NSGigE *d)
492 : EtherInt(name), dev(d) { dev->setInterface(this); }
494 virtual bool recvPacket(PacketPtr pkt) { return dev->recvPacket(pkt); }
495 virtual void sendDone() { dev->transferDone(); }
498 #endif // __DEV_NS_GIGE_HH__