vnic_intr.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright 2008-2010 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. */
  19. #ifndef _VNIC_INTR_H_
  20. #define _VNIC_INTR_H_
  21. #include <linux/pci.h>
  22. #include "vnic_dev.h"
  23. #define VNIC_INTR_TIMER_TYPE_ABS 0
  24. #define VNIC_INTR_TIMER_TYPE_QUIET 1
  25. /* Interrupt control */
  26. struct vnic_intr_ctrl {
  27. u32 coalescing_timer; /* 0x00 */
  28. u32 pad0;
  29. u32 coalescing_value; /* 0x08 */
  30. u32 pad1;
  31. u32 coalescing_type; /* 0x10 */
  32. u32 pad2;
  33. u32 mask_on_assertion; /* 0x18 */
  34. u32 pad3;
  35. u32 mask; /* 0x20 */
  36. u32 pad4;
  37. u32 int_credits; /* 0x28 */
  38. u32 pad5;
  39. u32 int_credit_return; /* 0x30 */
  40. u32 pad6;
  41. };
  42. struct vnic_intr {
  43. unsigned int index;
  44. struct vnic_dev *vdev;
  45. struct vnic_intr_ctrl __iomem *ctrl; /* memory-mapped */
  46. };
  47. static inline void vnic_intr_unmask(struct vnic_intr *intr)
  48. {
  49. iowrite32(0, &intr->ctrl->mask);
  50. }
  51. static inline void vnic_intr_mask(struct vnic_intr *intr)
  52. {
  53. iowrite32(1, &intr->ctrl->mask);
  54. }
  55. static inline int vnic_intr_masked(struct vnic_intr *intr)
  56. {
  57. return ioread32(&intr->ctrl->mask);
  58. }
  59. static inline void vnic_intr_return_credits(struct vnic_intr *intr,
  60. unsigned int credits, int unmask, int reset_timer)
  61. {
  62. #define VNIC_INTR_UNMASK_SHIFT 16
  63. #define VNIC_INTR_RESET_TIMER_SHIFT 17
  64. u32 int_credit_return = (credits & 0xffff) |
  65. (unmask ? (1 << VNIC_INTR_UNMASK_SHIFT) : 0) |
  66. (reset_timer ? (1 << VNIC_INTR_RESET_TIMER_SHIFT) : 0);
  67. iowrite32(int_credit_return, &intr->ctrl->int_credit_return);
  68. }
  69. static inline unsigned int vnic_intr_credits(struct vnic_intr *intr)
  70. {
  71. return ioread32(&intr->ctrl->int_credits);
  72. }
  73. static inline void vnic_intr_return_all_credits(struct vnic_intr *intr)
  74. {
  75. unsigned int credits = vnic_intr_credits(intr);
  76. int unmask = 1;
  77. int reset_timer = 1;
  78. vnic_intr_return_credits(intr, credits, unmask, reset_timer);
  79. }
  80. static inline u32 vnic_intr_legacy_pba(u32 __iomem *legacy_pba)
  81. {
  82. /* read PBA without clearing */
  83. return ioread32(legacy_pba);
  84. }
  85. void vnic_intr_free(struct vnic_intr *intr);
  86. int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
  87. unsigned int index);
  88. void vnic_intr_init(struct vnic_intr *intr, u32 coalescing_timer,
  89. unsigned int coalescing_type, unsigned int mask_on_assertion);
  90. void vnic_intr_coalescing_timer_set(struct vnic_intr *intr,
  91. u32 coalescing_timer);
  92. void vnic_intr_clean(struct vnic_intr *intr);
  93. #endif /* _VNIC_INTR_H_ */