hns_dsaf_rcb.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_MAX_COALESCED_FRAMES 1023
  30. #define HNS_RCB_MIN_COALESCED_FRAMES 1
  31. #define HNS_RCB_DEF_COALESCED_FRAMES 50
  32. #define HNS_RCB_CLK_FREQ_MHZ 350
  33. #define HNS_RCB_MAX_COALESCED_USECS 0x3ff
  34. #define HNS_RCB_DEF_COALESCED_USECS 50
  35. #define HNS_RCB_COMMON_ENDIAN 1
  36. #define HNS_BD_SIZE_512_TYPE 0
  37. #define HNS_BD_SIZE_1024_TYPE 1
  38. #define HNS_BD_SIZE_2048_TYPE 2
  39. #define HNS_BD_SIZE_4096_TYPE 3
  40. #define HNS_RCB_COMMON_DUMP_REG_NUM 80
  41. #define HNS_RCB_RING_DUMP_REG_NUM 40
  42. #define HNS_RING_STATIC_REG_NUM 28
  43. #define HNS_DUMP_REG_NUM 500
  44. #define HNS_STATIC_REG_NUM 12
  45. #define HNS_TSO_MODE_8BD_32K 1
  46. #define HNS_TSO_MDOE_4BD_16K 0
  47. enum rcb_int_flag {
  48. RCB_INT_FLAG_TX = 0x1,
  49. RCB_INT_FLAG_RX = (0x1 << 1),
  50. RCB_INT_FLAG_MAX = (0x1 << 2), /*must be the last element */
  51. };
  52. struct hns_ring_hw_stats {
  53. u64 tx_pkts;
  54. u64 ppe_tx_ok_pkts;
  55. u64 ppe_tx_drop_pkts;
  56. u64 rx_pkts;
  57. u64 ppe_rx_ok_pkts;
  58. u64 ppe_rx_drop_pkts;
  59. };
  60. struct ring_pair_cb {
  61. struct rcb_common_cb *rcb_common; /* ring belongs to */
  62. struct device *dev; /*device for DMA mapping */
  63. struct hnae_queue q;
  64. u16 index; /* global index in a rcb common device */
  65. u16 buf_size;
  66. int virq[HNS_RCB_IRQ_NUM_PER_QUEUE];
  67. u8 port_id_in_comm;
  68. u8 used_by_vf;
  69. struct hns_ring_hw_stats hw_stats;
  70. };
  71. struct rcb_common_cb {
  72. u8 __iomem *io_base;
  73. phys_addr_t phy_base;
  74. struct dsaf_device *dsaf_dev;
  75. u16 max_vfn;
  76. u16 max_q_per_vf;
  77. u8 comm_index;
  78. u32 ring_num;
  79. u32 desc_num; /* desc num per queue*/
  80. struct ring_pair_cb ring_pair_cb[0];
  81. };
  82. int hns_rcb_buf_size2type(u32 buf_size);
  83. int hns_rcb_common_get_cfg(struct dsaf_device *dsaf_dev, int comm_index);
  84. void hns_rcb_common_free_cfg(struct dsaf_device *dsaf_dev, u32 comm_index);
  85. int hns_rcb_common_init_hw(struct rcb_common_cb *rcb_common);
  86. void hns_rcb_start(struct hnae_queue *q, u32 val);
  87. void hns_rcb_get_cfg(struct rcb_common_cb *rcb_common);
  88. void hns_rcb_get_queue_mode(enum dsaf_mode dsaf_mode,
  89. u16 *max_vfn, u16 *max_q_per_vf);
  90. void hns_rcb_common_init_commit_hw(struct rcb_common_cb *rcb_common);
  91. void hns_rcb_ring_enable_hw(struct hnae_queue *q, u32 val);
  92. void hns_rcb_int_clr_hw(struct hnae_queue *q, u32 flag);
  93. void hns_rcb_int_ctrl_hw(struct hnae_queue *q, u32 flag, u32 enable);
  94. void hns_rcbv2_int_ctrl_hw(struct hnae_queue *q, u32 flag, u32 mask);
  95. void hns_rcbv2_int_clr_hw(struct hnae_queue *q, u32 flag);
  96. void hns_rcb_init_hw(struct ring_pair_cb *ring);
  97. void hns_rcb_reset_ring_hw(struct hnae_queue *q);
  98. void hns_rcb_wait_fbd_clean(struct hnae_queue **qs, int q_num, u32 flag);
  99. u32 hns_rcb_get_coalesced_frames(
  100. struct rcb_common_cb *rcb_common, u32 port_idx);
  101. u32 hns_rcb_get_coalesce_usecs(
  102. struct rcb_common_cb *rcb_common, u32 port_idx);
  103. int hns_rcb_set_coalesce_usecs(
  104. struct rcb_common_cb *rcb_common, u32 port_idx, u32 timeout);
  105. int hns_rcb_set_coalesced_frames(
  106. struct rcb_common_cb *rcb_common, u32 port_idx, u32 coalesced_frames);
  107. void hns_rcb_update_stats(struct hnae_queue *queue);
  108. void hns_rcb_get_stats(struct hnae_queue *queue, u64 *data);
  109. void hns_rcb_get_common_regs(struct rcb_common_cb *rcb_common, void *data);
  110. int hns_rcb_get_ring_sset_count(int stringset);
  111. int hns_rcb_get_common_regs_count(void);
  112. int hns_rcb_get_ring_regs_count(void);
  113. void hns_rcb_get_ring_regs(struct hnae_queue *queue, void *data);
  114. void hns_rcb_get_strings(int stringset, u8 *data, int index);
  115. #endif /* _HNS_DSAF_RCB_H */