1 /* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */
3 /* Authors: Bernard Metzler <bmt@zurich.ibm.com> */
4 /* Greg Joyce <greg@opengridcomputing.com> */
5 /* Copyright (c) 2008-2019, IBM Corporation */
6 /* Copyright (c) 2017, Open Grid Computing, Inc. */
12 #include <linux/tcp.h>
14 #include <rdma/iw_cm.h>
18 SIW_EPSTATE_LISTENING
,
19 SIW_EPSTATE_CONNECTING
,
20 SIW_EPSTATE_AWAIT_MPAREQ
,
21 SIW_EPSTATE_RECVD_MPAREQ
,
22 SIW_EPSTATE_AWAIT_MPAREP
,
23 SIW_EPSTATE_RDMA_MODE
,
28 struct mpa_rr hdr
; /* peer mpa hdr in host byte order */
29 struct mpa_v2_data v2_ctrl
;
30 struct mpa_v2_data v2_ctrl_req
;
38 struct iw_cm_id
*cm_id
;
39 struct siw_device
*sdev
;
40 struct list_head devq
;
44 wait_queue_head_t waitq
;
45 enum siw_cep_state state
;
47 struct list_head listenq
;
48 struct siw_cep
*listen_cep
;
53 struct siw_cm_work
*mpa_timer
;
54 struct list_head work_freelist
;
56 struct siw_mpa_info mpa
;
59 bool enhanced_rdma_conn_est
;
61 /* Saved upcalls of socket */
62 void (*sk_state_change
)(struct sock
*sk
);
63 void (*sk_data_ready
)(struct sock
*sk
);
64 void (*sk_write_space
)(struct sock
*sk
);
65 void (*sk_error_report
)(struct sock
*sk
);
69 * Connection initiator waits 10 seconds to receive an
70 * MPA reply after sending out MPA request. Reponder waits for
71 * 5 seconds for MPA request to arrive if new TCP connection
74 #define MPAREQ_TIMEOUT (HZ * 10)
75 #define MPAREP_TIMEOUT (HZ * 5)
78 SIW_CM_WORK_ACCEPT
= 1,
79 SIW_CM_WORK_READ_MPAHDR
,
80 SIW_CM_WORK_CLOSE_LLP
, /* close socket */
81 SIW_CM_WORK_PEER_CLOSE
, /* socket indicated peer close */
82 SIW_CM_WORK_MPATIMEOUT
86 struct delayed_work work
;
87 struct list_head list
;
88 enum siw_work_type type
;
92 #define to_sockaddr_in(a) (*(struct sockaddr_in *)(&(a)))
93 #define to_sockaddr_in6(a) (*(struct sockaddr_in6 *)(&(a)))
95 static inline int getname_peer(struct socket
*s
, struct sockaddr_storage
*a
)
97 return s
->ops
->getname(s
, (struct sockaddr
*)a
, 1);
100 static inline int getname_local(struct socket
*s
, struct sockaddr_storage
*a
)
102 return s
->ops
->getname(s
, (struct sockaddr
*)a
, 0);
105 static inline int ksock_recv(struct socket
*sock
, char *buf
, size_t size
,
108 struct kvec iov
= { buf
, size
};
109 struct msghdr msg
= { .msg_name
= NULL
, .msg_flags
= flags
};
111 return kernel_recvmsg(sock
, &msg
, &iov
, 1, size
, flags
);
114 int siw_connect(struct iw_cm_id
*id
, struct iw_cm_conn_param
*parm
);
115 int siw_accept(struct iw_cm_id
*id
, struct iw_cm_conn_param
*param
);
116 int siw_reject(struct iw_cm_id
*id
, const void *data
, u8 len
);
117 int siw_create_listen(struct iw_cm_id
*id
, int backlog
);
118 int siw_destroy_listen(struct iw_cm_id
*id
);
120 void siw_cep_get(struct siw_cep
*cep
);
121 void siw_cep_put(struct siw_cep
*cep
);
122 int siw_cm_queue_work(struct siw_cep
*cep
, enum siw_work_type type
);
124 int siw_cm_init(void);
125 void siw_cm_exit(void);
128 * TCP socket interface
130 #define sk_to_qp(sk) (((struct siw_cep *)((sk)->sk_user_data))->qp)
131 #define sk_to_cep(sk) ((struct siw_cep *)((sk)->sk_user_data))