fc_encaps.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright(c) 2007 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_ENCAPS_H_
  20. #define _FC_ENCAPS_H_
  21. /*
  22. * Protocol definitions from RFC 3643 - Fibre Channel Frame Encapsulation.
  23. *
  24. * Note: The frame length field is the number of 32-bit words in
  25. * the encapsulation including the fcip_encaps_header, CRC and EOF words.
  26. * The minimum frame length value in bytes is (32 + 24 + 4 + 4) * 4 = 64.
  27. * The maximum frame length value in bytes is (32 + 24 + 2112 + 4 + 4) = 2172.
  28. */
  29. #define FC_ENCAPS_MIN_FRAME_LEN 64 /* min frame len (bytes) (see above) */
  30. #define FC_ENCAPS_MAX_FRAME_LEN (FC_ENCAPS_MIN_FRAME_LEN + FC_MAX_PAYLOAD)
  31. #define FC_ENCAPS_VER 1 /* current version number */
  32. struct fc_encaps_hdr {
  33. __u8 fc_proto; /* protocol number */
  34. __u8 fc_ver; /* version of encapsulation */
  35. __u8 fc_proto_n; /* ones complement of protocol */
  36. __u8 fc_ver_n; /* ones complement of version */
  37. unsigned char fc_proto_data[8]; /* protocol specific data */
  38. __be16 fc_len_flags; /* 10-bit length/4 w/ 6 flag bits */
  39. __be16 fc_len_flags_n; /* ones complement of length / flags */
  40. /*
  41. * Offset 0x10
  42. */
  43. __be32 fc_time[2]; /* time stamp: seconds and fraction */
  44. __be32 fc_crc; /* CRC */
  45. __be32 fc_sof; /* start of frame (see FC_SOF below) */
  46. /* 0x20 - FC frame content followed by EOF word */
  47. };
  48. #define FCIP_ENCAPS_HDR_LEN 0x20 /* expected length for asserts */
  49. /*
  50. * Macro's for making redundant copies of EOF and SOF.
  51. */
  52. #define FC_XY(x, y) ((((x) & 0xff) << 8) | ((y) & 0xff))
  53. #define FC_XYXY(x, y) ((FCIP_XY(x, y) << 16) | FCIP_XY(x, y))
  54. #define FC_XYNN(x, y) (FCIP_XYXY(x, y) ^ 0xffff)
  55. #define FC_SOF_ENCODE(n) FC_XYNN(n, n)
  56. #define FC_EOF_ENCODE(n) FC_XYNN(n, n)
  57. /*
  58. * SOF / EOF bytes.
  59. */
  60. enum fc_sof {
  61. FC_SOF_F = 0x28, /* fabric */
  62. FC_SOF_I4 = 0x29, /* initiate class 4 */
  63. FC_SOF_I2 = 0x2d, /* initiate class 2 */
  64. FC_SOF_I3 = 0x2e, /* initiate class 3 */
  65. FC_SOF_N4 = 0x31, /* normal class 4 */
  66. FC_SOF_N2 = 0x35, /* normal class 2 */
  67. FC_SOF_N3 = 0x36, /* normal class 3 */
  68. FC_SOF_C4 = 0x39, /* activate class 4 */
  69. } __attribute__((packed));
  70. enum fc_eof {
  71. FC_EOF_N = 0x41, /* normal (not last frame of seq) */
  72. FC_EOF_T = 0x42, /* terminate (last frame of sequence) */
  73. FC_EOF_RT = 0x44,
  74. FC_EOF_DT = 0x46, /* disconnect-terminate class-1 */
  75. FC_EOF_NI = 0x49, /* normal-invalid */
  76. FC_EOF_DTI = 0x4e, /* disconnect-terminate-invalid */
  77. FC_EOF_RTI = 0x4f,
  78. FC_EOF_A = 0x50, /* abort */
  79. } __attribute__((packed));
  80. #define FC_SOF_CLASS_MASK 0x06 /* mask for class of service in SOF */
  81. /*
  82. * Define classes in terms of the SOF code (initial).
  83. */
  84. enum fc_class {
  85. FC_CLASS_NONE = 0, /* software value indicating no class */
  86. FC_CLASS_2 = FC_SOF_I2,
  87. FC_CLASS_3 = FC_SOF_I3,
  88. FC_CLASS_4 = FC_SOF_I4,
  89. FC_CLASS_F = FC_SOF_F,
  90. };
  91. /*
  92. * Determine whether SOF code indicates the need for a BLS ACK.
  93. */
  94. static inline int fc_sof_needs_ack(enum fc_sof sof)
  95. {
  96. return (~sof) & 0x02; /* true for class 1, 2, 4, 6, or F */
  97. }
  98. /*
  99. * Given an fc_class, return the normal (non-initial) SOF value.
  100. */
  101. static inline enum fc_sof fc_sof_normal(enum fc_class class)
  102. {
  103. return class + FC_SOF_N3 - FC_SOF_I3; /* diff is always 8 */
  104. }
  105. /*
  106. * Compute class from SOF value.
  107. */
  108. static inline enum fc_class fc_sof_class(enum fc_sof sof)
  109. {
  110. return (sof & 0x7) | FC_SOF_F;
  111. }
  112. /*
  113. * Determine whether SOF is for the initial frame of a sequence.
  114. */
  115. static inline int fc_sof_is_init(enum fc_sof sof)
  116. {
  117. return sof < 0x30;
  118. }
  119. #endif /* _FC_ENCAPS_H_ */