2 * Copyright 2008 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 #include <linux/if_ether.h>
24 * This header file includes all of the data structures used for
25 * communication by the host driver to the fcp firmware.
29 * Exchange and sequence id space allocated to the host driver
31 #define FCPIO_HOST_EXCH_RANGE_START 0x1000
32 #define FCPIO_HOST_EXCH_RANGE_END 0x1fff
33 #define FCPIO_HOST_SEQ_ID_RANGE_START 0x80
34 #define FCPIO_HOST_SEQ_ID_RANGE_END 0xff
41 * Initiator request types
50 * Target request types
52 FCPIO_TCMND_16 = 0x11,
75 FCPIO_LUNMAP_REQ_CMPL,
77 FCPIO_FLOGI_FIP_REG_CMPL,
81 * Header status codes from the firmware
84 FCPIO_SUCCESS = 0, /* request was successful */
87 * If a request to the firmware is rejected, the original request
88 * header will be returned with the status set to one of the following:
90 FCPIO_INVALID_HEADER, /* header contains invalid data */
91 FCPIO_OUT_OF_RESOURCE, /* out of resources to complete request */
92 FCPIO_INVALID_PARAM, /* some parameter in request is invalid */
93 FCPIO_REQ_NOT_SUPPORTED, /* request type is not supported */
94 FCPIO_IO_NOT_FOUND, /* requested I/O was not found */
97 * Once a request is processed, the firmware will usually return
98 * a cmpl message type. In cases where errors occurred,
99 * the header status field would be filled in with one of the following:
101 FCPIO_ABORTED = 0x41, /* request was aborted */
102 FCPIO_TIMEOUT, /* request was timed out */
103 FCPIO_SGL_INVALID, /* request was aborted due to sgl error */
104 FCPIO_MSS_INVALID, /* request was aborted due to mss error */
105 FCPIO_DATA_CNT_MISMATCH, /* recv/sent more/less data than exp. */
106 FCPIO_FW_ERR, /* request was terminated due to fw error */
107 FCPIO_ITMF_REJECTED, /* itmf req was rejected by remote node */
108 FCPIO_ITMF_FAILED, /* itmf req was failed by remote node */
109 FCPIO_ITMF_INCORRECT_LUN, /* itmf req targeted incorrect LUN */
110 FCPIO_CMND_REJECTED, /* request was invalid and rejected */
111 FCPIO_NO_PATH_AVAIL, /* no paths to the lun was available */
112 FCPIO_PATH_FAILED, /* i/o sent to current path failed */
113 FCPIO_LUNMAP_CHNG_PEND, /* i/o rejected due to lunmap change */
117 * The header command tag. All host requests will use the "tag" field
118 * to mark commands with a unique tag. When the firmware responds to
119 * a host request, it will copy the tag field into the response.
121 * The only firmware requests that will use the rx_id/ox_id fields instead
122 * of the tag field will be the target command and target task management
123 * requests. These two requests do not have corresponding host requests
124 * since they come directly from the FC initiator on the network.
137 fcpio_tag_id_enc(struct fcpio_tag *tag, u32 id)
143 fcpio_tag_id_dec(struct fcpio_tag *tag, u32 *id)
149 fcpio_tag_exid_enc(struct fcpio_tag *tag, u16 ox_id, u16 rx_id)
151 tag->u.ex_id.rx_id = rx_id;
152 tag->u.ex_id.ox_id = ox_id;
156 fcpio_tag_exid_dec(struct fcpio_tag *tag, u16 *ox_id, u16 *rx_id)
158 *rx_id = tag->u.ex_id.rx_id;
159 *ox_id = tag->u.ex_id.ox_id;
163 * The header for an fcpio request, whether from the firmware or from the
166 struct fcpio_header {
167 u8 type; /* enum fcpio_type */
168 u8 status; /* header status entry */
169 u16 _resvd; /* reserved */
170 struct fcpio_tag tag; /* header tag */
174 fcpio_header_enc(struct fcpio_header *hdr,
176 struct fcpio_tag tag)
179 hdr->status = status;
185 fcpio_header_dec(struct fcpio_header *hdr,
186 u8 *type, u8 *status,
187 struct fcpio_tag *tag)
190 *status = hdr->status;
196 #define LUN_ADDRESS 8
199 * fcpio_icmnd_16: host -> firmware request
201 * used for sending out an initiator SCSI 16-byte command
203 struct fcpio_icmnd_16 {
204 u32 lunmap_id; /* index into lunmap table */
205 u8 special_req_flags; /* special exchange request flags */
206 u8 _resvd0[3]; /* reserved */
207 u32 sgl_cnt; /* scatter-gather list count */
208 u32 sense_len; /* sense buffer length */
209 u64 sgl_addr; /* scatter-gather list addr */
210 u64 sense_addr; /* sense buffer address */
211 u8 crn; /* SCSI Command Reference No. */
212 u8 pri_ta; /* SCSI Priority and Task attribute */
213 u8 _resvd1; /* reserved: should be 0 */
214 u8 flags; /* command flags */
215 u8 scsi_cdb[CDB_16]; /* SCSI Cmnd Descriptor Block */
216 u32 data_len; /* length of data expected */
217 u8 lun[LUN_ADDRESS]; /* FC vNIC only: LUN address */
218 u8 _resvd2; /* reserved */
219 u8 d_id[3]; /* FC vNIC only: Target D_ID */
220 u16 mss; /* FC vNIC only: max burst */
221 u16 _resvd3; /* reserved */
222 u32 r_a_tov; /* FC vNIC only: Res. Alloc Timeout */
223 u32 e_d_tov; /* FC vNIC only: Err Detect Timeout */
227 * Special request flags
229 #define FCPIO_ICMND_SRFLAG_RETRY 0x01 /* Enable Retry handling on exchange */
232 * Priority/Task Attribute settings
234 #define FCPIO_ICMND_PTA_SIMPLE 0 /* simple task attribute */
235 #define FCPIO_ICMND_PTA_HEADQ 1 /* head of queue task attribute */
236 #define FCPIO_ICMND_PTA_ORDERED 2 /* ordered task attribute */
237 #define FCPIO_ICMND_PTA_ACA 4 /* auto contingent allegiance */
238 #define FCPIO_ICMND_PRI_SHIFT 3 /* priority field starts in bit 3 */
243 #define FCPIO_ICMND_RDDATA 0x02 /* read data */
244 #define FCPIO_ICMND_WRDATA 0x01 /* write data */
247 * fcpio_icmnd_32: host -> firmware request
249 * used for sending out an initiator SCSI 32-byte command
251 struct fcpio_icmnd_32 {
252 u32 lunmap_id; /* index into lunmap table */
253 u8 special_req_flags; /* special exchange request flags */
254 u8 _resvd0[3]; /* reserved */
255 u32 sgl_cnt; /* scatter-gather list count */
256 u32 sense_len; /* sense buffer length */
257 u64 sgl_addr; /* scatter-gather list addr */
258 u64 sense_addr; /* sense buffer address */
259 u8 crn; /* SCSI Command Reference No. */
260 u8 pri_ta; /* SCSI Priority and Task attribute */
261 u8 _resvd1; /* reserved: should be 0 */
262 u8 flags; /* command flags */
263 u8 scsi_cdb[CDB_32]; /* SCSI Cmnd Descriptor Block */
264 u32 data_len; /* length of data expected */
265 u8 lun[LUN_ADDRESS]; /* FC vNIC only: LUN address */
266 u8 _resvd2; /* reserved */
267 u8 d_id[3]; /* FC vNIC only: Target D_ID */
268 u16 mss; /* FC vNIC only: max burst */
269 u16 _resvd3; /* reserved */
270 u32 r_a_tov; /* FC vNIC only: Res. Alloc Timeout */
271 u32 e_d_tov; /* FC vNIC only: Error Detect Timeout */
275 * fcpio_itmf: host -> firmware request
277 * used for requesting the firmware to abort a request and/or send out
278 * a task management function
280 * The t_tag field is only needed when the request type is ABT_TASK.
283 u32 lunmap_id; /* index into lunmap table */
284 u32 tm_req; /* SCSI Task Management request */
285 u32 t_tag; /* header tag of fcpio to be aborted */
286 u32 _resvd; /* _reserved */
287 u8 lun[LUN_ADDRESS]; /* FC vNIC only: LUN address */
288 u8 _resvd1; /* reserved */
289 u8 d_id[3]; /* FC vNIC only: Target D_ID */
290 u32 r_a_tov; /* FC vNIC only: R_A_TOV in msec */
291 u32 e_d_tov; /* FC vNIC only: E_D_TOV in msec */
295 * Task Management request
297 enum fcpio_itmf_tm_req_type {
298 FCPIO_ITMF_ABT_TASK_TERM = 0x01, /* abort task and terminate */
299 FCPIO_ITMF_ABT_TASK, /* abort task and issue abts */
300 FCPIO_ITMF_ABT_TASK_SET, /* abort task set */
301 FCPIO_ITMF_CLR_TASK_SET, /* clear task set */
302 FCPIO_ITMF_LUN_RESET, /* logical unit reset task mgmt */
303 FCPIO_ITMF_CLR_ACA, /* Clear ACA condition */
307 * fcpio_tdata: host -> firmware request
309 * used for requesting the firmware to send out a read data transfer for a
313 u16 rx_id; /* FC rx_id of target command */
314 u16 flags; /* command flags */
315 u32 rel_offset; /* data sequence relative offset */
316 u32 sgl_cnt; /* scatter-gather list count */
317 u32 data_len; /* length of data expected to send */
318 u64 sgl_addr; /* scatter-gather list address */
324 #define FCPIO_TDATA_SCSI_RSP 0x01 /* send a scsi resp. after last frame */
327 * fcpio_txrdy: host -> firmware request
329 * used for requesting the firmware to send out a write data transfer for a
333 u16 rx_id; /* FC rx_id of target command */
334 u16 _resvd0; /* reserved */
335 u32 rel_offset; /* data sequence relative offset */
336 u32 sgl_cnt; /* scatter-gather list count */
337 u32 data_len; /* length of data expected to send */
338 u64 sgl_addr; /* scatter-gather list address */
342 * fcpio_trsp: host -> firmware request
344 * used for requesting the firmware to send out a response for a target
348 u16 rx_id; /* FC rx_id of target command */
349 u16 _resvd0; /* reserved */
350 u32 sense_len; /* sense data buffer length */
351 u64 sense_addr; /* sense data buffer address */
352 u16 _resvd1; /* reserved */
353 u8 flags; /* response request flags */
354 u8 scsi_status; /* SCSI status */
355 u32 residual; /* SCSI data residual value of I/O */
359 * resposnse request flags
361 #define FCPIO_TRSP_RESID_UNDER 0x08 /* residual is valid and is underflow */
362 #define FCPIO_TRSP_RESID_OVER 0x04 /* residual is valid and is overflow */
365 * fcpio_ttmf_ack: host -> firmware response
367 * used by the host to indicate to the firmware it has received and processed
368 * the target tmf request
370 struct fcpio_ttmf_ack {
371 u16 rx_id; /* FC rx_id of target command */
372 u16 _resvd0; /* reserved */
373 u32 tmf_status; /* SCSI task management status */
377 * fcpio_tabort: host -> firmware request
379 * used by the host to request the firmware to abort a target request that was
380 * received by the firmware
382 struct fcpio_tabort {
383 u16 rx_id; /* rx_id of the target request */
387 * fcpio_reset: host -> firmware request
389 * used by the host to signal a reset of the driver to the firmware
390 * and to request firmware to clean up all outstanding I/O
396 enum fcpio_flogi_reg_format_type {
397 FCPIO_FLOGI_REG_DEF_DEST = 0, /* Use the oui | s_id mac format */
398 FCPIO_FLOGI_REG_GW_DEST, /* Use the fixed gateway mac */
402 * fcpio_flogi_reg: host -> firmware request
405 * used by the host to notify the firmware of the lif's s_id
406 * and destination mac address format
408 struct fcpio_flogi_reg {
410 u8 s_id[3]; /* FC vNIC only: Source S_ID */
411 u8 gateway_mac[ETH_ALEN]; /* Destination gateway mac */
413 u32 r_a_tov; /* R_A_TOV in msec */
414 u32 e_d_tov; /* E_D_TOV in msec */
418 * fcpio_echo: host -> firmware request
420 * sends a heartbeat echo request to the firmware
427 * fcpio_lunmap_req: host -> firmware request
430 * sends a request to retrieve the lunmap table for scsi vnics
432 struct fcpio_lunmap_req {
433 u64 addr; /* address of the buffer */
434 u32 len; /* len of the buffer */
438 * fcpio_flogi_fip_reg: host -> firmware request
441 * used by the host to notify the firmware of the lif's s_id
442 * and destination mac address format
444 struct fcpio_flogi_fip_reg {
446 u8 s_id[3]; /* FC vNIC only: Source S_ID */
447 u8 fcf_mac[ETH_ALEN]; /* FCF Target destination mac */
449 u32 r_a_tov; /* R_A_TOV in msec */
450 u32 e_d_tov; /* E_D_TOV in msec */
451 u8 ha_mac[ETH_ALEN]; /* Host adapter source mac */
456 * Basic structure for all fcpio structures that are sent from the host to the
457 * firmware. They are 128 bytes per structure.
459 #define FCPIO_HOST_REQ_LEN 128 /* expected length of host requests */
461 struct fcpio_host_req {
462 struct fcpio_header hdr;
466 * Defines space needed for request
468 u8 buf[FCPIO_HOST_REQ_LEN - sizeof(struct fcpio_header)];
471 * Initiator host requests
473 struct fcpio_icmnd_16 icmnd_16;
474 struct fcpio_icmnd_32 icmnd_32;
475 struct fcpio_itmf itmf;
478 * Target host requests
480 struct fcpio_tdata tdata;
481 struct fcpio_txrdy txrdy;
482 struct fcpio_trsp trsp;
483 struct fcpio_ttmf_ack ttmf_ack;
484 struct fcpio_tabort tabort;
489 struct fcpio_reset reset;
490 struct fcpio_flogi_reg flogi_reg;
491 struct fcpio_echo echo;
492 struct fcpio_lunmap_req lunmap_req;
493 struct fcpio_flogi_fip_reg flogi_fip_reg;
498 * fcpio_icmnd_cmpl: firmware -> host response
500 * used for sending the host a response to an initiator command
502 struct fcpio_icmnd_cmpl {
503 u8 _resvd0[6]; /* reserved */
504 u8 flags; /* response flags */
505 u8 scsi_status; /* SCSI status */
506 u32 residual; /* SCSI data residual length */
507 u32 sense_len; /* SCSI sense length */
513 #define FCPIO_ICMND_CMPL_RESID_UNDER 0x08 /* resid under and valid */
514 #define FCPIO_ICMND_CMPL_RESID_OVER 0x04 /* resid over and valid */
517 * fcpio_itmf_cmpl: firmware -> host response
519 * used for sending the host a response for a itmf request
521 struct fcpio_itmf_cmpl {
522 u32 _resvd; /* reserved */
526 * fcpio_tcmnd_16: firmware -> host request
528 * used by the firmware to notify the host of an incoming target SCSI 16-Byte
531 struct fcpio_tcmnd_16 {
532 u8 lun[LUN_ADDRESS]; /* FC vNIC only: LUN address */
533 u8 crn; /* SCSI Command Reference No. */
534 u8 pri_ta; /* SCSI Priority and Task attribute */
535 u8 _resvd2; /* reserved: should be 0 */
536 u8 flags; /* command flags */
537 u8 scsi_cdb[CDB_16]; /* SCSI Cmnd Descriptor Block */
538 u32 data_len; /* length of data expected */
539 u8 _resvd1; /* reserved */
540 u8 s_id[3]; /* FC vNIC only: Source S_ID */
544 * Priority/Task Attribute settings
546 #define FCPIO_TCMND_PTA_SIMPLE 0 /* simple task attribute */
547 #define FCPIO_TCMND_PTA_HEADQ 1 /* head of queue task attribute */
548 #define FCPIO_TCMND_PTA_ORDERED 2 /* ordered task attribute */
549 #define FCPIO_TCMND_PTA_ACA 4 /* auto contingent allegiance */
550 #define FCPIO_TCMND_PRI_SHIFT 3 /* priority field starts in bit 3 */
555 #define FCPIO_TCMND_RDDATA 0x02 /* read data */
556 #define FCPIO_TCMND_WRDATA 0x01 /* write data */
559 * fcpio_tcmnd_32: firmware -> host request
561 * used by the firmware to notify the host of an incoming target SCSI 32-Byte
564 struct fcpio_tcmnd_32 {
565 u8 lun[LUN_ADDRESS]; /* FC vNIC only: LUN address */
566 u8 crn; /* SCSI Command Reference No. */
567 u8 pri_ta; /* SCSI Priority and Task attribute */
568 u8 _resvd2; /* reserved: should be 0 */
569 u8 flags; /* command flags */
570 u8 scsi_cdb[CDB_32]; /* SCSI Cmnd Descriptor Block */
571 u32 data_len; /* length of data expected */
572 u8 _resvd0; /* reserved */
573 u8 s_id[3]; /* FC vNIC only: Source S_ID */
577 * fcpio_tdrsp_cmpl: firmware -> host response
579 * used by the firmware to notify the host of a response to a host target
582 struct fcpio_tdrsp_cmpl {
583 u16 rx_id; /* rx_id of the target request */
584 u16 _resvd0; /* reserved */
588 * fcpio_ttmf: firmware -> host request
590 * used by the firmware to notify the host of an incoming task management
594 u8 _resvd0; /* reserved */
595 u8 s_id[3]; /* FC vNIC only: Source S_ID */
596 u8 lun[LUN_ADDRESS]; /* FC vNIC only: LUN address */
597 u8 crn; /* SCSI Command Reference No. */
598 u8 _resvd2[3]; /* reserved */
599 u32 tmf_type; /* task management request type */
603 * Task Management request
605 #define FCPIO_TTMF_CLR_ACA 0x40 /* Clear ACA condition */
606 #define FCPIO_TTMF_LUN_RESET 0x10 /* logical unit reset task mgmt */
607 #define FCPIO_TTMF_CLR_TASK_SET 0x04 /* clear task set */
608 #define FCPIO_TTMF_ABT_TASK_SET 0x02 /* abort task set */
609 #define FCPIO_TTMF_ABT_TASK 0x01 /* abort task */
612 * fcpio_tabort_cmpl: firmware -> host response
614 * used by the firmware to respond to a host's tabort request
616 struct fcpio_tabort_cmpl {
617 u16 rx_id; /* rx_id of the target request */
618 u16 _resvd0; /* reserved */
622 * fcpio_ack: firmware -> host response
624 * used by firmware to notify the host of the last work request received
627 u16 request_out; /* last host entry received */
632 * fcpio_reset_cmpl: firmware -> host response
634 * use by firmware to respond to the host's reset request
636 struct fcpio_reset_cmpl {
641 * fcpio_flogi_reg_cmpl: firmware -> host response
644 * response to the fcpio_flogi_reg request
646 struct fcpio_flogi_reg_cmpl {
651 * fcpio_echo_cmpl: firmware -> host response
653 * response to the fcpio_echo request
655 struct fcpio_echo_cmpl {
660 * fcpio_lunmap_chng: firmware -> host notification
663 * notifies the host that the lunmap tables have changed
665 struct fcpio_lunmap_chng {
670 * fcpio_lunmap_req_cmpl: firmware -> host response
673 * response for lunmap table request from the host
675 struct fcpio_lunmap_req_cmpl {
680 * Basic structure for all fcpio structures that are sent from the firmware to
681 * the host. They are 64 bytes per structure.
683 #define FCPIO_FW_REQ_LEN 64 /* expected length of fw requests */
684 struct fcpio_fw_req {
685 struct fcpio_header hdr;
689 * Defines space needed for request
691 u8 buf[FCPIO_FW_REQ_LEN - sizeof(struct fcpio_header)];
694 * Initiator firmware responses
696 struct fcpio_icmnd_cmpl icmnd_cmpl;
697 struct fcpio_itmf_cmpl itmf_cmpl;
700 * Target firmware new requests
702 struct fcpio_tcmnd_16 tcmnd_16;
703 struct fcpio_tcmnd_32 tcmnd_32;
706 * Target firmware responses
708 struct fcpio_tdrsp_cmpl tdrsp_cmpl;
709 struct fcpio_ttmf ttmf;
710 struct fcpio_tabort_cmpl tabort_cmpl;
713 * Firmware response to work received
715 struct fcpio_ack ack;
720 struct fcpio_reset_cmpl reset_cmpl;
721 struct fcpio_flogi_reg_cmpl flogi_reg_cmpl;
722 struct fcpio_echo_cmpl echo_cmpl;
723 struct fcpio_lunmap_chng lunmap_chng;
724 struct fcpio_lunmap_req_cmpl lunmap_req_cmpl;
729 * Access routines to encode and decode the color bit, which is the most
730 * significant bit of the MSB of the structure
732 static inline void fcpio_color_enc(struct fcpio_fw_req *fw_req, u8 color)
734 u8 *c = ((u8 *) fw_req) + sizeof(struct fcpio_fw_req) - 1;
742 static inline void fcpio_color_dec(struct fcpio_fw_req *fw_req, u8 *color)
744 u8 *c = ((u8 *) fw_req) + sizeof(struct fcpio_fw_req) - 1;
749 * Make sure color bit is read from desc *before* other fields
750 * are read from desc. Hardware guarantees color bit is last
751 * bit (byte) written. Adding the rmb() prevents the compiler
752 * and/or CPU from reordering the reads which would potentially
753 * result in reading stale values.
761 * Lunmap table entry for scsi vnics
763 #define FCPIO_LUNMAP_TABLE_SIZE 256
764 #define FCPIO_FLAGS_LUNMAP_VALID 0x80
765 #define FCPIO_FLAGS_BOOT 0x01
766 struct fcpio_lunmap_entry {
775 struct fcpio_lunmap_tbl {
777 struct fcpio_lunmap_entry lunmaps[FCPIO_LUNMAP_TABLE_SIZE];
780 #endif /* _FCPIO_H_ */