xref: /openbmc/linux/drivers/scsi/snic/vnic_intr.c (revision 7cc39531)
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright 2014 Cisco Systems, Inc.  All rights reserved.
3 
4 #include <linux/kernel.h>
5 #include <linux/errno.h>
6 #include <linux/types.h>
7 #include <linux/pci.h>
8 #include <linux/delay.h>
9 #include "vnic_dev.h"
10 #include "vnic_intr.h"
11 
12 void svnic_intr_free(struct vnic_intr *intr)
13 {
14 	intr->ctrl = NULL;
15 }
16 
17 int svnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
18 	unsigned int index)
19 {
20 	intr->index = index;
21 	intr->vdev = vdev;
22 
23 	intr->ctrl = svnic_dev_get_res(vdev, RES_TYPE_INTR_CTRL, index);
24 	if (!intr->ctrl) {
25 		pr_err("Failed to hook INTR[%d].ctrl resource\n",
26 			index);
27 		return -EINVAL;
28 	}
29 
30 	return 0;
31 }
32 
33 void svnic_intr_init(struct vnic_intr *intr, unsigned int coalescing_timer,
34 	unsigned int coalescing_type, unsigned int mask_on_assertion)
35 {
36 	iowrite32(coalescing_timer, &intr->ctrl->coalescing_timer);
37 	iowrite32(coalescing_type, &intr->ctrl->coalescing_type);
38 	iowrite32(mask_on_assertion, &intr->ctrl->mask_on_assertion);
39 	iowrite32(0, &intr->ctrl->int_credits);
40 }
41 
42 void svnic_intr_clean(struct vnic_intr *intr)
43 {
44 	iowrite32(0, &intr->ctrl->int_credits);
45 }
46