tp.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* $Date: 2006/02/07 04:21:54 $ $RCSfile: tp.c,v $ $Revision: 1.73 $ */
  3. #include "common.h"
  4. #include "regs.h"
  5. #include "tp.h"
  6. #ifdef CONFIG_CHELSIO_T1_1G
  7. #include "fpga_defs.h"
  8. #endif
  9. struct petp {
  10. adapter_t *adapter;
  11. };
  12. /* Pause deadlock avoidance parameters */
  13. #define DROP_MSEC 16
  14. #define DROP_PKTS_CNT 1
  15. static void tp_init(adapter_t * ap, const struct tp_params *p,
  16. unsigned int tp_clk)
  17. {
  18. u32 val;
  19. if (!t1_is_asic(ap))
  20. return;
  21. val = F_TP_IN_CSPI_CPL | F_TP_IN_CSPI_CHECK_IP_CSUM |
  22. F_TP_IN_CSPI_CHECK_TCP_CSUM | F_TP_IN_ESPI_ETHERNET;
  23. if (!p->pm_size)
  24. val |= F_OFFLOAD_DISABLE;
  25. else
  26. val |= F_TP_IN_ESPI_CHECK_IP_CSUM | F_TP_IN_ESPI_CHECK_TCP_CSUM;
  27. writel(val, ap->regs + A_TP_IN_CONFIG);
  28. writel(F_TP_OUT_CSPI_CPL |
  29. F_TP_OUT_ESPI_ETHERNET |
  30. F_TP_OUT_ESPI_GENERATE_IP_CSUM |
  31. F_TP_OUT_ESPI_GENERATE_TCP_CSUM, ap->regs + A_TP_OUT_CONFIG);
  32. writel(V_IP_TTL(64) |
  33. F_PATH_MTU /* IP DF bit */ |
  34. V_5TUPLE_LOOKUP(p->use_5tuple_mode) |
  35. V_SYN_COOKIE_PARAMETER(29), ap->regs + A_TP_GLOBAL_CONFIG);
  36. /*
  37. * Enable pause frame deadlock prevention.
  38. */
  39. if (is_T2(ap) && ap->params.nports > 1) {
  40. u32 drop_ticks = DROP_MSEC * (tp_clk / 1000);
  41. writel(F_ENABLE_TX_DROP | F_ENABLE_TX_ERROR |
  42. V_DROP_TICKS_CNT(drop_ticks) |
  43. V_NUM_PKTS_DROPPED(DROP_PKTS_CNT),
  44. ap->regs + A_TP_TX_DROP_CONFIG);
  45. }
  46. }
  47. void t1_tp_destroy(struct petp *tp)
  48. {
  49. kfree(tp);
  50. }
  51. struct petp *t1_tp_create(adapter_t *adapter, struct tp_params *p)
  52. {
  53. struct petp *tp = kzalloc(sizeof(*tp), GFP_KERNEL);
  54. if (!tp)
  55. return NULL;
  56. tp->adapter = adapter;
  57. return tp;
  58. }
  59. void t1_tp_intr_enable(struct petp *tp)
  60. {
  61. u32 tp_intr = readl(tp->adapter->regs + A_PL_ENABLE);
  62. #ifdef CONFIG_CHELSIO_T1_1G
  63. if (!t1_is_asic(tp->adapter)) {
  64. /* FPGA */
  65. writel(0xffffffff,
  66. tp->adapter->regs + FPGA_TP_ADDR_INTERRUPT_ENABLE);
  67. writel(tp_intr | FPGA_PCIX_INTERRUPT_TP,
  68. tp->adapter->regs + A_PL_ENABLE);
  69. } else
  70. #endif
  71. {
  72. /* We don't use any TP interrupts */
  73. writel(0, tp->adapter->regs + A_TP_INT_ENABLE);
  74. writel(tp_intr | F_PL_INTR_TP,
  75. tp->adapter->regs + A_PL_ENABLE);
  76. }
  77. }
  78. void t1_tp_intr_disable(struct petp *tp)
  79. {
  80. u32 tp_intr = readl(tp->adapter->regs + A_PL_ENABLE);
  81. #ifdef CONFIG_CHELSIO_T1_1G
  82. if (!t1_is_asic(tp->adapter)) {
  83. /* FPGA */
  84. writel(0, tp->adapter->regs + FPGA_TP_ADDR_INTERRUPT_ENABLE);
  85. writel(tp_intr & ~FPGA_PCIX_INTERRUPT_TP,
  86. tp->adapter->regs + A_PL_ENABLE);
  87. } else
  88. #endif
  89. {
  90. writel(0, tp->adapter->regs + A_TP_INT_ENABLE);
  91. writel(tp_intr & ~F_PL_INTR_TP,
  92. tp->adapter->regs + A_PL_ENABLE);
  93. }
  94. }
  95. void t1_tp_intr_clear(struct petp *tp)
  96. {
  97. #ifdef CONFIG_CHELSIO_T1_1G
  98. if (!t1_is_asic(tp->adapter)) {
  99. writel(0xffffffff,
  100. tp->adapter->regs + FPGA_TP_ADDR_INTERRUPT_CAUSE);
  101. writel(FPGA_PCIX_INTERRUPT_TP, tp->adapter->regs + A_PL_CAUSE);
  102. return;
  103. }
  104. #endif
  105. writel(0xffffffff, tp->adapter->regs + A_TP_INT_CAUSE);
  106. writel(F_PL_INTR_TP, tp->adapter->regs + A_PL_CAUSE);
  107. }
  108. int t1_tp_intr_handler(struct petp *tp)
  109. {
  110. u32 cause;
  111. #ifdef CONFIG_CHELSIO_T1_1G
  112. /* FPGA doesn't support TP interrupts. */
  113. if (!t1_is_asic(tp->adapter))
  114. return 1;
  115. #endif
  116. cause = readl(tp->adapter->regs + A_TP_INT_CAUSE);
  117. writel(cause, tp->adapter->regs + A_TP_INT_CAUSE);
  118. return 0;
  119. }
  120. static void set_csum_offload(struct petp *tp, u32 csum_bit, int enable)
  121. {
  122. u32 val = readl(tp->adapter->regs + A_TP_GLOBAL_CONFIG);
  123. if (enable)
  124. val |= csum_bit;
  125. else
  126. val &= ~csum_bit;
  127. writel(val, tp->adapter->regs + A_TP_GLOBAL_CONFIG);
  128. }
  129. void t1_tp_set_ip_checksum_offload(struct petp *tp, int enable)
  130. {
  131. set_csum_offload(tp, F_IP_CSUM, enable);
  132. }
  133. void t1_tp_set_tcp_checksum_offload(struct petp *tp, int enable)
  134. {
  135. set_csum_offload(tp, F_TCP_CSUM, enable);
  136. }
  137. /*
  138. * Initialize TP state. tp_params contains initial settings for some TP
  139. * parameters, particularly the one-time PM and CM settings.
  140. */
  141. int t1_tp_reset(struct petp *tp, struct tp_params *p, unsigned int tp_clk)
  142. {
  143. adapter_t *adapter = tp->adapter;
  144. tp_init(adapter, p, tp_clk);
  145. writel(F_TP_RESET, adapter->regs + A_TP_RESET);
  146. return 0;
  147. }