Skip to content

Commit

Permalink
[SCSI] FC protocol definition header files
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
  • Loading branch information
Robert Love authored and James Bottomley committed Dec 29, 2008
1 parent 21465ed commit f032c2f
Show file tree
Hide file tree
Showing 8 changed files with 1,983 additions and 0 deletions.
816 changes: 816 additions & 0 deletions include/scsi/fc/fc_els.h

Large diffs are not rendered by default.

138 changes: 138 additions & 0 deletions include/scsi/fc/fc_encaps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Copyright(c) 2007 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
* Maintained at www.Open-FCoE.org
*/
#ifndef _FC_ENCAPS_H_
#define _FC_ENCAPS_H_

/*
* Protocol definitions from RFC 3643 - Fibre Channel Frame Encapsulation.
*
* Note: The frame length field is the number of 32-bit words in
* the encapsulation including the fcip_encaps_header, CRC and EOF words.
* The minimum frame length value in bytes is (32 + 24 + 4 + 4) * 4 = 64.
* The maximum frame length value in bytes is (32 + 24 + 2112 + 4 + 4) = 2172.
*/
#define FC_ENCAPS_MIN_FRAME_LEN 64 /* min frame len (bytes) (see above) */
#define FC_ENCAPS_MAX_FRAME_LEN (FC_ENCAPS_MIN_FRAME_LEN + FC_MAX_PAYLOAD)

#define FC_ENCAPS_VER 1 /* current version number */

struct fc_encaps_hdr {
__u8 fc_proto; /* protocol number */
__u8 fc_ver; /* version of encapsulation */
__u8 fc_proto_n; /* ones complement of protocol */
__u8 fc_ver_n; /* ones complement of version */

unsigned char fc_proto_data[8]; /* protocol specific data */

__be16 fc_len_flags; /* 10-bit length/4 w/ 6 flag bits */
__be16 fc_len_flags_n; /* ones complement of length / flags */

/*
* Offset 0x10
*/
__be32 fc_time[2]; /* time stamp: seconds and fraction */
__be32 fc_crc; /* CRC */
__be32 fc_sof; /* start of frame (see FC_SOF below) */

/* 0x20 - FC frame content followed by EOF word */
};

#define FCIP_ENCAPS_HDR_LEN 0x20 /* expected length for asserts */

/*
* Macro's for making redundant copies of EOF and SOF.
*/
#define FC_XY(x, y) ((((x) & 0xff) << 8) | ((y) & 0xff))
#define FC_XYXY(x, y) ((FCIP_XY(x, y) << 16) | FCIP_XY(x, y))
#define FC_XYNN(x, y) (FCIP_XYXY(x, y) ^ 0xffff)

#define FC_SOF_ENCODE(n) FC_XYNN(n, n)
#define FC_EOF_ENCODE(n) FC_XYNN(n, n)

/*
* SOF / EOF bytes.
*/
enum fc_sof {
FC_SOF_F = 0x28, /* fabric */
FC_SOF_I4 = 0x29, /* initiate class 4 */
FC_SOF_I2 = 0x2d, /* initiate class 2 */
FC_SOF_I3 = 0x2e, /* initiate class 3 */
FC_SOF_N4 = 0x31, /* normal class 4 */
FC_SOF_N2 = 0x35, /* normal class 2 */
FC_SOF_N3 = 0x36, /* normal class 3 */
FC_SOF_C4 = 0x39, /* activate class 4 */
} __attribute__((packed));

enum fc_eof {
FC_EOF_N = 0x41, /* normal (not last frame of seq) */
FC_EOF_T = 0x42, /* terminate (last frame of sequence) */
FC_EOF_RT = 0x44,
FC_EOF_DT = 0x46, /* disconnect-terminate class-1 */
FC_EOF_NI = 0x49, /* normal-invalid */
FC_EOF_DTI = 0x4e, /* disconnect-terminate-invalid */
FC_EOF_RTI = 0x4f,
FC_EOF_A = 0x50, /* abort */
} __attribute__((packed));

#define FC_SOF_CLASS_MASK 0x06 /* mask for class of service in SOF */

/*
* Define classes in terms of the SOF code (initial).
*/
enum fc_class {
FC_CLASS_NONE = 0, /* software value indicating no class */
FC_CLASS_2 = FC_SOF_I2,
FC_CLASS_3 = FC_SOF_I3,
FC_CLASS_4 = FC_SOF_I4,
FC_CLASS_F = FC_SOF_F,
};

/*
* Determine whether SOF code indicates the need for a BLS ACK.
*/
static inline int fc_sof_needs_ack(enum fc_sof sof)
{
return (~sof) & 0x02; /* true for class 1, 2, 4, 6, or F */
}

