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 #define KSMBD_WORK_INLINE_IOVS 4 17 18 enum { 19 KSMBD_WORK_ACTIVE = 0, 20 KSMBD_WORK_CANCELLED, 21 KSMBD_WORK_CLOSED, 22 }; 23 24 struct aux_read { 25 void *buf; 26 struct list_head entry; 27 }; 28 29 /* one of these for every pending CIFS request at the connection */ 30 struct ksmbd_work { 31 /* Server corresponding to this mid */ 32 struct ksmbd_conn *conn; 33 struct ksmbd_session *sess; 34 struct ksmbd_tree_connect *tcon; 35 36 /* Pointer to received SMB header */ 37 void *request_buf; 38 /* Response buffer */ 39 void *response_buf; 40 41 struct list_head aux_read_list; 42 43 struct kvec *iov; 44 int iov_alloc_cnt; 45 int iov_cnt; 46 int iov_idx; 47 struct kvec iov_inline[KSMBD_WORK_INLINE_IOVS]; 48 49 /* Next cmd hdr in compound req buf*/ 50 int next_smb2_rcv_hdr_off; 51 /* Next cmd hdr in compound rsp buf*/ 52 int next_smb2_rsp_hdr_off; 53 /* Current cmd hdr in compound rsp buf*/ 54 int curr_smb2_rsp_hdr_off; 55 56 /* 57 * Current Local FID assigned compound response if SMB2 CREATE 58 * command is present in compound request 59 */ 60 u64 compound_fid; 61 u64 compound_pfid; 62 u64 compound_sid; 63 __le32 compound_status; 64 65 const struct cred *saved_cred; 66 67 /* Number of granted credits */ 68 unsigned int credits_granted; 69 70 /* response smb header size */ 71 unsigned int response_sz; 72 73 void *tr_buf; 74 /* Contiguous SMB2 compression transform owned by this work item. */ 75 void *compress_buf; 76 77 unsigned char state; 78 /* No response for cancelled request */ 79 bool send_no_response:1; 80 /* Request is encrypted */ 81 bool encrypted:1; 82 /* READ response should be wrapped in a compression transform. */ 83 bool compress_response:1; 84 /* Is this SYNC or ASYNC ksmbd_work */ 85 bool asynchronous:1; 86 bool need_invalidate_rkey:1; 87 88 unsigned int remote_key; 89 /* cancel works */ 90 int async_id; 91 void **cancel_argv; 92 void (*cancel_fn)(void **argv); 93 94 struct work_struct work; 95 /* List head at conn->requests */ 96 struct list_head request_entry; 97 /* List head at conn->async_requests */ 98 struct list_head async_request_entry; 99 struct list_head fp_entry; 100 }; 101 102 /** 103 * ksmbd_resp_buf_next - Get next buffer on compound response. 104 * @work: smb work containing response buffer 105 */ 106 static inline void *ksmbd_resp_buf_next(struct ksmbd_work *work) 107 { 108 return work->response_buf + work->next_smb2_rsp_hdr_off + 4; 109 } 110 111 /** 112 * ksmbd_resp_buf_curr - Get current buffer on compound response. 113 * @work: smb work containing response buffer 114 */ 115 static inline void *ksmbd_resp_buf_curr(struct ksmbd_work *work) 116 { 117 return work->response_buf + work->curr_smb2_rsp_hdr_off + 4; 118 } 119 120 /** 121 * ksmbd_req_buf_next - Get next buffer on compound request. 122 * @work: smb work containing response buffer 123 */ 124 static inline void *ksmbd_req_buf_next(struct ksmbd_work *work) 125 { 126 return work->request_buf + work->next_smb2_rcv_hdr_off + 4; 127 } 128 129 struct ksmbd_work *ksmbd_alloc_work_struct(void); 130 void ksmbd_free_work_struct(struct ksmbd_work *work); 131 132 void ksmbd_work_pool_destroy(void); 133 int ksmbd_work_pool_init(void); 134 135 int ksmbd_workqueue_init(void); 136 void ksmbd_workqueue_destroy(void); 137 bool ksmbd_queue_work(struct ksmbd_work *work); 138 int ksmbd_iov_pin_rsp_read(struct ksmbd_work *work, void *ib, int len, 139 void *aux_buf, unsigned int aux_size); 140 int ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len); 141 int allocate_interim_rsp_buf(struct ksmbd_work *work); 142 #endif /* __KSMBD_WORK_H__ */ 143