wq_enet_desc.h 3.8 KB

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