enic: fix warnings
[dpdk.git] / lib / librte_pmd_enic / vnic / 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 #ident "$Id: vnic_intr.h 171146 2014-05-02 07:08:20Z ssujith $"
35
36 #ifndef _VNIC_INTR_H_
37 #define _VNIC_INTR_H_
38
39
40 #include "vnic_dev.h"
41
42 #define VNIC_INTR_TIMER_TYPE_ABS        0
43 #define VNIC_INTR_TIMER_TYPE_QUIET      1
44
45 /* Interrupt control */
46 struct vnic_intr_ctrl {
47         u32 coalescing_timer;           /* 0x00 */
48         u32 pad0;
49         u32 coalescing_value;           /* 0x08 */
50         u32 pad1;
51         u32 coalescing_type;            /* 0x10 */
52         u32 pad2;
53         u32 mask_on_assertion;          /* 0x18 */
54         u32 pad3;
55         u32 mask;                       /* 0x20 */
56         u32 pad4;
57         u32 int_credits;                /* 0x28 */
58         u32 pad5;
59         u32 int_credit_return;          /* 0x30 */
60         u32 pad6;
61 };
62
63 struct vnic_intr {
64         unsigned int index;
65         struct vnic_dev *vdev;
66         struct vnic_intr_ctrl __iomem *ctrl;            /* memory-mapped */
67 };
68
69 static inline void vnic_intr_unmask(struct vnic_intr *intr)
70 {
71         iowrite32(0, &intr->ctrl->mask);
72 }
73
74 static inline void vnic_intr_mask(struct vnic_intr *intr)
75 {
76         iowrite32(1, &intr->ctrl->mask);
77 }
78
79 static inline int vnic_intr_masked(struct vnic_intr *intr)
80 {
81         return ioread32(&intr->ctrl->mask);
82 }
83
84 static inline void vnic_intr_return_credits(struct vnic_intr *intr,
85         unsigned int credits, int unmask, int reset_timer)
86 {
87 #define VNIC_INTR_UNMASK_SHIFT          16
88 #define VNIC_INTR_RESET_TIMER_SHIFT     17
89
90         u32 int_credit_return = (credits & 0xffff) |
91                 (unmask ? (1 << VNIC_INTR_UNMASK_SHIFT) : 0) |
92                 (reset_timer ? (1 << VNIC_INTR_RESET_TIMER_SHIFT) : 0);
93
94         iowrite32(int_credit_return, &intr->ctrl->int_credit_return);
95 }
96
97 static inline unsigned int vnic_intr_credits(struct vnic_intr *intr)
98 {
99         return ioread32(&intr->ctrl->int_credits);
100 }
101
102 static inline void vnic_intr_return_all_credits(struct vnic_intr *intr)
103 {
104         unsigned int credits = vnic_intr_credits(intr);
105         int unmask = 1;
106         int reset_timer = 1;
107
108         vnic_intr_return_credits(intr, credits, unmask, reset_timer);
109 }
110
111 static inline u32 vnic_intr_legacy_pba(u32 __iomem *legacy_pba)
112 {
113         /* read PBA without clearing */
114         return ioread32(legacy_pba);
115 }
116
117 void vnic_intr_free(struct vnic_intr *intr);
118 int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
119         unsigned int index);
120 void vnic_intr_init(struct vnic_intr *intr, u32 coalescing_timer,
121         unsigned int coalescing_type, unsigned int mask_on_assertion);
122 void vnic_intr_coalescing_timer_set(struct vnic_intr *intr,
123         u32 coalescing_timer);
124 void vnic_intr_clean(struct vnic_intr *intr);
125
126 #endif /* _VNIC_INTR_H_ */