12SN/A/* 211071SN/A * Copyright (c) 2015 ARM Limited 311071SN/A * All rights reserved 411071SN/A * 511071SN/A * The license below extends only to copyright in the software and shall 611071SN/A * not be construed as granting a license to any other intellectual 711071SN/A * property including but not limited to intellectual property relating 811071SN/A * to a hardware implementation of the functionality of the software 911071SN/A * licensed hereunder. You may use the software subject to the license 1011071SN/A * terms below provided that you ensure that this notice is replicated 1111071SN/A * unmodified and in its entirety in all distributions of the software, 1211071SN/A * modified or unmodified, in source code or in binary form. 1311071SN/A * 141762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 152SN/A * All rights reserved. 162SN/A * 172SN/A * Redistribution and use in source and binary forms, with or without 182SN/A * modification, are permitted provided that the following conditions are 192SN/A * met: redistributions of source code must retain the above copyright 202SN/A * notice, this list of conditions and the following disclaimer; 212SN/A * redistributions in binary form must reproduce the above copyright 222SN/A * notice, this list of conditions and the following disclaimer in the 232SN/A * documentation and/or other materials provided with the distribution; 242SN/A * neither the name of the copyright holders nor the names of its 252SN/A * contributors may be used to endorse or promote products derived from 262SN/A * this software without specific prior written permission. 272SN/A * 282SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665SN/A * 402665SN/A * Authors: Nathan Binkert 412SN/A */ 422SN/A 432SN/A/* @file 442SN/A * Device module for modelling a fixed bandwidth full duplex ethernet link 452SN/A */ 462SN/A 4711263Sandreas.sandberg@arm.com#ifndef __DEV_NET_ETHERLINK_HH__ 4811263Sandreas.sandberg@arm.com#define __DEV_NET_ETHERLINK_HH__ 492SN/A 5011071SN/A#include <queue> 5111071SN/A 526216SN/A#include "base/types.hh" 5311263Sandreas.sandberg@arm.com#include "dev/net/etherint.hh" 5411263Sandreas.sandberg@arm.com#include "dev/net/etherpkt.hh" 554981SN/A#include "params/EtherLink.hh" 561354SN/A#include "sim/eventq.hh" 5756SN/A#include "sim/sim_object.hh" 582SN/A 592SN/Aclass EtherDump; 601435SN/Aclass Checkpoint; 612SN/A/* 622SN/A * Model for a fixed bandwidth full duplex ethernet link 632SN/A */ 6413784Sgabeblack@google.comclass EtherLink : public SimObject 652SN/A{ 662SN/A protected: 672SN/A class Interface; 682SN/A 6911071SN/A /* 7011071SN/A * Model for a single uni-directional link 7111071SN/A */ 721435SN/A class Link 731435SN/A { 742SN/A protected: 7511071SN/A const std::string objName; 76265SN/A 7711071SN/A EtherLink *const parent; 7811071SN/A const int number; 791435SN/A 802SN/A Interface *txint; 812SN/A Interface *rxint; 822SN/A 8311071SN/A const double ticksPerByte; 8411071SN/A const Tick linkDelay; 8511071SN/A const Tick delayVar; 8611071SN/A EtherDump *const dump; 872SN/A 882SN/A protected: 892SN/A /* 902SN/A * Transfer is complete 912SN/A */ 922566SN/A EthPacketPtr packet; 93633SN/A void txDone(); 9412087Sspwilson2@wisc.edu EventFunctionWrapper doneEvent; 952SN/A 9611071SN/A /** 9711071SN/A * Maintain a queue of in-flight packets. Assume that the 9811071SN/A * delay is non-zero and constant (i.e., at most one packet 9911071SN/A * per tick). 10011071SN/A */ 10111071SN/A std::deque<std::pair<Tick, EthPacketPtr>> txQueue; 10211071SN/A 10311071SN/A void processTxQueue(); 10412087Sspwilson2@wisc.edu EventFunctionWrapper txQueueEvent; 10511071SN/A 1062566SN/A void txComplete(EthPacketPtr packet); 1072SN/A 1082SN/A public: 1091435SN/A Link(const std::string &name, EtherLink *p, int num, 1101954SN/A double rate, Tick delay, Tick delay_var, EtherDump *dump); 1112SN/A ~Link() {} 1122SN/A 1131435SN/A const std::string name() const { return objName; } 114265SN/A 1152SN/A bool busy() const { return (bool)packet; } 1162566SN/A bool transmit(EthPacketPtr packet); 1172SN/A 1182SN/A void setTxInt(Interface *i) { assert(!txint); txint = i; } 1192SN/A void setRxInt(Interface *i) { assert(!rxint); rxint = i; } 120558SN/A 12110905SN/A void serialize(const std::string &base, CheckpointOut &cp) const; 12210905SN/A void unserialize(const std::string &base, CheckpointIn &cp); 1232SN/A }; 1242SN/A 1252SN/A /* 1262SN/A * Interface at each end of the link 1272SN/A */ 1282SN/A class Interface : public EtherInt 1292SN/A { 1302SN/A private: 1312SN/A Link *txlink; 1322SN/A 1332SN/A public: 1342SN/A Interface(const std::string &name, Link *txlink, Link *rxlink); 1352566SN/A bool recvPacket(EthPacketPtr packet) { return txlink->transmit(packet); } 1361017SN/A void sendDone() { peer->sendDone(); } 1374419SN/A bool isBusy() { return txlink->busy(); } 1382SN/A }; 1392SN/A 1401435SN/A Link *link[2]; 1414981SN/A Interface *interface[2]; 1422SN/A 1432SN/A public: 1444981SN/A typedef EtherLinkParams Params; 1454981SN/A EtherLink(const Params *p); 1462SN/A virtual ~EtherLink(); 147558SN/A 1484981SN/A const Params * 1494981SN/A params() const 1504981SN/A { 1514981SN/A return dynamic_cast<const Params *>(_params); 1524981SN/A } 1534981SN/A 15413784Sgabeblack@google.com Port &getPort(const std::string &if_name, 15513784Sgabeblack@google.com PortID idx=InvalidPortID) override; 1564981SN/A 15711168SN/A void serialize(CheckpointOut &cp) const override; 15811168SN/A void unserialize(CheckpointIn &cp) override; 159558SN/A 1602SN/A}; 1612SN/A 16211263Sandreas.sandberg@arm.com#endif // __DEV_NET_ETHERLINK_HH__ 163