11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * of PCI-SCSI IO processors. 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr> 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This driver is derived from the Linux sym53c8xx driver. 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 1998-2000 Gerard Roudier 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The sym53c8xx driver is derived from the ncr53c8xx driver that had been 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * a port of the FreeBSD ncr driver to Linux-1.2.13. 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The original ncr driver has been written for 386bsd and FreeBSD by 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Wolfgang Stanglmeier <wolf@cologne.de> 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Stefan Esser <se@mi.Uni-Koeln.de> 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 1994 Wolfgang Stanglmeier 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Other major contributions: 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * NVRAM detection and reading. 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk> 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *----------------------------------------------------------------------------- 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This program is free software; you can redistribute it and/or modify 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * it under the terms of the GNU General Public License as published by 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * (at your option) any later version. 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This program is distributed in the hope that it will be useful, 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * GNU General Public License for more details. 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * You should have received a copy of the GNU General Public License 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * along with this program; if not, write to the Free Software 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef SYM_MISC_H 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SYM_MISC_H 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * A la VMS/CAM-3 queue management. 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldstypedef struct sym_quehead { 471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sym_quehead *flink; /* Forward pointer */ 481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sym_quehead *blink; /* Backward pointer */ 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} SYM_QUEHEAD; 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define sym_que_init(ptr) do { \ 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (ptr)->flink = (ptr); (ptr)->blink = (ptr); \ 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} while (0) 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 551beb6fa85ca9afaee109811a3f4a984232a32a4fHarvey Harrisonstatic inline struct sym_quehead *sym_que_first(struct sym_quehead *head) 561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (head->flink == head) ? 0 : head->flink; 581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 601beb6fa85ca9afaee109811a3f4a984232a32a4fHarvey Harrisonstatic inline struct sym_quehead *sym_que_last(struct sym_quehead *head) 611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (head->blink == head) ? 0 : head->blink; 631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 651beb6fa85ca9afaee109811a3f4a984232a32a4fHarvey Harrisonstatic inline void __sym_que_add(struct sym_quehead * new, 661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sym_quehead * blink, 671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sym_quehead * flink) 681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds flink->blink = new; 701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds new->flink = flink; 711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds new->blink = blink; 721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds blink->flink = new; 731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 751beb6fa85ca9afaee109811a3f4a984232a32a4fHarvey Harrisonstatic inline void __sym_que_del(struct sym_quehead * blink, 761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sym_quehead * flink) 771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds flink->blink = blink; 791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds blink->flink = flink; 801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 821beb6fa85ca9afaee109811a3f4a984232a32a4fHarvey Harrisonstatic inline int sym_que_empty(struct sym_quehead *head) 831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return head->flink == head; 851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 871beb6fa85ca9afaee109811a3f4a984232a32a4fHarvey Harrisonstatic inline void sym_que_splice(struct sym_quehead *list, 881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sym_quehead *head) 891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sym_quehead *first = list->flink; 911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (first != list) { 931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sym_quehead *last = list->blink; 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sym_quehead *at = head->flink; 951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds first->blink = head; 971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds head->flink = first; 981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds last->flink = at; 1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds at->blink = last; 1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1041beb6fa85ca9afaee109811a3f4a984232a32a4fHarvey Harrisonstatic inline void sym_que_move(struct sym_quehead *orig, 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sym_quehead *dest) 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sym_quehead *first, *last; 1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds first = orig->flink; 1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (first != orig) { 1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds first->blink = dest; 1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dest->flink = first; 1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds last = orig->blink; 1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds last->flink = dest; 1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dest->blink = last; 1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds orig->flink = orig; 1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds orig->blink = orig; 1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dest->flink = dest; 1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dest->blink = dest; 1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 124d7f305e9a08040649b0800245e67708df58cdb55Benjamin Herrenschmidt#define sym_que_entry(ptr, type, member) container_of(ptr, type, member) 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define sym_insque(new, pos) __sym_que_add(new, pos, (pos)->flink) 1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define sym_remque(el) __sym_que_del((el)->blink, (el)->flink) 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define sym_insque_head(new, head) __sym_que_add(new, head, (head)->flink) 1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1321beb6fa85ca9afaee109811a3f4a984232a32a4fHarvey Harrisonstatic inline struct sym_quehead *sym_remque_head(struct sym_quehead *head) 1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sym_quehead *elem = head->flink; 1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (elem != head) 1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __sym_que_del(head, elem->flink); 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds elem = NULL; 1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return elem; 1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define sym_insque_tail(new, head) __sym_que_add(new, (head)->blink, head) 1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1451beb6fa85ca9afaee109811a3f4a984232a32a4fHarvey Harrisonstatic inline struct sym_quehead *sym_remque_tail(struct sym_quehead *head) 1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sym_quehead *elem = head->blink; 1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (elem != head) 1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __sym_que_del(elem->blink, head); 1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds elem = 0; 1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return elem; 1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This one may be useful. 1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FOR_EACH_QUEUED_ELEMENT(head, qp) \ 1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (qp = (head)->flink; qp != (head); qp = qp->flink) 1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * FreeBSD does not offer our kind of queue in the CAM CCB. 1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * So, we have to cast. 1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define sym_qptr(p) ((struct sym_quehead *) (p)) 1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Simple bitmap operations. 1691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define sym_set_bit(p, n) (((u32 *)(p))[(n)>>5] |= (1<<((n)&0x1f))) 1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define sym_clr_bit(p, n) (((u32 *)(p))[(n)>>5] &= ~(1<<((n)&0x1f))) 1721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define sym_is_bit(p, n) (((u32 *)(p))[(n)>>5] & (1<<((n)&0x1f))) 1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The below round up/down macros are to be used with a constant 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * as argument (sizeof(...) for example), for the compiler to 1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * optimize the whole thing. 1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define _U_(a,m) (a)<=(1<<m)?m: 1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Round up logarithm to base 2 of a 16 bit constant. 1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define _LGRU16_(a) \ 1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds( \ 1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds _U_(a, 0)_U_(a, 1)_U_(a, 2)_U_(a, 3)_U_(a, 4)_U_(a, 5)_U_(a, 6)_U_(a, 7) \ 1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds _U_(a, 8)_U_(a, 9)_U_(a,10)_U_(a,11)_U_(a,12)_U_(a,13)_U_(a,14)_U_(a,15) \ 1881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16) 1891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* SYM_MISC_H */ 191