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-vms.c 1.33 04/01/15 Copyright 1997 J. Schilling */
15 * Interface for the VMS generic SCSI implementation.
17 * The idea for an elegant mapping to VMS device dontroller names
18 * is from Chip Dancy Chip.Dancy@hp.com. This allows up to
19 * 26 IDE controllers (DQ[A-Z][0-1]).
21 * This is a hack, that tries to emulate the functionality
24 * Warning: you may change this source, but if you do that
25 * you need to change the _usal_version and _usal_auth* string below.
26 * You may not return "schily" for an SCG_AUTHOR request anymore.
27 * Choose your name instead of "schily" and make clear that the version
28 * string is related to a modified source.
30 * Copyright (c) 1997 J. Schilling
33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License version 2
35 * as published by the Free Software Foundation.
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
42 * You should have received a copy of the GNU General Public License along with
43 * this program; see the file COPYING. If not, write to the Free Software
44 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
52 #include <LIB$ROUTINES.H>
55 * Warning: you may change this source, but if you do that
56 * you need to change the _usal_version and _usal_auth* string below.
57 * You may not return "schily" for an SCG_AUTHOR request anymore.
58 * Choose your name instead of "schily" and make clear that the version
59 * string is related to a modified source.
61 static char _usal_trans_version[] = "scsi-vms.c-1.33"; /* The version for this transport*/
63 #define VMS_MAX_DK 4 /* DK[A-D] VMS device controllers */
64 #define VMS_MAX_GK 4 /* GK[A-D] VMS device controllers */
65 #define VMS_MAX_DQ 26 /* DQ[A-Z] VMS device controllers */
67 #define VMS_DKRANGE_MAX VMS_MAX_DK
68 #define VMS_GKRANGE_MAX (VMS_DKRANGE_MAX + VMS_MAX_GK)
69 #define VMS_DQRANGE_MAX (VMS_GKRANGE_MAX + VMS_MAX_DQ)
71 #define MAX_SCG VMS_DQRANGE_MAX /* Max # of SCSI controllers */
75 #define MAX_DMA_VMS (63*1024) /* Check if this is not too big */
76 #define MAX_PHSTMO_VMS 300
77 #define MAX_DSCTMO_VMS ((64*1024)-1) /* max value for OpenVMS/AXP 7.1 ehh*/
80 * Define a mapping from the scsi busno to the three character
81 * VMS device controller.
82 * The valid busno values are broken into three ranges, one for each of
83 * the three supported devices: dk, gk, and dq.
84 * The vmschar[] and vmschar1[] arrays are subscripted by an offset
85 * corresponding to each of the three ranges [0,1,2] to provide the
86 * two characters of the VMS device.
87 * The offset of the busno value within its range is used to define the
88 * third character, using the vmschar2[] array.
90 static char vmschar[] = {'d', 'g', 'd'};
91 static char vmschar1[] = {'k', 'k', 'q'};
92 static char vmschar2[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
93 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
94 'u', 'v', 'w', 'x', 'y', 'z'};
97 static int do_usal_cmd(SCSI *usalp, struct usal_cmd *sp);
98 static int do_usal_sense(SCSI *usalp, struct usal_cmd *sp);
100 #define DEVICE_NAMELEN 8
103 Uint SCSI$L_OPCODE; /* SCSI Operation Code */
104 Uint SCSI$L_FLAGS; /* SCSI Flags Bit Map */
105 char *SCSI$A_CMD_ADDR; /* ->SCSI command buffer */
106 Uint SCSI$L_CMD_LEN; /* SCSI command length, bytes */
107 char *SCSI$A_DATA_ADDR; /* ->SCSI data buffer */
108 Uint SCSI$L_DATA_LEN; /* SCSI data length, bytes */
109 Uint SCSI$L_PAD_LEN; /* SCSI pad length, bytes */
110 Uint SCSI$L_PH_CH_TMOUT; /* SCSI phase change timeout */
111 Uint SCSI$L_DISCON_TMOUT; /* SCSI disconnect timeout */
112 Uint SCSI$L_RES_1; /* Reserved */
113 Uint SCSI$L_RES_2; /* Reserved */
114 Uint SCSI$L_RES_3; /* Reserved */
115 Uint SCSI$L_RES_4; /* Reserved */
116 Uint SCSI$L_RES_5; /* Reserved */
117 Uint SCSI$L_RES_6; /* Reserved */
121 #pragma member_alignment save
122 #pragma nomember_alignment
126 Ushort SCSI$W_VMS_STAT; /* VMS status code */
127 Ulong SCSI$L_IOSB_TFR_CNT; /* Actual #bytes transferred */
128 char SCSI$B_IOSB_FILL_1;
129 Uchar SCSI$B_IOSB_STS; /* SCSI device status */
133 #pragma member_alignment restore
136 #define SCSI$K_GOOD_STATUS 0
137 #define SCSI$K_CHECK_CONDITION 0x2
138 #define SCSI$K_CONDITION_MET 0x4
139 #define SCSI$K_BUSY 0x8
140 #define SCSI$K_INTERMEDIATE 0x10
141 #define SCSI$K_INTERMEDIATE_C_MET 0x14
142 #define SCSI$K_RESERVATION_CONFLICT 0x18
143 #define SCSI$K_COMMAND_TERMINATED 0x22
144 #define SCSI$K_QUEUE_FULL 0x28
147 #define SCSI$K_WRITE 0X0 /* direction of transfer=write */
148 #define SCSI$K_READ 0X1 /* direction of transfer=read */
149 #define SCSI$K_FL_ENAB_DIS 0X2 /* enable disconnects */
150 #define SCSI$K_FL_ENAB_SYNC 0X4 /* enable sync */
151 #define GK_EFN 0 /* Event flag number */
153 static char gk_device[8]; /* XXX JS hoffentlich gibt es keinen Ueberlauf */
154 static Ushort gk_chan;
155 static Ushort transfer_length;
158 static $DESCRIPTOR(gk_device_desc, gk_device);
159 static struct SCSI$IOSB gk_iosb;
160 static struct SCSI$DESC gk_desc;
167 #define usallocal(p) ((struct usal_local *)((p)->local))
170 * Return version information for the low level SCSI transport code.
171 * This has been introduced to make it easier to trace down problems
175 usalo_version(SCSI *usalp, int what)
177 if (usalp != (SCSI *)0) {
181 return (_usal_trans_version);
183 * If you changed this source, you are not allowed to
184 * return "schily" for the SCG_AUTHOR request.
187 return (_usal_auth_cdrkit);
196 usalo_help(SCSI *usalp, FILE *f)
198 __usal_help(f, "IO$_DIAGNOSE", "Generic SCSI",
199 "", "bus,target,lun", "1,2,0", FALSE, FALSE);
204 usalo_open(SCSI *usalp, char *device)
206 int busno = usal_scsibus(usalp);
207 int tgt = usal_target(usalp);
208 int tlun = usal_lun(usalp);
209 char devname[DEVICE_NAMELEN];
216 if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN) {
219 snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
220 "Illegal value for busno, target or lun '%d,%d,%d'",
225 if ((device != NULL && *device != '\0') || (busno == -2 && tgt == -2)) {
228 snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
229 "Open by 'devname' not supported on this OS");
232 if (busno < 0 || tgt < 0 || tlun < 0) {
234 * There is no real reason why we cannot scan on VMS,
235 * but for now it is not possible.
238 snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
239 "Unable to scan on VMS");
243 if (usalp->local == NULL) {
244 usalp->local = malloc(sizeof (struct usal_local));
245 if (usalp->local == NULL)
249 if (busno < VMS_DKRANGE_MAX) { /* in the dk range? */
251 range_offset = busno;
252 } else if (busno < VMS_GKRANGE_MAX) { /* in the gk range? */
254 range_offset = busno - VMS_DKRANGE_MAX;
255 } else if (busno < VMS_DQRANGE_MAX) { /* in the dq range? */
257 range_offset = busno - VMS_GKRANGE_MAX;
259 buschar = vmschar[range]; /* get first device char*/
260 buschar1 = vmschar1[range]; /* get 2nd device char*/
261 buschar2 = vmschar2[range_offset]; /* get controller char*/
263 snprintf(devname, sizeof (devname), "%c%c%c%d0%d:",
264 buschar, buschar1, buschar2,
266 strcpy(gk_device, devname);
267 status = sys$assign(&gk_device_desc, &gk_chan, 0, 0);
269 fprintf((FILE *)usalp->errfile,
270 "Unable to access scsi-device \"%s\"\n", &gk_device[0]);
273 if (usalp->debug > 0) {
274 fp = fopen("cdrecord_io.log", "w", "rfm=stmlf", "rat=cr");
276 perror("Failing opening i/o-logfile");
284 usalo_close(SCSI *usalp)
287 * XXX close gk_chan ???
293 status = sys$dassgn(gk_chan);
299 usalo_maxdma(SCSI *usalp, long amt)
301 return (MAX_DMA_VMS);
305 usalo_havebus(SCSI *usalp, int busno)
313 usalo_fileno(SCSI *usalp, int busno, int tgt, int tlun)
321 usalo_initiator_id(SCSI *usalp)
327 usalo_isatapi(SCSI *usalp)
329 int busno = usal_scsibus(usalp);
338 usalo_reset(SCSI *usalp, int what)
345 usalo_getbuf(SCSI *usalp, long amt)
347 if (usalp->debug > 0) {
348 fprintf((FILE *)usalp->errfile,
349 "usalo_getbuf: %ld bytes\n", amt);
351 usalp->bufbase = malloc((size_t)(amt)); /* XXX JS XXX valloc() ??? */
352 return (usalp->bufbase);
356 usalo_freebuf(SCSI *usalp)
359 free(usalp->bufbase);
360 usalp->bufbase = NULL;
364 do_usal_cmd(SCSI *usalp, struct usal_cmd *sp)
372 /* XXX JS XXX This cannot be OK */
373 notcmdretry = (sp->flags & SCG_CMD_RETRY)^SCG_CMD_RETRY;
374 /* error corrected ehh */
376 * XXX JS Wenn das notcmdretry Flag bei VMS auch 0x08 ist und Du darauf hoffst,
377 * XXX Dasz ich den Wert nie aendere, dann ist das richtig.
378 * XXX Siehe unten: Das gleiche gilt fuer SCG_RECV_DATA und SCG_DISRE_ENA !!!
381 cmdadr = (char *)sp->cdb.cmd_cdb;
382 /* XXX JS XXX This cannot be OK */
383 gk_desc.SCSI$L_FLAGS = ((sp->flags & SCG_RECV_DATA) |
384 (sp->flags & SCG_DISRE_ENA)|
386 /* XXX siehe oben, das ist ein bitweises oder!!! */
387 gk_desc.SCSI$A_DATA_ADDR = sp->addr;
388 gk_desc.SCSI$L_DATA_LEN = sp->size;
389 gk_desc.SCSI$A_CMD_ADDR = cmdadr;
390 gk_desc.SCSI$L_CMD_LEN = sp->cdb_len;
391 gk_desc.SCSI$L_PH_CH_TMOUT = sp->timeout;
392 gk_desc.SCSI$L_DISCON_TMOUT = sp->timeout;
393 if (gk_desc.SCSI$L_PH_CH_TMOUT > MAX_PHSTMO_VMS)
394 gk_desc.SCSI$L_PH_CH_TMOUT = MAX_PHSTMO_VMS;
395 if (gk_desc.SCSI$L_DISCON_TMOUT > MAX_DSCTMO_VMS)
396 gk_desc.SCSI$L_DISCON_TMOUT = MAX_DSCTMO_VMS;
397 gk_desc.SCSI$L_OPCODE = 1; /* SCSI Operation Code */
398 gk_desc.SCSI$L_PAD_LEN = 0; /* SCSI pad length, bytes */
399 gk_desc.SCSI$L_RES_1 = 0; /* Reserved */
400 gk_desc.SCSI$L_RES_2 = 0; /* Reserved */
401 gk_desc.SCSI$L_RES_3 = 0; /* Reserved */
402 gk_desc.SCSI$L_RES_4 = 0; /* Reserved */
403 gk_desc.SCSI$L_RES_5 = 0; /* Reserved */
404 gk_desc.SCSI$L_RES_6 = 0; /* Reserved */
405 if (usalp->debug > 0) {
406 fprintf(fp, "***********************************************************\n");
407 fprintf(fp, "SCSI VMS-I/O parameters\n");
408 fprintf(fp, "OPCODE: %d", gk_desc.SCSI$L_OPCODE);
409 fprintf(fp, " FLAGS: %d\n", gk_desc.SCSI$L_FLAGS);
411 for (i = 0; i < gk_desc.SCSI$L_CMD_LEN; i++) {
412 fprintf(fp, "%x ", sp->cdb.cmd_cdb[i]);
415 fprintf(fp, "DATA_LEN: %d\n", gk_desc.SCSI$L_DATA_LEN);
416 fprintf(fp, "PH_CH_TMOUT: %d", gk_desc.SCSI$L_PH_CH_TMOUT);
417 fprintf(fp, " DISCON_TMOUT: %d\n", gk_desc.SCSI$L_DISCON_TMOUT);
419 status = sys$qiow(GK_EFN, gk_chan, IO$_DIAGNOSE, &gk_iosb, 0, 0,
420 &gk_desc, sizeof (gk_desc), 0, 0, 0, 0);
423 if (usalp->debug > 0) {
424 fprintf(fp, "qiow-status: %i\n", status);
425 fprintf(fp, "VMS status code %i\n", gk_iosb.SCSI$W_VMS_STAT);
426 fprintf(fp, "Actual #bytes transferred %i\n", gk_iosb.SCSI$L_IOSB_TFR_CNT);
427 fprintf(fp, "SCSI device status %i\n", gk_iosb.SCSI$B_IOSB_STS);
428 if (gk_iosb.SCSI$L_IOSB_TFR_CNT != gk_desc.SCSI$L_DATA_LEN) {
429 fprintf(fp, "#bytes transferred != DATA_LEN\n");
433 if (!(status & 1)) { /* Fehlerindikation fuer sys$qiow() */
434 sp->ux_errno = geterrno();
435 /* schwerwiegender nicht SCSI bedingter Fehler => return (-1) */
436 if (sp->ux_errno == ENOTTY || sp->ux_errno == ENXIO ||
437 sp->ux_errno == EINVAL || sp->ux_errno == EACCES) {
440 if (sp->ux_errno == 0)
446 sp->resid = gk_desc.SCSI$L_DATA_LEN - gk_iosb.SCSI$L_IOSB_TFR_CNT;
448 if (usalo_isatapi(usalp)) {
449 scsi_sts = ((gk_iosb.SCSI$B_IOSB_STS >> 4) & 0x7);
451 scsi_sts = gk_iosb.SCSI$B_IOSB_STS;
454 if (gk_iosb.SCSI$W_VMS_STAT == SS$_NORMAL && scsi_sts == 0) {
455 sp->error = SCG_NO_ERROR;
456 if (usalp->debug > 0) {
457 fprintf(fp, "scsi_sts == 0\n");
458 fprintf(fp, "gk_iosb.SCSI$B_IOSB_STS == 0\n");
459 fprintf(fp, "sp->error %i\n", sp->error);
460 fprintf(fp, "sp->resid %i\n", sp->resid);
465 severity = gk_iosb.SCSI$W_VMS_STAT & 0x7;
468 sp->error = SCG_FATAL;
469 if (usalp->debug > 0) {
470 fprintf(fp, "scsi_sts & 2\n");
471 fprintf(fp, "gk_iosb.SCSI$B_IOSB_STS & 2\n");
472 fprintf(fp, "gk_iosb.SCSI$W_VMS_STAT & 0x7 == SS$_FATAL\n");
473 fprintf(fp, "sp->error %i\n", sp->error);
477 if (gk_iosb.SCSI$W_VMS_STAT == SS$_TIMEOUT) {
478 sp->error = SCG_TIMEOUT;
479 if (usalp->debug > 0) {
480 fprintf(fp, "scsi_sts & 2\n");
481 fprintf(fp, "gk_iosb.SCSI$B_IOSB_STS & 2\n");
482 fprintf(fp, "gk_iosb.SCSI$W_VMS_STAT == SS$_TIMEOUT\n");
483 fprintf(fp, "sp->error %i\n", sp->error);
487 sp->error = SCG_RETRYABLE;
488 sp->u_scb.cmd_scb[0] = scsi_sts;
489 if (usalp->debug > 0) {
490 fprintf(fp, "scsi_sts & 2\n");
491 fprintf(fp, "gk_iosb.SCSI$B_IOSB_STS & 2\n");
492 fprintf(fp, "gk_iosb.SCSI$W_VMS_STAT != 0\n");
493 fprintf(fp, "sp->error %i\n", sp->error);
499 do_usal_sense(SCSI *usalp, struct usal_cmd *sp)
502 struct usal_cmd s_cmd;
504 fillbytes((caddr_t)&s_cmd, sizeof (s_cmd), '\0');
505 s_cmd.addr = (char *)sp->u_sense.cmd_sense;
506 s_cmd.size = sp->sense_len;
507 s_cmd.flags = SCG_RECV_DATA|SCG_DISRE_ENA;
508 s_cmd.cdb_len = SC_G0_CDBLEN;
509 s_cmd.sense_len = CCS_SENSE_LEN;
510 s_cmd.cdb.g0_cdb.cmd = SC_REQUEST_SENSE;
511 s_cmd.cdb.g0_cdb.lun = sp->cdb.g0_cdb.lun;
512 s_cmd.cdb.g0_cdb.count = sp->sense_len;
513 ret = do_usal_cmd(usalp, &s_cmd);
517 if (s_cmd.u_scb.cmd_scb[0] & 02) {
518 /* XXX ??? Check condition on request Sense ??? */
520 sp->sense_count = sp->sense_len - s_cmd.resid;
525 usalo_send(SCSI *usalp)
527 struct usal_cmd *sp = usalp->scmd;
531 sp->error = SCG_FATAL;
534 ret = do_usal_cmd(usalp, sp);
537 if (sp->u_scb.cmd_scb[0] & 02)
538 ret = do_usal_sense(usalp, sp);