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.
28 * Authors: Nathan Binkert
33 * Device module for modelling the National Semiconductor
34 * DP83820 ethernet controller
37 #ifndef __DEV_NS_GIGE_HH__
38 #define __DEV_NS_GIGE_HH__
40 #include "base/inet.hh"
41 #include "dev/etherdevice.hh"
42 #include "dev/etherint.hh"
43 #include "dev/etherpkt.hh"
44 #include "dev/io_device.hh"
45 #include "dev/ns_gige_reg.h"
46 #include "dev/pktfifo.hh"
47 #include "params/NSGigE.hh"
48 #include "sim/eventq.hh"
50 // Hash filtering constants
51 const uint16_t FHASH_ADDR = 0x100;
52 const uint16_t FHASH_SIZE = 0x100;
55 const uint8_t EEPROM_READ = 0x2;
56 const uint8_t EEPROM_SIZE = 64; // Size in words of NSC93C46 EEPROM
57 const uint8_t EEPROM_PMATCH2_ADDR = 0xA; // EEPROM Address of PMATCH word 2
58 const uint8_t EEPROM_PMATCH1_ADDR = 0xB; // EEPROM Address of PMATCH word 1
59 const uint8_t EEPROM_PMATCH0_ADDR = 0xC; // EEPROM Address of PMATCH word 0
62 * Ethernet device registers
103 * for perfect match memory.
104 * the linux driver doesn't use any other ROM
106 uint8_t perfectMatch[ETH_ADDR_LEN];
109 * for hash table memory.
110 * used by the freebsd driver
112 uint8_t filterHash[FHASH_SIZE];
119 * NS DP83820 Ethernet device model
121 class NSGigE : public EtherDevBase
124 /** Transmit State Machine states */
136 /** Receive State Machine States */
157 /** EEPROM State Machine States */
167 /** device register file */
178 /*** BASIC STRUCTURES FOR TX/RX ***/
183 /** various helper vars */
184 EthPacketPtr txPacket;
185 EthPacketPtr rxPacket;
186 uint8_t *txPacketBufPtr;
187 uint8_t *rxPacketBufPtr;
199 /* tx State Machine */
203 /** Current Transmit Descriptor Done */
205 /** halt the tx state machine after next packet */
207 /** ptr to the next byte in the current fragment */
209 /** count of bytes remaining in the current descriptor */
213 /** rx State Machine */
217 /** Current Receive Descriptor Done */
219 /** num of bytes in the current packet being drained from rxDataFifo */
221 /** halt the rx state machine after current packet */
223 /** ptr to the next byte in current fragment */
225 /** count of bytes remaining in the current descriptor */
231 /** EEPROM State Machine */
232 EEPROMState eepromState;
234 uint8_t eepromBitsToRx;
235 uint8_t eepromOpcode;
236 uint8_t eepromAddress;
258 void rxDmaReadDone();
259 friend class EventWrapper<NSGigE, &NSGigE::rxDmaReadDone>;
260 EventWrapper<NSGigE, &NSGigE::rxDmaReadDone> rxDmaReadEvent;
262 void rxDmaWriteDone();
263 friend class EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone>;
264 EventWrapper<NSGigE, &NSGigE::rxDmaWriteDone> rxDmaWriteEvent;
266 void txDmaReadDone();
267 friend class EventWrapper<NSGigE, &NSGigE::txDmaReadDone>;
268 EventWrapper<NSGigE, &NSGigE::txDmaReadDone> txDmaReadEvent;
270 void txDmaWriteDone();
271 friend class EventWrapper<NSGigE, &NSGigE::txDmaWriteDone>;
272 EventWrapper<NSGigE, &NSGigE::txDmaWriteDone> txDmaWriteEvent;
287 typedef EventWrapper<NSGigE, &NSGigE::rxKick> RxKickEvent;
288 friend void RxKickEvent::process();
289 RxKickEvent rxKickEvent;
293 typedef EventWrapper<NSGigE, &NSGigE::txKick> TxKickEvent;
294 friend void TxKickEvent::process();
295 TxKickEvent txKickEvent;
303 void txEventTransmit()
306 if (txState == txFifoBlock)
309 typedef EventWrapper<NSGigE, &NSGigE::txEventTransmit> TxEvent;
310 friend void TxEvent::process();
317 * receive address filter
320 bool rxFilter(const EthPacketPtr &packet);
321 bool acceptBroadcast;
322 bool acceptMulticast;
326 bool multicastHashEnable;
329 * Interrupt management
331 void devIntrPost(uint32_t interrupts);
332 void devIntrClear(uint32_t interrupts);
333 void devIntrChangeMask();
338 void cpuIntrPost(Tick when);
342 typedef EventWrapper<NSGigE, &NSGigE::cpuInterrupt> IntrEvent;
343 friend void IntrEvent::process();
344 IntrEvent *intrEvent;
345 NSGigEInt *interface;
348 typedef NSGigEParams Params;
349 const Params *params() const {
350 return dynamic_cast<const Params *>(_params);
353 NSGigE(Params *params);
356 virtual EtherInt *getEthPort(const std::string &if_name, int idx);
358 virtual Tick writeConfig(PacketPtr pkt);
360 virtual Tick read(PacketPtr pkt);
361 virtual Tick write(PacketPtr pkt);
363 bool cpuIntrPending() const;
364 void cpuIntrAck() { cpuIntrClear(); }
366 bool recvPacket(EthPacketPtr packet);
369 virtual void serialize(std::ostream &os);
370 virtual void unserialize(Checkpoint *cp, const std::string §ion);
376 * Ethernet Interface for an Ethernet Device
378 class NSGigEInt : public EtherInt
384 NSGigEInt(const std::string &name, NSGigE *d)
385 : EtherInt(name), dev(d)
388 virtual bool recvPacket(EthPacketPtr pkt) { return dev->recvPacket(pkt); }
389 virtual void sendDone() { dev->transferDone(); }
392 #endif // __DEV_NS_GIGE_HH__