2 * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
3 * of PCI-SCSI IO processors.
5 * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
7 * This driver is derived from the Linux sym53c8xx driver.
8 * Copyright (C) 1998-2000 Gerard Roudier
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.
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
18 * Other major contributions:
20 * NVRAM detection and reading.
21 * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
23 *-----------------------------------------------------------------------------
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.
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.
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
44 * A la VMS/CAM-3 queue management.
46 typedef struct sym_quehead
{
47 struct sym_quehead
*flink
; /* Forward pointer */
48 struct sym_quehead
*blink
; /* Backward pointer */
51 #define sym_que_init(ptr) do { \
52 (ptr)->flink = (ptr); (ptr)->blink = (ptr); \
55 static __inline
struct sym_quehead
*sym_que_first(struct sym_quehead
*head
)
57 return (head
->flink
== head
) ? 0 : head
->flink
;
60 static __inline
struct sym_quehead
*sym_que_last(struct sym_quehead
*head
)
62 return (head
->blink
== head
) ? 0 : head
->blink
;
65 static __inline
void __sym_que_add(struct sym_quehead
* new,
66 struct sym_quehead
* blink
,
67 struct sym_quehead
* flink
)
75 static __inline
void __sym_que_del(struct sym_quehead
* blink
,
76 struct sym_quehead
* flink
)
82 static __inline
int sym_que_empty(struct sym_quehead
*head
)
84 return head
->flink
== head
;
87 static __inline
void sym_que_splice(struct sym_quehead
*list
,
88 struct sym_quehead
*head
)
90 struct sym_quehead
*first
= list
->flink
;
93 struct sym_quehead
*last
= list
->blink
;
94 struct sym_quehead
*at
= head
->flink
;
104 static __inline
void sym_que_move(struct sym_quehead
*orig
,
105 struct sym_quehead
*dest
)
107 struct sym_quehead
*first
, *last
;
124 #define sym_que_entry(ptr, type, member) \
125 ((type *)((char *)(ptr)-(unsigned int)(&((type *)0)->member)))
128 #define sym_insque(new, pos) __sym_que_add(new, pos, (pos)->flink)
130 #define sym_remque(el) __sym_que_del((el)->blink, (el)->flink)
132 #define sym_insque_head(new, head) __sym_que_add(new, head, (head)->flink)
134 static __inline
struct sym_quehead
*sym_remque_head(struct sym_quehead
*head
)
136 struct sym_quehead
*elem
= head
->flink
;
139 __sym_que_del(head
, elem
->flink
);
145 #define sym_insque_tail(new, head) __sym_que_add(new, (head)->blink, head)
147 static __inline
struct sym_quehead
*sym_remque_tail(struct sym_quehead
*head
)
149 struct sym_quehead
*elem
= head
->blink
;
152 __sym_que_del(elem
->blink
, head
);
159 * This one may be useful.
161 #define FOR_EACH_QUEUED_ELEMENT(head, qp) \
162 for (qp = (head)->flink; qp != (head); qp = qp->flink)
164 * FreeBSD does not offer our kind of queue in the CAM CCB.
165 * So, we have to cast.
167 #define sym_qptr(p) ((struct sym_quehead *) (p))
170 * Simple bitmap operations.
172 #define sym_set_bit(p, n) (((u32 *)(p))[(n)>>5] |= (1<<((n)&0x1f)))
173 #define sym_clr_bit(p, n) (((u32 *)(p))[(n)>>5] &= ~(1<<((n)&0x1f)))
174 #define sym_is_bit(p, n) (((u32 *)(p))[(n)>>5] & (1<<((n)&0x1f)))
177 * The below round up/down macros are to be used with a constant
178 * as argument (sizeof(...) for example), for the compiler to
179 * optimize the whole thing.
181 #define _U_(a,m) (a)<=(1<<m)?m:
184 * Round up logarithm to base 2 of a 16 bit constant.
186 #define _LGRU16_(a) \
188 _U_(a, 0)_U_(a, 1)_U_(a, 2)_U_(a, 3)_U_(a, 4)_U_(a, 5)_U_(a, 6)_U_(a, 7) \
189 _U_(a, 8)_U_(a, 9)_U_(a,10)_U_(a,11)_U_(a,12)_U_(a,13)_U_(a,14)_U_(a,15) \
192 #endif /* SYM_MISC_H */