2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)scsi-hpux.c 1.31 04/01/15 Copyright 1997 J. Schilling */
15 * Interface for the HP-UX generic SCSI implementation.
17 * Warning: you may change this source, but if you do that
18 * you need to change the _usal_version and _usal_auth* string below.
19 * You may not return "schily" for an SCG_AUTHOR request anymore.
20 * Choose your name instead of "schily" and make clear that the version
21 * string is related to a modified source.
23 * Copyright (c) 1997 J. Schilling
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License version 2
28 * as published by the Free Software Foundation.
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 along with
36 * this program; see the file COPYING. If not, write to the Free Software
37 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
44 * Warning: you may change this source, but if you do that
45 * you need to change the _usal_version and _usal_auth* string below.
46 * You may not return "schily" for an SCG_AUTHOR request anymore.
47 * Choose your name instead of "schily" and make clear that the version
48 * string is related to a modified source.
50 static char _usal_trans_version[] = "scsi-hpux.c-1.31"; /* The version for this transport*/
52 #define MAX_SCG 16 /* Max # of SCSI controllers */
57 short usalfiles[MAX_SCG][MAX_TGT][MAX_LUN];
59 #define usallocal(p) ((struct usal_local *)((p)->local))
62 # define MAX_DMA_HP SCSI_MAXPHYS
64 # define MAX_DMA_HP (63*1024) /* Check if this is not too big */
69 * Return version information for the low level SCSI transport code.
70 * This has been introduced to make it easier to trace down problems
74 usalo_version(SCSI *usalp, int what)
76 if (usalp != (SCSI *)0) {
80 return (_usal_trans_version);
82 * If you changed this source, you are not allowed to
83 * return "schily" for the SCG_AUTHOR request.
86 return (_usal_auth_cdrkit);
95 usalo_help(SCSI *usalp, FILE *f)
97 __usal_help(f, "SIOC", "Generic SCSI",
98 "", "bus,target,lun", "1,2,0", TRUE, FALSE);
103 usalo_open(SCSI *usalp, char *device)
105 int busno = usal_scsibus(usalp);
106 int tgt = usal_target(usalp);
107 int tlun = usal_lun(usalp);
112 register int nopen = 0;
115 if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN) {
118 snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
119 "Illegal value for busno, target or lun '%d,%d,%d'",
124 if ((device != NULL && *device != '\0') || (busno == -2 && tgt == -2)) {
127 snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
128 "Open by 'devname' not supported on this OS");
132 if (usalp->local == NULL) {
133 usalp->local = malloc(sizeof (struct usal_local));
134 if (usalp->local == NULL)
137 for (b = 0; b < MAX_SCG; b++) {
138 for (t = 0; t < MAX_TGT; t++) {
139 for (l = 0; l < MAX_LUN; l++)
140 usallocal(usalp)->usalfiles[b][t][l] = (short)-1;
145 if (busno >= 0 && tgt >= 0 && tlun >= 0) {
147 snprintf(devname, sizeof (devname),
148 "/dev/rscsi/c%xt%xl%x", busno, tgt, tlun);
149 f = open(devname, O_RDWR);
152 usallocal(usalp)->usalfiles[busno][tgt][tlun] = f;
155 for (b = 0; b < MAX_SCG; b++) {
156 for (t = 0; t < MAX_TGT; t++) {
157 /* for (l = 0; l < MAX_LUN; l++) {*/
158 for (l = 0; l < 1; l++) {
159 snprintf(devname, sizeof (devname),
160 "/dev/rscsi/c%xt%xl%x", b, t, l);
161 /*fprintf(stderr, "name: '%s'\n", devname);*/
162 f = open(devname, O_RDWR);
164 usallocal(usalp)->usalfiles[b][t][l] = (short)f;
166 } else if (usalp->debug > 0) {
167 errmsg("open '%s'\n", devname);
177 usalo_close(SCSI *usalp)
184 if (usalp->local == NULL)
187 for (b = 0; b < MAX_SCG; b++) {
188 for (t = 0; t < MAX_TGT; t++) {
189 for (l = 0; l < MAX_LUN; l++) {
190 f = usallocal(usalp)->usalfiles[b][t][l];
193 usallocal(usalp)->usalfiles[b][t][l] = (short)-1;
201 usalo_maxdma(SCSI *usalp, long amt)
207 usalo_getbuf(SCSI *usalp, long amt)
209 if (usalp->debug > 0) {
210 fprintf((FILE *)usalp->errfile,
211 "usalo_getbuf: %ld bytes\n", amt);
213 usalp->bufbase = valloc((size_t)(amt));
214 return (usalp->bufbase);
218 usalo_freebuf(SCSI *usalp)
221 free(usalp->bufbase);
222 usalp->bufbase = NULL;
226 usalo_havebus(SCSI *usalp, int busno)
231 if (busno < 0 || busno >= MAX_SCG)
234 if (usalp->local == NULL)
237 for (t = 0; t < MAX_TGT; t++) {
238 for (l = 0; l < MAX_LUN; l++)
239 if (usallocal(usalp)->usalfiles[busno][t][l] >= 0)
246 usalo_fileno(SCSI *usalp, int busno, int tgt, int tlun)
248 if (busno < 0 || busno >= MAX_SCG ||
249 tgt < 0 || tgt >= MAX_TGT ||
250 tlun < 0 || tlun >= MAX_LUN)
253 if (usalp->local == NULL)
256 return ((int)usallocal(usalp)->usalfiles[busno][tgt][tlun]);
260 usalo_initiator_id(SCSI *usalp)
266 usalo_isatapi(SCSI *usalp)
272 usalo_reset(SCSI *usalp, int what)
274 if (what == SCG_RESET_NOP)
276 if (what != SCG_RESET_BUS) {
280 return (ioctl(usalp->fd, SIOC_RESET_BUS, 0));
284 usalo_send(SCSI *usalp)
286 struct usal_cmd *sp = usalp->scmd;
289 struct sctl_io sctl_io;
291 if ((usalp->fd < 0) || (sp->cdb_len > sizeof (sctl_io.cdb))) {
292 sp->error = SCG_FATAL;
296 fillbytes((caddr_t)&sctl_io, sizeof (sctl_io), '\0');
299 /* flags = SCTL_INIT_WDTR|SCTL_INIT_SDTR;*/
300 if (sp->flags & SCG_RECV_DATA)
302 if ((sp->flags & SCG_DISRE_ENA) == 0)
303 flags |= SCTL_NO_ATN;
305 sctl_io.flags = flags;
307 movebytes(&sp->cdb, sctl_io.cdb, sp->cdb_len);
308 sctl_io.cdb_length = sp->cdb_len;
310 sctl_io.data_length = sp->size;
311 sctl_io.data = sp->addr;
313 if (sp->timeout == 0)
314 sctl_io.max_msecs = 0;
316 sctl_io.max_msecs = (sp->timeout * 1000) + 500;
319 sp->error = SCG_NO_ERROR;
321 sp->u_scb.cmd_scb[0] = 0;
324 ret = ioctl(usalp->fd, SIOC_IO, &sctl_io);
326 sp->error = SCG_FATAL;
327 sp->ux_errno = errno;
330 if (usalp->debug > 0)
331 fprintf(stderr, "cdb_status: %X, size: %d xfer: %d\n", sctl_io.cdb_status, sctl_io.data_length, sctl_io.data_xfer);
333 if (sctl_io.cdb_status == 0 || sctl_io.cdb_status == 0x02)
334 sp->resid = sp->size - sctl_io.data_xfer;
336 if (sctl_io.cdb_status & SCTL_SELECT_TIMEOUT ||
337 sctl_io.cdb_status & SCTL_INVALID_REQUEST) {
338 sp->error = SCG_FATAL;
339 } else if (sctl_io.cdb_status & SCTL_INCOMPLETE) {
340 sp->error = SCG_TIMEOUT;
341 } else if (sctl_io.cdb_status > 0xFF) {
342 errmsgno(EX_BAD, "SCSI problems: cdb_status: %X\n", sctl_io.cdb_status);
344 } else if ((sctl_io.cdb_status & 0xFF) != 0) {
345 sp->error = SCG_RETRYABLE;
348 sp->u_scb.cmd_scb[0] = sctl_io.cdb_status & 0xFF;
350 sp->sense_count = sctl_io.sense_xfer;
351 if (sp->sense_count > SCG_MAX_SENSE)
352 sp->sense_count = SCG_MAX_SENSE;
354 if (sctl_io.sense_status != S_GOOD) {
357 movebytes(sctl_io.sense, sp->u_sense.cmd_sense, sp->sense_count);
363 #define sense u_sense.Sense