fc_encode.h 22 KB

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