static int megasas_ld_get_info_submit(SCSIDevice *sdev, int lun,

                                      MegasasCmd *cmd)

{

    struct mfi_ld_info *info = cmd->iov_buf;

    size_t dcmd_size = sizeof(struct mfi_ld_info);

    uint8_t cdb[6];

    SCSIRequest *req;

    ssize_t len, resid;

    BlockConf *conf = &sdev->conf;

    uint16_t sdev_id = ((sdev->id & 0xFF) >> 8) | (lun & 0xFF);

    uint64_t ld_size;



    if (!cmd->iov_buf) {

        cmd->iov_buf = g_malloc(dcmd_size);

        memset(cmd->iov_buf, 0x0, dcmd_size);

        info = cmd->iov_buf;

        megasas_setup_inquiry(cdb, 0x83, sizeof(info->vpd_page83));

        req = scsi_req_new(sdev, cmd->index, lun, cdb, cmd);

        if (!req) {

            trace_megasas_dcmd_req_alloc_failed(cmd->index,

                                                "LD get info vpd inquiry");

            g_free(cmd->iov_buf);

            cmd->iov_buf = NULL;

            return MFI_STAT_FLASH_ALLOC_FAIL;

        }

        trace_megasas_dcmd_internal_submit(cmd->index,

                                           "LD get info vpd inquiry", lun);

        len = scsi_req_enqueue(req);

        if (len > 0) {

            cmd->iov_size = len;

            scsi_req_continue(req);

        }

        return MFI_STAT_INVALID_STATUS;

    }



    info->ld_config.params.state = MFI_LD_STATE_OPTIMAL;

    info->ld_config.properties.ld.v.target_id = lun;

    info->ld_config.params.stripe_size = 3;

    info->ld_config.params.num_drives = 1;

    info->ld_config.params.is_consistent = 1;

    /* Logical device size is in blocks */

    bdrv_get_geometry(conf->bs, &ld_size);

    info->size = cpu_to_le64(ld_size);

    memset(info->ld_config.span, 0, sizeof(info->ld_config.span));

    info->ld_config.span[0].start_block = 0;

    info->ld_config.span[0].num_blocks = info->size;

    info->ld_config.span[0].array_ref = cpu_to_le16(sdev_id);



    resid = dma_buf_read(cmd->iov_buf, dcmd_size, &cmd->qsg);

    g_free(cmd->iov_buf);

    cmd->iov_size = dcmd_size - resid;

    cmd->iov_buf = NULL;

    return MFI_STAT_OK;

}

static int megasas_ld_get_info_submit(SCSIDevice *sdev, int lun,

                                      MegasasCmd *cmd)

{

    struct mfi_ld_info *info = cmd->iov_buf;

    size_t dcmd_size = sizeof(struct mfi_ld_info);

    uint8_t cdb[6];

    SCSIRequest *req;

    ssize_t len, resid;

    BlockConf *conf = &sdev->conf;

    uint16_t sdev_id = ((sdev->id & 0xFF) >> 8) | (lun & 0xFF);

    uint64_t ld_size;



    if (!cmd->iov_buf) {

        cmd->iov_buf = g_malloc(dcmd_size);

        memset(cmd->iov_buf, 0x0, dcmd_size);

        info = cmd->iov_buf;

        megasas_setup_inquiry(cdb, 0x83, sizeof(info->vpd_page83));

        req = scsi_req_new(sdev, cmd->index, lun, cdb, cmd);

        if (!req) {

            trace_megasas_dcmd_req_alloc_failed(cmd->index,

                                                "LD get info vpd inquiry");

            g_free(cmd->iov_buf);

            cmd->iov_buf = NULL;

            return MFI_STAT_FLASH_ALLOC_FAIL;

        }

        trace_megasas_dcmd_internal_submit(cmd->index,

                                           "LD get info vpd inquiry", lun);

        len = scsi_req_enqueue(req);

        if (len > 0) {

            cmd->iov_size = len;

            scsi_req_continue(req);

        }

        return MFI_STAT_INVALID_STATUS;

    }



    info->ld_config.params.state = MFI_LD_STATE_OPTIMAL;

    info->ld_config.properties.ld.v.target_id = lun;

    info->ld_config.params.stripe_size = 3;

    info->ld_config.params.num_drives = 1;

    info->ld_config.params.is_consistent = 1;

    

    bdrv_get_geometry(conf->bs, &ld_size);

    info->size = cpu_to_le64(ld_size);

    memset(info->ld_config.span, 0, sizeof(info->ld_config.span));

    info->ld_config.span[0].start_block = 0;

    info->ld_config.span[0].num_blocks = info->size;

    info->ld_config.span[0].array_ref = cpu_to_le16(sdev_id);



    resid = dma_buf_read(cmd->iov_buf, dcmd_size, &cmd->qsg);

    g_free(cmd->iov_buf);

    cmd->iov_size = dcmd_size - resid;

    cmd->iov_buf = NULL;

    return MFI_STAT_OK;

}

static int FUNC_0(SCSIDevice *VAR_0, int VAR_1,

                                      MegasasCmd *VAR_2)

