Skip to content

Commit fe7e85c

Browse files
Gavin Shanmpe
authored andcommitted
powerpc/powernv: Override dma_get_required_mask()
The dma_get_required_mask() function is used by some drivers to query the platform about what DMA mask is needed to cover all of memory. This is a bit of a strange semantic when we have to choose between IOMMU translation or bypass, but essentially what it means is "what DMA mask will give best performances". Currently, our IOMMU backend always returns a 32-bit mask here, we don't do anything special to it when we have bypass available. This causes some drivers to choose a 32-bit mask, thus losing the ability to use the bypass window, thinking this is more efficient. The problem was reported from the driver of following device: 0004:03:00.0 0107: 1000:0087 (rev 05) 0004:03:00.0 Serial Attached SCSI controller: LSI Logic / Symbios \ Logic SAS2308 PCI-Express Fusion-MPT SAS-2 (rev 05) This patch adds an override of that function in order to, instead, return a 64-bit mask whenever a bypass window is available in order for drivers to prefer this configuration. Reported-by: Murali N. Iyer <mniyer@us.ibm.com> Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 372fb80 commit fe7e85c

7 files changed

Lines changed: 62 additions & 4 deletions

File tree

‎arch/powerpc/include/asm/dma-mapping.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ static inline int dma_supported(struct device *dev, u64 mask)
135135

136136
extern int dma_set_mask(struct device *dev, u64 dma_mask);
137137
extern int __dma_set_mask(struct device *dev, u64 dma_mask);
138+
extern u64 __dma_get_required_mask(struct device *dev);
138139

139140
#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
140141

‎arch/powerpc/kernel/dma.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ int __dma_set_mask(struct device *dev, u64 dma_mask)
202202
*dev->dma_mask = dma_mask;
203203
return 0;
204204
}
205+
205206
int dma_set_mask(struct device *dev, u64 dma_mask)
206207
{
207208
if (ppc_md.dma_set_mask)
@@ -210,13 +211,10 @@ int dma_set_mask(struct device *dev, u64 dma_mask)
210211
}
211212
EXPORT_SYMBOL(dma_set_mask);
212213

213-
u64 dma_get_required_mask(struct device *dev)
214+
u64 __dma_get_required_mask(struct device *dev)
214215
{
215216
struct dma_map_ops *dma_ops = get_dma_ops(dev);
216217

217-
if (ppc_md.dma_get_required_mask)
218-
return ppc_md.dma_get_required_mask(dev);
219-
220218
if (unlikely(dma_ops == NULL))
221219
return 0;
222220

@@ -225,6 +223,14 @@ u64 dma_get_required_mask(struct device *dev)
225223

226224
return DMA_BIT_MASK(8 * sizeof(dma_addr_t));
227225
}
226+
227+
u64 dma_get_required_mask(struct device *dev)
228+
{
229+
if (ppc_md.dma_get_required_mask)
230+
return ppc_md.dma_get_required_mask(dev);
231+
232+
return __dma_get_required_mask(dev);
233+
}
228234
EXPORT_SYMBOL_GPL(dma_get_required_mask);
229235

230236
static int __init dma_init(void)

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,28 @@ static int pnv_pci_ioda_dma_set_mask(struct pnv_phb *phb,
889889
return 0;
890890
}
891891

892+
static u64 pnv_pci_ioda_dma_get_required_mask(struct pnv_phb *phb,
893+
struct pci_dev *pdev)
894+
{
895+
struct pci_dn *pdn = pci_get_pdn(pdev);
896+
struct pnv_ioda_pe *pe;
897+
u64 end, mask;
898+
899+
if (WARN_ON(!pdn || pdn->pe_number == IODA_INVALID_PE))
900+
return 0;
901+
902+
pe = &phb->ioda.pe_array[pdn->pe_number];
903+
if (!pe->tce_bypass_enabled)
904+
return __dma_get_required_mask(&pdev->dev);
905+
906+
907+
end = pe->tce_bypass_base + memblock_end_of_DRAM();
908+
mask = 1ULL << (fls64(end) - 1);
909+
mask += mask - 1;
910+
911+
return mask;
912+
}
913+
892914
static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe,
893915
struct pci_bus *bus,
894916
bool add_to_iommu_group)
@@ -1781,6 +1803,7 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
17811803
/* Setup TCEs */
17821804
phb->dma_dev_setup = pnv_pci_ioda_dma_dev_setup;
17831805
phb->dma_set_mask = pnv_pci_ioda_dma_set_mask;
1806+
phb->dma_get_required_mask = pnv_pci_ioda_dma_get_required_mask;
17841807

