osd_initiator.h 13 KB

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