Skip to content

Commit f032c2f

Browse files
Robert Lovejejb
authored andcommitted
[SCSI] FC protocol definition header files
Signed-off-by: Robert Love <robert.w.love@intel.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
1 parent 21465ed commit f032c2f

8 files changed

Lines changed: 1983 additions & 0 deletions

File tree

‎include/scsi/fc/fc_els.h‎

Lines changed: 816 additions & 0 deletions
Large diffs are not rendered by default.

‎include/scsi/fc/fc_encaps.h‎

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

‎include/scsi/fc/fc_fc2.h‎

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Copyright(c) 2007 Intel Corporation. All rights reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms and conditions of the GNU General Public License,
6+
* version 2, as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program; if not, write to the Free Software Foundation, Inc.,
15+
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16+
*
17+
* Maintained at www.Open-FCoE.org
18+
*/
19+
20+
#ifndef _FC_FC2_H_
21+
#define _FC_FC2_H_
22+
23+
/*
24+
* Fibre Channel Exchanges and Sequences.
25+
*/
26+
#ifndef PACKED
27+
#define PACKED __attribute__ ((__packed__))
28+
#endif /* PACKED */
29+
30+
31+
/*
32+
* Sequence Status Block.
33+
* This format is set by the FC-FS standard and is sent over the wire.
34+
* Note that the fields aren't all naturally aligned.
35+
*/
36+
struct fc_ssb {
37+
__u8 ssb_seq_id; /* sequence ID */
38+
__u8 _ssb_resvd;
39+
__be16 ssb_low_seq_cnt; /* lowest SEQ_CNT */
40+
41+
__be16 ssb_high_seq_cnt; /* highest SEQ_CNT */
42+
__be16 ssb_s_stat; /* sequence status flags */
43+
44+
__be16 ssb_err_seq_cnt; /* error SEQ_CNT */
45+
__u8 ssb_fh_cs_ctl; /* frame header CS_CTL */
46+
__be16 ssb_fh_ox_id; /* frame header OX_ID */
47+
__be16 ssb_rx_id; /* responder's exchange ID */
48+
__u8 _ssb_resvd2[2];
49+
} PACKED;
50+
51+
/*
52+
* The SSB should be 17 bytes. Since it's layout is somewhat strange,
53+
* we define the size here so that code can ASSERT that the size comes out
54+
* correct.
55+
*/
56+
#define FC_SSB_SIZE 17 /* length of fc_ssb for assert */
57+
58+
/*
59+
* ssb_s_stat - flags from FC-FS-2 T11/1619-D Rev 0.90.
60+
*/
61+
#define SSB_ST_RESP (1 << 15) /* sequence responder */
62+
#define SSB_ST_ACTIVE (1 << 14) /* sequence is active */
63+
#define SSB_ST_ABNORMAL (1 << 12) /* abnormal ending condition */
64+
65+
#define SSB_ST_REQ_MASK (3 << 10) /* ACK, abort sequence condition */
66+
#define SSB_ST_REQ_CONT (0 << 10)
67+
#define SSB_ST_REQ_ABORT (1 << 10)
68+
#define SSB_ST_REQ_STOP (2 << 10)
69+
#define SSB_ST_REQ_RETRANS (3 << 10)
70+
71+
#define SSB_ST_ABTS (1 << 9) /* ABTS protocol completed */
72+
#define SSB_ST_RETRANS (1 << 8) /* retransmission completed */
73+
#define SSB_ST_TIMEOUT (1 << 7) /* sequence timed out by recipient */
74+
#define SSB_ST_P_RJT (1 << 6) /* P_RJT transmitted */
75+
76+
#define SSB_ST_CLASS_BIT 4 /* class of service field LSB */
77+
#define SSB_ST_CLASS_MASK 3 /* class of service mask */
78+
#define SSB_ST_ACK (1 << 3) /* ACK (EOFt or EOFdt) transmitted */
79+
80+
/*
81+
* Exchange Status Block.
82+
* This format is set by the FC-FS standard and is sent over the wire.
83+
* Note that the fields aren't all naturally aligned.
84+
*/
85+
struct fc_esb {
86+
__u8 esb_cs_ctl; /* CS_CTL for frame header */
87+
__be16 esb_ox_id; /* originator exchange ID */
88+
__be16 esb_rx_id; /* responder exchange ID */
89+
__be32 esb_orig_fid; /* fabric ID of originator */
90+
__be32 esb_resp_fid; /* fabric ID of responder */
91+
__be32 esb_e_stat; /* status */
92+
__u8 _esb_resvd[4];
93+
__u8 esb_service_params[112]; /* TBD */
94+
__u8 esb_seq_status[8]; /* sequence statuses, 8 bytes each */
95+
} __attribute__((packed));;
96+
97+
98+
/*
99+
* Define expected size for ASSERTs.
100+
* See comments on FC_SSB_SIZE.
101+
*/
102+
#define FC_ESB_SIZE (1 + 5*4 + 112 + 8) /* expected size */
103+
104+
/*
105+
* esb_e_stat - flags from FC-FS-2 T11/1619-D Rev 0.90.
106+
*/
107+
#define ESB_ST_RESP (1 << 31) /* responder to exchange */
108+
#define ESB_ST_SEQ_INIT (1 << 30) /* port holds sequence initiaive */
109+
#define ESB_ST_COMPLETE (1 << 29) /* exchange is complete */
110+
#define ESB_ST_ABNORMAL (1 << 28) /* abnormal ending condition */
111+
#define ESB_ST_REC_QUAL (1 << 26) /* recovery qualifier active */
112+
113+
#define ESB_ST_ERRP_BIT 24 /* LSB for error policy */
114+
#define ESB_ST_ERRP_MASK (3 << 24) /* mask for error policy */
115+
#define ESB_ST_ERRP_MULT (0 << 24) /* abort, discard multiple sequences */
116+
#define ESB_ST_ERRP_SING (1 << 24) /* abort, discard single sequence */
117+
#define ESB_ST_ERRP_INF (2 << 24) /* process with infinite buffers */
118+
#define ESB_ST_ERRP_IMM (3 << 24) /* discard mult. with immed. retran. */
119+
120+
#define ESB_ST_OX_ID_INVL (1 << 23) /* originator XID invalid */
121+
#define ESB_ST_RX_ID_INVL (1 << 22) /* responder XID invalid */
122+
#define ESB_ST_PRI_INUSE (1 << 21) /* priority / preemption in use */
123+
124+
#endif /* _FC_FC2_H_ */

