Merge gblack@m5.eecs.umich.edu:/bk/multiarch
[gem5.git] / dev / etherlink.hh
1 /*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /* @file
30 * Device module for modelling a fixed bandwidth full duplex ethernet link
31 */
32
33 #ifndef __DEV_ETHERLINK_HH__
34 #define __DEV_ETHERLINK_HH__
35
36 #include "dev/etherint.hh"
37 #include "dev/etherpkt.hh"
38 #include "sim/eventq.hh"
39 #include "sim/host.hh"
40 #include "sim/sim_object.hh"
41
42 class EtherDump;
43 class Checkpoint;
44 /*
45 * Model for a fixed bandwidth full duplex ethernet link
46 */
47 class EtherLink : public SimObject
48 {
49 protected:
50 class Interface;
51
52 friend class LinkDelayEvent;
53 /*
54 * Model for a single uni-directional link
55 */
56 class Link
57 {
58 protected:
59 std::string objName;
60
61 EtherLink *parent;
62 int number;
63
64 Interface *txint;
65 Interface *rxint;
66
67 double ticksPerByte;
68 Tick linkDelay;
69 Tick delayVar;
70 EtherDump *dump;
71
72 protected:
73 /*
74 * Transfer is complete
75 */
76 PacketPtr packet;
77 void txDone();
78 typedef EventWrapper<Link, &Link::txDone> DoneEvent;
79 friend void DoneEvent::process();
80 DoneEvent doneEvent;
81
82 friend class LinkDelayEvent;
83 void txComplete(PacketPtr packet);
84
85 public:
86 Link(const std::string &name, EtherLink *p, int num,
87 double rate, Tick delay, Tick delay_var, EtherDump *dump);
88 ~Link() {}
89
90 const std::string name() const { return objName; }
91
92 bool busy() const { return (bool)packet; }
93 bool transmit(PacketPtr packet);
94
95 void setTxInt(Interface *i) { assert(!txint); txint = i; }
96 void setRxInt(Interface *i) { assert(!rxint); rxint = i; }
97
98 void serialize(const std::string &base, std::ostream &os);
99 void unserialize(const std::string &base, Checkpoint *cp,
100 const std::string &section);
101 };
102
103 /*
104 * Interface at each end of the link
105 */
106 class Interface : public EtherInt
107 {
108 private:
109 Link *txlink;
110
111 public:
112 Interface(const std::string &name, Link *txlink, Link *rxlink);
113 bool recvPacket(PacketPtr packet) { return txlink->transmit(packet); }
114 void sendDone() { peer->sendDone(); }
115 };
116
117 Link *link[2];
118 EtherInt *interface[2];
119
120 public:
121 EtherLink(const std::string &name, EtherInt *peer0, EtherInt *peer1,
122 double rate, Tick delay, Tick delayVar, EtherDump *dump);
123 virtual ~EtherLink();
124
125 virtual void serialize(std::ostream &os);
126 virtual void unserialize(Checkpoint *cp, const std::string &section);
127
128 };
129
130 #endif // __ETHERLINK_HH__