osd_initiator.h 14 KB

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