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