xref: /freebsd/sys/dev/enic/vnic_intr.h (revision d9a42747950146bf03cda7f6e25d219253f8a57a)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  */
5 
6 #ifndef _VNIC_INTR_H_
7 #define _VNIC_INTR_H_
8 
9 
10 #include "vnic_dev.h"
11 
12 #define VNIC_INTR_TIMER_TYPE_ABS	0
13 #define VNIC_INTR_TIMER_TYPE_QUIET	1
14 
15 /* Interrupt control */
16 struct vnic_intr_ctrl {
17 	u32 coalescing_timer;		/* 0x00 */
18 #define INTR_COALESCING_TIMER		   0x00
19 	u32 pad0;
20 	u32 coalescing_value;		/* 0x08 */
21 #define INTR_COALESCING_VALUE		   0x08
22 	u32 pad1;
23 	u32 coalescing_type;		/* 0x10 */
24 #define INTR_COALESCING_TYPE		   0x10
25 	u32 pad2;
26 	u32 mask_on_assertion;		/* 0x18 */
27 #define INTR_MASK_ON_ASSERTION		   0x18
28 	u32 pad3;
29 	u32 mask;			/* 0x20 */
30 #define INTR_MASK			   0x20
31 	u32 pad4;
32 	u32 int_credits;		/* 0x28 */
33 #define INTR_CREDITS			   0x28
34 	u32 pad5;
35 	u32 int_credit_return;		/* 0x30 */
36 #define INTR_CREDIT_RETURN		   0x30
37 	u32 pad6;
38 };
39 
40 struct vnic_intr {
41 	unsigned int index;
42 	struct vnic_dev *vdev;
43 	struct vnic_res *ctrl;
44 };
45 
46 static inline void vnic_intr_mask(struct vnic_intr *intr)
47 {
48 	ENIC_BUS_WRITE_4(intr->ctrl, INTR_MASK, 1);
49 }
50 
51 static inline int vnic_intr_masked(struct vnic_intr *intr)
52 {
53 	int ret;
54 
55 	ret = ENIC_BUS_READ_4(intr->ctrl, INTR_MASK);
56 	return ret;
57 }
58 
59 static inline void vnic_intr_unmask(struct vnic_intr *intr)
60 {
61 	ENIC_BUS_WRITE_4(intr->ctrl, INTR_MASK, 0);
62 }
63 
64 static inline void vnic_intr_return_credits(struct vnic_intr *intr,
65 	unsigned int credits, int unmask, int reset_timer)
66 {
67 #define VNIC_INTR_UNMASK_SHIFT		16
68 #define VNIC_INTR_RESET_TIMER_SHIFT	17
69 
70 	u32 int_credit_return = (credits & 0xffff) |
71 		(unmask ? (1 << VNIC_INTR_UNMASK_SHIFT) : 0) |
72 		(reset_timer ? (1 << VNIC_INTR_RESET_TIMER_SHIFT) : 0);
73 
74 	ENIC_BUS_WRITE_4(intr->ctrl, INTR_CREDIT_RETURN, int_credit_return);
75 }
76 
77 static inline unsigned int vnic_intr_credits(struct vnic_intr *intr)
78 {
79 	return ENIC_BUS_READ_4(intr->ctrl, INTR_CREDITS);
80 }
81 
82 static inline void vnic_intr_return_all_credits(struct vnic_intr *intr)
83 {
84 	unsigned int credits = vnic_intr_credits(intr);
85 	int unmask = 1;
86 	int reset_timer = 1;
87 
88 	vnic_intr_return_credits(intr, credits, unmask, reset_timer);
89 }
90 
91 void vnic_intr_free(struct vnic_intr *intr);
92 int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
93 	unsigned int index);
94 void vnic_intr_init(struct vnic_intr *intr, u32 coalescing_timer,
95 	unsigned int coalescing_type, unsigned int mask_on_assertion);
96 void vnic_intr_coalescing_timer_set(struct vnic_intr *intr,
97 	u32 coalescing_timer);
98 void vnic_intr_clean(struct vnic_intr *intr);
99 
100 #endif /* _VNIC_INTR_H_ */
101