blob: 35fd4744f3e9d3951c23191c6f9baebce0afc32a [file] [log] [blame]
Robert Love42e9a922008-12-09 15:10:17 -08001/*
2 * Copyright(c) 2008 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_ENCODE_H_
21#define _FC_ENCODE_H_
22#include <asm/unaligned.h>
Neerav Parikhd78c3172012-01-22 17:30:05 -080023#include <linux/utsname.h>
Robert Love42e9a922008-12-09 15:10:17 -080024
Joe Eykholt24f089e2010-07-20 15:21:01 -070025/*
26 * F_CTL values for simple requests and responses.
27 */
28#define FC_FCTL_REQ (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)
29#define FC_FCTL_RESP (FC_FC_EX_CTX | FC_FC_LAST_SEQ | \
30 FC_FC_END_SEQ | FC_FC_SEQ_INIT)
31
Robert Love42e9a922008-12-09 15:10:17 -080032struct fc_ns_rft {
33 struct fc_ns_fid fid; /* port ID object */
34 struct fc_ns_fts fts; /* FC4-types object */
35};
36
37struct fc_ct_req {
38 struct fc_ct_hdr hdr;
39 union {
40 struct fc_ns_gid_ft gid;
41 struct fc_ns_rn_id rn;
42 struct fc_ns_rft rft;
Joe Eykholtab593b12009-11-03 11:49:27 -080043 struct fc_ns_rff_id rff;
Joe Eykholt2ab7e1e2009-08-25 14:03:58 -070044 struct fc_ns_fid fid;
Chris Leech5baa17c2009-11-03 11:46:56 -080045 struct fc_ns_rsnn snn;
Chris Leechc9866a52009-11-03 11:47:01 -080046 struct fc_ns_rspn spn;
Neerav Parikhd78c3172012-01-22 17:30:05 -080047 struct fc_fdmi_rhba rhba;
48 struct fc_fdmi_rpa rpa;
49 struct fc_fdmi_dprt dprt;
50 struct fc_fdmi_dhba dhba;
Robert Love42e9a922008-12-09 15:10:17 -080051 } payload;
52};
53
Bhanu Prakash Gollapudi059f04d2011-02-25 15:03:07 -080054static inline void __fc_fill_fc_hdr(struct fc_frame_header *fh,
55 enum fc_rctl r_ctl,
56 u32 did, u32 sid, enum fc_fh_type type,
57 u32 f_ctl, u32 parm_offset)
58{
59 WARN_ON(r_ctl == 0);
60 fh->fh_r_ctl = r_ctl;
61 hton24(fh->fh_d_id, did);
62 hton24(fh->fh_s_id, sid);
63 fh->fh_type = type;
64 hton24(fh->fh_f_ctl, f_ctl);
65 fh->fh_cs_ctl = 0;
66 fh->fh_df_ctl = 0;
67 fh->fh_parm_offset = htonl(parm_offset);
68}
69
Robert Love42e9a922008-12-09 15:10:17 -080070/**
71 * fill FC header fields in specified fc_frame
72 */
73static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl,
74 u32 did, u32 sid, enum fc_fh_type type,
75 u32 f_ctl, u32 parm_offset)
76{
77 struct fc_frame_header *fh;
78
79 fh = fc_frame_header_get(fp);
Bhanu Prakash Gollapudi059f04d2011-02-25 15:03:07 -080080 __fc_fill_fc_hdr(fh, r_ctl, did, sid, type, f_ctl, parm_offset);
Robert Love42e9a922008-12-09 15:10:17 -080081}
82
83/**
Joe Eykholt370c3bd2009-08-25 14:03:47 -070084 * fc_adisc_fill() - Fill in adisc request frame
85 * @lport: local port.
86 * @fp: fc frame where payload will be placed.
87 */
88static inline void fc_adisc_fill(struct fc_lport *lport, struct fc_frame *fp)
89{
90 struct fc_els_adisc *adisc;
91
92 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
93 memset(adisc, 0, sizeof(*adisc));
94 adisc->adisc_cmd = ELS_ADISC;
95 put_unaligned_be64(lport->wwpn, &adisc->adisc_wwpn);
96 put_unaligned_be64(lport->wwnn, &adisc->adisc_wwnn);
Robert Love7b2787e2010-05-07 15:18:41 -070097 hton24(adisc->adisc_port_id, lport->port_id);
Joe Eykholt370c3bd2009-08-25 14:03:47 -070098}
99
100/**
Robert Love42e9a922008-12-09 15:10:17 -0800101 * fc_ct_hdr_fill- fills ct header and reset ct payload
102 * returns pointer to ct request.
103 */
104static inline struct fc_ct_req *fc_ct_hdr_fill(const struct fc_frame *fp,
Neerav Parikh1ea2c1d2012-01-22 17:30:00 -0800105 unsigned int op, size_t req_size,
106 enum fc_ct_fs_type fs_type,
107 u8 subtype)
Robert Love42e9a922008-12-09 15:10:17 -0800108{
109 struct fc_ct_req *ct;
110 size_t ct_plen;
111
112 ct_plen = sizeof(struct fc_ct_hdr) + req_size;
113 ct = fc_frame_payload_get(fp, ct_plen);
114 memset(ct, 0, ct_plen);
115 ct->hdr.ct_rev = FC_CT_REV;
Neerav Parikh1ea2c1d2012-01-22 17:30:00 -0800116 ct->hdr.ct_fs_type = fs_type;
117 ct->hdr.ct_fs_subtype = subtype;
Robert Love42e9a922008-12-09 15:10:17 -0800118 ct->hdr.ct_cmd = htons((u16) op);
119 return ct;
120}
121
122/**
Neerav Parikh1ea2c1d2012-01-22 17:30:00 -0800123 * fc_ct_ns_fill() - Fill in a name service request frame
Joe Eykholt2ab7e1e2009-08-25 14:03:58 -0700124 * @lport: local port.
125 * @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries.
126 * @fp: frame to contain payload.
127 * @op: CT opcode.
128 * @r_ctl: pointer to FC header R_CTL.
129 * @fh_type: pointer to FC-4 type.
Robert Love42e9a922008-12-09 15:10:17 -0800130 */
Neerav Parikh1ea2c1d2012-01-22 17:30:00 -0800131static inline int fc_ct_ns_fill(struct fc_lport *lport,
Joe Eykholt2ab7e1e2009-08-25 14:03:58 -0700132 u32 fc_id, struct fc_frame *fp,
Joe Eykholta46f3272009-08-25 14:00:55 -0700133 unsigned int op, enum fc_rctl *r_ctl,
Robert Love42e9a922008-12-09 15:10:17 -0800134 enum fc_fh_type *fh_type)
135{
136 struct fc_ct_req *ct;
Joe Eykholt5f9a0562009-11-03 11:48:55 -0800137 size_t len;
Robert Love42e9a922008-12-09 15:10:17 -0800138
139 switch (op) {
140 case FC_NS_GPN_FT:
Neerav Parikh1ea2c1d2012-01-22 17:30:00 -0800141 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_gid_ft),
142 FC_FST_DIR, FC_NS_SUBTYPE);
Robert Love42e9a922008-12-09 15:10:17 -0800143 ct->payload.gid.fn_fc4_type = FC_TYPE_FCP;
144 break;
145
Joe Eykholt2ab7e1e2009-08-25 14:03:58 -0700146 case FC_NS_GPN_ID:
Neerav Parikh1ea2c1d2012-01-22 17:30:00 -0800147 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_fid),
148 FC_FST_DIR, FC_NS_SUBTYPE);
149 ct->payload.gid.fn_fc4_type = FC_TYPE_FCP;
Joe Eykholt2ab7e1e2009-08-25 14:03:58 -0700150 hton24(ct->payload.fid.fp_fid, fc_id);
151 break;
152
Robert Love42e9a922008-12-09 15:10:17 -0800153 case FC_NS_RFT_ID:
Neerav Parikh1ea2c1d2012-01-22 17:30:00 -0800154 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rft),
155 FC_FST_DIR, FC_NS_SUBTYPE);
Robert Love7b2787e2010-05-07 15:18:41 -0700156 hton24(ct->payload.rft.fid.fp_fid, lport->port_id);
Robert Love42e9a922008-12-09 15:10:17 -0800157 ct->payload.rft.fts = lport->fcts;
158 break;
159
Joe Eykholtab593b12009-11-03 11:49:27 -0800160 case FC_NS_RFF_ID:
Neerav Parikh1ea2c1d2012-01-22 17:30:00 -0800161 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rff_id),
162 FC_FST_DIR, FC_NS_SUBTYPE);
Robert Love7b2787e2010-05-07 15:18:41 -0700163 hton24(ct->payload.rff.fr_fid.fp_fid, lport->port_id);
Joe Eykholtab593b12009-11-03 11:49:27 -0800164 ct->payload.rff.fr_type = FC_TYPE_FCP;
165 if (lport->service_params & FCP_SPPF_INIT_FCN)
166 ct->payload.rff.fr_feat = FCP_FEAT_INIT;
167 if (lport->service_params & FCP_SPPF_TARG_FCN)
168 ct->payload.rff.fr_feat |= FCP_FEAT_TARG;
169 break;
170
Chris Leechc9c7bd72009-11-03 11:46:51 -0800171 case FC_NS_RNN_ID:
Neerav Parikh1ea2c1d2012-01-22 17:30:00 -0800172 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rn_id),
173 FC_FST_DIR, FC_NS_SUBTYPE);
Robert Love7b2787e2010-05-07 15:18:41 -0700174 hton24(ct->payload.rn.fr_fid.fp_fid, lport->port_id);
Chris Leechc9c7bd72009-11-03 11:46:51 -0800175 put_unaligned_be64(lport->wwnn, &ct->payload.rn.fr_wwn);
Robert Love42e9a922008-12-09 15:10:17 -0800176 break;
177
Chris Leechc9866a52009-11-03 11:47:01 -0800178 case FC_NS_RSPN_ID:
Joe Eykholt5f9a0562009-11-03 11:48:55 -0800179 len = strnlen(fc_host_symbolic_name(lport->host), 255);
Neerav Parikh1ea2c1d2012-01-22 17:30:00 -0800180 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rspn) + len,
181 FC_FST_DIR, FC_NS_SUBTYPE);
Robert Love7b2787e2010-05-07 15:18:41 -0700182 hton24(ct->payload.spn.fr_fid.fp_fid, lport->port_id);
Chris Leechc9866a52009-11-03 11:47:01 -0800183 strncpy(ct->payload.spn.fr_name,
Joe Eykholt5f9a0562009-11-03 11:48:55 -0800184 fc_host_symbolic_name(lport->host), len);
185 ct->payload.spn.fr_name_len = len;
Chris Leechc9866a52009-11-03 11:47:01 -0800186 break;
187
Chris Leech5baa17c2009-11-03 11:46:56 -0800188 case FC_NS_RSNN_NN:
Joe Eykholt5f9a0562009-11-03 11:48:55 -0800189 len = strnlen(fc_host_symbolic_name(lport->host), 255);
Neerav Parikh1ea2c1d2012-01-22 17:30:00 -0800190 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rsnn) + len,
191 FC_FST_DIR, FC_NS_SUBTYPE);
Chris Leech5baa17c2009-11-03 11:46:56 -0800192 put_unaligned_be64(lport->wwnn, &ct->payload.snn.fr_wwn);
193 strncpy(ct->payload.snn.fr_name,
Joe Eykholt5f9a0562009-11-03 11:48:55 -0800194 fc_host_symbolic_name(lport->host), len);
195 ct->payload.snn.fr_name_len = len;
Chris Leech5baa17c2009-11-03 11:46:56 -0800196 break;
197
Robert Love42e9a922008-12-09 15:10:17 -0800198 default:
Robert Love42e9a922008-12-09 15:10:17 -0800199 return -EINVAL;
200 }
201 *r_ctl = FC_RCTL_DD_UNSOL_CTL;
Robert Love42e9a922008-12-09 15:10:17 -0800202 *fh_type = FC_TYPE_CT;
203 return 0;
204}
205
206/**
Neerav Parikhd78c3172012-01-22 17:30:05 -0800207 * fc_ct_ms_fill() - Fill in a mgmt service request frame
208 * @lport: local port.
209 * @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries.
210 * @fp: frame to contain payload.
211 * @op: CT opcode.
212 * @r_ctl: pointer to FC header R_CTL.
213 * @fh_type: pointer to FC-4 type.
214 */
215static inline int fc_ct_ms_fill(struct fc_lport *lport,
216 u32 fc_id, struct fc_frame *fp,
217 unsigned int op, enum fc_rctl *r_ctl,
218 enum fc_fh_type *fh_type)
219{
220 struct fc_ct_req *ct;
221 size_t len;
222 struct fc_fdmi_attr_entry *entry;
223 struct fs_fdmi_attrs *hba_attrs;
224 int numattrs = 0;
225
226 switch (op) {
227 case FC_FDMI_RHBA:
228 numattrs = 10;
229 len = sizeof(struct fc_fdmi_rhba);
230 len -= sizeof(struct fc_fdmi_attr_entry);
231 len += (numattrs * FC_FDMI_ATTR_ENTRY_HEADER_LEN);
232 len += FC_FDMI_HBA_ATTR_NODENAME_LEN;
233 len += FC_FDMI_HBA_ATTR_MANUFACTURER_LEN;
234 len += FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN;
235 len += FC_FDMI_HBA_ATTR_MODEL_LEN;
236 len += FC_FDMI_HBA_ATTR_MODELDESCR_LEN;
237 len += FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN;
238 len += FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN;
239 len += FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN;
240 len += FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN;
241 len += FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN;
242 ct = fc_ct_hdr_fill(fp, op, len, FC_FST_MGMT,
243 FC_FDMI_SUBTYPE);
244
245 /* HBA Identifier */
246 put_unaligned_be64(lport->wwpn, &ct->payload.rhba.hbaid.id);
247 /* Number of Ports - always 1 */
248 put_unaligned_be32(1, &ct->payload.rhba.port.numport);
249 /* Port Name */
250 put_unaligned_be64(lport->wwpn,
251 &ct->payload.rhba.port.port[0].portname);
252
253 /* HBA Attributes */
254 put_unaligned_be32(numattrs,
255 &ct->payload.rhba.hba_attrs.numattrs);
256 hba_attrs = &ct->payload.rhba.hba_attrs;
257 entry = (struct fc_fdmi_attr_entry *)hba_attrs->attr;
258 /* NodeName*/
259 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
260 len += FC_FDMI_HBA_ATTR_NODENAME_LEN;
261 put_unaligned_be16(FC_FDMI_HBA_ATTR_NODENAME,
262 &entry->type);
263 put_unaligned_be16(len, &entry->len);
264 put_unaligned_be64(lport->wwnn,
265 (__be64 *)&entry->value[0]);
266
267 /* Manufacturer */
268 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
269 FC_FDMI_HBA_ATTR_NODENAME_LEN);
270 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
271 len += FC_FDMI_HBA_ATTR_MANUFACTURER_LEN;
272 put_unaligned_be16(FC_FDMI_HBA_ATTR_MANUFACTURER,
273 &entry->type);
274 put_unaligned_be16(len, &entry->len);
275 strncpy((char *)&entry->value,
276 fc_host_manufacturer(lport->host),
277 FC_FDMI_HBA_ATTR_MANUFACTURER_LEN);
278
279 /* SerialNumber */
280 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
281 FC_FDMI_HBA_ATTR_MANUFACTURER_LEN);
282 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
283 len += FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN;
284 put_unaligned_be16(FC_FDMI_HBA_ATTR_SERIALNUMBER,
285 &entry->type);
286 put_unaligned_be16(len, &entry->len);
287 strncpy((char *)&entry->value,
288 fc_host_serial_number(lport->host),
289 FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN);
290
291 /* Model */
292 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
293 FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN);
294 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
295 len += FC_FDMI_HBA_ATTR_MODEL_LEN;
296 put_unaligned_be16(FC_FDMI_HBA_ATTR_MODEL,
297 &entry->type);
298 put_unaligned_be16(len, &entry->len);
299 strncpy((char *)&entry->value,
300 fc_host_model(lport->host),
301 FC_FDMI_HBA_ATTR_MODEL_LEN);
302
303 /* Model Description */
304 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
305 FC_FDMI_HBA_ATTR_MODEL_LEN);
306 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
307 len += FC_FDMI_HBA_ATTR_MODELDESCR_LEN;
308 put_unaligned_be16(FC_FDMI_HBA_ATTR_MODELDESCRIPTION,
309 &entry->type);
310 put_unaligned_be16(len, &entry->len);
311 strncpy((char *)&entry->value,
312 fc_host_model_description(lport->host),
313 FC_FDMI_HBA_ATTR_MODELDESCR_LEN);
314
315 /* Hardware Version */
316 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
317 FC_FDMI_HBA_ATTR_MODELDESCR_LEN);
318 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
319 len += FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN;
320 put_unaligned_be16(FC_FDMI_HBA_ATTR_HARDWAREVERSION,
321 &entry->type);
322 put_unaligned_be16(len, &entry->len);
323 strncpy((char *)&entry->value,
324 fc_host_hardware_version(lport->host),
325 FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN);
326
327 /* Driver Version */
328 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
329 FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN);
330 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
331 len += FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN;
332 put_unaligned_be16(FC_FDMI_HBA_ATTR_DRIVERVERSION,
333 &entry->type);
334 put_unaligned_be16(len, &entry->len);
335 strncpy((char *)&entry->value,
336 fc_host_driver_version(lport->host),
337 FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN);
338
339 /* OptionROM Version */
340 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
341 FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN);
342 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
343 len += FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN;
344 put_unaligned_be16(FC_FDMI_HBA_ATTR_OPTIONROMVERSION,
345 &entry->type);
346 put_unaligned_be16(len, &entry->len);
347 strncpy((char *)&entry->value,
348 fc_host_optionrom_version(lport->host),
349 FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN);
350
351 /* Firmware Version */
352 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
353 FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN);
354 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
355 len += FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN;
356 put_unaligned_be16(FC_FDMI_HBA_ATTR_FIRMWAREVERSION,
357 &entry->type);
358 put_unaligned_be16(len, &entry->len);
359 strncpy((char *)&entry->value,
360 fc_host_firmware_version(lport->host),
361 FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN);
362
363 /* OS Name and Version */
364 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
365 FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN);
366 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
367 len += FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN;
368 put_unaligned_be16(FC_FDMI_HBA_ATTR_OSNAMEVERSION,
369 &entry->type);
370 put_unaligned_be16(len, &entry->len);
371 snprintf((char *)&entry->value,
372 FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN,
373 "%s v%s",
374 init_utsname()->sysname,
375 init_utsname()->release);
376 break;
377 case FC_FDMI_RPA:
378 numattrs = 6;
379 len = sizeof(struct fc_fdmi_rpa);
380 len -= sizeof(struct fc_fdmi_attr_entry);
381 len += (numattrs * FC_FDMI_ATTR_ENTRY_HEADER_LEN);
382 len += FC_FDMI_PORT_ATTR_FC4TYPES_LEN;
383 len += FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN;
384 len += FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN;
385 len += FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN;
386 len += FC_FDMI_PORT_ATTR_OSDEVICENAME_LEN;
387 len += FC_FDMI_PORT_ATTR_HOSTNAME_LEN;
388 ct = fc_ct_hdr_fill(fp, op, len, FC_FST_MGMT,
389 FC_FDMI_SUBTYPE);
390
391 /* Port Name */
392 put_unaligned_be64(lport->wwpn,
393 &ct->payload.rpa.port.portname);
394
395 /* Port Attributes */
396 put_unaligned_be32(numattrs,
397 &ct->payload.rpa.hba_attrs.numattrs);
398
399 hba_attrs = &ct->payload.rpa.hba_attrs;
400 entry = (struct fc_fdmi_attr_entry *)hba_attrs->attr;
401
402 /* FC4 types */
403 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
404 len += FC_FDMI_PORT_ATTR_FC4TYPES_LEN;
405 put_unaligned_be16(FC_FDMI_PORT_ATTR_FC4TYPES,
406 &entry->type);
407 put_unaligned_be16(len, &entry->len);
408 memcpy(&entry->value, fc_host_supported_fc4s(lport->host),
409 FC_FDMI_PORT_ATTR_FC4TYPES_LEN);
410
411 /* Supported Speed */
412 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
413 FC_FDMI_PORT_ATTR_FC4TYPES_LEN);
414 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
415 len += FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN;
416 put_unaligned_be16(FC_FDMI_PORT_ATTR_SUPPORTEDSPEED,
417 &entry->type);
418 put_unaligned_be16(len, &entry->len);
419
420 put_unaligned_be32(fc_host_supported_speeds(lport->host),
421 &entry->value);
422
423 /* Current Port Speed */
424 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
425 FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN);
426 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
427 len += FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN;
428 put_unaligned_be16(FC_FDMI_PORT_ATTR_CURRENTPORTSPEED,
429 &entry->type);
430 put_unaligned_be16(len, &entry->len);
431 put_unaligned_be32(lport->link_speed,
432 &entry->value);
433
434 /* Max Frame Size */
435 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
436 FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN);
437 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
438 len += FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN;
439 put_unaligned_be16(FC_FDMI_PORT_ATTR_MAXFRAMESIZE,
440 &entry->type);
441 put_unaligned_be16(len, &entry->len);
442 put_unaligned_be32(fc_host_maxframe_size(lport->host),
443 &entry->value);
444
445 /* OS Device Name */
446 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
447 FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN);
448 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
449 len += FC_FDMI_PORT_ATTR_OSDEVICENAME_LEN;
450 put_unaligned_be16(FC_FDMI_PORT_ATTR_OSDEVICENAME,
451 &entry->type);
452 put_unaligned_be16(len, &entry->len);
453 /* Use the sysfs device name */
454 strncpy((char *)&entry->value,
455 dev_name(&lport->host->shost_gendev),
456 strnlen(dev_name(&lport->host->shost_gendev),
457 FC_FDMI_PORT_ATTR_HOSTNAME_LEN));
458
459 /* Host Name */
460 entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
461 FC_FDMI_PORT_ATTR_OSDEVICENAME_LEN);
462 len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
463 len += FC_FDMI_PORT_ATTR_HOSTNAME_LEN;
464 put_unaligned_be16(FC_FDMI_PORT_ATTR_HOSTNAME,
465 &entry->type);
466 put_unaligned_be16(len, &entry->len);
467 if (strlen(fc_host_system_hostname(lport->host)))
468 strncpy((char *)&entry->value,
469 fc_host_system_hostname(lport->host),
470 strnlen(fc_host_system_hostname(lport->host),
471 FC_FDMI_PORT_ATTR_HOSTNAME_LEN));
472 else
473 strncpy((char *)&entry->value,
474 init_utsname()->nodename,
475 FC_FDMI_PORT_ATTR_HOSTNAME_LEN);
476 break;
477 case FC_FDMI_DPRT:
478 len = sizeof(struct fc_fdmi_dprt);
479 ct = fc_ct_hdr_fill(fp, op, len, FC_FST_MGMT,
480 FC_FDMI_SUBTYPE);
481 /* Port Name */
482 put_unaligned_be64(lport->wwpn,
483 &ct->payload.dprt.port.portname);
484 break;
485 case FC_FDMI_DHBA:
486 len = sizeof(struct fc_fdmi_dhba);
487 ct = fc_ct_hdr_fill(fp, op, len, FC_FST_MGMT,
488 FC_FDMI_SUBTYPE);
489 /* HBA Identifier */
490 put_unaligned_be64(lport->wwpn, &ct->payload.dhba.hbaid.id);
491 break;
492 default:
493 return -EINVAL;
494 }
495 *r_ctl = FC_RCTL_DD_UNSOL_CTL;
496 *fh_type = FC_TYPE_CT;
497 return 0;
498}
499
500/**
Neerav Parikh1ea2c1d2012-01-22 17:30:00 -0800501 * fc_ct_fill() - Fill in a common transport service request frame
502 * @lport: local port.
503 * @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries.
504 * @fp: frame to contain payload.
505 * @op: CT opcode.
506 * @r_ctl: pointer to FC header R_CTL.
507 * @fh_type: pointer to FC-4 type.
508 */
509static inline int fc_ct_fill(struct fc_lport *lport,
510 u32 fc_id, struct fc_frame *fp,
511 unsigned int op, enum fc_rctl *r_ctl,
512 enum fc_fh_type *fh_type, u32 *did)
513{
514 int rc = -EINVAL;
515
516 switch (fc_id) {
Neerav Parikhd78c3172012-01-22 17:30:05 -0800517 case FC_FID_MGMT_SERV:
518 rc = fc_ct_ms_fill(lport, fc_id, fp, op, r_ctl, fh_type);
519 *did = FC_FID_MGMT_SERV;
520 break;
Neerav Parikh1ea2c1d2012-01-22 17:30:00 -0800521 case FC_FID_DIR_SERV:
522 default:
523 rc = fc_ct_ns_fill(lport, fc_id, fp, op, r_ctl, fh_type);
524 *did = FC_FID_DIR_SERV;
525 break;
526 }
527
528 return rc;
529}
530/**
Robert Love42e9a922008-12-09 15:10:17 -0800531 * fc_plogi_fill - Fill in plogi request frame
532 */
533static inline void fc_plogi_fill(struct fc_lport *lport, struct fc_frame *fp,
534 unsigned int op)
535{
536 struct fc_els_flogi *plogi;
537 struct fc_els_csp *csp;
538 struct fc_els_cssp *cp;
539
540 plogi = fc_frame_payload_get(fp, sizeof(*plogi));
541 memset(plogi, 0, sizeof(*plogi));
542 plogi->fl_cmd = (u8) op;
543 put_unaligned_be64(lport->wwpn, &plogi->fl_wwpn);
544 put_unaligned_be64(lport->wwnn, &plogi->fl_wwnn);
545
546 csp = &plogi->fl_csp;
547 csp->sp_hi_ver = 0x20;
548 csp->sp_lo_ver = 0x20;
549 csp->sp_bb_cred = htons(10); /* this gets set by gateway */
550 csp->sp_bb_data = htons((u16) lport->mfs);
551 cp = &plogi->fl_cssp[3 - 1]; /* class 3 parameters */
552 cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
553 csp->sp_features = htons(FC_SP_FT_CIRO);
554 csp->sp_tot_seq = htons(255); /* seq. we accept */
555 csp->sp_rel_off = htons(0x1f);
556 csp->sp_e_d_tov = htonl(lport->e_d_tov);
557
558 cp->cp_rdfs = htons((u16) lport->mfs);
559 cp->cp_con_seq = htons(255);
560 cp->cp_open_seq = 1;
561}
562
563/**
564 * fc_flogi_fill - Fill in a flogi request frame.
565 */
566static inline void fc_flogi_fill(struct fc_lport *lport, struct fc_frame *fp)
567{
568 struct fc_els_csp *sp;
569 struct fc_els_cssp *cp;
570 struct fc_els_flogi *flogi;
571
572 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
573 memset(flogi, 0, sizeof(*flogi));
574 flogi->fl_cmd = (u8) ELS_FLOGI;
575 put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn);
576 put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn);
577 sp = &flogi->fl_csp;
578 sp->sp_hi_ver = 0x20;
579 sp->sp_lo_ver = 0x20;
580 sp->sp_bb_cred = htons(10); /* this gets set by gateway */
581 sp->sp_bb_data = htons((u16) lport->mfs);
582 cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */
583 cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
Chris Leechdb36c062009-11-03 11:46:24 -0800584 if (lport->does_npiv)
585 sp->sp_features = htons(FC_SP_FT_NPIV);
586}
587
588/**
589 * fc_fdisc_fill - Fill in a fdisc request frame.
590 */
591static inline void fc_fdisc_fill(struct fc_lport *lport, struct fc_frame *fp)
592{
593 struct fc_els_csp *sp;
594 struct fc_els_cssp *cp;
595 struct fc_els_flogi *fdisc;
596
597 fdisc = fc_frame_payload_get(fp, sizeof(*fdisc));
598 memset(fdisc, 0, sizeof(*fdisc));
599 fdisc->fl_cmd = (u8) ELS_FDISC;
600 put_unaligned_be64(lport->wwpn, &fdisc->fl_wwpn);
601 put_unaligned_be64(lport->wwnn, &fdisc->fl_wwnn);
602 sp = &fdisc->fl_csp;
603 sp->sp_hi_ver = 0x20;
604 sp->sp_lo_ver = 0x20;
605 sp->sp_bb_cred = htons(10); /* this gets set by gateway */
606 sp->sp_bb_data = htons((u16) lport->mfs);
607 cp = &fdisc->fl_cssp[3 - 1]; /* class 3 parameters */
608 cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
Robert Love42e9a922008-12-09 15:10:17 -0800609}
610
611/**
612 * fc_logo_fill - Fill in a logo request frame.
613 */
614static inline void fc_logo_fill(struct fc_lport *lport, struct fc_frame *fp)
615{
616 struct fc_els_logo *logo;
617
618 logo = fc_frame_payload_get(fp, sizeof(*logo));
619 memset(logo, 0, sizeof(*logo));
620 logo->fl_cmd = ELS_LOGO;
Robert Love7b2787e2010-05-07 15:18:41 -0700621 hton24(logo->fl_n_port_id, lport->port_id);
Robert Love42e9a922008-12-09 15:10:17 -0800622 logo->fl_n_port_wwn = htonll(lport->wwpn);
623}
624
625/**
626 * fc_rtv_fill - Fill in RTV (read timeout value) request frame.
627 */
628static inline void fc_rtv_fill(struct fc_lport *lport, struct fc_frame *fp)
629{
630 struct fc_els_rtv *rtv;
631
632 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
633 memset(rtv, 0, sizeof(*rtv));
634 rtv->rtv_cmd = ELS_RTV;
635}
636
637/**
638 * fc_rec_fill - Fill in rec request frame
639 */
640static inline void fc_rec_fill(struct fc_lport *lport, struct fc_frame *fp)
641{
642 struct fc_els_rec *rec;
643 struct fc_exch *ep = fc_seq_exch(fr_seq(fp));
644
645 rec = fc_frame_payload_get(fp, sizeof(*rec));
646 memset(rec, 0, sizeof(*rec));
647 rec->rec_cmd = ELS_REC;
Robert Love7b2787e2010-05-07 15:18:41 -0700648 hton24(rec->rec_s_id, lport->port_id);
Robert Love42e9a922008-12-09 15:10:17 -0800649 rec->rec_ox_id = htons(ep->oxid);
650 rec->rec_rx_id = htons(ep->rxid);
651}
652
653/**
654 * fc_prli_fill - Fill in prli request frame
655 */
656static inline void fc_prli_fill(struct fc_lport *lport, struct fc_frame *fp)
657{
658 struct {
659 struct fc_els_prli prli;
660 struct fc_els_spp spp;
661 } *pp;
662
663 pp = fc_frame_payload_get(fp, sizeof(*pp));
664 memset(pp, 0, sizeof(*pp));
665 pp->prli.prli_cmd = ELS_PRLI;
666 pp->prli.prli_spp_len = sizeof(struct fc_els_spp);
667 pp->prli.prli_len = htons(sizeof(*pp));
668 pp->spp.spp_type = FC_TYPE_FCP;
669 pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR;
670 pp->spp.spp_params = htonl(lport->service_params);
671}
672
673/**
674 * fc_scr_fill - Fill in a scr request frame.
675 */
676static inline void fc_scr_fill(struct fc_lport *lport, struct fc_frame *fp)
677{
678 struct fc_els_scr *scr;
679
680 scr = fc_frame_payload_get(fp, sizeof(*scr));
681 memset(scr, 0, sizeof(*scr));
682 scr->scr_cmd = ELS_SCR;
683 scr->scr_reg_func = ELS_SCRF_FULL;
684}
685
686/**
687 * fc_els_fill - Fill in an ELS request frame
688 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700689static inline int fc_els_fill(struct fc_lport *lport,
Joe Eykholta46f3272009-08-25 14:00:55 -0700690 u32 did,
Robert Love42e9a922008-12-09 15:10:17 -0800691 struct fc_frame *fp, unsigned int op,
Joe Eykholta46f3272009-08-25 14:00:55 -0700692 enum fc_rctl *r_ctl, enum fc_fh_type *fh_type)
Robert Love42e9a922008-12-09 15:10:17 -0800693{
694 switch (op) {
Joe Eykholt370c3bd2009-08-25 14:03:47 -0700695 case ELS_ADISC:
696 fc_adisc_fill(lport, fp);
697 break;
698
Robert Love42e9a922008-12-09 15:10:17 -0800699 case ELS_PLOGI:
700 fc_plogi_fill(lport, fp, ELS_PLOGI);
Robert Love42e9a922008-12-09 15:10:17 -0800701 break;
702
703 case ELS_FLOGI:
704 fc_flogi_fill(lport, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800705 break;
706
Chris Leechdb36c062009-11-03 11:46:24 -0800707 case ELS_FDISC:
708 fc_fdisc_fill(lport, fp);
709 break;
710
Robert Love42e9a922008-12-09 15:10:17 -0800711 case ELS_LOGO:
712 fc_logo_fill(lport, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800713 break;
714
715 case ELS_RTV:
716 fc_rtv_fill(lport, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800717 break;
718
719 case ELS_REC:
720 fc_rec_fill(lport, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800721 break;
722
723 case ELS_PRLI:
724 fc_prli_fill(lport, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800725 break;
726
727 case ELS_SCR:
728 fc_scr_fill(lport, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800729 break;
730
731 default:
Robert Love42e9a922008-12-09 15:10:17 -0800732 return -EINVAL;
733 }
734
735 *r_ctl = FC_RCTL_ELS_REQ;
736 *fh_type = FC_TYPE_ELS;
737 return 0;
738}
739#endif /* _FC_ENCODE_H_ */