bfa_q.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. /**
  18. * bfa_q.h Circular queue definitions.
  19. */
  20. #ifndef __BFA_Q_H__
  21. #define __BFA_Q_H__
  22. #define bfa_q_first(_q) ((void *)(((struct list_head *) (_q))->next))
  23. #define bfa_q_next(_qe) (((struct list_head *) (_qe))->next)
  24. #define bfa_q_prev(_qe) (((struct list_head *) (_qe))->prev)
  25. /*
  26. * bfa_q_qe_init - to initialize a queue element
  27. */
  28. #define bfa_q_qe_init(_qe) { \
  29. bfa_q_next(_qe) = (struct list_head *) NULL; \
  30. bfa_q_prev(_qe) = (struct list_head *) NULL; \
  31. }
  32. /*
  33. * bfa_q_deq - dequeue an element from head of the queue
  34. */
  35. #define bfa_q_deq(_q, _qe) { \
  36. if (!list_empty(_q)) { \
  37. (*((struct list_head **) (_qe))) = bfa_q_next(_q); \
  38. bfa_q_prev(bfa_q_next(*((struct list_head **) _qe))) = \
  39. (struct list_head *) (_q); \
  40. bfa_q_next(_q) = bfa_q_next(*((struct list_head **) _qe)); \
  41. BFA_Q_DBG_INIT(*((struct list_head **) _qe)); \
  42. } else { \
  43. *((struct list_head **) (_qe)) = (struct list_head *) NULL; \
  44. } \
  45. }
  46. /*
  47. * bfa_q_deq_tail - dequeue an element from tail of the queue
  48. */
  49. #define bfa_q_deq_tail(_q, _qe) { \
  50. if (!list_empty(_q)) { \
  51. *((struct list_head **) (_qe)) = bfa_q_prev(_q); \
  52. bfa_q_next(bfa_q_prev(*((struct list_head **) _qe))) = \
  53. (struct list_head *) (_q); \
  54. bfa_q_prev(_q) = bfa_q_prev(*(struct list_head **) _qe); \
  55. BFA_Q_DBG_INIT(*((struct list_head **) _qe)); \
  56. } else { \
  57. *((struct list_head **) (_qe)) = (struct list_head *) NULL; \
  58. } \
  59. }
  60. /*
  61. * #ifdef BFA_DEBUG (Using bfa_assert to check for debug_build is not
  62. * consistent across modules)
  63. */
  64. #ifndef BFA_PERF_BUILD
  65. #define BFA_Q_DBG_INIT(_qe) bfa_q_qe_init(_qe)
  66. #else
  67. #define BFA_Q_DBG_INIT(_qe)
  68. #endif
  69. #define bfa_q_is_on_q(_q, _qe) \
  70. bfa_q_is_on_q_func(_q, (struct list_head *)(_qe))
  71. extern int bfa_q_is_on_q_func(struct list_head *q, struct list_head *qe);
  72. #endif