sym_misc.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
  3. * of PCI-SCSI IO processors.
  4. *
  5. * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
  6. *
  7. * This driver is derived from the Linux sym53c8xx driver.
  8. * Copyright (C) 1998-2000 Gerard Roudier
  9. *
  10. * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
  11. * a port of the FreeBSD ncr driver to Linux-1.2.13.
  12. *
  13. * The original ncr driver has been written for 386bsd and FreeBSD by
  14. * Wolfgang Stanglmeier <wolf@cologne.de>
  15. * Stefan Esser <se@mi.Uni-Koeln.de>
  16. * Copyright (C) 1994 Wolfgang Stanglmeier
  17. *
  18. * Other major contributions:
  19. *
  20. * NVRAM detection and reading.
  21. * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
  22. *
  23. *-----------------------------------------------------------------------------
  24. *
  25. * This program is free software; you can redistribute it and/or modify
  26. * it under the terms of the GNU General Public License as published by
  27. * the Free Software Foundation; either version 2 of the License, or
  28. * (at your option) any later version.
  29. *
  30. * This program is distributed in the hope that it will be useful,
  31. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. * GNU General Public License for more details.
  34. *
  35. * You should have received a copy of the GNU General Public License
  36. * along with this program; if not, write to the Free Software
  37. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  38. */
  39. #ifndef SYM_MISC_H
  40. #define SYM_MISC_H
  41. /*
  42. * A la VMS/CAM-3 queue management.
  43. */
  44. typedef struct sym_quehead {
  45. struct sym_quehead *flink; /* Forward pointer */
  46. struct sym_quehead *blink; /* Backward pointer */
  47. } SYM_QUEHEAD;
  48. #define sym_que_init(ptr) do { \
  49. (ptr)->flink = (ptr); (ptr)->blink = (ptr); \
  50. } while (0)
  51. static inline struct sym_quehead *sym_que_first(struct sym_quehead *head)
  52. {
  53. return (head->flink == head) ? 0 : head->flink;
  54. }
  55. static inline struct sym_quehead *sym_que_last(struct sym_quehead *head)
  56. {
  57. return (head->blink == head) ? 0 : head->blink;
  58. }
  59. static inline void __sym_que_add(struct sym_quehead * new,
  60. struct sym_quehead * blink,
  61. struct sym_quehead * flink)
  62. {
  63. flink->blink = new;
  64. new->flink = flink;
  65. new->blink = blink;
  66. blink->flink = new;
  67. }
  68. static inline void __sym_que_del(struct sym_quehead * blink,
  69. struct sym_quehead * flink)
  70. {
  71. flink->blink = blink;
  72. blink->flink = flink;
  73. }
  74. static inline int sym_que_empty(struct sym_quehead *head)
  75. {
  76. return head->flink == head;
  77. }
  78. static inline void sym_que_splice(struct sym_quehead *list,
  79. struct sym_quehead *head)
  80. {
  81. struct sym_quehead *first = list->flink;
  82. if (first != list) {
  83. struct sym_quehead *last = list->blink;
  84. struct sym_quehead *at = head->flink;
  85. first->blink = head;
  86. head->flink = first;
  87. last->flink = at;
  88. at->blink = last;
  89. }
  90. }
  91. static inline void sym_que_move(struct sym_quehead *orig,
  92. struct sym_quehead *dest)
  93. {
  94. struct sym_quehead *first, *last;
  95. first = orig->flink;
  96. if (first != orig) {
  97. first->blink = dest;
  98. dest->flink = first;
  99. last = orig->blink;
  100. last->flink = dest;
  101. dest->blink = last;
  102. orig->flink = orig;
  103. orig->blink = orig;
  104. } else {
  105. dest->flink = dest;
  106. dest->blink = dest;
  107. }
  108. }
  109. #define sym_que_entry(ptr, type, member) container_of(ptr, type, member)
  110. #define sym_insque(new, pos) __sym_que_add(new, pos, (pos)->flink)
  111. #define sym_remque(el) __sym_que_del((el)->blink, (el)->flink)
  112. #define sym_insque_head(new, head) __sym_que_add(new, head, (head)->flink)
  113. static inline struct sym_quehead *sym_remque_head(struct sym_quehead *head)
  114. {
  115. struct sym_quehead *elem = head->flink;
  116. if (elem != head)
  117. __sym_que_del(head, elem->flink);
  118. else
  119. elem = NULL;
  120. return elem;
  121. }
  122. #define sym_insque_tail(new, head) __sym_que_add(new, (head)->blink, head)
  123. static inline struct sym_quehead *sym_remque_tail(struct sym_quehead *head)
  124. {
  125. struct sym_quehead *elem = head->blink;
  126. if (elem != head)
  127. __sym_que_del(elem->blink, head);
  128. else
  129. elem = 0;
  130. return elem;
  131. }
  132. /*
  133. * This one may be useful.
  134. */
  135. #define FOR_EACH_QUEUED_ELEMENT(head, qp) \
  136. for (qp = (head)->flink; qp != (head); qp = qp->flink)
  137. /*
  138. * FreeBSD does not offer our kind of queue in the CAM CCB.
  139. * So, we have to cast.
  140. */
  141. #define sym_qptr(p) ((struct sym_quehead *) (p))
  142. /*
  143. * Simple bitmap operations.
  144. */
  145. #define sym_set_bit(p, n) (((u32 *)(p))[(n)>>5] |= (1<<((n)&0x1f)))
  146. #define sym_clr_bit(p, n) (((u32 *)(p))[(n)>>5] &= ~(1<<((n)&0x1f)))
  147. #define sym_is_bit(p, n) (((u32 *)(p))[(n)>>5] & (1<<((n)&0x1f)))
  148. /*
  149. * The below round up/down macros are to be used with a constant
  150. * as argument (sizeof(...) for example), for the compiler to
  151. * optimize the whole thing.
  152. */
  153. #define _U_(a,m) (a)<=(1<<m)?m:
  154. /*
  155. * Round up logarithm to base 2 of a 16 bit constant.
  156. */
  157. #define _LGRU16_(a) \
  158. ( \
  159. _U_(a, 0)_U_(a, 1)_U_(a, 2)_U_(a, 3)_U_(a, 4)_U_(a, 5)_U_(a, 6)_U_(a, 7) \
  160. _U_(a, 8)_U_(a, 9)_U_(a,10)_U_(a,11)_U_(a,12)_U_(a,13)_U_(a,14)_U_(a,15) \
  161. 16)
  162. #endif /* SYM_MISC_H */