Skip to content

Commit f456834

Browse files
Ian Munsiempe
authored andcommitted
powerpc/powernv: Split cxl code out into a separate file
The support for using the Mellanox CX4 in cxl mode will require additions to the PHB code. In preparation for this, move the existing cxl code out of pci-ioda.c into a separate pci-cxl.c file to keep things more organised. Signed-off-by: Ian Munsie <imunsie@au1.ibm.com> Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> Reviewed-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent fc9f75e commit f456834

4 files changed

Lines changed: 173 additions & 156 deletions

File tree

‎arch/powerpc/platforms/powernv/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ obj-y += opal-kmsg.o
66

77
obj-$(CONFIG_SMP) += smp.o subcore.o subcore-asm.o
88
obj-$(CONFIG_PCI) += pci.o pci-ioda.o npu-dma.o
9+
obj-$(CONFIG_CXL_BASE) += pci-cxl.o
910
obj-$(CONFIG_EEH) += eeh-powernv.o
1011
obj-$(CONFIG_PPC_SCOM) += opal-xscom.o
1112
obj-$(CONFIG_MEMORY_FAILURE) += opal-memory-errors.o
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
* Copyright 2014-2016 IBM Corp.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version
7+
* 2 of the License, or (at your option) any later version.
8+
*/
9+
10+
#include <asm/pnv-pci.h>
11+
#include <asm/opal.h>
12+
13+
#include "pci.h"
14+
15+
struct device_node *pnv_pci_get_phb_node(struct pci_dev *dev)
16+
{
17+
struct pci_controller *hose = pci_bus_to_host(dev->bus);
18+
19+
return of_node_get(hose->dn);
20+
}
21+
EXPORT_SYMBOL(pnv_pci_get_phb_node);
22+
23+
int pnv_phb_to_cxl_mode(struct pci_dev *dev, uint64_t mode)
24+
{
25+
struct pci_controller *hose = pci_bus_to_host(dev->bus);
26+
struct pnv_phb *phb = hose->private_data;
27+
struct pnv_ioda_pe *pe;
28+
int rc;
29+
30+
pe = pnv_ioda_get_pe(dev);
31+
if (!pe)
32+
return -ENODEV;
33+
34+
pe_info(pe, "Switching PHB to CXL\n");
35+
36+
rc = opal_pci_set_phb_cxl_mode(phb->opal_id, mode, pe->pe_number);
37+
if (rc == OPAL_UNSUPPORTED)
38+
dev_err(&dev->dev, "Required cxl mode not supported by firmware - update skiboot\n");
39+
else if (rc)
40+
dev_err(&dev->dev, "opal_pci_set_phb_cxl_mode failed: %i\n", rc);
41+
42+
return rc;
43+
}
44+
EXPORT_SYMBOL(pnv_phb_to_cxl_mode);
45+
46+
/* Find PHB for cxl dev and allocate MSI hwirqs?
47+
* Returns the absolute hardware IRQ number
48+
*/
49+
int pnv_cxl_alloc_hwirqs(struct pci_dev *dev, int num)
50+
{
51+
struct pci_controller *hose = pci_bus_to_host(dev->bus);
52+
struct pnv_phb *phb = hose->private_data;
53+
int hwirq = msi_bitmap_alloc_hwirqs(&phb->msi_bmp, num);
54+
55+
if (hwirq < 0) {
56+
dev_warn(&dev->dev, "Failed to find a free MSI\n");
57+
return -ENOSPC;
58+
}
59+
60+
return phb->msi_base + hwirq;
61+
}
62+
EXPORT_SYMBOL(pnv_cxl_alloc_hwirqs);
63+
64+
void pnv_cxl_release_hwirqs(struct pci_dev *dev, int hwirq, int num)
65+
{
66+
struct pci_controller *hose = pci_bus_to_host(dev->bus);
67+
struct pnv_phb *phb = hose->private_data;
68+
69+
msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq - phb->msi_base, num);
70+
}
71+
EXPORT_SYMBOL(pnv_cxl_release_hwirqs);
72+
73+
void pnv_cxl_release_hwirq_ranges(struct cxl_irq_ranges *irqs,
74+
struct pci_dev *dev)
75+
{
76+
struct pci_controller *hose = pci_bus_to_host(dev->bus);
77+
struct pnv_phb *phb = hose->private_data;
78+
int i, hwirq;
79+
80+
for (i = 1; i < CXL_IRQ_RANGES; i++) {
81+
if (!irqs->range[i])
82+
continue;
83+
pr_devel("cxl release irq range 0x%x: offset: 0x%lx limit: %ld\n",
84+
i, irqs->offset[i],
85+
irqs->range[i]);
86+
hwirq = irqs->offset[i] - phb->msi_base;
87+
msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq,
88+
irqs->range[i]);
89+
}
90+
}
91+
EXPORT_SYMBOL(pnv_cxl_release_hwirq_ranges);
92+
93+
int pnv_cxl_alloc_hwirq_ranges(struct cxl_irq_ranges *irqs,
94+
struct pci_dev *dev, int num)
95+
{
96+
struct pci_controller *hose = pci_bus_to_host(dev->bus);
97+
struct pnv_phb *phb = hose->private_data;
98+
int i, hwirq, try;
99+
100+
memset(irqs, 0, sizeof(struct cxl_irq_ranges));
101+
102+
/* 0 is reserved for the multiplexed PSL DSI interrupt */
103+
for (i = 1; i < CXL_IRQ_RANGES && num; i++) {
104+
try = num;
105+
while (try) {
106+
hwirq = msi_bitmap_alloc_hwirqs(&phb->msi_bmp, try);
107+
if (hwirq >= 0)
108+
break;
109+
try /= 2;
110+
}
111+
if (!try)
112+
goto fail;
113+
114+
irqs->offset[i] = phb->msi_base + hwirq;
115+
irqs->range[i] = try;
116+
pr_devel("cxl alloc irq range 0x%x: offset: 0x%lx limit: %li\n",
117+
i, irqs->offset[i], irqs->range[i]);
118+
num -= try;
119+
}
120+
if (num)
121+
goto fail;
122+
123+
return 0;
124+
fail:
125+
pnv_cxl_release_hwirq_ranges(irqs, dev);
126+
return -ENOSPC;
127+
}
128+
EXPORT_SYMBOL(pnv_cxl_alloc_hwirq_ranges);
129+
130+
int pnv_cxl_get_irq_count(struct pci_dev *dev)
131+
{
132+
struct pci_controller *hose = pci_bus_to_host(dev->bus);
133+
struct pnv_phb *phb = hose->private_data;
134+
135+
return phb->msi_bmp.irq_count;
136+
}
137+
EXPORT_SYMBOL(pnv_cxl_get_irq_count);
138+
139+
int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq,
140+
unsigned int virq)
141+
{
142+
struct pci_controller *hose = pci_bus_to_host(dev->bus);
143+
struct pnv_phb *phb = hose->private_data;
144+
unsigned int xive_num = hwirq - phb->msi_base;
145+
struct pnv_ioda_pe *pe;
146+
int rc;
147+
148+
if (!(pe = pnv_ioda_get_pe(dev)))
149+
return -ENODEV;
150+
151+
/* Assign XIVE to PE */
152+
rc = opal_pci_set_xive_pe(phb->opal_id, pe->pe_number, xive_num);
153+
if (rc) {
154+
pe_warn(pe, "%s: OPAL error %d setting msi_base 0x%x "
155+
"hwirq 0x%x XIVE 0x%x PE\n",
156+
pci_name(dev), rc, phb->msi_base, hwirq, xive_num);
157+
return -EIO;
158+
}
159+
pnv_set_msi_irq_chip(phb, virq);
160+
161+
return 0;
162+
}
163+
EXPORT_SYMBOL(pnv_cxl_ioda_msi_setup);

