pci.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_S390_PCI_H
  3. #define __ASM_S390_PCI_H
  4. /* must be set before including pci_clp.h */
  5. #define PCI_BAR_COUNT 6
  6. #include <linux/pci.h>
  7. #include <linux/mutex.h>
  8. #include <linux/iommu.h>
  9. #include <asm-generic/pci.h>
  10. #include <asm/pci_clp.h>
  11. #include <asm/pci_debug.h>
  12. #include <asm/sclp.h>
  13. #define PCIBIOS_MIN_IO 0x1000
  14. #define PCIBIOS_MIN_MEM 0x10000000
  15. #define pcibios_assign_all_busses() (0)
  16. void __iomem *pci_iomap(struct pci_dev *, int, unsigned long);
  17. void pci_iounmap(struct pci_dev *, void __iomem *);
  18. int pci_domain_nr(struct pci_bus *);
  19. int pci_proc_domain(struct pci_bus *);
  20. #define ZPCI_BUS_NR 0 /* default bus number */
  21. #define ZPCI_DEVFN 0 /* default device number */
  22. /* PCI Function Controls */
  23. #define ZPCI_FC_FN_ENABLED 0x80
  24. #define ZPCI_FC_ERROR 0x40
  25. #define ZPCI_FC_BLOCKED 0x20
  26. #define ZPCI_FC_DMA_ENABLED 0x10
  27. #define ZPCI_FMB_DMA_COUNTER_VALID (1 << 23)
  28. struct zpci_fmb_fmt0 {
  29. u64 dma_rbytes;
  30. u64 dma_wbytes;
  31. };
  32. struct zpci_fmb_fmt1 {
  33. u64 rx_bytes;
  34. u64 rx_packets;
  35. u64 tx_bytes;
  36. u64 tx_packets;
  37. };
  38. struct zpci_fmb_fmt2 {
  39. u64 consumed_work_units;
  40. u64 max_work_units;
  41. };
  42. struct zpci_fmb_fmt3 {
  43. u64 tx_bytes;
  44. };
  45. struct zpci_fmb {
  46. u32 format : 8;
  47. u32 fmt_ind : 24;
  48. u32 samples;
  49. u64 last_update;
  50. /* common counters */
  51. u64 ld_ops;
  52. u64 st_ops;
  53. u64 stb_ops;
  54. u64 rpcit_ops;
  55. /* format specific counters */
  56. union {
  57. struct zpci_fmb_fmt0 fmt0;
  58. struct zpci_fmb_fmt1 fmt1;
  59. struct zpci_fmb_fmt2 fmt2;
  60. struct zpci_fmb_fmt3 fmt3;
  61. };
  62. } __packed __aligned(128);
  63. enum zpci_state {
  64. ZPCI_FN_STATE_STANDBY = 0,
  65. ZPCI_FN_STATE_CONFIGURED = 1,
  66. ZPCI_FN_STATE_RESERVED = 2,
  67. ZPCI_FN_STATE_ONLINE = 3,
  68. };
  69. struct zpci_bar_struct {
  70. struct resource *res; /* bus resource */
  71. u32 val; /* bar start & 3 flag bits */
  72. u16 map_idx; /* index into bar mapping array */
  73. u8 size; /* order 2 exponent */
  74. };
  75. struct s390_domain;
  76. /* Private data per function */
  77. struct zpci_dev {
  78. struct pci_bus *bus;
  79. struct list_head entry; /* list of all zpci_devices, needed for hotplug, etc. */
  80. enum zpci_state state;
  81. u32 fid; /* function ID, used by sclp */
  82. u32 fh; /* function handle, used by insn's */
  83. u16 vfn; /* virtual function number */
  84. u16 pchid; /* physical channel ID */
  85. u8 pfgid; /* function group ID */
  86. u8 pft; /* pci function type */
  87. u16 domain;
  88. struct mutex lock;
  89. u8 pfip[CLP_PFIP_NR_SEGMENTS]; /* pci function internal path */
  90. u32 uid; /* user defined id */
  91. u8 util_str[CLP_UTIL_STR_LEN]; /* utility string */
  92. /* IRQ stuff */
  93. u64 msi_addr; /* MSI address */
  94. unsigned int max_msi; /* maximum number of MSI's */
  95. struct airq_iv *aibv; /* adapter interrupt bit vector */
  96. unsigned long aisb; /* number of the summary bit */
  97. /* DMA stuff */
  98. unsigned long *dma_table;
  99. spinlock_t dma_table_lock;
  100. int tlb_refresh;
  101. spinlock_t iommu_bitmap_lock;
  102. unsigned long *iommu_bitmap;
  103. unsigned long *lazy_bitmap;
  104. unsigned long iommu_size;
  105. unsigned long iommu_pages;
  106. unsigned int next_bit;
  107. struct iommu_device iommu_dev; /* IOMMU core handle */
  108. char res_name[16];
  109. struct zpci_bar_struct bars[PCI_BAR_COUNT];
  110. u64 start_dma; /* Start of available DMA addresses */
  111. u64 end_dma; /* End of available DMA addresses */
  112. u64 dma_mask; /* DMA address space mask */
  113. /* Function measurement block */
  114. struct zpci_fmb *fmb;
  115. u16 fmb_update; /* update interval */
  116. u16 fmb_length;
  117. /* software counters */
  118. atomic64_t allocated_pages;
  119. atomic64_t mapped_pages;
  120. atomic64_t unmapped_pages;
  121. enum pci_bus_speed max_bus_speed;
  122. struct dentry *debugfs_dev;
  123. struct dentry *debugfs_perf;
  124. struct s390_domain *s390_domain; /* s390 IOMMU domain data */
  125. };
  126. static inline bool zdev_enabled(struct zpci_dev *zdev)
  127. {
  128. return (zdev->fh & (1UL << 31)) ? true : false;
  129. }
  130. extern const struct attribute_group *zpci_attr_groups[];
  131. /* -----------------------------------------------------------------------------
  132. Prototypes
  133. ----------------------------------------------------------------------------- */
  134. /* Base stuff */
  135. int zpci_create_device(struct zpci_dev *);
  136. void zpci_remove_device(struct zpci_dev *zdev);
  137. int zpci_enable_device(struct zpci_dev *);
  138. int zpci_disable_device(struct zpci_dev *);
  139. int zpci_register_ioat(struct zpci_dev *, u8, u64, u64, u64);
  140. int zpci_unregister_ioat(struct zpci_dev *, u8);
  141. void zpci_remove_reserved_devices(void);
  142. /* CLP */
  143. int clp_scan_pci_devices(void);
  144. int clp_rescan_pci_devices(void);
  145. int clp_rescan_pci_devices_simple(void);
  146. int clp_add_pci_device(u32, u32, int);
  147. int clp_enable_fh(struct zpci_dev *, u8);
  148. int clp_disable_fh(struct zpci_dev *);
  149. int clp_get_state(u32 fid, enum zpci_state *state);
  150. /* IOMMU Interface */
  151. int zpci_init_iommu(struct zpci_dev *zdev);
  152. void zpci_destroy_iommu(struct zpci_dev *zdev);
  153. #ifdef CONFIG_PCI
  154. /* Error handling and recovery */
  155. void zpci_event_error(void *);
  156. void zpci_event_availability(void *);
  157. void zpci_rescan(void);
  158. bool zpci_is_enabled(void);
  159. #else /* CONFIG_PCI */
  160. static inline void zpci_event_error(void *e) {}
  161. static inline void zpci_event_availability(void *e) {}
  162. static inline void zpci_rescan(void) {}
  163. #endif /* CONFIG_PCI */
  164. #ifdef CONFIG_HOTPLUG_PCI_S390
  165. int zpci_init_slot(struct zpci_dev *);
  166. void zpci_exit_slot(struct zpci_dev *);
  167. #else /* CONFIG_HOTPLUG_PCI_S390 */
  168. static inline int zpci_init_slot(struct zpci_dev *zdev)
  169. {
  170. return 0;
  171. }
  172. static inline void zpci_exit_slot(struct zpci_dev *zdev) {}
  173. #endif /* CONFIG_HOTPLUG_PCI_S390 */
  174. /* Helpers */
  175. static inline struct zpci_dev *to_zpci(struct pci_dev *pdev)
  176. {
  177. return pdev->sysdata;
  178. }
  179. struct zpci_dev *get_zdev_by_fid(u32);
  180. /* DMA */
  181. int zpci_dma_init(void);
  182. void zpci_dma_exit(void);
  183. /* FMB */
  184. int zpci_fmb_enable_device(struct zpci_dev *);
  185. int zpci_fmb_disable_device(struct zpci_dev *);
  186. /* Debug */
  187. int zpci_debug_init(void);
  188. void zpci_debug_exit(void);
  189. void zpci_debug_init_device(struct zpci_dev *, const char *);
  190. void zpci_debug_exit_device(struct zpci_dev *);
  191. void zpci_debug_info(struct zpci_dev *, struct seq_file *);
  192. /* Error reporting */
  193. int zpci_report_error(struct pci_dev *, struct zpci_report_error_header *);
  194. #ifdef CONFIG_NUMA
  195. /* Returns the node based on PCI bus */
  196. static inline int __pcibus_to_node(const struct pci_bus *bus)
  197. {
  198. return NUMA_NO_NODE;
  199. }
  200. static inline const struct cpumask *
  201. cpumask_of_pcibus(const struct pci_bus *bus)
  202. {
  203. return cpu_online_mask;
  204. }
  205. #endif /* CONFIG_NUMA */
  206. #endif