wq_enet_desc.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright 2008 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. #ifndef _WQ_ENET_DESC_H_
  19. #define _WQ_ENET_DESC_H_
  20. /* Ethernet work queue descriptor: 16B */
  21. struct wq_enet_desc {
  22. __le64 address;
  23. __le16 length;
  24. __le16 mss_loopback;
  25. __le16 header_length_flags;
  26. __le16 vlan_tag;
  27. };
  28. #define WQ_ENET_ADDR_BITS 64
  29. #define WQ_ENET_LEN_BITS 14
  30. #define WQ_ENET_LEN_MASK ((1 << WQ_ENET_LEN_BITS) - 1)
  31. #define WQ_ENET_MSS_BITS 14
  32. #define WQ_ENET_MSS_MASK ((1 << WQ_ENET_MSS_BITS) - 1)
  33. #define WQ_ENET_MSS_SHIFT 2
  34. #define WQ_ENET_LOOPBACK_SHIFT 1
  35. #define WQ_ENET_HDRLEN_BITS 10
  36. #define WQ_ENET_HDRLEN_MASK ((1 << WQ_ENET_HDRLEN_BITS) - 1)
  37. #define WQ_ENET_FLAGS_OM_BITS 2
  38. #define WQ_ENET_FLAGS_OM_MASK ((1 << WQ_ENET_FLAGS_OM_BITS) - 1)
  39. #define WQ_ENET_FLAGS_EOP_SHIFT 12
  40. #define WQ_ENET_FLAGS_CQ_ENTRY_SHIFT 13
  41. #define WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT 14
  42. #define WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT 15
  43. #define WQ_ENET_OFFLOAD_MODE_CSUM 0
  44. #define WQ_ENET_OFFLOAD_MODE_RESERVED 1
  45. #define WQ_ENET_OFFLOAD_MODE_CSUM_L4 2
  46. #define WQ_ENET_OFFLOAD_MODE_TSO 3
  47. static inline void wq_enet_desc_enc(struct wq_enet_desc *desc,
  48. u64 address, u16 length, u16 mss, u16 header_length,
  49. u8 offload_mode, u8 eop, u8 cq_entry, u8 fcoe_encap,
  50. u8 vlan_tag_insert, u16 vlan_tag, u8 loopback)
  51. {
  52. desc->address = cpu_to_le64(address);
  53. desc->length = cpu_to_le16(length & WQ_ENET_LEN_MASK);
  54. desc->mss_loopback = cpu_to_le16((mss & WQ_ENET_MSS_MASK) <<
  55. WQ_ENET_MSS_SHIFT | (loopback & 1) << WQ_ENET_LOOPBACK_SHIFT);
  56. desc->header_length_flags = cpu_to_le16(
  57. (header_length & WQ_ENET_HDRLEN_MASK) |
  58. (offload_mode & WQ_ENET_FLAGS_OM_MASK) << WQ_ENET_HDRLEN_BITS |
  59. (eop & 1) << WQ_ENET_FLAGS_EOP_SHIFT |
  60. (cq_entry & 1) << WQ_ENET_FLAGS_CQ_ENTRY_SHIFT |
  61. (fcoe_encap & 1) << WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT |
  62. (vlan_tag_insert & 1) << WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT);
  63. desc->vlan_tag = cpu_to_le16(vlan_tag);
  64. }
  65. static inline void wq_enet_desc_dec(struct wq_enet_desc *desc,
  66. u64 *address, u16 *length, u16 *mss, u16 *header_length,
  67. u8 *offload_mode, u8 *eop, u8 *cq_entry, u8 *fcoe_encap,
  68. u8 *vlan_tag_insert, u16 *vlan_tag, u8 *loopback)
  69. {
  70. *address = le64_to_cpu(desc->address);
  71. *length = le16_to_cpu(desc->length) & WQ_ENET_LEN_MASK;
  72. *mss = (le16_to_cpu(desc->mss_loopback) >> WQ_ENET_MSS_SHIFT) &
  73. WQ_ENET_MSS_MASK;
  74. *loopback = (u8)((le16_to_cpu(desc->mss_loopback) >>
  75. WQ_ENET_LOOPBACK_SHIFT) & 1);
  76. *header_length = le16_to_cpu(desc->header_length_flags) &
  77. WQ_ENET_HDRLEN_MASK;
  78. *offload_mode = (u8)((le16_to_cpu(desc->header_length_flags) >>
  79. WQ_ENET_HDRLEN_BITS) & WQ_ENET_FLAGS_OM_MASK);
  80. *eop = (u8)((le16_to_cpu(desc->header_length_flags) >>
  81. WQ_ENET_FLAGS_EOP_SHIFT) & 1);
  82. *cq_entry = (u8)((le16_to_cpu(desc->header_length_flags) >>
  83. WQ_ENET_FLAGS_CQ_ENTRY_SHIFT) & 1);
  84. *fcoe_encap = (u8)((le16_to_cpu(desc->header_length_flags) >>
  85. WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT) & 1);
  86. *vlan_tag_insert = (u8)((le16_to_cpu(desc->header_length_flags) >>
  87. WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT) & 1);
  88. *vlan_tag = le16_to_cpu(desc->vlan_tag);
  89. }
  90. #endif /* _WQ_ENET_DESC_H_ */