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