nes_cm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /*
  2. * Copyright (c) 2006 - 2009 Intel-NE, 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. */
  33. #ifndef NES_CM_H
  34. #define NES_CM_H
  35. #define QUEUE_EVENTS
  36. #define NES_MANAGE_APBVT_DEL 0
  37. #define NES_MANAGE_APBVT_ADD 1
  38. #define NES_MPA_REQUEST_ACCEPT 1
  39. #define NES_MPA_REQUEST_REJECT 2
  40. /* IETF MPA -- defines, enums, structs */
  41. #define IEFT_MPA_KEY_REQ "MPA ID Req Frame"
  42. #define IEFT_MPA_KEY_REP "MPA ID Rep Frame"
  43. #define IETF_MPA_KEY_SIZE 16
  44. #define IETF_MPA_VERSION 1
  45. enum ietf_mpa_flags {
  46. IETF_MPA_FLAGS_MARKERS = 0x80, /* receive Markers */
  47. IETF_MPA_FLAGS_CRC = 0x40, /* receive Markers */
  48. IETF_MPA_FLAGS_REJECT = 0x20, /* Reject */
  49. };
  50. struct ietf_mpa_frame {
  51. u8 key[IETF_MPA_KEY_SIZE];
  52. u8 flags;
  53. u8 rev;
  54. __be16 priv_data_len;
  55. u8 priv_data[0];
  56. };
  57. #define ietf_mpa_req_resp_frame ietf_mpa_frame
  58. struct nes_v4_quad {
  59. u32 rsvd0;
  60. __le32 DstIpAdrIndex; /* Only most significant 5 bits are valid */
  61. __be32 SrcIpadr;
  62. __be16 TcpPorts[2]; /* src is low, dest is high */
  63. };
  64. struct nes_cm_node;
  65. enum nes_timer_type {
  66. NES_TIMER_TYPE_SEND,
  67. NES_TIMER_TYPE_RECV,
  68. NES_TIMER_NODE_CLEANUP,
  69. NES_TIMER_TYPE_CLOSE,
  70. };
  71. #define NES_PASSIVE_STATE_INDICATED 0
  72. #define NES_DO_NOT_SEND_RESET_EVENT 1
  73. #define NES_SEND_RESET_EVENT 2
  74. #define MAX_NES_IFS 4
  75. #define SET_ACK 1
  76. #define SET_SYN 2
  77. #define SET_FIN 4
  78. #define SET_RST 8
  79. #define TCP_OPTIONS_PADDING 3
  80. struct option_base {
  81. u8 optionnum;
  82. u8 length;
  83. };
  84. enum option_numbers {
  85. OPTION_NUMBER_END,
  86. OPTION_NUMBER_NONE,
  87. OPTION_NUMBER_MSS,
  88. OPTION_NUMBER_WINDOW_SCALE,
  89. OPTION_NUMBER_SACK_PERM,
  90. OPTION_NUMBER_SACK,
  91. OPTION_NUMBER_WRITE0 = 0xbc
  92. };
  93. struct option_mss {
  94. u8 optionnum;
  95. u8 length;
  96. __be16 mss;
  97. };
  98. struct option_windowscale {
  99. u8 optionnum;
  100. u8 length;
  101. u8 shiftcount;
  102. };
  103. union all_known_options {
  104. char as_end;
  105. struct option_base as_base;
  106. struct option_mss as_mss;
  107. struct option_windowscale as_windowscale;
  108. };
  109. struct nes_timer_entry {
  110. struct list_head list;
  111. unsigned long timetosend; /* jiffies */
  112. struct sk_buff *skb;
  113. u32 type;
  114. u32 retrycount;
  115. u32 retranscount;
  116. u32 context;
  117. u32 seq_num;
  118. u32 send_retrans;
  119. int close_when_complete;
  120. struct net_device *netdev;
  121. };
  122. #define NES_DEFAULT_RETRYS 64
  123. #define NES_DEFAULT_RETRANS 8
  124. #ifdef CONFIG_INFINIBAND_NES_DEBUG
  125. #define NES_RETRY_TIMEOUT (1000*HZ/1000)
  126. #else
  127. #define NES_RETRY_TIMEOUT (3000*HZ/1000)
  128. #endif
  129. #define NES_SHORT_TIME (10)
  130. #define NES_LONG_TIME (2000*HZ/1000)
  131. #define NES_CM_HASHTABLE_SIZE 1024
  132. #define NES_CM_TCP_TIMER_INTERVAL 3000
  133. #define NES_CM_DEFAULT_MTU 1540
  134. #define NES_CM_DEFAULT_FRAME_CNT 10
  135. #define NES_CM_THREAD_STACK_SIZE 256
  136. #define NES_CM_DEFAULT_RCV_WND 64240 // before we know that window scaling is allowed
  137. #define NES_CM_DEFAULT_RCV_WND_SCALED 256960 // after we know that window scaling is allowed
  138. #define NES_CM_DEFAULT_RCV_WND_SCALE 2
  139. #define NES_CM_DEFAULT_FREE_PKTS 0x000A
  140. #define NES_CM_FREE_PKT_LO_WATERMARK 2
  141. #define NES_CM_DEFAULT_MSS 536
  142. #define NES_CM_DEF_SEQ 0x159bf75f
  143. #define NES_CM_DEF_LOCAL_ID 0x3b47
  144. #define NES_CM_DEF_SEQ2 0x18ed5740
  145. #define NES_CM_DEF_LOCAL_ID2 0xb807
  146. #define MAX_CM_BUFFER 512
  147. typedef u32 nes_addr_t;
  148. #define nes_cm_tsa_context nes_qp_context
  149. struct nes_qp;
  150. /* cm node transition states */
  151. enum nes_cm_node_state {
  152. NES_CM_STATE_UNKNOWN,
  153. NES_CM_STATE_INITED,
  154. NES_CM_STATE_LISTENING,
  155. NES_CM_STATE_SYN_RCVD,
  156. NES_CM_STATE_SYN_SENT,
  157. NES_CM_STATE_ONE_SIDE_ESTABLISHED,
  158. NES_CM_STATE_ESTABLISHED,
  159. NES_CM_STATE_ACCEPTING,
  160. NES_CM_STATE_MPAREQ_SENT,
  161. NES_CM_STATE_MPAREQ_RCVD,
  162. NES_CM_STATE_MPAREJ_RCVD,
  163. NES_CM_STATE_TSA,
  164. NES_CM_STATE_FIN_WAIT1,
  165. NES_CM_STATE_FIN_WAIT2,
  166. NES_CM_STATE_CLOSE_WAIT,
  167. NES_CM_STATE_TIME_WAIT,
  168. NES_CM_STATE_LAST_ACK,
  169. NES_CM_STATE_CLOSING,
  170. NES_CM_STATE_CLOSED
  171. };
  172. enum nes_tcpip_pkt_type {
  173. NES_PKT_TYPE_UNKNOWN,
  174. NES_PKT_TYPE_SYN,
  175. NES_PKT_TYPE_SYNACK,
  176. NES_PKT_TYPE_ACK,
  177. NES_PKT_TYPE_FIN,
  178. NES_PKT_TYPE_RST
  179. };
  180. /* type of nes connection */
  181. enum nes_cm_conn_type {
  182. NES_CM_IWARP_CONN_TYPE,
  183. };
  184. /* CM context params */
  185. struct nes_cm_tcp_context {
  186. u8 client;
  187. u32 loc_seq_num;
  188. u32 loc_ack_num;
  189. u32 rem_ack_num;
  190. u32 rcv_nxt;
  191. u32 loc_id;
  192. u32 rem_id;
  193. u32 snd_wnd;
  194. u32 max_snd_wnd;
  195. u32 rcv_wnd;
  196. u32 mss;
  197. u8 snd_wscale;
  198. u8 rcv_wscale;
  199. struct nes_cm_tsa_context tsa_cntxt;
  200. struct timeval sent_ts;
  201. };
  202. enum nes_cm_listener_state {
  203. NES_CM_LISTENER_PASSIVE_STATE=1,
  204. NES_CM_LISTENER_ACTIVE_STATE=2,
  205. NES_CM_LISTENER_EITHER_STATE=3
  206. };
  207. struct nes_cm_listener {
  208. struct list_head list;
  209. struct nes_cm_core *cm_core;
  210. u8 loc_mac[ETH_ALEN];
  211. nes_addr_t loc_addr;
  212. u16 loc_port;
  213. struct iw_cm_id *cm_id;
  214. enum nes_cm_conn_type conn_type;
  215. atomic_t ref_count;
  216. struct nes_vnic *nesvnic;
  217. atomic_t pend_accepts_cnt;
  218. int backlog;
  219. enum nes_cm_listener_state listener_state;
  220. u32 reused_node;
  221. };
  222. /* per connection node and node state information */
  223. struct nes_cm_node {
  224. nes_addr_t loc_addr, rem_addr;
  225. u16 loc_port, rem_port;
  226. u8 loc_mac[ETH_ALEN];
  227. u8 rem_mac[ETH_ALEN];
  228. enum nes_cm_node_state state;
  229. struct nes_cm_tcp_context tcp_cntxt;
  230. struct nes_cm_core *cm_core;
  231. struct sk_buff_head resend_list;
  232. atomic_t ref_count;
  233. struct net_device *netdev;
  234. struct nes_cm_node *loopbackpartner;
  235. struct nes_timer_entry *send_entry;
  236. spinlock_t retrans_list_lock;
  237. struct nes_timer_entry *recv_entry;
  238. int send_write0;
  239. union {
  240. struct ietf_mpa_frame mpa_frame;
  241. u8 mpa_frame_buf[MAX_CM_BUFFER];
  242. };
  243. u16 mpa_frame_size;
  244. struct iw_cm_id *cm_id;
  245. struct list_head list;
  246. int accelerated;
  247. struct nes_cm_listener *listener;
  248. enum nes_cm_conn_type conn_type;
  249. struct nes_vnic *nesvnic;
  250. int apbvt_set;
  251. int accept_pend;
  252. struct list_head timer_entry;
  253. struct list_head reset_entry;
  254. struct nes_qp *nesqp;
  255. atomic_t passive_state;
  256. };
  257. /* structure for client or CM to fill when making CM api calls. */
  258. /* - only need to set relevant data, based on op. */
  259. struct nes_cm_info {
  260. union {
  261. struct iw_cm_id *cm_id;
  262. struct net_device *netdev;
  263. };
  264. u16 loc_port;
  265. u16 rem_port;
  266. nes_addr_t loc_addr;
  267. nes_addr_t rem_addr;
  268. enum nes_cm_conn_type conn_type;
  269. int backlog;
  270. };
  271. /* CM event codes */
  272. enum nes_cm_event_type {
  273. NES_CM_EVENT_UNKNOWN,
  274. NES_CM_EVENT_ESTABLISHED,
  275. NES_CM_EVENT_MPA_REQ,
  276. NES_CM_EVENT_MPA_CONNECT,
  277. NES_CM_EVENT_MPA_ACCEPT,
  278. NES_CM_EVENT_MPA_REJECT,
  279. NES_CM_EVENT_MPA_ESTABLISHED,
  280. NES_CM_EVENT_CONNECTED,
  281. NES_CM_EVENT_CLOSED,
  282. NES_CM_EVENT_RESET,
  283. NES_CM_EVENT_DROPPED_PKT,
  284. NES_CM_EVENT_CLOSE_IMMED,
  285. NES_CM_EVENT_CLOSE_HARD,
  286. NES_CM_EVENT_CLOSE_CLEAN,
  287. NES_CM_EVENT_ABORTED,
  288. NES_CM_EVENT_SEND_FIRST
  289. };
  290. /* event to post to CM event handler */
  291. struct nes_cm_event {
  292. enum nes_cm_event_type type;
  293. struct nes_cm_info cm_info;
  294. struct work_struct event_work;
  295. struct nes_cm_node *cm_node;
  296. };
  297. struct nes_cm_core {
  298. enum nes_cm_node_state state;
  299. atomic_t listen_node_cnt;
  300. struct nes_cm_node listen_list;
  301. spinlock_t listen_list_lock;
  302. u32 mtu;
  303. u32 free_tx_pkt_max;
  304. u32 rx_pkt_posted;
  305. atomic_t ht_node_cnt;
  306. struct list_head connected_nodes;
  307. /* struct list_head hashtable[NES_CM_HASHTABLE_SIZE]; */
  308. spinlock_t ht_lock;
  309. struct timer_list tcp_timer;
  310. struct nes_cm_ops *api;
  311. int (*post_event)(struct nes_cm_event *event);
  312. atomic_t events_posted;
  313. struct workqueue_struct *event_wq;
  314. struct workqueue_struct *disconn_wq;
  315. atomic_t node_cnt;
  316. u64 aborted_connects;
  317. u32 options;
  318. struct nes_cm_node *current_listen_node;
  319. };
  320. #define NES_CM_SET_PKT_SIZE (1 << 1)
  321. #define NES_CM_SET_FREE_PKT_Q_SIZE (1 << 2)
  322. /* CM ops/API for client interface */
  323. struct nes_cm_ops {
  324. int (*accelerated)(struct nes_cm_core *, struct nes_cm_node *);
  325. struct nes_cm_listener * (*listen)(struct nes_cm_core *, struct nes_vnic *,
  326. struct nes_cm_info *);
  327. int (*stop_listener)(struct nes_cm_core *, struct nes_cm_listener *);
  328. struct nes_cm_node * (*connect)(struct nes_cm_core *,
  329. struct nes_vnic *, u16, void *,
  330. struct nes_cm_info *);
  331. int (*close)(struct nes_cm_core *, struct nes_cm_node *);
  332. int (*accept)(struct nes_cm_core *, struct ietf_mpa_frame *,
  333. struct nes_cm_node *);
  334. int (*reject)(struct nes_cm_core *, struct ietf_mpa_frame *,
  335. struct nes_cm_node *);
  336. int (*recv_pkt)(struct nes_cm_core *, struct nes_vnic *,
  337. struct sk_buff *);
  338. int (*destroy_cm_core)(struct nes_cm_core *);
  339. int (*get)(struct nes_cm_core *);
  340. int (*set)(struct nes_cm_core *, u32, u32);
  341. };
  342. int schedule_nes_timer(struct nes_cm_node *, struct sk_buff *,
  343. enum nes_timer_type, int, int);
  344. int nes_cm_disconn(struct nes_qp *);
  345. int nes_accept(struct iw_cm_id *, struct iw_cm_conn_param *);
  346. int nes_reject(struct iw_cm_id *, const void *, u8);
  347. int nes_connect(struct iw_cm_id *, struct iw_cm_conn_param *);
  348. int nes_create_listen(struct iw_cm_id *, int);
  349. int nes_destroy_listen(struct iw_cm_id *);
  350. int nes_cm_recv(struct sk_buff *, struct net_device *);
  351. int nes_cm_start(void);
  352. int nes_cm_stop(void);
  353. #endif /* NES_CM_H */