Imported Upstream version 16.04
[deb_dpdk.git] / drivers / net / enic / base / vnic_intr.h
1 /*
2  * Copyright 2008-2010 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  *
5  * Copyright (c) 2014, Cisco Systems, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34
35 #ifndef _VNIC_INTR_H_
36 #define _VNIC_INTR_H_
37
38
39 #include "vnic_dev.h"
40
41 #define VNIC_INTR_TIMER_TYPE_ABS        0
42 #define VNIC_INTR_TIMER_TYPE_QUIET      1
43
44 /* Interrupt control */
45 struct vnic_intr_ctrl {
46         u32 coalescing_timer;           /* 0x00 */
47         u32 pad0;
48         u32 coalescing_value;           /* 0x08 */
49         u32 pad1;
50         u32 coalescing_type;            /* 0x10 */
51         u32 pad2;
52         u32 mask_on_assertion;          /* 0x18 */
53         u32 pad3;
54         u32 mask;                       /* 0x20 */
55         u32 pad4;
56         u32 int_credits;                /* 0x28 */
57         u32 pad5;
58         u32 int_credit_return;          /* 0x30 */
59         u32 pad6;
60 };
61
62 struct vnic_intr {
63         unsigned int index;
64         struct vnic_dev *vdev;
65         struct vnic_intr_ctrl __iomem *ctrl;            /* memory-mapped */
66 };
67
68 static inline void vnic_intr_unmask(struct vnic_intr *intr)
69 {
70         iowrite32(0, &intr->ctrl->mask);
71 }
72
73 static inline void vnic_intr_mask(struct vnic_intr *intr)
74 {
75         iowrite32(1, &intr->ctrl->mask);
76 }
77
78 static inline int vnic_intr_masked(struct vnic_intr *intr)
79 {
80         return ioread32(&intr->ctrl->mask);
81 }
82
83 static inline void vnic_intr_return_credits(struct vnic_intr *intr,
84         unsigned int credits, int unmask, int reset_timer)
85 {
86 #define VNIC_INTR_UNMASK_SHIFT          16
87 #define VNIC_INTR_RESET_TIMER_SHIFT     17
88
89         u32 int_credit_return = (credits & 0xffff) |
90                 (unmask ? (1 << VNIC_INTR_UNMASK_SHIFT) : 0) |
91                 (reset_timer ? (1 << VNIC_INTR_RESET_TIMER_SHIFT) : 0);
92
93         iowrite32(int_credit_return, &intr->ctrl->int_credit_return);
94 }
95
96 static inline unsigned int vnic_intr_credits(struct vnic_intr *intr)
97 {
98         return ioread32(&intr->ctrl->int_credits);
99 }
100
101 static inline void vnic_intr_return_all_credits(struct vnic_intr *intr)
102 {
103         unsigned int credits = vnic_intr_credits(intr);
104         int unmask = 1;
105         int reset_timer = 1;
106
107         vnic_intr_return_credits(intr, credits, unmask, reset_timer);
108 }
109
110 static inline u32 vnic_intr_legacy_pba(u32 __iomem *legacy_pba)
111 {
112         /* read PBA without clearing */
113         return ioread32(legacy_pba);
114 }
115
116 void vnic_intr_free(struct vnic_intr *intr);
117 int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
118         unsigned int index);
119 void vnic_intr_init(struct vnic_intr *intr, u32 coalescing_timer,
120         unsigned int coalescing_type, unsigned int mask_on_assertion);
121 void vnic_intr_coalescing_timer_set(struct vnic_intr *intr,
122         u32 coalescing_timer);
123 void vnic_intr_clean(struct vnic_intr *intr);
124
125 #endif /* _VNIC_INTR_H_ */