cq_desc.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2014 Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. */
  17. #ifndef _CQ_DESC_H_
  18. #define _CQ_DESC_H_
  19. /*
  20. * Completion queue descriptor types
  21. */
  22. enum cq_desc_types {
  23. CQ_DESC_TYPE_WQ_ENET = 0,
  24. CQ_DESC_TYPE_DESC_COPY = 1,
  25. CQ_DESC_TYPE_WQ_EXCH = 2,
  26. CQ_DESC_TYPE_RQ_ENET = 3,
  27. CQ_DESC_TYPE_RQ_FCP = 4,
  28. };
  29. /* Completion queue descriptor: 16B
  30. *
  31. * All completion queues have this basic layout. The
  32. * type_specific area is unique for each completion
  33. * queue type.
  34. */
  35. struct cq_desc {
  36. __le16 completed_index;
  37. __le16 q_number;
  38. u8 type_specific[11];
  39. u8 type_color;
  40. };
  41. #define CQ_DESC_TYPE_BITS 4
  42. #define CQ_DESC_TYPE_MASK ((1 << CQ_DESC_TYPE_BITS) - 1)
  43. #define CQ_DESC_COLOR_MASK 1
  44. #define CQ_DESC_COLOR_SHIFT 7
  45. #define CQ_DESC_Q_NUM_BITS 10
  46. #define CQ_DESC_Q_NUM_MASK ((1 << CQ_DESC_Q_NUM_BITS) - 1)
  47. #define CQ_DESC_COMP_NDX_BITS 12
  48. #define CQ_DESC_COMP_NDX_MASK ((1 << CQ_DESC_COMP_NDX_BITS) - 1)
  49. static inline void cq_desc_dec(const struct cq_desc *desc_arg,
  50. u8 *type, u8 *color, u16 *q_number, u16 *completed_index)
  51. {
  52. const struct cq_desc *desc = desc_arg;
  53. const u8 type_color = desc->type_color;
  54. *color = (type_color >> CQ_DESC_COLOR_SHIFT) & CQ_DESC_COLOR_MASK;
  55. /*
  56. * Make sure color bit is read from desc *before* other fields
  57. * are read from desc. Hardware guarantees color bit is last
  58. * bit (byte) written. Adding the rmb() prevents the compiler
  59. * and/or CPU from reordering the reads which would potentially
  60. * result in reading stale values.
  61. */
  62. rmb();
  63. *type = type_color & CQ_DESC_TYPE_MASK;
  64. *q_number = le16_to_cpu(desc->q_number) & CQ_DESC_Q_NUM_MASK;
  65. *completed_index = le16_to_cpu(desc->completed_index) &
  66. CQ_DESC_COMP_NDX_MASK;
  67. }
  68. #endif /* _CQ_DESC_H_ */