i40iw_cm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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. /* IETF RTR MSG Fields */
  53. #define IETF_PEER_TO_PEER 0x8000
  54. #define IETF_FLPDU_ZERO_LEN 0x4000
  55. #define IETF_RDMA0_WRITE 0x8000
  56. #define IETF_RDMA0_READ 0x4000
  57. #define IETF_NO_IRD_ORD 0x3FFF
  58. /* HW-supported IRD sizes*/
  59. #define I40IW_HW_IRD_SETTING_2 2
  60. #define I40IW_HW_IRD_SETTING_4 4
  61. #define I40IW_HW_IRD_SETTING_8 8
  62. #define I40IW_HW_IRD_SETTING_16 16
  63. #define I40IW_HW_IRD_SETTING_32 32
  64. #define I40IW_HW_IRD_SETTING_64 64
  65. #define MAX_PORTS 65536
  66. #define I40IW_VLAN_PRIO_SHIFT 13
  67. enum ietf_mpa_flags {
  68. IETF_MPA_FLAGS_MARKERS = 0x80, /* receive Markers */
  69. IETF_MPA_FLAGS_CRC = 0x40, /* receive Markers */
  70. IETF_MPA_FLAGS_REJECT = 0x20, /* Reject */
  71. };
  72. struct ietf_mpa_v1 {
  73. u8 key[IETF_MPA_KEY_SIZE];
  74. u8 flags;
  75. u8 rev;
  76. __be16 priv_data_len;
  77. u8 priv_data[0];
  78. };
  79. #define ietf_mpa_req_resp_frame ietf_mpa_frame
  80. struct ietf_rtr_msg {
  81. __be16 ctrl_ird;
  82. __be16 ctrl_ord;
  83. };
  84. struct ietf_mpa_v2 {
  85. u8 key[IETF_MPA_KEY_SIZE];
  86. u8 flags;
  87. u8 rev;
  88. __be16 priv_data_len;
  89. struct ietf_rtr_msg rtr_msg;
  90. u8 priv_data[0];
  91. };
  92. struct i40iw_cm_node;
  93. enum i40iw_timer_type {
  94. I40IW_TIMER_TYPE_SEND,
  95. I40IW_TIMER_TYPE_RECV,
  96. I40IW_TIMER_NODE_CLEANUP,
  97. I40IW_TIMER_TYPE_CLOSE,
  98. };
  99. #define I40IW_PASSIVE_STATE_INDICATED 0
  100. #define I40IW_DO_NOT_SEND_RESET_EVENT 1
  101. #define I40IW_SEND_RESET_EVENT 2
  102. #define MAX_I40IW_IFS 4
  103. #define SET_ACK 0x1
  104. #define SET_SYN 0x2
  105. #define SET_FIN 0x4
  106. #define SET_RST 0x8
  107. #define TCP_OPTIONS_PADDING 3
  108. struct option_base {
  109. u8 optionnum;
  110. u8 length;
  111. };
  112. enum option_numbers {
  113. OPTION_NUMBER_END,
  114. OPTION_NUMBER_NONE,
  115. OPTION_NUMBER_MSS,
  116. OPTION_NUMBER_WINDOW_SCALE,
  117. OPTION_NUMBER_SACK_PERM,
  118. OPTION_NUMBER_SACK,
  119. OPTION_NUMBER_WRITE0 = 0xbc
  120. };
  121. struct option_mss {
  122. u8 optionnum;
  123. u8 length;
  124. __be16 mss;
  125. };
  126. struct option_windowscale {
  127. u8 optionnum;
  128. u8 length;
  129. u8 shiftcount;
  130. };
  131. union all_known_options {
  132. char as_end;
  133. struct option_base as_base;
  134. struct option_mss as_mss;
  135. struct option_windowscale as_windowscale;
  136. };
  137. struct i40iw_timer_entry {
  138. struct list_head list;
  139. unsigned long timetosend; /* jiffies */
  140. struct i40iw_puda_buf *sqbuf;
  141. u32 type;
  142. u32 retrycount;
  143. u32 retranscount;
  144. u32 context;
  145. u32 send_retrans;
  146. int close_when_complete;
  147. };
  148. #define I40IW_DEFAULT_RETRYS 64
  149. #define I40IW_DEFAULT_RETRANS 8
  150. #define I40IW_DEFAULT_TTL 0x40
  151. #define I40IW_DEFAULT_RTT_VAR 0x6
  152. #define I40IW_DEFAULT_SS_THRESH 0x3FFFFFFF
  153. #define I40IW_DEFAULT_REXMIT_THRESH 8
  154. #define I40IW_RETRY_TIMEOUT HZ
  155. #define I40IW_SHORT_TIME 10
  156. #define I40IW_LONG_TIME (2 * HZ)
  157. #define I40IW_MAX_TIMEOUT ((unsigned long)(12 * HZ))
  158. #define I40IW_CM_HASHTABLE_SIZE 1024
  159. #define I40IW_CM_TCP_TIMER_INTERVAL 3000
  160. #define I40IW_CM_DEFAULT_MTU 1540
  161. #define I40IW_CM_DEFAULT_FRAME_CNT 10
  162. #define I40IW_CM_THREAD_STACK_SIZE 256
  163. #define I40IW_CM_DEFAULT_RCV_WND 64240
  164. #define I40IW_CM_DEFAULT_RCV_WND_SCALED 0x3fffc
  165. #define I40IW_CM_DEFAULT_RCV_WND_SCALE 2
  166. #define I40IW_CM_DEFAULT_FREE_PKTS 0x000A
  167. #define I40IW_CM_FREE_PKT_LO_WATERMARK 2
  168. #define I40IW_CM_DEFAULT_MSS 536
  169. #define I40IW_CM_DEF_SEQ 0x159bf75f
  170. #define I40IW_CM_DEF_LOCAL_ID 0x3b47
  171. #define I40IW_CM_DEF_SEQ2 0x18ed5740
  172. #define I40IW_CM_DEF_LOCAL_ID2 0xb807
  173. #define MAX_CM_BUFFER (I40IW_MAX_IETF_SIZE + IETF_MAX_PRIV_DATA_LEN)
  174. typedef u32 i40iw_addr_t;
  175. #define i40iw_cm_tsa_context i40iw_qp_context
  176. struct i40iw_qp;
  177. /* cm node transition states */
  178. enum i40iw_cm_node_state {
  179. I40IW_CM_STATE_UNKNOWN,
  180. I40IW_CM_STATE_INITED,
  181. I40IW_CM_STATE_LISTENING,
  182. I40IW_CM_STATE_SYN_RCVD,
  183. I40IW_CM_STATE_SYN_SENT,
  184. I40IW_CM_STATE_ONE_SIDE_ESTABLISHED,
  185. I40IW_CM_STATE_ESTABLISHED,
  186. I40IW_CM_STATE_ACCEPTING,
  187. I40IW_CM_STATE_MPAREQ_SENT,
  188. I40IW_CM_STATE_MPAREQ_RCVD,
  189. I40IW_CM_STATE_MPAREJ_RCVD,
  190. I40IW_CM_STATE_OFFLOADED,
  191. I40IW_CM_STATE_FIN_WAIT1,
  192. I40IW_CM_STATE_FIN_WAIT2,
  193. I40IW_CM_STATE_CLOSE_WAIT,
  194. I40IW_CM_STATE_TIME_WAIT,
  195. I40IW_CM_STATE_LAST_ACK,
  196. I40IW_CM_STATE_CLOSING,
  197. I40IW_CM_STATE_LISTENER_DESTROYED,
  198. I40IW_CM_STATE_CLOSED
  199. };
  200. enum mpa_frame_version {
  201. IETF_MPA_V1 = 1,
  202. IETF_MPA_V2 = 2
  203. };
  204. enum mpa_frame_key {
  205. MPA_KEY_REQUEST,
  206. MPA_KEY_REPLY
  207. };
  208. enum send_rdma0 {
  209. SEND_RDMA_READ_ZERO = 1,
  210. SEND_RDMA_WRITE_ZERO = 2
  211. };
  212. enum i40iw_tcpip_pkt_type {
  213. I40IW_PKT_TYPE_UNKNOWN,
  214. I40IW_PKT_TYPE_SYN,
  215. I40IW_PKT_TYPE_SYNACK,
  216. I40IW_PKT_TYPE_ACK,
  217. I40IW_PKT_TYPE_FIN,
  218. I40IW_PKT_TYPE_RST
  219. };
  220. /* CM context params */
  221. struct i40iw_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 timeval sent_ts;
  236. };
  237. enum i40iw_cm_listener_state {
  238. I40IW_CM_LISTENER_PASSIVE_STATE = 1,
  239. I40IW_CM_LISTENER_ACTIVE_STATE = 2,
  240. I40IW_CM_LISTENER_EITHER_STATE = 3
  241. };
  242. struct i40iw_cm_listener {
  243. struct list_head list;
  244. struct i40iw_cm_core *cm_core;
  245. u8 loc_mac[ETH_ALEN];
  246. u32 loc_addr[4];
  247. u16 loc_port;
  248. struct iw_cm_id *cm_id;
  249. atomic_t ref_count;
  250. struct i40iw_device *iwdev;
  251. atomic_t pend_accepts_cnt;
  252. int backlog;
  253. enum i40iw_cm_listener_state listener_state;
  254. u32 reused_node;
  255. u8 user_pri;
  256. u8 tos;
  257. u16 vlan_id;
  258. bool qhash_set;
  259. bool ipv4;
  260. struct list_head child_listen_list;
  261. };
  262. struct i40iw_kmem_info {
  263. void *addr;
  264. u32 size;
  265. };
  266. /* per connection node and node state information */
  267. struct i40iw_cm_node {
  268. u32 loc_addr[4], rem_addr[4];
  269. u16 loc_port, rem_port;
  270. u16 vlan_id;
  271. enum i40iw_cm_node_state state;
  272. u8 loc_mac[ETH_ALEN];
  273. u8 rem_mac[ETH_ALEN];
  274. atomic_t ref_count;
  275. struct i40iw_qp *iwqp;
  276. struct i40iw_device *iwdev;
  277. struct i40iw_sc_dev *dev;
  278. struct i40iw_cm_tcp_context tcp_cntxt;
  279. struct i40iw_cm_core *cm_core;
  280. struct i40iw_cm_node *loopbackpartner;
  281. struct i40iw_timer_entry *send_entry;
  282. struct i40iw_timer_entry *close_entry;
  283. spinlock_t retrans_list_lock; /* cm transmit packet */
  284. enum send_rdma0 send_rdma0_op;
  285. u16 ird_size;
  286. u16 ord_size;
  287. u16 mpav2_ird_ord;
  288. struct iw_cm_id *cm_id;
  289. struct list_head list;
  290. int accelerated;
  291. struct i40iw_cm_listener *listener;
  292. int apbvt_set;
  293. int accept_pend;
  294. struct list_head timer_entry;
  295. struct list_head reset_entry;
  296. struct list_head connected_entry;
  297. atomic_t passive_state;
  298. bool qhash_set;
  299. u8 user_pri;
  300. u8 tos;
  301. bool ipv4;
  302. bool snd_mark_en;
  303. u16 lsmm_size;
  304. enum mpa_frame_version mpa_frame_rev;
  305. struct i40iw_kmem_info pdata;
  306. union {
  307. struct ietf_mpa_v1 mpa_frame;
  308. struct ietf_mpa_v2 mpa_v2_frame;
  309. };
  310. u8 pdata_buf[IETF_MAX_PRIV_DATA_LEN];
  311. struct i40iw_kmem_info mpa_hdr;
  312. };
  313. /* structure for client or CM to fill when making CM api calls. */
  314. /* - only need to set relevant data, based on op. */
  315. struct i40iw_cm_info {
  316. struct iw_cm_id *cm_id;
  317. u16 loc_port;
  318. u16 rem_port;
  319. u32 loc_addr[4];
  320. u32 rem_addr[4];
  321. u16 vlan_id;
  322. int backlog;
  323. u8 user_pri;
  324. u8 tos;
  325. bool ipv4;
  326. };
  327. /* CM event codes */
  328. enum i40iw_cm_event_type {
  329. I40IW_CM_EVENT_UNKNOWN,
  330. I40IW_CM_EVENT_ESTABLISHED,
  331. I40IW_CM_EVENT_MPA_REQ,
  332. I40IW_CM_EVENT_MPA_CONNECT,
  333. I40IW_CM_EVENT_MPA_ACCEPT,
  334. I40IW_CM_EVENT_MPA_REJECT,
  335. I40IW_CM_EVENT_MPA_ESTABLISHED,
  336. I40IW_CM_EVENT_CONNECTED,
  337. I40IW_CM_EVENT_RESET,
  338. I40IW_CM_EVENT_ABORTED
  339. };
  340. /* event to post to CM event handler */
  341. struct i40iw_cm_event {
  342. enum i40iw_cm_event_type type;
  343. struct i40iw_cm_info cm_info;
  344. struct work_struct event_work;
  345. struct i40iw_cm_node *cm_node;
  346. };
  347. struct i40iw_cm_core {
  348. struct i40iw_device *iwdev;
  349. struct i40iw_sc_dev *dev;
  350. struct list_head listen_nodes;
  351. struct list_head connected_nodes;
  352. struct timer_list tcp_timer;
  353. struct workqueue_struct *event_wq;
  354. struct workqueue_struct *disconn_wq;
  355. spinlock_t ht_lock; /* manage hash table */
  356. spinlock_t listen_list_lock; /* listen list */
  357. unsigned long active_side_ports[BITS_TO_LONGS(MAX_PORTS)];
  358. u64 stats_nodes_created;
  359. u64 stats_nodes_destroyed;
  360. u64 stats_listen_created;
  361. u64 stats_listen_destroyed;
  362. u64 stats_listen_nodes_created;
  363. u64 stats_listen_nodes_destroyed;
  364. u64 stats_loopbacks;
  365. u64 stats_accepts;
  366. u64 stats_rejects;
  367. u64 stats_connect_errs;
  368. u64 stats_passive_errs;
  369. u64 stats_pkt_retrans;
  370. u64 stats_backlog_drops;
  371. };
  372. int i40iw_schedule_cm_timer(struct i40iw_cm_node *cm_node,
  373. struct i40iw_puda_buf *sqbuf,
  374. enum i40iw_timer_type type,
  375. int send_retrans,
  376. int close_when_complete);
  377. int i40iw_accept(struct iw_cm_id *, struct iw_cm_conn_param *);
  378. int i40iw_reject(struct iw_cm_id *, const void *, u8);
  379. int i40iw_connect(struct iw_cm_id *, struct iw_cm_conn_param *);
  380. int i40iw_create_listen(struct iw_cm_id *, int);
  381. int i40iw_destroy_listen(struct iw_cm_id *);
  382. int i40iw_cm_start(struct i40iw_device *);
  383. int i40iw_cm_stop(struct i40iw_device *);
  384. int i40iw_arp_table(struct i40iw_device *iwdev,
  385. u32 *ip_addr,
  386. bool ipv4,
  387. u8 *mac_addr,
  388. u32 action);
  389. void i40iw_if_notify(struct i40iw_device *iwdev, struct net_device *netdev,
  390. u32 *ipaddr, bool ipv4, bool ifup);
  391. void i40iw_cm_disconnect_all(struct i40iw_device *iwdev);
  392. #endif /* I40IW_CM_H */