2 This file is provided under a dual BSD/GPLv2 license. When using or
3 redistributing this file, you may do so under either license.
6 Copyright(c) 2014 Intel Corporation.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of version 2 of the GNU General Public License as
9 published by the Free Software Foundation.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
20 Copyright(c) 2014 Intel Corporation.
21 Redistribution and use in source and binary forms, with or without
22 modification, are permitted provided that the following conditions
25 * Redistributions of source code must retain the above copyright
26 notice, this list of conditions and the following disclaimer.
27 * Redistributions in binary form must reproduce the above copyright
28 notice, this list of conditions and the following disclaimer in
29 the documentation and/or other materials provided with the
31 * Neither the name of Intel Corporation nor the names of its
32 contributors may be used to endorse or promote products derived
33 from this software without specific prior written permission.
35 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 #include <linux/kernel.h>
48 #include <linux/init.h>
49 #include <linux/types.h>
50 #include <linux/pci.h>
51 #include <linux/slab.h>
52 #include <linux/errno.h>
53 #include <linux/interrupt.h>
54 #include "adf_accel_devices.h"
55 #include "adf_common_drv.h"
57 #include "adf_cfg_strings.h"
58 #include "adf_cfg_common.h"
59 #include "adf_transport_access_macros.h"
60 #include "adf_transport_internal.h"
61 #include "adf_pf2vf_msg.h"
63 #define ADF_VINTSOU_OFFSET 0x204
64 #define ADF_VINTSOU_BUN BIT(0)
65 #define ADF_VINTSOU_PF2VF BIT(1)
67 static int adf_enable_msi(struct adf_accel_dev
*accel_dev
)
69 struct adf_accel_pci
*pci_dev_info
= &accel_dev
->accel_pci_dev
;
70 int stat
= pci_enable_msi(pci_dev_info
->pci_dev
);
73 dev_err(&GET_DEV(accel_dev
),
74 "Failed to enable MSI interrupts\n");
78 accel_dev
->vf
.irq_name
= kzalloc(ADF_MAX_MSIX_VECTOR_NAME
, GFP_KERNEL
);
79 if (!accel_dev
->vf
.irq_name
)
85 static void adf_disable_msi(struct adf_accel_dev
*accel_dev
)
87 struct pci_dev
*pdev
= accel_to_pci_dev(accel_dev
);
89 kfree(accel_dev
->vf
.irq_name
);
90 pci_disable_msi(pdev
);
93 static void adf_pf2vf_bh_handler(void *data
)
95 struct adf_accel_dev
*accel_dev
= data
;
96 struct adf_hw_device_data
*hw_data
= accel_dev
->hw_device
;
97 struct adf_bar
*pmisc
=
98 &GET_BARS(accel_dev
)[hw_data
->get_misc_bar_id(hw_data
)];
99 void __iomem
*pmisc_bar_addr
= pmisc
->virt_addr
;
102 /* Read the message from PF */
103 msg
= ADF_CSR_RD(pmisc_bar_addr
, hw_data
->get_pf2vf_offset(0));
105 if (!(msg
& ADF_PF2VF_MSGORIGIN_SYSTEM
))
106 /* Ignore legacy non-system (non-kernel) PF2VF messages */
109 switch ((msg
& ADF_PF2VF_MSGTYPE_MASK
) >> ADF_PF2VF_MSGTYPE_SHIFT
) {
110 case ADF_PF2VF_MSGTYPE_RESTARTING
:
111 dev_dbg(&GET_DEV(accel_dev
),
112 "Restarting msg received from PF 0x%x\n", msg
);
113 adf_dev_stop(accel_dev
);
115 case ADF_PF2VF_MSGTYPE_VERSION_RESP
:
116 dev_dbg(&GET_DEV(accel_dev
),
117 "Version resp received from PF 0x%x\n", msg
);
118 accel_dev
->vf
.pf_version
=
119 (msg
& ADF_PF2VF_VERSION_RESP_VERS_MASK
) >>
120 ADF_PF2VF_VERSION_RESP_VERS_SHIFT
;
121 accel_dev
->vf
.compatible
=
122 (msg
& ADF_PF2VF_VERSION_RESP_RESULT_MASK
) >>
123 ADF_PF2VF_VERSION_RESP_RESULT_SHIFT
;
124 complete(&accel_dev
->vf
.iov_msg_completion
);
130 /* To ack, clear the PF2VFINT bit */
132 ADF_CSR_WR(pmisc_bar_addr
, hw_data
->get_pf2vf_offset(0), msg
);
134 /* Re-enable PF2VF interrupts */
135 adf_enable_pf2vf_interrupts(accel_dev
);
138 dev_err(&GET_DEV(accel_dev
),
139 "Unknown message from PF (0x%x); leaving PF2VF ints disabled\n",
143 static int adf_setup_pf2vf_bh(struct adf_accel_dev
*accel_dev
)
145 tasklet_init(&accel_dev
->vf
.pf2vf_bh_tasklet
,
146 (void *)adf_pf2vf_bh_handler
, (unsigned long)accel_dev
);
148 mutex_init(&accel_dev
->vf
.vf2pf_lock
);
152 static void adf_cleanup_pf2vf_bh(struct adf_accel_dev
*accel_dev
)
154 tasklet_disable(&accel_dev
->vf
.pf2vf_bh_tasklet
);
155 tasklet_kill(&accel_dev
->vf
.pf2vf_bh_tasklet
);
156 mutex_destroy(&accel_dev
->vf
.vf2pf_lock
);
159 static irqreturn_t
adf_isr(int irq
, void *privdata
)
161 struct adf_accel_dev
*accel_dev
= privdata
;
162 struct adf_hw_device_data
*hw_data
= accel_dev
->hw_device
;
163 struct adf_bar
*pmisc
=
164 &GET_BARS(accel_dev
)[hw_data
->get_misc_bar_id(hw_data
)];
165 void __iomem
*pmisc_bar_addr
= pmisc
->virt_addr
;
168 /* Read VF INT source CSR to determine the source of VF interrupt */
169 v_int
= ADF_CSR_RD(pmisc_bar_addr
, ADF_VINTSOU_OFFSET
);
171 /* Check for PF2VF interrupt */
172 if (v_int
& ADF_VINTSOU_PF2VF
) {
173 /* Disable PF to VF interrupt */
174 adf_disable_pf2vf_interrupts(accel_dev
);
176 /* Schedule tasklet to handle interrupt BH */
177 tasklet_hi_schedule(&accel_dev
->vf
.pf2vf_bh_tasklet
);
181 /* Check bundle interrupt */
182 if (v_int
& ADF_VINTSOU_BUN
) {
183 struct adf_etr_data
*etr_data
= accel_dev
->transport
;
184 struct adf_etr_bank_data
*bank
= &etr_data
->banks
[0];
186 /* Disable Flag and Coalesce Ring Interrupts */
187 WRITE_CSR_INT_FLAG_AND_COL(bank
->csr_addr
, bank
->bank_number
,
189 tasklet_hi_schedule(&bank
->resp_handler
);
196 static int adf_request_msi_irq(struct adf_accel_dev
*accel_dev
)
198 struct pci_dev
*pdev
= accel_to_pci_dev(accel_dev
);
202 snprintf(accel_dev
->vf
.irq_name
, ADF_MAX_MSIX_VECTOR_NAME
,
203 "qat_%02x:%02d.%02d", pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
),
204 PCI_FUNC(pdev
->devfn
));
205 ret
= request_irq(pdev
->irq
, adf_isr
, 0, accel_dev
->vf
.irq_name
,
208 dev_err(&GET_DEV(accel_dev
), "failed to enable irq for %s\n",
209 accel_dev
->vf
.irq_name
);
212 cpu
= accel_dev
->accel_id
% num_online_cpus();
213 irq_set_affinity_hint(pdev
->irq
, get_cpu_mask(cpu
));
218 static int adf_setup_bh(struct adf_accel_dev
*accel_dev
)
220 struct adf_etr_data
*priv_data
= accel_dev
->transport
;
222 tasklet_init(&priv_data
->banks
[0].resp_handler
, adf_response_handler
,
223 (unsigned long)priv_data
->banks
);
227 static void adf_cleanup_bh(struct adf_accel_dev
*accel_dev
)
229 struct adf_etr_data
*priv_data
= accel_dev
->transport
;
231 tasklet_disable(&priv_data
->banks
[0].resp_handler
);
232 tasklet_kill(&priv_data
->banks
[0].resp_handler
);
236 * adf_vf_isr_resource_free() - Free IRQ for acceleration device
237 * @accel_dev: Pointer to acceleration device.
239 * Function frees interrupts for acceleration device virtual function.
241 void adf_vf_isr_resource_free(struct adf_accel_dev
*accel_dev
)
243 struct pci_dev
*pdev
= accel_to_pci_dev(accel_dev
);
245 irq_set_affinity_hint(pdev
->irq
, NULL
);
246 free_irq(pdev
->irq
, (void *)accel_dev
);
247 adf_cleanup_bh(accel_dev
);
248 adf_cleanup_pf2vf_bh(accel_dev
);
249 adf_disable_msi(accel_dev
);
251 EXPORT_SYMBOL_GPL(adf_vf_isr_resource_free
);
254 * adf_vf_isr_resource_alloc() - Allocate IRQ for acceleration device
255 * @accel_dev: Pointer to acceleration device.
257 * Function allocates interrupts for acceleration device virtual function.
259 * Return: 0 on success, error code otherwise.
261 int adf_vf_isr_resource_alloc(struct adf_accel_dev
*accel_dev
)
263 if (adf_enable_msi(accel_dev
))
266 if (adf_setup_pf2vf_bh(accel_dev
))
269 if (adf_setup_bh(accel_dev
))
272 if (adf_request_msi_irq(accel_dev
))
277 adf_vf_isr_resource_free(accel_dev
);
280 EXPORT_SYMBOL_GPL(adf_vf_isr_resource_alloc
);