* SCSI CAM driver and ioctls
@ 1995-06-06 4:00 Oleg V.Solovyanov, IHEP
1995-06-08 4:00 ` Alan Rollow - Dr. File System's Home for Wayward Inodes.
0 siblings, 1 reply; 2+ messages in thread
From: Oleg V.Solovyanov, IHEP @ 1995-06-06 4:00 UTC (permalink / raw)
Hello all !
First about the problem:
1. I have PDS5000/33 with Ultrix 4.4 and SCSI CAM driver (as device asc0)
2. I want to send SCSI commands (filling CDBs by myself) directly
to SCSI device, or even BUS/TARGET/LUN
So, is it possible somehow ? I've found a number of IOCTLs in rzdisk.h file,
and SCSI_SPECIAL ioctl in scsi_special.h file, but they are not exactly what
I want, 'cause I'd like to provide my own SCSI CDB blocks and fill some
reserved bits there. Looks like SCSI_SPECIAL ioctl is a good candidate for
doing this, but it is not very clear for me how to use it.
Also, what will be good for me, to use some other device for open(),
and then using ioctl() on that device issue SCSI command for another one,
for example, if it was switched off during boot...
Best regards,
Oleg.
----------------------------------------------------------
Oleg V.Solovyanov Institute for High Energy Physics
solovyanov@mx.ihep.su
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: SCSI CAM driver and ioctls
1995-06-06 4:00 SCSI CAM driver and ioctls Oleg V.Solovyanov, IHEP
@ 1995-06-08 4:00 ` Alan Rollow - Dr. File System's Home for Wayward Inodes.
0 siblings, 0 replies; 2+ messages in thread
From: Alan Rollow - Dr. File System's Home for Wayward Inodes. @ 1995-06-08 4:00 UTC (permalink / raw)
In article <1995Jun6.143535.15496@ixwin.ihep.su>, solovyanov@m10.ihep.su (Oleg V.Solovyanov, IHEP) writes:
> 1. I have PDS5000/33 with Ultrix 4.4 and SCSI CAM driver (as device asc0)
> 2. I want to send SCSI commands (filling CDBs by myself) directly
> to SCSI device, or even BUS/TARGET/LUN
>
> So, is it possible somehow ?
Yes. Use the CAM User Agent. If you have the CAM documentation, it
should have a section showing how to use the User Agent. Unfortunately
I don't know the full title nor the part number. I will include a
program at the end of this that uses the User Agent to do an Inquire.
>I've found a number of IOCTLs in rzdisk.h file,
> and SCSI_SPECIAL ioctl in scsi_special.h file, but they are not exactly what
> I want, 'cause I'd like to provide my own SCSI CDB blocks and fill some
> reserved bits there.
Those I/O controls were for the old SCSI driver anyway and wouldn't
work with the CAM Driver.
>Looks like SCSI_SPECIAL ioctl is a good candidate for
> doing this, but it is not very clear for me how to use it.
>
> Also, what will be good for me, to use some other device for open(),
> and then using ioctl() on that device issue SCSI command for another one,
> for example, if it was switched off during boot...
The CAM interface requires that you specify the device to get
a command by bus/target/LUN. You don't even have to open the
device. You open /dev/cam and then use appropriate I/O controls
to send the commands. This example uses DEVIOCGET and the file
name to figure out the bus, target and LUN. You may want to change
it to allow passing the numbers directly. Please note that the
device number encoding is different between ULTRIX and Digital UNIX:
/*
* Author: Alan Rollow, Subsystems Engineering, Digital Equipment Corp.
* File: %M%
* Date: %G%
* Version: %I%
*
* %M% - Simple (?) program to use the CAM User Agent to do
* INQUIRY of a device. Allow specifying the device by name
* rather than (bus,target,lun).
*
* (?) After this exercise one wonders if the people that
* design Standards ever have to use them...
*/
#ifndef lint
static char SccsId[] = "%W% (SCSI) %G%" ;
#endif
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#ifdef __osf__
#include <io/common/iotypes.h>
#endif
#include <io/cam/cam.h>
#include <io/cam/dec_cam.h>
#include <io/cam/uagt.h>
#include <io/cam/scsi_all.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <errno.h>
/*
* Space for the inquiry results.
*/
#define INQUIRY_LEN 36
#define SCSI_IDS 8
unsigned char buf[INQUIRY_LEN] ;
/*
* Program name for error messages.
*/
char *program ;
/*
* Given a device name, use DEVIOCGET to get the generic
* information about the device, which includes, SCSI ID
* and bus name. Use that to fill in the appropriate
* fields of the CCB structure.
*
* Assume a LUN number of 0.
*/
set_scsi_ids(char *device, int *bus, int *target, int *lun)
{
register fd ;
struct stat data ;
#ifdef __osf__
union {
struct {
unsigned part : 6 ;
unsigned lun : 4 ;
unsigned target : 4 ;
unsigned bus : 6 ;
unsigned index : 12 ;
} scsi ;
dev_t device ;
} convert ;
#else
union {
struct {
unsigned part : 3 ;
unsigned target : 3 ;
unsigned bus : 2 ;
unsigned index : 8 ;
} scsi ;
dev_t device ;
} convert ;
#endif
if( stat(device, &data) == -1 ) {
fprintf(stderr, "%s: Can't get BTL for %s: %s.\n", program,
device, strerror(errno)) ;
return -1 ;
}
convert.device = data.st_rdev ;
/*
* The assumption that the unit number % 8 is probably
* only valid for 8 bit SCSI.
*/
*bus = convert.scsi.bus ;
*target = convert.scsi.target ;
#ifdef __osf__
*lun = convert.scsi.lun ;
#else
*lun = 0 ;
#endif
return 1 ;
}
int fd = -1 ;
char *
scsi_inquire(int bus, int target, int lun)
{
static char buffer[INQUIRY_LEN+3] ;
UAGT_CAM_CCB ua_ccb ;
CCB_SCSIIO ccb ;
ALL_INQ_CDB *inq ;
ALL_INQ_DATA *idp ;
/*
* If the CAM interface hasn't been opened yet, do so.
*/
if( fd == -1 )
if((fd = open("/dev/cam", O_RDONLY)) == -1 ) {
fprintf(stderr, "%s: Can't open /dev/cam: %s.\n",
program, strerror(errno)) ;
return NULL ;
}
/*
* Setup the CCB.
*/
bzero((char *)&ccb, sizeof(CCB_SCSIIO)) ;
ccb.cam_ch.my_addr = (struct ccb_header *)&ccb ;
ccb.cam_ch.cam_ccb_len = sizeof(CCB_SCSIIO) ;
ccb.cam_ch.cam_func_code = XPT_SCSI_IO ;
ccb.cam_ch.cam_flags = CAM_DIR_IN | CAM_DIS_AUTOSENSE ;
ccb.cam_ch.cam_path_id = bus ;
ccb.cam_ch.cam_target_id = target ;
ccb.cam_ch.cam_target_lun = lun ;
/*
* Setup the rest of the CCB for the INQUIRY.
*/
ccb.cam_data_ptr = buf ;
ccb.cam_dxfer_len = INQUIRY_LEN ;
ccb.cam_timeout = CAM_TIME_DEFAULT ;
ccb.cam_cdb_len = sizeof(ALL_INQ_CDB) ;
/*
* Setup the INQUIRY CDB.
*/
inq = (ALL_INQ_CDB *)ccb.cam_cdb_io.cam_cdb_bytes ;
inq->opcode = ALL_INQ_OP ;
inq->alloc_len = INQUIRY_LEN ;
inq->evpd = 0 ;
inq->lun = ccb.cam_ch.cam_target_lun ;
inq->page = 0 ;
inq->control = 0 ;
/*
* Setup the User Agent data structure.
*/
bzero((char *)&ua_ccb, sizeof(UAGT_CAM_CCB)) ;
ua_ccb.uagt_ccb = (CCB_HEADER *)&ccb ;
ua_ccb.uagt_ccblen = sizeof(CCB_SCSIIO) ;
ua_ccb.uagt_buffer = buf ;
ua_ccb.uagt_buflen = INQUIRY_LEN ;
ua_ccb.uagt_snsbuf = NULL ;
ua_ccb.uagt_snslen = 0 ;
ua_ccb.uagt_cdb = NULL ;
ua_ccb.uagt_cdblen = 0 ;
/*
* Now we finally get to do the I/O to do the
* inquiry.
*/
if( ioctl(fd, UAGT_CAM_IO, (char *)&ua_ccb) == -1 ) {
fprintf(stderr, "%s: User Agent ioctl failed: %s.\n",
program, strerror(errno)) ;
return NULL ;
}
/*
* Check the CCB to see if the INQUIRY failed.
*/
if( ccb.cam_ch.cam_status != CAM_REQ_CMP ) {
fprintf(stderr, "%s: The INQUIRY failed on (%d,%d,%d): %x.\n",
program, bus, target, lun, ccb.cam_ch.cam_status) ;
return NULL ;
}
else {
idp = (ALL_INQ_DATA *)buf ;
sprintf(buffer, "%16.16s", idp->pid) ;
return buffer ;
}
}
main(int argc, char *argv[])
{
char *inq ;
register i ;
int bus, target, lun ;
program = argv[0] ;
for(i = 1; i < argc; i++) {
if( set_scsi_ids(argv[i], &bus, &target, &lun) == -1 )
continue ;
if((inq = scsi_inquire(bus, target, lun)) != NULL )
printf("%s: %s\n", argv[i], inq) ;
}
if( fd != -1 )
if( close(fd) == -1 )
fprintf(stderr, "%s: Can't close /dev/cam: %s.\n",
program, strerror(errno)) ;
return 0 ;
}
>
> Best regards,
> Oleg.
>
>
>----------------------------------------------------------
>Oleg V.Solovyanov Institute for High Energy Physics
>solovyanov@mx.ihep.su
>
>
--
Alan Rollow alan@nabeth.cxo.dec.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1995-06-08 4:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-06-06 4:00 SCSI CAM driver and ioctls Oleg V.Solovyanov, IHEP
1995-06-08 4:00 ` Alan Rollow - Dr. File System's Home for Wayward Inodes.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox