Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2222792rwb; Fri, 11 Nov 2022 06:42:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf7EQmhCGBJj7pF2mSEEFhHPKTzi7gIvqdWEhEhiNbMqNa3gRxwJxaF7tWMA+luAcg3YUjAU X-Received: by 2002:a17:906:34ca:b0:7ae:7eca:46ad with SMTP id h10-20020a17090634ca00b007ae7eca46admr2089803ejb.198.1668177761420; Fri, 11 Nov 2022 06:42:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668177761; cv=none; d=google.com; s=arc-20160816; b=WVrjYR3zh6DKMGQHkFkYFt856lzBCfZTm5bY9wXH7wbEiEYGaLvtGhl0WTz6os1NcL 5mzz9j5BhdsjsPPD/UJDJAwgjClRhaBdbsYwBjoO60ux3DZ6SjQ2Pmb/jboKmNYQ86c1 QqkCcFSnhHpkDdBHlYbTamWvQlXvfI0RiDqG9ozWTRZWKM6CRfS4sZdSoUFRPu65ajWN EmKKfVXZGW95GzdaL1FfIpg44qk9KRDiZ/1pN8bDfrXInwJZFyAg0uxYBvtGmCwFbTvI 9KLq5IJ9R3gIhb+II9HLCSj1RvzLGPLWnxWS8jEjwElnegxHDbCm4elj3mTR2HGYGAJu dL5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=IySA7q2kc9s+Hs2L8EoPsrfP4Hl32p6yL0Sk0XoI7lE=; b=zcZPERIHrjlMNlC4THEr3aImnXSR8GZIWakX3K9GhgsK+ooBL+OzDOEqV3Klnzu+8f aaAjNExwO3VP1hqyN6sWwV3tde3246vu4c1/ZOhyvaWghXva4IBJGrwTkqhfiE8SGkZ1 eMaQsTnoR45ttjvpbP0u+tKpnvNqnOhLs/PdunpEMjzHQQqz7aVihohXQcQu8KWC5Anj zReNo9ezhI3y/aQ9VZEVMjtw1DVX2SFIFx3NHHxfdWT08o3vNL26PGGD63lD4GpID2qk yLuZ9R8NcHR7YiBiYOxDscytm0OTlXfmywzstKlUuUUXeTQH+i+1bneYfVFAk98wvI2+ yEcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JhXIZ3xs; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e16-20020a50ec90000000b00461f10cb543si1834854edr.154.2022.11.11.06.42.19; Fri, 11 Nov 2022 06:42:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JhXIZ3xs; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234344AbiKKOH5 (ORCPT + 91 others); Fri, 11 Nov 2022 09:07:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234506AbiKKOHB (ORCPT ); Fri, 11 Nov 2022 09:07:01 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE2E48BA88; Fri, 11 Nov 2022 05:59:50 -0800 (PST) Message-ID: <20221111135205.836259395@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668175107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=IySA7q2kc9s+Hs2L8EoPsrfP4Hl32p6yL0Sk0XoI7lE=; b=JhXIZ3xsgiGBibsCVxO6poVIfqA3RfwjsYLK6ETSgHmOBOnf5lZkYicqflqh4WKiAHTvbE tb77jodb251i75+vdbnBVrFd1xap2qLNb8EnYl09l/gQr1BKA8LyQOxGDUDJ0SAeQ5xbfL nb3HjnkMhdlldRQrseLQwCxqopB96aa+3px1xjzEYCzOR/8aqKLoiRl2bNTlEeZOYVy9MF YQwtbyIgmY7bRlOqKni3FAFVxyW6Xo9XbFvsnQA89gJsVec57EkqJunAok4tXo3JsY9rsp sKoFm95RLojk+LWAC16cKgADNk0kDD9DfPqAPtx86VcTSa0IOjA3vuSDKwWTXQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668175107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=IySA7q2kc9s+Hs2L8EoPsrfP4Hl32p6yL0Sk0XoI7lE=; b=xlQZ+n5DInBwbdrr1qkyYkeaiT8YEj8UaNfj+sy/2EmMN33nWc8Ei0pO6FAJYG1FlmPaYo DkCche6zOoSLFwAA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe , "Ahmed S. Darwish" , Reinette Chatre Subject: [patch 10/33] PCI/MSI: Split __pci_write_msi_msg() References: <20221111133158.196269823@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Fri, 11 Nov 2022 14:58:27 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The upcoming per device MSI domains will create different domains for MSI and MSI-X. Split the write message function into MSI and MSI-X helpers so they can be used by those new domain functions seperately. Signed-off-by: Ahmed S. Darwish Signed-off-by: Thomas Gleixner --- drivers/pci/msi/msi.c | 104 +++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 50 deletions(-) --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -180,6 +180,58 @@ void __pci_read_msi_msg(struct msi_desc } } +static inline void pci_write_msg_msi(struct pci_dev *dev, struct msi_desc *desc, + struct msi_msg *msg) +{ + int pos = dev->msi_cap; + u16 msgctl; + + pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); + msgctl &= ~PCI_MSI_FLAGS_QSIZE; + msgctl |= desc->pci.msi_attrib.multiple << 4; + pci_write_config_word(dev, pos + PCI_MSI_FLAGS, msgctl); + + pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, msg->address_lo); + if (desc->pci.msi_attrib.is_64) { + pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, msg->address_hi); + pci_write_config_word(dev, pos + PCI_MSI_DATA_64, msg->data); + } else { + pci_write_config_word(dev, pos + PCI_MSI_DATA_32, msg->data); + } + /* Ensure that the writes are visible in the device */ + pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); +} + +static inline void pci_write_msg_msix(struct msi_desc *desc, struct msi_msg *msg) +{ + void __iomem *base = pci_msix_desc_addr(desc); + u32 ctrl = desc->pci.msix_ctrl; + bool unmasked = !(ctrl & PCI_MSIX_ENTRY_CTRL_MASKBIT); + + if (desc->pci.msi_attrib.is_virtual) + return; + /* + * The specification mandates that the entry is masked + * when the message is modified: + * + * "If software changes the Address or Data value of an + * entry while the entry is unmasked, the result is + * undefined." + */ + if (unmasked) + pci_msix_write_vector_ctrl(desc, ctrl | PCI_MSIX_ENTRY_CTRL_MASKBIT); + + writel(msg->address_lo, base + PCI_MSIX_ENTRY_LOWER_ADDR); + writel(msg->address_hi, base + PCI_MSIX_ENTRY_UPPER_ADDR); + writel(msg->data, base + PCI_MSIX_ENTRY_DATA); + + if (unmasked) + pci_msix_write_vector_ctrl(desc, ctrl); + + /* Ensure that the writes are visible in the device */ + readl(base + PCI_MSIX_ENTRY_DATA); +} + void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg) { struct pci_dev *dev = msi_desc_to_pci_dev(entry); @@ -187,63 +239,15 @@ void __pci_write_msi_msg(struct msi_desc if (dev->current_state != PCI_D0 || pci_dev_is_disconnected(dev)) { /* Don't touch the hardware now */ } else if (entry->pci.msi_attrib.is_msix) { - void __iomem *base = pci_msix_desc_addr(entry); - u32 ctrl = entry->pci.msix_ctrl; - bool unmasked = !(ctrl & PCI_MSIX_ENTRY_CTRL_MASKBIT); - - if (entry->pci.msi_attrib.is_virtual) - goto skip; - - /* - * The specification mandates that the entry is masked - * when the message is modified: - * - * "If software changes the Address or Data value of an - * entry while the entry is unmasked, the result is - * undefined." - */ - if (unmasked) - pci_msix_write_vector_ctrl(entry, ctrl | PCI_MSIX_ENTRY_CTRL_MASKBIT); - - writel(msg->address_lo, base + PCI_MSIX_ENTRY_LOWER_ADDR); - writel(msg->address_hi, base + PCI_MSIX_ENTRY_UPPER_ADDR); - writel(msg->data, base + PCI_MSIX_ENTRY_DATA); - - if (unmasked) - pci_msix_write_vector_ctrl(entry, ctrl); - - /* Ensure that the writes are visible in the device */ - readl(base + PCI_MSIX_ENTRY_DATA); + pci_write_msg_msix(entry, msg); } else { - int pos = dev->msi_cap; - u16 msgctl; - - pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); - msgctl &= ~PCI_MSI_FLAGS_QSIZE; - msgctl |= entry->pci.msi_attrib.multiple << 4; - pci_write_config_word(dev, pos + PCI_MSI_FLAGS, msgctl); - - pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, - msg->address_lo); - if (entry->pci.msi_attrib.is_64) { - pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, - msg->address_hi); - pci_write_config_word(dev, pos + PCI_MSI_DATA_64, - msg->data); - } else { - pci_write_config_word(dev, pos + PCI_MSI_DATA_32, - msg->data); - } - /* Ensure that the writes are visible in the device */ - pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); + pci_write_msg_msi(dev, entry, msg); } -skip: entry->msg = *msg; if (entry->write_msi_msg) entry->write_msi_msg(entry, entry->write_msi_msg_data); - } void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg)