Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3729337rdg; Wed, 18 Oct 2023 04:35:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPevuy9vCy0riEvn8dko06AKKtYtfdah6uPBO31sfVSD+dWiL8Hjv4Lxi4bB/Ds8USDVts X-Received: by 2002:a05:6a20:12d3:b0:17b:40:ccd6 with SMTP id v19-20020a056a2012d300b0017b0040ccd6mr3728920pzg.2.1697628918676; Wed, 18 Oct 2023 04:35:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697628918; cv=none; d=google.com; s=arc-20160816; b=gMxilkhC9WTsGSM/AsqmdZFcbybDZQyQXAepsE7CPMkteE+0OrNqfx9SBR4A8xjJWS pkB56QnvXb4Q1bORFHrNE+FroAC5H6tsvAMxRMl6p7okMxcsxIhcecrrnuxkKThhi/ze AGGr3SqHAi/PXdumyvwlK97FijQrUEcjpggL+XvgCVAI8cWDYZ1uEGE2ndcFzDymoQwW hOxtbuOgmMs0n/9Ywcj0xVpsMBjqQItRWD+nN865l0t2yd7aOCuXf4n1GaNC8cy1gp91 IZIehaIoJZxyL4qr4w9PhLk2SdKHde92nfNxeEN8euSEUenLdm0Y+str8hMzgLqEd+wE QmQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ENFZSFU4kGiFka8pQDw8Yer50AYytlPajpltxNAMRVg=; fh=bayJXXzCogY1NniUO68+IV8OTuFyZvNndGRqtMfemNk=; b=JE8ORvKQj2xmKSusu6Jjz/EkYOKzgter+43Sc90Q0PDjpTXeL6UB1/z8I7oHmIiCpX SRWCcxzDm0EcPzsvjPog/9bROZeChkjEBoN8r0+lL8rKwJzpjrKjj4502Ds7blBzCzZv CchHoBRu0XbcJldyz47mHbeV1H2skplMIpR7VMUMVNnI2BV8KKYC/BFuEQTEi/k0a7mx jtNPffU65T0ULyXAZmVTJuunoGxQjLWtm69oKzuSb9dbY3uGWqSDRjC2ln7B9lYCLLmp vaikpUEqq4L7GMahMZWcfurKMuvN54uX1Lh8EbVTE2YSZnrWcH0cR3EVBVB14g+UaOPQ jLfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aGbYegRU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id a11-20020a170902ee8b00b001c60c109ce7si3751294pld.295.2023.10.18.04.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 04:35:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aGbYegRU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7C6C680F5F12; Wed, 18 Oct 2023 04:35:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235105AbjJRLfI (ORCPT + 99 others); Wed, 18 Oct 2023 07:35:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234836AbjJRLfB (ORCPT ); Wed, 18 Oct 2023 07:35:01 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CAD612F; Wed, 18 Oct 2023 04:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697628895; x=1729164895; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NRJlQShSFWurHaKOv7QhLLMxfjt9JndN5eDKi4TZy98=; b=aGbYegRUtj56RBdWDPRzO9F0UnjGtoWATtUqMrSJdZjhGYMQ2A6ivG4d 6pVdPGZDrHNJw3PzKnMNjDxsDxINogltPm/9AIegeJsjnG2nhApe4a3FP Kbkd/js6XQVoJwiqrb+NGYeu3Se3MhMV73t52u4PH8gLgZPtY01u8TS6p oHSFuxXJwF7XFJwp7YkFMS3hFHW167AeXArQkgnWhIvOdznIfeBSo503b /8hS6qXYv4iFhgM0hZwCv1NFG45oiZFRX8q0WLUB1b45O8JQvpTnEZiST oSbpvY0P3CxKt/rzUfUHYaW4OLTHrpITf658DpasvOLG1+E/FcvfspS9d w==; X-IronPort-AV: E=McAfee;i="6600,9927,10866"; a="376365782" X-IronPort-AV: E=Sophos;i="6.03,234,1694761200"; d="scan'208";a="376365782" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2023 04:34:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10866"; a="733145191" X-IronPort-AV: E=Sophos;i="6.03,234,1694761200"; d="scan'208";a="733145191" Received: from suguccin-mobl1.amr.corp.intel.com (HELO localhost) ([10.252.44.63]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2023 04:34:47 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: Bjorn Helgaas , linux-pci@vger.kernel.org, Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Jonathan Cameron , linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH 7/7] PCI/MSI: Use FIELD_GET/PREP() Date: Wed, 18 Oct 2023 14:32:54 +0300 Message-Id: <20231018113254.17616-8-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231018113254.17616-1-ilpo.jarvinen@linux.intel.com> References: <20231018113254.17616-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 18 Oct 2023 04:35:16 -0700 (PDT) Instead of custom masking and shifting, use FIELD_GET/PREP() with register fields. Signed-off-by: Ilpo Järvinen --- drivers/pci/msi/msi.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c index ef1d8857a51b..682fa877478f 100644 --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -6,6 +6,7 @@ * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com) * Copyright (C) 2016 Christoph Hellwig. */ +#include #include #include #include @@ -188,7 +189,7 @@ static inline void pci_write_msg_msi(struct pci_dev *dev, struct msi_desc *desc, pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); msgctl &= ~PCI_MSI_FLAGS_QSIZE; - msgctl |= desc->pci.msi_attrib.multiple << 4; + msgctl |= FIELD_PREP(PCI_MSI_FLAGS_QSIZE, desc->pci.msi_attrib.multiple); pci_write_config_word(dev, pos + PCI_MSI_FLAGS, msgctl); pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, msg->address_lo); @@ -299,7 +300,7 @@ static int msi_setup_msi_desc(struct pci_dev *dev, int nvec, desc.pci.msi_attrib.is_64 = !!(control & PCI_MSI_FLAGS_64BIT); desc.pci.msi_attrib.can_mask = !!(control & PCI_MSI_FLAGS_MASKBIT); desc.pci.msi_attrib.default_irq = dev->irq; - desc.pci.msi_attrib.multi_cap = (control & PCI_MSI_FLAGS_QMASK) >> 1; + desc.pci.msi_attrib.multi_cap = FIELD_GET(PCI_MSI_FLAGS_QMASK, control); desc.pci.msi_attrib.multiple = ilog2(__roundup_pow_of_two(nvec)); desc.affinity = masks; @@ -478,7 +479,7 @@ int pci_msi_vec_count(struct pci_dev *dev) return -EINVAL; pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl); - ret = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1); + ret = 1 << FIELD_GET(PCI_MSI_FLAGS_QMASK, msgctl); return ret; } @@ -511,7 +512,8 @@ void __pci_restore_msi_state(struct pci_dev *dev) pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control); pci_msi_update_mask(entry, 0, 0); control &= ~PCI_MSI_FLAGS_QSIZE; - control |= (entry->pci.msi_attrib.multiple << 4) | PCI_MSI_FLAGS_ENABLE; + control |= PCI_MSI_FLAGS_ENABLE | + FIELD_PREP(PCI_MSI_FLAGS_QSIZE, entry->pci.msi_attrib.multiple); pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control); } -- 2.30.2