1 // Support for several common scsi like command data block requests
3 // Copyright (C) 2010 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002 MandrakeSoft S.A.
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
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
13 #include "ahci.h" // atapi_cmd_data
14 #include "usb-msc.h" // usb_cmd_data
16 // Route command to low-level handler.
18 cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize)
20 u8 type = GET_GLOBAL(op->drive_g->type);
23 return atapi_cmd_data(op, cdbcmd, blocksize);
25 return usb_cmd_data(op, cdbcmd, blocksize);
27 return ahci_cmd_data(op, cdbcmd, blocksize);
30 return DISK_RET_EPARAM;
35 cdb_get_inquiry(struct disk_op_s *op, struct cdbres_inquiry *data)
37 struct cdb_request_sense cmd;
38 memset(&cmd, 0, sizeof(cmd));
39 cmd.command = CDB_CMD_INQUIRY;
40 cmd.length = sizeof(*data);
43 return cdb_cmd_data(op, &cmd, sizeof(*data));
48 cdb_get_sense(struct disk_op_s *op, struct cdbres_request_sense *data)
50 struct cdb_request_sense cmd;
51 memset(&cmd, 0, sizeof(cmd));
52 cmd.command = CDB_CMD_REQUEST_SENSE;
53 cmd.length = sizeof(*data);
56 return cdb_cmd_data(op, &cmd, sizeof(*data));
61 cdb_read_capacity(struct disk_op_s *op, struct cdbres_read_capacity *data)
63 struct cdb_read_capacity cmd;
64 memset(&cmd, 0, sizeof(cmd));
65 cmd.command = CDB_CMD_READ_CAPACITY;
68 return cdb_cmd_data(op, &cmd, sizeof(*data));
73 cdb_read(struct disk_op_s *op)
75 struct cdb_rwdata_10 cmd;
76 memset(&cmd, 0, sizeof(cmd));
77 cmd.command = CDB_CMD_READ_10;
78 cmd.lba = htonl(op->lba);
79 cmd.count = htons(op->count);
80 return cdb_cmd_data(op, &cmd, GET_GLOBAL(op->drive_g->blksize));