Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. #ifndef _IPXE_FIP_H
  2. #define _IPXE_FIP_H
  3. /*
  4. * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of the
  9. * License, or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. * 02110-1301, USA.
  20. */
  21. #include <stdint.h>
  22. #include <ipxe/fc.h>
  23. #include <ipxe/fcels.h>
  24. #include <ipxe/fcoe.h>
  25. /** A FIP frame header */
  26. struct fip_header {
  27. /** Frame version */
  28. uint8_t version;
  29. /** Reserved */
  30. uint8_t reserved_a;
  31. /** Protocol code */
  32. uint16_t code;
  33. /** Reserved */
  34. uint8_t reserved_b;
  35. /** Subcode */
  36. uint8_t subcode;
  37. /** Descriptor list length in 32-bit words */
  38. uint16_t len;
  39. /** Flags */
  40. uint16_t flags;
  41. } __attribute__ (( packed ));
  42. /** FIP frame version */
  43. #define FIP_VERSION 0x10
  44. /** FIP protocol code */
  45. enum fip_code {
  46. FIP_CODE_DISCOVERY = 0x0001, /**< Discovery */
  47. FIP_CODE_ELS = 0x0002, /**< Extended link services */
  48. FIP_CODE_MAINTAIN = 0x0003, /**< Maintain virtual links */
  49. FIP_CODE_VLAN = 0x0004, /**< VLAN */
  50. };
  51. /** FIP protocol subcode for discovery */
  52. enum fip_discovery_subcode {
  53. FIP_DISCOVERY_SOLICIT = 0x01, /**< Discovery solicitation */
  54. FIP_DISCOVERY_ADVERTISE = 0x02, /**< Discovery advertisement */
  55. };
  56. /** FIP protocol subcode for extended link services */
  57. enum fip_els_subcode {
  58. FIP_ELS_REQUEST = 0x01, /**< ELS request */
  59. FIP_ELS_RESPONSE = 0x02, /**< ELS response */
  60. };
  61. /** FIP protocol subcode for keep alive / clear links */
  62. enum fip_vitality_subcode {
  63. FIP_MAINTAIN_KEEP_ALIVE = 0x01, /**< Keep alive */
  64. FIP_MAINTAIN_CLEAR_LINKS = 0x02,/**< Clear virtual links */
  65. };
  66. /** FIP protocol subcode for VLAN */
  67. enum fip_vlan_subcode {
  68. FIP_VLAN_REQUEST = 0x01, /**< VLAN request */
  69. FIP_VLAN_NOTIFY = 0x02, /**< VLAN notification */
  70. };
  71. /** FIP flags */
  72. enum fip_flags {
  73. FIP_FP = 0x8000, /**< Fabric-provided MAC address */
  74. FIP_SP = 0x4000, /**< Server-provided MAC address */
  75. FIP_A = 0x0004, /**< Available for login */
  76. FIP_S = 0x0002, /**< Solicited */
  77. FIP_F = 0x0001, /**< Forwarder */
  78. };
  79. /** FIP descriptor common fields */
  80. struct fip_common {
  81. /** Type */
  82. uint8_t type;
  83. /** Length in 32-bit words */
  84. uint8_t len;
  85. /** Reserved */
  86. uint8_t reserved[2];
  87. } __attribute__ (( packed ));
  88. /** FIP descriptor types */
  89. enum fip_type {
  90. FIP_RESERVED = 0x00, /**< Reserved */
  91. FIP_PRIORITY = 0x01, /**< Priority */
  92. FIP_MAC_ADDRESS = 0x02, /**< MAC address */
  93. FIP_FC_MAP = 0x03, /**< FC-MAP */
  94. FIP_NAME_ID = 0x04, /**< Name identifier */
  95. FIP_FABRIC = 0x05, /**< Fabric */
  96. FIP_MAX_FCOE_SIZE = 0x06, /**< Max FCoE size */
  97. FIP_FLOGI = 0x07, /**< FLOGI */
  98. FIP_NPIV_FDISC = 0x08, /**< NPIV FDISC */
  99. FIP_LOGO = 0x09, /**< LOGO */
  100. FIP_ELP = 0x0a, /**< ELP */
  101. FIP_VX_PORT_ID = 0x0b, /**< Vx port identification */
  102. FIP_FKA_ADV_P = 0x0c, /**< FKA ADV period */
  103. FIP_VENDOR_ID = 0x0d, /**< Vendor ID */
  104. FIP_VLAN = 0x0e, /**< VLAN */
  105. FIP_NUM_DESCRIPTOR_TYPES
  106. };
  107. /** FIP descriptor type is critical */
  108. #define FIP_IS_CRITICAL( type ) ( (type) <= 0x7f )
  109. /** A FIP priority descriptor */
  110. struct fip_priority {
  111. /** Type */
  112. uint8_t type;
  113. /** Length in 32-bit words */
  114. uint8_t len;
  115. /** Reserved */
  116. uint8_t reserved;
  117. /** Priority
  118. *
  119. * A higher value indicates a lower priority.
  120. */
  121. uint8_t priority;
  122. } __attribute__ (( packed ));
  123. /** Default FIP priority */
  124. #define FIP_DEFAULT_PRIORITY 128
  125. /** Lowest FIP priority */
  126. #define FIP_LOWEST_PRIORITY 255
  127. /** A FIP MAC address descriptor */
  128. struct fip_mac_address {
  129. /** Type */
  130. uint8_t type;
  131. /** Length in 32-bit words */
  132. uint8_t len;
  133. /** MAC address */
  134. uint8_t mac[ETH_ALEN];
  135. } __attribute__ (( packed ));
  136. /** A FIP FC-MAP descriptor */
  137. struct fip_fc_map {
  138. /** Type */
  139. uint8_t type;
  140. /** Length in 32-bit words */
  141. uint8_t len;
  142. /** Reserved */
  143. uint8_t reserved[3];
  144. /** FC-MAP */
  145. struct fcoe_map map;
  146. } __attribute__ (( packed ));
  147. /** A FIP name identifier descriptor */
  148. struct fip_name_id {
  149. /** Type */
  150. uint8_t type;
  151. /** Length in 32-bit words */
  152. uint8_t len;
  153. /** Reserved */
  154. uint8_t reserved[2];
  155. /** Name identifier */
  156. struct fc_name name;
  157. } __attribute__ (( packed ));
  158. /** A FIP fabric descriptor */
  159. struct fip_fabric {
  160. /** Type */
  161. uint8_t type;
  162. /** Length in 32-bit words */
  163. uint8_t len;
  164. /** Virtual Fabric ID, if any */
  165. uint16_t vf_id;
  166. /** Reserved */
  167. uint8_t reserved;
  168. /** FC-MAP */
  169. struct fcoe_map map;
  170. /** Fabric name */
  171. struct fc_name name;
  172. } __attribute__ (( packed ));
  173. /** A FIP max FCoE size descriptor */
  174. struct fip_max_fcoe_size {
  175. /** Type */
  176. uint8_t type;
  177. /** Length in 32-bit words */
  178. uint8_t len;
  179. /** Maximum FCoE size */
  180. uint16_t mtu;
  181. } __attribute__ (( packed ));
  182. /** A FIP descriptor containing an encapsulated ELS frame */
  183. struct fip_els {
  184. /** Type */
  185. uint8_t type;
  186. /** Length in 32-bit words */
  187. uint8_t len;
  188. /** Reserved */
  189. uint8_t reserved[2];
  190. /** Fibre Channel frame header */
  191. struct fc_frame_header fc;
  192. /** ELS frame */
  193. struct fc_els_frame_common els;
  194. } __attribute__ (( packed ));
  195. /** A FIP descriptor containing an encapsulated login frame */
  196. struct fip_login {
  197. /** Type */
  198. uint8_t type;
  199. /** Length in 32-bit words */
  200. uint8_t len;
  201. /** Reserved */
  202. uint8_t reserved[2];
  203. /** Fibre Channel frame header */
  204. struct fc_frame_header fc;
  205. /** ELS frame */
  206. struct fc_login_frame els;
  207. } __attribute__ (( packed ));
  208. /** A FIP descriptor containing an encapsulated LOGO request frame */
  209. struct fip_logo_request {
  210. /** Type */
  211. uint8_t type;
  212. /** Length in 32-bit words */
  213. uint8_t len;
  214. /** Reserved */
  215. uint8_t reserved[2];
  216. /** Fibre Channel frame header */
  217. struct fc_frame_header fc;
  218. /** ELS frame */
  219. struct fc_logout_request_frame els;
  220. } __attribute__ (( packed ));
  221. /** A FIP descriptor containing an encapsulated LOGO response frame */
  222. struct fip_logo_response {
  223. /** Type */
  224. uint8_t type;
  225. /** Length in 32-bit words */
  226. uint8_t len;
  227. /** Reserved */
  228. uint8_t reserved[2];
  229. /** Fibre Channel frame header */
  230. struct fc_frame_header fc;
  231. /** ELS frame */
  232. struct fc_logout_response_frame els;
  233. } __attribute__ (( packed ));
  234. /** A FIP descriptor containing an encapsulated ELP frame */
  235. struct fip_elp {
  236. /** Type */
  237. uint8_t type;
  238. /** Length in 32-bit words */
  239. uint8_t len;
  240. /** Reserved */
  241. uint8_t reserved[2];
  242. /** Fibre Channel frame header */
  243. struct fc_frame_header fc;
  244. /** ELS frame */
  245. struct fc_els_frame_common els;
  246. /** Uninteresting content */
  247. uint32_t dull[25];
  248. } __attribute__ (( packed ));
  249. /** A FIP descriptor containing an encapsulated LS_RJT frame */
  250. struct fip_ls_rjt {
  251. /** Type */
  252. uint8_t type;
  253. /** Length in 32-bit words */
  254. uint8_t len;
  255. /** Reserved */
  256. uint8_t reserved[2];
  257. /** Fibre Channel frame header */
  258. struct fc_frame_header fc;
  259. /** ELS frame */
  260. struct fc_ls_rjt_frame els;
  261. } __attribute__ (( packed ));
  262. /** A FIP Vx port identification descriptor */
  263. struct fip_vx_port_id {
  264. /** Type */
  265. uint8_t type;
  266. /** Length in 32-bit words */
  267. uint8_t len;
  268. /** MAC address */
  269. uint8_t mac[ETH_ALEN];
  270. /** Reserved */
  271. uint8_t reserved;
  272. /** Address identifier */
  273. struct fc_port_id id;
  274. /** Port name */
  275. struct fc_name name;
  276. } __attribute__ (( packed ));
  277. /** A FIP FKA ADV period descriptor */
  278. struct fip_fka_adv_p {
  279. /** Type */
  280. uint8_t type;
  281. /** Length in 32-bit words */
  282. uint8_t len;
  283. /** Reserved */
  284. uint8_t reserved;
  285. /** Flags */
  286. uint8_t flags;
  287. /** Keep alive advertisement period in milliseconds */
  288. uint32_t period;
  289. } __attribute__ (( packed ));
  290. /** FIP FKA ADV period flags */
  291. enum fip_fka_adv_p_flags {
  292. FIP_NO_KEEPALIVE = 0x01, /**< Do not send keepalives */
  293. };
  294. /** A FIP vendor ID descriptor */
  295. struct fip_vendor_id {
  296. /** Type */
  297. uint8_t type;
  298. /** Length in 32-bit words */
  299. uint8_t len;
  300. /** Reserved */
  301. uint8_t reserved[2];
  302. /** Vendor ID */
  303. uint8_t vendor[8];
  304. } __attribute__ (( packed ));
  305. /** A FIP VLAN descriptor */
  306. struct fip_vlan {
  307. /** Type */
  308. uint8_t type;
  309. /** Length in 32-bit words */
  310. uint8_t len;
  311. /** VLAN ID */
  312. uint16_t vlan;
  313. } __attribute__ (( packed ));
  314. /** A FIP descriptor */
  315. union fip_descriptor {
  316. /** Common fields */
  317. struct fip_common common;
  318. /** Priority descriptor */
  319. struct fip_priority priority;
  320. /** MAC address descriptor */
  321. struct fip_mac_address mac_address;
  322. /** FC-MAP descriptor */
  323. struct fip_fc_map fc_map;
  324. /** Name identifier descriptor */
  325. struct fip_name_id name_id;
  326. /** Fabric descriptor */
  327. struct fip_fabric fabric;
  328. /** Max FCoE size descriptor */
  329. struct fip_max_fcoe_size max_fcoe_size;
  330. /** FLOGI descriptor */
  331. struct fip_els flogi;
  332. /** FLOGI request descriptor */
  333. struct fip_login flogi_request;
  334. /** FLOGI LS_ACC descriptor */
  335. struct fip_login flogi_ls_acc;
  336. /** FLOGI LS_RJT descriptor */
  337. struct fip_ls_rjt flogi_ls_rjt;
  338. /** NPIV FDISC descriptor */
  339. struct fip_els npiv_fdisc;
  340. /** NPIV FDISC request descriptor */
  341. struct fip_login npiv_fdisc_request;
  342. /** NPIV FDISC LS_ACC descriptor */
  343. struct fip_login npiv_fdisc_ls_acc;
  344. /** NPIV FDISC LS_RJT descriptor */
  345. struct fip_ls_rjt npiv_fdisc_ls_rjt;
  346. /** LOGO descriptor */
  347. struct fip_els logo;
  348. /** LOGO request descriptor */
  349. struct fip_logo_request logo_request;
  350. /** LOGO LS_ACC descriptor */
  351. struct fip_logo_response logo_ls_acc;
  352. /** LOGO LS_RJT descriptor */
  353. struct fip_ls_rjt logo_ls_rjt;
  354. /** ELS descriptor */
  355. struct fip_els elp;
  356. /** ELP request descriptor */
  357. struct fip_elp elp_request;
  358. /** ELP LS_ACC descriptor */
  359. struct fip_elp elp_ls_acc;
  360. /** ELP LS_RJT descriptor */
  361. struct fip_ls_rjt elp_ls_rjt;
  362. /** Vx port identification descriptor */
  363. struct fip_vx_port_id vx_port_id;
  364. /** FKA ADV period descriptor */
  365. struct fip_fka_adv_p fka_adv_p;
  366. /** Vendor ID descriptor */
  367. struct fip_vendor_id vendor_id;
  368. /** VLAN descriptor */
  369. struct fip_vlan vlan;
  370. } __attribute__ (( packed ));
  371. /** A FIP descriptor set */
  372. struct fip_descriptors {
  373. /** Descriptors, indexed by type */
  374. union fip_descriptor *desc[FIP_NUM_DESCRIPTOR_TYPES];
  375. };
  376. /**
  377. * Define a function to extract a specific FIP descriptor type from a list
  378. *
  379. * @v type Descriptor type
  380. * @v name Descriptor name
  381. * @v finder Descriptor finder
  382. */
  383. #define FIP_DESCRIPTOR( type, name ) \
  384. static inline __attribute__ (( always_inline )) \
  385. typeof ( ( ( union fip_descriptor * ) NULL )->name ) * \
  386. fip_ ## name ( struct fip_descriptors *descs ) { \
  387. return &(descs->desc[type]->name); \
  388. }
  389. FIP_DESCRIPTOR ( FIP_PRIORITY, priority );
  390. FIP_DESCRIPTOR ( FIP_MAC_ADDRESS, mac_address );
  391. FIP_DESCRIPTOR ( FIP_FC_MAP, fc_map );
  392. FIP_DESCRIPTOR ( FIP_NAME_ID, name_id );
  393. FIP_DESCRIPTOR ( FIP_FABRIC, fabric );
  394. FIP_DESCRIPTOR ( FIP_MAX_FCOE_SIZE, max_fcoe_size );
  395. FIP_DESCRIPTOR ( FIP_FLOGI, flogi );
  396. FIP_DESCRIPTOR ( FIP_FLOGI, flogi_request );
  397. FIP_DESCRIPTOR ( FIP_FLOGI, flogi_ls_acc );
  398. FIP_DESCRIPTOR ( FIP_FLOGI, flogi_ls_rjt );
  399. FIP_DESCRIPTOR ( FIP_NPIV_FDISC, npiv_fdisc );
  400. FIP_DESCRIPTOR ( FIP_NPIV_FDISC, npiv_fdisc_request );
  401. FIP_DESCRIPTOR ( FIP_NPIV_FDISC, npiv_fdisc_ls_acc );
  402. FIP_DESCRIPTOR ( FIP_NPIV_FDISC, npiv_fdisc_ls_rjt );
  403. FIP_DESCRIPTOR ( FIP_LOGO, logo );
  404. FIP_DESCRIPTOR ( FIP_LOGO, logo_request );
  405. FIP_DESCRIPTOR ( FIP_LOGO, logo_ls_acc );
  406. FIP_DESCRIPTOR ( FIP_LOGO, logo_ls_rjt );
  407. FIP_DESCRIPTOR ( FIP_ELP, elp );
  408. FIP_DESCRIPTOR ( FIP_ELP, elp_request );
  409. FIP_DESCRIPTOR ( FIP_ELP, elp_ls_acc );
  410. FIP_DESCRIPTOR ( FIP_ELP, elp_ls_rjt );
  411. FIP_DESCRIPTOR ( FIP_VX_PORT_ID, vx_port_id );
  412. FIP_DESCRIPTOR ( FIP_FKA_ADV_P, fka_adv_p );
  413. FIP_DESCRIPTOR ( FIP_VENDOR_ID, vendor_id );
  414. FIP_DESCRIPTOR ( FIP_VLAN, vlan );
  415. #endif /* _IPXE_FIP_H */