vnic_intr.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2008 Cisco Systems, Inc. All rights reserved.
  4. * Copyright 2007 Nuova Systems, Inc. All rights reserved.
  5. */
  6. #ifndef _VNIC_INTR_H_
  7. #define _VNIC_INTR_H_
  8. #include <linux/pci.h>
  9. #include "vnic_dev.h"
  10. /*
  11. * These defines avoid symbol clash between fnic and enic (Cisco 10G Eth
  12. * Driver) when both are built with CONFIG options =y
  13. */
  14. #define vnic_intr_unmask fnic_intr_unmask
  15. #define vnic_intr_mask fnic_intr_mask
  16. #define vnic_intr_return_credits fnic_intr_return_credits
  17. #define vnic_intr_credits fnic_intr_credits
  18. #define vnic_intr_return_all_credits fnic_intr_return_all_credits
  19. #define vnic_intr_legacy_pba fnic_intr_legacy_pba
  20. #define vnic_intr_free fnic_intr_free
  21. #define vnic_intr_alloc fnic_intr_alloc
  22. #define vnic_intr_init fnic_intr_init
  23. #define vnic_intr_clean fnic_intr_clean
  24. #define VNIC_INTR_TIMER_MAX 0xffff
  25. #define VNIC_INTR_TIMER_TYPE_ABS 0
  26. #define VNIC_INTR_TIMER_TYPE_QUIET 1
  27. /* Interrupt control */
  28. struct vnic_intr_ctrl {
  29. u32 coalescing_timer; /* 0x00 */
  30. u32 pad0;
  31. u32 coalescing_value; /* 0x08 */
  32. u32 pad1;
  33. u32 coalescing_type; /* 0x10 */
  34. u32 pad2;
  35. u32 mask_on_assertion; /* 0x18 */
  36. u32 pad3;
  37. u32 mask; /* 0x20 */
  38. u32 pad4;
  39. u32 int_credits; /* 0x28 */
  40. u32 pad5;
  41. u32 int_credit_return; /* 0x30 */
  42. u32 pad6;
  43. };
  44. struct vnic_intr {
  45. unsigned int index;
  46. struct vnic_dev *vdev;
  47. struct vnic_intr_ctrl __iomem *ctrl; /* memory-mapped */
  48. };
  49. static inline void vnic_intr_unmask(struct vnic_intr *intr)
  50. {
  51. iowrite32(0, &intr->ctrl->mask);
  52. }
  53. static inline void vnic_intr_mask(struct vnic_intr *intr)
  54. {
  55. iowrite32(1, &intr->ctrl->mask);
  56. }
  57. static inline void vnic_intr_return_credits(struct vnic_intr *intr,
  58. unsigned int credits, int unmask, int reset_timer)
  59. {
  60. #define VNIC_INTR_UNMASK_SHIFT 16
  61. #define VNIC_INTR_RESET_TIMER_SHIFT 17
  62. u32 int_credit_return = (credits & 0xffff) |
  63. (unmask ? (1 << VNIC_INTR_UNMASK_SHIFT) : 0) |
  64. (reset_timer ? (1 << VNIC_INTR_RESET_TIMER_SHIFT) : 0);
  65. iowrite32(int_credit_return, &intr->ctrl->int_credit_return);
  66. }
  67. static inline unsigned int vnic_intr_credits(struct vnic_intr *intr)
  68. {
  69. return ioread32(&intr->ctrl->int_credits);
  70. }
  71. static inline void vnic_intr_return_all_credits(struct vnic_intr *intr)
  72. {
  73. unsigned int credits = vnic_intr_credits(intr);
  74. int unmask = 1;
  75. int reset_timer = 1;
  76. vnic_intr_return_credits(intr, credits, unmask, reset_timer);
  77. }
  78. static inline u32 vnic_intr_legacy_pba(u32 __iomem *legacy_pba)
  79. {
  80. /* read PBA without clearing */
  81. return ioread32(legacy_pba);
  82. }
  83. void vnic_intr_free(struct vnic_intr *intr);
  84. int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
  85. unsigned int index);
  86. void vnic_intr_init(struct vnic_intr *intr, unsigned int coalescing_timer,
  87. unsigned int coalescing_type, unsigned int mask_on_assertion);
  88. void vnic_intr_clean(struct vnic_intr *intr);
  89. #endif /* _VNIC_INTR_H_ */