1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
3 /* Authors: Cheng Xu <chengyou@linux.alibaba.com> */
4 /* Kai Shen <kaishen@linux.alibaba.com> */
5 /* Copyright (c) 2020-2022, Alibaba Group. */
7 /* Authors: Bernard Metzler <bmt@zurich.ibm.com> */
8 /* Greg Joyce <greg@opengridcomputing.com> */
9 /* Copyright (c) 2008-2019, IBM Corporation */
10 /* Copyright (c) 2017, Open Grid Computing, Inc. */
12 #ifndef __ERDMA_CM_H__
13 #define __ERDMA_CM_H__
15 #include <linux/tcp.h>
17 #include <rdma/iw_cm.h>
19 /* iWarp MPA protocol defs */
20 #define MPA_REVISION_EXT_1 129
21 #define MPA_MAX_PRIVDATA RDMA_MAX_PRIVATE_DATA
22 #define MPA_KEY_REQ "MPA ID Req Frame"
23 #define MPA_KEY_REP "MPA ID Rep Frame"
24 #define MPA_KEY_SIZE 16
25 #define MPA_DEFAULT_HDR_LEN 28
27 struct mpa_rr_params
{
33 * MPA request/response Hdr bits & fields
36 MPA_RR_FLAG_MARKERS
= cpu_to_be16(0x8000),
37 MPA_RR_FLAG_CRC
= cpu_to_be16(0x4000),
38 MPA_RR_FLAG_REJECT
= cpu_to_be16(0x2000),
39 MPA_RR_RESERVED
= cpu_to_be16(0x1f00),
40 MPA_RR_MASK_REVISION
= cpu_to_be16(0x00ff)
44 * MPA request/reply header
48 struct mpa_rr_params params
;
51 struct erdma_mpa_ext
{
57 MPA_EXT_FLAG_CC
= cpu_to_be32(0x0000000f),
60 struct erdma_mpa_info
{
61 struct mpa_rr hdr
; /* peer mpa hdr in host byte order */
62 struct erdma_mpa_ext ext_data
;
67 struct erdma_sk_upcalls
{
68 void (*sk_state_change
)(struct sock
*sk
);
69 void (*sk_data_ready
)(struct sock
*sk
, int bytes
);
70 void (*sk_error_report
)(struct sock
*sk
);
75 enum erdma_cep_state
{
76 ERDMA_EPSTATE_IDLE
= 1,
77 ERDMA_EPSTATE_LISTENING
,
78 ERDMA_EPSTATE_CONNECTING
,
79 ERDMA_EPSTATE_AWAIT_MPAREQ
,
80 ERDMA_EPSTATE_RECVD_MPAREQ
,
81 ERDMA_EPSTATE_AWAIT_MPAREP
,
82 ERDMA_EPSTATE_RDMA_MODE
,
87 struct iw_cm_id
*cm_id
;
88 struct erdma_dev
*dev
;
89 struct list_head devq
;
93 wait_queue_head_t waitq
;
94 enum erdma_cep_state state
;
96 struct list_head listenq
;
97 struct erdma_cep
*listen_cep
;
102 struct erdma_cm_work
*mpa_timer
;
103 struct list_head work_freelist
;
105 struct erdma_mpa_info mpa
;
110 /* hold user's private data. */
113 /* Saved upcalls of socket llp.sock */
114 void (*sk_state_change
)(struct sock
*sk
);
115 void (*sk_data_ready
)(struct sock
*sk
);
116 void (*sk_error_report
)(struct sock
*sk
);
119 #define MPAREQ_TIMEOUT (HZ * 20)
120 #define MPAREP_TIMEOUT (HZ * 10)
121 #define CONNECT_TIMEOUT (HZ * 10)
123 enum erdma_work_type
{
124 ERDMA_CM_WORK_ACCEPT
= 1,
125 ERDMA_CM_WORK_READ_MPAHDR
,
126 ERDMA_CM_WORK_CLOSE_LLP
, /* close socket */
127 ERDMA_CM_WORK_PEER_CLOSE
, /* socket indicated peer close */
128 ERDMA_CM_WORK_MPATIMEOUT
,
129 ERDMA_CM_WORK_CONNECTED
,
130 ERDMA_CM_WORK_CONNECTTIMEOUT
133 struct erdma_cm_work
{
134 struct delayed_work work
;
135 struct list_head list
;
136 enum erdma_work_type type
;
137 struct erdma_cep
*cep
;
140 #define to_sockaddr_in(a) (*(struct sockaddr_in *)(&(a)))
142 static inline int getname_peer(struct socket
*s
, struct sockaddr_storage
*a
)
144 return s
->ops
->getname(s
, (struct sockaddr
*)a
, 1);
147 static inline int getname_local(struct socket
*s
, struct sockaddr_storage
*a
)
149 return s
->ops
->getname(s
, (struct sockaddr
*)a
, 0);
152 int erdma_connect(struct iw_cm_id
*id
, struct iw_cm_conn_param
*param
);
153 int erdma_accept(struct iw_cm_id
*id
, struct iw_cm_conn_param
*param
);
154 int erdma_reject(struct iw_cm_id
*id
, const void *pdata
, u8 plen
);
155 int erdma_create_listen(struct iw_cm_id
*id
, int backlog
);
156 int erdma_destroy_listen(struct iw_cm_id
*id
);
158 void erdma_cep_get(struct erdma_cep
*ceq
);
159 void erdma_cep_put(struct erdma_cep
*ceq
);
160 int erdma_cm_queue_work(struct erdma_cep
*ceq
, enum erdma_work_type type
);
162 int erdma_cm_init(void);
163 void erdma_cm_exit(void);
165 #define sk_to_cep(sk) ((struct erdma_cep *)((sk)->sk_user_data))