mic_intr.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Intel MIC Platform Software Stack (MPSS)
  3. *
  4. * Copyright(c) 2013 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License, version 2, as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * The full GNU General Public License is included in this distribution in
  16. * the file called "COPYING".
  17. *
  18. * Intel MIC Host driver.
  19. *
  20. */
  21. #ifndef _MIC_INTR_H_
  22. #define _MIC_INTR_H_
  23. #include <linux/bitops.h>
  24. #include <linux/interrupt.h>
  25. /*
  26. * The minimum number of msix vectors required for normal operation.
  27. * 3 for virtio network, console and block devices.
  28. * 1 for card shutdown notifications.
  29. * 4 for host owned DMA channels.
  30. * 1 for SCIF
  31. */
  32. #define MIC_MIN_MSIX 9
  33. #define MIC_NUM_OFFSETS 32
  34. /**
  35. * mic_intr_source - The type of source that will generate
  36. * the interrupt.The number of types needs to be in sync with
  37. * MIC_NUM_INTR_TYPES
  38. *
  39. * MIC_INTR_DB: The source is a doorbell
  40. * MIC_INTR_DMA: The source is a DMA channel
  41. * MIC_INTR_ERR: The source is an error interrupt e.g. SBOX ERR
  42. * MIC_NUM_INTR_TYPES: Total number of interrupt sources.
  43. */
  44. enum mic_intr_type {
  45. MIC_INTR_DB = 0,
  46. MIC_INTR_DMA,
  47. MIC_INTR_ERR,
  48. MIC_NUM_INTR_TYPES
  49. };
  50. /**
  51. * struct mic_intr_info - Contains h/w specific interrupt sources
  52. * information.
  53. *
  54. * @intr_start_idx: Contains the starting indexes of the
  55. * interrupt types.
  56. * @intr_len: Contains the length of the interrupt types.
  57. */
  58. struct mic_intr_info {
  59. u16 intr_start_idx[MIC_NUM_INTR_TYPES];
  60. u16 intr_len[MIC_NUM_INTR_TYPES];
  61. };
  62. /**
  63. * struct mic_irq_info - OS specific irq information
  64. *
  65. * @next_avail_src: next available doorbell that can be assigned.
  66. * @msix_entries: msix entries allocated while setting up MSI-x
  67. * @mic_msi_map: The MSI/MSI-x mapping information.
  68. * @num_vectors: The number of MSI/MSI-x vectors that have been allocated.
  69. * @cb_ida: callback ID allocator to track the callbacks registered.
  70. * @mic_intr_lock: spinlock to protect the interrupt callback list.
  71. * @mic_thread_lock: spinlock to protect the thread callback list.
  72. * This lock is used to protect against thread_fn while
  73. * mic_intr_lock is used to protect against interrupt handler.
  74. * @cb_list: Array of callback lists one for each source.
  75. * @mask: Mask used by the main thread fn to call the underlying thread fns.
  76. */
  77. struct mic_irq_info {
  78. int next_avail_src;
  79. struct msix_entry *msix_entries;
  80. u32 *mic_msi_map;
  81. u16 num_vectors;
  82. struct ida cb_ida;
  83. spinlock_t mic_intr_lock;
  84. spinlock_t mic_thread_lock;
  85. struct list_head *cb_list;
  86. unsigned long mask;
  87. };
  88. /**
  89. * struct mic_intr_cb - Interrupt callback structure.
  90. *
  91. * @handler: The callback function
  92. * @thread_fn: The thread_fn.
  93. * @data: Private data of the requester.
  94. * @cb_id: The callback id. Identifies this callback.
  95. * @list: list head pointing to the next callback structure.
  96. */
  97. struct mic_intr_cb {
  98. irq_handler_t handler;
  99. irq_handler_t thread_fn;
  100. void *data;
  101. int cb_id;
  102. struct list_head list;
  103. };
  104. /**
  105. * struct mic_irq - opaque pointer used as cookie
  106. */
  107. struct mic_irq;
  108. /* Forward declaration */
  109. struct mic_device;
  110. /**
  111. * struct mic_hw_intr_ops: MIC HW specific interrupt operations
  112. * @intr_init: Initialize H/W specific interrupt information.
  113. * @enable_interrupts: Enable interrupts from the hardware.
  114. * @disable_interrupts: Disable interrupts from the hardware.
  115. * @program_msi_to_src_map: Update MSI mapping registers with
  116. * irq information.
  117. * @read_msi_to_src_map: Read MSI mapping registers containing
  118. * irq information.
  119. */
  120. struct mic_hw_intr_ops {
  121. void (*intr_init)(struct mic_device *mdev);
  122. void (*enable_interrupts)(struct mic_device *mdev);
  123. void (*disable_interrupts)(struct mic_device *mdev);
  124. void (*program_msi_to_src_map) (struct mic_device *mdev,
  125. int idx, int intr_src, bool set);
  126. u32 (*read_msi_to_src_map) (struct mic_device *mdev,
  127. int idx);
  128. };
  129. int mic_next_db(struct mic_device *mdev);
  130. struct mic_irq *
  131. mic_request_threaded_irq(struct mic_device *mdev,
  132. irq_handler_t handler, irq_handler_t thread_fn,
  133. const char *name, void *data, int intr_src,
  134. enum mic_intr_type type);
  135. void mic_free_irq(struct mic_device *mdev,
  136. struct mic_irq *cookie, void *data);
  137. int mic_setup_interrupts(struct mic_device *mdev, struct pci_dev *pdev);
  138. void mic_free_interrupts(struct mic_device *mdev, struct pci_dev *pdev);
  139. void mic_intr_restore(struct mic_device *mdev);
  140. #endif