osd_initiator.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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 <ooo@electrozaur.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 <scsi/osd_protocol.h>
  17. #include <scsi/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. unsigned def_timeout;
  46. #ifdef OSD_VER1_SUPPORT
  47. enum osd_std_version version;
  48. #endif
  49. };
  50. /* Unique Identification of an OSD device */
  51. struct osd_dev_info {
  52. unsigned systemid_len;
  53. u8 systemid[OSD_SYSTEMID_LEN];
  54. unsigned osdname_len;
  55. u8 *osdname;
  56. };
  57. /* Retrieve/return osd_dev(s) for use by Kernel clients
  58. * Use IS_ERR/ERR_PTR on returned "osd_dev *".
  59. */
  60. struct osd_dev *osduld_path_lookup(const char *dev_name);
  61. struct osd_dev *osduld_info_lookup(const struct osd_dev_info *odi);
  62. void osduld_put_device(struct osd_dev *od);
  63. const struct osd_dev_info *osduld_device_info(struct osd_dev *od);
  64. bool osduld_device_same(struct osd_dev *od, const struct osd_dev_info *odi);
  65. /* Add/remove test ioctls from external modules */
  66. typedef int (do_test_fn)(struct osd_dev *od, unsigned cmd, unsigned long arg);
  67. int osduld_register_test(unsigned ioctl, do_test_fn *do_test);
  68. void osduld_unregister_test(unsigned ioctl);
  69. /* These are called by uld at probe time */
  70. void osd_dev_init(struct osd_dev *od, struct scsi_device *scsi_device);
  71. void osd_dev_fini(struct osd_dev *od);
  72. /**
  73. * osd_auto_detect_ver - Detect the OSD version, return Unique Identification
  74. *
  75. * @od: OSD target lun handle
  76. * @caps: Capabilities authorizing OSD root read attributes access
  77. * @odi: Retrieved information uniquely identifying the osd target lun
  78. * Note: odi->osdname must be kfreed by caller.
  79. *
  80. * Auto detects the OSD version of the OSD target and sets the @od
  81. * accordingly. Meanwhile also returns the "system id" and "osd name" root
  82. * attributes which uniquely identify the OSD target. This member is usually
  83. * called by the ULD. ULD users should call osduld_device_info().
  84. * This rutine allocates osd requests and memory at GFP_KERNEL level and might
  85. * sleep.
  86. */
  87. int osd_auto_detect_ver(struct osd_dev *od,
  88. void *caps, struct osd_dev_info *odi);
  89. static inline struct request_queue *osd_request_queue(struct osd_dev *od)
  90. {
  91. return od->scsi_device->request_queue;
  92. }
  93. /* we might want to use function vector in the future */
  94. static inline void osd_dev_set_ver(struct osd_dev *od, enum osd_std_version v)
  95. {
  96. #ifdef OSD_VER1_SUPPORT
  97. od->version = v;
  98. #endif
  99. }
  100. static inline bool osd_dev_is_ver1(struct osd_dev *od)
  101. {
  102. #ifdef OSD_VER1_SUPPORT
  103. return od->version == OSD_VER1;
  104. #else
  105. return false;
  106. #endif
  107. }
  108. struct osd_request;
  109. typedef void (osd_req_done_fn)(struct osd_request *or, void *private);
  110. struct osd_request {
  111. struct osd_cdb cdb;
  112. struct osd_data_out_integrity_info out_data_integ;
  113. struct osd_data_in_integrity_info in_data_integ;
  114. struct osd_dev *osd_dev;
  115. struct request *request;
  116. struct _osd_req_data_segment {
  117. void *buff;
  118. unsigned alloc_size; /* 0 here means: don't call kfree */
  119. unsigned total_bytes;
  120. } cdb_cont, set_attr, enc_get_attr, get_attr;
  121. struct _osd_io_info {
  122. struct bio *bio;
  123. u64 total_bytes;
  124. u64 residual;
  125. struct request *req;
  126. struct _osd_req_data_segment *last_seg;
  127. u8 *pad_buff;
  128. } out, in;
  129. unsigned timeout;
  130. unsigned retries;
  131. unsigned sense_len;
  132. u8 sense[OSD_MAX_SENSE_LEN];
  133. enum osd_attributes_mode attributes_mode;
  134. osd_req_done_fn *async_done;
  135. void *async_private;
  136. blk_status_t async_error;
  137. int req_errors;
  138. };
  139. static inline bool osd_req_is_ver1(struct osd_request *or)
  140. {
  141. return osd_dev_is_ver1(or->osd_dev);
  142. }
  143. /*
  144. * How to use the osd library:
  145. *
  146. * osd_start_request
  147. * Allocates a request.
  148. *
  149. * osd_req_*
  150. * Call one of, to encode the desired operation.
  151. *
  152. * osd_add_{get,set}_attr
  153. * Optionally add attributes to the CDB, list or page mode.
  154. *
  155. * osd_finalize_request
  156. * Computes final data out/in offsets and signs the request,
  157. * making it ready for execution.
  158. *
  159. * osd_execute_request
  160. * May be called to execute it through the block layer. Other wise submit
  161. * the associated block request in some other way.
  162. *
  163. * After execution:
  164. * osd_req_decode_sense
  165. * Decodes sense information to verify execution results.
  166. *
  167. * osd_req_decode_get_attr
  168. * Retrieve osd_add_get_attr_list() values if used.
  169. *
  170. * osd_end_request
  171. * Must be called to deallocate the request.
  172. */
  173. /**
  174. * osd_start_request - Allocate and initialize an osd_request
  175. *
  176. * @osd_dev: OSD device that holds the scsi-device and default values
  177. * that the request is associated with.
  178. *
  179. * Allocate osd_request and initialize all members to the
  180. * default/initial state.
  181. */
  182. struct osd_request *osd_start_request(struct osd_dev *od);
  183. enum osd_req_options {
  184. OSD_REQ_FUA = 0x08, /* Force Unit Access */
  185. OSD_REQ_DPO = 0x10, /* Disable Page Out */
  186. OSD_REQ_BYPASS_TIMESTAMPS = 0x80,
  187. };
  188. /**
  189. * osd_finalize_request - Sign request and prepare request for execution
  190. *
  191. * @or: osd_request to prepare
  192. * @options: combination of osd_req_options bit flags or 0.
  193. * @cap: A Pointer to an OSD_CAP_LEN bytes buffer that is received from
  194. * The security manager as capabilities for this cdb.
  195. * @cap_key: The cryptographic key used to sign the cdb/data. Can be null
  196. * if NOSEC is used.
  197. *
  198. * The actual request and bios are only allocated here, so are the get_attr
  199. * buffers that will receive the returned attributes. Copy's @cap to cdb.
  200. * Sign the cdb/data with @cap_key.
  201. */
  202. int osd_finalize_request(struct osd_request *or,
  203. u8 options, const void *cap, const u8 *cap_key);
  204. /**
  205. * osd_execute_request - Execute the request synchronously through block-layer
  206. *
  207. * @or: osd_request to Executed
  208. *
  209. * Calls blk_execute_rq to q the command and waits for completion.
  210. */
  211. int osd_execute_request(struct osd_request *or);
  212. /**
  213. * osd_execute_request_async - Execute the request without waitting.
  214. *
  215. * @or: - osd_request to Executed
  216. * @done: (Optional) - Called at end of execution
  217. * @private: - Will be passed to @done function
  218. *
  219. * Calls blk_execute_rq_nowait to queue the command. When execution is done
  220. * optionally calls @done with @private as parameter. @or->async_error will
  221. * have the return code
  222. */
  223. int osd_execute_request_async(struct osd_request *or,
  224. osd_req_done_fn *done, void *private);
  225. /**
  226. * osd_req_decode_sense_full - Decode sense information after execution.
  227. *
  228. * @or: - osd_request to examine
  229. * @osi - Receives a more detailed error report information (optional).
  230. * @silent - Do not print to dmsg (Even if enabled)
  231. * @bad_obj_list - Some commands act on multiple objects. Failed objects will
  232. * be received here (optional)
  233. * @max_obj - Size of @bad_obj_list.
  234. * @bad_attr_list - List of failing attributes (optional)
  235. * @max_attr - Size of @bad_attr_list.
  236. *
  237. * After execution, osd_request results are analyzed using this function. The
  238. * return code is the final disposition on the error. So it is possible that a
  239. * CHECK_CONDITION was returned from target but this will return NO_ERROR, for
  240. * example on recovered errors. All parameters are optional if caller does
  241. * not need any returned information.
  242. * Note: This function will also dump the error to dmsg according to settings
  243. * of the SCSI_OSD_DPRINT_SENSE Kconfig value. Set @silent if you know the
  244. * command would routinely fail, to not spam the dmsg file.
  245. */
  246. /**
  247. * osd_err_priority - osd categorized return codes in ascending severity.
  248. *
  249. * The categories are borrowed from the pnfs_osd_errno enum.
  250. * See comments for translated Linux codes returned by osd_req_decode_sense.
  251. */
  252. enum osd_err_priority {
  253. OSD_ERR_PRI_NO_ERROR = 0,
  254. /* Recoverable, caller should clear_highpage() all pages */
  255. OSD_ERR_PRI_CLEAR_PAGES = 1, /* -EFAULT */
  256. OSD_ERR_PRI_RESOURCE = 2, /* -ENOMEM */
  257. OSD_ERR_PRI_BAD_CRED = 3, /* -EINVAL */
  258. OSD_ERR_PRI_NO_ACCESS = 4, /* -EACCES */
  259. OSD_ERR_PRI_UNREACHABLE = 5, /* any other */
  260. OSD_ERR_PRI_NOT_FOUND = 6, /* -ENOENT */
  261. OSD_ERR_PRI_NO_SPACE = 7, /* -ENOSPC */
  262. OSD_ERR_PRI_EIO = 8, /* -EIO */
  263. };
  264. struct osd_sense_info {
  265. enum osd_err_priority osd_err_pri;
  266. int key; /* one of enum scsi_sense_keys */
  267. int additional_code ; /* enum osd_additional_sense_codes */
  268. union { /* Sense specific information */
  269. u16 sense_info;
  270. u16 cdb_field_offset; /* scsi_invalid_field_in_cdb */
  271. };
  272. union { /* Command specific information */
  273. u64 command_info;
  274. };
  275. u32 not_initiated_command_functions; /* osd_command_functions_bits */
  276. u32 completed_command_functions; /* osd_command_functions_bits */
  277. struct osd_obj_id obj;
  278. struct osd_attr attr;
  279. };
  280. int osd_req_decode_sense_full(struct osd_request *or,
  281. struct osd_sense_info *osi, bool silent,
  282. struct osd_obj_id *bad_obj_list, int max_obj,
  283. struct osd_attr *bad_attr_list, int max_attr);
  284. static inline int osd_req_decode_sense(struct osd_request *or,
  285. struct osd_sense_info *osi)
  286. {
  287. return osd_req_decode_sense_full(or, osi, false, NULL, 0, NULL, 0);
  288. }
  289. /**
  290. * osd_end_request - return osd_request to free store
  291. *
  292. * @or: osd_request to free
  293. *
  294. * Deallocate all osd_request resources (struct req's, BIOs, buffers, etc.)
  295. */
  296. void osd_end_request(struct osd_request *or);
  297. /*
  298. * CDB Encoding
  299. *
  300. * Note: call only one of the following methods.
  301. */
  302. /*
  303. * Device commands
  304. */
  305. void osd_req_set_master_seed_xchg(struct osd_request *or, ...);/* NI */
  306. void osd_req_set_master_key(struct osd_request *or, ...);/* NI */
  307. void osd_req_format(struct osd_request *or, u64 tot_capacity);
  308. /* list all partitions
  309. * @list header must be initialized to zero on first run.
  310. *
  311. * Call osd_is_obj_list_done() to find if we got the complete list.
  312. */
  313. int osd_req_list_dev_partitions(struct osd_request *or,
  314. osd_id initial_id, struct osd_obj_id_list *list, unsigned nelem);
  315. void osd_req_flush_obsd(struct osd_request *or,
  316. enum osd_options_flush_scope_values);
  317. void osd_req_perform_scsi_command(struct osd_request *or,
  318. const u8 *cdb, ...);/* NI */
  319. void osd_req_task_management(struct osd_request *or, ...);/* NI */
  320. /*
  321. * Partition commands
  322. */
  323. void osd_req_create_partition(struct osd_request *or, osd_id partition);
  324. void osd_req_remove_partition(struct osd_request *or, osd_id partition);
  325. void osd_req_set_partition_key(struct osd_request *or,
  326. osd_id partition, u8 new_key_id[OSD_CRYPTO_KEYID_SIZE],
  327. u8 seed[OSD_CRYPTO_SEED_SIZE]);/* NI */
  328. /* list all collections in the partition
  329. * @list header must be init to zero on first run.
  330. *
  331. * Call osd_is_obj_list_done() to find if we got the complete list.
  332. */
  333. int osd_req_list_partition_collections(struct osd_request *or,
  334. osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
  335. unsigned nelem);
  336. /* list all objects in the partition
  337. * @list header must be init to zero on first run.
  338. *
  339. * Call osd_is_obj_list_done() to find if we got the complete list.
  340. */
  341. int osd_req_list_partition_objects(struct osd_request *or,
  342. osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
  343. unsigned nelem);
  344. void osd_req_flush_partition(struct osd_request *or,
  345. osd_id partition, enum osd_options_flush_scope_values);
  346. /*
  347. * Collection commands
  348. */
  349. void osd_req_create_collection(struct osd_request *or,
  350. const struct osd_obj_id *);/* NI */
  351. void osd_req_remove_collection(struct osd_request *or,
  352. const struct osd_obj_id *);/* NI */
  353. /* list all objects in the collection */
  354. int osd_req_list_collection_objects(struct osd_request *or,
  355. const struct osd_obj_id *, osd_id initial_id,
  356. struct osd_obj_id_list *list, unsigned nelem);
  357. /* V2 only filtered list of objects in the collection */
  358. void osd_req_query(struct osd_request *or, ...);/* NI */
  359. void osd_req_flush_collection(struct osd_request *or,
  360. const struct osd_obj_id *, enum osd_options_flush_scope_values);
  361. void osd_req_get_member_attrs(struct osd_request *or, ...);/* V2-only NI */
  362. void osd_req_set_member_attrs(struct osd_request *or, ...);/* V2-only NI */
  363. /*
  364. * Object commands
  365. */
  366. void osd_req_create_object(struct osd_request *or, struct osd_obj_id *);
  367. void osd_req_remove_object(struct osd_request *or, struct osd_obj_id *);
  368. void osd_req_write(struct osd_request *or,
  369. const struct osd_obj_id *obj, u64 offset, struct bio *bio, u64 len);
  370. int osd_req_write_kern(struct osd_request *or,
  371. const struct osd_obj_id *obj, u64 offset, void *buff, u64 len);
  372. void osd_req_append(struct osd_request *or,
  373. const struct osd_obj_id *, struct bio *data_out);/* NI */
  374. void osd_req_create_write(struct osd_request *or,
  375. const struct osd_obj_id *, struct bio *data_out, u64 offset);/* NI */
  376. void osd_req_clear(struct osd_request *or,
  377. const struct osd_obj_id *, u64 offset, u64 len);/* NI */
  378. void osd_req_punch(struct osd_request *or,
  379. const struct osd_obj_id *, u64 offset, u64 len);/* V2-only NI */
  380. void osd_req_flush_object(struct osd_request *or,
  381. const struct osd_obj_id *, enum osd_options_flush_scope_values,
  382. /*V2*/ u64 offset, /*V2*/ u64 len);
  383. void osd_req_read(struct osd_request *or,
  384. const struct osd_obj_id *obj, u64 offset, struct bio *bio, u64 len);
  385. int osd_req_read_kern(struct osd_request *or,
  386. const struct osd_obj_id *obj, u64 offset, void *buff, u64 len);
  387. /* Scatter/Gather write/read commands */
  388. int osd_req_write_sg(struct osd_request *or,
  389. const struct osd_obj_id *obj, struct bio *bio,
  390. const struct osd_sg_entry *sglist, unsigned numentries);
  391. int osd_req_read_sg(struct osd_request *or,
  392. const struct osd_obj_id *obj, struct bio *bio,
  393. const struct osd_sg_entry *sglist, unsigned numentries);
  394. int osd_req_write_sg_kern(struct osd_request *or,
  395. const struct osd_obj_id *obj, void **buff,
  396. const struct osd_sg_entry *sglist, unsigned numentries);
  397. int osd_req_read_sg_kern(struct osd_request *or,
  398. const struct osd_obj_id *obj, void **buff,
  399. const struct osd_sg_entry *sglist, unsigned numentries);
  400. /*
  401. * Root/Partition/Collection/Object Attributes commands
  402. */
  403. /* get before set */
  404. void osd_req_get_attributes(struct osd_request *or, const struct osd_obj_id *);
  405. /* set before get */
  406. void osd_req_set_attributes(struct osd_request *or, const struct osd_obj_id *);
  407. /*
  408. * Attributes appended to most commands
  409. */
  410. /* Attributes List mode (or V2 CDB) */
  411. /*
  412. * TODO: In ver2 if at finalize time only one attr was set and no gets,
  413. * then the Attributes CDB mode is used automatically to save IO.
  414. */
  415. /* set a list of attributes. */
  416. int osd_req_add_set_attr_list(struct osd_request *or,
  417. const struct osd_attr *, unsigned nelem);
  418. /* get a list of attributes */
  419. int osd_req_add_get_attr_list(struct osd_request *or,
  420. const struct osd_attr *, unsigned nelem);
  421. /*
  422. * Attributes list decoding
  423. * Must be called after osd_request.request was executed
  424. * It is called in a loop to decode the returned get_attr
  425. * (see osd_add_get_attr)
  426. */
  427. int osd_req_decode_get_attr_list(struct osd_request *or,
  428. struct osd_attr *, int *nelem, void **iterator);
  429. /* Attributes Page mode */
  430. /*
  431. * Read an attribute page and optionally set one attribute
  432. *
  433. * Retrieves the attribute page directly to a user buffer.
  434. * @attr_page_data shall stay valid until end of execution.
  435. * See osd_attributes.h for common page structures
  436. */
  437. int osd_req_add_get_attr_page(struct osd_request *or,
  438. u32 page_id, void *attr_page_data, unsigned max_page_len,
  439. const struct osd_attr *set_one);
  440. #endif /* __OSD_LIB_H__ */