You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fcels.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. #ifndef _IPXE_FCELS_H
  2. #define _IPXE_FCELS_H
  3. /**
  4. * @file
  5. *
  6. * Fibre Channel Extended Link Services
  7. *
  8. */
  9. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  10. #include <stdint.h>
  11. #include <ipxe/fc.h>
  12. #include <ipxe/tables.h>
  13. #include <ipxe/refcnt.h>
  14. #include <ipxe/list.h>
  15. #include <ipxe/process.h>
  16. #include <ipxe/interface.h>
  17. /** Fibre Channel ELS frame common parameters */
  18. struct fc_els_frame_common {
  19. /** ELS command code */
  20. uint8_t command;
  21. /** Reserved */
  22. uint8_t reserved[3];
  23. } __attribute__ (( packed ));
  24. /** Fibre Channel ELS command codes */
  25. enum fc_els_command_code {
  26. FC_ELS_LS_RJT = 0x01, /**< Link Service Reject */
  27. FC_ELS_LS_ACC = 0x02, /**< Link Service Accept */
  28. FC_ELS_PLOGI = 0x03, /**< Port Login */
  29. FC_ELS_FLOGI = 0x04, /**< Fabric Login */
  30. FC_ELS_LOGO = 0x05, /**< Logout */
  31. FC_ELS_RTV = 0x0e, /**< Read Timeout Value */
  32. FC_ELS_ECHO = 0x10, /**< Echo */
  33. FC_ELS_PRLI = 0x20, /**< Process Login */
  34. FC_ELS_PRLO = 0x21, /**< Process Logout */
  35. };
  36. /** A Fibre Channel LS_RJT frame */
  37. struct fc_ls_rjt_frame {
  38. /** ELS command code */
  39. uint8_t command;
  40. /** Reserved */
  41. uint8_t reserved[4];
  42. /** Reason code */
  43. uint8_t reason;
  44. /** Reason code explanation */
  45. uint8_t explanation;
  46. /** Vendor unique */
  47. uint8_t vendor;
  48. } __attribute__ (( packed ));
  49. /** Fibre Channel ELS rejection reason codes */
  50. enum fc_els_reject_reason {
  51. /** Invalid ELS command code */
  52. FC_ELS_RJT_INVALID_COMMAND = 0x01,
  53. /** Logical error */
  54. FC_ELS_RJT_ILLOGICAL = 0x03,
  55. /** Logical busy */
  56. FC_ELS_RJT_BUSY = 0x05,
  57. /** Protocol error */
  58. FC_ELS_RJT_PROTOCOL = 0x07,
  59. /** Unable to perform command request */
  60. FC_ELS_RJT_UNABLE = 0x09,
  61. /** Command not supported */
  62. FC_ELS_RJT_UNSUPPORTED = 0x0b,
  63. /** Command already in progress */
  64. FC_ELS_RJT_IN_PROGRESS = 0x0e,
  65. };
  66. /** Fibre Channel "common" service parameters */
  67. struct fc_login_common {
  68. /** Login version */
  69. uint16_t version;
  70. /** Buffer-to-buffer credit */
  71. uint16_t credit;
  72. /** Flags */
  73. uint16_t flags;
  74. /** Receive size */
  75. uint16_t mtu;
  76. /** "Common"?! */
  77. union {
  78. struct {
  79. /** Maximum number of concurrent sequences */
  80. uint16_t max_seq;
  81. /** Relative offset by info category */
  82. uint16_t rel_offs;
  83. } plogi;
  84. struct {
  85. /** Resource allocation timeout value */
  86. uint32_t r_a_tov;
  87. } flogi;
  88. } u;
  89. /** Error detection timeout value */
  90. uint32_t e_d_tov;
  91. } __attribute__ (( packed ));
  92. /** Fibre Channel default login version */
  93. #define FC_LOGIN_VERSION 0x2020
  94. /** Fibre Channel default buffer-to-buffer credit */
  95. #define FC_LOGIN_DEFAULT_B2B 10
  96. /** Continuously increasing relative offset */
  97. #define FC_LOGIN_CONTINUOUS_OFFSET 0x8000
  98. /** Clean address */
  99. #define FC_LOGIN_CLEAN 0x8000
  100. /** Multiple N_Port_ID support */
  101. #define FC_LOGIN_MULTI_N 0x8000
  102. /** Random relative offset */
  103. #define FC_LOGIN_RANDOM_OFFSET 0x4000
  104. /** Virtual fabrics */
  105. #define FC_LOGIN_VIRTUAL 0x4000
  106. /** Vendor version level */
  107. #define FC_LOGIN_VENDOR 0x2000
  108. /** Multiple N_Port_ID support */
  109. #define FC_LOGIN_MULTI_F 0x2000
  110. /** Forwarder port */
  111. #define FC_LOGIN_F_PORT 0x1000
  112. /** Alternative credit management */
  113. #define FC_LOGIN_ALT_CREDIT 0x0800
  114. /** Name server session started */
  115. #define FC_LOGIN_NSS_STARTED 0x0800
  116. /** Begin name server session */
  117. #define FC_LOGIN_NSS_BEGIN 0x0400
  118. /** 1ns error detection timer resolution */
  119. #define FC_LOGIN_HIRES_E_D_TOV 0x0400
  120. /** Broadcast supported */
  121. #define FC_LOGIN_BROADCAST 0x0100
  122. /** Query buffer conditions */
  123. #define FC_LOGIN_QUERY_BUF 0x0040
  124. /** Security */
  125. #define FC_LOGIN_SECURITY 0x0020
  126. /** Clock sync primitive capable */
  127. #define FC_LOGIN_CLOCK_SYNC 0x0010
  128. /** Short R_T timeout */
  129. #define FC_LOGIN_SHORT_R_T_TOV 0x0008
  130. /** Dynamic half duplex */
  131. #define FC_LOGIN_DHD 0x0004
  132. /** Continuously increasing sequence count */
  133. #define FC_LOGIN_CONTINUOUS_SEQ 0x0002
  134. /** Payload */
  135. #define FC_LOGIN_PAYLOAD 0x0001
  136. /** Fibre Channel default MTU */
  137. #define FC_LOGIN_DEFAULT_MTU 1452
  138. /** Default maximum number of concurrent sequences */
  139. #define FC_LOGIN_DEFAULT_MAX_SEQ 255
  140. /** Default relative offset by info category */
  141. #define FC_LOGIN_DEFAULT_REL_OFFS 0x1f
  142. /** Default E_D timeout value */
  143. #define FC_LOGIN_DEFAULT_E_D_TOV 2000
  144. /** Fibre Channel class-specific login parameters */
  145. struct fc_login_class {
  146. /** Flags */
  147. uint16_t flags;
  148. /** Initiator flags */
  149. uint16_t init_flags;
  150. /** Recipient flags */
  151. uint16_t recip_flags;
  152. /** Receive data field size */
  153. uint16_t mtu;
  154. /** Maximum number of concurrent sequences */
  155. uint16_t max_seq;
  156. /** End-to-end credit */
  157. uint16_t credit;
  158. /** Reserved */
  159. uint8_t reserved0;
  160. /** Maximum number of open sequences per exchange */
  161. uint8_t max_seq_per_xchg;
  162. /** Reserved */
  163. uint8_t reserved1[2];
  164. } __attribute__ (( packed ));
  165. /** Class valid */
  166. #define FC_LOGIN_CLASS_VALID 0x8000
  167. /** Sequential delivery requested */
  168. #define FC_LOGIN_CLASS_SEQUENTIAL 0x0800
  169. /** A Fibre Channel FLOGI/PLOGI frame */
  170. struct fc_login_frame {
  171. /** ELS command code */
  172. uint8_t command;
  173. /** Reserved */
  174. uint8_t reserved[3];
  175. /** Common service parameters */
  176. struct fc_login_common common;
  177. /** Port name */
  178. struct fc_name port_wwn;
  179. /** Node name */
  180. struct fc_name node_wwn;
  181. /** Class 1 service parameters */
  182. struct fc_login_class class1;
  183. /** Class 2 service parameters */
  184. struct fc_login_class class2;
  185. /** Class 3 service parameters */
  186. struct fc_login_class class3;
  187. /** Class 4 service parameters */
  188. struct fc_login_class class4;
  189. /** Vendor version level */
  190. uint8_t vendor_version[16];
  191. } __attribute__ (( packed ));
  192. /** A Fibre Channel LOGO request frame */
  193. struct fc_logout_request_frame {
  194. /** ELS command code */
  195. uint8_t command;
  196. /** Reserved */
  197. uint8_t reserved[4];
  198. /** Port ID */
  199. struct fc_port_id port_id;
  200. /** Port name */
  201. struct fc_name port_wwn;
  202. } __attribute__ (( packed ));
  203. /** A Fibre Channel LOGO response frame */
  204. struct fc_logout_response_frame {
  205. /** ELS command code */
  206. uint8_t command;
  207. /** Reserved */
  208. uint8_t reserved[3];
  209. } __attribute__ (( packed ));
  210. /** A Fibre Channel PRLI service parameter page */
  211. struct fc_prli_page {
  212. /** Type code */
  213. uint8_t type;
  214. /** Type code extension */
  215. uint8_t type_ext;
  216. /** Flags and response code */
  217. uint16_t flags;
  218. /** Reserved */
  219. uint32_t reserved[2];
  220. } __attribute__ (( packed ));
  221. /** Establish image pair */
  222. #define FC_PRLI_ESTABLISH 0x2000
  223. /** Response code mask */
  224. #define FC_PRLI_RESPONSE_MASK 0x0f00
  225. /** Request was executed successfully */
  226. #define FC_PRLI_RESPONSE_SUCCESS 0x0100
  227. /** A Fibre Channel PRLI frame */
  228. struct fc_prli_frame {
  229. /** ELS command code */
  230. uint8_t command;
  231. /** Page length */
  232. uint8_t page_len;
  233. /** Payload length */
  234. uint16_t len;
  235. /** Service parameter page */
  236. struct fc_prli_page page;
  237. } __attribute__ (( packed ));
  238. /** A Fibre Channel RTV request frame */
  239. struct fc_rtv_request_frame {
  240. /** ELS command code */
  241. uint8_t command;
  242. /** Reserved */
  243. uint8_t reserved[3];
  244. } __attribute__ (( packed ));
  245. /** A Fibre Channel RTV response frame */
  246. struct fc_rtv_response_frame {
  247. /** ELS command code */
  248. uint8_t command;
  249. /** Reserved */
  250. uint8_t reserved0[3];
  251. /** Resource allocation timeout value */
  252. uint32_t r_a_tov;
  253. /** Error detection timeout value */
  254. uint32_t e_d_tov;
  255. /** Timeout qualifier */
  256. uint16_t flags;
  257. /** Reserved */
  258. uint16_t reserved1;
  259. } __attribute__ (( packed ));
  260. /** 1ns error detection timer resolution */
  261. #define FC_RTV_HIRES_E_D_TOV 0x0400
  262. /** Short R_T timeout */
  263. #define FC_RTV_SHORT_R_T_TOV 0x0008
  264. /** A Fibre Channel ECHO frame */
  265. struct fc_echo_frame_header {
  266. /** ELS command code */
  267. uint8_t command;
  268. /** Reserved */
  269. uint8_t reserved[3];
  270. } __attribute__ (( packed ));
  271. /** A Fibre Channel extended link services transaction */
  272. struct fc_els {
  273. /** Reference count */
  274. struct refcnt refcnt;
  275. /** Job control interface */
  276. struct interface job;
  277. /** Fibre Channel exchange */
  278. struct interface xchg;
  279. /** Request sending process */
  280. struct process process;
  281. /** Fibre Channel port */
  282. struct fc_port *port;
  283. /** Local port ID */
  284. struct fc_port_id port_id;
  285. /** Peer port ID */
  286. struct fc_port_id peer_port_id;
  287. /** ELS handler, if known */
  288. struct fc_els_handler *handler;
  289. /** Flags */
  290. unsigned int flags;
  291. };
  292. /** Fibre Channel extended link services transaction flags */
  293. enum fc_els_flags {
  294. /** ELS transaction is a request */
  295. FC_ELS_REQUEST = 0x0001,
  296. };
  297. /** A Fibre Channel extended link services handler */
  298. struct fc_els_handler {
  299. /** Name */
  300. const char *name;
  301. /** Transmit ELS frame
  302. *
  303. * @v els Fibre Channel ELS transaction
  304. * @ret rc Return status code
  305. */
  306. int ( * tx ) ( struct fc_els *els );
  307. /** Receive ELS frame
  308. *
  309. * @v els Fibre Channel ELS transaction
  310. * @v data ELS frame
  311. * @v len Length of ELS frame
  312. * @ret rc Return status code
  313. */
  314. int ( * rx ) ( struct fc_els *els, void *data, size_t len );
  315. /** Detect ELS frame
  316. *
  317. * @v els Fibre Channel ELS transaction
  318. * @v data ELS frame
  319. * @v len Length of ELS frame
  320. * @ret rc Return status code
  321. */
  322. int ( * detect ) ( struct fc_els *els, const void *data, size_t len );
  323. };
  324. /** Fibre Channel ELS handler table */
  325. #define FC_ELS_HANDLERS __table ( struct fc_els_handler, "fc_els_handlers" )
  326. /** Declare a Fibre Channel ELS handler */
  327. #define __fc_els_handler __table_entry ( FC_ELS_HANDLERS, 01 )
  328. /** A Fibre Channel ELS PRLI descriptor */
  329. struct fc_els_prli_descriptor {
  330. /** Upper-layer protocol type */
  331. unsigned int type;
  332. /** Service parameter length */
  333. size_t param_len;
  334. /** Fibre Channel ELS handler */
  335. struct fc_els_handler *handler;
  336. };
  337. /** Fibre Channel ELS PRLI descriptor table */
  338. #define FC_ELS_PRLI_DESCRIPTORS \
  339. __table ( struct fc_els_prli_descriptor, "fc_els_prli_descriptors" )
  340. /** Declare a Fibre Channel ELS PRLI descriptor */
  341. #define __fc_els_prli_descriptor __table_entry ( FC_ELS_PRLI_DESCRIPTORS, 01 )
  342. /**
  343. * Check if Fibre Channel ELS transaction is a request
  344. *
  345. * @v els Fibre Channel ELS transaction
  346. * @ret is_request ELS transaction is a request
  347. */
  348. static inline int fc_els_is_request ( struct fc_els *els ) {
  349. return ( els->flags & FC_ELS_REQUEST );
  350. }
  351. /**
  352. * Calculate ELS command to transmit
  353. *
  354. * @v els Fibre Channel ELS transaction
  355. * @v request_command Command for requests
  356. * @v command Command to transmit
  357. */
  358. static inline unsigned int fc_els_tx_command ( struct fc_els *els,
  359. unsigned int request_command ) {
  360. return ( fc_els_is_request ( els ) ? request_command : FC_ELS_LS_ACC );
  361. }
  362. extern int fc_els_tx ( struct fc_els *els, const void *data, size_t len );
  363. extern int fc_els_request ( struct interface *job, struct fc_port *port,
  364. struct fc_port_id *peer_port_id,
  365. struct fc_els_handler *handler );
  366. extern int fc_els_flogi ( struct interface *parent, struct fc_port *port );
  367. extern int fc_els_plogi ( struct interface *parent, struct fc_port *port,
  368. struct fc_port_id *peer_port_id );
  369. extern int fc_els_logo ( struct interface *parent, struct fc_port *port,
  370. struct fc_port_id *peer_port_id );
  371. extern int fc_els_prli ( struct interface *parent, struct fc_port *port,
  372. struct fc_port_id *peer_port_id, unsigned int type );
  373. extern int fc_els_prli_tx ( struct fc_els *els,
  374. struct fc_els_prli_descriptor *descriptor,
  375. void *param );
  376. extern int fc_els_prli_rx ( struct fc_els *els,
  377. struct fc_els_prli_descriptor *descriptor,
  378. void *data, size_t len );
  379. extern int fc_els_prli_detect ( struct fc_els *els __unused,
  380. struct fc_els_prli_descriptor *descriptor,
  381. const void *data, size_t len );
  382. #endif /* _IPXE_FCELS_H */