[PATCH] PCI: DMA bursting advice

After seeing, at best, "guesses" as to the following kind
of information in several drivers, I decided that we really
need a way for platforms to specifically give advice in this
area for what works best with their PCI controller implementation.

Basically, this new interface gives DMA bursting advice on
PCI. There are three forms of the advice:

1) Burst as much as possible, it is not necessary to end bursts
on some particular boundary for best performance.

2) Burst on some byte count multiple. A DMA burst to some multiple of
number of bytes may be done, but it is important to end the burst
on an exact multiple for best performance.

The best example of this I am aware of are the PPC64 PCI
controllers, where if you end a burst mid-cacheline then
chip has to refetch the data and the IOMMU translations
which hurts performance a lot.

3) Burst on a single byte count multiple. Bursts shall end
exactly on the next multiple boundary for best performance.

Sparc64 and Alpha's PCI controllers operate this way. They
disconnect any device which tries to burst across a cacheline
boundary.

Actually, newer sparc64 PCI controllers do not have this behavior.
That is why the "pdev" is passed into the interface, so I can
add code later to check which PCI controller the system is using
and give advice accordingly.

Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by David S. Miller and committed by Greg Kroah-Hartman e24c2d96 2311b1f2

+174
+17
include/asm-alpha/pci.h
··· 223 /* Nothing to do. */ 224 } 225 226 /* TODO: integrate with include/asm-generic/pci.h ? */ 227 static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel) 228 {
··· 223 /* Nothing to do. */ 224 } 225 226 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 227 + enum pci_dma_burst_strategy *strat, 228 + unsigned long *strategy_parameter) 229 + { 230 + unsigned long cacheline_size; 231 + u8 byte; 232 + 233 + pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte); 234 + if (byte == 0) 235 + cacheline_size = 1024; 236 + else 237 + cacheline_size = (int) byte * 4; 238 + 239 + *strat = PCI_DMA_BURST_BOUNDARY; 240 + *strategy_parameter = cacheline_size; 241 + } 242 + 243 /* TODO: integrate with include/asm-generic/pci.h ? */ 244 static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel) 245 {
+8
include/asm-arm/pci.h
··· 42 #define pci_unmap_len(PTR, LEN_NAME) ((PTR)->LEN_NAME) 43 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) (((PTR)->LEN_NAME) = (VAL)) 44 45 #define HAVE_PCI_MMAP 46 extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, 47 enum pci_mmap_state mmap_state, int write_combine);
··· 42 #define pci_unmap_len(PTR, LEN_NAME) ((PTR)->LEN_NAME) 43 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) (((PTR)->LEN_NAME) = (VAL)) 44 45 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 46 + enum pci_dma_burst_strategy *strat, 47 + unsigned long *strategy_parameter) 48 + { 49 + *strat = PCI_DMA_BURST_INFINITY; 50 + *strategy_parameter = ~0UL; 51 + } 52 + 53 #define HAVE_PCI_MMAP 54 extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, 55 enum pci_mmap_state mmap_state, int write_combine);
+8
include/asm-frv/pci.h
··· 57 */ 58 #define PCI_DMA_BUS_IS_PHYS (1) 59 60 /* 61 * These are pretty much arbitary with the CoMEM implementation. 62 * We have the whole address space to ourselves.
··· 57 */ 58 #define PCI_DMA_BUS_IS_PHYS (1) 59 60 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 61 + enum pci_dma_burst_strategy *strat, 62 + unsigned long *strategy_parameter) 63 + { 64 + *strat = PCI_DMA_BURST_INFINITY; 65 + *strategy_parameter = ~0UL; 66 + } 67 + 68 /* 69 * These are pretty much arbitary with the CoMEM implementation. 70 * We have the whole address space to ourselves.
+8
include/asm-i386/pci.h
··· 99 { 100 } 101 102 #endif /* __KERNEL__ */ 103 104 /* implement the pci_ DMA API in terms of the generic device dma_ one */
··· 99 { 100 } 101 102 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 103 + enum pci_dma_burst_strategy *strat, 104 + unsigned long *strategy_parameter) 105 + { 106 + *strat = PCI_DMA_BURST_INFINITY; 107 + *strategy_parameter = ~0UL; 108 + } 109 + 110 #endif /* __KERNEL__ */ 111 112 /* implement the pci_ DMA API in terms of the generic device dma_ one */
+17
include/asm-ia64/pci.h
··· 82 #define sg_dma_len(sg) ((sg)->dma_length) 83 #define sg_dma_address(sg) ((sg)->dma_address) 84 85 #define HAVE_PCI_MMAP 86 extern int pci_mmap_page_range (struct pci_dev *dev, struct vm_area_struct *vma, 87 enum pci_mmap_state mmap_state, int write_combine);
··· 82 #define sg_dma_len(sg) ((sg)->dma_length) 83 #define sg_dma_address(sg) ((sg)->dma_address) 84 85 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 86 + enum pci_dma_burst_strategy *strat, 87 + unsigned long *strategy_parameter) 88 + { 89 + unsigned long cacheline_size; 90 + u8 byte; 91 + 92 + pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte); 93 + if (byte == 0) 94 + cacheline_size = 1024; 95 + else 96 + cacheline_size = (int) byte * 4; 97 + 98 + *strat = PCI_DMA_BURST_MULTIPLE; 99 + *strategy_parameter = cacheline_size; 100 + } 101 + 102 #define HAVE_PCI_MMAP 103 extern int pci_mmap_page_range (struct pci_dev *dev, struct vm_area_struct *vma, 104 enum pci_mmap_state mmap_state, int write_combine);
+8
include/asm-mips/pci.h
··· 130 extern void pci_dac_dma_sync_single_for_device(struct pci_dev *pdev, 131 dma64_addr_t dma_addr, size_t len, int direction); 132 133 extern void pcibios_resource_to_bus(struct pci_dev *dev, 134 struct pci_bus_region *region, struct resource *res); 135
··· 130 extern void pci_dac_dma_sync_single_for_device(struct pci_dev *pdev, 131 dma64_addr_t dma_addr, size_t len, int direction); 132 133 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 134 + enum pci_dma_burst_strategy *strat, 135 + unsigned long *strategy_parameter) 136 + { 137 + *strat = PCI_DMA_BURST_INFINITY; 138 + *strategy_parameter = ~0UL; 139 + } 140 + 141 extern void pcibios_resource_to_bus(struct pci_dev *dev, 142 struct pci_bus_region *region, struct resource *res); 143
+17
include/asm-parisc/pci.h
··· 230 /* export the pci_ DMA API in terms of the dma_ one */ 231 #include <asm-generic/pci-dma-compat.h> 232 233 extern void 234 pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region, 235 struct resource *res);
··· 230 /* export the pci_ DMA API in terms of the dma_ one */ 231 #include <asm-generic/pci-dma-compat.h> 232 233 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 234 + enum pci_dma_burst_strategy *strat, 235 + unsigned long *strategy_parameter) 236 + { 237 + unsigned long cacheline_size; 238 + u8 byte; 239 + 240 + pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte); 241 + if (byte == 0) 242 + cacheline_size = 1024; 243 + else 244 + cacheline_size = (int) byte * 4; 245 + 246 + *strat = PCI_DMA_BURST_MULTIPLE; 247 + *strategy_parameter = cacheline_size; 248 + } 249 + 250 extern void 251 pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region, 252 struct resource *res);
+8
include/asm-ppc/pci.h
··· 69 #define pci_unmap_len(PTR, LEN_NAME) (0) 70 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0) 71 72 /* 73 * At present there are very few 32-bit PPC machines that can have 74 * memory above the 4GB point, and we don't support that.
··· 69 #define pci_unmap_len(PTR, LEN_NAME) (0) 70 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0) 71 72 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 73 + enum pci_dma_burst_strategy *strat, 74 + unsigned long *strategy_parameter) 75 + { 76 + *strat = PCI_DMA_BURST_INFINITY; 77 + *strategy_parameter = ~0UL; 78 + } 79 + 80 /* 81 * At present there are very few 32-bit PPC machines that can have 82 * memory above the 4GB point, and we don't support that.
+17
include/asm-ppc64/pci.h
··· 78 return 0; 79 } 80 81 extern int pci_domain_nr(struct pci_bus *bus); 82 83 /* Decide whether to display the domain number in /proc */
··· 78 return 0; 79 } 80 81 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 82 + enum pci_dma_burst_strategy *strat, 83 + unsigned long *strategy_parameter) 84 + { 85 + unsigned long cacheline_size; 86 + u8 byte; 87 + 88 + pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte); 89 + if (byte == 0) 90 + cacheline_size = 1024; 91 + else 92 + cacheline_size = (int) byte * 4; 93 + 94 + *strat = PCI_DMA_BURST_MULTIPLE; 95 + *strategy_parameter = cacheline_size; 96 + } 97 + 98 extern int pci_domain_nr(struct pci_bus *bus); 99 100 /* Decide whether to display the domain number in /proc */
+8
include/asm-sh/pci.h
··· 96 #define sg_dma_address(sg) (virt_to_bus((sg)->dma_address)) 97 #define sg_dma_len(sg) ((sg)->length) 98 99 /* Board-specific fixup routines. */ 100 extern void pcibios_fixup(void); 101 extern void pcibios_fixup_irqs(void);
··· 96 #define sg_dma_address(sg) (virt_to_bus((sg)->dma_address)) 97 #define sg_dma_len(sg) ((sg)->length) 98 99 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 100 + enum pci_dma_burst_strategy *strat, 101 + unsigned long *strategy_parameter) 102 + { 103 + *strat = PCI_DMA_BURST_INFINITY; 104 + *strategy_parameter = ~0UL; 105 + } 106 + 107 /* Board-specific fixup routines. */ 108 extern void pcibios_fixup(void); 109 extern void pcibios_fixup_irqs(void);
+8
include/asm-sh64/pci.h
··· 86 #define sg_dma_address(sg) ((sg)->dma_address) 87 #define sg_dma_len(sg) ((sg)->length) 88 89 /* Board-specific fixup routines. */ 90 extern void pcibios_fixup(void); 91 extern void pcibios_fixup_irqs(void);
··· 86 #define sg_dma_address(sg) ((sg)->dma_address) 87 #define sg_dma_len(sg) ((sg)->length) 88 89 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 90 + enum pci_dma_burst_strategy *strat, 91 + unsigned long *strategy_parameter) 92 + { 93 + *strat = PCI_DMA_BURST_INFINITY; 94 + *strategy_parameter = ~0UL; 95 + } 96 + 97 /* Board-specific fixup routines. */ 98 extern void pcibios_fixup(void); 99 extern void pcibios_fixup_irqs(void);
+8
include/asm-sparc/pci.h
··· 144 145 #define pci_dac_dma_supported(dev, mask) (0) 146 147 static inline void pcibios_add_platform_entries(struct pci_dev *dev) 148 { 149 }
··· 144 145 #define pci_dac_dma_supported(dev, mask) (0) 146 147 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 148 + enum pci_dma_burst_strategy *strat, 149 + unsigned long *strategy_parameter) 150 + { 151 + *strat = PCI_DMA_BURST_INFINITY; 152 + *strategy_parameter = ~0UL; 153 + } 154 + 155 static inline void pcibios_add_platform_entries(struct pci_dev *dev) 156 { 157 }
+17
include/asm-sparc64/pci.h
··· 220 return (dma_addr == PCI_DMA_ERROR_CODE); 221 } 222 223 /* Return the index of the PCI controller for device PDEV. */ 224 225 extern int pci_domain_nr(struct pci_bus *bus);
··· 220 return (dma_addr == PCI_DMA_ERROR_CODE); 221 } 222 223 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 224 + enum pci_dma_burst_strategy *strat, 225 + unsigned long *strategy_parameter) 226 + { 227 + unsigned long cacheline_size; 228 + u8 byte; 229 + 230 + pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte); 231 + if (byte == 0) 232 + cacheline_size = 1024; 233 + else 234 + cacheline_size = (int) byte * 4; 235 + 236 + *strat = PCI_DMA_BURST_BOUNDARY; 237 + *strategy_parameter = cacheline_size; 238 + } 239 + 240 /* Return the index of the PCI controller for device PDEV. */ 241 242 extern int pci_domain_nr(struct pci_bus *bus);
+8
include/asm-v850/pci.h
··· 81 pci_free_consistent (struct pci_dev *pdev, size_t size, void *cpu_addr, 82 dma_addr_t dma_addr); 83 84 static inline void pcibios_add_platform_entries(struct pci_dev *dev) 85 { 86 }
··· 81 pci_free_consistent (struct pci_dev *pdev, size_t size, void *cpu_addr, 82 dma_addr_t dma_addr); 83 84 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 85 + enum pci_dma_burst_strategy *strat, 86 + unsigned long *strategy_parameter) 87 + { 88 + *strat = PCI_DMA_BURST_INFINITY; 89 + *strategy_parameter = ~0UL; 90 + } 91 + 92 static inline void pcibios_add_platform_entries(struct pci_dev *dev) 93 { 94 }
+8
include/asm-x86_64/pci.h
··· 123 flush_write_buffers(); 124 } 125 126 #define HAVE_PCI_MMAP 127 extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, 128 enum pci_mmap_state mmap_state, int write_combine);
··· 123 flush_write_buffers(); 124 } 125 126 + static inline void pci_dma_burst_advice(struct pci_dev *pdev, 127 + enum pci_dma_burst_strategy *strat, 128 + unsigned long *strategy_parameter) 129 + { 130 + *strat = PCI_DMA_BURST_INFINITY; 131 + *strategy_parameter = ~0UL; 132 + } 133 + 134 #define HAVE_PCI_MMAP 135 extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, 136 enum pci_mmap_state mmap_state, int write_combine);
+9
include/linux/pci.h
··· 874 #define pci_pool_alloc(pool, flags, handle) dma_pool_alloc(pool, flags, handle) 875 #define pci_pool_free(pool, vaddr, addr) dma_pool_free(pool, vaddr, addr) 876 877 #if defined(CONFIG_ISA) || defined(CONFIG_EISA) 878 extern struct pci_dev *isa_bridge; 879 #endif
··· 874 #define pci_pool_alloc(pool, flags, handle) dma_pool_alloc(pool, flags, handle) 875 #define pci_pool_free(pool, vaddr, addr) dma_pool_free(pool, vaddr, addr) 876 877 + enum pci_dma_burst_strategy { 878 + PCI_DMA_BURST_INFINITY, /* make bursts as large as possible, 879 + strategy_parameter is N/A */ 880 + PCI_DMA_BURST_BOUNDARY, /* disconnect at every strategy_parameter 881 + byte boundaries */ 882 + PCI_DMA_BURST_MULTIPLE, /* disconnect at some multiple of 883 + strategy_parameter byte boundaries */ 884 + }; 885 + 886 #if defined(CONFIG_ISA) || defined(CONFIG_EISA) 887 extern struct pci_dev *isa_bridge; 888 #endif