1*e6550b3eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2a6a5580cSJeff Kirsher /*
3a6a5580cSJeff Kirsher  * Copyright 2008-2010 Cisco Systems, Inc.  All rights reserved.
4a6a5580cSJeff Kirsher  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
5a6a5580cSJeff Kirsher  */
6a6a5580cSJeff Kirsher 
7a6a5580cSJeff Kirsher #include <linux/kernel.h>
8a6a5580cSJeff Kirsher #include <linux/errno.h>
9a6a5580cSJeff Kirsher #include <linux/types.h>
10a6a5580cSJeff Kirsher #include <linux/pci.h>
11a6a5580cSJeff Kirsher #include <linux/delay.h>
12a6a5580cSJeff Kirsher 
13a6a5580cSJeff Kirsher #include "vnic_dev.h"
14a6a5580cSJeff Kirsher #include "vnic_intr.h"
156a3c2f83SGovindarajulu Varadarajan #include "enic.h"
16a6a5580cSJeff Kirsher 
vnic_intr_free(struct vnic_intr * intr)17a6a5580cSJeff Kirsher void vnic_intr_free(struct vnic_intr *intr)
18a6a5580cSJeff Kirsher {
19a6a5580cSJeff Kirsher 	intr->ctrl = NULL;
20a6a5580cSJeff Kirsher }
21a6a5580cSJeff Kirsher 
vnic_intr_alloc(struct vnic_dev * vdev,struct vnic_intr * intr,unsigned int index)22a6a5580cSJeff Kirsher int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
23a6a5580cSJeff Kirsher 	unsigned int index)
24a6a5580cSJeff Kirsher {
25a6a5580cSJeff Kirsher 	intr->index = index;
26a6a5580cSJeff Kirsher 	intr->vdev = vdev;
27a6a5580cSJeff Kirsher 
28a6a5580cSJeff Kirsher 	intr->ctrl = vnic_dev_get_res(vdev, RES_TYPE_INTR_CTRL, index);
29a6a5580cSJeff Kirsher 	if (!intr->ctrl) {
30e327f4e1SJoe Perches 		vdev_err(vdev, "Failed to hook INTR[%d].ctrl resource\n",
31e327f4e1SJoe Perches 			 index);
32a6a5580cSJeff Kirsher 		return -EINVAL;
33a6a5580cSJeff Kirsher 	}
34a6a5580cSJeff Kirsher 
35a6a5580cSJeff Kirsher 	return 0;
36a6a5580cSJeff Kirsher }
37a6a5580cSJeff Kirsher 
vnic_intr_init(struct vnic_intr * intr,u32 coalescing_timer,unsigned int coalescing_type,unsigned int mask_on_assertion)38a6a5580cSJeff Kirsher void vnic_intr_init(struct vnic_intr *intr, u32 coalescing_timer,
39a6a5580cSJeff Kirsher 	unsigned int coalescing_type, unsigned int mask_on_assertion)
40a6a5580cSJeff Kirsher {
41a6a5580cSJeff Kirsher 	vnic_intr_coalescing_timer_set(intr, coalescing_timer);
42a6a5580cSJeff Kirsher 	iowrite32(coalescing_type, &intr->ctrl->coalescing_type);
43a6a5580cSJeff Kirsher 	iowrite32(mask_on_assertion, &intr->ctrl->mask_on_assertion);
44a6a5580cSJeff Kirsher 	iowrite32(0, &intr->ctrl->int_credits);
45a6a5580cSJeff Kirsher }
46a6a5580cSJeff Kirsher 
vnic_intr_coalescing_timer_set(struct vnic_intr * intr,u32 coalescing_timer)47a6a5580cSJeff Kirsher void vnic_intr_coalescing_timer_set(struct vnic_intr *intr,
48a6a5580cSJeff Kirsher 	u32 coalescing_timer)
49a6a5580cSJeff Kirsher {
50a6a5580cSJeff Kirsher 	iowrite32(vnic_dev_intr_coal_timer_usec_to_hw(intr->vdev,
51a6a5580cSJeff Kirsher 		coalescing_timer), &intr->ctrl->coalescing_timer);
52a6a5580cSJeff Kirsher }
53a6a5580cSJeff Kirsher 
vnic_intr_clean(struct vnic_intr * intr)54a6a5580cSJeff Kirsher void vnic_intr_clean(struct vnic_intr *intr)
55a6a5580cSJeff Kirsher {
56a6a5580cSJeff Kirsher 	iowrite32(0, &intr->ctrl->int_credits);
57a6a5580cSJeff Kirsher }
58