c2_mq.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2005 Ammasso, Inc. All rights reserved.
  3. * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #ifndef _C2_MQ_H_
  34. #define _C2_MQ_H_
  35. #include <linux/kernel.h>
  36. #include <linux/dma-mapping.h>
  37. #include "c2_wr.h"
  38. enum c2_shared_regs {
  39. C2_SHARED_ARMED = 0x10,
  40. C2_SHARED_NOTIFY = 0x18,
  41. C2_SHARED_SHARED = 0x40,
  42. };
  43. struct c2_mq_shared {
  44. u16 unused1;
  45. u8 armed;
  46. u8 notification_type;
  47. u32 unused2;
  48. u16 shared;
  49. /* Pad to 64 bytes. */
  50. u8 pad[64 - sizeof(u16) - 2 * sizeof(u8) - sizeof(u32) - sizeof(u16)];
  51. };
  52. enum c2_mq_type {
  53. C2_MQ_HOST_TARGET = 1,
  54. C2_MQ_ADAPTER_TARGET = 2,
  55. };
  56. /*
  57. * c2_mq_t is for kernel-mode MQs like the VQs Cand the AEQ.
  58. * c2_user_mq_t (which is the same format) is for user-mode MQs...
  59. */
  60. #define C2_MQ_MAGIC 0x4d512020 /* 'MQ ' */
  61. struct c2_mq {
  62. u32 magic;
  63. union {
  64. u8 *host;
  65. u8 __iomem *adapter;
  66. } msg_pool;
  67. dma_addr_t host_dma;
  68. DEFINE_DMA_UNMAP_ADDR(mapping);
  69. u16 hint_count;
  70. u16 priv;
  71. struct c2_mq_shared __iomem *peer;
  72. __be16 *shared;
  73. dma_addr_t shared_dma;
  74. u32 q_size;
  75. u32 msg_size;
  76. u32 index;
  77. enum c2_mq_type type;
  78. };
  79. static __inline__ int c2_mq_empty(struct c2_mq *q)
  80. {
  81. return q->priv == be16_to_cpu(*q->shared);
  82. }
  83. static __inline__ int c2_mq_full(struct c2_mq *q)
  84. {
  85. return q->priv == (be16_to_cpu(*q->shared) + q->q_size - 1) % q->q_size;
  86. }
  87. extern void c2_mq_lconsume(struct c2_mq *q, u32 wqe_count);
  88. extern void *c2_mq_alloc(struct c2_mq *q);
  89. extern void c2_mq_produce(struct c2_mq *q);
  90. extern void *c2_mq_consume(struct c2_mq *q);
  91. extern void c2_mq_free(struct c2_mq *q);
  92. extern void c2_mq_req_init(struct c2_mq *q, u32 index, u32 q_size, u32 msg_size,
  93. u8 __iomem *pool_start, u16 __iomem *peer, u32 type);
  94. extern void c2_mq_rep_init(struct c2_mq *q, u32 index, u32 q_size, u32 msg_size,
  95. u8 *pool_start, u16 __iomem *peer, u32 type);
  96. #endif /* _C2_MQ_H_ */