aboutsummaryrefslogtreecommitdiff
path: root/drivers/scsi/bfa/bfa_fcbuild.h
blob: 49e0ee4a733479b71f8faa5ee9b1def8f1d78a5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
 * Copyright (c) 2014- QLogic Corporation.
 * All rights reserved
 * www.qlogic.com
 *
 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
 */
/*
 * fcbuild.h - FC link service frame building and parsing routines
 */

#ifndef __FCBUILD_H__
#define __FCBUILD_H__

#include "bfad_drv.h"
#include "bfa_fc.h"
#include "bfa_defs_fcs.h"

/*
 * Utility Macros/functions
 */

#define wwn_is_equal(_wwn1, _wwn2)		\
	(memcmp(&(_wwn1), &(_wwn2), sizeof(wwn_t)) == 0)

#define fc_roundup(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))

/*
 * Given the fc response length, this routine will return
 * the length of the actual payload bytes following the CT header.
 *
 * Assumes the input response length does not include the crc, eof, etc.
 */
static inline   u32
fc_get_ctresp_pyld_len(u32 resp_len)
{
	return resp_len - sizeof(struct ct_hdr_s);
}

/*
 * Convert bfa speed to rpsc speed value.
 */
static inline  enum bfa_port_speed
fc_rpsc_operspeed_to_bfa_speed(enum fc_rpsc_op_speed speed)
{
	switch (speed) {

	case RPSC_OP_SPEED_1G:
		return BFA_PORT_SPEED_1GBPS;

	case RPSC_OP_SPEED_2G:
		return BFA_PORT_SPEED_2GBPS;

	case RPSC_OP_SPEED_4G:
		return BFA_PORT_SPEED_4GBPS;

	case RPSC_OP_SPEED_8G:
		return BFA_PORT_SPEED_8GBPS;

	case RPSC_OP_SPEED_16G:
		return BFA_PORT_SPEED_16GBPS;

	case RPSC_OP_SPEED_10G:
		return BFA_PORT_SPEED_10GBPS;

	default:
		return BFA_PORT_SPEED_UNKNOWN;
	}
}

/*
 * Convert RPSC speed to bfa speed value.
 */
static inline   enum fc_rpsc_op_speed
fc_bfa_speed_to_rpsc_operspeed(enum bfa_port_speed op_speed)
{
	switch (op_speed) {

	case BFA_PORT_SPEED_1GBPS:
		return RPSC_OP_SPEED_1G;

	case BFA_PORT_SPEED_2GBPS:
		return RPSC_OP_SPEED_2G;

	case BFA_PORT_SPEED_4GBPS:
		return RPSC_OP_SPEED_4G;

	case BFA_PORT_SPEED_8GBPS:
		return RPSC_OP_SPEED_8G;

	case BFA_PORT_SPEED_16GBPS:
		return RPSC_OP_SPEED_16G;

	case BFA_PORT_SPEED_10GBPS:
		return RPSC_OP_SPEED_10G;

	default:
		return RPSC_OP_SPEED_NOT_EST;
	}
}

enum fc_parse_status {
	FC_PARSE_OK = 0,
	FC_PARSE_FAILURE = 1,
	FC_PARSE_BUSY = 2,
	FC_PARSE_LEN_INVAL,
	FC_PARSE_ACC_INVAL,
	FC_PARSE_PWWN_NOT_EQUAL,
	FC_PARSE_NWWN_NOT_EQUAL,
	FC_PARSE_RXSZ_INVAL,
	FC_PARSE_NOT_FCP,
	FC_PARSE_OPAFLAG_INVAL,
	FC_PARSE_RPAFLAG_INVAL,
	FC_PARSE_OPA_INVAL,
	FC_PARSE_RPA_INVAL,

};

struct fc_templates_s {
	struct fchs_s fc_els_req;
	struct fchs_s fc_bls_req;
	struct fc_logi_s plogi;
	struct fc_rrq_s rrq;
};

void            fcbuild_init(void);

u16        fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
			u32 s_id, u16 ox_id, wwn_t port_name, wwn_t node_name,
			       u16 pdu_size, u8 set_npiv, u8 set_auth,
			       u16 local_bb_credits);

u16        fc_fdisc_build(struct fchs_s *buf, struct fc_logi_s *flogi, u32 s_id,
			       u16 ox_id, wwn_t port_name, wwn_t node_name,
			       u16 pdu_size);

u16        fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
				   u32 s_id, __be16 ox_id,
				   wwn_t port_name, wwn_t node_name,
				   u16 pdu_size,
				   u16 local_bb_credits, u8 bb_scn);

u16        fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id,
			       u32 s_id, u16 ox_id, wwn_t port_name,
			       wwn_t node_name, u16 pdu_size, u16 bb_cr);

enum fc_parse_status fc_plogi_parse(struct fchs_s *fchs);

u16        fc_abts_build(struct fchs_s *buf, u32 d_id, u32 s_id,
			      u16 ox_id);

enum fc_parse_status fc_abts_rsp_parse(struct fchs_s *buf, int len);

