blob: 5ece58e40c97970ecea27e30dd11ffed82246877 [file] [log] [blame]
Namjae Jeon0626e662021-03-16 13:07:11 +09001/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Copyright (C) 2019 Samsung Electronics Co., Ltd.
4 */
5
6#ifndef __KSMBD_WORK_H__
7#define __KSMBD_WORK_H__
8
9#include <linux/ctype.h>
10#include <linux/workqueue.h>
11
12struct ksmbd_conn;
13struct ksmbd_session;
14struct ksmbd_tree_connect;
15
16enum {
17 KSMBD_WORK_ACTIVE = 0,
18 KSMBD_WORK_CANCELLED,
19 KSMBD_WORK_CLOSED,
20};
21
22/* one of these for every pending CIFS request at the connection */
23struct ksmbd_work {
24 /* Server corresponding to this mid */
25 struct ksmbd_conn *conn;
26 struct ksmbd_session *sess;
27 struct ksmbd_tree_connect *tcon;
28
29 /* Pointer to received SMB header */
Namjae Jeone5066492021-03-30 12:35:23 +090030 void *request_buf;
Namjae Jeon0626e662021-03-16 13:07:11 +090031 /* Response buffer */
Namjae Jeone5066492021-03-30 12:35:23 +090032 void *response_buf;
Namjae Jeon0626e662021-03-16 13:07:11 +090033
34 /* Read data buffer */
Namjae Jeone5066492021-03-30 12:35:23 +090035 void *aux_payload_buf;
Namjae Jeon0626e662021-03-16 13:07:11 +090036
37 /* Next cmd hdr in compound req buf*/
38 int next_smb2_rcv_hdr_off;
39 /* Next cmd hdr in compound rsp buf*/
40 int next_smb2_rsp_hdr_off;
41
42 /*
43 * Current Local FID assigned compound response if SMB2 CREATE
44 * command is present in compound request
45 */
Namjae Jeon38673692021-07-08 12:32:27 +090046 u64 compound_fid;
47 u64 compound_pfid;
48 u64 compound_sid;
Namjae Jeon0626e662021-03-16 13:07:11 +090049
50 const struct cred *saved_cred;
51
52 /* Number of granted credits */
53 unsigned int credits_granted;
54
55 /* response smb header size */
56 unsigned int resp_hdr_sz;
57 unsigned int response_sz;
58 /* Read data count */
59 unsigned int aux_payload_sz;
60
61 void *tr_buf;
62
63 unsigned char state;
64 /* Multiple responses for one request e.g. SMB ECHO */
65 bool multiRsp:1;
66 /* No response for cancelled request */
67 bool send_no_response:1;
68 /* Request is encrypted */
69 bool encrypted:1;
70 /* Is this SYNC or ASYNC ksmbd_work */
71 bool syncronous:1;
72 bool need_invalidate_rkey:1;
Namjae Jeon0626e662021-03-16 13:07:11 +090073
74 unsigned int remote_key;
75 /* cancel works */
76 int async_id;
77 void **cancel_argv;
78 void (*cancel_fn)(void **argv);
79
80 struct work_struct work;
81 /* List head at conn->requests */
82 struct list_head request_entry;
83 /* List head at conn->async_requests */
84 struct list_head async_request_entry;
85 struct list_head fp_entry;
86 struct list_head interim_entry;
87};
88
Namjae Jeon8a893312021-06-25 13:43:37 +090089/**
90 * ksmbd_resp_buf_next - Get next buffer on compound response.
91 * @work: smb work containing response buffer
92 */
93static inline void *ksmbd_resp_buf_next(struct ksmbd_work *work)
94{
Namjae Jeoncb451722021-11-03 08:08:44 +090095 return work->response_buf + work->next_smb2_rsp_hdr_off + 4;
Namjae Jeon8a893312021-06-25 13:43:37 +090096}
97
98/**
99 * ksmbd_req_buf_next - Get next buffer on compound request.
100 * @work: smb work containing response buffer
101 */
102static inline void *ksmbd_req_buf_next(struct ksmbd_work *work)
103{
Namjae Jeoncb451722021-11-03 08:08:44 +0900104 return work->request_buf + work->next_smb2_rcv_hdr_off + 4;
Namjae Jeon8a893312021-06-25 13:43:37 +0900105}
Namjae Jeon0626e662021-03-16 13:07:11 +0900106
107struct ksmbd_work *ksmbd_alloc_work_struct(void);
108void ksmbd_free_work_struct(struct ksmbd_work *work);
109
110void ksmbd_work_pool_destroy(void);
111int ksmbd_work_pool_init(void);
112
113int ksmbd_workqueue_init(void);
114void ksmbd_workqueue_destroy(void);
115bool ksmbd_queue_work(struct ksmbd_work *work);
116
117#endif /* __KSMBD_WORK_H__ */