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 __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"
49 * Ethernet device registers
88 * for perfect match memory.
89 * the linux driver doesn't use any other ROM
91 uint8_t perfectMatch[ETH_ADDR_LEN];
103 * NS DP82830 Ethernet device model
105 class NSGigE : public PciDev
108 /** Transmit State Machine states */
120 /** Receive State Machine States */
143 static const Addr size = sizeof(dp_regs);
146 typedef std::deque<PacketPtr> pktbuf_t;
147 typedef pktbuf_t::iterator pktiter_t;
149 /** device register file */
160 /*** BASIC STRUCTURES FOR TX/RX ***/
165 /** various helper vars */
168 uint8_t *txPacketBufPtr;
169 uint8_t *rxPacketBufPtr;
179 /* tx State Machine */
183 /** Current Transmit Descriptor Done */
185 /** halt the tx state machine after next packet */
187 /** ptr to the next byte in the current fragment */
189 /** count of bytes remaining in the current descriptor */
193 /** rx State Machine */
197 /** Current Receive Descriptor Done */
199 /** num of bytes in the current packet being drained from rxDataFifo */
201 /** halt the rx state machine after current packet */
203 /** ptr to the next byte in current fragment */
205 /** count of bytes remaining in the current descriptor */
223 void rxDmaReadCopy();
224 void rxDmaWriteCopy();
231 void txDmaReadCopy();
232 void txDmaWriteCopy();
234 void rxDmaReadDone();
235 friend class EventWrapper<NSGigE, &NSGigE::rxDmaReadDone>;
236 EventWrapper<NSGigE, &NSGigE::rxDmaReadDone> rxDmaReadEvent;
238 void rxDmaWriteDone();
239 friend class EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone>;
240 EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone> rxDmaWriteEvent;
242 void txDmaReadDone();
243 friend class EventWrapper<NSGigE, &NSGigE::txDmaReadDone>;
244 EventWrapper<NSGigE, &NSGigE::txDmaReadDone> txDmaReadEvent;
246 void txDmaWriteDone();
247 friend class EventWrapper<NSGigE, &NSGigE::txDmaWriteDone>;
248 EventWrapper<NSGigE, &NSGigE::txDmaWriteDone> txDmaWriteEvent;
264 typedef EventWrapper<NSGigE, &NSGigE::rxKick> RxKickEvent;
265 friend class RxKickEvent;
269 typedef EventWrapper<NSGigE, &NSGigE::txKick> TxKickEvent;
270 friend class TxKickEvent;
276 void txEventTransmit()
279 if (txState == txFifoBlock)
282 typedef EventWrapper<NSGigE, &NSGigE::txEventTransmit> TxEvent;
283 friend class TxEvent;
290 * receive address filter
293 bool rxFilter(const PacketPtr &packet);
294 bool acceptBroadcast;
295 bool acceptMulticast;
300 PhysicalMemory *physmem;
303 * Interrupt management
305 IntrControl *intctrl;
306 void devIntrPost(uint32_t interrupts);
307 void devIntrClear(uint32_t interrupts);
308 void devIntrChangeMask();
313 void cpuIntrPost(Tick when);
317 typedef EventWrapper<NSGigE, &NSGigE::cpuInterrupt> IntrEvent;
318 friend class IntrEvent;
319 IntrEvent *intrEvent;
320 NSGigEInt *interface;
323 struct Params : public PciDev::Params
325 PhysicalMemory *pmem;
336 Tick dma_write_delay;
337 Tick dma_read_factor;
338 Tick dma_write_factor;
341 uint32_t tx_fifo_size;
342 uint32_t rx_fifo_size;
345 NSGigE(Params *params);
347 const Params *params() const { return (const Params *)_params; }
349 virtual void WriteConfig(int offset, int size, uint32_t data);
350 virtual void ReadConfig(int offset, int size, uint8_t *data);
352 virtual Fault read(MemReqPtr &req, uint8_t *data);
353 virtual Fault write(MemReqPtr &req, const uint8_t *data);
355 bool cpuIntrPending() const;
356 void cpuIntrAck() { cpuIntrClear(); }
358 bool recvPacket(PacketPtr packet);
361 void setInterface(NSGigEInt *i) { assert(!interface); interface = i; }
363 virtual void serialize(std::ostream &os);
364 virtual void unserialize(Checkpoint *cp, const std::string §ion);
370 Stats::Scalar<> txBytes;
371 Stats::Scalar<> rxBytes;
372 Stats::Scalar<> txPackets;
373 Stats::Scalar<> rxPackets;
374 Stats::Scalar<> txIpChecksums;
375 Stats::Scalar<> rxIpChecksums;
376 Stats::Scalar<> txTcpChecksums;
377 Stats::Scalar<> rxTcpChecksums;
378 Stats::Scalar<> txUdpChecksums;
379 Stats::Scalar<> rxUdpChecksums;
380 Stats::Scalar<> descDmaReads;
381 Stats::Scalar<> descDmaWrites;
382 Stats::Scalar<> descDmaRdBytes;
383 Stats::Scalar<> descDmaWrBytes;
384 Stats::Formula txBandwidth;
385 Stats::Formula rxBandwidth;
386 Stats::Formula txPacketRate;
387 Stats::Formula rxPacketRate;
390 Tick cacheAccess(MemReqPtr &req);
394 * Ethernet Interface for an Ethernet Device
396 class NSGigEInt : public EtherInt
402 NSGigEInt(const std::string &name, NSGigE *d)
403 : EtherInt(name), dev(d) { dev->setInterface(this); }
405 virtual bool recvPacket(PacketPtr pkt) { return dev->recvPacket(pkt); }
406 virtual void sendDone() { dev->transferDone(); }
409 #endif // __DEV_NS_GIGE_HH__