nes_cm.h 11 KB

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