public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Marcin Wojtas" <mw@semihalf.com>
To: devel@edk2.groups.io
Cc: quic_llindhol@quicinc.com, ardb+tianocore@kernel.org,
	mw@semihalf.com, jaz@semihalf.com, gjb@semihalf.com,
	upstream@semihalf.com, sunny.Wang@arm.com
Subject: [edk2-platforms PATCH 8/8] Marvell/Drivers: Pp2Dxe: Fix Pp2SnpReceive
Date: Mon, 14 Mar 2022 16:38:37 +0100	[thread overview]
Message-ID: <20220314153837.1885852-9-mw@semihalf.com> (raw)
In-Reply-To: <20220314153837.1885852-1-mw@semihalf.com>

This patch adds missing parameter's and SNP instance
status checks in SnpReceive callback. Additionally,
the local variables declarations are cleaned-up.

Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c | 43 ++++++++++++++++----
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git a/Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c b/Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c
index 841a1c8f84..5e463ac932 100644
--- a/Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c
+++ b/Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c
@@ -1214,23 +1214,50 @@ Pp2SnpReceive (
   )
 {
   INTN ReceivedPackets;
-  PP2DXE_CONTEXT *Pp2Context = INSTANCE_FROM_SNP(This);
-  PP2DXE_PORT *Port = &Pp2Context->Port;
-  MVPP2_SHARED *Mvpp2Shared = Pp2Context->Port.Priv;
+  PP2DXE_CONTEXT *Pp2Context;
+  PP2DXE_PORT *Port;
   UINTN PhysAddr, VirtAddr;
-  EFI_STATUS Status = EFI_SUCCESS;
+  EFI_STATUS Status;
   EFI_TPL SavedTpl;
   UINT32 StatusReg;
   INTN PoolId;
   UINTN PktLength;
   UINT8 *DataPtr;
   MVPP2_RX_DESC *RxDesc;
-  MVPP2_RX_QUEUE *Rxq = &Port->Rxqs[0];
+  MVPP2_RX_QUEUE *Rxq;
+
+  /* Check input parameters. */
+  if (This == NULL || Buffer == NULL || BufferSize == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  SavedTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+  Pp2Context = INSTANCE_FROM_SNP (This);
 
+  /* Check whether the driver was started and initialized. */
+  if (This->Mode->State != EfiSimpleNetworkInitialized) {
+    switch (This->Mode->State) {
+    case EfiSimpleNetworkStopped:
+      DEBUG ((DEBUG_WARN, "Pp2Dxe%d: not started\n", Pp2Context->Instance));
+      ReturnUnlock (SavedTpl, EFI_NOT_STARTED);
+    case EfiSimpleNetworkStarted:
+      DEBUG ((DEBUG_WARN, "Pp2Dxe%d: not initialized\n", Pp2Context->Instance));
+      ReturnUnlock (SavedTpl, EFI_DEVICE_ERROR);
+    default:
+      DEBUG ((DEBUG_WARN,
+        "Pp2Dxe%d: wrong state: %u\n",
+        Pp2Context->Instance,
+        This->Mode->State));
+      ReturnUnlock (SavedTpl, EFI_DEVICE_ERROR);
+    }
+  }
+
+  Port = &Pp2Context->Port;
   ASSERT (Port != NULL);
+  Rxq = &Port->Rxqs[0];
   ASSERT (Rxq != NULL);
 
-  SavedTpl = gBS->RaiseTPL (TPL_CALLBACK);
   ReceivedPackets = Mvpp2RxqReceived(Port, Rxq->Id);
 
   if (ReceivedPackets == 0) {
@@ -1285,10 +1312,12 @@ Pp2SnpReceive (
     *EtherType = NTOHS (*(UINT16 *)(&DataPtr[12]));
   }
 
+  Status = EFI_SUCCESS;
+
 drop:
   /* Refill: pass packet back to BM */
   PoolId = (StatusReg & MVPP2_RXD_BM_POOL_ID_MASK) >> MVPP2_RXD_BM_POOL_ID_OFFS;
-  Mvpp2BmPoolPut(Mvpp2Shared, PoolId, PhysAddr, VirtAddr);
+  Mvpp2BmPoolPut (Pp2Context->Port.Priv, PoolId, PhysAddr, VirtAddr);
 
   /* Update counters with 1 packet received and 1 packet refilled */
   Mvpp2RxqStatusUpdate(Port, Rxq->Id, 1, 1);
-- 
2.29.0


  parent reply	other threads:[~2022-03-14 15:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-14 15:38 [edk2-platforms PATCH 0/8] Marvell Pp2Dxe fixes Marcin Wojtas
2022-03-14 15:38 ` [edk2-platforms PATCH 1/8] Marvell/Drivers: Pp2Dxe: Fix Pp2SnpShutdown Marcin Wojtas
2022-03-14 15:38 ` [edk2-platforms PATCH 2/8] Marvell/Drivers: Pp2Dxe: Fix Pp2SnpReceiveFilters Marcin Wojtas
2022-03-14 15:38 ` [edk2-platforms PATCH 3/8] Marvell/Drivers: Pp2Dxe: Fix Pp2SnpStart & Pp2SnpStop Marcin Wojtas
2022-03-14 15:38 ` [edk2-platforms PATCH 4/8] Marvell/Drivers: Pp2Dxe: Implement Pp2SnpIpToMac Marcin Wojtas
2022-03-14 15:38 ` [edk2-platforms PATCH 5/8] Marvell/Drivers: Pp2Dxe: Fix Pp2SnpGetStatus Marcin Wojtas
2022-03-14 15:38 ` [edk2-platforms PATCH 6/8] Marvell/Drivers: Pp2Dxe: Fix Pp2SnpTransmit Marcin Wojtas
2022-03-14 15:38 ` [edk2-platforms PATCH 7/8] Marvell/Drivers: Pp2Dxe: Fix Pp2SnpReset Marcin Wojtas
2022-03-14 15:38 ` Marcin Wojtas [this message]
2022-04-06 20:01 ` [edk2-platforms PATCH 0/8] Marvell Pp2Dxe fixes Marcin Wojtas
2022-04-07 10:51   ` Sunny Wang
2022-04-20  8:26     ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220314153837.1885852-9-mw@semihalf.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox