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 /** device register file */
184 /*** BASIC STRUCTURES FOR TX/RX ***/
189 /** various helper vars */
192 uint8_t *txPacketBufPtr;
193 uint8_t *rxPacketBufPtr;
205 /* state machine cycle time */
207 inline Tick cycles(int numCycles) const { return numCycles * clock; }
209 /* tx State Machine */
213 /** Current Transmit Descriptor Done */
215 /** halt the tx state machine after next packet */
217 /** ptr to the next byte in the current fragment */
219 /** count of bytes remaining in the current descriptor */
223 /** rx State Machine */
227 /** Current Receive Descriptor Done */
229 /** num of bytes in the current packet being drained from rxDataFifo */
231 /** halt the rx state machine after current packet */
233 /** ptr to the next byte in current fragment */
235 /** count of bytes remaining in the current descriptor */
239 struct RegWriteData {
242 RegWriteData(Addr da, uint32_t val) : daddr(da), value(val) {}
245 std::vector<std::list<RegWriteData> > writeQueue;
250 /** EEPROM State Machine */
251 EEPROMState eepromState;
253 uint8_t eepromBitsToRx;
254 uint8_t eepromOpcode;
255 uint8_t eepromAddress;
270 void rxDmaReadCopy();
271 void rxDmaWriteCopy();
278 void txDmaReadCopy();
279 void txDmaWriteCopy();
281 void rxDmaReadDone();
282 friend class EventWrapper<NSGigE, &NSGigE::rxDmaReadDone>;
283 EventWrapper<NSGigE, &NSGigE::rxDmaReadDone> rxDmaReadEvent;
285 void rxDmaWriteDone();
286 friend class EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone>;
287 EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone> rxDmaWriteEvent;
289 void txDmaReadDone();
290 friend class EventWrapper<NSGigE, &NSGigE::txDmaReadDone>;
291 EventWrapper<NSGigE, &NSGigE::txDmaReadDone> txDmaReadEvent;
293 void txDmaWriteDone();
294 friend class EventWrapper<NSGigE, &NSGigE::txDmaWriteDone>;
295 EventWrapper<NSGigE, &NSGigE::txDmaWriteDone> txDmaWriteEvent;
310 typedef EventWrapper<NSGigE, &NSGigE::rxKick> RxKickEvent;
311 friend void RxKickEvent::process();
312 RxKickEvent rxKickEvent;
316 typedef EventWrapper<NSGigE, &NSGigE::txKick> TxKickEvent;
317 friend void TxKickEvent::process();
318 TxKickEvent txKickEvent;
326 void txEventTransmit()
329 if (txState == txFifoBlock)
332 typedef EventWrapper<NSGigE, &NSGigE::txEventTransmit> TxEvent;
333 friend void TxEvent::process();
340 * receive address filter
343 bool rxFilter(const PacketPtr &packet);
344 bool acceptBroadcast;
345 bool acceptMulticast;
349 bool multicastHashEnable;
351 PhysicalMemory *physmem;
354 * Interrupt management
356 void devIntrPost(uint32_t interrupts);
357 void devIntrClear(uint32_t interrupts);
358 void devIntrChangeMask();
363 void cpuIntrPost(Tick when);
367 typedef EventWrapper<NSGigE, &NSGigE::cpuInterrupt> IntrEvent;
368 friend void IntrEvent::process();
369 IntrEvent *intrEvent;
370 NSGigEInt *interface;
373 struct Params : public PciDev::Params
375 PhysicalMemory *pmem;
385 bool pio_delay_write;
389 Tick dma_write_delay;
390 Tick dma_read_factor;
391 Tick dma_write_factor;
394 uint32_t tx_fifo_size;
395 uint32_t rx_fifo_size;
398 bool dma_no_allocate;
401 NSGigE(Params *params);
403 const Params *params() const { return (const Params *)_params; }
405 virtual void writeConfig(int offset, int size, const uint8_t *data);
406 virtual void readConfig(int offset, int size, uint8_t *data);
408 virtual Fault * read(MemReqPtr &req, uint8_t *data);
409 virtual Fault * write(MemReqPtr &req, const uint8_t *data);
411 bool cpuIntrPending() const;
412 void cpuIntrAck() { cpuIntrClear(); }
414 bool recvPacket(PacketPtr packet);
417 void setInterface(NSGigEInt *i) { assert(!interface); interface = i; }
419 virtual void serialize(std::ostream &os);
420 virtual void unserialize(Checkpoint *cp, const std::string §ion);
426 Stats::Scalar<> txBytes;
427 Stats::Scalar<> rxBytes;
428 Stats::Scalar<> txPackets;
429 Stats::Scalar<> rxPackets;
430 Stats::Scalar<> txIpChecksums;
431 Stats::Scalar<> rxIpChecksums;
432 Stats::Scalar<> txTcpChecksums;
433 Stats::Scalar<> rxTcpChecksums;
434 Stats::Scalar<> txUdpChecksums;
435 Stats::Scalar<> rxUdpChecksums;
436 Stats::Scalar<> descDmaReads;
437 Stats::Scalar<> descDmaWrites;
438 Stats::Scalar<> descDmaRdBytes;
439 Stats::Scalar<> descDmaWrBytes;
440 Stats::Formula totBandwidth;
441 Stats::Formula totPackets;
442 Stats::Formula totBytes;
443 Stats::Formula totPacketRate;
444 Stats::Formula txBandwidth;
445 Stats::Formula rxBandwidth;
446 Stats::Formula txPacketRate;
447 Stats::Formula rxPacketRate;
448 Stats::Scalar<> postedSwi;
449 Stats::Formula coalescedSwi;
450 Stats::Scalar<> totalSwi;
451 Stats::Scalar<> postedRxIdle;
452 Stats::Formula coalescedRxIdle;
453 Stats::Scalar<> totalRxIdle;
454 Stats::Scalar<> postedRxOk;
455 Stats::Formula coalescedRxOk;
456 Stats::Scalar<> totalRxOk;
457 Stats::Scalar<> postedRxDesc;
458 Stats::Formula coalescedRxDesc;
459 Stats::Scalar<> totalRxDesc;
460 Stats::Scalar<> postedTxOk;
461 Stats::Formula coalescedTxOk;
462 Stats::Scalar<> totalTxOk;
463 Stats::Scalar<> postedTxIdle;
464 Stats::Formula coalescedTxIdle;
465 Stats::Scalar<> totalTxIdle;
466 Stats::Scalar<> postedTxDesc;
467 Stats::Formula coalescedTxDesc;
468 Stats::Scalar<> totalTxDesc;
469 Stats::Scalar<> postedRxOrn;
470 Stats::Formula coalescedRxOrn;
471 Stats::Scalar<> totalRxOrn;
472 Stats::Formula coalescedTotal;
473 Stats::Scalar<> postedInterrupts;
474 Stats::Scalar<> droppedPackets;
477 Tick cacheAccess(MemReqPtr &req);
481 * Ethernet Interface for an Ethernet Device
483 class NSGigEInt : public EtherInt
489 NSGigEInt(const std::string &name, NSGigE *d)
490 : EtherInt(name), dev(d) { dev->setInterface(this); }
492 virtual bool recvPacket(PacketPtr pkt) { return dev->recvPacket(pkt); }
493 virtual void sendDone() { dev->transferDone(); }
496 #endif // __DEV_NS_GIGE_HH__