2  * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
 
   3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
 
   5  * This program is free software; you may redistribute it and/or modify
 
   6  * it under the terms of the GNU General Public License as published by
 
   7  * the Free Software Foundation; version 2 of the License.
 
   9  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
  10  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
  11  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
  12  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 
  13  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
  14  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
  15  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
  23 #include <linux/pci.h>
 
  27 #define VNIC_INTR_TIMER_MAX             0xffff
 
  29 #define VNIC_INTR_TIMER_TYPE_ABS        0
 
  30 #define VNIC_INTR_TIMER_TYPE_QUIET      1
 
  32 /* Interrupt control */
 
  33 struct vnic_intr_ctrl {
 
  34         u32 coalescing_timer;           /* 0x00 */
 
  36         u32 coalescing_value;           /* 0x08 */
 
  38         u32 coalescing_type;            /* 0x10 */
 
  40         u32 mask_on_assertion;          /* 0x18 */
 
  44         u32 int_credits;                /* 0x28 */
 
  46         u32 int_credit_return;          /* 0x30 */
 
  52         struct vnic_dev *vdev;
 
  53         struct vnic_intr_ctrl __iomem *ctrl;            /* memory-mapped */
 
  56 static inline void vnic_intr_unmask(struct vnic_intr *intr)
 
  58         iowrite32(0, &intr->ctrl->mask);
 
  61 static inline void vnic_intr_mask(struct vnic_intr *intr)
 
  63         iowrite32(1, &intr->ctrl->mask);
 
  66 static inline void vnic_intr_return_credits(struct vnic_intr *intr,
 
  67         unsigned int credits, int unmask, int reset_timer)
 
  69 #define VNIC_INTR_UNMASK_SHIFT          16
 
  70 #define VNIC_INTR_RESET_TIMER_SHIFT     17
 
  72         u32 int_credit_return = (credits & 0xffff) |
 
  73                 (unmask ? (1 << VNIC_INTR_UNMASK_SHIFT) : 0) |
 
  74                 (reset_timer ? (1 << VNIC_INTR_RESET_TIMER_SHIFT) : 0);
 
  76         iowrite32(int_credit_return, &intr->ctrl->int_credit_return);
 
  79 static inline u32 vnic_intr_legacy_pba(u32 __iomem *legacy_pba)
 
  81         /* get and ack interrupt in one read (clear-and-ack-on-read) */
 
  82         return ioread32(legacy_pba);
 
  85 void vnic_intr_free(struct vnic_intr *intr);
 
  86 int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
 
  88 void vnic_intr_init(struct vnic_intr *intr, unsigned int coalescing_timer,
 
  89         unsigned int coalescing_type, unsigned int mask_on_assertion);
 
  90 void vnic_intr_clean(struct vnic_intr *intr);
 
  92 #endif /* _VNIC_INTR_H_ */