i40iw_cm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. /*******************************************************************************
  2. *
  3. * Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenFabrics.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. *
  33. *******************************************************************************/
  34. #ifndef I40IW_CM_H
  35. #define I40IW_CM_H
  36. #define QUEUE_EVENTS
  37. #define I40IW_MANAGE_APBVT_DEL 0
  38. #define I40IW_MANAGE_APBVT_ADD 1
  39. #define I40IW_MPA_REQUEST_ACCEPT 1
  40. #define I40IW_MPA_REQUEST_REJECT 2
  41. /* IETF MPA -- defines, enums, structs */
  42. #define IEFT_MPA_KEY_REQ "MPA ID Req Frame"
  43. #define IEFT_MPA_KEY_REP "MPA ID Rep Frame"
  44. #define IETF_MPA_KEY_SIZE 16
  45. #define IETF_MPA_VERSION 1
  46. #define IETF_MAX_PRIV_DATA_LEN 512
  47. #define IETF_MPA_FRAME_SIZE 20
  48. #define IETF_RTR_MSG_SIZE 4
  49. #define IETF_MPA_V2_FLAG 0x10
  50. #define SNDMARKER_SEQNMASK 0x000001FF
  51. #define I40IW_MAX_IETF_SIZE 32
  52. #define MPA_ZERO_PAD_LEN 4
  53. /* IETF RTR MSG Fields */
  54. #define IETF_PEER_TO_PEER 0x8000
  55. #define IETF_FLPDU_ZERO_LEN 0x4000
  56. #define IETF_RDMA0_WRITE 0x8000
  57. #define IETF_RDMA0_READ 0x4000
  58. #define IETF_NO_IRD_ORD 0x3FFF
  59. /* HW-supported IRD sizes*/
  60. #define I40IW_HW_IRD_SETTING_2 2
  61. #define I40IW_HW_IRD_SETTING_4 4
  62. #define I40IW_HW_IRD_SETTING_8 8
  63. #define I40IW_HW_IRD_SETTING_16 16
  64. #define I40IW_HW_IRD_SETTING_32 32
  65. #define I40IW_HW_IRD_SETTING_64 64
  66. enum ietf_mpa_flags {
  67. IETF_MPA_FLAGS_MARKERS = 0x80, /* receive Markers */
  68. IETF_MPA_FLAGS_CRC = 0x40, /* receive Markers */
  69. IETF_MPA_FLAGS_REJECT = 0x20, /* Reject */
  70. };
  71. struct ietf_mpa_v1 {
  72. u8 key[IETF_MPA_KEY_SIZE];
  73. u8 flags;
  74. u8 rev;
  75. __be16 priv_data_len;
  76. u8 priv_data[0];
  77. };
  78. #define ietf_mpa_req_resp_frame ietf_mpa_frame
  79. struct ietf_rtr_msg {
  80. __be16 ctrl_ird;
  81. __be16 ctrl_ord;
  82. };
  83. struct ietf_mpa_v2 {
  84. u8 key[IETF_MPA_KEY_SIZE];
  85. u8 flags;
  86. u8 rev;
  87. __be16 priv_data_len;
  88. struct ietf_rtr_msg rtr_msg;
  89. u8 priv_data[0];
  90. };
  91. struct i40iw_cm_node;
  92. enum i40iw_timer_type {
  93. I40IW_TIMER_TYPE_SEND,
  94. I40IW_TIMER_TYPE_RECV,
  95. I40IW_TIMER_NODE_CLEANUP,
  96. I40IW_TIMER_TYPE_CLOSE,
  97. };
  98. #define I40IW_PASSIVE_STATE_INDICATED 0
  99. #define I40IW_DO_NOT_SEND_RESET_EVENT 1
  100. #define I40IW_SEND_RESET_EVENT 2
  101. #define MAX_I40IW_IFS 4
  102. #define SET_ACK 0x1
  103. #define SET_SYN 0x2
  104. #define SET_FIN 0x4
  105. #define SET_RST 0x8
  106. #define TCP_OPTIONS_PADDING 3
  107. struct option_base {
  108. u8 optionnum;
  109. u8 length;
  110. };
  111. enum option_numbers {
  112. OPTION_NUMBER_END,
  113. OPTION_NUMBER_NONE,
  114. OPTION_NUMBER_MSS,
  115. OPTION_NUMBER_WINDOW_SCALE,
  116. OPTION_NUMBER_SACK_PERM,
  117. OPTION_NUMBER_SACK,
  118. OPTION_NUMBER_WRITE0 = 0xbc
  119. };
  120. struct option_mss {
  121. u8 optionnum;
  122. u8 length;
  123. __be16 mss;
  124. };
  125. struct option_windowscale {
  126. u8 optionnum;
  127. u8 length;
  128. u8 shiftcount;
  129. };
  130. union all_known_options {
  131. char as_end;
  132. struct option_base as_base;
  133. struct option_mss as_mss;
  134. struct option_windowscale as_windowscale;
  135. };
  136. struct i40iw_timer_entry {
  137. struct list_head list;
  138. unsigned long timetosend; /* jiffies */
  139. struct i40iw_puda_buf *sqbuf;
  140. u32 type;
  141. u32 retrycount;
  142. u32 retranscount;
  143. u32 context;
  144. u32 send_retrans;
  145. int close_when_complete;
  146. };
  147. #define I40IW_DEFAULT_RETRYS 64
  148. #define I40IW_DEFAULT_RETRANS 8
  149. #define I40IW_DEFAULT_TTL 0x40
  150. #define I40IW_DEFAULT_RTT_VAR 0x6
  151. #define I40IW_DEFAULT_SS_THRESH 0x3FFFFFFF
  152. #define I40IW_DEFAULT_REXMIT_THRESH 8
  153. #define I40IW_RETRY_TIMEOUT HZ
  154. #define I40IW_SHORT_TIME 10
  155. #define I40IW_LONG_TIME (2 * HZ)
  156. #define I40IW_MAX_TIMEOUT ((unsigned long)(12 * HZ))
  157. #define I40IW_CM_HASHTABLE_SIZE 1024
  158. #define I40IW_CM_TCP_TIMER_INTERVAL 3000
  159. #define I40IW_CM_DEFAULT_MTU 1540
  160. #define I40IW_CM_DEFAULT_FRAME_CNT 10
  161. #define I40IW_CM_THREAD_STACK_SIZE 256
  162. #define I40IW_CM_DEFAULT_RCV_WND 64240
  163. #define I40IW_CM_DEFAULT_RCV_WND_SCALED 0x3fffc
  164. #define I40IW_CM_DEFAULT_RCV_WND_SCALE 2
  165. #define I40IW_CM_DEFAULT_FREE_PKTS 0x000A
  166. #define I40IW_CM_FREE_PKT_LO_WATERMARK 2
  167. #define I40IW_CM_DEFAULT_MSS 536
  168. #define I40IW_CM_DEF_SEQ 0x159bf75f
  169. #define I40IW_CM_DEF_LOCAL_ID 0x3b47
  170. #define I40IW_CM_DEF_SEQ2 0x18ed5740
  171. #define I40IW_CM_DEF_LOCAL_ID2 0xb807
  172. #define MAX_CM_BUFFER (I40IW_MAX_IETF_SIZE + IETF_MAX_PRIV_DATA_LEN)
  173. typedef u32 i40iw_addr_t;
  174. #define i40iw_cm_tsa_context i40iw_qp_context
  175. struct i40iw_qp;
  176. /* cm node transition states */
  177. enum i40iw_cm_node_state {
  178. I40IW_CM_STATE_UNKNOWN,
  179. I40IW_CM_STATE_INITED,
  180. I40IW_CM_STATE_LISTENING,
  181. I40IW_CM_STATE_SYN_RCVD,
  182. I40IW_CM_STATE_SYN_SENT,
  183. I40IW_CM_STATE_ONE_SIDE_ESTABLISHED,
  184. I40IW_CM_STATE_ESTABLISHED,
  185. I40IW_CM_STATE_ACCEPTING,
  186. I40IW_CM_STATE_MPAREQ_SENT,
  187. I40IW_CM_STATE_MPAREQ_RCVD,
  188. I40IW_CM_STATE_MPAREJ_RCVD,
  189. I40IW_CM_STATE_OFFLOADED,
  190. I40IW_CM_STATE_FIN_WAIT1,
  191. I40IW_CM_STATE_FIN_WAIT2,
  192. I40IW_CM_STATE_CLOSE_WAIT,
  193. I40IW_CM_STATE_TIME_WAIT,
  194. I40IW_CM_STATE_LAST_ACK,
  195. I40IW_CM_STATE_CLOSING,
  196. I40IW_CM_STATE_LISTENER_DESTROYED,
  197. I40IW_CM_STATE_CLOSED
  198. };
  199. enum mpa_frame_version {
  200. IETF_MPA_V1 = 1,
  201. IETF_MPA_V2 = 2
  202. };
  203. enum mpa_frame_key {
  204. MPA_KEY_REQUEST,
  205. MPA_KEY_REPLY
  206. };
  207. enum send_rdma0 {
  208. SEND_RDMA_READ_ZERO = 1,
  209. SEND_RDMA_WRITE_ZERO = 2
  210. };
  211. enum i40iw_tcpip_pkt_type {
  212. I40IW_PKT_TYPE_UNKNOWN,
  213. I40IW_PKT_TYPE_SYN,
  214. I40IW_PKT_TYPE_SYNACK,
  215. I40IW_PKT_TYPE_ACK,
  216. I40IW_PKT_TYPE_FIN,
  217. I40IW_PKT_TYPE_RST
  218. };
  219. /* CM context params */
  220. struct i40iw_cm_tcp_context {
  221. u8 client;
  222. u32 loc_seq_num;
  223. u32 loc_ack_num;
  224. u32 rem_ack_num;
  225. u32 rcv_nxt;
  226. u32 loc_id;
  227. u32 rem_id;
  228. u32 snd_wnd;
  229. u32 max_snd_wnd;
  230. u32 rcv_wnd;
  231. u32 mss;
  232. u8 snd_wscale;
  233. u8 rcv_wscale;
  234. struct timeval sent_ts;
  235. };
  236. enum i40iw_cm_listener_state {
  237. I40IW_CM_LISTENER_PASSIVE_STATE = 1,
  238. I40IW_CM_LISTENER_ACTIVE_STATE = 2,
  239. I40IW_CM_LISTENER_EITHER_STATE = 3
  240. };
  241. struct i40iw_cm_listener {
  242. struct list_head list;
  243. struct i40iw_cm_core *cm_core;
  244. u8 loc_mac[ETH_ALEN];
  245. u32 loc_addr[4];
  246. u16 loc_port;
  247. struct iw_cm_id *cm_id;
  248. atomic_t ref_count;
  249. struct i40iw_device *iwdev;
  250. atomic_t pend_accepts_cnt;
  251. int backlog;
  252. enum i40iw_cm_listener_state listener_state;
  253. u32 reused_node;
  254. u8 user_pri;
  255. u16 vlan_id;
  256. bool qhash_set;
  257. bool ipv4;
  258. struct list_head child_listen_list;
  259. };
  260. struct i40iw_kmem_info {
  261. void *addr;
  262. u32 size;
  263. };
  264. /* per connection node and node state information */
  265. struct i40iw_cm_node {
  266. u32 loc_addr[4], rem_addr[4];
  267. u16 loc_port, rem_port;
  268. u16 vlan_id;
  269. enum i40iw_cm_node_state state;
  270. u8 loc_mac[ETH_ALEN];
  271. u8 rem_mac[ETH_ALEN];
  272. atomic_t ref_count;
  273. struct i40iw_qp *iwqp;
  274. struct i40iw_device *iwdev;
  275. struct i40iw_sc_dev *dev;
  276. struct i40iw_cm_tcp_context tcp_cntxt;
  277. struct i40iw_cm_core *cm_core;
  278. struct i40iw_cm_node *loopbackpartner;
  279. struct i40iw_timer_entry *send_entry;
  280. struct i40iw_timer_entry *close_entry;
  281. spinlock_t retrans_list_lock; /* cm transmit packet */
  282. enum send_rdma0 send_rdma0_op;
  283. u16 ird_size;
  284. u16 ord_size;
  285. u16 mpav2_ird_ord;
  286. struct iw_cm_id *cm_id;
  287. struct list_head list;
  288. int accelerated;
  289. struct i40iw_cm_listener *listener;
  290. int apbvt_set;
  291. int accept_pend;
  292. struct list_head timer_entry;
  293. struct list_head reset_entry;
  294. atomic_t passive_state;
  295. bool qhash_set;
  296. u8 user_pri;
  297. bool ipv4;
  298. bool snd_mark_en;
  299. u16 lsmm_size;
  300. enum mpa_frame_version mpa_frame_rev;
  301. struct i40iw_kmem_info pdata;
  302. union {
  303. struct ietf_mpa_v1 mpa_frame;
  304. struct ietf_mpa_v2 mpa_v2_frame;
  305. };
  306. u8 pdata_buf[IETF_MAX_PRIV_DATA_LEN];
  307. struct i40iw_kmem_info mpa_hdr;
  308. };
  309. /* structure for client or CM to fill when making CM api calls. */
  310. /* - only need to set relevant data, based on op. */
  311. struct i40iw_cm_info {
  312. struct iw_cm_id *cm_id;
  313. u16 loc_port;
  314. u16 rem_port;
  315. u32 loc_addr[4];
  316. u32 rem_addr[4];
  317. u16 vlan_id;
  318. int backlog;
  319. u16 user_pri;
  320. bool ipv4;
  321. };
  322. /* CM event codes */
  323. enum i40iw_cm_event_type {
  324. I40IW_CM_EVENT_UNKNOWN,
  325. I40IW_CM_EVENT_ESTABLISHED,
  326. I40IW_CM_EVENT_MPA_REQ,
  327. I40IW_CM_EVENT_MPA_CONNECT,
  328. I40IW_CM_EVENT_MPA_ACCEPT,
  329. I40IW_CM_EVENT_MPA_REJECT,
  330. I40IW_CM_EVENT_MPA_ESTABLISHED,
  331. I40IW_CM_EVENT_CONNECTED,
  332. I40IW_CM_EVENT_RESET,
  333. I40IW_CM_EVENT_ABORTED
  334. };
  335. /* event to post to CM event handler */
  336. struct i40iw_cm_event {
  337. enum i40iw_cm_event_type type;
  338. struct i40iw_cm_info cm_info;
  339. struct work_struct event_work;
  340. struct i40iw_cm_node *cm_node;
  341. };
  342. struct i40iw_cm_core {
  343. struct i40iw_device *iwdev;
  344. struct i40iw_sc_dev *dev;
  345. struct list_head listen_nodes;
  346. struct list_head connected_nodes;
  347. struct timer_list tcp_timer;
  348. struct workqueue_struct *event_wq;
  349. struct workqueue_struct *disconn_wq;
  350. spinlock_t ht_lock; /* manage hash table */
  351. spinlock_t listen_list_lock; /* listen list */
  352. u64 stats_nodes_created;
  353. u64 stats_nodes_destroyed;
  354. u64 stats_listen_created;
  355. u64 stats_listen_destroyed;
  356. u64 stats_listen_nodes_created;
  357. u64 stats_listen_nodes_destroyed;
  358. u64 stats_loopbacks;
  359. u64 stats_accepts;
  360. u64 stats_rejects;
  361. u64 stats_connect_errs;
  362. u64 stats_passive_errs;
  363. u64 stats_pkt_retrans;
  364. u64 stats_backlog_drops;
  365. };
  366. int i40iw_schedule_cm_timer(struct i40iw_cm_node *cm_node,
  367. struct i40iw_puda_buf *sqbuf,
  368. enum i40iw_timer_type type,
  369. int send_retrans,
  370. int close_when_complete);
  371. int i40iw_accept(struct iw_cm_id *, struct iw_cm_conn_param *);
  372. int i40iw_reject(struct iw_cm_id *, const void *, u8);
  373. int i40iw_connect(struct iw_cm_id *, struct iw_cm_conn_param *);
  374. int i40iw_create_listen(struct iw_cm_id *, int);
  375. int i40iw_destroy_listen(struct iw_cm_id *);
  376. int i40iw_cm_start(struct i40iw_device *);
  377. int i40iw_cm_stop(struct i40iw_device *);
  378. int i40iw_arp_table(struct i40iw_device *iwdev,
  379. u32 *ip_addr,
  380. bool ipv4,
  381. u8 *mac_addr,
  382. u32 action);
  383. #endif /* I40IW_CM_H */