From patchwork Thu Jun 16 15:50:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Vecera X-Patchwork-Id: 12884394 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49DF5C43334 for ; Thu, 16 Jun 2022 15:50:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377029AbiFPPuR (ORCPT ); Thu, 16 Jun 2022 11:50:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233010AbiFPPuQ (ORCPT ); Thu, 16 Jun 2022 11:50:16 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D77DC4198D for ; Thu, 16 Jun 2022 08:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655394615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=oR7FOdSV73SVoRM/IWrD/GkndnxYt8yDT3D88SGhE+o=; b=KniY/roz9LTxN8zv9keAz/4oUqCCy9xQb2q+NQNKcOXjAQRO2B0mbuWKnQduILOV/wjr5V KnurLL75iqgsJfBJkzEnXKtm7DG9ShlWNtB9tJV2ppzJnGX/qOrX2jW1fTp/oOyt/W+CcN DMHGwfNd1ACy6ofbqsF2V18zdjlZxco= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-427-OUqm75LlNwq79eUNlPNt-w-1; Thu, 16 Jun 2022 11:50:13 -0400 X-MC-Unique: OUqm75LlNwq79eUNlPNt-w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0B5FE296A609; Thu, 16 Jun 2022 15:50:13 +0000 (UTC) Received: from p1.luc.cera.cz.com (unknown [10.40.193.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3AB710725; Thu, 16 Jun 2022 15:50:11 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Michal Kubecek , Daniel Juarez , Ido Schimmel Subject: [PATCH ethtool] sff-8079/8472: Fix missing sff-8472 output in netlink path Date: Thu, 16 Jun 2022 17:50:09 +0200 Message-Id: <20220616155009.3609572-1-ivecera@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Commit 5b64c66f58d ("ethtool: Add netlink handler for getmodule (-m)") provided a netlink variant for getmodule but also introduced a regression as netlink output is different from ioctl output that provides information from A2h page via sff8472_show_all(). To fix this the netlink path should check a presence of A2h page by value of bit 6 in byte 92 of page A0h and if it is set then get A2h page and call sff8472_show_all(). Fixes: 5b64c66f58d ("ethtool: Add netlink handler for getmodule (-m)") Tested-by: Daniel Juarez Co-authored-by: Ido Schimmel Signed-off-by: Ivan Vecera Reviewed-by: Ido Schimmel Tested-by: Ido Schimmel --- sfpid.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/sfpid.c b/sfpid.c index 621d1e86c278..1bc45c183770 100644 --- a/sfpid.c +++ b/sfpid.c @@ -13,8 +13,9 @@ #include "sff-common.h" #include "netlink/extapi.h" -#define SFF8079_PAGE_SIZE 0x80 -#define SFF8079_I2C_ADDRESS_LOW 0x50 +#define SFF8079_PAGE_SIZE 0x80 +#define SFF8079_I2C_ADDRESS_LOW 0x50 +#define SFF8079_I2C_ADDRESS_HIGH 0x51 static void sff8079_show_identifier(const __u8 *id) { @@ -450,18 +451,55 @@ void sff8079_show_all_ioctl(const __u8 *id) sff8079_show_all_common(id); } -int sff8079_show_all_nl(struct cmd_context *ctx) +static int sff8079_get_eeprom_page(struct cmd_context *ctx, u8 i2c_address, + __u8 *buf) { struct ethtool_module_eeprom request = { .length = SFF8079_PAGE_SIZE, - .i2c_address = SFF8079_I2C_ADDRESS_LOW, + .i2c_address = i2c_address, }; int ret; ret = nl_get_eeprom_page(ctx, &request); - if (ret < 0) - return ret; - sff8079_show_all_common(request.data); + if (!ret) + memcpy(buf, request.data, SFF8079_PAGE_SIZE); + + return ret; +} + +int sff8079_show_all_nl(struct cmd_context *ctx) +{ + u8 *buf; + int ret; + + /* The SFF-8472 parser expects a single buffer that contains the + * concatenation of the first 256 bytes from addresses A0h and A2h, + * respectively. + */ + buf = calloc(1, ETH_MODULE_SFF_8472_LEN); + if (!buf) + return -ENOMEM; + + /* Read A0h page */ + ret = sff8079_get_eeprom_page(ctx, SFF8079_I2C_ADDRESS_LOW, buf); + if (ret) + goto out; + + sff8079_show_all_common(buf); + + /* Finish if A2h page is not present */ + if (!(buf[92] & (1 << 6))) + goto out; + + /* Read A2h page */ + ret = sff8079_get_eeprom_page(ctx, SFF8079_I2C_ADDRESS_HIGH, + buf + ETH_MODULE_SFF_8079_LEN); + if (ret) + goto out; + + sff8472_show_all(buf); +out: + free(buf); - return 0; + return ret; }