1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Intel MIC Platform Software Stack (MPSS)
5 * Copyright(c) 2013 Intel Corporation.
7 * Intel MIC Host driver.
12 #include <linux/bitops.h>
13 #include <linux/interrupt.h>
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.
21 #define MIC_MIN_MSIX 9
22 #define MIC_NUM_OFFSETS 32
25 * mic_intr_source - The type of source that will generate
26 * the interrupt.The number of types needs to be in sync with
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.
42 * struct mic_intr_info - Contains h/w specific interrupt sources
45 * @intr_start_idx: Contains the starting indexes of the
47 * @intr_len: Contains the length of the interrupt types.
49 struct mic_intr_info
{
50 u16 intr_start_idx
[MIC_NUM_INTR_TYPES
];
51 u16 intr_len
[MIC_NUM_INTR_TYPES
];
55 * struct mic_irq_info - OS specific irq information
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.
71 struct msix_entry
*msix_entries
;
75 spinlock_t mic_intr_lock
;
76 spinlock_t mic_thread_lock
;
77 struct list_head
*cb_list
;
82 * struct mic_intr_cb - Interrupt callback structure.
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.
91 irq_handler_t handler
;
92 irq_handler_t thread_fn
;
95 struct list_head list
;
99 * struct mic_irq - opaque pointer used as cookie
103 /* Forward declaration */
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
113 * @read_msi_to_src_map: Read MSI mapping registers containing
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
,
126 int mic_next_db(struct mic_device
*mdev
);
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
);