etherlink.hh revision 265
19793Sakash.bagdia@arm.com/* 28706Sandreas.hansson@arm.com * Copyright (c) 2003 The Regents of The University of Michigan 38706Sandreas.hansson@arm.com * All rights reserved. 48706Sandreas.hansson@arm.com * 58706Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 68706Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 78706Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 88706Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 98706Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 108706Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 118706Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 128706Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 135369Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from 143005Sstever@eecs.umich.edu * this software without specific prior written permission. 153005Sstever@eecs.umich.edu * 163005Sstever@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173005Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 183005Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 193005Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 203005Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 213005Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 223005Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 233005Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 243005Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 253005Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263005Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273005Sstever@eecs.umich.edu */ 283005Sstever@eecs.umich.edu 293005Sstever@eecs.umich.edu/* @file 303005Sstever@eecs.umich.edu * Device module for modelling a fixed bandwidth full duplex ethernet link 313005Sstever@eecs.umich.edu */ 323005Sstever@eecs.umich.edu 333005Sstever@eecs.umich.edu#ifndef __ETHERLINK_HH__ 343005Sstever@eecs.umich.edu#define __ETHERLINK_HH__ 353005Sstever@eecs.umich.edu 363005Sstever@eecs.umich.edu#include "sim/host.hh" 373005Sstever@eecs.umich.edu#include "sim/eventq.hh" 383005Sstever@eecs.umich.edu#include "dev/etherint.hh" 393005Sstever@eecs.umich.edu#include "dev/etherpkt.hh" 403005Sstever@eecs.umich.edu#include "sim/sim_object.hh" 412710SN/A 422710SN/Aclass EtherDump; 433005Sstever@eecs.umich.edu 442889SN/A/* 456654Snate@binkert.org * Model for a fixed bandwidth full duplex ethernet link 466654Snate@binkert.org */ 476654Snate@binkert.orgclass EtherLink : public SimObject 482667SN/A{ 496654Snate@binkert.org protected: 506654Snate@binkert.org class Interface; 516654Snate@binkert.org 525457Ssaidi@eecs.umich.edu /* 536654Snate@binkert.org * Model for a single uni-directional link 548169SLisa.Hsu@amd.com */ 559100SBrad.Beckmann@amd.com class Link : public Serializeable { 568169SLisa.Hsu@amd.com protected: 578920Snilay@cs.wisc.edu std::string objName; 588169SLisa.Hsu@amd.com 593395Shsul@eecs.umich.edu Interface *txint; 606981SLisa.Hsu@amd.com Interface *rxint; 613448Shsul@eecs.umich.edu 625369Ssaidi@eecs.umich.edu double ticks_per_byte; 633394Shsul@eecs.umich.edu EtherDump *dump; 649197Snilay@cs.wisc.edu 659197Snilay@cs.wisc.edu protected: 669197Snilay@cs.wisc.edu /* 679197Snilay@cs.wisc.edu * Transfer is complete 689197Snilay@cs.wisc.edu */ 699197Snilay@cs.wisc.edu class DoneEvent : public Event 709197Snilay@cs.wisc.edu { 719197Snilay@cs.wisc.edu protected: 729197Snilay@cs.wisc.edu Link *link; 739197Snilay@cs.wisc.edu 749197Snilay@cs.wisc.edu public: 759197Snilay@cs.wisc.edu DoneEvent(EventQueue *q, Link *l) 769197Snilay@cs.wisc.edu : Event(q), link(l) {} 779197Snilay@cs.wisc.edu virtual void process() { link->txDone(); } 789197Snilay@cs.wisc.edu virtual const char *description() 799197Snilay@cs.wisc.edu { return "ethernet link completion"; } 809197Snilay@cs.wisc.edu }; 819197Snilay@cs.wisc.edu 829197Snilay@cs.wisc.edu friend class DoneEvent; 839197Snilay@cs.wisc.edu DoneEvent event; 849197Snilay@cs.wisc.edu PacketPtr packet; 859197Snilay@cs.wisc.edu 869197Snilay@cs.wisc.edu void txDone(); 879197Snilay@cs.wisc.edu 889197Snilay@cs.wisc.edu public: 899217Snilay@cs.wisc.edu Link(const std::string &name, double rate, EtherDump *dump); 909197Snilay@cs.wisc.edu ~Link() {} 919197Snilay@cs.wisc.edu 929197Snilay@cs.wisc.edu virtual std::string name() const { return objName; } 939197Snilay@cs.wisc.edu 949197Snilay@cs.wisc.edu bool busy() const { return (bool)packet; } 959197Snilay@cs.wisc.edu bool transmit(PacketPtr packet); 969197Snilay@cs.wisc.edu 979197Snilay@cs.wisc.edu void setTxInt(Interface *i) { assert(!txint); txint = i; } 989197Snilay@cs.wisc.edu void setRxInt(Interface *i) { assert(!rxint); rxint = i; } 999197Snilay@cs.wisc.edu }; 1009197Snilay@cs.wisc.edu 1019197Snilay@cs.wisc.edu /* 1029197Snilay@cs.wisc.edu * Interface at each end of the link 1039197Snilay@cs.wisc.edu */ 1049197Snilay@cs.wisc.edu class Interface : public EtherInt 1059197Snilay@cs.wisc.edu { 1069197Snilay@cs.wisc.edu private: 1079197Snilay@cs.wisc.edu Link *txlink; 1089197Snilay@cs.wisc.edu 1099197Snilay@cs.wisc.edu public: 1102957SN/A Interface(const std::string &name, Link *txlink, Link *rxlink); 1118920Snilay@cs.wisc.edu bool recvPacket(PacketPtr packet) { return txlink->transmit(packet); } 1128920Snilay@cs.wisc.edu void sendDone() { } 1132957SN/A }; 1148862Snilay@cs.wisc.edu 1158862Snilay@cs.wisc.edu Link *link1; 1168467Snilay@cs.wisc.edu Link *link2; 1172957SN/A 1182957SN/A EtherInt *int1; 1192957SN/A EtherInt *int2; 1202957SN/A 1212957SN/A public: 1222957SN/A EtherLink(const std::string &name, EtherInt *i1, EtherInt *i2, 1238167SLisa.Hsu@amd.com Tick speed, EtherDump *dump); 1249197Snilay@cs.wisc.edu virtual ~EtherLink(); 1258167SLisa.Hsu@amd.com}; 1265369Ssaidi@eecs.umich.edu 1278167SLisa.Hsu@amd.com#endif // __ETHERLINK_HH__ 1288167SLisa.Hsu@amd.com