etherlink.hh revision 10905
12315SN/A/* 28733Sgeoffrey.blake@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 38733Sgeoffrey.blake@arm.com * All rights reserved. 48733Sgeoffrey.blake@arm.com * 58733Sgeoffrey.blake@arm.com * Redistribution and use in source and binary forms, with or without 68733Sgeoffrey.blake@arm.com * modification, are permitted provided that the following conditions are 78733Sgeoffrey.blake@arm.com * met: redistributions of source code must retain the above copyright 88733Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer; 98733Sgeoffrey.blake@arm.com * redistributions in binary form must reproduce the above copyright 108733Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer in the 118733Sgeoffrey.blake@arm.com * documentation and/or other materials provided with the distribution; 128733Sgeoffrey.blake@arm.com * neither the name of the copyright holders nor the names of its 138733Sgeoffrey.blake@arm.com * contributors may be used to endorse or promote products derived from 142332SN/A * this software without specific prior written permission. 152315SN/A * 162315SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172315SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182315SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192315SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202315SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212315SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222315SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232315SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242315SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252315SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262315SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272315SN/A * 282315SN/A * Authors: Nathan Binkert 292315SN/A */ 302315SN/A 312315SN/A/* @file 322315SN/A * Device module for modelling a fixed bandwidth full duplex ethernet link 332315SN/A */ 342315SN/A 352315SN/A#ifndef __DEV_ETHERLINK_HH__ 362315SN/A#define __DEV_ETHERLINK_HH__ 372315SN/A 382315SN/A#include "base/types.hh" 392689SN/A#include "dev/etherint.hh" 402689SN/A#include "dev/etherobject.hh" 418733Sgeoffrey.blake@arm.com#include "dev/etherpkt.hh" 422315SN/A#include "params/EtherLink.hh" 432315SN/A#include "sim/eventq.hh" 442315SN/A#include "sim/sim_object.hh" 452315SN/A 462315SN/Aclass EtherDump; 478888Sgeoffrey.blake@arm.comclass Checkpoint; 488793Sgblack@eecs.umich.edu/* 492315SN/A * Model for a fixed bandwidth full duplex ethernet link 506658Snate@binkert.org */ 512315SN/Aclass EtherLink : public EtherObject 528733Sgeoffrey.blake@arm.com{ 532683SN/A protected: 548229Snate@binkert.org class Interface; 552680SN/A 568733Sgeoffrey.blake@arm.com friend class LinkDelayEvent; 578733Sgeoffrey.blake@arm.com /* 588793Sgblack@eecs.umich.edu * Model for a single uni-directional link 592315SN/A */ 602315SN/A class Link 612315SN/A { 622315SN/A protected: 638733Sgeoffrey.blake@arm.com std::string objName; 642315SN/A 658733Sgeoffrey.blake@arm.com EtherLink *parent; 662315SN/A int number; 678733Sgeoffrey.blake@arm.com 688733Sgeoffrey.blake@arm.com Interface *txint; 698733Sgeoffrey.blake@arm.com Interface *rxint; 708733Sgeoffrey.blake@arm.com 718733Sgeoffrey.blake@arm.com double ticksPerByte; 729023Sgblack@eecs.umich.edu Tick linkDelay; 738733Sgeoffrey.blake@arm.com Tick delayVar; 748733Sgeoffrey.blake@arm.com EtherDump *dump; 758733Sgeoffrey.blake@arm.com 768733Sgeoffrey.blake@arm.com protected: 778733Sgeoffrey.blake@arm.com /* 788733Sgeoffrey.blake@arm.com * Transfer is complete 798733Sgeoffrey.blake@arm.com */ 808733Sgeoffrey.blake@arm.com EthPacketPtr packet; 818733Sgeoffrey.blake@arm.com void txDone(); 828733Sgeoffrey.blake@arm.com typedef EventWrapper<Link, &Link::txDone> DoneEvent; 838733Sgeoffrey.blake@arm.com friend void DoneEvent::process(); 848733Sgeoffrey.blake@arm.com DoneEvent doneEvent; 858733Sgeoffrey.blake@arm.com 868733Sgeoffrey.blake@arm.com friend class LinkDelayEvent; 878733Sgeoffrey.blake@arm.com void txComplete(EthPacketPtr packet); 888733Sgeoffrey.blake@arm.com 898733Sgeoffrey.blake@arm.com public: 908733Sgeoffrey.blake@arm.com Link(const std::string &name, EtherLink *p, int num, 918733Sgeoffrey.blake@arm.com double rate, Tick delay, Tick delay_var, EtherDump *dump); 928733Sgeoffrey.blake@arm.com ~Link() {} 938733Sgeoffrey.blake@arm.com 948733Sgeoffrey.blake@arm.com const std::string name() const { return objName; } 958733Sgeoffrey.blake@arm.com 968733Sgeoffrey.blake@arm.com bool busy() const { return (bool)packet; } 978733Sgeoffrey.blake@arm.com bool transmit(EthPacketPtr packet); 988733Sgeoffrey.blake@arm.com 998733Sgeoffrey.blake@arm.com void setTxInt(Interface *i) { assert(!txint); txint = i; } 1008733Sgeoffrey.blake@arm.com void setRxInt(Interface *i) { assert(!rxint); rxint = i; } 1018733Sgeoffrey.blake@arm.com 1028733Sgeoffrey.blake@arm.com void serialize(const std::string &base, CheckpointOut &cp) const; 1038733Sgeoffrey.blake@arm.com void unserialize(const std::string &base, CheckpointIn &cp); 1048733Sgeoffrey.blake@arm.com }; 1058733Sgeoffrey.blake@arm.com 1068733Sgeoffrey.blake@arm.com /* 1078733Sgeoffrey.blake@arm.com * Interface at each end of the link 1088733Sgeoffrey.blake@arm.com */ 1098733Sgeoffrey.blake@arm.com class Interface : public EtherInt 1108733Sgeoffrey.blake@arm.com { 1118733Sgeoffrey.blake@arm.com private: 1128733Sgeoffrey.blake@arm.com Link *txlink; 1138733Sgeoffrey.blake@arm.com 1148733Sgeoffrey.blake@arm.com public: 1158733Sgeoffrey.blake@arm.com Interface(const std::string &name, Link *txlink, Link *rxlink); 1169023Sgblack@eecs.umich.edu bool recvPacket(EthPacketPtr packet) { return txlink->transmit(packet); } 1178733Sgeoffrey.blake@arm.com void sendDone() { peer->sendDone(); } 1188733Sgeoffrey.blake@arm.com bool isBusy() { return txlink->busy(); } 1198733Sgeoffrey.blake@arm.com }; 1208733Sgeoffrey.blake@arm.com 1218733Sgeoffrey.blake@arm.com Link *link[2]; 1228733Sgeoffrey.blake@arm.com Interface *interface[2]; 1232315SN/A 1242315SN/A public: 1252315SN/A typedef EtherLinkParams Params; 1268733Sgeoffrey.blake@arm.com EtherLink(const Params *p); 1278733Sgeoffrey.blake@arm.com virtual ~EtherLink(); 1288733Sgeoffrey.blake@arm.com 1298733Sgeoffrey.blake@arm.com const Params * 1308733Sgeoffrey.blake@arm.com params() const 1318733Sgeoffrey.blake@arm.com { 1328733Sgeoffrey.blake@arm.com return dynamic_cast<const Params *>(_params); 1338733Sgeoffrey.blake@arm.com } 1348733Sgeoffrey.blake@arm.com 1358733Sgeoffrey.blake@arm.com virtual EtherInt *getEthPort(const std::string &if_name, int idx); 1368733Sgeoffrey.blake@arm.com 1378733Sgeoffrey.blake@arm.com void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE; 1382332SN/A void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE; 1392332SN/A 1402332SN/A}; 1412332SN/A 1422332SN/A#endif // __ETHERLINK_HH__ 1432315SN/A