1 /*- 2 * SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB 3 * 4 * Copyright (c) 2015 - 2021 Intel Corporation 5 * 6 * This software is available to you under a choice of one of two 7 * licenses. You may choose to be licensed under the terms of the GNU 8 * General Public License (GPL) Version 2, available from the file 9 * COPYING in the main directory of this source tree, or the 10 * OpenFabrics.org BSD license below: 11 * 12 * Redistribution and use in source and binary forms, with or 13 * without modification, are permitted provided that the following 14 * conditions are met: 15 * 16 * - Redistributions of source code must retain the above 17 * copyright notice, this list of conditions and the following 18 * disclaimer. 19 * 20 * - Redistributions in binary form must reproduce the above 21 * copyright notice, this list of conditions and the following 22 * disclaimer in the documentation and/or other materials 23 * provided with the distribution. 24 * 25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 * SOFTWARE. 33 */ 34 /*$FreeBSD$*/ 35 36 #ifndef IRDMA_CM_H 37 #define IRDMA_CM_H 38 39 #define IRDMA_MPA_REQUEST_ACCEPT 1 40 #define IRDMA_MPA_REQUEST_REJECT 2 41 42 /* IETF MPA -- defines */ 43 #define IEFT_MPA_KEY_REQ "MPA ID Req Frame" 44 #define IEFT_MPA_KEY_REP "MPA ID Rep Frame" 45 #define IETF_MPA_KEY_SIZE 16 46 #define IETF_MPA_VER 1 47 #define IETF_MAX_PRIV_DATA_LEN 512 48 #define IETF_MPA_FRAME_SIZE 20 49 #define IETF_RTR_MSG_SIZE 4 50 #define IETF_MPA_V2_FLAG 0x10 51 #define SNDMARKER_SEQNMASK 0x000001ff 52 #define IRDMA_MAX_IETF_SIZE 32 53 54 /* IETF RTR MSG Fields */ 55 #define IETF_PEER_TO_PEER 0x8000 56 #define IETF_FLPDU_ZERO_LEN 0x4000 57 #define IETF_RDMA0_WRITE 0x8000 58 #define IETF_RDMA0_READ 0x4000 59 #define IETF_NO_IRD_ORD 0x3fff 60 61 #define MAX_PORTS 65536 62 63 #define IRDMA_PASSIVE_STATE_INDICATED 0 64 #define IRDMA_DO_NOT_SEND_RESET_EVENT 1 65 #define IRDMA_SEND_RESET_EVENT 2 66 67 #define MAX_IRDMA_IFS 4 68 69 #define SET_ACK 1 70 #define SET_SYN 2 71 #define SET_FIN 4 72 #define SET_RST 8 73 74 #define TCP_OPTIONS_PADDING 3 75 76 #define IRDMA_DEFAULT_RETRYS 64 77 #define IRDMA_DEFAULT_RETRANS 8 78 #define IRDMA_DEFAULT_TTL 0x40 79 #define IRDMA_DEFAULT_RTT_VAR 6 80 #define IRDMA_DEFAULT_SS_THRESH 0x3fffffff 81 #define IRDMA_DEFAULT_REXMIT_THRESH 8 82 83 #define IRDMA_RETRY_TIMEOUT HZ 84 #define IRDMA_SHORT_TIME 10 85 #define IRDMA_LONG_TIME (2 * HZ) 86 #define IRDMA_MAX_TIMEOUT ((unsigned long)(12 * HZ)) 87 88 #define IRDMA_CM_HASHTABLE_SIZE 1024 89 #define IRDMA_CM_TCP_TIMER_INTERVAL 3000 90 #define IRDMA_CM_DEFAULT_MTU 1540 91 #define IRDMA_CM_DEFAULT_FRAME_CNT 10 92 #define IRDMA_CM_THREAD_STACK_SIZE 256 93 #define IRDMA_CM_DEFAULT_RCV_WND 64240 94 #define IRDMA_CM_DEFAULT_RCV_WND_SCALED 0x3FFFC 95 #define IRDMA_CM_DEFAULT_RCV_WND_SCALE 2 96 #define IRDMA_CM_DEFAULT_FREE_PKTS 10 97 #define IRDMA_CM_FREE_PKT_LO_WATERMARK 2 98 #define IRDMA_CM_DEFAULT_MSS 536 99 #define IRDMA_CM_DEFAULT_MPA_VER 2 100 #define IRDMA_CM_DEFAULT_SEQ 0x159bf75f 101 #define IRDMA_CM_DEFAULT_LOCAL_ID 0x3b47 102 #define IRDMA_CM_DEFAULT_SEQ2 0x18ed5740 103 #define IRDMA_CM_DEFAULT_LOCAL_ID2 0xb807 104 #define IRDMA_MAX_CM_BUF (IRDMA_MAX_IETF_SIZE + IETF_MAX_PRIV_DATA_LEN) 105 106 enum ietf_mpa_flags { 107 IETF_MPA_FLAGS_REJECT = 0x20, 108 IETF_MPA_FLAGS_CRC = 0x40, 109 IETF_MPA_FLAGS_MARKERS = 0x80, 110 }; 111 112 enum irdma_timer_type { 113 IRDMA_TIMER_TYPE_SEND, 114 IRDMA_TIMER_TYPE_CLOSE, 115 }; 116 117 enum option_nums { 118 OPTION_NUM_EOL, 119 OPTION_NUM_NONE, 120 OPTION_NUM_MSS, 121 OPTION_NUM_WINDOW_SCALE, 122 OPTION_NUM_SACK_PERM, 123 OPTION_NUM_SACK, 124 OPTION_NUM_WRITE0 = 0xbc, 125 }; 126 127 /* cm node transition states */ 128 enum irdma_cm_node_state { 129 IRDMA_CM_STATE_UNKNOWN, 130 IRDMA_CM_STATE_INITED, 131 IRDMA_CM_STATE_LISTENING, 132 IRDMA_CM_STATE_SYN_RCVD, 133 IRDMA_CM_STATE_SYN_SENT, 134 IRDMA_CM_STATE_ONE_SIDE_ESTABLISHED, 135 IRDMA_CM_STATE_ESTABLISHED, 136 IRDMA_CM_STATE_ACCEPTING, 137 IRDMA_CM_STATE_MPAREQ_SENT, 138 IRDMA_CM_STATE_MPAREQ_RCVD, 139 IRDMA_CM_STATE_MPAREJ_RCVD, 140 IRDMA_CM_STATE_OFFLOADED, 141 IRDMA_CM_STATE_FIN_WAIT1, 142 IRDMA_CM_STATE_FIN_WAIT2, 143 IRDMA_CM_STATE_CLOSE_WAIT, 144 IRDMA_CM_STATE_TIME_WAIT, 145 IRDMA_CM_STATE_LAST_ACK, 146 IRDMA_CM_STATE_CLOSING, 147 IRDMA_CM_STATE_LISTENER_DESTROYED, 148 IRDMA_CM_STATE_CLOSED, 149 }; 150 151 enum mpa_frame_ver { 152 IETF_MPA_V1 = 1, 153 IETF_MPA_V2 = 2, 154 }; 155 156 enum mpa_frame_key { 157 MPA_KEY_REQUEST, 158 MPA_KEY_REPLY, 159 }; 160 161 enum send_rdma0 { 162 SEND_RDMA_READ_ZERO = 1, 163 SEND_RDMA_WRITE_ZERO = 2, 164 }; 165 166 enum irdma_tcpip_pkt_type { 167 IRDMA_PKT_TYPE_UNKNOWN, 168 IRDMA_PKT_TYPE_SYN, 169 IRDMA_PKT_TYPE_SYNACK, 170 IRDMA_PKT_TYPE_ACK, 171 IRDMA_PKT_TYPE_FIN, 172 IRDMA_PKT_TYPE_RST, 173 }; 174 175 enum irdma_cm_listener_state { 176 IRDMA_CM_LISTENER_PASSIVE_STATE = 1, 177 IRDMA_CM_LISTENER_ACTIVE_STATE = 2, 178 IRDMA_CM_LISTENER_EITHER_STATE = 3, 179 }; 180 181 /* CM event codes */ 182 enum irdma_cm_event_type { 183 IRDMA_CM_EVENT_UNKNOWN, 184 IRDMA_CM_EVENT_ESTABLISHED, 185 IRDMA_CM_EVENT_MPA_REQ, 186 IRDMA_CM_EVENT_MPA_CONNECT, 187 IRDMA_CM_EVENT_MPA_ACCEPT, 188 IRDMA_CM_EVENT_MPA_REJECT, 189 IRDMA_CM_EVENT_MPA_ESTABLISHED, 190 IRDMA_CM_EVENT_CONNECTED, 191 IRDMA_CM_EVENT_RESET, 192 IRDMA_CM_EVENT_ABORTED, 193 }; 194 195 struct irdma_bth { /* Base Trasnport Header */ 196 u8 opcode; 197 u8 flags; 198 __be16 pkey; 199 __be32 qpn; 200 __be32 apsn; 201 }; 202 203 struct ietf_mpa_v1 { 204 u8 key[IETF_MPA_KEY_SIZE]; 205 u8 flags; 206 u8 rev; 207 __be16 priv_data_len; 208 u8 priv_data[]; 209 }; 210 211 struct ietf_rtr_msg { 212 __be16 ctrl_ird; 213 __be16 ctrl_ord; 214 }; 215 216 struct ietf_mpa_v2 { 217 u8 key[IETF_MPA_KEY_SIZE]; 218 u8 flags; 219 u8 rev; 220 __be16 priv_data_len; 221 struct ietf_rtr_msg rtr_msg; 222 u8 priv_data[]; 223 }; 224 225 struct option_base { 226 u8 optionnum; 227 u8 len; 228 }; 229 230 struct option_mss { 231 u8 optionnum; 232 u8 len; 233 __be16 mss; 234 }; 235 236 struct option_windowscale { 237 u8 optionnum; 238 u8 len; 239 u8 shiftcount; 240 }; 241 242 union all_known_options { 243 char eol; 244 struct option_base base; 245 struct option_mss mss; 246 struct option_windowscale windowscale; 247 }; 248 249 struct irdma_timer_entry { 250 struct list_head list; 251 unsigned long timetosend; /* jiffies */ 252 struct irdma_puda_buf *sqbuf; 253 u32 type; 254 u32 retrycount; 255 u32 retranscount; 256 u32 context; 257 u32 send_retrans; 258 int close_when_complete; 259 }; 260 261 /* CM context params */ 262 struct irdma_cm_tcp_context { 263 u8 client; 264 u32 loc_seq_num; 265 u32 loc_ack_num; 266 u32 rem_ack_num; 267 u32 rcv_nxt; 268 u32 loc_id; 269 u32 rem_id; 270 u32 snd_wnd; 271 u32 max_snd_wnd; 272 u32 rcv_wnd; 273 u32 mss; 274 u8 snd_wscale; 275 u8 rcv_wscale; 276 }; 277 278 struct irdma_apbvt_entry { 279 struct hlist_node hlist; 280 u32 use_cnt; 281 u16 port; 282 }; 283 284 struct irdma_cm_listener { 285 struct list_head list; 286 struct iw_cm_id *cm_id; 287 struct irdma_cm_core *cm_core; 288 struct irdma_device *iwdev; 289 struct list_head child_listen_list; 290 struct irdma_apbvt_entry *apbvt_entry; 291 enum irdma_cm_listener_state listener_state; 292 atomic_t refcnt; 293 atomic_t pend_accepts_cnt; 294 u32 loc_addr[4]; 295 u32 reused_node; 296 int backlog; 297 u16 loc_port; 298 u16 vlan_id; 299 u8 loc_mac[ETH_ALEN]; 300 u8 user_pri; 301 u8 tos; 302 bool qhash_set:1; 303 bool ipv4:1; 304 }; 305 306 struct irdma_kmem_info { 307 void *addr; 308 u32 size; 309 }; 310 311 struct irdma_mpa_priv_info { 312 const void *addr; 313 u32 size; 314 }; 315 316 struct irdma_cm_node { 317 struct irdma_qp *iwqp; 318 struct irdma_device *iwdev; 319 struct irdma_sc_dev *dev; 320 struct irdma_cm_tcp_context tcp_cntxt; 321 struct irdma_cm_core *cm_core; 322 struct irdma_timer_entry *send_entry; 323 struct irdma_timer_entry *close_entry; 324 struct irdma_cm_listener *listener; 325 struct list_head timer_entry; 326 struct list_head reset_entry; 327 struct list_head teardown_entry; 328 struct irdma_apbvt_entry *apbvt_entry; 329 struct rcu_head rcu_head; 330 struct irdma_mpa_priv_info pdata; 331 struct irdma_sc_ah *ah; 332 struct irdma_kmem_info mpa_hdr; 333 struct iw_cm_id *cm_id; 334 struct hlist_node list; 335 struct completion establish_comp; 336 spinlock_t retrans_list_lock; /* protect CM node rexmit updates*/ 337 atomic_t passive_state; 338 atomic_t refcnt; 339 enum irdma_cm_node_state state; 340 enum send_rdma0 send_rdma0_op; 341 enum mpa_frame_ver mpa_frame_rev; 342 u32 loc_addr[4], rem_addr[4]; 343 u16 loc_port, rem_port; 344 int apbvt_set; 345 int accept_pend; 346 u16 vlan_id; 347 u16 ird_size; 348 u16 ord_size; 349 u16 mpav2_ird_ord; 350 u16 lsmm_size; 351 u8 pdata_buf[IETF_MAX_PRIV_DATA_LEN]; 352 u8 loc_mac[ETH_ALEN]; 353 u8 rem_mac[ETH_ALEN]; 354 u8 user_pri; 355 u8 tos; 356 bool ack_rcvd:1; 357 bool qhash_set:1; 358 bool ipv4:1; 359 bool snd_mark_en:1; 360 bool rcv_mark_en:1; 361 bool do_lpb:1; 362 bool accelerated:1; 363 struct ietf_mpa_v2 mpa_v2_frame; 364 }; 365 366 /* Used by internal CM APIs to pass CM information*/ 367 struct irdma_cm_info { 368 struct iw_cm_id *cm_id; 369 u16 loc_port; 370 u16 rem_port; 371 u32 loc_addr[4]; 372 u32 rem_addr[4]; 373 u32 qh_qpid; 374 u16 vlan_id; 375 int backlog; 376 u8 user_pri; 377 u8 tos; 378 bool ipv4; 379 }; 380 381 struct irdma_cm_event { 382 enum irdma_cm_event_type type; 383 struct irdma_cm_info cm_info; 384 struct work_struct event_work; 385 struct irdma_cm_node *cm_node; 386 }; 387 388 struct irdma_cm_core { 389 struct irdma_device *iwdev; 390 struct irdma_sc_dev *dev; 391 struct list_head listen_list; 392 DECLARE_HASHTABLE(cm_hash_tbl, 8); 393 DECLARE_HASHTABLE(apbvt_hash_tbl, 8); 394 struct timer_list tcp_timer; 395 struct workqueue_struct *event_wq; 396 spinlock_t ht_lock; /* protect CM node (active side) list */ 397 spinlock_t listen_list_lock; /* protect listener list */ 398 spinlock_t apbvt_lock; /*serialize apbvt add/del entries*/ 399 u64 stats_nodes_created; 400 u64 stats_nodes_destroyed; 401 u64 stats_listen_created; 402 u64 stats_listen_destroyed; 403 u64 stats_listen_nodes_created; 404 u64 stats_listen_nodes_destroyed; 405 u64 stats_lpbs; 406 u64 stats_accepts; 407 u64 stats_rejects; 408 u64 stats_connect_errs; 409 u64 stats_passive_errs; 410 u64 stats_pkt_retrans; 411 u64 stats_backlog_drops; 412 struct irdma_puda_buf *(*form_cm_frame)(struct irdma_cm_node *cm_node, 413 struct irdma_kmem_info *options, 414 struct irdma_kmem_info *hdr, 415 struct irdma_mpa_priv_info *pdata, 416 u8 flags); 417 int (*cm_create_ah)(struct irdma_cm_node *cm_node, bool wait); 418 void (*cm_free_ah)(struct irdma_cm_node *cm_node); 419 }; 420 421 int irdma_schedule_cm_timer(struct irdma_cm_node *cm_node, 422 struct irdma_puda_buf *sqbuf, 423 enum irdma_timer_type type, int send_retrans, 424 int close_when_complete); 425 426 static inline u8 irdma_tos2dscp(u8 tos) 427 { 428 #define IRDMA_DSCP_S 2 429 #define IRDMA_DSCP_M (0x3f << IRDMA_DSCP_S) 430 return RS_32(tos, IRDMA_DSCP); 431 } 432 433 int irdma_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param); 434 int irdma_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len); 435 int irdma_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param); 436 int irdma_create_listen(struct iw_cm_id *cm_id, int backlog); 437 int irdma_destroy_listen(struct iw_cm_id *cm_id); 438 int irdma_add_arp(struct irdma_pci_f *rf, u32 *ip, u8 *mac); 439 void irdma_cm_teardown_connections(struct irdma_device *iwdev, u32 *ipaddr, 440 struct irdma_cm_info *nfo, 441 bool disconnect_all); 442 int irdma_cm_start(struct irdma_device *dev); 443 int irdma_cm_stop(struct irdma_device *dev); 444 bool irdma_ipv4_is_lpb(u32 loc_addr, u32 rem_addr); 445 bool irdma_ipv6_is_lpb(u32 *loc_addr, u32 *rem_addr); 446 int irdma_arp_table(struct irdma_pci_f *rf, u32 *ip_addr, 447 u8 *mac_addr, u32 action); 448 bool irdma_port_in_use(struct irdma_cm_core *cm_core, u16 port); 449 void irdma_send_ack(struct irdma_cm_node *cm_node); 450 void irdma_lpb_nop(struct irdma_sc_qp *qp); 451 void irdma_rem_ref_cm_node(struct irdma_cm_node *cm_node); 452 void irdma_add_conn_est_qh(struct irdma_cm_node *cm_node); 453 #endif /* IRDMA_CM_H */ 454