Skip to contentSkip to conversation

ATAPI-SCSI bridge GSoC project

RFC In review Alexander Bezzubikov 3 participants 3 messages Jul 18, 2015 – Jul 20, 2015

lore
Share & tools
lore
#0 lore raw

RFC 1/1 ATAPI-SCSI bridge GSoC project

atapi: ATAPI-SCSI bridge device created
private SCSI bus added to bridge
ATAPI inquiry command can use a bridge

---
 hw/ide/atapi.c         |  36 +++++--
 hw/ide/core.c          | 207 +++++++++++++++++++--------------------
 hw/ide/internal.h      | 257 +++++++++++++++++++++++++------------------------
 hw/ide/qdev.c          |  43 ++++++++-
 hw/scsi/scsi-disk.c    |   4 +-
 include/hw/scsi/scsi.h |   6 +-
 6 files changed, 310 insertions(+), 243 deletions(-)
hw/ide/atapi.c +28 -8
index 950e311..e931e0e 100644
@@ -635,6 +635,20 @@ static void cmd_request_sense(IDEState *s, uint8_t *buf)
     ide_atapi_cmd_reply(s, 18, max_len);
 }
 
+static void inquiry_wrapper(IDEState *s, uint8_t *buf)
+{
+    IDEDevice *dev = s->bus->master;
+    SCSIDevice *scsi_dev = scsi_device_find(&dev->scsi_bus, 0, 0, 0);
+    SCSIRequest *req = scsi_req_new(scsi_dev, 0, 0, buf, NULL);
+    
+    int max_len = scsi_disk_emulate_inquiry(req, buf);
+    int idx = 36;
+    
+    ide_atapi_cmd_reply(s, idx, max_len);
+    
+    return;
+}
+
 static void cmd_inquiry(IDEState *s, uint8_t *buf)
 {
     uint8_t page_code = buf[2];
@@ -1170,7 +1184,7 @@ enum {
     CHECK_READY = 0x02,
 };
 
-static const struct {
+static const struct atapi_command {
     void (*handler)(IDEState *s, uint8_t *buf);
     int flags;
 } atapi_cmd_table[0x100] = {
@@ -1193,11 +1207,17 @@ static const struct {
     [ 0xbd ] = { cmd_mechanism_status,              0 },
     [ 0xbe ] = { cmd_read_cd,                       CHECK_READY },
     /* [1] handler detects and reports not ready condition itself */
-};
+},
+  bridge_cmd_table[0x100] = {
+    [ 0x12 ] = { inquiry_wrapper,                   ALLOW_UA }
+  };
 
 void ide_atapi_cmd(IDEState *s)
 {
     uint8_t *buf;
+    
+    const struct atapi_command *cmd_table = (s->drive_kind == IDE_BRIDGE &&
+        bridge_cmd_table[s->io_buffer[0]].handler) ? bridge_cmd_table : atapi_cmd_table;
 
     buf = s->io_buffer;
 #ifdef DEBUG_IDE_ATAPI
@@ -1217,7 +1237,7 @@ void ide_atapi_cmd(IDEState *s)
      * here, is pending.
      */
     if (s->sense_key == UNIT_ATTENTION &&
-        !(atapi_cmd_table[s->io_buffer[0]].flags & ALLOW_UA)) {
+        !(cmd_table[s->io_buffer[0]].flags & ALLOW_UA)) {
         ide_atapi_cmd_check_status(s);
         return;
     }
@@ -1228,7 +1248,7 @@ void ide_atapi_cmd(IDEState *s)
      * GET_EVENT_STATUS_NOTIFICATION to detect such tray open/close
      * states rely on this behavior.
      */
-    if (!(atapi_cmd_table[s->io_buffer[0]].flags & ALLOW_UA) &&
+    if (!(cmd_table[s->io_buffer[0]].flags & ALLOW_UA) &&
         !s->tray_open && blk_is_inserted(s->blk) && s->cdrom_changed) {
 
         if (s->cdrom_changed == 1) {
@@ -1243,7 +1263,7 @@ void ide_atapi_cmd(IDEState *s)
     }
 
     /* Report a Not Ready condition if appropriate for the command */
-    if ((atapi_cmd_table[s->io_buffer[0]].flags & CHECK_READY) &&
+    if ((cmd_table[s->io_buffer[0]].flags & CHECK_READY) &&
         (!media_present(s) || !blk_is_inserted(s->blk)))
     {
         ide_atapi_cmd_error(s, NOT_READY, ASC_MEDIUM_NOT_PRESENT);
@@ -1251,10 +1271,10 @@ void ide_atapi_cmd(IDEState *s)
     }
 
     /* Execute the command */
-    if (atapi_cmd_table[s->io_buffer[0]].handler) {
-        atapi_cmd_table[s->io_buffer[0]].handler(s, buf);
+    if (cmd_table[s->io_buffer[0]].handler) {
+        cmd_table[s->io_buffer[0]].handler(s, buf);
         return;
     }
 
     ide_atapi_cmd_error(s, ILLEGAL_REQUEST, ASC_ILLEGAL_OPCODE);
-}
+}
\ No newline at end of file
hw/ide/core.c +105 -102

388 lines not on this page · raw message

hw/ide/internal.h +130 -127

385 lines not on this page · raw message

hw/ide/qdev.c +41 -2

81 lines not on this page · raw message

hw/scsi/scsi-disk.c +2 -2
index 54d71f4..2ecb540 100644
@@ -527,7 +527,7 @@ static uint8_t *scsi_get_buf(SCSIRequest *req)
     return (uint8_t *)r->iov.iov_base;
 }
 
-static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
+int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
 {
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
     int buflen = 0;
@@ -2759,4 +2759,4 @@ static void scsi_disk_register_types(void)
     type_register_static(&scsi_disk_info);
 }
 
-type_init(scsi_disk_register_types)
+type_init(scsi_disk_register_types)
\ No newline at end of file
include/hw/scsi/scsi.h +4 -2
index cdaf0f8..beecbbc 100644
@@ -7,7 +7,7 @@
 #include "sysemu/sysemu.h"
 #include "qemu/notify.h"
 
-#define MAX_SCSI_DEVS	255
+#define MAX_SCSI_DEVS   255
 
 #define SCSI_CMD_BUF_SIZE     16
 #define SCSI_SENSE_LEN      18
@@ -275,7 +275,9 @@ void scsi_device_unit_attention_reported(SCSIDevice *dev);
 int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed);
 SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lun);
 
+int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf);
+
 /* scsi-generic.c. */
 extern const SCSIReqOps scsi_generic_req_ops;
 
-#endif
+#endif
\ No newline at end of file
Signature · 1 line
2.1.4
#1 lore raw
Quoted 3 lines · Alexander Bezzubikov

atapi: ATAPI-SCSI bridge device created
private SCSI bus added to bridge
ATAPI inquiry command can use a bridge

Hi!

Not everybody is familiar with your GSoC project, so it would be great if you could be a little bit more verbose in your patch description.

Unfortunately, your patch also has some style issues, please make sure to read http://qemu-project.org/Contribute/SubmitAPatch first. Especially:
- Your patch lacks a Signed-off-by line
- scripts/checkpatch.pl reports quite a bunch of errors
- Make sure to CC the right maintainers

Hope that helps,
Thomas

#2 lore raw
In reply to Alexander Bezzubikov
Quoted 3 lines · Alexander Bezzubikov

atapi: ATAPI-SCSI bridge device created
private SCSI bus added to bridge
ATAPI inquiry command can use a bridge

Multiple items is a clue that this patch should be split up into patches with smaller logical changes.

That will also allow you to write commit descriptions that give the rationale for the changes.