From patchwork Fri Sep 10 06:22:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12484449 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C01D0C433EF for ; Fri, 10 Sep 2021 06:28:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E5E3610C9 for ; Fri, 10 Sep 2021 06:28:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231171AbhIJG3T (ORCPT ); Fri, 10 Sep 2021 02:29:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230467AbhIJG3S (ORCPT ); Fri, 10 Sep 2021 02:29:18 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6459C061574; Thu, 9 Sep 2021 23:28:07 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id t18so1083673wrb.0; Thu, 09 Sep 2021 23:28:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=JWf4yF5KquCSwG+63OJJa1U7ntFDUJfhUzH00QrGcfU=; b=YizobErLJdrH7022UAiQyOvkewG4HyS05ecVD8IwQz9OKvhrnbbvspIKSol5R6YYTK IYksQn+SY1DxYpLVNMYEwb4/9qWggQUqbWntNstG1kjp149XU1dYOGb4cYOGh7FRQ7+O vrfWvhYQSPcOFfEFDuQWEcQ//++3DyIFkTA99cDx1YP0yiErSPJwRHaQl0BLU30kArNW O15zfhItll1+GjMLz8EI2JOEYPnAJRPFdVPHsUkREUCwTq8DEd9N8GvdIg/kpryP8ot/ d60VEeIY2H5soUz/2AX0EqU09tqQmUHggOXumaRW1ccR5ngKy1JxrkW1zmktxTEA3l68 Il7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=JWf4yF5KquCSwG+63OJJa1U7ntFDUJfhUzH00QrGcfU=; b=7bzcJlhkoRi5nF0/1F9eJsnD+ENMCymQxYTJHtXb3Us9KewWjCTjO6L06m3TBSfNMv PeuYbjF22np6xL7WLxKUpmrvvjoHoVPtnkh15rcpLEapnVyrzv0DygesjKbem5THsNJa TD2Pp2u6DvEqoOSgmAAjXIGJrCxfHZT2b2B7VSr7fP85GIpHrOVxuGgEakcRY7yFiHC/ PnxwTLvd36/dDQ7UvFpBG0IMuRUV1HFNuEF9NtqON1TT9g6lRFUqPWAbKF6Mw1IqEdvA N5DwQZa9gohtdLDnN45CEsBzU6IVKSdmFPc2Etur7GWZ9xl1cJxRSmWgLa6/z1wLH2A1 B4vA== X-Gm-Message-State: AOAM5326vurtrWPlQOU/ENHBLy987kc4pHQSPDnuOWeNwRfG33+bV+P4 4xA69seP7PKqOoIIz7XTLzucBlDAnAU= X-Google-Smtp-Source: ABdhPJysvk/ywMehS9Iujv5cudSBURB3fGf4P63th6jMzOJuBM9XVWhdRjC0I+cjPDSteQClzUfwGw== X-Received: by 2002:adf:ecc6:: with SMTP id s6mr494360wro.361.1631255285655; Thu, 09 Sep 2021 23:28:05 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:c9c:396a:4a57:ee58? (p200300ea8f0845000c9c396a4a57ee58.dip0.t-ipconnect.de. [2003:ea:8f08:4500:c9c:396a:4a57:ee58]) by smtp.googlemail.com with ESMTPSA id m29sm3875515wrb.89.2021.09.09.23.28.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Sep 2021 23:28:05 -0700 (PDT) Subject: [PATCH 1/5] PCI/VPD: Add pci_read/write_vpd_any() From: Heiner Kallweit To: Bjorn Helgaas , Jakub Kicinski , David Miller , Raju Rangoju Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: Message-ID: <93ecce28-a158-f02a-d134-8afcaced8efe@gmail.com> Date: Fri, 10 Sep 2021 08:22:06 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In certain cases we need a variant of pci_read_vpd()/pci_write_vpd() that does not check against dev->vpd.len. Such cases are: - reading VPD if dev->vpd.len isn't set yet (in pci_vpd_size()) - devices that map non-VPD information to arbitrary places in VPD address space (example: Chelsio T3 EEPROM write-protect flag) Therefore add function variants that check against PCI_VPD_MAX_SIZE only. Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 72 +++++++++++++++++++++++++++++++-------------- include/linux/pci.h | 2 ++ 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 25557b272..286cad2a6 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -138,9 +138,10 @@ static int pci_vpd_wait(struct pci_dev *dev, bool set) } static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, - void *arg) + void *arg, bool check_size) { struct pci_vpd *vpd = &dev->vpd; + unsigned int max_len = check_size ? vpd->len : PCI_VPD_MAX_SIZE; int ret = 0; loff_t end = pos + count; u8 *buf = arg; @@ -151,11 +152,11 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, if (pos < 0) return -EINVAL; - if (pos > vpd->len) + if (pos >= max_len) return 0; - if (end > vpd->len) { - end = vpd->len; + if (end > max_len) { + end = max_len; count = end - pos; } @@ -199,9 +200,10 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, } static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, - const void *arg) + const void *arg, bool check_size) { struct pci_vpd *vpd = &dev->vpd; + unsigned int max_len = check_size ? vpd->len : PCI_VPD_MAX_SIZE; const u8 *buf = arg; loff_t end = pos + count; int ret = 0; @@ -212,7 +214,7 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, if (pos < 0 || (pos & 3) || (count & 3)) return -EINVAL; - if (end > vpd->len) + if (end > max_len) return -EINVAL; if (mutex_lock_killable(&vpd->lock)) @@ -365,6 +367,24 @@ static int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off, return -ENOENT; } +static ssize_t __pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf, + bool check_size) +{ + ssize_t ret; + + if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0) { + dev = pci_get_func0_dev(dev); + if (!dev) + return -ENODEV; + + ret = pci_vpd_read(dev, pos, count, buf, check_size); + pci_dev_put(dev); + return ret; + } + + return pci_vpd_read(dev, pos, count, buf, check_size); +} + /** * pci_read_vpd - Read one entry from Vital Product Data * @dev: PCI device struct @@ -373,6 +393,20 @@ static int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off, * @buf: pointer to where to store result */ ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf) +{ + return __pci_read_vpd(dev, pos, count, buf, true); +} +EXPORT_SYMBOL(pci_read_vpd); + +/* Same, but allow to access any address */ +ssize_t pci_read_vpd_any(struct pci_dev *dev, loff_t pos, size_t count, void *buf) +{ + return __pci_read_vpd(dev, pos, count, buf, false); +} +EXPORT_SYMBOL(pci_read_vpd_any); + +static ssize_t __pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, + const void *buf, bool check_size) { ssize_t ret; @@ -381,14 +415,13 @@ ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf) if (!dev) return -ENODEV; - ret = pci_vpd_read(dev, pos, count, buf); + ret = pci_vpd_write(dev, pos, count, buf, check_size); pci_dev_put(dev); return ret; } - return pci_vpd_read(dev, pos, count, buf); + return pci_vpd_write(dev, pos, count, buf, check_size); } -EXPORT_SYMBOL(pci_read_vpd); /** * pci_write_vpd - Write entry to Vital Product Data @@ -399,22 +432,17 @@ EXPORT_SYMBOL(pci_read_vpd); */ ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf) { - ssize_t ret; - - if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0) { - dev = pci_get_func0_dev(dev); - if (!dev) - return -ENODEV; - - ret = pci_vpd_write(dev, pos, count, buf); - pci_dev_put(dev); - return ret; - } - - return pci_vpd_write(dev, pos, count, buf); + return __pci_write_vpd(dev, pos, count, buf, true); } EXPORT_SYMBOL(pci_write_vpd); +/* Same, but allow to access any address */ +ssize_t pci_write_vpd_any(struct pci_dev *dev, loff_t pos, size_t count, const void *buf) +{ + return __pci_write_vpd(dev, pos, count, buf, false); +} +EXPORT_SYMBOL(pci_write_vpd_any); + int pci_vpd_find_ro_info_keyword(const void *buf, unsigned int len, const char *kw, unsigned int *size) { diff --git a/include/linux/pci.h b/include/linux/pci.h index cd8aa6fce..9649bd9e4 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1350,6 +1350,8 @@ void pci_unlock_rescan_remove(void); /* Vital Product Data routines */ ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf); ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf); +ssize_t pci_read_vpd_any(struct pci_dev *dev, loff_t pos, size_t count, void *buf); +ssize_t pci_write_vpd_any(struct pci_dev *dev, loff_t pos, size_t count, const void *buf); /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */ resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx); From patchwork Fri Sep 10 06:22:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12484451 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10D60C433FE for ; Fri, 10 Sep 2021 06:28:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB239611B0 for ; Fri, 10 Sep 2021 06:28:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231196AbhIJG3W (ORCPT ); Fri, 10 Sep 2021 02:29:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231183AbhIJG3V (ORCPT ); Fri, 10 Sep 2021 02:29:21 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76C98C061574; Thu, 9 Sep 2021 23:28:10 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id x6so1012185wrv.13; Thu, 09 Sep 2021 23:28:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=u3zmKxjyEOJYPS9SmOYf4AyL2ftl92VU0j3IVWq2EsQ=; b=keUOb0zmKQpvnkuqvN6cdLjxbAuLWTs3i/G0FYIrj9QcV0k0cD70JY6A6RMvUyjrzi kPnhyHoaSI/6MOp+j+LSxn6JATI1IRnf09f/pq+eLSutFdAOKxF3S79KyieuBMyM3ZOK YNHfrSZwJ9A8ImX0UW/5oUycaBNduu5Oe+R5IEOqAYPCSqH7f5zZhgZo4uwGgo/CQ0za +1WhoFzz/4AaUS0wN4Lf/6NvCpYh6/ekpPuluRSvljd2YfVTwSl26k3gMHpLyfjuibRl 4QnsA4Db4JoEAFEjKjNlXU13U7kQoq9dIV8lZ+LmVdoBh6DM5+5PiF4PqH5bRt9p/QZZ NWgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=u3zmKxjyEOJYPS9SmOYf4AyL2ftl92VU0j3IVWq2EsQ=; b=ZOtP6nWrhpUQ9ddb+pokRkXdJOlzEuYqBJyXCXb2+CY68iEd+hMUGgS8aXsLeA4vAb yBN8ubXs+Y3h10E33aLuJ1HcnEoI1HwSVa8Cd26EN1sixIRZjPO/YbfEzqwYCvCQNAf5 wg3WzKy1DnQHC0A69StAr9bDldU8YYH04khMpAtrZj25umECeoT2AWXm6SDCCeoN7EwU HOks6QvbydKeD3Fg6kh6tnZGlIIjUGLiQj17WfRm1ifsu2aaaO+LiPUXhcoUiBkRYyuD vf5OA4lIVHc/McwEhzOjv/KwH2Ed6QHlGC5t4+9wdjUdo8qdlrGDXPBQgTgbtzgtb0Ou o+tg== X-Gm-Message-State: AOAM53077CgqczoQlY52ZrvsBIBdzUgtFIMqKRv7zf8ofUaIc38hKk7D AXTYJ3/RaXLfRtmHtf0OduIckGLStH4= X-Google-Smtp-Source: ABdhPJwfcI+3IV3Pu6oVC7YZ+/UypQtZ06cU1n1FaZglyS7f5Yu1bM9nuEY5tzutE5WPCcXlMuQ8ig== X-Received: by 2002:adf:fdd2:: with SMTP id i18mr7686897wrs.406.1631255288922; Thu, 09 Sep 2021 23:28:08 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:c9c:396a:4a57:ee58? (p200300ea8f0845000c9c396a4a57ee58.dip0.t-ipconnect.de. [2003:ea:8f08:4500:c9c:396a:4a57:ee58]) by smtp.googlemail.com with ESMTPSA id t23sm3912274wrb.71.2021.09.09.23.28.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Sep 2021 23:28:08 -0700 (PDT) Subject: [PATCH 2/5] PCI/VPD: Use pci_read_vpd_any() in pci_vpd_size() From: Heiner Kallweit To: Bjorn Helgaas , Jakub Kicinski , David Miller , Raju Rangoju Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: Message-ID: <049fa71c-c7af-9c69-51c0-05c1bc2bf660@gmail.com> Date: Fri, 10 Sep 2021 08:22:49 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use new function pci_read_vpd_any() to simplify the code. Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 286cad2a6..517789205 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -57,10 +57,7 @@ static size_t pci_vpd_size(struct pci_dev *dev) size_t off = 0, size; unsigned char tag, header[1+2]; /* 1 byte tag, 2 bytes length */ - /* Otherwise the following reads would fail. */ - dev->vpd.len = PCI_VPD_MAX_SIZE; - - while (pci_read_vpd(dev, off, 1, header) == 1) { + while (pci_read_vpd_any(dev, off, 1, header) == 1) { size = 0; if (off == 0 && (header[0] == 0x00 || header[0] == 0xff)) @@ -68,7 +65,7 @@ static size_t pci_vpd_size(struct pci_dev *dev) if (header[0] & PCI_VPD_LRDT) { /* Large Resource Data Type Tag */ - if (pci_read_vpd(dev, off + 1, 2, &header[1]) != 2) { + if (pci_read_vpd_any(dev, off + 1, 2, &header[1]) != 2) { pci_warn(dev, "failed VPD read at offset %zu\n", off + 1); return off ?: PCI_VPD_SZ_INVALID; From patchwork Fri Sep 10 06:24:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12484453 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C738C433F5 for ; Fri, 10 Sep 2021 06:28:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 42D19611AD for ; Fri, 10 Sep 2021 06:28:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231200AbhIJG3h (ORCPT ); Fri, 10 Sep 2021 02:29:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231197AbhIJG3Y (ORCPT ); Fri, 10 Sep 2021 02:29:24 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEC58C061574; Thu, 9 Sep 2021 23:28:13 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id m25-20020a7bcb99000000b002e751bcb5dbso571731wmi.5; Thu, 09 Sep 2021 23:28:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=WvdbKbJMvq+eieS3i12cZKM/UZny/bR09IRoyLStsYI=; b=Q+dv54qf2yNvF2g35D3Xe6UesG++wEmbatOfJonRyXTaDmUnAQ6HFwbO+9Ylb4FHvC TzyvdR1nynMNgM1T26/XW5AStfowUVyqDahbIC9q/3Np8J6WfRi53HxxiIYtkss916zi H5bLH2YiQLaj3ZatgGCqygfdn+tFD1vVKVGHQ3U0EWwhHAQ/o6al6/n7CWyvJmVTXApF ny10nWSbn1XZcmYNnZV3fkeqw0gTxWi5T/2anJmwxKqfm/cbKIUtZbCoQEmdC8VpR3Rr z4ZrmblCKE61sAGGIvoT1zVz17MAO+cd8px/LY5oVg3ra2DLfkGAJ5705D7DSuVquOJR kvDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=WvdbKbJMvq+eieS3i12cZKM/UZny/bR09IRoyLStsYI=; b=0WazIWcKZhLJBFqqA+bog22FW5GbY9cD73VRR9NyvlbbNCwEKrbH17msUd0tNzV2Yf XT4dThq0LOLPrcbw1/ye7w8abyQr6aVTK7vaN7LgiKI8+9+uX4c3rGu9gqqjBvxFBAnT u129yURNV7L0jbmL84gQTnSLUZ1thOUDPelaZ6cFCZb/qfblLUpEXBbJdjexxnMokzCW Y9ls/whf/vr4hScnLHb+jWF+oBDGWXTGtlwwx1grSGYH8eXYn7nI1Y85u32vOm1DP734 BWU2mSfyt2+bL9225GB8ffCQ10spZu6pErQGze5/xEqW5Qikx0HjqqeVI6s2oemEFaHC 3aOg== X-Gm-Message-State: AOAM532YrBoqD2UtUjNeO39W+zz6G9YpZlw5HWH6gXdOCLzD0k1UkUA5 8BVo36K7n3XHA50Qn4VprtJ0kXh9OrM= X-Google-Smtp-Source: ABdhPJyQktFxj6Iae09ku4OarF/xLtnG4RccOzodP0b2pWYAMsCcoKs/V5od8ZfRSIOp/B3ef3ng7A== X-Received: by 2002:a1c:7e85:: with SMTP id z127mr6661179wmc.141.1631255292199; Thu, 09 Sep 2021 23:28:12 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:c9c:396a:4a57:ee58? (p200300ea8f0845000c9c396a4a57ee58.dip0.t-ipconnect.de. [2003:ea:8f08:4500:c9c:396a:4a57:ee58]) by smtp.googlemail.com with ESMTPSA id l7sm3198306wmp.48.2021.09.09.23.28.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Sep 2021 23:28:11 -0700 (PDT) Subject: [PATCH 3/5] cxgb3: Remove t3_seeprom_read and use VPD API From: Heiner Kallweit To: Bjorn Helgaas , Jakub Kicinski , David Miller , Raju Rangoju Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: Message-ID: <68ef15bb-b6bf-40ad-160c-aaa72c4a70f8@gmail.com> Date: Fri, 10 Sep 2021 08:24:07 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Using the VPD API allows to simplify the code and completely get rid of t3_seeprom_read(). Note that we don't have to use pci_read_vpd_any() here because a VPD quirk sets dev->vpd.len to the full EEPROM size. Tested with a T320 card. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/chelsio/cxgb3/common.h | 1 - .../net/ethernet/chelsio/cxgb3/cxgb3_main.c | 27 ++++------ drivers/net/ethernet/chelsio/cxgb3/t3_hw.c | 54 +++---------------- 3 files changed, 18 insertions(+), 64 deletions(-) diff --git a/drivers/net/ethernet/chelsio/cxgb3/common.h b/drivers/net/ethernet/chelsio/cxgb3/common.h index b706f2fbe..56312f9ed 100644 --- a/drivers/net/ethernet/chelsio/cxgb3/common.h +++ b/drivers/net/ethernet/chelsio/cxgb3/common.h @@ -676,7 +676,6 @@ void t3_link_changed(struct adapter *adapter, int port_id); void t3_link_fault(struct adapter *adapter, int port_id); int t3_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc); const struct adapter_info *t3_get_adapter_info(unsigned int board_id); -int t3_seeprom_read(struct adapter *adapter, u32 addr, __le32 *data); int t3_seeprom_write(struct adapter *adapter, u32 addr, __le32 data); int t3_seeprom_wp(struct adapter *adapter, int enable); int t3_get_tp_version(struct adapter *adapter, u32 *vers); diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c index 38e47703f..d73339682 100644 --- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c +++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c @@ -2036,20 +2036,16 @@ static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *e, { struct port_info *pi = netdev_priv(dev); struct adapter *adapter = pi->adapter; - int i, err = 0; - - u8 *buf = kmalloc(EEPROMSIZE, GFP_KERNEL); - if (!buf) - return -ENOMEM; + int cnt; e->magic = EEPROM_MAGIC; - for (i = e->offset & ~3; !err && i < e->offset + e->len; i += 4) - err = t3_seeprom_read(adapter, i, (__le32 *) & buf[i]); + cnt = pci_read_vpd(adapter->pdev, e->offset, e->len, data); + if (cnt < 0) + return cnt; - if (!err) - memcpy(data, buf + e->offset, e->len); - kfree(buf); - return err; + e->len = cnt; + + return 0; } static int set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, @@ -2072,12 +2068,9 @@ static int set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, buf = kmalloc(aligned_len, GFP_KERNEL); if (!buf) return -ENOMEM; - err = t3_seeprom_read(adapter, aligned_offset, (__le32 *) buf); - if (!err && aligned_len > 4) - err = t3_seeprom_read(adapter, - aligned_offset + aligned_len - 4, - (__le32 *) & buf[aligned_len - 4]); - if (err) + err = pci_read_vpd(adapter->pdev, aligned_offset, aligned_len, + buf); + if (err < 0) goto out; memcpy(buf + (eeprom->offset & 3), data, eeprom->len); } else diff --git a/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c b/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c index 7ff31d102..4ecf40b02 100644 --- a/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c +++ b/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c @@ -599,42 +599,6 @@ struct t3_vpd { #define EEPROM_STAT_ADDR 0x4000 #define VPD_BASE 0xc00 -/** - * t3_seeprom_read - read a VPD EEPROM location - * @adapter: adapter to read - * @addr: EEPROM address - * @data: where to store the read data - * - * Read a 32-bit word from a location in VPD EEPROM using the card's PCI - * VPD ROM capability. A zero is written to the flag bit when the - * address is written to the control register. The hardware device will - * set the flag to 1 when 4 bytes have been read into the data register. - */ -int t3_seeprom_read(struct adapter *adapter, u32 addr, __le32 *data) -{ - u16 val; - int attempts = EEPROM_MAX_POLL; - u32 v; - unsigned int base = adapter->params.pci.vpd_cap_addr; - - if ((addr >= EEPROMSIZE && addr != EEPROM_STAT_ADDR) || (addr & 3)) - return -EINVAL; - - pci_write_config_word(adapter->pdev, base + PCI_VPD_ADDR, addr); - do { - udelay(10); - pci_read_config_word(adapter->pdev, base + PCI_VPD_ADDR, &val); - } while (!(val & PCI_VPD_ADDR_F) && --attempts); - - if (!(val & PCI_VPD_ADDR_F)) { - CH_ERR(adapter, "reading EEPROM address 0x%x failed\n", addr); - return -EIO; - } - pci_read_config_dword(adapter->pdev, base + PCI_VPD_DATA, &v); - *data = cpu_to_le32(v); - return 0; -} - /** * t3_seeprom_write - write a VPD EEPROM location * @adapter: adapter to write @@ -708,24 +672,22 @@ static int vpdstrtou16(char *s, u8 len, unsigned int base, u16 *val) */ static int get_vpd_params(struct adapter *adapter, struct vpd_params *p) { - int i, addr, ret; struct t3_vpd vpd; + u8 base_val = 0; + int addr, ret; /* * Card information is normally at VPD_BASE but some early cards had * it at 0. */ - ret = t3_seeprom_read(adapter, VPD_BASE, (__le32 *)&vpd); - if (ret) + ret = pci_read_vpd(adapter->pdev, VPD_BASE, 1, &base_val); + if (ret < 0) return ret; - addr = vpd.id_tag == 0x82 ? VPD_BASE : 0; + addr = base_val == PCI_VPD_LRDT_ID_STRING ? VPD_BASE : 0; - for (i = 0; i < sizeof(vpd); i += 4) { - ret = t3_seeprom_read(adapter, addr + i, - (__le32 *)((u8 *)&vpd + i)); - if (ret) - return ret; - } + ret = pci_read_vpd(adapter->pdev, addr, sizeof(vpd), &vpd); + if (ret < 0) + return ret; ret = vpdstrtouint(vpd.cclk_data, vpd.cclk_len, 10, &p->cclk); if (ret) From patchwork Fri Sep 10 06:25:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12484455 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50B30C4332F for ; Fri, 10 Sep 2021 06:28:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 32945611AF for ; Fri, 10 Sep 2021 06:28:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231209AbhIJG3i (ORCPT ); Fri, 10 Sep 2021 02:29:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231183AbhIJG31 (ORCPT ); Fri, 10 Sep 2021 02:29:27 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CFBBC061756; Thu, 9 Sep 2021 23:28:17 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id u15-20020a05600c19cf00b002f6445b8f55so603515wmq.0; Thu, 09 Sep 2021 23:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=z25soX/dlUjEEze8+LybPfo7Hfy5/6i6KwpPFbn2xqc=; b=L6iEN54AZrSuMIdo3he4EZqUvaIEswWiGTEzCh+r3K959/LFe7fnxsT13JVLgsfmNI JhwshUeUqjgV40Q3SvqkRhmdOoosCNEHql5ZvabmKSflhIG+Fg30BpNGsim383mDcf5D Tyy2/1xSEjW5yK0o+p2ld5/plutrFxYz9i/dicdBfuRkngAwKivl39qCzD1CyxLMlOQp 8hGeC73j5JY4DVBtah+1kp8DL27rHqo4zxH9atDyXcKsEzOetXCWOggQeoGO5e5HhVui Xn09cFmtpyrudUwi4pmQVMugWLJsvoVo5J6onRYwTfs9iEC9RJWrSFJjcYoywwypp/ba CBJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=z25soX/dlUjEEze8+LybPfo7Hfy5/6i6KwpPFbn2xqc=; b=MhhK06GFYqCQBvQdlQt92s7va4Te+FRALIv/XDej6p0mtytpPuCIDhBKLH6kTRlIPW h6NzVa/m9gdcfJzYbnDStcpr0WptFV2kowEUsu3GuaBOrqN78Yz+Li7od+4QdPMud4Lx IjLwXM/DKVXIXnzMTIlSg+qUwHprTJfrhQYsG+1B25TNVvQBuh9umNFfBXHHa5j72Q+0 OzB7yq/sHaeJmPMdzK1PQOyiR/IejWV3KRcF7xClZmhXvOyz8V6FIzpfcVhbTbXtuVG+ +CykRPbWHO1OuZZDbOcD/s4uR8lVk+cEJTpsunV0VebFbCv8J+saGzMrGJKmgT3QrnDL m+DQ== X-Gm-Message-State: AOAM531l96AO5cgwSo/hl+EtmQ+WI6/YWJ0keWcCVhUanim1RK30X+dD Zk2wrxCtUXzULGh4MyM+Lvd9cmjagX4= X-Google-Smtp-Source: ABdhPJyT/aWoWzBCHEMqDL2HQFqk5MhD3qCvPcpPjc1egEadO1akp4XRmQuAnWnGgj1gHVVAE6nY1w== X-Received: by 2002:a7b:c5d8:: with SMTP id n24mr6708628wmk.51.1631255295419; Thu, 09 Sep 2021 23:28:15 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:c9c:396a:4a57:ee58? (p200300ea8f0845000c9c396a4a57ee58.dip0.t-ipconnect.de. [2003:ea:8f08:4500:c9c:396a:4a57:ee58]) by smtp.googlemail.com with ESMTPSA id v10sm3813961wrg.15.2021.09.09.23.28.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Sep 2021 23:28:15 -0700 (PDT) Subject: [PATCH 4/5] cxgb3: Use VPD API in t3_seeprom_wp() From: Heiner Kallweit To: Bjorn Helgaas , Jakub Kicinski , David Miller , Raju Rangoju Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: Message-ID: Date: Fri, 10 Sep 2021 08:25:49 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use standard VPD API to replace t3_seeprom_write(), this prepares for removing this function. Chelsio T3 maps the EEPROM write protect flag to an arbitrary place in VPD address space, therefore we have to use pci_write_vpd_any(). Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/chelsio/cxgb3/t3_hw.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c b/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c index 4ecf40b02..ec4b49ebe 100644 --- a/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c +++ b/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c @@ -642,7 +642,14 @@ int t3_seeprom_write(struct adapter *adapter, u32 addr, __le32 data) */ int t3_seeprom_wp(struct adapter *adapter, int enable) { - return t3_seeprom_write(adapter, EEPROM_STAT_ADDR, enable ? 0xc : 0); + u32 data = enable ? 0xc : 0; + int ret; + + /* EEPROM_STAT_ADDR is outside VPD area, use pci_write_vpd_any() */ + ret = pci_write_vpd_any(adapter->pdev, EEPROM_STAT_ADDR, sizeof(u32), + &data); + + return ret < 0 ? ret : 0; } static int vpdstrtouint(char *s, u8 len, unsigned int base, unsigned int *val) From patchwork Fri Sep 10 06:27:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12484457 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 678F7C433F5 for ; Fri, 10 Sep 2021 06:28:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4FA6E611AD for ; Fri, 10 Sep 2021 06:28:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231253AbhIJG3j (ORCPT ); Fri, 10 Sep 2021 02:29:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231206AbhIJG3a (ORCPT ); Fri, 10 Sep 2021 02:29:30 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56C3AC061574; Thu, 9 Sep 2021 23:28:20 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id g16so1045918wrb.3; Thu, 09 Sep 2021 23:28:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=BEChKUpHUmXhTGEtZcd0x0DwjyIGrrpVYK+hpDQ+L/k=; b=YhlEoJTSoEafgKpmxDwPRCClV7fs+0ObWNjO4p4XJgj/DZXUt8U5MjLL7KylgcpXZJ sjTtX6gxgGzg0G0FZ6Py0pZeqMMVUhf1m67hGUYTFmtFvOAgcl6NOrhyrnIpv7cXo5kc Qnyu7xToNTiZsZntVL8E0vyLVmhfZGl9z/gOcQKti1jTc3UyhvqiJCY0fklMSUoFxp2Q BJ+j25X2zljxBrYdqJA119/hScwi3LCCwOXCr+u4Zlj8XaWshq8ryRHBhcTZa/alzgyG HIS5VhsYv+rnFvu4g5RVR6BhUB1EPNnFwuTS02L5clCXMuHA+UEfZkEYBjYFN3L7oRWU waLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=BEChKUpHUmXhTGEtZcd0x0DwjyIGrrpVYK+hpDQ+L/k=; b=pNojfETUmds4eEeNI+a/SgMDcS7qT0zkGcAz1kg5DOoAuPvz+29CH9XmS+Dosbel+y pQxdO2tdosAPqdCi7bW82RRjPeFgiBGwTttysXC8zVQ3dSqOoN4aXEdVGbi6a2Q4TQSy zNUEvHIxis3IvCYyTCsOYDG8iBM3+vvOfTuKHfcroAvRe7ane180I7YLqQ9VXPGrtfKl DMBh9xPWunwyWVnof0PAXuueJLJGQCeuioMVVOtnm7YVBb8KGqP9EnZhSU7jGHAGL3Qv xVyCm0zuYx6hIOpUG1uwtoBUTTf9rhTr80mEifsVMAV5E0oFdMDLkAalbPIQuz+iaqz0 UNTg== X-Gm-Message-State: AOAM530w6Vr8WFtcaKuZD8sKcnhRQs8RCML0zxplYRyzfuyJ3Rn1D2Bm Zl3sl9qdJhTQ1DCTnRWcZgENPRf5ObI= X-Google-Smtp-Source: ABdhPJxIIGGVU5DA0a69MXDVvABs5Pz2jNzE6lelZxBsSiXoDqdDNxhwoXFd4qMtbi0qZja9to+DFg== X-Received: by 2002:adf:fd8c:: with SMTP id d12mr7733884wrr.21.1631255298731; Thu, 09 Sep 2021 23:28:18 -0700 (PDT) Received: from ?IPv6:2003:ea:8f08:4500:c9c:396a:4a57:ee58? (p200300ea8f0845000c9c396a4a57ee58.dip0.t-ipconnect.de. [2003:ea:8f08:4500:c9c:396a:4a57:ee58]) by smtp.googlemail.com with ESMTPSA id a6sm3364537wmb.7.2021.09.09.23.28.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Sep 2021 23:28:18 -0700 (PDT) Subject: [PATCH 5/5] cxgb3: Remove seeprom_write and use VPD API From: Heiner Kallweit To: Bjorn Helgaas , Jakub Kicinski , David Miller , Raju Rangoju Cc: "linux-pci@vger.kernel.org" , "netdev@vger.kernel.org" References: Message-ID: Date: Fri, 10 Sep 2021 08:27:08 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Using the VPD API allows to simplify the code and completely get rid of t3_seeprom_write(). Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/chelsio/cxgb3/common.h | 1 - .../net/ethernet/chelsio/cxgb3/cxgb3_main.c | 11 ++---- drivers/net/ethernet/chelsio/cxgb3/t3_hw.c | 35 ------------------- 3 files changed, 3 insertions(+), 44 deletions(-) diff --git a/drivers/net/ethernet/chelsio/cxgb3/common.h b/drivers/net/ethernet/chelsio/cxgb3/common.h index 56312f9ed..d115ec932 100644 --- a/drivers/net/ethernet/chelsio/cxgb3/common.h +++ b/drivers/net/ethernet/chelsio/cxgb3/common.h @@ -676,7 +676,6 @@ void t3_link_changed(struct adapter *adapter, int port_id); void t3_link_fault(struct adapter *adapter, int port_id); int t3_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc); const struct adapter_info *t3_get_adapter_info(unsigned int board_id); -int t3_seeprom_write(struct adapter *adapter, u32 addr, __le32 data); int t3_seeprom_wp(struct adapter *adapter, int enable); int t3_get_tp_version(struct adapter *adapter, u32 *vers); int t3_check_tpsram_version(struct adapter *adapter); diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c index d73339682..e185f5f24 100644 --- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c +++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c @@ -2054,7 +2054,6 @@ static int set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, struct port_info *pi = netdev_priv(dev); struct adapter *adapter = pi->adapter; u32 aligned_offset, aligned_len; - __le32 *p; u8 *buf; int err; @@ -2080,17 +2079,13 @@ static int set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, if (err) goto out; - for (p = (__le32 *) buf; !err && aligned_len; aligned_len -= 4, p++) { - err = t3_seeprom_write(adapter, aligned_offset, *p); - aligned_offset += 4; - } - - if (!err) + err = pci_write_vpd(adapter->pdev, aligned_offset, aligned_len, buf); + if (err >= 0) err = t3_seeprom_wp(adapter, 1); out: if (buf != data) kfree(buf); - return err; + return err < 0 ? err : 0; } static void get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) diff --git a/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c b/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c index ec4b49ebe..cb85c2f21 100644 --- a/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c +++ b/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c @@ -595,44 +595,9 @@ struct t3_vpd { u32 pad; /* for multiple-of-4 sizing and alignment */ }; -#define EEPROM_MAX_POLL 40 #define EEPROM_STAT_ADDR 0x4000 #define VPD_BASE 0xc00 -/** - * t3_seeprom_write - write a VPD EEPROM location - * @adapter: adapter to write - * @addr: EEPROM address - * @data: value to write - * - * Write a 32-bit word to a location in VPD EEPROM using the card's PCI - * VPD ROM capability. - */ -int t3_seeprom_write(struct adapter *adapter, u32 addr, __le32 data) -{ - u16 val; - int attempts = EEPROM_MAX_POLL; - unsigned int base = adapter->params.pci.vpd_cap_addr; - - if ((addr >= EEPROMSIZE && addr != EEPROM_STAT_ADDR) || (addr & 3)) - return -EINVAL; - - pci_write_config_dword(adapter->pdev, base + PCI_VPD_DATA, - le32_to_cpu(data)); - pci_write_config_word(adapter->pdev,base + PCI_VPD_ADDR, - addr | PCI_VPD_ADDR_F); - do { - msleep(1); - pci_read_config_word(adapter->pdev, base + PCI_VPD_ADDR, &val); - } while ((val & PCI_VPD_ADDR_F) && --attempts); - - if (val & PCI_VPD_ADDR_F) { - CH_ERR(adapter, "write to EEPROM address 0x%x failed\n", addr); - return -EIO; - } - return 0; -} - /** * t3_seeprom_wp - enable/disable EEPROM write protection * @adapter: the adapter