sense visible despite ide-floppy in 2.6 maybe
Doug G:
Did I do something wrong, or does "everyone know" already,
SCSI pass thru in 2.6 omits ide-floppy, except if we do resort to the ide-scsi deprecated there?
Or more specifically,
Can ioctl SG_IO fetch the offset 7 Additional Length field of op x03 "REQUEST SENSE" data?
Naively I thought yes of course, I know that works with /dev/scd$n.
But then I tried a /dev/hd$v ide-floppy. No joy. perror tells me ioctl SG_IO fails via "Invalid argument", dmesg has no comment. sg_scan you know. ~/bin/sgio source is the trivial exercise quoted in source far below, specifically with an O_NONBLOCK|O_RDWR open as you can see.
$ sudo sg3_utils-1.06/sg_scan /dev/hdd /dev/scd0 sg_scan: device /dev/hdd failed on scsi ioctl, skip: Input/output error /dev/scd0: scsi0 channel=0 id=0 lun=0 [em] $ $ sudo ~/bin/sgio /dev/hdd /dev/scd0 | strings ioctl SG_IO: Invalid argument Iomega RRD 74.B $
$ uname -srm Linux 2.6.7-rc2 i686 $ lsmod | grep ide ide_floppy 17664 0 $ sudo mount /dev/hdd /mnt/hdd $ sudo umount /dev/hdd $ alias xstrings="tr -d ' \r\n' | perl -wpe 's/(..)/chr hex \$1/eg' | strings" $ sudo cat /proc/ide/hdd/identify | xstrings 803048B34F460C1E 25.Q IOMEGA ZIP 250 ATAPI (c) Copyright IOMEGA 2002 601//320 $
Pat LaVarre
P.S. I fell into trying all this when a friend not yet living in Linux noticed my recent linux-ide report of a SATAPI host choking over an available sense length rudely not aligned to four bytes.
----- ~/bin/sgio.c
#include <fcntl.h>
#include <scsi/sg.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <string.h>
#include <unistd.h>
static unsigned char static_cdb[0x100];
static unsigned char static_data[0x1000];
static unsigned char static_sense[0x100];
static void populate(sg_io_hdr_t * sih)
{
memset(sih, '\0', sizeof *sih);
sih->interface_id = 'S';
memset(&static_cdb, '\0', sizeof static_cdb);
sih->cmdp = static_cdb;
sih->cmd_len = 6;
memcpy(sih->cmdp, "\x12\0\0\0\x24\0", sih->cmd_len);
memset(&static_data, '\0', sizeof static_data);
sih->dxferp = static_data;
sih->dxfer_len = 0x24;
sih->dxfer_direction = SG_DXFER_NONE;
sih->dxfer_direction = SG_DXFER_TO_DEV;
sih->dxfer_direction = SG_DXFER_FROM_DEV;
memset(&static_sense, '\0', sizeof static_sense);
sih->sbp = static_sense;
sih->mx_sb_len = 0x12; /* SATAPI may need 4 byte alignment */
sih->timeout = 30 * 1000; /* ms */
; /* sih->iovec_count sih->flags sih->pack_id sih->usr_ptr */
; /* sih->status sih->masked_status sih->msg_status */
; /* sih->sb_len_wr sih->host_status sih->drive_status */
; /* sih->resid sih->duration sih->info */
}static void talk(int fd)
{
static sg_io_hdr_t static_sih;
sg_io_hdr_t * sih = &static_sih;
int ii;
populate(sih);
ii = ioctl(fd, SG_IO, sih);
if (ii < 0) {
perror("ioctl SG_IO");
} else {
fwrite(sih->dxferp, sih->dxfer_len, 1, stdout);
if ((sih->info & SG_INFO_OK_MASK) != SG_INFO_OK) {
fprintf(stderr, "x %X %X %X\n",
sih->info, sih->resid, sih->sb_len_wr);
}
}
}int main(int argc, char * argv[])
{
int ix = 0;
--argc; ++argv;
for (ix = 0; ix < argc; ++ix)
{
int fd = open(argv[ix], O_NONBLOCK|O_RDWR);
if (fd < 0) {
perror("open");
} else {
int vn = 0;
if (0 <= ioctl(fd, SG_GET_VERSION_NUM, &vn)) {
if (vn < 30000) {
perror("ioctl SG_GET_VERSION_NUM");
continue;
}
}
talk(fd);
close(fd);
}
}
return 0;
}Quoted 12 lines · Pat LaVarre
Doug G:
Did I do something wrong, or does "everyone know" already,
SCSI pass thru in 2.6 omits ide-floppy, except if we do resort to the ide-scsi deprecated there?
Or more specifically,
Can ioctl
SG_IOfetch the offset 7 Additional Length field of op x03 "REQUEST SENSE" data?
Quoted 6 lines
Naively I thought yes of course, I know that works with
/dev/scd$n.But then I tried a
/dev/hd$vide-floppy. No joy. perror tells me ioctlSG_IOfails via "Invalid argument", dmesg has no comment.sg_scanyou know. ~/bin/sgio source is the trivial exercise quoted in source far below, specifically with an O_NONBLOCK|O_RDWR open as you can see.
Hmm fudge. There are two problems - first you need to pass through SG_IO ioctl from the ide layer, ide-cd gets it through cdrom.c currently. That's the easy part, attached.
Secondly, you need to map struct request to a idefloppy_pc_t packet command. Currently it just passes through START_STOP, it could in fact handle any request that doesn't carry data though:
idefloppy_blockpc_cmd()
{
if (rq->data_len)
return 1;
if (rq->cmd_len > sizeof(pc->c))
return 1;
idefloppy_init_pc(pc);
memcpy(pc->c, rq->cmd, sizeof(pc->c));
return 0;
}For data transfer, it's more tricky. Well actually, if you restrict yourself to non-bio backed request, then it becomes pretty trivial! ide-floppy expects a contig buffer, a bio is scattered by nature.
Signature · 1 line
Jens Axboe
Quoted 3 lines · Jens Axboe
For data transfer, it's more tricky. Well actually, if you restrict yourself to non-bio backed request, then it becomes pretty trivial! ide-floppy expects a contig buffer, a bio is scattered by nature.
Since it handles REQ_CMD just fine (*), this should actually just work. Pat, can you test if it does?
* Scattered handling if dma fails looks very fishy, should be audited.
===== drivers/ide/ide.c 1.149 vs edited =====
drivers/ide/ide.c +2 -0
@@ -153,6 +153,7 @@#include <linux/cdrom.h> #include <linux/seq_file.h> #include <linux/device.h> +#include <scsi/sg.h> #include <asm/byteorder.h> #include <asm/irq.h>
@@ -1605,6 +1606,7 @@case CDROMEJECT :case CDROMCLOSETRAY : +case SG_IO :return scsi_cmd_ioctl (bdev->bd_disk, cmd, p);case HDIO_GET_BUSSTATE :
===== drivers/ide/ide-floppy.c 1.39 vs edited =====
drivers/ide/ide-floppy.c +14 -13
@@ -1210,19 +1210,23 @@set_bit (PC_DMA_RECOMMENDED , &pc->flags); } -static int +static void idefloppy_blockpc_cmd (idefloppy_floppy_t *floppy,idefloppy_pc_t *pc,struct request *rq) { -/* -* just support eject for now, it would not be hard to make the -* REQ_BLOCK_PC support fully-featured -*/ -if (rq->cmd[0 ] !=IDEFLOPPY_START_STOP_CMD ) -return 1 ; -idefloppy_init_pc (pc); + pc->callback = &idefloppy_rw_callback;memcpy (pc->c, rq->cmd,sizeof (pc->c)); -return 0 ; + pc->rq = rq; + pc->b_count = rq->data_len; +if (rq_data_dir (rq) ==WRITE ) +set_bit (PC_WRITING , &pc->flags); + pc->buffer =NULL ; +/* +* possibly problematic, doesn't look like ide-floppy correctly +* handled scattered requests if dma fails... +*/ + pc->request_transfer = pc->buffer_size = rq->data_len; +set_bit (PC_DMA_RECOMMENDED , &pc->flags); }/*
@@ -1267,10 +1271,7 @@ pc = (idefloppy_pc_t *) rq->buffer; }else if (rq->flags &REQ_BLOCK_PC ) { pc =idefloppy_next_pc_storage (drive); -if (idefloppy_blockpc_cmd (floppy, pc, rq)) { -idefloppy_do_end_request (drive,0 ,0 ); -return ide_stopped; - } +idefloppy_blockpc_cmd (floppy, pc, rq); }else {blk_dump_rq_flags (rq,"ide-floppy: unsupported command in queue" );
Signature · 1 line
Jens Axboe
Quoted 1 line
Hmm fudge.
Sorry, this English I do not understand.
drivers/ide/ide.c 2004-06-09 10:07:46 +02:00
Quoted 2 lines
drivers/ide/ide.c 2004-06-09 10:07:46 +02:00 renamed from drivers/ide/ide.c 2004-06-04 21:14:59 +02:00 +0
-0
Patch! Cool, thank you.
Quoted 1 line
Pat, can you test
Gladly. Unless redirected, I will try combining:
a) kernel.org 2.6.7-rc3 plus the patch of this thread,
b) PATAPI drive connected as /dev/hdd,
c) open of /dev/hdd with flags O_NONBLOCK|O_RDWR, ioctl SG_IO
d) cdb = x 1B 00:00:00 00 00 // Stop
e) cdb = x 1B 00:00:00 01 00 // Start
Pat LaVarre
Quoted 11 lines · Pat LaVarre
Quoted 1 line
Hmm fudge.
Sorry, this English I do not understand.
drivers/ide/ide.c 2004-06-09 10:07:46 +02:00
Quoted 2 lines
drivers/ide/ide.c 2004-06-09 10:07:46 +02:00 renamed from drivers/ide/ide.c 2004-06-04 21:14:59 +02:00 +0
-0Patch! Cool, thank you.
Quoted 1 line
Pat, can you test
Quoted 7 lines
Gladly. Unless redirected, I will try combining:
a) kernel.org 2.6.7-rc3 plus the patch of this thread,
b) PATAPI drive connected as/dev/hdd,
c) open of/dev/hddwith flags O_NONBLOCK|O_RDWR, ioctlSG_IO
d) cdb = x 1B 00:00:00 00 00 // Stop
e) cdb = x 1B 00:00:00 01 00 // Start
f) issue some command that transfers data as well.
if you use the 2nd patch I posted.
Signature · 1 line
Jens Axboe
Jens A:
Quoted 5 lines
a) kernel.org 2.6.7-rc3 plus the patch of this thread,
b) PATAPI drive connected as/dev/hdd,
c) open of/dev/hddwith flags O_NONBLOCK|O_RDWR, ioctlSG_IO
d) cdb = x 1B 00:00:00 00 00 // Stop
e) cdb = x 1B 00:00:00 01 00 // Start
Yes now "Hn" (i.e. expecting no data) works here, every time I try.
Cool instant demo of how helpful linux-scsi folk are, thank you.
Quoted 3 lines
For data transfer, it's more tricky. Well actually, if you restrict yourself to non-bio backed request, then it becomes pretty trivial! ide-floppy expects a contig buffer, a bio is scattered by nature.
Yes "Hi" (i.e. expecting data in) gives me zeroes.
Quoted 1 line
...
Also something's broken (far far outside of the kernel) in plscsi. I found success only by patching the trivial sgio.c that I posted in this thread, as shown below.
Pat LaVarre
sgio-up.c renamed from sgio.c +3 -3
@@ -17,14 +17,14 @@ static void populate(sg_io_hdr_t * sih)memset (&static_cdb,'\0' ,sizeof static_cdb); sih->cmdp = static_cdb; sih->cmd_len =6 ; -memcpy (sih->cmdp,"\x12\0\0\0\x24\0" , sih->cmd_len); +memcpy (sih->cmdp,"\x1B\0\0\0\x01\0" , sih->cmd_len);memset (&static_data,'\0' ,sizeof static_data); sih->dxferp = static_data; - sih->dxfer_len =0x24 ; - sih->dxfer_direction =SG_DXFER_NONE ; + sih->dxfer_len =0x00 ; sih->dxfer_direction =SG_DXFER_TO_DEV ; sih->dxfer_direction =SG_DXFER_FROM_DEV ; + sih->dxfer_direction =SG_DXFER_NONE ;memset (&static_sense,'\0' ,sizeof static_sense); sih->sbp = static_sense;
sgio-dn.c renamed from sgio-up.c +1 -1
@@ -17,7 +17,7 @@ static void populate(sg_io_hdr_t * sih)memset (&static_cdb,'\0' ,sizeof static_cdb); sih->cmdp = static_cdb; sih->cmd_len =6 ; -memcpy (sih->cmdp,"\x1B\0\0\0\x01\0" , sih->cmd_len); +memcpy (sih->cmdp,"\x1B\0\0\0\x00\0" , sih->cmd_len);memset (&static_data,'\0' ,sizeof static_data); sih->dxferp = static_data;
Quoted 3 lines
Also something's broken (far far outside of the kernel) in plscsi. I found success only by patching the trivial
sgio.cthat I posted in this thread, as shown below.
Ah. That is, despite the patch inserting idefloppy_blockpc_cmd,
ioctl(fd, SG_GET_VERSION_NUM, &vn) returns negative.
Pat LaVarre
P.S. More specifically,
plscsi, with perhaps excessively paranoid automagic, therefore chose not to try 2.4 style ioctl SG_IO, complaining:
// sgioOpen.ioctl: Invalid argument
// plscsi.sclOpenNext: "/dev/hdd" not opened
By contrast, my back-of-the-envelope sgio.c was quietly stepping past this trouble without complaint, in fact requiring vn at or beyond 30,000 only from devices that do support ioctl fd SG_GET_VERSION &vn. The trivial patch to get that fragment of code to behave as sensitively as plscsi is of course:
sgio.c renamed from sgio.was.c +5 -2
@@ -61,12 +61,15 @@ int main(int argc, char * argv[]) --argc; ++argv;for (ix =0 ; ix < argc; ++ix) { -int fd =open (argv[ix],O_NONBLOCK |O_RDWR ); +int fd =open (argv[ix],O_NONBLOCK );if (fd <0 ) {perror ("open" ); }else {int vn =0 ; -if (0 <=ioctl (fd,SG_GET_VERSION_NUM , &vn)) { +if (ioctl (fd,SG_GET_VERSION_NUM , &vn) <0 ) { +perror ("ioctl SG_GET_VERSION_NUM" ); + ;/* fallthru to talk anyhow */ + }else {if (vn <30000 ) {perror ("ioctl SG_GET_VERSION_NUM" );continue ;
Jens A:
Quoted 5 lines
Quoted 3 lines
a) ...
...
e) ......
f) issue some command that transfers data as well.
I tried an op x12 (18) Inquiry for up to x24 (36) bytes.
I got back zeroes even when I memset my data originally to equal catenated copies of "\xAE" (174).
Under such provocations, dmesg then consistently reports:
hdd: The disk reports a capacity of 250640384 bytes, but the drive only handles 250609664
hdd: unknown partition table
hdd: leftover data in idefloppy_input_buffers, bcount == 36
Also I saw:
$ sudo /sbin/hdparm /dev/hdd
/dev/hdd:
HDIO_GET_MULTCOUNT failed: Invalid argument
IO_support = 0 (default 16-bit) unmaskirq = 0 (off) using_dma = 1 (on) keepsettings = 0 (off) readonly = 0 (off)
readahead = 256 (on)
geometry = 239/64/32, sectors = 489472, start = 0
$
Also the open-ioctl-close spins up the disk, despite O_NONBLOCK.
Quoted 1 line
if you use the 2nd patch I posted.
I tried the only patch I have yet found. It applied clean. Below I quote the resulting diff.
Pat LaVarre
drivers/ide/ide-floppy.c +14 -13
@@ -1210,19 +1210,23 @@ static void idefloppy_create_rw_cmd (ideset_bit (PC_DMA_RECOMMENDED , &pc->flags); } -static int +static void idefloppy_blockpc_cmd (idefloppy_floppy_t *floppy,idefloppy_pc_t *pc,struct request *rq) { -/* -* just support eject for now, it would not be hard to make the -* REQ_BLOCK_PC support fully-featured -*/ -if (rq->cmd[0 ] !=IDEFLOPPY_START_STOP_CMD ) -return 1 ; -idefloppy_init_pc (pc); + pc->callback = &idefloppy_rw_callback;memcpy (pc->c, rq->cmd,sizeof (pc->c)); -return 0 ; + pc->rq = rq; + pc->b_count = rq->data_len; +if (rq_data_dir (rq) ==WRITE ) +set_bit (PC_WRITING , &pc->flags); + pc->buffer =NULL ; +/* +* possibly problematic, doesn't look like ide-floppy correctly +* handled scattered requests if dma fails... +*/ + pc->request_transfer = pc->buffer_size = rq->data_len; +set_bit (PC_DMA_RECOMMENDED , &pc->flags); }/*
@@ -1267,10 +1271,7 @@ static ide_startstop_t idefloppy_do_requ pc = (idefloppy_pc_t *) rq->buffer; }else if (rq->flags &REQ_BLOCK_PC ) { pc =idefloppy_next_pc_storage (drive); -if (idefloppy_blockpc_cmd (floppy, pc, rq)) { -idefloppy_do_end_request (drive,0 ,0 ); -return ide_stopped; - } +idefloppy_blockpc_cmd (floppy, pc, rq); }else {blk_dump_rq_flags (rq,"ide-floppy: unsupported command in queue" );
Quoted 6 lines · Pat LaVarre
Doug G:
Did I do something wrong, or does "everyone know" already,
SCSI pass thru in 2.6 omits ide-floppy, except if we do resort to the ide-scsi deprecated there?
Pat,
In lk 2.6 the ide-scsi driver is "deprecated" for cd/dvd device types but not other device types that use the ATAPI protocol. The ide-scsi driver is in the same group as the usb-storage and sbp2 drivers which bridge between the SCSI stack and other subsystem stacks. The ongoing problems we have with this group of drivers is as much to do with their technical complexity (spanning two different driver architectures) as it is to do with the politics of kernel development.
Anyway ide-scsi probably needs some repair work in lk 2.6. Both Willem Riede and I have tried. IMO the ide-scsi driver looks ok from the scsi subsystem side ....
Quoted 11 lines
Or more specifically,
Can ioctl
SG_IOfetch the offset 7 Additional Length field of op x03 "REQUEST SENSE" data?Naively I thought yes of course, I know that works with
/dev/scd$n.But then I tried a
/dev/hd$vide-floppy. No joy. perror tells me ioctlSG_IOfails via "Invalid argument", dmesg has no comment.sg_scanyou know. ~/bin/sgio source is the trivial exercise quoted in source far below, specifically with an O_NONBLOCK|O_RDWR open as you can see.
My method with the SG_IO ioctl was to yield errnos if the SCSI command could not be sent (or was rejected at the point of transmission). So if there is an errno there will be no sense buffer (or any other valid response data). It is only when a response to the SCSI command is received that errno will be clear (and the various status variables should be checked).
Quoted 9 lines
$ sudo sg3_utils-1.06/sg_scan /dev/hdd /dev/scd0 sg_scan: device /dev/hdd failed on scsi ioctl, skip: Input/output error /dev/scd0: scsi0 channel=0 id=0 lun=0 [em] $ $ sudo ~/bin/sgio /dev/hdd /dev/scd0 | strings ioctl SG_IO: Invalid argument Iomega RRD 74.B $
Quoted 14 lines
$ uname -srm Linux 2.6.7-rc2 i686 $ lsmod | grep ide ide_floppy 17664 0 $ sudo mount /dev/hdd /mnt/hdd $ sudo umount /dev/hdd $ alias xstrings="tr -d ' \r\n' | perl -wpe 's/(..)/chr hex \$1/eg' | strings" $ sudo cat /proc/ide/hdd/identify | xstrings 803048B34F460C1E 25.Q IOMEGA ZIP 250 ATAPI (c) Copyright IOMEGA 2002 601//320 $
Perhaps you could sent me the "strace" of this failure so I can have a closer look at what is going on.
Quoted 5 lines
Pat LaVarre
P.S. I fell into trying all this when a friend not yet living in Linux noticed my recent linux-ide report of a SATAPI host choking over an available sense length rudely not aligned to four bytes.
The underlying serial protocols used by sATA and SAS do seem to be in units of "dwords" (i.e. 4 byte quantities). I have noticed several SCSI standards changing the maximum allocation length of a one byte field (e.g. in an INQUIRY and MODE SENSE(6) ) from 255 to 252. The intent seems to be to have lengths that are multiples of 4.
Quoted 14 lines
-----
~/bin/sgio.c#include <
fcntl.h>
#include <scsi/sg.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <string.h>
#include <unistd.h>static unsigned char static_cdb[0x100];
static unsigned char static_data[0x1000];
static unsigned char static_sense[0x100];static void
populate(sg_io_hdr_t * sih)
Quoted 15 lines
{
memset(sih, '\0', sizeof *sih);
sih->interface_id = 'S';
memset(&static_cdb, '\0', sizeof static_cdb);
sih->cmdp = static_cdb;
sih->cmd_len = 6;
memcpy(sih->cmdp, "\x12\0\0\0\x24\0", sih->cmd_len);
memset(&static_data, '\0', sizeof static_data);
sih->dxferp = static_data;
sih->dxfer_len = 0x24;
sih->dxfer_direction = SG_DXFER_NONE;
sih->dxfer_direction = SG_DXFER_TO_DEV;
sih->dxfer_direction = SG_DXFER_FROM_DEV;The three above lines look a bit strange :-)
Quoted 30 lines
memset(&static_sense, '\0', sizeof static_sense); sih->sbp = static_sense; sih->mx_sb_len = 0x12; /* SATAPI may need 4 byte alignment */ sih->timeout = 30 * 1000; /* ms */ ; /* sih->iovec_count sih->flags sih->pack_id sih->usr_ptr */ ; /* sih->status sih->masked_status sih->msg_status */ ; /* sih->sb_len_wr sih->host_status sih->drive_status */ ; /* sih->resid sih->duration sih->info */ }static void talk(int fd)
{ static sg_io_hdr_t static_sih; sg_io_hdr_t * sih = &static_sih; int ii; populate(sih); ii = ioctl(fd, SG_IO, sih); if (ii < 0) { perror("ioctl SG_IO"); } else { fwrite(sih->dxferp, sih->dxfer_len, 1, stdout); if ((sih->info & SG_INFO_OK_MASK) != SG_INFO_OK) { fprintf(stderr, "x %X %X %X\n", sih->info, sih->resid, sih->sb_len_wr); } } }int
main(int argc, char * argv[])
Quoted 15 lines
{
int ix = 0;
--argc; ++argv;
for (ix = 0; ix < argc; ++ix)
{
int fd = open(argv[ix], O_NONBLOCK|O_RDWR);
if (fd < 0) {
perror("open");
} else {
int vn = 0;
if (0 <= ioctl(fd, SG_GET_VERSION_NUM, &vn)) {
if (vn < 30000) {
perror("ioctl SG_GET_VERSION_NUM");
continue;
}Note: I have started to drop this SG_GET_VERSION_NUM ioctl() check. It is still needed in the special case where the sg driver is working asynchronously (i.e. sending commands with write() and receiving the response with read() ).
Quoted 7 lines
} talk(fd); close(fd); } } return 0; }
Doug Gilbert
Quoted 14 lines · Douglas Gilbert
Quoted 2 lines · Pat LaVarre
SCSI pass thru in 2.6 omits ide-floppy, except if we do resort to the ide-scsi deprecated there?
Pat,
In lk 2.6 the ide-scsi driver is "deprecated" for cd/dvd device types but not other device types that use the ATAPI protocol. The ide-scsi driver is in the same group as the usb-storage and sbp2 drivers which bridge between the SCSI stack and other subsystem stacks. The ongoing problems we have with this group of drivers is as much to do with their technical complexity (spanning two different driver architectures) as it is to do with the politics of kernel development.
Quoted 3 lines
Anyway ide-scsi probably needs some repair work in lk 2.6. Both Willem Riede and I have tried. IMO the ide-scsi driver looks ok from the scsi subsystem side ....
And actually it works very well for me currently. (That's not to say there couldn't still be issues with other hardware). If you have specific problems I'll be happy to try and help.
Regards, Willem Riede.
Quoted 9 lines · Pat LaVarre
Jens A:
Quoted 5 lines
a) kernel.org 2.6.7-rc3 plus the patch of this thread,
b) PATAPI drive connected as/dev/hdd,
c) open of/dev/hddwith flags O_NONBLOCK|O_RDWR, ioctlSG_IO
d) cdb = x 1B 00:00:00 00 00 // Stop
e) cdb = x 1B 00:00:00 01 00 // StartYes now "Hn" (i.e. expecting no data) works here, every time I try.
Good
Quoted 5 lines
Quoted 3 lines
For data transfer, it's more tricky. Well actually, if you restrict yourself to non-bio backed request, then it becomes pretty trivial! ide-floppy expects a contig buffer, a bio is scattered by nature.
Yes "Hi" (i.e. expecting data in) gives me zeroes.
Not so good... I'll take a 2nd look and get you something to test, unfortunately I cannot test here as I have no atapi floppy drives.
Signature · 1 line
Jens Axboe
Quoted 6 lines · Pat LaVarre
Quoted 3 lines
Also something's broken (far far outside of the kernel) in plscsi. I found success only by patching the trivial
sgio.cthat I posted in this thread, as shown below.Ah. That is, despite the patch inserting
idefloppy_blockpc_cmd,
Quoted 8 lines
ioctl(fd, SG_GET_VERSION_NUM, &vn)returns negative.Pat LaVarre
P.S. More specifically,plscsi, with perhaps excessively paranoid automagic, therefore chose not to try 2.4 style ioctl
SG_IO, complaining:
ide.c needs the whole range of SG ioctls that block/scsi_ioctl.c supports. I'll add that.
Signature · 1 line
Jens Axboe
Quoted 10 lines · Pat LaVarre
Jens A:
Quoted 5 lines
Quoted 3 lines
a) ...
...
e) ......
f) issue some command that transfers data as well.I tried an op x12 (18) Inquiry for up to x24 (36) bytes.
Quoted 8 lines
I got back zeroes even when I memset my data originally to equal catenated copies of "\xAE" (174).
Under such provocations, dmesg then consistently reports:
hdd: The disk reports a capacity of 250640384 bytes, but the drive only handles 250609664
hdd: unknown partition table
hdd: leftover data inidefloppy_input_buffers, bcount == 36
Ah that's a good hint. Can you try changing the pc->buffer = NULL in idefloppy_blockpc_cmd() to pc->buffer = rq->data? Also, only set PC_DMA_RECOMMENDED if it isn't set. Something ala
pc->buffer = rq->data; if (rq->bio) set_bit(PC_DMA_RECOMMENDED, &pc->flags);
that should work, I think. Do this on top of the patch you are already using.
Signature · 1 line
Jens Axboe
Quoted 24 lines · Jens Axboe
Quoted 10 lines · Pat LaVarre
Jens A:
Quoted 5 lines
Quoted 3 lines
a) ...
...
e) ......
f) issue some command that transfers data as well.I tried an op x12 (18) Inquiry for up to x24 (36) bytes.
Quoted 8 lines
I got back zeroes even when I memset my data originally to equal catenated copies of "\xAE" (174).
Under such provocations, dmesg then consistently reports:
hdd: The disk reports a capacity of 250640384 bytes, but the drive only handles 250609664
hdd: unknown partition table
hdd: leftover data inidefloppy_input_buffers, bcount == 36Ah that's a good hint. Can you try changing the
pc->buffer= NULL inidefloppy_blockpc_cmd()topc->buffer=rq->data? Also, only setPC_DMA_RECOMMENDEDif it isn't set. Something ala
Quoted 6 lines
pc->buffer = rq->data; if (rq->bio) set_bit(PC_DMA_RECOMMENDED, &pc->flags);that should work, I think. Do this on top of the patch you are already using.
Here's an updated version.
===== drivers/ide/ide.c 1.149 vs edited =====
drivers/ide/ide.c +6 -5
@@ -1458,9 +1458,14 @@ {ide_drive_t *drive = bdev->bd_disk->private_data;ide_settings_t *setting; -int err =0 ; +int err;void __user *p = (void __user *)arg; + err =scsi_cmd_ioctl (bdev->bd_disk, cmd, p); +if (err != -ENOTTY ) +return err; + + err =0 ;down (&ide_setting_sem);if ((setting =ide_find_setting_by_ioctl (drive, cmd)) !=NULL ) {if (cmd == setting->read_ioctl) {
@@ -1602,10 +1607,6 @@ }return 0 ; } - -case CDROMEJECT : -case CDROMCLOSETRAY : -return scsi_cmd_ioctl (bdev->bd_disk, cmd, p);case HDIO_GET_BUSSTATE :if (!capable (CAP_SYS_ADMIN ))
===== drivers/ide/ide-floppy.c 1.39 vs edited =====
drivers/ide/ide-floppy.c +16 -13
@@ -1210,19 +1210,25 @@set_bit (PC_DMA_RECOMMENDED , &pc->flags); } -static int +static void idefloppy_blockpc_cmd (idefloppy_floppy_t *floppy,idefloppy_pc_t *pc,struct request *rq) { -/* -* just support eject for now, it would not be hard to make the -* REQ_BLOCK_PC support fully-featured -*/ -if (rq->cmd[0 ] !=IDEFLOPPY_START_STOP_CMD ) -return 1 ; -idefloppy_init_pc (pc); + pc->callback = &idefloppy_rw_callback;memcpy (pc->c, rq->cmd,sizeof (pc->c)); -return 0 ; + pc->rq = rq; + pc->b_count = rq->data_len; +if (rq->data_len &&rq_data_dir (rq) ==WRITE ) +set_bit (PC_WRITING , &pc->flags); + pc->buffer = rq->data; +if (rq->bio) +set_bit (PC_DMA_RECOMMENDED , &pc->flags); + +/* +* possibly problematic, doesn't look like ide-floppy correctly +* handled scattered requests if dma fails... +*/ + pc->request_transfer = pc->buffer_size = rq->data_len; }/*
@@ -1267,10 +1273,7 @@ pc = (idefloppy_pc_t *) rq->buffer; }else if (rq->flags &REQ_BLOCK_PC ) { pc =idefloppy_next_pc_storage (drive); -if (idefloppy_blockpc_cmd (floppy, pc, rq)) { -idefloppy_do_end_request (drive,0 ,0 ); -return ide_stopped; - } +idefloppy_blockpc_cmd (floppy, pc, rq); }else {blk_dump_rq_flags (rq,"ide-floppy: unsupported command in queue" );
Signature · 1 line
Jens Axboe
Willem R:
Quoted 8 lines
Quoted 2 lines
ide-scsi ... usb-storage .... sbp2 ... technical complex ...
... actually works very well for me currently.
(That's not to say there couldn't still be
issues with other hardware). If you have
specific problems I'll be happy to try and
help.
ide-scsi trouble is now interesting again, if observed since 2.6.5, especially if observed with ATAPI devices other than DVD/ CD.
is my guess of what we mean after reading this thread and the discussion of ide-scsi changes at:
http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.5
Quoted 6 lines
Quoted 6 lines
From: Douglas Gilbert ...
...
In lk 2.6 the ide-scsi driver
is "deprecated" for cd/dvd device types but not other device types
that use the ATAPI protocol.
Thank you I needed that education. Therefore another advantage for PDT x05 among RMB is that SCSI pass thru started working earlier in lk 2.6.
Pat LaVarre
Quoted 1 line
Quoted 1 line
should work, I think.
Yes, thank you!
I reverted drivers/ide/ide.c ide-floppy.c to 2.6.7-rc3 and then saw your updated version applied clean.
Quoted 1 line
Here's an updated version.
For me now ioctl SG_GET_VERSION_NUM works, and ioctl SG_IO works, ...
Except ioctl SG_IO sg_io_hdr_t.resid always comes back unchanged from its initial dxfer_len value. I see nonzero residue reported by the trivial code I mentioned before, same there as in plscsi.
Pat LaVarre
$ echo -n $'\xAE' >xae.bin $ hexdump -C xae.bin 00000000 ae |.| 00000001 $ $ sudo plscsi /dev/hdd -f xae.bin -i x24 -x "12 00:00:00 24 00" -v x 00000000 12 00:00:00 24 00 .. .. .. .. .. .. .. .. .. .. "R@@@$@" x 00000000 00:80:00:01 75:00:00:00 49:4F:4D:45 47:41:20:20 "@@@Au@@@IOMEGA " x 00000010 5A:49:50:20 32:35:30:20 20:20:20:20 20:20:20:20 "ZIP 250 " x 00000020 32:35:2E:51 .. .. .. .. .. .. .. .. .. .. .. .. "25.Q" // 36 = x24 = plscsi.main exit int $ $ sudo plscsi /dev/hdd -f xae.bin -i x7A -x "12 00:00:00 7A 00" -v x 00000000 12 00:00:00 7A 00 .. .. .. .. .. .. .. .. .. .. "R@@@z@" x 00000000 00:80:00:01 75:00:00:00 49:4F:4D:45 47:41:20:20 "@@@Au@@@IOMEGA " x 00000010 5A:49:50:20 32:35:30:20 20:20:20:20 20:20:20:20 "ZIP 250 " x 00000020 32:35:2E:51 30:36:2F:31 33:2F:30:32 00:00:00:00 "25.Q06/13/02@@@@" x 00000030 00:00:00:00 00:00:00:00 00:00:00:00 00:00:00:00 "@@@@@@@@@@@@@@@@" ... x 00000050 00:00:00:00 00:00:00:00 00:00:00:00 00:00:00:00 "@@@@@@@@@@@@@@@@" x 00000060 28:63:29:20 43:6F:70:79 72:69:67:68 74:20:49:4F "(c) Copyright IO" x 00000070 4D:45:47:41 20:32:30:30 30:20 .. .. .. .. .. .. "MEGA 2000 " // 122 = x7A = plscsi.main exit int $ $ sudo plscsi /dev/hdd -f xae.bin -i xFF -x "12 00:00:00 FF 00" -v x 00000000 12 00:00:00 FF 00 .. .. .. .. .. .. .. .. .. .. "R@@@?@" x 00000000 00:80:00:01 75:00:00:00 49:4F:4D:45 47:41:20:20 "@@@Au@@@IOMEGA " x 00000010 5A:49:50:20 32:35:30:20 20:20:20:20 20:20:20:20 "ZIP 250 " x 00000020 32:35:2E:51 30:36:2F:31 33:2F:30:32 00:00:00:00 "25.Q06/13/02@@@@" x 00000030 00:00:00:00 00:00:00:00 00:00:00:00 00:00:00:00 "@@@@@@@@@@@@@@@@" ... x 00000050 00:00:00:00 00:00:00:00 00:00:00:00 00:00:00:00 "@@@@@@@@@@@@@@@@" x 00000060 28:63:29:20 43:6F:70:79 72:69:67:68 74:20:49:4F "(c) Copyright IO" x 00000070 4D:45:47:41 20:32:30:30 30:20:00:00 00:00:00:00 "MEGA 2000 @@@@@@" x 00000080 00:00:00:00 00:00:00:00 00:00:00:00 00:00:00:00 "@@@@@@@@@@@@@@@@" ... x 000000E0 00:00:00:00 00:00:00:00 00:00:00:00 00:00:00:00 "@@@@@@@@@@@@@@@@" x 000000F0 00:00:00:00 00:00:00:00 00:00:00:00 00:00:00 .. "@@@@@@@@@@@@@@@" // 255 = xFF = plscsi.main exit int $
Doug G:
Quoted 6 lines
The underlying serial protocols used by sATA and SAS do seem to be in units of "dwords" (i.e. 4 byte quantities). I have noticed several SCSI standards changing the maximum allocation length of a one byte field (e.g. in an INQUIRY and MODE SENSE(6) ) from 255 to 252. The intent seems to be to have lengths that are multiples of 4.
Aye, analogously, I remember noticing that t10.org op x7F claims to max out CDB length at x104 rather than the x107 that that additional length could express.
Quoted 11 lines
Quoted 6 lines
int vn = 0; if (0 <= ioctl(fd, SG_GET_VERSION_NUM, &vn)) { if (vn < 30000) { perror("ioctl SG_GET_VERSION_NUM"); continue; }Note: I have started to drop this
SG_GET_VERSION_NUMioctl()check. It is still needed in the special case where the sg driver is working asynchronously (i.e. sending commands withwrite()and receiving the response withread()).
Help?
I thought the purpose of ioctl SG_GET_VERSION_NUM was to avoid sending ioctl SG_IO on a Linux so old that ioctl SG_IO meant something different.
Is that wrong? Can I expect Linux to behave reasonably whenever I assault it with a root-privileged ioctl SG_IO, no matter what the ioctl SG_GET_VERSION_NUM results are?
Quoted 7 lines
Quoted 5 lines
sih->dxferp = static_data; sih->dxfer_len = 0x24; sih->dxfer_direction = SG_DXFER_NONE; sih->dxfer_direction = SG_DXFER_TO_DEV; sih->dxfer_direction = SG_DXFER_FROM_DEV;The three above lines look a bit strange :-)
Help? Why strange?
These three lines exist because I can easily reorder them to change quickly among the three main options of expecting data in, data out, or no data. Commenting out the two lines that have no effect would actually make that edit more difficult.
Maybe your ":-)" means you understood that?
Quoted 2 lines
Perhaps you could sent me the "strace" of this failure so I can have a closer look at what is going on.
I will try to remember to strace next time I report a failing ioctl.
I will believe the progress of this thread has obsoleted that specific request unless you say different.
Quoted 5 lines
Quoted 5 lines
Can ioctl
SG_IOfetch the offset 7 Additional Length field of op x03 "REQUEST SENSE" data?Naively I thought yes of course, I know that works with
/dev/scd$n.
Quoted 8 lines
Quoted 2 lines
But then I tried a
/dev/hd$vide-floppy. No joy. perror tells me ioctlSG_IOfails via "Invalid argument", ...My method with the
SG_IOioctl was to yield errnos if the SCSI command could not be sent (or was rejected at the point of transmission). So if there is an errno there will be no sense buffer (or any other valid response data).
This much I did understand correctly from the doc.
I did eventually write:
ii = ioctl(fd, SG_IO, sih);
if (ii < 0) {
perror("ioctl SG_IO");
... die ...
} else {
fwrite(sih->dxferp, sih->dxfer_len, 1, stdout);
if ((sih->info & SG_INFO_OK_MASK) != SG_INFO_OK) {
... die ...
} else if (sih->resid != 0) {
... die ...
}
...
}The case that falls thru without "die"ing is my guess of when SG_IO actually has reported complete success.
Pat LaVarre
Quoted 10 lines · Pat LaVarre
Quoted 1 line
Quoted 1 line
should work, I think.
Yes, thank you!
I reverted
drivers/ide/ide.cide-floppy.cto 2.6.7-rc3 and then saw your updated version applied clean.Quoted 1 line
Here's an updated version.
For me now ioctl
SG_GET_VERSION_NUMworks, and ioctlSG_IOworks, ...
Super!
Quoted 3 lines
Except ioctl
SG_IOsg_io_hdr_t.resid always comes back unchanged from its initialdxfer_lenvalue. I see nonzero residue reported by the trivial code I mentioned before, same there as in plscsi.
That's expected, I need to change the callback to set these correctly (it's not modifying any of the sg_io_hdr output values in the test patch). I'll try and get you a patch tomorrow, if you could check error reporting + residual with that, we can get something into mainline soon.
Signature · 1 line
Jens Axboe
Quoted 11 lines · Douglas Gilbert
Quoted 6 lines · Pat LaVarre
Doug G:
Did I do something wrong, or does "everyone know" already,
SCSI pass thru in 2.6 omits ide-floppy, except if we do resort to the ide-scsi deprecated there?
Pat,
In lk 2.6 the ide-scsi driver is "deprecated" for cd/dvd device types but not other device types that use the ATAPI protocol. The ide-scsi
Direct-device is still clearly superior. ide-scsi is deprecated for any ATAPI type device using SG_IO, other uses may vary.
Quoted 3 lines
Anyway ide-scsi probably needs some repair work in lk 2.6. Both Willem Riede and I have tried. IMO the ide-scsi driver looks ok from the scsi subsystem side ....
Should work since months.
Quoted 12 lines
Quoted 11 lines
Or more specifically,
Can ioctl
SG_IOfetch the offset 7 Additional Length field of op x03 "REQUEST SENSE" data?Naively I thought yes of course, I know that works with
/dev/scd$n.But then I tried a
/dev/hd$vide-floppy. No joy. perror tells me ioctlSG_IOfails via "Invalid argument", dmesg has no comment.sg_scanyou know. ~/bin/sgio source is the trivial exercise quoted in source far below, specifically with an O_NONBLOCK|O_RDWR open as you can see.
Quoted 7 lines
My method with the
SG_IOioctl was to yield errnos if the SCSI command could not be sent (or was rejected at the point of transmission). So if there is an errno there will be no sense buffer (or any other valid response data). It is only when a response to the SCSI command is received that errno will be clear (and the various status variables should be checked).
The issue here is that ide-floppy doesn't grok REQ_BLOCK_PC requests correctly, so when SG_IO generates them they are failed.
Signature · 1 line
Jens Axboe
Quoted 1 line · Pat LaVarre
Doug G:
<snip/>
Quoted 16 lines
Quoted 8 lines
Quoted 7 lines
int vn = 0; if (0 <= ioctl(fd, SG_GET_VERSION_NUM, &vn)) { if (vn < 30000) { perror("ioctl SG_GET_VERSION_NUM"); continue; }Quoted 4 lines
Note: I have started to drop this
SG_GET_VERSION_NUMioctl()check. It is still needed in the special case where the sg driver is working asynchronously (i.e. sending commands withwrite()and receiving the response withread()).Help?
Quoted 7 lines
I thought the purpose of ioctl
SG_GET_VERSION_NUMwas to avoid sending ioctlSG_IOon a Linux so old that ioctlSG_IOmeant something different.Is that wrong? Can I expect Linux to behave reasonably whenever I assault it with a root-privileged ioctl
SG_IO, no matter what the ioctlSG_GET_VERSION_NUMresults are?
To the best of my knowledge the SG_IO ioctl (request id 0x2285) does not clash with any other ioctl in linux. With version 2 of the sg driver and earlier ( <= lk 2.2) the SG_IO ioctl didn't exist. The problem arises when the asynchronous sg driver interface (i.e. write() a SCSI command the read() the response when it arrives) is very dangerous to do on anything other than an sg device! I crunched the partition table on one of my disks when the SG_IO ioctl was first introduced to the block layer. This is because I used a utility in the sg3_utils package that used the async interface (i.e. write()/read() ) on a block device :-)
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
sih->dxferp = static_data; sih->dxfer_len = 0x24; sih->dxfer_direction = SG_DXFER_NONE; sih->dxfer_direction = SG_DXFER_TO_DEV; sih->dxfer_direction = SG_DXFER_FROM_DEV;The three above lines look a bit strange :-)
Quoted 8 lines
Help? Why strange?
These three lines exist because I can easily reorder them to change quickly among the three main options of expecting data in, data out, or no data. Commenting out the two lines that have no effect would actually make that edit more difficult.
Maybe your ":-)" means you understood that?
Well I think the janitors go over the top sometimes (especially if they hound driver maintainers out of their support roles) but ...
there is the smaller matter of efficiency and code size. How about:
// dxfer_direction is one of SG_DXFER_NONE,
// SG_DXFER_TO_DEV, or SG_DXFER_FROM_DEV
sih->dxfer_direction = SG_DXFER_FROM_DEV;
Quoted 8 lines
Quoted 2 lines
Perhaps you could sent me the "strace" of this failure so I can have a closer look at what is going on.
I will try to remember to strace next time I report a failing ioctl.
I will believe the progress of this thread has obsoleted that specific request unless you say different.
Yes, it seems as though Jens is close to, or has solved this problem.
Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
Can ioctl
SG_IOfetch the offset 7 Additional Length field of op x03 "REQUEST SENSE" data?Naively I thought yes of course, I know that works with
/dev/scd$n.Quoted 8 lines
Quoted 2 lines
But then I tried a
/dev/hd$vide-floppy. No joy. perror tells me ioctlSG_IOfails via "Invalid argument", ...My method with the
SG_IOioctl was to yield errnos if the SCSI command could not be sent (or was rejected at the point of transmission). So if there is an errno there will be no sense buffer (or any other valid response data).This much I did understand correctly from the doc.
Quoted 8 lines
I did eventually write:
ii = ioctl(fd, SG_IO, sih); if (ii < 0) { perror("ioctl SG_IO"); ... die ... } else { fwrite(sih->dxferp, sih->dxfer_len, 1, stdout);
If this fwrite() is outputting something that has be read from the device then it shouldn't be done _before_ the following status/warning/error checks.
Quoted 10 lines
if ((sih->info & SG_INFO_OK_MASK) != SG_INFO_OK) { ... die ... } else if (sih->resid != 0) { ... die ... } ... }The case that falls thru without "die"ing is my guess of when
SG_IOactually has reported complete success.
It is not quite that simple. There are some statuses like the sense key of RECOVERED ERROR that imply the operation worked but "I thought you would like to know that your disk might be dying ...". Then there are UNIT ATTENTIONs to inform you that the device has been reset or the reservation you had has been cleared by someone else. If that information isn't relevant to your application then executing the command again will most likely succeed. There can also be deferred errors (i.e. that write you did earlier failed which can happen when write caching is employed).
So I'm trying to encourage you and others to check the returned SCSI status (and other statuses that could flag a command timeout for example) and if necessary decode the sense buffer. sg_err.[hc] in sg3_utils does a lot of this work.
Doug Gilbert
Quoted 3 lines
ide-scsi is deprecated for any
ATAPI type device usingSG_IO,
other uses may vary.
I will next try SG_IO with PATAPI in 2.6.7,
i.e. that's my guess unless corrected of how I can best help next now.
Pat LaVarre
Quoted 6 lines · Pat LaVarre
Quoted 3 lines
ide-scsi is deprecated for any
ATAPI type device usingSG_IO,
other uses may vary.I will next try
SG_IOwith PATAPI in 2.6.7,
i.e. that's my guess unless corrected of how I can best help next now.
Just hold of until tomorrow, you still need the update ide-floppy SG_IO patch (which I didn't do yet). Or you can look into completing it yourself, if you have time to spend on that today.
Signature · 1 line
Jens Axboe