etherbus.cc revision 13766
18926Sandreas.hansson@arm.com/* 27586SAli.Saidi@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 37586SAli.Saidi@arm.com * All rights reserved. 47586SAli.Saidi@arm.com * 57586SAli.Saidi@arm.com * Redistribution and use in source and binary forms, with or without 67586SAli.Saidi@arm.com * modification, are permitted provided that the following conditions are 77586SAli.Saidi@arm.com * met: redistributions of source code must retain the above copyright 87586SAli.Saidi@arm.com * notice, this list of conditions and the following disclaimer; 97586SAli.Saidi@arm.com * redistributions in binary form must reproduce the above copyright 107586SAli.Saidi@arm.com * notice, this list of conditions and the following disclaimer in the 117586SAli.Saidi@arm.com * documentation and/or other materials provided with the distribution; 127586SAli.Saidi@arm.com * neither the name of the copyright holders nor the names of its 133970Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 143005Sstever@eecs.umich.edu * this software without specific prior written permission. 153005Sstever@eecs.umich.edu * 163005Sstever@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173005Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 183005Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 193005Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 203005Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 213005Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 223005Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 233005Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 243005Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 253005Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263005Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273005Sstever@eecs.umich.edu * 283005Sstever@eecs.umich.edu * Authors: Nathan Binkert 293005Sstever@eecs.umich.edu */ 303005Sstever@eecs.umich.edu 313005Sstever@eecs.umich.edu/* @file 323005Sstever@eecs.umich.edu * Device module for modelling an ethernet hub 333005Sstever@eecs.umich.edu */ 343005Sstever@eecs.umich.edu#include "dev/net/etherbus.hh" 353005Sstever@eecs.umich.edu 363005Sstever@eecs.umich.edu#include <cmath> 373005Sstever@eecs.umich.edu#include <deque> 383005Sstever@eecs.umich.edu#include <string> 393005Sstever@eecs.umich.edu#include <vector> 403005Sstever@eecs.umich.edu 416654Snate@binkert.org#include "base/logging.hh" 426654Snate@binkert.org#include "base/trace.hh" 432889SN/A#include "debug/Ethernet.hh" 442710SN/A#include "debug/EthernetData.hh" 456654Snate@binkert.org#include "dev/net/etherdump.hh" 466654Snate@binkert.org#include "dev/net/etherint.hh" 476654Snate@binkert.org#include "dev/net/etherpkt.hh" 485457Ssaidi@eecs.umich.edu#include "params/EtherBus.hh" 496654Snate@binkert.org#include "sim/core.hh" 506654Snate@binkert.org 512934SN/Ausing namespace std; 522549SN/A 532995SN/AEtherBus::EtherBus(const Params *p) 543395Shsul@eecs.umich.edu : SimObject(p), ticksPerByte(p->speed), loopback(p->loopback), 556981SLisa.Hsu@amd.com event([this]{ txDone(); }, "ethernet bus completion"), 563448Shsul@eecs.umich.edu sender(0), dump(p->dump) 578920Snilay@cs.wisc.edu{ 583444Sktlim@umich.edu} 592889SN/A 608920Snilay@cs.wisc.eduvoid 618920Snilay@cs.wisc.eduEtherBus::txDone() 623322Shsul@eecs.umich.edu{ 632710SN/A devlist_t::iterator i = devlist.begin(); 642710SN/A devlist_t::iterator end = devlist.end(); 652710SN/A 662710SN/A DPRINTF(Ethernet, "ethernet packet received: length=%d\n", packet->length); 672710SN/A DDUMP(EthernetData, packet->data, packet->length); 682710SN/A 693322Shsul@eecs.umich.edu while (i != end) { 703304Sstever@eecs.umich.edu if (loopback || *i != sender) 713322Shsul@eecs.umich.edu (*i)->sendPacket(packet); 723322Shsul@eecs.umich.edu ++i; 733304Sstever@eecs.umich.edu } 743481Shsul@eecs.umich.edu 753481Shsul@eecs.umich.edu sender->sendDone(); 762566SN/A 779129Sandreas.hansson@arm.com if (dump) 789129Sandreas.hansson@arm.com dump->dump(packet); 792995SN/A 802995SN/A sender = 0; 813304Sstever@eecs.umich.edu packet = 0; 823304Sstever@eecs.umich.edu} 833304Sstever@eecs.umich.edu 842995SN/AEtherInt* 852995SN/AEtherBus::getEthPort(const std::string &if_name, int idx) 862995SN/A{ 872917SN/A panic("Etherbus doesn't work\n"); 882995SN/A} 898956Sjayneel@cs.wisc.edu 902995SN/Abool 918956Sjayneel@cs.wisc.eduEtherBus::send(EtherInt *sndr, EthPacketPtr &pkt) 923304Sstever@eecs.umich.edu{ 936135Sgblack@eecs.umich.edu if (busy()) { 946135Sgblack@eecs.umich.edu DPRINTF(Ethernet, "ethernet packet not sent, bus busy\n", curTick()); 956654Snate@binkert.org return false; 963819Shsul@eecs.umich.edu } 976654Snate@binkert.org 985222Sksewell@umich.edu DPRINTF(Ethernet, "ethernet packet sent: length=%d\n", pkt->length); 996654Snate@binkert.org DDUMP(EthernetData, pkt->data, pkt->length); 1003819Shsul@eecs.umich.edu 1016654Snate@binkert.org packet = pkt; 1027925Sgblack@eecs.umich.edu sender = sndr; 1037586SAli.Saidi@arm.com int delay = (int)ceil(((double)pkt->simLength * ticksPerByte) + 1.0); 1048061SAli.Saidi@ARM.com DPRINTF(Ethernet, "scheduling packet: delay=%d, (rate=%f)\n", 1058061SAli.Saidi@ARM.com delay, ticksPerByte); 1068061SAli.Saidi@ARM.com schedule(event, curTick() + delay); 1073819Shsul@eecs.umich.edu 1089059Snilay@cs.wisc.edu return true; 1093819Shsul@eecs.umich.edu} 1103873Sbinkertn@umich.edu 1113873Sbinkertn@umich.eduEtherBus * 1123873Sbinkertn@umich.eduEtherBusParams::create() 1133873Sbinkertn@umich.edu{ 1143873Sbinkertn@umich.edu return new EtherBus(this); 1153873Sbinkertn@umich.edu} 1168659SAli.Saidi@ARM.com