sbp_target.h 5.8 KB

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