cq_desc.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright 2014 Cisco Systems, Inc. All rights reserved. */
  3. #ifndef _CQ_DESC_H_
  4. #define _CQ_DESC_H_
  5. /*
  6. * Completion queue descriptor types
  7. */
  8. enum cq_desc_types {
  9. CQ_DESC_TYPE_WQ_ENET = 0,
  10. CQ_DESC_TYPE_DESC_COPY = 1,
  11. CQ_DESC_TYPE_WQ_EXCH = 2,
  12. CQ_DESC_TYPE_RQ_ENET = 3,
  13. CQ_DESC_TYPE_RQ_FCP = 4,
  14. };
  15. /* Completion queue descriptor: 16B
  16. *
  17. * All completion queues have this basic layout. The
  18. * type_specific area is unique for each completion
  19. * queue type.
  20. */
  21. struct cq_desc {
  22. __le16 completed_index;
  23. __le16 q_number;
  24. u8 type_specific[11];
  25. u8 type_color;
  26. };
  27. #define CQ_DESC_TYPE_BITS 4
  28. #define CQ_DESC_TYPE_MASK ((1 << CQ_DESC_TYPE_BITS) - 1)
  29. #define CQ_DESC_COLOR_MASK 1
  30. #define CQ_DESC_COLOR_SHIFT 7
  31. #define CQ_DESC_Q_NUM_BITS 10
  32. #define CQ_DESC_Q_NUM_MASK ((1 << CQ_DESC_Q_NUM_BITS) - 1)
  33. #define CQ_DESC_COMP_NDX_BITS 12
  34. #define CQ_DESC_COMP_NDX_MASK ((1 << CQ_DESC_COMP_NDX_BITS) - 1)
  35. static inline void cq_desc_dec(const struct cq_desc *desc_arg,
  36. u8 *type, u8 *color, u16 *q_number, u16 *completed_index)
  37. {
  38. const struct cq_desc *desc = desc_arg;
  39. const u8 type_color = desc->type_color;
  40. *color = (type_color >> CQ_DESC_COLOR_SHIFT) & CQ_DESC_COLOR_MASK;
  41. /*
  42. * Make sure color bit is read from desc *before* other fields
  43. * are read from desc. Hardware guarantees color bit is last
  44. * bit (byte) written. Adding the rmb() prevents the compiler
  45. * and/or CPU from reordering the reads which would potentially
  46. * result in reading stale values.
  47. */
  48. rmb();
  49. *type = type_color & CQ_DESC_TYPE_MASK;
  50. *q_number = le16_to_cpu(desc->q_number) & CQ_DESC_Q_NUM_MASK;
  51. *completed_index = le16_to_cpu(desc->completed_index) &
  52. CQ_DESC_COMP_NDX_MASK;
  53. }
  54. #endif /* _CQ_DESC_H_ */