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
41 #include <dev/sym/sym_glue.h>
46 #ifdef SYM_OPT_HANDLE_IO_TIMEOUT
48 * Optional CCB timeout handling.
50 * This code is useful for O/Ses that allow or expect
51 * SIMs (low-level drivers) to handle SCSI IO timeouts.
52 * It uses a power-of-two based algorithm of my own:)
53 * that avoids scanning of lists, provided that:
55 * - The IO does complete in less than half the associated
57 * - The greatest delay between the queuing of the IO and
58 * its completion is less than
59 * (1<<(SYM_CONF_TIMEOUT_ORDER_MAX-1))/2 ticks.
61 * For example, if tick is 1 second and the max order is 8,
62 * any IO that is completed within less than 64 seconds will
63 * just be put into some list at queuing and be removed
64 * at completion without any additionnal overhead.
68 * Set a timeout condition on a CCB.
70 void sym_timeout_ccb(hcb_p np, ccb_p cp, u_int ticks)
72 sym_remque(&cp->tmo_linkq);
73 cp->tmo_clock = np->tmo_clock + ticks;
75 sym_insque_head(&cp->tmo_linkq, &np->tmo0_ccbq);
78 int i = SYM_CONF_TIMEOUT_ORDER_MAX - 1;
80 if (ticks >= (1<<(i+1)))
84 if (!(np->tmo_actq & (1<<i)))
85 i += SYM_CONF_TIMEOUT_ORDER_MAX;
86 sym_insque_head(&cp->tmo_linkq, &np->tmo_ccbq[i]);
91 * Walk a list of CCB and handle timeout conditions.
92 * Should never be called in normal situations.
94 static void sym_walk_ccb_tmo_list(hcb_p np, SYM_QUEHEAD *tmoq)
96 SYM_QUEHEAD qtmp, *qp;
99 sym_que_move(tmoq, &qtmp);
100 while ((qp = sym_remque_head(&qtmp)) != 0) {
101 sym_insque_head(qp, &np->tmo0_ccbq);
102 cp = sym_que_entry(qp, struct sym_ccb, tmo_linkq);
103 if (cp->tmo_clock != np->tmo_clock &&
104 cp->tmo_clock + 1 != np->tmo_clock)
105 sym_timeout_ccb(np, cp, cp->tmo_clock - np->tmo_clock);
107 sym_abort_ccb(np, cp, 1);
112 * Our clock handler called from the O/S specific side.
114 void sym_clock(hcb_p np)
120 tmp ^= (++np->tmo_clock);
122 for (i = 0; i < SYM_CONF_TIMEOUT_ORDER_MAX; i++, tmp >>= 1) {
126 if (np->tmo_actq & (1<<i))
127 j += SYM_CONF_TIMEOUT_ORDER_MAX;
129 if (!sym_que_empty(&np->tmo_ccbq[j])) {
130 sym_walk_ccb_tmo_list(np, &np->tmo_ccbq[j]);
132 np->tmo_actq ^= (1<<i);
135 #endif /* SYM_OPT_HANDLE_IO_TIMEOUT */
138 #ifdef SYM_OPT_ANNOUNCE_TRANSFER_RATE
140 * Announce transfer rate if anything changed since last announcement.
142 void sym_announce_transfer_rate(hcb_p np, int target)
144 tcb_p tp = &np->target[target];
146 #define __tprev tp->tinfo.prev
147 #define __tcurr tp->tinfo.curr
149 if (__tprev.options == __tcurr.options &&
150 __tprev.width == __tcurr.width &&
151 __tprev.offset == __tcurr.offset &&
152 !(__tprev.offset && __tprev.period != __tcurr.period))
155 __tprev.options = __tcurr.options;
156 __tprev.width = __tcurr.width;
157 __tprev.offset = __tcurr.offset;
158 __tprev.period = __tcurr.period;
160 if (__tcurr.offset && __tcurr.period) {
161 u_int period, f10, mb10;
164 period = f10 = mb10 = 0;
167 if (__tcurr.period <= 9) {
173 if (__tcurr.period <= 11) {
176 if (__tcurr.period == 11)
179 else if (__tcurr.period < 25) {
181 if (__tcurr.period == 12)
184 else if (__tcurr.period <= 50) {
188 period = 40 * __tcurr.period;
189 f10 = 100000 << (__tcurr.width ? 1 : 0);
190 mb10 = (f10 + period/2) / period;
193 "%s:%d: %s %sSCSI %d.%d MB/s %s%s%s (%d.%d ns, offset %d)\n",
194 sym_name(np), target, scsi, __tcurr.width? "WIDE " : "",
196 (__tcurr.options & PPR_OPT_DT) ? "DT" : "ST",
197 (__tcurr.options & PPR_OPT_IU) ? " IU" : "",
198 (__tcurr.options & PPR_OPT_QAS) ? " QAS" : "",
199 period/10, period%10, __tcurr.offset);
202 printf_info ("%s:%d: %sasynchronous.\n",
203 sym_name(np), target, __tcurr.width? "wide " : "");
207 #endif /* SYM_OPT_ANNOUNCE_TRANSFER_RATE */