nes_cm.h 11 KB

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