blob: 48568e63085d46a162247294f080838f38113c2c [file] [log] [blame]
Kevin O'Connor76977b22010-02-17 01:01:32 -05001// Support for several common scsi like command data block requests
2//
3// Copyright (C) 2010 Kevin O'Connor <kevin@koconnor.net>
4// Copyright (C) 2002 MandrakeSoft S.A.
5//
6// This file may be distributed under the terms of the GNU LGPLv3 license.
7
8#include "biosvar.h" // GET_GLOBAL
9#include "util.h" // htonl
10#include "disk.h" // struct disk_op_s
11#include "blockcmd.h" // struct cdb_request_sense
12#include "ata.h" // atapi_cmd_data
Kevin O'Connor7149fc82010-02-17 23:24:42 -050013#include "usb-msc.h" // usb_cmd_data
Kevin O'Connor76977b22010-02-17 01:01:32 -050014
Kevin O'Connor7149fc82010-02-17 23:24:42 -050015// Route command to low-level handler.
Kevin O'Connor76977b22010-02-17 01:01:32 -050016static int
17cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize)
18{
19 u8 type = GET_GLOBAL(op->drive_g->type);
20 switch (type) {
21 case DTYPE_ATAPI:
22 return atapi_cmd_data(op, cdbcmd, blocksize);
Kevin O'Connor7149fc82010-02-17 23:24:42 -050023 case DTYPE_USB:
24 return usb_cmd_data(op, cdbcmd, blocksize);
Kevin O'Connor76977b22010-02-17 01:01:32 -050025 default:
26 op->count = 0;
27 return DISK_RET_EPARAM;
28 }
29}
30
Kevin O'Connor7149fc82010-02-17 23:24:42 -050031int
32cdb_get_inquiry(struct disk_op_s *op, struct cdbres_inquiry *data)
33{
34 struct cdb_request_sense cmd;
35 memset(&cmd, 0, sizeof(cmd));
36 cmd.command = CDB_CMD_INQUIRY;
37 cmd.length = sizeof(*data);
38 op->count = 1;
39 op->buf_fl = data;
40 return cdb_cmd_data(op, &cmd, sizeof(*data));
41}
42
Kevin O'Connor76977b22010-02-17 01:01:32 -050043// Request SENSE
44int
45cdb_get_sense(struct disk_op_s *op, struct cdbres_request_sense *data)
46{
47 struct cdb_request_sense cmd;
48 memset(&cmd, 0, sizeof(cmd));
49 cmd.command = CDB_CMD_REQUEST_SENSE;
50 cmd.length = sizeof(*data);
51 op->count = 1;
52 op->buf_fl = data;
53 return cdb_cmd_data(op, &cmd, sizeof(*data));
54}
55
56// Request capacity
57int
58cdb_read_capacity(struct disk_op_s *op, struct cdbres_read_capacity *data)
59{
60 struct cdb_read_capacity cmd;
61 memset(&cmd, 0, sizeof(cmd));
62 cmd.command = CDB_CMD_READ_CAPACITY;
63 op->count = 1;
64 op->buf_fl = data;
65 return cdb_cmd_data(op, &cmd, sizeof(*data));
66}
67
68// Read sectors.
69int
70cdb_read(struct disk_op_s *op)
71{
72 struct cdb_rwdata_10 cmd;
73 memset(&cmd, 0, sizeof(cmd));
74 cmd.command = CDB_CMD_READ_10;
75 cmd.lba = htonl(op->lba);
76 cmd.count = htons(op->count);
Kevin O'Connor7149fc82010-02-17 23:24:42 -050077 return cdb_cmd_data(op, &cmd, GET_GLOBAL(op->drive_g->blksize));
Kevin O'Connor76977b22010-02-17 01:01:32 -050078}