~ubuntu-branches/ubuntu/natty/hdparm/natty

« back to all changes in this revision

Viewing changes to sgio.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2010-01-17 18:02:44 UTC
  • mto: (2.1.5 sid)
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: james.westby@ubuntu.com-20100117180244-p53m2zbnkf9my7sp
Tags: upstream-9.27
ImportĀ upstreamĀ versionĀ 9.27

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
static inline int needs_lba48 (__u8 ata_op, __u64 lba, unsigned int nsect)
57
57
{
58
 
        const __u64 lba28_limit = (1<<28) - 1;
59
 
 
60
58
        switch (ata_op) {
 
59
                case ATA_OP_DSM:
61
60
                case ATA_OP_READ_PIO_EXT:
62
61
                case ATA_OP_READ_DMA_EXT:
63
62
                case ATA_OP_WRITE_PIO_EXT:
80
79
        return 0;
81
80
}
82
81
 
 
82
static inline int is_dma (__u8 ata_op)
 
83
{
 
84
        switch (ata_op) {
 
85
                case ATA_OP_DSM:
 
86
                case ATA_OP_READ_DMA_EXT:
 
87
                case ATA_OP_READ_FPDMA:
 
88
                case ATA_OP_WRITE_DMA_EXT:
 
89
                case ATA_OP_WRITE_FPDMA:
 
90
                case ATA_OP_READ_DMA:
 
91
                case ATA_OP_WRITE_DMA:
 
92
                        return SG_DMA;
 
93
                default:
 
94
                        return SG_PIO;
 
95
        }
 
96
}
 
97
 
83
98
void tf_init (struct ata_tf *tf, __u8 ata_op, __u64 lba, unsigned int nsect)
84
99
{
85
100
        memset(tf, 0, sizeof(*tf));
204
219
        io_hdr.pack_id          = tf_to_lba(tf);
205
220
        io_hdr.timeout          = (timeout_secs ? timeout_secs : 5) * 1000; /* msecs */
206
221
 
207
 
        if (verbose)
 
222
        if (verbose) {
208
223
                dump_bytes("outgoing cdb", cdb, sizeof(cdb));
 
224
                if (data)
 
225
                        dump_bytes("data", data, 16);
 
226
        }
 
227
 
209
228
        if (ioctl(fd, SG_IO, &io_hdr) == -1) {
210
229
                if (verbose)
211
230
                        perror("ioctl(fd,SG_IO)");
212
231
                return -1;      /* SG_IO not supported */
213
232
        }
 
233
 
214
234
        if (verbose)
215
235
                fprintf(stderr, "SG_IO: ATA_%u status=0x%x, host_status=0x%x, driver_status=0x%x\n",
216
236
                        io_hdr.cmd_len, io_hdr.status, io_hdr.host_status, io_hdr.driver_status);
307
327
                tf.lob.lbah  = 0xc2;
308
328
        }
309
329
 
310
 
        rc = sg16(fd, SG_READ, SG_PIO, &tf, data, data_bytes, 0);
 
330
        rc = sg16(fd, SG_READ, is_dma(tf.command), &tf, data, data_bytes, 0);
311
331
        if (rc == -1) {
312
332
                if (errno == EINVAL || errno == ENODEV)
313
333
                        goto use_legacy_ioctl;
322
342
 
323
343
use_legacy_ioctl:
324
344
#endif /* SG_IO */
325
 
        if (verbose)
326
 
                fprintf(stderr, "Trying legacy HDIO_DRIVE_CMD\n");
 
345
        if (verbose) {
 
346
                if (args)
 
347
                        fprintf(stderr, "Trying legacy HDIO_DRIVE_CMD\n");
 
348
        }
327
349
        return ioctl(fd, HDIO_DRIVE_CMD, args);
328
350
}
329
351
 
343
365
        if (verbose) {
344
366
                printf("oflags.lob_all=0x%02x, flags={", r->oflags.lob_all);
345
367
                if (r->oflags.lob.feat) printf(" feat");
 
368
                if (r->oflags.lob.nsect)printf(" nsect");
346
369
                if (r->oflags.lob.lbal) printf(" lbal");
347
 
                if (r->oflags.lob.nsect)printf(" nsect");
348
370
                if (r->oflags.lob.lbam) printf(" lbam");
349
371
                if (r->oflags.lob.lbah) printf(" lbah");
350
372
                if (r->oflags.lob.dev)  printf(" dev");
352
374
                printf(" }\n");
353
375
                printf("oflags.hob_all=0x%02x, flags={", r->oflags.hob_all);
354
376
                if (r->oflags.hob.feat) printf(" feat");
 
377
                if (r->oflags.hob.nsect)printf(" nsect");
355
378
                if (r->oflags.hob.lbal) printf(" lbal");
356
 
                if (r->oflags.hob.nsect)printf(" nsect");
357
379
                if (r->oflags.hob.lbam) printf(" lbam");
358
380
                if (r->oflags.hob.lbah) printf(" lbah");
359
381
                printf(" }\n");
366
388
        if (r->oflags.lob.lbah)         tf.lob.lbah  = r->lob.lbah;
367
389
        if (r->oflags.lob.dev)          tf.dev       = r->lob.dev;
368
390
        if (r->oflags.lob.command)      tf.command   = r->lob.command;
369
 
        if (r->oflags.hob_all || r->iflags.hob_all) {
 
391
        if (needs_lba48(tf.command,0,0) || r->oflags.hob_all || r->iflags.hob_all) {
370
392
                tf.is_lba48 = 1;
371
393
                if (r->oflags.hob.feat) tf.hob.feat  = r->hob.feat;
372
394
                if (r->oflags.hob.lbal) tf.hob.lbal  = r->hob.lbal;
389
411
                        break;
390
412
        }
391
413
 
392
 
        rc = sg16(fd, rw, SG_PIO, &tf, data, data_bytes, timeout_secs);
 
414
        rc = sg16(fd, rw, is_dma(tf.command), &tf, data, data_bytes, timeout_secs);
393
415
        if (rc == -1) {
394
416
                if (errno == EINVAL || errno == ENODEV)
395
417
                        goto use_legacy_ioctl;
418
440
        if (verbose)
419
441
                fprintf(stderr, "trying legacy HDIO_DRIVE_TASKFILE\n");
420
442
        errno = 0;
 
443
 
421
444
        rc = ioctl(fd, HDIO_DRIVE_TASKFILE, r);
422
445
        if (verbose) {
423
446
                int err = errno;