iwch_cm.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Copyright (c) 2006 Chelsio, 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 _IWCH_CM_H_
  33. #define _IWCH_CM_H_
  34. #include <linux/inet.h>
  35. #include <linux/wait.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/kref.h>
  38. #include <rdma/ib_verbs.h>
  39. #include <rdma/iw_cm.h>
  40. #include "cxgb3_offload.h"
  41. #include "iwch_provider.h"
  42. #define MPA_KEY_REQ "MPA ID Req Frame"
  43. #define MPA_KEY_REP "MPA ID Rep Frame"
  44. #define MPA_MAX_PRIVATE_DATA 256
  45. #define MPA_REV 0 /* XXX - amso1100 uses rev 0 ! */
  46. #define MPA_REJECT 0x20
  47. #define MPA_CRC 0x40
  48. #define MPA_MARKERS 0x80
  49. #define MPA_FLAGS_MASK 0xE0
  50. #define put_ep(ep) { \
  51. PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__, \
  52. ep, atomic_read(&((ep)->kref.refcount))); \
  53. WARN_ON(atomic_read(&((ep)->kref.refcount)) < 1); \
  54. kref_put(&((ep)->kref), __free_ep); \
  55. }
  56. #define get_ep(ep) { \
  57. PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \
  58. ep, atomic_read(&((ep)->kref.refcount))); \
  59. kref_get(&((ep)->kref)); \
  60. }
  61. struct mpa_message {
  62. u8 key[16];
  63. u8 flags;
  64. u8 revision;
  65. __be16 private_data_size;
  66. u8 private_data[0];
  67. };
  68. struct terminate_message {
  69. u8 layer_etype;
  70. u8 ecode;
  71. __be16 hdrct_rsvd;
  72. u8 len_hdrs[0];
  73. };
  74. #define TERM_MAX_LENGTH (sizeof(struct terminate_message) + 2 + 18 + 28)
  75. enum iwch_layers_types {
  76. LAYER_RDMAP = 0x00,
  77. LAYER_DDP = 0x10,
  78. LAYER_MPA = 0x20,
  79. RDMAP_LOCAL_CATA = 0x00,
  80. RDMAP_REMOTE_PROT = 0x01,
  81. RDMAP_REMOTE_OP = 0x02,
  82. DDP_LOCAL_CATA = 0x00,
  83. DDP_TAGGED_ERR = 0x01,
  84. DDP_UNTAGGED_ERR = 0x02,
  85. DDP_LLP = 0x03
  86. };
  87. enum iwch_rdma_ecodes {
  88. RDMAP_INV_STAG = 0x00,
  89. RDMAP_BASE_BOUNDS = 0x01,
  90. RDMAP_ACC_VIOL = 0x02,
  91. RDMAP_STAG_NOT_ASSOC = 0x03,
  92. RDMAP_TO_WRAP = 0x04,
  93. RDMAP_INV_VERS = 0x05,
  94. RDMAP_INV_OPCODE = 0x06,
  95. RDMAP_STREAM_CATA = 0x07,
  96. RDMAP_GLOBAL_CATA = 0x08,
  97. RDMAP_CANT_INV_STAG = 0x09,
  98. RDMAP_UNSPECIFIED = 0xff
  99. };
  100. enum iwch_ddp_ecodes {
  101. DDPT_INV_STAG = 0x00,
  102. DDPT_BASE_BOUNDS = 0x01,
  103. DDPT_STAG_NOT_ASSOC = 0x02,
  104. DDPT_TO_WRAP = 0x03,
  105. DDPT_INV_VERS = 0x04,
  106. DDPU_INV_QN = 0x01,
  107. DDPU_INV_MSN_NOBUF = 0x02,
  108. DDPU_INV_MSN_RANGE = 0x03,
  109. DDPU_INV_MO = 0x04,
  110. DDPU_MSG_TOOBIG = 0x05,
  111. DDPU_INV_VERS = 0x06
  112. };
  113. enum iwch_mpa_ecodes {
  114. MPA_CRC_ERR = 0x02,
  115. MPA_MARKER_ERR = 0x03
  116. };
  117. enum iwch_ep_state {
  118. IDLE = 0,
  119. LISTEN,
  120. CONNECTING,
  121. MPA_REQ_WAIT,
  122. MPA_REQ_SENT,
  123. MPA_REQ_RCVD,
  124. MPA_REP_SENT,
  125. FPDU_MODE,
  126. ABORTING,
  127. CLOSING,
  128. MORIBUND,
  129. DEAD,
  130. };
  131. enum iwch_ep_flags {
  132. PEER_ABORT_IN_PROGRESS = 0,
  133. ABORT_REQ_IN_PROGRESS = 1,
  134. RELEASE_RESOURCES = 2,
  135. CLOSE_SENT = 3,
  136. };
  137. struct iwch_ep_common {
  138. struct iw_cm_id *cm_id;
  139. struct iwch_qp *qp;
  140. struct t3cdev *tdev;
  141. enum iwch_ep_state state;
  142. struct kref kref;
  143. spinlock_t lock;
  144. struct sockaddr_in local_addr;
  145. struct sockaddr_in remote_addr;
  146. wait_queue_head_t waitq;
  147. int rpl_done;
  148. int rpl_err;
  149. unsigned long flags;
  150. };
  151. struct iwch_listen_ep {
  152. struct iwch_ep_common com;
  153. unsigned int stid;
  154. int backlog;
  155. };
  156. struct iwch_ep {
  157. struct iwch_ep_common com;
  158. struct iwch_ep *parent_ep;
  159. struct timer_list timer;
  160. unsigned int atid;
  161. u32 hwtid;
  162. u32 snd_seq;
  163. u32 rcv_seq;
  164. struct l2t_entry *l2t;
  165. struct dst_entry *dst;
  166. struct sk_buff *mpa_skb;
  167. struct iwch_mpa_attributes mpa_attr;
  168. unsigned int mpa_pkt_len;
  169. u8 mpa_pkt[sizeof(struct mpa_message) + MPA_MAX_PRIVATE_DATA];
  170. u8 tos;
  171. u16 emss;
  172. u16 plen;
  173. u32 ird;
  174. u32 ord;
  175. };
  176. static inline struct iwch_ep *to_ep(struct iw_cm_id *cm_id)
  177. {
  178. return cm_id->provider_data;
  179. }
  180. static inline struct iwch_listen_ep *to_listen_ep(struct iw_cm_id *cm_id)
  181. {
  182. return cm_id->provider_data;
  183. }
  184. static inline int compute_wscale(int win)
  185. {
  186. int wscale = 0;
  187. while (wscale < 14 && (65535<<wscale) < win)
  188. wscale++;
  189. return wscale;
  190. }
  191. /* CM prototypes */
  192. int iwch_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param);
  193. int iwch_create_listen(struct iw_cm_id *cm_id, int backlog);
  194. int iwch_destroy_listen(struct iw_cm_id *cm_id);
  195. int iwch_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len);
  196. int iwch_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param);
  197. int iwch_ep_disconnect(struct iwch_ep *ep, int abrupt, gfp_t gfp);
  198. int iwch_quiesce_tid(struct iwch_ep *ep);
  199. int iwch_resume_tid(struct iwch_ep *ep);
  200. void __free_ep(struct kref *kref);
  201. void iwch_rearp(struct iwch_ep *ep);
  202. int iwch_ep_redirect(void *ctx, struct dst_entry *old, struct dst_entry *new, struct l2t_entry *l2t);
  203. int __init iwch_cm_init(void);
  204. void __exit iwch_cm_term(void);
  205. extern int peer2peer;
  206. #endif /* _IWCH_CM_H_ */