2 * Copyright 2008-2010 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
5 * Copyright (c) 2014, Cisco Systems, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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.
41 #define VNIC_INTR_TIMER_TYPE_ABS 0
42 #define VNIC_INTR_TIMER_TYPE_QUIET 1
44 /* Interrupt control */
45 struct vnic_intr_ctrl {
46 u32 coalescing_timer; /* 0x00 */
48 u32 coalescing_value; /* 0x08 */
50 u32 coalescing_type; /* 0x10 */
52 u32 mask_on_assertion; /* 0x18 */
56 u32 int_credits; /* 0x28 */
58 u32 int_credit_return; /* 0x30 */
64 struct vnic_dev *vdev;
65 struct vnic_intr_ctrl __iomem *ctrl; /* memory-mapped */
68 static inline void vnic_intr_unmask(struct vnic_intr *intr)
70 iowrite32(0, &intr->ctrl->mask);
73 static inline void vnic_intr_mask(struct vnic_intr *intr)
75 iowrite32(1, &intr->ctrl->mask);
78 static inline int vnic_intr_masked(struct vnic_intr *intr)
80 return ioread32(&intr->ctrl->mask);
83 static inline void vnic_intr_return_credits(struct vnic_intr *intr,
84 unsigned int credits, int unmask, int reset_timer)
86 #define VNIC_INTR_UNMASK_SHIFT 16
87 #define VNIC_INTR_RESET_TIMER_SHIFT 17
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);
93 iowrite32(int_credit_return, &intr->ctrl->int_credit_return);
96 static inline unsigned int vnic_intr_credits(struct vnic_intr *intr)
98 return ioread32(&intr->ctrl->int_credits);
101 static inline void vnic_intr_return_all_credits(struct vnic_intr *intr)
103 unsigned int credits = vnic_intr_credits(intr);
107 vnic_intr_return_credits(intr, credits, unmask, reset_timer);
110 static inline u32 vnic_intr_legacy_pba(u32 __iomem *legacy_pba)
112 /* read PBA without clearing */
113 return ioread32(legacy_pba);
116 void vnic_intr_free(struct vnic_intr *intr);
117 int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
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);
125 #endif /* _VNIC_INTR_H_ */