1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright(c) 2008 Intel Corporation. All rights reserved.
5 * Maintained at www.Open-FCoE.org
10 #include <asm/unaligned.h>
11 #include <linux/utsname.h>
12 #include <scsi/fc/fc_ms.h>
15 * F_CTL values for simple requests and responses.
17 #define FC_FCTL_REQ (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)
18 #define FC_FCTL_RESP (FC_FC_EX_CTX | FC_FC_LAST_SEQ | \
19 FC_FC_END_SEQ | FC_FC_SEQ_INIT)
22 struct fc_ns_fid fid
; /* port ID object */
23 struct fc_ns_fts fts
; /* FC4-types object */
29 struct fc_ns_gid_ft gid
;
30 struct fc_ns_rn_id rn
;
32 struct fc_ns_rff_id rff
;
34 struct fc_ns_rsnn snn
;
35 struct fc_ns_rspn spn
;
36 struct fc_fdmi_rhba rhba
;
37 struct fc_fdmi_rpa rpa
;
38 struct fc_fdmi_dprt dprt
;
39 struct fc_fdmi_dhba dhba
;
44 * fc_adisc_fill() - Fill in adisc request frame
46 * @fp: fc frame where payload will be placed.
48 static inline void fc_adisc_fill(struct fc_lport
*lport
, struct fc_frame
*fp
)
50 struct fc_els_adisc
*adisc
;
52 adisc
= fc_frame_payload_get(fp
, sizeof(*adisc
));
53 memset(adisc
, 0, sizeof(*adisc
));
54 adisc
->adisc_cmd
= ELS_ADISC
;
55 put_unaligned_be64(lport
->wwpn
, &adisc
->adisc_wwpn
);
56 put_unaligned_be64(lport
->wwnn
, &adisc
->adisc_wwnn
);
57 hton24(adisc
->adisc_port_id
, lport
->port_id
);
61 * fc_ct_hdr_fill- fills ct header and reset ct payload
62 * returns pointer to ct request.
64 static inline struct fc_ct_req
*fc_ct_hdr_fill(const struct fc_frame
*fp
,
65 unsigned int op
, size_t req_size
,
66 enum fc_ct_fs_type fs_type
,
72 ct_plen
= sizeof(struct fc_ct_hdr
) + req_size
;
73 ct
= fc_frame_payload_get(fp
, ct_plen
);
74 memset(ct
, 0, ct_plen
);
75 ct
->hdr
.ct_rev
= FC_CT_REV
;
76 ct
->hdr
.ct_fs_type
= fs_type
;
77 ct
->hdr
.ct_fs_subtype
= subtype
;
78 ct
->hdr
.ct_cmd
= htons((u16
) op
);
83 * fc_ct_ns_fill() - Fill in a name service request frame
85 * @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries.
86 * @fp: frame to contain payload.
88 * @r_ctl: pointer to FC header R_CTL.
89 * @fh_type: pointer to FC-4 type.
91 static inline int fc_ct_ns_fill(struct fc_lport
*lport
,
92 u32 fc_id
, struct fc_frame
*fp
,
93 unsigned int op
, enum fc_rctl
*r_ctl
,
94 enum fc_fh_type
*fh_type
)
101 ct
= fc_ct_hdr_fill(fp
, op
, sizeof(struct fc_ns_gid_ft
),
102 FC_FST_DIR
, FC_NS_SUBTYPE
);
103 ct
->payload
.gid
.fn_fc4_type
= FC_TYPE_FCP
;
107 ct
= fc_ct_hdr_fill(fp
, op
, sizeof(struct fc_ns_fid
),
108 FC_FST_DIR
, FC_NS_SUBTYPE
);
109 ct
->payload
.gid
.fn_fc4_type
= FC_TYPE_FCP
;
110 hton24(ct
->payload
.fid
.fp_fid
, fc_id
);
114 ct
= fc_ct_hdr_fill(fp
, op
, sizeof(struct fc_ns_rft
),
115 FC_FST_DIR
, FC_NS_SUBTYPE
);
116 hton24(ct
->payload
.rft
.fid
.fp_fid
, lport
->port_id
);
117 ct
->payload
.rft
.fts
= lport
->fcts
;
121 ct
= fc_ct_hdr_fill(fp
, op
, sizeof(struct fc_ns_rff_id
),
122 FC_FST_DIR
, FC_NS_SUBTYPE
);
123 hton24(ct
->payload
.rff
.fr_fid
.fp_fid
, lport
->port_id
);
124 ct
->payload
.rff
.fr_type
= FC_TYPE_FCP
;
125 if (lport
->service_params
& FCP_SPPF_INIT_FCN
)
126 ct
->payload
.rff
.fr_feat
= FCP_FEAT_INIT
;
127 if (lport
->service_params
& FCP_SPPF_TARG_FCN
)
128 ct
->payload
.rff
.fr_feat
|= FCP_FEAT_TARG
;
132 ct
= fc_ct_hdr_fill(fp
, op
, sizeof(struct fc_ns_rn_id
),
133 FC_FST_DIR
, FC_NS_SUBTYPE
);
134 hton24(ct
->payload
.rn
.fr_fid
.fp_fid
, lport
->port_id
);
135 put_unaligned_be64(lport
->wwnn
, &ct
->payload
.rn
.fr_wwn
);
139 len
= strnlen(fc_host_symbolic_name(lport
->host
), 255);
140 ct
= fc_ct_hdr_fill(fp
, op
, sizeof(struct fc_ns_rspn
) + len
,
141 FC_FST_DIR
, FC_NS_SUBTYPE
);
142 hton24(ct
->payload
.spn
.fr_fid
.fp_fid
, lport
->port_id
);
143 strncpy(ct
->payload
.spn
.fr_name
,
144 fc_host_symbolic_name(lport
->host
), len
);
145 ct
->payload
.spn
.fr_name_len
= len
;
149 len
= strnlen(fc_host_symbolic_name(lport
->host
), 255);
150 ct
= fc_ct_hdr_fill(fp
, op
, sizeof(struct fc_ns_rsnn
) + len
,
151 FC_FST_DIR
, FC_NS_SUBTYPE
);
152 put_unaligned_be64(lport
->wwnn
, &ct
->payload
.snn
.fr_wwn
);
153 strncpy(ct
->payload
.snn
.fr_name
,
154 fc_host_symbolic_name(lport
->host
), len
);
155 ct
->payload
.snn
.fr_name_len
= len
;
161 *r_ctl
= FC_RCTL_DD_UNSOL_CTL
;
162 *fh_type
= FC_TYPE_CT
;
166 static inline void fc_ct_ms_fill_attr(struct fc_fdmi_attr_entry
*entry
,
167 const char *in
, size_t len
)
169 int copied
= strscpy(entry
->value
, in
, len
);
171 memset(entry
->value
, copied
, len
- copied
);
175 * fc_ct_ms_fill() - Fill in a mgmt service request frame
176 * @lport: local port.
177 * @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries.
178 * @fp: frame to contain payload.
180 * @r_ctl: pointer to FC header R_CTL.
181 * @fh_type: pointer to FC-4 type.
183 static inline int fc_ct_ms_fill(struct fc_lport
*lport
,
184 u32 fc_id
, struct fc_frame
*fp
,
185 unsigned int op
, enum fc_rctl
*r_ctl
,
186 enum fc_fh_type
*fh_type
)
188 struct fc_ct_req
*ct
;
190 struct fc_fdmi_attr_entry
*entry
;
191 struct fs_fdmi_attrs
*hba_attrs
;
197 len
= sizeof(struct fc_fdmi_rhba
);
198 len
-= sizeof(struct fc_fdmi_attr_entry
);
199 len
+= (numattrs
* FC_FDMI_ATTR_ENTRY_HEADER_LEN
);
200 len
+= FC_FDMI_HBA_ATTR_NODENAME_LEN
;
201 len
+= FC_FDMI_HBA_ATTR_MANUFACTURER_LEN
;
202 len
+= FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN
;
203 len
+= FC_FDMI_HBA_ATTR_MODEL_LEN
;
204 len
+= FC_FDMI_HBA_ATTR_MODELDESCR_LEN
;
205 len
+= FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN
;
206 len
+= FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN
;
207 len
+= FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN
;
208 len
+= FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN
;
209 len
+= FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN
;
210 ct
= fc_ct_hdr_fill(fp
, op
, len
, FC_FST_MGMT
,
214 put_unaligned_be64(lport
->wwpn
, &ct
->payload
.rhba
.hbaid
.id
);
215 /* Number of Ports - always 1 */
216 put_unaligned_be32(1, &ct
->payload
.rhba
.port
.numport
);
218 put_unaligned_be64(lport
->wwpn
,
219 &ct
->payload
.rhba
.port
.port
[0].portname
);
222 put_unaligned_be32(numattrs
,
223 &ct
->payload
.rhba
.hba_attrs
.numattrs
);
224 hba_attrs
= &ct
->payload
.rhba
.hba_attrs
;
225 entry
= (struct fc_fdmi_attr_entry
*)hba_attrs
->attr
;
227 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
228 len
+= FC_FDMI_HBA_ATTR_NODENAME_LEN
;
229 put_unaligned_be16(FC_FDMI_HBA_ATTR_NODENAME
,
231 put_unaligned_be16(len
, &entry
->len
);
232 put_unaligned_be64(lport
->wwnn
,
233 (__be64
*)&entry
->value
[0]);
236 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
237 FC_FDMI_HBA_ATTR_NODENAME_LEN
);
238 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
239 len
+= FC_FDMI_HBA_ATTR_MANUFACTURER_LEN
;
240 put_unaligned_be16(FC_FDMI_HBA_ATTR_MANUFACTURER
,
242 put_unaligned_be16(len
, &entry
->len
);
243 fc_ct_ms_fill_attr(entry
,
244 fc_host_manufacturer(lport
->host
),
245 FC_FDMI_HBA_ATTR_MANUFACTURER_LEN
);
248 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
249 FC_FDMI_HBA_ATTR_MANUFACTURER_LEN
);
250 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
251 len
+= FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN
;
252 put_unaligned_be16(FC_FDMI_HBA_ATTR_SERIALNUMBER
,
254 put_unaligned_be16(len
, &entry
->len
);
255 fc_ct_ms_fill_attr(entry
,
256 fc_host_serial_number(lport
->host
),
257 FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN
);
260 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
261 FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN
);
262 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
263 len
+= FC_FDMI_HBA_ATTR_MODEL_LEN
;
264 put_unaligned_be16(FC_FDMI_HBA_ATTR_MODEL
,
266 put_unaligned_be16(len
, &entry
->len
);
267 fc_ct_ms_fill_attr(entry
,
268 fc_host_model(lport
->host
),
269 FC_FDMI_HBA_ATTR_MODEL_LEN
);
271 /* Model Description */
272 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
273 FC_FDMI_HBA_ATTR_MODEL_LEN
);
274 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
275 len
+= FC_FDMI_HBA_ATTR_MODELDESCR_LEN
;
276 put_unaligned_be16(FC_FDMI_HBA_ATTR_MODELDESCRIPTION
,
278 put_unaligned_be16(len
, &entry
->len
);
279 fc_ct_ms_fill_attr(entry
,
280 fc_host_model_description(lport
->host
),
281 FC_FDMI_HBA_ATTR_MODELDESCR_LEN
);
283 /* Hardware Version */
284 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
285 FC_FDMI_HBA_ATTR_MODELDESCR_LEN
);
286 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
287 len
+= FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN
;
288 put_unaligned_be16(FC_FDMI_HBA_ATTR_HARDWAREVERSION
,
290 put_unaligned_be16(len
, &entry
->len
);
291 fc_ct_ms_fill_attr(entry
,
292 fc_host_hardware_version(lport
->host
),
293 FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN
);
296 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
297 FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN
);
298 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
299 len
+= FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN
;
300 put_unaligned_be16(FC_FDMI_HBA_ATTR_DRIVERVERSION
,
302 put_unaligned_be16(len
, &entry
->len
);
303 fc_ct_ms_fill_attr(entry
,
304 fc_host_driver_version(lport
->host
),
305 FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN
);
307 /* OptionROM Version */
308 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
309 FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN
);
310 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
311 len
+= FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN
;
312 put_unaligned_be16(FC_FDMI_HBA_ATTR_OPTIONROMVERSION
,
314 put_unaligned_be16(len
, &entry
->len
);
315 fc_ct_ms_fill_attr(entry
,
316 fc_host_optionrom_version(lport
->host
),
317 FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN
);
319 /* Firmware Version */
320 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
321 FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN
);
322 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
323 len
+= FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN
;
324 put_unaligned_be16(FC_FDMI_HBA_ATTR_FIRMWAREVERSION
,
326 put_unaligned_be16(len
, &entry
->len
);
327 fc_ct_ms_fill_attr(entry
,
328 fc_host_firmware_version(lport
->host
),
329 FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN
);
331 /* OS Name and Version */
332 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
333 FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN
);
334 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
335 len
+= FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN
;
336 put_unaligned_be16(FC_FDMI_HBA_ATTR_OSNAMEVERSION
,
338 put_unaligned_be16(len
, &entry
->len
);
339 snprintf((char *)&entry
->value
,
340 FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN
,
342 init_utsname()->sysname
,
343 init_utsname()->release
);
347 len
= sizeof(struct fc_fdmi_rpa
);
348 len
-= sizeof(struct fc_fdmi_attr_entry
);
349 len
+= (numattrs
* FC_FDMI_ATTR_ENTRY_HEADER_LEN
);
350 len
+= FC_FDMI_PORT_ATTR_FC4TYPES_LEN
;
351 len
+= FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN
;
352 len
+= FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN
;
353 len
+= FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN
;
354 len
+= FC_FDMI_PORT_ATTR_OSDEVICENAME_LEN
;
355 len
+= FC_FDMI_PORT_ATTR_HOSTNAME_LEN
;
356 ct
= fc_ct_hdr_fill(fp
, op
, len
, FC_FST_MGMT
,
360 put_unaligned_be64(lport
->wwpn
,
361 &ct
->payload
.rpa
.port
.portname
);
363 /* Port Attributes */
364 put_unaligned_be32(numattrs
,
365 &ct
->payload
.rpa
.hba_attrs
.numattrs
);
367 hba_attrs
= &ct
->payload
.rpa
.hba_attrs
;
368 entry
= (struct fc_fdmi_attr_entry
*)hba_attrs
->attr
;
371 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
372 len
+= FC_FDMI_PORT_ATTR_FC4TYPES_LEN
;
373 put_unaligned_be16(FC_FDMI_PORT_ATTR_FC4TYPES
,
375 put_unaligned_be16(len
, &entry
->len
);
376 memcpy(&entry
->value
, fc_host_supported_fc4s(lport
->host
),
377 FC_FDMI_PORT_ATTR_FC4TYPES_LEN
);
379 /* Supported Speed */
380 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
381 FC_FDMI_PORT_ATTR_FC4TYPES_LEN
);
382 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
383 len
+= FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN
;
384 put_unaligned_be16(FC_FDMI_PORT_ATTR_SUPPORTEDSPEED
,
386 put_unaligned_be16(len
, &entry
->len
);
388 put_unaligned_be32(fc_host_supported_speeds(lport
->host
),
391 /* Current Port Speed */
392 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
393 FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN
);
394 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
395 len
+= FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN
;
396 put_unaligned_be16(FC_FDMI_PORT_ATTR_CURRENTPORTSPEED
,
398 put_unaligned_be16(len
, &entry
->len
);
399 put_unaligned_be32(lport
->link_speed
,
403 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
404 FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN
);
405 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
406 len
+= FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN
;
407 put_unaligned_be16(FC_FDMI_PORT_ATTR_MAXFRAMESIZE
,
409 put_unaligned_be16(len
, &entry
->len
);
410 put_unaligned_be32(fc_host_maxframe_size(lport
->host
),
414 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
415 FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN
);
416 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
417 len
+= FC_FDMI_PORT_ATTR_OSDEVICENAME_LEN
;
418 put_unaligned_be16(FC_FDMI_PORT_ATTR_OSDEVICENAME
,
420 put_unaligned_be16(len
, &entry
->len
);
421 /* Use the sysfs device name */
422 fc_ct_ms_fill_attr(entry
,
423 dev_name(&lport
->host
->shost_gendev
),
424 strnlen(dev_name(&lport
->host
->shost_gendev
),
425 FC_FDMI_PORT_ATTR_HOSTNAME_LEN
));
428 entry
= (struct fc_fdmi_attr_entry
*)((char *)entry
->value
+
429 FC_FDMI_PORT_ATTR_OSDEVICENAME_LEN
);
430 len
= FC_FDMI_ATTR_ENTRY_HEADER_LEN
;
431 len
+= FC_FDMI_PORT_ATTR_HOSTNAME_LEN
;
432 put_unaligned_be16(FC_FDMI_PORT_ATTR_HOSTNAME
,
434 put_unaligned_be16(len
, &entry
->len
);
435 if (strlen(fc_host_system_hostname(lport
->host
)))
436 fc_ct_ms_fill_attr(entry
,
437 fc_host_system_hostname(lport
->host
),
438 strnlen(fc_host_system_hostname(lport
->host
),
439 FC_FDMI_PORT_ATTR_HOSTNAME_LEN
));
441 fc_ct_ms_fill_attr(entry
,
442 init_utsname()->nodename
,
443 FC_FDMI_PORT_ATTR_HOSTNAME_LEN
);
446 len
= sizeof(struct fc_fdmi_dprt
);
447 ct
= fc_ct_hdr_fill(fp
, op
, len
, FC_FST_MGMT
,
450 put_unaligned_be64(lport
->wwpn
,
451 &ct
->payload
.dprt
.port
.portname
);
454 len
= sizeof(struct fc_fdmi_dhba
);
455 ct
= fc_ct_hdr_fill(fp
, op
, len
, FC_FST_MGMT
,
458 put_unaligned_be64(lport
->wwpn
, &ct
->payload
.dhba
.hbaid
.id
);
463 *r_ctl
= FC_RCTL_DD_UNSOL_CTL
;
464 *fh_type
= FC_TYPE_CT
;
469 * fc_ct_fill() - Fill in a common transport service request frame
470 * @lport: local port.
471 * @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries.
472 * @fp: frame to contain payload.
474 * @r_ctl: pointer to FC header R_CTL.
475 * @fh_type: pointer to FC-4 type.
477 static inline int fc_ct_fill(struct fc_lport
*lport
,
478 u32 fc_id
, struct fc_frame
*fp
,
479 unsigned int op
, enum fc_rctl
*r_ctl
,
480 enum fc_fh_type
*fh_type
, u32
*did
)
485 case FC_FID_MGMT_SERV
:
486 rc
= fc_ct_ms_fill(lport
, fc_id
, fp
, op
, r_ctl
, fh_type
);
487 *did
= FC_FID_MGMT_SERV
;
489 case FC_FID_DIR_SERV
:
491 rc
= fc_ct_ns_fill(lport
, fc_id
, fp
, op
, r_ctl
, fh_type
);
492 *did
= FC_FID_DIR_SERV
;
499 * fc_plogi_fill - Fill in plogi request frame
501 static inline void fc_plogi_fill(struct fc_lport
*lport
, struct fc_frame
*fp
,
504 struct fc_els_flogi
*plogi
;
505 struct fc_els_csp
*csp
;
506 struct fc_els_cssp
*cp
;
508 plogi
= fc_frame_payload_get(fp
, sizeof(*plogi
));
509 memset(plogi
, 0, sizeof(*plogi
));
510 plogi
->fl_cmd
= (u8
) op
;
511 put_unaligned_be64(lport
->wwpn
, &plogi
->fl_wwpn
);
512 put_unaligned_be64(lport
->wwnn
, &plogi
->fl_wwnn
);
514 csp
= &plogi
->fl_csp
;
515 csp
->sp_hi_ver
= 0x20;
516 csp
->sp_lo_ver
= 0x20;
517 csp
->sp_bb_cred
= htons(10); /* this gets set by gateway */
518 csp
->sp_bb_data
= htons((u16
) lport
->mfs
);
519 cp
= &plogi
->fl_cssp
[3 - 1]; /* class 3 parameters */
520 cp
->cp_class
= htons(FC_CPC_VALID
| FC_CPC_SEQ
);
521 csp
->sp_features
= htons(FC_SP_FT_CIRO
);
522 csp
->sp_tot_seq
= htons(255); /* seq. we accept */
523 csp
->sp_rel_off
= htons(0x1f);
524 csp
->sp_e_d_tov
= htonl(lport
->e_d_tov
);
526 cp
->cp_rdfs
= htons((u16
) lport
->mfs
);
527 cp
->cp_con_seq
= htons(255);
532 * fc_flogi_fill - Fill in a flogi request frame.
534 static inline void fc_flogi_fill(struct fc_lport
*lport
, struct fc_frame
*fp
)
536 struct fc_els_csp
*sp
;
537 struct fc_els_cssp
*cp
;
538 struct fc_els_flogi
*flogi
;
540 flogi
= fc_frame_payload_get(fp
, sizeof(*flogi
));
541 memset(flogi
, 0, sizeof(*flogi
));
542 flogi
->fl_cmd
= (u8
) ELS_FLOGI
;
543 put_unaligned_be64(lport
->wwpn
, &flogi
->fl_wwpn
);
544 put_unaligned_be64(lport
->wwnn
, &flogi
->fl_wwnn
);
546 sp
->sp_hi_ver
= 0x20;
547 sp
->sp_lo_ver
= 0x20;
548 sp
->sp_bb_cred
= htons(10); /* this gets set by gateway */
549 sp
->sp_bb_data
= htons((u16
) lport
->mfs
);
550 cp
= &flogi
->fl_cssp
[3 - 1]; /* class 3 parameters */
551 cp
->cp_class
= htons(FC_CPC_VALID
| FC_CPC_SEQ
);
552 if (lport
->does_npiv
)
553 sp
->sp_features
= htons(FC_SP_FT_NPIV
);
557 * fc_fdisc_fill - Fill in a fdisc request frame.
559 static inline void fc_fdisc_fill(struct fc_lport
*lport
, struct fc_frame
*fp
)
561 struct fc_els_csp
*sp
;
562 struct fc_els_cssp
*cp
;
563 struct fc_els_flogi
*fdisc
;
565 fdisc
= fc_frame_payload_get(fp
, sizeof(*fdisc
));
566 memset(fdisc
, 0, sizeof(*fdisc
));
567 fdisc
->fl_cmd
= (u8
) ELS_FDISC
;
568 put_unaligned_be64(lport
->wwpn
, &fdisc
->fl_wwpn
);
569 put_unaligned_be64(lport
->wwnn
, &fdisc
->fl_wwnn
);
571 sp
->sp_hi_ver
= 0x20;
572 sp
->sp_lo_ver
= 0x20;
573 sp
->sp_bb_cred
= htons(10); /* this gets set by gateway */
574 sp
->sp_bb_data
= htons((u16
) lport
->mfs
);
575 cp
= &fdisc
->fl_cssp
[3 - 1]; /* class 3 parameters */
576 cp
->cp_class
= htons(FC_CPC_VALID
| FC_CPC_SEQ
);
580 * fc_logo_fill - Fill in a logo request frame.
582 static inline void fc_logo_fill(struct fc_lport
*lport
, struct fc_frame
*fp
)
584 struct fc_els_logo
*logo
;
586 logo
= fc_frame_payload_get(fp
, sizeof(*logo
));
587 memset(logo
, 0, sizeof(*logo
));
588 logo
->fl_cmd
= ELS_LOGO
;
589 hton24(logo
->fl_n_port_id
, lport
->port_id
);
590 logo
->fl_n_port_wwn
= htonll(lport
->wwpn
);
594 * fc_rtv_fill - Fill in RTV (read timeout value) request frame.
596 static inline void fc_rtv_fill(struct fc_lport
*lport
, struct fc_frame
*fp
)
598 struct fc_els_rtv
*rtv
;
600 rtv
= fc_frame_payload_get(fp
, sizeof(*rtv
));
601 memset(rtv
, 0, sizeof(*rtv
));
602 rtv
->rtv_cmd
= ELS_RTV
;
606 * fc_rec_fill - Fill in rec request frame
608 static inline void fc_rec_fill(struct fc_lport
*lport
, struct fc_frame
*fp
)
610 struct fc_els_rec
*rec
;
611 struct fc_exch
*ep
= fc_seq_exch(fr_seq(fp
));
613 rec
= fc_frame_payload_get(fp
, sizeof(*rec
));
614 memset(rec
, 0, sizeof(*rec
));
615 rec
->rec_cmd
= ELS_REC
;
616 hton24(rec
->rec_s_id
, lport
->port_id
);
617 rec
->rec_ox_id
= htons(ep
->oxid
);
618 rec
->rec_rx_id
= htons(ep
->rxid
);
622 * fc_prli_fill - Fill in prli request frame
624 static inline void fc_prli_fill(struct fc_lport
*lport
, struct fc_frame
*fp
)
627 struct fc_els_prli prli
;
628 struct fc_els_spp spp
;
631 pp
= fc_frame_payload_get(fp
, sizeof(*pp
));
632 memset(pp
, 0, sizeof(*pp
));
633 pp
->prli
.prli_cmd
= ELS_PRLI
;
634 pp
->prli
.prli_spp_len
= sizeof(struct fc_els_spp
);
635 pp
->prli
.prli_len
= htons(sizeof(*pp
));
636 pp
->spp
.spp_type
= FC_TYPE_FCP
;
637 pp
->spp
.spp_flags
= FC_SPP_EST_IMG_PAIR
;
638 pp
->spp
.spp_params
= htonl(lport
->service_params
);
642 * fc_scr_fill - Fill in a scr request frame.
644 static inline void fc_scr_fill(struct fc_lport
*lport
, struct fc_frame
*fp
)
646 struct fc_els_scr
*scr
;
648 scr
= fc_frame_payload_get(fp
, sizeof(*scr
));
649 memset(scr
, 0, sizeof(*scr
));
650 scr
->scr_cmd
= ELS_SCR
;
651 scr
->scr_reg_func
= ELS_SCRF_FULL
;
655 * fc_els_fill - Fill in an ELS request frame
657 static inline int fc_els_fill(struct fc_lport
*lport
,
659 struct fc_frame
*fp
, unsigned int op
,
660 enum fc_rctl
*r_ctl
, enum fc_fh_type
*fh_type
)
664 fc_adisc_fill(lport
, fp
);
668 fc_plogi_fill(lport
, fp
, ELS_PLOGI
);
672 fc_flogi_fill(lport
, fp
);
676 fc_fdisc_fill(lport
, fp
);
680 fc_logo_fill(lport
, fp
);
684 fc_rtv_fill(lport
, fp
);
688 fc_rec_fill(lport
, fp
);
692 fc_prli_fill(lport
, fp
);
696 fc_scr_fill(lport
, fp
);
703 *r_ctl
= FC_RCTL_ELS_REQ
;
704 *fh_type
= FC_TYPE_ELS
;
707 #endif /* _FC_ENCODE_H_ */