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 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. The name of the author may not be used to endorse or promote products
31 * derived from this software without specific prior written permission.
33 * Where this Software is combined with software released under the terms of
34 * the GNU Public License ("GPL") and the terms of the GPL would require the
35 * combined work to also be released under the terms of the GPL, the terms
36 * and conditions of this License will apply in addition to those of the
37 * GPL with the exception of any terms or conditions of this License that
38 * conflict with, or are expressly prohibited by, the GPL.
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
44 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 #include <dev/sym/sym_glue.h>
59 #ifdef SYM_OPT_HANDLE_IO_TIMEOUT
61 * Optional CCB timeout handling.
63 * This code is useful for O/Ses that allow or expect
64 * SIMs (low-level drivers) to handle SCSI IO timeouts.
65 * It uses a power-of-two based algorithm of my own:)
66 * that avoids scanning of lists, provided that:
68 * - The IO does complete in less than half the associated
70 * - The greatest delay between the queuing of the IO and
71 * its completion is less than
72 * (1<<(SYM_CONF_TIMEOUT_ORDER_MAX-1))/2 ticks.
74 * For example, if tick is 1 second and the max order is 8,
75 * any IO that is completed within less than 64 seconds will
76 * just be put into some list at queuing and be removed
77 * at completion without any additionnal overhead.
81 * Set a timeout condition on a CCB.
83 void sym_timeout_ccb(hcb_p np, ccb_p cp, u_int ticks)
85 sym_remque(&cp->tmo_linkq);
86 cp->tmo_clock = np->tmo_clock + ticks;
88 sym_insque_head(&cp->tmo_linkq, &np->tmo0_ccbq);
91 int i = SYM_CONF_TIMEOUT_ORDER_MAX - 1;
93 if (ticks >= (1<<(i+1)))
97 if (!(np->tmo_actq & (1<<i)))
98 i += SYM_CONF_TIMEOUT_ORDER_MAX;
99 sym_insque_head(&cp->tmo_linkq, &np->tmo_ccbq[i]);
104 * Walk a list of CCB and handle timeout conditions.
105 * Should never be called in normal situations.
107 static void sym_walk_ccb_tmo_list(hcb_p np, SYM_QUEHEAD *tmoq)
109 SYM_QUEHEAD qtmp, *qp;
112 sym_que_move(tmoq, &qtmp);
113 while ((qp = sym_remque_head(&qtmp)) != 0) {
114 sym_insque_head(qp, &np->tmo0_ccbq);
115 cp = sym_que_entry(qp, struct sym_ccb, tmo_linkq);
116 if (cp->tmo_clock != np->tmo_clock &&
117 cp->tmo_clock + 1 != np->tmo_clock)
118 sym_timeout_ccb(np, cp, cp->tmo_clock - np->tmo_clock);
120 sym_abort_ccb(np, cp, 1);
125 * Our clock handler called from the O/S specific side.
127 void sym_clock(hcb_p np)
133 tmp ^= (++np->tmo_clock);
135 for (i = 0; i < SYM_CONF_TIMEOUT_ORDER_MAX; i++, tmp >>= 1) {
139 if (np->tmo_actq & (1<<i))
140 j += SYM_CONF_TIMEOUT_ORDER_MAX;
142 if (!sym_que_empty(&np->tmo_ccbq[j])) {
143 sym_walk_ccb_tmo_list(np, &np->tmo_ccbq[j]);
145 np->tmo_actq ^= (1<<i);
148 #endif /* SYM_OPT_HANDLE_IO_TIMEOUT */
151 #ifdef SYM_OPT_ANNOUNCE_TRANSFER_RATE
153 * Announce transfer rate if anything changed since last announcement.
155 void sym_announce_transfer_rate(hcb_p np, int target)
157 tcb_p tp = &np->target[target];
159 #define __tprev tp->tinfo.prev
160 #define __tcurr tp->tinfo.curr
162 if (__tprev.options == __tcurr.options &&
163 __tprev.width == __tcurr.width &&
164 __tprev.offset == __tcurr.offset &&
165 !(__tprev.offset && __tprev.period != __tcurr.period))
168 __tprev.options = __tcurr.options;
169 __tprev.width = __tcurr.width;
170 __tprev.offset = __tcurr.offset;
171 __tprev.period = __tcurr.period;
173 if (__tcurr.offset && __tcurr.period) {
174 u_int period, f10, mb10;
177 period = f10 = mb10 = 0;
180 if (__tcurr.period <= 9) {
186 if (__tcurr.period <= 11) {
189 if (__tcurr.period == 11)
192 else if (__tcurr.period < 25) {
194 if (__tcurr.period == 12)
197 else if (__tcurr.period <= 50) {
201 period = 40 * __tcurr.period;
202 f10 = 100000 << (__tcurr.width ? 1 : 0);
203 mb10 = (f10 + period/2) / period;
206 "%s:%d: %s %sSCSI %d.%d MB/s %s (%d.%d ns, offset %d)\n",
207 sym_name(np), target, scsi, __tcurr.width? "WIDE " : "",
209 (__tcurr.options & PPR_OPT_DT) ? "DT" : "ST",
210 period/10, period%10, __tcurr.offset);
213 printf_info ("%s:%d: %sasynchronous.\n",
214 sym_name(np), target, __tcurr.width? "wide " : "");
218 #endif /* SYM_OPT_ANNOUNCE_TRANSFER_RATE */