mic_intr.h 4.5 KB

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