cq_desc.h 1.8 KB

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