Kyle Swenson | 8d8f654 | 2021-03-15 11:02:55 -0600 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. |
| 3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. |
| 4 | * |
| 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. |
| 8 | * |
| 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 |
| 16 | * SOFTWARE. |
| 17 | */ |
| 18 | #ifndef _VNIC_INTR_H_ |
| 19 | #define _VNIC_INTR_H_ |
| 20 | |
| 21 | #include <linux/pci.h> |
| 22 | #include "vnic_dev.h" |
| 23 | |
| 24 | /* |
| 25 | * These defines avoid symbol clash between fnic and enic (Cisco 10G Eth |
| 26 | * Driver) when both are built with CONFIG options =y |
| 27 | */ |
| 28 | #define vnic_intr_unmask fnic_intr_unmask |
| 29 | #define vnic_intr_mask fnic_intr_mask |
| 30 | #define vnic_intr_return_credits fnic_intr_return_credits |
| 31 | #define vnic_intr_credits fnic_intr_credits |
| 32 | #define vnic_intr_return_all_credits fnic_intr_return_all_credits |
| 33 | #define vnic_intr_legacy_pba fnic_intr_legacy_pba |
| 34 | #define vnic_intr_free fnic_intr_free |
| 35 | #define vnic_intr_alloc fnic_intr_alloc |
| 36 | #define vnic_intr_init fnic_intr_init |
| 37 | #define vnic_intr_clean fnic_intr_clean |
| 38 | |
| 39 | #define VNIC_INTR_TIMER_MAX 0xffff |
| 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 void vnic_intr_return_credits(struct vnic_intr *intr, |
| 79 | unsigned int credits, int unmask, int reset_timer) |
| 80 | { |
| 81 | #define VNIC_INTR_UNMASK_SHIFT 16 |
| 82 | #define VNIC_INTR_RESET_TIMER_SHIFT 17 |
| 83 | |
| 84 | u32 int_credit_return = (credits & 0xffff) | |
| 85 | (unmask ? (1 << VNIC_INTR_UNMASK_SHIFT) : 0) | |
| 86 | (reset_timer ? (1 << VNIC_INTR_RESET_TIMER_SHIFT) : 0); |
| 87 | |
| 88 | iowrite32(int_credit_return, &intr->ctrl->int_credit_return); |
| 89 | } |
| 90 | |
| 91 | static inline unsigned int vnic_intr_credits(struct vnic_intr *intr) |
| 92 | { |
| 93 | return ioread32(&intr->ctrl->int_credits); |
| 94 | } |
| 95 | |
| 96 | static inline void vnic_intr_return_all_credits(struct vnic_intr *intr) |
| 97 | { |
| 98 | unsigned int credits = vnic_intr_credits(intr); |
| 99 | int unmask = 1; |
| 100 | int reset_timer = 1; |
| 101 | |
| 102 | vnic_intr_return_credits(intr, credits, unmask, reset_timer); |
| 103 | } |
| 104 | |
| 105 | static inline u32 vnic_intr_legacy_pba(u32 __iomem *legacy_pba) |
| 106 | { |
| 107 | /* read PBA without clearing */ |
| 108 | return ioread32(legacy_pba); |
| 109 | } |
| 110 | |
| 111 | void vnic_intr_free(struct vnic_intr *intr); |
| 112 | int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr, |
| 113 | unsigned int index); |
| 114 | void vnic_intr_init(struct vnic_intr *intr, unsigned int coalescing_timer, |
| 115 | unsigned int coalescing_type, unsigned int mask_on_assertion); |
| 116 | void vnic_intr_clean(struct vnic_intr *intr); |
| 117 | |
| 118 | #endif /* _VNIC_INTR_H_ */ |