/*
* Given an fc_class, return the normal (non-initial) SOF value.
*/
static inline enum fc_sof fc_sof_normal(enum fc_class class)
{
return class + FC_SOF_N3 - FC_SOF_I3; /* diff is always 8 */
}

/*
* Compute class from SOF value.
*/
static inline enum fc_class fc_sof_class(enum fc_sof sof)
{
return (sof & 0x7) | FC_SOF_F;
}

/*
* Determine whether SOF is for the initial frame of a sequence.
*/
static inline int fc_sof_is_init(enum fc_sof sof)
{
return sof < 0x30;
}

#endif /* _FC_ENCAPS_H_ */
124 changes: 124 additions & 0 deletions include/scsi/fc/fc_fc2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Copyright(c) 2007 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
* Maintained at www.Open-FCoE.org
*/

#ifndef _FC_FC2_H_
#define _FC_FC2_H_

/*
* Fibre Channel Exchanges and Sequences.
*/
#ifndef PACKED
#define PACKED __attribute__ ((__packed__))
#endif /* PACKED */


/*
* Sequence Status Block.
* This format is set by the FC-FS standard and is sent over the wire.
* Note that the fields aren't all naturally aligned.
*/
struct fc_ssb {
__u8 ssb_seq_id; /* sequence ID */
__u8 _ssb_resvd;
__be16 ssb_low_seq_cnt; /* lowest SEQ_CNT */

__be16 ssb_high_seq_cnt; /* highest SEQ_CNT */
__be16 ssb_s_stat; /* sequence status flags */

__be16 ssb_err_seq_cnt; /* error SEQ_CNT */
__u8 ssb_fh_cs_ctl; /* frame header CS_CTL */
__be16 ssb_fh_ox_id; /* frame header OX_ID */
__be16 ssb_rx_id; /* responder's exchange ID */
__u8 _ssb_resvd2[2];
} PACKED;

/*
* The SSB should be 17 bytes. Since it's layout is somewhat strange,
* we define the size here so that code can ASSERT that the size comes out
* correct.
*/
#define FC_SSB_SIZE 17 /* length of fc_ssb for assert */

/*
* ssb_s_stat - flags from FC-FS-2 T11/1619-D Rev 0.90.
*/
#define SSB_ST_RESP (1 << 15) /* sequence responder */
#define SSB_ST_ACTIVE (1 << 14) /* sequence is active */
#define SSB_ST_ABNORMAL (1 << 12) /* abnormal ending condition */

#define SSB_ST_REQ_MASK (3 << 10) /* ACK, abort sequence condition */
#define SSB_ST_REQ_CONT (0 << 10)
#define SSB_ST_REQ_ABORT (1 << 10)
#define SSB_ST_REQ_STOP (2 << 10)
#define SSB_ST_REQ_RETRANS (3 << 10)

#define SSB_ST_ABTS (1 << 9) /* ABTS protocol completed */
#define SSB_ST_RETRANS (1 << 8) /* retransmission completed */
#define SSB_ST_TIMEOUT (1 << 7) /* sequence timed out by recipient */
#define SSB_ST_P_RJT (1 << 6) /* P_RJT transmitted */

#define SSB_ST_CLASS_BIT 4 /* class of service field LSB */
#define SSB_ST_CLASS_MASK 3 /* class of service mask */
#define SSB_ST_ACK (1 << 3) /* ACK (EOFt or EOFdt) transmitted */

/*
* Exchange Status Block.
* This format is set by the FC-FS standard and is sent over the wire.
* Note that the fields aren't all naturally aligned.
*/
struct fc_esb {
__u8 esb_cs_ctl; /* CS_CTL for frame header */
__be16 esb_ox_id; /* originator exchange ID */
__be16 esb_rx_id; /* responder exchange ID */
__be32 esb_orig_fid; /* fabric ID of originator */
__be32 esb_resp_fid; /* fabric ID of responder */
__be32 esb_e_stat; /* status */
__u8 _esb_resvd[4];
__u8 esb_service_params[112]; /* TBD */
__u8 esb_seq_status[8]; /* sequence statuses, 8 bytes each */
} __attribute__((packed));;


/*
* Define expected size for ASSERTs.
* See comments on FC_SSB_SIZE.
*/
#define FC_ESB_SIZE (1 + 5*4 + 112 + 8) /* expected size */

/*
* esb_e_stat - flags from FC-FS-2 T11/1619-D Rev 0.90.
*/
#define ESB_ST_RESP (1 << 31) /* responder to exchange */
#define ESB_ST_SEQ_INIT (1 << 30) /* port holds sequence initiaive */
#define ESB_ST_COMPLETE (1 << 29) /* exchange is complete */
#define ESB_ST_ABNORMAL (1 << 28) /* abnormal ending condition */
#define ESB_ST_REC_QUAL (1 << 26) /* recovery qualifier active */

