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)
171 copied = strscpy(entry->value, in, len);
172 if (copied > 0 && copied + 1 < len)
173 memset(entry->value + copied + 1, 0, len - copied - 1);
177 * fc_ct_ms_fill() - Fill in a mgmt service request frame
178 * @lport: local port.
179 * @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries.
180 * @fp: frame to contain payload.
182 * @r_ctl: pointer to FC header R_CTL.
183 * @fh_type: pointer to FC-4 type.
185 static inline int fc_ct_ms_fill(struct fc_lport *lport,
186 u32 fc_id, struct fc_frame *fp,
187 unsigned int op, enum fc_rctl *r_ctl,
188 enum fc_fh_type *fh_type)
190 struct fc_ct_req *ct;
192 struct fc_fdmi_attr_entry *entry;
193 struct fs_fdmi_attrs *hba_attrs;
195 struct fc_host_attrs *fc_host = shost_to_fc_host(lport->host);
200 len = sizeof(struct fc_fdmi_rhba);
201 len -= sizeof(struct fc_fdmi_attr_entry);
202 len += (numattrs * FC_FDMI_ATTR_ENTRY_HEADER_LEN);
203 len += FC_FDMI_HBA_ATTR_NODENAME_LEN;
204 len += FC_FDMI_HBA_ATTR_MANUFACTURER_LEN;
205 len += FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN;
206 len += FC_FDMI_HBA_ATTR_MODEL_LEN;
207 len += FC_FDMI_HBA_ATTR_MODELDESCR_LEN;
208 len += FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN;
209 len += FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN;
210 len += FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN;
211 len += FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN;
212 len += FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN;
213 len += FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN;
215 if (fc_host->fdmi_version == FDMI_V2) {
217 len += FC_FDMI_HBA_ATTR_NODESYMBLNAME_LEN;
218 len += FC_FDMI_HBA_ATTR_VENDORSPECIFICINFO_LEN;
219 len += FC_FDMI_HBA_ATTR_NUMBEROFPORTS_LEN;
220 len += FC_FDMI_HBA_ATTR_FABRICNAME_LEN;
221 len += FC_FDMI_HBA_ATTR_BIOSVERSION_LEN;
222 len += FC_FDMI_HBA_ATTR_BIOSSTATE_LEN;
223 len += FC_FDMI_HBA_ATTR_VENDORIDENTIFIER_LEN;
226 ct = fc_ct_hdr_fill(fp, op, len, FC_FST_MGMT,
230 put_unaligned_be64(lport->wwpn, &ct->payload.rhba.hbaid.id);
231 /* Number of Ports - always 1 */
232 put_unaligned_be32(1, &ct->payload.rhba.port.numport);
234 put_unaligned_be64(lport->wwpn,
235 &ct->payload.rhba.port.port[0].portname);
238 put_unaligned_be32(numattrs,
239 &ct->payload.rhba.hba_attrs.numattrs);
240 hba_attrs = &ct->payload.rhba.hba_attrs;
241 entry = (struct fc_fdmi_attr_entry *)hba_attrs->attr;
243 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
244 len += FC_FDMI_HBA_ATTR_NODENAME_LEN;
245 put_unaligned_be16(FC_FDMI_HBA_ATTR_NODENAME,
247 put_unaligned_be16(len, &entry->len);
248 put_unaligned_be64(lport->wwnn,
249 (__be64 *)&entry->value[0]);
252 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
253 FC_FDMI_HBA_ATTR_NODENAME_LEN);
254 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
255 len += FC_FDMI_HBA_ATTR_MANUFACTURER_LEN;
256 put_unaligned_be16(FC_FDMI_HBA_ATTR_MANUFACTURER,
258 put_unaligned_be16(len, &entry->len);
259 fc_ct_ms_fill_attr(entry,
260 fc_host_manufacturer(lport->host),
261 FC_FDMI_HBA_ATTR_MANUFACTURER_LEN);
264 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
265 FC_FDMI_HBA_ATTR_MANUFACTURER_LEN);
266 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
267 len += FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN;
268 put_unaligned_be16(FC_FDMI_HBA_ATTR_SERIALNUMBER,
270 put_unaligned_be16(len, &entry->len);
271 fc_ct_ms_fill_attr(entry,
272 fc_host_serial_number(lport->host),
273 FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN);
276 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
277 FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN);
278 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
279 len += FC_FDMI_HBA_ATTR_MODEL_LEN;
280 put_unaligned_be16(FC_FDMI_HBA_ATTR_MODEL,
282 put_unaligned_be16(len, &entry->len);
283 fc_ct_ms_fill_attr(entry,
284 fc_host_model(lport->host),
285 FC_FDMI_HBA_ATTR_MODEL_LEN);
287 /* Model Description */
288 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
289 FC_FDMI_HBA_ATTR_MODEL_LEN);
290 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
291 len += FC_FDMI_HBA_ATTR_MODELDESCR_LEN;
292 put_unaligned_be16(FC_FDMI_HBA_ATTR_MODELDESCRIPTION,
294 put_unaligned_be16(len, &entry->len);
295 fc_ct_ms_fill_attr(entry,
296 fc_host_model_description(lport->host),
297 FC_FDMI_HBA_ATTR_MODELDESCR_LEN);
299 /* Hardware Version */
300 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
301 FC_FDMI_HBA_ATTR_MODELDESCR_LEN);
302 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
303 len += FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN;
304 put_unaligned_be16(FC_FDMI_HBA_ATTR_HARDWAREVERSION,
306 put_unaligned_be16(len, &entry->len);
307 fc_ct_ms_fill_attr(entry,
308 fc_host_hardware_version(lport->host),
309 FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN);
312 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
313 FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN);
314 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
315 len += FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN;
316 put_unaligned_be16(FC_FDMI_HBA_ATTR_DRIVERVERSION,
318 put_unaligned_be16(len, &entry->len);
319 fc_ct_ms_fill_attr(entry,
320 fc_host_driver_version(lport->host),
321 FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN);
323 /* OptionROM Version */
324 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
325 FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN);
326 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
327 len += FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN;
328 put_unaligned_be16(FC_FDMI_HBA_ATTR_OPTIONROMVERSION,
330 put_unaligned_be16(len, &entry->len);
331 fc_ct_ms_fill_attr(entry,
333 FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN);
335 /* Firmware Version */
336 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
337 FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN);
338 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
339 len += FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN;
340 put_unaligned_be16(FC_FDMI_HBA_ATTR_FIRMWAREVERSION,
342 put_unaligned_be16(len, &entry->len);
343 fc_ct_ms_fill_attr(entry,
344 fc_host_firmware_version(lport->host),
345 FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN);
347 /* OS Name and Version */
348 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
349 FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN);
350 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
351 len += FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN;
352 put_unaligned_be16(FC_FDMI_HBA_ATTR_OSNAMEVERSION,
354 put_unaligned_be16(len, &entry->len);
355 snprintf((char *)&entry->value,
356 FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN,
358 init_utsname()->sysname,
359 init_utsname()->release);
362 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
363 FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN);
364 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
365 len += FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN;
366 put_unaligned_be16(FC_FDMI_HBA_ATTR_MAXCTPAYLOAD,
368 put_unaligned_be16(len, &entry->len);
369 put_unaligned_be32(fc_host_max_ct_payload(lport->host),
372 if (fc_host->fdmi_version == FDMI_V2) {
373 /* Node symbolic name */
374 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
375 FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN);
376 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
377 len += FC_FDMI_HBA_ATTR_NODESYMBLNAME_LEN;
378 put_unaligned_be16(FC_FDMI_HBA_ATTR_NODESYMBLNAME,
380 put_unaligned_be16(len, &entry->len);
381 fc_ct_ms_fill_attr(entry,
382 fc_host_symbolic_name(lport->host),
383 FC_FDMI_HBA_ATTR_NODESYMBLNAME_LEN);
385 /* Vendor specific info */
386 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
387 FC_FDMI_HBA_ATTR_NODESYMBLNAME_LEN);
388 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
389 len += FC_FDMI_HBA_ATTR_VENDORSPECIFICINFO_LEN;
390 put_unaligned_be16(FC_FDMI_HBA_ATTR_VENDORSPECIFICINFO,
392 put_unaligned_be16(len, &entry->len);
393 put_unaligned_be32(0,
396 /* Number of ports */
397 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
398 FC_FDMI_HBA_ATTR_VENDORSPECIFICINFO_LEN);
399 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
400 len += FC_FDMI_HBA_ATTR_NUMBEROFPORTS_LEN;
401 put_unaligned_be16(FC_FDMI_HBA_ATTR_NUMBEROFPORTS,
403 put_unaligned_be16(len, &entry->len);
404 put_unaligned_be32(fc_host_num_ports(lport->host),
408 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
409 FC_FDMI_HBA_ATTR_NUMBEROFPORTS_LEN);
410 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
411 len += FC_FDMI_HBA_ATTR_FABRICNAME_LEN;
412 put_unaligned_be16(FC_FDMI_HBA_ATTR_FABRICNAME,
414 put_unaligned_be16(len, &entry->len);
415 put_unaligned_be64(fc_host_fabric_name(lport->host),
419 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
420 FC_FDMI_HBA_ATTR_FABRICNAME_LEN);
421 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
422 len += FC_FDMI_HBA_ATTR_BIOSVERSION_LEN;
423 put_unaligned_be16(FC_FDMI_HBA_ATTR_BIOSVERSION,
425 put_unaligned_be16(len, &entry->len);
426 fc_ct_ms_fill_attr(entry,
427 fc_host_bootbios_version(lport->host),
428 FC_FDMI_HBA_ATTR_BIOSVERSION_LEN);
431 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
432 FC_FDMI_HBA_ATTR_BIOSVERSION_LEN);
433 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
434 len += FC_FDMI_HBA_ATTR_BIOSSTATE_LEN;
435 put_unaligned_be16(FC_FDMI_HBA_ATTR_BIOSSTATE,
437 put_unaligned_be16(len, &entry->len);
438 put_unaligned_be32(fc_host_bootbios_state(lport->host),
441 /* Vendor identifier */
442 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
443 FC_FDMI_HBA_ATTR_BIOSSTATE_LEN);
444 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
445 len += FC_FDMI_HBA_ATTR_VENDORIDENTIFIER_LEN;
446 put_unaligned_be16(FC_FDMI_HBA_ATTR_VENDORIDENTIFIER,
448 put_unaligned_be16(len, &entry->len);
449 fc_ct_ms_fill_attr(entry,
450 fc_host_vendor_identifier(lport->host),
451 FC_FDMI_HBA_ATTR_VENDORIDENTIFIER_LEN);
457 len = sizeof(struct fc_fdmi_rpa);
458 len -= sizeof(struct fc_fdmi_attr_entry);
459 len += (numattrs * FC_FDMI_ATTR_ENTRY_HEADER_LEN);
460 len += FC_FDMI_PORT_ATTR_FC4TYPES_LEN;
461 len += FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN;
462 len += FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN;
463 len += FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN;
464 len += FC_FDMI_PORT_ATTR_OSDEVICENAME_LEN;
465 len += FC_FDMI_PORT_ATTR_HOSTNAME_LEN;
468 if (fc_host->fdmi_version == FDMI_V2) {
471 len += FC_FDMI_PORT_ATTR_NODENAME_LEN;
472 len += FC_FDMI_PORT_ATTR_PORTNAME_LEN;
473 len += FC_FDMI_PORT_ATTR_SYMBOLICNAME_LEN;
474 len += FC_FDMI_PORT_ATTR_PORTTYPE_LEN;
475 len += FC_FDMI_PORT_ATTR_SUPPORTEDCLASSSRVC_LEN;
476 len += FC_FDMI_PORT_ATTR_FABRICNAME_LEN;
477 len += FC_FDMI_PORT_ATTR_CURRENTFC4TYPE_LEN;
478 len += FC_FDMI_PORT_ATTR_PORTSTATE_LEN;
479 len += FC_FDMI_PORT_ATTR_DISCOVEREDPORTS_LEN;
480 len += FC_FDMI_PORT_ATTR_PORTID_LEN;
484 ct = fc_ct_hdr_fill(fp, op, len, FC_FST_MGMT,
488 put_unaligned_be64(lport->wwpn,
489 &ct->payload.rpa.port.portname);
491 /* Port Attributes */
492 put_unaligned_be32(numattrs,
493 &ct->payload.rpa.hba_attrs.numattrs);
495 hba_attrs = &ct->payload.rpa.hba_attrs;
496 entry = (struct fc_fdmi_attr_entry *)hba_attrs->attr;
499 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
500 len += FC_FDMI_PORT_ATTR_FC4TYPES_LEN;
501 put_unaligned_be16(FC_FDMI_PORT_ATTR_FC4TYPES,
503 put_unaligned_be16(len, &entry->len);
504 memcpy(&entry->value, fc_host_supported_fc4s(lport->host),
505 FC_FDMI_PORT_ATTR_FC4TYPES_LEN);
507 /* Supported Speed */
508 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
509 FC_FDMI_PORT_ATTR_FC4TYPES_LEN);
510 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
511 len += FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN;
512 put_unaligned_be16(FC_FDMI_PORT_ATTR_SUPPORTEDSPEED,
514 put_unaligned_be16(len, &entry->len);
516 put_unaligned_be32(fc_host_supported_speeds(lport->host),
519 /* Current Port Speed */
520 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
521 FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN);
522 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
523 len += FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN;
524 put_unaligned_be16(FC_FDMI_PORT_ATTR_CURRENTPORTSPEED,
526 put_unaligned_be16(len, &entry->len);
527 put_unaligned_be32(lport->link_speed,
531 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
532 FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN);
533 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
534 len += FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN;
535 put_unaligned_be16(FC_FDMI_PORT_ATTR_MAXFRAMESIZE,
537 put_unaligned_be16(len, &entry->len);
538 put_unaligned_be32(fc_host_maxframe_size(lport->host),
542 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
543 FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN);
544 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
545 len += FC_FDMI_PORT_ATTR_OSDEVICENAME_LEN;
546 put_unaligned_be16(FC_FDMI_PORT_ATTR_OSDEVICENAME,
548 put_unaligned_be16(len, &entry->len);
549 /* Use the sysfs device name */
550 fc_ct_ms_fill_attr(entry,
551 dev_name(&lport->host->shost_gendev),
552 strnlen(dev_name(&lport->host->shost_gendev),
553 FC_FDMI_PORT_ATTR_HOSTNAME_LEN));
556 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
557 FC_FDMI_PORT_ATTR_OSDEVICENAME_LEN);
558 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
559 len += FC_FDMI_PORT_ATTR_HOSTNAME_LEN;
560 put_unaligned_be16(FC_FDMI_PORT_ATTR_HOSTNAME,
562 put_unaligned_be16(len, &entry->len);
563 if (strlen(fc_host_system_hostname(lport->host)))
564 fc_ct_ms_fill_attr(entry,
565 fc_host_system_hostname(lport->host),
566 strnlen(fc_host_system_hostname(lport->host),
567 FC_FDMI_PORT_ATTR_HOSTNAME_LEN));
569 fc_ct_ms_fill_attr(entry,
570 init_utsname()->nodename,
571 FC_FDMI_PORT_ATTR_HOSTNAME_LEN);
574 if (fc_host->fdmi_version == FDMI_V2) {
577 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
578 FC_FDMI_PORT_ATTR_HOSTNAME_LEN);
579 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
580 len += FC_FDMI_PORT_ATTR_NODENAME_LEN;
581 put_unaligned_be16(FC_FDMI_PORT_ATTR_NODENAME,
583 put_unaligned_be16(len, &entry->len);
584 put_unaligned_be64(fc_host_node_name(lport->host),
588 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
589 FC_FDMI_PORT_ATTR_NODENAME_LEN);
590 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
591 len += FC_FDMI_PORT_ATTR_PORTNAME_LEN;
592 put_unaligned_be16(FC_FDMI_PORT_ATTR_PORTNAME,
594 put_unaligned_be16(len, &entry->len);
595 put_unaligned_be64(lport->wwpn,
598 /* Port symbolic name */
599 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
600 FC_FDMI_PORT_ATTR_PORTNAME_LEN);
601 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
602 len += FC_FDMI_PORT_ATTR_SYMBOLICNAME_LEN;
603 put_unaligned_be16(FC_FDMI_PORT_ATTR_SYMBOLICNAME,
605 put_unaligned_be16(len, &entry->len);
606 fc_ct_ms_fill_attr(entry,
607 fc_host_symbolic_name(lport->host),
608 FC_FDMI_PORT_ATTR_SYMBOLICNAME_LEN);
611 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
612 FC_FDMI_PORT_ATTR_SYMBOLICNAME_LEN);
613 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
614 len += FC_FDMI_PORT_ATTR_PORTTYPE_LEN;
615 put_unaligned_be16(FC_FDMI_PORT_ATTR_PORTTYPE,
617 put_unaligned_be16(len, &entry->len);
618 put_unaligned_be32(fc_host_port_type(lport->host),
621 /* Supported class of service */
622 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
623 FC_FDMI_PORT_ATTR_PORTTYPE_LEN);
624 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
625 len += FC_FDMI_PORT_ATTR_SUPPORTEDCLASSSRVC_LEN;
626 put_unaligned_be16(FC_FDMI_PORT_ATTR_SUPPORTEDCLASSSRVC,
628 put_unaligned_be16(len, &entry->len);
629 put_unaligned_be32(fc_host_supported_classes(lport->host),
632 /* Port Fabric name */
633 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
634 FC_FDMI_PORT_ATTR_SUPPORTEDCLASSSRVC_LEN);
635 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
636 len += FC_FDMI_PORT_ATTR_FABRICNAME_LEN;
637 put_unaligned_be16(FC_FDMI_PORT_ATTR_FABRICNAME,
639 put_unaligned_be16(len, &entry->len);
640 put_unaligned_be64(fc_host_fabric_name(lport->host),
643 /* Port active FC-4 */
644 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
645 FC_FDMI_PORT_ATTR_FABRICNAME_LEN);
646 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
647 len += FC_FDMI_PORT_ATTR_CURRENTFC4TYPE_LEN;
648 put_unaligned_be16(FC_FDMI_PORT_ATTR_CURRENTFC4TYPE,
650 put_unaligned_be16(len, &entry->len);
651 memcpy(&entry->value, fc_host_active_fc4s(lport->host),
652 FC_FDMI_PORT_ATTR_CURRENTFC4TYPE_LEN);
655 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
656 FC_FDMI_PORT_ATTR_CURRENTFC4TYPE_LEN);
657 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
658 len += FC_FDMI_PORT_ATTR_PORTSTATE_LEN;
659 put_unaligned_be16(FC_FDMI_PORT_ATTR_PORTSTATE,
661 put_unaligned_be16(len, &entry->len);
662 put_unaligned_be32(fc_host_port_state(lport->host),
665 /* Discovered ports */
666 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
667 FC_FDMI_PORT_ATTR_PORTSTATE_LEN);
668 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
669 len += FC_FDMI_PORT_ATTR_DISCOVEREDPORTS_LEN;
670 put_unaligned_be16(FC_FDMI_PORT_ATTR_DISCOVEREDPORTS,
672 put_unaligned_be16(len, &entry->len);
673 put_unaligned_be32(fc_host_num_discovered_ports(lport->host),
677 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
678 FC_FDMI_PORT_ATTR_DISCOVEREDPORTS_LEN);
679 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
680 len += FC_FDMI_PORT_ATTR_PORTID_LEN;
681 put_unaligned_be16(FC_FDMI_PORT_ATTR_PORTID,
683 put_unaligned_be16(len, &entry->len);
684 put_unaligned_be32(fc_host_port_id(lport->host),
690 len = sizeof(struct fc_fdmi_dprt);
691 ct = fc_ct_hdr_fill(fp, op, len, FC_FST_MGMT,
694 put_unaligned_be64(lport->wwpn,
695 &ct->payload.dprt.port.portname);
698 len = sizeof(struct fc_fdmi_dhba);
699 ct = fc_ct_hdr_fill(fp, op, len, FC_FST_MGMT,
702 put_unaligned_be64(lport->wwpn, &ct->payload.dhba.hbaid.id);
707 *r_ctl = FC_RCTL_DD_UNSOL_CTL;
708 *fh_type = FC_TYPE_CT;
713 * fc_ct_fill() - Fill in a common transport service request frame
714 * @lport: local port.
715 * @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries.
716 * @fp: frame to contain payload.
718 * @r_ctl: pointer to FC header R_CTL.
719 * @fh_type: pointer to FC-4 type.
721 static inline int fc_ct_fill(struct fc_lport *lport,
722 u32 fc_id, struct fc_frame *fp,
723 unsigned int op, enum fc_rctl *r_ctl,
724 enum fc_fh_type *fh_type, u32 *did)
729 case FC_FID_MGMT_SERV:
730 rc = fc_ct_ms_fill(lport, fc_id, fp, op, r_ctl, fh_type);
731 *did = FC_FID_MGMT_SERV;
733 case FC_FID_DIR_SERV:
735 rc = fc_ct_ns_fill(lport, fc_id, fp, op, r_ctl, fh_type);
736 *did = FC_FID_DIR_SERV;
743 * fc_plogi_fill - Fill in plogi request frame
745 static inline void fc_plogi_fill(struct fc_lport *lport, struct fc_frame *fp,
748 struct fc_els_flogi *plogi;
749 struct fc_els_csp *csp;
750 struct fc_els_cssp *cp;
752 plogi = fc_frame_payload_get(fp, sizeof(*plogi));
753 memset(plogi, 0, sizeof(*plogi));
754 plogi->fl_cmd = (u8) op;
755 put_unaligned_be64(lport->wwpn, &plogi->fl_wwpn);
756 put_unaligned_be64(lport->wwnn, &plogi->fl_wwnn);
758 csp = &plogi->fl_csp;
759 csp->sp_hi_ver = 0x20;
760 csp->sp_lo_ver = 0x20;
761 csp->sp_bb_cred = htons(10); /* this gets set by gateway */
762 csp->sp_bb_data = htons((u16) lport->mfs);
763 cp = &plogi->fl_cssp[3 - 1]; /* class 3 parameters */
764 cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
765 csp->sp_features = htons(FC_SP_FT_CIRO);
766 csp->sp_tot_seq = htons(255); /* seq. we accept */
767 csp->sp_rel_off = htons(0x1f);
768 csp->sp_e_d_tov = htonl(lport->e_d_tov);
770 cp->cp_rdfs = htons((u16) lport->mfs);
771 cp->cp_con_seq = htons(255);
776 * fc_flogi_fill - Fill in a flogi request frame.
778 static inline void fc_flogi_fill(struct fc_lport *lport, struct fc_frame *fp)
780 struct fc_els_csp *sp;
781 struct fc_els_cssp *cp;
782 struct fc_els_flogi *flogi;
784 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
785 memset(flogi, 0, sizeof(*flogi));
786 flogi->fl_cmd = (u8) ELS_FLOGI;
787 put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn);
788 put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn);
790 sp->sp_hi_ver = 0x20;
791 sp->sp_lo_ver = 0x20;
792 sp->sp_bb_cred = htons(10); /* this gets set by gateway */
793 sp->sp_bb_data = htons((u16) lport->mfs);
794 cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */
795 cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
796 if (lport->does_npiv)
797 sp->sp_features = htons(FC_SP_FT_NPIV);
801 * fc_fdisc_fill - Fill in a fdisc request frame.
803 static inline void fc_fdisc_fill(struct fc_lport *lport, struct fc_frame *fp)
805 struct fc_els_csp *sp;
806 struct fc_els_cssp *cp;
807 struct fc_els_flogi *fdisc;
809 fdisc = fc_frame_payload_get(fp, sizeof(*fdisc));
810 memset(fdisc, 0, sizeof(*fdisc));
811 fdisc->fl_cmd = (u8) ELS_FDISC;
812 put_unaligned_be64(lport->wwpn, &fdisc->fl_wwpn);
813 put_unaligned_be64(lport->wwnn, &fdisc->fl_wwnn);
815 sp->sp_hi_ver = 0x20;
816 sp->sp_lo_ver = 0x20;
817 sp->sp_bb_cred = htons(10); /* this gets set by gateway */
818 sp->sp_bb_data = htons((u16) lport->mfs);
819 cp = &fdisc->fl_cssp[3 - 1]; /* class 3 parameters */
820 cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
824 * fc_logo_fill - Fill in a logo request frame.
826 static inline void fc_logo_fill(struct fc_lport *lport, struct fc_frame *fp)
828 struct fc_els_logo *logo;
830 logo = fc_frame_payload_get(fp, sizeof(*logo));
831 memset(logo, 0, sizeof(*logo));
832 logo->fl_cmd = ELS_LOGO;
833 hton24(logo->fl_n_port_id, lport->port_id);
834 logo->fl_n_port_wwn = htonll(lport->wwpn);
838 * fc_rtv_fill - Fill in RTV (read timeout value) request frame.
840 static inline void fc_rtv_fill(struct fc_lport *lport, struct fc_frame *fp)
842 struct fc_els_rtv *rtv;
844 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
845 memset(rtv, 0, sizeof(*rtv));
846 rtv->rtv_cmd = ELS_RTV;
850 * fc_rec_fill - Fill in rec request frame
852 static inline void fc_rec_fill(struct fc_lport *lport, struct fc_frame *fp)
854 struct fc_els_rec *rec;
855 struct fc_exch *ep = fc_seq_exch(fr_seq(fp));
857 rec = fc_frame_payload_get(fp, sizeof(*rec));
858 memset(rec, 0, sizeof(*rec));
859 rec->rec_cmd = ELS_REC;
860 hton24(rec->rec_s_id, lport->port_id);
861 rec->rec_ox_id = htons(ep->oxid);
862 rec->rec_rx_id = htons(ep->rxid);
866 * fc_prli_fill - Fill in prli request frame
868 static inline void fc_prli_fill(struct fc_lport *lport, struct fc_frame *fp)
871 struct fc_els_prli prli;
872 struct fc_els_spp spp;
875 pp = fc_frame_payload_get(fp, sizeof(*pp));
876 memset(pp, 0, sizeof(*pp));
877 pp->prli.prli_cmd = ELS_PRLI;
878 pp->prli.prli_spp_len = sizeof(struct fc_els_spp);
879 pp->prli.prli_len = htons(sizeof(*pp));
880 pp->spp.spp_type = FC_TYPE_FCP;
881 pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR;
882 pp->spp.spp_params = htonl(lport->service_params);
886 * fc_scr_fill - Fill in a scr request frame.
888 static inline void fc_scr_fill(struct fc_lport *lport, struct fc_frame *fp)
890 struct fc_els_scr *scr;
892 scr = fc_frame_payload_get(fp, sizeof(*scr));
893 memset(scr, 0, sizeof(*scr));
894 scr->scr_cmd = ELS_SCR;
895 scr->scr_reg_func = ELS_SCRF_FULL;
899 * fc_els_fill - Fill in an ELS request frame
901 static inline int fc_els_fill(struct fc_lport *lport,
903 struct fc_frame *fp, unsigned int op,
904 enum fc_rctl *r_ctl, enum fc_fh_type *fh_type)
908 fc_adisc_fill(lport, fp);
912 fc_plogi_fill(lport, fp, ELS_PLOGI);
916 fc_flogi_fill(lport, fp);
920 fc_fdisc_fill(lport, fp);
924 fc_logo_fill(lport, fp);
928 fc_rtv_fill(lport, fp);
932 fc_rec_fill(lport, fp);
936 fc_prli_fill(lport, fp);
940 fc_scr_fill(lport, fp);
947 *r_ctl = FC_RCTL_ELS_REQ;
948 *fh_type = FC_TYPE_ELS;
951 #endif /* _FC_ENCODE_H_ */