‎include/scsi/fc/fc_fcoe.h‎

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright(c) 2007 Intel Corporation. All rights reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms and conditions of the GNU General Public License,
6+
* version 2, as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program; if not, write to the Free Software Foundation, Inc.,
15+
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16+
*
17+
* Maintained at www.Open-FCoE.org
18+
*/
19+
20+
#ifndef _FC_FCOE_H_
21+
#define _FC_FCOE_H_
22+
23+
/*
24+
* FCoE - Fibre Channel over Ethernet.
25+
*/
26+
27+
/*
28+
* The FCoE ethertype eventually goes in net/if_ether.h.
29+
*/
30+
#ifndef ETH_P_FCOE
31+
#define ETH_P_FCOE 0x8906 /* FCOE ether type */
32+
#endif
33+
34+
#ifndef ETH_P_8021Q
35+
#define ETH_P_8021Q 0x8100
36+
#endif
37+
38+
/*
39+
* FC_FCOE_OUI hasn't been standardized yet. XXX TBD.
40+
*/
41+
#ifndef FC_FCOE_OUI
42+
#define FC_FCOE_OUI 0x0efc00 /* upper 24 bits of FCOE dest MAC TBD */
43+
#endif
44+
45+
/*
46+
* The destination MAC address for the fabric login may get a different OUI.
47+
* This isn't standardized yet.
48+
*/
49+
#ifndef FC_FCOE_FLOGI_MAC
50+
/* gateway MAC - TBD */
51+
#define FC_FCOE_FLOGI_MAC { 0x0e, 0xfc, 0x00, 0xff, 0xff, 0xfe }
52+
#endif
53+
54+
#define FC_FCOE_VER 0 /* version */
55+
56+
/*
57+
* Ethernet Addresses based on FC S_ID and D_ID.
58+
* Generated by FC_FCOE_OUI | S_ID/D_ID
59+
*/
60+
#define FC_FCOE_ENCAPS_ID(n) (((u64) FC_FCOE_OUI << 24) | (n))
61+
#define FC_FCOE_DECAPS_ID(n) ((n) >> 24)
62+
63+
/*
64+
* FCoE frame header - 14 bytes
65+
*
66+
* This is the August 2007 version of the FCoE header as defined by T11.
67+
* This follows the VLAN header, which includes the ethertype.
68+
*/
69+
struct fcoe_hdr {
70+
__u8 fcoe_ver; /* version field - upper 4 bits */
71+
__u8 fcoe_resvd[12]; /* reserved - send zero and ignore */
72+
__u8 fcoe_sof; /* start of frame per RFC 3643 */
73+
};
74+
75+
#define FC_FCOE_DECAPS_VER(hp) ((hp)->fcoe_ver >> 4)
76+
#define FC_FCOE_ENCAPS_VER(hp, ver) ((hp)->fcoe_ver = (ver) << 4)
77+
78+
/*
79+
* FCoE CRC & EOF - 8 bytes.
80+
*/
81+
struct fcoe_crc_eof {
82+
__le32 fcoe_crc32; /* CRC for FC packet */
83+
__u8 fcoe_eof; /* EOF from RFC 3643 */
84+
__u8 fcoe_resvd[3]; /* reserved - send zero and ignore */
85+
} __attribute__((packed));
86+
87+
/*
88+
* Minimum FCoE + FC header length
89+
* 14 bytes FCoE header + 24 byte FC header = 38 bytes
90+
*/
91+
#define FCOE_HEADER_LEN 38
92+
93+
/*
94+
* Minimum FCoE frame size
95+
* 14 bytes FCoE header + 24 byte FC header + 8 byte FCoE trailer = 46 bytes
96+
*/
97+
#define FCOE_MIN_FRAME 46
98+
99+
/*
100+
* fc_fcoe_set_mac - Store OUI + DID into MAC address field.
101+
* @mac: mac address to be set
102+
* @did: fc dest id to use
103+
*/
104+
static inline void fc_fcoe_set_mac(u8 *mac, u8 *did)
105+
{
106+
mac[0] = (u8) (FC_FCOE_OUI >> 16);
107+
mac[1] = (u8) (FC_FCOE_OUI >> 8);
108+
mac[2] = (u8) FC_FCOE_OUI;
109+
mac[3] = did[0];
110+
mac[4] = did[1];
111+
mac[5] = did[2];
112+
}
113+
114+
#endif /* _FC_FCOE_H_ */

0 commit comments

Comments
 (0)