u16        fc_rrq_build(struct fchs_s *buf, struct fc_rrq_s *rrq, u32 d_id,
			     u32 s_id, u16 ox_id, u16 rrq_oxid);

u16        fc_rspnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
				u16 ox_id, u8 *name);
u16	fc_rsnn_nn_build(struct fchs_s *fchs, void *pld, u32 s_id,
				wwn_t node_name, u8 *name);

u16        fc_rftid_build(struct fchs_s *fchs, void *pld, u32 s_id,
			       u16 ox_id, enum bfa_lport_role role);

u16       fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id,
				   u16 ox_id, u8 *fc4_bitmap,
				   u32 bitmap_size);

u16	fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
			u16 ox_id, u8 fc4_type, u8 fc4_ftrs);

u16        fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
			       u16 ox_id, wwn_t port_name);

u16        fc_gpnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
			       u16 ox_id, u32 port_id);

u16	fc_gs_rjt_build(struct fchs_s *fchs, struct ct_hdr_s *cthdr,
			u32 d_id, u32 s_id, u16 ox_id,
			u8 reason_code, u8 reason_code_expl);

u16        fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
			u8 set_br_reg, u32 s_id, u16 ox_id);

u16        fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
				   u32 s_id, u16 ox_id,
				   wwn_t port_name, wwn_t node_name,
				   u16 pdu_size, u16 bb_cr);

u16        fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
			u32 d_id, u32 s_id, __be16 ox_id, wwn_t port_name,
			       wwn_t node_name);

enum fc_parse_status fc_adisc_parse(struct fchs_s *fchs, void *pld,
			u32 host_dap, wwn_t node_name, wwn_t port_name);

enum fc_parse_status fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len,
				 wwn_t port_name, wwn_t node_name);

u16        fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
				   u32 d_id, u32 s_id, __be16 ox_id,
				   wwn_t port_name, wwn_t node_name);
u16        fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt,
				u32 d_id, u32 s_id, __be16 ox_id,
				u8 reason_code, u8 reason_code_expl);
u16        fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd,
				u32 d_id, u32 s_id, __be16 ox_id);
u16        fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id,
			      u32 s_id, u16 ox_id);

enum fc_parse_status fc_prli_rsp_parse(struct fc_prli_s *prli, int len);

u16        fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
				  u32 s_id, __be16 ox_id,
				  enum bfa_lport_role role);

u16        fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid,
			      u32 d_id, u32 s_id, u16 ox_id,
			      u32 data_format);

u16        fc_rnid_acc_build(struct fchs_s *fchs,
			struct fc_rnid_acc_s *rnid_acc, u32 d_id, u32 s_id,
			__be16 ox_id, u32 data_format,
			struct fc_rnid_common_id_data_s *common_id_data,
			struct fc_rnid_general_topology_data_s *gen_topo_data);

u16	fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rps2c,
			u32 d_id, u32 s_id, u32 *pid_list, u16 npids);
u16        fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc,
			      u32 d_id, u32 s_id, u16 ox_id);
u16        fc_rpsc_acc_build(struct fchs_s *fchs,
			struct fc_rpsc_acc_s *rpsc_acc, u32 d_id, u32 s_id,
			__be16 ox_id, struct fc_rpsc_speed_info_s *oper_speed);
u16        fc_gid_ft_build(struct fchs_s *fchs, void *pld, u32 s_id,
				u8 fc4_type);

u16        fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
			       u32 port_id, wwn_t port_name);

u16        fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
			       u32 port_id, wwn_t node_name);

u16        fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
			       u32 port_id, u32 cos);

u16        fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
			       u32 port_id, u8 port_type);

u16        fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id,
			       u32 port_id);

u16        fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id,
			      u32 s_id, u16 ox_id, wwn_t port_name);

u16        fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
				  u32 s_id, __be16 ox_id);

u16        fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
				     u16 cmd_code);
u16	fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
u16	fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);

void		fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask);

void		fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
					 __be16 ox_id);

enum fc_parse_status	fc_plogi_rsp_parse(struct fchs_s *fchs, int len,
					wwn_t port_name);

enum fc_parse_status	fc_prli_parse(struct fc_prli_s *prli);

enum fc_parse_status	fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name,
					wwn_t port_name);

u16 fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
		u32 s_id, __be16 ox_id, u16 rx_id);

int fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code);

u16 fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
		u32 d_id, u32 s_id, __be16 ox_id, int num_pages);

u16 fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc,
		u32 d_id, u32 s_id, __be16 ox_id, int num_pages);

u16 fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
		u16 ox_id, wwn_t port_name, wwn_t node_name,
		u16 pdu_size);

u16 fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name);

u16 fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
		u16 ox_id, int num_pages);

u16 fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
		u16 ox_id, int num_pages, enum fc_tprlo_type tprlo_type,
		u32 tpr_id);

u16 fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
		__be16 ox_id, u32 reason_code, u32 reason_expl);

u16 fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
		u32 port_id);

u16 fc_ct_rsp_parse(struct ct_hdr_s *cthdr);

u16 fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn, u32 s_id,
		u16 ox_id);
#endif