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