1
/* @(#)scsi-qnx.c 1.3 04/01/15 Copyright 1998-2003 J. Schilling */
3
static char __sccsid[] =
4
"@(#)scsi-qnx.c 1.3 04/01/15 Copyright 1998-2003 J. Schilling";
7
* Interface for QNX (Neutrino generic SCSI implementation).
8
* First version adopted from the OSF-1 version by
9
* Kevin Chiles <kchiles@qnx.com>
11
* Warning: you may change this source, but if you do that
12
* you need to change the _scg_version and _scg_auth* string below.
13
* You may not return "schily" for an SCG_AUTHOR request anymore.
14
* Choose your name instead of "schily" and make clear that the version
15
* string is related to a modified source.
17
* Copyright (c) 1998-2003 J. Schilling
20
* This program is free software; you can redistribute it and/or modify
21
* it under the terms of the GNU General Public License as published by
22
* the Free Software Foundation; either version 2, or (at your option)
25
* This program is distributed in the hope that it will be useful,
26
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
* GNU General Public License for more details.
30
* You should have received a copy of the GNU General Public License along with
31
* this program; see the file COPYING. If not, write to the Free Software
32
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36
#include <sys/types.h>
37
#include <sys/dcmd_cam.h>
38
#include <sys/cam_device.h>
41
* Warning: you may change this source, but if you do that
42
* you need to change the _scg_version and _scg_auth* string below.
43
* You may not return "schily" for an SCG_AUTHOR request anymore.
44
* Choose your name instead of "schily" and make clear that the version
45
* string is related to a modified source.
47
LOCAL char _scg_trans_version[] = "scsi-qnx.c-1.3"; /* The version for this transport*/
49
#define MAX_SCG 16 /* Max # of SCSI controllers */
57
#define scglocal(p) ((struct scg_local *)((p)->local))
58
#define QNX_CAM_MAX_DMA (32*1024)
60
#ifndef AUTO_SENSE_LEN
61
# define AUTO_SENSE_LEN 32 /* SCG_MAX_SENSE */
65
* Return version information for the low level SCSI transport code.
66
* This has been introduced to make it easier to trace down problems
70
scgo_version(scgp, what)
74
if (scgp != (SCSI *)0) {
78
return (_scg_trans_version);
80
* If you changed this source, you are not allowed to
81
* return "schily" for the SCG_AUTHOR request.
84
return ("Initial Version adopted from OSF-1 by QNX-people");
85
return (_scg_auth_schily);
98
__scg_help(f, "CAM", "Generic transport independent SCSI (Common Access Method)",
99
"", "bus,target,lun", "1,2,0", TRUE, FALSE);
104
scgo_open(scgp, device)
110
if (device == NULL || *device == '\0') {
113
js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
114
"'devname' must be specified on this OS");
118
if (scgp->local == NULL) {
119
scgp->local = malloc(sizeof (struct scg_local));
120
if (scgp->local == NULL)
122
scglocal(scgp)->fd = -1;
125
if (scglocal(scgp)->fd != -1) /* multiple open? */
128
if ((scglocal(scgp)->fd = open(device, O_RDONLY, 0)) < 0) {
130
js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
131
"Cannot open '%s'", device);
135
scg_settarget(scgp, 0, 0, 0);
144
if (scgp->local == NULL)
147
if (scglocal(scgp)->fd >= 0)
148
close(scglocal(scgp)->fd);
149
scglocal(scgp)->fd = -1;
154
scgo_maxdma(scgp, amt)
158
long maxdma = QNX_CAM_MAX_DMA;
164
scgo_getbuf(scgp, amt)
170
if (scgp->debug > 0) {
171
js_fprintf((FILE *)scgp->errfile, "scgo_getbuf: %ld bytes\n", amt);
174
if ((addr = mmap(NULL, amt, PROT_READ | PROT_WRITE | PROT_NOCACHE,
175
MAP_ANON | MAP_PHYS | MAP_NOX64K, NOFD, 0)) == MAP_FAILED) {
179
scgp->bufbase = addr;
188
munmap(scgp->bufbase, QNX_CAM_MAX_DMA);
189
scgp->bufbase = NULL;
193
scgo_havebus(scgp, busno)
202
scgo_fileno(scgp, busno, tgt, tlun)
208
if (scgp->local == NULL)
211
return ((busno < 0 || busno >= MAX_SCG) ? -1 : scglocal(scgp)->fd);
215
scgo_initiator_id(scgp)
227
if (devctl(scgp->fd, DCMD_CAM_DEVINFO, &cinfo, sizeof (cinfo), NULL) != EOK) {
228
return (TRUE); /* default to ATAPI */
230
return ((cinfo.flags & DEV_ATAPI) ? TRUE : FALSE);
234
scgo_reset(scgp, what)
255
sp->error = SCG_FATAL;
259
memset(&cpt, 0, sizeof (cpt));
263
sp->error = SCG_NO_ERROR;
264
cpt.cam_timeout = sp->timeout;
265
cpt.cam_cdb_len = sp->cdb_len;
266
memcpy(cpt.cam_cdb, sp->cdb.cmd_cdb, sp->cdb_len);
268
if (sp->sense_len != -1) {
269
cpt.cam_sense_len = sp->sense_len;
270
cpt.cam_sense_ptr = sizeof (cpt); /* XXX Offset from start of struct to data ??? */
273
cpt.cam_flags |= CAM_DIS_AUTOSENSE;
276
if (cpt.cam_dxfer_len = sp->size) {
278
cpt.cam_data_ptr = (paddr_t)sizeof (cpt) + cpt.cam_sense_len;
279
if (sp->flags & SCG_RECV_DATA) {
280
cpt.cam_flags |= CAM_DIR_IN;
282
cpt.cam_flags |= CAM_DIR_OUT;
285
cpt.cam_flags |= CAM_DIR_NONE;
288
SETIOV(&iov[0], &cpt, sizeof (cpt));
289
SETIOV(&iov[1], sp->u_sense.cmd_sense, cpt.cam_sense_len);
290
SETIOV(&iov[2], sp->addr, sp->size);
291
if (devctlv(scglocal(scgp)->fd, DCMD_CAM_PASS_THRU, icnt, icnt, iov, iov, NULL)) {
292
sp->ux_errno = geterrno();
293
sp->error = SCG_FATAL;
294
if (scgp->debug > 0) {
295
errmsg("cam_io failed\n");
300
sp->resid = cpt.cam_resid;
301
sp->u_scb.cmd_scb[0] = cpt.cam_scsi_status;
303
switch (cpt.cam_status & CAM_STATUS_MASK) {
307
case CAM_SEL_TIMEOUT:
308
sp->error = SCG_FATAL;
312
case CAM_CMD_TIMEOUT:
313
sp->error = SCG_TIMEOUT;
318
sp->error = SCG_RETRYABLE;
323
if (cpt.cam_status & CAM_AUTOSNS_VALID) {
324
sp->sense_count = min(cpt.cam_sense_len - cpt.cam_sense_resid,
326
sp->sense_count = min(sp->sense_count, sp->sense_len);
327
if (sp->sense_len < 0)