etherbus.cc revision 11800
12SN/A/*
21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
32SN/A * All rights reserved.
42SN/A *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665SN/A *
282665SN/A * Authors: Nathan Binkert
292SN/A */
302SN/A
312SN/A/* @file
322SN/A * Device module for modelling an ethernet hub
332SN/A */
3411263Sandreas.sandberg@arm.com#include "dev/net/etherbus.hh"
352SN/A
36146SN/A#include <cmath>
372SN/A#include <deque>
382SN/A#include <string>
392SN/A#include <vector>
402SN/A
4111800Sbrandon.potter@amd.com#include "base/misc.hh"
42146SN/A#include "base/trace.hh"
438232SN/A#include "debug/Ethernet.hh"
448232SN/A#include "debug/EthernetData.hh"
4511263Sandreas.sandberg@arm.com#include "dev/net/etherdump.hh"
4611263Sandreas.sandberg@arm.com#include "dev/net/etherint.hh"
4711263Sandreas.sandberg@arm.com#include "dev/net/etherpkt.hh"
484762SN/A#include "params/EtherBus.hh"
494167SN/A#include "sim/core.hh"
502SN/A
512SN/Ausing namespace std;
522SN/A
534981SN/AEtherBus::EtherBus(const Params *p)
544981SN/A    : EtherObject(p), ticksPerByte(p->speed), loopback(p->loopback),
555606SN/A      event(this), sender(0), dump(p->dump)
561634SN/A{
571634SN/A}
582SN/A
592SN/Avoid
602SN/AEtherBus::txDone()
612SN/A{
622SN/A    devlist_t::iterator i = devlist.begin();
632SN/A    devlist_t::iterator end = devlist.end();
642SN/A
652SN/A    DPRINTF(Ethernet, "ethernet packet received: length=%d\n", packet->length);
662SN/A    DDUMP(EthernetData, packet->data, packet->length);
672SN/A
682SN/A    while (i != end) {
692SN/A        if (loopback || *i != sender)
702SN/A            (*i)->sendPacket(packet);
712SN/A        ++i;
722SN/A    }
732SN/A
742SN/A    sender->sendDone();
752SN/A
762SN/A    if (dump)
772SN/A        dump->dump(packet);
782SN/A
792SN/A    sender = 0;
802SN/A    packet = 0;
812SN/A}
822SN/A
834981SN/AEtherInt*
844981SN/AEtherBus::getEthPort(const std::string &if_name, int idx)
854981SN/A{
864981SN/A    panic("Etherbus doesn't work\n");
874981SN/A}
882SN/A
892SN/Abool
902566SN/AEtherBus::send(EtherInt *sndr, EthPacketPtr &pkt)
912SN/A{
922SN/A    if (busy()) {
937823SN/A        DPRINTF(Ethernet, "ethernet packet not sent, bus busy\n", curTick());
942SN/A        return false;
952SN/A    }
962SN/A
972SN/A    DPRINTF(Ethernet, "ethernet packet sent: length=%d\n", pkt->length);
982SN/A    DDUMP(EthernetData, pkt->data, pkt->length);
992SN/A
1002SN/A    packet = pkt;
1012SN/A    sender = sndr;
10211701Smichael.lebeane@amd.com    int delay = (int)ceil(((double)pkt->simLength * ticksPerByte) + 1.0);
1032SN/A    DPRINTF(Ethernet, "scheduling packet: delay=%d, (rate=%f)\n",
1041634SN/A            delay, ticksPerByte);
1057823SN/A    schedule(event, curTick() + delay);
1062SN/A
1072SN/A    return true;
1082SN/A}
1092SN/A
1104762SN/AEtherBus *
1114762SN/AEtherBusParams::create()
1122SN/A{
1134981SN/A    return new EtherBus(this);
1142SN/A}
115