1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
4  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
5  */
6 
7 #ifndef _FDLS_FC_H_
8 #define _FDLS_FC_H_
9 
10 /* This file contains the declarations for FC fabric services
11  * and target discovery
12  *
13  * Request and Response for
14  * 1. FLOGI
15  * 2. PLOGI to Fabric Controller
16  * 3. GPN_ID, GPN_FT
17  * 4. RSCN
18  * 5. PLOGI to Target
19  * 6. PRLI to Target
20  */
21 
22 #include <scsi/scsi.h>
23 #include <scsi/fc/fc_els.h>
24 #include <uapi/scsi/fc/fc_fs.h>
25 #include <uapi/scsi/fc/fc_ns.h>
26 #include <uapi/scsi/fc/fc_gs.h>
27 #include <uapi/linux/if_ether.h>
28 #include <scsi/fc/fc_ms.h>
29 #include <linux/minmax.h>
30 #include <linux/if_ether.h>
31 #include <scsi/fc/fc_encaps.h>
32 #include <scsi/fc/fc_fcoe.h>
33 
34 #define FDLS_MIN_FRAMES	(32)
35 #define FDLS_MIN_FRAME_ELEM	(4)
36 #define FNIC_FCP_SP_RD_XRDY_DIS 0x00000002
37 #define FNIC_FCP_SP_TARGET      0x00000010
38 #define FNIC_FCP_SP_INITIATOR   0x00000020
39 #define FNIC_FCP_SP_CONF_CMPL   0x00000080
40 #define FNIC_FCP_SP_RETRY       0x00000100
41 
42 #define FNIC_FC_CONCUR_SEQS    (0xFF)
43 #define FNIC_FC_RO_INFO        (0x1F)
44 
45 /* Little Endian */
46 #define FNIC_UNASSIGNED_OXID	(0xffff)
47 #define FNIC_UNASSIGNED_RXID	(0xffff)
48 #define FNIC_ELS_REQ_FCTL      (0x000029)
49 #define FNIC_ELS_REP_FCTL      (0x000099)
50 
51 #define FNIC_FCP_RSP_FCTL      (0x000099)
52 #define FNIC_REQ_ABTS_FCTL     (0x000009)
53 
54 #define FNIC_FC_PH_VER_HI      (0x20)
55 #define FNIC_FC_PH_VER_LO      (0x20)
56 #define FNIC_FC_PH_VER         (0x2020)
57 #define FNIC_FC_B2B_CREDIT     (0x0A)
58 #define FNIC_FC_B2B_RDF_SZ     (0x0800)
59 
60 #define FNIC_LOGI_RDF_SIZE(_logi) ((_logi).fl_csp.sp_bb_data)
61 #define FNIC_LOGI_R_A_TOV(_logi) ((_logi).fl_csp.sp_r_a_tov)
62 #define FNIC_LOGI_E_D_TOV(_logi) ((_logi).fl_csp.sp_e_d_tov)
63 #define FNIC_LOGI_FEATURES(_logi) (be16_to_cpu((_logi).fl_csp.sp_features))
64 #define FNIC_LOGI_PORT_NAME(_logi) ((_logi).fl_wwpn)
65 #define FNIC_LOGI_NODE_NAME(_logi) ((_logi).fl_wwnn)
66 
67 #define FNIC_LOGI_SET_RDF_SIZE(_logi, _rdf_size) \
68 	(FNIC_LOGI_RDF_SIZE(_logi) = cpu_to_be16(_rdf_size))
69 #define FNIC_LOGI_SET_E_D_TOV(_logi, _e_d_tov) \
70 	(FNIC_LOGI_E_D_TOV(_logi) = cpu_to_be32(_e_d_tov))
71 #define FNIC_LOGI_SET_R_A_TOV(_logi, _r_a_tov) \
72 	(FNIC_LOGI_R_A_TOV(_logi) = cpu_to_be32(_r_a_tov))
73 
74 #define FNIC_STD_SET_S_ID(_fchdr, _sid)        memcpy((_fchdr).fh_s_id, _sid, 3)
75 #define FNIC_STD_SET_D_ID(_fchdr, _did)        memcpy((_fchdr).fh_d_id, _did, 3)
76 #define FNIC_STD_SET_OX_ID(_fchdr, _oxid)      ((_fchdr).fh_ox_id = cpu_to_be16(_oxid))
77 #define FNIC_STD_SET_RX_ID(_fchdr, _rxid)      ((_fchdr).fh_rx_id = cpu_to_be16(_rxid))
78 
79 #define FNIC_STD_SET_R_CTL(_fchdr, _rctl)	((_fchdr).fh_r_ctl = _rctl)
80 #define FNIC_STD_SET_TYPE(_fchdr, _type)	((_fchdr).fh_type = _type)
81 #define FNIC_STD_SET_F_CTL(_fchdr, _fctl) \
82 	put_unaligned_be24(_fctl, &((_fchdr).fh_f_ctl))
83 
84 #define FNIC_STD_SET_NPORT_NAME(_ptr, _wwpn)	put_unaligned_be64(_wwpn, _ptr)
85 #define FNIC_STD_SET_NODE_NAME(_ptr, _wwnn)	put_unaligned_be64(_wwnn, _ptr)
86 #define FNIC_STD_SET_PORT_ID(__req, __portid) \
87 	memcpy(__req.fr_fid.fp_fid, __portid, 3)
88 #define FNIC_STD_SET_PORT_NAME(_req, _pName) \
89 	(put_unaligned_be64(_pName, &_req.fr_wwn))
90 
91 #define FNIC_STD_GET_OX_ID(_fchdr)		(be16_to_cpu((_fchdr)->fh_ox_id))
92 #define FNIC_STD_GET_RX_ID(_fchdr)		(be16_to_cpu((_fchdr)->fh_rx_id))
93 #define FNIC_STD_GET_S_ID(_fchdr)		((_fchdr)->fh_s_id)
94 #define FNIC_STD_GET_D_ID(_fchdr)		((_fchdr)->fh_d_id)
95 #define FNIC_STD_GET_TYPE(_fchdr)		((_fchdr)->fh_type)
96 #define FNIC_STD_GET_F_CTL(_fchdr)		((_fchdr)->fh_f_ctl)
97 #define FNIC_STD_GET_R_CTL(_fchdr)		((_fchdr)->fh_r_ctl)
98 
99 #define FNIC_STD_GET_FC_CT_CMD(__fcct_hdr)  (be16_to_cpu(__fcct_hdr->ct_cmd))
100 
101 #define FNIC_FCOE_MAX_FRAME_SZ  (2048)
102 #define FNIC_FCOE_MIN_FRAME_SZ  (280)
103 #define FNIC_FC_MAX_PAYLOAD_LEN (2048)
104 #define FNIC_MIN_DATA_FIELD_SIZE  (256)
105 
106 #define FNIC_FC_EDTOV_NSEC    (0x400)
107 #define FNIC_NSEC_TO_MSEC     (0x1000000)
108 #define FCP_PRLI_FUNC_TARGET	(0x0010)
109 
110 #define FNIC_FC_R_CTL_SOLICITED_DATA			(0x21)
111 #define FNIC_FC_F_CTL_LAST_END_SEQ				(0x98)
112 #define FNIC_FC_F_CTL_LAST_END_SEQ_INT			(0x99)
113 #define FNIC_FC_F_CTL_FIRST_LAST_SEQINIT		(0x29)
114 #define FNIC_FC_R_CTL_FC4_SCTL					(0x03)
115 #define FNIC_FC_CS_CTL							(0x00)
116 
117 #define FNIC_FC_FRAME_UNSOLICITED(_fchdr)				\
118 		(_fchdr->fh_r_ctl == FC_RCTL_ELS_REQ)
119 #define FNIC_FC_FRAME_SOLICITED_DATA(_fchdr)			\
120 		(_fchdr->fh_r_ctl == FNIC_FC_R_CTL_SOLICITED_DATA)
121 #define FNIC_FC_FRAME_SOLICITED_CTRL_REPLY(_fchdr)		\
122 		(_fchdr->fh_r_ctl == FC_RCTL_ELS_REP)
123 #define FNIC_FC_FRAME_FCTL_LAST_END_SEQ(_fchdr)			\
124 		(_fchdr->fh_f_ctl[0] == FNIC_FC_F_CTL_LAST_END_SEQ)
125 #define FNIC_FC_FRAME_FCTL_LAST_END_SEQ_INT(_fchdr)		\
126 		(_fchdr->fh_f_ctl[0] == FNIC_FC_F_CTL_LAST_END_SEQ_INT)
127 #define FNIC_FC_FRAME_FCTL_FIRST_LAST_SEQINIT(_fchdr)	\
128 		(_fchdr->fh_f_ctl[0] == FNIC_FC_F_CTL_FIRST_LAST_SEQINIT)
129 #define FNIC_FC_FRAME_FC4_SCTL(_fchdr)					\
130 		(_fchdr->fh_r_ctl == FNIC_FC_R_CTL_FC4_SCTL)
131 #define FNIC_FC_FRAME_TYPE_BLS(_fchdr) (_fchdr->fh_type == FC_TYPE_BLS)
132 #define FNIC_FC_FRAME_TYPE_ELS(_fchdr) (_fchdr->fh_type == FC_TYPE_ELS)
133 #define FNIC_FC_FRAME_TYPE_FC_GS(_fchdr) (_fchdr->fh_type == FC_TYPE_CT)
134 #define FNIC_FC_FRAME_CS_CTL(_fchdr) (_fchdr->fh_cs_ctl == FNIC_FC_CS_CTL)
135 
136 #define FNIC_FC_C3_RDF         (0xfff)
137 #define FNIC_FC_PLOGI_RSP_RDF(_plogi_rsp) \
138 	(min(_plogi_rsp->u.csp_plogi.b2b_rdf_size, \
139 	(_plogi_rsp->spc3[4] & FNIC_FC_C3_RDF)))
140 #define FNIC_FC_PLOGI_RSP_CONCUR_SEQ(_plogi_rsp) \
141 	(min((uint16_t) (be16_to_cpu(_plogi_rsp->els.fl_csp.sp_tot_seq)), \
142 	 (uint16_t) (be16_to_cpu(_plogi_rsp->els.fl_cssp[2].cp_con_seq) & 0xff)))
143 
144 /* FLOGI/PLOGI struct */
145 struct fc_std_flogi {
146 	struct fc_frame_header fchdr;
147 	struct fc_els_flogi els;
148 } __packed;
149 
150 struct fc_std_els_acc_rsp {
151 	struct fc_frame_header fchdr;
152 	struct fc_els_ls_acc acc;
153 } __packed;
154 
155 struct fc_std_els_rjt_rsp {
156 	struct fc_frame_header fchdr;
157 	struct fc_els_ls_rjt rej;
158 } __packed;
159 
160 struct fc_std_els_adisc {
161 	struct fc_frame_header fchdr;
162 	struct fc_els_adisc els;
163 } __packed;
164 
165 struct fc_std_rls_acc {
166 	struct fc_frame_header fchdr;
167 	struct fc_els_rls_resp els;
168 } __packed;
169 
170 struct fc_std_abts_ba_acc {
171 	struct fc_frame_header fchdr;
172 	struct fc_ba_acc acc;
173 } __packed;
174 
175 struct fc_std_abts_ba_rjt {
176 	struct fc_frame_header fchdr;
177 	struct fc_ba_rjt rjt;
178 } __packed;
179 
180 struct fc_std_els_prli {
181 	struct fc_frame_header fchdr;
182 	struct fc_els_prli els_prli;
183 	struct fc_els_spp sp;
184 }	 __packed;
185 
186 struct fc_std_rpn_id {
187 	struct fc_frame_header fchdr;
188 	struct fc_ct_hdr fc_std_ct_hdr;
189 	struct fc_ns_rn_id rpn_id;
190 } __packed;
191 
192 struct fc_std_fdmi_rhba {
193 	struct fc_frame_header fchdr;
194 	struct fc_ct_hdr fc_std_ct_hdr;
195 	struct fc_fdmi_rhba rhba;
196 } __packed;
197 
198 struct fc_std_fdmi_rpa {
199 	struct fc_frame_header fchdr;
200 	struct fc_ct_hdr fc_std_ct_hdr;
201 	struct fc_fdmi_rpa rpa;
202 }	 __packed;
203 
204 struct fc_std_rft_id {
205 	struct fc_frame_header fchdr;
206 	struct fc_ct_hdr fc_std_ct_hdr;
207 	struct fc_ns_rft_id rft_id;
208 } __packed;
209 
210 struct fc_std_rff_id {
211 	struct fc_frame_header fchdr;
212 	struct fc_ct_hdr fc_std_ct_hdr;
213 	struct fc_ns_rff_id rff_id;
214 } __packed;
215 
216 struct fc_std_gpn_ft {
217 	struct fc_frame_header fchdr;
218 	struct fc_ct_hdr fc_std_ct_hdr;
219 	struct fc_ns_gid_ft gpn_ft;
220 } __packed;
221 
222 /* Accept CT_IU	for	GPN_FT	*/
223 struct fc_gpn_ft_rsp_iu {
224 	uint8_t		ctrl;
225 	uint8_t		fcid[3];
226 	uint32_t	rsvd;
227 	__be64		wwpn;
228 } __packed;
229 
230 struct fc_std_rls {
231 	struct fc_frame_header fchdr;
232 	struct fc_els_rls els;
233 } __packed;
234 
235 struct fc_std_scr {
236 	struct fc_frame_header fchdr;
237 	struct fc_els_scr scr;
238 } __packed;
239 
240 struct fc_std_rscn {
241 	struct fc_frame_header fchdr;
242 	struct fc_els_rscn els;
243 } __packed;
244 
245 struct fc_std_logo {
246 	struct fc_frame_header fchdr;
247 	struct fc_els_logo els;
248 } __packed;
249 
250 #define	FNIC_ETH_FCOE_HDRS_OFFSET	\
251 	(sizeof(struct ethhdr) + sizeof(struct fcoe_hdr))
252 
253 #endif	/*	_FDLS_FC_H	*/
254