1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2015 - 2021 Intel Corporation */
6 #define IRDMA_MPA_REQUEST_ACCEPT 1
7 #define IRDMA_MPA_REQUEST_REJECT 2
9 /* IETF MPA -- defines */
10 #define IEFT_MPA_KEY_REQ "MPA ID Req Frame"
11 #define IEFT_MPA_KEY_REP "MPA ID Rep Frame"
12 #define IETF_MPA_KEY_SIZE 16
13 #define IETF_MPA_VER 1
14 #define IETF_MAX_PRIV_DATA_LEN 512
15 #define IETF_MPA_FRAME_SIZE 20
16 #define IETF_RTR_MSG_SIZE 4
17 #define IETF_MPA_V2_FLAG 0x10
18 #define SNDMARKER_SEQNMASK 0x000001ff
19 #define IRDMA_MAX_IETF_SIZE 32
21 /* IETF RTR MSG Fields */
22 #define IETF_PEER_TO_PEER 0x8000
23 #define IETF_FLPDU_ZERO_LEN 0x4000
24 #define IETF_RDMA0_WRITE 0x8000
25 #define IETF_RDMA0_READ 0x4000
26 #define IETF_NO_IRD_ORD 0x3fff
28 #define MAX_PORTS 65536
30 #define IRDMA_PASSIVE_STATE_INDICATED 0
31 #define IRDMA_DO_NOT_SEND_RESET_EVENT 1
32 #define IRDMA_SEND_RESET_EVENT 2
34 #define MAX_IRDMA_IFS 4
41 #define TCP_OPTIONS_PADDING 3
43 #define IRDMA_DEFAULT_RETRYS 64
44 #define IRDMA_DEFAULT_RETRANS 32
45 #define IRDMA_DEFAULT_TTL 0x40
46 #define IRDMA_DEFAULT_RTT_VAR 6
47 #define IRDMA_DEFAULT_SS_THRESH 0x3fffffff
48 #define IRDMA_DEFAULT_REXMIT_THRESH 8
50 #define IRDMA_RETRY_TIMEOUT HZ
51 #define IRDMA_SHORT_TIME 10
52 #define IRDMA_LONG_TIME (2 * HZ)
53 #define IRDMA_MAX_TIMEOUT ((unsigned long)(12 * HZ))
55 #define IRDMA_CM_HASHTABLE_SIZE 1024
56 #define IRDMA_CM_TCP_TIMER_INTERVAL 3000
57 #define IRDMA_CM_DEFAULT_MTU 1540
58 #define IRDMA_CM_DEFAULT_FRAME_CNT 10
59 #define IRDMA_CM_THREAD_STACK_SIZE 256
60 #define IRDMA_CM_DEFAULT_RCV_WND 64240
61 #define IRDMA_CM_DEFAULT_RCV_WND_SCALED 0x3FFFC
62 #define IRDMA_CM_DEFAULT_RCV_WND_SCALE 2
63 #define IRDMA_CM_DEFAULT_FREE_PKTS 10
64 #define IRDMA_CM_FREE_PKT_LO_WATERMARK 2
65 #define IRDMA_CM_DEFAULT_MSS 536
66 #define IRDMA_CM_DEFAULT_MPA_VER 2
67 #define IRDMA_CM_DEFAULT_SEQ 0x159bf75f
68 #define IRDMA_CM_DEFAULT_LOCAL_ID 0x3b47
69 #define IRDMA_CM_DEFAULT_SEQ2 0x18ed5740
70 #define IRDMA_CM_DEFAULT_LOCAL_ID2 0xb807
71 #define IRDMA_MAX_CM_BUF (IRDMA_MAX_IETF_SIZE + IETF_MAX_PRIV_DATA_LEN)
74 IETF_MPA_FLAGS_REJECT
= 0x20,
75 IETF_MPA_FLAGS_CRC
= 0x40,
76 IETF_MPA_FLAGS_MARKERS
= 0x80,
79 enum irdma_timer_type
{
80 IRDMA_TIMER_TYPE_SEND
,
81 IRDMA_TIMER_TYPE_CLOSE
,
88 OPTION_NUM_WINDOW_SCALE
,
91 OPTION_NUM_WRITE0
= 0xbc,
94 /* cm node transition states */
95 enum irdma_cm_node_state
{
96 IRDMA_CM_STATE_UNKNOWN
,
97 IRDMA_CM_STATE_INITED
,
98 IRDMA_CM_STATE_LISTENING
,
99 IRDMA_CM_STATE_SYN_RCVD
,
100 IRDMA_CM_STATE_SYN_SENT
,
101 IRDMA_CM_STATE_ONE_SIDE_ESTABLISHED
,
102 IRDMA_CM_STATE_ESTABLISHED
,
103 IRDMA_CM_STATE_ACCEPTING
,
104 IRDMA_CM_STATE_MPAREQ_SENT
,
105 IRDMA_CM_STATE_MPAREQ_RCVD
,
106 IRDMA_CM_STATE_MPAREJ_RCVD
,
107 IRDMA_CM_STATE_OFFLOADED
,
108 IRDMA_CM_STATE_FIN_WAIT1
,
109 IRDMA_CM_STATE_FIN_WAIT2
,
110 IRDMA_CM_STATE_CLOSE_WAIT
,
111 IRDMA_CM_STATE_TIME_WAIT
,
112 IRDMA_CM_STATE_LAST_ACK
,
113 IRDMA_CM_STATE_CLOSING
,
114 IRDMA_CM_STATE_LISTENER_DESTROYED
,
115 IRDMA_CM_STATE_CLOSED
,
129 SEND_RDMA_READ_ZERO
= 1,
130 SEND_RDMA_WRITE_ZERO
= 2,
133 enum irdma_tcpip_pkt_type
{
134 IRDMA_PKT_TYPE_UNKNOWN
,
136 IRDMA_PKT_TYPE_SYNACK
,
142 enum irdma_cm_listener_state
{
143 IRDMA_CM_LISTENER_PASSIVE_STATE
= 1,
144 IRDMA_CM_LISTENER_ACTIVE_STATE
= 2,
145 IRDMA_CM_LISTENER_EITHER_STATE
= 3,
149 enum irdma_cm_event_type
{
150 IRDMA_CM_EVENT_UNKNOWN
,
151 IRDMA_CM_EVENT_ESTABLISHED
,
152 IRDMA_CM_EVENT_MPA_REQ
,
153 IRDMA_CM_EVENT_MPA_CONNECT
,
154 IRDMA_CM_EVENT_MPA_ACCEPT
,
155 IRDMA_CM_EVENT_MPA_REJECT
,
156 IRDMA_CM_EVENT_MPA_ESTABLISHED
,
157 IRDMA_CM_EVENT_CONNECTED
,
158 IRDMA_CM_EVENT_RESET
,
159 IRDMA_CM_EVENT_ABORTED
,
163 u8 key
[IETF_MPA_KEY_SIZE
];
166 __be16 priv_data_len
;
170 struct ietf_rtr_msg
{
176 u8 key
[IETF_MPA_KEY_SIZE
];
179 __be16 priv_data_len
;
180 struct ietf_rtr_msg rtr_msg
;
195 struct option_windowscale
{
201 union all_known_options
{
203 struct option_base base
;
204 struct option_mss mss
;
205 struct option_windowscale windowscale
;
208 struct irdma_timer_entry
{
209 struct list_head list
;
210 unsigned long timetosend
; /* jiffies */
211 struct irdma_puda_buf
*sqbuf
;
217 int close_when_complete
;
220 /* CM context params */
221 struct irdma_cm_tcp_context
{
237 struct irdma_apbvt_entry
{
238 struct hlist_node hlist
;
243 struct irdma_cm_listener
{
244 struct list_head list
;
245 struct iw_cm_id
*cm_id
;
246 struct irdma_cm_core
*cm_core
;
247 struct irdma_device
*iwdev
;
248 struct list_head child_listen_list
;
249 struct irdma_apbvt_entry
*apbvt_entry
;
250 enum irdma_cm_listener_state listener_state
;
252 atomic_t pend_accepts_cnt
;
258 u8 loc_mac
[ETH_ALEN
];
265 struct irdma_kmem_info
{
270 struct irdma_mpa_priv_info
{
275 struct irdma_cm_node
{
276 struct irdma_qp
*iwqp
;
277 struct irdma_device
*iwdev
;
278 struct irdma_sc_dev
*dev
;
279 struct irdma_cm_tcp_context tcp_cntxt
;
280 struct irdma_cm_core
*cm_core
;
281 struct irdma_timer_entry
*send_entry
;
282 struct irdma_timer_entry
*close_entry
;
283 struct irdma_cm_listener
*listener
;
284 struct list_head timer_entry
;
285 struct list_head reset_entry
;
286 struct list_head teardown_entry
;
287 struct irdma_apbvt_entry
*apbvt_entry
;
288 struct rcu_head rcu_head
;
289 struct irdma_mpa_priv_info pdata
;
290 struct irdma_sc_ah
*ah
;
292 struct ietf_mpa_v1 mpa_frame
;
293 struct ietf_mpa_v2 mpa_v2_frame
;
295 struct irdma_kmem_info mpa_hdr
;
296 struct iw_cm_id
*cm_id
;
297 struct hlist_node list
;
298 struct completion establish_comp
;
299 spinlock_t retrans_list_lock
; /* protect CM node rexmit updates*/
300 atomic_t passive_state
;
302 enum irdma_cm_node_state state
;
303 enum send_rdma0 send_rdma0_op
;
304 enum mpa_frame_ver mpa_frame_rev
;
305 u32 loc_addr
[4], rem_addr
[4];
306 u16 loc_port
, rem_port
;
314 u8 pdata_buf
[IETF_MAX_PRIV_DATA_LEN
];
315 u8 loc_mac
[ETH_ALEN
];
316 u8 rem_mac
[ETH_ALEN
];
328 /* Used by internal CM APIs to pass CM information*/
329 struct irdma_cm_info
{
330 struct iw_cm_id
*cm_id
;
343 struct irdma_cm_event
{
344 enum irdma_cm_event_type type
;
345 struct irdma_cm_info cm_info
;
346 struct work_struct event_work
;
347 struct irdma_cm_node
*cm_node
;
350 struct irdma_cm_core
{
351 struct irdma_device
*iwdev
;
352 struct irdma_sc_dev
*dev
;
353 struct list_head listen_list
;
354 DECLARE_HASHTABLE(cm_hash_tbl
, 8);
355 DECLARE_HASHTABLE(apbvt_hash_tbl
, 8);
356 struct timer_list tcp_timer
;
357 struct workqueue_struct
*event_wq
;
358 spinlock_t ht_lock
; /* protect CM node (active side) list */
359 spinlock_t listen_list_lock
; /* protect listener list */
360 spinlock_t apbvt_lock
; /*serialize apbvt add/del entries*/
361 u64 stats_nodes_created
;
362 u64 stats_nodes_destroyed
;
363 u64 stats_listen_created
;
364 u64 stats_listen_destroyed
;
365 u64 stats_listen_nodes_created
;
366 u64 stats_listen_nodes_destroyed
;
370 u64 stats_connect_errs
;
371 u64 stats_passive_errs
;
372 u64 stats_pkt_retrans
;
373 u64 stats_backlog_drops
;
374 struct irdma_puda_buf
*(*form_cm_frame
)(struct irdma_cm_node
*cm_node
,
375 struct irdma_kmem_info
*options
,
376 struct irdma_kmem_info
*hdr
,
377 struct irdma_mpa_priv_info
*pdata
,
379 int (*cm_create_ah
)(struct irdma_cm_node
*cm_node
, bool wait
);
380 void (*cm_free_ah
)(struct irdma_cm_node
*cm_node
);
383 int irdma_schedule_cm_timer(struct irdma_cm_node
*cm_node
,
384 struct irdma_puda_buf
*sqbuf
,
385 enum irdma_timer_type type
, int send_retrans
,
386 int close_when_complete
);
388 static inline u8
irdma_tos2dscp(u8 tos
)
390 #define IRDMA_DSCP_VAL GENMASK(7, 2)
391 return (u8
)FIELD_GET(IRDMA_DSCP_VAL
, tos
);
394 int irdma_accept(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
);
395 int irdma_reject(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
);
396 int irdma_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
);
397 int irdma_create_listen(struct iw_cm_id
*cm_id
, int backlog
);
398 int irdma_destroy_listen(struct iw_cm_id
*cm_id
);
399 int irdma_add_arp(struct irdma_pci_f
*rf
, u32
*ip
, bool ipv4
, const u8
*mac
);
400 void irdma_cm_teardown_connections(struct irdma_device
*iwdev
, u32
*ipaddr
,
401 struct irdma_cm_info
*nfo
,
402 bool disconnect_all
);
403 int irdma_cm_start(struct irdma_device
*dev
);
404 int irdma_cm_stop(struct irdma_device
*dev
);
405 bool irdma_ipv4_is_lpb(u32 loc_addr
, u32 rem_addr
);
406 bool irdma_ipv6_is_lpb(u32
*loc_addr
, u32
*rem_addr
);
407 int irdma_arp_table(struct irdma_pci_f
*rf
, u32
*ip_addr
, bool ipv4
,
408 const u8
*mac_addr
, u32 action
);
409 void irdma_if_notify(struct irdma_device
*iwdev
, struct net_device
*netdev
,
410 u32
*ipaddr
, bool ipv4
, bool ifup
);
411 bool irdma_port_in_use(struct irdma_cm_core
*cm_core
, u16 port
);
412 void irdma_send_ack(struct irdma_cm_node
*cm_node
);
413 void irdma_lpb_nop(struct irdma_sc_qp
*qp
);
414 void irdma_rem_ref_cm_node(struct irdma_cm_node
*cm_node
);
415 void irdma_add_conn_est_qh(struct irdma_cm_node
*cm_node
);
416 #endif /* IRDMA_CM_H */