etherlink.hh revision 12087
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/etherobject.hh" 5511263Sandreas.sandberg@arm.com#include "dev/net/etherpkt.hh" 564981SN/A#include "params/EtherLink.hh" 571354SN/A#include "sim/eventq.hh" 5856SN/A#include "sim/sim_object.hh" 592SN/A 602SN/Aclass EtherDump; 611435SN/Aclass Checkpoint; 622SN/A/* 632SN/A * Model for a fixed bandwidth full duplex ethernet link 642SN/A */ 654981SN/Aclass EtherLink : public EtherObject 662SN/A{ 672SN/A protected: 682SN/A class Interface; 692SN/A 7011071SN/A /* 7111071SN/A * Model for a single uni-directional link 7211071SN/A */ 731435SN/A class Link 741435SN/A { 752SN/A protected: 7611071SN/A const std::string objName; 77265SN/A 7811071SN/A EtherLink *const parent; 7911071SN/A const int number; 801435SN/A 812SN/A Interface *txint; 822SN/A Interface *rxint; 832SN/A 8411071SN/A const double ticksPerByte; 8511071SN/A const Tick linkDelay; 8611071SN/A const Tick delayVar; 8711071SN/A EtherDump *const dump; 882SN/A 892SN/A protected: 902SN/A /* 912SN/A * Transfer is complete 922SN/A */ 932566SN/A EthPacketPtr packet; 94633SN/A void txDone(); 9512087Sspwilson2@wisc.edu EventFunctionWrapper doneEvent; 962SN/A 9711071SN/A /** 9811071SN/A * Maintain a queue of in-flight packets. Assume that the 9911071SN/A * delay is non-zero and constant (i.e., at most one packet 10011071SN/A * per tick). 10111071SN/A */ 10211071SN/A std::deque<std::pair<Tick, EthPacketPtr>> txQueue; 10311071SN/A 10411071SN/A void processTxQueue(); 10512087Sspwilson2@wisc.edu EventFunctionWrapper txQueueEvent; 10611071SN/A 1072566SN/A void txComplete(EthPacketPtr packet); 1082SN/A 1092SN/A public: 1101435SN/A Link(const std::string &name, EtherLink *p, int num, 1111954SN/A double rate, Tick delay, Tick delay_var, EtherDump *dump); 1122SN/A ~Link() {} 1132SN/A 1141435SN/A const std::string name() const { return objName; } 115265SN/A 1162SN/A bool busy() const { return (bool)packet; } 1172566SN/A bool transmit(EthPacketPtr packet); 1182SN/A 1192SN/A void setTxInt(Interface *i) { assert(!txint); txint = i; } 1202SN/A void setRxInt(Interface *i) { assert(!rxint); rxint = i; } 121558SN/A 12210905SN/A void serialize(const std::string &base, CheckpointOut &cp) const; 12310905SN/A void unserialize(const std::string &base, CheckpointIn &cp); 1242SN/A }; 1252SN/A 1262SN/A /* 1272SN/A * Interface at each end of the link 1282SN/A */ 1292SN/A class Interface : public EtherInt 1302SN/A { 1312SN/A private: 1322SN/A Link *txlink; 1332SN/A 1342SN/A public: 1352SN/A Interface(const std::string &name, Link *txlink, Link *rxlink); 1362566SN/A bool recvPacket(EthPacketPtr packet) { return txlink->transmit(packet); } 1371017SN/A void sendDone() { peer->sendDone(); } 1384419SN/A bool isBusy() { return txlink->busy(); } 1392SN/A }; 1402SN/A 1411435SN/A Link *link[2]; 1424981SN/A Interface *interface[2]; 1432SN/A 1442SN/A public: 1454981SN/A typedef EtherLinkParams Params; 1464981SN/A EtherLink(const Params *p); 1472SN/A virtual ~EtherLink(); 148558SN/A 1494981SN/A const Params * 1504981SN/A params() const 1514981SN/A { 1524981SN/A return dynamic_cast<const Params *>(_params); 1534981SN/A } 1544981SN/A 15511169SN/A EtherInt *getEthPort(const std::string &if_name, int idx) 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