wq_enet_desc.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2014 Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. */
  17. #ifndef _WQ_ENET_DESC_H_
  18. #define _WQ_ENET_DESC_H_
  19. /* Ethernet work queue descriptor: 16B */
  20. struct wq_enet_desc {
  21. __le64 address;
  22. __le16 length;
  23. __le16 mss_loopback;
  24. __le16 header_length_flags;
  25. __le16 vlan_tag;
  26. };
  27. #define WQ_ENET_ADDR_BITS 64
  28. #define WQ_ENET_LEN_BITS 14
  29. #define WQ_ENET_LEN_MASK ((1 << WQ_ENET_LEN_BITS) - 1)
  30. #define WQ_ENET_MSS_BITS 14
  31. #define WQ_ENET_MSS_MASK ((1 << WQ_ENET_MSS_BITS) - 1)
  32. #define WQ_ENET_MSS_SHIFT 2
  33. #define WQ_ENET_LOOPBACK_SHIFT 1
  34. #define WQ_ENET_HDRLEN_BITS 10
  35. #define WQ_ENET_HDRLEN_MASK ((1 << WQ_ENET_HDRLEN_BITS) - 1)
  36. #define WQ_ENET_FLAGS_OM_BITS 2
  37. #define WQ_ENET_FLAGS_OM_MASK ((1 << WQ_ENET_FLAGS_OM_BITS) - 1)
  38. #define WQ_ENET_FLAGS_EOP_SHIFT 12
  39. #define WQ_ENET_FLAGS_CQ_ENTRY_SHIFT 13
  40. #define WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT 14
  41. #define WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT 15
  42. #define WQ_ENET_OFFLOAD_MODE_CSUM 0
  43. #define WQ_ENET_OFFLOAD_MODE_RESERVED 1
  44. #define WQ_ENET_OFFLOAD_MODE_CSUM_L4 2
  45. #define WQ_ENET_OFFLOAD_MODE_TSO 3
  46. static inline void wq_enet_desc_enc(struct wq_enet_desc *desc,
  47. u64 address, u16 length, u16 mss, u16 header_length,
  48. u8 offload_mode, u8 eop, u8 cq_entry, u8 fcoe_encap,
  49. u8 vlan_tag_insert, u16 vlan_tag, u8 loopback)
  50. {
  51. desc->address = cpu_to_le64(address);
  52. desc->length = cpu_to_le16(length & WQ_ENET_LEN_MASK);
  53. desc->mss_loopback = cpu_to_le16((mss & WQ_ENET_MSS_MASK) <<
  54. WQ_ENET_MSS_SHIFT | (loopback & 1) << WQ_ENET_LOOPBACK_SHIFT);
  55. desc->header_length_flags = cpu_to_le16(
  56. (header_length & WQ_ENET_HDRLEN_MASK) |
  57. (offload_mode & WQ_ENET_FLAGS_OM_MASK) << WQ_ENET_HDRLEN_BITS |
  58. (eop & 1) << WQ_ENET_FLAGS_EOP_SHIFT |
  59. (cq_entry & 1) << WQ_ENET_FLAGS_CQ_ENTRY_SHIFT |
  60. (fcoe_encap & 1) << WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT |
  61. (vlan_tag_insert & 1) << WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT);
  62. desc->vlan_tag = cpu_to_le16(vlan_tag);
  63. }
  64. static inline void wq_enet_desc_dec(struct wq_enet_desc *desc,
  65. u64 *address, u16 *length, u16 *mss, u16 *header_length,
  66. u8 *offload_mode, u8 *eop, u8 *cq_entry, u8 *fcoe_encap,
  67. u8 *vlan_tag_insert, u16 *vlan_tag, u8 *loopback)
  68. {
  69. *address = le64_to_cpu(desc->address);
  70. *length = le16_to_cpu(desc->length) & WQ_ENET_LEN_MASK;
  71. *mss = (le16_to_cpu(desc->mss_loopback) >> WQ_ENET_MSS_SHIFT) &
  72. WQ_ENET_MSS_MASK;
  73. *loopback = (u8)((le16_to_cpu(desc->mss_loopback) >>
  74. WQ_ENET_LOOPBACK_SHIFT) & 1);
  75. *header_length = le16_to_cpu(desc->header_length_flags) &
  76. WQ_ENET_HDRLEN_MASK;
  77. *offload_mode = (u8)((le16_to_cpu(desc->header_length_flags) >>
  78. WQ_ENET_HDRLEN_BITS) & WQ_ENET_FLAGS_OM_MASK);
  79. *eop = (u8)((le16_to_cpu(desc->header_length_flags) >>
  80. WQ_ENET_FLAGS_EOP_SHIFT) & 1);
  81. *cq_entry = (u8)((le16_to_cpu(desc->header_length_flags) >>
  82. WQ_ENET_FLAGS_CQ_ENTRY_SHIFT) & 1);
  83. *fcoe_encap = (u8)((le16_to_cpu(desc->header_length_flags) >>
  84. WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT) & 1);
  85. *vlan_tag_insert = (u8)((le16_to_cpu(desc->header_length_flags) >>
  86. WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT) & 1);
  87. *vlan_tag = le16_to_cpu(desc->vlan_tag);
  88. }
  89. #endif /* _WQ_ENET_DESC_H_ */