fc_encode.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright(c) 2008 Intel Corporation. All rights reserved.
  4. *
  5. * Maintained at www.Open-FCoE.org
  6. */
  7. #ifndef _FC_ENCODE_H_
  8. #define _FC_ENCODE_H_
  9. #include <asm/unaligned.h>
  10. #include <linux/utsname.h>
  11. /*
  12. * F_CTL values for simple requests and responses.
  13. */
  14. #define FC_FCTL_REQ (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)
  15. #define FC_FCTL_RESP (FC_FC_EX_CTX | FC_FC_LAST_SEQ | \
  16. FC_FC_END_SEQ | FC_FC_SEQ_INIT)
  17. struct fc_ns_rft {
  18. struct fc_ns_fid fid; /* port ID object */
  19. struct fc_ns_fts fts; /* FC4-types object */
  20. };
  21. struct fc_ct_req {
  22. struct fc_ct_hdr hdr;
  23. union {
  24. struct fc_ns_gid_ft gid;
  25. struct fc_ns_rn_id rn;
  26. struct fc_ns_rft rft;
  27. struct fc_ns_rff_id rff;
  28. struct fc_ns_fid fid;
  29. struct fc_ns_rsnn snn;
  30. struct fc_ns_rspn spn;
  31. struct fc_fdmi_rhba rhba;
  32. struct fc_fdmi_rpa rpa;
  33. struct fc_fdmi_dprt dprt;
  34. struct fc_fdmi_dhba dhba;
  35. } payload;
  36. };
  37. static inline void __fc_fill_fc_hdr(struct fc_frame_header *fh,
  38. enum fc_rctl r_ctl,
  39. u32 did, u32 sid, enum fc_fh_type type,
  40. u32 f_ctl, u32 parm_offset)
  41. {
  42. WARN_ON(r_ctl == 0);
  43. fh->fh_r_ctl = r_ctl;
  44. hton24(fh->fh_d_id, did);
  45. hton24(fh->fh_s_id, sid);
  46. fh->fh_type = type;
  47. hton24(fh->fh_f_ctl, f_ctl);
  48. fh->fh_cs_ctl = 0;
  49. fh->fh_df_ctl = 0;
  50. fh->fh_parm_offset = htonl(parm_offset);
  51. }
  52. /**
  53. * fill FC header fields in specified fc_frame
  54. */
  55. static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl,
  56. u32 did, u32 sid, enum fc_fh_type type,
  57. u32 f_ctl, u32 parm_offset)
  58. {
  59. struct fc_frame_header *fh;
  60. fh = fc_frame_header_get(fp);
  61. __fc_fill_fc_hdr(fh, r_ctl, did, sid, type, f_ctl, parm_offset);
  62. }
  63. /**
  64. * fc_adisc_fill() - Fill in adisc request frame
  65. * @lport: local port.
  66. * @fp: fc frame where payload will be placed.
  67. */
  68. static inline void fc_adisc_fill(struct fc_lport *lport, struct fc_frame *fp)
  69. {
  70. struct fc_els_adisc *adisc;
  71. adisc = fc_frame_payload_get(fp, sizeof(*adisc));
  72. memset(adisc, 0, sizeof(*adisc));
  73. adisc->adisc_cmd = ELS_ADISC;
  74. put_unaligned_be64(lport->wwpn, &adisc->adisc_wwpn);
  75. put_unaligned_be64(lport->wwnn, &adisc->adisc_wwnn);
  76. hton24(adisc->adisc_port_id, lport->port_id);
  77. }
  78. /**
  79. * fc_ct_hdr_fill- fills ct header and reset ct payload
  80. * returns pointer to ct request.
  81. */
  82. static inline struct fc_ct_req *fc_ct_hdr_fill(const struct fc_frame *fp,
  83. unsigned int op, size_t req_size,
  84. enum fc_ct_fs_type fs_type,
  85. u8 subtype)
  86. {
  87. struct fc_ct_req *ct;
  88. size_t ct_plen;
  89. ct_plen = sizeof(struct fc_ct_hdr) + req_size;
  90. ct = fc_frame_payload_get(fp, ct_plen);
  91. memset(ct, 0, ct_plen);
  92. ct->hdr.ct_rev = FC_CT_REV;
  93. ct->hdr.ct_fs_type = fs_type;
  94. ct->hdr.ct_fs_subtype = subtype;
  95. ct->hdr.ct_cmd = htons((u16) op);
  96. return ct;
  97. }
  98. /**
  99. * fc_ct_ns_fill() - Fill in a name service request frame
  100. * @lport: local port.
  101. * @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries.
  102. * @fp: frame to contain payload.
  103. * @op: CT opcode.
  104. * @r_ctl: pointer to FC header R_CTL.
  105. * @fh_type: pointer to FC-4 type.
  106. */
  107. static inline int fc_ct_ns_fill(struct fc_lport *lport,
  108. u32 fc_id, struct fc_frame *fp,
  109. unsigned int op, enum fc_rctl *r_ctl,
  110. enum fc_fh_type *fh_type)
  111. {
  112. struct fc_ct_req *ct;
  113. size_t len;
  114. switch (op) {
  115. case FC_NS_GPN_FT:
  116. ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_gid_ft),
  117. FC_FST_DIR, FC_NS_SUBTYPE);
  118. ct->payload.gid.fn_fc4_type = FC_TYPE_FCP;
  119. break;
  120. case FC_NS_GPN_ID:
  121. ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_fid),
  122. FC_FST_DIR, FC_NS_SUBTYPE);
  123. ct->payload.gid.fn_fc4_type = FC_TYPE_FCP;
  124. hton24(ct->payload.fid.fp_fid, fc_id);
  125. break;
  126. case FC_NS_RFT_ID:
  127. ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rft),
  128. FC_FST_DIR, FC_NS_SUBTYPE);
  129. hton24(ct->payload.rft.fid.fp_fid, lport->port_id);
  130. ct->payload.rft.fts = lport->fcts;
  131. break;
  132. case FC_NS_RFF_ID:
  133. ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rff_id),
  134. FC_FST_DIR, FC_NS_SUBTYPE);
  135. hton24(ct->payload.rff.fr_fid.fp_fid, lport->port_id);
  136. ct->payload.rff.fr_type = FC_TYPE_FCP;
  137. if (lport->service_params & FCP_SPPF_INIT_FCN)
  138. ct->payload.rff.fr_feat = FCP_FEAT_INIT;
  139. if (lport->service_params & FCP_SPPF_TARG_FCN)
  140. ct->payload.rff.fr_feat |= FCP_FEAT_TARG;
  141. break;
  142. case FC_NS_RNN_ID:
  143. ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rn_id),
  144. FC_FST_DIR, FC_NS_SUBTYPE);
  145. hton24(ct->payload.rn.fr_fid.fp_fid, lport->port_id);
  146. put_unaligned_be64(lport->wwnn, &ct->payload.rn.fr_wwn);
  147. break;
  148. case FC_NS_RSPN_ID:
  149. len = strnlen(fc_host_symbolic_name(lport->host), 255);
  150. ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rspn) + len,
  151. FC_FST_DIR, FC_NS_SUBTYPE);
  152. hton24(ct->payload.spn.fr_fid.fp_fid, lport->port_id);
  153. strncpy(ct->payload.spn.fr_name,
  154. fc_host_symbolic_name(lport->host), len);
  155. ct->payload.spn.fr_name_len = len;
  156. break;
  157. case FC_NS_RSNN_NN:
  158. len = strnlen(fc_host_symbolic_name(lport->host), 255);
  159. ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rsnn) + len,
  160. FC_FST_DIR, FC_NS_SUBTYPE);
  161. put_unaligned_be64(lport->wwnn, &ct->payload.snn.fr_wwn);
  162. strncpy(ct->payload.snn.fr_name,
  163. fc_host_symbolic_name(lport->host), len);
  164. ct->payload.snn.fr_name_len = len;
  165. break;
  166. default:
  167. return -EINVAL;
  168. }
  169. *r_ctl = FC_RCTL_DD_UNSOL_CTL;
  170. *fh_type = FC_TYPE_CT;
  171. return 0;
  172. }
  173. /**
  174. * fc_ct_ms_fill() - Fill in a mgmt service request frame
  175. * @lport: local port.
  176. * @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries.
  177. * @fp: frame to contain payload.
  178. * @op: CT opcode.
  179. * @r_ctl: pointer to FC header R_CTL.
  180. * @fh_type: pointer to FC-4 type.
  181. */
  182. static inline int fc_ct_ms_fill(struct fc_lport *lport,
  183. u32 fc_id, struct fc_frame *fp,
  184. unsigned int op, enum fc_rctl *r_ctl,
  185. enum fc_fh_type *fh_type)
  186. {
  187. struct fc_ct_req *ct;
  188. size_t len;
  189. struct fc_fdmi_attr_entry *entry;
  190. struct fs_fdmi_attrs *hba_attrs;
  191. int numattrs = 0;
  192. switch (op) {
  193. case FC_FDMI_RHBA:
  194. numattrs = 10;
  195. len = sizeof(struct fc_fdmi_rhba);
  196. len -= sizeof(struct fc_fdmi_attr_entry);
  197. len += (numattrs * FC_FDMI_ATTR_ENTRY_HEADER_LEN);
  198. len += FC_FDMI_HBA_ATTR_NODENAME_LEN;
  199. len += FC_FDMI_HBA_ATTR_MANUFACTURER_LEN;
  200. len += FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN;
  201. len += FC_FDMI_HBA_ATTR_MODEL_LEN;
  202. len += FC_FDMI_HBA_ATTR_MODELDESCR_LEN;
  203. len += FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN;
  204. len += FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN;
  205. len += FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN;
  206. len += FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN;
  207. len += FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN;
  208. ct = fc_ct_hdr_fill(fp, op, len, FC_FST_MGMT,
  209. FC_FDMI_SUBTYPE);
  210. /* HBA Identifier */
  211. put_unaligned_be64(lport->wwpn, &ct->payload.rhba.hbaid.id);
  212. /* Number of Ports - always 1 */
  213. put_unaligned_be32(1, &ct->payload.rhba.port.numport);
  214. /* Port Name */
  215. put_unaligned_be64(lport->wwpn,
  216. &ct->payload.rhba.port.port[0].portname);
  217. /* HBA Attributes */
  218. put_unaligned_be32(numattrs,
  219. &ct->payload.rhba.hba_attrs.numattrs);
  220. hba_attrs = &ct->payload.rhba.hba_attrs;
  221. entry = (struct fc_fdmi_attr_entry *)hba_attrs->attr;
  222. /* NodeName*/
  223. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  224. len += FC_FDMI_HBA_ATTR_NODENAME_LEN;
  225. put_unaligned_be16(FC_FDMI_HBA_ATTR_NODENAME,
  226. &entry->type);
  227. put_unaligned_be16(len, &entry->len);
  228. put_unaligned_be64(lport->wwnn,
  229. (__be64 *)&entry->value[0]);
  230. /* Manufacturer */
  231. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  232. FC_FDMI_HBA_ATTR_NODENAME_LEN);
  233. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  234. len += FC_FDMI_HBA_ATTR_MANUFACTURER_LEN;
  235. put_unaligned_be16(FC_FDMI_HBA_ATTR_MANUFACTURER,
  236. &entry->type);
  237. put_unaligned_be16(len, &entry->len);
  238. strncpy((char *)&entry->value,
  239. fc_host_manufacturer(lport->host),
  240. FC_FDMI_HBA_ATTR_MANUFACTURER_LEN);
  241. /* SerialNumber */
  242. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  243. FC_FDMI_HBA_ATTR_MANUFACTURER_LEN);
  244. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  245. len += FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN;
  246. put_unaligned_be16(FC_FDMI_HBA_ATTR_SERIALNUMBER,
  247. &entry->type);
  248. put_unaligned_be16(len, &entry->len);
  249. strncpy((char *)&entry->value,
  250. fc_host_serial_number(lport->host),
  251. FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN);
  252. /* Model */
  253. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  254. FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN);
  255. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  256. len += FC_FDMI_HBA_ATTR_MODEL_LEN;
  257. put_unaligned_be16(FC_FDMI_HBA_ATTR_MODEL,
  258. &entry->type);
  259. put_unaligned_be16(len, &entry->len);
  260. strncpy((char *)&entry->value,
  261. fc_host_model(lport->host),
  262. FC_FDMI_HBA_ATTR_MODEL_LEN);
  263. /* Model Description */
  264. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  265. FC_FDMI_HBA_ATTR_MODEL_LEN);
  266. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  267. len += FC_FDMI_HBA_ATTR_MODELDESCR_LEN;
  268. put_unaligned_be16(FC_FDMI_HBA_ATTR_MODELDESCRIPTION,
  269. &entry->type);
  270. put_unaligned_be16(len, &entry->len);
  271. strncpy((char *)&entry->value,
  272. fc_host_model_description(lport->host),
  273. FC_FDMI_HBA_ATTR_MODELDESCR_LEN);
  274. /* Hardware Version */
  275. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  276. FC_FDMI_HBA_ATTR_MODELDESCR_LEN);
  277. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  278. len += FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN;
  279. put_unaligned_be16(FC_FDMI_HBA_ATTR_HARDWAREVERSION,
  280. &entry->type);
  281. put_unaligned_be16(len, &entry->len);
  282. strncpy((char *)&entry->value,
  283. fc_host_hardware_version(lport->host),
  284. FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN);
  285. /* Driver Version */
  286. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  287. FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN);
  288. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  289. len += FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN;
  290. put_unaligned_be16(FC_FDMI_HBA_ATTR_DRIVERVERSION,
  291. &entry->type);
  292. put_unaligned_be16(len, &entry->len);
  293. strncpy((char *)&entry->value,
  294. fc_host_driver_version(lport->host),
  295. FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN);
  296. /* OptionROM Version */
  297. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  298. FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN);
  299. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  300. len += FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN;
  301. put_unaligned_be16(FC_FDMI_HBA_ATTR_OPTIONROMVERSION,
  302. &entry->type);
  303. put_unaligned_be16(len, &entry->len);
  304. strncpy((char *)&entry->value,
  305. fc_host_optionrom_version(lport->host),
  306. FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN);
  307. /* Firmware Version */
  308. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  309. FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN);
  310. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  311. len += FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN;
  312. put_unaligned_be16(FC_FDMI_HBA_ATTR_FIRMWAREVERSION,
  313. &entry->type);
  314. put_unaligned_be16(len, &entry->len);
  315. strncpy((char *)&entry->value,
  316. fc_host_firmware_version(lport->host),
  317. FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN);
  318. /* OS Name and Version */
  319. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  320. FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN);
  321. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  322. len += FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN;
  323. put_unaligned_be16(FC_FDMI_HBA_ATTR_OSNAMEVERSION,
  324. &entry->type);
  325. put_unaligned_be16(len, &entry->len);
  326. snprintf((char *)&entry->value,
  327. FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN,
  328. "%s v%s",
  329. init_utsname()->sysname,
  330. init_utsname()->release);
  331. break;
  332. case FC_FDMI_RPA:
  333. numattrs = 6;
  334. len = sizeof(struct fc_fdmi_rpa);
  335. len -= sizeof(struct fc_fdmi_attr_entry);
  336. len += (numattrs * FC_FDMI_ATTR_ENTRY_HEADER_LEN);
  337. len += FC_FDMI_PORT_ATTR_FC4TYPES_LEN;
  338. len += FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN;
  339. len += FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN;
  340. len += FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN;
  341. len += FC_FDMI_PORT_ATTR_OSDEVICENAME_LEN;
  342. len += FC_FDMI_PORT_ATTR_HOSTNAME_LEN;
  343. ct = fc_ct_hdr_fill(fp, op, len, FC_FST_MGMT,
  344. FC_FDMI_SUBTYPE);
  345. /* Port Name */
  346. put_unaligned_be64(lport->wwpn,
  347. &ct->payload.rpa.port.portname);
  348. /* Port Attributes */
  349. put_unaligned_be32(numattrs,
  350. &ct->payload.rpa.hba_attrs.numattrs);
  351. hba_attrs = &ct->payload.rpa.hba_attrs;
  352. entry = (struct fc_fdmi_attr_entry *)hba_attrs->attr;
  353. /* FC4 types */
  354. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  355. len += FC_FDMI_PORT_ATTR_FC4TYPES_LEN;
  356. put_unaligned_be16(FC_FDMI_PORT_ATTR_FC4TYPES,
  357. &entry->type);
  358. put_unaligned_be16(len, &entry->len);
  359. memcpy(&entry->value, fc_host_supported_fc4s(lport->host),
  360. FC_FDMI_PORT_ATTR_FC4TYPES_LEN);
  361. /* Supported Speed */
  362. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  363. FC_FDMI_PORT_ATTR_FC4TYPES_LEN);
  364. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  365. len += FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN;
  366. put_unaligned_be16(FC_FDMI_PORT_ATTR_SUPPORTEDSPEED,
  367. &entry->type);
  368. put_unaligned_be16(len, &entry->len);
  369. put_unaligned_be32(fc_host_supported_speeds(lport->host),
  370. &entry->value);
  371. /* Current Port Speed */
  372. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  373. FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN);
  374. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  375. len += FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN;
  376. put_unaligned_be16(FC_FDMI_PORT_ATTR_CURRENTPORTSPEED,
  377. &entry->type);
  378. put_unaligned_be16(len, &entry->len);
  379. put_unaligned_be32(lport->link_speed,
  380. &entry->value);
  381. /* Max Frame Size */
  382. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  383. FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN);
  384. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  385. len += FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN;
  386. put_unaligned_be16(FC_FDMI_PORT_ATTR_MAXFRAMESIZE,
  387. &entry->type);
  388. put_unaligned_be16(len, &entry->len);
  389. put_unaligned_be32(fc_host_maxframe_size(lport->host),
  390. &entry->value);
  391. /* OS Device Name */
  392. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  393. FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN);
  394. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  395. len += FC_FDMI_PORT_ATTR_OSDEVICENAME_LEN;
  396. put_unaligned_be16(FC_FDMI_PORT_ATTR_OSDEVICENAME,
  397. &entry->type);
  398. put_unaligned_be16(len, &entry->len);
  399. /* Use the sysfs device name */
  400. strncpy((char *)&entry->value,
  401. dev_name(&lport->host->shost_gendev),
  402. strnlen(dev_name(&lport->host->shost_gendev),
  403. FC_FDMI_PORT_ATTR_HOSTNAME_LEN));
  404. /* Host Name */
  405. entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
  406. FC_FDMI_PORT_ATTR_OSDEVICENAME_LEN);
  407. len = FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  408. len += FC_FDMI_PORT_ATTR_HOSTNAME_LEN;
  409. put_unaligned_be16(FC_FDMI_PORT_ATTR_HOSTNAME,
  410. &entry->type);
  411. put_unaligned_be16(len, &entry->len);
  412. if (strlen(fc_host_system_hostname(lport->host)))
  413. strncpy((char *)&entry->value,
  414. fc_host_system_hostname(lport->host),
  415. strnlen(fc_host_system_hostname(lport->host),
  416. FC_FDMI_PORT_ATTR_HOSTNAME_LEN));
  417. else
  418. strncpy((char *)&entry->value,
  419. init_utsname()->nodename,
  420. FC_FDMI_PORT_ATTR_HOSTNAME_LEN);
  421. break;
  422. case FC_FDMI_DPRT:
  423. len = sizeof(struct fc_fdmi_dprt);
  424. ct = fc_ct_hdr_fill(fp, op, len, FC_FST_MGMT,
  425. FC_FDMI_SUBTYPE);
  426. /* Port Name */
  427. put_unaligned_be64(lport->wwpn,
  428. &ct->payload.dprt.port.portname);
  429. break;
  430. case FC_FDMI_DHBA:
  431. len = sizeof(struct fc_fdmi_dhba);
  432. ct = fc_ct_hdr_fill(fp, op, len, FC_FST_MGMT,
  433. FC_FDMI_SUBTYPE);
  434. /* HBA Identifier */
  435. put_unaligned_be64(lport->wwpn, &ct->payload.dhba.hbaid.id);
  436. break;
  437. default:
  438. return -EINVAL;
  439. }
  440. *r_ctl = FC_RCTL_DD_UNSOL_CTL;
  441. *fh_type = FC_TYPE_CT;
  442. return 0;
  443. }
  444. /**
  445. * fc_ct_fill() - Fill in a common transport service request frame
  446. * @lport: local port.
  447. * @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries.
  448. * @fp: frame to contain payload.
  449. * @op: CT opcode.
  450. * @r_ctl: pointer to FC header R_CTL.
  451. * @fh_type: pointer to FC-4 type.
  452. */
  453. static inline int fc_ct_fill(struct fc_lport *lport,
  454. u32 fc_id, struct fc_frame *fp,
  455. unsigned int op, enum fc_rctl *r_ctl,
  456. enum fc_fh_type *fh_type, u32 *did)
  457. {
  458. int rc = -EINVAL;
  459. switch (fc_id) {
  460. case FC_FID_MGMT_SERV:
  461. rc = fc_ct_ms_fill(lport, fc_id, fp, op, r_ctl, fh_type);
  462. *did = FC_FID_MGMT_SERV;
  463. break;
  464. case FC_FID_DIR_SERV:
  465. default:
  466. rc = fc_ct_ns_fill(lport, fc_id, fp, op, r_ctl, fh_type);
  467. *did = FC_FID_DIR_SERV;
  468. break;
  469. }
  470. return rc;
  471. }
  472. /**
  473. * fc_plogi_fill - Fill in plogi request frame
  474. */
  475. static inline void fc_plogi_fill(struct fc_lport *lport, struct fc_frame *fp,
  476. unsigned int op)
  477. {
  478. struct fc_els_flogi *plogi;
  479. struct fc_els_csp *csp;
  480. struct fc_els_cssp *cp;
  481. plogi = fc_frame_payload_get(fp, sizeof(*plogi));
  482. memset(plogi, 0, sizeof(*plogi));
  483. plogi->fl_cmd = (u8) op;
  484. put_unaligned_be64(lport->wwpn, &plogi->fl_wwpn);
  485. put_unaligned_be64(lport->wwnn, &plogi->fl_wwnn);
  486. csp = &plogi->fl_csp;
  487. csp->sp_hi_ver = 0x20;
  488. csp->sp_lo_ver = 0x20;
  489. csp->sp_bb_cred = htons(10); /* this gets set by gateway */
  490. csp->sp_bb_data = htons((u16) lport->mfs);
  491. cp = &plogi->fl_cssp[3 - 1]; /* class 3 parameters */
  492. cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
  493. csp->sp_features = htons(FC_SP_FT_CIRO);
  494. csp->sp_tot_seq = htons(255); /* seq. we accept */
  495. csp->sp_rel_off = htons(0x1f);
  496. csp->sp_e_d_tov = htonl(lport->e_d_tov);
  497. cp->cp_rdfs = htons((u16) lport->mfs);
  498. cp->cp_con_seq = htons(255);
  499. cp->cp_open_seq = 1;
  500. }
  501. /**
  502. * fc_flogi_fill - Fill in a flogi request frame.
  503. */
  504. static inline void fc_flogi_fill(struct fc_lport *lport, struct fc_frame *fp)
  505. {
  506. struct fc_els_csp *sp;
  507. struct fc_els_cssp *cp;
  508. struct fc_els_flogi *flogi;
  509. flogi = fc_frame_payload_get(fp, sizeof(*flogi));
  510. memset(flogi, 0, sizeof(*flogi));
  511. flogi->fl_cmd = (u8) ELS_FLOGI;
  512. put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn);
  513. put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn);
  514. sp = &flogi->fl_csp;
  515. sp->sp_hi_ver = 0x20;
  516. sp->sp_lo_ver = 0x20;
  517. sp->sp_bb_cred = htons(10); /* this gets set by gateway */
  518. sp->sp_bb_data = htons((u16) lport->mfs);
  519. cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */
  520. cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
  521. if (lport->does_npiv)
  522. sp->sp_features = htons(FC_SP_FT_NPIV);
  523. }
  524. /**
  525. * fc_fdisc_fill - Fill in a fdisc request frame.
  526. */
  527. static inline void fc_fdisc_fill(struct fc_lport *lport, struct fc_frame *fp)
  528. {
  529. struct fc_els_csp *sp;
  530. struct fc_els_cssp *cp;
  531. struct fc_els_flogi *fdisc;
  532. fdisc = fc_frame_payload_get(fp, sizeof(*fdisc));
  533. memset(fdisc, 0, sizeof(*fdisc));
  534. fdisc->fl_cmd = (u8) ELS_FDISC;
  535. put_unaligned_be64(lport->wwpn, &fdisc->fl_wwpn);
  536. put_unaligned_be64(lport->wwnn, &fdisc->fl_wwnn);
  537. sp = &fdisc->fl_csp;
  538. sp->sp_hi_ver = 0x20;
  539. sp->sp_lo_ver = 0x20;
  540. sp->sp_bb_cred = htons(10); /* this gets set by gateway */
  541. sp->sp_bb_data = htons((u16) lport->mfs);
  542. cp = &fdisc->fl_cssp[3 - 1]; /* class 3 parameters */
  543. cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
  544. }
  545. /**
  546. * fc_logo_fill - Fill in a logo request frame.
  547. */
  548. static inline void fc_logo_fill(struct fc_lport *lport, struct fc_frame *fp)
  549. {
  550. struct fc_els_logo *logo;
  551. logo = fc_frame_payload_get(fp, sizeof(*logo));
  552. memset(logo, 0, sizeof(*logo));
  553. logo->fl_cmd = ELS_LOGO;
  554. hton24(logo->fl_n_port_id, lport->port_id);
  555. logo->fl_n_port_wwn = htonll(lport->wwpn);
  556. }
  557. /**
  558. * fc_rtv_fill - Fill in RTV (read timeout value) request frame.
  559. */
  560. static inline void fc_rtv_fill(struct fc_lport *lport, struct fc_frame *fp)
  561. {
  562. struct fc_els_rtv *rtv;
  563. rtv = fc_frame_payload_get(fp, sizeof(*rtv));
  564. memset(rtv, 0, sizeof(*rtv));
  565. rtv->rtv_cmd = ELS_RTV;
  566. }
  567. /**
  568. * fc_rec_fill - Fill in rec request frame
  569. */
  570. static inline void fc_rec_fill(struct fc_lport *lport, struct fc_frame *fp)
  571. {
  572. struct fc_els_rec *rec;
  573. struct fc_exch *ep = fc_seq_exch(fr_seq(fp));
  574. rec = fc_frame_payload_get(fp, sizeof(*rec));
  575. memset(rec, 0, sizeof(*rec));
  576. rec->rec_cmd = ELS_REC;
  577. hton24(rec->rec_s_id, lport->port_id);
  578. rec->rec_ox_id = htons(ep->oxid);
  579. rec->rec_rx_id = htons(ep->rxid);
  580. }
  581. /**
  582. * fc_prli_fill - Fill in prli request frame
  583. */
  584. static inline void fc_prli_fill(struct fc_lport *lport, struct fc_frame *fp)
  585. {
  586. struct {
  587. struct fc_els_prli prli;
  588. struct fc_els_spp spp;
  589. } *pp;
  590. pp = fc_frame_payload_get(fp, sizeof(*pp));
  591. memset(pp, 0, sizeof(*pp));
  592. pp->prli.prli_cmd = ELS_PRLI;
  593. pp->prli.prli_spp_len = sizeof(struct fc_els_spp);
  594. pp->prli.prli_len = htons(sizeof(*pp));
  595. pp->spp.spp_type = FC_TYPE_FCP;
  596. pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR;
  597. pp->spp.spp_params = htonl(lport->service_params);
  598. }
  599. /**
  600. * fc_scr_fill - Fill in a scr request frame.
  601. */
  602. static inline void fc_scr_fill(struct fc_lport *lport, struct fc_frame *fp)
  603. {
  604. struct fc_els_scr *scr;
  605. scr = fc_frame_payload_get(fp, sizeof(*scr));
  606. memset(scr, 0, sizeof(*scr));
  607. scr->scr_cmd = ELS_SCR;
  608. scr->scr_reg_func = ELS_SCRF_FULL;
  609. }
  610. /**
  611. * fc_els_fill - Fill in an ELS request frame
  612. */
  613. static inline int fc_els_fill(struct fc_lport *lport,
  614. u32 did,
  615. struct fc_frame *fp, unsigned int op,
  616. enum fc_rctl *r_ctl, enum fc_fh_type *fh_type)
  617. {
  618. switch (op) {
  619. case ELS_ADISC:
  620. fc_adisc_fill(lport, fp);
  621. break;
  622. case ELS_PLOGI:
  623. fc_plogi_fill(lport, fp, ELS_PLOGI);
  624. break;
  625. case ELS_FLOGI:
  626. fc_flogi_fill(lport, fp);
  627. break;
  628. case ELS_FDISC:
  629. fc_fdisc_fill(lport, fp);
  630. break;
  631. case ELS_LOGO:
  632. fc_logo_fill(lport, fp);
  633. break;
  634. case ELS_RTV:
  635. fc_rtv_fill(lport, fp);
  636. break;
  637. case ELS_REC:
  638. fc_rec_fill(lport, fp);
  639. break;
  640. case ELS_PRLI:
  641. fc_prli_fill(lport, fp);
  642. break;
  643. case ELS_SCR:
  644. fc_scr_fill(lport, fp);
  645. break;
  646. default:
  647. return -EINVAL;
  648. }
  649. *r_ctl = FC_RCTL_ELS_REQ;
  650. *fh_type = FC_TYPE_ELS;
  651. return 0;
  652. }
  653. #endif /* _FC_ENCODE_H_ */