From patchwork Wed Dec 7 11:49:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 87036 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp271869qgi; Wed, 7 Dec 2016 03:53:35 -0800 (PST) X-Received: by 10.237.47.227 with SMTP id m90mr59574997qtd.120.1481111615122; Wed, 07 Dec 2016 03:53:35 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 66si14218016qkt.189.2016.12.07.03.53.34; Wed, 07 Dec 2016 03:53:35 -0800 (PST) Received-SPF: pass (google.com: domain of linaro-uefi-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linaro-uefi-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=linaro-uefi-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C431762EA2; Wed, 7 Dec 2016 11:53:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_FRT_BELOW2 autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 6CD5F60EFB; Wed, 7 Dec 2016 11:52:27 +0000 (UTC) X-Original-To: linaro-uefi@lists.linaro.org Delivered-To: linaro-uefi@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B7A8F60ED2; Wed, 7 Dec 2016 11:52:14 +0000 (UTC) Received: from mail-pg0-f48.google.com (mail-pg0-f48.google.com [74.125.83.48]) by lists.linaro.org (Postfix) with ESMTPS id BADB760E27 for ; Wed, 7 Dec 2016 11:51:42 +0000 (UTC) Received: by mail-pg0-f48.google.com with SMTP id p66so161415357pga.2 for ; Wed, 07 Dec 2016 03:51:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=C+AL8kcBRRPMfN723ECBWpUMqTD+2qo0mFK1quxFSYo=; b=LGbESPJHEStmWyHNW2kMM2EE92hjEXq+18yTXI3BqRtT0goKC8qonfOFbXZQ8Frg7j zfpDLiKtwf5YVGRsVtwlQ8Rf8wicq1ChLSGah5DgWMVoEiV0wMNjs6kXq/RLy1k5fITn T2RD3QCGRru1+KzToJLRmnQgWw/pwBViNv72Hn17CytDuXriSbUjqLJujizd7018QMdD k0mFAI8Gt3GVoCTY5FDi1DVJUwjtLO4apkheBnKmpgpdlpO90uRhTR1tn6h+/yR0LvnB KsP0lnLI19YU6jbTp1QgdGkomNgZmoZ2OVznOoC4/wIEvmMCHKFmO65CW1tVsgVLr/s+ 3XiQ== X-Gm-Message-State: AKaTC02IF9LaYGZjp14Qsl8zrDbdCuB1uCppHynOA3rZPg/Xrn0pQ5Agbmu8yjNstkYG1P26C/E= X-Received: by 10.99.242.5 with SMTP id v5mr118637305pgh.181.1481111501995; Wed, 07 Dec 2016 03:51:41 -0800 (PST) Received: from localhost.localdomain ([119.145.15.121]) by smtp.gmail.com with ESMTPSA id y20sm42169141pfj.26.2016.12.07.03.51.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Dec 2016 03:51:41 -0800 (PST) From: Heyi Guo To: linaro-uefi@lists.linaro.org Date: Wed, 7 Dec 2016 19:49:00 +0800 Message-Id: <1481111375-71058-4-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1481111375-71058-1-git-send-email-heyi.guo@linaro.org> References: <1481111375-71058-1-git-send-email-heyi.guo@linaro.org> Cc: Peicong Li , sunchenhui@huawei.com, wanghuiqiang@huawei.com Subject: [Linaro-uefi] [linaro-uefi v7 03/38] D03/D05: Change to access EEPROM data by checking page boundary X-BeenThere: linaro-uefi@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-uefi-bounces@lists.linaro.org Sender: "Linaro-uefi" We would get incorrect data when accessing multiple bytes at one time and going across EEPROM page boundary, so we split data when the length greater than page boundary. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Peicong Li Signed-off-by: Heyi Guo Reviewed-by: Leif Lindholm --- .../Drivers/OemNicConfig2PHi1610/OemNicConfig2P.c | 45 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/Platforms/Hisilicon/D03/Drivers/OemNicConfig2PHi1610/OemNicConfig2P.c b/Platforms/Hisilicon/D03/Drivers/OemNicConfig2PHi1610/OemNicConfig2P.c index 994ed6a..dcaf3aa 100644 --- a/Platforms/Hisilicon/D03/Drivers/OemNicConfig2PHi1610/OemNicConfig2P.c +++ b/Platforms/Hisilicon/D03/Drivers/OemNicConfig2PHi1610/OemNicConfig2P.c @@ -26,6 +26,7 @@ #include #define EEPROM_I2C_PORT 6 +#define EEPROM_PAGE_SIZE 0x40 EFI_STATUS EFIAPI OemGetMac2P (IN OUT EFI_MAC_ADDRESS *Mac, IN UINTN Port); @@ -110,6 +111,8 @@ EFI_STATUS OemGetMacE2prom(IN UINT32 Port, OUT UINT8 *pucAddr) UINT16 I2cOffset; UINT16 crc16; NIC_MAC_ADDRESS stMacDesc = {0}; + UINT16 RemainderMacOffset; + UINT16 LessSizeOfPage; Status = I2CInit(0, EEPROM_I2C_PORT, Normal); if (EFI_ERROR(Status)) @@ -124,7 +127,25 @@ EFI_STATUS OemGetMacE2prom(IN UINT32 Port, OUT UINT8 *pucAddr) stI2cDev.Port = EEPROM_I2C_PORT; stI2cDev.SlaveDeviceAddress = I2C_SLAVEADDR_EEPROM; stI2cDev.Socket = 0; - Status = I2CRead(&stI2cDev, I2cOffset, sizeof(NIC_MAC_ADDRESS), (UINT8 *)&stMacDesc); + RemainderMacOffset = I2cOffset % EEPROM_PAGE_SIZE; + LessSizeOfPage = EEPROM_PAGE_SIZE - RemainderMacOffset; + //The length of NIC_MAC_ADDRESS is 10 bytes long, + //It surly less than EEPROM page size, so we could + //code as bellow, check the address whether across the page boundary, + //and split the data when across page boundary. + if (sizeof(NIC_MAC_ADDRESS) <= LessSizeOfPage) { + Status = I2CRead(&stI2cDev, I2cOffset, sizeof(NIC_MAC_ADDRESS), (UINT8 *)&stMacDesc); + } else { + Status = I2CRead(&stI2cDev, I2cOffset, LessSizeOfPage, (UINT8 *)&stMacDesc); + if (!(EFI_ERROR(Status))) { + Status |= I2CRead( + &stI2cDev, + I2cOffset + LessSizeOfPage, + sizeof(NIC_MAC_ADDRESS) - LessSizeOfPage, + (UINT8 *)&stMacDesc + LessSizeOfPage + ); + } + } if (EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR, "[%a]:[%dL] Call I2cRead failed! p1=0x%x.\n", __FUNCTION__, __LINE__, Status)); @@ -153,6 +174,8 @@ EFI_STATUS OemSetMacE2prom(IN UINT32 Port, IN UINT8 *pucAddr) stMacDesc.MacLen = MAC_ADDR_LEN; + UINT16 RemainderMacOffset; + UINT16 LessSizeOfPage; gBS->CopyMem((VOID *)(stMacDesc.Mac), (VOID *)pucAddr, MAC_ADDR_LEN); stMacDesc.Crc16 = make_crc_checksum((UINT8 *)&(stMacDesc.MacLen), sizeof(stMacDesc.MacLen) + MAC_ADDR_LEN); @@ -170,7 +193,25 @@ EFI_STATUS OemSetMacE2prom(IN UINT32 Port, IN UINT8 *pucAddr) stI2cDev.Port = EEPROM_I2C_PORT; stI2cDev.SlaveDeviceAddress = I2C_SLAVEADDR_EEPROM; stI2cDev.Socket = 0; - Status = I2CWrite(&stI2cDev, I2cOffset, sizeof(NIC_MAC_ADDRESS), (UINT8 *)&stMacDesc); + RemainderMacOffset = I2cOffset % EEPROM_PAGE_SIZE; + LessSizeOfPage = EEPROM_PAGE_SIZE - RemainderMacOffset; + //The length of NIC_MAC_ADDRESS is 10 bytes long, + //It surly less than EEPROM page size, so we could + //code as bellow, check the address whether across the page boundary, + //and split the data when across page boundary. + if (sizeof(NIC_MAC_ADDRESS) <= LessSizeOfPage) { + Status = I2CWrite(&stI2cDev, I2cOffset, sizeof(NIC_MAC_ADDRESS), (UINT8 *)&stMacDesc); + } else { + Status = I2CWrite(&stI2cDev, I2cOffset, LessSizeOfPage, (UINT8 *)&stMacDesc); + if (!(EFI_ERROR(Status))) { + Status |= I2CWrite( + &stI2cDev, + I2cOffset + LessSizeOfPage, + sizeof(NIC_MAC_ADDRESS) - LessSizeOfPage, + (UINT8 *)&stMacDesc + LessSizeOfPage + ); + } + } if (EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR, "[%a]:[%dL] Call I2cWrite failed! p1=0x%x.\n", __FUNCTION__, __LINE__, Status));