nes_cm.h 12 KB

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