From patchwork Thu May 13 20:58:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 1478202 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=ogQ0IQ9I; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Fh3tQ1bNMz9sWM for ; Fri, 14 May 2021 06:59:10 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233203AbhEMVAT (ORCPT ); Thu, 13 May 2021 17:00:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233227AbhEMVAT (ORCPT ); Thu, 13 May 2021 17:00:19 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8A14C061574 for ; Thu, 13 May 2021 13:59:08 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 8so839555wmc.5 for ; Thu, 13 May 2021 13:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=G8Z0UQqtafs8h1p+WkxnF/FQBX1MA7dX49CozQ6F0fA=; b=ogQ0IQ9IaDuGbCbjOZhZcEf72zbdhOANFaDWjcHdHsOLLJ9SDCtrR9TZIEX7gMV95m 36WEDSmSJjBzS+2b8JQBtFaKVGw9sppC219cqLuQllX//gGQGOPPf9+N0eUrdu0qtPuy K3y8Buk3vpi9lNgYkINiMkRm7l8gxSMXKLc2Hx4VMcfBcHEmc/IE59CxybtUf30TKWVM t6jyrWGQIr4/ISfLyvBuqDOoUp53U/cHo1bofS1I3Cl4mwxvABXonuAbC5ii9Gse5U7c ygSrKEDcXxTPFxVhExWT3bd5Hn20Od2B2qzzICqTJPcRIsC8SKFsQyUwgUPGPfP1c0d3 Lj0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=G8Z0UQqtafs8h1p+WkxnF/FQBX1MA7dX49CozQ6F0fA=; b=qOjD7ohhJiCXqoFXGR8vfdFxXDzRGOAiWyj1i/4koRAFKEpBoN2DArXikUlOHjCX2i PraEhf3lL3wfPRk/DUyuJD6Iu0J7MyUuyeV70gzRm/+gV1lbtRVPbb1fTsVeTQdrTq0/ s+pPuGsK3UZmVGxJKsrwh7Mvr41aVFTHVneeB7RizzUZKOblGkX9OjzuQtvwQ4YIOosM 2+dcgni2TSdshHxIEQpfdhTJ8egJiBTqElUkM/jCPvNizHZI7NST++xkOSVq4T8WEQEN PyIkOWp/FPVX9Dt/zY9NztmRmI1PoSigVqTpUPy7nBplILK1yo+56aHsotSevojOS3h3 4XXg== X-Gm-Message-State: AOAM530XTcSieR5CQ3dItErhX4t2BoF2mr2GD26hrnJu1DYtN6MOSwon 1fH1rBIrC/kfirdjx4nOT9gYFzY4AnQoxw== X-Google-Smtp-Source: ABdhPJxUDrlOuipoeFvke2BQF26lGOlnxPtgPd3LjlRDwIqvcpZhFwkc2Z6fM+zSGdIOlWT2ZR1mOg== X-Received: by 2002:a7b:c4c9:: with SMTP id g9mr5593390wmk.90.1620939547292; Thu, 13 May 2021 13:59:07 -0700 (PDT) Received: from ?IPv6:2003:ea:8f38:4600:dc15:2d50:47c3:384f? (p200300ea8f384600dc152d5047c3384f.dip0.t-ipconnect.de. [2003:ea:8f38:4600:dc15:2d50:47c3:384f]) by smtp.googlemail.com with ESMTPSA id 136sm1858456wmb.7.2021.05.13.13.59.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 May 2021 13:59:06 -0700 (PDT) Subject: [PATCH 1/5] PCI/VPD: Refactor pci_vpd_size From: Heiner Kallweit To: Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: Message-ID: <1cdda5f1-e1ea-af9f-cfbe-952b7d37e246@gmail.com> Date: Thu, 13 May 2021 22:58:40 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The only Short Resource Data Type tag is the end tag. This allows to remove the generic SRDT tag handling and the code be significantly simplified. Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 46 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 26bf7c877..ecdce170f 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -73,50 +73,28 @@ EXPORT_SYMBOL(pci_write_vpd); static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) { size_t off = 0; - unsigned char header[1+2]; /* 1 byte tag, 2 bytes length */ + u8 header[3]; /* 1 byte tag, 2 bytes length */ while (off < old_size && pci_read_vpd(dev, off, 1, header) == 1) { - unsigned char tag; - if (!header[0] && !off) { pci_info(dev, "Invalid VPD tag 00, assume missing optional VPD EPROM\n"); return 0; } - if (header[0] & PCI_VPD_LRDT) { - /* Large Resource Data Type Tag */ - tag = pci_vpd_lrdt_tag(header); - /* Only read length from known tag items */ - if ((tag == PCI_VPD_LTIN_ID_STRING) || - (tag == PCI_VPD_LTIN_RO_DATA) || - (tag == PCI_VPD_LTIN_RW_DATA)) { - if (pci_read_vpd(dev, off+1, 2, - &header[1]) != 2) { - pci_warn(dev, "invalid large VPD tag %02x size at offset %zu", - tag, off + 1); - return 0; - } - off += PCI_VPD_LRDT_TAG_SIZE + - pci_vpd_lrdt_size(header); - } - } else { - /* Short Resource Data Type Tag */ - off += PCI_VPD_SRDT_TAG_SIZE + - pci_vpd_srdt_size(header); - tag = pci_vpd_srdt_tag(header); - } - - if (tag == PCI_VPD_STIN_END) /* End tag descriptor */ - return off; + if (header[0] == PCI_VPD_SRDT_END) + return off + PCI_VPD_SRDT_TAG_SIZE; - if ((tag != PCI_VPD_LTIN_ID_STRING) && - (tag != PCI_VPD_LTIN_RO_DATA) && - (tag != PCI_VPD_LTIN_RW_DATA)) { - pci_warn(dev, "invalid %s VPD tag %02x at offset %zu", - (header[0] & PCI_VPD_LRDT) ? "large" : "short", - tag, off); + if (header[0] != PCI_VPD_LRDT_ID_STRING && + header[0] != PCI_VPD_LRDT_RO_DATA && + header[0] != PCI_VPD_LRDT_RW_DATA) { + pci_warn(dev, "invalid VPD tag %02x at offset %zu", header[0], off); return 0; } + + if (pci_read_vpd(dev, off + 1, 2, header + 1) != 2) + return 0; + + off += PCI_VPD_LRDT_TAG_SIZE + pci_vpd_lrdt_size(header); } return 0; } From patchwork Thu May 13 20:55:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 1478199 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=hv+fhFd7; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Fh3tD3sbRz9sWM for ; Fri, 14 May 2021 06:59:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232486AbhEMVAJ (ORCPT ); Thu, 13 May 2021 17:00:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231235AbhEMVAI (ORCPT ); Thu, 13 May 2021 17:00:08 -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 55505C061574 for ; Thu, 13 May 2021 13:58:58 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id x8so5831461wrq.9 for ; Thu, 13 May 2021 13:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=UeYFsUJJmpRUKdSs0Tp5gwBJrNb4ZqLnzL0AtDJ8jmo=; b=hv+fhFd7CNhwioZm7JU2OoKRyTmXEaezFNM6n6JHVxBExaMaLs0qJJd4qCW7UpIygW maWMwk5pv4aPYr59tBPQ3cgxe3Eg/qIGUsA/enYF1y7NxiuHYgn0LQmlxAzzOcgC18Wf kx4upvml/9twmd08BXpzkIeyD8Kdb6cn8F5NJysxlvR70al69Te6T/YCobB3MjEalEE0 8oP26ghIOyFyINboELcaH/SmLnKdTnkGAMHrmsWQY+INbtEU/wDVawShvF9/2VuEbqdv z4vkMtilaaAprgudDFEc0LAQI9BJ3JAcsLGpC/6iy5UxolTODb7ylO6ZJ3gTvqrTTXnt rgdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=UeYFsUJJmpRUKdSs0Tp5gwBJrNb4ZqLnzL0AtDJ8jmo=; b=e1MC23mkRkUgTP8lLBgK1acpkkFpwQBmiDncL5RV/wsl2ujep7PlheP+wGRRyrIKQ4 XGNoN87WE79LwBvWR5Z3gX5oW1/ZjzlW1MltUyBnBUL6qMa1Ib4SCjMHfys8pmuzh150 0mr5APjK+V3fB7FzV58JK/QwLvFXW1Ve/gOgVXr3iQRr201QYVgCY+aXfVfp+sUgJGuG beA3GO8Lu8WFDfJCB0JdCaye17t+QQ05S6Yos78rDkSrMUv1qQBRWkwcbdMdfGhGeu9R tYZfHy53ETAXjd94NJ21yDTwOTBCDExTj5MPCZz6n2dSP0ey2yjCrVnUwjW2XMCPAjkz 3oFA== X-Gm-Message-State: AOAM5304N0vhh7MadR+ZnpPTUSVj0XbKnmnr971gKwl5fQzOLhryeETV JxOx8J204VoD2CNtUikeK2v+3fgTwh/zFg== X-Google-Smtp-Source: ABdhPJwlmFJ8wL0ycVobv7bgFFql5UJrDCrJgLJtlU4yH7HFdCZvXGagCQzlQT37GJQtVnv22OR2sA== X-Received: by 2002:a5d:64c6:: with SMTP id f6mr54774765wri.18.1620939536817; Thu, 13 May 2021 13:58:56 -0700 (PDT) Received: from ?IPv6:2003:ea:8f38:4600:dc15:2d50:47c3:384f? (p200300ea8f384600dc152d5047c3384f.dip0.t-ipconnect.de. [2003:ea:8f38:4600:dc15:2d50:47c3:384f]) by smtp.googlemail.com with ESMTPSA id p12sm3179909wme.20.2021.05.13.13.58.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 May 2021 13:58:56 -0700 (PDT) Subject: [PATCH 2/5] PCI: Clean up VPD constants and functions in pci.h From: Heiner Kallweit To: Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: Message-ID: <97f81466-96a8-4895-aafe-c7317c852db7@gmail.com> Date: Thu, 13 May 2021 22:55:26 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Move some constants that are used by vpd.c only from include/linux/pci.h to drivers/pci/vpd.c. In addition remove some unused VPD inline functions. Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 7 +++++++ include/linux/pci.h | 43 ------------------------------------------- 2 files changed, 7 insertions(+), 43 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index ecdce170f..ff537371c 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -13,6 +13,13 @@ /* VPD access through PCI 2.2+ VPD capability */ +/* Small Resource Data Type */ +#define PCI_VPD_SRDT_TAG_SIZE 1 +#define PCI_VPD_SRDT_END (0x0f << 3) /* end tag */ + +/* Large Resource Data Type */ +#define PCI_VPD_LRDT_TIN_MASK 0x7f + struct pci_vpd_ops { ssize_t (*read)(struct pci_dev *dev, loff_t pos, size_t count, void *buf); ssize_t (*write)(struct pci_dev *dev, loff_t pos, size_t count, const void *buf); diff --git a/include/linux/pci.h b/include/linux/pci.h index c20211e59..c21558821 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2240,17 +2240,7 @@ int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask); #define PCI_VPD_LRDT_RO_DATA PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RO_DATA) #define PCI_VPD_LRDT_RW_DATA PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RW_DATA) -/* Small Resource Data Type Tag Item Names */ -#define PCI_VPD_STIN_END 0x0f /* End */ - -#define PCI_VPD_SRDT_END (PCI_VPD_STIN_END << 3) - -#define PCI_VPD_SRDT_TIN_MASK 0x78 -#define PCI_VPD_SRDT_LEN_MASK 0x07 -#define PCI_VPD_LRDT_TIN_MASK 0x7f - #define PCI_VPD_LRDT_TAG_SIZE 3 -#define PCI_VPD_SRDT_TAG_SIZE 1 #define PCI_VPD_INFO_FLD_HDR_SIZE 3 @@ -2271,39 +2261,6 @@ static inline u16 pci_vpd_lrdt_size(const u8 *lrdt) return (u16)lrdt[1] + ((u16)lrdt[2] << 8); } -/** - * pci_vpd_lrdt_tag - Extracts the Large Resource Data Type Tag Item - * @lrdt: Pointer to the beginning of the Large Resource Data Type tag - * - * Returns the extracted Large Resource Data Type Tag item. - */ -static inline u16 pci_vpd_lrdt_tag(const u8 *lrdt) -{ - return (u16)(lrdt[0] & PCI_VPD_LRDT_TIN_MASK); -} - -/** - * pci_vpd_srdt_size - Extracts the Small Resource Data Type length - * @srdt: Pointer to the beginning of the Small Resource Data Type tag - * - * Returns the extracted Small Resource Data Type length. - */ -static inline u8 pci_vpd_srdt_size(const u8 *srdt) -{ - return (*srdt) & PCI_VPD_SRDT_LEN_MASK; -} - -/** - * pci_vpd_srdt_tag - Extracts the Small Resource Data Type Tag Item - * @srdt: Pointer to the beginning of the Small Resource Data Type tag - * - * Returns the extracted Small Resource Data Type Tag Item. - */ -static inline u8 pci_vpd_srdt_tag(const u8 *srdt) -{ - return ((*srdt) & PCI_VPD_SRDT_TIN_MASK) >> 3; -} - /** * pci_vpd_info_field_size - Extracts the information field length * @info_field: Pointer to the beginning of an information field header From patchwork Thu May 13 20:56:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 1478200 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=F9xrnnCI; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Fh3tH1cwJz9sWM for ; Fri, 14 May 2021 06:59:03 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231235AbhEMVAM (ORCPT ); Thu, 13 May 2021 17:00:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233223AbhEMVAL (ORCPT ); Thu, 13 May 2021 17:00:11 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93B09C06174A for ; Thu, 13 May 2021 13:59:01 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id o6-20020a05600c4fc6b029015ec06d5269so496217wmq.0 for ; Thu, 13 May 2021 13:59:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Rhe9xzTsUM7XOWGRiaEe44S1N02oZhvUJrE4FQ7so2w=; b=F9xrnnCIdiqD3byyObLpI7r1GSZTS9jL9BQk9jHs6BzkYewxqsyNpkEqZnzklH53V4 luo003Esmict7q4YFgXqGZLy+SGYA6zqNiLnr0fYwxAicYhFVOkZXn53b1KZEifTFUME 5YgZh1o5uBW3CH8ndWCBBFsy7jym7fYkWzi7vMTMwxDt5RPGevrqQb6HgEiITotDYGvt iJuf+aLQ5EZqFgokXS//x6VBF9YyxWHMZeN4oyVsLFWHMWwt6ShuNfV/9fGBJ17NoYz3 mSdgBUocKJzLiIlUCGqOcQIxhZZbA68jgNjLKrXVGUNbPCNd7V4+ahHbuzmOxn5vuRd5 7EEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=Rhe9xzTsUM7XOWGRiaEe44S1N02oZhvUJrE4FQ7so2w=; b=CRcqA3iPc+z5MPk2/wAz/7LZkiqHhYtaywzWpvV6REj3dlsyWeTxO23LadjO/fwS51 B0ac4CniExA9KfRaYxd0aSSqx+J/gFORJkpbds9j8bbMKUlIa81BsyrPB6fgZtmjSVw+ hb95RQ3JGu2zYDM4+fn8olPdXd6xW7DlGiQSKwSwgfJCJ18eYThORyZeEAWy5LfphooR I/S6jnOhKB1SMepzywXVAnd0Tcj6nYPcQwqBuvF30L7RfMpXrOUQw+d98QlsYmiSkpKL AenYOoGraKVKuy9qI0fWnZeNmKzhbTttSLzitLGqvOFMtH8+cNtO6MiWyu6AnnMrAPNU jb0w== X-Gm-Message-State: AOAM531iMPB8Boq9syuS06i5bBR1d43T+DdzRnvQn/T1w8F7LESsHDvp tQtVhjEI9nDkVOQoXC3xVJivOVR7YjMqDA== X-Google-Smtp-Source: ABdhPJzhQnQyc1kJs9Ez314fzB6i2dL77qgPngWkUqyk4sPacW0kXD/Y8PR+XrM4y6lEbRCVqWkImg== X-Received: by 2002:a05:600c:19c8:: with SMTP id u8mr5864793wmq.50.1620939540072; Thu, 13 May 2021 13:59:00 -0700 (PDT) Received: from ?IPv6:2003:ea:8f38:4600:dc15:2d50:47c3:384f? (p200300ea8f384600dc152d5047c3384f.dip0.t-ipconnect.de. [2003:ea:8f38:4600:dc15:2d50:47c3:384f]) by smtp.googlemail.com with ESMTPSA id n5sm4080091wrx.31.2021.05.13.13.58.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 May 2021 13:58:59 -0700 (PDT) Subject: [PATCH 3/5] PCI/VPD: Remove old_size argument from pci_vpd_size From: Heiner Kallweit To: Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: Message-ID: Date: Thu, 13 May 2021 22:56:09 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org vpd->len is initialized to PCI_VPD_MAX_SIZE, and if a quirk is used to set a specific VPD size, then pci_vpd_set_size() sets vpd->valid, resulting in pci_vpd_size() not being called. Therefore we can remove the old_size argument. Note that we don't have to check off < PCI_VPD_MAX_SIZE because that's implicitly done by pci_read_vpd(). Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index ff537371c..e73a3a55f 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -75,14 +75,13 @@ EXPORT_SYMBOL(pci_write_vpd); /** * pci_vpd_size - determine actual size of Vital Product Data * @dev: pci device struct - * @old_size: current assumed size, also maximum allowed size */ -static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) +static size_t pci_vpd_size(struct pci_dev *dev) { size_t off = 0; u8 header[3]; /* 1 byte tag, 2 bytes length */ - while (off < old_size && pci_read_vpd(dev, off, 1, header) == 1) { + while (pci_read_vpd(dev, off, 1, header) == 1) { if (!header[0] && !off) { pci_info(dev, "Invalid VPD tag 00, assume missing optional VPD EPROM\n"); return 0; @@ -164,7 +163,7 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, if (!vpd->valid) { vpd->valid = 1; - vpd->len = pci_vpd_size(dev, vpd->len); + vpd->len = pci_vpd_size(dev); } if (vpd->len == 0) @@ -231,7 +230,7 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, if (!vpd->valid) { vpd->valid = 1; - vpd->len = pci_vpd_size(dev, vpd->len); + vpd->len = pci_vpd_size(dev); } if (vpd->len == 0) @@ -455,6 +454,7 @@ static void quirk_blacklist_vpd(struct pci_dev *dev) { if (dev->vpd) { dev->vpd->len = 0; + dev->vpd->valid = 1; pci_warn(dev, FW_BUG "disabling VPD access (can't determine size of non-standard VPD format)\n"); } } From patchwork Thu May 13 20:56:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 1478201 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=DkUtse0C; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Fh3tM0Yrtz9sWX for ; Fri, 14 May 2021 06:59:07 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233223AbhEMVAQ (ORCPT ); Thu, 13 May 2021 17:00:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233203AbhEMVAQ (ORCPT ); Thu, 13 May 2021 17:00:16 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA373C061574 for ; Thu, 13 May 2021 13:59:04 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 8so839498wmc.5 for ; Thu, 13 May 2021 13:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Ta99OcHaPrzvQEEzZKq7Wr4h68NLduJIqHZlGn9OJ9M=; b=DkUtse0CZY3ebLOAq+Bodgq1ZB8Uq4Jdu6f7xaPuVXMxbDaIikFdOZiDgVR3FJfTqI tApky8g+JqLteXQe9AJkucPB9W01c23jxU+GJQqoblPglO+syxufMjfHgFPI3VxV//CU bj6rxEfl3Pgy2TAM1F8h1/Pc1GjsfNxn8/lLCiTn1qXT5HQblIRycLzohYpde4EVxEDA Jf13MKfxPpYs6mJC4WBDzTT4wEWUHtrjbBoO2Dyr8s8frtm5L09wnzepvdNK9gutgBst YtHuogpDSgsQ/xg1RJsfEq+sK3JL+ok29XVuuyF/4AgIxtEAK13NMsC4Y8b8NAIKZdQ4 yyiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=Ta99OcHaPrzvQEEzZKq7Wr4h68NLduJIqHZlGn9OJ9M=; b=NG4p45sOssBvOOg95pUV6mQDA4eh4O8KcVtvmACzZc3BbA2uBI4Ckaa0GYhw4e7Eaw 3s6RWswm/nTavgnERobOjIBdAMLL3y0H+IlEFfVXKEYPFoAoNURn/Zru8K2H+BZyCi1a uArqzHM+k1Pnok2A3qG96YMi8FeKjZcRoW3L9QU484MJotY7RPdgWUYPDYHHBgnkhgb6 VzRJYEZtbxrOewbM5jIf0rKXGAPTKvxXrjGbVPKf4WAgMNUMpTsE6rObDybHHeR6b4/A x+/42GG/rsS4JDZSVITj0l0uFcjPZsZM6CQi8iAzT9wuEgSSD1V7d8Tp6n8v4cMVnqot MjBA== X-Gm-Message-State: AOAM5315wf3Csmy/941KpWwhpx1E5rO1RWCPNYSKq0B2ArNbWOVltDdJ fPcn8XEY35crz3PhskgdO2mhoNv1p12Qkg== X-Google-Smtp-Source: ABdhPJxHTVGu6j5jS0dFt9mG6pmeLn2H/XAibFnVegvd3t0NpV6tfu9elG6GuwHpmqwxzkhC/p33cA== X-Received: by 2002:a05:600c:4fd6:: with SMTP id o22mr23984811wmq.83.1620939543333; Thu, 13 May 2021 13:59:03 -0700 (PDT) Received: from ?IPv6:2003:ea:8f38:4600:dc15:2d50:47c3:384f? (p200300ea8f384600dc152d5047c3384f.dip0.t-ipconnect.de. [2003:ea:8f38:4600:dc15:2d50:47c3:384f]) by smtp.googlemail.com with ESMTPSA id k10sm10374422wmf.0.2021.05.13.13.59.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 May 2021 13:59:03 -0700 (PDT) Subject: [PATCH 4/5] PCI/VPD: Make pci_vpd_wait uninterruptible From: Heiner Kallweit To: Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: Message-ID: <258bf994-bc2a-2907-9181-2c7a562986d5@gmail.com> Date: Thu, 13 May 2021 22:56:41 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Reading/writing 4 bytes should be fast enough even on a slow bus, therefore pci_vpd_wait() doesn't have to be interruptible. Making it uninterruptible allows to simplify the code. In addition make VPD writes uninterruptible in general. It's about vital data, and allowing writes to be interruptible may leave the VPD in an inconsistent state. Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index e73a3a55f..76b20a13a 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -31,7 +31,6 @@ struct pci_vpd { unsigned int len; u16 flag; u8 cap; - unsigned int busy:1; unsigned int valid:1; }; @@ -121,22 +120,14 @@ static int pci_vpd_wait(struct pci_dev *dev) u16 status; int ret; - if (!vpd->busy) - return 0; - do { ret = pci_user_read_config_word(dev, vpd->cap + PCI_VPD_ADDR, &status); if (ret < 0) return ret; - if ((status & PCI_VPD_ADDR_F) == vpd->flag) { - vpd->busy = 0; + if ((status & PCI_VPD_ADDR_F) == vpd->flag) return 0; - } - - if (fatal_signal_pending(current)) - return -EINTR; if (time_after(jiffies, timeout)) break; @@ -154,7 +145,7 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, void *arg) { struct pci_vpd *vpd = dev->vpd; - int ret; + int ret = 0; loff_t end = pos + count; u8 *buf = arg; @@ -180,19 +171,19 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, if (mutex_lock_killable(&vpd->lock)) return -EINTR; - ret = pci_vpd_wait(dev); - if (ret < 0) - goto out; - while (pos < end) { u32 val; unsigned int i, skip; + if (fatal_signal_pending(current)) { + ret = -EINTR; + break; + } + ret = pci_user_write_config_word(dev, vpd->cap + PCI_VPD_ADDR, pos & ~3); if (ret < 0) break; - vpd->busy = 1; vpd->flag = PCI_VPD_ADDR_F; ret = pci_vpd_wait(dev); if (ret < 0) @@ -212,7 +203,7 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, val >>= 8; } } -out: + mutex_unlock(&vpd->lock); return ret ? ret : count; } @@ -242,10 +233,6 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, if (mutex_lock_killable(&vpd->lock)) return -EINTR; - ret = pci_vpd_wait(dev); - if (ret < 0) - goto out; - while (pos < end) { u32 val; @@ -262,7 +249,6 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, if (ret < 0) break; - vpd->busy = 1; vpd->flag = 0; ret = pci_vpd_wait(dev); if (ret < 0) @@ -270,7 +256,7 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, pos += sizeof(u32); } -out: + mutex_unlock(&vpd->lock); return ret ? ret : count; } @@ -333,7 +319,6 @@ void pci_vpd_init(struct pci_dev *dev) vpd->ops = &pci_vpd_ops; mutex_init(&vpd->lock); vpd->cap = cap; - vpd->busy = 0; vpd->valid = 0; dev->vpd = vpd; } From patchwork Thu May 13 21:02:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 1478203 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=sP4NkqxC; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Fh3xx4dhLz9sWM for ; Fri, 14 May 2021 07:02:13 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233242AbhEMVDW (ORCPT ); Thu, 13 May 2021 17:03:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233226AbhEMVDT (ORCPT ); Thu, 13 May 2021 17:03:19 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E2A6C061574 for ; Thu, 13 May 2021 14:02:08 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id u133so3789002wmg.1 for ; Thu, 13 May 2021 14:02:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=hv/3AuEAWRU5UmgUEGy6SQZx0UkkZoKNbV070ZhXdiE=; b=sP4NkqxCt9deFh+LhVoiBxNRf+2KnaQ4Hgs4OTBhsliSds1aPrD/bCQTJU/wvHMLNx T5zsjLuFX6YCTYK0GPdJYbqIKkU0FwxUMDQ6BZuC2pnb6BGltACN34qby4lUD2IDnHz9 B8VEI7dqUCkFWWGfBUvlPx7yLa1Hj4RmELizVoJiH/+r/6TORGce5n4pJm4ltTaEJeCp GxbKbWZzshyuskVFDP0iISeJKyWVvWU1Xzs97i8NPBdlGMHKUELsN1NyBn/hFlYgw+8l VWv3kwCkyQlibURfyh5lJVRnuUwIBakaTfi+Aw7rvcXgv4yPVxJE61t5NzQxdF6/oVRn /leQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=hv/3AuEAWRU5UmgUEGy6SQZx0UkkZoKNbV070ZhXdiE=; b=DPUgQtOHeyQS4K8YtiJZtc7p/x+s1B6Q/1cq8U/oz4tNQSXM0ZijpB0JJDi9IQ8ch7 UYDIlqEOPD+v/KYD8YiqB7Lx2GCE00GBBX26rPPO7pN4IPlVUWSCl7eVYLVNhB1Ifhip Pejt40ARHf/PlxoEYjKdQWFQOc69G0cyGb94PqYTBcmJNpX5okkVR1J6RF1BjOcIZfer mfcOYJuB4ynsHtN/4xMiQPzepeFCPf7mqSjtuM05mCI4KLZveyblJkkqm8XetXgE0MlG Mmjx0+SS0ug6yADl6aSmWkQReRlawxBtd5TUA+JxAiSdfQaYoVimBDlBBCEL9AYNeV+P PlLQ== X-Gm-Message-State: AOAM530iO4QQX7UJuX69SZHpAFjvhBN0eDZRH9vNMpNnMMNHwWcxYibE dey1m1jvaFBWtAGBfCXi/uMp52LRwOEUdA== X-Google-Smtp-Source: ABdhPJw21fXwf9j/Psmv32dz0Jn1oQs9FelhdmOPiAdOvJ7N/PVJ0GnWJPYmq2cSfbfFBkzS5UbVsg== X-Received: by 2002:a05:600c:154a:: with SMTP id f10mr46907949wmg.31.1620939726977; Thu, 13 May 2021 14:02:06 -0700 (PDT) Received: from ?IPv6:2003:ea:8f38:4600:dc15:2d50:47c3:384f? (p200300ea8f384600dc152d5047c3384f.dip0.t-ipconnect.de. [2003:ea:8f38:4600:dc15:2d50:47c3:384f]) by smtp.googlemail.com with ESMTPSA id h13sm3399077wml.26.2021.05.13.14.02.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 May 2021 14:02:06 -0700 (PDT) Subject: [PATCH 5/5] PCI/VPD: Remove pci_vpd member flag From: Heiner Kallweit To: Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: Message-ID: Date: Thu, 13 May 2021 23:02:01 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Remove the flag member and simplify the code. Signed-off-by: Heiner Kallweit --- drivers/pci/vpd.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 76b20a13a..df252f906 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -29,7 +29,6 @@ struct pci_vpd { const struct pci_vpd_ops *ops; struct mutex lock; unsigned int len; - u16 flag; u8 cap; unsigned int valid:1; }; @@ -109,10 +108,11 @@ static size_t pci_vpd_size(struct pci_dev *dev) * This code has to spin since there is no other notification from the PCI * hardware. Since the VPD is often implemented by serial attachment to an * EEPROM, it may take many milliseconds to complete. + * @set: if true wait for flag to be set, else wait for it to be cleared * * Returns 0 on success, negative values indicate error. */ -static int pci_vpd_wait(struct pci_dev *dev) +static int pci_vpd_wait(struct pci_dev *dev, bool set) { struct pci_vpd *vpd = dev->vpd; unsigned long timeout = jiffies + msecs_to_jiffies(125); @@ -126,7 +126,7 @@ static int pci_vpd_wait(struct pci_dev *dev) if (ret < 0) return ret; - if ((status & PCI_VPD_ADDR_F) == vpd->flag) + if (!!(status & PCI_VPD_ADDR_F) == set) return 0; if (time_after(jiffies, timeout)) @@ -184,8 +184,7 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, pos & ~3); if (ret < 0) break; - vpd->flag = PCI_VPD_ADDR_F; - ret = pci_vpd_wait(dev); + ret = pci_vpd_wait(dev, true); if (ret < 0) break; @@ -249,8 +248,7 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, if (ret < 0) break; - vpd->flag = 0; - ret = pci_vpd_wait(dev); + ret = pci_vpd_wait(dev, false); if (ret < 0) break;