sbp_target.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _SBP_BASE_H
  3. #define _SBP_BASE_H
  4. #include <linux/firewire.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/types.h>
  7. #include <linux/workqueue.h>
  8. #include <target/target_core_base.h>
  9. #define SBP_VERSION "v0.1"
  10. #define SBP_NAMELEN 32
  11. #define SBP_ORB_FETCH_SIZE 8
  12. #define MANAGEMENT_AGENT_STATE_IDLE 0
  13. #define MANAGEMENT_AGENT_STATE_BUSY 1
  14. #define ORB_NOTIFY(v) (((v) >> 31) & 0x01)
  15. #define ORB_REQUEST_FORMAT(v) (((v) >> 29) & 0x03)
  16. #define MANAGEMENT_ORB_FUNCTION(v) (((v) >> 16) & 0x0f)
  17. #define MANAGEMENT_ORB_FUNCTION_LOGIN 0x0
  18. #define MANAGEMENT_ORB_FUNCTION_QUERY_LOGINS 0x1
  19. #define MANAGEMENT_ORB_FUNCTION_RECONNECT 0x3
  20. #define MANAGEMENT_ORB_FUNCTION_SET_PASSWORD 0x4
  21. #define MANAGEMENT_ORB_FUNCTION_LOGOUT 0x7
  22. #define MANAGEMENT_ORB_FUNCTION_ABORT_TASK 0xb
  23. #define MANAGEMENT_ORB_FUNCTION_ABORT_TASK_SET 0xc
  24. #define MANAGEMENT_ORB_FUNCTION_LOGICAL_UNIT_RESET 0xe
  25. #define MANAGEMENT_ORB_FUNCTION_TARGET_RESET 0xf
  26. #define LOGIN_ORB_EXCLUSIVE(v) (((v) >> 28) & 0x01)
  27. #define LOGIN_ORB_RESERVED(v) (((v) >> 24) & 0x0f)
  28. #define LOGIN_ORB_RECONNECT(v) (((v) >> 20) & 0x0f)
  29. #define LOGIN_ORB_LUN(v) (((v) >> 0) & 0xffff)
  30. #define LOGIN_ORB_PASSWORD_LENGTH(v) (((v) >> 16) & 0xffff)
  31. #define LOGIN_ORB_RESPONSE_LENGTH(v) (((v) >> 0) & 0xffff)
  32. #define RECONNECT_ORB_LOGIN_ID(v) (((v) >> 0) & 0xffff)
  33. #define LOGOUT_ORB_LOGIN_ID(v) (((v) >> 0) & 0xffff)
  34. #define CMDBLK_ORB_DIRECTION(v) (((v) >> 27) & 0x01)
  35. #define CMDBLK_ORB_SPEED(v) (((v) >> 24) & 0x07)
  36. #define CMDBLK_ORB_MAX_PAYLOAD(v) (((v) >> 20) & 0x0f)
  37. #define CMDBLK_ORB_PG_TBL_PRESENT(v) (((v) >> 19) & 0x01)
  38. #define CMDBLK_ORB_PG_SIZE(v) (((v) >> 16) & 0x07)
  39. #define CMDBLK_ORB_DATA_SIZE(v) (((v) >> 0) & 0xffff)
  40. #define STATUS_BLOCK_SRC(v) (((v) & 0x03) << 30)
  41. #define STATUS_BLOCK_RESP(v) (((v) & 0x03) << 28)
  42. #define STATUS_BLOCK_DEAD(v) (((v) ? 1 : 0) << 27)
  43. #define STATUS_BLOCK_LEN(v) (((v) & 0x07) << 24)
  44. #define STATUS_BLOCK_SBP_STATUS(v) (((v) & 0xff) << 16)
  45. #define STATUS_BLOCK_ORB_OFFSET_HIGH(v) (((v) & 0xffff) << 0)
  46. #define STATUS_SRC_ORB_CONTINUING 0
  47. #define STATUS_SRC_ORB_FINISHED 1
  48. #define STATUS_SRC_UNSOLICITED 2
  49. #define STATUS_RESP_REQUEST_COMPLETE 0
  50. #define STATUS_RESP_TRANSPORT_FAILURE 1
  51. #define STATUS_RESP_ILLEGAL_REQUEST 2
  52. #define STATUS_RESP_VENDOR_DEPENDENT 3
  53. #define SBP_STATUS_OK 0
  54. #define SBP_STATUS_REQ_TYPE_NOTSUPP 1
  55. #define SBP_STATUS_SPEED_NOTSUPP 2
  56. #define SBP_STATUS_PAGE_SIZE_NOTSUPP 3
  57. #define SBP_STATUS_ACCESS_DENIED 4
  58. #define SBP_STATUS_LUN_NOTSUPP 5
  59. #define SBP_STATUS_PAYLOAD_TOO_SMALL 6
  60. /* 7 is reserved */
  61. #define SBP_STATUS_RESOURCES_UNAVAIL 8
  62. #define SBP_STATUS_FUNCTION_REJECTED 9
  63. #define SBP_STATUS_LOGIN_ID_UNKNOWN 10
  64. #define SBP_STATUS_DUMMY_ORB_COMPLETE 11
  65. #define SBP_STATUS_REQUEST_ABORTED 12
  66. #define SBP_STATUS_UNSPECIFIED_ERROR 0xff
  67. #define AGENT_STATE_RESET 0
  68. #define AGENT_STATE_ACTIVE 1
  69. #define AGENT_STATE_SUSPENDED 2
  70. #define AGENT_STATE_DEAD 3
  71. struct sbp2_pointer {
  72. __be32 high;
  73. __be32 low;
  74. };
  75. struct sbp_command_block_orb {
  76. struct sbp2_pointer next_orb;
  77. struct sbp2_pointer data_descriptor;
  78. __be32 misc;
  79. u8 command_block[12];
  80. };
  81. struct sbp_page_table_entry {
  82. __be16 segment_length;
  83. __be16 segment_base_hi;
  84. __be32 segment_base_lo;
  85. };
  86. struct sbp_management_orb {
  87. struct sbp2_pointer ptr1;
  88. struct sbp2_pointer ptr2;
  89. __be32 misc;
  90. __be32 length;
  91. struct sbp2_pointer status_fifo;
  92. };
  93. struct sbp_status_block {
  94. __be32 status;
  95. __be32 orb_low;
  96. u8 data[24];
  97. };
  98. struct sbp_login_response_block {
  99. __be32 misc;
  100. struct sbp2_pointer command_block_agent;
  101. __be32 reconnect_hold;
  102. };
  103. struct sbp_login_descriptor {
  104. struct sbp_session *sess;
  105. struct list_head link;
  106. u32 login_lun;
  107. u64 status_fifo_addr;
  108. int exclusive;
  109. u16 login_id;
  110. struct sbp_target_agent *tgt_agt;
  111. };
  112. struct sbp_session {
  113. spinlock_t lock;
  114. struct se_session *se_sess;
  115. struct list_head login_list;
  116. struct delayed_work maint_work;
  117. u64 guid; /* login_owner_EUI_64 */
  118. int node_id; /* login_owner_ID */
  119. struct fw_card *card;
  120. int generation;
  121. int speed;
  122. int reconnect_hold;
  123. u64 reconnect_expires;
  124. };
  125. struct sbp_tpg {
  126. /* Target portal group tag for TCM */
  127. u16 tport_tpgt;
  128. /* Pointer back to sbp_tport */
  129. struct sbp_tport *tport;
  130. /* Returned by sbp_make_tpg() */
  131. struct se_portal_group se_tpg;
  132. };
  133. struct sbp_tport {
  134. /* Target Unit Identifier (EUI-64) */
  135. u64 guid;
  136. /* Target port name */
  137. char tport_name[SBP_NAMELEN];
  138. /* Returned by sbp_make_tport() */
  139. struct se_wwn tport_wwn;
  140. struct sbp_tpg *tpg;
  141. /* FireWire unit directory */
  142. struct fw_descriptor unit_directory;
  143. /* SBP Management Agent */
  144. struct sbp_management_agent *mgt_agt;
  145. /* Parameters */
  146. int enable;
  147. s32 directory_id;
  148. int mgt_orb_timeout;
  149. int max_reconnect_timeout;
  150. int max_logins_per_lun;
  151. };
  152. static inline u64 sbp2_pointer_to_addr(const struct sbp2_pointer *ptr)
  153. {
  154. return (u64)(be32_to_cpu(ptr->high) & 0x0000ffff) << 32 |
  155. (be32_to_cpu(ptr->low) & 0xfffffffc);
  156. }
  157. static inline void addr_to_sbp2_pointer(u64 addr, struct sbp2_pointer *ptr)
  158. {
  159. ptr->high = cpu_to_be32(addr >> 32);
  160. ptr->low = cpu_to_be32(addr);
  161. }
  162. struct sbp_target_agent {
  163. spinlock_t lock;
  164. struct fw_address_handler handler;
  165. struct sbp_login_descriptor *login;
  166. int state;
  167. struct work_struct work;
  168. u64 orb_pointer;
  169. bool doorbell;
  170. };
  171. struct sbp_target_request {
  172. struct sbp_login_descriptor *login;
  173. u64 orb_pointer;
  174. struct sbp_command_block_orb orb;
  175. struct sbp_status_block status;
  176. struct work_struct work;
  177. struct se_cmd se_cmd;
  178. struct sbp_page_table_entry *pg_tbl;
  179. void *cmd_buf;
  180. unsigned char sense_buf[TRANSPORT_SENSE_BUFFER];
  181. };
  182. struct sbp_management_agent {
  183. spinlock_t lock;
  184. struct sbp_tport *tport;
  185. struct fw_address_handler handler;
  186. int state;
  187. struct work_struct work;
  188. u64 orb_offset;
  189. struct sbp_management_request *request;
  190. };
  191. struct sbp_management_request {
  192. struct sbp_management_orb orb;
  193. struct sbp_status_block status;
  194. struct fw_card *card;
  195. int generation;
  196. int node_addr;
  197. int speed;
  198. };
  199. #endif