[SCSI] libosd: Define an osd_dev wrapper to retrieve the request_queue
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / scsi / osd_initiator.h
CommitLineData
de258bf5
BH
1/*
2 * osd_initiator.h - OSD initiator API definition
3 *
4 * Copyright (C) 2008 Panasas Inc. All rights reserved.
5 *
6 * Authors:
7 * Boaz Harrosh <bharrosh@panasas.com>
8 * Benny Halevy <bhalevy@panasas.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 *
13 */
14#ifndef __OSD_INITIATOR_H__
15#define __OSD_INITIATOR_H__
16
17#include "osd_protocol.h"
18#include "osd_types.h"
19
20#include <linux/blkdev.h>
fc2fac5b 21#include <scsi/scsi_device.h>
de258bf5
BH
22
23/* Note: "NI" in comments below means "Not Implemented yet" */
24
c6572c98
BH
25/* Configure of code:
26 * #undef if you *don't* want OSD v1 support in runtime.
27 * If #defined the initiator will dynamically configure to encode OSD v1
28 * CDB's if the target is detected to be OSD v1 only.
29 * OSD v2 only commands, options, and attributes will be ignored if target
30 * is v1 only.
31 * If #defined will result in bigger/slower code (OK Slower maybe not)
32 * Q: Should this be CONFIG_SCSI_OSD_VER1_SUPPORT and set from Kconfig?
33 */
34#define OSD_VER1_SUPPORT y
35
36enum osd_std_version {
37 OSD_VER_NONE = 0,
38 OSD_VER1 = 1,
39 OSD_VER2 = 2,
40};
41
de258bf5
BH
42/*
43 * Object-based Storage Device.
44 * This object represents an OSD device.
45 * It is not a full linux device in any way. It is only
46 * a place to hang resources associated with a Linux
47 * request Q and some default properties.
48 */
49struct osd_dev {
50 struct scsi_device *scsi_device;
51 unsigned def_timeout;
c6572c98
BH
52
53#ifdef OSD_VER1_SUPPORT
54 enum osd_std_version version;
55#endif
de258bf5
BH
56};
57
b799bc7d
BH
58/* Retrieve/return osd_dev(s) for use by Kernel clients */
59struct osd_dev *osduld_path_lookup(const char *dev_name); /*Use IS_ERR/ERR_PTR*/
60void osduld_put_device(struct osd_dev *od);
61
95b05a7d
BH
62/* Add/remove test ioctls from external modules */
63typedef int (do_test_fn)(struct osd_dev *od, unsigned cmd, unsigned long arg);
64int osduld_register_test(unsigned ioctl, do_test_fn *do_test);
65void osduld_unregister_test(unsigned ioctl);
66
67/* These are called by uld at probe time */
de258bf5
BH
68void osd_dev_init(struct osd_dev *od, struct scsi_device *scsi_device);
69void osd_dev_fini(struct osd_dev *od);
70
1b9dce94
BH
71/* some hi level device operations */
72int osd_auto_detect_ver(struct osd_dev *od, void *caps); /* GFP_KERNEL */
fc2fac5b
BH
73static inline struct request_queue *osd_request_queue(struct osd_dev *od)
74{
75 return od->scsi_device->request_queue;
76}
1b9dce94 77
c6572c98
BH
78/* we might want to use function vector in the future */
79static inline void osd_dev_set_ver(struct osd_dev *od, enum osd_std_version v)
80{
81#ifdef OSD_VER1_SUPPORT
82 od->version = v;
83#endif
84}
85
de258bf5
BH
86struct osd_request;
87typedef void (osd_req_done_fn)(struct osd_request *or, void *private);
88
89struct osd_request {
90 struct osd_cdb cdb;
91 struct osd_data_out_integrity_info out_data_integ;
92 struct osd_data_in_integrity_info in_data_integ;
93
94 struct osd_dev *osd_dev;
95 struct request *request;
96
97 struct _osd_req_data_segment {
98 void *buff;
99 unsigned alloc_size; /* 0 here means: don't call kfree */
100 unsigned total_bytes;
101 } set_attr, enc_get_attr, get_attr;
102
103 struct _osd_io_info {
104 struct bio *bio;
105 u64 total_bytes;
106 struct request *req;
107 struct _osd_req_data_segment *last_seg;
108 u8 *pad_buff;
109 } out, in;
110
111 gfp_t alloc_flags;
112 unsigned timeout;
113 unsigned retries;
114 u8 sense[OSD_MAX_SENSE_LEN];
115 enum osd_attributes_mode attributes_mode;
116
117 osd_req_done_fn *async_done;
118 void *async_private;
119 int async_error;
120};
121
c6572c98
BH
122/* OSD Version control */
123static inline bool osd_req_is_ver1(struct osd_request *or)
124{
125#ifdef OSD_VER1_SUPPORT
126 return or->osd_dev->version == OSD_VER1;
127#else
128 return false;
129#endif
130}
131
de258bf5
BH
132/*
133 * How to use the osd library:
134 *
135 * osd_start_request
136 * Allocates a request.
137 *
138 * osd_req_*
139 * Call one of, to encode the desired operation.
140 *
141 * osd_add_{get,set}_attr
142 * Optionally add attributes to the CDB, list or page mode.
143 *
144 * osd_finalize_request
145 * Computes final data out/in offsets and signs the request,
146 * making it ready for execution.
147 *
148 * osd_execute_request
149 * May be called to execute it through the block layer. Other wise submit
150 * the associated block request in some other way.
151 *
152 * After execution:
153 * osd_req_decode_sense
154 * Decodes sense information to verify execution results.
155 *
156 * osd_req_decode_get_attr
157 * Retrieve osd_add_get_attr_list() values if used.
158 *
159 * osd_end_request
160 * Must be called to deallocate the request.
161 */
162
163/**
164 * osd_start_request - Allocate and initialize an osd_request
165 *
166 * @osd_dev: OSD device that holds the scsi-device and default values
167 * that the request is associated with.
168 * @gfp: The allocation flags to use for request allocation, and all
169 * subsequent allocations. This will be stored at
170 * osd_request->alloc_flags, can be changed by user later
171 *
172 * Allocate osd_request and initialize all members to the
173 * default/initial state.
174 */
175struct osd_request *osd_start_request(struct osd_dev *od, gfp_t gfp);
176
177enum osd_req_options {
178 OSD_REQ_FUA = 0x08, /* Force Unit Access */
179 OSD_REQ_DPO = 0x10, /* Disable Page Out */
180
181 OSD_REQ_BYPASS_TIMESTAMPS = 0x80,
182};
183
184/**
185 * osd_finalize_request - Sign request and prepare request for execution
186 *
187 * @or: osd_request to prepare
188 * @options: combination of osd_req_options bit flags or 0.
189 * @cap: A Pointer to an OSD_CAP_LEN bytes buffer that is received from
190 * The security manager as capabilities for this cdb.
191 * @cap_key: The cryptographic key used to sign the cdb/data. Can be null
192 * if NOSEC is used.
193 *
194 * The actual request and bios are only allocated here, so are the get_attr
195 * buffers that will receive the returned attributes. Copy's @cap to cdb.
196 * Sign the cdb/data with @cap_key.
197 */
198int osd_finalize_request(struct osd_request *or,
199 u8 options, const void *cap, const u8 *cap_key);
200
201/**
202 * osd_execute_request - Execute the request synchronously through block-layer
203 *
204 * @or: osd_request to Executed
205 *
206 * Calls blk_execute_rq to q the command and waits for completion.
207 */
208int osd_execute_request(struct osd_request *or);
209
210/**
211 * osd_execute_request_async - Execute the request without waitting.
212 *
213 * @or: - osd_request to Executed
214 * @done: (Optional) - Called at end of execution
215 * @private: - Will be passed to @done function
216 *
217 * Calls blk_execute_rq_nowait to queue the command. When execution is done
218 * optionally calls @done with @private as parameter. @or->async_error will
219 * have the return code
220 */
221int osd_execute_request_async(struct osd_request *or,
222 osd_req_done_fn *done, void *private);
223
98f3aea2
BH
224/**
225 * osd_req_decode_sense_full - Decode sense information after execution.
226 *
227 * @or: - osd_request to examine
228 * @osi - Recievs a more detailed error report information (optional).
229 * @silent - Do not print to dmsg (Even if enabled)
230 * @bad_obj_list - Some commands act on multiple objects. Failed objects will
231 * be recieved here (optional)
232 * @max_obj - Size of @bad_obj_list.
233 * @bad_attr_list - List of failing attributes (optional)
234 * @max_attr - Size of @bad_attr_list.
235 *
236 * After execution, sense + return code can be analyzed using this function. The
237 * return code is the final disposition on the error. So it is possible that a
238 * CHECK_CONDITION was returned from target but this will return NO_ERROR, for
239 * example on recovered errors. All parameters are optional if caller does
240 * not need any returned information.
241 * Note: This function will also dump the error to dmsg according to settings
242 * of the SCSI_OSD_DPRINT_SENSE Kconfig value. Set @silent if you know the
243 * command would routinely fail, to not spam the dmsg file.
244 */
245struct osd_sense_info {
246 int key; /* one of enum scsi_sense_keys */
247 int additional_code ; /* enum osd_additional_sense_codes */
248 union { /* Sense specific information */
249 u16 sense_info;
250 u16 cdb_field_offset; /* scsi_invalid_field_in_cdb */
251 };
252 union { /* Command specific information */
253 u64 command_info;
254 };
255
256 u32 not_initiated_command_functions; /* osd_command_functions_bits */
257 u32 completed_command_functions; /* osd_command_functions_bits */
258 struct osd_obj_id obj;
259 struct osd_attr attr;
260};
261
262int osd_req_decode_sense_full(struct osd_request *or,
263 struct osd_sense_info *osi, bool silent,
264 struct osd_obj_id *bad_obj_list, int max_obj,
265 struct osd_attr *bad_attr_list, int max_attr);
266
267static inline int osd_req_decode_sense(struct osd_request *or,
268 struct osd_sense_info *osi)
269{
270 return osd_req_decode_sense_full(or, osi, false, NULL, 0, NULL, 0);
271}
272
de258bf5
BH
273/**
274 * osd_end_request - return osd_request to free store
275 *
276 * @or: osd_request to free
277 *
278 * Deallocate all osd_request resources (struct req's, BIOs, buffers, etc.)
279 */
280void osd_end_request(struct osd_request *or);
281
282/*
283 * CDB Encoding
284 *
285 * Note: call only one of the following methods.
286 */
287
288/*
289 * Device commands
290 */
291void osd_req_set_master_seed_xchg(struct osd_request *or, ...);/* NI */
292void osd_req_set_master_key(struct osd_request *or, ...);/* NI */
293
294void osd_req_format(struct osd_request *or, u64 tot_capacity);
295
296/* list all partitions
297 * @list header must be initialized to zero on first run.
298 *
299 * Call osd_is_obj_list_done() to find if we got the complete list.
300 */
301int osd_req_list_dev_partitions(struct osd_request *or,
302 osd_id initial_id, struct osd_obj_id_list *list, unsigned nelem);
303
304void osd_req_flush_obsd(struct osd_request *or,
305 enum osd_options_flush_scope_values);
306
307void osd_req_perform_scsi_command(struct osd_request *or,
308 const u8 *cdb, ...);/* NI */
309void osd_req_task_management(struct osd_request *or, ...);/* NI */
310
311/*
312 * Partition commands
313 */
314void osd_req_create_partition(struct osd_request *or, osd_id partition);
315void osd_req_remove_partition(struct osd_request *or, osd_id partition);
316
317void osd_req_set_partition_key(struct osd_request *or,
318 osd_id partition, u8 new_key_id[OSD_CRYPTO_KEYID_SIZE],
319 u8 seed[OSD_CRYPTO_SEED_SIZE]);/* NI */
320
321/* list all collections in the partition
322 * @list header must be init to zero on first run.
323 *
324 * Call osd_is_obj_list_done() to find if we got the complete list.
325 */
326int osd_req_list_partition_collections(struct osd_request *or,
327 osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
328 unsigned nelem);
329
330/* list all objects in the partition
331 * @list header must be init to zero on first run.
332 *
333 * Call osd_is_obj_list_done() to find if we got the complete list.
334 */
335int osd_req_list_partition_objects(struct osd_request *or,
336 osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
337 unsigned nelem);
338
339void osd_req_flush_partition(struct osd_request *or,
340 osd_id partition, enum osd_options_flush_scope_values);
341
342/*
343 * Collection commands
344 */
345void osd_req_create_collection(struct osd_request *or,
346 const struct osd_obj_id *);/* NI */
347void osd_req_remove_collection(struct osd_request *or,
348 const struct osd_obj_id *);/* NI */
349
350/* list all objects in the collection */
351int osd_req_list_collection_objects(struct osd_request *or,
352 const struct osd_obj_id *, osd_id initial_id,
353 struct osd_obj_id_list *list, unsigned nelem);
354
355/* V2 only filtered list of objects in the collection */
356void osd_req_query(struct osd_request *or, ...);/* NI */
357
358void osd_req_flush_collection(struct osd_request *or,
359 const struct osd_obj_id *, enum osd_options_flush_scope_values);
360
361void osd_req_get_member_attrs(struct osd_request *or, ...);/* V2-only NI */
362void osd_req_set_member_attrs(struct osd_request *or, ...);/* V2-only NI */
363
364/*
365 * Object commands
366 */
367void osd_req_create_object(struct osd_request *or, struct osd_obj_id *);
368void osd_req_remove_object(struct osd_request *or, struct osd_obj_id *);
369
370void osd_req_write(struct osd_request *or,
62f469b5 371 const struct osd_obj_id *obj, u64 offset, struct bio *bio, u64 len);
0e35afbc
BH
372int osd_req_write_kern(struct osd_request *or,
373 const struct osd_obj_id *obj, u64 offset, void *buff, u64 len);
de258bf5
BH
374void osd_req_append(struct osd_request *or,
375 const struct osd_obj_id *, struct bio *data_out);/* NI */
376void osd_req_create_write(struct osd_request *or,
377 const struct osd_obj_id *, struct bio *data_out, u64 offset);/* NI */
378void osd_req_clear(struct osd_request *or,
379 const struct osd_obj_id *, u64 offset, u64 len);/* NI */
380void osd_req_punch(struct osd_request *or,
381 const struct osd_obj_id *, u64 offset, u64 len);/* V2-only NI */
382
383void osd_req_flush_object(struct osd_request *or,
384 const struct osd_obj_id *, enum osd_options_flush_scope_values,
385 /*V2*/ u64 offset, /*V2*/ u64 len);
386
387void osd_req_read(struct osd_request *or,
62f469b5 388 const struct osd_obj_id *obj, u64 offset, struct bio *bio, u64 len);
0e35afbc
BH
389int osd_req_read_kern(struct osd_request *or,
390 const struct osd_obj_id *obj, u64 offset, void *buff, u64 len);
de258bf5
BH
391
392/*
393 * Root/Partition/Collection/Object Attributes commands
394 */
395
396/* get before set */
397void osd_req_get_attributes(struct osd_request *or, const struct osd_obj_id *);
398
399/* set before get */
400void osd_req_set_attributes(struct osd_request *or, const struct osd_obj_id *);
401
402/*
403 * Attributes appended to most commands
404 */
405
406/* Attributes List mode (or V2 CDB) */
407 /*
408 * TODO: In ver2 if at finalize time only one attr was set and no gets,
409 * then the Attributes CDB mode is used automatically to save IO.
410 */
411
412/* set a list of attributes. */
413int osd_req_add_set_attr_list(struct osd_request *or,
414 const struct osd_attr *, unsigned nelem);
415
416/* get a list of attributes */
417int osd_req_add_get_attr_list(struct osd_request *or,
418 const struct osd_attr *, unsigned nelem);
419
420/*
421 * Attributes list decoding
422 * Must be called after osd_request.request was executed
423 * It is called in a loop to decode the returned get_attr
424 * (see osd_add_get_attr)
425 */
426int osd_req_decode_get_attr_list(struct osd_request *or,
427 struct osd_attr *, int *nelem, void **iterator);
428
429/* Attributes Page mode */
430
431/*
432 * Read an attribute page and optionally set one attribute
433 *
434 * Retrieves the attribute page directly to a user buffer.
435 * @attr_page_data shall stay valid until end of execution.
436 * See osd_attributes.h for common page structures
437 */
438int osd_req_add_get_attr_page(struct osd_request *or,
439 u32 page_id, void *attr_page_data, unsigned max_page_len,
440 const struct osd_attr *set_one);
441
442#endif /* __OSD_LIB_H__ */