nes_cm.h 10 KB

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