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 #ifndef _VNIC_INTR_H_
8a6a5580cSJeff Kirsher #define _VNIC_INTR_H_
9a6a5580cSJeff Kirsher 
10a6a5580cSJeff Kirsher #include <linux/pci.h>
11a6a5580cSJeff Kirsher 
12a6a5580cSJeff Kirsher #include "vnic_dev.h"
13a6a5580cSJeff Kirsher 
14a6a5580cSJeff Kirsher #define VNIC_INTR_TIMER_TYPE_ABS	0
15a6a5580cSJeff Kirsher #define VNIC_INTR_TIMER_TYPE_QUIET	1
16a6a5580cSJeff Kirsher 
17a6a5580cSJeff Kirsher /* Interrupt control */
18a6a5580cSJeff Kirsher struct vnic_intr_ctrl {
19a6a5580cSJeff Kirsher 	u32 coalescing_timer;		/* 0x00 */
20a6a5580cSJeff Kirsher 	u32 pad0;
21a6a5580cSJeff Kirsher 	u32 coalescing_value;		/* 0x08 */
22a6a5580cSJeff Kirsher 	u32 pad1;
23a6a5580cSJeff Kirsher 	u32 coalescing_type;		/* 0x10 */
24a6a5580cSJeff Kirsher 	u32 pad2;
25a6a5580cSJeff Kirsher 	u32 mask_on_assertion;		/* 0x18 */
26a6a5580cSJeff Kirsher 	u32 pad3;
27a6a5580cSJeff Kirsher 	u32 mask;			/* 0x20 */
28a6a5580cSJeff Kirsher 	u32 pad4;
29a6a5580cSJeff Kirsher 	u32 int_credits;		/* 0x28 */
30a6a5580cSJeff Kirsher 	u32 pad5;
31a6a5580cSJeff Kirsher 	u32 int_credit_return;		/* 0x30 */
32a6a5580cSJeff Kirsher 	u32 pad6;
33a6a5580cSJeff Kirsher };
34a6a5580cSJeff Kirsher 
35a6a5580cSJeff Kirsher struct vnic_intr {
36a6a5580cSJeff Kirsher 	unsigned int index;
37a6a5580cSJeff Kirsher 	struct vnic_dev *vdev;
38a6a5580cSJeff Kirsher 	struct vnic_intr_ctrl __iomem *ctrl;		/* memory-mapped */
39a6a5580cSJeff Kirsher };
40a6a5580cSJeff Kirsher 
vnic_intr_unmask(struct vnic_intr * intr)41a6a5580cSJeff Kirsher static inline void vnic_intr_unmask(struct vnic_intr *intr)
42a6a5580cSJeff Kirsher {
43a6a5580cSJeff Kirsher 	iowrite32(0, &intr->ctrl->mask);
44a6a5580cSJeff Kirsher }
45a6a5580cSJeff Kirsher 
vnic_intr_mask(struct vnic_intr * intr)46a6a5580cSJeff Kirsher static inline void vnic_intr_mask(struct vnic_intr *intr)
47a6a5580cSJeff Kirsher {
48a6a5580cSJeff Kirsher 	iowrite32(1, &intr->ctrl->mask);
49a6a5580cSJeff Kirsher }
50a6a5580cSJeff Kirsher 
vnic_intr_masked(struct vnic_intr * intr)51a6a5580cSJeff Kirsher static inline int vnic_intr_masked(struct vnic_intr *intr)
52a6a5580cSJeff Kirsher {
53a6a5580cSJeff Kirsher 	return ioread32(&intr->ctrl->mask);
54a6a5580cSJeff Kirsher }
55a6a5580cSJeff Kirsher 
vnic_intr_return_credits(struct vnic_intr * intr,unsigned int credits,int unmask,int reset_timer)56a6a5580cSJeff Kirsher static inline void vnic_intr_return_credits(struct vnic_intr *intr,
57a6a5580cSJeff Kirsher 	unsigned int credits, int unmask, int reset_timer)
58a6a5580cSJeff Kirsher {
59a6a5580cSJeff Kirsher #define VNIC_INTR_UNMASK_SHIFT		16
60a6a5580cSJeff Kirsher #define VNIC_INTR_RESET_TIMER_SHIFT	17
61a6a5580cSJeff Kirsher 
62a6a5580cSJeff Kirsher 	u32 int_credit_return = (credits & 0xffff) |
63a6a5580cSJeff Kirsher 		(unmask ? (1 << VNIC_INTR_UNMASK_SHIFT) : 0) |
64a6a5580cSJeff Kirsher 		(reset_timer ? (1 << VNIC_INTR_RESET_TIMER_SHIFT) : 0);
65a6a5580cSJeff Kirsher 
66a6a5580cSJeff Kirsher 	iowrite32(int_credit_return, &intr->ctrl->int_credit_return);
67a6a5580cSJeff Kirsher }
68a6a5580cSJeff Kirsher 
vnic_intr_credits(struct vnic_intr * intr)69a6a5580cSJeff Kirsher static inline unsigned int vnic_intr_credits(struct vnic_intr *intr)
70a6a5580cSJeff Kirsher {
71a6a5580cSJeff Kirsher 	return ioread32(&intr->ctrl->int_credits);
72a6a5580cSJeff Kirsher }
73a6a5580cSJeff Kirsher 
vnic_intr_return_all_credits(struct vnic_intr * intr)74a6a5580cSJeff Kirsher static inline void vnic_intr_return_all_credits(struct vnic_intr *intr)
75a6a5580cSJeff Kirsher {
76a6a5580cSJeff Kirsher 	unsigned int credits = vnic_intr_credits(intr);
77a6a5580cSJeff Kirsher 	int unmask = 1;
78a6a5580cSJeff Kirsher 	int reset_timer = 1;
79a6a5580cSJeff Kirsher 
80a6a5580cSJeff Kirsher 	vnic_intr_return_credits(intr, credits, unmask, reset_timer);
81a6a5580cSJeff Kirsher }
82a6a5580cSJeff Kirsher 
vnic_intr_legacy_pba(u32 __iomem * legacy_pba)83a6a5580cSJeff Kirsher static inline u32 vnic_intr_legacy_pba(u32 __iomem *legacy_pba)
84a6a5580cSJeff Kirsher {
85a6a5580cSJeff Kirsher 	/* read PBA without clearing */
86a6a5580cSJeff Kirsher 	return ioread32(legacy_pba);
87a6a5580cSJeff Kirsher }
88a6a5580cSJeff Kirsher 
89a6a5580cSJeff Kirsher void vnic_intr_free(struct vnic_intr *intr);
90a6a5580cSJeff Kirsher int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
91a6a5580cSJeff Kirsher 	unsigned int index);
92a6a5580cSJeff Kirsher void vnic_intr_init(struct vnic_intr *intr, u32 coalescing_timer,
93a6a5580cSJeff Kirsher 	unsigned int coalescing_type, unsigned int mask_on_assertion);
94a6a5580cSJeff Kirsher void vnic_intr_coalescing_timer_set(struct vnic_intr *intr,
95a6a5580cSJeff Kirsher 	u32 coalescing_timer);
96a6a5580cSJeff Kirsher void vnic_intr_clean(struct vnic_intr *intr);
97a6a5580cSJeff Kirsher 
98a6a5580cSJeff Kirsher #endif /* _VNIC_INTR_H_ */
99