etherlink.hh revision 4419
12381SN/A/* 210342SCurtis.Dunham@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 38949Sandreas.hansson@arm.com * All rights reserved. 48949Sandreas.hansson@arm.com * 58949Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 68949Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 78949Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 88949Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 98949Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 108949Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 118949Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 128949Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 138949Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 142592SN/A * this software without specific prior written permission. 157636Ssteve.reinhardt@amd.com * 162381SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172381SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182381SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192381SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202381SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212381SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222381SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232381SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242381SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252381SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262381SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272381SN/A * 282381SN/A * Authors: Nathan Binkert 292381SN/A */ 302381SN/A 312381SN/A/* @file 322381SN/A * Device module for modelling a fixed bandwidth full duplex ethernet link 332381SN/A */ 342381SN/A 352381SN/A#ifndef __DEV_ETHERLINK_HH__ 362381SN/A#define __DEV_ETHERLINK_HH__ 372381SN/A 382381SN/A#include "dev/etherint.hh" 392381SN/A#include "dev/etherpkt.hh" 402665Ssaidi@eecs.umich.edu#include "sim/eventq.hh" 412665Ssaidi@eecs.umich.edu#include "sim/host.hh" 422665Ssaidi@eecs.umich.edu#include "sim/sim_object.hh" 432665Ssaidi@eecs.umich.edu 449031Sandreas.hansson@arm.comclass EtherDump; 452381SN/Aclass Checkpoint; 462381SN/A/* 472381SN/A * Model for a fixed bandwidth full duplex ethernet link 482381SN/A */ 492662Sstever@eecs.umich.educlass EtherLink : public SimObject 502381SN/A{ 512381SN/A protected: 522381SN/A class Interface; 532381SN/A 542381SN/A friend class LinkDelayEvent; 558229Snate@binkert.org /* 563348Sbinkertn@umich.edu * Model for a single uni-directional link 573348Sbinkertn@umich.edu */ 583348Sbinkertn@umich.edu class Link 595735Snate@binkert.org { 604024Sbinkertn@umich.edu protected: 615735Snate@binkert.org std::string objName; 623940Ssaidi@eecs.umich.edu 635314Sstever@gmail.com EtherLink *parent; 646216Snate@binkert.org int number; 652392SN/A 664167Sbinkertn@umich.edu Interface *txint; 672394SN/A Interface *rxint; 688737Skoansin.tan@gmail.com 693349Sbinkertn@umich.edu double ticksPerByte; 702394SN/A Tick linkDelay; 712812Srdreslin@umich.edu Tick delayVar; 722812Srdreslin@umich.edu EtherDump *dump; 734022Sstever@eecs.umich.edu 744022Sstever@eecs.umich.edu protected: 755735Snate@binkert.org /* 765735Snate@binkert.org * Transfer is complete 774022Sstever@eecs.umich.edu */ 785735Snate@binkert.org EthPacketPtr packet; 795735Snate@binkert.org void txDone(); 805735Snate@binkert.org typedef EventWrapper<Link, &Link::txDone> DoneEvent; 814022Sstever@eecs.umich.edu friend void DoneEvent::process(); 824022Sstever@eecs.umich.edu DoneEvent doneEvent; 834022Sstever@eecs.umich.edu 844022Sstever@eecs.umich.edu friend class LinkDelayEvent; 854473Sstever@eecs.umich.edu void txComplete(EthPacketPtr packet); 865319Sstever@gmail.com 874022Sstever@eecs.umich.edu public: 884022Sstever@eecs.umich.edu Link(const std::string &name, EtherLink *p, int num, 894022Sstever@eecs.umich.edu double rate, Tick delay, Tick delay_var, EtherDump *dump); 904022Sstever@eecs.umich.edu ~Link() {} 914022Sstever@eecs.umich.edu 924022Sstever@eecs.umich.edu const std::string name() const { return objName; } 934022Sstever@eecs.umich.edu 944022Sstever@eecs.umich.edu bool busy() const { return (bool)packet; } 954022Sstever@eecs.umich.edu bool transmit(EthPacketPtr packet); 964022Sstever@eecs.umich.edu 977465Ssteve.reinhardt@amd.com void setTxInt(Interface *i) { assert(!txint); txint = i; } 984628Sstever@eecs.umich.edu void setRxInt(Interface *i) { assert(!rxint); rxint = i; } 997465Ssteve.reinhardt@amd.com 1007465Ssteve.reinhardt@amd.com void serialize(const std::string &base, std::ostream &os); 1014022Sstever@eecs.umich.edu void unserialize(const std::string &base, Checkpoint *cp, 1024022Sstever@eecs.umich.edu const std::string §ion); 1034626Sstever@eecs.umich.edu }; 1044626Sstever@eecs.umich.edu 1057669Ssteve.reinhardt@amd.com /* 1064626Sstever@eecs.umich.edu * Interface at each end of the link 1074040Ssaidi@eecs.umich.edu */ 1084040Ssaidi@eecs.umich.edu class Interface : public EtherInt 1095650Sgblack@eecs.umich.edu { 1105650Sgblack@eecs.umich.edu private: 1114870Sstever@eecs.umich.edu Link *txlink; 1124870Sstever@eecs.umich.edu 1134870Sstever@eecs.umich.edu public: 1144870Sstever@eecs.umich.edu Interface(const std::string &name, Link *txlink, Link *rxlink); 1154870Sstever@eecs.umich.edu bool recvPacket(EthPacketPtr packet) { return txlink->transmit(packet); } 1164870Sstever@eecs.umich.edu void sendDone() { peer->sendDone(); } 1178436SBrad.Beckmann@amd.com bool isBusy() { return txlink->busy(); } 1188436SBrad.Beckmann@amd.com }; 1195314Sstever@gmail.com 1205314Sstever@gmail.com Link *link[2]; 1218184Ssomayeh@cs.wisc.edu EtherInt *interface[2]; 1228716Snilay@cs.wisc.edu 1234022Sstever@eecs.umich.edu public: 1244022Sstever@eecs.umich.edu EtherLink(const std::string &name, EtherInt *peer0, EtherInt *peer1, 1254022Sstever@eecs.umich.edu double rate, Tick delay, Tick delayVar, EtherDump *dump); 1264022Sstever@eecs.umich.edu virtual ~EtherLink(); 1275735Snate@binkert.org 1285735Snate@binkert.org virtual void serialize(std::ostream &os); 1295735Snate@binkert.org virtual void unserialize(Checkpoint *cp, const std::string §ion); 1304022Sstever@eecs.umich.edu 1314022Sstever@eecs.umich.edu}; 1324626Sstever@eecs.umich.edu 1334626Sstever@eecs.umich.edu#endif // __ETHERLINK_HH__ 1347465Ssteve.reinhardt@amd.com