From nobody Thu Apr 25 10:15:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1575040195; cv=none; d=zohomail.com; s=zohoarc; b=PeNcIAqY1pMnK7J/wcCZrerJ0a2loTp0mmpf6hE+TXw3YM2AI2rVGivKzyQxeMlCodCkLR8W+1xdvqR+oCSyhNmm/zUSPIkWhmEm/1lKxfgLEljGo/qPAMl2MgD9HVjeVETs9VEs3xojU9FhwLmKENbxTSmHPQDsUjcn3y45G0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575040195; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=IP/SLTFWhk4WDxJ1ziCkF6+oL9+QPiFnZPV17DQ8R5U=; b=T9R9VjRZohk9nXtgQ5dGchiJKM9Q1kZESZoGvXtbhbQoSn6lJRaT6rgPV8F08Ayniz7T94WyOEnK9t6CFfhmeJVlQfWrOAe2Nw9bNJ5cEbotf2gUOsjSZcjwlZavR8ibMSff2mmOBh5W07It3g3upyNrBD1INZevSB89PzcLazY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575040195125722.7337381939606; Fri, 29 Nov 2019 07:09:55 -0800 (PST) Received: from localhost ([::1]:60074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iahu3-0000vM-O7 for importer@patchew.org; Fri, 29 Nov 2019 10:09:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57250) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iahpj-0007eG-Bp for qemu-devel@nongnu.org; Fri, 29 Nov 2019 10:05:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iahpd-00021n-84 for qemu-devel@nongnu.org; Fri, 29 Nov 2019 10:05:20 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:34959) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iahpd-0001w6-0W; Fri, 29 Nov 2019 10:05:17 -0500 Received: by mail-wm1-x342.google.com with SMTP id n5so15446956wmc.0; Fri, 29 Nov 2019 07:05:16 -0800 (PST) Received: from PKL-BWASIM-LT.mgc.mentorg.com ([110.93.212.98]) by smtp.gmail.com with ESMTPSA id c1sm26928066wrs.24.2019.11.29.07.05.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Nov 2019 07:05:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=IP/SLTFWhk4WDxJ1ziCkF6+oL9+QPiFnZPV17DQ8R5U=; b=UqZt/0sF6K3hSurWZjirrNXqcWwXrukOFmuTPzKfJwKDBaAA+AaplJ5xTOBoWj/vaZ oHPCv7uR6jFVcxIUQlF6BcvGAe9durEObp3zng0zJV4wfK7RGG2UIg1pFw8MSIOJC9dK o2aS74idukEd2Pl/49GOUPpbqrIfeZ0Hg9Xr4YatEdMkOvDev4gT8/syCtX3pEViJOmG acceuJQUjZA6/G8j81sa48b6XQFY8rR0Xy5lDKBoSw+VWPpCPPRVyVP/LfHwRh4JXmGV 5s1tlBT6PUgp4yXdyahk6YopshUJKI1bjj49NUyS0Gf+K0RCVHVMpOXa/ffoX/jPZjHN 3irQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=IP/SLTFWhk4WDxJ1ziCkF6+oL9+QPiFnZPV17DQ8R5U=; b=RfLKxpMblNRVQDJu5IAEbRzm8sdADUvPELav0sU0nV6m/XM6si0+So3xPIPQFKMPY1 sOlsh3Pz9/BIoKnB0R26Sy+CPXnE1qt7sQjDnjE2x6dIJow8XUIT0LA7cFWLU0Cbdjda VjFu1Rbc38zh4W9ZB38rcs9PZHmtZbSocFmBUFbFa4VhBLvYUZ77ECowY7Ff4M3lJAIB omD49HJsteOTAPcPGq0fm2bsRxznWYDIBqHhTC7Z5yh2dfmTLkNDawpYOVSK2RXqg+Vk TLcamdhlU566Da21eODe/nQlYz+HSTeERlBUbekMtNgdzsIV6qgvb+7GbR/glmAO6bYq dMFg== X-Gm-Message-State: APjAAAX9GP+E87ysqagqS9UP3qk/B5GtV3MUU/paXAWZpN2FS/eibmIr AM4xTVQR076+cStTDgAcaedENnB4u34= X-Google-Smtp-Source: APXvYqw7wSlSfmEgnoLUm9hxVaNc9nWlGA4F2c2ZKys3SWjL/QWyCOubTlmEEYyrnM+jUbGvMhlk0g== X-Received: by 2002:a7b:c5d0:: with SMTP id n16mr15744553wmk.78.1575039914542; Fri, 29 Nov 2019 07:05:14 -0800 (PST) From: bilalwasim676@gmail.com To: qemu-devel@nongnu.org Subject: [PATCH] net/imx_fec: Updating the IMX_FEC IP to support loopback mode. Date: Fri, 29 Nov 2019 20:05:08 +0500 Message-Id: <20191129150508.24404-1-bilalwasim676@gmail.com> X-Mailer: git-send-email 2.19.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, aa1ronham@gmail.com, jcd@tribudubois.net, qemu-arm@nongnu.org, bilal_wasim@mentor.com, linux@roeck-us.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: bwasim Loopback mode only works when specific conditions (as dictated by the IP guide) are met, i.e. the MII_MODE is set and the RMII_MODE is cleared. If not, we simply send the packet on the output queue (for TX to the host network). Tested by running a custom RTOS and TXing a ton of packets. The same packets were received on the RX side.. Signed-off-by: Bilal Wasim --- hw/net/imx_fec.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c index bd99236864..c51e7f7363 100644 --- a/hw/net/imx_fec.c +++ b/hw/net/imx_fec.c @@ -256,6 +256,29 @@ static const VMStateDescription vmstate_imx_eth =3D { =20 static void imx_eth_update(IMXFECState *s); =20 +/* + * Function to check if the MAC is configured to run in loopback mode. + * If so, invoke the "receive" routine. + * Else write to the output. + * */ +static void send_pkt(IMXFECState *s, uint8_t *frame, int frame_size) +{ + NetClientState *nc =3D qemu_get_queue(s->nic); + + /* + * Loopback or Normal mode ? + * Per the FEC Manual: If loopback is enabled, the MII_MODE + * should be SET and the RMII_MODE should be cleared. Loopback + * will only work if this criterion is met. If not met, + * we will send the frame on the output queue. */ + if ((s->regs[ENET_RCR] & ENET_RCR_LOOP) && (s->regs[ENET_RCR] & ENET_R= CR_MII_MODE) + && !(s->regs[ENET_RCR] & ENET_RCR_RMII_MODE)) { + nc->info->receive(nc, frame, frame_size); + } else { + qemu_send_packet(nc, frame, frame_size); + } +} + /* * The MII phy could raise a GPIO to the processor which in turn * could be handled as an interrpt by the OS. @@ -488,7 +511,7 @@ static void imx_fec_do_tx(IMXFECState *s) frame_size +=3D len; if (bd.flags & ENET_BD_L) { /* Last buffer in frame. */ - qemu_send_packet(qemu_get_queue(s->nic), s->frame, frame_size); + send_pkt(s, (uint8_t *)&s->frame, frame_size); ptr =3D s->frame; frame_size =3D 0; s->regs[ENET_EIR] |=3D ENET_INT_TXF; @@ -586,7 +609,7 @@ static void imx_enet_do_tx(IMXFECState *s, uint32_t ind= ex) } /* Last buffer in frame. */ =20 - qemu_send_packet(qemu_get_queue(s->nic), s->frame, frame_size); + send_pkt(s, (uint8_t *)&s->frame, frame_size); ptr =3D s->frame; =20 frame_size =3D 0; --=20 2.19.1.windows.1