1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * fs/hmdfs/comm/transport.h
4 *
5 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
6 */
7
8#ifndef HMDFS_TRANSPORT_H
9#define HMDFS_TRANSPORT_H
10
11#include "connection.h"
12
13#define ENCRYPT_FLAG 1
14#define DECRYPT_FLAG 0
15
16struct aeadcrypt_result {
17	struct completion completion;
18	int err;
19};
20
21#define ADAPTER_MESSAGE_LENGTH (1024 * 1024 + 1024) // 1M + 1K
22#define MAX_RECV_SIZE sizeof(struct hmdfs_head_cmd)
23
24#define TCP_KVEC_HEAD 0
25#define TCP_KVEC_DATA 1
26
27enum TCP_KVEC_FILE_ELE_INDEX {
28	TCP_KVEC_FILE_PARA = 1,
29	TCP_KVEC_FILE_CONTENT = 2,
30};
31
32enum TCP_KVEC_TYPE {
33	TCP_KVEC_ELE_SINGLE = 1,
34	TCP_KVEC_ELE_DOUBLE = 2,
35	TCP_KVEC_ELE_TRIPLE = 3,
36};
37
38#define TCP_RECV_TIMEOUT     2
39#define MAX_RECV_RETRY_TIMES 2
40
41#ifndef SO_RCVTIMEO
42#define SO_RCVTIMEO SO_RCVTIMEO_OLD
43#endif
44
45struct tcp_handle {
46	struct connection *connect;
47	int recvbuf_maxsize;
48	struct mutex close_mutex;
49	/*
50	 * To achieve atomicity.
51	 *
52	 * The sock lock held at the tcp layer may be temporally released at
53	 * `sk_wait_event()` when waiting for sock buffer. From this point on,
54	 * threads serialized at the initial call to `lock_sock()` contained
55	 * in `tcp_sendmsg()` can proceed, resuling in intermixed messages.
56	 */
57	struct mutex send_mutex;
58	struct socket *sock;
59	int fd;
60	struct kmem_cache *recv_cache;
61	struct task_struct *recv_task;
62};
63
64void hmdfs_get_connection(struct hmdfs_peer *peer);
65void hmdfs_reget_connection(struct connection *conn);
66struct connection *hmdfs_get_conn_tcp(struct hmdfs_peer *node, int socket_fd,
67				      uint8_t *master_key, uint8_t status);
68void tcp_stop_connect(struct connection *connect);
69uint32_t hmdfs_tcpi_rtt(struct hmdfs_peer *node);
70void tcp_close_socket(struct tcp_handle *tcp);
71
72#ifdef CONFIG_HMDFS_FS_ENCRYPTION
73int tcp_send_rekey_request(struct connection *connect);
74#endif
75
76#endif
77