2 * Copyright (c) 2004 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 __NS_GIGE_HH__
35 #define __NS_GIGE_HH__
37 //#include "base/range.hh"
38 #include "dev/etherint.hh"
39 #include "dev/etherpkt.hh"
40 #include "sim/eventq.hh"
41 #include "dev/ns_gige_reg.h"
42 #include "base/statistics.hh"
43 #include "dev/pcidev.hh"
44 #include "dev/tsunami.hh"
45 #include "dev/io_device.hh"
46 #include "mem/bus/bus.hh"
48 /** defined by the NS83820 data sheet */
49 //these are now params for the device
50 //#define MAX_TX_FIFO_SIZE 8192
51 //#define MAX_RX_FIFO_SIZE 32768
53 /** length of ethernet address in bytes */
57 * Ethernet device registers
95 /** for perfect match memory. the linux driver doesn't use any other ROM */
96 uint8_t perfectMatch[EADDR_LEN];
101 class PhysicalMemory;
108 * NS DP82830 Ethernet device model
110 class NSGigE : public PciDev
113 /** Transmit State Machine states */
125 /** Receive State Machine States */
147 /** pointer to the chipset */
152 static const Addr size = sizeof(dp_regs);
155 typedef std::deque<PacketPtr> pktbuf_t;
156 typedef pktbuf_t::iterator pktiter_t;
158 /** device register file */
169 /*** BASIC STRUCTURES FOR TX/RX ***/
172 uint32_t maxTxFifoSize;
174 uint32_t maxRxFifoSize;
176 /** various helper vars */
179 uint8_t *txPacketBufPtr;
180 uint8_t *rxPacketBufPtr;
190 /* tx State Machine */
192 /** Current Transmit Descriptor Done */
194 /** current amt of free space in txDataFifo in bytes */
195 uint32_t txFifoAvail;
196 /** halt the tx state machine after next packet */
198 /** ptr to the next byte in the current fragment */
200 /** count of bytes remaining in the current descriptor */
204 /** rx State Machine */
206 /** Current Receive Descriptor Done */
208 /** num of bytes in the current packet being drained from rxDataFifo */
210 /** number of bytes in the rxFifo */
212 /** halt the rx state machine after current packet */
214 /** ptr to the next byte in current fragment */
216 /** count of bytes remaining in the current descriptor */
234 void rxDmaReadCopy();
235 void rxDmaWriteCopy();
242 void txDmaReadCopy();
243 void txDmaWriteCopy();
245 void rxDmaReadDone();
246 friend class EventWrapper<NSGigE, &NSGigE::rxDmaReadDone>;
247 EventWrapper<NSGigE, &NSGigE::rxDmaReadDone> rxDmaReadEvent;
249 void rxDmaWriteDone();
250 friend class EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone>;
251 EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone> rxDmaWriteEvent;
253 void txDmaReadDone();
254 friend class EventWrapper<NSGigE, &NSGigE::txDmaReadDone>;
255 EventWrapper<NSGigE, &NSGigE::txDmaReadDone> txDmaReadEvent;
257 void txDmaWriteDone();
258 friend class EventWrapper<NSGigE, &NSGigE::txDmaWriteDone>;
259 EventWrapper<NSGigE, &NSGigE::txDmaWriteDone> txDmaWriteEvent;
275 typedef EventWrapper<NSGigE, &NSGigE::rxKick> RxKickEvent;
276 friend class RxKickEvent;
280 typedef EventWrapper<NSGigE, &NSGigE::txKick> TxKickEvent;
281 friend class TxKickEvent;
287 void txEventTransmit()
290 if (txState == txFifoBlock)
293 typedef EventWrapper<NSGigE, &NSGigE::txEventTransmit> TxEvent;
294 friend class TxEvent;
301 * receive address filter
304 bool rxFilter(PacketPtr packet);
305 bool acceptBroadcast;
306 bool acceptMulticast;
311 PhysicalMemory *physmem;
314 * Interrupt management
316 IntrControl *intctrl;
317 void devIntrPost(uint32_t interrupts);
318 void devIntrClear(uint32_t interrupts);
319 void devIntrChangeMask();
324 void cpuIntrPost(Tick when);
328 typedef EventWrapper<NSGigE, &NSGigE::cpuInterrupt> IntrEvent;
329 friend class IntrEvent;
330 IntrEvent *intrEvent;
333 * Hardware checksum support
335 bool udpChecksum(PacketPtr packet, bool gen);
336 bool tcpChecksum(PacketPtr packet, bool gen);
337 bool ipChecksum(PacketPtr packet, bool gen);
338 uint16_t checksumCalc(uint16_t *pseudo, uint16_t *buf, uint32_t len);
340 NSGigEInt *interface;
343 NSGigE(const std::string &name, IntrControl *i, Tick intr_delay,
344 PhysicalMemory *pmem, Tick tx_delay, Tick rx_delay,
345 MemoryController *mmu, HierParams *hier, Bus *header_bus,
346 Bus *payload_bus, Tick pio_latency, bool dma_desc_free,
347 bool dma_data_free, Tick dma_read_delay, Tick dma_write_delay,
348 Tick dma_read_factor, Tick dma_write_factor, PciConfigAll *cf,
349 PciConfigData *cd, Tsunami *t, uint32_t bus, uint32_t dev,
350 uint32_t func, bool rx_filter, const int eaddr[6],
351 uint32_t tx_fifo_size, uint32_t rx_fifo_size);
354 virtual void WriteConfig(int offset, int size, uint32_t data);
355 virtual void ReadConfig(int offset, int size, uint8_t *data);
357 virtual Fault read(MemReqPtr &req, uint8_t *data);
358 virtual Fault write(MemReqPtr &req, const uint8_t *data);
360 bool cpuIntrPending() const;
361 void cpuIntrAck() { cpuIntrClear(); }
363 bool recvPacket(PacketPtr packet);
366 void setInterface(NSGigEInt *i) { assert(!interface); interface = i; }
368 virtual void serialize(std::ostream &os);
369 virtual void unserialize(Checkpoint *cp, const std::string §ion);
375 Stats::Scalar<> txBytes;
376 Stats::Scalar<> rxBytes;
377 Stats::Scalar<> txPackets;
378 Stats::Scalar<> rxPackets;
379 Stats::Scalar<> txIPChecksums;
380 Stats::Scalar<> rxIPChecksums;
381 Stats::Scalar<> txTCPChecksums;
382 Stats::Scalar<> rxTCPChecksums;
383 Stats::Scalar<> descDmaReads;
384 Stats::Scalar<> descDmaWrites;
385 Stats::Scalar<> descDmaRdBytes;
386 Stats::Scalar<> descDmaWrBytes;
387 Stats::Formula txBandwidth;
388 Stats::Formula rxBandwidth;
389 Stats::Formula txPacketRate;
390 Stats::Formula rxPacketRate;
393 Tick cacheAccess(MemReqPtr &req);
397 * Ethernet Interface for an Ethernet Device
399 class NSGigEInt : public EtherInt
405 NSGigEInt(const std::string &name, NSGigE *d)
406 : EtherInt(name), dev(d) { dev->setInterface(this); }
408 virtual bool recvPacket(PacketPtr &pkt) { return dev->recvPacket(pkt); }
409 virtual void sendDone() { dev->transferDone(); }
412 #endif // __NS_GIGE_HH__