#define ESB_ST_ERRP_BIT 24 /* LSB for error policy */
#define ESB_ST_ERRP_MASK (3 << 24) /* mask for error policy */
#define ESB_ST_ERRP_MULT (0 << 24) /* abort, discard multiple sequences */
#define ESB_ST_ERRP_SING (1 << 24) /* abort, discard single sequence */
#define ESB_ST_ERRP_INF (2 << 24) /* process with infinite buffers */
#define ESB_ST_ERRP_IMM (3 << 24) /* discard mult. with immed. retran. */

#define ESB_ST_OX_ID_INVL (1 << 23) /* originator XID invalid */
#define ESB_ST_RX_ID_INVL (1 << 22) /* responder XID invalid */
#define ESB_ST_PRI_INUSE (1 << 21) /* priority / preemption in use */

#endif /* _FC_FC2_H_ */
114 changes: 114 additions & 0 deletions include/scsi/fc/fc_fcoe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright(c) 2007 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
* Maintained at www.Open-FCoE.org
*/

#ifndef _FC_FCOE_H_
#define _FC_FCOE_H_

/*
* FCoE - Fibre Channel over Ethernet.
*/

/*
* The FCoE ethertype eventually goes in net/if_ether.h.
*/
#ifndef ETH_P_FCOE
#define ETH_P_FCOE 0x8906 /* FCOE ether type */
#endif

#ifndef ETH_P_8021Q
#define ETH_P_8021Q 0x8100
#endif

/*
* FC_FCOE_OUI hasn't been standardized yet. XXX TBD.
*/
#ifndef FC_FCOE_OUI
#define FC_FCOE_OUI 0x0efc00 /* upper 24 bits of FCOE dest MAC TBD */
#endif

/*
* The destination MAC address for the fabric login may get a different OUI.
* This isn't standardized yet.
*/
#ifndef FC_FCOE_FLOGI_MAC
/* gateway MAC - TBD */
#define FC_FCOE_FLOGI_MAC { 0x0e, 0xfc, 0x00, 0xff, 0xff, 0xfe }
#endif

#define FC_FCOE_VER 0 /* version */

/*
* Ethernet Addresses based on FC S_ID and D_ID.
* Generated by FC_FCOE_OUI | S_ID/D_ID
*/
#define FC_FCOE_ENCAPS_ID(n) (((u64) FC_FCOE_OUI << 24) | (n))
#define FC_FCOE_DECAPS_ID(n) ((n) >> 24)

/*
* FCoE frame header - 14 bytes
*
* This is the August 2007 version of the FCoE header as defined by T11.
* This follows the VLAN header, which includes the ethertype.
*/
struct fcoe_hdr {
__u8 fcoe_ver; /* version field - upper 4 bits */
__u8 fcoe_resvd[12]; /* reserved - send zero and ignore */
__u8 fcoe_sof; /* start of frame per RFC 3643 */
};

#define FC_FCOE_DECAPS_VER(hp) ((hp)->fcoe_ver >> 4)
#define FC_FCOE_ENCAPS_VER(hp, ver) ((hp)->fcoe_ver = (ver) << 4)

/*
* FCoE CRC & EOF - 8 bytes.
*/
struct fcoe_crc_eof {
__le32 fcoe_crc32; /* CRC for FC packet */
__u8 fcoe_eof; /* EOF from RFC 3643 */
__u8 fcoe_resvd[3]; /* reserved - send zero and ignore */
} __attribute__((packed));

/*
* Minimum FCoE + FC header length
* 14 bytes FCoE header + 24 byte FC header = 38 bytes
*/
#define FCOE_HEADER_LEN 38

/*
* Minimum FCoE frame size
* 14 bytes FCoE header + 24 byte FC header + 8 byte FCoE trailer = 46 bytes
*/
#define FCOE_MIN_FRAME 46

/*
* fc_fcoe_set_mac - Store OUI + DID into MAC address field.
* @mac: mac address to be set
* @did: fc dest id to use
*/
static inline void fc_fcoe_set_mac(u8 *mac, u8 *did)
{
mac[0] = (u8) (FC_FCOE_OUI >> 16);
mac[1] = (u8) (FC_FCOE_OUI >> 8);
mac[2] = (u8) FC_FCOE_OUI;
mac[3] = did[0];
mac[4] = did[1];
mac[5] = did[2];
}

#endif /* _FC_FCOE_H_ */
Loading

0 comments on commit f032c2f

Please sign in to comment.