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