mic_intr.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. */
  30. #define MIC_MIN_MSIX 4
  31. #define MIC_NUM_OFFSETS 32
  32. /**
  33. * mic_intr_source - The type of source that will generate
  34. * the interrupt.The number of types needs to be in sync with
  35. * MIC_NUM_INTR_TYPES
  36. *
  37. * MIC_INTR_DB: The source is a doorbell
  38. * MIC_INTR_DMA: The source is a DMA channel
  39. * MIC_INTR_ERR: The source is an error interrupt e.g. SBOX ERR
  40. * MIC_NUM_INTR_TYPES: Total number of interrupt sources.
  41. */
  42. enum mic_intr_type {
  43. MIC_INTR_DB = 0,
  44. MIC_INTR_DMA,
  45. MIC_INTR_ERR,
  46. MIC_NUM_INTR_TYPES
  47. };
  48. /**
  49. * struct mic_intr_info - Contains h/w specific interrupt sources
  50. * information.
  51. *
  52. * @intr_start_idx: Contains the starting indexes of the
  53. * interrupt types.
  54. * @intr_len: Contains the length of the interrupt types.
  55. */
  56. struct mic_intr_info {
  57. u16 intr_start_idx[MIC_NUM_INTR_TYPES];
  58. u16 intr_len[MIC_NUM_INTR_TYPES];
  59. };
  60. /**
  61. * struct mic_irq_info - OS specific irq information
  62. *
  63. * @next_avail_src: next available doorbell that can be assigned.
  64. * @msix_entries: msix entries allocated while setting up MSI-x
  65. * @mic_msi_map: The MSI/MSI-x mapping information.
  66. * @num_vectors: The number of MSI/MSI-x vectors that have been allocated.
  67. * @cb_ida: callback ID allocator to track the callbacks registered.
  68. * @mic_intr_lock: spinlock to protect the interrupt callback list.
  69. * @mic_thread_lock: spinlock to protect the thread callback list.
  70. * This lock is used to protect against thread_fn while
  71. * mic_intr_lock is used to protect against interrupt handler.
  72. * @cb_list: Array of callback lists one for each source.
  73. * @mask: Mask used by the main thread fn to call the underlying thread fns.
  74. */
  75. struct mic_irq_info {
  76. int next_avail_src;
  77. struct msix_entry *msix_entries;
  78. u32 *mic_msi_map;
  79. u16 num_vectors;
  80. struct ida cb_ida;
  81. spinlock_t mic_intr_lock;
  82. spinlock_t mic_thread_lock;
  83. struct list_head *cb_list;
  84. unsigned long mask;
  85. };
  86. /**
  87. * struct mic_intr_cb - Interrupt callback structure.
  88. *
  89. * @handler: The callback function
  90. * @thread_fn: The thread_fn.
  91. * @data: Private data of the requester.
  92. * @cb_id: The callback id. Identifies this callback.
  93. * @list: list head pointing to the next callback structure.
  94. */
  95. struct mic_intr_cb {
  96. irq_handler_t handler;
  97. irq_handler_t thread_fn;
  98. void *data;
  99. int cb_id;
  100. struct list_head list;
  101. };
  102. /**
  103. * struct mic_irq - opaque pointer used as cookie
  104. */
  105. struct mic_irq;
  106. /* Forward declaration */
  107. struct mic_device;
  108. /**
  109. * struct mic_hw_intr_ops: MIC HW specific interrupt operations
  110. * @intr_init: Initialize H/W specific interrupt information.
  111. * @enable_interrupts: Enable interrupts from the hardware.
  112. * @disable_interrupts: Disable interrupts from the hardware.
  113. * @program_msi_to_src_map: Update MSI mapping registers with
  114. * irq information.
  115. * @read_msi_to_src_map: Read MSI mapping registers containing
  116. * irq information.
  117. */
  118. struct mic_hw_intr_ops {
  119. void (*intr_init)(struct mic_device *mdev);
  120. void (*enable_interrupts)(struct mic_device *mdev);
  121. void (*disable_interrupts)(struct mic_device *mdev);
  122. void (*program_msi_to_src_map) (struct mic_device *mdev,
  123. int idx, int intr_src, bool set);
  124. u32 (*read_msi_to_src_map) (struct mic_device *mdev,
  125. int idx);
  126. };
  127. int mic_next_db(struct mic_device *mdev);
  128. struct mic_irq *
  129. mic_request_threaded_irq(struct mic_device *mdev,
  130. irq_handler_t handler, irq_handler_t thread_fn,
  131. const char *name, void *data, int intr_src,
  132. enum mic_intr_type type);
  133. void mic_free_irq(struct mic_device *mdev,
  134. struct mic_irq *cookie, void *data);
  135. int mic_setup_interrupts(struct mic_device *mdev, struct pci_dev *pdev);
  136. void mic_free_interrupts(struct mic_device *mdev, struct pci_dev *pdev);
  137. void mic_intr_restore(struct mic_device *mdev);
  138. #endif