hns_dsaf_rcb.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (c) 2014-2015 Hisilicon Limited.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. */
  9. #ifndef _HNS_DSAF_RCB_H
  10. #define _HNS_DSAF_RCB_H
  11. #include <linux/netdevice.h>
  12. #include <linux/platform_device.h>
  13. #include "hnae.h"
  14. #include "hns_dsaf_main.h"
  15. struct rcb_common_cb;
  16. #define HNS_RCB_IRQ_NUM_PER_QUEUE 2
  17. #define HNS_RCB_IRQ_IDX_TX 0
  18. #define HNS_RCB_IRQ_IDX_RX 1
  19. #define HNS_RCB_TX_REG_OFFSET 0x40
  20. #define HNS_RCB_SERVICE_NW_ENGINE_NUM DSAF_COMM_CHN
  21. #define HNS_RCB_DEBUG_NW_ENGINE_NUM 1
  22. #define HNS_RCB_RING_MAX_BD_PER_PKT 3
  23. #define HNS_RCB_RING_MAX_TXBD_PER_PKT 3
  24. #define HNS_RCBV2_RING_MAX_TXBD_PER_PKT 8
  25. #define HNS_RCB_MAX_PKT_SIZE MAC_MAX_MTU
  26. #define HNS_RCB_RING_MAX_PENDING_BD 1024
  27. #define HNS_RCB_RING_MIN_PENDING_BD 16
  28. #define HNS_RCB_REG_OFFSET 0x10000
  29. #define HNS_RCB_TX_FRAMES_LOW 1
  30. #define HNS_RCB_RX_FRAMES_LOW 1
  31. #define HNS_RCB_TX_FRAMES_HIGH 1023
  32. #define HNS_RCB_RX_FRAMES_HIGH 1023
  33. #define HNS_RCB_TX_USECS_LOW 1
  34. #define HNS_RCB_RX_USECS_LOW 1
  35. #define HNS_RCB_TX_USECS_HIGH 1023
  36. #define HNS_RCB_RX_USECS_HIGH 1023
  37. #define HNS_RCB_MAX_COALESCED_FRAMES 1023
  38. #define HNS_RCB_MIN_COALESCED_FRAMES 1
  39. #define HNS_RCB_DEF_RX_COALESCED_FRAMES 50
  40. #define HNS_RCB_DEF_TX_COALESCED_FRAMES 1
  41. #define HNS_RCB_CLK_FREQ_MHZ 350
  42. #define HNS_RCB_MAX_COALESCED_USECS 0x3ff
  43. #define HNS_RCB_DEF_COALESCED_USECS 30
  44. #define HNS_RCB_DEF_GAP_TIME_USECS 20
  45. #define HNS_RCB_TX_PKTLINE_OFFSET 8
  46. #define HNS_RCB_COMMON_ENDIAN 1
  47. #define HNS_BD_SIZE_512_TYPE 0
  48. #define HNS_BD_SIZE_1024_TYPE 1
  49. #define HNS_BD_SIZE_2048_TYPE 2
  50. #define HNS_BD_SIZE_4096_TYPE 3
  51. #define HNS_RCB_COMMON_DUMP_REG_NUM 80
  52. #define HNS_RCB_RING_DUMP_REG_NUM 40
  53. #define HNS_RING_STATIC_REG_NUM 28
  54. #define HNS_DUMP_REG_NUM 500
  55. #define HNS_STATIC_REG_NUM 12
  56. #define HNS_TSO_MODE_8BD_32K 1
  57. #define HNS_TSO_MDOE_4BD_16K 0
  58. enum rcb_int_flag {
  59. RCB_INT_FLAG_TX = 0x1,
  60. RCB_INT_FLAG_RX = (0x1 << 1),
  61. RCB_INT_FLAG_MAX = (0x1 << 2), /*must be the last element */
  62. };
  63. struct hns_ring_hw_stats {
  64. u64 tx_pkts;
  65. u64 ppe_tx_ok_pkts;
  66. u64 ppe_tx_drop_pkts;
  67. u64 rx_pkts;
  68. u64 ppe_rx_ok_pkts;
  69. u64 ppe_rx_drop_pkts;
  70. };
  71. struct ring_pair_cb {
  72. struct rcb_common_cb *rcb_common; /* ring belongs to */
  73. struct device *dev; /*device for DMA mapping */
  74. struct hnae_queue q;
  75. u16 index; /* global index in a rcb common device */
  76. u16 buf_size;
  77. int virq[HNS_RCB_IRQ_NUM_PER_QUEUE];
  78. u8 port_id_in_comm;
  79. u8 used_by_vf;
  80. struct hns_ring_hw_stats hw_stats;
  81. };
  82. struct rcb_common_cb {
  83. u8 __iomem *io_base;
  84. phys_addr_t phy_base;
  85. struct dsaf_device *dsaf_dev;
  86. u16 max_vfn;
  87. u16 max_q_per_vf;
  88. u8 comm_index;
  89. u32 ring_num;
  90. u32 desc_num; /* desc num per queue*/
  91. struct ring_pair_cb ring_pair_cb[0];
  92. };
  93. int hns_rcb_buf_size2type(u32 buf_size);
  94. int hns_rcb_common_get_cfg(struct dsaf_device *dsaf_dev, int comm_index);
  95. void hns_rcb_common_free_cfg(struct dsaf_device *dsaf_dev, u32 comm_index);
  96. int hns_rcb_common_init_hw(struct rcb_common_cb *rcb_common);
  97. void hns_rcb_start(struct hnae_queue *q, u32 val);
  98. int hns_rcb_get_cfg(struct rcb_common_cb *rcb_common);
  99. void hns_rcb_get_queue_mode(enum dsaf_mode dsaf_mode,
  100. u16 *max_vfn, u16 *max_q_per_vf);
  101. void hns_rcb_common_init_commit_hw(struct rcb_common_cb *rcb_common);
  102. void hns_rcb_ring_enable_hw(struct hnae_queue *q, u32 val);
  103. void hns_rcb_int_clr_hw(struct hnae_queue *q, u32 flag);
  104. void hns_rcb_int_ctrl_hw(struct hnae_queue *q, u32 flag, u32 enable);
  105. void hns_rcbv2_int_ctrl_hw(struct hnae_queue *q, u32 flag, u32 mask);
  106. void hns_rcbv2_int_clr_hw(struct hnae_queue *q, u32 flag);
  107. void hns_rcb_init_hw(struct ring_pair_cb *ring);
  108. void hns_rcb_reset_ring_hw(struct hnae_queue *q);
  109. void hns_rcb_wait_fbd_clean(struct hnae_queue **qs, int q_num, u32 flag);
  110. int hns_rcb_wait_tx_ring_clean(struct hnae_queue *qs);
  111. u32 hns_rcb_get_rx_coalesced_frames(
  112. struct rcb_common_cb *rcb_common, u32 port_idx);
  113. u32 hns_rcb_get_tx_coalesced_frames(
  114. struct rcb_common_cb *rcb_common, u32 port_idx);
  115. u32 hns_rcb_get_coalesce_usecs(
  116. struct rcb_common_cb *rcb_common, u32 port_idx);
  117. int hns_rcb_set_coalesce_usecs(
  118. struct rcb_common_cb *rcb_common, u32 port_idx, u32 timeout);
  119. int hns_rcb_set_rx_coalesced_frames(
  120. struct rcb_common_cb *rcb_common, u32 port_idx, u32 coalesced_frames);
  121. int hns_rcb_set_tx_coalesced_frames(
  122. struct rcb_common_cb *rcb_common, u32 port_idx, u32 coalesced_frames);
  123. void hns_rcb_update_stats(struct hnae_queue *queue);
  124. void hns_rcb_get_stats(struct hnae_queue *queue, u64 *data);
  125. void hns_rcb_get_common_regs(struct rcb_common_cb *rcb_common, void *data);
  126. int hns_rcb_get_ring_sset_count(int stringset);
  127. int hns_rcb_get_common_regs_count(void);
  128. int hns_rcb_get_ring_regs_count(void);
  129. void hns_rcb_get_ring_regs(struct hnae_queue *queue, void *data);
  130. void hns_rcb_get_strings(int stringset, u8 *data, int index);
  131. void hns_rcb_set_rx_ring_bs(struct hnae_queue *q, u32 buf_size);
  132. void hns_rcb_set_tx_ring_bs(struct hnae_queue *q, u32 buf_size);
  133. #endif /* _HNS_DSAF_RCB_H */