libcxgb_cm.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) 2016 Chelsio Communications, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef __LIBCXGB_CM_H__
  33. #define __LIBCXGB_CM_H__
  34. #include <net/tcp.h>
  35. #include <cxgb4.h>
  36. #include <t4_msg.h>
  37. #include <l2t.h>
  38. void
  39. cxgb_get_4tuple(struct cpl_pass_accept_req *, enum chip_type,
  40. int *, __u8 *, __u8 *, __be16 *, __be16 *);
  41. struct dst_entry *
  42. cxgb_find_route(struct cxgb4_lld_info *,
  43. struct net_device *(*)(struct net_device *),
  44. __be32, __be32, __be16, __be16, u8);
  45. struct dst_entry *
  46. cxgb_find_route6(struct cxgb4_lld_info *,
  47. struct net_device *(*)(struct net_device *),
  48. __u8 *, __u8 *, __be16, __be16, u8, __u32);
  49. /* Returns whether a CPL status conveys negative advice.
  50. */
  51. static inline bool cxgb_is_neg_adv(unsigned int status)
  52. {
  53. return status == CPL_ERR_RTX_NEG_ADVICE ||
  54. status == CPL_ERR_PERSIST_NEG_ADVICE ||
  55. status == CPL_ERR_KEEPALV_NEG_ADVICE;
  56. }
  57. static inline void
  58. cxgb_best_mtu(const unsigned short *mtus, unsigned short mtu,
  59. unsigned int *idx, int use_ts, int ipv6)
  60. {
  61. unsigned short hdr_size = (ipv6 ?
  62. sizeof(struct ipv6hdr) :
  63. sizeof(struct iphdr)) +
  64. sizeof(struct tcphdr) +
  65. (use_ts ?
  66. round_up(TCPOLEN_TIMESTAMP, 4) : 0);
  67. unsigned short data_size = mtu - hdr_size;
  68. cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
  69. }
  70. static inline u32 cxgb_compute_wscale(u32 win)
  71. {
  72. u32 wscale = 0;
  73. while (wscale < 14 && (65535 << wscale) < win)
  74. wscale++;
  75. return wscale;
  76. }
  77. static inline void
  78. cxgb_mk_tid_release(struct sk_buff *skb, u32 len, u32 tid, u16 chan)
  79. {
  80. struct cpl_tid_release *req;
  81. req = (struct cpl_tid_release *)__skb_put(skb, len);
  82. memset(req, 0, len);
  83. INIT_TP_WR(req, tid);
  84. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
  85. set_wr_txq(skb, CPL_PRIORITY_SETUP, chan);
  86. }
  87. static inline void
  88. cxgb_mk_close_con_req(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
  89. void *handle, arp_err_handler_t handler)
  90. {
  91. struct cpl_close_con_req *req;
  92. req = (struct cpl_close_con_req *)__skb_put(skb, len);
  93. memset(req, 0, len);
  94. INIT_TP_WR(req, tid);
  95. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
  96. set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
  97. t4_set_arp_err_handler(skb, handle, handler);
  98. }
  99. static inline void
  100. cxgb_mk_abort_req(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
  101. void *handle, arp_err_handler_t handler)
  102. {
  103. struct cpl_abort_req *req;
  104. req = (struct cpl_abort_req *)__skb_put(skb, len);
  105. memset(req, 0, len);
  106. INIT_TP_WR(req, tid);
  107. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, tid));
  108. req->cmd = CPL_ABORT_SEND_RST;
  109. set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
  110. t4_set_arp_err_handler(skb, handle, handler);
  111. }
  112. static inline void
  113. cxgb_mk_abort_rpl(struct sk_buff *skb, u32 len, u32 tid, u16 chan)
  114. {
  115. struct cpl_abort_rpl *rpl;
  116. rpl = (struct cpl_abort_rpl *)__skb_put(skb, len);
  117. memset(rpl, 0, len);
  118. INIT_TP_WR(rpl, tid);
  119. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, tid));
  120. rpl->cmd = CPL_ABORT_NO_RST;
  121. set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
  122. }
  123. static inline void
  124. cxgb_mk_rx_data_ack(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
  125. u32 credit_dack)
  126. {
  127. struct cpl_rx_data_ack *req;
  128. req = (struct cpl_rx_data_ack *)__skb_put(skb, len);
  129. memset(req, 0, len);
  130. INIT_TP_WR(req, tid);
  131. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK, tid));
  132. req->credit_dack = cpu_to_be32(credit_dack);
  133. set_wr_txq(skb, CPL_PRIORITY_ACK, chan);
  134. }
  135. #endif