4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
29 * Definitions for common FC Target.
32 #include <sys/stmf_defines.h>
33 #include <sys/fct_defines.h>
34 #include <sys/portif.h>
40 typedef enum fct_struct_id
{
41 FCT_STRUCT_LOCAL_PORT
= 1,
42 FCT_STRUCT_REMOTE_PORT
,
43 FCT_STRUCT_CMD_RCVD_ELS
,
44 FCT_STRUCT_CMD_SOL_ELS
,
45 FCT_STRUCT_CMD_SOL_CT
,
46 FCT_STRUCT_CMD_RCVD_ABTS
,
47 FCT_STRUCT_CMD_FCP_XCHG
,
48 FCT_STRUCT_DBUF_STORE
,
53 typedef struct fct_remote_port
{
57 struct fct_local_port
*rp_port
;
58 uint8_t rp_nwwn
[FC_WWN_LEN
];
59 uint8_t rp_pwwn
[FC_WWN_LEN
];
60 uint32_t rp_id
; /* 8 or 24 bit */
61 uint32_t rp_hard_address
;
65 #define FCT_HANDLE_NONE 0xffff
67 typedef struct fct_cmd
{
68 void *cmd_fct_private
;
69 void *cmd_fca_private
;
72 struct fct_local_port
*cmd_port
;
74 /* During cmd porting this can be set to NULL */
75 struct fct_remote_port
*cmd_rp
;
77 /* To link cmds together for handling things like ABTS. */
78 struct fct_cmd
*cmd_link
;
82 /* During cmd posting this can be set to FCT_HANDLE_NONE */
83 uint16_t cmd_rp_handle
;
90 fct_status_t cmd_comp_status
;
94 * fcmd_cmd_handle: Bit definitions.
96 * +--------------+------------+------------+------------+
97 * | V |uniq_cntr |fca specific| cmd slot index |
98 * +--------------+------------+------------+------------+
101 #define CMD_HANDLE_SLOT_INDEX(x) ((x) & 0xffff)
102 #define CMD_HANDLE_VALID(x) ((x) & 0x80000000)
105 FCT_CMD_FCP_XCHG
= 0x0001,
106 FCT_CMD_RCVD_ELS
= 0x0002,
107 FCT_CMD_SOL_ELS
= 0x0004,
108 FCT_CMD_RCVD_ABTS
= 0x0008,
109 FCT_CMD_SOL_CT
= 0x0010,
111 FCT_CMD_TYPE_ALL
= 0xffff
114 typedef struct fct_els
{
115 uint16_t els_req_size
;
116 uint16_t els_resp_size
;
117 uint16_t els_req_alloc_size
;
118 uint16_t els_resp_alloc_size
;
119 uint8_t *els_req_payload
;
120 uint8_t *els_resp_payload
;
123 typedef struct fct_sol_ct
{
124 uint16_t ct_req_size
;
125 uint16_t ct_resp_size
;
126 uint16_t ct_req_alloc_size
;
127 uint16_t ct_resp_alloc_size
;
128 uint8_t *ct_req_payload
;
129 uint8_t *ct_resp_payload
;
132 typedef struct fct_rcvd_abts
{
133 uint8_t abts_resp_rctl
; /* Can be BA_ACC or BA_RJT */
136 uint8_t abts_resp_payload
[12];
142 #define ABTS_STATE_RECEIVED 0
143 #define ABTS_STATE_RESPONDED 1
144 #define ABTS_STATE_COMPLETED 2
145 #define ABTS_STATE_ABORT_REQUESTED 3
146 #define ABTS_STATE_ABORT_COMPLETED 4
148 #define FCHBA_MANUFACTURER_LEN 64
149 #define FCHBA_SERIAL_NUMBER_LEN 64
150 #define FCHBA_MODEL_LEN 256
151 #define FCHBA_MODEL_DESCRIPTION_LEN 256
152 #define FCHBA_HARDWARE_VERSION_LEN 256
153 #define FCHBA_DRIVER_VERSION_LEN 256
154 #define FCHBA_OPTION_ROM_VERSION_LEN 256
155 #define FCHBA_FIRMWARE_VERSION_LEN 256
156 #define FCHBA_DRIVER_NAME_LEN 256
157 #define FCHBA_SYMB_NAME_LEN 255
159 typedef struct fct_port_attrs
{
160 char manufacturer
[FCHBA_MANUFACTURER_LEN
];
161 char serial_number
[FCHBA_SERIAL_NUMBER_LEN
];
162 char model
[FCHBA_MODEL_LEN
];
163 char model_description
[FCHBA_MODEL_DESCRIPTION_LEN
];
164 char hardware_version
[FCHBA_HARDWARE_VERSION_LEN
];
165 char driver_version
[FCHBA_DRIVER_VERSION_LEN
];
166 char option_rom_version
[FCHBA_OPTION_ROM_VERSION_LEN
];
167 char firmware_version
[FCHBA_FIRMWARE_VERSION_LEN
];
168 char driver_name
[FCHBA_DRIVER_NAME_LEN
];
169 uint32_t vendor_specific_id
;
170 uint32_t supported_cos
;
171 uint32_t supported_speed
;
172 uint32_t max_frame_size
;
175 typedef struct fct_dbuf_store
{
176 void *fds_fct_private
;
177 void *fds_fca_private
;
178 struct stmf_dbuf_store
*fds_ds
;
180 stmf_data_buf_t
*(*fds_alloc_data_buf
)(struct fct_local_port
*port
,
181 uint32_t size
, uint32_t *pminsize
, uint32_t flags
);
182 void (*fds_free_data_buf
)(struct fct_dbuf_store
*fds
,
183 stmf_data_buf_t
*dbuf
);
186 typedef struct fct_local_port
{
187 void *port_fct_private
;
188 void *port_fca_private
;
189 stmf_local_port_t
*port_lport
;
191 uint8_t port_nwwn
[FC_WWN_LEN
];
192 uint8_t port_pwwn
[FC_WWN_LEN
];
193 char *port_default_alias
;
194 char *port_sym_node_name
;
195 char *port_sym_port_name
;
197 stmf_port_provider_t
*port_pp
;
199 uint32_t port_hard_address
;
200 uint16_t port_max_logins
;
201 uint16_t port_max_xchges
;
202 uint32_t port_fca_fcp_cmd_size
;
203 uint32_t port_fca_rp_private_size
;
204 uint32_t port_fca_sol_els_private_size
;
205 uint32_t port_fca_sol_ct_private_size
;
207 /* in milliseconds */
208 uint32_t port_fca_abort_timeout
;
210 fct_dbuf_store_t
*port_fds
;
211 fct_status_t (*port_get_link_info
)(
212 struct fct_local_port
*port
, struct fct_link_info
*li
);
213 fct_status_t (*port_register_remote_port
)(
214 struct fct_local_port
*port
, struct fct_remote_port
*rp
,
215 struct fct_cmd
*login_els
);
216 fct_status_t (*port_deregister_remote_port
)(
217 struct fct_local_port
*port
, struct fct_remote_port
*rp
);
218 fct_status_t (*port_send_cmd
)(fct_cmd_t
*cmd
);
219 fct_status_t (*port_xfer_scsi_data
)(fct_cmd_t
*cmd
,
220 stmf_data_buf_t
*dbuf
, uint32_t flags
);
221 fct_status_t (*port_send_cmd_response
)(fct_cmd_t
*cmd
,
223 fct_status_t (*port_abort_cmd
)(struct fct_local_port
*port
,
224 fct_cmd_t
*cmd
, uint32_t flags
);
225 void (*port_ctl
)(struct fct_local_port
*port
,
227 fct_status_t (*port_flogi_xchg
)(struct fct_local_port
*port
,
228 struct fct_flogi_xchg
*fx
);
229 void (*port_populate_hba_details
)(
230 struct fct_local_port
*port
, struct fct_port_attrs
*port_attrs
);
234 * Common struct used during FLOGI exchange.
236 typedef struct fct_flogi_xchg
{
237 uint8_t fx_op
; /* ELS_OP_FLOGI or ELS_OP_ACC/RJT */
238 uint8_t fx_rjt_reason
;
240 uint8_t fx_sec_timeout
; /* Timeout in seconds */
241 uint32_t fx_fport
:1, /* 0=N_port, 1=F_port */
243 uint32_t fx_sid
; /* 24 bit SID to use */
244 uint32_t fx_did
; /* 24 bit DID to use */
249 typedef struct fct_link_info
{
251 uint8_t port_topology
;
257 * FCA sets this bit to indicate that fct does not need to do FLOGI
258 * because either FCA did the FLOGI or it determined that its a private
259 * loop. Setting this bit by FCA is optional.
263 /* FCA sets this bit to indicate that it did FLOGI */
264 port_fca_flogi_done
:1,
266 /* FCT sets this bit to indicate that it did FLOGI */
267 port_fct_flogi_done
:1;
271 /* The fields below are only valid if someone did a successful flogi */
272 uint8_t port_rnwwn
[8];
273 uint8_t port_rpwwn
[8];
279 #define PORT_TOPOLOGY_UNKNOWN 0
280 #define PORT_TOPOLOGY_PT_TO_PT 1
281 #define PORT_TOPOLOGY_PRIVATE_LOOP 2
282 #define PORT_TOPOLOGY_PUBLIC_LOOP 6
283 #define PORT_TOPOLOGY_FABRIC_PT_TO_PT 5
284 #define PORT_TOPOLOGY_FABRIC_BIT 4
286 #define PORT_FLOGI_DONE(li) (((li)->port_fca_flogi_done) || \
287 ((li)->port_fct_flogi_done))
292 #define PORT_SPEED_UNKNOWN 0
293 #define PORT_SPEED_1G 1
294 #define PORT_SPEED_2G 2
295 #define PORT_SPEED_4G 4
296 #define PORT_SPEED_8G 8
301 #define FCT_TERMINATE_CMD 1
306 #define FCT_STATE_OFFLINE 0
307 #define FCT_STATE_ONLINING 1
308 #define FCT_STATE_ONLINE 2
309 #define FCT_STATE_OFFLINING 3
312 * fct ctl commands. These should not conflict with stmf ctl commands
314 #define FCT_CMD_PORT_ONLINE (STMF_LPORT_CTL_CMDS | 0x01)
315 #define FCT_CMD_PORT_ONLINE_COMPLETE (STMF_LPORT_CTL_CMDS | 0x02)
316 #define FCT_CMD_PORT_OFFLINE (STMF_LPORT_CTL_CMDS | 0x03)
317 #define FCT_CMD_PORT_OFFLINE_COMPLETE (STMF_LPORT_CTL_CMDS | 0x04)
318 #define FCT_ACK_PORT_ONLINE_COMPLETE (STMF_LPORT_CTL_CMDS | 0x05)
319 #define FCT_ACK_PORT_OFFLINE_COMPLETE (STMF_LPORT_CTL_CMDS | 0x06)
322 * IO flags for cmd flow.
324 #define FCT_IOF_FCA_DONE 0x10000
325 #define FCT_IOF_FORCE_FCA_DONE 0x20000
331 #define FCT_FILL_CTIU_PREAMPLE(x_payload, x_ctop) _NOTE(EMPTY)
333 #define FCT_FILL_CTIU_PREAMPLE(x_payload, x_ctop) \
335 x_payload[0] = 0x02; \
336 x_payload[4] = 0xFC; \
337 x_payload[5] = 0x02; \
338 x_payload[8] = 0xFF & (x_ctop >> 8); \
339 x_payload[9] = 0xFF & (x_ctop); \
343 uint64_t fct_netbuf_to_value(uint8_t *buf
, uint8_t nbytes
);
344 void fct_value_to_netbuf(uint64_t value
, uint8_t *buf
, uint8_t nbytes
);
345 void *fct_alloc(fct_struct_id_t struct_id
, int additional_size
, int flags
);
346 void fct_free(void *ptr
);
347 fct_cmd_t
*fct_scsi_task_alloc(struct fct_local_port
*port
,
348 uint16_t rp_handle
, uint32_t rportid
, uint8_t *lun
,
349 uint16_t cdb_length
, uint16_t task_ext
);
350 fct_status_t
fct_register_local_port(fct_local_port_t
*port
);
351 fct_status_t
fct_deregister_local_port(fct_local_port_t
*port
);
352 void fct_handle_event(fct_local_port_t
*port
, int event_id
,
353 uint32_t event_flags
, caddr_t arg
);
354 void fct_post_rcvd_cmd(fct_cmd_t
*cmd
, stmf_data_buf_t
*dbuf
);
355 void fct_queue_cmd_for_termination(fct_cmd_t
*cmd
, fct_status_t s
);
356 void fct_queue_scsi_task_for_termination(fct_cmd_t
*cmd
, fct_status_t s
);
357 fct_cmd_t
*fct_handle_to_cmd(fct_local_port_t
*port
, uint32_t fct_handle
);
358 void fct_ctl(struct stmf_local_port
*lport
, int cmd
, void *arg
);
359 void fct_cmd_fca_aborted(fct_cmd_t
*cmd
, fct_status_t s
, uint32_t ioflags
);
360 uint16_t fct_get_rp_handle(fct_local_port_t
*port
, uint32_t rportid
);
361 void fct_send_response_done(fct_cmd_t
*cmd
, fct_status_t s
, uint32_t ioflags
);
362 void fct_send_cmd_done(fct_cmd_t
*cmd
, fct_status_t s
, uint32_t ioflags
);
363 void fct_scsi_data_xfer_done(fct_cmd_t
*cmd
, stmf_data_buf_t
*dbuf
,
365 fct_status_t
fct_port_initialize(fct_local_port_t
*port
, uint32_t rflags
,
366 char *additional_info
);
367 fct_status_t
fct_port_shutdown(fct_local_port_t
*port
, uint32_t rflags
,
368 char *additional_info
);
369 fct_status_t
fct_handle_rcvd_flogi(fct_local_port_t
*port
,
370 fct_flogi_xchg_t
*fx
);
371 void fct_log_local_port_event(fct_local_port_t
*port
, char *subclass
);
372 void fct_log_remote_port_event(fct_local_port_t
*port
, char *subclass
,
373 uint8_t *rp_pwwn
, uint32_t rp_id
);