tp.c 4.0 KB

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