etherlink.hh revision 1762
11689SN/A/*
212106SRekai.GonzalezAlberquilla@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
39913Ssteve.reinhardt@amd.com * All rights reserved.
47854SAli.Saidi@ARM.com *
57854SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without
67854SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are
77854SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright
87854SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer;
97854SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright
107854SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the
117854SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution;
127854SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its
137854SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from
147854SAli.Saidi@ARM.com * this software without specific prior written permission.
152329SN/A *
161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271689SN/A */
281689SN/A
291689SN/A/* @file
301689SN/A * Device module for modelling a fixed bandwidth full duplex ethernet link
311689SN/A */
321689SN/A
331689SN/A#ifndef __DEV_ETHERLINK_HH__
341689SN/A#define __DEV_ETHERLINK_HH__
351689SN/A
361689SN/A#include "dev/etherint.hh"
371689SN/A#include "dev/etherpkt.hh"
381689SN/A#include "sim/eventq.hh"
391689SN/A#include "sim/host.hh"
402665Ssaidi@eecs.umich.edu#include "sim/sim_object.hh"
412665Ssaidi@eecs.umich.edu
422935Sksewell@umich.educlass EtherDump;
431689SN/Aclass Checkpoint;
441689SN/A/*
459944Smatt.horsnell@ARM.com * Model for a fixed bandwidth full duplex ethernet link
469944Smatt.horsnell@ARM.com */
479944Smatt.horsnell@ARM.comclass EtherLink : public SimObject
481060SN/A{
491060SN/A  protected:
503773Sgblack@eecs.umich.edu    class Interface;
516329Sgblack@eecs.umich.edu
526658Snate@binkert.org    friend class LinkDelayEvent;
531717SN/A     /*
549913Ssteve.reinhardt@amd.com      * Model for a single uni-directional link
558232Snate@binkert.org      */
568232Snate@binkert.org    class Link
579527SMatt.Horsnell@arm.com    {
585529Snate@binkert.org      protected:
591060SN/A        std::string objName;
606221Snate@binkert.org
616221Snate@binkert.org        EtherLink *parent;
621061SN/A        int number;
635529Snate@binkert.org
644329Sktlim@umich.edu        Interface *txint;
654329Sktlim@umich.edu        Interface *rxint;
662292SN/A
672292SN/A        double ticksPerByte;
682292SN/A        Tick linkDelay;
692292SN/A        EtherDump *dump;
7012109SRekai.GonzalezAlberquilla@arm.com
711060SN/A      protected:
7210172Sdam.sunwoo@arm.com        /*
7310172Sdam.sunwoo@arm.com         * Transfer is complete
7410172Sdam.sunwoo@arm.com         */
7510172Sdam.sunwoo@arm.com        PacketPtr packet;
7610172Sdam.sunwoo@arm.com        void txDone();
772292SN/A        typedef EventWrapper<Link, &Link::txDone> DoneEvent;
7810328Smitch.hayenga@arm.com        friend void DoneEvent::process();
792292SN/A        DoneEvent doneEvent;
802292SN/A
812292SN/A        friend class LinkDelayEvent;
822292SN/A        void txComplete(PacketPtr packet);
832292SN/A
842292SN/A      public:
852292SN/A        Link(const std::string &name, EtherLink *p, int num,
861060SN/A             double rate, Tick delay, EtherDump *dump);
871060SN/A        ~Link() {}
881061SN/A
891060SN/A        const std::string name() const { return objName; }
902292SN/A
911062SN/A        bool busy() const { return (bool)packet; }
921062SN/A        bool transmit(PacketPtr packet);
938240Snate@binkert.org
941062SN/A        void setTxInt(Interface *i) { assert(!txint); txint = i; }
951062SN/A        void setRxInt(Interface *i) { assert(!rxint); rxint = i; }
961062SN/A
978240Snate@binkert.org        void serialize(const std::string &base, std::ostream &os);
981062SN/A        void unserialize(const std::string &base, Checkpoint *cp,
991062SN/A                                 const std::string &section);
1001062SN/A    };
1018240Snate@binkert.org
1021062SN/A    /*
1031062SN/A     * Interface at each end of the link
1042301SN/A     */
1058240Snate@binkert.org    class Interface : public EtherInt
1062301SN/A    {
1072301SN/A      private:
1082292SN/A        Link *txlink;
1098240Snate@binkert.org
1102292SN/A      public:
1112292SN/A        Interface(const std::string &name, Link *txlink, Link *rxlink);
1121062SN/A        bool recvPacket(PacketPtr packet) { return txlink->transmit(packet); }
1138240Snate@binkert.org        void sendDone() { peer->sendDone(); }
1141062SN/A    };
1151062SN/A
1161062SN/A    Link *link[2];
1178240Snate@binkert.org    EtherInt *interface[2];
1181062SN/A
1191062SN/A  public:
1201062SN/A    EtherLink(const std::string &name, EtherInt *peer0, EtherInt *peer1,
1218240Snate@binkert.org              double rate, Tick delay, EtherDump *dump);
1221062SN/A    virtual ~EtherLink();
1231062SN/A
1241062SN/A    virtual void serialize(std::ostream &os);
1258240Snate@binkert.org    virtual void unserialize(Checkpoint *cp, const std::string &section);
1262292SN/A
1271062SN/A};
1281062SN/A
1298240Snate@binkert.org#endif // __ETHERLINK_HH__
1302292SN/A