1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/*
* pt: Processor Type driver.
*
* Copyright (C) 1995, HD Associates, Inc.
* PO Box 276
* Pepperell, MA 01463
* 508 433 5266
* dufault@hda.com
*
* This code is contributed to the University of California at Berkeley:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: pt.c,v 1.15 1996/03/10 18:17:54 davidg Exp $
*/
/*
* XXX dufault@hda.com: We need the "kern devconf" stuff, but I'm not
* going to add it until it is done in a simple way that provides
* base behavior in scsi_driver.c
*/
#include "opt_bounce.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
#include <sys/proc.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#ifdef DEVFS
#include <sys/devfsext.h>
#endif /*DEVFS*/
#include <scsi/scsi_all.h>
#include <scsi/scsiconf.h>
struct scsi_data {
struct buf_queue_head buf_queue;
};
static d_open_t ptopen;
static d_close_t ptclose;
static d_ioctl_t ptioctl;
static d_strategy_t ptstrategy;
#define CDEV_MAJOR 61
static struct cdevsw pt_cdevsw =
{ ptopen, ptclose, rawread, rawwrite, /*61*/
ptioctl, nostop, nullreset, nodevtotty,/* pt */
seltrue, nommap, ptstrategy, "pt", NULL, -1 };
SCSI_DEVICE_ENTRIES(pt)
static void ptstart(u_int32_t unit, u_int32_t flags);
static void pt_strategy(struct buf *bp, struct scsi_link *sc_link);
static int pt_sense(struct scsi_xfer *scsi_xfer);
static struct scsi_device pt_switch =
{
pt_sense,
ptstart, /* we have a queue, and this is how we service it */
NULL,
NULL,
"pt",
0,
{0, 0},
SDEV_ONCE_ONLY, /* Only one open allowed */
0,
"Processor",
ptopen,
sizeof(struct scsi_data),
T_PROCESSOR,
0,
0,
0,
0,
0,
pt_strategy,
};
/*
* ptstart looks to see if there is a buf waiting for the device
* and that the device is not already busy. If both are true,
* It dequeues the buf and creates a scsi command to perform the
* transfer required. The transfer request will call scsi_done
* on completion, which will in turn call this routine again
* so that the next queued transfer is performed.
* The bufs are queued by the strategy routine (ptstrategy)
*
* This routine is also called after other non-queued requests
* have been made of the scsi driver, to ensure that the queue
* continues to be drained.
* ptstart() is called at splbio
*/
static void
ptstart(unit, flags)
u_int32_t unit;
u_int32_t flags;
{
struct scsi_link *sc_link = SCSI_LINK(&pt_switch, unit);
struct scsi_data *pt = sc_link->sd;
register struct buf *bp = 0;
struct
{
#define PROCESSOR_SEND 0x0A
#define PROCESSOR_RECEIVE 0x08
u_char op_code;
u_char byte2;
u_char len[3];
u_char control;
} cmd;
SC_DEBUG(sc_link, SDEV_DB2, ("ptstart "));
/*
* See if there is a buf to do and we are not already
* doing one
*/
while (sc_link->opennings != 0) {
/* if a special awaits, let it proceed first */
if (sc_link->flags & SDEV_WAITING) {
sc_link->flags &= ~SDEV_WAITING;
wakeup((caddr_t)sc_link);
return;
}
bp = pt->buf_queue.tqh_first;
if (bp == NULL) { /* yes, an assign */
return;
}
TAILQ_REMOVE( &pt->buf_queue, bp, b_act);
/*
* Fill out the scsi command
*/
bzero(&cmd, sizeof(cmd));
if ((bp->b_flags & B_READ) == B_WRITE) {
cmd.op_code = PROCESSOR_SEND;
flags |= SCSI_DATA_OUT;
} else {
cmd.op_code = PROCESSOR_RECEIVE;
flags |= SCSI_DATA_IN;
}
scsi_uto3b(bp->b_bcount, cmd.len);
/*
* go ask the adapter to do all this for us
*/
if (scsi_scsi_cmd(sc_link,
(struct scsi_generic *) &cmd,
sizeof(cmd),
(u_char *) bp->b_un.b_addr,
bp->b_bcount,
0,
10000,
bp,
flags) == SUCCESSFULLY_QUEUED) {
} else {
printf("pt%ld: oops not queued\n", unit);
bp->b_flags |= B_ERROR;
bp->b_error = EIO;
biodone(bp);
}
} /* go back and see if we can cram more work in.. */
}
static void
pt_strategy(struct buf *bp, struct scsi_link *sc_link)
{
unsigned char unit;
u_int32_t opri;
struct scsi_data *pt;
unit = minor((bp->b_dev));
pt = sc_link->sd;
opri = splbio();
/*
* Use a bounce buffer if necessary
*/
#ifdef BOUNCE_BUFFERS
if (sc_link->flags & SDEV_BOUNCE)
vm_bounce_alloc(bp);
#endif
/*
* Place it in the queue of activities for this tape
* at the end (a bit silly because we only have one user..
* (but it could fork() ))
*/
TAILQ_INSERT_TAIL( &pt->buf_queue, bp, b_act);
/*
* Tell the device to get going on the transfer if it's
* not doing anything, otherwise just wait for completion
* (All a bit silly if we're only allowing 1 open but..)
*/
ptstart(unit, 0);
splx(opri);
return;
}
/*
* sense handler: Called to determine what to do when the
* device returns a CHECK CONDITION.
*
* For the processor type devices we try to handle the "info" field.
*/
static int
pt_sense(struct scsi_xfer *xs)
{
struct scsi_sense_data *sense = &(xs->sense);
struct buf *bp;
long resid;
if ((sense->error_code & SSD_ERRCODE_VALID) == 0 ||
(sense->ext.extended.flags & SSD_ILI) == 0) {
return SCSIRET_CONTINUE; /* let the default handler handle it */
}
resid = ntohl(*((int32_t *) sense->ext.extended.info));
bp = xs->bp;
if (resid < 0) {
/* It synthesized data in order to fill our request.
* Move resid back to cover this.
*/
xs->resid = -resid;
xs->flags |= SCSI_RESID_VALID;
return 0;
}
else {
/* It wanted to send more data. We can't really do anything
* about this.
*/
return SCSIRET_CONTINUE;
}
}
static pt_devsw_installed = 0;
static void pt_drvinit(void *unused)
{
dev_t dev;
#ifdef DEVFS
int unit;
#endif
if( ! pt_devsw_installed ) {
dev = makedev(CDEV_MAJOR, 0);
cdevsw_add(&dev,&pt_cdevsw, NULL);
pt_devsw_installed = 1;
#ifdef DEVFS
/* XXX only 1 unit. */
for (unit = 0; unit < 1; unit++) {
/* XXX not saving tokens yet. */
devfs_add_devswf(&pt_cdevsw, unit, DV_CHR,
UID_ROOT, GID_WHEEL, 0600,
"pt%d", unit);
devfs_add_devswf(&pt_cdevsw, unit | SCSI_CONTROL_MASK,
DV_CHR,
UID_ROOT, GID_WHEEL, 0600,
"pt%d.ctl", unit);
}
#endif
}
}
SYSINIT(ptdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,pt_drvinit,NULL)
|