You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sanboot.h 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #ifndef _IPXE_SANBOOT_H
  2. #define _IPXE_SANBOOT_H
  3. /** @file
  4. *
  5. * iPXE sanboot API
  6. *
  7. * The sanboot API provides methods for hooking, unhooking,
  8. * describing, and booting from SAN devices.
  9. */
  10. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  11. #include <ipxe/api.h>
  12. #include <ipxe/refcnt.h>
  13. #include <ipxe/list.h>
  14. #include <ipxe/uri.h>
  15. #include <ipxe/retry.h>
  16. #include <ipxe/process.h>
  17. #include <ipxe/blockdev.h>
  18. #include <config/sanboot.h>
  19. /** A SAN path */
  20. struct san_path {
  21. /** Containing SAN device */
  22. struct san_device *sandev;
  23. /** Path index */
  24. unsigned int index;
  25. /** SAN device URI */
  26. struct uri *uri;
  27. /** List of open/closed paths */
  28. struct list_head list;
  29. /** Underlying block device interface */
  30. struct interface block;
  31. /** Process */
  32. struct process process;
  33. /** Path status */
  34. int path_rc;
  35. };
  36. /** A SAN device */
  37. struct san_device {
  38. /** Reference count */
  39. struct refcnt refcnt;
  40. /** List of SAN devices */
  41. struct list_head list;
  42. /** Drive number */
  43. unsigned int drive;
  44. /** Command interface */
  45. struct interface command;
  46. /** Command timeout timer */
  47. struct retry_timer timer;
  48. /** Command status */
  49. int command_rc;
  50. /** Raw block device capacity */
  51. struct block_device_capacity capacity;
  52. /** Block size shift
  53. *
  54. * To allow for emulation of CD-ROM access, this represents
  55. * the left-shift required to translate from exposed logical
  56. * I/O blocks to underlying blocks.
  57. */
  58. unsigned int blksize_shift;
  59. /** Drive is a CD-ROM */
  60. int is_cdrom;
  61. /** Driver private data */
  62. void *priv;
  63. /** Number of paths */
  64. unsigned int paths;
  65. /** Current active path */
  66. struct san_path *active;
  67. /** List of opened SAN paths */
  68. struct list_head opened;
  69. /** List of closed SAN paths */
  70. struct list_head closed;
  71. /** SAN paths */
  72. struct san_path path[0];
  73. };
  74. /**
  75. * Calculate static inline sanboot API function name
  76. *
  77. * @v _prefix Subsystem prefix
  78. * @v _api_func API function
  79. * @ret _subsys_func Subsystem API function
  80. */
  81. #define SANBOOT_INLINE( _subsys, _api_func ) \
  82. SINGLE_API_INLINE ( SANBOOT_PREFIX_ ## _subsys, _api_func )
  83. /**
  84. * Provide a sanboot API implementation
  85. *
  86. * @v _prefix Subsystem prefix
  87. * @v _api_func API function
  88. * @v _func Implementing function
  89. */
  90. #define PROVIDE_SANBOOT( _subsys, _api_func, _func ) \
  91. PROVIDE_SINGLE_API ( SANBOOT_PREFIX_ ## _subsys, _api_func, _func )
  92. /**
  93. * Provide a static inline sanboot API implementation
  94. *
  95. * @v _prefix Subsystem prefix
  96. * @v _api_func API function
  97. */
  98. #define PROVIDE_SANBOOT_INLINE( _subsys, _api_func ) \
  99. PROVIDE_SINGLE_API_INLINE ( SANBOOT_PREFIX_ ## _subsys, _api_func )
  100. /* Include all architecture-independent sanboot API headers */
  101. #include <ipxe/null_sanboot.h>
  102. #include <ipxe/dummy_sanboot.h>
  103. #include <ipxe/efi/efi_block.h>
  104. /* Include all architecture-dependent sanboot API headers */
  105. #include <bits/sanboot.h>
  106. /**
  107. * Hook SAN device
  108. *
  109. * @v drive Drive number
  110. * @v uris List of URIs
  111. * @v count Number of URIs
  112. * @ret drive Drive number, or negative error
  113. */
  114. int san_hook ( unsigned int drive, struct uri **uris, unsigned int count );
  115. /**
  116. * Unhook SAN device
  117. *
  118. * @v drive Drive number
  119. */
  120. void san_unhook ( unsigned int drive );
  121. /**
  122. * Attempt to boot from a SAN device
  123. *
  124. * @v drive Drive number
  125. * @ret rc Return status code
  126. */
  127. int san_boot ( unsigned int drive );
  128. /**
  129. * Describe SAN device for SAN-booted operating system
  130. *
  131. * @v drive Drive number
  132. * @ret rc Return status code
  133. */
  134. int san_describe ( unsigned int drive );
  135. extern struct list_head san_devices;
  136. /** Iterate over all SAN devices */
  137. #define for_each_sandev( sandev ) \
  138. list_for_each_entry ( (sandev), &san_devices, list )
  139. /** There exist some SAN devices
  140. *
  141. * @ret existence Existence of SAN devices
  142. */
  143. static inline int have_sandevs ( void ) {
  144. return ( ! list_empty ( &san_devices ) );
  145. }
  146. /**
  147. * Get reference to SAN device
  148. *
  149. * @v sandev SAN device
  150. * @ret sandev SAN device
  151. */
  152. static inline __attribute__ (( always_inline )) struct san_device *
  153. sandev_get ( struct san_device *sandev ) {
  154. ref_get ( &sandev->refcnt );
  155. return sandev;
  156. }
  157. /**
  158. * Drop reference to SAN device
  159. *
  160. * @v sandev SAN device
  161. */
  162. static inline __attribute__ (( always_inline )) void
  163. sandev_put ( struct san_device *sandev ) {
  164. ref_put ( &sandev->refcnt );
  165. }
  166. /**
  167. * Calculate SAN device block size
  168. *
  169. * @v sandev SAN device
  170. * @ret blksize Sector size
  171. */
  172. static inline size_t sandev_blksize ( struct san_device *sandev ) {
  173. return ( sandev->capacity.blksize << sandev->blksize_shift );
  174. }
  175. /**
  176. * Calculate SAN device capacity
  177. *
  178. * @v sandev SAN device
  179. * @ret blocks Number of blocks
  180. */
  181. static inline uint64_t sandev_capacity ( struct san_device *sandev ) {
  182. return ( sandev->capacity.blocks >> sandev->blksize_shift );
  183. }
  184. /**
  185. * Check if SAN device needs to be reopened
  186. *
  187. * @v sandev SAN device
  188. * @ret needs_reopen SAN device needs to be reopened
  189. */
  190. static inline int sandev_needs_reopen ( struct san_device *sandev ) {
  191. return ( sandev->active == NULL );
  192. }
  193. extern struct san_device * sandev_find ( unsigned int drive );
  194. extern int sandev_reopen ( struct san_device *sandev );
  195. extern int sandev_reset ( struct san_device *sandev );
  196. extern int sandev_rw ( struct san_device *sandev, uint64_t lba,
  197. unsigned int count, userptr_t buffer,
  198. int ( * block_rw ) ( struct interface *control,
  199. struct interface *data,
  200. uint64_t lba, unsigned int count,
  201. userptr_t buffer, size_t len ) );
  202. extern struct san_device * alloc_sandev ( struct uri **uris, unsigned int count,
  203. size_t priv_size );
  204. extern int register_sandev ( struct san_device *sandev );
  205. extern void unregister_sandev ( struct san_device *sandev );
  206. extern unsigned int san_default_drive ( void );
  207. #endif /* _IPXE_SANBOOT_H */