0001
0002 #ifndef _SBP_BASE_H
0003 #define _SBP_BASE_H
0004
0005 #include <linux/firewire.h>
0006 #include <linux/spinlock.h>
0007 #include <linux/types.h>
0008 #include <linux/workqueue.h>
0009 #include <target/target_core_base.h>
0010
0011 #define SBP_VERSION "v0.1"
0012 #define SBP_NAMELEN 32
0013
0014 #define SBP_ORB_FETCH_SIZE 8
0015
0016 #define MANAGEMENT_AGENT_STATE_IDLE 0
0017 #define MANAGEMENT_AGENT_STATE_BUSY 1
0018
0019 #define ORB_NOTIFY(v) (((v) >> 31) & 0x01)
0020 #define ORB_REQUEST_FORMAT(v) (((v) >> 29) & 0x03)
0021
0022 #define MANAGEMENT_ORB_FUNCTION(v) (((v) >> 16) & 0x0f)
0023
0024 #define MANAGEMENT_ORB_FUNCTION_LOGIN 0x0
0025 #define MANAGEMENT_ORB_FUNCTION_QUERY_LOGINS 0x1
0026 #define MANAGEMENT_ORB_FUNCTION_RECONNECT 0x3
0027 #define MANAGEMENT_ORB_FUNCTION_SET_PASSWORD 0x4
0028 #define MANAGEMENT_ORB_FUNCTION_LOGOUT 0x7
0029 #define MANAGEMENT_ORB_FUNCTION_ABORT_TASK 0xb
0030 #define MANAGEMENT_ORB_FUNCTION_ABORT_TASK_SET 0xc
0031 #define MANAGEMENT_ORB_FUNCTION_LOGICAL_UNIT_RESET 0xe
0032 #define MANAGEMENT_ORB_FUNCTION_TARGET_RESET 0xf
0033
0034 #define LOGIN_ORB_EXCLUSIVE(v) (((v) >> 28) & 0x01)
0035 #define LOGIN_ORB_RESERVED(v) (((v) >> 24) & 0x0f)
0036 #define LOGIN_ORB_RECONNECT(v) (((v) >> 20) & 0x0f)
0037 #define LOGIN_ORB_LUN(v) (((v) >> 0) & 0xffff)
0038 #define LOGIN_ORB_PASSWORD_LENGTH(v) (((v) >> 16) & 0xffff)
0039 #define LOGIN_ORB_RESPONSE_LENGTH(v) (((v) >> 0) & 0xffff)
0040
0041 #define RECONNECT_ORB_LOGIN_ID(v) (((v) >> 0) & 0xffff)
0042 #define LOGOUT_ORB_LOGIN_ID(v) (((v) >> 0) & 0xffff)
0043
0044 #define CMDBLK_ORB_DIRECTION(v) (((v) >> 27) & 0x01)
0045 #define CMDBLK_ORB_SPEED(v) (((v) >> 24) & 0x07)
0046 #define CMDBLK_ORB_MAX_PAYLOAD(v) (((v) >> 20) & 0x0f)
0047 #define CMDBLK_ORB_PG_TBL_PRESENT(v) (((v) >> 19) & 0x01)
0048 #define CMDBLK_ORB_PG_SIZE(v) (((v) >> 16) & 0x07)
0049 #define CMDBLK_ORB_DATA_SIZE(v) (((v) >> 0) & 0xffff)
0050
0051 #define STATUS_BLOCK_SRC(v) (((v) & 0x03) << 30)
0052 #define STATUS_BLOCK_RESP(v) (((v) & 0x03) << 28)
0053 #define STATUS_BLOCK_DEAD(v) (((v) ? 1 : 0) << 27)
0054 #define STATUS_BLOCK_LEN(v) (((v) & 0x07) << 24)
0055 #define STATUS_BLOCK_SBP_STATUS(v) (((v) & 0xff) << 16)
0056 #define STATUS_BLOCK_ORB_OFFSET_HIGH(v) (((v) & 0xffff) << 0)
0057
0058 #define STATUS_SRC_ORB_CONTINUING 0
0059 #define STATUS_SRC_ORB_FINISHED 1
0060 #define STATUS_SRC_UNSOLICITED 2
0061
0062 #define STATUS_RESP_REQUEST_COMPLETE 0
0063 #define STATUS_RESP_TRANSPORT_FAILURE 1
0064 #define STATUS_RESP_ILLEGAL_REQUEST 2
0065 #define STATUS_RESP_VENDOR_DEPENDENT 3
0066
0067 #define SBP_STATUS_OK 0
0068 #define SBP_STATUS_REQ_TYPE_NOTSUPP 1
0069 #define SBP_STATUS_SPEED_NOTSUPP 2
0070 #define SBP_STATUS_PAGE_SIZE_NOTSUPP 3
0071 #define SBP_STATUS_ACCESS_DENIED 4
0072 #define SBP_STATUS_LUN_NOTSUPP 5
0073 #define SBP_STATUS_PAYLOAD_TOO_SMALL 6
0074
0075 #define SBP_STATUS_RESOURCES_UNAVAIL 8
0076 #define SBP_STATUS_FUNCTION_REJECTED 9
0077 #define SBP_STATUS_LOGIN_ID_UNKNOWN 10
0078 #define SBP_STATUS_DUMMY_ORB_COMPLETE 11
0079 #define SBP_STATUS_REQUEST_ABORTED 12
0080 #define SBP_STATUS_UNSPECIFIED_ERROR 0xff
0081
0082 #define AGENT_STATE_RESET 0
0083 #define AGENT_STATE_ACTIVE 1
0084 #define AGENT_STATE_SUSPENDED 2
0085 #define AGENT_STATE_DEAD 3
0086
0087 struct sbp2_pointer {
0088 __be32 high;
0089 __be32 low;
0090 };
0091
0092 struct sbp_command_block_orb {
0093 struct sbp2_pointer next_orb;
0094 struct sbp2_pointer data_descriptor;
0095 __be32 misc;
0096 u8 command_block[12];
0097 };
0098
0099 struct sbp_page_table_entry {
0100 __be16 segment_length;
0101 __be16 segment_base_hi;
0102 __be32 segment_base_lo;
0103 };
0104
0105 struct sbp_management_orb {
0106 struct sbp2_pointer ptr1;
0107 struct sbp2_pointer ptr2;
0108 __be32 misc;
0109 __be32 length;
0110 struct sbp2_pointer status_fifo;
0111 };
0112
0113 struct sbp_status_block {
0114 __be32 status;
0115 __be32 orb_low;
0116 u8 data[24];
0117 };
0118
0119 struct sbp_login_response_block {
0120 __be32 misc;
0121 struct sbp2_pointer command_block_agent;
0122 __be32 reconnect_hold;
0123 };
0124
0125 struct sbp_login_descriptor {
0126 struct sbp_session *sess;
0127 struct list_head link;
0128
0129 u32 login_lun;
0130
0131 u64 status_fifo_addr;
0132 int exclusive;
0133 u16 login_id;
0134
0135 struct sbp_target_agent *tgt_agt;
0136 };
0137
0138 struct sbp_session {
0139 spinlock_t lock;
0140 struct se_session *se_sess;
0141 struct list_head login_list;
0142 struct delayed_work maint_work;
0143
0144 u64 guid;
0145 int node_id;
0146
0147 struct fw_card *card;
0148 int generation;
0149 int speed;
0150
0151 int reconnect_hold;
0152 u64 reconnect_expires;
0153 };
0154
0155 struct sbp_tpg {
0156
0157 u16 tport_tpgt;
0158
0159 struct sbp_tport *tport;
0160
0161 struct se_portal_group se_tpg;
0162 };
0163
0164 struct sbp_tport {
0165
0166 u64 guid;
0167
0168 char tport_name[SBP_NAMELEN];
0169
0170 struct se_wwn tport_wwn;
0171
0172 struct sbp_tpg *tpg;
0173
0174
0175 struct fw_descriptor unit_directory;
0176
0177
0178 struct sbp_management_agent *mgt_agt;
0179
0180
0181 int enable;
0182 s32 directory_id;
0183 int mgt_orb_timeout;
0184 int max_reconnect_timeout;
0185 int max_logins_per_lun;
0186 };
0187
0188 static inline u64 sbp2_pointer_to_addr(const struct sbp2_pointer *ptr)
0189 {
0190 return (u64)(be32_to_cpu(ptr->high) & 0x0000ffff) << 32 |
0191 (be32_to_cpu(ptr->low) & 0xfffffffc);
0192 }
0193
0194 static inline void addr_to_sbp2_pointer(u64 addr, struct sbp2_pointer *ptr)
0195 {
0196 ptr->high = cpu_to_be32(addr >> 32);
0197 ptr->low = cpu_to_be32(addr);
0198 }
0199
0200 struct sbp_target_agent {
0201 spinlock_t lock;
0202 struct fw_address_handler handler;
0203 struct sbp_login_descriptor *login;
0204 int state;
0205 struct work_struct work;
0206 u64 orb_pointer;
0207 bool doorbell;
0208 };
0209
0210 struct sbp_target_request {
0211 struct sbp_login_descriptor *login;
0212 u64 orb_pointer;
0213 struct sbp_command_block_orb orb;
0214 struct sbp_status_block status;
0215 struct work_struct work;
0216
0217 struct se_cmd se_cmd;
0218 struct sbp_page_table_entry *pg_tbl;
0219 void *cmd_buf;
0220
0221 unsigned char sense_buf[TRANSPORT_SENSE_BUFFER];
0222 };
0223
0224 struct sbp_management_agent {
0225 spinlock_t lock;
0226 struct sbp_tport *tport;
0227 struct fw_address_handler handler;
0228 int state;
0229 struct work_struct work;
0230 u64 orb_offset;
0231 struct sbp_management_request *request;
0232 };
0233
0234 struct sbp_management_request {
0235 struct sbp_management_orb orb;
0236 struct sbp_status_block status;
0237 struct fw_card *card;
0238 int generation;
0239 int node_addr;
0240 int speed;
0241 };
0242
0243 #endif