tp.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. if (t1_is_asic(ap)) {
  18. u32 val;
  19. val = F_TP_IN_CSPI_CPL | F_TP_IN_CSPI_CHECK_IP_CSUM |
  20. F_TP_IN_CSPI_CHECK_TCP_CSUM | F_TP_IN_ESPI_ETHERNET;
  21. if (!p->pm_size)
  22. val |= F_OFFLOAD_DISABLE;
  23. else
  24. val |= F_TP_IN_ESPI_CHECK_IP_CSUM |
  25. 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,
  31. 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),
  36. ap->regs + A_TP_GLOBAL_CONFIG);
  37. /*
  38. * Enable pause frame deadlock prevention.
  39. */
  40. if (is_T2(ap) && ap->params.nports > 1) {
  41. u32 drop_ticks = DROP_MSEC * (tp_clk / 1000);
  42. writel(F_ENABLE_TX_DROP | F_ENABLE_TX_ERROR |
  43. V_DROP_TICKS_CNT(drop_ticks) |
  44. V_NUM_PKTS_DROPPED(DROP_PKTS_CNT),
  45. ap->regs + A_TP_TX_DROP_CONFIG);
  46. }
  47. }
  48. }
  49. void t1_tp_destroy(struct petp *tp)
  50. {
  51. kfree(tp);
  52. }
  53. struct petp *__devinit t1_tp_create(adapter_t * adapter, struct tp_params *p)
  54. {
  55. struct petp *tp = kzalloc(sizeof(*tp), GFP_KERNEL);
  56. if (!tp)
  57. return NULL;
  58. tp->adapter = adapter;
  59. return tp;
  60. }
  61. void t1_tp_intr_enable(struct petp *tp)
  62. {
  63. u32 tp_intr = readl(tp->adapter->regs + A_PL_ENABLE);
  64. #ifdef CONFIG_CHELSIO_T1_1G
  65. if (!t1_is_asic(tp->adapter)) {
  66. /* FPGA */
  67. writel(0xffffffff,
  68. tp->adapter->regs + FPGA_TP_ADDR_INTERRUPT_ENABLE);
  69. writel(tp_intr | FPGA_PCIX_INTERRUPT_TP,
  70. tp->adapter->regs + A_PL_ENABLE);
  71. } else
  72. #endif
  73. {
  74. /* We don't use any TP interrupts */
  75. writel(0, tp->adapter->regs + A_TP_INT_ENABLE);
  76. writel(tp_intr | F_PL_INTR_TP,
  77. tp->adapter->regs + A_PL_ENABLE);
  78. }
  79. }
  80. void t1_tp_intr_disable(struct petp *tp)
  81. {
  82. u32 tp_intr = readl(tp->adapter->regs + A_PL_ENABLE);
  83. #ifdef CONFIG_CHELSIO_T1_1G
  84. if (!t1_is_asic(tp->adapter)) {
  85. /* FPGA */
  86. writel(0, tp->adapter->regs + FPGA_TP_ADDR_INTERRUPT_ENABLE);
  87. writel(tp_intr & ~FPGA_PCIX_INTERRUPT_TP,
  88. tp->adapter->regs + A_PL_ENABLE);
  89. } else
  90. #endif
  91. {
  92. writel(0, tp->adapter->regs + A_TP_INT_ENABLE);
  93. writel(tp_intr & ~F_PL_INTR_TP,
  94. tp->adapter->regs + A_PL_ENABLE);
  95. }
  96. }
  97. void t1_tp_intr_clear(struct petp *tp)
  98. {
  99. #ifdef CONFIG_CHELSIO_T1_1G
  100. if (!t1_is_asic(tp->adapter)) {
  101. writel(0xffffffff,
  102. tp->adapter->regs + FPGA_TP_ADDR_INTERRUPT_CAUSE);
  103. writel(FPGA_PCIX_INTERRUPT_TP, tp->adapter->regs + A_PL_CAUSE);
  104. return;
  105. }
  106. #endif
  107. writel(0xffffffff, tp->adapter->regs + A_TP_INT_CAUSE);
  108. writel(F_PL_INTR_TP, tp->adapter->regs + A_PL_CAUSE);
  109. }
  110. int t1_tp_intr_handler(struct petp *tp)
  111. {
  112. u32 cause;
  113. #ifdef CONFIG_CHELSIO_T1_1G
  114. /* FPGA doesn't support TP interrupts. */
  115. if (!t1_is_asic(tp->adapter))
  116. return 1;
  117. #endif
  118. cause = readl(tp->adapter->regs + A_TP_INT_CAUSE);
  119. writel(cause, tp->adapter->regs + A_TP_INT_CAUSE);
  120. return 0;
  121. }
  122. static void set_csum_offload(struct petp *tp, u32 csum_bit, int enable)
  123. {
  124. u32 val = readl(tp->adapter->regs + A_TP_GLOBAL_CONFIG);
  125. if (enable)
  126. val |= csum_bit;
  127. else
  128. val &= ~csum_bit;
  129. writel(val, tp->adapter->regs + A_TP_GLOBAL_CONFIG);
  130. }
  131. void t1_tp_set_ip_checksum_offload(struct petp *tp, int enable)
  132. {
  133. set_csum_offload(tp, F_IP_CSUM, enable);
  134. }
  135. void t1_tp_set_udp_checksum_offload(struct petp *tp, int enable)
  136. {
  137. set_csum_offload(tp, F_UDP_CSUM, enable);
  138. }
  139. void t1_tp_set_tcp_checksum_offload(struct petp *tp, int enable)
  140. {
  141. set_csum_offload(tp, F_TCP_CSUM, enable);
  142. }
  143. /*
  144. * Initialize TP state. tp_params contains initial settings for some TP
  145. * parameters, particularly the one-time PM and CM settings.
  146. */
  147. int t1_tp_reset(struct petp *tp, struct tp_params *p, unsigned int tp_clk)
  148. {
  149. adapter_t *adapter = tp->adapter;
  150. tp_init(adapter, p, tp_clk);
  151. writel(F_TP_RESET, adapter->regs + A_TP_RESET);
  152. return 0;
  153. }