/*1* Copyright(c) 2007 Intel Corporation. All rights reserved.2*3* This program is free software; you can redistribute it and/or modify it4* under the terms and conditions of the GNU General Public License,5* version 2, as published by the Free Software Foundation.6*7* This program is distributed in the hope it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for10* more details.11*12* You should have received a copy of the GNU General Public License along with13* this program; if not, write to the Free Software Foundation, Inc.,14* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.15*16* Maintained at www.Open-FCoE.org17*/18#ifndef _FC_ENCAPS_H_19#define _FC_ENCAPS_H_2021/*22* Protocol definitions from RFC 3643 - Fibre Channel Frame Encapsulation.23*24* Note: The frame length field is the number of 32-bit words in25* the encapsulation including the fcip_encaps_header, CRC and EOF words.26* The minimum frame length value in bytes is (32 + 24 + 4 + 4) * 4 = 64.27* The maximum frame length value in bytes is (32 + 24 + 2112 + 4 + 4) = 2172.28*/29#define FC_ENCAPS_MIN_FRAME_LEN 64 /* min frame len (bytes) (see above) */30#define FC_ENCAPS_MAX_FRAME_LEN (FC_ENCAPS_MIN_FRAME_LEN + FC_MAX_PAYLOAD)3132#define FC_ENCAPS_VER 1 /* current version number */3334struct fc_encaps_hdr {35__u8 fc_proto; /* protocol number */36__u8 fc_ver; /* version of encapsulation */37__u8 fc_proto_n; /* ones complement of protocol */38__u8 fc_ver_n; /* ones complement of version */3940unsigned char fc_proto_data[8]; /* protocol specific data */4142__be16 fc_len_flags; /* 10-bit length/4 w/ 6 flag bits */43__be16 fc_len_flags_n; /* ones complement of length / flags */4445/*46* Offset 0x1047*/48__be32 fc_time[2]; /* time stamp: seconds and fraction */49__be32 fc_crc; /* CRC */50__be32 fc_sof; /* start of frame (see FC_SOF below) */5152/* 0x20 - FC frame content followed by EOF word */53};5455#define FCIP_ENCAPS_HDR_LEN 0x20 /* expected length for asserts */5657/*58* Macro's for making redundant copies of EOF and SOF.59*/60#define FC_XY(x, y) ((((x) & 0xff) << 8) | ((y) & 0xff))61#define FC_XYXY(x, y) ((FCIP_XY(x, y) << 16) | FCIP_XY(x, y))62#define FC_XYNN(x, y) (FCIP_XYXY(x, y) ^ 0xffff)6364#define FC_SOF_ENCODE(n) FC_XYNN(n, n)65#define FC_EOF_ENCODE(n) FC_XYNN(n, n)6667/*68* SOF / EOF bytes.69*/70enum fc_sof {71FC_SOF_F = 0x28, /* fabric */72FC_SOF_I4 = 0x29, /* initiate class 4 */73FC_SOF_I2 = 0x2d, /* initiate class 2 */74FC_SOF_I3 = 0x2e, /* initiate class 3 */75FC_SOF_N4 = 0x31, /* normal class 4 */76FC_SOF_N2 = 0x35, /* normal class 2 */77FC_SOF_N3 = 0x36, /* normal class 3 */78FC_SOF_C4 = 0x39, /* activate class 4 */79} __attribute__((packed));8081enum fc_eof {82FC_EOF_N = 0x41, /* normal (not last frame of seq) */83FC_EOF_T = 0x42, /* terminate (last frame of sequence) */84FC_EOF_RT = 0x44,85FC_EOF_DT = 0x46, /* disconnect-terminate class-1 */86FC_EOF_NI = 0x49, /* normal-invalid */87FC_EOF_DTI = 0x4e, /* disconnect-terminate-invalid */88FC_EOF_RTI = 0x4f,89FC_EOF_A = 0x50, /* abort */90} __attribute__((packed));9192#define FC_SOF_CLASS_MASK 0x06 /* mask for class of service in SOF */9394/*95* Define classes in terms of the SOF code (initial).96*/97enum fc_class {98FC_CLASS_NONE = 0, /* software value indicating no class */99FC_CLASS_2 = FC_SOF_I2,100FC_CLASS_3 = FC_SOF_I3,101FC_CLASS_4 = FC_SOF_I4,102FC_CLASS_F = FC_SOF_F,103};104105/*106* Determine whether SOF code indicates the need for a BLS ACK.107*/108static inline int fc_sof_needs_ack(enum fc_sof sof)109{110return (~sof) & 0x02; /* true for class 1, 2, 4, 6, or F */111}112113/*114* Given an fc_class, return the normal (non-initial) SOF value.115*/116static inline enum fc_sof fc_sof_normal(enum fc_class class)117{118return class + FC_SOF_N3 - FC_SOF_I3; /* diff is always 8 */119}120121/*122* Compute class from SOF value.123*/124static inline enum fc_class fc_sof_class(enum fc_sof sof)125{126return (sof & 0x7) | FC_SOF_F;127}128129/*130* Determine whether SOF is for the initial frame of a sequence.131*/132static inline int fc_sof_is_init(enum fc_sof sof)133{134return sof < 0x30;135}136137#endif /* _FC_ENCAPS_H_ */138139140