|
|
1.1 root 1: /*
2: * Copyright (c) 1988 University of Utah.
3: * Copyright (c) 1990 The Regents of the University of California.
4: * All rights reserved.
5: *
6: * This code is derived from software contributed to Berkeley by
7: * Van Jacobson of Lawrence Berkeley Laboratory and the Systems
8: * Programming Group of the University of Utah Computer Science Department.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
20: * This product includes software developed by the University of
21: * California, Berkeley and its contributors.
22: * 4. Neither the name of the University nor the names of its contributors
23: * may be used to endorse or promote products derived from this software
24: * without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36: * SUCH DAMAGE.
37: *
38: * from: Utah $Hdr: sd.c 1.2 90/01/23$
39: *
1.1.1.2 ! root 40: * from: @(#)sd.c 7.4 (Berkeley) 5/5/91
! 41: * sd.c,v 1.2 1993/05/22 07:59:23 cgd Exp
1.1 root 42: */
43:
44: /*
45: * SCSI CCS disk driver
46: */
47:
48: #include <sys/param.h>
49: #include "saio.h"
50: #include "samachdep.h"
51:
52: #include "../dev/scsireg.h"
53:
54: struct sd_softc {
55: char sc_retry;
56: char sc_alive;
57: short sc_blkshift;
58: } sd_softc[NSD];
59:
60: int sdpartoff[] = {
61: 1024, 17408, 0, 17408,
62: 115712, 218112, 82944, 0
63: };
64:
65: #define SDRETRY 2
66:
67: sdinit(unit)
68: register int unit;
69: {
70: register struct sd_softc *ss;
71: u_char stat;
72: int capbuf[2];
73:
74: if (unit > NSD)
75: return (0);
76: ss = &sd_softc[unit];
77: /* NB: HP6300 won't boot if next printf is removed (???) - vj */
78: printf("sd%d: ", unit);
79: if ((stat = scsi_test_unit_rdy(unit)) == 0) {
80: /* drive may be doing RTZ - wait a bit */
81: printf("not ready - retrying ... ");
82: if (stat == STS_CHECKCOND) {
83: DELAY(1000000);
84: if (scsi_test_unit_rdy(unit) == 0) {
85: printf("giving up.\n");
86: return (0);
87: }
88: }
89: }
90: printf("unit ready.\n");
91: /*
92: * try to get the drive block size.
93: */
94: capbuf[0] = 0;
95: capbuf[1] = 0;
96: if (scsi_read_capacity(unit, (u_char *)capbuf, sizeof(capbuf)) != 0) {
97: if (capbuf[1] > DEV_BSIZE)
98: for (; capbuf[1] > DEV_BSIZE; capbuf[1] >>= 1)
99: ++ss->sc_blkshift;
100: }
101: ss->sc_alive = 1;
102: return (1);
103: }
104:
105: sdreset(unit)
106: {
107: }
108:
109: sdopen(io)
110: struct iob *io;
111: {
112: register int unit = io->i_unit;
113: register struct sd_softc *ss = &sd_softc[unit];
114: struct sdinfo *ri;
115:
116: if (scsialive(unit) == 0)
117: _stop("scsi controller not configured");
118: if (ss->sc_alive == 0)
119: if (sdinit(unit) == 0)
120: _stop("sd init failed");
121: if (io->i_boff < 0 || io->i_boff > 7)
122: _stop("sd bad minor");
123: io->i_boff = sdpartoff[io->i_boff];
124: }
125:
126: sdstrategy(io, func)
127: register struct iob *io;
128: register int func;
129: {
130: register int unit = io->i_unit;
131: register struct sd_softc *ss = &sd_softc[unit];
132: char stat;
133: daddr_t blk = io->i_bn >> ss->sc_blkshift;
134: u_int nblk = io->i_cc >> ss->sc_blkshift;
135:
136: ss->sc_retry = 0;
137: retry:
138: if (func == F_READ)
139: stat = scsi_tt_read(unit, io->i_ma, io->i_cc, blk, nblk);
140: else
141: stat = scsi_tt_write(unit, io->i_ma, io->i_cc, blk, nblk);
142: if (stat) {
143: printf("sd(%d,?) err: 0x%x\n", unit, stat);
144: if (++ss->sc_retry > SDRETRY)
145: return(-1);
146: else
147: goto retry;
148: }
149: return(io->i_cc);
150: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.