xref: /OK3568_Linux_fs/kernel/include/scsi/fc/fc_encaps.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright(c) 2007 Intel Corporation. All rights reserved.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Maintained at www.Open-FCoE.org
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun #ifndef _FC_ENCAPS_H_
8*4882a593Smuzhiyun #define _FC_ENCAPS_H_
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun /*
11*4882a593Smuzhiyun  * Protocol definitions from RFC 3643 - Fibre Channel Frame Encapsulation.
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * Note:  The frame length field is the number of 32-bit words in
14*4882a593Smuzhiyun  * the encapsulation including the fcip_encaps_header, CRC and EOF words.
15*4882a593Smuzhiyun  * The minimum frame length value in bytes is (32 + 24 + 4 + 4) * 4 = 64.
16*4882a593Smuzhiyun  * The maximum frame length value in bytes is (32 + 24 + 2112 + 4 + 4) = 2172.
17*4882a593Smuzhiyun  */
18*4882a593Smuzhiyun #define FC_ENCAPS_MIN_FRAME_LEN 64	/* min frame len (bytes) (see above) */
19*4882a593Smuzhiyun #define FC_ENCAPS_MAX_FRAME_LEN (FC_ENCAPS_MIN_FRAME_LEN + FC_MAX_PAYLOAD)
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #define FC_ENCAPS_VER       1           /* current version number */
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun struct fc_encaps_hdr {
24*4882a593Smuzhiyun 	__u8	fc_proto;	/* protocol number */
25*4882a593Smuzhiyun 	__u8	fc_ver;		/* version of encapsulation */
26*4882a593Smuzhiyun 	__u8	fc_proto_n;	/* ones complement of protocol */
27*4882a593Smuzhiyun 	__u8	fc_ver_n;	/* ones complement of version */
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun 	unsigned char fc_proto_data[8]; /* protocol specific data */
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun 	__be16	fc_len_flags;	/* 10-bit length/4 w/ 6 flag bits */
32*4882a593Smuzhiyun 	__be16	fc_len_flags_n;	/* ones complement of length / flags */
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun 	/*
35*4882a593Smuzhiyun 	 * Offset 0x10
36*4882a593Smuzhiyun 	 */
37*4882a593Smuzhiyun 	__be32	fc_time[2];	/* time stamp: seconds and fraction */
38*4882a593Smuzhiyun 	__be32	fc_crc;		/* CRC */
39*4882a593Smuzhiyun 	__be32	fc_sof;		/* start of frame (see FC_SOF below) */
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun 	/* 0x20 - FC frame content followed by EOF word */
42*4882a593Smuzhiyun };
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun #define FCIP_ENCAPS_HDR_LEN 0x20	/* expected length for asserts */
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /*
47*4882a593Smuzhiyun  * Macro's for making redundant copies of EOF and SOF.
48*4882a593Smuzhiyun  */
49*4882a593Smuzhiyun #define FC_XY(x, y)		((((x) & 0xff) << 8) | ((y) & 0xff))
50*4882a593Smuzhiyun #define FC_XYXY(x, y)		((FCIP_XY(x, y) << 16) | FCIP_XY(x, y))
51*4882a593Smuzhiyun #define FC_XYNN(x, y)		(FCIP_XYXY(x, y) ^ 0xffff)
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun #define FC_SOF_ENCODE(n)	FC_XYNN(n, n)
54*4882a593Smuzhiyun #define FC_EOF_ENCODE(n)	FC_XYNN(n, n)
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /*
57*4882a593Smuzhiyun  * SOF / EOF bytes.
58*4882a593Smuzhiyun  */
59*4882a593Smuzhiyun enum fc_sof {
60*4882a593Smuzhiyun 	FC_SOF_F =	0x28,	/* fabric */
61*4882a593Smuzhiyun 	FC_SOF_I4 =	0x29,	/* initiate class 4 */
62*4882a593Smuzhiyun 	FC_SOF_I2 =	0x2d,	/* initiate class 2 */
63*4882a593Smuzhiyun 	FC_SOF_I3 =	0x2e,	/* initiate class 3 */
64*4882a593Smuzhiyun 	FC_SOF_N4 =	0x31,	/* normal class 4 */
65*4882a593Smuzhiyun 	FC_SOF_N2 =	0x35,	/* normal class 2 */
66*4882a593Smuzhiyun 	FC_SOF_N3 =	0x36,	/* normal class 3 */
67*4882a593Smuzhiyun 	FC_SOF_C4 =	0x39,	/* activate class 4 */
68*4882a593Smuzhiyun } __attribute__((packed));
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun enum fc_eof {
71*4882a593Smuzhiyun 	FC_EOF_N =	0x41,	/* normal (not last frame of seq) */
72*4882a593Smuzhiyun 	FC_EOF_T =	0x42,	/* terminate (last frame of sequence) */
73*4882a593Smuzhiyun 	FC_EOF_RT =	0x44,
74*4882a593Smuzhiyun 	FC_EOF_DT =	0x46,	/* disconnect-terminate class-1 */
75*4882a593Smuzhiyun 	FC_EOF_NI =	0x49,	/* normal-invalid */
76*4882a593Smuzhiyun 	FC_EOF_DTI =	0x4e,	/* disconnect-terminate-invalid */
77*4882a593Smuzhiyun 	FC_EOF_RTI =	0x4f,
78*4882a593Smuzhiyun 	FC_EOF_A =	0x50,	/* abort */
79*4882a593Smuzhiyun } __attribute__((packed));
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun #define FC_SOF_CLASS_MASK 0x06	/* mask for class of service in SOF */
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun /*
84*4882a593Smuzhiyun  * Define classes in terms of the SOF code (initial).
85*4882a593Smuzhiyun  */
86*4882a593Smuzhiyun enum fc_class {
87*4882a593Smuzhiyun 	FC_CLASS_NONE = 0,	/* software value indicating no class */
88*4882a593Smuzhiyun 	FC_CLASS_2 =	FC_SOF_I2,
89*4882a593Smuzhiyun 	FC_CLASS_3 =	FC_SOF_I3,
90*4882a593Smuzhiyun 	FC_CLASS_4 =	FC_SOF_I4,
91*4882a593Smuzhiyun 	FC_CLASS_F =	FC_SOF_F,
92*4882a593Smuzhiyun };
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun /*
95*4882a593Smuzhiyun  * Determine whether SOF code indicates the need for a BLS ACK.
96*4882a593Smuzhiyun  */
fc_sof_needs_ack(enum fc_sof sof)97*4882a593Smuzhiyun static inline int fc_sof_needs_ack(enum fc_sof sof)
98*4882a593Smuzhiyun {
99*4882a593Smuzhiyun 	return (~sof) & 0x02;	/* true for class 1, 2, 4, 6, or F */
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun /*
103*4882a593Smuzhiyun  * Given an fc_class, return the normal (non-initial) SOF value.
104*4882a593Smuzhiyun  */
fc_sof_normal(enum fc_class class)105*4882a593Smuzhiyun static inline enum fc_sof fc_sof_normal(enum fc_class class)
106*4882a593Smuzhiyun {
107*4882a593Smuzhiyun 	return class + FC_SOF_N3 - FC_SOF_I3;	/* diff is always 8 */
108*4882a593Smuzhiyun }
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun /*
111*4882a593Smuzhiyun  * Compute class from SOF value.
112*4882a593Smuzhiyun  */
fc_sof_class(enum fc_sof sof)113*4882a593Smuzhiyun static inline enum fc_class fc_sof_class(enum fc_sof sof)
114*4882a593Smuzhiyun {
115*4882a593Smuzhiyun 	return (sof & 0x7) | FC_SOF_F;
116*4882a593Smuzhiyun }
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun /*
119*4882a593Smuzhiyun  * Determine whether SOF is for the initial frame of a sequence.
120*4882a593Smuzhiyun  */
fc_sof_is_init(enum fc_sof sof)121*4882a593Smuzhiyun static inline int fc_sof_is_init(enum fc_sof sof)
122*4882a593Smuzhiyun {
123*4882a593Smuzhiyun 	return sof < 0x30;
124*4882a593Smuzhiyun }
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun #endif /* _FC_ENCAPS_H_ */
127