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