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 /* 71 * Credit charge added to conn->outstanding_credits at receive time 72 * for the SMB2 PDU currently being processed, pending release. Zero 73 * once the charge has been returned (on the response or error path). 74 */ 75 unsigned short credit_charge; 76 77 /* response smb header size */ 78 unsigned int response_sz; 79 80 void *tr_buf; 81 /* Contiguous SMB2 compression transform owned by this work item. */ 82 void *compress_buf; 83 84 unsigned char state; 85 /* No response for cancelled request */ 86 bool send_no_response:1; 87 /* Request is encrypted */ 88 bool encrypted:1; 89 /* READ response should be wrapped in a compression transform. */ 90 bool compress_response:1; 91 /* Is this SYNC or ASYNC ksmbd_work */ 92 bool asynchronous:1; 93 bool need_invalidate_rkey:1; 94 95 unsigned int remote_key; 96 /* cancel works */ 97 int async_id; 98 void **cancel_argv; 99 void (*cancel_fn)(void **argv); 100 101 struct work_struct work; 102 /* List head at conn->requests */ 103 struct list_head request_entry; 104 /* List head at conn->async_requests */ 105 struct list_head async_request_entry; 106 struct list_head fp_entry; 107 }; 108 109 /** 110 * ksmbd_resp_buf_next - Get next buffer on compound response. 111 * @work: smb work containing response buffer 112 */ 113 static inline void *ksmbd_resp_buf_next(struct ksmbd_work *work) 114 { 115 return work->response_buf + work->next_smb2_rsp_hdr_off + 4; 116 } 117 118 /** 119 * ksmbd_resp_buf_curr - Get current buffer on compound response. 120 * @work: smb work containing response buffer 121 */ 122 static inline void *ksmbd_resp_buf_curr(struct ksmbd_work *work) 123 { 124 return work->response_buf + work->curr_smb2_rsp_hdr_off + 4; 125 } 126 127 /** 128 * ksmbd_req_buf_next - Get next buffer on compound request. 129 * @work: smb work containing response buffer 130 */ 131 static inline void *ksmbd_req_buf_next(struct ksmbd_work *work) 132 { 133 return work->request_buf + work->next_smb2_rcv_hdr_off + 4; 134 } 135 136 struct ksmbd_work *ksmbd_alloc_work_struct(void); 137 void ksmbd_free_work_struct(struct ksmbd_work *work); 138 139 void ksmbd_work_pool_destroy(void); 140 int ksmbd_work_pool_init(void); 141 142 int ksmbd_workqueue_init(void); 143 void ksmbd_workqueue_destroy(void); 144 bool ksmbd_queue_work(struct ksmbd_work *work); 145 int ksmbd_iov_pin_rsp_read(struct ksmbd_work *work, void *ib, int len, 146 void *aux_buf, unsigned int aux_size); 147 int ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len); 148 int allocate_interim_rsp_buf(struct ksmbd_work *work); 149 #endif /* __KSMBD_WORK_H__ */ 150