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.
34 #ident "$Id: vnic_intr.h 171146 2014-05-02 07:08:20Z ssujith $"
42 #define VNIC_INTR_TIMER_TYPE_ABS 0
43 #define VNIC_INTR_TIMER_TYPE_QUIET 1
45 /* Interrupt control */
46 struct vnic_intr_ctrl {
47 u32 coalescing_timer; /* 0x00 */
49 u32 coalescing_value; /* 0x08 */
51 u32 coalescing_type; /* 0x10 */
53 u32 mask_on_assertion; /* 0x18 */
57 u32 int_credits; /* 0x28 */
59 u32 int_credit_return; /* 0x30 */
65 struct vnic_dev *vdev;
66 struct vnic_intr_ctrl __iomem *ctrl; /* memory-mapped */
69 static inline void vnic_intr_unmask(struct vnic_intr *intr)
71 iowrite32(0, &intr->ctrl->mask);
74 static inline void vnic_intr_mask(struct vnic_intr *intr)
76 iowrite32(1, &intr->ctrl->mask);
79 static inline int vnic_intr_masked(struct vnic_intr *intr)
81 return ioread32(&intr->ctrl->mask);
84 static inline void vnic_intr_return_credits(struct vnic_intr *intr,
85 unsigned int credits, int unmask, int reset_timer)
87 #define VNIC_INTR_UNMASK_SHIFT 16
88 #define VNIC_INTR_RESET_TIMER_SHIFT 17
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);
94 iowrite32(int_credit_return, &intr->ctrl->int_credit_return);
97 static inline unsigned int vnic_intr_credits(struct vnic_intr *intr)
99 return ioread32(&intr->ctrl->int_credits);
102 static inline void vnic_intr_return_all_credits(struct vnic_intr *intr)
104 unsigned int credits = vnic_intr_credits(intr);
108 vnic_intr_return_credits(intr, credits, unmask, reset_timer);
111 static inline u32 vnic_intr_legacy_pba(u32 __iomem *legacy_pba)
113 /* read PBA without clearing */
114 return ioread32(legacy_pba);
117 void vnic_intr_free(struct vnic_intr *intr);
118 int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
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);
126 #endif /* _VNIC_INTR_H_ */