etherlink.hh revision 11071
12SN/A/*
21762SN/A * Copyright (c) 2015 ARM Limited
32SN/A * All rights reserved
42SN/A *
52SN/A * The license below extends only to copyright in the software and shall
62SN/A * not be construed as granting a license to any other intellectual
72SN/A * property including but not limited to intellectual property relating
82SN/A * to a hardware implementation of the functionality of the software
92SN/A * licensed hereunder.  You may use the software subject to the license
102SN/A * terms below provided that you ensure that this notice is replicated
112SN/A * unmodified and in its entirety in all distributions of the software,
122SN/A * modified or unmodified, in source code or in binary form.
132SN/A *
142SN/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.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * 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
312439SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322984Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33146SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34146SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35146SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36146SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37146SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38146SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
391717SN/A *
40146SN/A * Authors: Nathan Binkert
411717SN/A */
42146SN/A
431977SN/A/* @file
442623SN/A * Device module for modelling a fixed bandwidth full duplex ethernet link
452683Sktlim@umich.edu */
461717SN/A
47146SN/A#ifndef __DEV_ETHERLINK_HH__
482683Sktlim@umich.edu#define __DEV_ETHERLINK_HH__
493348Sbinkertn@umich.edu
502683Sktlim@umich.edu#include <queue>
512036SN/A
52146SN/A#include "base/types.hh"
5356SN/A#include "dev/etherint.hh"
5456SN/A#include "dev/etherobject.hh"
5556SN/A#include "dev/etherpkt.hh"
56695SN/A#include "params/EtherLink.hh"
572901Ssaidi@eecs.umich.edu#include "sim/eventq.hh"
582SN/A#include "sim/sim_object.hh"
591858SN/A
603565Sgblack@eecs.umich.educlass EtherDump;
613565Sgblack@eecs.umich.educlass Checkpoint;
622171SN/A/*
632170SN/A * Model for a fixed bandwidth full duplex ethernet link
643562Sgblack@eecs.umich.edu */
65146SN/Aclass EtherLink : public EtherObject
662462SN/A{
67146SN/A  protected:
682SN/A    class Interface;
692SN/A
702449SN/A    /*
711355SN/A     * Model for a single uni-directional link
722623SN/A     */
734495Sacolyte@umich.edu    class Link
74224SN/A    {
751858SN/A      protected:
762683Sktlim@umich.edu        const std::string objName;
772420SN/A
782683Sktlim@umich.edu        EtherLink *const parent;
793402Sktlim@umich.edu        const int number;
802420SN/A
812SN/A        Interface *txint;
824400Srdreslin@umich.edu        Interface *rxint;
832672Sktlim@umich.edu
842683Sktlim@umich.edu        const double ticksPerByte;
852SN/A        const Tick linkDelay;
862SN/A        const Tick delayVar;
87334SN/A        EtherDump *const dump;
88140SN/A
89334SN/A      protected:
902SN/A        /*
912SN/A         * Transfer is complete
922SN/A         */
932680Sktlim@umich.edu        EthPacketPtr packet;
944377Sgblack@eecs.umich.edu        void txDone();
954377Sgblack@eecs.umich.edu        typedef EventWrapper<Link, &Link::txDone> DoneEvent;
964377Sgblack@eecs.umich.edu        friend void DoneEvent::process();
972SN/A        DoneEvent doneEvent;
982SN/A
992623SN/A        /**
1002SN/A         * Maintain a queue of in-flight packets. Assume that the
1012SN/A         * delay is non-zero and constant (i.e., at most one packet
1022SN/A         * per tick).
103180SN/A         */
1042623SN/A        std::deque<std::pair<Tick, EthPacketPtr>> txQueue;
105393SN/A
106393SN/A        void processTxQueue();
107393SN/A        typedef EventWrapper<Link, &Link::processTxQueue> TxQueueEvent;
108393SN/A        friend void TxQueueEvent::process();
109384SN/A        TxQueueEvent txQueueEvent;
110384SN/A
111393SN/A        void txComplete(EthPacketPtr packet);
1122623SN/A
113393SN/A      public:
114393SN/A        Link(const std::string &name, EtherLink *p, int num,
115393SN/A             double rate, Tick delay, Tick delay_var, EtherDump *dump);
116393SN/A        ~Link() {}
117384SN/A
118189SN/A        const std::string name() const { return objName; }
119189SN/A
1202623SN/A        bool busy() const { return (bool)packet; }
1212SN/A        bool transmit(EthPacketPtr packet);
122729SN/A
123334SN/A        void setTxInt(Interface *i) { assert(!txint); txint = i; }
1242SN/A        void setRxInt(Interface *i) { assert(!rxint); rxint = i; }
1252SN/A
1262SN/A        void serialize(const std::string &base, CheckpointOut &cp) const;
1272SN/A        void unserialize(const std::string &base, CheckpointIn &cp);
1282SN/A    };
1292SN/A
1302SN/A    /*
1312SN/A     * Interface at each end of the link
1322SN/A     */
1332SN/A    class Interface : public EtherInt
1342SN/A    {
1352SN/A      private:
1361001SN/A        Link *txlink;
1371001SN/A
1381001SN/A      public:
1391001SN/A        Interface(const std::string &name, Link *txlink, Link *rxlink);
1401001SN/A        bool recvPacket(EthPacketPtr packet) { return txlink->transmit(packet); }
1412SN/A        void sendDone() { peer->sendDone(); }
1422SN/A        bool isBusy() { return txlink->busy(); }
1432SN/A    };
1442SN/A
1452SN/A    Link *link[2];
1462SN/A    Interface *interface[2];
1472SN/A
1482SN/A  public:
1492SN/A    typedef EtherLinkParams Params;
1502SN/A    EtherLink(const Params *p);
1512SN/A    virtual ~EtherLink();
1522SN/A
1532SN/A    const Params *
1542SN/A    params() const
1552SN/A    {
1562SN/A        return dynamic_cast<const Params *>(_params);
1572SN/A    }
1582390SN/A
1592390SN/A    virtual EtherInt *getEthPort(const std::string &if_name, int idx);
1602390SN/A
1612390SN/A    void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
1622390SN/A    void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
1632390SN/A
1642390SN/A};
1652390SN/A
1662390SN/A#endif // __ETHERLINK_HH__
1672390SN/A