‎arch/powerpc/platforms/powernv/pci-ioda.c‎

Lines changed: 3 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ static int pnv_ioda_get_pe_state(struct pnv_phb *phb, int pe_no)
595595
* but in the meantime, we need to protect them to avoid warnings
596596
*/
597597
#ifdef CONFIG_PCI_MSI
598-
static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev)
598+
struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev)
599599
{
600600
struct pci_controller *hose = pci_bus_to_host(dev->bus);
601601
struct pnv_phb *phb = hose->private_data;
@@ -2700,7 +2700,7 @@ static void pnv_ioda2_msi_eoi(struct irq_data *d)
27002700
}
27012701

27022702

2703-
static void set_msi_irq_chip(struct pnv_phb *phb, unsigned int virq)
2703+
void pnv_set_msi_irq_chip(struct pnv_phb *phb, unsigned int virq)
27042704
{
27052705
struct irq_data *idata;
27062706
struct irq_chip *ichip;
@@ -2722,159 +2722,6 @@ static void set_msi_irq_chip(struct pnv_phb *phb, unsigned int virq)
27222722
irq_set_chip(virq, &phb->ioda.irq_chip);
27232723
}
27242724

2725-
#ifdef CONFIG_CXL_BASE
2726-
2727-
struct device_node *pnv_pci_get_phb_node(struct pci_dev *dev)
2728-
{
2729-
struct pci_controller *hose = pci_bus_to_host(dev->bus);
2730-
2731-
return of_node_get(hose->dn);
2732-
}
2733-
EXPORT_SYMBOL(pnv_pci_get_phb_node);
2734-
2735-
int pnv_phb_to_cxl_mode(struct pci_dev *dev, uint64_t mode)
2736-
{
2737-
struct pci_controller *hose = pci_bus_to_host(dev->bus);
2738-
struct pnv_phb *phb = hose->private_data;
2739-
struct pnv_ioda_pe *pe;
2740-
int rc;
2741-
2742-
pe = pnv_ioda_get_pe(dev);
2743-
if (!pe)
2744-
return -ENODEV;
2745-
2746-
pe_info(pe, "Switching PHB to CXL\n");
2747-
2748-
rc = opal_pci_set_phb_cxl_mode(phb->opal_id, mode, pe->pe_number);
2749-
if (rc == OPAL_UNSUPPORTED)
2750-
dev_err(&dev->dev, "Required cxl mode not supported by firmware - update skiboot\n");
2751-
else if (rc)
2752-
dev_err(&dev->dev, "opal_pci_set_phb_cxl_mode failed: %i\n", rc);
2753-
2754-
return rc;
2755-
}
2756-
EXPORT_SYMBOL(pnv_phb_to_cxl_mode);
2757-
2758-
/* Find PHB for cxl dev and allocate MSI hwirqs?
2759-
* Returns the absolute hardware IRQ number
2760-
*/
2761-
int pnv_cxl_alloc_hwirqs(struct pci_dev *dev, int num)
2762-
{
2763-
struct pci_controller *hose = pci_bus_to_host(dev->bus);
2764-
struct pnv_phb *phb = hose->private_data;
2765-
int hwirq = msi_bitmap_alloc_hwirqs(&phb->msi_bmp, num);
2766-
2767-
if (hwirq < 0) {
2768-
dev_warn(&dev->dev, "Failed to find a free MSI\n");
2769-
return -ENOSPC;
2770-
}
2771-
2772-
return phb->msi_base + hwirq;
2773-
}
2774-
EXPORT_SYMBOL(pnv_cxl_alloc_hwirqs);
2775-
2776-
void pnv_cxl_release_hwirqs(struct pci_dev *dev, int hwirq, int num)
2777-
{
2778-
struct pci_controller *hose = pci_bus_to_host(dev->bus);
2779-
struct pnv_phb *phb = hose->private_data;
2780-
2781-
msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq - phb->msi_base, num);
2782-
}
2783-
EXPORT_SYMBOL(pnv_cxl_release_hwirqs);
2784-
2785-
void pnv_cxl_release_hwirq_ranges(struct cxl_irq_ranges *irqs,
2786-
struct pci_dev *dev)
2787-
{
2788-
struct pci_controller *hose = pci_bus_to_host(dev->bus);
2789-
struct pnv_phb *phb = hose->private_data;
2790-
int i, hwirq;
2791-
2792-
for (i = 1; i < CXL_IRQ_RANGES; i++) {
2793-
if (!irqs->range[i])
2794-
continue;
2795-
pr_devel("cxl release irq range 0x%x: offset: 0x%lx limit: %ld\n",
2796-
i, irqs->offset[i],
2797-
irqs->range[i]);
2798-
hwirq = irqs->offset[i] - phb->msi_base;
2799-
msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq,
2800-
irqs->range[i]);
2801-
}
2802-
}
2803-
EXPORT_SYMBOL(pnv_cxl_release_hwirq_ranges);
2804-
2805-
int pnv_cxl_alloc_hwirq_ranges(struct cxl_irq_ranges *irqs,
2806-
struct pci_dev *dev, int num)
2807-
{
2808-
struct pci_controller *hose = pci_bus_to_host(dev->bus);
2809-
struct pnv_phb *phb = hose->private_data;
2810-
int i, hwirq, try;
2811-
2812-
memset(irqs, 0, sizeof(struct cxl_irq_ranges));
2813-
2814-
/* 0 is reserved for the multiplexed PSL DSI interrupt */
2815-
for (i = 1; i < CXL_IRQ_RANGES && num; i++) {
2816-
try = num;
2817-
while (try) {
2818-
hwirq = msi_bitmap_alloc_hwirqs(&phb->msi_bmp, try);
2819-
if (hwirq >= 0)
2820-
break;
2821-
try /= 2;
2822-
}
2823-
if (!try)
2824-
goto fail;
2825-
2826-
irqs->offset[i] = phb->msi_base + hwirq;
2827-
irqs->range[i] = try;
2828-
pr_devel("cxl alloc irq range 0x%x: offset: 0x%lx limit: %li\n",
2829-
i, irqs->offset[i], irqs->range[i]);
2830-
num -= try;
2831-
}
2832-
if (num)
2833-
goto fail;
2834-
2835-
return 0;
2836-
fail:
2837-
pnv_cxl_release_hwirq_ranges(irqs, dev);
2838-
return -ENOSPC;
2839-
}
2840-
EXPORT_SYMBOL(pnv_cxl_alloc_hwirq_ranges);
2841-
2842-
int pnv_cxl_get_irq_count(struct pci_dev *dev)
2843-
{
2844-
struct pci_controller *hose = pci_bus_to_host(dev->bus);
2845-
struct pnv_phb *phb = hose->private_data;
2846-
2847-
return phb->msi_bmp.irq_count;
2848-
}
2849-
EXPORT_SYMBOL(pnv_cxl_get_irq_count);
2850-
2851-
int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq,
2852-
unsigned int virq)
2853-
{
2854-
struct pci_controller *hose = pci_bus_to_host(dev->bus);
2855-
struct pnv_phb *phb = hose->private_data;
2856-
unsigned int xive_num = hwirq - phb->msi_base;
2857-
struct pnv_ioda_pe *pe;
2858-
int rc;
2859-
2860-
if (!(pe = pnv_ioda_get_pe(dev)))
2861-
return -ENODEV;
2862-
2863-
/* Assign XIVE to PE */
2864-
rc = opal_pci_set_xive_pe(phb->opal_id, pe->pe_number, xive_num);
2865-
if (rc) {
2866-
pe_warn(pe, "%s: OPAL error %d setting msi_base 0x%x "
2867-
"hwirq 0x%x XIVE 0x%x PE\n",
2868-
pci_name(dev), rc, phb->msi_base, hwirq, xive_num);
2869-
return -EIO;
2870-
}
2871-
set_msi_irq_chip(phb, virq);
2872-
2873-
return 0;
2874-
}
2875-
EXPORT_SYMBOL(pnv_cxl_ioda_msi_setup);
2876-
#endif
2877-
28782725
static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev,
28792726
unsigned int hwirq, unsigned int virq,
28802727
unsigned int is_64, struct msi_msg *msg)
@@ -2931,7 +2778,7 @@ static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev,
29312778
}
29322779
msg->data = be32_to_cpu(data);
29332780

2934-
set_msi_irq_chip(phb, virq);
2781+
pnv_set_msi_irq_chip(phb, virq);
29352782

29362783
pr_devel("%s: %s-bit MSI on hwirq %x (xive #%d),"
29372784
" address=%x_%08x data=%x PE# %d\n",

‎arch/powerpc/platforms/powernv/pci.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#ifndef __POWERNV_PCI_H
22
#define __POWERNV_PCI_H
33

4+
#include <linux/iommu.h>
5+
#include <asm/iommu.h>
6+
#include <asm/msi_bitmap.h>
7+
48
struct pci_dn;
59

610
enum pnv_phb_type {
@@ -212,6 +216,8 @@ extern void pnv_pci_dma_dev_setup(struct pci_dev *pdev);
212216
extern void pnv_pci_dma_bus_setup(struct pci_bus *bus);
213217
extern int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type);
214218
extern void pnv_teardown_msi_irqs(struct pci_dev *pdev);
219+
extern struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev);
220+
extern void pnv_set_msi_irq_chip(struct pnv_phb *phb, unsigned int virq);
215221

216222
extern void pe_level_printk(const struct pnv_ioda_pe *pe, const char *level,
217223
const char *fmt, ...);

0 commit comments

Comments
 (0)