{

    struct mfi_ld_info *VAR_3 = VAR_2->iov_buf;

    size_t dcmd_size = sizeof(struct mfi_ld_info);

    uint8_t cdb[6];

    SCSIRequest *req;

    ssize_t len, resid;

    BlockConf *conf = &VAR_0->conf;

    uint16_t sdev_id = ((VAR_0->id & 0xFF) >> 8) | (VAR_1 & 0xFF);

    uint64_t ld_size;



    if (!VAR_2->iov_buf) {

        VAR_2->iov_buf = g_malloc(dcmd_size);

        memset(VAR_2->iov_buf, 0x0, dcmd_size);

        VAR_3 = VAR_2->iov_buf;

        megasas_setup_inquiry(cdb, 0x83, sizeof(VAR_3->vpd_page83));

        req = scsi_req_new(VAR_0, VAR_2->index, VAR_1, cdb, VAR_2);

        if (!req) {

            trace_megasas_dcmd_req_alloc_failed(VAR_2->index,

                                                "LD get VAR_3 vpd inquiry");

            g_free(VAR_2->iov_buf);

            VAR_2->iov_buf = NULL;

            return MFI_STAT_FLASH_ALLOC_FAIL;

        }

        trace_megasas_dcmd_internal_submit(VAR_2->index,

                                           "LD get VAR_3 vpd inquiry", VAR_1);

        len = scsi_req_enqueue(req);

        if (len > 0) {

            VAR_2->iov_size = len;

            scsi_req_continue(req);

        }

        return MFI_STAT_INVALID_STATUS;

    }



    VAR_3->ld_config.params.state = MFI_LD_STATE_OPTIMAL;

    VAR_3->ld_config.properties.ld.v.target_id = VAR_1;

    VAR_3->ld_config.params.stripe_size = 3;

    VAR_3->ld_config.params.num_drives = 1;

    VAR_3->ld_config.params.is_consistent = 1;

    

    bdrv_get_geometry(conf->bs, &ld_size);

    VAR_3->size = cpu_to_le64(ld_size);

    memset(VAR_3->ld_config.span, 0, sizeof(VAR_3->ld_config.span));

    VAR_3->ld_config.span[0].start_block = 0;

    VAR_3->ld_config.span[0].num_blocks = VAR_3->size;

    VAR_3->ld_config.span[0].array_ref = cpu_to_le16(sdev_id);



    resid = dma_buf_read(VAR_2->iov_buf, dcmd_size, &VAR_2->qsg);

    g_free(VAR_2->iov_buf);

    VAR_2->iov_size = dcmd_size - resid;

    VAR_2->iov_buf = NULL;

    return MFI_STAT_OK;

}

static int FUNC_0(SCSIDevice *VAR_0, int VAR_1,
MegasasCmd *VAR_2)
{ struct mfi_ld_info *VAR_3 = VAR_2->iov_buf; size_t dcmd_size = sizeof(struct mfi_ld_info); uint8_t cdb[6]; SCSIRequest *req; ssize_t len, resid; BlockConf *conf = &VAR_0->conf; uint16_t sdev_id = ((VAR_0->id & 0xFF) >> 8) | (VAR_1 & 0xFF); uint64_t ld_size; if (!VAR_2->iov_buf) { VAR_2->iov_buf = g_malloc(dcmd_size); memset(VAR_2->iov_buf, 0x0, dcmd_size); VAR_3 = VAR_2->iov_buf; megasas_setup_inquiry(cdb, 0x83, sizeof(VAR_3->vpd_page83)); req = scsi_req_new(VAR_0, VAR_2->index, VAR_1, cdb, VAR_2); if (!req) { trace_megasas_dcmd_req_alloc_failed(VAR_2->index,
"LD get VAR_3 vpd inquiry"); g_free(VAR_2->iov_buf); VAR_2->iov_buf = NULL; return MFI_STAT_FLASH_ALLOC_FAIL; } trace_megasas_dcmd_internal_submit(VAR_2->index,
"LD get VAR_3 vpd inquiry", VAR_1); len = scsi_req_enqueue(req); if (len > 0) { VAR_2->iov_size = len; scsi_req_continue(req); } return MFI_STAT_INVALID_STATUS; } VAR_3->ld_config.params.state = MFI_LD_STATE_OPTIMAL; VAR_3->ld_config.properties.ld.v.target_id = VAR_1; VAR_3->ld_config.params.stripe_size = 3; VAR_3->ld_config.params.num_drives = 1; VAR_3->ld_config.params.is_consistent = 1; bdrv_get_geometry(conf->bs, &ld_size); VAR_3->size = cpu_to_le64(ld_size); memset(VAR_3->ld_config.span, 0, sizeof(VAR_3->ld_config.span)); VAR_3->ld_config.span[0].start_block = 0; VAR_3->ld_config.span[0].num_blocks = VAR_3->size; VAR_3->ld_config.span[0].array_ref = cpu_to_le16(sdev_id); resid = dma_buf_read(VAR_2->iov_buf, dcmd_size, &VAR_2->qsg); g_free(VAR_2->iov_buf); VAR_2->iov_size = dcmd_size - resid; VAR_2->iov_buf = NULL; return MFI_STAT_OK; }