Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 1 | /* 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 | |
| 12 | struct ksmbd_conn; |
| 13 | struct ksmbd_session; |
| 14 | struct ksmbd_tree_connect; |
| 15 | |
| 16 | enum { |
| 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 */ |
| 23 | struct 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 Jeon | e506649 | 2021-03-30 12:35:23 +0900 | [diff] [blame] | 30 | void *request_buf; |
Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 31 | /* Response buffer */ |
Namjae Jeon | e506649 | 2021-03-30 12:35:23 +0900 | [diff] [blame] | 32 | void *response_buf; |
Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 33 | |
| 34 | /* Read data buffer */ |
Namjae Jeon | e506649 | 2021-03-30 12:35:23 +0900 | [diff] [blame] | 35 | void *aux_payload_buf; |
Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 36 | |
| 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 Jeon | 3867369 | 2021-07-08 12:32:27 +0900 | [diff] [blame] | 46 | u64 compound_fid; |
| 47 | u64 compound_pfid; |
| 48 | u64 compound_sid; |
Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 49 | |
| 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 Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 73 | |
| 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 Jeon | 8a89331 | 2021-06-25 13:43:37 +0900 | [diff] [blame] | 89 | /** |
| 90 | * ksmbd_resp_buf_next - Get next buffer on compound response. |
| 91 | * @work: smb work containing response buffer |
| 92 | */ |
| 93 | static inline void *ksmbd_resp_buf_next(struct ksmbd_work *work) |
| 94 | { |
Namjae Jeon | cb45172 | 2021-11-03 08:08:44 +0900 | [diff] [blame] | 95 | return work->response_buf + work->next_smb2_rsp_hdr_off + 4; |
Namjae Jeon | 8a89331 | 2021-06-25 13:43:37 +0900 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /** |
| 99 | * ksmbd_req_buf_next - Get next buffer on compound request. |
| 100 | * @work: smb work containing response buffer |
| 101 | */ |
| 102 | static inline void *ksmbd_req_buf_next(struct ksmbd_work *work) |
| 103 | { |
Namjae Jeon | cb45172 | 2021-11-03 08:08:44 +0900 | [diff] [blame] | 104 | return work->request_buf + work->next_smb2_rcv_hdr_off + 4; |
Namjae Jeon | 8a89331 | 2021-06-25 13:43:37 +0900 | [diff] [blame] | 105 | } |
Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 106 | |
| 107 | struct ksmbd_work *ksmbd_alloc_work_struct(void); |
| 108 | void ksmbd_free_work_struct(struct ksmbd_work *work); |
| 109 | |
| 110 | void ksmbd_work_pool_destroy(void); |
| 111 | int ksmbd_work_pool_init(void); |
| 112 | |
| 113 | int ksmbd_workqueue_init(void); |
| 114 | void ksmbd_workqueue_destroy(void); |
| 115 | bool ksmbd_queue_work(struct ksmbd_work *work); |
| 116 | |
| 117 | #endif /* __KSMBD_WORK_H__ */ |