nes_cm.h 12 KB

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