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/statistics.hh"
38 #include "dev/etherint.hh"
39 #include "dev/etherpkt.hh"
40 #include "dev/io_device.hh"
41 #include "dev/ns_gige_reg.h"
42 #include "dev/pcidev.hh"
43 #include "dev/tsunami.hh"
44 #include "mem/bus/bus.hh"
45 #include "sim/eventq.hh"
47 /** length of ethernet address in bytes */
51 * Ethernet device registers
90 * for perfect match memory.
91 * the linux driver doesn't use any other ROM
93 uint8_t perfectMatch[EADDR_LEN];
105 * NS DP82830 Ethernet device model
107 class NSGigE : public PciDev
110 /** Transmit State Machine states */
122 /** Receive State Machine States */
144 /** pointer to the chipset */
149 static const Addr size = sizeof(dp_regs);
152 typedef std::deque<PacketPtr> pktbuf_t;
153 typedef pktbuf_t::iterator pktiter_t;
155 /** device register file */
166 /*** BASIC STRUCTURES FOR TX/RX ***/
169 uint32_t maxTxFifoSize;
171 uint32_t maxRxFifoSize;
173 /** various helper vars */
176 uint8_t *txPacketBufPtr;
177 uint8_t *rxPacketBufPtr;
187 /* tx State Machine */
191 /** Current Transmit Descriptor Done */
193 /** current amt of free space in txDataFifo in bytes */
194 uint32_t txFifoAvail;
195 /** halt the tx state machine after next packet */
197 /** ptr to the next byte in the current fragment */
199 /** count of bytes remaining in the current descriptor */
203 /** rx State Machine */
207 /** Current Receive Descriptor Done */
209 /** num of bytes in the current packet being drained from rxDataFifo */
211 /** number of bytes in the rxFifo */
213 /** halt the rx state machine after current packet */
215 /** ptr to the next byte in current fragment */
217 /** count of bytes remaining in the current descriptor */
235 void rxDmaReadCopy();
236 void rxDmaWriteCopy();
243 void txDmaReadCopy();
244 void txDmaWriteCopy();
246 void rxDmaReadDone();
247 friend class EventWrapper<NSGigE, &NSGigE::rxDmaReadDone>;
248 EventWrapper<NSGigE, &NSGigE::rxDmaReadDone> rxDmaReadEvent;
250 void rxDmaWriteDone();
251 friend class EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone>;
252 EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone> rxDmaWriteEvent;
254 void txDmaReadDone();
255 friend class EventWrapper<NSGigE, &NSGigE::txDmaReadDone>;
256 EventWrapper<NSGigE, &NSGigE::txDmaReadDone> txDmaReadEvent;
258 void txDmaWriteDone();
259 friend class EventWrapper<NSGigE, &NSGigE::txDmaWriteDone>;
260 EventWrapper<NSGigE, &NSGigE::txDmaWriteDone> txDmaWriteEvent;
276 typedef EventWrapper<NSGigE, &NSGigE::rxKick> RxKickEvent;
277 friend class RxKickEvent;
281 typedef EventWrapper<NSGigE, &NSGigE::txKick> TxKickEvent;
282 friend class TxKickEvent;
288 void txEventTransmit()
291 if (txState == txFifoBlock)
294 typedef EventWrapper<NSGigE, &NSGigE::txEventTransmit> TxEvent;
295 friend class TxEvent;
302 * receive address filter
305 bool rxFilter(PacketPtr packet);
306 bool acceptBroadcast;
307 bool acceptMulticast;
312 PhysicalMemory *physmem;
315 * Interrupt management
317 IntrControl *intctrl;
318 void devIntrPost(uint32_t interrupts);
319 void devIntrClear(uint32_t interrupts);
320 void devIntrChangeMask();
325 void cpuIntrPost(Tick when);
329 typedef EventWrapper<NSGigE, &NSGigE::cpuInterrupt> IntrEvent;
330 friend class IntrEvent;
331 IntrEvent *intrEvent;
334 * Hardware checksum support
336 bool udpChecksum(PacketPtr packet, bool gen);
337 bool tcpChecksum(PacketPtr packet, bool gen);
338 bool ipChecksum(PacketPtr packet, bool gen);
339 uint16_t checksumCalc(uint16_t *pseudo, uint16_t *buf, uint32_t len);
341 NSGigEInt *interface;
344 NSGigE(const std::string &name, IntrControl *i, Tick intr_delay,
345 PhysicalMemory *pmem, Tick tx_delay, Tick rx_delay,
346 MemoryController *mmu, HierParams *hier, Bus *header_bus,
347 Bus *payload_bus, Tick pio_latency, bool dma_desc_free,
348 bool dma_data_free, Tick dma_read_delay, Tick dma_write_delay,
349 Tick dma_read_factor, Tick dma_write_factor, PciConfigAll *cf,
350 PciConfigData *cd, Tsunami *t, uint32_t bus, uint32_t dev,
351 uint32_t func, bool rx_filter, const int eaddr[6],
352 uint32_t tx_fifo_size, uint32_t rx_fifo_size);
355 virtual void WriteConfig(int offset, int size, uint32_t data);
356 virtual void ReadConfig(int offset, int size, uint8_t *data);
358 virtual Fault read(MemReqPtr &req, uint8_t *data);
359 virtual Fault write(MemReqPtr &req, const uint8_t *data);
361 bool cpuIntrPending() const;
362 void cpuIntrAck() { cpuIntrClear(); }
364 bool recvPacket(PacketPtr packet);
367 void setInterface(NSGigEInt *i) { assert(!interface); interface = i; }
369 virtual void serialize(std::ostream &os);
370 virtual void unserialize(Checkpoint *cp, const std::string §ion);
376 Stats::Scalar<> txBytes;
377 Stats::Scalar<> rxBytes;
378 Stats::Scalar<> txPackets;
379 Stats::Scalar<> rxPackets;
380 Stats::Scalar<> txIPChecksums;
381 Stats::Scalar<> rxIPChecksums;
382 Stats::Scalar<> txTCPChecksums;
383 Stats::Scalar<> rxTCPChecksums;
384 Stats::Scalar<> descDmaReads;
385 Stats::Scalar<> descDmaWrites;
386 Stats::Scalar<> descDmaRdBytes;
387 Stats::Scalar<> descDmaWrBytes;
388 Stats::Formula txBandwidth;
389 Stats::Formula rxBandwidth;
390 Stats::Formula txPacketRate;
391 Stats::Formula rxPacketRate;
394 Tick cacheAccess(MemReqPtr &req);
398 * Ethernet Interface for an Ethernet Device
400 class NSGigEInt : public EtherInt
406 NSGigEInt(const std::string &name, NSGigE *d)
407 : EtherInt(name), dev(d) { dev->setInterface(this); }
409 virtual bool recvPacket(PacketPtr &pkt) { return dev->recvPacket(pkt); }
410 virtual void sendDone() { dev->transferDone(); }
413 #endif // __NS_GIGE_HH__