17851808
/* Setup shutdown function for kexec */
17861809
phb->shutdown = pnv_pci_ioda_shutdown;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,17 @@ int pnv_pci_dma_set_mask(struct pci_dev *pdev, u64 dma_mask)
761761
return __dma_set_mask(&pdev->dev, dma_mask);
762762
}
763763

764+
u64 pnv_pci_dma_get_required_mask(struct pci_dev *pdev)
765+
{
766+
struct pci_controller *hose = pci_bus_to_host(pdev->bus);
767+
struct pnv_phb *phb = hose->private_data;
768+
769+
if (phb && phb->dma_get_required_mask)
770+
return phb->dma_get_required_mask(phb, pdev);
771+
772+
return __dma_get_required_mask(&pdev->dev);
773+
}
774+
764775
void pnv_pci_shutdown(void)
765776
{
766777
struct pci_controller *hose;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ struct pnv_phb {
124124
void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
125125
int (*dma_set_mask)(struct pnv_phb *phb, struct pci_dev *pdev,
126126
u64 dma_mask);
127+
u64 (*dma_get_required_mask)(struct pnv_phb *phb,
128+
struct pci_dev *pdev);
127129
void (*fixup_phb)(struct pci_controller *hose);
128130
u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn);
129131
void (*shutdown)(struct pnv_phb *phb);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct pci_dev;
1313
extern void pnv_pci_init(void);
1414
extern void pnv_pci_shutdown(void);
1515
extern int pnv_pci_dma_set_mask(struct pci_dev *pdev, u64 dma_mask);
16+
extern u64 pnv_pci_dma_get_required_mask(struct pci_dev *pdev);
1617
#else
1718
static inline void pnv_pci_init(void) { }
1819
static inline void pnv_pci_shutdown(void) { }
@@ -21,6 +22,11 @@ static inline int pnv_pci_dma_set_mask(struct pci_dev *pdev, u64 dma_mask)
2122
{
2223
return -ENODEV;
2324
}
25+
26+
static inline u64 pnv_pci_dma_get_required_mask(struct pci_dev *pdev)
27+
{
28+
return 0;
29+
}
2430
#endif
2531

2632
extern void pnv_lpc_init(void);

‎arch/powerpc/platforms/powernv/setup.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ static int pnv_dma_set_mask(struct device *dev, u64 dma_mask)
173173
return __dma_set_mask(dev, dma_mask);
174174
}
175175

176+
static u64 pnv_dma_get_required_mask(struct device *dev)
177+
{
178+
if (dev_is_pci(dev))
179+
return pnv_pci_dma_get_required_mask(to_pci_dev(dev));
180+
181+
return __dma_get_required_mask(dev);
182+
}
183+
176184
static void pnv_shutdown(void)
177185
{
178186
/* Let the PCI code clear up IODA tables */
@@ -335,6 +343,7 @@ define_machine(powernv) {
335343
.power_save = power7_idle,
336344
.calibrate_decr = generic_calibrate_decr,
337345
.dma_set_mask = pnv_dma_set_mask,
346+
.dma_get_required_mask = pnv_dma_get_required_mask,
338347
#ifdef CONFIG_KEXEC
339348
.kexec_cpu_down = pnv_kexec_cpu_down,
340349
#endif

0 commit comments

Comments
 (0)