cq_desc.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 _CQ_DESC_H_
  20. #define _CQ_DESC_H_
  21. /*
  22. * Completion queue descriptor types
  23. */
  24. enum cq_desc_types {
  25. CQ_DESC_TYPE_WQ_ENET = 0,
  26. CQ_DESC_TYPE_DESC_COPY = 1,
  27. CQ_DESC_TYPE_WQ_EXCH = 2,
  28. CQ_DESC_TYPE_RQ_ENET = 3,
  29. CQ_DESC_TYPE_RQ_FCP = 4,
  30. };
  31. /* Completion queue descriptor: 16B
  32. *
  33. * All completion queues have this basic layout. The
  34. * type_specfic area is unique for each completion
  35. * queue type.
  36. */
  37. struct cq_desc {
  38. __le16 completed_index;
  39. __le16 q_number;
  40. u8 type_specfic[11];
  41. u8 type_color;
  42. };
  43. #define CQ_DESC_TYPE_BITS 4
  44. #define CQ_DESC_TYPE_MASK ((1 << CQ_DESC_TYPE_BITS) - 1)
  45. #define CQ_DESC_COLOR_MASK 1
  46. #define CQ_DESC_COLOR_SHIFT 7
  47. #define CQ_DESC_Q_NUM_BITS 10
  48. #define CQ_DESC_Q_NUM_MASK ((1 << CQ_DESC_Q_NUM_BITS) - 1)
  49. #define CQ_DESC_COMP_NDX_BITS 12
  50. #define CQ_DESC_COMP_NDX_MASK ((1 << CQ_DESC_COMP_NDX_BITS) - 1)
  51. static inline void cq_desc_dec(const struct cq_desc *desc_arg,
  52. u8 *type, u8 *color, u16 *q_number, u16 *completed_index)
  53. {
  54. const struct cq_desc *desc = desc_arg;
  55. const u8 type_color = desc->type_color;
  56. *color = (type_color >> CQ_DESC_COLOR_SHIFT) & CQ_DESC_COLOR_MASK;
  57. /*
  58. * Make sure color bit is read from desc *before* other fields
  59. * are read from desc. Hardware guarantees color bit is last
  60. * bit (byte) written. Adding the rmb() prevents the compiler
  61. * and/or CPU from reordering the reads which would potentially
  62. * result in reading stale values.
  63. */
  64. rmb();
  65. *type = type_color & CQ_DESC_TYPE_MASK;
  66. *q_number = le16_to_cpu(desc->q_number) & CQ_DESC_Q_NUM_MASK;
  67. *completed_index = le16_to_cpu(desc->completed_index) &
  68. CQ_DESC_COMP_NDX_MASK;
  69. }
  70. #endif /* _CQ_DESC_H_ */